Blame view

views/order/index.php 17.5 KB
e0906f08   Alexey Boroda   -Fixing existing ...
1
  <?php
2ad65823   Alexey Boroda   -Added date range...
2
3
4
5
      /**
       * @var ActiveDataProvider $dataProvider
       * @var OrderSearch        $searchModel
       * @var View               $this
287e356d   Alexey Boroda   -Permissions read...
6
7
       * @var array              $allowedLabels
       * @var boolean            $canCreate
2ad65823   Alexey Boroda   -Added date range...
8
9
       */
      
bb962a6d   Alexey Boroda   -Order in process
10
11
      use artweb\artbox\ecommerce\models\Delivery;
      use artweb\artbox\ecommerce\models\Label;
ce75bc1d   Alexey Boroda   -Grid view half w...
12
      use artweb\artbox\ecommerce\models\Order;
2ad65823   Alexey Boroda   -Added date range...
13
      use artweb\artbox\ecommerce\models\OrderSearch;
01185786   Alexey Boroda   -Sms in process
14
      use common\models\User;
2ad65823   Alexey Boroda   -Added date range...
15
      use kartik\daterange\DateRangePicker;
bb962a6d   Alexey Boroda   -Order in process
16
      use kartik\select2\Select2;
2ad65823   Alexey Boroda   -Added date range...
17
      use yii\data\ActiveDataProvider;
01185786   Alexey Boroda   -Sms in process
18
      use yii\helpers\ArrayHelper;
e0906f08   Alexey Boroda   -Fixing existing ...
19
      use yii\helpers\Html;
ce75bc1d   Alexey Boroda   -Grid view half w...
20
21
      use kartik\grid\GridView;
      use yii\helpers\StringHelper;
bb962a6d   Alexey Boroda   -Order in process
22
      use yii\helpers\Url;
01185786   Alexey Boroda   -Sms in process
23
      use yii\web\JsExpression;
2ad65823   Alexey Boroda   -Added date range...
24
      use yii\web\View;
bb962a6d   Alexey Boroda   -Order in process
25
      use yii\widgets\ActiveForm;
01185786   Alexey Boroda   -Sms in process
26
      use yii\widgets\Pjax;
e0906f08   Alexey Boroda   -Fixing existing ...
27
28
29
      
      $this->title = 'Заказы';
      $this->params[ 'breadcrumbs' ][] = $this->title;
ccfc5763   Alexey Boroda   -Order in process 3
30
31
32
33
34
35
36
37
      
      $js = <<< JS
  $('[name="OrderSearch[phone]"]').mask('+38(000)000-00-00', {
      placeholder: '+38(___)___-__-__'
  });
  JS;
      
      $this->registerJs($js, View::POS_READY);
db3040d3   Alexey Boroda   -Order module alm...
38
  
e0906f08   Alexey Boroda   -Fixing existing ...
39
  ?>
2ad65823   Alexey Boroda   -Added date range...
40
41
  <h1>Заказы</h1>
  <p>
287e356d   Alexey Boroda   -Permissions read...
42
43
44
45
      <?= Html::a(\Yii::t('app', 'Добавить заказ'), [ 'create' ], [
        'class' => $canCreate ? 'btn btn-success btn-lg' : 'btn btn-success btn-lg disabled',
        
      ]) ?>
2ad65823   Alexey Boroda   -Added date range...
46
  </p>
01185786   Alexey Boroda   -Sms in process
47
  <?php Pjax::begin(); ?>
bb962a6d   Alexey Boroda   -Order in process
48
49
50
51
52
53
54
55
56
57
  <?php
      $searchForm = ActiveForm::begin(
          [
              'method' => 'GET',
              'action' => Url::to([ 'order/index' ]),
              'id'     => 'search-form',
          ]
      );
  ?>
  
dbdd0d43   Alexey Boroda   -Images and spoil...
58
  
287e356d   Alexey Boroda   -Permissions read...
59
60
  
  
bb962a6d   Alexey Boroda   -Order in process
61
  
f2d1c773   Alexey Boroda   -Images popup fix...
62
  <?php
287e356d   Alexey Boroda   -Permissions read...
63
64
65
66
67
68
      //    echo Html::button(\Yii::t('app', 'Скрыть/Показать'), [
      //  'data-toggle' => 'collapse',
      //  'data-target' => '#search-fields',
      //  'class' => 'btn btn-default'
      //]);
      //?>
f2d1c773   Alexey Boroda   -Images popup fix...
69
70
  <div class="box box-primary">
    <div class="box-header with-border">
287e356d   Alexey Boroda   -Permissions read...
71
      <!--    <h3 class="box-title"></h3>-->
f2d1c773   Alexey Boroda   -Images popup fix...
72
73
74
75
76
77
78
79
80
81
        <?php echo Html::submitButton(
            \Yii::t('app', 'Искать'),
            [
                'class' => 'btn btn-primary',
            ]
        ) ?>
      <div class="box-tools pull-right">
        <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
      </div>
    </div>
287e356d   Alexey Boroda   -Permissions read...
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
149
150
151
152
153
154
155
156
157
158
159
  
    <div class="row box-body" id="search-fields">
      <div class="col-md-4">
          <?php
              echo $searchForm->field($searchModel, 'label')
                              ->widget(
                                  Select2::className(),
                                  [
                                      'data'          => Label::find()
                                                              ->joinWith('lang')
                                                              ->select(
                                                                  [
                                                                      'CONCAT(order_label.label,order_label_lang.title) AS name',
                                                                      'id',
                                                                  ]
                                                              )
                                                              ->filterWhere([ 'id' => $allowedLabels ])
                                                              ->indexBy('id')
                                                              ->asArray()
                                                              ->column(),
                                      'options'       => [ 'placeholder' => 'Выберите метки ...' ],
                                      'pluginOptions' => [
                                          'allowClear' => true,
                                          'multiple'   => true,
                                      ],
                                  ]
                              );
          ?>
          <?php
              echo $searchForm->field($searchModel, 'delivery')
                              ->widget(
                                  Select2::className(),
                                  [
                                      'data'          => Delivery::find()
                                                                 ->joinWith('lang')
                                                                 ->select('order_delivery_lang.title, id')
                                                                 ->indexBy('id')
                                                                 ->asArray()
                                                                 ->column(),
                                      'options'       => [ 'placeholder' => 'Выберите способ доставки ...' ],
                                      'pluginOptions' => [
                                          'allowClear' => true,
                                          'multiple'   => true,
                                      ],
                                  ]
                              );
          ?>
          
          <?php
              $query = new JsExpression(
                  'function(params) { return {q:params.term}; }'
              );
              echo $searchForm->field($searchModel, 'sku')
                              ->widget(
                                  Select2::className(),
                                  [
                                      'options'       => [ 'placeholder' => 'Search for a product ...' ],
                                      'pluginOptions' => [
                                          'allowClear'         => true,
                                          'minimumInputLength' => 3,
                                          'language'           => [
                                              'errorLoading' => new JsExpression(
                                                  "function () { return 'Waiting for results...'; }"
                                              ),
                                          ],
                                          'ajax'               => [
                                              'url'      => \yii\helpers\Url::to([ 'find-product' ]),
                                              'dataType' => 'json',
                                              'data'     => $query,
                                          ],
                                          'escapeMarkup'       => new JsExpression(
                                              'function (markup) { return markup; }'
                                          ),
                                          'templateResult'     => new JsExpression(
                                              'function(data) { return data.sku; }'
                                          ),
                                          'templateSelection'  => new JsExpression(
                                              'function (data) {
0893579c   Alexey Boroda   -Bug fixed
160
161
162
163
164
165
                                       if(data.sku == undefined) {
                                           return "sku"; 
                                       } else {
                                           return data.sku;
                                       }
                                      }'
287e356d   Alexey Boroda   -Permissions read...
166
167
168
169
170
171
172
                                          ),
                                      ],
                                  ]
                              );
          
          ?>
      </div>
54350885   Alexey Boroda   -Order module sma...
173
174
  
  
287e356d   Alexey Boroda   -Permissions read...
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
      <div class="col-md-4">
          <?= $searchForm->field($searchModel, 'manager_id')
                         ->dropDownList(
                             ArrayHelper::map(
                                 User::find()
                                     ->asArray()
                                     ->all(),
                                 'id',
                                 'username'
                             ),
                             [ 'prompt' => \Yii::t('app', 'Выберите менеджера ...') ]
                         ) ?>
          
          <?= $searchForm->field($searchModel, 'email')
                         ->textInput() ?>
54350885   Alexey Boroda   -Order module sma...
190
  
287e356d   Alexey Boroda   -Permissions read...
191
192
193
194
195
196
197
198
      </div>
      <div class="col-md-4">
          <?= $searchForm->field($searchModel, 'declaration')
                         ->textInput() ?>
          
          <?= $searchForm->field($searchModel, 'consignment')
                         ->textInput() ?>
      </div>
54350885   Alexey Boroda   -Order module sma...
199
    </div>
01185786   Alexey Boroda   -Sms in process
200
  
f2d1c773   Alexey Boroda   -Images popup fix...
201
  </div>
287e356d   Alexey Boroda   -Permissions read...
202
  
bb962a6d   Alexey Boroda   -Order in process
203
  <p>
ce75bc1d   Alexey Boroda   -Grid view half w...
204
205
206
      <?php
          echo GridView::widget(
              [
622a985a   Alexey Boroda   -Feed in process
207
                  'hover'        => true,
ce75bc1d   Alexey Boroda   -Grid view half w...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
                  'dataProvider' => $dataProvider,
                  'filterModel'  => $searchModel,
                  'rowOptions'   => function($model) {
                      if ($model->wasted) {
                          return [ 'class' => 'danger' ];
                      } else {
                          return [];
                      }
                  },
                  'columns'      => [
                      [
                          'attribute' => 'id',
                          'filter'    => $searchForm->field($searchModel, 'id')
                                                    ->textInput(),
28b51b30   Alexey Boroda   -Order module bug...
222
                          'content'   => function($model) {
b0c7d586   Alexey Boroda   -Bykov fixes
223
                              $manager = $model->manager;
54350885   Alexey Boroda   -Order module sma...
224
                              if (empty($manager)) {
287e356d   Alexey Boroda   -Permissions read...
225
226
227
228
229
230
231
232
233
234
235
                                  return Html::a(
                                      $model->id,
                                      [
                                          'update',
                                          'id' => $model->id,
                                      ],
                                      [
                                          'target'    => '_blank',
                                          'data-pjax' => '0',
                                      ]
                                  );
b0c7d586   Alexey Boroda   -Bykov fixes
236
                              } else {
287e356d   Alexey Boroda   -Permissions read...
237
238
239
240
241
242
243
244
245
246
247
                                  return Html::a(
                                          $model->id,
                                          [
                                              'update',
                                              'id' => $model->id,
                                          ],
                                          [
                                              'target'    => '_blank',
                                              'data-pjax' => '0',
                                          ]
                                      ) . '<br>' . $manager->username;
b0c7d586   Alexey Boroda   -Bykov fixes
248
                              }
28b51b30   Alexey Boroda   -Order module bug...
249
                          },
ce75bc1d   Alexey Boroda   -Grid view half w...
250
251
252
                      ],
                      [
                          'attribute' => 'created_at',
622a985a   Alexey Boroda   -Feed in process
253
                          'content'   => function($model) {
54350885   Alexey Boroda   -Order module sma...
254
255
                              return date('d/m/Y', $model->created_at) . '<br>' . date('G:i', $model->created_at);
                          },
ce75bc1d   Alexey Boroda   -Grid view half w...
256
257
258
259
260
261
262
263
264
265
266
                          'filter'    => $searchForm->field($searchModel, 'date_range')
                                                    ->widget(
                                                        DateRangePicker::className(),
                                                        [
                                                            'convertFormat' => false,
                                                            'pluginOptions' => [
                                                                'locale' => [
                                                                    'format'    => 'D-M-Y',
                                                                    'separator' => ' to ',
                                                                ],
                                                                'opens'  => 'left',
bb962a6d   Alexey Boroda   -Order in process
267
                                                            ],
ce75bc1d   Alexey Boroda   -Grid view half w...
268
269
270
271
272
273
274
                                                        ]
                                                    )
                                                    ->label(false)
                                                    ->render(),
                      ],
                      [
                          'attribute' => 'deadline',
01185786   Alexey Boroda   -Sms in process
275
276
                          'content'   => function($model) {
                              if ($model->deadline == '') {
ce75bc1d   Alexey Boroda   -Grid view half w...
277
278
                                  return '';
                              } else {
622a985a   Alexey Boroda   -Feed in process
279
280
281
282
                                  return \Yii::$app->formatter->asDate(
                                          $model->deadline,
                                          'php:d M'
                                      ) . '<br>' . \Yii::$app->formatter->asDate($model->deadline, 'php:Y г');
ce75bc1d   Alexey Boroda   -Grid view half w...
283
                              }
01185786   Alexey Boroda   -Sms in process
284
                          },
ce75bc1d   Alexey Boroda   -Grid view half w...
285
286
                      ],
                      'name',
54350885   Alexey Boroda   -Order module sma...
287
288
289
290
                      [
                          'attribute' => 'total',
                          'content'   => function($model) {
                              if (empty($model->total)) {
622a985a   Alexey Boroda   -Feed in process
291
                                  return '';
54350885   Alexey Boroda   -Order module sma...
292
                              } else {
622a985a   Alexey Boroda   -Feed in process
293
                                  return $model->total;
54350885   Alexey Boroda   -Order module sma...
294
295
296
                              }
                          },
                      ],
ce75bc1d   Alexey Boroda   -Grid view half w...
297
298
299
300
301
302
303
304
305
306
                      [
                          'attribute' => 'pay',
                          'content'   => function($model) {
                              if ($model->pay == false) {
                                  return '<span class="glyphicon glyphicon-remove"></span>';
                              } else {
                                  return '<span class="glyphicon glyphicon-ok"></span>';
                              }
                          },
                      ],
de382cfb   Alexey Boroda   -Two numbers
307
                      [
287e356d   Alexey Boroda   -Permissions read...
308
309
310
311
                          'attribute' => 'phone',
                          'content'   => function($model) {
                              return $model->phone . '<br>' . $model->phone2;
                          },
de382cfb   Alexey Boroda   -Two numbers
312
                      ],
653d2754   Alexey Boroda   -Order module sma...
313
314
315
                      [
                          'attribute' => 'adress',
                          'content'   => function($model) {
54350885   Alexey Boroda   -Order module sma...
316
317
318
319
320
321
322
323
324
325
                              if (!empty($model->adress)) {
                                  return Html::a(
                                      StringHelper::truncate($model->adress, 10, '...'),
                                      '#',
                                      [
                                          'data-toggle' => 'tooltip',
                                          'title'       => $model->adress,
                                          'onclick'     => 'event.preventDefault();',
                                      ]
                                  );
653d2754   Alexey Boroda   -Order module sma...
326
327
328
329
330
                              } else {
                                  return '';
                              }
                          },
                      ],
ce75bc1d   Alexey Boroda   -Grid view half w...
331
332
                      [
                          'attribute' => 'label',
01185786   Alexey Boroda   -Sms in process
333
                          'filter'    => false,
ce75bc1d   Alexey Boroda   -Grid view half w...
334
335
336
337
                          'value'     => function($model) {
                              /**
                               * @var Order $modl
                               */
54350885   Alexey Boroda   -Order module sma...
338
                              if (empty($model->orderLabel)) {
ce75bc1d   Alexey Boroda   -Grid view half w...
339
340
341
342
343
344
                                  return '--';
                              } else {
                                  return $model->orderLabel->label;
                              }
                          },
                      ],
ce75bc1d   Alexey Boroda   -Grid view half w...
345
346
347
                      [
                          'attribute' => 'body',
                          'content'   => function($model) {
54350885   Alexey Boroda   -Order module sma...
348
                              if (!empty($model->body)) {
b8e6a5c4   Alexey Boroda   -Order module sma...
349
                                  return StringHelper::truncate($model->body, 10, '...');
ce75bc1d   Alexey Boroda   -Grid view half w...
350
351
352
353
354
                              } else {
                                  return '';
                              }
                          },
                      ],
deaedeb0   Alexey Boroda   -Order module tas...
355
356
357
                      [
                          'attribute' => 'sms',
                          'content'   => function($model) {
54350885   Alexey Boroda   -Order module sma...
358
359
                              if (!empty($model->sms)) {
                                  return Html::a(
b8e6a5c4   Alexey Boroda   -Order module sma...
360
                                      StringHelper::truncate($model->sms, 10, '...'),
54350885   Alexey Boroda   -Order module sma...
361
362
363
364
365
366
367
                                      '#',
                                      [
                                          'data-toggle' => 'tooltip',
                                          'title'       => $model->sms,
                                          'onclick'     => 'event.preventDefault();',
                                      ]
                                  );
deaedeb0   Alexey Boroda   -Order module tas...
368
369
370
371
372
                              } else {
                                  return '';
                              }
                          },
                      ],
ce75bc1d   Alexey Boroda   -Grid view half w...
373
                      [
28b51b30   Alexey Boroda   -Order module bug...
374
375
                          'class'    => 'yii\grid\ActionColumn',
                          'template' => \Yii::$app->user->identity->isAdmin(
ff71eeed   Alexey Boroda   -Logs ready
376
                          ) ? '{history} {view} {update} {delete}' : '{view} {update}',
28b51b30   Alexey Boroda   -Order module bug...
377
                          'buttons'  => [
287e356d   Alexey Boroda   -Permissions read...
378
                              'update'  => function($url, $model) {
28b51b30   Alexey Boroda   -Order module bug...
379
380
381
                                  return Html::a(
                                      Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-pencil' ]),
                                      $url,
f2d1c773   Alexey Boroda   -Images popup fix...
382
                                      [
287e356d   Alexey Boroda   -Permissions read...
383
384
                                          'target'    => '_blank',
                                          'data-pjax' => '0',
f2d1c773   Alexey Boroda   -Images popup fix...
385
                                      ]
28b51b30   Alexey Boroda   -Order module bug...
386
387
                                  );
                              },
ff71eeed   Alexey Boroda   -Logs ready
388
389
390
                              'history' => function($url, $model) {
                                  return Html::a(
                                      Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-time' ]),
ff71eeed   Alexey Boroda   -Logs ready
391
                                      [
287e356d   Alexey Boroda   -Permissions read...
392
393
394
395
396
                                          'log',
                                          'id' => $model->id,
                                      ],
                                      [
                                          'target'    => '_blank',
ff71eeed   Alexey Boroda   -Logs ready
397
398
399
400
                                          'data-pjax' => '0',
                                      ]
                                  );
                              },
28b51b30   Alexey Boroda   -Order module bug...
401
                          ],
ce75bc1d   Alexey Boroda   -Grid view half w...
402
                      ],
bb962a6d   Alexey Boroda   -Order in process
403
                  ],
ce75bc1d   Alexey Boroda   -Grid view half w...
404
405
406
              ]
          );
      ?>
bb962a6d   Alexey Boroda   -Order in process
407
408
409
410
  </p>
  <?php
      ActiveForm::end();
  ?>
01185786   Alexey Boroda   -Sms in process
411
  <?php Pjax::end(); ?>