/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UePartidaEntidad::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'id_ue' => $this->id_ue, 'id_tipo_entidad' => $this->id_tipo_entidad]);
     $query->select(['ANY_VALUE(id) as id', 'cuenta', 'partida'])->andFilterWhere(['like', 'cuenta', $this->cuenta])->andFilterWhere(['like', 'partida', $this->partida])->groupBy('partida, cuenta');
     return $dataProvider;
 }
Beispiel #2
0
 public function obtener_uej_relacionadas($entidad, $cuenta, $partida)
 {
     $ue = "";
     $uej = UePartidaEntidad::find()->select(['unidad_ejecutora.nombre as name'])->innerjoin('unidad_ejecutora', 'ue_partida_entidad.id_ue=unidad_ejecutora.id')->where(['ue_partida_entidad.cuenta' => $cuenta])->andWhere(['ue_partida_entidad.partida' => $partida])->andwhere(['ue_partida_entidad.id_tipo_entidad' => $entidad])->asArray()->all();
     foreach ($uej as $key => $value) {
         $ue .= $value['name'] . ", ";
     }
     $ue = substr($ue, 0, -2);
     return $ue;
 }
 /**
  * Updates an existing AccionCentralizadaPedido 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);
     //autocomplete
     //$materiales = MaterialesServicios::find()
     //      ->select(['nombre', 'id', 'precio'])
     //    ->all();
     $materiales = UePartidaEntidad::find()->andWhere(['id_tipo_entidad' => 2])->andWhere(['id_ue' => $model->asignado0->accion_especifica_ue0->id_ue])->All();
     foreach ($materiales as $key => $value) {
         foreach ($value->materialesPartidaEntidad as $key => $value) {
             if (isset($value)) {
                 $materiales1[] = $value;
             }
         }
     }
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         //verificando que la unidad ejecutora no este aprobada
         $usuario = UserAccounts::findOne(\Yii::$app->user->id);
         $accion = AccionCentralizadaAsignar::find()->where(['usuario' => $usuario->id])->One();
         if ($accion->accion_centralizada_ac_especifica_uej->aprobado == 1) {
             return ['title' => "Requerimientos", 'content' => '<span class="text-danger">Esta Unidad Ejecutora Ya no Puede Realizar Pedidos </span>', 'footer' => Html::button('Cerrar', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"])];
         }
         if ($request->isGet) {
             return ['title' => "Pedido", 'content' => $this->renderAjax('update', ['model' => $this->findModel($id), 'materiales' => $materiales1]), 'footer' => Html::button('Cerrar', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Guardar', ['class' => 'btn btn-primary', 'type' => "submit"])];
         } else {
             if ($model->load($request->post()) && $model->save()) {
                 return ['forceReload' => 'true', 'title' => "Pedido", 'content' => $this->renderAjax('view', ['model' => $this->findModel($id), 'materiales' => $materiales1]), 'footer' => Html::button('Cerrar', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Editar', ['update', 'id' => $id], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])];
             } else {
                 return ['title' => "Pedido", 'content' => $this->renderAjax('update', ['model' => $this->findModel($id), 'materiales' => $materiales1]), 'footer' => Html::button('Cerrar', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Guardar', ['class' => 'btn btn-primary', 'type' => "submit"])];
             }
         }
     } else {
         /*
          *   Process for non-ajax request
          */
         if ($model->load($request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('update', ['model' => $model, 'materiales' => $materiales]);
         }
     }
 }
 /**
  * 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]);
     }
 }