@extends('layouts.app', ['pageTitle' => 'Invoices / Receivables', 'pageSubtitle' => 'Create customer invoices and receive payments'])
@section('content')
<div class="card"><h3 class="section-title">Create Invoice</h3><form method="POST" action="{{ route('admin.invoices.store') }}" class="form-grid">@csrf
<div class="field"><label>Customer</label><select name="contact_id"><option value="">Walk-in / None</option>@foreach($customers as $c)<option value="{{ $c->id }}">{{ $c->name }}</option>@endforeach</select></div><div class="field"><label>Invoice Date</label><input type="date" name="invoice_date" value="{{ date('Y-m-d') }}" required></div><div class="field"><label>Due Date</label><input type="date" name="due_date"></div><div class="field"><label>Subtotal</label><input type="number" step="0.01" name="subtotal" required></div><div class="field"><label>Tax Amount</label><input type="number" step="0.01" name="tax_amount" value="0"></div><div class="field"><label>Notes</label><input name="notes"></div><div><button class="btn" type="submit">Create Invoice</button></div></form></div>
<div class="card"><h3 class="section-title">Invoices</h3><div class="table-wrap"><table><thead><tr><th>No</th><th>Customer</th><th>Date</th><th>Total</th><th>Paid</th><th>Status</th><th>Receive Payment</th></tr></thead><tbody>@foreach($invoices as $i)<tr><td>{{ $i->invoice_number }}</td><td>{{ $i->contact_name ?? 'N/A' }}</td><td>{{ $i->invoice_date }}</td><td>₦{{ number_format($i->total_amount,2) }}</td><td>₦{{ number_format($i->amount_paid,2) }}</td><td><span class="badge {{ $i->status === 'paid' ? '' : 'warn' }}">{{ $i->status }}</span></td><td>@if($i->status !== 'paid')<form method="POST" action="{{ route('admin.invoices.receive', $i->id) }}" class="actions">@csrf<select name="bank_account_id" required>@foreach($banks as $b)<option value="{{ $b->id }}">{{ $b->bank_name }}</option>@endforeach</select><input style="width:120px" type="number" step="0.01" name="amount" placeholder="Amount" required><input type="hidden" name="method" value="bank_transfer"><input style="width:130px" name="reference" placeholder="Reference"><button class="btn btn-small" type="submit">Receive</button></form>@endif</td></tr>@endforeach</tbody></table></div><p class="footer-note">Create at least one bank account during setup, which the seeder already does.</p></div>
@endsection
