Commit 8de5e9b394a4c946a726f5b04188073f0d51f309
Merge remote-tracking branch 'origin/Credits' into statistics
# Conflicts: # models/Order.php
Showing
4 changed files
with
426 additions
and
328 deletions
Show diff stats
controllers/OrderController.php
@@ -6,12 +6,14 @@ | @@ -6,12 +6,14 @@ | ||
6 | use artweb\artbox\ecommerce\models\OrderLabelHistory; | 6 | use artweb\artbox\ecommerce\models\OrderLabelHistory; |
7 | use artweb\artbox\ecommerce\models\OrderLog; | 7 | use artweb\artbox\ecommerce\models\OrderLog; |
8 | use artweb\artbox\ecommerce\models\OrderSearch; | 8 | use artweb\artbox\ecommerce\models\OrderSearch; |
9 | + use common\components\CreditHelper; | ||
9 | use common\models\User; | 10 | use common\models\User; |
10 | use Yii; | 11 | use Yii; |
11 | use yii\data\ArrayDataProvider; | 12 | use yii\data\ArrayDataProvider; |
12 | use yii\db\ActiveQuery; | 13 | use yii\db\ActiveQuery; |
13 | use yii\helpers\Json; | 14 | use yii\helpers\Json; |
14 | use yii\helpers\VarDumper; | 15 | use yii\helpers\VarDumper; |
16 | + use yii\validators\NumberValidator; | ||
15 | use yii\web\Controller; | 17 | use yii\web\Controller; |
16 | use yii\filters\VerbFilter; | 18 | use yii\filters\VerbFilter; |
17 | use yii\data\ActiveDataProvider; | 19 | use yii\data\ActiveDataProvider; |
@@ -351,6 +353,18 @@ | @@ -351,6 +353,18 @@ | ||
351 | 353 | ||
352 | $model = $this->findModel($id); | 354 | $model = $this->findModel($id); |
353 | 355 | ||
356 | + if ($model->payment == 10) { | ||
357 | + $model->validators->append( | ||
358 | + new NumberValidator( | ||
359 | + [ | ||
360 | + 'attributes' => 'credit_sum', | ||
361 | + 'max' => $model->total - CreditHelper::MIN_CREDIT_SUM, | ||
362 | + 'min' => $model->total - CreditHelper::MAX_CREDIT_SUM, | ||
363 | + ] | ||
364 | + ) | ||
365 | + ); | ||
366 | + } | ||
367 | + | ||
354 | /** | 368 | /** |
355 | * @var User $user | 369 | * @var User $user |
356 | */ | 370 | */ |
models/Basket.php
@@ -10,6 +10,7 @@ | @@ -10,6 +10,7 @@ | ||
10 | /** | 10 | /** |
11 | * Class Basket to work with basket | 11 | * Class Basket to work with basket |
12 | * | 12 | * |
13 | + * @property bool isCredit | ||
13 | * @package artweb\artbox\ecommerce\models | 14 | * @package artweb\artbox\ecommerce\models |
14 | */ | 15 | */ |
15 | class Basket extends Component | 16 | class Basket extends Component |
@@ -32,7 +33,7 @@ | @@ -32,7 +33,7 @@ | ||
32 | $this->session = \Yii::$app->session; | 33 | $this->session = \Yii::$app->session; |
33 | if (!$this->session->has('basket')) { | 34 | if (!$this->session->has('basket')) { |
34 | $this->session->set('basket', []); | 35 | $this->session->set('basket', []); |
35 | - } elseif(!empty($this->session->get('basket'))) { | 36 | + } elseif (!empty( $this->session->get('basket') )) { |
36 | $cookies = \Yii::$app->response->cookies; | 37 | $cookies = \Yii::$app->response->cookies; |
37 | $cookies->add( | 38 | $cookies->add( |
38 | new Cookie( | 39 | new Cookie( |
@@ -144,8 +145,9 @@ | @@ -144,8 +145,9 @@ | ||
144 | { | 145 | { |
145 | $this->session->set('basket', $data); | 146 | $this->session->set('basket', $data); |
146 | $cookies = \Yii::$app->response->cookies; | 147 | $cookies = \Yii::$app->response->cookies; |
147 | - if(empty($data)) { | 148 | + if (empty( $data )) { |
148 | $cookies->remove('basket'); | 149 | $cookies->remove('basket'); |
150 | + $cookies->remove('isCredit'); | ||
149 | } else { | 151 | } else { |
150 | $cookies->add( | 152 | $cookies->add( |
151 | new Cookie( | 153 | new Cookie( |
@@ -247,6 +249,23 @@ | @@ -247,6 +249,23 @@ | ||
247 | public function clear() | 249 | public function clear() |
248 | { | 250 | { |
249 | $this->setData([]); | 251 | $this->setData([]); |
252 | + \Yii::$app->response->cookies->remove('isCredit'); | ||
253 | + } | ||
254 | + | ||
255 | + /** | ||
256 | + * Check if is credit cookie flag set | ||
257 | + * | ||
258 | + * @return bool | ||
259 | + */ | ||
260 | + public static function getIsCredit(): bool | ||
261 | + { | ||
262 | + // Get cookies from global in order to skip yii2 cookie validation | ||
263 | + $cookies = $_COOKIE; | ||
264 | + if (isset( $cookies[ 'isCredit' ] )) { | ||
265 | + return true; | ||
266 | + } else { | ||
267 | + return false; | ||
268 | + } | ||
250 | } | 269 | } |
251 | 270 | ||
252 | } | 271 | } |
models/Order.php
@@ -61,6 +61,8 @@ | @@ -61,6 +61,8 @@ | ||
61 | * @property Delivery $orderDelivery | 61 | * @property Delivery $orderDelivery |
62 | * @property OrderPayment $orderPayment | 62 | * @property OrderPayment $orderPayment |
63 | * @property OrderLog[] $logs | 63 | * @property OrderLog[] $logs |
64 | + * @property float $credit_sum | ||
65 | + * @property int $credit_month | ||
64 | */ | 66 | */ |
65 | class Order extends ActiveRecord | 67 | class Order extends ActiveRecord |
66 | { | 68 | { |
@@ -214,6 +216,21 @@ | @@ -214,6 +216,21 @@ | ||
214 | ], | 216 | ], |
215 | [ | 217 | [ |
216 | [ | 218 | [ |
219 | + 'credit_month', | ||
220 | + ], | ||
221 | + 'integer', | ||
222 | + 'min' => 3, | ||
223 | + 'max' => 36, | ||
224 | + ], | ||
225 | + [ | ||
226 | + [ | ||
227 | + 'credit_sum', | ||
228 | + ], | ||
229 | + 'number', | ||
230 | + 'min' => 0, | ||
231 | + ], | ||
232 | + [ | ||
233 | + [ | ||
217 | 'deadline', | 234 | 'deadline', |
218 | 'name', | 235 | 'name', |
219 | 'numbercard', | 236 | 'numbercard', |
@@ -348,6 +365,8 @@ | @@ -348,6 +365,8 @@ | ||
348 | 'shipping_by' => Yii::t('app', 'Отправка за счет'), | 365 | 'shipping_by' => Yii::t('app', 'Отправка за счет'), |
349 | 'city' => Yii::t('app', 'Город'), | 366 | 'city' => Yii::t('app', 'Город'), |
350 | 'numbercard' => Yii::t('app', '№ карточки'), | 367 | 'numbercard' => Yii::t('app', '№ карточки'), |
368 | + 'credit_month' => Yii::t('app', 'Количество месяцев'), | ||
369 | + 'credit_sum' => Yii::t('app', 'Первоначальный взнос'), | ||
351 | ]; | 370 | ]; |
352 | } | 371 | } |
353 | 372 |
views/order/_form.php
@@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
5 | use artweb\artbox\ecommerce\models\OrderPayment; | 5 | use artweb\artbox\ecommerce\models\OrderPayment; |
6 | use artweb\artbox\ecommerce\models\OrderProduct; | 6 | use artweb\artbox\ecommerce\models\OrderProduct; |
7 | use backend\models\SmsTemplate; | 7 | use backend\models\SmsTemplate; |
8 | + use common\components\CreditHelper; | ||
8 | use common\models\User; | 9 | use common\models\User; |
9 | use kartik\grid\GridView; | 10 | use kartik\grid\GridView; |
10 | use kartik\grid\SerialColumn; | 11 | use kartik\grid\SerialColumn; |
@@ -144,8 +145,8 @@ JS; | @@ -144,8 +145,8 @@ JS; | ||
144 | 145 | ||
145 | <?php $form = ActiveForm::begin( | 146 | <?php $form = ActiveForm::begin( |
146 | [ | 147 | [ |
147 | - 'id' => 'main-form', | ||
148 | -// 'options' => [ 'class' => 'form-inline' ], | 148 | + 'id' => 'main-form', |
149 | + // 'options' => [ 'class' => 'form-inline' ], | ||
149 | ] | 150 | ] |
150 | ); ?> | 151 | ); ?> |
151 | <div class="container"> | 152 | <div class="container"> |
@@ -333,6 +334,51 @@ JS; | @@ -333,6 +334,51 @@ JS; | ||
333 | ), | 334 | ), |
334 | [ 'prompt' => 'Способ оплаты ...' ] | 335 | [ 'prompt' => 'Способ оплаты ...' ] |
335 | ); ?> | 336 | ); ?> |
337 | + <?php | ||
338 | + if ($model->payment == 10) { | ||
339 | + ?> | ||
340 | + <div> | ||
341 | + <div class="col-xs-4"> | ||
342 | + <?php | ||
343 | + echo $form->field($model, 'credit_sum') | ||
344 | + ->textInput( | ||
345 | + [ | ||
346 | + 'class' => 'form-control credit_input', | ||
347 | + 'data-sum' => $model->total, | ||
348 | + ] | ||
349 | + ); | ||
350 | + ?> | ||
351 | + </div> | ||
352 | + <div class="col-xs-4"> | ||
353 | + <?php | ||
354 | + echo Html::tag('span', $model->total - $model->credit_sum, [ | ||
355 | + 'class' => 'credit_value_full', | ||
356 | + ]); | ||
357 | + ?> | ||
358 | + </div> | ||
359 | + <div class="col-xs-4"> | ||
360 | + <?php | ||
361 | + echo $form->field($model, 'credit_month') | ||
362 | + ->textInput( | ||
363 | + [ | ||
364 | + 'class' => 'form-control credit_input', | ||
365 | + ] | ||
366 | + ); | ||
367 | + ?> | ||
368 | + </div> | ||
369 | + <div class="clearfix"></div> | ||
370 | + <p> | ||
371 | + <span class="credit_value"> | ||
372 | + <?php | ||
373 | + echo CreditHelper::getCredit($model->total - $model->credit_sum, $model->credit_month); | ||
374 | + ?> | ||
375 | + </span> | ||
376 | + <span>грн/мес</span> | ||
377 | + </p> | ||
378 | + </div> | ||
379 | + <?php | ||
380 | + } | ||
381 | + ?> | ||
336 | 382 | ||
337 | <?= $form->field($model, 'insurance') ?> | 383 | <?= $form->field($model, 'insurance') ?> |
338 | 384 | ||
@@ -366,348 +412,348 @@ JS; | @@ -366,348 +412,348 @@ JS; | ||
366 | <br> | 412 | <br> |
367 | <br> | 413 | <br> |
368 | <div class="container"> | 414 | <div class="container"> |
369 | - <div class="row"> | ||
370 | - <?php | ||
371 | - echo GridView::widget( | ||
372 | - [ | ||
373 | - 'dataProvider' => $dataProvider, | ||
374 | - 'rowOptions' => function($model) { | ||
375 | - if ($model->removed) { | ||
376 | - return [ 'class' => 'danger' ]; | ||
377 | - } else { | ||
378 | - return []; | ||
379 | - } | ||
380 | - }, | ||
381 | - 'layout' => '{items}{pager}', | ||
382 | - 'columns' => [ | ||
383 | - [ | ||
384 | - 'class' => SerialColumn::className(), | ||
385 | - ], | ||
386 | - 'sku', | ||
387 | - [ | ||
388 | - 'attribute' => 'product_name', | ||
389 | - 'content' => function($model) { | ||
390 | - if (!empty($model->product_name)) { | 415 | + <div class="row"> |
416 | + <?php | ||
417 | + echo GridView::widget( | ||
418 | + [ | ||
419 | + 'dataProvider' => $dataProvider, | ||
420 | + 'rowOptions' => function ($model) { | ||
421 | + if ($model->removed) { | ||
422 | + return [ 'class' => 'danger' ]; | ||
423 | + } else { | ||
424 | + return []; | ||
425 | + } | ||
426 | + }, | ||
427 | + 'layout' => '{items}{pager}', | ||
428 | + 'columns' => [ | ||
429 | + [ | ||
430 | + 'class' => SerialColumn::className(), | ||
431 | + ], | ||
432 | + 'sku', | ||
433 | + [ | ||
434 | + 'attribute' => 'product_name', | ||
435 | + 'content' => function ($model) { | ||
436 | + if (!empty( $model->product_name )) { | ||
437 | + | ||
438 | + if (empty( $model->productVariant )) { | ||
439 | + return ''; | ||
440 | + } | ||
441 | + | ||
442 | + return Html::a( | ||
443 | + StringHelper::truncate($model->product_name, 10, '...'), | ||
444 | + '#', | ||
445 | + [ | ||
446 | + 'onclick' => 'event.preventDefault();', | ||
447 | + 'data-toggle' => 'popover', | ||
448 | + 'data-placement' => 'right', | ||
449 | + 'data-html' => 'true', | ||
450 | + 'data-content' => Html::img( | ||
451 | + $model->productVariant->imageUrl, | ||
452 | + [ | ||
453 | + 'class' => 'img-rounded', | ||
454 | + ] | ||
455 | + ) . Html::tag('p', $model->product_name), | ||
456 | + ] | ||
457 | + ); | ||
458 | + } else { | ||
459 | + return ''; | ||
460 | + } | ||
461 | + }, | ||
462 | + ], | ||
463 | + [ | ||
464 | + 'attribute' => 'productVariant.product.brand.lang.title', | ||
465 | + 'label' => 'Брэнд', | ||
466 | + ], | ||
467 | + [ | ||
468 | + 'attribute' => 'productVariant.lang.title', | ||
469 | + 'label' => \Yii::t('app', 'Цвет'), | ||
470 | + 'content' => function ($model) { | ||
391 | 471 | ||
392 | - if (empty($model->productVariant)) { | 472 | + if (empty( $model->productVariant )) { |
393 | return ''; | 473 | return ''; |
394 | - } | ||
395 | - | ||
396 | - return Html::a( | ||
397 | - StringHelper::truncate($model->product_name, 10, '...'), | ||
398 | - '#', | ||
399 | - [ | ||
400 | - 'onclick' => 'event.preventDefault();', | ||
401 | - 'data-toggle' => 'popover', | ||
402 | - 'data-placement' => 'right', | ||
403 | - 'data-html' => 'true', | ||
404 | - 'data-content' => Html::img( | ||
405 | - $model->productVariant->imageUrl, | ||
406 | - [ | ||
407 | - 'class' => 'img-rounded', | ||
408 | - ] | ||
409 | - ) . Html::tag('p', $model->product_name), | ||
410 | - ] | ||
411 | - ); | ||
412 | - } else { | ||
413 | - return ''; | ||
414 | - } | ||
415 | - }, | ||
416 | - ], | ||
417 | - [ | ||
418 | - 'attribute' => 'productVariant.product.brand.lang.title', | ||
419 | - 'label' => 'Брэнд', | ||
420 | - ], | ||
421 | - [ | ||
422 | - 'attribute' => 'productVariant.lang.title', | ||
423 | - 'label' => \Yii::t('app', 'Цвет'), | ||
424 | - 'content' => function($model) { | ||
425 | - | ||
426 | - if (empty($model->productVariant)) { | ||
427 | - return ''; | ||
428 | - } | ||
429 | - | ||
430 | - if (preg_match('@.*\.(png|jpg|gif)@i', $model->productVariant->lang->title)) { | ||
431 | - return ''; | ||
432 | - } else { | ||
433 | - return $model->productVariant->lang->title; | ||
434 | - } | ||
435 | - }, | ||
436 | - ], | ||
437 | - [ | ||
438 | - 'attribute' => 'productVariant.size', | ||
439 | - 'label' => 'Размер', | ||
440 | - ], | ||
441 | - 'price', | ||
442 | - [ | ||
443 | - 'class' => 'kartik\grid\EditableColumn', | ||
444 | - 'attribute' => 'count', | ||
445 | - 'editableOptions' => [ | ||
446 | - 'header' => \Yii::t('app', 'Количество'), | ||
447 | - 'inputType' => kartik\editable\Editable::INPUT_SPIN, | ||
448 | - 'options' => [ | ||
449 | - 'pluginOptions' => [ | ||
450 | - 'min' => 0, | ||
451 | - 'max' => 5000, | ||
452 | - ], | ||
453 | - ], | ||
454 | - 'pluginEvents' => [ | ||
455 | - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
456 | - ], | ||
457 | - ], | ||
458 | - 'format' => [ | ||
459 | - 'decimal', | ||
460 | - 0, | ||
461 | - ], | ||
462 | - 'pageSummary' => false, | ||
463 | - ], | ||
464 | - 'sum_cost', | ||
465 | - [ | ||
466 | - 'class' => 'kartik\grid\EditableColumn', | ||
467 | - 'attribute' => 'booking', | ||
468 | - 'editableOptions' => [ | ||
469 | - 'header' => \Yii::t('app', 'Бронь'), | ||
470 | - 'inputType' => kartik\editable\Editable::INPUT_TEXT, | ||
471 | - 'options' => [ | ||
472 | - 'class' => 'booking-typeahead', | ||
473 | - 'pluginOptions' => [ | ||
474 | - 'min' => 0, | ||
475 | - 'max' => 20, | ||
476 | - ], | ||
477 | - ], | ||
478 | - 'pluginEvents' => [ | ||
479 | - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
480 | - ], | ||
481 | - ], | ||
482 | - 'format' => [ | ||
483 | - 'text', | ||
484 | - ], | ||
485 | - 'pageSummary' => false, | ||
486 | - ], | ||
487 | - [ | ||
488 | - 'class' => 'kartik\grid\EditableColumn', | ||
489 | - 'attribute' => 'status', | ||
490 | - 'editableOptions' => [ | ||
491 | - 'header' => \Yii::t('app', 'Статус'), | ||
492 | - 'inputType' => kartik\editable\Editable::INPUT_TEXT, | ||
493 | - 'options' => [ | ||
494 | - 'class' => 'status-typeahead', | ||
495 | - 'pluginOptions' => [ | ||
496 | - 'min' => 0, | ||
497 | - 'max' => 20, | ||
498 | - ], | ||
499 | - ], | ||
500 | - 'pluginEvents' => [ | ||
501 | - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
502 | - ], | ||
503 | - ], | ||
504 | - 'format' => [ | ||
505 | - 'text', | ||
506 | - ], | ||
507 | - 'pageSummary' => false, | ||
508 | - ], | ||
509 | - [ | ||
510 | - 'class' => 'kartik\grid\EditableColumn', | ||
511 | - 'attribute' => 'return', | ||
512 | - 'editableOptions' => [ | ||
513 | - 'header' => \Yii::t('app', 'Возврат'), | ||
514 | - 'inputType' => kartik\editable\Editable::INPUT_CHECKBOX, | ||
515 | - 'options' => [], | ||
516 | - 'pluginEvents' => [ | ||
517 | - 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
518 | - ], | ||
519 | - ], | ||
520 | - 'format' => [ | ||
521 | - 'boolean', | ||
522 | - ], | ||
523 | - 'pageSummary' => false, | ||
524 | - ], | ||
525 | - [ | ||
526 | - 'content' => function($model) { | ||
527 | - | ||
528 | - if (empty($model->productVariant)) { | ||
529 | - return '<i class="glyphicon glyphicon-remove"></i>'; | ||
530 | - } | ||
531 | - | ||
532 | - $content = '<table class="table"><tbody><tr><th>Склад</th><th>кол.</th></tr>'; | ||
533 | - foreach ($model->productVariant->variantStocks as $stock) { | ||
534 | - $content .= '<tr><td>' . $stock->stock->title . '</td><td>' . $stock->quantity . '</td></tr>'; | ||
535 | - } | ||
536 | - return Html::a( | ||
537 | - '<i class="glyphicon glyphicon-home"></i>', | ||
538 | - '#', | ||
539 | - [ | ||
540 | - 'onclick' => 'event.preventDefault();', | ||
541 | - 'data-toggle' => 'popover', | ||
542 | - 'data-placement' => 'left', | ||
543 | - 'data-html' => 'true', | ||
544 | - 'data-content' => $content . '</tbody></table>', | ||
545 | - ] | ||
546 | - ); | ||
547 | - }, | ||
548 | - ], | ||
549 | - [ | ||
550 | - 'class' => 'yii\grid\ActionColumn', | ||
551 | - 'template' => '{delete}', | ||
552 | - 'buttons' => [ | ||
553 | - 'delete' => function($url, $product) { | ||
554 | - if ($product->removed) { | ||
555 | - return ''; | ||
556 | - } else { | ||
557 | - return Html::a( | ||
558 | - Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-trash' ]), | ||
559 | - [ | ||
560 | - 'delete-product', | ||
561 | - 'id' => $product->id, | ||
562 | - ], | ||
563 | - [ | ||
564 | - 'class' => 'delete-button', | ||
565 | - // 'data' => [ | ||
566 | - // 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', | ||
567 | - // 'method' => 'GET', | ||
568 | - // ], | ||
569 | - ] | ||
570 | - ); | ||
571 | - } | ||
572 | - }, | ||
573 | - ], | ||
574 | - ], | ||
575 | - ], | ||
576 | - 'responsive' => true, | ||
577 | - 'hover' => true, | ||
578 | - 'pjax' => true, | ||
579 | - 'pjaxSettings' => [ | ||
580 | - 'options' => [ | ||
581 | - 'scrollTo' => 'false', | ||
582 | - 'id' => 'order-products-grid', | ||
583 | - ], | ||
584 | - ], | ||
585 | - ] | ||
586 | - ); | ||
587 | - ?> | ||
588 | - </div> | 474 | + } |
475 | + | ||
476 | + if (preg_match('@.*\.(png|jpg|gif)@i', $model->productVariant->lang->title)) { | ||
477 | + return ''; | ||
478 | + } else { | ||
479 | + return $model->productVariant->lang->title; | ||
480 | + } | ||
481 | + }, | ||
482 | + ], | ||
483 | + [ | ||
484 | + 'attribute' => 'productVariant.size', | ||
485 | + 'label' => 'Размер', | ||
486 | + ], | ||
487 | + 'price', | ||
488 | + [ | ||
489 | + 'class' => 'kartik\grid\EditableColumn', | ||
490 | + 'attribute' => 'count', | ||
491 | + 'editableOptions' => [ | ||
492 | + 'header' => \Yii::t('app', 'Количество'), | ||
493 | + 'inputType' => kartik\editable\Editable::INPUT_SPIN, | ||
494 | + 'options' => [ | ||
495 | + 'pluginOptions' => [ | ||
496 | + 'min' => 0, | ||
497 | + 'max' => 5000, | ||
498 | + ], | ||
499 | + ], | ||
500 | + 'pluginEvents' => [ | ||
501 | + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
502 | + ], | ||
503 | + ], | ||
504 | + 'format' => [ | ||
505 | + 'decimal', | ||
506 | + 0, | ||
507 | + ], | ||
508 | + 'pageSummary' => false, | ||
509 | + ], | ||
510 | + 'sum_cost', | ||
511 | + [ | ||
512 | + 'class' => 'kartik\grid\EditableColumn', | ||
513 | + 'attribute' => 'booking', | ||
514 | + 'editableOptions' => [ | ||
515 | + 'header' => \Yii::t('app', 'Бронь'), | ||
516 | + 'inputType' => kartik\editable\Editable::INPUT_TEXT, | ||
517 | + 'options' => [ | ||
518 | + 'class' => 'booking-typeahead', | ||
519 | + 'pluginOptions' => [ | ||
520 | + 'min' => 0, | ||
521 | + 'max' => 20, | ||
522 | + ], | ||
523 | + ], | ||
524 | + 'pluginEvents' => [ | ||
525 | + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
526 | + ], | ||
527 | + ], | ||
528 | + 'format' => [ | ||
529 | + 'text', | ||
530 | + ], | ||
531 | + 'pageSummary' => false, | ||
532 | + ], | ||
533 | + [ | ||
534 | + 'class' => 'kartik\grid\EditableColumn', | ||
535 | + 'attribute' => 'status', | ||
536 | + 'editableOptions' => [ | ||
537 | + 'header' => \Yii::t('app', 'Статус'), | ||
538 | + 'inputType' => kartik\editable\Editable::INPUT_TEXT, | ||
539 | + 'options' => [ | ||
540 | + 'class' => 'status-typeahead', | ||
541 | + 'pluginOptions' => [ | ||
542 | + 'min' => 0, | ||
543 | + 'max' => 20, | ||
544 | + ], | ||
545 | + ], | ||
546 | + 'pluginEvents' => [ | ||
547 | + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
548 | + ], | ||
549 | + ], | ||
550 | + 'format' => [ | ||
551 | + 'text', | ||
552 | + ], | ||
553 | + 'pageSummary' => false, | ||
554 | + ], | ||
555 | + [ | ||
556 | + 'class' => 'kartik\grid\EditableColumn', | ||
557 | + 'attribute' => 'return', | ||
558 | + 'editableOptions' => [ | ||
559 | + 'header' => \Yii::t('app', 'Возврат'), | ||
560 | + 'inputType' => kartik\editable\Editable::INPUT_CHECKBOX, | ||
561 | + 'options' => [], | ||
562 | + 'pluginEvents' => [ | ||
563 | + 'editableSuccess' => 'function(event) { $.pjax.reload({container:"#order-products-grid"}); }', | ||
564 | + ], | ||
565 | + ], | ||
566 | + 'format' => [ | ||
567 | + 'boolean', | ||
568 | + ], | ||
569 | + 'pageSummary' => false, | ||
570 | + ], | ||
571 | + [ | ||
572 | + 'content' => function ($model) { | ||
573 | + | ||
574 | + if (empty( $model->productVariant )) { | ||
575 | + return '<i class="glyphicon glyphicon-remove"></i>'; | ||
576 | + } | ||
577 | + | ||
578 | + $content = '<table class="table"><tbody><tr><th>Склад</th><th>кол.</th></tr>'; | ||
579 | + foreach ($model->productVariant->variantStocks as $stock) { | ||
580 | + $content .= '<tr><td>' . $stock->stock->title . '</td><td>' . $stock->quantity . '</td></tr>'; | ||
581 | + } | ||
582 | + return Html::a( | ||
583 | + '<i class="glyphicon glyphicon-home"></i>', | ||
584 | + '#', | ||
585 | + [ | ||
586 | + 'onclick' => 'event.preventDefault();', | ||
587 | + 'data-toggle' => 'popover', | ||
588 | + 'data-placement' => 'left', | ||
589 | + 'data-html' => 'true', | ||
590 | + 'data-content' => $content . '</tbody></table>', | ||
591 | + ] | ||
592 | + ); | ||
593 | + }, | ||
594 | + ], | ||
595 | + [ | ||
596 | + 'class' => 'yii\grid\ActionColumn', | ||
597 | + 'template' => '{delete}', | ||
598 | + 'buttons' => [ | ||
599 | + 'delete' => function ($url, $product) { | ||
600 | + if ($product->removed) { | ||
601 | + return ''; | ||
602 | + } else { | ||
603 | + return Html::a( | ||
604 | + Html::tag('span', '', [ 'class' => 'glyphicon glyphicon-trash' ]), | ||
605 | + [ | ||
606 | + 'delete-product', | ||
607 | + 'id' => $product->id, | ||
608 | + ], | ||
609 | + [ | ||
610 | + 'class' => 'delete-button', | ||
611 | + // 'data' => [ | ||
612 | + // 'confirm' => 'Вы уверены, что хотите удалить этот элемент?', | ||
613 | + // 'method' => 'GET', | ||
614 | + // ], | ||
615 | + ] | ||
616 | + ); | ||
617 | + } | ||
618 | + }, | ||
619 | + ], | ||
620 | + ], | ||
621 | + ], | ||
622 | + 'responsive' => true, | ||
623 | + 'hover' => true, | ||
624 | + 'pjax' => true, | ||
625 | + 'pjaxSettings' => [ | ||
626 | + 'options' => [ | ||
627 | + 'scrollTo' => 'false', | ||
628 | + 'id' => 'order-products-grid', | ||
629 | + ], | ||
630 | + ], | ||
631 | + ] | ||
632 | + ); | ||
633 | + ?> | ||
634 | + </div> | ||
589 | </div> | 635 | </div> |
590 | <div class="container"> | 636 | <div class="container"> |
591 | <?php Pjax::begin([ 'id' => 'total-cost' ]); ?> | 637 | <?php Pjax::begin([ 'id' => 'total-cost' ]); ?> |
592 | - <h2>Сумма заказа : <span class="label label-success"><?php echo $model->total; ?><?php echo \Yii::t( | ||
593 | - 'app', | ||
594 | - 'грн' | ||
595 | - ) ?></span></h2> | 638 | + <h2>Сумма заказа : <span class="label label-success"><?php echo $model->total; ?><?php echo \Yii::t( |
639 | + 'app', | ||
640 | + 'грн' | ||
641 | + ) ?></span></h2> | ||
596 | <?php Pjax::end(); ?> | 642 | <?php Pjax::end(); ?> |
597 | </div> | 643 | </div> |
598 | <div class="container"> | 644 | <div class="container"> |
599 | - <div class="row"> | ||
600 | - <?php $newProductForm = ActiveForm::begin( | ||
601 | - [ | ||
602 | - 'action' => yii\helpers\Url::to([ 'add' ]), | ||
603 | - 'id' => 'add-product-form', | ||
604 | - ] | ||
605 | - ); | ||
606 | - $newOrderProduct = new OrderProduct(); | ||
607 | - ?> | ||
608 | - <div class="col-md-8"> | ||
609 | - <?php echo $newProductForm->field($newOrderProduct, 'id') | ||
610 | - ->widget( | ||
611 | - Select2::className(), | ||
612 | - [ | ||
613 | - 'options' => [ 'placeholder' => 'Search for a product ...' ], | ||
614 | - 'pluginOptions' => [ | ||
615 | - 'allowClear' => true, | ||
616 | - 'disabled' => $model->isNewRecord ? true : false, | ||
617 | - 'minimumInputLength' => 3, | ||
618 | - 'language' => [ | ||
619 | - 'errorLoading' => new JsExpression( | ||
620 | - "function () { return 'Waiting for results...'; }" | 645 | + <div class="row"> |
646 | + <?php $newProductForm = ActiveForm::begin( | ||
647 | + [ | ||
648 | + 'action' => yii\helpers\Url::to([ 'add' ]), | ||
649 | + 'id' => 'add-product-form', | ||
650 | + ] | ||
651 | + ); | ||
652 | + $newOrderProduct = new OrderProduct(); | ||
653 | + ?> | ||
654 | + <div class="col-md-8"> | ||
655 | + <?php echo $newProductForm->field($newOrderProduct, 'id') | ||
656 | + ->widget( | ||
657 | + Select2::className(), | ||
658 | + [ | ||
659 | + 'options' => [ 'placeholder' => 'Search for a product ...' ], | ||
660 | + 'pluginOptions' => [ | ||
661 | + 'allowClear' => true, | ||
662 | + 'disabled' => $model->isNewRecord ? true : false, | ||
663 | + 'minimumInputLength' => 3, | ||
664 | + 'language' => [ | ||
665 | + 'errorLoading' => new JsExpression( | ||
666 | + "function () { return 'Waiting for results...'; }" | ||
667 | + ), | ||
668 | + ], | ||
669 | + 'ajax' => [ | ||
670 | + 'url' => \yii\helpers\Url::to([ 'find-product' ]), | ||
671 | + 'dataType' => 'json', | ||
672 | + 'data' => new JsExpression( | ||
673 | + 'function(params) { return {q:params.term}; }' | ||
674 | + ), | ||
675 | + ], | ||
676 | + 'escapeMarkup' => new JsExpression( | ||
677 | + 'function (markup) { return markup; }' | ||
621 | ), | 678 | ), |
622 | - ], | ||
623 | - 'ajax' => [ | ||
624 | - 'url' => \yii\helpers\Url::to([ 'find-product' ]), | ||
625 | - 'dataType' => 'json', | ||
626 | - 'data' => new JsExpression( | ||
627 | - 'function(params) { return {q:params.term}; }' | 679 | + 'templateResult' => new JsExpression( |
680 | + 'function(data) { return data.sku; }' | ||
681 | + ), | ||
682 | + 'templateSelection' => new JsExpression( | ||
683 | + 'function (data) { return data.sku; }' | ||
628 | ), | 684 | ), |
629 | ], | 685 | ], |
630 | - 'escapeMarkup' => new JsExpression( | ||
631 | - 'function (markup) { return markup; }' | ||
632 | - ), | ||
633 | - 'templateResult' => new JsExpression( | ||
634 | - 'function(data) { return data.sku; }' | ||
635 | - ), | ||
636 | - 'templateSelection' => new JsExpression( | ||
637 | - 'function (data) { return data.sku; }' | ||
638 | - ), | ||
639 | - ], | ||
640 | - ] | ||
641 | - ) | ||
642 | - ->label('Артикул'); | ||
643 | - | ||
644 | - ?> | ||
645 | - </div> | ||
646 | - <div class="col-md-2"> | ||
647 | - <?php echo $newProductForm->field( | ||
648 | - $newOrderProduct, | ||
649 | - 'count' | ||
650 | - ) | ||
651 | - ->input( | ||
652 | - 'number', | 686 | + ] |
687 | + ) | ||
688 | + ->label('Артикул'); | ||
689 | + | ||
690 | + ?> | ||
691 | + </div> | ||
692 | + <div class="col-md-2"> | ||
693 | + <?php echo $newProductForm->field( | ||
694 | + $newOrderProduct, | ||
695 | + 'count' | ||
696 | + ) | ||
697 | + ->input( | ||
698 | + 'number', | ||
699 | + [ | ||
700 | + 'disabled' => $model->isNewRecord ? true : false, | ||
701 | + ] | ||
702 | + ); ?> | ||
703 | + </div> | ||
704 | + <div class="col-md-2" style="margin-top: 23px"> | ||
705 | + <?php echo Html::submitButton( | ||
706 | + \Yii::t('app', 'Добавить'), | ||
707 | + [ | ||
708 | + 'class' => $model->isNewRecord ? 'btn btn-primary disabled' : 'btn btn-primary', | ||
709 | + ] | ||
710 | + ) ?> | ||
711 | + </div> | ||
712 | + <?php echo $newProductForm->field($newOrderProduct, 'order_id') | ||
713 | + ->hiddenInput( | ||
653 | [ | 714 | [ |
654 | - 'disabled' => $model->isNewRecord ? true : false, | 715 | + 'value' => $model->id, |
655 | ] | 716 | ] |
656 | - ); ?> | 717 | + ) |
718 | + ->label(false) ?> | ||
719 | + <?php ActiveForm::end(); ?> | ||
657 | </div> | 720 | </div> |
658 | - <div class="col-md-2" style="margin-top: 23px"> | ||
659 | - <?php echo Html::submitButton( | ||
660 | - \Yii::t('app', 'Добавить'), | 721 | + |
722 | + <br> | ||
723 | + <div class="row"> | ||
724 | + <?= Html::button( | ||
725 | + $model->isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Сохранить'), | ||
726 | + [ | ||
727 | + 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg', | ||
728 | + 'id' => 'page-submit', | ||
729 | + ] | ||
730 | + ) ?> | ||
731 | + <?= Html::a( | ||
732 | + \Yii::t('app', 'Печать'), | ||
733 | + yii\helpers\Url::to( | ||
734 | + [ | ||
735 | + 'order/print', | ||
736 | + 'order_id' => $model->id, | ||
737 | + ] | ||
738 | + ), | ||
739 | + [ | ||
740 | + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', | ||
741 | + 'target' => '_blank', | ||
742 | + ] | ||
743 | + ) ?> | ||
744 | + <?= Html::a( | ||
745 | + \Yii::t('app', 'Выйти'), | ||
746 | + yii\helpers\Url::to( | ||
747 | + [ | ||
748 | + 'close-order', | ||
749 | + 'id' => $model->id, | ||
750 | + ] | ||
751 | + ), | ||
661 | [ | 752 | [ |
662 | - 'class' => $model->isNewRecord ? 'btn btn-primary disabled' : 'btn btn-primary', | 753 | + 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', |
663 | ] | 754 | ] |
664 | ) ?> | 755 | ) ?> |
665 | </div> | 756 | </div> |
666 | - <?php echo $newProductForm->field($newOrderProduct, 'order_id') | ||
667 | - ->hiddenInput( | ||
668 | - [ | ||
669 | - 'value' => $model->id, | ||
670 | - ] | ||
671 | - ) | ||
672 | - ->label(false) ?> | ||
673 | - <?php ActiveForm::end(); ?> | ||
674 | - </div> | ||
675 | - | ||
676 | - <br> | ||
677 | - <div class="row"> | ||
678 | - <?= Html::button( | ||
679 | - $model->isNewRecord ? \Yii::t('app', 'Создать') : \Yii::t('app', 'Сохранить'), | ||
680 | - [ | ||
681 | - 'class' => $model->isNewRecord ? 'btn btn-success btn-lg' : 'btn btn-primary btn-lg', | ||
682 | - 'id' => 'page-submit', | ||
683 | - ] | ||
684 | - ) ?> | ||
685 | - <?= Html::a( | ||
686 | - \Yii::t('app', 'Печать'), | ||
687 | - yii\helpers\Url::to( | ||
688 | - [ | ||
689 | - 'order/print', | ||
690 | - 'order_id' => $model->id, | ||
691 | - ] | ||
692 | - ), | ||
693 | - [ | ||
694 | - 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', | ||
695 | - 'target' => '_blank', | ||
696 | - ] | ||
697 | - ) ?> | ||
698 | - <?= Html::a( | ||
699 | - \Yii::t('app', 'Выйти'), | ||
700 | - yii\helpers\Url::to( | ||
701 | - [ | ||
702 | - 'close-order', | ||
703 | - 'id' => $model->id, | ||
704 | - ] | ||
705 | - ), | ||
706 | - [ | ||
707 | - 'class' => $model->isNewRecord ? 'btn btn-info disabled btn-lg' : 'btn btn-info btn-lg', | ||
708 | - ] | ||
709 | - ) ?> | ||
710 | - </div> | ||
711 | 757 | ||
712 | </div> | 758 | </div> |
713 | <br> | 759 | <br> |