/** * 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()]); } }