/** * 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; }
/** * Finds the ProductStockHistory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param double $time * @param integer $warehouse_id * @param integer $product_id * @return ProductStockHistory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($time, $warehouse_id, $product_id) { if (($model = ProductStockHistory::findOne(['time' => $time, 'warehouse_id' => $warehouse_id, 'product_id' => $product_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }