<?php $pageTitle = 'Banking'; ?>
<div class="page-heading"><div><p class="eyebrow">Cash Management</p><h2>Bank, Cash & Card Accounts</h2><p>Record transactions and reconcile activity.</p></div></div>
<div class="stats-grid"><?php foreach ($accounts as $account): ?><div class="stat-card"><span><?= e(readable_status($account['account_type'])) ?></span><strong><?= money($account['current_balance']) ?></strong><small><?= e($account['account_name']) ?><?= $account['last_four'] ? ' · '.$account['last_four'] : '' ?></small></div><?php endforeach; ?></div>
<div class="content-grid two-col">
    <form class="card form-stack" method="post" action="<?= url('/accounting/banking/account') ?>"><?= csrf_field() ?><div class="card-header"><h3>Add Account</h3></div><label><span>Account Name</span><input name="account_name" required></label><div class="form-grid"><label><span>Type</span><select name="account_type"><option value="bank">Bank</option><option value="cash">Cash</option><option value="credit_card">Credit Card</option><option value="fuel_card">Fuel Card</option></select></label><label><span>Institution</span><input name="institution"></label><label><span>Last Four</span><input name="last_four"></label><label><span>Opening Balance</span><input type="number" step="0.01" name="opening_balance" value="0"></label></div><button class="btn btn-primary">Add Account</button></form>
    <form class="card form-stack" method="post" action="<?= url('/accounting/banking/transaction') ?>"><?= csrf_field() ?><div class="card-header"><h3>New Transaction</h3></div><label><span>Account</span><select name="bank_account_id" required><?php foreach ($accounts as $account): ?><option value="<?= (int)$account['id'] ?>"><?= e($account['account_name']) ?></option><?php endforeach; ?></select></label><div class="form-grid"><label><span>Type</span><select name="transaction_type"><option value="deposit">Deposit</option><option value="withdrawal">Withdrawal</option><option value="fee">Fee</option><option value="adjustment">Adjustment</option><option value="transfer_in">Transfer In</option><option value="transfer_out">Transfer Out</option></select></label><label><span>Date</span><input type="date" name="transaction_date" value="<?= date('Y-m-d') ?>"></label><label><span>Amount</span><input type="number" step="0.01" min="0.01" name="amount" required></label><label><span>Reference</span><input name="reference_number"></label></div><label><span>Description</span><textarea name="description"></textarea></label><button class="btn btn-primary">Record Transaction</button></form>
</div>
<section class="card table-card"><div class="card-header"><h3>Recent Transactions</h3></div><div class="table-wrap"><table><thead><tr><th>Date</th><th>Account</th><th>Type</th><th>Reference</th><th>Amount</th><th>Reconciliation</th></tr></thead><tbody><?php foreach ($transactions as $transaction): ?><tr><td><?= e(date_display($transaction['transaction_date'])) ?></td><td><?= e($transaction['account_name']) ?></td><td><?= e(readable_status($transaction['transaction_type'])) ?></td><td><?= e($transaction['reference_number'] ?: '-') ?></td><td><?= money($transaction['amount']) ?></td><td><?php if ($transaction['reconciled_at']): ?><span class="badge badge-success">Reconciled</span><?php else: ?><form method="post" action="<?= url('/accounting/banking/reconcile') ?>"><?= csrf_field() ?><input type="hidden" name="id" value="<?= (int)$transaction['id'] ?>"><button class="btn btn-light btn-sm">Mark reconciled</button></form><?php endif; ?></td></tr><?php endforeach; ?><?php if (!$transactions): ?><tr><td colspan="6" class="empty-state">No transactions recorded.</td></tr><?php endif; ?></tbody></table></div></section>
