<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?>

<style>
    .customer_details_table .table > tbody > tr > td, .customer_details_table .table > tbody > tr > th{
        padding: 5px !important;
        line-height: 1 !important;
        font-size: 12px !important;
        border-top: 1px solid #ccc !important;
    }
    .order_barcodes img{
        width: 100%;
    }
    @media print{
         .modal-content{
          width: 100%;
      }
        .modal-content {
            -webkit-print-color-adjust: exact !important;
        }
        .customer_details_table .table > tbody > tr > td, .customer_details_table .table > tbody > tr > th{
            padding: 5px !important;
            line-height: 1 !important;
            font-size: 12px !important;
            border-top: 1px solid #ccc !important;
            -webkit-print-color-adjust: exact !important;
            border: 1px solid #ddd !important;
        }
        .row {
            margin-right: -15px;
            margin-left: -15px;
            display: block;
        }
        .top_section .col-md-5{
            width: 41.66666667%;
        }
        .top_section .col-md-2{
            width:16.66666667%;
        }
        .top_section .col-md-5, .top_section .col-md-2{
            float: left;
        }
        .table-striped>tbody>tr:nth-child(odd)>td, .table-striped>tbody>tr:nth-child(odd)>th {
            background-color: #f9f9f9 !important;
            -webkit-print-color-adjust: exact !important;
        }
        .main_details_table .table>thead>tr>th, .main_details_table .table>tbody>tr>th, .main_details_table .table>tfoot>tr>th, .main_details_table .table>thead>tr>td, .main_details_table .table>tbody>tr>td, .main_details_table .table>tfoot>tr>td {
            padding: 5px;
            line-height: 1.42857143;
            vertical-align: top;
            border-top: 1px solid #ccc !important;
            -webkit-print-color-adjust: exact !important;
        }
        .main_details_table .table-bordered>thead>tr>th, .main_details_table .table-bordered>tbody>tr>th, .main_details_table .table-bordered>tfoot>tr>th, .main_details_table .table-bordered>thead>tr>td, .main_details_table .table-bordered>tbody>tr>td, .main_details_table .table-bordered>tfoot>tr>td {
            border: 1px solid #ddd !important;
            -webkit-print-color-adjust: exact !important;
        }
        .main_details_table .table > thead:first-child > tr:first-child > th, .main_details_table .table > thead:first-child > tr:first-child > td, .main_details_table .table-striped thead tr.primary:nth-child(odd) th {
            background-color: #428BCA !important;
            color: white !important;
            border-color: #357EBD !important;
            border-top: 1px solid #357EBD !important;
            text-align: left;
            font-size: 12px;
            -webkit-print-color-adjust: exact !important;
        }
        .arabic_text{
            margin-top: 12px;
        }
        * { overflow: visible !important; } 
        page { page-break-after:always; }
    }
</style>


<div class="modal-dialog modal-lg no-modal-header">
    <div class="modal-content">
        <div class="modal-body">
            <div class="row">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <i class="fa fa-2x">&times;</i>
                </button>
                <button type="button" class="btn btn-xs btn-default no-print pull-right" style="margin-right:15px;" onclick="window.print();">
                    <i class="fa fa-print"></i> <?= lang('print'); ?>
                </button>
            </div>
            <div class="row top_section">
                <div class="col-md-5 text-left">
                    <h2 style="margin-top:10px;"><?= $biller->company != '-' ? $biller->company : $biller->name; ?></h2>
                    <?= $biller->company ? "" : "Attn: " . $biller->name ?>

                    <?php
                    echo $biller->address . "<br>" . $biller->city . " " . $biller->postal_code . " " . $biller->state . "<br>" . $biller->country;

                    echo lang("tel") . ": " . $biller->phone;
                    ?>
                    </div>
                    
                    <div class="col-md-2">
                        <div class="order_barcodes">
                     <?php 
                     $seller_name = $biller->company;
                    // $seller_name = bin2hex($seller_name);
                     $name = strlen($biller->company);
                     $tag_name ='01';
                     $length_name =$name;
                     $first_tag = $tag_name.''.$name;
                     $first_tag_hex = $this->sma->dec2hex($length_name);
                     if(strlen($first_tag_hex) == '1'){
                         $first_tag_hex ='0'.''.$first_tag_hex;
                     }
                     else{
                         $first_tag_hex = $first_tag_hex;
                     }
                     
                     //$first_tag_hex_to_string = hex2bin($first_tag_hex);
                     $seller_name = $this->sma->hex2str($tag_name).''.$this->sma->hex2str($first_tag_hex).''.$seller_name;
                     //$this->sma->hex2str($content)
                     $seller_vat = $biller->vat_no;
                    // $seller_vat = bin2hex($seller_vat);
                     $vat = strlen($seller_vat);
                     $tag_vat ='02';
                     $length_vat =$vat;
                     $second_tag = $tag_vat.''.$vat;
                     $second_tag_hex =  $this->sma->dec2hex($length_vat);
                     if(strlen($second_tag_hex) == '1'){
                         $second_tag_hex ='0'.''.$second_tag_hex;
                     }
                     else{
                         $second_tag_hex = $second_tag_hex;
                     }
                    // $second_tag_hex_to_string = hex2bin($second_tag_hex);
                    
                     $seller_vat = $this->sma->hex2str($tag_vat).''.$this->sma->hex2str($second_tag_hex).''.$seller_vat;
                   
                     $seller_date = $inv->date;
                     //$seller_date = bin2hex($seller_date);
                     $date = strlen($inv->date);
                     $tag_date ='03';
                     $length_date =$date;
                     $third_tag = $tag_date.''.$date;
                     $third_tag_hex = $this->sma->dec2hex($length_date);
                     if(strlen($third_tag_hex) == '1'){
                         $third_tag_hex ='0'.''.$third_tag_hex;
                     }
                     else{
                         $third_tag_hex = $third_tag_hex;
                     }
                    // $third_tag_hex_to_string = hex2bin($third_tag_hex);
                     $seller_date = $this->sma->hex2str($tag_date).''.$this->sma->hex2str($third_tag_hex).''.$seller_date;
                       
                     $seller_invoice_total = $this->sma->formatQuantity($inv->grand_total);
                    // $seller_invoice_total =bin2hex($seller_invoice_total);
                     $grand = strlen($this->sma->formatQuantity($inv->grand_total));
                     $tag_grand ='04';
                     $length_tot =$grand;
                     $fourth_tag = $tag_grand.''.$grand;
                     $fourth_tag_hex = $this->sma->dec2hex($length_tot);
                     if(strlen($fourth_tag_hex) == '1'){
                         $fourth_tag_hex ='0'.''.$fourth_tag_hex;
                     }
                     else{
                         $fourth_tag_hex = $fourth_tag_hex;
                     }
                     //$fourth_tag_hex_to_string = hex2bin($fourth_tag_hex);
                     $seller_invoice_total =$this->sma->hex2str($tag_grand).''.$this->sma->hex2str($fourth_tag_hex).''.$seller_invoice_total;
                    //$vat_values = $this->sma->formatMoney($return_sale ? ($inv->product_tax+$return_sale->product_tax) : $inv->product_tax);
                     //$vat_values ='15';
                     $vats=0;
                     foreach ($rows as $vat){
                      $vats+=  $vat->item_tax ;
                     }
                     $vat_values =$vats;
                     $seller_vat_value = $this->sma->formatQuantity($vat_values);
                     // $seller_vat_value =  bin2hex($seller_vat_value); 
                     $vat_value = strlen($this->sma->formatQuantity($vat_values));
                     $tag_vat_value ='05';
                     $length_vat =$vat_value;
                     $fifth_tag = $tag_vat_value.''.$vat_value; 
                     $fifth_tag_hex = $this->sma->dec2hex($length_vat);
                     if(strlen($fifth_tag_hex) == '1'){
                         $fifth_tag_hex ='0'.''.$fifth_tag_hex;
                     }
                     else{
                         $fifth_tag_hex = $fifth_tag_hex;
                     }
                    // $fifth_tag_hex_to_string = hex2bin($fifth_tag_hex);
                     $seller_vat_value = $this->sma->hex2str($tag_vat_value).''.$this->sma->hex2str($fifth_tag_hex).''.$seller_vat_value;
                    //print_r($seller_vat_value);
                     
                     $content = $seller_name.''.$seller_vat.''.$seller_date.''.$seller_invoice_total.''.$seller_vat_value;
                     
                      ?>
                                  <br>
                              <?php  //$bin =$this->sma->hex2str($content);
                    $b64 = base64_encode($content); //print_r($content);
                    
                    ?>
                       <?= $this->sma->new_qrcode('link',$b64, 256); ?>
                                        
                         </div>
                    <div class="clearfix"></div>
                </div>
                    
                <div class="col-md-5 text-right arabic_text">
                    <?php
                    

                    echo "<p>";

                   
                    if ($biller->cf1 != "-" && $biller->cf1 != "") {
                        echo "<b>" . $biller->cf1 . "</b>" . "<br>";
                    }
                    if ($biller->cf2 != "-" && $biller->cf2 != "") {
                        echo "" . $biller->cf2 . "<br>";
                    }
                    if ($biller->cf3 != "-" && $biller->cf3 != "") {
                        echo "" . $biller->cf3;
                    }
                    if ($biller->cf4 != "-" && $biller->cf4 != "") {
                        echo "," . $biller->cf4;
                    }
                    if ($biller->cf5 != "-" && $biller->cf5 != "") {
                        echo "," . $biller->cf5;
                    }
                    if ($biller->cf6 != "-" && $biller->cf6 != "") {
                        echo "," . $biller->cf6;
                    }
                     if ($biller->vat_no != "-" && $biller->vat_no != "") {
                        echo "<br>" . $biller->vat_no;
                    }

                    echo "</p>";
                    ?>
                </div>
            </div>
                <!--<div class="row bold">
                    
                    <div class="col-xs-7 text-right order_barcodes">
                       <!-- <img src="<?= admin_url('misc/barcode/'.$this->sma->base64url_encode($inv->reference_no).'/code128/74/0/1'); ?>" alt="<?= $inv->reference_no; ?>" class="bcimg" />
                        <?= $this->sma->qrcode('link', urlencode(admin_url('sales/view/' . $inv->id)), 2); ?>
                    </div>
                    <div class="clearfix"></div>
                </div>-->
            <div class="clearfix"></div>
            
            <div class="row">
                <div class="col-md-12 text-center">
                    <h2 style="font-size: 20px;">TAX INVOICE / فاتورة ضريبية   </h2>
                </div>
            </div>
            
            <div class="row customer_details_table">
                <div class="col-md-12">
                    <div class="table-responsive">
                        <table class="table table-bordered table-hover table-striped print-table order-table">
                             <tbody>
                                <tr>
                                    <td>Biller / بيلر  </td>
                                    <th><?= $created_by->first_name . ' ' . $created_by->last_name; ?></th>
                                    <td>Invoice # / فاتورة </td>
                                    <th><?= $inv->reference_no; ?></th>
                                </tr>
                                <?php if(!empty($inv->original_inv)){ ?>
                                <tr>
                                    <td>Original Invoice Number/ رقم فاتورة المبيعات المرتجعة  
                                    </td>
                                    <th><?= $inv->original_inv; ?></th>
                                    <td>Date / تاريخ </td>
                                    <th><?= $this->sma->hrld($inv->date); ?></th>
                                    
                                </tr>
                                <tr>
                                    <td>Customer Vat / الرقم الضريبي </td>
                                    <th><?= $customer->vat_no; ?></th>
                                    <td>Customer / عميل  </td>
                                    <th colspan="3"><?= $customer->company ? $customer->company : $customer->name; ?></th>
                                </tr>
                                <tr>
                                    <td>Customer Address / عنوان العميل </td>
                                    <th colspan="3"><?= $customer->address . $customer->city . " " . $customer->postal_code . " " . $customer->state . $customer->country; ?></th>
                                </tr>
                                <?php } else{ ?>
                                  
                                  <tr>
                                    
                                    <td>Date / تاريخ </td>
                                    <th><?= $this->sma->hrld($inv->date); ?></th>
                                    <td>Customer Vat / الرقم الضريبي </td>
                                    <th><?= $customer->vat_no; ?></th>
                                </tr>
                                <tr>
                                    
                                    <td>Customer / عميل  </td>
                                    <th colspan="3"><?= $customer->company ? $customer->company : $customer->name; ?></th>
                                </tr>
                                <tr>
                                    <td>Customer Address / عنوان العميل </td>
                                    <th colspan="3"><?= $customer->address . $customer->city . " " . $customer->postal_code . " " . $customer->state . $customer->country; ?></th>
                                </tr>
                                  
                                  <?php  
                                }
                                ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="col-md-12 main_details_table">
                <div class="table-responsive">
                    <table class="table table-bordered table-hover table-striped print-table order-table">
    
                        <thead>
    
                        <tr>
                            <th><?= lang("no"); ?></th>
                            <th><?= lang("description"); ?></th>
                            <?php if ($Settings->indian_gst) { ?>
                                <th><?= lang("hsn_code"); ?></th>
                            <?php } ?>
                            <th>Qty</th>
                            <th>U.Price</th>
                            <?php
                            if ($Settings->tax1 && $inv->product_tax > 0) {
                                echo '<th>' . lang("tax") . '</th>';
                            }
                            if ($Settings->product_discount && $inv->product_discount != 0) {
                                echo '<th>' . lang("discount") . '</th>';
                            }
                            ?>
                            <th><?= lang("subtotal"); ?></th>
                        </tr>
    
                        </thead>
    
                        <tbody>
    
                        <?php $r = 1; $sub=$qty=0;
                        foreach ($rows as $row):
                        ?>
                            <tr>
                                <td style="text-align:center; width:40px; vertical-align:middle;"><?= $r; ?></td>
                                <td style="vertical-align:middle;">
                                    <?= $row->product_code.' - '.$row->product_name . ($row->variant ? ' (' . $row->variant . ')' : ''); ?>
                                    <?= $row->second_name ? '/' . $row->second_name : ''; ?>
                                    <?= $row->details ? '<br>' . $row->details : ''; ?>
                                    <?= $row->serial_no ? '<br>' . $row->serial_no : ''; ?>
                                </td>
                                <?php if ($Settings->indian_gst) { ?>
                                <td style="width: 80px; text-align:center; vertical-align:middle;"><?= $row->hsn_code; ?></td>
                                <?php } ?>
                                <td style="width: 30px; text-align:center; vertical-align:middle;"><?= $this->sma->formatQuantity($row->unit_quantity); ?></td>
                                <td style="text-align:right; width:50px;"><?= $this->sma->formatMoney($row->net_unit_price); ?></td>
                                <?php
                                $qty = $row->unit_quantity * $row->net_unit_price;
                                $sub+=$qty;
                               // $sub =
                                if ($Settings->tax1 && $inv->product_tax > 0) {
                                    echo '<td style="width: 50px; text-align:right; vertical-align:middle;">' . ($row->item_tax != 0 ? '' : '') . ' ' . $this->sma->formatMoney($row->item_tax) . '</td>';
                                }
                                if ($Settings->product_discount && $inv->product_discount != 0) {
                                    echo '<td style="width: 50px; text-align:right; vertical-align:middle;">' . ($row->discount != 0 ? '<small>(' . $row->discount . ')</small> ' : '') . $this->sma->formatMoney($row->item_discount) . '</td>';
                                }
                                ?>
                                <td style="text-align:right; width:90px;"><?= $this->sma->formatMoney($qty); ?></td>
                            </tr>
                            <?php
                            $r++;
                        endforeach;
                        if ($return_rows) {
                            echo '<tr class="warning"><td colspan="100%" class="no-border"><strong>'.lang('returned_items').'</strong></td></tr>';
                            foreach ($return_rows as $row):
                            ?>
                                <tr class="warning">
                                    <td style="text-align:center; width:40px; vertical-align:middle;"><?= $r; ?></td>
                                    <td style="vertical-align:middle;">
                                        <?= $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>
                                    <?php if ($Settings->indian_gst) { ?>
                                    <td style="width: 80px; text-align:center; vertical-align:middle;"><?= $row->hsn_code; ?></td>
                                    <?php } ?>
                                    <td style="width: 80px; text-align:center; vertical-align:middle;"><?= $this->sma->formatQuantity($row->quantity).' '.$row->product_unit_code; ?></td>
                                    <td style="text-align:right; width:100px;"><?= $this->sma->formatMoney($row->unit_price); ?></td>
                                    <?php
                                    if ($Settings->tax1 && $inv->product_tax > 0) {
                                        echo '<td style="width: 100px; text-align:right; vertical-align:middle;">' . ($row->item_tax != 0 ? '<small>('.($Settings->indian_gst ? $row->tax : $row->tax_code).')</small>' : '') . ' ' . $this->sma->formatMoney($row->item_tax) . '</td>';
                                    }
                                    if ($Settings->product_discount && $inv->product_discount != 0) {
                                        echo '<td style="width: 100px; text-align:right; vertical-align:middle;">' . ($row->discount != 0 ? '<small>(' . $row->discount . ')</small> ' : '') . $this->sma->formatMoney($row->item_discount) . '</td>';
                                    }
                                    ?>
                                    <td style="text-align:right; width:120px;"><?= $this->sma->formatMoney($row->subtotal); ?></td>
                                </tr>
                                <?php
                                $r++;
                            endforeach;
                        }
                        ?>
                        </tbody>
                        <tfoot>
                        <?php
                        $col = $Settings->indian_gst ? 5 : 4;
                        if ($Settings->product_discount && $inv->product_discount != 0) {
                            $col++;
                        }
                        if ($Settings->tax1 && $inv->product_tax > 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;
                        }
                        ?>
                        <?php if ($inv->grand_total != $inv->total) { ?>
                            <tr>
                                <td colspan="<?= $tcol; ?>"
                                    style="text-align:right; padding-right:10px;"><?= lang("total"); ?>
                                    (<?= $default_currency->code; ?>)
                                </td>
                                <?php
                                if ($Settings->tax1 && $inv->product_tax > 0) {
                                    echo '<td style="text-align:right;">' . $this->sma->formatMoney($return_sale ? ($inv->product_tax+$return_sale->product_tax) : $inv->product_tax) . '</td>';
                                }
                                if ($Settings->product_discount && $inv->product_discount != 0) {
                                    echo '<td style="text-align:right;">' . $this->sma->formatMoney($return_sale ? ($inv->product_discount+$return_sale->product_discount) : $inv->product_discount) . '</td>';
                                }
                                ?>
                                <td style="text-align:right; padding-right:10px;"><?= $this->sma->formatMoney($sub); ?></td>
                            </tr>
                        <?php } ?>
                        <?php
                        if ($return_sale) {
                            echo '<tr><td colspan="' . $col . '" style="text-align:right; padding-right:10px;;">' . lang("return_total") . ' (' . $default_currency->code . ')</td><td style="text-align:right; padding-right:10px;">' . $this->sma->formatMoney($return_sale->grand_total) . '</td></tr>';
                        }
                        if ($inv->surcharge != 0) {
                            echo '<tr><td colspan="' . $col . '" style="text-align:right; padding-right:10px;;">' . lang("return_surcharge") . ' (' . $default_currency->code . ')</td><td style="text-align:right; padding-right:10px;">' . $this->sma->formatMoney($inv->surcharge) . '</td></tr>';
                        }
                        ?>
    
                        <?php if ($Settings->indian_gst) {
                            if ($inv->cgst > 0) {
                                $cgst = $return_sale ? $inv->cgst + $return_sale->cgst : $inv->cgst;
                                echo '<tr><td colspan="' . $col . '" class="text-right">' . lang('cgst') . ' (' . $default_currency->code . ')</td><td class="text-right">' . ( $Settings->format_gst ? $this->sma->formatMoney($cgst) : $cgst) . '</td></tr>';
                            }
                            if ($inv->sgst > 0) {
                                $sgst = $return_sale ? $inv->sgst + $return_sale->sgst : $inv->sgst;
                                echo '<tr><td colspan="' . $col . '" class="text-right">' . lang('sgst') . ' (' . $default_currency->code . ')</td><td class="text-right">' . ( $Settings->format_gst ? $this->sma->formatMoney($sgst) : $sgst) . '</td></tr>';
                            }
                            if ($inv->igst > 0) {
                                $igst = $return_sale ? $inv->igst + $return_sale->igst : $inv->igst;
                                echo '<tr><td colspan="' . $col . '" class="text-right">' . lang('igst') . ' (' . $default_currency->code . ')</td><td class="text-right">' . ( $Settings->format_gst ? $this->sma->formatMoney($igst) : $igst) . '</td></tr>';
                            }
                        } ?>
    
                        <?php if ($inv->order_discount != 0) {
                            echo '<tr><td colspan="' . $col . '" style="text-align:right; padding-right:10px;;">' . lang("order_discount") . ' (' . $default_currency->code . ')</td><td style="text-align:right; padding-right:10px;">'.($inv->order_discount_id ? '<small>('.$inv->order_discount_id.')</small> ' : '') . $this->sma->formatMoney($return_sale ? ($inv->order_discount+$return_sale->order_discount) : $inv->order_discount) . '</td></tr>';
                        }
                        ?>
                        <?php if ($Settings->tax2 && $inv->order_tax != 0) {
                            echo '<tr><td colspan="' . $col . '" style="text-align:right; padding-right:10px;">' . lang("order_tax") . ' (' . $default_currency->code . ')</td><td style="text-align:right; padding-right:10px;">' . $this->sma->formatMoney($return_sale ? ($inv->order_tax+$return_sale->order_tax) : $inv->order_tax) . '</td></tr>';
                        }
                        ?>
                        <?php if ($inv->shipping != 0) {
                            echo '<tr><td colspan="' . $col . '" style="text-align:right; padding-right:10px;;">' . lang("shipping") . ' (' . $default_currency->code . ')</td><td style="text-align:right; padding-right:10px;">' . $this->sma->formatMoney($inv->shipping) . '</td></tr>';
                        }
                        ?>
                        <tr>
                            <td colspan="<?= $col; ?>"
                                style="text-align:right; font-weight:bold;"><?= lang("Subtotal"); ?> / المجموع الفرعي
                                (<?= $default_currency->code; ?>)
                            </td>
                            <td style="text-align:right; padding-right:10px; font-weight:bold;"><?= $this->sma->formatMoney($sub);?></td>
                        </tr>
                        <tr>
                            <td colspan="<?= $col; ?>"
                                style="text-align:right; font-weight:bold;">VAT (15%) / ضريبة
                                (<?= $default_currency->code; ?>)
                            </td>
                            <td style="text-align:right; padding-right:10px; font-weight:bold;"><?=$this->sma->formatMoney($return_sale ? ($inv->product_tax+$return_sale->product_tax) : $inv->product_tax)?></td>
                        </tr>
                        <tr>
                            <td colspan="<?= $col; ?>"
                                style="text-align:right; font-weight:bold;"><?= lang("total_amount"); ?> / المبلغ الإجمالي
                                (<?= $default_currency->code; ?>)
                            </td>
                            <td style="text-align:right; padding-right:10px; font-weight:bold;"><?= $this->sma->formatMoney($return_sale ? ($inv->grand_total+$return_sale->grand_total) : $inv->grand_total); ?></td>
                        </tr>
                        <tr>
                            <td colspan="<?= $col; ?>"
                                style="text-align:right; font-weight:bold;"><?= lang("paid"); ?> / دفع
                                (<?= $default_currency->code; ?>)
                            </td>
                            <td style="text-align:right; font-weight:bold;"><?= $this->sma->formatMoney($return_sale ? ($inv->paid+$return_sale->paid) : $inv->paid); ?></td>
                        </tr>
                        <tr>
                            <td colspan="<?= $col; ?>"
                                style="text-align:right; font-weight:bold;"><?= lang("balance"); ?> / الرصيد
                                (<?= $default_currency->code; ?>)
                            </td>
                            <td style="text-align:right; font-weight:bold;"><?= $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>
                    </table>
                </div>
            </div>
            
   <div class="col-xs-7 pull-right">
                  <!--<div class="col-xs-12 text-right order_barcodes">
                     <?php 
                     $seller_name = $biller->company;
                    // $seller_name = bin2hex($seller_name);
                     $name = strlen($biller->company);
                     $tag_name ='01';
                     $length_name =$name;
                     $first_tag = $tag_name.''.$name;
                     $first_tag_hex = $this->sma->dec2hex($length_name);
                     if(strlen($first_tag_hex) == '1'){
                         $first_tag_hex ='0'.''.$first_tag_hex;
                     }
                     else{
                         $first_tag_hex = $first_tag_hex;
                     }
                     
                     //$first_tag_hex_to_string = hex2bin($first_tag_hex);
                     $seller_name = $this->sma->hex2str($tag_name).''.$this->sma->hex2str($first_tag_hex).''.$seller_name;
                     //$this->sma->hex2str($content)
                     $seller_vat = $biller->vat_no;
                    // $seller_vat = bin2hex($seller_vat);
                     $vat = strlen($seller_vat);
                     $tag_vat ='02';
                     $length_vat =$vat;
                     $second_tag = $tag_vat.''.$vat;
                     $second_tag_hex =  $this->sma->dec2hex($length_vat);
                     if(strlen($second_tag_hex) == '1'){
                         $second_tag_hex ='0'.''.$second_tag_hex;
                     }
                     else{
                         $second_tag_hex = $second_tag_hex;
                     }
                    // $second_tag_hex_to_string = hex2bin($second_tag_hex);
                    
                     $seller_vat = $this->sma->hex2str($tag_vat).''.$this->sma->hex2str($second_tag_hex).''.$seller_vat;
                   
                     $seller_date = $inv->date;
                     //$seller_date = bin2hex($seller_date);
                     $date = strlen($inv->date);
                     $tag_date ='03';
                     $length_date =$date;
                     $third_tag = $tag_date.''.$date;
                     $third_tag_hex = $this->sma->dec2hex($length_date);
                     if(strlen($third_tag_hex) == '1'){
                         $third_tag_hex ='0'.''.$third_tag_hex;
                     }
                     else{
                         $third_tag_hex = $third_tag_hex;
                     }
                    // $third_tag_hex_to_string = hex2bin($third_tag_hex);
                     $seller_date = $this->sma->hex2str($tag_date).''.$this->sma->hex2str($third_tag_hex).''.$seller_date;
                       
                     $seller_invoice_total = $this->sma->formatQuantity($inv->grand_total);
                    // $seller_invoice_total =bin2hex($seller_invoice_total);
                     $grand = strlen($this->sma->formatQuantity($inv->grand_total));
                     $tag_grand ='04';
                     $length_tot =$grand;
                     $fourth_tag = $tag_grand.''.$grand;
                     $fourth_tag_hex = $this->sma->dec2hex($length_tot);
                     if(strlen($fourth_tag_hex) == '1'){
                         $fourth_tag_hex ='0'.''.$fourth_tag_hex;
                     }
                     else{
                         $fourth_tag_hex = $fourth_tag_hex;
                     }
                     //$fourth_tag_hex_to_string = hex2bin($fourth_tag_hex);
                     $seller_invoice_total =$this->sma->hex2str($tag_grand).''.$this->sma->hex2str($fourth_tag_hex).''.$seller_invoice_total;
                    
                     $vat_values ='15';
                     $seller_vat_value = $this->sma->formatQuantity($vat_values);
                     // $seller_vat_value =  bin2hex($seller_vat_value); 
                     $vat_value = strlen($this->sma->formatQuantity($vat_values));
                     $tag_vat_value ='05';
                     $length_vat =$vat_value;
                     $fifth_tag = $tag_vat_value.''.$vat_value; 
                     $fifth_tag_hex = $this->sma->dec2hex($length_vat);
                     if(strlen($fifth_tag_hex) == '1'){
                         $fifth_tag_hex ='0'.''.$fifth_tag_hex;
                     }
                     else{
                         $fifth_tag_hex = $fifth_tag_hex;
                     }
                    // $fifth_tag_hex_to_string = hex2bin($fifth_tag_hex);
                     $seller_vat_value = $this->sma->hex2str($tag_vat_value).''.$this->sma->hex2str($fifth_tag_hex).''.$seller_vat_value;
                    //print_r($seller_vat_value);
                     
                     $content = $seller_name.''.$seller_vat.''.$seller_date.''.$seller_invoice_total.''.$seller_vat_value;
                     
                      ?>
              <br>
          <?php  //$bin =$this->sma->hex2str($content);
$b64 = base64_encode($content); //print_r($content);

?>
   <?= $this->sma->new_qrcode('link',$b64, 256); ?>
                    
                         </div>
                    <div class="clearfix"></div>-->
                </div>
           <!-- <?= $Settings->invoice_view > 0 ? $this->gst->summary($rows, $return_rows, ($return_sale ? $inv->product_tax+$return_sale->product_tax : $inv->product_tax)) : ''; ?>-->

            <div class="row">
                <div class="col-xs-12">
                    <?php
                        if ($inv->note || $inv->note != "") { ?>
                            <div class="well well-sm">
                                <p class="bold"><?= lang("note"); ?>:</p>
                                <div><?= $this->sma->decode_html($inv->note); ?></div>
                            </div>
                        <?php
                        }
                        if ($inv->staff_note || $inv->staff_note != "") { ?>
                            <div class="well well-sm staff_note">
                                <p class="bold"><?= lang("staff_note"); ?>:</p>
                                <div><?= $this->sma->decode_html($inv->staff_note); ?></div>
                            </div>
                        <?php } ?>
                </div>

                <?php if ($customer->award_points != 0 && $Settings->each_spent > 0) { ?>
                <div class="col-xs-5 pull-left">
                    <div class="well well-sm">
                        <?=
                        '<p>'.lang('this_sale').': '.floor(($inv->grand_total/$Settings->each_spent)*$Settings->ca_point)
                        .'<br>'.
                        lang('total').' '.lang('award_points').': '. $customer->award_points . '</p>';?>
                    </div>
                </div>
                <?php } ?>

                
            </div>
            <?php if (!$Supplier || !$Customer) { ?>
                <div class="buttons">
                    <div class="btn-group btn-group-justified">
                        <div class="btn-group">
                            <a href="<?= admin_url('sales/add_payment/' . $inv->id) ?>" class="tip btn btn-primary" title="<?= lang('add_payment') ?>" data-toggle="modal" data-target="#myModal2">
                                <i class="fa fa-dollar"></i>
                                <span class="hidden-sm hidden-xs"><?= lang('payment') ?></span>
                            </a>
                        </div>
                        <div class="btn-group">
                            <a href="<?= admin_url('sales/add_delivery/' . $inv->id) ?>" class="tip btn btn-primary" title="<?= lang('add_delivery') ?>" data-toggle="modal" data-target="#myModal2">
                                <i class="fa fa-truck"></i>
                                <span class="hidden-sm hidden-xs"><?= lang('delivery') ?></span>
                            </a>
                        </div>
                        <?php if ($inv->attachment) { ?>
                            <div class="btn-group">
                                <a href="<?= admin_url('welcome/download/' . $inv->attachment) ?>" class="tip btn btn-primary" title="<?= lang('attachment') ?>">
                                    <i class="fa fa-chain"></i>
                                    <span class="hidden-sm hidden-xs"><?= lang('attachment') ?></span>
                                </a>
                            </div>
                        <?php } ?>
                        <div class="btn-group">
                            <a href="<?= admin_url('sales/email/' . $inv->id) ?>" data-toggle="modal" data-target="#myModal2" class="tip btn btn-primary" title="<?= lang('email') ?>">
                                <i class="fa fa-envelope-o"></i>
                                <span class="hidden-sm hidden-xs"><?= lang('email') ?></span>
                            </a>
                        </div>
                        <div class="btn-group">
                            <a href="<?= admin_url('sales/pdf/' . $inv->id) ?>" class="tip btn btn-primary" title="<?= lang('download_pdf') ?>">
                                <i class="fa fa-download"></i>
                                <span class="hidden-sm hidden-xs"><?= lang('pdf') ?></span>
                            </a>
                        </div>
                        <?php if ( ! $inv->sale_id) { ?>
                        <div class="btn-group">
                            <a href="<?= admin_url('sales/edit/' . $inv->id) ?>" class="tip btn btn-warning sledit" title="<?= lang('edit') ?>">
                                <i class="fa fa-edit"></i>
                                <span class="hidden-sm hidden-xs"><?= lang('edit') ?></span>
                            </a>
                        </div>
                        <!--<div class="btn-group">
                            <a href="#" class="tip btn btn-danger bpo" title="<b><?= $this->lang->line("delete_sale") ?></b>"
                                data-content="<div style='width:150px;'><p><?= lang('r_u_sure') ?></p><a class='btn btn-danger' href='<?= admin_url('sales/delete/' . $inv->id) ?>'><?= lang('i_m_sure') ?></a> <button class='btn bpo-close'><?= lang('no') ?></button></div>"
                                data-html="true" data-placement="top">
                                <i class="fa fa-trash-o"></i>
                                <span class="hidden-sm hidden-xs"><?= lang('delete') ?></span>
                            </a>
                        </div>-->
                        <?php } ?>
                    </div>
                </div>
            <?php } ?>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready( function() {
        $('.tip').tooltip();
    });
</script>
