From 41f0c49267f42c0ed10960e0796e57ec9b87151c Mon Sep 17 00:00:00 2001 From: yarik Date: Fri, 16 Dec 2016 14:38:43 +0200 Subject: [PATCH] Print and email --- controllers/OrderController.php | 60 ++++++++++++++++++++++++++++++++---------------------------- views/order/print.php | 208 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 240 insertions(+), 28 deletions(-) create mode 100755 views/order/print.php diff --git a/controllers/OrderController.php b/controllers/OrderController.php index eafd9e5..6070352 100755 --- a/controllers/OrderController.php +++ b/controllers/OrderController.php @@ -7,6 +7,7 @@ use common\models\User; use phpDocumentor\Reflection\Types\Null_; use Yii; + use yii\data\ArrayDataProvider; use yii\helpers\ArrayHelper; use yii\helpers\Json; use yii\helpers\VarDumper; @@ -150,10 +151,10 @@ public function actionAdd() { - if (!empty(\Yii::$app->request->post())) { + if (!empty( \Yii::$app->request->post() )) { $id = \Yii::$app->request->post('OrderProduct')[ 'id' ]; $order_id = \Yii::$app->request->post('OrderProduct')[ 'order_id' ]; - if (!empty(\Yii::$app->request->post('OrderProduct')[ 'count' ])) { + if (!empty( \Yii::$app->request->post('OrderProduct')[ 'count' ] )) { $count = \Yii::$app->request->post('OrderProduct')[ 'count' ]; } else { $count = 1; @@ -173,7 +174,7 @@ ) ->one(); - if (!empty($model)) { + if (!empty( $model )) { $model->count += $count; } else { $model = new OrderProduct(); @@ -218,7 +219,7 @@ if ($orderProduct->load($post)) { $orderProduct->save(); $output = ''; - if (isset($posted[ 'count' ])) { + if (isset( $posted[ 'count' ] )) { $output = Yii::$app->formatter->asDecimal($orderProduct->count, 0); } $out = Json::encode( @@ -267,20 +268,23 @@ } } - public function actionPrint() + public function actionPrint($order_id) { - $orderId = Yii::$app->request->get("order_id"); - if (!empty($orderId)) { - $order = $this->findModel($orderId); - return $this->renderPartial( - '@frontend/views/cabinet/order_print', - [ - 'order' => $order, - ] - ); - } else { - throw new NotFoundHttpException('The requested page does not exist.'); - } + $order = $this->findModel($order_id); + $dataProvider = new ArrayDataProvider( + [ + 'allModels' => $order->products, + 'pagination' => false, + 'sort' => false, + ] + ); + return $this->renderPartial( + 'print', + [ + 'order' => $order, + 'dataProvider' => $dataProvider, + ] + ); } @@ -303,7 +307,7 @@ $orderProduct->save(); $orderProduct->order->totalRecount(); $output = ''; - if (isset($posted[ 'count' ])) { + if (isset( $posted[ 'count' ] )) { $output = Yii::$app->formatter->asDecimal($orderProduct->count, 0); } $out = Json::encode( @@ -338,13 +342,13 @@ ] ); - if (empty($model->manager_id)) { + if (empty( $model->manager_id )) { $model->manager_id = \Yii::$app->user->id; } $headers = \Yii::$app->response->headers; $headers->set('Access-Control-Allow-Origin', '*'); - + if ($model->load(Yii::$app->request->post()) && $model->save()) { $this->unblockOrder($model->id); return $this->render( @@ -365,7 +369,7 @@ } } - public function actionFindProduct($q = NULL, $id = NULL) + public function actionFindProduct($q = null, $id = null) { \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $out = [ @@ -424,7 +428,7 @@ protected function findModel($id) { - if (( $model = Order::findOne($id) ) !== NULL) { + if (( $model = Order::findOne($id) ) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); @@ -445,9 +449,9 @@ if (!$model->published) { $model->deleteUnpublished(); } -// return $this->redirect('index'); + // return $this->redirect('index'); } - + public function actionCloseOrder($id) { try { @@ -458,16 +462,16 @@ if ($model->edit_id == \Yii::$app->user->id) { $this->unblockOrder($id); } - + if (!$model->published) { $model->deleteUnpublished(); } - return $this->redirect('index'); + return $this->redirect('index'); } public function actionBlockOrder() { - if (!empty(\Yii::$app->request->post())) { + if (!empty( \Yii::$app->request->post() )) { \Yii::$app->response->format = Response::FORMAT_JSON; $model = $this->findModel(\Yii::$app->request->post('id')); @@ -484,7 +488,7 @@ if ($model->save()) { return [ 'time' => $date, - 'user' => !empty($user) ? $user->username : '', + 'user' => !empty( $user ) ? $user->username : '', ]; } else { return [ diff --git a/views/order/print.php b/views/order/print.php new file mode 100755 index 0000000..3f69a56 --- /dev/null +++ b/views/order/print.php @@ -0,0 +1,208 @@ + +beginPage(); ?> + + + + + head() ?> + + + +beginBody(); ?> +
+ $order, + 'attributes' => [ + [ + 'attribute' => 'manager.username', + 'label' => \Yii::t('app', 'Manager Username'), + ], + 'id', + 'created_at:date', + [ + 'attribute' => 'user.username', + 'label' => \Yii::t('app', 'Client Username'), + ], + [ + 'attribute' => 'email', + 'value' => $order->email?:(!empty($order->user)?$order->user->email:null), + ], + [ + 'attribute' => 'phone', + 'value' => $order->phone?:(!empty($order->user)?$order->user->phone:null), + ], + [ + 'attribute' => 'phone2', + 'value' => $order->phone2?:null, + ], + [ + 'attribute' => 'numbercard', + 'value' => $order->numbercard?:null, + ], + [ + 'attribute' => 'comment', + 'value' => $order->comment?:null, + ], + [ + 'attribute' => 'delivery', + 'value' => $order->deliveryString?:null, + ], + [ + 'attribute' => 'declaration', + 'value' => $order->declaration?:null, + ], + [ + 'attribute' => 'stock', + 'value' => $order->stock?:null, + ], + [ + 'attribute' => 'payment', + 'value' => $order->orderPayment?$order->orderPayment->lang->title:null, + ], + [ + 'attribute' => 'insurance', + 'value' => $order->insurance?:null, + ], + [ + 'attribute' => 'amount_imposed', + 'value' => $order->amount_imposed?:null, + ], + [ + 'attribute' => 'shipping_by', + 'value' => $order->shipping_by?:null, + ], + [ + 'attribute' => 'city', + 'value' => $order->city?:null, + ], + [ + 'attribute' => 'adress', + 'value' => $order->adress?:null, + ], + [ + 'attribute' => 'body', + 'value' => $order->body?:null, + ], + ], + ]); + ?> +
+
+products)) { + echo GridView::widget([ + 'tableOptions' => [ + 'cellspacing' => '10', + 'cellpadding' => '3', + ], + 'dataProvider' => $dataProvider, + 'columns' => [ + [ + 'class' => 'yii\grid\SerialColumn', + ], + 'sku', + [ + 'attribute' => 'productVariant.product.brand.lang.title', + 'label' => \Yii::t('app', 'Brand'), + ], + [ + 'attribute' => 'productVariant.product.fullName', + 'label' => \Yii::t('app', 'Fullname'), + ], + [ + 'label' => \Yii::t('app', 'Properties'), + 'value' => function($model) { + /** + * @var OrderProduct $model + */ + $value = ''; + foreach ($model->productVariant->properties as $property) { + $value .= $property->lang->title.':'.implode(',', ArrayHelper::getColumn($property->customOptions, 'lang.value')).'
'; + } + return $value; + }, + 'format' => 'html', + ], + 'count', + 'price', + 'sum_cost', + 'booking', + ], + 'showOnEmpty' => false, + 'layout' => "{items}", + ]); +} + ?> +
+
+
getAttributeLabel('total').': '.\Yii::$app->formatter->asDecimal($order->total); ?> грн.
+
getAttributeLabel('delivery_cost').': '.\Yii::$app->formatter->asDecimal($order->delivery_cost); ?>
+
+
+
+ $order, + 'attributes' => [ + 'id', + 'created_at:date', + [ + 'attribute' => 'user.username', + 'label' => \Yii::t('app', 'Client Username'), + ], + [ + 'attribute' => 'phone', + 'value' => $order->phone?:(!empty($order->user)?$order->user->phone:null), + ], + [ + 'attribute' => 'city', + 'value' => $order->city?:null, + ], + [ + 'attribute' => 'adress', + 'value' => $order->adress?:null, + ], + [ + 'attribute' => 'comment', + 'value' => $order->comment?:null, + ], + [ + 'attribute' => 'stock', + 'value' => $order->stock?:null, + ], + [ + 'attribute' => 'insurance', + 'value' => $order->insurance?:null, + ], + [ + 'attribute' => 'amount_imposed', + 'value' => $order->amount_imposed?:null, + ], + [ + 'attribute' => 'shipping_by', + 'value' => $order->shipping_by?:null, + ], + ], +]); + ?> +
+endBody(); ?> + + +endPage(); ?> \ No newline at end of file -- libgit2 0.21.4