/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = BillItem::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(['id' => $this->id, 'item_id' => $this->item_id, 'bill_id' => $this->bill_id, 'amount' => $this->amount, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'description', $this->description]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function searchWithItem($params) { $query = Bill::find(); $query->innerJoinWith('price'); $query->joinWith('billItems.item'); $query->orderBy(BillItem::tableName() . '.updated_at DESC'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new Sort(['attributes' => [self::tableName() . '.id', 'price_total' => ['asc' => ['price.total' => SORT_ASC], 'desc' => ['price.total' => SORT_DESC]], 'discount', self::tableName() . '.created_at', self::tableName() . '.updated_at'], 'defaultOrder' => [self::tableName() . '.updated_at' => 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([self::tableName() . '.id' => $this->id, 'price_id' => $this->price_id, 'discount' => $this->discount, self::tableName() . '.created_at' => $this->created_at, self::tableName() . '.updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'price.total', $this->price_total]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function searchWithItem($params) { $query = Item::find(); $query->innerJoinWith('itemPrices.price'); $query->joinWith('billItems'); $query->orderBy(BillItem::tableName() . '.quantity DESC'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => new Sort(['attributes' => ['name', 'code', 'quantity', 'quantity_stock', 'created_at', 'updated_at', 'item_total' => ['asc' => ['price.total' => SORT_ASC], 'desc' => ['price.total' => 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(['quantity' => $this->quantity, 'quantity_stock' => $this->quantity_stock, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'price.total', $this->item_total]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getBillItems() { return $this->hasMany(BillItem::className(), ['bill_id' => 'id']); }
/** * Finds the BillItem model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return BillItem the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = BillItem::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }