@extends('crm.master') @section('title', 'New Booking — ' . config('app.name')) @php $bookingRoutePrefix = $bookingRoutePrefix ?? (request()->routeIs('crm.booking.*') ? 'crm.booking.' : (request()->routeIs('car-rental.*') ? 'car-rental.' : 'booking.')); $productDetails = $products->mapWithKeys(function ($product) { $durationToMinutes = function ($value, $unit) { if (blank($value) || blank($unit)) { return null; } $value = (int) $value; if ($value <= 0) { return null; } return match ($unit) { 'minutes' => $value, 'hours' => $value * 60, 'days' => $value * 1440, default => null, }; }; $formatRuleDuration = function ($minutes) { if ($minutes % 1440 === 0) { $days = (int) ($minutes / 1440); return $days . ' ' . ($days === 1 ? 'day' : 'days'); } if ($minutes % 60 === 0) { $hours = (int) ($minutes / 60); return $hours . ' ' . ($hours === 1 ? 'hour' : 'hours'); } return $minutes . ' ' . ($minutes === 1 ? 'minute' : 'minutes'); }; $enabledRules = $product->availability ->where('booking_rules_enabled', true) ->values(); $minDurationMinutes = null; $maxDurationMinutes = null; $bookingWindowMinutes = null; $cutoffWindowMinutes = null; foreach ($enabledRules as $availabilityRule) { $min = $durationToMinutes($availabilityRule->min_duration_value, $availabilityRule->min_duration_unit); $max = $durationToMinutes($availabilityRule->max_duration_value, $availabilityRule->max_duration_unit); $bookingWindow = $durationToMinutes($availabilityRule->booking_window_value, $availabilityRule->booking_window_unit); $cutoffWindow = $durationToMinutes($availabilityRule->cutoff_window_value, $availabilityRule->cutoff_window_unit); if ($min !== null) { $minDurationMinutes = max($minDurationMinutes ?? 0, $min); } if ($max !== null) { $maxDurationMinutes = $maxDurationMinutes === null ? $max : min($maxDurationMinutes, $max); } if ($bookingWindow !== null) { $bookingWindowMinutes = $bookingWindowMinutes === null ? $bookingWindow : min($bookingWindowMinutes, $bookingWindow); } if ($cutoffWindow !== null) { $cutoffWindowMinutes = max($cutoffWindowMinutes ?? 0, $cutoffWindow); } } $ruleParts = []; if ($minDurationMinutes !== null) { $ruleParts[] = 'Minimum booking ' . $formatRuleDuration($minDurationMinutes); } if ($maxDurationMinutes !== null) { $ruleParts[] = 'Maximum booking ' . $formatRuleDuration($maxDurationMinutes); } if ($bookingWindowMinutes !== null) { $ruleParts[] = 'Book up to ' . $formatRuleDuration($bookingWindowMinutes) . ' in advance'; } if ($cutoffWindowMinutes !== null) { $ruleParts[] = 'Book at least ' . $formatRuleDuration($cutoffWindowMinutes) . ' before start'; } return [ $product->id => [ 'id' => $product->id, 'name' => $product->name, 'description' => $product->description, 'category' => optional($product->category)->name, 'price' => (float) $product->display_price, 'rate_type' => $product->display_rate_type, 'available' => (bool) $product->is_available, 'tags' => $product->tags->pluck('name')->values(), 'photos' => $product->photos->map(function ($photo) { return asset($photo->path); })->values(), 'rule_summary' => !empty($ruleParts) ? implode(' · ', $ruleParts) : null, ], ]; }); @endphp @section('head-extra') @endsection @section('content')
{{ $date->format('l, F j, Y') }}