/**
  * Creates a new GoodsMovement model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($type = null)
 {
     $model = new GoodsMovement();
     $model->type = $type;
     $model->description = $type == GoodsMovement::TYPE_RECEIVE ? 'Penerimaan Pembelian' : 'Pengeluaran Manual';
     $model->date = date('Y-m-d');
     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]);
 }
 public function actionCreateReceipt($type, $id, $desc = null)
 {
     $model = new GoodsMovement(['reff_type' => $type, 'reff_id' => $id, 'description' => $desc]);
     if (($reff = $model->updateFromReceipt()) !== false) {
         list($reffModel, $reff) = $reff;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     if ($type == GoodsMovement::REFF_TRANSFER) {
         $model->vendor_id = 12;
         $model->vendor_name = 'Internal';
     }
     $model->date = date('Y-m-d');
     $model->type = GoodsMovement::TYPE_RECEIVE;
     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]);
 }