<?php
require_once __DIR__ . '/../app/bootstrap.php';
use App\Core\PosService; use App\Core\Database;
PosService::requireAccess();
$vendorId = PosService::currentVendorId();
$register = PosService::defaultRegister($vendorId);
$shift = $register ? PosService::currentShift((int)$register['id'], (int)(current_user()['id'] ?? 0)) : null;
$held = Database::fetchAll('SELECT * FROM pos_held_sales WHERE vendor_id=? AND status="held" ORDER BY id DESC LIMIT 50', [$vendorId]);
$pageTitle = 'Held Sales | Pro POS';
require_once __DIR__ . '/partials/header.php';
?>
<div class="card pos-card"><div class="card-header bg-white d-flex justify-content-between"><strong>Held Sales</strong><a class="btn btn-sm btn-primary" href="<?= url('pos/register.php') ?>">New Sale</a></div><div class="table-responsive"><table class="table align-middle mb-0"><thead><tr><th>Hold No</th><th>Customer</th><th>Items</th><th>Total</th><th>Held By</th><th>Date</th><th></th></tr></thead><tbody><?php if(!$held): ?><?= table_empty(7,'No held sales.') ?><?php else: foreach($held as $row): $items=json_decode($row['cart_json'] ?? '[]', true) ?: []; ?><tr><td><strong><?= e($row['hold_no']) ?></strong></td><td><?= e($row['customer_name'] ?: 'Walk-in') ?></td><td><?= count($items) ?></td><td><?= money($row['total_amount'] ?? 0) ?></td><td>#<?= e($row['cashier_id']) ?></td><td><?= e($row['created_at']) ?></td><td><button class="btn btn-sm btn-outline-primary" data-load-held="<?= (int)$row['id'] ?>">Load</button> <button class="btn btn-sm btn-outline-danger" data-delete-held="<?= (int)$row['id'] ?>">Delete</button></td></tr><?php endforeach; endif; ?></tbody></table></div></div>
<?php require_once __DIR__ . '/partials/footer.php'; ?>
