1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use hipanel\modules\finance\models\Plan; |
4
|
|
|
use hipanel\modules\finance\models\TemplatePrice; |
5
|
|
|
use hipanel\modules\finance\widgets\BillType; |
6
|
|
|
use hipanel\modules\finance\widgets\LinkToObjectResolver; |
7
|
|
|
use hipanel\widgets\AmountWithCurrency; |
8
|
|
|
use Money\Currency; |
9
|
|
|
use Money\Formatter\DecimalMoneyFormatter; |
10
|
|
|
use Money\Money; |
11
|
|
|
use yii\bootstrap\Html; |
12
|
|
|
use yii\helpers\StringHelper; |
13
|
|
|
use yii\widgets\ActiveForm; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @var Plan|null $plan |
17
|
|
|
* @var TemplatePrice $model |
18
|
|
|
* @var ActiveForm $form |
19
|
|
|
* @var int $i |
20
|
|
|
*/ |
21
|
|
|
?> |
22
|
|
|
|
23
|
|
|
<div class="form-instance"> |
24
|
|
|
<div class="col-md-2" style="white-space: normal"> |
25
|
|
|
<?= Html::activeHiddenInput($model, "[$i]object_id", ['ref' => 'object_id']) ?> |
26
|
|
|
<?= Html::activeHiddenInput($model, "[$i]unit") ?> |
27
|
|
|
<?= Html::activeHiddenInput($model, "[$i]quantity") ?> |
28
|
|
|
<?= Html::activeHiddenInput($model, "[$i]type") ?> |
29
|
|
|
<?= Html::activeHiddenInput($model, "[$i]currency") ?> |
30
|
|
|
<?= Html::activeHiddenInput($model, "[$i]class") ?> |
31
|
|
|
<?= Html::activeHiddenInput($model, "[$i]object") ?> |
32
|
|
|
<strong> |
33
|
|
|
<?= LinkToObjectResolver::widget([ |
34
|
|
|
'model' => $model->object, |
35
|
|
|
'labelAttribute' => 'name', |
36
|
|
|
]) ?> |
37
|
|
|
</strong> |
38
|
|
|
<br /> |
39
|
|
|
<?= BillType::widget([ |
40
|
|
|
'model' => $model, |
41
|
|
|
'field' => 'type', |
42
|
|
|
])?> |
43
|
|
|
</div> |
44
|
|
|
<div class="col-md-1"> |
45
|
|
|
<?php if ($model->isOveruse()): ?> |
46
|
|
|
<?= $form->field($model, "[$i]quantity")->textInput() ?> |
47
|
|
|
<?php endif ?> |
48
|
|
|
</div> |
49
|
|
|
<div class="col-md-1"> |
50
|
|
View Code Duplication |
<?php if ($model->unitOptions !== []): ?> |
|
|
|
|
51
|
|
|
<?= $form->field($model, "[$i]unit")->dropDownList($model->unitOptions) ?> |
52
|
|
|
<?php endif ?> |
53
|
|
|
</div> |
54
|
|
|
<div class="col-md-4"> |
55
|
|
|
<div class="col-md-4"> |
56
|
|
|
<?php if (StringHelper::startsWith($model->type, Plan::TYPE_REFERRAL)) : ?> |
57
|
|
|
<?= $form->field($model, "[$i]rate")->input('number', ['min' => 0]) ?> |
58
|
|
|
<?= Html::activeHiddenInput($model, "[$i]price") ?> |
59
|
|
|
<?= Html::activeHiddenInput($model, "[$i]currency") ?> |
60
|
|
|
<?php else : ?> |
61
|
|
|
<div class="<?= AmountWithCurrency::$widgetClass ?>"> |
62
|
|
|
<?= $form->field($model, "[$i]price")->widget(AmountWithCurrency::class, [ |
63
|
|
|
'currencyAttributeName' => 'currency', |
64
|
|
|
'currencyAttributeOptions' => [ |
65
|
|
|
'items' => $this->context->getCurrencyTypes(), |
66
|
|
|
], |
67
|
|
|
'currencyDropdownOptions' => [ |
68
|
|
|
'disabled' => true, |
69
|
|
|
'hidden' => true, |
70
|
|
|
], |
71
|
|
|
]) ?> |
72
|
|
|
</div> |
73
|
|
|
<?php endif; ?> |
74
|
|
|
</div> |
75
|
|
|
<?php if ($model->subprices) : ?> |
76
|
|
|
<?php foreach ($model->subprices as $currCode => $subprice): ?> |
77
|
|
|
<div class="col-md-4"> |
78
|
|
|
<div class="<?= AmountWithCurrency::$widgetClass ?>"> |
79
|
|
|
<?= $form->field($model, "[$i]subprices")->widget(AmountWithCurrency::class, [ |
80
|
|
|
'options' => [ |
81
|
|
|
'id' => Html::getInputName($model, "[$i][subprices]$currCode"), |
82
|
|
|
'name' => Html::getInputName($model, "[$i][subprices]$currCode"), |
83
|
|
|
'value' => Yii::$container->get(DecimalMoneyFormatter::class) |
84
|
|
|
->format(new Money($model->subprices[$currCode]['amount'] ?? 0, new Currency($currCode))), |
85
|
|
|
], |
86
|
|
|
'selectedCurrencyCode' => $currCode, |
87
|
|
|
'currencyAttributeName' => 'subprices', |
88
|
|
|
'currencyDropdownOptions' => [ |
89
|
|
|
'disabled' => true, |
90
|
|
|
'hidden' => true, |
91
|
|
|
], |
92
|
|
|
'currencyAttributeOptions' => [ |
93
|
|
|
'items' => $this->context->getCurrencyTypes(), |
94
|
|
|
], |
95
|
|
|
])->label(Yii::t('hipanel.finance.price', 'Price in {currency}', ['currency' => $currCode])) ?> |
96
|
|
|
</div> |
97
|
|
|
</div> |
98
|
|
|
<?php endforeach; ?> |
99
|
|
|
<?php endif; ?> |
100
|
|
|
</div> |
101
|
|
|
<div class="col-md-3"> |
102
|
|
|
<?= $form->field($model, "[$i]note") ?> |
103
|
|
|
</div> |
104
|
|
|
<div class="col-md-1" style="padding-top: 25px;"> |
105
|
|
|
<label> </label> |
106
|
|
|
<button type="button" class="remove-item btn bg-maroon btn-sm btn-flat" tabindex="-1"> |
107
|
|
|
<i class="glyphicon glyphicon-minus"></i> |
108
|
|
|
</button> |
109
|
|
|
</div> |
110
|
|
|
</div> |
111
|
|
|
|
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.