1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace hipanel\modules\finance\widgets\combo; |
4
|
|
|
|
5
|
|
|
use hiqdev\combo\Combo; |
6
|
|
|
use yii\helpers\ArrayHelper; |
7
|
|
|
use yii\web\JsExpression; |
8
|
|
|
|
9
|
|
|
class BillHwPurchaseCombo extends Combo |
10
|
|
|
{ |
11
|
|
|
/** {@inheritdoc} */ |
12
|
|
|
public $type = 'bill/descr'; |
13
|
|
|
|
14
|
|
|
/** {@inheritdoc} */ |
15
|
|
|
public $name = 'descr'; |
16
|
|
|
|
17
|
|
|
/** {@inheritdoc} */ |
18
|
|
|
public $url = '/finance/bill/index'; |
19
|
|
|
|
20
|
|
|
/** {@inheritdoc} */ |
21
|
|
|
public $_return = ['id', 'client', 'sum', 'currency', 'descr', 'label', 'time']; |
22
|
|
|
|
23
|
|
|
/** {@inheritdoc} */ |
24
|
|
|
public $_rename = ['text' => 'label']; |
25
|
|
|
|
26
|
|
|
/** {@inheritdoc} */ |
27
|
|
|
public $_primaryFilter = 'descr'; |
28
|
|
|
|
29
|
|
|
/** {@inheritdoc} */ |
30
|
|
|
public function getPluginOptions($options = []) |
31
|
|
|
{ |
32
|
|
|
return parent::getPluginOptions([ |
33
|
|
|
'select2Options' => [ |
34
|
|
|
'templateResult' => new JsExpression("function (data) { |
35
|
|
|
if (data.loading) { |
36
|
|
|
return data.text; |
37
|
|
|
} |
38
|
|
|
var client = '<b>' + data.client + ': ' |
39
|
|
|
color = data.sum < 0 ? 'text-danger' : 'text-success'; |
40
|
|
|
sum = ' <span class=\"' + color +'\">' + data.sum + '</span> ' |
41
|
|
|
currency = ' ' + data.currency.toUpperCase() + '</b><br>' |
42
|
|
|
descr = (data.descr ? data.descr : data.label); |
43
|
|
|
|
44
|
|
|
return client + sum + currency + (descr ? descr : '<span class=\"text-muted\">--</span>'); |
45
|
|
|
}"), |
46
|
|
|
'escapeMarkup' => new JsExpression('function (markup) { |
47
|
|
|
return markup; // Allows HTML |
48
|
|
|
}'), |
49
|
|
|
], |
50
|
|
|
]); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** {@inheritdoc} */ |
54
|
|
|
public function getFilter() |
55
|
|
|
{ |
56
|
|
|
return ArrayHelper::merge(parent::getFilter(), [ |
57
|
|
|
'ftype' => ['format' => 'other,hw_purchase'], |
58
|
|
|
'limit' => ['format' => '50'], |
59
|
|
|
]); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
|