<?php
// Variables available: $company, $inv, $client, $items
$totalQty = 0;
?>

<div class="thermal-invoice">

    <!-- LOGO -->
    <?php if(!empty($company['logo'])): ?>
        <div class="th-center">
            <img src="../<?= $company['logo'] ?>" class="th-logo" style="max-width:90px; max-height:70px; width:auto; height:auto;">
        </div>
    <?php endif; ?>

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

    <hr>

    <div class="th-center th-title">TRANSPORT COPY / DELIVERY CHALLAN</div>

    <hr>

    <!-- DOCUMENT INFO -->
<!-- DOCUMENT INFO -->
<div class="th-left th-small">
    Invoice No: <?= htmlspecialchars($inv['invoice_no']) ?><br>
    Date: <?= date('d-m-Y', strtotime($inv['invoice_date'])) ?><br>
    Customer: <?= htmlspecialchars($client['name']) ?><br>
    Mobile: <?= htmlspecialchars($client['phone'] ?? '') ?><br>
    Driver: <?= htmlspecialchars($inv['driver_name'] ?? '________________') ?><br>
    Vehicle No: <?= htmlspecialchars($inv['vehicle_no'] ?? '________________') ?>
</div>

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

    <hr>

    <!-- ITEM TABLE (NO PRICE) -->
    <table class="th-items" width="100%">
        <thead>
            <tr>
                <th align="left">ITEM</th>
                <th align="left">HSN</th>
                <th align="right">QTY</th>
                <th align="right">UNIT</th>
            </tr>
        </thead>
        <tbody>
        <?php while($row = $items->fetch_assoc()):
            $totalQty += $row['sold_qty'];
        ?>
            <tr>
                <td><?= htmlspecialchars($row['product_name']) ?></td>
                <td><?= htmlspecialchars($row['hsn_code']) ?></td>
                <td align="right"><?= $row['sold_qty'] ?></td>
                <td align="right"><?= htmlspecialchars($row['unit']) ?></td>
            </tr>
        <?php endwhile; ?>
        </tbody>
    </table>

    <hr>

    <div class="th-left th-small">
        Total Quantity: <b><?= $totalQty ?></b>
    </div>

    <br>

    <div class="th-left th-small">
        Receiver Signature: ______________________
    </div>

    <br>

    <div class="th-right th-small">
        For <?= strtoupper($company['company_name']) ?><br><br>
        Authorised Signatory
    </div>

    <hr>

    <div class="th-center th-small">
        Goods received in good condition.
    </div>

</div>
