Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MaterialesServicios::find();
     // Join para la relacion
     $query->joinWith(['cuenta0']);
     $query->joinWith(['presentacion0']);
     $query->joinWith(['unidadMedida']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //Ordenamiento
     $dataProvider->sort->attributes['nombrePresentacion'] = ['asc' => ['presentacion.nombre' => SORT_ASC], 'desc' => ['presentacion.nombre' => SORT_DESC]];
     $dataProvider->sort->attributes['nombreUnidadMedida'] = ['asc' => ['unidad_medida.unidad_medida' => SORT_ASC], 'desc' => ['unidad_medida.unidad_medida' => SORT_DESC]];
     $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, 'cuenta' => $this->cuenta, 'partida' => $this->partida, 'generica' => $this->generica, 'especifica' => $this->especifica, 'subespecifica' => $this->subespecifica, 'unidad_medida' => $this->unidad_medida, 'presentacion' => $this->presentacion, 'precio' => $this->precio, 'iva' => $this->iva, 'materiales_servicios.estatus' => $this->estatus]);
     $query->andFilterWhere(['materiales_servicios.estatus' => $this->nombreEstatus]);
     $query->andFilterWhere(['like', 'nombre', $this->nombre]);
     $query->andFilterWhere(['like', 'presentacion.nombre', $this->nombrePresentacion]);
     $query->andFilterWhere(['like', 'unidad_medida.unidad_medida', $this->nombreUnidadMedida]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdMaterial()
 {
     return $this->hasOne(MaterialesServicios::className(), ['id' => 'id_material']);
 }
 /**
  * Finds the MaterialesServicios model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return MaterialesServicios the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = MaterialesServicios::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 4
0
 public function getMaterialesPartidaEntidad()
 {
     return $this->hasMany(MaterialesServicios::className(), ['cuenta' => 'cuenta', 'partida' => 'partida']);
 }
Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMaterialesServicios()
 {
     return $this->hasMany(MaterialesServicios::className(), ['presentacion' => 'id']);
 }
Esempio n. 6
0
 /**
  * Updates an existing ProyectoPedido 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', 'iva'])->all();
     //Arreglo de precios, iva, etc con id del material/servicio
     $precios = json_encode(ArrayHelper::toArray(ArrayHelper::index($materiales, 'id')));
     if ($request->isAjax) {
         /*
          *   Process for ajax request
          */
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isGet) {
             return ['title' => "Pedido", 'content' => $this->renderAjax('update', ['model' => $this->findModel($id), 'materiales' => $materiales, 'precios' => $precios]), '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' => $materiales, 'precios' => $precios]), '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' => $materiales, 'precios' => $precios]), '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, 'precios' => $precios]);
         }
     }
 }
Esempio n. 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMaterialesServicios()
 {
     return $this->hasOne(MaterialesServicios::className(), ['cuenta' => 'cuenta', 'partida' => 'partida', 'generica' => 'generica', 'especifica' => 'especifica', 'subespecifica' => 'subespecifica']);
 }
 public function actionLlenarprecio()
 {
     $request = Yii::$app->request;
     if ($request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         if ($request->isPost) {
             //Acciones Especificas
             $ace = MaterialesServicios::find()->select(["precio", "iva"])->where(['id' => $request->post('id')])->asArray()->all();
             if ($ace != null) {
                 return $ace;
             } else {
                 return 0;
             }
         }
     }
 }