@include('Partials.sidebar')
@include('Partials.header')

Booking #{{ $booking->id }}

  1. โ€บ
  2. Bookings
  3. โ€บ
  4. #{{ $booking->id }}
@foreach(['success','error'] as $t) @if(session($t))
{{ session($t) }}
@endif @endforeach @php // Determine the actual role of the agent who made this booking // (booked_by_broker_id is set for BOTH brokers and sales agents, // so isBrokerBooking() alone can't distinguish them โ€” check the // related user's role directly). $agentRole = $booking->broker->role ?? null; // 'broker' | 'sales' | null $isAgentBooking = (bool) $booking->broker; $isSalesBooking = $agentRole === 'sales'; $isBrokerBooking = $agentRole === 'broker'; $agentLabel = $isSalesBooking ? 'Sales Agent' : ($isBrokerBooking ? 'Broker' : 'Agent'); $agentBadgeText = $isSalesBooking ? 'Sales Booking' : ($isBrokerBooking ? 'Broker Booking' : 'Agent Booking'); $agentIcon = $isSalesBooking ? '๐Ÿ“ˆ' : '๐Ÿค'; // โ”€โ”€ Milestones that already have a manual payment awaiting approval โ”€โ”€ // (built from $pendingManualTxns, passed in from BookingAdminController@show) // Used below to hide the milestone's own "Mark as paid" button and avoid // creating a second, duplicate PaymentTransaction for the same milestone. $milestonePendingTxnIds = $pendingManualTxns ->map(fn($t) => json_decode($t->meta, true)['milestone_id'] ?? null) ->filter() ->map(fn($v) => (int) $v) ->all(); @endphp
{{-- โ”€โ”€ Left: booking details โ”€โ”€ --}}
{{-- Unit info --}}
Unit Details
@foreach([ ['Unit No', $booking->plot_number], ['Type', $booking->plot_type], ['Block', optional($booking->block)->block_name ?? $booking->block ?? 'โ€”'], ['Direction', $booking->direction], ['Area', $booking->area], ['Price', $booking->price], ['Project ID', $booking->project_id], ] as [$lbl, $val])
{{ $lbl }}
{{ $val ?: 'โ€”' }}
@endforeach
@if($booking->paymentPlan)
Payment Plan: {{ $booking->paymentPlan->name }} @if($booking->total_amount)  ยท Total: {{ $currency }} {{ number_format($booking->total_amount, 2) }} @endif @if($booking->down_payment_amount)  ยท Down Payment: {{ $currency }} {{ number_format($booking->down_payment_amount, 2) }} @endif
@endif
{{-- Client info --}}
@if($isAgentBooking) Client Details {{ $agentIcon }} {{ $agentBadgeText }} @else Buyer Details @endif
Client Name
{{ $booking->displayClientName() }}
Phone
{{ $booking->displayClientPhone() }}
@if($booking->client_email)
Email
{{ $booking->client_email }}
@endif
@if($isAgentBooking && $booking->broker)
{{ $agentLabel }} Name
{{ $booking->broker->name }}
@if($isBrokerBooking)
Company
{{ $booking->broker->broker_company ?? 'โ€”' }}
@endif
{{ $agentLabel }} Phone
{{ $booking->broker->phone ?? 'โ€”' }}
Role
{{ $agentLabel }}
@endif @if($booking->notes)
Notes: {{ $booking->notes }}
@endif
{{-- โ”€โ”€ Payment Schedule (booking_milestones) โ”€โ”€ --}} @php $milestones = \App\Models\BookingMilestone::where('booking_id', $booking->id) ->orderBy('sort_order') ->get(); $totalAmount = $milestones->sum('total_with_tax'); $paidAmount = $milestones->where('status', 'paid')->sum('total_with_tax'); $balanceDue = $totalAmount - $paidAmount; $pendingCount = $milestones->filter(fn($m) => $m->status !== 'paid' && $m->status !== 'waived')->count(); @endphp @if($milestones->isNotEmpty())
Payment Schedule @if($pendingCount > 0) {{ $pendingCount }} pending @endif
Paid: {{ $currency }} {{ $paidAmount }}  ยท  Balance: {{ $currency }} {{ $balanceDue }}
{{-- Progress bar --}} @if($totalAmount > 0) @php $pct = min(100, round(($paidAmount / $totalAmount) * 100)); @endphp
Payment Progress {{ $pct }}% complete
@endif {{-- Milestone rows --}} @foreach($milestones as $m) @php $isOverdue = $m->status === 'pending' && $m->due_date && $m->due_date->isPast(); $effStatus = $m->status === 'paid' ? 'paid' : ($m->status === 'waived' ? 'waived' : ($isOverdue ? 'overdue' : 'pending')); $dotColor = match($effStatus) { 'paid' => '#22c55e', 'overdue' => '#ef4444', 'waived' => '#94a3b8', default => '#f59e0b', }; $rowBg = $effStatus === 'paid' ? 'rgba(34,197,94,0.04)' : ($effStatus === 'overdue' ? 'rgba(239,68,68,0.04)' : ''); $hasPendingManualTxn = in_array($m->id, $milestonePendingTxnIds); @endphp
{{-- Status dot --}}
{{-- Milestone number --}}
{{ $effStatus === 'paid' ? 'โœ“' : $loop->iteration }}
{{-- Label + dates --}}
{{ $m->label }} @if($m->percentage) ({{ $m->percentage }}%) @endif @if($hasPendingManualTxn) Awaiting approval @endif
@if($m->due_date) Due: {{ $m->due_date->format('d M Y') }} @if($isOverdue) โš  Overdue by {{ $m->due_date->diffForHumans() }} @endif @endif @if($m->paid_at) ยท Paid {{ $m->paid_at->format('d M Y') }} @endif @if($m->notes) ยท {{ $m->notes }} @endif
{{-- Amount --}}
{{ $currency }} {{$m->total_with_tax }}
{{ $effStatus }}
{{-- Remind bell (only for pending/overdue if user exists) --}} @if(in_array($effStatus, ['pending','overdue']) && $booking->user)
@csrf
@endif {{-- Mark as paid button (only for pending/overdue AND no manual payment already awaiting approval for this milestone โ€” prevents creating a second, duplicate PaymentTransaction) --}} @if(in_array($effStatus, ['pending','overdue']) && !$hasPendingManualTxn)
@csrf
@elseif($hasPendingManualTxn) See below โ†“ @endif
@endforeach {{-- Summary footer --}}
Total: {{ $currency }} {{ $totalAmount }}
Paid: {{ $currency }} {{ $paidAmount }}  ยท  Balance: {{ $currency }} {{ $balanceDue }}
@elseif($booking->paymentPlan && $booking->booking_status === 'confirmed') {{-- Plan exists but milestones not yet snapshotted --}}
Payment plan milestones not yet generated for this booking. They are created automatically when the user pays via the online gateway. For manual bookings, use the button below.
@csrf
@endif @if($pendingManualTxns->isNotEmpty())
Pending Manual Payments
@foreach($pendingManualTxns as $txn) @php $meta = json_decode($txn->meta, true) ?? []; @endphp
{{ $currency }} {{ number_format($txn->amount, 2) }} ยท {{ ucfirst(str_replace('_', ' ', $meta['payment_mode'] ?? $txn->mode)) }} @if($meta['milestone_label'] ?? null) โ€” {{ $meta['milestone_label'] }} @endif
Submitted by {{ $meta['submitted_by_name'] ?? 'Unknown' }} ({{ ucfirst($meta['submitted_by_role'] ?? 'โ€”') }}) ยท {{ $txn->created_at->format('d M Y, h:i A') }}
@if($txn->notes)
{{ $txn->notes }}
@endif
@csrf
@csrf
@endforeach
@endif
{{-- โ”€โ”€ Right: actions โ”€โ”€ --}}
{{-- Booking status --}}
Booking Status
Current: {!! $booking->bookingStatusBadge() !!}
Booked on {{ $booking->created_at->format('d M Y, h:i A') }}
@csrf
{{-- Commission (agent bookings โ€” broker or sales) --}} @if($isAgentBooking)
Commission {{ $agentLabel }}
Rate
{{ $booking->commission_rate }}%
Amount
{{ $currency }} {{ number_format($booking->commission_amount, 2) }}
Current: {!! $booking->commissionStatusBadge() !!} @if($booking->commission_paid_at)
Paid on {{ $booking->commission_paid_at->format('d M Y') }}
@endif
@csrf
{{ $currency }}
@endif {{-- Payment Reminder (pending bookings โ€” no plan) --}} @if($booking->booking_status === 'pending' && $booking->user)
Payment Reminder

Send a payment reminder to {{ $booking->user->name }} ({{ $booking->user->email }}). This creates an in-app notification and sends an email.

@csrf
@endif {{-- Quick stats for confirmed bookings with plan --}} @if($booking->booking_status === 'confirmed' && $milestones->isNotEmpty())
Payment Summary
@foreach([ ['Paid', $paidAmount, '#22c55e', 'fas fa-check-circle'], ['Balance', $balanceDue, $balanceDue > 0 ? '#f59e0b' : '#22c55e', 'fas fa-clock'], ['Total', $totalAmount, '#c9a96e', 'fas fa-file-invoice-dollar'], ] as [$lbl, $val, $col, $icon])
{{ $lbl }}
{{ $currency }} {{ $val }}
@endforeach {{-- Overdue alert --}} @php $overdueCount = $milestones->filter(fn($m) => $m->status === 'pending' && $m->due_date && $m->due_date->isPast() )->count(); @endphp @if($overdueCount > 0)
{{ $overdueCount }} overdue milestone{{ $overdueCount > 1 ? 's' : '' }}
@endif
@endif {{-- Danger zone --}}
Danger Zone
@csrf @method('DELETE')
@include('Partials.footer')