Commit ce75bc1d5faf2be681e54cf9885b9f1919f0a8e0
1 parent
ccfc5763
-Grid view half way done
Showing
2 changed files
with
121 additions
and
47 deletions
Show diff stats
models/Order.php
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | * @property integer $updated_at |
16 | 16 | * @property integer $deleted_at |
17 | 17 | * @property integer $deadline |
18 | + * @property boolean $wasted | |
18 | 19 | * @property integer $reason |
19 | 20 | * @property string $check |
20 | 21 | * @property string $sms |
... | ... | @@ -209,7 +210,7 @@ |
209 | 210 | */ |
210 | 211 | public function getOrderLabel() |
211 | 212 | { |
212 | - return $this->hasOne(Label::className(), [ 'id' => 'status' ]); | |
213 | + return $this->hasOne(Label::className(), [ 'id' => 'label' ]); | |
213 | 214 | } |
214 | 215 | |
215 | 216 | /** |
... | ... | @@ -235,5 +236,18 @@ |
235 | 236 | return ''; |
236 | 237 | } |
237 | 238 | } |
238 | - | |
239 | + | |
240 | + /** | |
241 | + * If deadline is fucked up returns true, | |
242 | + * if deadline is not setted return false, like everything is ok | |
243 | + * @return bool | |
244 | + */ | |
245 | + public function getWasted() | |
246 | + { | |
247 | + if (empty($this->deadline)) { | |
248 | + return false; | |
249 | + } else { | |
250 | + return time() > $this->deadline; | |
251 | + } | |
252 | + } | |
239 | 253 | } |
240 | 254 | \ No newline at end of file | ... | ... |
views/order/index.php
... | ... | @@ -7,12 +7,14 @@ |
7 | 7 | |
8 | 8 | use artweb\artbox\ecommerce\models\Delivery; |
9 | 9 | use artweb\artbox\ecommerce\models\Label; |
10 | + use artweb\artbox\ecommerce\models\Order; | |
10 | 11 | use artweb\artbox\ecommerce\models\OrderSearch; |
11 | 12 | use kartik\daterange\DateRangePicker; |
12 | 13 | use kartik\select2\Select2; |
13 | 14 | use yii\data\ActiveDataProvider; |
14 | 15 | use yii\helpers\Html; |
15 | - use yii\grid\GridView; | |
16 | + use kartik\grid\GridView; | |
17 | + use yii\helpers\StringHelper; | |
16 | 18 | use yii\helpers\Url; |
17 | 19 | use yii\web\View; |
18 | 20 | use yii\widgets\ActiveForm; |
... | ... | @@ -60,11 +62,16 @@ JS; |
60 | 62 | 'model' => $searchModel, |
61 | 63 | 'attribute' => 'label', |
62 | 64 | 'data' => Label::find() |
63 | - ->joinWith('lang') | |
64 | - ->select(['CONCAT(order_label.label,order_label_lang.title) AS name', 'id']) | |
65 | - ->indexBy('id') | |
66 | - ->asArray() | |
67 | - ->column(), | |
65 | + ->joinWith('lang') | |
66 | + ->select( | |
67 | + [ | |
68 | + 'CONCAT(order_label.label,order_label_lang.title) AS name', | |
69 | + 'id', | |
70 | + ] | |
71 | + ) | |
72 | + ->indexBy('id') | |
73 | + ->asArray() | |
74 | + ->column(), | |
68 | 75 | 'options' => [ 'placeholder' => 'Select a state ...' ], |
69 | 76 | 'pluginOptions' => [ |
70 | 77 | 'allowClear' => true, |
... | ... | @@ -94,47 +101,100 @@ JS; |
94 | 101 | ); |
95 | 102 | ?> |
96 | 103 | <p> |
97 | -<?php | |
98 | - echo GridView::widget( | |
99 | - [ | |
100 | - 'dataProvider' => $dataProvider, | |
101 | - 'filterModel' => $searchModel, | |
102 | - 'columns' => [ | |
103 | - [ | |
104 | - 'attribute' => 'id', | |
105 | - 'filter' => $searchForm->field($searchModel, 'id') | |
106 | - ->textInput(), | |
107 | - ], | |
108 | - [ | |
109 | - 'attribute' => 'created_at', | |
110 | - 'format' => 'date', | |
111 | - 'filter' => $searchForm->field($searchModel, 'date_range') | |
112 | - ->widget( | |
113 | - DateRangePicker::className(), | |
114 | - [ | |
115 | - 'convertFormat' => false, | |
116 | - 'pluginOptions' => [ | |
117 | - 'locale' => [ | |
118 | - 'format' => 'D-M-Y', | |
119 | - 'separator' => ' to ', | |
104 | + <?php | |
105 | + echo GridView::widget( | |
106 | + [ | |
107 | + 'dataProvider' => $dataProvider, | |
108 | + 'filterModel' => $searchModel, | |
109 | + 'rowOptions' => function($model) { | |
110 | + if ($model->wasted) { | |
111 | + return [ 'class' => 'danger' ]; | |
112 | + } else { | |
113 | + return []; | |
114 | + } | |
115 | + }, | |
116 | + 'columns' => [ | |
117 | + [ | |
118 | + 'attribute' => 'id', | |
119 | + 'filter' => $searchForm->field($searchModel, 'id') | |
120 | + ->textInput(), | |
121 | + ], | |
122 | + [ | |
123 | + 'attribute' => 'created_at', | |
124 | + 'format' => 'date', | |
125 | + 'filter' => $searchForm->field($searchModel, 'date_range') | |
126 | + ->widget( | |
127 | + DateRangePicker::className(), | |
128 | + [ | |
129 | + 'convertFormat' => false, | |
130 | + 'pluginOptions' => [ | |
131 | + 'locale' => [ | |
132 | + 'format' => 'D-M-Y', | |
133 | + 'separator' => ' to ', | |
134 | + ], | |
135 | + 'opens' => 'left', | |
120 | 136 | ], |
121 | - 'opens' => 'left', | |
122 | - ], | |
123 | - ] | |
124 | - ) | |
125 | - ->label(false) | |
126 | - ->render(), | |
127 | - ], | |
128 | - 'name', | |
129 | - 'phone', | |
130 | - 'status', | |
131 | - [ | |
132 | - 'class' => 'yii\grid\ActionColumn', | |
137 | + ] | |
138 | + ) | |
139 | + ->label(false) | |
140 | + ->render(), | |
141 | + ], | |
142 | + [ | |
143 | + 'attribute' => 'deadline', | |
144 | + 'content' => function($model) { | |
145 | + if ($model->deadline == ''){ | |
146 | + return ''; | |
147 | + } else { | |
148 | + return \Yii::$app->formatter->asDate($model->deadline); | |
149 | + } | |
150 | + } | |
151 | + ], | |
152 | + 'name', | |
153 | + 'total', | |
154 | + [ | |
155 | + 'attribute' => 'pay', | |
156 | + 'content' => function($model) { | |
157 | + if ($model->pay == false) { | |
158 | + return '<span class="glyphicon glyphicon-remove"></span>'; | |
159 | + } else { | |
160 | + return '<span class="glyphicon glyphicon-ok"></span>'; | |
161 | + } | |
162 | + }, | |
163 | + ], | |
164 | + 'phone', | |
165 | + 'adress', | |
166 | + [ | |
167 | + 'attribute' => 'label', | |
168 | + 'value' => function($model) { | |
169 | + /** | |
170 | + * @var Order $modl | |
171 | + */ | |
172 | + if (empty( $model->orderLabel )) { | |
173 | + return '--'; | |
174 | + } else { | |
175 | + return $model->orderLabel->label; | |
176 | + } | |
177 | + }, | |
178 | + ], | |
179 | + | |
180 | + [ | |
181 | + 'attribute' => 'body', | |
182 | + 'content' => function($model) { | |
183 | + if (!empty( $model->body )) { | |
184 | + return StringHelper::truncate($model->body, 8, '...'); | |
185 | + } else { | |
186 | + return ''; | |
187 | + } | |
188 | + }, | |
189 | + ], | |
190 | + 'sms', | |
191 | + [ | |
192 | + 'class' => 'yii\grid\ActionColumn', | |
193 | + ], | |
133 | 194 | ], |
134 | - ], | |
135 | - ] | |
136 | - ); | |
137 | -?> | |
195 | + ] | |
196 | + ); | |
197 | + ?> | |
138 | 198 | </p> |
139 | 199 | <?php |
140 | 200 | ActiveForm::end(); | ... | ... |