@extends('layouts.app', ['pageTitle' => 'Bills / Payables', 'pageSubtitle' => 'Record supplier bills and outgoing payments'])
@section('content')
<div class="card"><h3 class="section-title">Create Bill</h3><form method="POST" action="{{ route('admin.bills.store') }}" class="form-grid">@csrf
<div class="field"><label>Supplier</label><select name="contact_id"><option value="">None</option>@foreach($suppliers as $s)<option value="{{ $s->id }}">{{ $s->name }}</option>@endforeach</select></div><div class="field"><label>Expense Account</label><select name="expense_account_id" required>@foreach($expenseAccounts as $a)<option value="{{ $a->id }}">{{ $a->code }} - {{ $a->name }}</option>@endforeach</select></div><div class="field"><label>Bill Date</label><input type="date" name="bill_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 Bill</button></div></form></div>
<div class="card"><h3 class="section-title">Bills</h3><div class="table-wrap"><table><thead><tr><th>No</th><th>Supplier</th><th>Date</th><th>Total</th><th>Paid</th><th>Status</th><th>Pay</th></tr></thead><tbody>@foreach($bills as $b)<tr><td>{{ $b->bill_number }}</td><td>{{ $b->contact_name ?? 'N/A' }}</td><td>{{ $b->bill_date }}</td><td>₦{{ number_format($b->total_amount,2) }}</td><td>₦{{ number_format($b->amount_paid,2) }}</td><td><span class="badge {{ $b->status === 'paid' ? '' : 'warn' }}">{{ $b->status }}</span></td><td>@if($b->status !== 'paid')<form method="POST" action="{{ route('admin.bills.pay', $b->id) }}" class="actions">@csrf<select name="bank_account_id" required>@foreach($banks as $bank)<option value="{{ $bank->id }}">{{ $bank->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">Pay</button></form>@endif</td></tr>@endforeach</tbody></table></div></div>
@endsection
