<?php $pageTitle='Accounting Center'; ?>
<div class="page-heading"><div><p class="eyebrow">Financial Operations</p><h1>Accounting Center</h1><p>Receivables, payables, expenses, cash, journals, and profitability in one place.</p></div><div class="page-actions"><a class="btn btn-primary" href="<?= url('/accounting/expenses/create') ?>">Add Expense</a><a class="btn btn-light" href="<?= url('/accounting/reports') ?>">Financial Reports</a></div></div>
<div class="stats-grid">
  <div class="stat-card highlight"><span>Open Receivables</span><strong><?= money($stats['receivables']) ?></strong><small>Outstanding customer invoices</small></div>
  <div class="stat-card"><span>Open Payables</span><strong><?= money($stats['payables']) ?></strong><small>Vendor bills not fully paid</small></div>
  <div class="stat-card"><span>Month Expenses</span><strong><?= money($stats['month_expenses']) ?></strong><small>Approved and posted expenses</small></div>
  <div class="stat-card"><span>Cash Position</span><strong><?= money($stats['cash']) ?></strong><small>Across active financial accounts</small></div>
</div>
<div class="content-grid two-col">
 <div class="panel"><div class="panel-header"><div><p class="eyebrow">Review Queue</p><h2>Recent Expenses</h2></div><a href="<?= url('/accounting/expenses') ?>">View all</a></div><div class="table-wrap"><table><thead><tr><th>Expense</th><th>Category</th><th>Amount</th><th>Status</th></tr></thead><tbody><?php foreach($expenses as $e):?><tr><td><strong><?= e($e['expense_number']) ?></strong><br><small><?= e(date_display($e['expense_date'])) ?></small></td><td><?= e($e['category_name']??'Other') ?></td><td><?= money((float)$e['amount']+(float)$e['tax_amount']) ?></td><td><span class="badge badge-<?= status_class($e['status']) ?>"><?= e(readable_status($e['status'])) ?></span></td></tr><?php endforeach;?><?php if(!$expenses):?><tr><td colspan="4" class="empty">No expenses yet.</td></tr><?php endif;?></tbody></table></div></div>
 <div class="panel"><div class="panel-header"><div><p class="eyebrow">Accounts Payable</p><h2>Recent Vendor Bills</h2></div><a href="<?= url('/accounting/bills') ?>">Manage bills</a></div><div class="mini-list"><?php foreach($bills as $b):?><div class="mini-card"><strong><?= e($b['bill_number'].' · '.$b['company_name']) ?></strong><span><?= money($b['balance_due']) ?> due <?= e(date_display($b['due_date'])) ?> · <?= e(readable_status($b['status'])) ?></span></div><?php endforeach;?><?php if(!$bills):?><p class="empty">No vendor bills yet.</p><?php endif;?></div></div>
</div>
<div class="panel"><div class="panel-header"><div><p class="eyebrow">Profitability</p><h2>Load Financial Snapshot</h2></div></div><div class="table-wrap"><table><thead><tr><th>Load</th><th>Revenue</th><th>Driver Pay</th><th>Expenses</th><th>Net Profit</th><th>Margin</th></tr></thead><tbody><?php foreach($profitability as $p):$margin=(float)$p['revenue']>0?((float)$p['net_profit']/(float)$p['revenue']*100):0;?><tr><td><strong><?= e($p['load_number']) ?></strong></td><td><?= money($p['revenue']) ?></td><td><?= money($p['driver_pay']) ?></td><td><?= money($p['expenses']) ?></td><td><strong><?= money($p['net_profit']) ?></strong></td><td><?= e(number_format($margin,1)) ?>%</td></tr><?php endforeach;?></tbody></table></div></div>
