Blame view

views/order/_form.php 33.2 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;
287e356d   Alexey Boroda   -Permissions read...
8
      use common\models\Permissions;
d57c8c00   Alexey Boroda   -Blocking in process
9
      use common\models\User;
7520dc0e   Alexey Boroda   -Grid with input ...
10
      use kartik\grid\GridView;
42883b83   Alexey Boroda   -Order form beta ...
11
      use kartik\grid\SerialColumn;
bb962a6d   Alexey Boroda   -Order in process
12
      use kartik\widgets\DatePicker;
2ad65823   Alexey Boroda   -Added date range...
13
      use kartik\widgets\Select2;
bb962a6d   Alexey Boroda   -Order in process
14
      use kartik\widgets\SwitchInput;
7520dc0e   Alexey Boroda   -Grid with input ...
15
      use yii\data\ActiveDataProvider;
e0906f08   Alexey Boroda   -Fixing existing ...
16
17
      use yii\helpers\Html;
      use yii\bootstrap\ActiveForm;
6f14188b   Alexey Boroda   -Product card fixed
18
19
      use yii\helpers\ArrayHelper;
      use artweb\artbox\ecommerce\models\Delivery;
42883b83   Alexey Boroda   -Order form beta ...
20
      use yii\helpers\StringHelper;
7520dc0e   Alexey Boroda   -Grid with input ...
21
      use yii\web\View;
2ad65823   Alexey Boroda   -Added date range...
22
      use yii\web\JsExpression;
42883b83   Alexey Boroda   -Order form beta ...
23
      use yii\widgets\Pjax;
e0906f08   Alexey Boroda   -Fixing existing ...
24
      
7520dc0e   Alexey Boroda   -Grid with input ...
25
26
27
28
29
      /**
       * @var View               $this
       * @var Order              $model
       * @var ActiveForm         $form
       * @var ActiveDataProvider $dataProvider
28b51b30   Alexey Boroda   -Order module bug...
30
       * @var User               $user
287e356d   Alexey Boroda   -Permissions read...
31
       * @var Permissions        $permissions
7520dc0e   Alexey Boroda   -Grid with input ...
32
       */
2ad65823   Alexey Boroda   -Added date range...
33
      
28b51b30   Alexey Boroda   -Order module bug...
34
35
      $user = \Yii::$app->user->identity;
      
2ad65823   Alexey Boroda   -Added date range...
36
37
38
39
40
41
42
43
44
45
46
      $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") {
42883b83   Alexey Boroda   -Order form beta ...
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
                   $.pjax.reload({container:"#order-products-grid"});
               }
          },
          error: function () {
          }
      });
  });
  $(document).on('click', '.delete-button', function(e) {
      e.preventDefault();
      var link = $(this).attr('href') + '&order_id=' + {$model->id};
      $.ajax({
          url: link,
          type: "GET",
          success: function (data) {
               if (data.status === "success") {
                   $.pjax.reload({container:"#order-products-grid"});
                   $('[data-toggle="popover"]').popover();
2ad65823   Alexey Boroda   -Added date range...
64
65
66
67
68
69
70
71
72
               }
          },
          error: function () {
          }
      });
  });
  JS;
      
      $this->registerJs($js, View::POS_READY);
bb962a6d   Alexey Boroda   -Order in process
73
74
75
76
77
      
      $js = <<< JS
  $('#order-phone, #order-phone2').mask('+38(000)000-00-00', {
      placeholder: '+38(___)___-__-__'
  });
42883b83   Alexey Boroda   -Order form beta ...
78
79
80
81
82
  $('[data-toggle="popover"]').popover();
  $(document).on('pjax:end', '#order-products-grid', function() {
    $('[data-toggle="popover"]').popover();
    $.pjax.reload({container: '#total-cost'});
  });
bb962a6d   Alexey Boroda   -Order in process
83
84
85
  JS;
      
      $this->registerJs($js, View::POS_READY);
01185786   Alexey Boroda   -Sms in process
86
87
88
89
      
      $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...
90
91
92
93
94
      var val = $('option:contains(' + text + ')').attr('value');
      $('#sms-text-area').val(val);
  });
  
  $(document).on('click', '#send-sms-action', function(event) {
b0c7d586   Alexey Boroda   -Bykov fixes
95
96
97
98
99
100
101
102
      var variant = $('input[name=send-phone]:checked').val();
      var content = $('#sms-text-area').val();
      if (variant == 1) {
          var phone = $('input#order-phone').val();    
      } else if (variant == 2) {
          var phone = $('input#order-phone2').val();    
      }
      console.log(phone);
db3040d3   Alexey Boroda   -Order module alm...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
      $.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
120
121
122
123
  });
  JS;
      
      $this->registerJs($js, View::POS_READY);
b0c7d586   Alexey Boroda   -Bykov fixes
124
125
126
      
      $js = <<< JS
  $(document).on('click', '#page-submit', function() {
52e22ec2   Administrator   add similar products
127
    var phone =  $('#order-phone').val(); 
f36d238b   Alexey Boroda   -Order publish fi...
128
129
130
131
    $.ajax({
      url: "/admin/ecommerce/order/publish-order",
      type: "GET",
      data: {
52e22ec2   Administrator   add similar products
132
133
          id: {$model->id},
          phone: phone
f36d238b   Alexey Boroda   -Order publish fi...
134
135
      },
      success: function (data) {
52e22ec2   Administrator   add similar products
136
  
f36d238b   Alexey Boroda   -Order publish fi...
137
138
139
140
      },
      error: function () {
      }
    });
52e22ec2   Administrator   add similar products
141
    $('#main-form').trigger('submit');
b0c7d586   Alexey Boroda   -Bykov fixes
142
143
144
145
146
  });
  JS;
      
      $this->registerJs($js, View::POS_READY);
  
e0906f08   Alexey Boroda   -Fixing existing ...
147
148
  ?>
  
f2d1c773   Alexey Boroda   -Images popup fix...
149
150
  <?php $form = ActiveForm::begin(
      [
93a0cd0b   Yarik   Credits
151
          'id' => 'main-form',
f2d1c773   Alexey Boroda   -Images popup fix...
152
153
      ]
  ); ?>
17569d93   Alexey Boroda   -Order product lo...
154
155
156
157
  
  
  <div class="box box-default">
    <div class="box-header with-border">
f23a9b6b   Alexey Boroda   -Quick fix
158
      <h3 class="box-title">Заказ</h3>
17569d93   Alexey Boroda   -Order product lo...
159
160
161
162
163
164
      <div class="box-tools pull-right">
        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
        </button>
      </div>
    </div>
    <div class="box-body">
17569d93   Alexey Boroda   -Order product lo...
165
166
  
  
287e356d   Alexey Boroda   -Permissions read...
167
168
      <div class="container">
        <div class="form-group">
42883b83   Alexey Boroda   -Order form beta ...
169
          <br>
287e356d   Alexey Boroda   -Permissions read...
170
171
  
  
42883b83   Alexey Boroda   -Order form beta ...
172
          <div class="row">
287e356d   Alexey Boroda   -Permissions read...
173
174
            <div class="col-sm-6">
                
e86ffb35   Alexey Boroda   -Permissions bug ...
175
176
177
                <?php
                    $model->deadline = date('d.m.Y', (int) $model->deadline);
                    echo $form->field($model, 'deadline')
287e356d   Alexey Boroda   -Permissions read...
178
179
180
181
                         ->widget(
                             DatePicker::className(),
                             [
                                 'disabled' => !$permissions->checkAttr('deadline'),
e86ffb35   Alexey Boroda   -Permissions bug ...
182
183
184
                                 'pluginOptions' => [
                                   'format' => 'dd.mm.yyyy',
                                 ],
287e356d   Alexey Boroda   -Permissions read...
185
186
187
                             ]
                         ) ?>
                
42883b83   Alexey Boroda   -Order form beta ...
188
                <?php
287e356d   Alexey Boroda   -Permissions read...
189
190
191
192
193
194
195
196
197
198
199
200
                    if ($permissions->checkAttr('pay')) {
                        echo $form->field($model, 'pay')
                                  ->widget(
                                      SwitchInput::className(),
                                      [
                                          'name'          => 'pay',
                                          'pluginOptions' => [
                                              'onText'  => \Yii::t('app', 'Оплачено'),
                                              'offText' => \Yii::t('app', 'Не оплачено'),
                                          ],
                                      ]
                                  );
42883b83   Alexey Boroda   -Order form beta ...
201
202
                    }
                ?>
287e356d   Alexey Boroda   -Permissions read...
203
204
205
206
207
208
209
210
211
212
213
214
215
                
                <?= $form->field($model, 'reason')
                         ->dropDownList(
                             Order::REASONS,
                             [
                                 'prompt'   => 'Выберите причину',
                                 'disabled' => !$permissions->checkAttr('reason'),
                             ]
                         ) ?>
                
                <?= $form->field($model, 'label')
                         ->dropDownList(
                             ArrayHelper::map(
e86ffb35   Alexey Boroda   -Permissions bug ...
216
217
218
                                 Label::find()->where([
                                   'id' => $permissions->labelsArray,
                                                      ])
287e356d   Alexey Boroda   -Permissions read...
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
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
                                      ->asArray()
                                      ->all(),
                                 'id',
                                 'label'
                             ),
                             [
                                 'prompt'   => 'Выберите метку',
                                 'disabled' => !$permissions->checkAttr('label'),
                             ]
                         ); ?>
                
                <?= $form->field($model, 'name')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('name') ]) ?>
                
                <?= $form->field($model, 'phone')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('phone') ]) ?>
                
                <?= $form->field($model, 'phone2')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('phone2') ]) ?>
                
                <?= $form->field($model, 'email')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('email') ]) ?>
                
                <?= $form->field(
                    $model,
                    'numbercard'
                )
                         ->textInput([ 'readonly' => !$permissions->checkAttr('numbercard') ]) ?>
                
                <?= $form->field($model, 'comment')
                         ->textarea(
                             [
                                 'rows'     => '3',
                                 'readonly' => !$permissions->checkAttr('comment'),
                             ]
                         ) ?>
                <?= $form->field($model, 'delivery')
                         ->dropDownList(
                             ArrayHelper::map(
                                 Delivery::find()
                                         ->joinWith('lang')
                                         ->asArray()
                                         ->all(),
                                 'id',
                                 'lang.title'
                             ),
                             [
                                 'prompt'   => \Yii::t('app', 'Выберите доставку ...'),
                                 'disabled' => !$permissions->checkAttr('delivery'),
                             ]
                         ) ?>
                
                <?php
                    
e86ffb35   Alexey Boroda   -Permissions bug ...
273
                    if ($permissions->checkAttr('manager_id')) {
287e356d   Alexey Boroda   -Permissions read...
274
275
276
277
278
279
280
281
282
283
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
                        echo $form->field($model, 'manager_id')
                                  ->dropDownList(
                                      ArrayHelper::map(
                                          User::find()
                                              ->asArray()
                                              ->all(),
                                          'id',
                                          'username'
                                      ),
                                      [ 'prompt' => \Yii::t('app', 'Менеджер') ]
                                  );
                    }
                ?>
  
              <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,
                            ],
                        ]
                    );
                
                ?>
              <br>
42883b83   Alexey Boroda   -Order form beta ...
310
                <?php
287e356d   Alexey Boroda   -Permissions read...
311
312
313
                    echo Html::textarea(
                        'sms-text',
                        '',
42883b83   Alexey Boroda   -Order form beta ...
314
                        [
287e356d   Alexey Boroda   -Permissions read...
315
316
317
                            'rows'  => 3,
                            'id'    => 'sms-text-area',
                            'class' => 'form-control',
42883b83   Alexey Boroda   -Order form beta ...
318
319
320
                        ]
                    );
                ?>
287e356d   Alexey Boroda   -Permissions read...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
              <br>
              <div class="row">
                <div class="col-md-6">
                    <?php
                        if (!$permissions->checkAttr('send_sms')) {
                            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',
                                ]
                            );
                        }
                    ?>
                </div>
                <div class="col-md-6">
                    <?php
                        echo Html::radioList(
                            'send-phone',
                            '1',
                            [
                                '1' => 'Первый номер',
                                '2' => 'Второй номер',
                            ]
                        );
                    ?>
                </div>
              </div>
  
            </div>
            <div class="col-sm-6">
                
                <?= $form->field($model, 'declaration')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('declaration') ]) ?>
                
                <?= $form->field($model, 'stock')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('stock') ]) ?>
                
                <?= $form->field($model, 'consignment')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('consignment') ]) ?>
                
                <?= $form->field($model, 'payment')
                         ->dropDownList(
                             ArrayHelper::map(
                                 OrderPayment::find()
                                             ->where([ 'status' => OrderPayment::ACTIVE ])
                                             ->asArray()
                                             ->all(),
                                 'id',
                                 'short'
                             ),
                             [
                                 'prompt'   => 'Способ оплаты ...',
                                 'disabled' => ( $model->payment == 10 || !$permissions->checkAttr(
                                         'payment'
                                     ) ) ? 'disabled' : false,
                             ]
                         ); ?>
                
                <?= $form->field($model, 'insurance')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('insurance') ]) ?>
                
                <?= $form->field($model, 'amount_imposed')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('amount_imposed') ]) ?>
                
                <?= $form->field($model, 'shipping_by')
                         ->dropDownList(
                             ArrayHelper::getColumn(Order::SHIPPING_BY, 'label'),
                             [
                                 'prompt'   => 'Оплата доставки ...',
                                 'disabled' => !$permissions->checkAttr('shipping_by'),
                             ]
                         ); ?>
                
                <?= $form->field($model, 'city')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('city') ]) ?>
                
                <?= $form->field($model, 'adress')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('adress') ]) ?>
                
                <?= $form->field($model, 'body')
                         ->textarea(
                             [
                                 'rows'     => '3',
                                 'readonly' => !$permissions->checkAttr('body'),
                             ]
                         ) ?>
                
                <?= $form->field($model, 'check')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('check') ]) ?>
                
                <?= $form->field($model, 'sms')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('sms') ]) ?>
                
                <?= $form->field($model, 'delivery_cost')
                         ->textInput([ 'readonly' => !$permissions->checkAttr('delivery_cost') ]) ?>
  
42883b83   Alexey Boroda   -Order form beta ...
425
            </div>
6f14188b   Alexey Boroda   -Product card fixed
426
          </div>
42883b83   Alexey Boroda   -Order form beta ...
427
  
42883b83   Alexey Boroda   -Order form beta ...
428
429
  
        </div>
e0906f08   Alexey Boroda   -Fixing existing ...
430
      </div>
17569d93   Alexey Boroda   -Order product lo...
431
  
17569d93   Alexey Boroda   -Order product lo...
432
433
434
    </div><!-- /.box-body -->
  </div><!-- /.box -->
  
e861ae92   Alexey Boroda   -Add column to pa...
435
  <?php ActiveForm::end(); ?>
17569d93   Alexey Boroda   -Order product lo...
436
437
438
439
  
  
  <div class="box box-default">
    <div class="box-header with-border">
f23a9b6b   Alexey Boroda   -Quick fix
440
      <h3 class="box-title">Товары</h3>
17569d93   Alexey Boroda   -Order product lo...
441
442
443
444
445
446
447
      <div class="box-tools pull-right">
        <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
        </button>
      </div>
    </div>
    <div class="box-body">
  
287e356d   Alexey Boroda   -Permissions read...
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
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
      <div class="container">
        <div class="row">
            <?php
                echo GridView::widget(
                    [
                        'dataProvider' => $dataProvider,
                        'rowOptions'   => function($model) {
                            if ($model->removed) {
                                return [ 'class' => 'danger' ];
                            } else {
                                return [];
                            }
                        },
                        'layout'       => '{items}{pager}',
                        'columns'      => [
                            [
                                'class' => SerialColumn::className(),
                            ],
                            'sku',
                            [
                                'attribute' => 'product_name',
                                'content'   => function($model) {
                                    if (!empty($model->product_name)) {
                                        
                                        if (empty($model->productVariant)) {
                                            return '';
                                        }
                                        
                                        return Html::a(
                                            StringHelper::truncate($model->product_name, 10, '...'),
                                            '#',
                                            [
                                                'onclick'        => 'event.preventDefault();',
                                                'data-toggle'    => 'popover',
                                                'data-placement' => 'right',
                                                'data-html'      => 'true',
                                                'data-content'   => Html::img(
                                                        $model->productVariant->imageUrl,
                                                        [
                                                            'class' => 'img-rounded',
                                                        ]
                                                    ) . Html::tag('p', $model->product_name),
                                            ]
                                        );
                                    } else {
                                        return '';
                                    }
                                },
                            ],
                            [
                                'attribute' => 'productVariant.product.brand.lang.title',
                                'label'     => 'Брэнд',
                            ],
                            [
                                'attribute' => 'productVariant.lang.title',
                                'label'     => \Yii::t('app', 'Цвет'),
                                'content'   => function($model) {
                                    
                                    if (empty($model->productVariant)) {
                                        return '';
                                    }
                                    
                                    if (preg_match('@.*\.(png|jpg|gif)@i', $model->productVariant->lang->title)) {
                                        return '';
                                    } else {
                                        return $model->productVariant->lang->title;
                                    }
                                },
                            ],
                            [
                                'attribute' => 'productVariant.size',
                                'label'     => 'Размер',
                            ],
                            'price',
                            [
                                'class'           => 'kartik\grid\EditableColumn',
                                'attribute'       => 'count',
                                'editableOptions' => [
                                    'header'       => \Yii::t('app', 'Количество'),
                                    'inputType'    => kartik\editable\Editable::INPUT_SPIN,
                                    'options'      => [
                                        'pluginOptions' => [
                                            'min' => 0,
                                            'max' => 5000,
                                        ],
                                        'disabled'      => !$permissions->checkAttr('product_count'),
                                    ],
                                    'pluginEvents' => [
                                        'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }',
                                    ],
                                ],
                                'format'          => [
                                    'decimal',
                                    0,
                                ],
                                'pageSummary'     => false,
                            ],
                            'sum_cost',
                            [
                                'class'           => 'kartik\grid\EditableColumn',
                                'attribute'       => 'booking',
                                'editableOptions' => [
                                    'header'       => \Yii::t('app', 'Бронь'),
                                    'inputType'    => kartik\editable\Editable::INPUT_TEXT,
                                    'options'      => [
                                        'class'         => 'booking-typeahead',
                                        'pluginOptions' => [
                                            'min' => 0,
                                            'max' => 20,
                                        ],
                                        'disabled'      => !$permissions->checkAttr('product_booking'),
                                    ],
                                    'pluginEvents' => [
                                        'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }',
                                    ],
                                ],
                                'format'          => [
                                    'text',
                                ],
                                'pageSummary'     => false,
                            ],
                            [
                                'class'           => 'kartik\grid\EditableColumn',
                                'attribute'       => 'status',
                                'editableOptions' => [
                                    'header'       => \Yii::t('app', 'Статус'),
                                    'inputType'    => kartik\editable\Editable::INPUT_TEXT,
                                    'options'      => [
                                        'class'         => 'status-typeahead',
                                        'pluginOptions' => [
                                            'min' => 0,
                                            'max' => 20,
                                        ],
                                        'disabled'      => !$permissions->checkAttr('product_status'),
                                    ],
                                    'pluginEvents' => [
                                        'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }',
                                    ],
                                ],
                                'format'          => [
                                    'text',
                                ],
                                'pageSummary'     => false,
                            ],
                            [
                                'class'           => 'kartik\grid\EditableColumn',
                                'attribute'       => 'return',
                                'editableOptions' => [
                                    'header'       => \Yii::t('app', 'Возврат'),
                                    'inputType'    => kartik\editable\Editable::INPUT_CHECKBOX,
                                    'options'      => [
                                        'disabled' => !$permissions->checkAttr('product_return'),
                                    ],
                                    'pluginEvents' => [
                                        'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }',
                                    ],
                                ],
                                'format'          => [
                                    'boolean',
                                ],
                                'pageSummary'     => false,
                            ],
                            [
                                'content' => function($model) {
                                    
                                    if (empty($model->productVariant)) {
                                        return '<i class="glyphicon glyphicon-remove"></i>';
                                    }
                                    
                                    $content = '<table class="table"><tbody><tr><th>Склад</th><th>кол.</th></tr>';
                                    foreach ($model->productVariant->variantStocks as $stock) {
                                        $content .= '<tr><td>' . $stock->stock->title . '</td><td>' . $stock->quantity . '</td></tr>';
                                    }
                                    return Html::a(
                                        '<i class="glyphicon glyphicon-home"></i>',
                                        '#',
                                        [
                                            'onclick'        => 'event.preventDefault();',
                                            'data-toggle'    => 'popover',
                                            'data-placement' => 'left',
                                            'data-html'      => 'true',
                                            'data-content'   => $content . '</tbody></table>',
                                        ]
                                    );
                                },
                            ],
                            [
                                'class'    => 'yii\grid\ActionColumn',
                                'template' => '{delete}',
                                'buttons'  => [
                                    'delete' => function($url, $product) use ($permissions) {
                                        if ($product->removed || !$permissions->checkAttr('delete_product')) {
                                            return '';
                                        } else {
                                            return Html::a(
                                                Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-trash' ]),
                                                [
                                                    'delete-product',
                                                    'id' => $product->id,
                                                ],
                                                [
                                                    'class' => 'delete-button',
                                                ]
                                            );
                                        }
                                    },
                                ],
                            ],
                        ],
                        'responsive'   => true,
                        'hover'        => true,
                        'pjax'         => true,
                        'pjaxSettings' => [
                            'options' => [
                                'scrollTo' => 'false',
                                'id'       => 'order-products-grid',
                            ],
                        ],
                    ]
                );
            ?>
        </div>
93a0cd0b   Yarik   Credits
670
      </div>
287e356d   Alexey Boroda   -Permissions read...
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
      <div class="container">
          <?php Pjax::begin([ 'id' => 'total-cost' ]); ?>
        <h2>Сумма заказа : <span class="label label-success"><?php echo $model->total; ?><?php echo \Yii::t(
                    'app',
                    'грн'
                ) ?></span></h2>
          <?php Pjax::end(); ?>
      </div>
      <div class="container">
        <div class="row">
            <?php $newProductForm = ActiveForm::begin(
                [
                    'action' => yii\helpers\Url::to([ 'add' ]),
                    'id'     => 'add-product-form',
                ]
            );
                $newOrderProduct = new OrderProduct();
            ?>
93a0cd0b   Yarik   Credits
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
          <div class="col-md-8">
              <?php echo $newProductForm->field($newOrderProduct, 'id')
                                        ->widget(
                                            Select2::className(),
                                            [
                                                'options'       => [ 'placeholder' => 'Search for a product ...' ],
                                                'pluginOptions' => [
                                                    'allowClear'         => true,
                                                    'disabled'           => $model->isNewRecord ? true : false,
                                                    '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; }'
2ad65823   Alexey Boroda   -Added date range...
713
                                                    ),
93a0cd0b   Yarik   Credits
714
715
716
717
718
                                                    'templateResult'     => new JsExpression(
                                                        'function(data) { return data.sku; }'
                                                    ),
                                                    'templateSelection'  => new JsExpression(
                                                        'function (data) { return data.sku; }'
2ad65823   Alexey Boroda   -Added date range...
719
720
                                                    ),
                                                ],
93a0cd0b   Yarik   Credits
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
                                            ]
                                        )
                                        ->label('Артикул');
              
              ?>
          </div>
          <div class="col-md-2">
              <?php echo $newProductForm->field(
                  $newOrderProduct,
                  'count'
              )
                                        ->input(
                                            'number',
                                            [
                                                'disabled' => $model->isNewRecord ? true : false,
                                            ]
                                        ); ?>
          </div>
          <div class="col-md-2" style="margin-top: 23px">
e86ffb35   Alexey Boroda   -Permissions bug ...
740
741
              <?php if ($permissions->checkAttr('add_product'))
                echo Html::submitButton(
93a0cd0b   Yarik   Credits
742
743
                  \Yii::t('app', 'Добавить'),
                  [
e86ffb35   Alexey Boroda   -Permissions bug ...
744
                      'class' => 'btn btn-primary',
93a0cd0b   Yarik   Credits
745
746
747
                  ]
              ) ?>
          </div>
287e356d   Alexey Boroda   -Permissions read...
748
749
750
751
752
753
754
755
756
            <?php echo $newProductForm->field($newOrderProduct, 'order_id')
                                      ->hiddenInput(
                                          [
                                              'value' => $model->id,
                                          ]
                                      )
                                      ->label(false) ?>
            <?php ActiveForm::end(); ?>
        </div>
17569d93   Alexey Boroda   -Order product lo...
757
758
  
  
287e356d   Alexey Boroda   -Permissions read...
759
      </div>
17569d93   Alexey Boroda   -Order product lo...
760
761
762
  
    </div><!-- /.box-body -->
  </div><!-- /.box -->
287e356d   Alexey Boroda   -Permissions read...
763
764
765
  
  
  <br>
17569d93   Alexey Boroda   -Order product lo...
766
  <div class="container">
287e356d   Alexey Boroda   -Permissions read...
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
    <div class="row">
        <?= Html::button(
            $model->isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Сохранить'),
            [
                'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg',
                'id'    => 'page-submit',
            ]
        ) ?>
        <?= 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(
                [
                    'close-order',
                    'id' => $model->id,
                ]
            ),
            [
                'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg',
            ]
        ) ?>
    </div>
2ad65823   Alexey Boroda   -Added date range...
801
  </div>
01185786   Alexey Boroda   -Sms in process
802
803
  <br>
  <br>