예제 #1
0
 public function flightdata(Request $request)
 {
     $flight = $request->DATA2;
     if (strtolower($flight) == 'bid') {
         // Bids are not supported just yet so lets error out
         return '0|Bids Not Supported In VAOS Yet';
     } else {
         if (is_numeric($flight)) {
             return '0|No Airline Code';
         }
         $flightinfo = $this->getProperFlightNum($flight);
         $route = Schedule::where('code', $flightinfo['code'])->where('flightnum', $flightinfo['flightnum'])->first();
         // lets separate the eloquent array into a single thing to send to the view
         $rte;
         /*
         foreach ($route as $r)
         {
         	$rte->depicao = $r->depicao;
         	$rte->arricao = $r->arricao;
         	$rte->route = $r->route;
         	$rte->registration = $r->registration;
         	$rte->flightlevel = $r->flightlevel;
         }
         */
         $status = '1|flightplan';
         return view('ACARS.xacars')->with(['status' => '1|flightplan', 'routedata' => $route]);
         //"1|flightplan $route->depicao $route->arricao $route->arricao $route->route 180 30 IFR $route->registration $route->flightlevel";
     }
 }
예제 #2
0
 public function actionIndex()
 {
     $api = Yii::$app->scheduleAPI;
     $date = date("Y-m-d");
     $getDate = Yii::$app->request->get('date');
     if ($getDate != "") {
         $scheduleData = $api->getScheduleArray(array("date" => $getDate));
         //Получаем данные для построения программы
         $date = $getDate;
     } else {
         $scheduleData = $api->getScheduleArray(array("date" => $date));
     }
     $model = new Schedule();
     $model->setData($scheduleData);
     $model->setDateBuild($date);
     return $this->render('index', ['model' => $model]);
 }
예제 #3
0
 /**
  * @inheritdoc
  */
 public function beforeSave($insert)
 {
     if ($this->type == 1) {
         $this->type_periodically = $this->time_periodically = NULL;
     } elseif ($this->type == 2) {
         $this->at_time = NULL;
         $this->event = $this->sendon = NULL;
     }
     return parent::beforeSave($insert);
 }
예제 #4
0
 /** 
  * observe Takenworkleave event saving
  * 1. count quotas
  * 2. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function saving($model)
 {
     $errors = new MessageBag();
     //1. count quotas
     $quota = 0;
     if ($model->person()->count() && $model->work()->count()) {
         $from = Carbon::createFromFormat('Y-m-d', $model->start);
         $to = Carbon::createFromFormat('Y-m-d', $modenl->end);
         $days = $from->diffInDays($to);
         $interval = new DateInterval('P1D');
         $to->add($interval);
         $daterange = new DatePeriod($from, $interval, $to);
         foreach ($daterange as $date) {
             //1a. check person schedule
             $ps = \App\Models\PersonSchedule::ondate($date->format('Y-m-d'))->personid($model->person_id)->first();
             if (!$ps) {
                 //1b. check schedule
                 $s = \App\Models\Schedule::ondate($date->format('Y-m-d'))->calendarid($model->work->calendar_id)->first();
                 if (!$s) {
                     //1c. check calendar
                     $c = \App\Models\Calendar::id($model->work->calendar_id)->first();
                     if ($c) {
                         $harikerja = explode(',', $c['workdays']);
                         $day = ['senin' => 'monday', 'selasa' => 'tuesday', 'rabu' => 'wednesday', 'kamis' => 'thursday', 'jumat' => 'friday', 'sabtu' => 'saturday', 'minggu' => 'sunday', 'monday' => 'monday', 'tuesday' => 'tuesday', 'wednesday' => 'wednesday', 'thursday' => 'thursday', 'friday' => 'friday', 'saturday' => 'saturday', 'sunday' => 'sunday'];
                         $workdays = [];
                         //translate to ing
                         foreach ($harikerja as $key => $value) {
                             $workdays[] = $day[strtolower($value)];
                         }
                         if (!in_array(strtolower($date->format('l')), $workdays)) {
                             $quota = $quota + 1;
                         }
                     }
                 } elseif (in_array($s['status'], ['HB', 'DN'])) {
                     $quota = $quota + 1;
                 }
             } elseif (in_array($ps['status'], ['HB', 'DN'])) {
                 $quota = $quota + 1;
             }
         }
     }
     $model->quota = $quota;
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
예제 #5
0
 /** 
  * observe schedule event saving
  * 1. check duplicate schedule
  * 2. act, accept or refuse
  * 
  * @param $model
  * @return bool
  */
 public function saving($model)
 {
     $errors = new MessageBag();
     if (is_null($model->id)) {
         $id = 0;
     } else {
         $id = $model->id;
     }
     //1. check duplicate schedule
     if ($model->calendar()->count()) {
         $other_schedule = \App\Models\Schedule::ondate($model->on->format('Y-m-d H:i:s'))->notid($id)->first();
         if ($other_schedule) {
             $errors->add('ondate', 'Tidak dapat menyimpan dua jadwal di hari yang sama. Silahkan edit jadwal sebelumnya tambahkan jadwal khusus pada karyawan yang bersangkutan.');
         }
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }
예제 #6
0
 /**
  * Delete a schedule (throw to queue)
  *
  * @return Response
  */
 public function delete($org_id = null, $cal_id = null, $id = null)
 {
     //
     $schedule = \App\Models\Schedule::id($id)->calendarid($cal_id)->with(['calendar', 'calendar.calendars'])->first();
     if (!$schedule) {
         return new JSend('error', (array) Input::all(), 'Jadwal tidak ditemukan.');
     }
     $errors = new MessageBag();
     DB::beginTransaction();
     //1. store schedule of calendar to queue
     $schedule = $schedule->toArray();
     //1a. Validate Basic schedule Parameter
     $parameter = $schedule;
     unset($parameter['calendar']);
     $total = \App\Models\Work::calendarid($cal_id)->count();
     $queue = new \App\Models\Queue();
     $queue->fill(['process_name' => 'hr:schedules', 'process_option' => 'delete', 'parameter' => json_encode($parameter), 'total_process' => $total, 'task_per_process' => 1, 'process_number' => 0, 'total_task' => $total, 'message' => 'Initial Commit']);
     if (!$queue->save()) {
         $errors->add('Schedule', $queue->getError());
     }
     //End of validate schedule
     //2. store schedule of calendars to queue
     if (!$errors->count() && isset($schedule['calendar']['calendars']) && is_array($schedule['calendar']['calendars'])) {
         foreach ($schedule['calendar']['calendars'] as $key => $value) {
             $cals_data = \App\Models\Calendar::id($value['id'])->calendarid($cal_id)->first();
             if (!$cals_data) {
                 $errors->add('Calendar', 'Tidak ada kalender ' . $value['name']);
             }
             if (!$errors->count()) {
                 $total = \App\Models\Work::calendarid($value['id'])->count();
                 $parameter['calendar_id'] = $value['id'];
                 $queue = new \App\Models\Queue();
                 $queue->fill(['process_name' => 'hr:schedules', 'process_option' => 'delete', 'parameter' => json_encode($parameter), 'total_process' => $total, 'task_per_process' => 1, 'process_number' => 0, 'total_task' => $total, 'message' => 'Initial Commit']);
                 if (!$queue->save()) {
                     $errors->add('Schedule', $queue->getError());
                 }
             }
         }
     }
     //End of validate calendar schedule
     if ($errors->count()) {
         DB::rollback();
         return new JSend('error', (array) Input::all(), $errors);
     }
     DB::commit();
     return new JSend('success', (array) $schedule);
 }
예제 #7
0
 function save_data($job_id, $employee_id)
 {
     try {
         $sh = new Schedule();
         $user_id = PostJob::findOne($job_id)->user_id;
         $sh->job_id = $job_id;
         $sh->employee_id = $employee_id;
         $sh->create_time = date('Y-m-d H:i:s');
         $sh->update_time = date('Y-m-d H:i:s');
         $sh->agency_id = Yii::$app->user->identity->id;
         $sh->user_id = $user_id;
         $res = $sh->save();
         return $res;
     } catch (Exception $e) {
         return false;
     }
 }
예제 #8
0
 public function jsonadd(Request $request)
 {
     $data = json_decode($request->getContent(), true);
     foreach ($data as $d) {
         $apt = new AirportsAPI();
         $depicao = Airport::where('icao', $d['depicao'])->get();
         $arricao = Airport::where('icao', $d['arricao'])->get();
         if ($depicao->isEmpty()) {
             $apt->addFromDB($d['depicao']);
         }
         if ($arricao->isEmpty()) {
             $apt->addFromDB($d['arricao']);
         }
         $entry = new Schedule();
         $entry->code = $d['code'];
         $entry->flightnum = $d['flightnum'];
         $entry->depicao = $d['depicao'];
         $entry->arricao = $d['arricao'];
         $entry->route = $d['route'];
         $entry->aircraft = $d['aircraft'];
         $entry->type = $d['type'];
         $entry->daysofweek = $d['daysofweek'];
         $entry->enabled = $d['enabled'];
         $entry->save();
     }
 }
예제 #9
0
 /**
  * boot
  * observing model
  *
  */
 public static function boot()
 {
     parent::boot();
     Schedule::observe(new ScheduleObserver());
 }
예제 #10
0
 /**
  * Finds the Schedule model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Schedule the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Schedule::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #11
0
 /**
  * delete schedule and update for persons
  *
  * @return void
  **/
 public function delete($id)
 {
     $queue = new \App\Models\Queue();
     $pending = $queue->find($id);
     $parameters = json_decode($pending->parameter, true);
     $messages = json_decode($pending->message, true);
     $errors = new MessageBag();
     $schedule_data = \App\Models\Schedule::id($parameters['id'])->first();
     if (!$schedule_data) {
         $errors->add('Batch', 'Tidak ada schedule.');
     } elseif (!$schedule_data->delete()) {
         $errors->add('Batch', $schedule_data->getError());
     }
     if (!$errors->count()) {
         $pnumber = $pending->total_process;
         $messages['message'][$pnumber] = 'Sukses Menghapus Jadwal ' . (isset($schedule_data['calendar']['name']) ? $schedule_data['calendar']['name'] : '');
         $pending->fill(['process_number' => $pnumber, 'message' => 'Sukses']);
     } else {
         $pnumber = $pending->total_process;
         $messages['message'][$pnumber] = 'Gagal Menghapus Jadwal ' . (isset($schedule_data['calendar']['name']) ? $schedule_data['calendar']['name'] : '');
         $messages['errors'][$pnumber] = $errors;
         $pending->fill(['process_number' => $pnumber, 'message' => 'Sukses']);
     }
     $pending->save();
     return true;
 }
예제 #12
0
 protected function getTime()
 {
     $time['getup'] = Schedule::total('getup');
     $time['finish'] = Schedule::total('finish');
     $time['learning'] = Schedule::slug('learning');
     $time['waste'] = Schedule::slug('waste');
     $time['work'] = Schedule::slug('work');
     $time['exercise'] = Schedule::slug('exercise');
     $time['total'] = round((strtotime($time['finish']) - strtotime($time['getup'])) / 60);
     return $time;
 }
예제 #13
0
 /** 
  * observe GivenWorkleave event saving
  * Case progressive workleave
  * 1. check workleave quota
  * 2. check start work
  * 3. check start work date
  * 4. check if progressive workleave is end of year and quota over 12
  * Case special workleave
  * 1. count quota
  * 
  * @param $model
  * @return bool
  */
 public function saving($model)
 {
     $errors = new MessageBag();
     //case a. if given workleave was progressive
     if ($model->work()->count() && $model->status == 'CN') {
         //1. check workleave quota
         if ($model->workleave()->count()) {
             $wleave_quota = $follow->workleave->quota;
         } else {
             $wleave_quota = 12;
         }
         //2. check start work
         $prev_work = Work::personid($model->person_id)->orderby('start', 'asc')->notid($model->work_id)->first();
         if ($prev_work) {
             $start_work = $prev_work->start;
         } else {
             $start_work = $model->work->start;
         }
         //2a. if work over a year ::
         //- end was end of start year + 3 months
         //- start could be taken now
         if ($start_work->diffInYears($model->start) >= 1) {
             $extendpolicy = \App\Models\Policy::organisationid($model->person->organisation_id)->type('extendsworkleave')->OnDate($model->start->format('Y-m-d H:i:s'))->orderby('started_at', 'desc')->first();
             if ($extendpolicy) {
                 $extends = $extendpolicy['value'];
             } else {
                 $extends = '+ 3 months';
             }
             $end = Carbon::create('end of December ' . $model->start->format('Y') . ' ' . $extends);
             $start = $model->start;
         } else {
             $extendpolicy = \App\Models\Policy::organisationid($model->person->organisation_id)->type('extendsmidworkleave')->OnDate($model->start->format('Y-m-d H:i:s'))->orderby('started_at', 'desc')->first();
             if ($extendpolicy) {
                 $extends = $extendpolicy['value'];
             } else {
                 $extends = '+ 1 year';
             }
             $end = Carbon::create('end of December ' . $model->start->format('Y') . ' ' . $extends);
             $start = $start_work->copy()->addYear();
         }
         //3. check start work date
         //3a. if start work date after 15
         if ($start_work->format('d') >= 15) {
             $next_start = $start->copy()->addMonth();
             //3a1. if next start workleave bigger than end ::
             //-quota set zero
             if (!is_null($model->work->end) && $next_start->format('Y-m-d H:i:s') > $model->work->end->format('Y-m-d H:i:s')) {
                 $quota = 0;
             } else {
                 $start = $next_start;
                 $quota = 1;
             }
         } else {
             $quota = 1;
         }
         //4. check if progressive workleave is end of year and quota over 12
         if ((int) $start->format('m') == 12 && $wleave_quota > 12) {
             $quota = $quota + ($wleave_quota - 12);
         }
         $model->start = $start->format('Y-m-d H:i:s');
         $model->end = $end->format('Y-m-d H:i:s');
         $model->quota = $quota;
     } elseif ($model->work()->count() && $model->status == 'CI') {
         $quota = 0;
         $from = Carbon::createFromFormat('Y-m-d', $model->start);
         $to = Carbon::createFromFormat('Y-m-d', $modenl->end);
         $days = $from->diffInDays($to);
         $interval = new DateInterval('P1D');
         $to->add($interval);
         $daterange = new DatePeriod($from, $interval, $to);
         foreach ($daterange as $date) {
             //1a. check person schedule
             $ps = \App\Models\PersonSchedule::ondate($date->format('Y-m-d'))->personid($model->person_id)->first();
             if (!$ps) {
                 //1b. check schedule
                 $s = \App\Models\Schedule::ondate($date->format('Y-m-d'))->calendarid($model->work->calendar_id)->first();
                 if (!$s) {
                     //1c. check calendar
                     $c = \App\Models\Calendar::id($model->work->calendar_id)->first();
                     if ($c) {
                         $harikerja = explode(',', $c['workdays']);
                         $day = ['senin' => 'monday', 'selasa' => 'tuesday', 'rabu' => 'wednesday', 'kamis' => 'thursday', 'jumat' => 'friday', 'sabtu' => 'saturday', 'minggu' => 'sunday', 'monday' => 'monday', 'tuesday' => 'tuesday', 'wednesday' => 'wednesday', 'thursday' => 'thursday', 'friday' => 'friday', 'saturday' => 'saturday', 'sunday' => 'sunday'];
                         $workdays = [];
                         //translate to ing
                         foreach ($harikerja as $key => $value) {
                             $workdays[] = $day[strtolower($value)];
                         }
                         if (!in_array(strtolower($date->format('l')), $workdays)) {
                             $quota = $quota + 1;
                         }
                     }
                 } elseif (in_array($s['status'], ['HB', 'DN'])) {
                     $quota = $quota + 1;
                 }
             } elseif (in_array($ps['status'], ['HB', 'DN'])) {
                 $quota = $quota + 1;
             }
         }
         $model->quota = $quota;
     }
     if ($errors->count()) {
         $model['errors'] = $errors;
         return false;
     }
     return true;
 }