@extends('layouts.app')
@section('title','Customer Invoices')
@section('page_title','Customer Invoices')
@section('content')
<div class="page-head"><div><h1>Customer Invoices</h1><p>Draft, approve, post, allocate and print UAE VAT invoices.</p></div>@if(auth()->user()->hasPermission('customer_invoices.create'))<a class="btn btn-primary" href="{{ route('invoices.create') }}">+ New Invoice</a>@endif</div>
<div class="card"><div class="toolbar"><form class="search"><input class="control" name="search" value="{{ request('search') }}" placeholder="Invoice, customer or PO"><select class="control" name="status" style="max-width:180px"><option value="">All statuses</option>@foreach(\App\Enums\DocumentStatus::cases() as $status)<option value="{{ $status->value }}" @selected(request('status')===$status->value)>{{ ucwords(str_replace('_',' ',$status->value)) }}</option>@endforeach</select><button class="btn btn-secondary">Filter</button></form><span class="muted">{{ $invoices->total() }} invoices</span></div>
<div class="table-wrap"><table class="table"><thead><tr><th>Invoice</th><th>Date</th><th>Customer</th><th>Type</th><th>Total</th><th>Paid / Allocated</th><th>Balance</th><th>Status</th><th>Actions</th></tr></thead><tbody>
@forelse($invoices as $invoice)@php($status=$invoice->status instanceof \App\Enums\DocumentStatus?$invoice->status->value:$invoice->status)@php($balance=(float)$invoice->grand_total-(float)$invoice->allocated_total)<tr><td><strong>{{ $invoice->invoice_number }}</strong><div class="muted">{{ $invoice->customer_po }}</div></td><td>{{ $invoice->issue_date->format('d M Y') }}</td><td>{{ $invoice->party?->legal_name }}</td><td>{{ ucwords(str_replace('_',' ',$invoice->invoice_type)) }}</td><td class="nowrap">{{ $invoice->currency_code }} {{ number_format((float)$invoice->grand_total,2) }}</td><td>{{ number_format((float)$invoice->allocated_total,2) }}</td><td>{{ number_format($balance,2) }}</td><td><span class="badge status-{{ $status }}">{{ ucwords(str_replace('_',' ',$status)) }}</span></td><td><div class="actions"><a class="btn btn-secondary btn-sm" href="{{ route('invoices.show',$invoice) }}">Open</a><a class="btn btn-secondary btn-sm" target="_blank" href="{{ route('invoices.print',$invoice) }}">Print</a></div></td></tr>@empty<tr><td colspan="9" class="empty">No invoices found.</td></tr>@endforelse
</tbody></table></div>{{ $invoices->links() }}</div>
@endsection
