<?php
$no = 1;
$totalKomisiPage = isset($total_komisi_page) ? (int) $total_komisi_page : 0;
?>
<div class="d-flex flex-wrap align-items-center justify-content-between mb-3">
  <div class="text-muted">Ringkasan total komisi untuk page ini.</div>
  <div class="font-weight-bold">Total Komisi Page: <?= rp($totalKomisiPage); ?></div>
</div>
<div class="table-responsive">
  <table class="table table-striped table-hover mb-0">
    <thead>
      <tr>
        <th style="width:60px;">No</th>
        <th>Tanggal</th>
        <th>No. Order</th>
        <th>Pelanggan</th>
        <th>Kasir</th>
        <th>Sales</th>
        <th class="text-center">Persentase</th>
        <th class="text-right">Total Transaksi</th>
        <th class="text-right">Komisi</th>
      </tr>
    </thead>
    <tbody>
      <?php if (!empty($posts)): ?>
        <?php foreach ($posts as $row): ?>
          <tr>
            <td><?= $no++; ?></td>
            <td><?= htmlspecialchars(tgl_indo($row['tgl_trx']), ENT_QUOTES, 'UTF-8'); ?></td>
            <td><?= htmlspecialchars($row['id_transaksi'], ENT_QUOTES, 'UTF-8'); ?></td>
            <td><?= htmlspecialchars($row['nama_pelanggan'], ENT_QUOTES, 'UTF-8'); ?></td>
            <td><?= htmlspecialchars($row['nama_kasir'], ENT_QUOTES, 'UTF-8'); ?></td>
            <td><?= htmlspecialchars($row['nama_sales'], ENT_QUOTES, 'UTF-8'); ?></td>
            <td class="text-center"><?= rtrim(rtrim(number_format((float) $row['komisi_persen'], 2, '.', ''), '0'), '.'); ?>%</td>
            <td class="text-right"><?= rp($row['total_bayar']); ?></td>
            <td class="text-right"><strong><?= rp($row['komisi_nominal']); ?></strong></td>
          </tr>
        <?php endforeach; ?>
      <?php else: ?>
        <tr>
          <td colspan="9" class="text-center">Belum ada data komisi sales.</td>
        </tr>
      <?php endif; ?>
    </tbody>
    <tfoot>
      <tr>
        <th colspan="8" class="text-right">Total Komisi</th>
        <th class="text-right"><?= rp($totalKomisiPage); ?></th>
      </tr>
    </tfoot>
  </table>
</div>

<?php if (isset($this->ajax_pagination) && method_exists($this->ajax_pagination, 'create_links')): ?>
  <div class="mt-3">
    <?= $this->ajax_pagination->create_links(); ?>
  </div>
<?php endif; ?>
