@extends('layouts.app')
@section('title','Expenses')
@section('page_title','Expense Management')
@section('content')
<div class="page-head"><div><h1>Expenses</h1><p>Cash, bank, card, employee and driver-paid expenses with VAT and job allocation.</p></div><a class="btn btn-primary" href="{{ route('expenses.create') }}">+ New Expense</a></div>
<div class="card"><div class="toolbar"><form class="search"><input class="control" name="search" value="{{ request('search') }}" placeholder="Number, category, description"><select class="control" name="status"><option value="">All statuses</option>@foreach(\App\Enums\DocumentStatus::cases() as $s)<option value="{{ $s->value }}" @selected(request('status')===$s->value)>{{ ucwords(str_replace('_',' ',$s->value)) }}</option>@endforeach</select><button class="btn btn-secondary">Filter</button></form><span class="muted">{{ $expenses->total() }} expenses</span></div><div class="table-wrap"><table class="table"><thead><tr><th>Expense</th><th>Date</th><th>Category</th><th>Payee</th><th>Account</th><th>VAT</th><th>Total</th><th>Status</th><th></th></tr></thead><tbody>@forelse($expenses as $e)@php($s=$e->status instanceof \App\Enums\DocumentStatus?$e->status->value:$e->status)<tr><td><strong>{{ $e->expense_number }}</strong><div class="muted">{{ $e->description }}</div></td><td>{{ $e->expense_date->format('d M Y') }}</td><td>{{ $e->category }}</td><td>{{ $e->party?->legal_name ?? 'Direct expense' }}</td><td>{{ $e->expenseAccount?->name }}</td><td>{{ number_format((float)$e->recoverable_vat+(float)$e->nonrecoverable_vat,2) }}</td><td>AED {{ number_format((float)$e->total_amount,2) }}</td><td><span class="badge status-{{ $s }}">{{ ucwords(str_replace('_',' ',$s)) }}</span></td><td><a class="btn btn-secondary btn-sm" href="{{ route('expenses.show',$e) }}">Open</a></td></tr>@empty<tr><td colspan="9" class="empty">No expenses found.</td></tr>@endforelse</tbody></table></div>{{ $expenses->links() }}</div>
@endsection
