Commit 41f0c49267f42c0ed10960e0796e57ec9b87151c

Authored by Yarik
1 parent be03d9ce

Print and email

Showing 2 changed files with 240 additions and 28 deletions   Show diff stats
controllers/OrderController.php
... ... @@ -7,6 +7,7 @@
7 7 use common\models\User;
8 8 use phpDocumentor\Reflection\Types\Null_;
9 9 use Yii;
  10 + use yii\data\ArrayDataProvider;
10 11 use yii\helpers\ArrayHelper;
11 12 use yii\helpers\Json;
12 13 use yii\helpers\VarDumper;
... ... @@ -150,10 +151,10 @@
150 151  
151 152 public function actionAdd()
152 153 {
153   - if (!empty(\Yii::$app->request->post())) {
  154 + if (!empty( \Yii::$app->request->post() )) {
154 155 $id = \Yii::$app->request->post('OrderProduct')[ 'id' ];
155 156 $order_id = \Yii::$app->request->post('OrderProduct')[ 'order_id' ];
156   - if (!empty(\Yii::$app->request->post('OrderProduct')[ 'count' ])) {
  157 + if (!empty( \Yii::$app->request->post('OrderProduct')[ 'count' ] )) {
157 158 $count = \Yii::$app->request->post('OrderProduct')[ 'count' ];
158 159 } else {
159 160 $count = 1;
... ... @@ -173,7 +174,7 @@
173 174 )
174 175 ->one();
175 176  
176   - if (!empty($model)) {
  177 + if (!empty( $model )) {
177 178 $model->count += $count;
178 179 } else {
179 180 $model = new OrderProduct();
... ... @@ -218,7 +219,7 @@
218 219 if ($orderProduct->load($post)) {
219 220 $orderProduct->save();
220 221 $output = '';
221   - if (isset($posted[ 'count' ])) {
  222 + if (isset( $posted[ 'count' ] )) {
222 223 $output = Yii::$app->formatter->asDecimal($orderProduct->count, 0);
223 224 }
224 225 $out = Json::encode(
... ... @@ -267,20 +268,23 @@
267 268 }
268 269 }
269 270  
270   - public function actionPrint()
  271 + public function actionPrint($order_id)
271 272 {
272   - $orderId = Yii::$app->request->get("order_id");
273   - if (!empty($orderId)) {
274   - $order = $this->findModel($orderId);
275   - return $this->renderPartial(
276   - '@frontend/views/cabinet/order_print',
277   - [
278   - 'order' => $order,
279   - ]
280   - );
281   - } else {
282   - throw new NotFoundHttpException('The requested page does not exist.');
283   - }
  273 + $order = $this->findModel($order_id);
  274 + $dataProvider = new ArrayDataProvider(
  275 + [
  276 + 'allModels' => $order->products,
  277 + 'pagination' => false,
  278 + 'sort' => false,
  279 + ]
  280 + );
  281 + return $this->renderPartial(
  282 + 'print',
  283 + [
  284 + 'order' => $order,
  285 + 'dataProvider' => $dataProvider,
  286 + ]
  287 + );
284 288  
285 289 }
286 290  
... ... @@ -303,7 +307,7 @@
303 307 $orderProduct->save();
304 308 $orderProduct->order->totalRecount();
305 309 $output = '';
306   - if (isset($posted[ 'count' ])) {
  310 + if (isset( $posted[ 'count' ] )) {
307 311 $output = Yii::$app->formatter->asDecimal($orderProduct->count, 0);
308 312 }
309 313 $out = Json::encode(
... ... @@ -338,13 +342,13 @@
338 342 ]
339 343 );
340 344  
341   - if (empty($model->manager_id)) {
  345 + if (empty( $model->manager_id )) {
342 346 $model->manager_id = \Yii::$app->user->id;
343 347 }
344 348  
345 349 $headers = \Yii::$app->response->headers;
346 350 $headers->set('Access-Control-Allow-Origin', '*');
347   -
  351 +
348 352 if ($model->load(Yii::$app->request->post()) && $model->save()) {
349 353 $this->unblockOrder($model->id);
350 354 return $this->render(
... ... @@ -365,7 +369,7 @@
365 369 }
366 370 }
367 371  
368   - public function actionFindProduct($q = NULL, $id = NULL)
  372 + public function actionFindProduct($q = null, $id = null)
369 373 {
370 374 \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
371 375 $out = [
... ... @@ -424,7 +428,7 @@
424 428  
425 429 protected function findModel($id)
426 430 {
427   - if (( $model = Order::findOne($id) ) !== NULL) {
  431 + if (( $model = Order::findOne($id) ) !== null) {
428 432 return $model;
429 433 } else {
430 434 throw new NotFoundHttpException('The requested page does not exist.');
... ... @@ -445,9 +449,9 @@
445 449 if (!$model->published) {
446 450 $model->deleteUnpublished();
447 451 }
448   -// return $this->redirect('index');
  452 + // return $this->redirect('index');
449 453 }
450   -
  454 +
451 455 public function actionCloseOrder($id)
452 456 {
453 457 try {
... ... @@ -458,16 +462,16 @@
458 462 if ($model->edit_id == \Yii::$app->user->id) {
459 463 $this->unblockOrder($id);
460 464 }
461   -
  465 +
462 466 if (!$model->published) {
463 467 $model->deleteUnpublished();
464 468 }
465   - return $this->redirect('index');
  469 + return $this->redirect('index');
466 470 }
467 471  
468 472 public function actionBlockOrder()
469 473 {
470   - if (!empty(\Yii::$app->request->post())) {
  474 + if (!empty( \Yii::$app->request->post() )) {
471 475 \Yii::$app->response->format = Response::FORMAT_JSON;
472 476  
473 477 $model = $this->findModel(\Yii::$app->request->post('id'));
... ... @@ -484,7 +488,7 @@
484 488 if ($model->save()) {
485 489 return [
486 490 'time' => $date,
487   - 'user' => !empty($user) ? $user->username : '',
  491 + 'user' => !empty( $user ) ? $user->username : '',
488 492 ];
489 493 } else {
490 494 return [
... ...
views/order/print.php 0 → 100755
  1 +<?php
  2 +
  3 +use artweb\artbox\ecommerce\models\Order;
  4 +use artweb\artbox\ecommerce\models\OrderProduct;use yii\data\ArrayDataProvider;
  5 +use yii\grid\GridView;
  6 +use yii\helpers\ArrayHelper;use yii\web\View;
  7 +use yii\widgets\DetailView;
  8 +
  9 +/**
  10 + * @var View $this
  11 + * @var Order $order
  12 + * @var ArrayDataProvider $dataProvider
  13 + */
  14 +?>
  15 +<?php $this->beginPage(); ?>
  16 +<!DOCTYPE html>
  17 +<html>
  18 +<head>
  19 + <meta charset="utf-8">
  20 + <?php $this->head() ?>
  21 + <script>
  22 +// window.print();
  23 + </script>
  24 +</head>
  25 +<body>
  26 +<?php $this->beginBody(); ?>
  27 +<div>
  28 +<?php
  29 + echo DetailView::widget([
  30 + 'model' => $order,
  31 + 'attributes' => [
  32 + [
  33 + 'attribute' => 'manager.username',
  34 + 'label' => \Yii::t('app', 'Manager Username'),
  35 + ],
  36 + 'id',
  37 + 'created_at:date',
  38 + [
  39 + 'attribute' => 'user.username',
  40 + 'label' => \Yii::t('app', 'Client Username'),
  41 + ],
  42 + [
  43 + 'attribute' => 'email',
  44 + 'value' => $order->email?:(!empty($order->user)?$order->user->email:null),
  45 + ],
  46 + [
  47 + 'attribute' => 'phone',
  48 + 'value' => $order->phone?:(!empty($order->user)?$order->user->phone:null),
  49 + ],
  50 + [
  51 + 'attribute' => 'phone2',
  52 + 'value' => $order->phone2?:null,
  53 + ],
  54 + [
  55 + 'attribute' => 'numbercard',
  56 + 'value' => $order->numbercard?:null,
  57 + ],
  58 + [
  59 + 'attribute' => 'comment',
  60 + 'value' => $order->comment?:null,
  61 + ],
  62 + [
  63 + 'attribute' => 'delivery',
  64 + 'value' => $order->deliveryString?:null,
  65 + ],
  66 + [
  67 + 'attribute' => 'declaration',
  68 + 'value' => $order->declaration?:null,
  69 + ],
  70 + [
  71 + 'attribute' => 'stock',
  72 + 'value' => $order->stock?:null,
  73 + ],
  74 + [
  75 + 'attribute' => 'payment',
  76 + 'value' => $order->orderPayment?$order->orderPayment->lang->title:null,
  77 + ],
  78 + [
  79 + 'attribute' => 'insurance',
  80 + 'value' => $order->insurance?:null,
  81 + ],
  82 + [
  83 + 'attribute' => 'amount_imposed',
  84 + 'value' => $order->amount_imposed?:null,
  85 + ],
  86 + [
  87 + 'attribute' => 'shipping_by',
  88 + 'value' => $order->shipping_by?:null,
  89 + ],
  90 + [
  91 + 'attribute' => 'city',
  92 + 'value' => $order->city?:null,
  93 + ],
  94 + [
  95 + 'attribute' => 'adress',
  96 + 'value' => $order->adress?:null,
  97 + ],
  98 + [
  99 + 'attribute' => 'body',
  100 + 'value' => $order->body?:null,
  101 + ],
  102 + ],
  103 + ]);
  104 + ?>
  105 +</div>
  106 +<div>
  107 +<?php
  108 + if(!empty($order->products)) {
  109 + echo GridView::widget([
  110 + 'tableOptions' => [
  111 + 'cellspacing' => '10',
  112 + 'cellpadding' => '3',
  113 + ],
  114 + 'dataProvider' => $dataProvider,
  115 + 'columns' => [
  116 + [
  117 + 'class' => 'yii\grid\SerialColumn',
  118 + ],
  119 + 'sku',
  120 + [
  121 + 'attribute' => 'productVariant.product.brand.lang.title',
  122 + 'label' => \Yii::t('app', 'Brand'),
  123 + ],
  124 + [
  125 + 'attribute' => 'productVariant.product.fullName',
  126 + 'label' => \Yii::t('app', 'Fullname'),
  127 + ],
  128 + [
  129 + 'label' => \Yii::t('app', 'Properties'),
  130 + 'value' => function($model) {
  131 + /**
  132 + * @var OrderProduct $model
  133 + */
  134 + $value = '';
  135 + foreach ($model->productVariant->properties as $property) {
  136 + $value .= $property->lang->title.':'.implode(',', ArrayHelper::getColumn($property->customOptions, 'lang.value')).'<br />';
  137 + }
  138 + return $value;
  139 + },
  140 + 'format' => 'html',
  141 + ],
  142 + 'count',
  143 + 'price',
  144 + 'sum_cost',
  145 + 'booking',
  146 + ],
  147 + 'showOnEmpty' => false,
  148 + 'layout' => "{items}",
  149 + ]);
  150 +}
  151 + ?>
  152 +</div>
  153 +<div>
  154 +<div style="display: inline-block; padding-right: 10px"><strong><?php echo $order->getAttributeLabel('total').': '.\Yii::$app->formatter->asDecimal($order->total); ?> грн.</strong></div>
  155 +<div style="display: inline-block"><strong><?php echo $order->getAttributeLabel('delivery_cost').': '.\Yii::$app->formatter->asDecimal($order->delivery_cost); ?></strong></div>
  156 +</div>
  157 +<div style="border-bottom: 4px dotted #a1a1a1; width: 100%; margin: 20px 0"></div>
  158 +<div>
  159 +<?php
  160 +echo DetailView::widget([
  161 + 'model' => $order,
  162 + 'attributes' => [
  163 + 'id',
  164 + 'created_at:date',
  165 + [
  166 + 'attribute' => 'user.username',
  167 + 'label' => \Yii::t('app', 'Client Username'),
  168 + ],
  169 + [
  170 + 'attribute' => 'phone',
  171 + 'value' => $order->phone?:(!empty($order->user)?$order->user->phone:null),
  172 + ],
  173 + [
  174 + 'attribute' => 'city',
  175 + 'value' => $order->city?:null,
  176 + ],
  177 + [
  178 + 'attribute' => 'adress',
  179 + 'value' => $order->adress?:null,
  180 + ],
  181 + [
  182 + 'attribute' => 'comment',
  183 + 'value' => $order->comment?:null,
  184 + ],
  185 + [
  186 + 'attribute' => 'stock',
  187 + 'value' => $order->stock?:null,
  188 + ],
  189 + [
  190 + 'attribute' => 'insurance',
  191 + 'value' => $order->insurance?:null,
  192 + ],
  193 + [
  194 + 'attribute' => 'amount_imposed',
  195 + 'value' => $order->amount_imposed?:null,
  196 + ],
  197 + [
  198 + 'attribute' => 'shipping_by',
  199 + 'value' => $order->shipping_by?:null,
  200 + ],
  201 + ],
  202 +]);
  203 + ?>
  204 +</div>
  205 +<?php $this->endBody(); ?>
  206 +</body>
  207 +</html>
  208 +<?php $this->endPage(); ?>
0 209 \ No newline at end of file
... ...