Exemplo n.º 1
0
 /**
  * Creates a new Sales model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $sale = new Sales();
     $get = Yii::$app->request->get();
     $post = Yii::$app->request->post();
     $merged = array_replace_recursive($post, $get);
     $load = $sale->load($merged);
     $card = Card::findOne(['no', $sale->card]);
     $cardStatus = false;
     if ($card && intval($card->sum) > intval($sale->sum)) {
         $card->sum = $card->sum - intval($sale->sum);
         if ($card->save()) {
             $cardStatus = true;
         }
     }
     if ($card && $cardStatus && $card->status === 0 && $load && $sale->save()) {
         if (isset($get['backurl'])) {
             return $this->redirect(['/card/view', 'id' => $card->no]);
         } else {
             return $this->redirect(['view', 'id' => $sale->id]);
         }
     } else {
         $sale->addError('sum', 'Не достаточно средств на карте.' . ($card ? ' Доступно ' . $card->sum : null));
         return $this->render('create', ['model' => $sale]);
     }
 }
Exemplo n.º 2
0
 /**
  * Creates a new Sales model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Sales();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 3
0
 /**
  * Creates a new Sales model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($store)
 {
     $model = new Sales();
     $model->date = date('Y-m-d H:i:s');
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['stores/view', 'id' => $model->fkstore_id]);
     } else {
         return $this->render('create', ['model' => $model, 'store' => Stores::findOne($store), 'fruit' => Fruit::find()->asArray()->all()]);
     }
 }