@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')
{{-- ═══════════ SIDEBAR ═══════════ --}}
{{-- Category --}}
Category
{{-- Custom Calendar --}}
@foreach(['Su','Mo','Tu','We','Th','Fr','Sa'] as $wd)
{{ $wd }}
@endforeach
{{-- Selected date pill --}}
{{ $date->format('D, M j, Y') }}
{{-- Tags --}} @if($allTags->isNotEmpty())
Tags
@foreach($allTags as $t) @endforeach
@endif
{{-- ═══════════ /SIDEBAR ═══════════ --}} {{-- ═══════════ MAIN ═══════════ --}}
{{-- Page header --}} @if($products->isEmpty())
No products found for the selected filters.
@else {{-- ── Grid View ── --}}
@foreach($products as $product) @php $photo = $product->photos->first(); @endphp
@if($photo) {{ $product->name }} @else
@endif
{{ $product->name }}
{{ $product->is_available ? 'Available' : 'Unavailable' }}
${{ number_format($product->display_price, 0) }} {{ $product->display_rate_type === 'per_hour' ? '/ hour' : ($product->display_rate_type === 'per_day' ? '/ day' : ($product->display_rate_type === 'per_24_hours' ? '/ 24 hrs' : '')) }}
@if($product->description)
{!! $product->description !!}
@endif @if($product->tags->isNotEmpty())
@foreach($product->tags as $t) {{ $t->name }} @endforeach
@endif
@if($product->is_available) @else @endif
@endforeach
{{-- ── List View ── --}} @endif
{{-- ═══════════ /MAIN ═══════════ --}}
{{-- ═══════════ BOOK NOW MODAL ═══════════ --}} {{-- ═══════════ AVAILABILITY MODAL ═══════════ --}}
@endsection @section('page-script') @endsection