Beispiel #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductStockModel::find();
     $query->select(['product_stock.*', 'product.*', 'warehouse.*']);
     $query->with(['product.group']);
     $query->joinWith(['product', 'warehouse']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['warehouse_id' => $this->warehouse_id, 'product_id' => $this->product_id, 'qty' => $this->qty, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andWhere(['like', 'lower(product.name)', strtolower($this->product_name)]);
     $query->andWhere(['like', 'lower(product.code)', strtolower($this->product_code)]);
     return $dataProvider;
 }
 /**
  * Finds the ProductStock model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $warehouse_id
  * @param integer $product_id
  * @return ProductStock the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($warehouse_id, $product_id)
 {
     if (($model = ProductStock::findOne(['warehouse_id' => $warehouse_id, 'product_id' => $product_id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }