Example #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = $this->find();
     $query->joinWith(['product', 'order']);
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     /* uncomment to sort by relations table on respective column */
     $dataProvider->sort->attributes['productTitle'] = ['asc' => [Product::tableName() . '.title' => SORT_ASC], 'desc' => [Product::tableName() . '.title' => 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()], ['product_id'], ['order_id'], ['amount'], ['quantity'], ['isdel']]);
     foreach ($params as $p) {
         $query->andFilterWhere($p);
     }
     $params = self::queryString([['data']]);
     foreach ($params as $p) {
         $query->andFilterWhere($p);
     }
     $params = self::queryTime([['time', $this->tableName()]]);
     foreach ($params as $p) {
         $query->andFilterWhere($p);
     }
     /* example to use search all in field1,field2,field3 or field4
     		if ($this->term)
     		{
     			$query->andFilterWhere(["OR","lower(field1) like '%".strtolower($this->term)."%'",
     				["OR","lower(field2) like '%".strtolower($this->term)."%'",
     					["OR","lower(field3) like '%".strtolower($this->term)."%'",
     						"lower(field4) like '%".strtolower($this->term)."%'"						
     					]
     				]
     			]);	
     		}	
     		*/
     $query->andFilterWhere(["like", "lower(" . Product::tableName() . ".title)", strtolower($this->productTitle)]);
     $query->andFilterWhere(["like", "lower(" . Order::tableName() . ".reference)", strtolower($this->orderReference)]);
     return $dataProvider;
 }
Example #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOrder()
 {
     return $this->hasOne(Order::className(), ['id' => 'order_id']);
 }
 /**
  * Finds the Order model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Order the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Order::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getYesOrders()
 {
     return $this->hasMany(Order::className(), ['customer_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;
 }
Example #6
0
 public static function find()
 {
     return parent::find()->where([Order::tableName() . '.isdel' => 0]);
 }