<?php ob_start(); ?>
<div class="card">
  <div class="toolbar"><h2>Expenses</h2><div><a href="index.php?controller=expense&action=add" class="btn btn-secondary">Add Expense</a></div></div>
  <form method="get" style="margin-bottom:10px"><input type="hidden" name="controller" value="expense"><input type="hidden" name="action" value="index">
    <div class="form-row filters">
      <div class="field"><label>Year</label><select name="year"><?php for($y=date('Y')-5;$y<=date('Y')+1;$y++): ?><option value="<?=$y?>" <?=($y==$year?'selected':'')?>><?=$y?></option><?php endfor; ?></select></div>
      <div class="field"><label>Month</label><select name="month"><?php for($m=1;$m<=12;$m++): ?><option value="<?=$m?>" <?=($m==$month?'selected':'')?>><?=date('F', mktime(0,0,0,$m,1))?></option><?php endfor; ?></select></div>
      <div style="align-self:end"><button type="submit" class="btn btn-primary">Filter</button></div>
    </div>
  </form>
  <table class="table"><thead><tr><th>Date</th><th>Name</th><th>Category</th><th>Amount</th><th>Note</th><th>Actions</th></tr></thead><tbody>
  <?php foreach($expenses as $r): ?>
    <tr>
      <td><?=htmlspecialchars($r['date'])?></td>
      <td><?=htmlspecialchars($r['apartment'])?></td>
      <td><?=htmlspecialchars($r['category'])?></td>
      <td><?=number_format($r['amount'],2)?></td>
      <td><?=htmlspecialchars($r['note'])?></td>
      <td class="actions"><a href="index.php?controller=expense&action=edit&id=<?=$r['id']?>">Edit</a><a href="index.php?controller=expense&action=delete&id=<?=$r['id']?>" onclick="return confirm('Delete?')">Delete</a></td>
    </tr>
  <?php endforeach; ?>
  </tbody></table>
</div>
<?php $content = ob_get_clean(); include __DIR__ . '/../layout.php'; ?>
