/** * Run the database seeds. * Run at terminal: * $ php artisan db:seed --class=ReservationDummySeeder * * @return void */ public function run() { \App\Schedule::create(['clinic_id' => 1, 'doctor_id' => 1, 'schedule_start' => '08:00:00', 'schedule_end' => '18:00:00', 'date' => date("Y-m-d", strtotime("+2 day")), 'quota' => 0, 'status_batal' => 0]); \App\Schedule::create(['clinic_id' => 2, 'doctor_id' => 1, 'schedule_start' => '08:00:00', 'schedule_end' => '18:00:00', 'date' => date("Y-m-d"), 'quota' => 10, 'status_batal' => 0]); \App\Schedule::create(['clinic_id' => 1, 'doctor_id' => 1, 'schedule_start' => '08:00:00', 'schedule_end' => '10:00:00', 'date' => date("Y-m-d", strtotime("+1 day")), 'quota' => 2, 'status_batal' => 1]); \App\Schedule::create(['clinic_id' => 1, 'doctor_id' => 1, 'schedule_start' => '13:00:00', 'schedule_end' => '18:00:00', 'date' => date("Y-m-d", strtotime("+1 day")), 'quota' => 5, 'status_batal' => 0]); \App\Clinic::create(['city_id' => 1, 'name' => 'RSU Haji', 'address' => 'Sukolilo', 'latitude' => '-7.265757', 'longitude' => '112.734146', 'telephone' => '081234567890', 'email' => '5345678']); \App\Clinic::create(['city_id' => 1, 'name' => 'RSAL', 'address' => 'Mayjend Sungkono', 'latitude' => '-7.265757', 'longitude' => '112.734146', 'telephone' => '081234567890', 'email' => '5345678']); }
public function storeSchedule(Request $request, $engineer_id) { //First we need to remove all the schedules //$objEngineer = Engineer::find($engineer_id); Schedule::where('engineer_id', $engineer_id)->delete(); foreach ($request->all() as $newObj) { Schedule::create($newObj); } return ["success" => true]; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(ScheduleCreateRequest $request) { $data = ['clinic_id' => Auth::user()->clinic->id, 'doctor_id' => $request->input('doctor_id'), 'schedule_start' => date("H:i", strtotime($request->input('schedule_start'))), 'schedule_end' => date("H:i", strtotime($request->input('schedule_end'))), 'date' => $request->input('date'), 'quota' => $request->input('quota'), 'status_batal' => '0']; Schedule::create($data); if ($request->input('repeat') == '2') { $iter = strtotime("+1 week", strtotime($data['date'])); while ($iter <= strtotime($request->input('max_date'))) { $data['date'] = date("Y-m-d", $iter); Schedule::create($data); $iter = strtotime("+1 week", strtotime($data['date'])); } } Session::flash('success', "Jadwal baru dokter berhasil ditambahkan"); return redirect()->back(); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $input = $request->all(); $master_id = $input['master_id']; $days = $input['days']; $time_from = $input['time_from']; $time_to = $input['time_to']; $break_from = $input['break_from']; $break_to = $input['break_to']; $queues = $input['queue']; $section_lists = []; foreach ($queues['plan_id'] as $i => $plan) { $section = $queues['section'][$i]; $section_slug = str_slug($section, "-"); $plans = Plan::findOrFail($plan)->semesters()->where('number', '=', $queues['number_semester'][$i])->where('year', '=', $queues['number_year'][$i])->get(); foreach ($plans as $sem) { foreach ($sem->subjects as $subject) { $sec_key = $master_id . "_" . $section_slug; $ref_key = $sec_key . "_" . $subject->id; $ref_data = []; $ref_data['key'] = $ref_key; $ref_data['sec_key'] = $sec_key; $ref_data['name'] = $section; $ref_data['master_id'] = $master_id; $ref_data['plan_id'] = $sem->plan_id; $ref_data['semester_id'] = $sem->id; $ref_data['subject_id'] = $subject->id; $ref_data['subject_code'] = $subject->code; $ref_data['subject_name'] = $subject->name; $ref_data['lec_hours'] = $subject->lec_hours; $ref_data['lab_hours'] = $subject->lab_hours; $ref_data['total_hours'] = $subject->lec_hours + $subject->lab_hours; $ref_data['feature_id'] = $subject->feature_id; $new_data = $this->store_allocate_days($ref_data); $section_lists[$section_slug][$subject->id] = $new_data; } } } foreach ($section_lists as $sl => $section) { foreach ($section as $s => $data) { $room_in = ['lec_hours' => 'lec_days', 'lab_hours' => 'lab_days']; foreach ($room_in as $in_hours => $in_days) { $rooms = []; if ($data[$in_hours] > 0 && count($data[$in_days]) > 0) { $s_room_id = null; $s_feature_id = $data['feature_id']; if ('lec_hours' == $in_hours) { $s_feature_id = 1; } $q_rooms = DB::table('rooms')->leftJoin(DB::raw("(select * from schedules WHERE master_id = {$master_id}) schedules"), 'rooms.id', '=', 'schedules.room_id')->select(DB::raw("rooms.id, TIME_TO_SEC( TIMEDIFF('{$time_to}', '{$time_from}') ) / 60 as time_required, SUM( TIME_TO_SEC(TIMEDIFF(schedules.time_to, schedules.time_from)) ) / 60 as time_spent"))->where('rooms.feature_id', $s_feature_id)->groupBy('rooms.id')->havingRaw('((time_required - time_spent) is null OR (time_required - time_spent) >= 60)')->orderBy('time_spent', 'desc')->orderBy('rooms.code', 'asc'); if (!empty($input['room_list'])) { $q_rooms->whereIN('rooms.id', $input['room_list']); } $rooms = $q_rooms->get(); if (!empty($rooms)) { $exist_schedule = Schedule::where('key', '=', $data['key'])->where('feature_id', '=', $s_feature_id)->where('master_id', '=', $master_id)->get(); if ($exist_schedule->isEmpty()) { foreach ($data[$in_days] as $s_time_day) { $schedule_data = []; $room_schedule = Schedule::where('time_day', '=', $s_time_day)->where('master_id', '=', $master_id)->where('section_key', '=', $data['sec_key'])->orderBy('time_to', 'DESC')->first(); if (empty($room_schedule)) { $s_time_from = $time_from; } else { $s_time_from = $room_schedule->time_to; } if ($s_time_from >= $break_from && $s_time_from <= $break_to) { $s_time_from = $break_to; } $tmp_time_to = $s_time_from; $tmp_time_to_hours = $data[$in_hours] / count($data[$in_days]) * 60; $s_time_to = date('H:i:s', strtotime("+{$tmp_time_to_hours} minutes", strtotime($tmp_time_to))); $room_avail = false; if (!empty($s_room_id)) { $room_time_schedule_data = ['room_id' => $s_room_id, 'time_day' => $s_time_day, 'time_from' => $s_time_from, 'time_to' => $s_time_to, 'time_from2' => $s_time_from, 'time_to2' => $s_time_to, 'master_id' => $master_id]; $room_time_schedule = $this->store_check_room_availability($room_time_schedule_data); if (empty($room_time_schedule)) { $room_avail = true; } } if (empty($room_avail)) { foreach ($rooms as $room) { $room_time_schedule_data = ['room_id' => $room->id, 'time_day' => $s_time_day, 'time_from' => $s_time_from, 'time_to' => $s_time_to, 'time_from2' => $s_time_from, 'time_to2' => $s_time_to, 'master_id' => $master_id]; $room_time_schedule = $this->store_check_room_availability($room_time_schedule_data, $master_id); if (empty($room_time_schedule)) { $s_room_id = $room->id; $room_avail = true; break; } } } if ($room_avail) { $schedule_data = ['key' => $data['key'], 'master_id' => $master_id, 'semester_id' => $data['semester_id'], 'subject_id' => $data['subject_id'], 'room_id' => $s_room_id, 'time_day' => $s_time_day, 'time_from' => $s_time_from, 'time_to' => $s_time_to, 'feature_id' => $s_feature_id, 'section_key' => $data['sec_key'], 'section_name' => $data['name']]; Schedule::create($schedule_data); } } } } } } } } $faculty_schedules = Schedule::whereNull('faculty_id')->groupBy('key')->where('master_id', $master_id)->orderBy('subject_id', 'DESC')->get(); if (!$faculty_schedules->isEmpty()) { foreach ($faculty_schedules as $faculty_schedule) { $s_faculty_id = null; $s_faculties = $faculty_schedule->subject->faculties->toArray(); $s_faculties_count = count($s_faculties) - 1; if ($s_faculties_count >= 0) { $s_faculty_rand = mt_rand(0, $s_faculties_count); $s_faculty = $s_faculties[$s_faculty_rand]; $s_faculty_id = $s_faculty['id']; } Schedule::where('key', '=', $faculty_schedule->key)->update(['faculty_id' => $s_faculty_id]); } } return redirect("/schedules/view?master_id={$master_id}"); }