Completed
Push — master ( 3d2236...299e74 )
by Dmitry
07:21
created

BillHwPurchaseCombo   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 3
dl 0
loc 53
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getPluginOptions() 0 22 1
A getFilter() 0 7 1
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 + ':&nbsp;'
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