/** * Lists all Customer models. * @return mixed */ public function actionIndex() { $query = Customer::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => Yii::$app->params['pagination']]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('index', ['models' => $models, 'pages' => $pages]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customer::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, 'photo_id' => $this->photo_id, 'gender' => $this->gender, 'date_of_birth' => $this->date_of_birth, 'token_expired' => $this->token_expired, 'state' => $this->state, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'cus_fullname', $this->cus_fullname])->andFilterWhere(['like', 'token', $this->token]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Customer::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); /* $dataProvider->setSort([ 'attributes' =>[ 'customerCodeLink'=>[ 'asc' => ['customer_code' => SORT_ASC], 'desc' => ['customer_code' => SORT_DESC], ], 'customerNameLink'=>[ 'asc' => ['customer_name' => SORT_ASC], 'desc' => ['customer_name' => 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([ 'id' => $this->id, 'gender' => $this->gender, 'customer_type' => $this->customer_type, 'birthday' => $this->birthday, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, ]);*/ if (isset($this->specialQuery_input) && isset($this->specialQuery_options)) { $query->andFilterWhere(['like', 'customer_code', $this->specialQuery_input])->orFilterWhere(['like', 'customer_name', $this->specialQuery_input])->orFilterWhere(['like', 'phone_number', $this->specialQuery_input]); if ($this->specialQuery_options == 2) { $query->andFilterWhere(['>', 'debit', 0]); } if ($this->specialQuery_options == 3) { $query->andFilterWhere(['=', 'customer_type', '1']); } if ($this->specialQuery_options == 4) { $query->andFilterWhere(['=', 'customer_type', '0']); } } else { $query->andFilterWhere(['like', 'customer_code', $this->customer_code])->andFilterWhere(['like', 'customer_name', $this->customer_name])->andFilterWhere(['=', 'customer_type', $this->customer_type])->andFilterWhere(['like', 'phone_number', $this->phone_number]); } return $dataProvider; }
/** * Creates a new Invoice model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Invoice(); if ($model->load(Yii::$app->request->post())) { //get Customer information $customer = Customer::find()->where(['id' => 1])->asArray()->one(); /* echo '<pre>'; print_r(JSON::encode($customer)); echo '</pre>';*/ $model->attribute1 = JSON::encode($customer); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model]); } }