@extends('layouts.app')
@section('title','Sales Invoices')
@section('content')
<div class="page-head"><div><h1>Sales invoices</h1><p>Finalized documents are immutable; corrections use a sales return.</p></div><a href="{{ route('sales.create') }}" class="btn btn-primary btn-dense"><i class="bi bi-plus-lg me-1"></i>New invoice</a></div>
<div class="card-erp"><div class="card-erp-body"><form class="row g-2 align-items-end"><div class="col-md-4"><label class="form-label">Search invoice or customer</label><input class="form-control" name="q" value="{{ request('q') }}"></div><div class="col-md-2"><label class="form-label">Status</label><select class="form-select" name="status"><option value="">All statuses</option>@foreach(['draft','finalized','cancelled'] as $s)<option @selected(request('status')===$s)>{{ $s }}</option>@endforeach</select></div><div class="col-md-2"><label class="form-label">From</label><input type="date" class="form-control" name="date_from" value="{{ request('date_from') }}"></div><div class="col-md-2"><label class="form-label">To</label><input type="date" class="form-control" name="date_to" value="{{ request('date_to') }}"></div><div class="col-md-2"><button class="btn btn-dark btn-dense w-100">Apply filters</button></div></form></div><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Invoice</th><th>Date</th><th>Customer</th><th>Warehouse</th><th>Payment</th><th class="text-end">Total</th><th class="text-end">Balance</th><th>Status</th><th></th></tr></thead><tbody>@forelse($sales as $sale)<tr><td><a class="fw-bold text-accent text-decoration-none" href="{{ route('sales.show',$sale) }}">{{ $sale->invoice_no }}</a><small class="d-block text-muted">{{ str_replace('_',' ',ucfirst($sale->invoice_type)) }}</small></td><td>{{ $sale->invoice_date->format('d M Y') }}</td><td><strong>{{ $sale->customer?->name_en }}</strong><small class="d-block text-muted" dir="rtl">{{ $sale->customer?->name_ar }}</small></td><td>{{ $sale->warehouse?->code }}</td><td>{{ ucfirst($sale->payment_type) }}</td><td class="text-end fw-bold">{{ number_format((float)$sale->grand_total,2) }}</td><td class="text-end">{{ number_format((float)$sale->balance_total,2) }}</td><td><span class="badge status-{{ $sale->status }}">{{ strtoupper($sale->status) }}</span></td><td class="text-end"><a class="btn btn-light border btn-dense" href="{{ route('sales.show',$sale) }}">Open</a></td></tr>@empty<tr><td colspan="9" class="text-center text-muted py-5">No sales invoices match the selected filters.</td></tr>@endforelse</tbody></table></div>@if($sales->hasPages())<div class="card-erp-body border-top">{{ $sales->links() }}</div>@endif</div>
@endsection
