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\grid; |
12
|
|
|
|
13
|
|
|
use hipanel\grid\DataColumn; |
14
|
|
|
use hipanel\grid\MainColumn; |
15
|
|
|
use hipanel\grid\RefColumn; |
16
|
|
|
use hipanel\helpers\Url; |
17
|
|
|
use hipanel\modules\client\grid\ClientColumn; |
18
|
|
|
use hipanel\modules\finance\menus\PlanActionsMenu; |
19
|
|
|
use hipanel\modules\finance\models\Plan; |
20
|
|
|
use hipanel\modules\finance\widgets\PlanAttributes; |
21
|
|
|
use hiqdev\yii2\menus\grid\MenuColumn; |
22
|
|
|
use Yii; |
23
|
|
|
use yii\helpers\Html; |
24
|
|
|
|
25
|
|
|
class PlanGridView extends \hipanel\grid\BoxedGridView |
26
|
|
|
{ |
27
|
|
|
public function columns(): array |
28
|
|
|
{ |
29
|
|
|
return array_merge(parent::columns(), [ |
30
|
|
|
'client' => [ |
31
|
|
|
'class' => ClientColumn::class, |
32
|
|
|
], |
33
|
|
|
'name' => [ |
34
|
|
|
'attribute' => 'name', |
35
|
|
|
'filterAttribute' => 'name_ilike', |
36
|
|
|
'filterOptions' => ['class' => 'narrow-filter'], |
37
|
|
|
'class' => MainColumn::class, |
38
|
|
|
'note' => 'note', |
39
|
|
|
'noteOptions' => [ |
40
|
|
|
'url' => Url::to(['@plan/set-note']), |
41
|
|
|
], |
42
|
|
|
'badges' => function (Plan $model): string { |
43
|
|
|
return $this->prepareBadges($model); |
44
|
|
|
}, |
45
|
|
|
], |
46
|
|
|
'simple_name' => [ |
47
|
|
|
'attribute' => 'name', |
48
|
|
|
'format' => 'html', |
49
|
|
|
'value' => function (Plan $model): string { |
50
|
|
|
return sprintf('%s %s', $model->name, $this->prepareBadges($model)); |
51
|
|
|
}, |
52
|
|
|
], |
53
|
|
|
'state' => [ |
54
|
|
|
'attribute' => 'state', |
55
|
|
|
'class' => RefColumn::class, |
56
|
|
|
'filterAttribute' => 'state', |
57
|
|
|
'filterOptions' => ['class' => 'narrow-filter'], |
58
|
|
|
'format' => 'html', |
59
|
|
|
'gtype' => 'state,tariff', |
60
|
|
|
], |
61
|
|
|
'type' => [ |
62
|
|
|
'attribute' => 'type', |
63
|
|
|
'class' => RefColumn::class, |
64
|
|
|
'filterAttribute' => 'type_in', |
65
|
|
|
'filterOptions' => ['class' => 'narrow-filter'], |
66
|
|
|
'format' => 'html', |
67
|
|
|
'gtype' => 'type,tariff', |
68
|
|
|
], |
69
|
|
|
'actions' => [ |
70
|
|
|
'class' => MenuColumn::class, |
71
|
|
|
'menuClass' => PlanActionsMenu::class, |
72
|
|
|
], |
73
|
|
|
'monthly' => [ |
74
|
|
|
'attribute' => 'monthly', |
75
|
|
|
'contentOptions' => ['id' => 'plan-monthly-value'], |
76
|
|
|
], |
77
|
|
|
'custom_attributes' => [ |
78
|
|
|
'class' => DataColumn::class, |
79
|
|
|
'label' => Yii::t('hipanel:finance', 'Attributes'), |
80
|
|
|
'format' => 'raw', |
81
|
|
|
'contentOptions' => ['style' => 'padding: 0;'], |
82
|
|
|
'value' => static fn(Plan $plan): string => PlanAttributes::widget(['plan' => $plan]), |
|
|
|
|
83
|
|
|
] |
84
|
|
|
]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param Plan $model |
89
|
|
|
* @return string |
90
|
|
|
*/ |
91
|
|
|
protected function prepareBadges(Plan $model): string |
92
|
|
|
{ |
93
|
|
|
$html = ''; |
94
|
|
|
if ($model->your_tariff) { |
95
|
|
|
$html .= Html::tag('span', Html::tag('i', null, ['class' => 'fa fa-lock']), ['class' => 'label bg-red pull-right', 'style' => 'margin-left: .1em;']); |
96
|
|
|
} |
97
|
|
|
if ($model->is_grouping) { |
98
|
|
|
$localization = Yii::t('hipanel.finance.plan', 'Grouping'); |
99
|
|
|
$html .= Html::tag('span', $localization, ['class' => 'label bg-olive pull-right']); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
return $html; |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|