<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $this->lang->line('sale') . ' ' . $inv->reference_no; ?></title>
    <link href="<?= $assets ?>styles/pdf/pdf_in.css" rel="stylesheet">
</head>
<body>
    <div id="wrap">
        <table width="100%" cellspacing="0" cellpadding="0" border="0" align="center">
                <thead>
                    <tr>
                        <th style="border-bottom:1px solid; font-weight:bolder; font-size:28px;" colspan="3" align="center">
                            CHALLAN
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td style="border-bottom:1px solid;" valign="middle">
                            <table width="100%" cellspacing="0" cellpadding="0">
                                <tbody>
                                    <tr>
                                        <td style="border-right:1px solid;" width="30%">
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <tbody>
                                                    <tr>
                                                        <td align="center">
                                                            <?php if ($logo) {
                                                                $path = base_url() . 'assets/uploads/logos/' . $biller->logo;
                                                                $type = pathinfo($path, PATHINFO_EXTENSION);
                                                                $data = file_get_contents($path);
                                                                $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
                                                                ?>
                                                                <img src="<?= $base64; ?>" alt="<?= $biller->company != '-' ? $biller->company : $biller->name; ?>" height="65">
                                                            <?php }
                                                            ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="center">
                                                            <span style="font-weight:bold;font-size:30px;"><?= $biller->company != '-' ? $biller->company : $biller->name; ?></span>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="center">
                                                            <strong>&nbsp;</strong>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <td style="border-right:1px solid;" width="40%">
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="font-size:16px;font-weight:bolder;" align="center">
                                                            <?= $biller->company ? '' : 'Attn: ' . $biller->name; ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="center">
                                                            <?php
                                                                echo $biller->address . ' ' . $biller->city . ' ' . $biller->postal_code . ' ' . $biller->state . ' ' . $biller->country;
                                                            ?>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                        if ($biller->cf1 != "-" && $biller->cf1 != "") {
                                                            echo '<tr>
                                                                    <td align="center" style="font-size:16px;font-weight:bolder;">'
                                                                        . lang("bcf1") . ": " . $biller->cf1 .
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if ($biller->cf2 != "-" && $biller->cf2 != "") {
                                                            echo '<tr>
                                                                    <td align="center" style="font-size:16px;font-weight:bolder;">'
                                                                        . lang("bcf2") . ": " . $biller->cf2 .
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if ($biller->cf3 != "-" && $biller->cf3 != "") {
                                                            echo '<tr>
                                                                    <td align="center" style="font-size:16px;font-weight:bolder;">'
                                                                        . lang("bcf3") . ": " . $biller->cf3 .
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if ($biller->cf4 != "-" && $biller->cf4 != "") {
                                                            echo '<tr>
                                                                    <td align="center" style="font-size:16px;font-weight:bolder;">'
                                                                        . lang("bcf4") . ": " . $biller->cf4 .
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if ($biller->cf5 != "-" && $biller->cf5 != "") {
                                                            echo '<tr>
                                                                    <td align="center" style="font-size:16px;font-weight:bolder;">'
                                                                        . lang("bcf5") . ": " . $biller->cf5 .
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if ($biller->cf6 != "-" && $biller->cf6 != "") {
                                                            echo '<tr>
                                                                    <td align="center" style="font-size:16px;font-weight:bolder;">'
                                                                        . lang("bcf6") . ": " . $biller->cf6 .
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <tr>
                                                        <td style="font-size:16px;" align="center">
                                                            <strong>
                                                                <?php echo lang('tel') . ': ' . $biller->phone; ?>
                                                            </strong>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td style="font-size:16px;" align="center">
                                                            <strong>
                                                                <?php echo lang('email') . ': ' . $biller->email; ?>
                                                            </strong>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <td width="30%">
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <tbody>
                                                    <tr>
                                                        <td align="center">
                                                            <?= lang('date'); ?>: <?= $this->sma->hrld($inv->date); ?>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td align="center">
                                                            <?= lang('ref'); ?>: <?= $inv->reference_no; ?>
                                                        </td>
                                                    </tr>
                                                    <?php if (!empty($inv->return_sale_ref)) {
                                                        echo '<tr>
                                                                <td align="center">'
                                                                    . lang("return_ref") . ': ' . $inv->return_sale_ref .
                                                                '</td>
                                                            </tr>';
                                                        }
                                                    ?>
                                                    <tr>
                                                        <td align="center">
                                                            <?php
                                                                $path = admin_url('misc/barcode/'.$this->sma->base64url_encode($inv->reference_no).'/code128/74/0/1');
                                                                $type = $Settings->barcode_img ? 'png' : 'svg+xml';
                                                                $data = file_get_contents($path);
                                                                $base64 = 'data:image/' . $type . ';base64,' . base64_encode($data);
                                                            ?>
                                                            <img src="<?= $base64; ?>" alt="<?= $inv->reference_no; ?>" class="bcimg" />
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="border-bottom:1px solid;">
                            <table width="100%" cellspacing="0" cellpadding="0">
                                <tbody>
                                    <tr>
                                        <th style="border-bottom:1px solid; font-size:18px;background-color:#eaeaea;" height="35px">
                                            Customer Detail
                                        </th>
                                        <!-- <th width="50%" style="font-size:18px;background-color:#eaeaea;border-bottom:1px solid;">
                                            Warehouse
                                        </th> -->
                                    </tr>
                                    <tr>
                                        <td>
                                            <table width="100%" cellpadding="0" cellspacing="0">
                                                <tbody>
                                                    <tr>
                                                        <td align="center">
                                                            <?= $customer->company && $customer->company != '-' ? $customer->company : $customer->name; ?>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                        if($customer->company && $customer->company == '-')
                                                        {
                                                            echo '<tr>
                                                                    <td align="center">'
                                                                        . 'Attn: ' . $customer->name .
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <tr>
                                                        <td align="center">
                                                            <?= $customer->address . ' ' . $customer->city . ' ' . $customer->postal_code . ' ' . $customer->state . ' ' . $customer->country ?>
                                                        </td>
                                                    </tr>
                                                    <?php
                                                        if($customer->cf1 != '-' && $customer->cf1 != '')
                                                        {
                                                            echo '<tr>
                                                                    <td align="center">'
                                                                        .lang('ccf1') . ': ' . $customer->cf1.
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if($customer->cf2 != '-' && $customer->cf2 != '')
                                                        {
                                                            echo '<tr>
                                                                    <td align="center">'
                                                                        .lang('ccf2') . ': ' . $customer->cf2.
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if($customer->cf3 != '-' && $customer->cf3 != '')
                                                        {
                                                            echo '<tr>
                                                                    <td align="center">'
                                                                        .lang('ccf3') . ': ' . $customer->cf3.
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if($customer->cf4 != '-' && $customer->cf4 != '')
                                                        {
                                                            echo '<tr>
                                                                    <td align="center">'
                                                                        .lang('ccf4') . ': ' . $customer->cf4.
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if($customer->cf5 != '-' && $customer->cf5 != '')
                                                        {
                                                            echo '<tr>
                                                                    <td align="center">'
                                                                        .lang('ccf5') . ': ' . $customer->cf5.
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <?php
                                                        if($customer->cf6 != '-' && $customer->cf6 != '')
                                                        {
                                                            echo '<tr>
                                                                    <td align="center">'
                                                                        .lang('ccf6') . ': ' . $customer->cf6.
                                                                    '</td>
                                                                </tr>';
                                                        }
                                                    ?>
                                                    <tr>
                                                        <td align="center"><?= lang('tel') . ': ' . $customer->phone ?> <?= lang('email') . ': ' . $customer->email ?></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td style="border-bottom:1px solid;">
                            <?php
                                    $col = $Settings->indian_gst ? 4 : 3;
                                    if ( $Settings->product_discount && $inv->product_discount != 0) {
                                        $col++;
                                    }
                                    if ($Settings->tax1 && $inv->product_tax > 0) {
                                        $col++;
                                    }
                                    if($inv->cgst > 0)
                                    {
                                        $col++;
                                    }
                                    if($inv->sgst > 0)
                                    {
                                        $col++;
                                    }
                                    if($inv->igst > 0)
                                    {
                                        $col++;
                                    }
                                    if ( $Settings->product_discount && $inv->product_discount != 0 && $Settings->tax1 && $inv->product_tax > 0) {
                                        $tcol = $col - 2;
                                    } elseif ( $Settings->product_discount && $inv->product_discount != 0) {
                                        $tcol = $col - 1;
                                    } elseif ($Settings->tax1 && $inv->product_tax > 0) {
                                        $tcol = $col - 1;
                                    } else {
                                        $tcol = $col;
                                    }
                            ?>
                            <table width="100%" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="3%" height="35px">
                                            <?= lang('no'); ?>
                                        </th>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="22%">
                                            <?= lang('description'); ?>
                                        </th>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="7%">
                                            <?= lang('quantity'); ?>
                                        </th>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="8%">
                                            <?= lang('unit_price'); ?>
                                        </th>
                                        <?php if ( $Settings->product_discount && $inv->product_discount != 0) { ?>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="8%">
                                            <?= lang('discount'); ?>
                                        </th>
                                        <?php } ?>
                                        <?php if ($Settings->tax1 && $inv->product_tax > 0) { ?>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="8%">
                                            <?= lang('tax'); ?>
                                        </th>
                                        <?php } ?>
                                        <?php if ($inv->cgst > 0) { ?>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="9%">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <thead>
                                                    <tr>
                                                        <th colspan="2" style="border-bottom:1px solid;">CGST</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;height:18px;" width="30%" align="center">%</td>
                                                        <td width="70%" align="center">Amount</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </th>
                                        <?php } ?>
                                        <?php if ($inv->sgst > 0) { ?>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="9%">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <thead>
                                                    <tr>
                                                        <th colspan="2" style="border-bottom:1px solid;">SGST</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;height:18px;" width="30%" align="center">%</td>
                                                        <td width="70%" align="center">Amount</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </th>
                                        <?php } ?>
                                        <?php if ($inv->igst > 0) { ?>
                                        <th style="border-bottom:1px solid;border-right:1px solid;" width="9%">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <thead>
                                                    <tr>
                                                        <th colspan="2" style="border-bottom:1px solid;">IGST</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;height:18px;" width="30%" align="center">%</td>
                                                        <td width="70%" align="center">Amount</td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </th>
                                        <?php } ?>
                                        <th style="border-bottom:1px solid;" width="10%">
                                            <?= lang('Subtotal'); ?>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php 
                                        $r = 1;
                                        $qty = 0;
                                        foreach ($rows as $row):
                                    ?>
                                    <tr>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center" height="35px">
                                            <?= $r; ?>
                                        </td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-left:3px;font-size:13px;" align="left">
                                            <?= $row->product_code.' - '.$row->product_name . ($row->variant ? ' (' . $row->variant . ')' : ''); ?>
                                            <?= $row->second_name ? '<br>' . $row->second_name : ''; ?>
                                            <?= $row->details ? '<br>' . $row->details : ''; ?>
                                            <?= $row->serial_no ? '<br>' . $row->serial_no : ''; ?>
                                        </td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <?= $this->sma->formatQuantity($row->unit_quantity).' '.$row->product_unit_code; ?>
                                        </td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;font-size:13px;" align="right">
                                            <?= $this->sma->formatMoney($row->unit_price); ?>
                                        </td>
                                        <?php if ( $Settings->product_discount && $inv->product_discount != 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;font-size:13px;" align="right">
                                            <?= $row->discount != 0 ? ("<small>(" . $row->discount . ")</small> " . $this->sma->formatMoney($row->item_discount)) : 0; ?>
                                        </td>
                                        <?php } ?>
                                        <?php if ($Settings->tax1 && $inv->product_tax > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;font-size:13px;" align="right">
                                            <?= $row->item_tax != 0 ? ("<small>(" . ($Settings->indian_gst ? $row->tax : $row->tax_code) . ")</small> " . $this->sma->formatMoney($row->item_tax)) : 0; ?>
                                        </td>
                                        <?php } ?>
                                        <?php if ($Settings->tax1 && $inv->product_tax > 0) { ?>
                                            <?php if ($inv->cgst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"><?= ($row->cgst > 0 ? str_replace("%","",$row->gst) : "0") ?></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"><?= ($row->cgst > 0 ? $this->sma->formatMoney($row->cgst) : "0") ?></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->sgst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"><?= ($row->sgst > 0 ? str_replace("%","",$row->gst) : "0") ?></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"><?= ($row->sgst > 0 ? $this->sma->formatMoney($row->sgst) : "0") ?></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->igst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"><?= ($row->igst > 0 ? str_replace("%","",$row->gst) : "0") ?></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"><?= ($row->igst > 0 ? $this->sma->formatMoney($row->igst) : "0") ?></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php } ?>
                                        <td style="border-bottom:1px solid #ddd;padding-right:3px;font-size:13px;" align="right">
                                            <?= $this->sma->formatMoney($row->subtotal); ?>
                                        </td>
                                    </tr>
                                    <?php
                                        $qty += $this->sma->formatQuantity($row->unit_quantity);
                                        $r++;
                                        endforeach;
                                        if ($return_rows) {
                                            echo '<tr class="warning"><td colspan="'.($col+1).'" class="no-border"><strong>'.lang('returned_items').'</strong></td></tr>';
                                            foreach ($return_rows as $row):
                                    ?>
                                    <tr class="warning">
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center" height="35px">
                                            <?= $r; ?>
                                        </td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-left:3px;font-size:13px;" align="left">
                                            <?= $row->product_code.' - '.$row->product_name . ($row->variant ? ' (' . $row->variant . ')' : ''); ?>
                                            <?= $row->second_name ? '<br>' . $row->second_name : ''; ?>
                                            <?= $row->details ? '<br>' . $row->details : ''; ?>
                                            <?= $row->serial_no ? '<br>' . $row->serial_no : ''; ?>
                                        </td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <?= $this->sma->formatQuantity($row->unit_quantity).' '.$row->product_unit_code; ?>
                                        </td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;font-size:13px;" align="right">
                                            <?= $this->sma->formatMoney($row->unit_price); ?>
                                        </td>
                                        <?php if ( $Settings->product_discount && $inv->product_discount != 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;font-size:13px;" align="right">
                                            <?= $row->discount != 0 ? ("<small>(" . $row->discount . ")</small> " . $this->sma->formatMoney($row->item_discount)) : 0; ?>
                                        </td>
                                        <?php } ?>
                                        <?php if ($Settings->tax1 && $inv->product_tax > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;font-size:13px;" align="right">
                                            <?= $row->item_tax != 0 ? ("<small>(" . ($Settings->indian_gst ? $row->tax : $row->tax_code) . ")</small> " . $this->sma->formatMoney($row->item_tax)) : 0; ?>
                                        </td>
                                        <?php } ?>
                                        <?php if ($Settings->tax1 && $inv->product_tax > 0) { ?>
                                            <?php if ($inv->cgst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"><?= ($row->cgst > 0 ? str_replace("%","",$row->gst) : "0") ?></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"><?= ($row->cgst > 0 ? $this->sma->formatMoney($row->cgst) : "0") ?></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->sgst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"><?= ($row->sgst > 0 ? str_replace("%","",$row->gst) : "0") ?></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"><?= ($row->sgst > 0 ? $this->sma->formatMoney($row->sgst) : "0") ?></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->igst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;font-size:13px;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"><?= ($row->igst > 0 ? str_replace("%","",$row->gst) : "0") ?></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"><?= ($row->igst > 0 ? $this->sma->formatMoney($row->igst) : "0") ?></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php } ?>
                                        <td style="border-bottom:1px solid #ddd;padding-right:3px;font-size:13px;" align="right">
                                            <?= $this->sma->formatMoney($row->subtotal); ?>
                                        </td>
                                    </tr>
                                    <?php
                                                $r++;
                                            endforeach;
                                        }
                                    ?>
                                    <?php 
                                        while($r <= 19) {
                                    ?>
                                    <tr>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;" align="center" height="35px"></td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-left:3px;" align="left"></td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;" align="center"></td>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;" align="right"></td>
                                        <?php if ( $Settings->product_discount && $inv->product_discount != 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;" align="right"></td>
                                        <?php } ?>
                                        <?php if ($Settings->tax1 && $inv->product_tax > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;padding-right:3px;" align="right"></td>
                                        <?php } ?>
                                        <?php if ($inv->cgst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->sgst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->igst > 0) { ?>
                                        <td style="border-bottom:1px solid #ddd;border-right:1px solid;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="border-right:1px solid;" width="30%" height="35px" align="center"></td>
                                                        <td style="padding-right:3px;" width="70%" align="right"></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <td style="border-bottom:1px solid #ddd;padding-right:3px;" align="right"></td>
                                    </tr>
                                    <?php 
                                        $r++;
                                        }
                                    ?>
                                
                                <!-- <tfoot> -->
                                    <tr style="background-color:#eaeaea;">
                                        <td style="border-bottom:1px solid;border-right:1px solid;" align="center" height="35px">
                                        </td>
                                        <td style="border-bottom:1px solid;border-right:1px solid;padding-right:3px;" align="right">
                                            <?= lang('total'); ?>
                                        </td>
                                        <td style="border-bottom:1px solid;border-right:1px solid;" align="center">
                                            <?= $this->sma->formatQuantity($qty); ?>
                                        </td>
                                        <td style="border-bottom:1px solid;border-right:1px solid;padding-right:3px;" align="right">
                                            &nbsp;
                                        </td>
                                        <?php if ( $Settings->product_discount && $inv->product_discount != 0) { ?>
                                        <td style="border-bottom:1px solid;border-right:1px solid;padding-right:3px;" align="right">
                                            <?= $this->sma->formatMoney($return_sale ? ($inv->product_discount+$return_sale->product_discount) : $inv->product_discount); ?>
                                        </td>
                                        <?php } ?>
                                        <?php if ($Settings->tax1 && $inv->product_tax > 0) { ?>
                                        <td style="border-bottom:1px solid;border-right:1px solid;padding-right:3px;" align="right">
                                            <?= $this->sma->formatMoney($return_sale ? ($inv->product_tax+$return_sale->product_tax) : $inv->product_tax); ?>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->cgst > 0) { ?>
                                        <td style="border-bottom:1px solid;border-right:1px solid;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="padding-right:3px;" align="right">
                                                            
                                                                <?php $cgst = $return_sale ? $inv->cgst + $return_sale->cgst : $inv->cgst; ?>
                                                                <?= ($Settings->format_gst ? $this->sma->formatMoney($cgst) : $cgst); ?>
                                                            
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->sgst > 0) { ?>
                                        <td style="border-bottom:1px solid;border-right:1px solid;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="padding-right:3px;" align="right">
                                                            
                                                                <?php $sgst = $return_sale ? $inv->sgst + $return_sale->sgst : $inv->sgst; ?>
                                                                <?= ($Settings->format_gst ? $this->sma->formatMoney($sgst) : $sgst); ?>
                                                            
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <?php if ($inv->igst > 0) { ?>
                                        <td style="border-bottom:1px solid;border-right:1px solid;" align="center">
                                            <table width="100%" cellspacing="0" cellpadding="0">
                                                <tbody>
                                                    <tr>
                                                        <td style="padding-right:3px;" align="right">
                                                            
                                                                <?php $igst = $return_sale ? $inv->igst + $return_sale->igst : $inv->igst; ?>
                                                                <?= ($Settings->format_gst ? $this->sma->formatMoney($igst) : $igst); ?>
                                                            
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </td>
                                        <?php } ?>
                                        <td style="border-bottom:1px solid;padding-right:3px;" align="right">
                                            <?= $this->sma->formatMoney($return_sale ? (($inv->total + $inv->product_tax)+($return_sale->total + $return_sale->product_tax)) : ($inv->total + $inv->product_tax)); ?>
                                        </td>
                                    </tr>
                                    <?php if ($inv->grand_total != $inv->total) { ?>
                                        <!-- <tr>
                                            <td colspan="10" align="right" style="border-right:1px solid;border-bottom:1px solid;padding-right:3px;" height="30px">
                                                <?= lang('total'); ?> (<?= $default_currency->code; ?>)
                                            </td>
                                            <td align="right" style="border-bottom:1px solid;padding-right:3px;">
                                                <?= $this->sma->formatMoney($return_sale ? (($inv->total + $inv->product_tax)+($return_sale->total + $return_sale->product_tax)) : ($inv->total + $inv->product_tax)); ?>
                                            </td>
                                        </tr> -->
                                    <?php } ?>
                                    <?php if ($return_sale) { ?>
                                        <tr>
                                            <td colspan="<?= $col ?>" align="right" height="35px" style="border-right:1px solid;border-bottom:1px solid;padding-right:3px;">
                                                <?= lang('return_total'); ?> (<?= $default_currency->code; ?>)
                                            </td>
                                            <td align="right" style="border-bottom:1px solid;padding-right:3px;">
                                                <?= $this->sma->formatMoney($return_sale->grand_total); ?>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    <?php if ($inv->surcharge != 0) { ?>
                                        <tr>
                                        <td colspan="<?= $col ?>" align="right" height="35px" style="border-right:1px solid;border-bottom:1px solid;padding-right:3px;">
                                                <?= lang('return_surcharge'); ?> (<?= $default_currency->code; ?>)
                                            </td>
                                            <td align="right" style="border-bottom:1px solid;padding-right:3px;">
                                                <?= $this->sma->formatMoney($inv->surcharge); ?>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    <?php if ($inv->shipping != 0) { ?>
                                        <tr>
                                        <td colspan="<?= $col ?>" align="right" height="35px" style="border-right:1px solid;border-bottom:1px solid;padding-right:3px;">
                                                <?= lang('shipping'); ?> (<?= $default_currency->code; ?>)
                                            </td>
                                            <td align="right" style="border-bottom:1px solid;padding-right:3px;">
                                                <?= $this->sma->formatMoney($inv->shipping); ?>
                                            </td>
                                        </tr>
                                    <?php } ?>
                                    <tr>
                                    <td colspan="<?= $col ?>" align="right" height="35px" style="border-right:1px solid;border-bottom:1px solid;padding-right:3px;">
                                            <?= lang('total_amount'); ?> (<?= $default_currency->code; ?>)
                                        </td>
                                        <td align="right" style="border-bottom:1px solid;padding-right:3px;">
                                            <?= $this->sma->formatMoney($return_sale ? ($inv->grand_total+$return_sale->grand_total) : $inv->grand_total); ?>
                                        </td>
                                    </tr>
                                    <tr>
                                    <td colspan="<?= $col ?>" align="right" height="35px" style="border-right:1px solid;border-bottom:1px solid;padding-right:3px;">
                                            <?= lang('paid'); ?> (<?= $default_currency->code; ?>)
                                        </td>
                                        <td align="right" style="border-bottom:1px solid;padding-right:3px;">
                                            <?= $this->sma->formatMoney($return_sale ? ($inv->paid+$return_sale->paid) : $inv->paid); ?>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="<?= $col ?>" align="right" height="35px" style="border-right:1px solid;padding-right:3px;">
                                            <?= lang('balance'); ?> (<?= $default_currency->code; ?>)
                                        </td>
                                        <td align="right" style="padding-right:3px;">
                                            <?= $this->sma->formatMoney(($return_sale ? ($inv->grand_total+$return_sale->grand_total) : $inv->grand_total) - ($return_sale ? ($inv->paid+$return_sale->paid) : $inv->paid)); ?>
                                        </td>
                                    </tr>
                                <!-- </tfoot> -->
                                </tbody>
                            </table>             
                        </td>
                </tr>
                <tr>
                    <td>
                        <table width="100%" cellspacing="0" cellpadding="0">
                            <tbody>
                                <tr>
                                    <td style="border-right:1px solid;" width="50%">
                                        <table width="100%" cellspacing="0" cellpadding="0">
                                            <thead>
                                                <tr>
                                                    <th>
                                                        <?= lang('seller'); ?> : <?= $biller->company != '-' ? $biller->company : $biller->name; ?>
                                                    </th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td height="130px">
                                                        &nbsp;
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="center">
                                                        <?= lang('stamp_sign'); ?>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                    <td width="50%">
                                        <table width="100%" cellspacing="0" cellpadding="0">
                                            <thead>
                                                <tr>
                                                    <th>
                                                        <?= lang('customer'); ?>: <?= $customer->company && $customer->company != '-' ? $customer->company : $customer->name; ?>
                                                    </th>
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <tr>
                                                    <td height="130px">
                                                        &nbsp;
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="center">
                                                        <?= lang('stamp_sign'); ?>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </body>
</html>