backup: before auth-required booking and phone number feature
This commit is contained in:
1 parent
83d9a67188
commit
900eb24b37
10 files changed
+618
-253
No files matched your search
@@ -52,6 +52,10 @@ class ParkingLotController extends Controller
|
||||
{
|
||||
$data = $request->validated();
|
||||
|
||||
// Never let validated() overwrite the stored image path with null.
|
||||
// Only update the image column when a new file is actually uploaded.
|
||||
unset($data['image']);
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
if ($parkingLot->image) {
|
||||
Storage::disk('public')->delete($parkingLot->image);
|
||||
@@ -91,6 +95,38 @@ class ParkingLotController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function updatePricing(Request $request, ParkingLot $parkingLot): JsonResponse
|
||||
{
|
||||
$data = $request->validate([
|
||||
'price_per_hour' => 'required|numeric|min:0|max:100000',
|
||||
'pricing_rules' => 'nullable|array',
|
||||
'pricing_rules.*'=> 'nullable|numeric|min:0|max:100000',
|
||||
]);
|
||||
|
||||
// Build clean rules array: only include days that differ from base price.
|
||||
// Keys 1-7 (Mon-Sun). Null or empty string means "use base price".
|
||||
$rules = [];
|
||||
foreach ($data['pricing_rules'] ?? [] as $day => $rate) {
|
||||
if ($rate !== null && $rate !== '' && (float) $rate !== (float) $data['price_per_hour']) {
|
||||
$rules[(int) $day] = (float) $rate;
|
||||
}
|
||||
}
|
||||
|
||||
$parkingLot->update([
|
||||
'price_per_hour' => $data['price_per_hour'],
|
||||
'pricing_rules' => empty($rules) ? null : $rules,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'message' => 'تم حفظ أسعار الموقف بنجاح',
|
||||
'data' => [
|
||||
'price_per_hour' => (float) $parkingLot->price_per_hour,
|
||||
'pricing_rules' => $parkingLot->pricing_rules,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function toggleStatus(ParkingLot $parkingLot): JsonResponse
|
||||
{
|
||||
$parkingLot->update(['is_active' => !$parkingLot->is_active]);
|
||||
|
||||
@@ -18,6 +18,9 @@ class BookingController extends Controller
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$lot = \App\Models\ParkingLot::find($validated['parking_lot_id']);
|
||||
$validated['pricing_snapshot'] = $lot?->pricingSnapshot();
|
||||
|
||||
$booking = \App\Models\Booking::create($validated);
|
||||
|
||||
// Note: In production, create CarRegistry here for the booking car
|
||||
|
||||
@@ -80,14 +80,15 @@ class OperatorController extends Controller
|
||||
}
|
||||
|
||||
$booking = Booking::create([
|
||||
'parking_lot_id' => $lot->id,
|
||||
'vehicle_plate' => $data['vehicle_plate'],
|
||||
'customer_name' => $data['customer_name'] ?? null,
|
||||
'phone' => $data['phone'] ?? null,
|
||||
'source' => 'walk_in',
|
||||
'start_time' => now(),
|
||||
'end_time' => now()->addHours($data['duration_hours']),
|
||||
'status' => 'active',
|
||||
'parking_lot_id' => $lot->id,
|
||||
'vehicle_plate' => $data['vehicle_plate'],
|
||||
'customer_name' => $data['customer_name'] ?? null,
|
||||
'phone' => $data['phone'] ?? null,
|
||||
'source' => 'walk_in',
|
||||
'start_time' => now(),
|
||||
'end_time' => now()->addHours($data['duration_hours']),
|
||||
'status' => 'active',
|
||||
'pricing_snapshot' => $lot->pricingSnapshot(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
@@ -128,7 +129,7 @@ class OperatorController extends Controller
|
||||
$start = $booking->start_time;
|
||||
$end = now();
|
||||
$duration = $start->diffInMinutes($end);
|
||||
$calc = $lot->calculateFee($start, $end);
|
||||
$calc = $lot->calculateFee($start, $end, $booking->pricing_snapshot);
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
@@ -163,7 +164,7 @@ class OperatorController extends Controller
|
||||
$lot = $booking->parkingLot;
|
||||
$start = $booking->start_time;
|
||||
$end = now();
|
||||
$calc = $lot->calculateFee($start, $end);
|
||||
$calc = $lot->calculateFee($start, $end, $booking->pricing_snapshot);
|
||||
|
||||
$proofPath = null;
|
||||
if ($request->hasFile('payment_proof')) {
|
||||
|
||||
Reference in new issue
Block a user