<?= $this->extend('layouts/owner') ?>
<?= $this->section('content') ?>
<div class="container-fluid">
  <div class="d-flex justify-content-between align-items-center mb-3"><h3><i class="fas fa-shopping-cart"></i> Order dari Admin</h3><small class="text-muted">Data diperbarui dari transaksi admin</small></div>
  <?php if (session()->getFlashdata('success')): ?><div class="alert alert-success"><?= esc(session()->getFlashdata('success')) ?></div><?php endif ?>
  <div class="card shadow"><div class="card-body table-responsive"><table class="table table-bordered align-middle"><thead class="table-dark"><tr><th>No. Order</th><th>Customer</th><th>Tanggal / Target</th><th>Total</th><th>Pembayaran</th><th>Status Produksi</th><th>Aksi</th></tr></thead><tbody>
  <?php foreach ($orders as $row): ?><tr>
    <td><?= esc($row['order_number']) ?></td><td><?= esc($row['customer_name']) ?></td><td><?= esc($row['created_at']) ?><br><small><?= esc($row['target_date'] ?: '-') ?></small></td>
    <td>Rp <?= number_format($row['total'], 0, ',', '.') ?></td><td><span class="badge bg-<?= $row['payment_status'] === 'paid' ? 'success' : ($row['payment_status'] === 'partial' ? 'warning' : 'secondary') ?>"><?= esc(strtoupper($row['payment_status'])) ?></span></td>
    <td><span class="badge bg-info"><?= esc(strtoupper($row['production_status'] ?: 'antrian')) ?></span></td><td><a class="btn btn-sm btn-info" href="<?= site_url('owner/order/detail/'.$row['id_order']) ?>">Detail</a><?php if ($row['order_type'] === 'po'): ?> <a class="btn btn-sm btn-primary" href="<?= site_url('owner/order/process/'.$row['id_order']) ?>">Proses</a> <a class="btn btn-sm btn-success" href="<?= site_url('owner/order/finish/'.$row['id_order']) ?>">Selesai</a><?php endif ?></td>
  </tr><?php endforeach ?>
  <?php if (empty($orders)): ?><tr><td colspan="7" class="text-center text-muted">Belum ada order dari admin.</td></tr><?php endif ?>
  </tbody></table></div></div>
</div>
<?= $this->endSection() ?>
