<?= $this->extend('layouts/main') ?>
<?= $this->section('content') ?>
<div class="page-header"><div><h1><i class="bi bi-credit-card me-2"></i>Log Expense</h1></div></div>
<?= form_open(base_url('finance/expenses/store')) ?>
<div class="row g-3"><div class="col-lg-7">
  <div class="fm-form-section">
    <h6><i class="bi bi-info-circle"></i>Expense Details</h6>
    <div class="row g-2">
      <div class="col-md-6"><label class="form-label">Facility <span class="text-danger">*</span></label><select name="facility_id" class="form-select" required><option value="">— Select —</option><?php foreach($facilities as $f): ?><option value="<?= $f['id'] ?>"><?= esc($f['name']) ?></option><?php endforeach; ?></select></div>
      <div class="col-md-6"><label class="form-label">Category</label><select name="category" class="form-select"><?php foreach(['maintenance'=>'Maintenance','utilities'=>'Utilities','cleaning'=>'Cleaning','security'=>'Security','repairs'=>'Repairs','staff'=>'Staff','admin'=>'Admin','other'=>'Other'] as $v=>$l): ?><option value="<?= $v ?>"><?= $l ?></option><?php endforeach; ?></select></div>
      <div class="col-md-6"><label class="form-label">Amount (<?= $currency ?>) <span class="text-danger">*</span></label><input type="number" name="amount" class="form-control" step="0.01" min="0.01" required></div>
      <div class="col-md-6"><label class="form-label">Expense Date <span class="text-danger">*</span></label><input type="date" name="expense_date" class="form-control" value="<?= date('Y-m-d') ?>" required></div>
      <div class="col-md-6"><label class="form-label">Linked Work Order</label><select name="work_order_id" class="form-select"><option value="">— None —</option><?php foreach($workOrders as $wo): ?><option value="<?= $wo['id'] ?>"><?= esc($wo['wo_number']) ?> — <?= esc(substr($wo['title'],0,30)) ?></option><?php endforeach; ?></select></div>
      <div class="col-12"><label class="form-label">Description <span class="text-danger">*</span></label><textarea name="description" class="form-control" rows="3" required></textarea></div>
    </div>
  </div>
</div></div>
<div class="d-flex gap-2 mt-2"><button type="submit" class="btn btn-fm-primary"><i class="bi bi-check-lg me-2"></i>Log Expense</button><a href="<?= base_url('finance/expenses') ?>" class="btn btn-fm-outline">Cancel</a></div>
<?= form_close() ?>
<?= $this->endSection() ?>
