BillHwPurchaseCombo::getPluginOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 22

Duplication

Lines 22
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 22
loc 22
ccs 0
cts 21
cp 0
rs 9.568
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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 + ':&nbsp;'
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