Exemple #1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdTipoEntidad()
 {
     return $this->hasOne(TipoEntidad::className(), ['id' => 'id_tipo_entidad']);
 }
 /**
  * Updates an existing UePartidaEntidad model.
  * For ajax request will return json object
  * and for non-ajax request if update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $request = Yii::$app->request;
     $model = $this->findModel($id);
     $cuenta = $model->cuenta;
     $partida = $model->partida;
     $ue = ArrayHelper::map(UnidadEjecutora::find()->asArray()->all(), 'id', 'nombre');
     $tipo_entidad = arrayHelper::map(TipoEntidad::find()->asArray()->all(), 'id', 'nombre');
     $verificar = ArrayHelper::map(UePartidaEntidad::find()->where('cuenta= :id', ['id' => $model->cuenta])->andwhere(['partida' => $model->partida])->andwhere(['id_tipo_entidad' => 1])->all(), 'id', 'id_ue');
     $verificar_acc = ArrayHelper::map(UePartidaEntidad::find()->where('cuenta= :id', ['id' => $model->cuenta])->andwhere(['partida' => $model->partida])->andwhere(['id_tipo_entidad' => 2])->all(), 'id', 'id_ue');
     /*
      *   Process for post resquest
      */
     if ($request->post()) {
         //
         $connection = \Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
             //verificando los cambios en los tipos de entidad proyecto y acc
             $proyecto = $request->post('ue_proyecto');
             $acc = $request->post('ue_acc');
             if (empty($proyecto) && empty($acc)) {
                 Yii::$app->getSession()->setFlash('danger', 'Error, no puede dejar las partida sin unidad ejecutora');
                 return $this->render('update', ['model' => $model, 'ue' => $ue, 'tipo_entidad' => $tipo_entidad, 'precarga_proyecto' => $verificar, 'precarga_acc' => $verificar_acc]);
             }
             $model->UejEntidad($proyecto, 1);
             $model->UejEntidad($acc, 2);
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollback();
             Yii::$app->getSession()->setFlash('danger', 'Error al actualizar unidades.');
             return $this->render('update', ['model' => $model, 'ue' => $ue, 'tipo_entidad' => $tipo_entidad, 'precarga_proyecto' => $verificar, 'precarga_acc' => $verificar_acc]);
         }
         return $this->redirect(['view', 'partida' => $partida, 'cuenta' => $cuenta]);
     } else {
         return $this->render('update', ['model' => $model, 'ue' => $ue, 'tipo_entidad' => $tipo_entidad, 'precarga_proyecto' => $verificar, 'precarga_acc' => $verificar_acc]);
     }
 }