Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Scheduleheader::find()->joinWith('scdlgroup', true, 'JOIN')->joinWith('user', true, 'JOIN');
     $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])->andFilterWhere(['like', 'username', $this->getAttribute('user.username')])->andFilterWhere(['like', 'SCDL_GROUP_NM', $this->getAttribute('scdlgroup.SCDL_GROUP_NM')]);
     return $dataProvider;
 }
 public function actionJsoncalendar_add()
 {
     if (Yii::$app->request->isAjax) {
         $request = Yii::$app->request;
         $model = new Scheduleheader();
         $profile = Yii::$app->getUserOpt->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;
 }
 /**
  * Creates a new Scheduleheader model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Scheduleheader();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->ID]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }