INI DIAAAAAAAAAAAAA, RESCHEDULE
This commit is contained in:
parent
39f984a3e5
commit
19423cac45
|
@ -482,7 +482,7 @@ public function deletePendingBooking($id)
|
||||||
}
|
}
|
||||||
|
|
||||||
public function showReschedule($id)
|
public function showReschedule($id)
|
||||||
{
|
{
|
||||||
$booking = Booking::with(['table.venue', 'table.venue.tables'])->findOrFail($id);
|
$booking = Booking::with(['table.venue', 'table.venue.tables'])->findOrFail($id);
|
||||||
|
|
||||||
// Check if user owns this booking
|
// Check if user owns this booking
|
||||||
|
@ -490,16 +490,11 @@ public function showReschedule($id)
|
||||||
return redirect()->route('booking.history')->with('error', 'Anda tidak memiliki akses ke booking ini.');
|
return redirect()->route('booking.history')->with('error', 'Anda tidak memiliki akses ke booking ini.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if booking is upcoming and paid
|
// Check if booking is upcoming
|
||||||
if ($booking->start_time <= now() || $booking->status !== 'paid') {
|
if ($booking->start_time <= now() || $booking->status !== 'paid') {
|
||||||
return redirect()->route('booking.history')->with('error', 'Booking ini tidak dapat di-reschedule.');
|
return redirect()->route('booking.history')->with('error', 'Booking ini tidak dapat di-reschedule.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if already rescheduled
|
|
||||||
if ($booking->has_rescheduled) {
|
|
||||||
return redirect()->route('booking.history')->with('error', 'Booking ini sudah pernah di-reschedule sebelumnya.');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if it's within the time limit (at least 1 hour before start)
|
// Check if it's within the time limit (at least 1 hour before start)
|
||||||
$rescheduleDeadline = Carbon::parse($booking->start_time)->subHour();
|
$rescheduleDeadline = Carbon::parse($booking->start_time)->subHour();
|
||||||
if (now() > $rescheduleDeadline) {
|
if (now() > $rescheduleDeadline) {
|
||||||
|
@ -513,13 +508,13 @@ public function showReschedule($id)
|
||||||
$duration = Carbon::parse($booking->start_time)->diffInHours($booking->end_time);
|
$duration = Carbon::parse($booking->start_time)->diffInHours($booking->end_time);
|
||||||
|
|
||||||
return view('pages.reschedule', compact('booking', 'venue', 'duration'));
|
return view('pages.reschedule', compact('booking', 'venue', 'duration'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process a reschedule request.
|
* Process a reschedule request.
|
||||||
*/
|
*/
|
||||||
public function processReschedule(Request $request, $id)
|
public function processReschedule(Request $request, $id)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'table_id' => 'required|exists:tables,id',
|
'table_id' => 'required|exists:tables,id',
|
||||||
'start_time' => 'required|date_format:Y-m-d H:i:s',
|
'start_time' => 'required|date_format:Y-m-d H:i:s',
|
||||||
|
@ -528,11 +523,10 @@ public function processReschedule(Request $request, $id)
|
||||||
|
|
||||||
$booking = Booking::findOrFail($id);
|
$booking = Booking::findOrFail($id);
|
||||||
|
|
||||||
// Perform the same validation as in showReschedule
|
// Perform validation
|
||||||
if ($booking->user_id !== auth()->id() ||
|
if ($booking->user_id !== auth()->id() ||
|
||||||
$booking->start_time <= now() ||
|
$booking->start_time <= now() ||
|
||||||
$booking->status !== 'paid' ||
|
$booking->status !== 'paid' ||
|
||||||
$booking->has_rescheduled ||
|
|
||||||
now() > Carbon::parse($booking->start_time)->subHour()) {
|
now() > Carbon::parse($booking->start_time)->subHour()) {
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
@ -540,7 +534,7 @@ public function processReschedule(Request $request, $id)
|
||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the selected time is available (except for this booking)
|
// Check if the selected time is available (exclude current booking when checking conflicts)
|
||||||
$existingBookings = Booking::where('table_id', $request->table_id)
|
$existingBookings = Booking::where('table_id', $request->table_id)
|
||||||
->where('id', '!=', $booking->id)
|
->where('id', '!=', $booking->id)
|
||||||
->where('status', 'paid')
|
->where('status', 'paid')
|
||||||
|
@ -558,19 +552,10 @@ public function processReschedule(Request $request, $id)
|
||||||
], 422);
|
], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store original booking details
|
// Update the booking with new schedule
|
||||||
$originalStartTime = $booking->start_time;
|
|
||||||
$originalEndTime = $booking->end_time;
|
|
||||||
$originalTableId = $booking->table_id;
|
|
||||||
|
|
||||||
// Update the booking
|
|
||||||
$booking->original_start_time = $originalStartTime;
|
|
||||||
$booking->original_end_time = $originalEndTime;
|
|
||||||
$booking->original_table_id = $originalTableId;
|
|
||||||
$booking->start_time = $request->start_time;
|
$booking->start_time = $request->start_time;
|
||||||
$booking->end_time = $request->end_time;
|
$booking->end_time = $request->end_time;
|
||||||
$booking->table_id = $request->table_id;
|
$booking->table_id = $request->table_id;
|
||||||
$booking->has_rescheduled = true;
|
|
||||||
$booking->save();
|
$booking->save();
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
|
@ -578,13 +563,13 @@ public function processReschedule(Request $request, $id)
|
||||||
'message' => 'Booking berhasil di-reschedule.',
|
'message' => 'Booking berhasil di-reschedule.',
|
||||||
'redirect' => route('booking.history')
|
'redirect' => route('booking.history')
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check availability for reschedule.
|
* Check availability for reschedule.
|
||||||
*/
|
*/
|
||||||
public function checkRescheduleAvailability(Request $request)
|
public function checkRescheduleAvailability(Request $request)
|
||||||
{
|
{
|
||||||
$request->validate([
|
$request->validate([
|
||||||
'table_id' => 'required|exists:tables,id',
|
'table_id' => 'required|exists:tables,id',
|
||||||
'date' => 'required|date_format:Y-m-d',
|
'date' => 'required|date_format:Y-m-d',
|
||||||
|
@ -609,5 +594,5 @@ public function checkRescheduleAvailability(Request $request)
|
||||||
});
|
});
|
||||||
|
|
||||||
return response()->json($bookings);
|
return response()->json($bookings);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -26,7 +26,6 @@
|
||||||
<p class="font-medium">{{ $duration }} Jam</p>
|
<p class="font-medium">{{ $duration }} Jam</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mb-6">
|
<div class="bg-yellow-50 border border-yellow-200 rounded-lg p-4 mb-6">
|
||||||
<div class="flex items-start">
|
<div class="flex items-start">
|
||||||
<div class="mr-3 text-yellow-500">
|
<div class="mr-3 text-yellow-500">
|
||||||
|
@ -35,16 +34,16 @@
|
||||||
<div>
|
<div>
|
||||||
<h3 class="font-semibold text-yellow-700">Perhatian</h3>
|
<h3 class="font-semibold text-yellow-700">Perhatian</h3>
|
||||||
<p class="text-yellow-700 text-sm">
|
<p class="text-yellow-700 text-sm">
|
||||||
• Reschedule hanya dapat dilakukan 1x untuk setiap booking<br>
|
• Reschedule dapat dilakukan selama minimal 1 jam sebelum jadwal booking<br>
|
||||||
• Batas waktu reschedule adalah 1 jam sebelum jadwal booking<br>
|
• Durasi booking akan tetap sama ({{ $duration }} jam)<br>
|
||||||
• Durasi booking akan tetap sama ({{ $duration }} jam)
|
• Setelah reschedule, jadwal lama akan digantikan dengan jadwal baru
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div x-data="rescheduleForm" class="bg-white rounded-lg shadow-md p-6">
|
<div x-data="rescheduleForm" class="bg-white rounded-lg shadow-md p-6">
|
||||||
<h2 class="text-lg font-semibold mb-4">Pilih Jadwal Baru</h2>
|
<h2 class="text-lg font-semibold mb-4">Pilih Jadwal Baru</h2>
|
||||||
|
|
||||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||||
|
@ -100,9 +99,8 @@ class="text-white px-4 py-2 rounded-lg">
|
||||||
<span x-show="isSubmitting">Memproses...</span>
|
<span x-show="isSubmitting">Memproses...</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('alpine:init', () => {
|
document.addEventListener('alpine:init', () => {
|
||||||
Alpine.data('rescheduleForm', () => ({
|
Alpine.data('rescheduleForm', () => ({
|
||||||
|
@ -110,6 +108,8 @@ class="text-white px-4 py-2 rounded-lg">
|
||||||
bookingId: {{ $booking->id }},
|
bookingId: {{ $booking->id }},
|
||||||
bookingDuration: {{ $duration }},
|
bookingDuration: {{ $duration }},
|
||||||
originalTableId: {{ $booking->table_id }},
|
originalTableId: {{ $booking->table_id }},
|
||||||
|
originalStartTime: "{{ \Carbon\Carbon::parse($booking->start_time)->format('H:i') }}",
|
||||||
|
originalDate: "{{ \Carbon\Carbon::parse($booking->start_time)->format('Y-m-d') }}",
|
||||||
selectedDate: '',
|
selectedDate: '',
|
||||||
selectedTableId: '',
|
selectedTableId: '',
|
||||||
selectedStartHour: null,
|
selectedStartHour: null,
|
||||||
|
@ -124,9 +124,9 @@ class="text-white px-4 py-2 rounded-lg">
|
||||||
const month = String(today.getMonth() + 1).padStart(2, '0');
|
const month = String(today.getMonth() + 1).padStart(2, '0');
|
||||||
const day = String(today.getDate()).padStart(2, '0');
|
const day = String(today.getDate()).padStart(2, '0');
|
||||||
this.today = `${year}-${month}-${day}`;
|
this.today = `${year}-${month}-${day}`;
|
||||||
this.selectedDate = this.today;
|
|
||||||
|
|
||||||
// Set original table as default
|
// Set original date and table as default
|
||||||
|
this.selectedDate = this.originalDate;
|
||||||
this.selectedTableId = this.originalTableId;
|
this.selectedTableId = this.originalTableId;
|
||||||
|
|
||||||
// Load schedules for today and selected table
|
// Load schedules for today and selected table
|
||||||
|
@ -134,7 +134,13 @@ class="text-white px-4 py-2 rounded-lg">
|
||||||
},
|
},
|
||||||
|
|
||||||
get canSubmit() {
|
get canSubmit() {
|
||||||
return this.selectedDate && this.selectedTableId && this.selectedStartHour !== null;
|
return this.selectedDate &&
|
||||||
|
this.selectedTableId &&
|
||||||
|
this.selectedStartHour !== null &&
|
||||||
|
// Prevent submitting if nothing changed
|
||||||
|
(this.selectedDate !== this.originalDate ||
|
||||||
|
this.selectedTableId != this.originalTableId ||
|
||||||
|
this.selectedStartHour !== this.originalStartTime.split(':')[0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
get formattedSchedule() {
|
get formattedSchedule() {
|
||||||
|
@ -161,9 +167,20 @@ class="text-white px-4 py-2 rounded-lg">
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/booking/reschedule/check-availability?table_id=${this.selectedTableId}&date=${this.selectedDate}&booking_id=${this.bookingId}`);
|
const response = await fetch(`/booking/reschedule/check-availability?table_id=${this.selectedTableId}&date=${this.selectedDate}&booking_id=${this.bookingId}`);
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
this.bookedSchedules = await response.json();
|
this.bookedSchedules = await response.json();
|
||||||
|
|
||||||
|
// If today is the original booking date and table is the original table,
|
||||||
|
// pre-select the original start hour
|
||||||
|
if (this.selectedDate === this.originalDate &&
|
||||||
|
parseInt(this.selectedTableId) === parseInt(this.originalTableId)) {
|
||||||
|
this.selectedStartHour = this.originalStartTime.split(':')[0];
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error checking booked schedules:', error);
|
console.error('Error checking booked schedules:', error);
|
||||||
|
alert('Terjadi kesalahan saat memeriksa jadwal. Silakan coba lagi.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -174,6 +191,15 @@ class="text-white px-4 py-2 rounded-lg">
|
||||||
// Check if slot end time exceeds midnight
|
// Check if slot end time exceeds midnight
|
||||||
if (endHourInt > 24) return false;
|
if (endHourInt > 24) return false;
|
||||||
|
|
||||||
|
// Check if this is the original booking's time slot (should be allowed)
|
||||||
|
const isOriginalTimeSlot = this.selectedDate === this.originalDate &&
|
||||||
|
parseInt(this.selectedTableId) === parseInt(this.originalTableId) &&
|
||||||
|
hour === this.originalStartTime.split(':')[0];
|
||||||
|
|
||||||
|
if (isOriginalTimeSlot) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if any existing booking overlaps with this slot
|
// Check if any existing booking overlaps with this slot
|
||||||
return !this.bookedSchedules.some(schedule => {
|
return !this.bookedSchedules.some(schedule => {
|
||||||
const scheduleStart = parseInt(schedule.start.split(':')[0]);
|
const scheduleStart = parseInt(schedule.start.split(':')[0]);
|
||||||
|
|
Loading…
Reference in New Issue