{{-- _order_card.blade.php — Carte commande réutilisable @param $order — FoodOrder model instance @param $panel — 'pending' | 'accepted' | 'preparing' | 'ready' --}} @php $isUrgent = $panel === 'pending' && $order->created_at->diffInMinutes(now()) > 5; $requestedAt = null; if (!empty($order->requested_at)) { try { $requestedAt = $order->requested_at instanceof \Carbon\CarbonInterface ? $order->requested_at : \Illuminate\Support\Carbon::parse($order->requested_at); } catch (\Throwable $e) { $requestedAt = null; } } $showScheduleTag = $requestedAt && in_array($order->status, ['accepted','scheduled']) && $requestedAt->isAfter(now()); $items = $order->items ?? collect(); $maxShow = 3; // ── Politique de paiement ── $payPolicy = method_exists($order, 'getPaymentPolicy') ? ((array) ($order->getPaymentPolicy() ?? [])) : []; $pType = $payPolicy['type'] ?? 'cash'; // cash | deposit | full_prepay $pPercent = $payPolicy['percent'] ?? 0; $pStatus = $order->payment_status ?? 'pending'; // pending | pending_capture | paid | refunded | partial $pMethod = $order->payment_method ?? ''; $isPaid = ($pStatus === 'paid'); $isCash = ($pType === 'cash'); $isDeposit = ($pType === 'deposit'); $isFullPay = ($pType === 'full_prepay'); // Montants pour acompte $depositAmount = $isDeposit ? round(($order->total ?? 0) * ($pPercent / 100), 2) : 0; $remainingAmount = $isDeposit ? round(($order->total ?? 0) - $depositAmount, 2) : 0; // Le paiement en ligne est-il requis mais pas encore fait ? $onlineRequired = !$isCash; $onlinePending = $onlineRequired && !$isPaid && $pStatus !== 'pending_capture'; // Livraison $isDelivery = ($order->delivery_type === 'delivery'); $isPickup = !$isDelivery; $hasDriver = !empty($order->driver_id); // Flux bloquant pour accept (pending) $canAccept = !($pMethod !== 'cash' && $pStatus === 'pending' && $onlineRequired); // Flux bloquant pour prépa (accepted) — livreur externe requis $requiresExternalDriver = method_exists($order, 'requiresExternalDriver') ? (bool) $order->requiresExternalDriver() : false; $hasDriverAccepted = method_exists($order, 'hasDriverAccepted') ? (bool) $order->hasDriverAccepted() : false; $needsDriver = $isDelivery && $requiresExternalDriver && !$hasDriverAccepted; @endphp
{{-- HEADER --}}
#{{ $order->order_number }} @if($showScheduleTag) 📅 {{ $requestedAt->format('d/m H\hi') }} @else {{ $order->created_at->diffForHumans(null, false, true) }} @endif
{{-- CLIENT --}}
{{ $order->client->name ?? 'Client' }}
{{-- ITEMS --}}
@foreach($items->take($maxShow) as $item)
{{ $item->quantity }}x {{ $item->product_name ?? $item->name ?? 'Produit' }}
@endforeach @if($items->count() > $maxShow)
+{{ $items->count() - $maxShow }} autre(s)…
@endif
{{-- SPECIAL NOTES --}} @if($order->special_instructions || $order->notes)
📝 {{ $order->special_instructions ?? $order->notes }}
@endif {{-- ══ PAIEMENT INFO ══ --}}
@if($isCash)
💵 Paiement espèces à la remise {{ number_format($order->total ?? 0, 2) }}€ à encaisser @if($isPaid) @endif
@elseif($isDeposit)
🏦 Acompte {{ $pPercent }}% en ligne {{ number_format($depositAmount, 2) }}€ en ligne + {{ number_format($remainingAmount, 2) }}€ espèces @if($isPaid) @elseif($pStatus === 'pending_capture') 🔒 Autorisé @else ⏳ Non payé @endif
@elseif($isFullPay)
💳 Paiement intégral en ligne {{ number_format($order->total ?? 0, 2) }}€ @if($isPaid) @elseif($pStatus === 'pending_capture') 🔒 Autorisé @else ⏳ Non payé @endif
@endif
{{-- FOOTER --}}
{{ number_format($order->total ?? 0, 2) }}€ {{ $isDelivery ? '🛵 Livraison' : '🏪 Emporter' }}
{{-- ══ INFOS CONTEXTUELLES (livreur, blocage, etc) ══ --}} @if($panel === 'accepted' && $isDelivery)
@if($hasDriver)
Livreur assigné
@elseif($needsDriver)
En attente d'un livreur (requis avant prépa)
@else
Recherche d'un livreur…
@endif
@endif @if($panel === 'pending' && !$canAccept)
Le client n'a pas encore payé en ligne — acceptation bloquée
@endif {{-- ══ ACTION BUTTONS ══ --}}
{{-- ═════ PENDING ═════ --}} @if($panel === 'pending') @if($canAccept)
@csrf
@else @endif
@csrf
@endif {{-- ═════ ACCEPTED ═════ --}} @if($panel === 'accepted') @if($needsDriver) @else
@csrf
@endif
@csrf
@endif {{-- ═════ PREPARING ═════ --}} @if($panel === 'preparing')
@csrf
@csrf
@endif {{-- ═════ READY ═════ --}} @if($panel === 'ready') {{-- PICKUP ──────────── --}} @if($isPickup) @if($isCash && !$isPaid) {{-- Cash non encaissé → confirmer espèces + code --}}
@csrf
@endif @if($isDeposit && !$isPaid) {{-- Acompte pas payé → bloquer --}} @elseif($isFullPay && !$isPaid) {{-- Full pay non payé → bloquer --}} @else @endif {{-- DELIVERY ──────────── --}} @else @if($isFullPay && !$isPaid && $pStatus !== 'pending_capture') @elseif($isDeposit && !$isPaid && $pStatus !== 'pending_capture') @else @if($hasDriver) @else
@csrf
@csrf
@endif @endif @endif @endif