@extends('layouts.app')
@section('title','Van Sales')
@section('content')
<div class="page-head"><div><h1>Van sales dashboard</h1><p>Each van is a warehouse and uses the same inventory and billing engine.</p></div><a href="{{ route('van.create') }}" class="btn btn-primary btn-dense"><i class="bi bi-plus-lg me-1"></i>Open van day</a></div>
<div class="row g-2 mb-2"><div class="col-6 col-md-3"><div class="card-erp stat-card"><div class="label">Open sessions</div><div class="value">{{ $sessions->where('status','open')->count() }}</div></div></div><div class="col-6 col-md-3"><div class="card-erp stat-card"><div class="label">Visible sales</div><div class="value">SAR {{ number_format((float)$sessions->sum(fn($s)=>$s->sales->where('status','finalized')->sum('grand_total')),2) }}</div></div></div></div>
<div class="card-erp"><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Session</th><th>Date</th><th>Van</th><th>Salesman</th><th>Route</th><th class="text-end">Sales</th><th class="text-end">Balance stock</th><th>Status</th><th></th></tr></thead><tbody>@forelse($sessions as $s)<tr><td class="fw-bold text-accent">{{ $s->session_no }}</td><td>{{ $s->session_date->format('d M Y') }}</td><td>{{ $s->warehouse?->code }}</td><td>{{ $s->salesman?->name }}</td><td>{{ $s->route?:'—' }}</td><td class="text-end">{{ number_format((float)$s->sales->where('status','finalized')->sum('grand_total'),2) }}</td><td class="text-end">{{ number_format((float)$s->warehouse?->stocks?->sum('qty'),2) }}</td><td><span class="badge status-{{ $s->status }}">{{ strtoupper($s->status) }}</span></td><td><a class="btn btn-light border btn-dense" href="{{ route('van.show',$s) }}">Open</a></td></tr>@empty<tr><td colspan="9" class="text-center text-muted py-5">No van sessions. Open a van day to begin.</td></tr>@endforelse</tbody></table></div>@if($sessions->hasPages())<div class="card-erp-body border-top">{{ $sessions->links() }}</div>@endif</div>
@endsection
