/** * @return \yii\db\ActiveQuery */ public function getConfirmations() { return $this->hasMany(Confirmation::className(), ['payment_id' => 'id']); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = $this->find(); $query->joinWith(['order', 'payment']); $dataProvider = new ActiveDataProvider(['query' => $query]); /* uncomment to sort by relations table on respective column */ $dataProvider->sort->attributes['paymentTerminal'] = ['asc' => [Payment::tableName() . '.terminal' => SORT_ASC], 'desc' => [Payment::tableName() . '.terminal' => SORT_DESC]]; $dataProvider->sort->attributes['orderReference'] = ['asc' => [Order::tableName() . '.reference' => SORT_ASC], 'desc' => [Order::tableName() . '.reference' => SORT_DESC]]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } $params = self::queryNumber([['id', $this->tableName()], ['order_id'], ['payment_id'], ['amount'], ['isdel']]); foreach ($params as $p) { $query->andFilterWhere($p); } $params = self::queryString([['terminal', Confirmation::tableName()], ['account', Confirmation::tableName()], ['name', Confirmation::tableName()], ['remarks']]); foreach ($params as $p) { $query->andFilterWhere($p); } $params = self::queryTime([['time']]); foreach ($params as $p) { $query->andFilterWhere($p); } /* example to use search all in field1,field2,field3 or field4 */ if ($this->paymentTerminal) { $query->andFilterWhere(["OR", "lower(" . Payment::tableName() . ".terminal) like '%" . strtolower($this->paymentTerminal) . "%'", ["OR", "lower(" . Payment::tableName() . ".account) like '%" . strtolower($this->paymentTerminal) . "%'", "lower(" . Payment::tableName() . ".name) like '%" . strtolower($this->paymentTerminal) . "%'"]]); } $query->andFilterWhere(["like", "lower(" . Order::tableName() . ".reference)", strtolower($this->orderReference)]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getConfirmations() { return $this->hasMany(Confirmation::className(), ['order_id' => 'id'])->where("isdel=0"); }
/** * Finds the Confirmation model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Confirmation the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Confirmation::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }