Blame view

views/statistics/index.php 19.6 KB
1ac35977   Alexey Boroda   -Staistics started
1
  <?php
ee0e1df5   Alexey Boroda   -Statistics half ...
2
      use artweb\artbox\ecommerce\models\Label;
44747138   Alexey Boroda   -Default statisti...
3
      use artweb\artbox\ecommerce\models\Order;
29257441   Alexey Boroda   -Manager filter o...
4
5
      use artweb\artbox\ecommerce\models\ProductVariant;
      use common\models\User;
c130fad8   Alexey Boroda   -Yml fix
6
      use kartik\daterange\DateRangePicker;
ee0e1df5   Alexey Boroda   -Statistics half ...
7
      use kartik\grid\GridView;
c130fad8   Alexey Boroda   -Yml fix
8
      use kartik\select2\Select2;
ee0e1df5   Alexey Boroda   -Statistics half ...
9
10
      use yii\data\ActiveDataProvider;
      use yii\helpers\ArrayHelper;
c130fad8   Alexey Boroda   -Yml fix
11
      use yii\helpers\Html;
44747138   Alexey Boroda   -Default statisti...
12
      use yii\helpers\StringHelper;
d7331490   Alexey Boroda   -Export ready
13
      use yii\helpers\Url;
1ac35977   Alexey Boroda   -Staistics started
14
      use yii\web\View;
44747138   Alexey Boroda   -Default statisti...
15
      use yiier\chartjs\ChartJs;
1ac35977   Alexey Boroda   -Staistics started
16
17
      
      /**
44747138   Alexey Boroda   -Default statisti...
18
19
       * @var View               $this
       * @var Label[]            $labels
29257441   Alexey Boroda   -Manager filter o...
20
       * @var User[]             $managers
44747138   Alexey Boroda   -Default statisti...
21
22
       * @var array              $labelStatistics
       * @var array              $rejectionStatistics
ee0e1df5   Alexey Boroda   -Statistics half ...
23
       * @var ActiveDataProvider $dataProvider
cbc8daa9   Alexey Boroda   -Order history ready
24
25
26
       * @var array              $labelChartData1
       * @var array              $labelChartData2
       * @var array              $labelChartData3
29257441   Alexey Boroda   -Manager filter o...
27
28
       * @var array              $rejectChartData1
       * @var array              $rejectChartData2
44747138   Alexey Boroda   -Default statisti...
29
30
       * @var string             $dateValue
       * @var int | boolean      $dataLabel
29257441   Alexey Boroda   -Manager filter o...
31
       * @var int | boolean      $dataManager
1ac35977   Alexey Boroda   -Staistics started
32
       */
894d945a   Alexey Boroda   -Logs bu fix and ...
33
34
35
36
37
38
39
40
41
42
43
44
      
      $this->registerJsFile(
          '/admin/js/statistics.js',
          [
              'position' => View::POS_END,
              'depends'  => 'yii\web\JqueryAsset',
          ]
      );
      
      $this->title = 'Статистика заказов';
      
      $this->params['breadcrumbs'][] = $this->title;
29257441   Alexey Boroda   -Manager filter o...
45
  
1ac35977   Alexey Boroda   -Staistics started
46
47
48
49
  ?>
  
  <div class="box box-default">
    <div class="box-header with-border">
cbc8daa9   Alexey Boroda   -Order history ready
50
      <h3 class="box-title">Поиск заказов</h3>
1ac35977   Alexey Boroda   -Staistics started
51
52
53
54
55
      <div class="box-tools pull-right">
        <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
      </div><!-- /.box-tools -->
    </div><!-- /.box-header -->
    <div class="box-body">
ee0e1df5   Alexey Boroda   -Statistics half ...
56
57
58
59
60
        <?= Html::beginForm(
            [ '/ecommerce/statistics' ],
            'get'
        ) ?>
      <div class="row">
29257441   Alexey Boroda   -Manager filter o...
61
        <div class="col-md-3">
ee0e1df5   Alexey Boroda   -Statistics half ...
62
63
64
            <?= DateRangePicker::widget(
                [
                    'name'          => 'date_range',
44747138   Alexey Boroda   -Default statisti...
65
                    'value'         => $dateValue,
ee0e1df5   Alexey Boroda   -Statistics half ...
66
67
68
69
70
71
72
73
74
                    'pluginOptions' => [
                        'locale' => [
                            'format'    => 'DD-MM-Y',
                            'separator' => ' : ',
                        ],
                    ],
                ]
            ) ?>
        </div>
29257441   Alexey Boroda   -Manager filter o...
75
        <div class="col-md-4">
ee0e1df5   Alexey Boroda   -Statistics half ...
76
77
            <?= Select2::widget(
                [
cbc8daa9   Alexey Boroda   -Order history ready
78
79
80
                    'name'          => 'label',
                    'value'         => $dataLabel,
                    'data'          => ArrayHelper::map(
ee0e1df5   Alexey Boroda   -Statistics half ...
81
82
83
84
85
86
87
88
                        $labels,
                        function($model) {
                            return $model->id;
                        },
                        function($model) {
                            return $model->lang->title;
                        }
                    ),
cbc8daa9   Alexey Boroda   -Order history ready
89
                    'options'       => [
29257441   Alexey Boroda   -Manager filter o...
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
                        'placeholder' => 'Все метки',
                    ],
                    'pluginOptions' => [
                        'allowClear' => true,
                    ],
                ]
            ) ?>
        </div>
        <div class="col-md-3">
            <?= Select2::widget(
                [
                    'name'          => 'manager',
                    'value'         => $dataManager,
                    'data'          => ArrayHelper::map(
                        $managers,
                        function(User $model) {
                            return $model->id;
                        },
                        function(User $model) {
                            return $model->username;
                        }
                    ),
                    'options'       => [
                        'placeholder' => 'Все менеджеры',
ee0e1df5   Alexey Boroda   -Statistics half ...
114
                    ],
44747138   Alexey Boroda   -Default statisti...
115
                    'pluginOptions' => [
cbc8daa9   Alexey Boroda   -Order history ready
116
                        'allowClear' => true,
44747138   Alexey Boroda   -Default statisti...
117
                    ],
ee0e1df5   Alexey Boroda   -Statistics half ...
118
119
120
121
122
                ]
            ) ?>
        </div>
        <div class="col-md-2">
            <?= Html::submitButton(
cbc8daa9   Alexey Boroda   -Order history ready
123
                'Поиск',
ee0e1df5   Alexey Boroda   -Statistics half ...
124
125
126
127
128
129
                [
                    'class' => 'btn btn-success',
                ]
            ) ?>
        </div>
      </div>
c130fad8   Alexey Boroda   -Yml fix
130
        <?= Html::endForm() ?>
1ac35977   Alexey Boroda   -Staistics started
131
132
    </div><!-- /.box-body -->
  </div><!-- /.box -->
ee0e1df5   Alexey Boroda   -Statistics half ...
133
134
135
  
  <div class="box box-default">
    <div class="box-header with-border">
29257441   Alexey Boroda   -Manager filter o...
136
      <h3 class="box-title">Метки, статистика за <?= empty($dateValue) ? 'всё время' : $dateValue ?></h3>
ee0e1df5   Alexey Boroda   -Statistics half ...
137
138
139
140
141
142
143
144
145
146
147
148
149
150
      <div class="box-tools pull-right">
        <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
      </div><!-- /.box-tools -->
    </div><!-- /.box-header -->
    <div class="box-body table-responsive no-padding">
      <table class="table table-hover">
        <tr>
          <td><b>Метка</b></td>
          <td><b>Заказов, шт.</b></td>
          <td><b>На сумму, грн.</b></td>
          <td><b>Заказано товаров, шт.</b></td>
          <td><b>Уникальных товаров, шт.</b></td>
        </tr>
          <?php
894d945a   Alexey Boroda   -Logs bu fix and ...
151
152
153
154
              $total_count = 0;
              $total_sum = 0;
              $total_products = 0;
              $total_unique = 0;
ee0e1df5   Alexey Boroda   -Statistics half ...
155
              foreach ($labelStatistics as $name => $statistic) {
894d945a   Alexey Boroda   -Logs bu fix and ...
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
                  if ($statistic) {
                      $link = Html::a(
                          $name,
                          [
                              'view',
                              'id'      => $statistic[ 'label' ],
                              'manager' => $dataManager,
                              'date'    => $dateValue,
                          ],
                          [
                            'target' => '_blank',
                          ]
                      );
                  } else {
                      $link = $name;
                  }
d9fd9ce5   Alexey Boroda   -Total for statis...
172
173
174
175
                  $total_count += $statistic[ 'count' ];
                  $total_sum += $statistic[ 'sum' ];
                  $total_products += $statistic[ 'products' ];
                  $total_unique += $statistic[ 'unique' ];
44747138   Alexey Boroda   -Default statisti...
176
177
                  echo Html::tag(
                      'tr',
894d945a   Alexey Boroda   -Logs bu fix and ...
178
179
180
181
                      Html::tag(
                          'td',
                          $link
                      ) . Html::tag('td', $statistic[ 'count' ]) . Html::tag(
44747138   Alexey Boroda   -Default statisti...
182
183
184
185
                          'td',
                          $statistic[ 'sum' ]
                      ) . Html::tag('td', $statistic[ 'products' ]) . Html::tag('td', $statistic[ 'unique' ])
                  );
d9fd9ce5   Alexey Boroda   -Total for statis...
186
              }
894d945a   Alexey Boroda   -Logs bu fix and ...
187
          ?>
d9fd9ce5   Alexey Boroda   -Total for statis...
188
189
        <tr>
          <td><b>Всего</b></td>
894d945a   Alexey Boroda   -Logs bu fix and ...
190
191
192
193
          <td><b><?= $total_count ?></b></td>
          <td><b><?= $total_sum ?></b></td>
          <td><b><?= $total_products ?></b></td>
          <td><b><?= $total_unique ?></b></td>
d9fd9ce5   Alexey Boroda   -Total for statis...
194
        </tr>
ee0e1df5   Alexey Boroda   -Statistics half ...
195
      </table>
ee0e1df5   Alexey Boroda   -Statistics half ...
196
    </div><!-- /.box-body -->
29257441   Alexey Boroda   -Manager filter o...
197
  
cbc8daa9   Alexey Boroda   -Order history ready
198
199
200
201
202
    <div class="box-footer">
      <div class="nav-tabs-custom">
  
        <!-- Nav tabs -->
        <ul class="nav nav-tabs" role="tablist">
29257441   Alexey Boroda   -Manager filter o...
203
204
          <li role="presentation" class="active">
            <a href="#home" aria-controls="home" role="tab" data-toggle="tab">Заказы</a></li>
cbc8daa9   Alexey Boroda   -Order history ready
205
          <li role="presentation"><a href="#profile" aria-controls="profile" role="tab" data-toggle="tab">Сумма</a></li>
29257441   Alexey Boroda   -Manager filter o...
206
207
          <li role="presentation"><a href="#messages" aria-controls="messages" role="tab" data-toggle="tab">Товары</a>
          </li>
cbc8daa9   Alexey Boroda   -Order history ready
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
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
280
281
282
283
284
285
286
287
288
289
290
        </ul>
  
        <!-- Tab panes -->
        <div class="tab-content">
          <div role="tabpanel" class="tab-pane active" id="home">
              <?= ChartJs::widget(
                  [
                      'type'          => 'bar',
                      'options'       => [
                          'height' => 200,
                          'width'  => 600,
                      ],
                      'data'          => $labelChartData1,
                      'clientOptions' => [
                          'title'  => [
                              'display' => true,
                              'text'    => 'Статистика меток',
                          ],
                          'scales' => [
                              'xAxes' => [
                                  [
                                      'display' => false,
                                  ],
                              ],
                          ],
                      ],
                  ]
              ); ?>
          </div>
          <div role="tabpanel" class="tab-pane" id="profile">
              <?= ChartJs::widget(
                  [
                      'type'          => 'bar',
                      'options'       => [
                          'height' => 200,
                          'width'  => 600,
                      ],
                      'data'          => $labelChartData2,
                      'clientOptions' => [
                          'title'  => [
                              'display' => true,
                              'text'    => 'Статистика меток',
                          ],
                          'scales' => [
                              'xAxes' => [
                                  [
                                      'display' => false,
                                  ],
                              ],
                          ],
                      ],
                  ]
              ); ?>
          </div>
          <div role="tabpanel" class="tab-pane" id="messages">
              <?= ChartJs::widget(
                  [
                      'type'          => 'bar',
                      'options'       => [
                          'height' => 200,
                          'width'  => 600,
                      ],
                      'data'          => $labelChartData3,
                      'clientOptions' => [
                          'title'  => [
                              'display' => true,
                              'text'    => 'Статистика меток',
                          ],
                          'scales' => [
                              'xAxes' => [
                                  [
                                      'display' => false,
                                  ],
                              ],
                          ],
                      ],
                  ]
              ); ?>
          </div>
        </div>
  
      </div>
    </div>
ee0e1df5   Alexey Boroda   -Statistics half ...
291
292
293
294
  </div><!-- /.box -->
  
  <div class="box box-default">
    <div class="box-header with-border">
29257441   Alexey Boroda   -Manager filter o...
295
      <h3 class="box-title">Причины отказа, статистика за <?= empty($dateValue) ? 'всё время' : $dateValue ?></h3>
ee0e1df5   Alexey Boroda   -Statistics half ...
296
297
298
299
300
301
302
303
304
305
306
307
308
      <div class="box-tools pull-right">
        <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
      </div><!-- /.box-tools -->
    </div><!-- /.box-header -->
    <div class="box-body table-responsive no-padding">
      <table class="table table-hover">
        <tr>
          <td><b>Причина</b></td>
          <td><b>Заказов, шт.</b></td>
          <td><b>На сумму, грн.</b></td>
        </tr>
          <?php
              foreach ($rejectionStatistics as $name => $statistic) {
44747138   Alexey Boroda   -Default statisti...
309
310
311
312
313
314
315
316
317
                  echo Html::tag(
                      'tr',
                      Html::tag('td', $name) . Html::tag('td', $statistic[ 'count' ]) . Html::tag(
                          'td',
                          $statistic[ 'sum' ]
                      )
                  );
              }
          ?>
ee0e1df5   Alexey Boroda   -Statistics half ...
318
319
      </table>
    </div><!-- /.box-body -->
29257441   Alexey Boroda   -Manager filter o...
320
  
cbc8daa9   Alexey Boroda   -Order history ready
321
322
    <div class="box-footer">
      <div class="nav-tabs-custom">
ee0e1df5   Alexey Boroda   -Statistics half ...
323
  
cbc8daa9   Alexey Boroda   -Order history ready
324
325
        <!-- Nav tabs -->
        <ul class="nav nav-tabs" role="tablist">
29257441   Alexey Boroda   -Manager filter o...
326
327
          <li role="presentation" class="active">
            <a href="#count" aria-controls="count" role="tab" data-toggle="tab">Заказы</a></li>
cbc8daa9   Alexey Boroda   -Order history ready
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
          <li role="presentation"><a href="#sum" aria-controls="sum" role="tab" data-toggle="tab">Сумма</a></li>
        </ul>
  
        <!-- Tab panes -->
        <div class="tab-content">
          <div role="tabpanel" class="tab-pane active" id="count">
              <?= ChartJs::widget(
                  [
                      'type'          => 'bar',
                      'options'       => [
                          'height' => 200,
                          'width'  => 600,
                      ],
                      'data'          => $rejectChartData1,
                      'clientOptions' => [
                          'title'  => [
                              'display' => true,
                              'text'    => 'Статистика отказов',
                          ],
                          'scales' => [
                              'xAxes' => [
                                  [
                                      'display' => false,
                                  ],
                              ],
                          ],
                      ],
                  ]
              ); ?>
          </div>
          <div role="tabpanel" class="tab-pane" id="sum">
              <?= ChartJs::widget(
                  [
                      'type'          => 'bar',
                      'options'       => [
                          'height' => 200,
                          'width'  => 600,
                      ],
                      'data'          => $rejectChartData2,
                      'clientOptions' => [
                          'title'  => [
                              'display' => true,
                              'text'    => 'Статистика отказов',
ee0e1df5   Alexey Boroda   -Statistics half ...
371
                          ],
cbc8daa9   Alexey Boroda   -Order history ready
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
                          'scales' => [
                              'xAxes' => [
                                  [
                                      'display' => false,
                                  ],
                              ],
                          ],
                      ],
                  ]
              ); ?>
          </div>
        </div>
  
      </div>
    </div>
29257441   Alexey Boroda   -Manager filter o...
387
  
cbc8daa9   Alexey Boroda   -Order history ready
388
389
  </div><!-- /.box -->
  
d7331490   Alexey Boroda   -Export ready
390
  <p>
894d945a   Alexey Boroda   -Logs bu fix and ...
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
      <?php
          echo Html::button(
              Html::tag(
                  'i',
                  '',
                  [
                      'class' => 'glyphicon glyphicon-cog',
                  ]
              ) . ' Создать выгрузку',
              [
                  'class'     => 'btn bg-navy',
                  'id'        => 'generate-button',
                  'data-link' => Url::to(
                      [
                          'export',
                          'date_range' => $dateValue,
                          'label'      => $dataLabel,
                          'manager'    => $dataManager,
                      ]
                  ),
              ]
          )
      ?>
d7331490   Alexey Boroda   -Export ready
414
  </p>
cbc8daa9   Alexey Boroda   -Order history ready
415
416
417
  <div class="box box-default">
    <div class="box-header with-border">
      <h3 class="box-title">Заказы</h3>
894d945a   Alexey Boroda   -Logs bu fix and ...
418
  
cbc8daa9   Alexey Boroda   -Order history ready
419
420
421
422
423
424
425
426
427
428
      <div class="box-tools pull-right">
        <button class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i></button>
      </div><!-- /.box-tools -->
    </div><!-- /.box-header -->
    <div class="box-body table-responsive">
        <?= GridView::widget(
            [
                'dataProvider' => $dataProvider,
                'columns'      => [
                    'id',
ca6a6b40   Alexey Boroda   -Date format for ...
429
                    [
894d945a   Alexey Boroda   -Logs bu fix and ...
430
431
432
433
434
435
                        'label'   => 'Дата добавления',
                        'content' => function(Order $model) {
                            return \Yii::$app->formatter->asDate(
                                    $model->created_at
                                ) . '<br>' . \Yii::$app->formatter->asTime($model->created_at);
                        },
ca6a6b40   Alexey Boroda   -Date format for ...
436
                    ],
cbc8daa9   Alexey Boroda   -Order history ready
437
                    'name',
5c177682   Alexey Boroda   -Order history ready
438
                    [
29257441   Alexey Boroda   -Manager filter o...
439
                        'label'   => 'Товары',
5c177682   Alexey Boroda   -Order history ready
440
                        'content' => function(Order $model) {
29257441   Alexey Boroda   -Manager filter o...
441
442
443
444
445
446
                            if (empty($model->products)) {
                                return '';
                            } else {
                                $content = '';
                                $i = 0;
                                foreach ($model->products as $product) {
894d945a   Alexey Boroda   -Logs bu fix and ...
447
448
449
450
451
                                    if (empty($product->productVariant)) {
                                        $image = '';
                                    } else {
                                        $image = $product->productVariant->imageUrl;
                                    }
29257441   Alexey Boroda   -Manager filter o...
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
                                    $i++;
                                    $content .= Html::a(
                                        $product->sku,
                                        '#',
                                        [
                                            'onclick'        => 'event.preventDefault();',
                                            'data-toggle'    => 'popover',
                                            'data-placement' => 'right',
                                            'data-html'      => 'true',
                                            'data-content'   => Html::img(
                                                    $image,
                                                    [
                                                        'class' => 'img-rounded',
                                                    ]
                                                ) . Html::tag('p', $product->product_name),
                                        ]
                                    );
                                    if ($i != count($model->products)) {
                                        $content .= ', ';
                                    }
                                    if ($i % 2 == 0) {
                                        $content .= '<br>';
                                    }
                                }
                                return $content;
5c177682   Alexey Boroda   -Order history ready
477
                            }
29257441   Alexey Boroda   -Manager filter o...
478
                        },
5c177682   Alexey Boroda   -Order history ready
479
                    ],
cbc8daa9   Alexey Boroda   -Order history ready
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
                    'city',
                    [
                        'attribute' => 'orderLabel.label',
                        'label'     => 'Метка',
                    ],
                    'total',
                    [
                        'attribute' => 'reason',
                        'content'   => function($model) {
                            /**
                             * @var Order $model
                             */
                            if (empty($model->reason)) {
                                return '';
                            } else {
                                return Order::REASONS[ $model->reason ];
                            }
                        },
                    ],
                    [
                        'attribute' => 'manager.username',
                        'label'     => 'Менеджер',
                    ],
                    [
                        'attribute' => 'body',
                        'content'   => function($model) {
                            /**
                             * @var Order $model
                             */
                            if (empty($model->body)) {
                                return '';
                            } else {
                                return Html::a(
                                    StringHelper::truncate($model->body, 10, '...'),
                                    '#',
                                    [
                                        'data-toggle' => 'tooltip',
                                        'title'       => $model->body,
                                        'onclick'     => 'event.preventDefault();',
                                    ]
                                );
                            }
                        },
                    ],
                    [
                        'content' => function($model) {
                            /**
                             * @var Order $model
                             */
                            return Html::a(
                                Html::tag('i', '', [ 'class' => 'glyphicon glyphicon-eye-open' ]),
                                [
                                    '/ecommerce/order/view',
                                    'id' => $model->id,
                                ],
                                [
                                    'target'    => '_blank',
                                    'data-pjax' => '0',
                                ]
                            );
                        },
                    ],
                ],
            ]
        ) ?>
  
    </div><!-- /.box-body -->
  </div><!-- /.box -->