1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @var \yii\web\View $this |
5
|
|
|
* @var \hipanel\modules\finance\models\CertificatePrice[] $prices |
6
|
|
|
* @var \hipanel\modules\finance\models\CertificatePrice $price |
7
|
|
|
* @var \hipanel\modules\finance\models\CertificatePrice[][] $parentPrices |
8
|
|
|
* @var \hipanel\modules\finance\models\Plan $plan |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
use hipanel\modules\finance\models\CertificatePrice; |
12
|
|
|
use hipanel\widgets\Box; |
13
|
|
|
use yii\bootstrap\ActiveForm; |
14
|
|
|
use yii\helpers\Html; |
15
|
|
|
use hipanel\helpers\Url; |
16
|
|
|
use hipanel\modules\finance\widgets\PriceInput; |
17
|
|
|
|
18
|
|
|
$this->registerJs(" |
19
|
|
|
$('#tariff-create-form').on('afterValidate', function (event, messages) { |
20
|
|
|
if(typeof $('.has-error').first().offset() !== 'undefined') { |
21
|
|
|
$('html, body').animate({ |
22
|
|
|
scrollTop: $('.has-error').first().offset().top |
23
|
|
|
}, 1000); |
24
|
|
|
} |
25
|
|
|
}); |
26
|
|
|
"); |
27
|
|
|
|
28
|
|
|
$this->registerCss(<<<CSS |
29
|
|
|
.text-gray { |
30
|
|
|
color: gray !important; |
31
|
|
|
} |
32
|
|
|
.price-table input::-webkit-outer-spin-button, |
33
|
|
|
.price-table input::-webkit-inner-spin-button { |
34
|
|
|
-webkit-appearance: none; |
35
|
|
|
margin: 0; |
36
|
|
|
} |
37
|
|
|
.price-table input[type=number] { |
38
|
|
|
-moz-appearance: textfield; |
39
|
|
|
} |
40
|
|
|
#main-table input { |
41
|
|
|
padding: 5px 3px !important; |
42
|
|
|
} |
43
|
|
|
#main-table div.col-md-6 { |
44
|
|
|
padding-left: 4px !important; |
45
|
|
|
} |
46
|
|
|
CSS |
47
|
|
|
); |
48
|
|
|
|
49
|
|
|
?> |
50
|
|
|
<?php if (!empty($prices)) : ?> |
51
|
|
|
<div class="tariff-create"> |
52
|
|
|
<?php $form = ActiveForm::begin(array_filter([ |
53
|
|
|
'id' => 'tariff-create-form', |
54
|
|
|
'action' => $action ?? null, |
55
|
|
|
])) ?> |
56
|
|
|
|
57
|
|
|
<?php Box::begin() ?> |
58
|
|
|
<div class="row"> |
59
|
|
|
<div class="col-md-12"> |
60
|
|
|
<table id="main-table" class="table table-condensed price-table"> |
61
|
|
|
<thead> |
62
|
|
|
<tr> |
63
|
|
|
<?= Html::tag('th', Yii::t('hipanel:finance:tariff', 'Name')); ?> |
64
|
|
View Code Duplication |
<?php foreach (CertificatePrice::getTypes() as $name) : ?> |
|
|
|
|
65
|
|
|
<?php foreach (CertificatePrice::getPeriods() as $period) : ?> |
66
|
|
|
<?= Html::tag('th', Yii::t('hipanel:finance:tariff', '{operation} for {duration}', [ |
67
|
|
|
'operation' => $name, |
68
|
|
|
'duration' => $period, |
69
|
|
|
])); ?> |
70
|
|
|
<?php endforeach; ?> |
71
|
|
|
<?php endforeach; ?> |
72
|
|
|
</tr> |
73
|
|
|
</thead> |
74
|
|
|
<tbody> |
75
|
|
|
<?php |
76
|
|
|
$i = 0; |
77
|
|
|
foreach ($prices as $object_id => $group) { |
78
|
|
|
?> |
79
|
|
|
<tr> |
80
|
|
|
<td><?= current($group)->object->label ?></td> |
81
|
|
|
<?php foreach (CertificatePrice::getTypes() as $type => $name) : ?> |
82
|
|
|
<?php $price = $group[$type]; ?> |
83
|
|
|
<?php if ($price === null): ?> |
84
|
|
|
<?= str_repeat('<td></td>', count(CertificatePrice::getPeriods())) ?> |
85
|
|
|
<?php continue; endif ?> |
86
|
|
|
<?php $price->plan_id = $plan_id ?? $price->plan_id; ?> |
87
|
|
|
<?= Html::activeHiddenInput($price, "[$i]id") ?> |
88
|
|
|
<?= Html::activeHiddenInput($price, "[$i]plan_id") ?> |
89
|
|
|
<?= Html::activeHiddenInput($price, "[$i]object_id") ?> |
90
|
|
|
<?= Html::activeHiddenInput($price, "[$i]currency") ?> |
91
|
|
|
<?= Html::activeHiddenInput($price, "[$i]price") ?> |
92
|
|
|
<?= Html::activeHiddenInput($price, "[$i]type") ?> |
93
|
|
|
<?= Html::activeHiddenInput($price, "[$i]unit") ?> |
94
|
|
|
<?php $originalPrice = $parentPrices[$object_id][$type] ?? null; ?> |
95
|
|
|
<?php foreach (CertificatePrice::getPeriods() as $period => $periodLabel) : ?> |
96
|
|
|
<td> |
97
|
|
|
<?= PriceInput::widget([ |
98
|
|
|
'basePrice' => $price->getMoneyForPeriod($period), |
99
|
|
|
'originalPrice' => ($originalPrice ?? $price)->getMoneyForPeriod($period), |
100
|
|
|
'activeField' => $form->field($price, "[$i]sums[$period]")]) ?> |
101
|
|
|
</td> |
102
|
|
|
<?php endforeach; ?> |
103
|
|
|
<?php ++$i; ?> |
104
|
|
|
<?php endforeach; ?> |
105
|
|
|
</tr> |
106
|
|
|
<?php |
107
|
|
|
} ?> |
108
|
|
|
</tbody> |
109
|
|
|
</table> |
110
|
|
|
</div> |
111
|
|
|
</div> |
112
|
|
|
|
113
|
|
|
<?php Box::end() ?> |
114
|
|
|
|
115
|
|
|
<?php Box::begin(['options' => ['class' => 'box-solid']]) ?> |
116
|
|
|
<div class="row"> |
117
|
|
|
<div class="col-md-12 no"> |
118
|
|
|
<?= Html::submitButton(Yii::t('hipanel', 'Save'), ['class' => 'btn btn-success']) ?> |
119
|
|
|
<?= Html::button(Yii::t('hipanel', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?> |
120
|
|
|
</div> |
121
|
|
|
</div> |
122
|
|
|
<?php Box::end() ?> |
123
|
|
|
<?php ActiveForm::end(); ?> |
124
|
|
|
</div> |
125
|
|
View Code Duplication |
<?php else: ?> |
|
|
|
|
126
|
|
|
<?php $box = Box::begin([ |
127
|
|
|
'title' => Yii::t('hipanel.finance.price', 'No price suggestions for this object'), |
128
|
|
|
]) ?> |
129
|
|
|
<?= Yii::t('hipanel.finance.price', 'We could not suggest any new prices of type "{suggestionType}" for the selected object. Probably, they were already created earlier or this suggestion type is not compatible with this object type', [ |
130
|
|
|
'suggestionType' => Yii::t('hipanel.finance.suggestionTypes', 'certificate'), |
131
|
|
|
]) ?> |
132
|
|
|
|
133
|
|
|
<br/> |
134
|
|
|
|
135
|
|
|
<?= Yii::t('hipanel.finance.price', 'You can return back to plan {backToPlan}', [ |
136
|
|
|
'backToPlan' => Html::a($plan->name, Url::to(['@plan/view', 'id' => $plan->id])), |
137
|
|
|
]) ?> |
138
|
|
|
<?= $box->endBody(); ?> |
139
|
|
|
<?php endif ?> |
140
|
|
|
|
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.