1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use hipanel\modules\finance\models\Plan; |
4
|
|
|
use hipanel\modules\finance\models\Price; |
5
|
|
|
use hipanel\modules\finance\models\RatePrice; |
6
|
|
|
use hipanel\modules\finance\widgets\BillType; |
7
|
|
|
use hipanel\modules\finance\widgets\FormulaInput; |
8
|
|
|
use hipanel\modules\finance\widgets\LinkToObjectResolver; |
9
|
|
|
use hipanel\widgets\AmountWithCurrency; |
10
|
|
|
use hipanel\widgets\XEditable; |
11
|
|
|
use yii\bootstrap\Html; |
12
|
|
|
use yii\web\JsExpression; |
13
|
|
|
use yii\widgets\ActiveForm; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var Plan|null $plan |
17
|
|
|
* @var Price $model |
18
|
|
|
* @var ActiveForm $form |
19
|
|
|
*/ |
20
|
|
|
?> |
21
|
|
|
|
22
|
|
|
<div class="form-instance"> |
23
|
|
|
<div class="col-md-2" style="white-space: normal"> |
24
|
|
|
<?= Html::activeHiddenInput($model, "[$i]object_id", ['ref' => 'object_id']) ?> |
25
|
|
|
<?= Html::activeHiddenInput($model, "[$i]plan_id") ?> |
26
|
|
|
<?= Html::activeHiddenInput($model, "[$i]type") ?> |
27
|
|
|
<?= Html::activeHiddenInput($model, "[$i]class") ?> |
28
|
|
|
<?= Html::activeHiddenInput($model, "[$i]object", ['value' => $model->object->name]) ?> |
29
|
|
|
<?= Html::activeHiddenInput($model, "[$i]quantity") ?> |
30
|
|
|
<?= Html::activeHiddenInput($model, "[$i]unit") ?> |
31
|
|
|
<?= Html::activeHiddenInput($model, "[$i]note", ['data-attribute' => 'note']) ?> |
32
|
|
|
|
33
|
|
|
<div class="form-group"> |
34
|
|
|
<?php if ($model->object->name === null): ?> |
35
|
|
|
<i><?= Yii::t('hipanel.finance.price', 'Any object') ?></i> |
36
|
|
|
<?php else: ?> |
37
|
|
|
<strong> |
38
|
|
|
<?= LinkToObjectResolver::widget([ |
39
|
|
|
'model' => $model->object, |
40
|
|
|
'labelAttribute' => 'name', |
41
|
|
|
'linkOptions' => [ |
42
|
|
|
'tabindex' => '-1', |
43
|
|
|
], |
44
|
|
|
]) ?> |
45
|
|
|
</strong> |
46
|
|
|
<?php endif ?> |
47
|
|
|
<?php if (!empty($model->object->label)) : ?> |
48
|
|
|
<br/><?= Html::encode($model->object->label) ?> |
49
|
|
|
<?php endif; ?> |
50
|
|
|
<br/> |
51
|
|
|
<?= BillType::widget([ |
52
|
|
|
'model' => $model, |
53
|
|
|
'field' => 'type', |
54
|
|
|
]) ?> |
55
|
|
|
<br/> |
56
|
|
|
<?= XEditable::widget([ |
57
|
|
|
'model' => $model, |
58
|
|
|
'attribute' => 'note', |
59
|
|
|
'pluginOptions' => [ |
60
|
|
|
'url' => new JsExpression(<<<'JS' |
61
|
|
|
function(params) { |
62
|
|
|
$(this).closest('.form-instance').find('input[data-attribute=note]').val(params.value); |
63
|
|
|
return $.Deferred().resolve(); |
64
|
|
|
} |
65
|
|
|
JS |
66
|
|
|
), |
67
|
|
|
], |
68
|
|
|
]) ?> |
69
|
|
|
</div> |
70
|
|
|
</div> |
71
|
|
|
<div class="col-md-1"> |
72
|
|
|
<?php if ($model->isOveruse()): ?> |
73
|
|
|
<?= $form->field($model, "[$i]quantity")->textInput() ?> |
74
|
|
|
<?php endif ?> |
75
|
|
|
</div> |
76
|
|
|
<div class="col-md-1"> |
77
|
|
View Code Duplication |
<?php if ($model->unitOptions !== []): ?> |
|
|
|
|
78
|
|
|
<?= $form->field($model, "[$i]unit")->dropDownList($model->unitOptions) ?> |
79
|
|
|
<?php endif ?> |
80
|
|
|
</div> |
81
|
|
|
<div class="col-md-2"> |
82
|
|
|
<?php if ($model instanceof RatePrice) : ?> |
83
|
|
|
<?= $form->field($model, "[$i]rate")->input('number') ?> |
84
|
|
|
<?= Html::activeHiddenInput($model, "[$i]price", ['value' => 0]) ?> |
85
|
|
|
<?= Html::activeHiddenInput($model, "[$i]currency", ['value' => $model->plan->currency]) ?> |
86
|
|
|
<?= Html::activeHiddenInput($model, "[$i]unit", ['value' => $model->plan->currency]) ?> |
87
|
|
|
<?php else : ?> |
88
|
|
|
<div class="<?= AmountWithCurrency::$widgetClass ?>"> |
89
|
|
|
<?= $form->field($model, "[$i]price")->widget(AmountWithCurrency::class, [ |
90
|
|
|
'currencyAttributeName' => 'currency', |
91
|
|
|
'currencyAttributeOptions' => [ |
92
|
|
|
'items' => $this->context->getCurrencyTypes(), |
93
|
|
|
], |
94
|
|
|
]) ?> |
95
|
|
|
<?= $form->field($model, "[$i]currency", ['template' => '{input}{error}'])->hiddenInput([ |
96
|
|
|
'ref' => 'currency', |
97
|
|
|
]) ?> |
98
|
|
|
</div> |
99
|
|
|
<div class="price-estimates"></div> |
100
|
|
|
<?php endif; ?> |
101
|
|
|
</div> |
102
|
|
|
<div class="col-md-5"> |
103
|
|
|
<?php if (!($model instanceof RatePrice)) : ?> |
104
|
|
|
<?= $form->field($model, "[$i]formula")->widget(FormulaInput::class) ?> |
105
|
|
|
<?php endif; ?> |
106
|
|
|
</div> |
107
|
|
|
<div class="col-md-1" style="padding-top: 25px;"> |
108
|
|
|
<label> </label> |
109
|
|
|
<button type="button" class="remove-item btn bg-maroon btn-sm btn-flat" tabindex="-1"> |
110
|
|
|
<i class="glyphicon glyphicon-minus"></i> |
111
|
|
|
</button> |
112
|
|
|
</div> |
113
|
|
|
<?php if ($model->isServer95Traf()) : ?> |
114
|
|
|
<div class="col-md-12 col-md-offset-2" style="margin-top: -1em"> |
115
|
|
|
<?= $form->field($model, "[$i]count_aggregated_traffic")->checkbox()->hint(Yii::t('hipanel.finance.price', '(reasonable for grouping tariffs only)')) ?> |
116
|
|
|
</div> |
117
|
|
|
<?php endif ?> |
118
|
|
|
</div> |
119
|
|
|
|
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.