Blame view

views/order/index.php 12.3 KB
e0906f08   Alexey Boroda   -Fixing existing ...
1
  <?php
2ad65823   Alexey Boroda   -Added date range...
2
3
4
5
6
7
      /**
       * @var ActiveDataProvider $dataProvider
       * @var OrderSearch        $searchModel
       * @var View               $this
       */
      
bb962a6d   Alexey Boroda   -Order in process
8
9
      use artweb\artbox\ecommerce\models\Delivery;
      use artweb\artbox\ecommerce\models\Label;
ce75bc1d   Alexey Boroda   -Grid view half w...
10
      use artweb\artbox\ecommerce\models\Order;
2ad65823   Alexey Boroda   -Added date range...
11
      use artweb\artbox\ecommerce\models\OrderSearch;
01185786   Alexey Boroda   -Sms in process
12
      use common\models\User;
2ad65823   Alexey Boroda   -Added date range...
13
      use kartik\daterange\DateRangePicker;
bb962a6d   Alexey Boroda   -Order in process
14
      use kartik\select2\Select2;
2ad65823   Alexey Boroda   -Added date range...
15
      use yii\data\ActiveDataProvider;
01185786   Alexey Boroda   -Sms in process
16
      use yii\helpers\ArrayHelper;
e0906f08   Alexey Boroda   -Fixing existing ...
17
      use yii\helpers\Html;
ce75bc1d   Alexey Boroda   -Grid view half w...
18
19
      use kartik\grid\GridView;
      use yii\helpers\StringHelper;
bb962a6d   Alexey Boroda   -Order in process
20
      use yii\helpers\Url;
01185786   Alexey Boroda   -Sms in process
21
      use yii\web\JsExpression;
2ad65823   Alexey Boroda   -Added date range...
22
      use yii\web\View;
bb962a6d   Alexey Boroda   -Order in process
23
      use yii\widgets\ActiveForm;
01185786   Alexey Boroda   -Sms in process
24
      use yii\widgets\Pjax;
e0906f08   Alexey Boroda   -Fixing existing ...
25
26
27
      
      $this->title = 'Заказы';
      $this->params[ 'breadcrumbs' ][] = $this->title;
ccfc5763   Alexey Boroda   -Order in process 3
28
29
30
31
32
33
34
35
      
      $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...
36
  
e0906f08   Alexey Boroda   -Fixing existing ...
37
  ?>
2ad65823   Alexey Boroda   -Added date range...
38
39
40
41
  <h1>Заказы</h1>
  <p>
      <?= Html::a('Add order', [ 'create' ], [ 'class' => 'btn btn-success' ]) ?>
  </p>
01185786   Alexey Boroda   -Sms in process
42
  <?php Pjax::begin(); ?>
bb962a6d   Alexey Boroda   -Order in process
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  <?php
      $searchForm = ActiveForm::begin(
          [
              'method' => 'GET',
              'action' => Url::to([ 'order/index' ]),
              'id'     => 'search-form',
          ]
      );
  ?>
  
  <p>
      
      <?php echo Html::submitButton(
          'Search',
          [
              'class' => 'btn btn-primary',
          ]
      ) ?>
  
  </p>
28b51b30   Alexey Boroda   -Order module bug...
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
  <div class="row">
      <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',
                                                                  ]
                                                              )
                                                              ->indexBy('id')
                                                              ->asArray()
                                                              ->column(),
                                      'options'       => [ 'placeholder' => 'Select a state ...' ],
                                      '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' => 'Select a state ...' ],
                                      '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
139
140
141
142
143
144
                                       if(data.sku == undefined) {
                                           return "sku"; 
                                       } else {
                                           return data.sku;
                                       }
                                      }'
28b51b30   Alexey Boroda   -Order module bug...
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
                                          ),
                                      ],
                                  ]
                              );
          
          ?>
      </div>
      
      
      <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() ?>
      
      </div>
      <div class="col-md-4">
          <?= $searchForm->field($searchModel, 'declaration')
                         ->textInput() ?>
          
          <?= $searchForm->field($searchModel, 'consignment')
                         ->textInput() ?>
      </div>
  </div>
01185786   Alexey Boroda   -Sms in process
179
  
bb962a6d   Alexey Boroda   -Order in process
180
  <p>
ce75bc1d   Alexey Boroda   -Grid view half w...
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
      <?php
          echo GridView::widget(
              [
                  '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...
198
                          'content'   => function($model) {
b0c7d586   Alexey Boroda   -Bykov fixes
199
                              $manager = $model->manager;
28b51b30   Alexey Boroda   -Order module bug...
200
                              if (empty( $manager )) {
b0c7d586   Alexey Boroda   -Bykov fixes
201
202
203
204
                                  return $model->id;
                              } else {
                                  return $model->id . ' ' . $manager->username;
                              }
28b51b30   Alexey Boroda   -Order module bug...
205
                          },
ce75bc1d   Alexey Boroda   -Grid view half w...
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
                      ],
                      [
                          'attribute' => 'created_at',
                          'format'    => 'date',
                          '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
221
                                                            ],
ce75bc1d   Alexey Boroda   -Grid view half w...
222
223
224
225
226
227
228
                                                        ]
                                                    )
                                                    ->label(false)
                                                    ->render(),
                      ],
                      [
                          'attribute' => 'deadline',
01185786   Alexey Boroda   -Sms in process
229
230
                          'content'   => function($model) {
                              if ($model->deadline == '') {
ce75bc1d   Alexey Boroda   -Grid view half w...
231
232
233
234
                                  return '';
                              } else {
                                  return \Yii::$app->formatter->asDate($model->deadline);
                              }
01185786   Alexey Boroda   -Sms in process
235
                          },
ce75bc1d   Alexey Boroda   -Grid view half w...
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
                      ],
                      'name',
                      'total',
                      [
                          'attribute' => 'pay',
                          'content'   => function($model) {
                              if ($model->pay == false) {
                                  return '<span class="glyphicon glyphicon-remove"></span>';
                              } else {
                                  return '<span class="glyphicon glyphicon-ok"></span>';
                              }
                          },
                      ],
                      'phone',
                      'adress',
                      [
                          'attribute' => 'label',
01185786   Alexey Boroda   -Sms in process
253
                          'filter'    => false,
ce75bc1d   Alexey Boroda   -Grid view half w...
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
                          'value'     => function($model) {
                              /**
                               * @var Order $modl
                               */
                              if (empty( $model->orderLabel )) {
                                  return '--';
                              } else {
                                  return $model->orderLabel->label;
                              }
                          },
                      ],
                      
                      [
                          'attribute' => 'body',
                          'content'   => function($model) {
                              if (!empty( $model->body )) {
0893579c   Alexey Boroda   -Bug fixed
270
                                  return StringHelper::truncate($model->body, 12, '...');
ce75bc1d   Alexey Boroda   -Grid view half w...
271
272
273
274
275
276
277
                              } else {
                                  return '';
                              }
                          },
                      ],
                      'sms',
                      [
28b51b30   Alexey Boroda   -Order module bug...
278
279
280
281
282
283
284
285
286
287
288
289
                          'class'    => 'yii\grid\ActionColumn',
                          'template' => \Yii::$app->user->identity->isAdmin(
                          ) ? '{view} {update} {delete}' : '{view} {update}',
                          'buttons'  => [
                              'update' => function($url, $model) {
                                  return Html::a(
                                      Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-pencil' ]),
                                      $url,
                                      [ 'target' => '_blank' ]
                                  );
                              },
                          ],
ce75bc1d   Alexey Boroda   -Grid view half w...
290
                      ],
bb962a6d   Alexey Boroda   -Order in process
291
                  ],
ce75bc1d   Alexey Boroda   -Grid view half w...
292
293
294
              ]
          );
      ?>
bb962a6d   Alexey Boroda   -Order in process
295
296
297
298
  </p>
  <?php
      ActiveForm::end();
  ?>
01185786   Alexey Boroda   -Sms in process
299
  <?php Pjax::end(); ?>