1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Finance module for HiPanel |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/hiqdev/hipanel-module-finance |
6
|
|
|
* @package hipanel-module-finance |
7
|
|
|
* @license BSD-3-Clause |
8
|
|
|
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace hipanel\modules\finance\widgets\combo; |
12
|
|
|
|
13
|
|
|
use hiqdev\combo\Combo; |
14
|
|
|
use yii\helpers\ArrayHelper; |
15
|
|
|
use yii\web\JsExpression; |
16
|
|
|
|
17
|
|
|
class BillHwPurchaseCombo extends Combo |
18
|
|
|
{ |
19
|
|
|
/** {@inheritdoc} */ |
20
|
|
|
public $type = 'bill/descr'; |
21
|
|
|
|
22
|
|
|
/** {@inheritdoc} */ |
23
|
|
|
public $name = 'descr'; |
24
|
|
|
|
25
|
|
|
/** {@inheritdoc} */ |
26
|
|
|
public $url = '/finance/bill/index'; |
27
|
|
|
|
28
|
|
|
/** {@inheritdoc} */ |
29
|
|
|
public $_return = ['id', 'client', 'sum', 'currency', 'descr', 'label', 'time']; |
30
|
|
|
|
31
|
|
|
/** {@inheritdoc} */ |
32
|
|
|
public $_rename = ['text' => 'label']; |
33
|
|
|
|
34
|
|
|
/** {@inheritdoc} */ |
35
|
|
|
public $_primaryFilter = 'descr'; |
36
|
|
|
|
37
|
|
|
/** {@inheritdoc} */ |
38
|
|
View Code Duplication |
public function getPluginOptions($options = []) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
return parent::getPluginOptions([ |
41
|
|
|
'select2Options' => [ |
42
|
|
|
'templateResult' => new JsExpression("function (data) { |
43
|
|
|
if (data.loading) { |
44
|
|
|
return data.text; |
45
|
|
|
} |
46
|
|
|
var client = '<b>' + data.client + ': ' |
47
|
|
|
color = data.sum < 0 ? 'text-danger' : 'text-success'; |
48
|
|
|
sum = ' <span class=\"' + color +'\">' + data.sum + '</span> ' |
49
|
|
|
currency = ' ' + data.currency.toUpperCase() + '</b><br>' |
50
|
|
|
descr = (data.descr ? data.descr : data.label); |
51
|
|
|
|
52
|
|
|
return client + sum + currency + (descr ? descr : '<span class=\"text-muted\">--</span>'); |
53
|
|
|
}"), |
54
|
|
|
'escapeMarkup' => new JsExpression('function (markup) { |
55
|
|
|
return markup; // Allows HTML |
56
|
|
|
}'), |
57
|
|
|
], |
58
|
|
|
]); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** {@inheritdoc} */ |
62
|
|
|
public function getFilter() |
63
|
|
|
{ |
64
|
|
|
return ArrayHelper::merge(parent::getFilter(), [ |
65
|
|
|
'ftype' => ['format' => 'other,hw_purchase'], |
66
|
|
|
'limit' => ['format' => '50'], |
67
|
|
|
]); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.