@extends('layouts.panel') @section('title', 'Detalle de Orden de Trabajo') @section('content')
{{-- Columna Izquierda: Ciclo Operativo e Información Principal --}}
{{-- 1. CICLO DE TRABAJO (PASOS DE LA ORDEN) --}}
Ciclo de la Orden de Trabajo
@php $workflowSteps = [ 'pendiente' => ['label' => 'Pendiente', 'icon' => 'bi-hourglass-split'], 'received' => ['label' => 'Recibido', 'icon' => 'bi-box-seam'], 'washing' => ['label' => 'Lavado', 'icon' => 'bi-water'], 'drying' => ['label' => 'Secado', 'icon' => 'bi-wind'], 'folding' => ['label' => 'Doblado', 'icon' => 'bi-layers'], 'bagging' => ['label' => 'Embolsado', 'icon' => 'bi-bag-check'], 'ready' => ['label' => 'Listo', 'icon' => 'bi-check-circle'], 'dispatched' => ['label' => 'Entregado', 'icon' => 'bi-truck'] ]; $stepKeys = array_keys($workflowSteps); $currentIndex = array_search($order->status, $stepKeys); if ($currentIndex === false) { $currentIndex = 0; } $statusColors = [ 'pendiente' => 'danger', 'received' => 'secondary', 'washing' => 'info', 'drying' => 'info', 'folding' => 'warning', 'bagging' => 'warning', 'ready' => 'success', 'dispatched' => 'primary', ]; $currentColor = $statusColors[$order->status] ?? 'secondary'; @endphp {{-- Componente Stepper de Pasos --}}
@foreach ($workflowSteps as $key => $step) @php $stepIdx = array_search($key, $stepKeys); $isCompleted = $stepIdx < $currentIndex; $isCurrent = $stepIdx === $currentIndex; @endphp
{{ $step['label'] }}
@endforeach
{{-- Resumen del Estado Operativo con Acción SweetAlert2 --}}
Etapa Operativa Actual: {{ $order->statusLabel() }}
{{-- 2. INFORMACIÓN DEL PEDIDO (DETALLE DE ORDEN DE TRABAJO) --}}
Detalle de Orden de trabajo
Cliente {{ $order->client->business_name ?? $order->contact_name ?? '—' }}
RUT {{ $order->client->rut ?? '—' }}
@if($order->branch)
Sucursal cliente {{ $order->branch->name }}
@endif
Nombre de contacto {{ $order->contact_name ?? '—' }}
Email de contacto {{ $order->contact_email ?? '—' }}
Teléfono de contacto {{ $order->contact_phone ?? '—' }}
Peso total {{ $order->weight_kg ? number_format($order->weight_kg, 2) . ' kg' : '—' }}
Tarifa aplicada @if($order->tariff) ${{ number_format($order->tariff->price_per_kg, 0, ',', '.') }}/kg {{ $order->tariff->client_id ? 'específica' : 'general' }} @else Sin tarifa asignada @endif
Fecha de retiro {{ $order->pickup_date?->format('d-m-Y') ?? '—' }}
Fecha de despacho {{ $order->delivery_date?->format('d-m-Y') ?? '—' }}
Dirección de retiro {{ $order->pickup_address ?? '—' }}
Dirección de despacho {{ $order->delivery_address ?? '—' }}
Registrado por {{ $order->createdBy->name ?? 'Sistema' }}
@if($order->notes)
Notas especiales

{{ $order->notes }}

@endif
{{-- 3. HISTORIAL DE ESTADOS --}}
Historial de estados
@forelse ($order->statusHistories as $history)
{{ \App\Models\Order::STATUSES[$history->status] ?? $history->status }}
{{ $history->created_at->format('d-m-Y H:i') }} — {{ $history->changedBy?->name ?? 'Sistema' }}
@if($history->notes)
{{ $history->notes }}
@endif
@empty

Sin historial registrado.

@endforelse
{{-- 4. PRENDAS --}}
Prendas
@forelse ($order->items as $item)
{{ $item->garment_type }} @if($item->service) {{ $item->service->name }} @endif @if($item->notes)
{{ $item->notes }}
@endif
{{ $item->quantity }} {{ $item->unit }} @if($item->unit_price)
P. unit: ${{ number_format($item->unit_price, 0, ',', '.') }}
Neto: ${{ number_format($item->net_price, 0, ',', '.') }} · IVA: ${{ number_format($item->tax_amount, 0, ',', '.') }}
Total: ${{ number_format($item->total_price, 0, ',', '.') }}
@else
Sin precio propio (cobrado por kg)
@endif
@empty

Sin prendas registradas para este pedido.

@endforelse
{{-- Columna Derecha: Estado Financiero y Facturación --}}
{{-- ESTADO DEL PAGO (incluye resumen financiero Neto/IVA/Total) --}}
Estado del pago
{{-- Resumen financiero: Neto / IVA / Total --}}
Neto {{ $order->net_amount ? '$' . number_format($order->net_amount, 0, ',', '.') : '—' }}
IVA {{ $order->tax_amount ? '$' . number_format($order->tax_amount, 0, ',', '.') : '—' }}
Total {{ $order->total_amount ? '$' . number_format($order->total_amount, 0, ',', '.') : '—' }}
@php $paymentConfig = [ 0 => ['color' => 'warning', 'label' => 'Pendiente', 'icon' => 'bi-hourglass-split'], 1 => ['color' => 'success', 'label' => 'Pagado', 'icon' => 'bi-check-circle-fill'], 2 => ['color' => 'danger', 'label' => 'Fallido/Rechazado', 'icon' => 'bi-x-circle-fill'], ]; $pState = $paymentConfig[(int) $order->payment_status] ?? $paymentConfig[0]; @endphp {{ $order->paymentStatusLabel() }}
@if($order->payment_method_id)
Método de pago ID #{{ $order->payment_method_id }}
@endif @if($order->payment_detail)
Detalle de pago
{{ $order->payment_detail }}
@endif
{{-- MÓDULO DE FACTURACIÓN ELECTRÓNICA (BSALE) --}}
Facturación Bsale
@if($order->invoices && $order->invoices->count() > 0)
Documentos Emitidos:
@foreach($order->invoices as $inv)
{{ $inv->dteType->name }} Folio N° {{ $inv->number ?? '—' }}
@if($inv->url_pdf) PDF @endif
@endforeach

@endif
@csrf @php $dteTypes = \App\Models\DteType::where('is_active', 1)->get(); @endphp
@if($order->income)
Ingreso asociado
Fecha de recepción {{ $order->income->received_at->format('d-m-Y H:i') }}
Referencia {{ $order->income->reference_number ?? '—' }}
@endif @if($order->tariff)
Detalle de tarifa
Tipo {{ $order->tariff->client_id ? 'Específica del cliente' : 'General' }}
@if($order->tariff->service)
Servicio {{ $order->tariff->service->name }}
@endif
Línea de servicio {{ $order->tariff->serviceLineLabel() }}
Precio por kg ${{ number_format($order->tariff->price_per_kg, 0, ',', '.') }}
Vigencia de la tarifa {{ $order->tariff->valid_from->format('d-m-Y') }} — {{ $order->tariff->valid_to?->format('d-m-Y') ?? 'indefinido' }}
@endif
{{-- Estilos para el Resumen Financiero dentro de la card de Estado del pago --}} {{-- Estilos para el Stepper del Ciclo Operativo --}} {{-- Script de cambio de estado con SweetAlert2 --}} @endsection