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(); ?> +