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\modules\client\grid\ClientColumn; |
14
|
|
|
use hipanel\modules\finance\models\FakeGroupingSale; |
15
|
|
|
use hipanel\modules\finance\models\FakeSale; |
16
|
|
|
use hipanel\modules\finance\models\Sale; |
17
|
|
|
use hipanel\modules\finance\widgets\LinkToObjectResolver; |
18
|
|
|
use Yii; |
19
|
|
|
use yii\helpers\Html; |
20
|
|
|
|
21
|
|
|
class SaleGridView extends \hipanel\grid\BoxedGridView |
22
|
|
|
{ |
23
|
|
|
public function columns() |
24
|
|
|
{ |
25
|
|
|
return array_merge(parent::columns(), [ |
26
|
|
|
'tariff' => [ |
27
|
|
|
'format' => 'html', |
28
|
|
|
'filterAttribute' => 'tariff_like', |
29
|
|
|
'value' => function ($model) { |
30
|
|
|
return Html::a($model->tariff, ['@plan/view', 'id' => $model->tariff_id]); |
31
|
|
|
}, |
32
|
|
|
], |
33
|
|
|
'time' => [ |
34
|
|
|
'format' => ['datetime'], |
35
|
|
|
'filter' => false, |
36
|
|
|
'contentOptions' => ['class' => 'text-nowrap'], |
37
|
|
|
], |
38
|
|
|
'seller' => [ |
39
|
|
|
'class' => ClientColumn::class, |
40
|
|
|
'idAttribute' => 'seller_id', |
41
|
|
|
'attribute' => 'seller_id', |
42
|
|
|
'nameAttribute' => 'seller', |
43
|
|
|
], |
44
|
|
|
'buyer' => [ |
45
|
|
|
'class' => ClientColumn::class, |
46
|
|
|
'idAttribute' => 'buyer_id', |
47
|
|
|
'attribute' => 'buyer_id', |
48
|
|
|
'nameAttribute' => 'buyer', |
49
|
|
|
], |
50
|
|
|
'object_v' => [ |
51
|
|
|
'label' => Yii::t('hipanel:finance:sale', 'Object'), |
52
|
|
|
'format' => 'html', |
53
|
|
|
'value' => function ($model) { |
54
|
|
|
$html = Html::beginTag('div', ['class' => 'sale-flex-cnt']); |
55
|
|
|
$html .= LinkToObjectResolver::widget([ |
56
|
|
|
'model' => $model, |
57
|
|
|
'typeAttribute' => 'tariff_type', |
58
|
|
|
'idAttribute' => 'object_id', |
59
|
|
|
]); |
60
|
|
|
$html .= Html::endTag('div'); |
61
|
|
|
|
62
|
|
|
return $html; |
63
|
|
|
}, |
64
|
|
|
], |
65
|
|
|
'object' => [ |
66
|
|
|
'format' => 'raw', |
67
|
|
|
'filterAttribute' => 'object_inilike', |
68
|
|
|
'value' => function (Sale $model) { |
69
|
|
|
if ($model instanceof FakeSale) { |
70
|
|
|
return $model->object; |
71
|
|
|
} |
72
|
|
|
$user = Yii::$app->user; |
73
|
|
|
$html = Html::beginTag('div', ['class' => 'sale-flex-cnt']); |
74
|
|
|
$html .= LinkToObjectResolver::widget([ |
75
|
|
|
'model' => $model, |
76
|
|
|
'typeAttribute' => 'tariff_type', |
77
|
|
|
'idAttribute' => 'object_id', |
78
|
|
|
]); |
79
|
|
|
$html .= Html::beginTag('div', ['class' => 'btn-group']); |
80
|
|
|
$html .= Html::a(Yii::t('hipanel:finance:sale', 'View'), ['@sale/view', 'id' => $model->id], ['class' => 'btn btn-xs btn-primary']); |
81
|
|
|
if ($user->can('sale.update')) { |
82
|
|
|
$html .= Html::a(Yii::t('hipanel:finance:sale', 'Edit'), ['@sale/update', 'id' => $model->id], ['class' => 'btn btn-xs btn-success']); |
83
|
|
|
} |
84
|
|
|
$html .= Html::endTag('div'); |
85
|
|
|
$html .= Html::endTag('div'); |
86
|
|
|
|
87
|
|
|
return $html; |
88
|
|
|
}, |
89
|
|
|
], |
90
|
|
|
'object_link' => [ |
91
|
|
|
'attribute' => 'object', |
92
|
|
|
'format' => 'raw', |
93
|
|
|
'filterAttribute' => 'object_like', |
94
|
|
|
'enableSorting' => false, |
95
|
|
View Code Duplication |
'value' => function (Sale $model) { |
|
|
|
|
96
|
|
|
if ($model instanceof FakeGroupingSale) { |
97
|
|
|
return $model->object; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
return LinkToObjectResolver::widget([ |
101
|
|
|
'model' => $model, |
102
|
|
|
'typeAttribute' => 'tariff_type', |
103
|
|
|
'idAttribute' => 'object_id', |
104
|
|
|
]); |
105
|
|
|
}, |
106
|
|
|
], |
107
|
|
|
]); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
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.