/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Temporales::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(['idproducto' => $this->idproducto, 'fecha' => $this->fecha]); return $dataProvider; }
/** * Updates an existing Productos model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $img_model = new UploadForm(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $request = Yii::$app->request; $id_producto = $model->id; $fotos = Fotos::find()->where(['idProducto' => $id_producto])->all(); foreach ($fotos as $foto) { Fotos::deleteFoto($foto); } $img_model->imageFiles = UploadedFile::getInstances($img_model, 'imageFiles'); if ($img_model->upload($model->id)) { if ($model->tipo == 0) { return $this->redirect(['view', 'id' => $model->id]); } else { if ($model->tipo == 1) { $porTiempo = Temporales::find()->where(['idproducto' => $model->id])->one(); $porTiempo->fecha = $request->post('fecha'); $porTiempo->idproducto = $model->id; $porTiempo->save(); return $this->redirect(['view', 'id' => $model->id]); } else { $stock = Stock::find()->where(['idproducto' => $model->id])->one(); $cantidad = $request->post('cant'); $stock->stock = $cantidad; $stock->idproducto = $model->id; $stock->save(); return $this->redirect(['view', 'id' => $model->id]); } } } } else { return $this->render('update', ['model' => $model, 'img_model' => $img_model]); } }
public function actionIndex() { $this->layout = 'frontoffice'; $parametro = date('Y-m-d'); $lista = Temporales::find()->where(['fecha' => $parametro])->all(); return $this->render('index', ['model' => $lista]); }
/** * @return \yii\db\ActiveQuery */ public function getTemporales() { return $this->hasOne(Temporales::className(), ['idproducto' => 'id']); }
/** * Finds the Temporales model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Temporales the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Temporales::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }