1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @var \yii\web\View |
5
|
|
|
* @var $model \hipanel\modules\finance\forms\DomainTariffForm |
6
|
|
|
*/ |
7
|
|
|
use hipanel\modules\finance\models\Tariff; |
8
|
|
|
use hipanel\widgets\Box; |
9
|
|
|
use hipanel\widgets\Pjax; |
10
|
|
|
use yii\bootstrap\ActiveForm; |
11
|
|
|
use yii\helpers\Html; |
12
|
|
|
use yii\helpers\Url; |
13
|
|
|
|
14
|
|
|
?> |
15
|
|
|
<?php Pjax::begin(['id' => 'tariff-pjax-container']) ?> |
16
|
|
|
|
17
|
|
|
<?php $form = ActiveForm::begin(array_filter([ |
18
|
|
|
'id' => 'tariff-create-form', |
19
|
|
|
'action' => isset($action) ? $action : null, |
20
|
|
|
])) ?> |
21
|
|
|
|
22
|
|
|
<?php Box::begin() ?> |
23
|
|
|
<div class="row"> |
24
|
|
|
<div class="col-md-12"> |
25
|
|
|
<?= Html::activeHiddenInput($model, 'id') ?> |
26
|
|
|
<?= $form->field($model, 'parent_id')->widget(\hipanel\modules\finance\widgets\TariffCombo::class, [ |
27
|
|
|
'tariffType' => Tariff::TYPE_DOMAIN, |
28
|
|
|
'inputOptions' => [ |
29
|
|
|
'id' => 'tariff-parent_id', |
30
|
|
|
'data-url' => Url::current(['parent_id' => null]), |
31
|
|
|
'readonly' => isset($model->id), |
32
|
|
|
], |
33
|
|
|
]); ?> |
34
|
|
|
<?= $form->field($model, 'name') ?> |
35
|
|
|
</div> |
36
|
|
|
</div> |
37
|
|
|
<?php Box::end() ?> |
38
|
|
|
|
39
|
|
|
<?php if (isset($model->parentTariff)): ?> |
40
|
|
|
<?php Box::begin() ?> |
41
|
|
|
<div class="row"> |
42
|
|
|
<div class="col-md-12"> |
43
|
|
|
<table class="table table-condensed"> |
44
|
|
|
<thead> |
45
|
|
|
<tr> |
46
|
|
|
<th></th> |
47
|
|
|
<?php foreach ($model->getResourceTypes() as $type) { |
48
|
|
|
echo Html::tag('th', $type); |
49
|
|
|
} ?> |
50
|
|
|
</tr> |
51
|
|
|
</thead> |
52
|
|
|
<tbody> |
53
|
|
|
<?php $i = 0 ?> |
54
|
|
View Code Duplication |
<?php foreach ($model->getZones() as $zone => $id) : ?> |
|
|
|
|
55
|
|
|
<tr> |
56
|
|
|
<td><?= $zone ?></td> |
57
|
|
|
<?php $baseResources = $model->getZoneParentResources($zone); ?> |
58
|
|
|
<?php foreach ($model->getZoneResources($zone) as $type => $resource) : ?> |
59
|
|
|
<td> |
60
|
|
|
<?= Html::activeHiddenInput($resource, "[$i]object_id") ?> |
61
|
|
|
<?= Html::activeHiddenInput($resource, "[$i]type") ?> |
62
|
|
|
|
63
|
|
|
<?= \hipanel\modules\finance\widgets\ResourcePriceInput::widget([ |
64
|
|
|
'basePrice' => $baseResources[$type]->price, |
65
|
|
|
'activeField' => $form->field($resource, "[$i]price"), |
66
|
|
|
]) ?> |
67
|
|
|
<?php ++$i; ?> |
68
|
|
|
<?php endforeach; ?> |
69
|
|
|
</tr> |
70
|
|
|
<?php endforeach; ?> |
71
|
|
|
</tbody> |
72
|
|
|
</table> |
73
|
|
|
</div> |
74
|
|
|
</div> |
75
|
|
|
<?php Box::end() ?> |
76
|
|
|
|
77
|
|
|
<div class="row"> |
78
|
|
|
<?php $services = $model->getServices(); ?> |
79
|
|
|
<?php $baseServices = $model->getParentServices(); ?> |
80
|
|
|
<?php foreach ($services as $service) : ?> |
81
|
|
|
<div class="col-md-3"> |
82
|
|
|
<?php Box::begin(['title' => $service->name]) ?> |
83
|
|
|
<table class="table table-condensed"> |
84
|
|
|
<thead> |
85
|
|
|
<tr> |
86
|
|
|
<?php foreach ($service->getOperations() as $operation => $title) : ?> |
87
|
|
|
<?= Html::tag('td', $title) ?> |
88
|
|
|
<?php endforeach; ?> |
89
|
|
|
</tr> |
90
|
|
|
<tbody> |
91
|
|
|
<tr> |
92
|
|
|
<?php foreach ($service->getOperations() as $operation => $title) : ?> |
93
|
|
|
<?php $resource = $service->getResource($operation); ?> |
94
|
|
|
<td> |
95
|
|
|
<?= Html::activeHiddenInput($resource, "[$i]object_id") ?> |
96
|
|
|
<?= Html::activeHiddenInput($resource, "[$i]type") ?> |
97
|
|
|
<?= \hipanel\modules\finance\widgets\ResourcePriceInput::widget([ |
98
|
|
|
'basePrice' => $baseServices[$service->type]->getResource($operation)->price, |
99
|
|
|
'activeField' => $form->field($resource, "[$i]price"), |
100
|
|
|
]) ?> |
101
|
|
|
</td> |
102
|
|
|
<?php ++$i; ?> |
103
|
|
|
<?php endforeach ?> |
104
|
|
|
</tr> |
105
|
|
|
</tbody> |
106
|
|
|
</thead></table> |
107
|
|
|
<?php Box::end(); ?> |
108
|
|
|
</div> |
109
|
|
|
<?php endforeach; ?> |
110
|
|
|
</div> |
111
|
|
|
<?php endif ?> |
112
|
|
|
|
113
|
|
|
|
114
|
|
|
<?php Box::begin(['options' => ['class' => 'box-solid']]) ?> |
115
|
|
|
<div class="row"> |
116
|
|
|
<div class="col-md-12 no"> |
117
|
|
|
<?= Html::submitButton(Yii::t('hipanel', 'Save'), ['class' => 'btn btn-success']) ?> |
118
|
|
|
<?= Html::button(Yii::t('hipanel', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?> |
119
|
|
|
</div> |
120
|
|
|
</div> |
121
|
|
|
<?php Box::end() ?> |
122
|
|
|
<?php ActiveForm::end(); ?> |
123
|
|
|
|
124
|
|
|
<?php |
125
|
|
|
$this->registerJs(<<<'JS' |
126
|
|
|
$('#tariff-parent_id').on('change', function () { |
127
|
|
|
var fakeInput = $('<input>').attr({'name': 'parent_id', 'value': $(this).val()}); |
128
|
|
|
var formAction = $(this).closest('select').attr('data-url'); |
129
|
|
|
var fakeForm = $('<form>').attr({'method': 'get', 'action': formAction}).html(fakeInput).on('submit', function(event) { |
130
|
|
|
$.pjax.submit(event, '#tariff-pjax-container'); |
131
|
|
|
event.preventDefault(); |
132
|
|
|
}).trigger('submit'); |
133
|
|
|
}); |
134
|
|
|
JS |
135
|
|
|
); ?> |
136
|
|
|
|
137
|
|
|
<?php Pjax::end(); ?> |
138
|
|
|
|
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.