/**
  * Creates a new Product model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Product();
     $attributes = Yii::$app->session->get(Product::className());
     if ($attributes) {
         $model->attributes = $attributes;
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->getBodyParam('action')) {
             Yii::$app->session->set(Product::className(), $model->attributes);
             return $this->redirect(["supplier/create"]);
         } else {
             Yii::$app->session->remove(Product::className());
         }
         if ($model->save()) {
             $estimateEntry = Yii::$app->session->get(EstimateEntry::className());
             if ($estimateEntry) {
                 return $this->redirect(['estimate/create-entry', 'id' => $estimateEntry['estimate_id']]);
             }
             return $this->redirect(['view', 'id' => $model->id]);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
 /**
  * Creates a new EstimateEntry model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @param integer $id estimate id
  * @return mixed
  */
 public function actionCreateEntry($id)
 {
     $estimate = $this->findModel($id);
     $model = new EstimateEntry();
     $model->estimate_id = $estimate->id;
     $attributes = Yii::$app->session->get(EstimateEntry::className());
     if ($attributes) {
         $model->attributes = $attributes;
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->getBodyParam('action')) {
             Yii::$app->session->set(EstimateEntry::className(), $model->attributes);
             return $this->redirect(["product/create"]);
         } else {
             Yii::$app->session->remove(EstimateEntry::className());
         }
         if ($model->save()) {
             $estimate->doEstimate();
             return $this->redirect(['view', 'id' => $estimate->id]);
         }
     }
     return $this->render('create-entry', ['model' => $model]);
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEntries()
 {
     return $this->hasMany(EstimateEntry::className(), ['estimate_id' => 'id']);
 }