/**
  * Creates a new Estimate model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Estimate();
     $attributes = Yii::$app->session->get(Estimate::className());
     if ($attributes) {
         $model->attributes = $attributes;
     }
     if ($model->load(Yii::$app->request->post())) {
         if (Yii::$app->request->getBodyParam('action')) {
             Yii::$app->session->set(Estimate::className(), $model->attributes);
             return $this->redirect(["client/create"]);
         } else {
             Yii::$app->session->remove(Estimate::className());
         }
         if ($model->save()) {
             return $this->redirect(['index']);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
 /**
  * Add a contact to an existing Client.
  * @param integer $id
  * @return mixed
  */
 public function actionAddContact($id)
 {
     $client = $this->findModel($id);
     $model = new ClientContact();
     $model->client_id = $client->id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $estimate = Yii::$app->session->get(Estimate::className());
         if ($estimate) {
             return $this->redirect(['estimate/create']);
         }
         return $this->redirect(['view', 'id' => $client->id]);
     } else {
         return $this->render('add-contact', ['model' => $model, 'client' => $client]);
     }
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getEstimate()
 {
     return $this->hasOne(Estimate::className(), ['id' => 'estimate_id']);
 }