Blame view

views/statistics/view.php 6.16 KB
894d945a   Alexey Boroda   -Logs bu fix and ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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
160
  <?php
      use artweb\artbox\ecommerce\models\Label;
      use artweb\artbox\ecommerce\models\Order;
      use kartik\grid\GridView;
      use yii\data\ActiveDataProvider;
      use yii\helpers\Html;
      use yii\helpers\StringHelper;
      use yii\web\View;
      
      /**
       * @var ActiveDataProvider $dataProvider
       * @var View               $this
       * @var Label              $label
       */
      
      $this->title = 'Статистика по метке: ' . $label->lang->title;
      
      $this->params['breadcrumbs'][] = [
        'url' => ['index'],
        'label' => 'Статистика заказов',
      ];
      $this->params['breadcrumbs'][] = $this->title;
      
      $js = <<< JS
   $('[data-toggle="popover"]').popover();
  JS;
  $this->registerJs($js, View::POS_READY);
    
  ?>
  
  <div class="box box-default">
    <div class="box-header with-border">
      <h3 class="box-title"><?=$this->title?></h3>
    </div><!-- /.box-header -->
    <div class="box-body">
      
        <?= GridView::widget(
            [
                'dataProvider' => $dataProvider,
                'columns'      => [
                    'id',
                    [
                        'label'   => 'Дата добавления',
                        'content' => function(Order $model) {
                            return \Yii::$app->formatter->asDate(
                                    $model->created_at
                                ) . '<br>' . \Yii::$app->formatter->asTime($model->created_at);
                        },
                    ],
                    'name',
                    [
                        'label'   => 'Товары',
                        'content' => function(Order $model) {
                            if (empty($model->products)) {
                                return '';
                            } else {
                                $content = '';
                                $i = 0;
                                foreach ($model->products as $product) {
                                    if (empty($product->productVariant)) {
                                        $image = '';
                                    } else {
                                        $image = $product->productVariant->imageUrl;
                                    }
                                    $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;
                            }
                        },
                    ],
                    '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>
  </div>