<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Invoice #<?= $invoice_id ?></title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css">
    <style>
        @media print { .no-print { display: none; } }
        body { font-family: monospace; }
    </style>
</head>
<body>
<div class="container mt-4">
     <!-- ================= WELCOME MESSAGE ================= -->
    <div class="welcome-msg">
        <i class="fa fa-user-circle"></i> Welcome, <strong><?= htmlspecialchars($username) ?></strong>!
    </div>
    <div class="d-flex justify-content-between">
        <h3>Invoice #<?= $invoice_id ?></h3>
        <button class="btn btn-primary no-print" onclick="window.print()">Print</button>
    </div>
    <p><strong>Tab:</strong> <?= htmlspecialchars($tab['tab_no']) ?> | 
       <strong>Bartender:</strong> <?= htmlspecialchars($tab['waiter']) ?></p>
    <p><strong>Guest / Customer:</strong> <?= htmlspecialchars($person) ?></p>
    <p><strong>Date:</strong> <?= date("d-M-Y H:i") ?></p>
    <hr>

    <h5>Items</h5>
    <table class="table table-bordered">
        <thead class="bg-dark text-white">
            <tr><th>#</th><th>SKU</th><th>Item</th><th>Price</th><th>Qty</th><th>VAT</th><th>Total</th></tr>
        </thead>
        <tbody>
            <?php
            if(count($tab_items)==0){
                echo "<tr><td colspan='7' class='text-center'>No items</td></tr>";
            } else {
                $i=1;
                foreach($tab_items as $item){
                    $price = number_format($item['price'],2);
                    $qty = $item['qty'];
                    $vat = number_format($item['vat'],2);
                    $total = number_format(($item['price']*$item['qty'])+$item['vat'],2);
                    $sku = $item['sku'] ?? '';
                    $name = $item['name'];
                    echo "<tr>
                    <td>$i</td>
                    <td>$sku</td>
                    <td>$name</td>
                    <td>$price</td>
                    <td>$qty</td>
                    <td>$vat</td>
                    <td>$total</td>
                    </tr>";
                    $i++;
                }
            }
            ?>
        </tbody>
        <tfoot>
            <tr><th colspan="5" class="text-end">Subtotal:</th><th colspan="2">MK <?= number_format($total_sub,2) ?></th></tr>
            <tr><th colspan="5" class="text-end">VAT:</th><th colspan="2">MK <?= number_format($total_vat,2) ?></th></tr>
            <tr><th colspan="5" class="text-end">Grand Total:</th><th colspan="2">MK <?= number_format($grand_total,2) ?></th></tr>
            <tr><th colspan="5" class="text-end">Payments Made:</th><th colspan="2">MK <?= number_format($total_paid,2) ?></th></tr>
            <tr><th colspan="5" class="text-end">Balance:</th><th colspan="2">MK <?= number_format($grand_total - $total_paid,2) ?></th></tr>
        </tfoot>
    </table>

    <p class="mt-4">Thank you for your business!</p>
</div>
</body>
</html>
