@@ -12,20 +12,33 @@ class GlobalCalendarController extends Controller
|
||||
{
|
||||
public function __invoke(Request $request): Response
|
||||
{
|
||||
$filters = $request->validate(['month' => ['nullable', 'date_format:Y-m']]);
|
||||
$filters = $request->validate([
|
||||
'month' => ['nullable', 'date_format:Y-m'],
|
||||
'status' => ['nullable', 'string', 'in:pending,confirmed,closed'],
|
||||
]);
|
||||
$month = isset($filters['month'])
|
||||
? CarbonImmutable::createFromFormat('!Y-m', $filters['month'])
|
||||
: now()->startOfMonth();
|
||||
|
||||
$query = Reservation::query()
|
||||
->with(['requester:id,name,department', 'items.asset:id,name,asset_tag'])
|
||||
->where('starts_at', '<', $month->addMonth())
|
||||
->where('ends_at', '>', $month);
|
||||
|
||||
if (! empty($filters['status'])) {
|
||||
$statusMap = [
|
||||
'pending' => ['pending_approval', 'awaiting_information'],
|
||||
'confirmed' => ['approved', 'ready', 'delivered', 'in_use'],
|
||||
'closed' => ['rejected', 'cancelled', 'expired', 'no_show', 'completed'],
|
||||
];
|
||||
$query->whereIn('status', $statusMap[$filters['status']]);
|
||||
}
|
||||
|
||||
return Inertia::render('reservations/calendar', [
|
||||
'scope' => 'global',
|
||||
'month' => $month->format('Y-m'),
|
||||
'reservations' => Reservation::query()
|
||||
->with(['requester:id,name,department', 'items.asset:id,name,asset_tag'])
|
||||
->where('starts_at', '<', $month->addMonth())
|
||||
->where('ends_at', '>', $month)
|
||||
->orderBy('starts_at')
|
||||
->get(),
|
||||
'reservations' => $query->orderBy('starts_at')->get(),
|
||||
'status' => $filters['status'] ?? '',
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user