Exemplo n.º 1
0
 /**
  * Creates a new GoodsMovement model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($type, $id, $desc = null)
 {
     $model = new GoodsMovement(['reff_type' => $type, 'reff_id' => $id, 'description' => $desc]);
     if (($reff = $model->updateFromReference()) !== false) {
         list($reffModel, $reff) = $reff;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $model->date = date('Y-m-d');
     $model->type = GoodsMovement::TYPE_ISSUE;
     if ($type == GoodsMovement::REFF_TRANSFER) {
         $model->vendor_id = 12;
         $model->vendor_name = 'Internal';
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->status = GoodsMovement::STATUS_DRAFT;
         $transaction = Yii::$app->db->beginTransaction();
         try {
             $model->items = Yii::$app->request->post('GoodsMovementDtl', []);
             if ($model->save()) {
                 $transaction->commit();
                 return $this->redirect(['view', 'id' => $model->id]);
             }
         } catch (\Exception $exc) {
             $transaction->rollBack();
             throw $exc;
         }
         $transaction->rollBack();
     }
     return $this->render('create', ['model' => $model, 'reffModel' => $reffModel, 'reff' => $reff]);
 }