<?php $totalQty = 0; ?>

<div class="thermal-invoice">

    <?php if (!empty($company['logo'])): ?>
    <div class="th-center">
        <img src="../<?= $company['logo'] ?>" class="th-logo">
    </div>
    <?php endif; ?>

    <div class="th-center th-company"><?= strtoupper(htmlspecialchars($company['company_name'])) ?></div>
    <div class="th-center th-small">
        <?= nl2br(htmlspecialchars($company['address'])) ?><br>
        Ph: <?= htmlspecialchars($company['phone']) ?>
    </div>

    <div class="th-sep"></div>
    <div class="th-center th-title">PURCHASE ORDER</div>
    <div class="th-sep"></div>

    <div class="th-left th-small">
        PO No: <?= htmlspecialchars($po['po_no']) ?><br>
        Date: <?= date('d-m-Y', strtotime($po['purchase_date'])) ?><br>
        Vendor: <?= htmlspecialchars($po['vendor_name']) ?>
        <?php if (!empty($po['supplier_invoice_no'])): ?>
        <br>Sup. Inv: <?= htmlspecialchars($po['supplier_invoice_no']) ?>
        <?php endif; ?>
    </div>

    <div class="th-center">
        <svg id="barcode" data-invoice="<?= htmlspecialchars($po['po_no']) ?>"></svg>
    </div>

    <div class="th-sep"></div>

    <table class="th-items" width="100%">
        <thead>
            <tr>
                <th class="c-item">ITEM</th>
                <th class="c-qty">QTY</th>
                <th class="c-rate">PRICE</th>
                <th class="c-amt">AMT</th>
            </tr>
        </thead>
        <tbody>
        <?php while ($row = $items->fetch_assoc()):
            $taxable = $row['purchase_price'] * $row['quantity'];
            $total   = $taxable * (1 + $row['gst_percent'] / 100);
            $totalQty += $row['quantity'];
        ?>
        <tr>
            <td class="c-item"><?= htmlspecialchars($row['product_name']) ?>
                <div style="font-size:9px;color:#555;"><?= htmlspecialchars($row['batch_no']) ?></div>
            </td>
            <td class="c-qty"><?= $row['quantity'] ?></td>
            <td class="c-rate"><?= number_format($row['purchase_price'], 2) ?></td>
            <td class="c-amt"><?= number_format($total, 2) ?></td>
        </tr>
        <?php endwhile; ?>
        </tbody>
    </table>

    <div class="th-sep"></div>

    <table class="th-totals">
        <tr><td>Total Qty</td><td><?= $totalQty ?></td></tr>
        <tr><td>Taxable</td><td><?= number_format($po['total_amount'], 2) ?></td></tr>
        <tr><td>GST</td><td><?= number_format($po['gst_amount'], 2) ?></td></tr>
        <tr class="th-grand"><td>NET TOTAL</td><td>&#8377; <?= number_format($po['net_amount'], 2) ?></td></tr>
    </table>

    <div class="th-sep"></div>

    <div class="th-center th-small">
        Computer Generated PO<br>
        Authorised Signatory
    </div>

</div>
