/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Scheduleheader::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, 'TGL1' => $this->TGL1, 'SCDL_GROUP' => $this->SCDL_GROUP, 'STATUS' => $this->STATUS, 'CREATE_AT' => $this->CREATE_AT, 'UPDATE_AT' => $this->UPDATE_AT]); $query->andFilterWhere(['like', 'USER_ID', $this->USER_ID])->andFilterWhere(['like', 'NOTE', $this->NOTE])->andFilterWhere(['like', 'CREATE_BY', $this->CREATE_BY])->andFilterWhere(['like', 'UPDATE_BY', $this->UPDATE_BY]); return $dataProvider; }
public function actionJsoncalendar_add() { if (Yii::$app->request->isAjax) { $request = Yii::$app->request; $model = new Scheduleheader(); $profile = Yii::$app->getUserOptcrm->Profile_user(); $usercreate = $profile->username; $end = $request->post('tgl2'); $start = $request->post('tgl1'); $scdl_group = $request->post('scdl_group'); $user_id = $request->post('user_id'); $note = $request->post('note'); $model->TGL1 = $start; $model->TGL2 = $end; $model->CREATE_BY = $usercreate; $model->CREATE_AT = date("Y-m-d H:i:s"); $model->NOTE = $note; $model->SCDL_GROUP = $scdl_group; $model->USER_ID = $user_id; $carisdl = ScheduleDetail::find()->where(['TGL' => $model->TGL1, 'SCDL_GROUP' => $scdl_group])->one(); // print_r($carisdl); // die(); // if exist data customers if ($carisdl) { echo 2; } else { if ($model->save()) { // foreach date :author wawan for ($date = strtotime($start); $date < strtotime($end); $date = strtotime("+1 day", $date)) { $tgl = date("Y-m-d", $date); $Customers = Customers::find()->where(['SCDL_GROUP' => $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'], $scdl_group, $user_id]])->execute(); } } } } } return true; }