Blame view

views/order/_form.php 20.5 KB
e0906f08   Alexey Boroda   -Fixing existing ...
1
2
  <?php
      
bb962a6d   Alexey Boroda   -Order in process
3
      use artweb\artbox\ecommerce\models\Label;
e0906f08   Alexey Boroda   -Fixing existing ...
4
      use artweb\artbox\ecommerce\models\Order;
30b799f2   Alexey Boroda   -Order in process 2
5
      use artweb\artbox\ecommerce\models\OrderPayment;
2ad65823   Alexey Boroda   -Added date range...
6
      use artweb\artbox\ecommerce\models\OrderProduct;
01185786   Alexey Boroda   -Sms in process
7
      use backend\models\SmsTemplate;
d57c8c00   Alexey Boroda   -Blocking in process
8
      use common\models\User;
7520dc0e   Alexey Boroda   -Grid with input ...
9
      use kartik\grid\GridView;
bb962a6d   Alexey Boroda   -Order in process
10
      use kartik\widgets\DatePicker;
2ad65823   Alexey Boroda   -Added date range...
11
      use kartik\widgets\Select2;
bb962a6d   Alexey Boroda   -Order in process
12
      use kartik\widgets\SwitchInput;
7520dc0e   Alexey Boroda   -Grid with input ...
13
      use yii\data\ActiveDataProvider;
e0906f08   Alexey Boroda   -Fixing existing ...
14
15
      use yii\helpers\Html;
      use yii\bootstrap\ActiveForm;
6f14188b   Alexey Boroda   -Product card fixed
16
17
      use yii\helpers\ArrayHelper;
      use artweb\artbox\ecommerce\models\Delivery;
7520dc0e   Alexey Boroda   -Grid with input ...
18
      use yii\web\View;
2ad65823   Alexey Boroda   -Added date range...
19
      use yii\web\JsExpression;
e0906f08   Alexey Boroda   -Fixing existing ...
20
      
7520dc0e   Alexey Boroda   -Grid with input ...
21
22
23
24
25
26
      /**
       * @var View               $this
       * @var Order              $model
       * @var ActiveForm         $form
       * @var ActiveDataProvider $dataProvider
       */
2ad65823   Alexey Boroda   -Added date range...
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
      
      $js = <<< JS
  $(document).on('submit', '#add-product-form', function(e) {
      e.preventDefault();
      var addFormData = $(this).serializeArray();
      var addFormAction = this.action;
      $.ajax({
          url: addFormAction,
          type: "POST",
          data: addFormData,
          success: function (data) {
               if (data.status === "success") {
                   $.pjax.reload({container:"#order-products-grid"});  //Reload GridView
               }
          },
          error: function () {
          }
      });
  });
  JS;
      
      $this->registerJs($js, View::POS_READY);
bb962a6d   Alexey Boroda   -Order in process
49
50
51
52
53
54
55
56
      
      $js = <<< JS
  $('#order-phone, #order-phone2').mask('+38(000)000-00-00', {
      placeholder: '+38(___)___-__-__'
  });
  JS;
      
      $this->registerJs($js, View::POS_READY);
01185786   Alexey Boroda   -Sms in process
57
58
59
60
      
      $js = <<< JS
  $(document).on('change', '#sms-template-selector', function(event) {
      var text = $('#select2-sms-template-selector-container').attr('title');
db3040d3   Alexey Boroda   -Order module alm...
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
      var val = $('option:contains(' + text + ')').attr('value');
      $('#sms-text-area').val(val);
  });
  
  $(document).on('click', '#send-sms-action', function(event) {
      console.log('click');
      var content = $('#sms-text-area').val()
      var phone = $('input#order-phone').val();    
      $.ajax({
          url: "/admin/ecommerce/order/send-sms",
          method: "POST",
          data: { 
              phone: phone,
              content: content
           },
          success: function(data) {
            console.log(data);
            var newButton = document.createElement('button');
            newButton.classList.add('btn', 'btn-default');
            newButton.innerText = 'Отправлено';
            var current = document.getElementById("send-sms-action");
            var parentDiv = current.parentNode;
            parentDiv.replaceChild(newButton, current);
          }
      });
01185786   Alexey Boroda   -Sms in process
86
87
88
89
  });
  JS;
      
      $this->registerJs($js, View::POS_READY);
e0906f08   Alexey Boroda   -Fixing existing ...
90
91
92
  ?>
  
  <?php $form = ActiveForm::begin(); ?>
6f14188b   Alexey Boroda   -Product card fixed
93
  <div class="container">
eb15a89c   Alexey Boroda   -Dancing with com...
94
      <div class="form-group">
db3040d3   Alexey Boroda   -Order module alm...
95
          <br>
eb15a89c   Alexey Boroda   -Dancing with com...
96
97
          <div class="row">
              <div class="col-sm-6">
bb962a6d   Alexey Boroda   -Order in process
98
                  
eb15a89c   Alexey Boroda   -Dancing with com...
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
                  <?= $form->field($model, 'deadline')
                           ->widget(
                               DatePicker::className(),
                               [
                      
                               ]
                           ) ?>
                  
                  <?php
                      echo $form->field($model, 'pay')
                                ->widget(
                                    SwitchInput::className(),
                                    [
                                        'name'          => 'pay',
                                        'pluginOptions' => [
                                            'onText'  => \Yii::t('app', 'Оплачено'),
                                            'offText' => \Yii::t('app', 'Не оплачено'),
                                        ],
                                    ]
                                ); ?>
                  
                  <?= $form->field($model, 'reason')
                           ->dropDownList(
db3040d3   Alexey Boroda   -Order module alm...
122
                               Order::REASONS,
eb15a89c   Alexey Boroda   -Dancing with com...
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
149
150
151
152
153
154
155
156
157
                               [ 'prompt' => 'Выберите причину' ]
                           ) ?>
                  
                  <?= $form->field($model, 'label')
                           ->dropDownList(
                               ArrayHelper::map(
                                   Label::find()
                                        ->asArray()
                                        ->all(),
                                   'id',
                                   'label'
                               ),
                               [ 'prompt' => 'Выберите метку' ]
                           ); ?>
                  
                  <?= $form->field($model, 'name') ?>
                  
                  <?= $form->field($model, 'phone') ?>
                  
                  <?= $form->field($model, 'phone2') ?>
                  
                  <?= $form->field($model, 'email') ?>
                  
                  <?= $form->field(
                      $model,
                      'numbercard'
                  )
                           ->textInput([ 'readonly' => true ]) ?>
                  
                  <?= $form->field($model, 'comment')
                           ->textarea([ 'rows' => '3' ]) ?>
                  <?= $form->field($model, 'delivery')
                           ->dropDownList(
                               ArrayHelper::map(
                                   Delivery::find()
30b799f2   Alexey Boroda   -Order in process 2
158
                                           ->joinWith('lang')
30b799f2   Alexey Boroda   -Order in process 2
159
160
                                           ->asArray()
                                           ->all(),
eb15a89c   Alexey Boroda   -Dancing with com...
161
162
163
164
165
                                   'id',
                                   'lang.title'
                               ),
                               [ 'prompt' => \Yii::t('app', 'Выберите доставку ...') ]
                           ) ?>
d57c8c00   Alexey Boroda   -Blocking in process
166
167
  
                  <?php
e861ae92   Alexey Boroda   -Add column to pa...
168
                      
d57c8c00   Alexey Boroda   -Blocking in process
169
170
171
172
173
174
175
176
177
178
179
180
181
182
                      if (\Yii::$app->user->identity->isAdmin()) {
                          echo $form->field($model, 'manager_id')
                                    ->dropDownList(
                                        ArrayHelper::map(
                                            User::find()
                                                ->asArray()
                                                ->all(),
                                            'id',
                                            'username'
                                        ),
                                        [ 'prompt' => \Yii::t('app', 'Менеджер') ]
                                    ) ;
                  }
                  ?>
e861ae92   Alexey Boroda   -Add column to pa...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
      
                      <h2><?php echo \Yii::t('app', 'Отправить смс'); ?></h2>
                          <?php
                              echo Select2::widget(
                                  [
                                      'id'            => 'sms-template-selector',
                                      'name'          => 'select-sms-template',
                                      'data'          => ArrayHelper::map(
                                          SmsTemplate::find()
                                                     ->asArray()
                                                     ->all(),
                                          'text',
                                          'title'
                                      ),
                                      'options'       => [ 'placeholder' => \Yii::t('app', 'Выберите шаблон') ],
                                      'pluginOptions' => [
                                          'allowClear' => true,
                                      ],
                                  ]
                              );
eb15a89c   Alexey Boroda   -Dancing with com...
203
              
e861ae92   Alexey Boroda   -Add column to pa...
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
                          ?>
                          <br>
                          <?php
                              echo Html::textarea(
                                  'sms-text',
                                  '',
                                  [
                                      'rows'  => 3,
                                      'id'    => 'sms-text-area',
                                      'class' => 'form-control',
                                  ]
                              );
                          ?>
                          <br>
                          <?php
                              if ($model->isNewRecord) {
                                  echo Html::button(
                                      \Yii::t('app', 'Отправить'),
                                      [
                                          'class' => 'btn btn-warning disabled',
                                      ]
                                  );
                              } else {
                                  echo Html::button(
                                      \Yii::t('app', 'Отправить'),
                                      [
                                          'class' => 'btn btn-warning',
                                          'id'    => 'send-sms-action',
                                      ]
                                  );
                              }
                          ?>
                  
eb15a89c   Alexey Boroda   -Dancing with com...
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
              </div>
              <div class="col-sm-6">
                  
                  <?= $form->field($model, 'declaration') ?>
                  
                  <?= $form->field($model, 'stock') ?>
                  
                  <?= $form->field($model, 'consignment') ?>
                  
                  <?= $form->field($model, 'payment')
                           ->dropDownList(
                               ArrayHelper::map(
                                   OrderPayment::find()
                                               ->joinWith('lang')
                                               ->where([ 'status' => OrderPayment::ACTIVE ])
                                               ->asArray()
                                               ->all(),
                                   'id',
                                   'lang.title'
                               ),
                               [ 'prompt' => 'Способ оплаты ...' ]
                           ); ?>
                  
                  <?= $form->field($model, 'insurance') ?>
                  
                  <?= $form->field($model, 'amount_imposed') ?>
                  
                  <?= $form->field($model, 'shipping_by')
                           ->dropDownList(
                               ArrayHelper::getColumn(Order::SHIPPING_BY, 'label'),
                               [ 'prompt' => 'Оплата доставки ...' ]
                           ); ?>
                  
                  <?= $form->field($model, 'city') ?>
                  
                  <?= $form->field($model, 'adress') ?>
                  
                  <?= $form->field($model, 'body')
                           ->textarea([ 'rows' => '3' ]) ?>
                  
                  <?= $form->field($model, 'check') ?>
                  
                  <?= $form->field($model, 'sms') ?>
6f14188b   Alexey Boroda   -Product card fixed
280
              
eb15a89c   Alexey Boroda   -Dancing with com...
281
              </div>
6f14188b   Alexey Boroda   -Product card fixed
282
          </div>
e0906f08   Alexey Boroda   -Fixing existing ...
283
      </div>
e861ae92   Alexey Boroda   -Add column to pa...
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
      <br>
      <div class="row">
          <?= Html::submitButton(
              $model->isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Обновить'),
              [ 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg' ]
          ) ?>
          <?= Html::a(
              \Yii::t('app', 'Печать'),
              yii\helpers\Url::to(
                  [
                      'order/print',
                      'order_id' => $model->id,
                  ]
              ),
              [
                  'class'  => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg',
                  'target' => '_blank',
              ]
          ) ?>
          <?= Html::a(
              \Yii::t('app', 'Выйти'),
              yii\helpers\Url::to(
                  [
                      'exit-order',
                      'id' => $model->id,
                  ]
              ),
              [
                  'class'  => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg',
              ]
          ) ?>
      </div>
e0906f08   Alexey Boroda   -Fixing existing ...
316
  </div>
2ad65823   Alexey Boroda   -Added date range...
317
  
e861ae92   Alexey Boroda   -Add column to pa...
318
319
320
  <?php ActiveForm::end(); ?>
  <br>
  <br>
7520dc0e   Alexey Boroda   -Grid with input ...
321
322
323
324
325
326
  <div class="container">
      <div class="row">
          <?php
              echo GridView::widget(
                  [
                      'dataProvider' => $dataProvider,
bb962a6d   Alexey Boroda   -Order in process
327
                      'layout'       => '{items}{pager}',
7520dc0e   Alexey Boroda   -Grid with input ...
328
329
                      'columns'      => [
                          'id',
7520dc0e   Alexey Boroda   -Grid with input ...
330
                          'sku',
01185786   Alexey Boroda   -Sms in process
331
332
333
334
                          'product_name',
                          'productVariant.product.brand.lang.title',
                          'productVariant.lang.title',
                          'price',
7520dc0e   Alexey Boroda   -Grid with input ...
335
336
337
338
                          [
                              'class'           => 'kartik\grid\EditableColumn',
                              'attribute'       => 'count',
                              'editableOptions' => [
01185786   Alexey Boroda   -Sms in process
339
340
341
                                  'header'       => \Yii::t('app', 'Количество'),
                                  'inputType'    => kartik\editable\Editable::INPUT_SPIN,
                                  'options'      => [
7520dc0e   Alexey Boroda   -Grid with input ...
342
343
344
345
346
                                      'pluginOptions' => [
                                          'min' => 0,
                                          'max' => 5000,
                                      ],
                                  ],
01185786   Alexey Boroda   -Sms in process
347
348
349
                                  'pluginEvents' => [
                                      'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }',
                                  ],
7520dc0e   Alexey Boroda   -Grid with input ...
350
                              ],
7520dc0e   Alexey Boroda   -Grid with input ...
351
352
                              'format'          => [
                                  'decimal',
2ad65823   Alexey Boroda   -Added date range...
353
                                  0,
7520dc0e   Alexey Boroda   -Grid with input ...
354
                              ],
2ad65823   Alexey Boroda   -Added date range...
355
                              'pageSummary'     => false,
7520dc0e   Alexey Boroda   -Grid with input ...
356
                          ],
01185786   Alexey Boroda   -Sms in process
357
                          'sum_cost',
7520dc0e   Alexey Boroda   -Grid with input ...
358
                          [
0893579c   Alexey Boroda   -Bug fixed
359
360
361
362
363
364
365
366
367
368
369
                              'class'           => 'kartik\grid\EditableColumn',
                              'attribute'       => 'booking',
                              'editableOptions' => [
                                  'header'       => \Yii::t('app', 'Бронь'),
                                  'inputType'    => kartik\editable\Editable::INPUT_TEXT,
                                  'options'      => [
                                      'pluginOptions' => [
                                          'min' => 0,
                                          'max' => 20,
                                      ],
                                  ],
0893579c   Alexey Boroda   -Bug fixed
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
                              ],
                              'format'          => [
                                  'text',
                              ],
                              'pageSummary'     => false,
                          ],
                          [
                              'class'           => 'kartik\grid\EditableColumn',
                              'attribute'       => 'status',
                              'editableOptions' => [
                                  'header'       => \Yii::t('app', 'Статус'),
                                  'inputType'    => kartik\editable\Editable::INPUT_TEXT,
                                  'options'      => [
                                      'pluginOptions' => [
                                          'min' => 0,
                                          'max' => 20,
                                      ],
                                  ],
0893579c   Alexey Boroda   -Bug fixed
388
389
390
391
392
393
                              ],
                              'format'          => [
                                  'text',
                              ],
                              'pageSummary'     => false,
                          ],
db3040d3   Alexey Boroda   -Order module alm...
394
395
396
397
398
399
400
401
402
403
404
405
406
                          [
                              'class'           => 'kartik\grid\EditableColumn',
                              'attribute'       => 'return',
                              'editableOptions' => [
                                  'header'       => \Yii::t('app', 'Возврат'),
                                  'inputType'    => kartik\editable\Editable::INPUT_CHECKBOX,
                                  'options'      => [],
                              ],
                              'format'          => [
                                  'boolean',
                              ],
                              'pageSummary'     => false,
                          ],
0893579c   Alexey Boroda   -Bug fixed
407
                          [
2ad65823   Alexey Boroda   -Added date range...
408
                              'class'    => 'yii\grid\ActionColumn',
7520dc0e   Alexey Boroda   -Grid with input ...
409
410
411
412
413
                              'template' => '{delete}',
                          ],
                      ],
                      'responsive'   => true,
                      'hover'        => true,
2ad65823   Alexey Boroda   -Added date range...
414
415
416
417
                      'pjax'         => true,
                      'pjaxSettings' => [
                          'options' => [
                              'scrollTo' => 'false',
bb962a6d   Alexey Boroda   -Order in process
418
                              'id'       => 'order-products-grid',
2ad65823   Alexey Boroda   -Added date range...
419
420
                          ],
                      ],
7520dc0e   Alexey Boroda   -Grid with input ...
421
422
423
                  ]
              );
          ?>
6f14188b   Alexey Boroda   -Product card fixed
424
      </div>
e0906f08   Alexey Boroda   -Fixing existing ...
425
  </div>
e0906f08   Alexey Boroda   -Fixing existing ...
426
  
2ad65823   Alexey Boroda   -Added date range...
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
  <div class="container">
      <div class="row">
          <?php $newProductForm = ActiveForm::begin(
              [
                  'action' => yii\helpers\Url::to([ 'add' ]),
                  'id'     => 'add-product-form',
              ]
          );
              $newOrderProduct = new OrderProduct();
          ?>
          <div class="col-md-8">
              <?php echo $newProductForm->field($newOrderProduct, 'id')
                                        ->widget(
                                            Select2::className(),
                                            [
                                                'options'       => [ 'placeholder' => 'Search for a product ...' ],
                                                'pluginOptions' => [
                                                    'allowClear'         => true,
bb962a6d   Alexey Boroda   -Order in process
445
                                                    'disabled'           => $model->isNewRecord ? true : false,
2ad65823   Alexey Boroda   -Added date range...
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
                                                    'minimumInputLength' => 3,
                                                    'language'           => [
                                                        'errorLoading' => new JsExpression(
                                                            "function () { return 'Waiting for results...'; }"
                                                        ),
                                                    ],
                                                    'ajax'               => [
                                                        'url'      => \yii\helpers\Url::to([ 'find-product' ]),
                                                        'dataType' => 'json',
                                                        'data'     => new JsExpression(
                                                            'function(params) { return {q:params.term}; }'
                                                        ),
                                                    ],
                                                    'escapeMarkup'       => new JsExpression(
                                                        'function (markup) { return markup; }'
                                                    ),
                                                    'templateResult'     => new JsExpression(
                                                        'function(data) { return data.sku; }'
                                                    ),
                                                    'templateSelection'  => new JsExpression(
                                                        'function (data) { return data.sku; }'
                                                    ),
                                                ],
                                            ]
                                        );
              
              ?>
          </div>
          <div class="col-md-2">
db3040d3   Alexey Boroda   -Order module alm...
475
476
477
478
479
480
481
482
483
484
              <?php echo $newProductForm->field(
                  $newOrderProduct,
                  'count'
              )
                                        ->input(
                                            'number',
                                            [
                                                'disabled' => $model->isNewRecord ? true : false,
                                            ]
                                        ); ?>
2ad65823   Alexey Boroda   -Added date range...
485
          </div>
db3040d3   Alexey Boroda   -Order module alm...
486
          <div class="col-md-2" style="margin-top: 23px">
2ad65823   Alexey Boroda   -Added date range...
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
              <?php echo Html::submitButton(
                  'Add',
                  [
                      'class' => $model->isNewRecord ? 'btn btn-primary disabled' : 'btn btn-primary',
                  ]
              ) ?>
          </div>
          <?php echo $newProductForm->field($newOrderProduct, 'order_id')
                                    ->hiddenInput(
                                        [
                                            'value' => $model->id,
                                        ]
                                    )
                                    ->label(false) ?>
          <?php ActiveForm::end(); ?>
      </div>
  </div>
01185786   Alexey Boroda   -Sms in process
504
505
  <br>
  <br>