public function store() { $data = Input::all(); $data['TRAVEL_SCHEDULE_DEPARTTIME'] = date('Y-m-d H:i', strtotime($data['date'] . " " . $data['depart_hour'] . ":" . $data['depart_minute'])); $plus = $data['hour_estimate'] * 60 + $data['minute_estimate']; $hour_arrive = date('H:i', strtotime('+' . $plus . ' minutes', strtotime($data['TRAVEL_SCHEDULE_DEPARTTIME']))); $data['TRAVEL_SCHEDULE_ARRIVETIME'] = date('Y-m-d H:i', strtotime($hour_arrive)); unset($data['_token']); unset($data['date']); unset($data['depart_hour'], $data['depart_minute'], $data['hour_estimate'], $data['minute_estimate']); $data['TRAVEL_SCHEDULE_CREATEBY'] = Session::get('id'); $flag = 0; $flag = Travelschedule::where(function ($query) use($data) { $query->where('TRAVEL_SCHEDULE_DEPARTTIME', '<=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_ARRIVETIME'])))->where('TRAVEL_SCHEDULE_ARRIVETIME', '>=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_ARRIVETIME']))); })->orWhere(function ($query) use($data) { $query->where('TRAVEL_SCHEDULE_DEPARTTIME', '<=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_DEPARTTIME'])))->where('TRAVEL_SCHEDULE_ARRIVETIME', '>=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_DEPARTTIME']))); })->orWhere(function ($query) use($data) { $query->where('TRAVEL_SCHEDULE_DEPARTTIME', '>=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_DEPARTTIME'])))->where('TRAVEL_SCHEDULE_ARRIVETIME', '<=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_ARRIVETIME']))); })->where('VEHICLE_ID', '=', $data['VEHICLE_ID'])->count(); if ($flag == 0) { Travelschedule::insert($data); } else { Session::flash("error", "Ada jadwal yang bentrok, mohon periksa kembali"); } return redirect::back(); }
function addJadwalMingguan() { $data = Input::all(); $start = date('Y-m-d', strtotime($data['start'])); $stop = date('Y-m-d', strtotime($data['stop'])); $tanggal = $data['tanggal']; unset($data['tanggal'], $data['_token']); $data['TRAVEL_SCHEDULE_CREATEBY'] = Session::get('id'); $hour_depart = date('H:i', strtotime($data['hour_depart'] . ':' . $data['minute_depart'])); $plus = $data['hour_estimate'] * 60 + $data['minute_estimate']; $hour_arrive = date('H:i', strtotime('+' . $plus . ' minutes', strtotime($hour_depart))); unset($data['hour_depart'], $data['minute_estimate'], $data['hour_estimate'], $data['minute_depart'], $data['start'], $data['stop']); $i = 0; $flag = 0; $data['TRAVEL_SCHEDULE_GROUP'] = md5(time()); while ($start <= $stop) { $index = date('N', strtotime($start)) - 1; if (in_array($index, $tanggal)) { $data['TRAVEL_SCHEDULE_DEPARTTIME'] = date('Y-m-d H:i', strtotime($start . " " . $hour_depart)); $data['TRAVEL_SCHEDULE_ARRIVETIME'] = date('Y-m-d H:i', strtotime($start . " " . $hour_arrive)); $flag = Travelschedule::where(function ($query) use($data) { $query->where('TRAVEL_SCHEDULE_DEPARTTIME', '<=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_ARRIVETIME'])))->where('TRAVEL_SCHEDULE_ARRIVETIME', '>=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_ARRIVETIME']))); })->orWhere(function ($query) use($data) { $query->where('TRAVEL_SCHEDULE_DEPARTTIME', '<=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_DEPARTTIME'])))->where('TRAVEL_SCHEDULE_ARRIVETIME', '>=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_DEPARTTIME']))); })->orWhere(function ($query) use($data) { $query->where('TRAVEL_SCHEDULE_DEPARTTIME', '>=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_DEPARTTIME'])))->where('TRAVEL_SCHEDULE_ARRIVETIME', '<=', date('Y-m-d H:i', strtotime($data['TRAVEL_SCHEDULE_ARRIVETIME']))); })->where('VEHICLE_ID', '=', $data['VEHICLE_ID'])->count(); if ($flag == 0) { Travelschedule::insert($data); } elseif ($flag > 0 && $i != 1) { echo json_encode("Ada jadwal yang bentrok, mohon periksa kembali"); $i = 1; } } $start = date('Y-m-d', strtotime('+1 day', strtotime($start))); } /*foreach ($tanggal as $key) { $temp=['DAY_ID'=>$key+1,'TRAVEL_SCHEDULE_UMUM_ID'=>$data['TRAVEL_SCHEDULE_UMUM_ID']]; //TravelScheduleUmumXDay::insert($temp); }*/ }