Skip to content

Commit

Permalink
Merge pull request #55 from ranggaadithia/testing
Browse files Browse the repository at this point in the history
modify: history, reschedule
  • Loading branch information
ranggaadithia authored Nov 5, 2023
2 parents 594a78b + 05fa7df commit b4fa8c4
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 111 deletions.
13 changes: 8 additions & 5 deletions app/Http/Controllers/HistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion app/Http/Controllers/LabBookingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
19 changes: 17 additions & 2 deletions app/Http/Controllers/RescheduleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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');
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('reschedule_requests', function (Blueprint $table) {
$table->text('reason_for_request')->nullable()->change();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('reschedule_requests', function (Blueprint $table) {
//
});
}
};
14 changes: 6 additions & 8 deletions resources/views/components/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class="d-flex align-items-center link-body-emphasis text-decoration-none dropdow
<form action="{{ route('logout') }}" method="POST">
@csrf
<li>
<button class="dropdown-item">Sign out</button>
<button class="dropdown-item">Logout</button>
</li>
</form>
</ul>
Expand All @@ -39,27 +39,25 @@ class="d-flex align-items-center link-body-emphasis text-decoration-none dropdow
</a>
</li>
<li>
<a href="{{ route('labs.index') }}" class="nav-link @if (route('labs.index'))
active
@endif" aria-current="page">
<a href="{{ route('labs.index') }}" class="nav-link {{ request()->routeIs('labs.*') ? 'active' : 'link-body-emphasis' }}">
<i class="bi bi-building-gear me-1"></i>
Manage Room
</a>
</li>
<li>
<a href="{{ route('class-schedule.index') }}" class="nav-link link-body-emphasis">
<a href="{{ route('class-schedule.index') }}" class="nav-link {{ request()->routeIs('class-schedule.*') ? 'active' : 'link-body-emphasis' }}">
<i class="bi bi-calendar3"></i>
Class Schedule
</a>
</li>
<li>
<a href="#" class="nav-link link-body-emphasis">
<a href="{{ route('reschedule.index') }}" class="nav-link {{ request()->routeIs('reschedule.*') ? 'active' : 'link-body-emphasis' }}">
<i class="bi bi-calendar2-range me-1"></i>
Move Schadule
Move Schedule
</a>
</li>
<li>
<a href="#" class="nav-link link-body-emphasis">
<a href="{{ route('report') }}" class="nav-link {{ request()->routeIs('report') ? 'active' : 'link-body-emphasis' }}">
<i class="bi bi-file-earmark-arrow-down"></i>
Report
</a>
Expand Down
42 changes: 31 additions & 11 deletions resources/views/dashboard/reschedule/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,52 @@

@section('container')

<h1>Move Schedule</h1>
@if (session()->has('success'))
<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success</strong> {{ session('success') }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
@if (session()->has('error'))
<div class="alert alert-danger alert-dismissible fade show" role="alert">
<strong>Failed</strong> {{ session('error') }}
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
@endif
<table class="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Tujuan</th>
<th scope="col">Nama Lab</th>
<th scope="col">Hari</th>
<th scope="col">Peminjam</th>
<th scope="col">Lab</th>
<th scope="col">Tanggal</th>
<th scope="col">Jam Mulai</th>
<th scope="col">Jam selesai</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
@foreach ($labsBooking as $booking)
<tr>
<th scope="row">1</th>
<td>Rekayasa bangunan</td>
<td>LAB APA GITU</td>
<td>Senin</td>
<td>26/09/2023</td>
<td>09.00</td>
<td>12.00</td>
<td>
<a href="" class="btn btn-warning">Request Reschadule</a>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $booking->reason_to_booking }}</td>
<td>{{ $booking->user->name }}</td>
<td>{{ $booking->lab->name }}</td>
<td>{{ $booking->booking_date }}</td>
<td>{{ $booking->start_time }}</td>
<td>{{ $booking->end_time }}</td>
<td class="d-flex">
<a href="{{ route('reschedule.create', $booking->id) }}" class="btn btn-outline-warning me-1">Reschadule</a>
<form action="{{ route('labs.destroy', $booking->id) }}" method="post">
@csrf
@method('delete')
<button type="submit" class="btn btn-outline-danger">Hapus</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>

Expand Down
9 changes: 5 additions & 4 deletions resources/views/home/history.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
</div>
<div class="p-6">
<h5 class="mb-2 text-lg font-medium leading-tight text-neutral-600 dark:text-neutral-200">
Tanggal
{{ \Carbon\Carbon::parse($history->booking_date)->format('d F Y') }}
({{ \Carbon\Carbon::parse($history->booking_date)->diffForHumans()}})
</h5>
<p class="mb-4 text-base text-neutral-600 dark:text-neutral-200">
Waktu pinjaman
{{ $history->start_time }} - {{ $history->end_time }}
</p>
<button type="button" href="#"
class="inline-block rounded bg-primary px-6 pb-2 pt-2.5 text-xs font-medium leading-normal text-white shadow-[0_4px_9px_-4px_#3b71ca] transition duration-150 ease-in-out hover:bg-primary-600 hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:bg-primary-600 focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] focus:outline-none focus:ring-0 active:bg-primary-700 active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.3),0_4px_18px_0_rgba(59,113,202,0.2)] dark:shadow-[0_4px_9px_-4px_rgba(59,113,202,0.5)] dark:hover:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:focus:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)] dark:active:shadow-[0_8px_9px_-4px_rgba(59,113,202,0.2),0_4px_18px_0_rgba(59,113,202,0.1)]"
Expand Down Expand Up @@ -43,10 +44,10 @@ class="inline-block rounded bg-red-500 px-6 pb-2 pt-2.5 text-xs font-medium lead
</div>
<div class="p-6">
<h5 class="mb-2 text-lg font-medium leading-tight text-neutral-600 dark:text-neutral-200">
Tanggal
{{ \Carbon\Carbon::parse($history->booking_date)->format('d F Y') }}
</h5>
<p class="mb-2 text-base text-neutral-600 dark:text-neutral-200">
Waktu pinjaman
{{ $history->start_time }} - {{ $history->end_time }}
</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions resources/views/layouts/dashboard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@
</main>
</body>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
@stack('scripts')
</html>
82 changes: 2 additions & 80 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,95 +60,17 @@
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(),
'days' => ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'],
'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');
});

0 comments on commit b4fa8c4

Please sign in to comment.