<?php
$this->load->view('partials/report_start', $this->data);
$report = isset($report) ? $report : array();
$from_date = isset($from_date) ? $from_date : date('d-m-Y', strtotime(date('Y') . '-04-01'));
$to_date = isset($to_date) ? $to_date : date('d-m-Y');
$budget_allotted = isset($budget_allotted) ? $budget_allotted : '';
$row = (!empty($report) && isset($report[0])) ? $report[0] : null;
?>
<form method="post">
  <div class="row filter-row align-items-end mb-3">
    <div class="col-md-3">
      <div class="form-group mb-0">
        <label>From Date</label>
        <input type="text" class="form-control js-date" name="from_date"
               value="<?php echo htmlspecialchars($from_date); ?>" placeholder="dd-mm-yyyy" autocomplete="off" required>
      </div>
    </div>
    <div class="col-md-3">
      <div class="form-group mb-0">
        <label>To Date</label>
        <input type="text" class="form-control js-date" name="to_date"
               value="<?php echo htmlspecialchars($to_date); ?>" placeholder="dd-mm-yyyy" autocomplete="off" required>
      </div>
    </div>
    <div class="col-md-3">
      <div class="form-group mb-0">
        <label>Budget Allotted</label>
        <input type="number" step="0.01" min="0" class="form-control" name="budget_allotted"
               value="<?php echo htmlspecialchars((string) $budget_allotted); ?>" required placeholder="e.g. 3000000">
      </div>
    </div>
    <div class="col-md-3">
      <?php $this->load->view('partials/report_actions'); ?>
    </div>
  </div>
  <?php if (!empty($date_error)) { ?>
    <div class="alert alert-warning py-2"><?php echo htmlspecialchars($date_error); ?></div>
  <?php } ?>
<?php if (!empty($searched) && $row) { ?>
  <div class="report-results-toolbar">
    <p class="report-summary mb-0">
      Date range: <strong><?php echo htmlspecialchars($from_date); ?></strong>
      to <strong><?php echo htmlspecialchars($to_date); ?></strong>
    </p>
    <?php $this->load->view('partials/report_exports'); ?>
  </div>
  <div class="card report-card mt-3">
    <div class="card-body">
      <p class="mb-1"><u><strong>Acquisition :</strong></u></p>
      <h4 class="mb-3"><strong>Budget Expenditure report</strong></h4>
      <p class="mb-4">
        Date Range:
        <strong><?php echo htmlspecialchars($from_date); ?></strong>
        to
        <strong><?php echo htmlspecialchars($to_date); ?></strong>
      </p>
      <div class="table-responsive">
        <table class="table table-bordered text-center mb-0" style="max-width:720px;">
          <thead>
            <tr>
              <th>Budget Allotted</th>
              <th>Amount Utilized</th>
              <th>Balance</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td><strong><?php echo number_format((float) $row->Budget_Allotted, 2); ?></strong></td>
              <td><strong><?php echo number_format((float) $row->Amount_Utilized, 2); ?></strong></td>
              <td><strong><?php echo number_format((float) $row->Balance, 2); ?></strong></td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
  </div>
<?php } ?>
</form>
<?php $this->load->view('partials/report_end'); ?>
