Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DraftPlan::find()->where('STATUS<>3')->orderBy(['GEO_ID' => SORT_DESC, 'GEO_SUB' => SORT_DESC, 'ODD_EVEN' => SORT_DESC, 'DAY_ID' => SORT_DESC]);
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => false]);
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['ID' => $this->ID, 'GEO_ID' => $this->GeoNm, 'LAYER_ID' => $this->LayerNm, 'DAY_ID' => $this->DAY_ID, 'DAY_VALUE' => $this->DayNm, 'STATUS' => $this->STATUS, 'YEAR' => $this->YEAR, 'ODD_EVEN' => $this->GanjilGenap, 'CREATED_AT' => $this->CREATED_AT, 'UPDATED_AT' => $this->UPDATED_AT, 'CUST_KD' => $this->CUST_KD]);
     $query->andFilterWhere(['like', 'CUST_KD', $this->CustNm])->andFilterWhere(['like', 'CREATED_BY', $this->CREATED_BY])->andFilterWhere(['like', 'UPDATED_BY', $this->UPDATED_BY]);
     return $dataProvider;
 }
Esempio n. 2
0
 /**
  * Creates a new DraftPlan model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new DraftPlan();
     if ($model->load(Yii::$app->request->post())) {
         $hsl = \Yii::$app->request->post();
         $tahun = $hsl['DraftPlan']['YEAR'];
         // $model->save();
         $check_exist = DraftPlan::find()->where(['GEO_ID' => $model->GEO_ID, 'YEAR' => $tahun])->one();
         /*get customers*/
         $get_customers = Customers::find()->where(['GEO' => $model->GEO_ID])->all();
         //     if(count($check_exist) != 0)
         //     {
         //        /*delete plan*/
         //         self::DeletePlan($model->GEO_ID);
         //         /*batch insert*/
         //         foreach ($get_customers as $key => $value) {
         //             # code...
         //               $batch = self::conn_esm()->CreateCommand()->batchInsert('c0002scdl_plan', ['CUST_KD', 'GEO_ID','LAYER_ID','YEAR'], [
         //             [$value->CUST_KD,$value->GEO,$value->LAYER,$tahun],
         //         ])->execute();
         //         }
         //     }else{
         //     /*batch insert*/
         //     foreach ($get_customers as $key => $value) {
         //         # code...
         //           $batch = self::conn_esm()->CreateCommand()->batchInsert('c0002scdl_plan', ['CUST_KD', 'GEO_ID','LAYER_ID','YEAR'], [
         //         [$value->CUST_KD,$value->GEO,$value->LAYER,$tahun],
         //     ])->execute();
         //     }
         // }
         if (count($check_exist) == 0) {
             /*batch insert*/
             foreach ($get_customers as $key => $value) {
                 # code...
                 $batch = self::conn_esm()->CreateCommand()->batchInsert('c0002scdl_plan', ['CUST_KD', 'GEO_ID', 'LAYER_ID', 'YEAR'], [[$value->CUST_KD, $value->GEO, $value->LAYER, $tahun]])->execute();
             }
         }
         return $this->redirect(['index']);
     } else {
         return $this->renderAjax('create', ['model' => $model, 'geo' => $this->get_arygeo()]);
     }
 }