/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Schedulegroup::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, 'STATUS' => $this->STATUS, 'CREATE_AT' => $this->CREATE_AT, 'UPDATE_AT' => $this->UPDATE_AT]); $query->andFilterWhere(['like', 'SCDL_GROUP_NM', $this->SCDL_GROUP_NM])->andFilterWhere(['like', 'KETERANGAN', $this->KETERANGAN])->andFilterWhere(['like', 'CREATE_BY', $this->CREATE_BY])->andFilterWhere(['like', 'UPDATE_BY', $this->UPDATE_BY]); return $dataProvider; }
/** author : wawan * Creates a new Scheduleheader model. * If creation is successful,batch insert table c0002scdl_detail. * @return mixed */ public function actionCreateGroup($tgl1, $tgl2) { if (Helper::checkRoute('create-group')) { $model = new Scheduleheader(); // data select2 for USER_ID where CRM and STATUS 10(active) $connection = \Yii::$app->db_esm; $querycariuser = '******' . $tgl1 . '") AND POSITION_SITE = "CRM" AND STATUS = 10'; $user = $connection->createCommand($querycariuser)->queryAll(); $datauser = ArrayHelper::map($user, 'id', 'username'); // data select2 for SCDL_GROUP $connection = \Yii::$app->db_esm; $model1 = $connection->createCommand('SELECT * from c0007 where ID NOT IN (SELECT DISTINCT(SCDL_GROUP) FROM c0002scdl_detail WHERE TGL="' . $tgl1 . '")'); $query = $model1->queryAll(); $datagroup = ArrayHelper::map($query, 'ID', 'SCDL_GROUP_NM'); //componen $profile = Yii::$app->getUserOptcrm->Profile_user(); $usercreate = $profile->username; //proses save if ($model->load(Yii::$app->request->post())) { $model->TGL1 = $tgl1; $model->TGL2 = $tgl2; $cari_groupName = Schedulegroup::find()->where(['ID' => $model->SCDL_GROUP])->asArray()->one(); /* split array author : wawan*/ $temp = explode(" ", $cari_groupName['SCDL_GROUP_NM']); $result = ''; foreach ($temp as $t) { $result .= $t[0]; } $model->NOTE = $result; $model->CREATE_BY = $usercreate; $model->CREATE_AT = date("Y-m-d H:i:s"); if ($model->save()) { // foreach date :author wawan for ($date = strtotime($tgl1); $date <= strtotime($tgl2); $date = strtotime("+1 day", $date)) { $tgl = date("Y-m-d", $date); //batch insert customers author :wawan $Customers = Customers::find()->where(['SCDL_GROUP' => $model->SCDL_GROUP])->asArray()->all(); foreach ($Customers as $key => $value) { # code... $connection = Yii::$app->db_esm; $connection->createCommand()->batchInsert('c0002scdl_detail', ['TGL', 'CUST_ID', 'SCDL_GROUP', 'USER_ID'], [[$tgl, $value['CUST_KD'], $model->SCDL_GROUP, $model->USER_ID]])->execute(); } } } return $this->redirect(['index']); } else { return $this->renderAjax('_formschedule', ['model' => $model, 'datagroup' => $datagroup, 'datauser' => $datauser]); } } else { return $this->renderAjax('_confirm_alert', []); } }
public function getGroup_scdl() { return $this->hasOne(Schedulegroup::className(), ['ID' => 'SCDL_GROUP']); }
/** * Finds the Schedulegroup model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Schedulegroup the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Schedulegroup::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }