/** * Creates a new RutaDiaria model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($idRuta) { $model = new RutaDiaria(); $ruta = Ruta::find()->where(['id' => $idRuta])->one(); $ordenComercios = OrdenComercio::find()->where(['id_ruta' => $idRuta])->all(); $model->id_usuario = $ruta->id_usuario; $model->fecha = date("Y-m-d"); if (!$this->existeRutaDiariaPorUsuarioYFecha($model->id_usuario, $model->fecha)) { $idRutaDiaria = $model->save(); if ($idRutaDiaria !== false) { $orden = 1; foreach ($ordenComercios as $ordenComercio) { $rutaDiariaComercio = new RutaDiariaComercio(); $rutaDiariaComercio->id_comercio = $ordenComercio->id_comercio; $rutaDiariaComercio->link("idRutaDiaria", $model); $rutaDiariaComercio->orden = $orden; $rutaDiariaComercio->save(); $orden++; } } Yii::$app->getSession()->setFlash('success', Yii::t('core', 'Daily Route has been created')); } else { Yii::$app->getSession()->setFlash('danger', Yii::t('core', 'There is already an instance of this route for today')); } return $this->redirect(['ruta/view', 'id' => $idRuta]); }
/** * Creates a new RutaDiariaComercio model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new RutaDiariaComercio(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }