backup: before cancel reservation feature on operator dashboard

This commit is contained in:
ghassan committed 2026-04-16 16:19:33 +03:00
1 parent 51bdf50292
commit c481135280
21 files changed
+793 -91

No files matched your search

@@ -85,7 +85,8 @@ class DashboardController extends Controller
'success' => true,
'data' => [
'daily_bookings' => array_values($dates),
'top_parking_lots' => $topLots->map(fn($lot) => ['name' => $lot->name, 'value' => $lot->bookings_count])->toArray(),
'top_parking_lots' => $topLots->map(fn($lot) => ['id' => $lot->id, 'name' => $lot->name, 'value' => $lot->bookings_count])->toArray(),
'daily_dates' => array_keys($dates),
'occupancy_trend' => $trend,
]
]);
+12 -3
View File
@@ -20,6 +20,7 @@ class BookingController extends Controller
$lot = \App\Models\ParkingLot::find($validated['parking_lot_id']);
$validated['pricing_snapshot'] = $lot?->pricingSnapshot();
$validated['user_id'] = $request->user()->id;
$booking = \App\Models\Booking::create($validated);
@@ -34,9 +35,17 @@ class BookingController extends Controller
public function index(Request $request)
{
$bookings = Booking::with('parkingLot')
->latest()
->paginate(10);
$query = Booking::with('parkingLot')->latest();
if ($request->filled('date')) {
$query->whereDate('created_at', $request->date);
}
if ($request->filled('parking_lot_id')) {
$query->where('parking_lot_id', $request->parking_lot_id);
}
$bookings = $query->paginate($request->integer('per_page', 10));
return response()->json([
'success' => true,
@@ -86,7 +86,7 @@ class OperatorController extends Controller
'phone' => $data['phone'] ?? null,
'source' => 'walk_in',
'start_time' => now(),
'end_time' => now()->addHours($data['duration_hours']),
'end_time' => now()->addHours((float) $data['duration_hours']),
'status' => 'active',
'pricing_snapshot' => $lot->pricingSnapshot(),
]);
+54 -4
View File
@@ -6,6 +6,7 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use App\Models\Booking;
use App\Models\ParkingLot;
class ProfileController extends Controller
{
@@ -16,13 +17,20 @@ class ProfileController extends Controller
public function update(Request $request)
{
$validated = $request->validateWithBag('updateName', [
'name' => 'required|string|max:255',
$request->validateWithBag('updateName', [
'name' => 'required|string|max:255',
'phone_country' => 'required|string|max:10',
'phone_local' => 'required|string|max:20',
], [
'phone_local.required' => 'رقم الهاتف مطلوب.',
]);
Auth::user()->update(['name' => $validated['name']]);
Auth::user()->update([
'name' => $request->name,
'phone' => $request->phone_country . $request->phone_local,
]);
return back()->with('success', 'تم تحديث الاسم بنجاح.');
return back()->with('success', 'تم تحديث البيانات بنجاح.');
}
public function updatePassword(Request $request)
@@ -44,6 +52,48 @@ class ProfileController extends Controller
return back()->with('success', 'تم تغيير كلمة السر بنجاح.');
}
public function reserve(Request $request)
{
$user = Auth::user();
$request->validate([
'parking_lot_id' => 'required|exists:parking_lots,id',
'vehicle_plate' => 'required|string|max:20',
'start_time' => 'required|date|after:now',
'end_time' => 'required|date|after:start_time',
]);
$lot = ParkingLot::findOrFail($request->parking_lot_id);
// Check capacity
$active = $lot->carRegistries()->active()->count()
+ $lot->bookings()->where('status', 'active')->count();
if ($active >= $lot->total_capacity) {
return response()->json([
'success' => false,
'message' => 'الموقف ممتلئ حالياً.',
], 409);
}
$booking = Booking::create([
'user_id' => $user->id,
'parking_lot_id' => $lot->id,
'customer_name' => $user->name,
'phone' => $user->phone ?? '',
'vehicle_plate' => $request->vehicle_plate,
'start_time' => $request->start_time,
'end_time' => $request->end_time,
'status' => 'active',
'pricing_snapshot' => $lot->pricingSnapshot(),
]);
return response()->json([
'success' => true,
'message' => 'تم الحجز بنجاح.',
'data' => ['id' => $booking->id],
], 201);
}
public function dashboard()
{
$bookings = Booking::with('parkingLot')
+5 -11
View File
@@ -25,23 +25,17 @@ class StoreBookingRequest extends FormRequest
{
return [
'parking_lot_id' => 'required|exists:parking_lots,id',
'customer_name' => 'required|string|max:255',
'phone' => 'required|string|max:20|regex:/^09[0-9]{8}$/',
'start_time' => 'required|date|after:now',
'end_time' => 'required|date|after:start_time',
'customer_name' => 'required|string|max:255',
'phone' => 'required|string|max:30',
'vehicle_plate' => 'nullable|string|max:20',
'start_time' => 'required|date|after:now',
'end_time' => 'required|date|after:start_time',
];
}
/**
* Get custom messages for validator errors.
*/
public function messages(): array
{
return [
'phone.regex' => 'رقم الهاتف يجب أن يكون رقم سوري صالح (09xxxxxxxx).',
];
}
/**
* Configure the validator after the validation rules have run.
*/
+1
View File
@@ -21,6 +21,7 @@ class User extends Authenticatable
protected $fillable = [
'name',
'email',
'phone',
'password',
'role',
];