backup: before operator assignment feature
This commit is contained in:
1 parent
c481135280
commit
ba453d7b82
12 files changed
+1126
-101
No files matched your search
@@ -47,34 +47,75 @@ class BookingController extends Controller
|
||||
));
|
||||
}
|
||||
|
||||
public function completeBooking(Request $request, Booking $booking): JsonResponse
|
||||
public function checkoutPreview(Booking $booking): JsonResponse
|
||||
{
|
||||
if ($booking->status !== 'active') {
|
||||
return response()->json([
|
||||
'success' => false,
|
||||
'message' => 'الحجز غير نشط'
|
||||
], 400);
|
||||
return response()->json(['success' => false, 'message' => 'الحجز غير نشط'], 400);
|
||||
}
|
||||
|
||||
$parkingLot = $booking->parkingLot;
|
||||
$actualDurationHours = $booking->start_time->diffInHours(now());
|
||||
$actualFee = ceil($actualDurationHours) * $parkingLot->price_per_hour;
|
||||
|
||||
$booking->update([
|
||||
'status' => 'completed',
|
||||
'end_time' => now()
|
||||
]);
|
||||
$lot = $booking->parkingLot;
|
||||
$start = $booking->start_time;
|
||||
$end = now();
|
||||
$duration = $start->diffInMinutes($end);
|
||||
$calc = $lot->calculateFee($start, $end, $booking->pricing_snapshot);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'تم إنهاء الحجز بنجاح',
|
||||
'data' => [
|
||||
'actual_duration' => $actualDurationHours . ' ساعات',
|
||||
'actual_fee' => number_format($actualFee, 2) . ' ' . config('app.currency', 'ريال'),
|
||||
'vehicle_plate' => $booking->vehicle_plate ?? $booking->customer_name
|
||||
]
|
||||
'data' => [
|
||||
'plate' => $booking->vehicle_plate,
|
||||
'customer_name' => $booking->customer_name,
|
||||
'lot_name' => $lot->name,
|
||||
'entry_time' => $start->format('Y/m/d H:i'),
|
||||
'exit_time' => $end->format('Y/m/d H:i'),
|
||||
'duration_label' => floor($duration / 60) . 'س ' . ($duration % 60) . 'د',
|
||||
'fee_details' => $calc['details'],
|
||||
'total_fee' => $calc['total'],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function completeBooking(Request $request, Booking $booking): JsonResponse
|
||||
{
|
||||
if ($booking->status !== 'active') {
|
||||
return response()->json(['success' => false, 'message' => 'الحجز غير نشط'], 400);
|
||||
}
|
||||
|
||||
$end = now();
|
||||
$type = $request->input('type', 'force'); // 'payment' | 'force'
|
||||
|
||||
if ($type === 'payment') {
|
||||
$request->validate([
|
||||
'payment_method' => 'required|in:cash,upload',
|
||||
'payment_proof' => 'nullable|file|mimes:jpg,jpeg,png,pdf|max:4096',
|
||||
]);
|
||||
|
||||
$lot = $booking->parkingLot;
|
||||
$calc = $lot->calculateFee($booking->start_time, $end, $booking->pricing_snapshot);
|
||||
|
||||
$proofPath = null;
|
||||
if ($request->hasFile('payment_proof')) {
|
||||
$proofPath = $request->file('payment_proof')->store('payment_proofs', 'public');
|
||||
}
|
||||
|
||||
$booking->update([
|
||||
'status' => 'completed',
|
||||
'end_time' => $end,
|
||||
'total_fee' => $calc['total'],
|
||||
'payment_method' => $request->payment_method,
|
||||
'payment_proof' => $proofPath,
|
||||
'paid_at' => $end,
|
||||
]);
|
||||
} else {
|
||||
// Force close — car left without paying
|
||||
$booking->update([
|
||||
'status' => 'completed',
|
||||
'end_time' => $end,
|
||||
'notes' => $request->input('notes') ?: null,
|
||||
]);
|
||||
}
|
||||
|
||||
return response()->json(['success' => true, 'message' => 'تم إنهاء الحجز بنجاح']);
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in new issue
Block a user