From 05fa7df424bf35ecf8f30922cd8b6be594f1f9e5 Mon Sep 17 00:00:00 2001 From: Rangga Adithia Date: Sun, 5 Nov 2023 20:30:06 +0800 Subject: [PATCH] modify: history, reschedule --- app/Http/Controllers/HistoryController.php | 13 +-- app/Http/Controllers/LabBookingController.php | 3 +- app/Http/Controllers/RescheduleController.php | 19 ++++- ...11_05_201200_modify_reason_for_request.php | 28 +++++++ resources/views/components/sidebar.blade.php | 14 ++-- .../dashboard/reschedule/index.blade.php | 42 +++++++--- resources/views/home/history.blade.php | 9 +- resources/views/layouts/dashboard.blade.php | 1 + routes/web.php | 82 +------------------ 9 files changed, 100 insertions(+), 111 deletions(-) create mode 100644 database/migrations/2023_11_05_201200_modify_reason_for_request.php diff --git a/app/Http/Controllers/HistoryController.php b/app/Http/Controllers/HistoryController.php index a270ac0..11b2455 100644 --- a/app/Http/Controllers/HistoryController.php +++ b/app/Http/Controllers/HistoryController.php @@ -12,11 +12,14 @@ public function history() { $now = Carbon::now(); - $upcomingHistories = LabsBooking::with('lab') - ->where('user_id', auth()->user()->id) - ->whereDate('booking_date', '=', $now->format('Y-m-d')) - ->orWhereDate('booking_date', '>', $now->format('Y-m-d')) - ->whereTime('start_time', '>', $now->format('H:i:s')) + $upcomingHistories = LabsBooking::with('lab', 'user') + ->where(function ($query) use ($now) { + $query->where('booking_date', '>=', $now->format('Y-m-d')) + ->orWhere(function ($subquery) use ($now) { + $subquery->where('booking_date', '=', $now->format('Y-m-d')) + ->where('start_time', '>', $now->format('H:i:s')); + }); + }) ->orderBy('booking_date', 'desc') ->get(); diff --git a/app/Http/Controllers/LabBookingController.php b/app/Http/Controllers/LabBookingController.php index bf64592..b17390f 100644 --- a/app/Http/Controllers/LabBookingController.php +++ b/app/Http/Controllers/LabBookingController.php @@ -96,6 +96,7 @@ public function update(Request $request, LabsBooking $labsBooking) */ public function destroy(LabsBooking $labsBooking) { - // + $labsBooking->delete(); + return redirect('/')->with('success', 'Booking berhasil dihapus'); } } diff --git a/app/Http/Controllers/RescheduleController.php b/app/Http/Controllers/RescheduleController.php index 0ef9a6a..97f2349 100644 --- a/app/Http/Controllers/RescheduleController.php +++ b/app/Http/Controllers/RescheduleController.php @@ -18,7 +18,22 @@ class RescheduleController extends Controller */ public function index() { - // + + $now = Carbon::now(); + + $labsBooking = LabsBooking::with('lab', 'user') + ->where(function ($query) use ($now) { + $query->where('booking_date', '>=', $now->format('Y-m-d')) + ->orWhere(function ($subquery) use ($now) { + $subquery->where('booking_date', '=', $now->format('Y-m-d')) + ->where('start_time', '>', $now->format('H:i:s')); + }); + }) + ->orderBy('booking_date', 'desc') + ->get(); + + + return view('dashboard.reschedule.index', compact('labsBooking')); } /** @@ -83,7 +98,7 @@ public function store(Request $request, string $labsBookingId) } $reschedule = RescheduleRequest::create($data); $this->acceptReschedule($reschedule->id); - return redirect('/'); + return redirect()->route('reschedule.index')->with('success', 'Jadwal berhasil di reschedule'); } diff --git a/database/migrations/2023_11_05_201200_modify_reason_for_request.php b/database/migrations/2023_11_05_201200_modify_reason_for_request.php new file mode 100644 index 0000000..09b4fe2 --- /dev/null +++ b/database/migrations/2023_11_05_201200_modify_reason_for_request.php @@ -0,0 +1,28 @@ +text('reason_for_request')->nullable()->change(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('reschedule_requests', function (Blueprint $table) { + // + }); + } +}; diff --git a/resources/views/components/sidebar.blade.php b/resources/views/components/sidebar.blade.php index 070af0e..20942b9 100644 --- a/resources/views/components/sidebar.blade.php +++ b/resources/views/components/sidebar.blade.php @@ -22,7 +22,7 @@ class="d-flex align-items-center link-body-emphasis text-decoration-none dropdow
@csrf
  • - +
  • @@ -39,27 +39,25 @@ class="d-flex align-items-center link-body-emphasis text-decoration-none dropdow
  • - + Manage Room
  • - + Class Schedule
  • - + - Move Schadule + Move Schedule
  • - + Report diff --git a/resources/views/dashboard/reschedule/index.blade.php b/resources/views/dashboard/reschedule/index.blade.php index 47fd8da..61688a5 100644 --- a/resources/views/dashboard/reschedule/index.blade.php +++ b/resources/views/dashboard/reschedule/index.blade.php @@ -2,13 +2,26 @@ @section('container') +

    Move Schedule

    +@if (session()->has('success')) + +@endif +@if (session()->has('error')) + +@endif - - + + @@ -16,18 +29,25 @@ + @foreach ($labsBooking as $booking) - - - - - - - - + + + + + + + + @endforeach
    # TujuanNama LabHariPeminjamLab Tanggal Jam Mulai Jam selesai
    1Rekayasa bangunanLAB APA GITUSenin26/09/202309.0012.00 - Request Reschadule + {{ $loop->iteration }}{{ $booking->reason_to_booking }}{{ $booking->user->name }}{{ $booking->lab->name }}{{ $booking->booking_date }}{{ $booking->start_time }}{{ $booking->end_time }} + Reschadule +
    + @csrf + @method('delete') + +
    diff --git a/resources/views/home/history.blade.php b/resources/views/home/history.blade.php index 5a940a1..82a75b5 100644 --- a/resources/views/home/history.blade.php +++ b/resources/views/home/history.blade.php @@ -12,10 +12,11 @@
    - Tanggal + {{ \Carbon\Carbon::parse($history->booking_date)->format('d F Y') }} + ({{ \Carbon\Carbon::parse($history->booking_date)->diffForHumans()}})

    - Waktu pinjaman + {{ $history->start_time }} - {{ $history->end_time }}

    diff --git a/resources/views/layouts/dashboard.blade.php b/resources/views/layouts/dashboard.blade.php index 1e6998a..f293d7d 100644 --- a/resources/views/layouts/dashboard.blade.php +++ b/resources/views/layouts/dashboard.blade.php @@ -23,4 +23,5 @@ + @stack('scripts') diff --git a/routes/web.php b/routes/web.php index bbd1996..7764dec 100644 --- a/routes/web.php +++ b/routes/web.php @@ -60,24 +60,13 @@ Route::resource('labs', LabController::class); Route::resource('class-schedule', ClassScheduleController::class)->except(('show')); Route::get('class-schedule/list', [ClassScheduleController::class, 'list'])->name('class-schedule.list'); + Route::get('reschedule/', [RescheduleController::class, 'index'])->name('reschedule.index'); Route::get('reschedule/{labs_booking}', [RescheduleController::class, 'create'])->name('reschedule.create'); Route::post('reschedule/{labs_booking}', [RescheduleController::class, 'store'])->name('reschedule.store'); + Route::delete('labs-booking/{labs_booking}', [LabBookingController::class, 'destroy'])->name('labs.destroy'); Route::get('report', Report::class)->name('report'); }); - - - - -// route testing below -Route::get('/time', function () { - return TimeMappings::$timeMappings; -}); - -Route::get('/export', function () { - return Excel::download(new ExportUser, 'users.xlsx'); -}); - Route::get('/test', function () { return view('test', [ 'labs' => Lab::all(), @@ -85,70 +74,3 @@ 'alphabet' => ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'] ]); }); - - -Route::get('/test_booking', function () { - $user = User::find(9); - $lab = Lab::find(1); - - - $user->labs()->attach($lab->id, ['booking_date' => today(), 'start_time' => 'D', 'end_time' => 'F', 'reason' => 'penelitian']); - return "success"; -}); - - -Route::get('/test_reschedule', function () { - - RescheduleRequest::create([ - 'lab_booking_id' => 2, - 'user_id' => 1, - 'new_booking_date' => Carbon::tomorrow(), - 'new_start_time' => 'D', - 'new_end_time' => 'F', - 'reason_for_request' => 'Maintenece', - 'status' => 'requested' - ]); - - return "success"; -}); - -// lab dashboard -Route::get('/lab', function () { - $labBookings = LabsBooking::all(); - - $rescheduleRequest = RescheduleRequest::all(); - - $days = []; - - foreach ($labBookings as $booking) { - $carbonDate = Carbon::parse($booking->booking_date); - $day = $carbonDate->format('l'); - $days[] = $day; - } - - - return view('test', compact('labBookings', 'days', 'rescheduleRequest')); -}); - - -// if user auth -Route::get('/user/{id}', function (string $id) { - return $reschduleRequest = RescheduleRequest::where('user_id', $id)->where('status', 'requested')->get(); - - // if (!empty($reschduleRequest)) { - // return "Jadwal Anda di Reschdule"; - // } else { - // return "aman"; - // } -}); - - -Route::get('/class_schedule', function () { - $class_schedule = ClassSchedule::all(); - return $class_schedule[0]->lab->name; -}); - - -Route::get('/table', function () { - return view('request_schedule.moveschadule'); -});