<?= $this->extend('frontend/layout/default') ?>
<?= $this->section('content') ?>

<section class="content-header">
  <div class="container-fluid">
    <div class="row mb-2">
      <div class="col-sm-6">
        <h1>Orders</h1>
      </div>
      <div class="col-sm-6 text-right">
        <a class="btn btn-primary btn-sm" href="<?php echo url('shopkeeper/orders/add') ?>"><i class="fa fa-plus pr-1"></i> New Order</a>
      </div>
    </div>
  </div>
</section>

<section class="content">
  <div class="container-fluid">
    <?php if (!$shopId): ?>
      <div class="alert alert-danger">No shop assigned. Ask admin to assign a shop.</div>
    <?php endif ?>

    <div class="card">
      <div class="card-body">
        <table id="example1" class="table table-bordered table-striped">
          <thead>
            <tr>
              <th width="70">Order #</th>
              <th>Customer</th>
              <th width="120">Subtotal</th>
              <th width="120">Discount</th>
              <th width="120">Total</th>
              <th width="120">Points</th>
              <th width="170">Created</th>
              <th width="90">Action</th>
            </tr>
          </thead>
          <tbody>
            <?php foreach ($orders as $o): ?>
              <tr>
                <td><?php echo $o->id ?></td>
                <td><?php echo esc($o->customer_name) ?></td>
                <td><?php echo esc($o->subtotal) ?></td>
                <td><?php echo esc($o->discount_total) ?></td>
                <td><?php echo esc($o->total) ?></td>
                <td><?php echo esc($o->points_earned) ?></td>
                <td><?php echo esc($o->created_at) ?></td>
                <td>
                  <a class="btn btn-sm btn-default" href="<?php echo url('shopkeeper/orders/view/'.$o->id) ?>"><i class="fas fa-eye"></i></a>
                </td>
              </tr>
            <?php endforeach ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>
</section>

<?= $this->endSection() ?>

