@extends('layouts.app')
@section('title','Purchase Invoices')
@section('content')
<div class="page-head"><div><h1>Purchase invoices</h1><p>Approved purchases update stock, weighted average cost, supplier payable, input VAT, and journals.</p></div><a href="{{ route('purchases.create') }}" class="btn btn-primary btn-dense"><i class="bi bi-plus-lg me-1"></i>New purchase</a></div>
<div class="card-erp"><div class="card-erp-body"><form class="row g-2 align-items-end"><div class="col-md-6"><label class="form-label">Search purchase, supplier invoice, or supplier</label><input class="form-control" name="q" value="{{ request('q') }}"></div><div class="col-md-3"><label class="form-label">Status</label><select class="form-select" name="status"><option value="">All</option>@foreach(['draft','finalized','cancelled'] as $s)<option @selected(request('status')===$s)>{{ $s }}</option>@endforeach</select></div><div class="col-md-3"><button class="btn btn-dark w-100">Apply</button></div></form></div><div class="table-responsive"><table class="table table-dense"><thead><tr><th>Purchase</th><th>Date</th><th>Supplier</th><th>Supplier invoice</th><th>Warehouse</th><th class="text-end">VAT</th><th class="text-end">Total</th><th class="text-end">Balance</th><th>Status</th><th></th></tr></thead><tbody>@forelse($purchases as $purchase)<tr><td><a class="fw-bold text-accent text-decoration-none" href="{{ route('purchases.show',$purchase) }}">{{ $purchase->purchase_no }}</a></td><td>{{ $purchase->purchase_date->format('d M Y') }}</td><td>{{ $purchase->supplier?->name_en }}</td><td>{{ $purchase->supplier_invoice_no?:'—' }}</td><td>{{ $purchase->warehouse?->code }}</td><td class="text-end">{{ number_format((float)$purchase->vat_total,2) }}</td><td class="text-end fw-bold">{{ number_format((float)$purchase->grand_total,2) }}</td><td class="text-end">{{ number_format((float)$purchase->balance_total,2) }}</td><td><span class="badge status-{{ $purchase->status }}">{{ strtoupper($purchase->status) }}</span></td><td><a class="btn btn-light border btn-dense" href="{{ route('purchases.show',$purchase) }}">Open</a></td></tr>@empty<tr><td colspan="10" class="text-center text-muted py-5">No purchase invoices found.</td></tr>@endforelse</tbody></table></div>@if($purchases->hasPages())<div class="card-erp-body border-top">{{ $purchases->links() }}</div>@endif</div>
@endsection
