<?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">DEBIT NOTE / PURCHASE RETURN</div>
    <div class="th-sep"></div>

    <div class="th-left th-small">
        Debit Note: <?= htmlspecialchars($pr['return_no']) ?><br>
        Date: <?= date('d-m-Y', strtotime($pr['return_date'])) ?><br>
        PO No: <?= htmlspecialchars($pr['po_no']) ?><br>
        Vendor: <?= htmlspecialchars($pr['vendor_name']) ?>
        <?php if (!empty($pr['reason'])): ?>
        <br>Reason: <?= htmlspecialchars($pr['reason']) ?>
        <?php endif; ?>
    </div>

    <div class="th-center">
        <svg id="barcode" data-invoice="<?= htmlspecialchars($pr['return_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()):
            $totalQty += $row['return_qty'];
        ?>
        <tr>
            <td class="c-item"><?= htmlspecialchars($row['product_name']) ?></td>
            <td class="c-qty"><?= $row['return_qty'] ?></td>
            <td class="c-rate"><?= number_format($row['purchase_price'], 2) ?></td>
            <td class="c-amt"><?= number_format($row['total_amount'], 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($pr['total_amount'], 2) ?></td></tr>
        <tr><td>GST</td><td><?= number_format($pr['gst_amount'], 2) ?></td></tr>
        <tr class="th-grand"><td>NET TOTAL</td><td>&#8377; <?= number_format($pr['net_amount'], 2) ?></td></tr>
    </table>

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

    <div class="th-center th-small">
        Goods returned to vendor.<br>
        Authorised Signatory
    </div>

</div>
