forked from hiqdev/hipanel-module-stock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoveByOne.php
148 lines (139 loc) · 6.3 KB
/
moveByOne.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
<?php
use hipanel\helpers\Url;
use hipanel\modules\stock\widgets\combo\DestinationCombo;
use hipanel\modules\stock\widgets\combo\RmaDestinationCombo;
use hipanel\modules\stock\widgets\combo\PartnoCombo;
use hipanel\modules\stock\widgets\combo\SourceCombo;
use hipanel\modules\stock\widgets\MoveTypeDropDownList;
use hipanel\widgets\Box;
use hipanel\widgets\DynamicFormWidget;
use yii\bootstrap\ActiveForm;
use yii\helpers\Html;
use yii\helpers\StringHelper;
/**
* @var \yii\web\View $this
* @var \hipanel\modules\stock\models\Part[] $models
* @var array $remotehands
* @var array $types
*/
$scenario = $this->context->action->scenario;
$this->title = StringHelper::startsWith($this->context->action->id, 'move-by-one') ? Yii::t('hipanel:stock', 'Move by one') : Yii::t('hipanel:stock', 'RMA');
$this->params['breadcrumbs'][] = ['label' => Yii::t('hipanel:stock', 'Parts'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $form = ActiveForm::begin([
'id' => 'dynamic-form',
'enableClientValidation' => true,
'validateOnBlur' => true,
'enableAjaxValidation' => true,
'validationUrl' => Url::toRoute(['validate-form', 'scenario' => reset($models)->isNewRecord ? 'create' : 'update']),
]) ?>
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 99, // the maximum times, an element can be cloned (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => reset($models),
'formId' => 'dynamic-form',
'formFields' => [
'id',
'move_type',
'src_id',
'dst_id',
'descr',
'remotehands',
'remote_ticket',
'hm_ticket',
],
]) ?>
<div class="container-items">
<?php foreach ($models as $i => $model) : ?>
<?php
// necessary for update action.
$model->scenario = $scenario;
if ($scenario === 'update' || $scenario === 'move') {
echo Html::activeHiddenInput($model, "[$i]id");
}
?>
<div class="item">
<?php Box::begin() ?>
<div class="row">
<div class="col-md-12">
<?php if ($scenario === 'bulk-move') : ?>
<?php if (is_array($model->parts) || $model->parts instanceof Traversable) : ?>
<?php foreach ($model->parts as $part_id => $part) : ?>
<?php $ids[] = $part_id; ?>
<div><?= $part['partno'] ?> : <?= $part['serial'] ?></div>
<?php endforeach; ?>
<?= Html::activeHiddenInput($model, "[$i]id", ['value' => $ids]); ?>
<?php endif; ?>
<?php else : ?>
<?= Html::activeHiddenInput($model, "[$i]id", ['value' => $model->id]); ?>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, "[$i]partno")->widget(PartnoCombo::class, [
'inputOptions' => [
'readonly' => true,
'unselect' => $model->partno,
],
]) ?>
</div>
<div class="col-md-6">
<?= $form->field($model, "[$i]serial")->textInput(['readonly' => true]) ?>
</div>
</div>
<?php endif; ?>
<div class="row">
<div class="col-md-6">
<?php $model->src_id = $model->dst_id ?>
<?= $form->field($model, "[$i]src_id")->widget(SourceCombo::class, [
'inputOptions' => [
'readonly' => true,
'unselect' => $model->src_id,
],
]) ?>
</div>
<div class="col-md-6">
<?php $model->dst_id = null ?>
<?php if (str_contains($this->context->action->id, 'rma')) : ?>
<?= $form->field($model, "[$i]dst_id")->widget(RmaDestinationCombo::class) ?>
<?php else : ?>
<?= $form->field($model, "[$i]dst_id")->widget(DestinationCombo::class) ?>
<?php endif ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, "[$i]move_type")->widget(MoveTypeDropDownList::class, ['items' => $types]) ?>
</div>
<div class="col-md-6">
<?= $form->field($model, "[$i]remotehands")->dropDownList($remotehands) ?>
</div>
</div>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, "[$i]remote_ticket")->textInput() ?>
</div>
<div class="col-md-6">
<?= $form->field($model, "[$i]hm_ticket")->textInput() ?>
</div>
</div>
<?= $form->field($model, "[$i]descr")->textarea()->label(Yii::t('hipanel:stock', 'Move description')) ?>
</div>
</div>
<?php Box::end() ?>
</div>
<?php endforeach; ?>
</div>
<?php DynamicFormWidget::end() ?>
<div class="row">
<div class="col-md-12 no">
<?= Html::submitButton(Yii::t('hipanel', 'Save'), ['class' => 'btn btn-success']) ?>
<?= Html::button(Yii::t('hipanel', 'Cancel'), ['class' => 'btn btn-default', 'onclick' => 'history.go(-1)']) ?>
</div>
</div>
<?php ActiveForm::end() ?>