예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = ProductStockHistoryModel::find();
     $query->select(['product_stock_history.*', 'product.*', 'warehouse.*', 'goods_movement.number']);
     $query->joinWith(['product', 'warehouse', 'goodsmovements']);
     if (!isset($params['sort'])) {
         $query->orderBy(['product.name' => SORT_ASC, 'time' => SORT_ASC]);
     }
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         $query->where('1=0');
         return $dataProvider;
     }
     $query->andFilterWhere(['product_stock_history.time' => $this->time, 'product_stock_history.warehouse_id' => $this->warehouse_id, 'product_id' => $this->product_id, 'qty_movement' => $this->qty_movement, 'qty_current' => $this->qty_current, 'movement_id' => $this->movement_id]);
     $query->andWhere(['like', 'lower(product.name)', strtolower($this->product_name)]);
     $query->andWhere(['like', 'lower(product.code)', strtolower($this->product_code)]);
     if (isset($params['goods_movement_number']) && $params['goods_movement_number'] != '') {
         $query->andWhere(['like', 'lower(goods_movement.number)', strtolower($this->goods_movement_number)]);
     }
     return $dataProvider;
 }