/**
  * @return \yii\db\ActiveQuery
  */
 public function getIdProgramacion()
 {
     return $this->hasOne(AccionCentralizadaVariableProgramacion::className(), ['id' => 'id_programacion']);
 }
 /**
  * Updates an existing LocalizacionAccVariable model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id, $variable, $localizacion
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $request = Yii::$app->request;
     $model = $this->findModel($id);
     $model1 = AccionCentralizadaVariableProgramacion::find()->where(['id_localizacion' => $model->id])->One();
     $model->scenario = $localizacion == '0' ? 'Nacional' : 'Estadal';
     //lista desplegable
     $paises = Pais::find()->all();
     $estados = Estados::find()->all();
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Localización y Programación", 'content' => $this->renderPartial('update', ['model' => $model, 'pais' => $paises, 'estados' => $estados, 'model1' => $model1]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 $model1->id_localizacion = $model->id;
                 if ($model1->load($request->post()) && $model1->save()) {
                     return ['forceReload' => 'true', 'title' => "Localización y Programación", 'content' => $this->renderAjax('view', ['model' => $model, 'model1' => $model1, 'id' => $model->id]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Editar', ['update', 'id' => $model->id, 'variable' => $model->id_variable, 'localizacion' => $model->idVariable->localizacion], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
                 } else {
                     return ['title' => "Localización y Programación", 'content' => $this->renderAjax('update', ['model' => $model, 'pais' => $paises, 'estados' => $estados, 'model1' => $model1]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
                 }
             } else {
                 return ['title' => "Localización", 'content' => $this->renderAjax('update', ['model' => $model, 'pais' => $paises, 'estados' => $estados, 'model1' => $model1]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } else {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('update', ['model' => $model]);
         }
     }
 }
示例#3
0
 /**
  * mostrar si ya existe una ejecucion
  * @return bool
  */
 public function getObtener_Ejecucion()
 {
     $programacion_ejecucion = AccionCentralizadaVariableProgramacion::find()->innerjoin('accion_centralizada_variable_ejecucion', 'accion_centralizada_variable_programacion.id=accion_centralizada_variable_ejecucion.id_programacion')->where(['accion_centralizada_variable_programacion.id_localizacion' => $this->id])->one();
     if ($programacion_ejecucion == NULL) {
         return false;
     } else {
         return true;
     }
 }
 /**
  * Creates a new AccionCentralizadaVariableEjecucion model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($id, $id_localizacion)
 {
     $desbloqueo = "";
     $total_cargado = 0;
     $model = new AccionCentralizadaVariableEjecucion();
     $model_programacion = AccionCentralizadaVariableProgramacion::find()->where(['id_localizacion' => $id_localizacion])->All();
     $total = $model_programacion[0]['enero'] + $model_programacion[0]['febrero'] + $model_programacion[0]['marzo'] + $model_programacion[0]['abril'] + $model_programacion[0]['mayo'] + $model_programacion[0]['junio'] + $model_programacion[0]['julio'] + $model_programacion[0]['agosto'] + $model_programacion[0]['septiembre'] + $model_programacion[0]['octubre'] + $model_programacion[0]['noviembre'] + $model_programacion[0]['diciembre'];
     $model_inicial = AccionCentralizadaVariableEjecucion::find()->where(['id_programacion' => $model_programacion[0]['id']])->asArray()->One();
     $model->id_programacion = $model_programacion[0]['id'];
     $model->id_usuario = Yii::$app->user->getId();
     $hoy = getdate();
     $fecha = $hoy['year'] . "/" . $hoy['mon'] . "/" . $hoy['mday'] . " " . $hoy['hours'] . ":" . $hoy['minutes'] . ":" . $hoy['seconds'];
     $model->fecha = $fecha;
     $desbloqueo[0] = 0;
     //verificar campos bloqueado
     if ($model_inicial == NULL) {
         //primera vez que carga, deberia habilitarse solamente enero
         $desbloqueo[0] = 1;
     } else {
         //verificar mes pendiente con la fecha o ultima carga realizada y fecha
         if ($model_inicial['diciembre'] == NULL && ($hoy['mon'] == 12 && $hoy['mday'] >= 5 || $hoy['mon'] > 12)) {
             $desbloqueo[0] = 12;
         }
         if ($model_inicial['noviembre'] == NULL && ($hoy['mon'] == 11 && $hoy['mday'] >= 5 || $hoy['mon'] > 11)) {
             $desbloqueo[0] = 11;
         }
         if ($model_inicial['octubre'] == NULL && ($hoy['mon'] == 10 && $hoy['mday'] >= 5 || $hoy['mon'] > 10)) {
             $desbloqueo[0] = 10;
         }
         if ($model_inicial['septiembre'] == NULL && ($hoy['mon'] == 9 && $hoy['mday'] >= 5 || $hoy['mon'] > 9)) {
             $desbloqueo[0] = 9;
         }
         if ($model_inicial['agosto'] == NULL && ($hoy['mon'] == 8 && $hoy['mday'] >= 5 || $hoy['mon'] > 8)) {
             $desbloqueo[0] = 8;
         }
         if ($model_inicial['julio'] == NULL && ($hoy['mon'] == 7 && $hoy['mday'] >= 5 || $hoy['mon'] > 7)) {
             $desbloqueo[0] = 7;
         }
         if ($model_inicial['junio'] == NULL && ($hoy['mon'] == 6 && $hoy['mday'] >= 5 || $hoy['mon'] > 6)) {
             $desbloqueo[0] = 6;
         }
         if ($model_inicial['mayo'] == NULL && ($hoy['mon'] == 5 && $hoy['mday'] >= 5 || $hoy['mon'] > 5)) {
             $desbloqueo[0] = 5;
         }
         if ($model_inicial['abril'] == NULL && ($hoy['mon'] == 4 && $hoy['mday'] >= 5 || $hoy['mon'] > 4)) {
             $desbloqueo[0] = 4;
         }
         if ($model_inicial['marzo'] == NULL && ($hoy['mon'] == 3 && $hoy['mday'] >= 5 || $hoy['mon'] > 3)) {
             $desbloqueo[0] = 3;
         }
         if ($model_inicial['febrero'] == NULL && ($hoy['mon'] == 2 && $hoy['mday'] >= 5 || $hoy['mon'] > 2)) {
             $desbloqueo[0] = 2;
         }
         //verificamos si desde el backend se le dio permiso para habilitar campos
         $permisos_espe = AccionCentralizadaDesbloqueoMes::find()->where(['id_ejecucion' => $model_inicial['id']])->asArray()->All();
         if ($permisos_espe != "") {
             foreach ($permisos_espe as $key) {
                 // se cargan los meses que se le dio permiso de carga
                 $desbloqueo[$key['mes']] = '1';
             }
         }
         $model = $this->findModel($model_inicial['id']);
         $total_cargado = $model->enero + $model->febrero + $model->marzo + $model->abril + $model->mayo + $model->junio + $model->julio + $model->agosto + $model->septiembre + $model->octubre + $model->noviembre + $model->diciembre;
     }
     //fin else modelo con datos
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['create', 'id' => $id, 'id_localizacion' => $id_localizacion]);
     } else {
         return $this->render('create', ['model' => $model, 'model_programacion' => $model_programacion, 'total' => $total, 'desbloqueo' => $desbloqueo, 'total_cargado' => $total_cargado]);
     }
 }