コード例 #1
0
 public function actionCrear()
 {
     PermisosController::permisoDocenteDirectorDecano();
     $model = new SolicitudMet();
     if ($model->load(Yii::$app->request->post())) {
         $tableviaje = new Viaje();
         $tableviaje->ORIGEN_VIAJE = $model->origen;
         $tableviaje->FECHA_INICIO_DIRECCION = $model->anhoi . '-' . $model->mesi . '-' . $model->diai . ' ' . '00:' . '00:' . '01';
         $tableviaje->FECHA_TERMINO_DIRECCION = $model->anhot . '-' . $model->mest . '-' . $model->diat . ' ' . '23:' . '59:' . '59';
         $tableviaje->insert();
         $ultimoidviaje = solicitudMet::ultimoID();
         if ($model->check1 == 1) {
             $tabledestino = new Destino();
             $tabledestino->ID_VIAJE = $ultimoidviaje;
             $tabledestino->DURACION_VIAJE_DIAS = $model->duracion1;
             $tabledestino->MEDIO_DE_TRANSPORTE = $model->transporte1;
             $tabledestino->CIUDAD_DESTINO = $model->ciudad1;
             $tabledestino->PAIS_DESTINO = $model->pais1;
             $tabledestino->insert();
         } else {
             $viaje = Viaje::find()->where(['ID_VIAJE' => $ultimoidviaje])->one();
             $viaje->delete();
             $tablesolicitud = new Solicitud();
             $msg = '<div class="alert alert-warning" role="alert"><strong>ERROR!</strong> No se envi&#243; la solicitud, ingrese datos v&#225;lidos.</div>';
             $modelsolicitud = $tablesolicitud->find()->where(['ID_USUARIO' => Yii::$app->user->identity->ID_USUARIO])->all();
             return $this->render('index', ['model' => $modelsolicitud, 'msg' => $msg]);
         }
         if ($model->check2 == 1) {
             if ($model->duracion2 != null && $model->transporte2 != null && $model->ciudad2 != null && $model->pais2 != null) {
                 $tabledestino2 = new Destino();
                 $tabledestino2->ID_VIAJE = $ultimoidviaje;
                 $tabledestino2->DURACION_VIAJE_DIAS = $model->duracion2;
                 $tabledestino2->MEDIO_DE_TRANSPORTE = $model->transporte2;
                 $tabledestino2->CIUDAD_DESTINO = $model->ciudad2;
                 $tabledestino2->PAIS_DESTINO = $model->pais2;
                 $tabledestino2->insert();
             } else {
                 Destino::deleteAll("ID_VIAJE=" . $ultimoidviaje);
                 $viaje = Viaje::find()->where(['ID_VIAJE' => $ultimoidviaje])->one();
                 $viaje->delete();
                 $tablesolicitud = new Solicitud();
                 $msg = '<div class="alert alert-danger" role="alert"><strong>ERROR!</strong> No se envi&#243; la solicitud, ingrese datos v&#225;lidos.</div>';
                 $modelsolicitud = $tablesolicitud->find()->where(['ID_USUARIO' => Yii::$app->user->identity->ID_USUARIO])->all();
                 return $this->render('index', ['model' => $modelsolicitud, 'msg' => $msg]);
             }
         }
         if ($model->check3 == 1) {
             if ($model->duracion3 != null && $model->transporte3 != null && $model->ciudad3 != null && $model->pais3 != null) {
                 $tabledestino3 = new Destino();
                 $tabledestino3->ID_VIAJE = $ultimoidviaje;
                 $tabledestino3->DURACION_VIAJE_DIAS = $model->duracion3;
                 $tabledestino3->MEDIO_DE_TRANSPORTE = $model->transporte3;
                 $tabledestino3->CIUDAD_DESTINO = $model->ciudad3;
                 $tabledestino3->PAIS_DESTINO = $model->pais3;
                 $tabledestino3->insert();
             } else {
                 Destino::deleteAll("ID_VIAJE=" . $ultimoidviaje);
                 $viaje = Viaje::find()->where(['ID_VIAJE' => $ultimoidviaje])->one();
                 $viaje->delete();
                 $tablesolicitud = new Solicitud();
                 $msg = '<div class="alert alert-danger" role="alert"><strong>ERROR!</strong> No se envi&#243; la solicitud, ingrese datos v&#225;lidos.</div>';
                 $modelsolicitud = $tablesolicitud->find()->where(['ID_USUARIO' => Yii::$app->user->identity->ID_USUARIO])->all();
                 return $this->render('index', ['model' => $modelsolicitud, 'msg' => $msg]);
             }
         }
         if ($model->check4 == 1) {
             if ($model->duracion4 != null && $model->transporte4 != null && $model->ciudad4 != null && $model->pais4 != null) {
                 $tabledestino4 = new Destino();
                 $tabledestino4->ID_VIAJE = $ultimoidviaje;
                 $tabledestino4->DURACION_VIAJE_DIAS = $model->duracion4;
                 $tabledestino4->MEDIO_DE_TRANSPORTE = $model->transporte4;
                 $tabledestino4->CIUDAD_DESTINO = $model->ciudad4;
                 $tabledestino4->PAIS_DESTINO = $model->pais4;
                 $tabledestino4->insert();
             } else {
                 Destino::deleteAll("ID_VIAJE=" . $ultimoidviaje);
                 $viaje = Viaje::find()->where(['ID_VIAJE' => $ultimoidviaje])->one();
                 $viaje->delete();
                 $tablesolicitud = new Solicitud();
                 $msg = '<div class="alert alert-danger" role="alert"><strong>ERROR!</strong> No se envi&#243; la solicitud, ingrese datos v&#225;lidos.</div>';
                 $modelsolicitud = $tablesolicitud->find()->where(['ID_USUARIO' => Yii::$app->user->identity->ID_USUARIO])->all();
                 return $this->render('index', ['model' => $modelsolicitud, 'msg' => $msg]);
             }
         }
         if ($model->check5 == 1) {
             if ($model->duracion5 != null && $model->transporte5 != null && $model->ciudad5 != null && $model->pais5 != null) {
                 $tabledestino5 = new Destino();
                 $tabledestino5->ID_VIAJE = $ultimoidviaje;
                 $tabledestino5->DURACION_VIAJE_DIAS = $model->duracion5;
                 $tabledestino5->MEDIO_DE_TRANSPORTE = $model->transporte5;
                 $tabledestino5->CIUDAD_DESTINO = $model->ciudad5;
                 $tabledestino5->PAIS_DESTINO = $model->pais5;
                 $tabledestino5->insert();
             } else {
                 Destino::deleteAll("ID_VIAJE=" . $ultimoidviaje);
                 $viaje = Viaje::find()->where(['ID_VIAJE' => $ultimoidviaje])->one();
                 $viaje->delete();
                 $tablesolicitud = new Solicitud();
                 $msg = '<div class="alert alert-danger" role="alert"><strong>ERROR!</strong> No se envi&#243; la solicitud, ingrese datos v&#225;lidos.</div>';
                 $modelsolicitud = $tablesolicitud->find()->where(['ID_USUARIO' => 1])->all();
                 return $this->render('index', ['model' => $modelsolicitud, 'msg' => $msg]);
             }
         }
         $tablesolicitud = new Solicitud();
         $tablesolicitud->ID_USUARIO = Yii::$app->user->identity->ID_USUARIO;
         $tablesolicitud->ID_TIPO_DE_VIAJE = $model->idtipoviaje;
         $tablesolicitud->ID_VIAJE = $ultimoidviaje;
         $tablesolicitud->FECHA_SOLICITUD = date("Y-m-d H:i:s");
         $tablesolicitud->ID_ESTADO = 1;
         $tablesolicitud->CUERPO_SOLICITUD = $model->cuerpo;
         $tablesolicitud->insert();
         $tablesolicitud = new Solicitud();
         $msg = '<div class="alert alert-success" role="alert"><strong>Enviada!</strong> Solicitud enviada.</div>';
         $modelsolicitud = $tablesolicitud->find()->where(['ID_USUARIO' => Yii::$app->user->identity->ID_USUARIO])->all();
         return $this->render('index', ['model' => $modelsolicitud, 'msg' => $msg]);
     } else {
         $msg = null;
         $tablesolicitud = new TipoViaje();
         $modeltipos = $tablesolicitud->find()->all();
         return $this->render('crear-solicitud', ['model' => $model, 'tipos' => $modeltipos, 'msg' => $msg]);
     }
 }
コード例 #2
0
 /**
  * Displays a single Gastosasociados model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     PermisosController::permisoDocenteDirectorDecano();
     return $this->render('view', ['model' => $this->findModel($id)]);
 }
コード例 #3
0
ファイル: SiteController.php プロジェクト: MvegaR/ingSotfware
 public function actionCreate()
 {
     PermisosController::permisoDocenteDirectorDecano();
     $model = new FormGastos();
     $msg = null;
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $table = new Gastos();
             $table->ID_VIAJE = $model->id_viaje;
             $table->NOMBRE_GASTO = $model->nombregasto;
             $table->MONTO_GASTO = $model->montogasto;
             $table->FECHA_GASTO = $model->fechagasto;
             if ($table->insert()) {
                 $msg = "Registro guardado correctamente";
                 $model->id_viaje = null;
                 $model->nombregasto = null;
                 $model->montogasto = null;
             } else {
                 $msg = "Ha ocurrido un error";
             }
         } else {
             $model->getErrors();
         }
     }
     return $this->render("create", ['model' => $model, 'msg' => $msg]);
 }