Пример #1
0
 public function validalias($model)
 {
     # code...
     $kondisiTrue = Barangalias::find()->where("KD_ALIAS='" . $this->KD_ALIAS . "' AND KD_DISTRIBUTOR='" . $this->KD_DISTRIBUTOR . "'")->one();
     if ($kondisiTrue) {
         $this->addError($model, 'Duplicated code because the code already exists in this distributor !, attention Better change name distributor or change code ');
     }
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Barangalias::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, 'KD_PARENT' => $this->KD_PARENT, 'CREATED_AT' => $this->CREATED_AT, 'UPDATED_AT' => $this->UPDATED_AT]);
     $query->andFilterWhere(['like', 'KD_BARANG', $this->KD_BARANG])->andFilterWhere(['like', 'KD_ALIAS', $this->KD_ALIAS])->andFilterWhere(['like', 'KD_DISTRIBUTOR', $this->KD_DISTRIBUTOR])->andFilterWhere(['like', 'CREATED_BY', $this->CREATED_BY])->andFilterWhere(['like', 'UPDATED_BY', $this->UPDATED_BY]);
     return $dataProvider;
 }
 public function actionUpdateAlias($id)
 {
     $model = Barangalias::find()->where(['KD_BARANG' => $id])->one();
     $id = Barang::find()->where(['KD_BARANG' => $id])->one();
     $nama = $id->NM_BARANG;
     $parent = $id->PARENT;
     if (Yii::$app->request->isAjax && $model->load($_POST)) {
         Yii::$app->response->format = 'json';
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->UPDATED_AT = date('Y-m-d');
         $model->UPDATED_BY = Yii::$app->user->identity->username;
         $model->save();
         return $this->redirect(['index-alias']);
     } else {
         return $this->renderAjax('_alias', ['model' => $model, 'id' => $id, 'nama' => $nama, 'parent' => $parent]);
     }
 }