@php
$pageConfigs = ['navbarType' => 'hidden', 'contentLayout' => 'wide'];
$configData = Helper::appClasses();
$statusMap = [
'pending' => ['Pendiente', 'warning', 'pending'],
'confirmed' => ['Confirmado', 'info', 'confirmed'],
'at_restaurant' => ['En restaurante', 'primary', 'restaurant'],
'en_route' => ['En camino', 'primary', 'route'],
'delivered' => ['Entregado', 'success', 'delivered'],
'cancelled' => ['Cancelado', 'danger', 'cancelled'],
];
$activeCollection = $activeDeliveries ?? collect();
$pendingCount = $activeCollection->where('status', 'pending')->count();
$confirmedCount = $activeCollection->whereIn('status', ['confirmed', 'at_restaurant'])->count();
$enRouteCount = $activeCollection->where('status', 'en_route')->count();
$urgentCount = $activeCollection->where('is_urgent', true)->count();
$totalActiveCount = $activeCollection->count();
$needsDetailsCount = $activeCollection->filter(function ($delivery) {
return $delivery->is_urgent && (
empty($delivery->customer_name)
|| $delivery->customer_name === 'Por definir'
|| empty($delivery->delivery_address)
|| $delivery->delivery_address === 'Por definir'
|| empty($delivery->customer_phone)
);
})->count();
@endphp
@extends('layouts/layoutMaster')
@section('title', 'Pedidos')
@section('content')
@if (session('success'))
{{ session('success') }}
@endif
@if ($errors->any())
@foreach ($errors->all() as $error)
{{ $error }}
@endforeach
@endif
@if ($activeCollection->count())
@if ($needsDetailsCount > 0)
Tienes {{ $needsDetailsCount }} pedido(s) urgente(s) que requieren completar datos del cliente.
@endif
@foreach ($activeCollection as $delivery)
@php
[$label, $color, $tone] = $statusMap[$delivery->status] ?? ['Pendiente', 'warning', 'pending'];
$origin = $delivery->restaurant?->address ?? '';
$destination = $delivery->delivery_address ?? '';
$navApp = auth()->user()->nav_app ?? 'maps';
$navUrl = $navApp === 'waze'
? 'https://waze.com/ul?q=' . urlencode($destination) . '&navigate=yes'
: 'https://www.google.com/maps/dir/?api=1&origin=' . urlencode($origin) . '&destination=' . urlencode($destination);
$needsDetails = $delivery->is_urgent && (
empty($delivery->customer_name)
|| $delivery->customer_name === 'Por definir'
|| empty($delivery->delivery_address)
|| $delivery->delivery_address === 'Por definir'
|| empty($delivery->customer_phone)
);
$nextAction = match ($delivery->status) {
'pending' => ['confirmed', 'Confirmar pedido', 'btn-primary', 'tabler-check'],
'confirmed' => ['at_restaurant', 'He llegado al restaurante', 'btn-info', 'tabler-building-store'],
'at_restaurant' => ['en_route', 'Salir al cliente', 'btn-warning', 'tabler-bike'],
'en_route' => ['delivered', 'Entregado', 'btn-success', 'tabler-checks'],
default => null,
};
$detailsPanelId = 'urgent-details-' . $delivery->id;
$blocksNextAction = $needsDetails
&& $nextAction
&& in_array($nextAction[0], ['en_route', 'delivered'], true);
@endphp
{{ $label }}
@if ($delivery->is_urgent)
Urgente
@endif
#{{ $delivery->id }}
{{ optional($delivery->created_at)->format('d/m H:i') }}
Cliente
{{ $delivery->customer_name ?: 'Por definir' }}
{{ $delivery->customer_phone ?: 'Sin teléfono' }}
Recogida
{{ $delivery->restaurant?->address ?? 'Restaurante' }}
Entrega
{{ $delivery->delivery_address ?: 'Por definir' }}
@if ($delivery->delivery_address_extra)
@endif
@if ($delivery->is_urgent)
@if ($needsDetails)
Completa cliente, teléfono y dirección antes de salir al cliente.
@else
Datos validados
Cliente{{ $delivery->customer_name }}
Teléfono{{ $delivery->customer_phone ?? '-' }}
Dirección{{ $delivery->delivery_address }}
@if ($delivery->delivery_address_extra)
Extra{{ $delivery->delivery_address_extra }}
@endif
@endif
@endif
@if ($blocksNextAction)
Debes completar Datos de cliente para continuar este pedido urgente.
@endif
@endforeach
Sin resultados con ese filtro
Ajusta el estado o limpia la búsqueda para ver más pedidos.
@else
No tienes pedidos activos
Cuando se te asigne uno, aparecerá aquí automáticamente.
Ir al mapa
@endif
@endsection
@section('page-style')
@endsection
@section('page-script')
@endsection