<!DOCTYPE HTML>
<html lang="en">

<head>
    <!--=============== basic  ===============-->

    <title>PRINT POS</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <!--=============== css  ===============-->
    <style type="text/css">
        body {
            font-family: 'Nunito', sans-serif;
            text-align: center;
            color: #777;
            background: #f9f9f9;
            font-weight: 400;
            margin: 0px;
            padding: 0px;

        }

        body h1 {
            font-weight: 500;
            margin-bottom: 0px;
            padding-bottom: 0px;
            color: #000;
        }

        @page {
            size: auto;
            margin: 0mm;
        }

        body h3 {
            font-weight: 400;
            margin-top: 10px;
            margin-bottom: 20px;
            font-style: italic;
            color: #000;
        }

        body a {
            color: #000;
        }

        .invoice-box {
            max-width: 500px;
            /* margin: 30px auto 30px; */
            margin: -29px auto 30px;
            padding: 15px;
            border: 1px solid #eee;
            font-size: 13px;
            line-height: 24px;
            background: #fff;
            color: #000;
        }

        .invoice-box table {
            width: 100%;
            /* width: 35%; */
            line-height: inherit;
            text-align: left;
        }

        .invoice-box table td {
            padding: 3px;
            vertical-align: top;
        }

        .invoice-box table tr td:nth-child(2) {
            text-align: right;
        }

        .invoice-box table tr.top table td {
            padding-bottom: 5px;
        }

        .invoice-box table tr.information table td {
            margin-top: 50px;
            padding-bottom: 20px;
        }

        .invoice-box table tr.heading td {
            background: #f9f9f9;
            border-bottom: 1px solid #eee;
            font-weight: 400;
        }

        .invoice-box table tr.details td {
            padding-bottom: 20px;
        }

        .invoice-box table tr.item td {
            border-bottom: 1px solid #eee;
        }

        .invoice-box table tr.item.last td {
            border-bottom: none;
        }

        .invoice-box table tr.total td:nth-child(2) {
            border-top: 2px solid #eee;
            font-weight: 400;
        }

        .print-button {
            padding: 7px 26px;
            text-decoration: none;
            color: #fff;
            background: #3AACED;
            display: inline-table;
            font-weight: 900;
            margin: 20px 0;
            font-size: 13px;
            border-radius: 4px;

        }

        @media only screen and (max-width: 600px) {
            .invoice-box table tr.top table td {
                width: 100%;
                display: block;
                text-align: center;
            }

            .invoice-box table tr.top table td {
                padding-bottom: 20px;
            }

            .invoice-box table tr.information table td {
                margin-top: 20px;
                padding-bottom: 20px;
            }

            .invoice-box table tr.information table td {
                width: 100%;
                display: block;
                text-align: center;
            }
        }

        @media print {
            .print-button {
                display: none;
            }

            .invoice-box {
                border: none;
            }
        }


        table th,
        table td {
            padding: 10px;
            border-bottom: 1px dashed;
            font-weight: 400;
        }

        table .desc {
            text-align: left;
        }

        table .unit {
            background: #f8f8f8;
        }

        table .qty {}

        table .total {
            background: #c00d0e;
            color: #FFFFFF;
        }

        table td.unit,
        table td.qty,
        table td.total {
            font-size: 1.2em;
        }

        .text-center {
            text-align: center !important;
        }

        .text-left {
            text-align: left !important;
        }

        .text-right {
            text-align: right !important;
        }

        .float-left {
            float: left !important;
        }

        .float-right {
            float: right !important;
        }

        .border-none {
            border: none !important;
        }

        .p-0 {
            padding: 0px !important;
        }

        .line_height {
            line-height: 0 !important;
        }

        .padd_left {
            padding-left: 0 !important;
            text-align: left !important;
        }

        .padd_right {
            padding-right: 0 !important;
            text-align: right !important;
        }

        .border-top {
            border-bottom: 1px dashed;
        }

        .product_border th {
            border: none;
        }
    </style>

</head>

<body onload="window.print()">
    <div class="invoice-box" id="divToPrint">

        <table>
            <tr class="top">
                <td colspan="2" style="border: none;">
                    <table>
                        <tr style="line-height:0;">
                            <td class="text-center border-none">

                                <?php
                                $warehouse_id = (int) Yii::app()->user->getState('user_warehouse_id');

                                $modelMasInventoryWarehouse = new MasInventoryWarehouse();

                                $arr_warehouse_list = $modelMasInventoryWarehouse->findByPk($warehouse_id);

                                if (isset(Yii::app()->user->master_user_company_id) && (int)Yii::app()->user->master_user_company_id > 0) {
                                    $company_id = Yii::app()->user->master_user_company_id;
                                }



                                $modelInvoice = Invoice::model()->findByPk($id);
                                /* $branch_name = $modelInvoice->branchDetails->branch_name;
                                 $branch_code = $modelInvoice->branchDetails->branch_code;
                                 $branch_address = $modelInvoice->branchDetails->branch_address;
                                 $branch_phone = $modelInvoice->branchDetails->branch_phone;
                                 $branch_mail = $modelInvoice->branchDetails->branch_email_id;*/
                                //end

                                $branchwarehouse_id = $modelInvoice->warehouse_id;

                                if (!empty($branchwarehouse_id)) {
                                    $model = new MasInventoryWarehouse();

                                    $model_det = $model->findByPk($branchwarehouse_id);
                                    $branch_logo = $model_det->upload_image;
                                }

                                if (!empty($branch_logo)) {

                                    $logo_name = $branch_logo;
                                } else {
                                    if (isset(Yii::app()->user->pdf_company_logo)) {
                                        $logo_name = Yii::app()->user->pdf_company_logo;
                                    } else {
                                        $logo_name = "pdf_logo.png";
                                    }
                                }
                                $invoice_type = $modelInvoice->invoice_type;
                                $invoice_no = $modelInvoice->invoice_no;
                                ?>
                                <?php if (!empty($branch_logo)) { ?>
                                    <img src="<?php echo 'uploads/warehouse/thumbs/' . $logo_name; ?> " alt="Logo" />
                                <?php } else { ?>
                                    <img src="<?php echo 'images/logo/' . $logo_name; ?> " alt="Logo" />

                                <?php } ?>
                            </td>

                        </tr>
                        <tr>
                            <td class="title text-center border-none p-0">
                                <h2 style="font-size: 15px;font-weight: 600;margin: 0;"><?php echo $arr_warehouse_list->warehouse_name; ?></h2>
                                <p style="margin: 0;font-size: 13px;width: 100%;display: inline-block;line-height: 1.4;">
                                    <?php
                                    if (isset(Yii::app()->user->master_user_company_id) && (int) Yii::app()->user->master_user_company_id > 0) {
                                        $company_id = Yii::app()->user->master_user_company_id;
                                    }
                                    $modelCompanyDetails = MasCompany::model()->findByPk($company_id);
                                    ?>

                                    <?php
                                    if (!empty($branchwarehouse_id)) {
                                        $modelMasInventoryWarehouse = new MasInventoryWarehouse();
                                        $model_det = $modelMasInventoryWarehouse->findByPk($branchwarehouse_id);
                                       
                                        $address_branch = $model_det->address;
                                    }
                                    if (!empty($address_branch)) {
                                        echo nl2br($address_branch);
                                    } else {
                                        echo $modelCompanyDetails->footer_line_two;
                                    }

                                    ?>



                                    <br>
                                    <!-- <span style="font-size: 13px;"> TRN: 100602107300003 -->
                                    <!-- <?php //$settings = MasCompany::model()->findByPk($company_id); 
                                            ?>
                        <?php // if ($settings->trn_no != '') { 
                        ?>

							<?php // echo $settings->trn_no; 
                            ?>
										<?php // } 
                                        ?> -->
                                    <!-- </span> -->
                                </p>
                            </td>
                        </tr>
                        <!-- -------------- -->
                        <table>
                            <tr>
                                <td></td>
                            </tr>
                        </table>
                        <!-- -------------- -->
                        <tr>

                            <td class="title text-center border-none p-0 line_height">
                                <p style="margin: 0;font-size: 16px;width: 50%;display: inline-block;font-weight: 600;line-height: 1;">
                                    TAX INVOICE </p>
                            </td>
                        </tr>

                    </table>
                </td>
            </tr>

            <!-- -------------- -->
            <table>
                <tr>
                    <td></td>
                </tr>
            </table>
            <!-- -------------- -->

            <table border="0" cellspacing="0" cellpadding="0">

                <tbody class="product_border" style="font-size:13px;">

                    <tr style="line-height: 1;">

                        <th colspan="1" style="padding: 0px 5px;"> Invoice Number</th>

                        <th colspan="1" style="padding: 0px 5px;"> :</th>
                        <th colspan="1" style="padding: 0px 5px;font-size:13px;">
                            <?php echo $modelInvoice->invoice_no;
                            /*  if (!empty($branch_code)) {
                        echo $branch_code . "-" . $modelInvoice->id;
                    } else {
                        echo $modelInvoice->id;
                    }  */

                            ?>
                        </th>
                    </tr>
                    <tr style="line-height: 1;">
                        <th colspan="1" style="padding: 0px 5px;"> Invoice Date</th>

                        <th colspan="1" style="padding: 0px 5px;"> :</th>
                        <th colspan="1" style="padding: 0px 5px;font-size:13px;">
                            <?php echo date('d/m/Y', STRTOTIME($modelInvoice->invoice_date)); ?>
                        </th>
                    </tr>
                    <!--<tr style="line-height: 1;">
                        <th colspan="1" style="padding: 0px 5px;"> Warehouse</th>

                        <th colspan="1" style="padding: 0px 5px;"> :</th>
                        <th colspan="1" style="padding: 0px 5px;font-size:13px;">
                            <?php
                            //  echo $branch_name;
                            ?>
                        </th>
                    </tr>-->
                    <tr style="line-height: 1;">
                        <th colspan="1" style="padding: 0px 5px;">Payment Mode</th>

                        <th colspan="1" style="padding: 0px 5px;"> :</th>
                        <th colspan="1" style="padding: 0px 5px;font-size:13px;">
                            <?php echo $modelInvoice->paymentTerm->payment_terms; ?>
                        </th>
                    </tr>
                    <tr style="line-height: 1;">
                        <th colspan="1" style="padding: 0px 5px;">Salesman</th>

                        <th colspan="1" style="padding: 0px 5px;"> :</th>
                        <th colspan="1" style="padding: 0px 5px;font-size:13px;">
                            <?php
                            echo $modelInvoice->leadowner->first_name . ' ' . $modelInvoice->leadowner->last_name;

                            ?>
                        </th>
                    </tr>

                    <tr style="line-height: 1;">
                        <th colspan="1" style="padding: 0px 5px;"> Customer</th>
                        <th colspan="1" style="padding: 0px 5px;"> :</th>
                        <th colspan="1" style="padding: 0px 5px;font-size:13px;">
                            <?php echo $modelInvoice->customer->customer_name; ?><br>

                        </th>

                    </tr>
                    <tr style="line-height: 1;">
                        <th colspan="1" style="padding: 0px 5px;"> Phone</th>
                        <th colspan="1" style="padding: 0px 5px;"> :</th>
                        <th colspan="1" style="padding: 0px 5px;font-size:13px;">
                            <?php echo $modelInvoice->customer->customer_phone_no; ?><br>

                        </th>

                    </tr>
                </tbody>
            </table>

            <!-- -------------- -->
            <table>
                <tr>
                    <td></td>
                </tr>
            </table>
            <!-- -------------- -->

            <table border="0" cellspacing="0" cellpadding="0">
                <thead style="font-size: 13px;">
                    <tr>
                        <th class="padd_left" style="padding: 0px;">Item</th>
                        <th style="padding: 0px;">Rate</th>
                        <th style="padding: 0px;">Qty</th>
                        <th class="padd_right" style="padding: 0px;">Total</th>
                    </tr>
                </thead>

                <tbody class="product_border" style="font-size:13px;">
                    <?php
                    $m = 1;
                    $condition .= '1=1';
                    $col = 12;
                    if ($bonus_quantity == "Y") {
                        $col = $col + 1;
                    }
                    $condition .= ' AND t.invoice_id ="' . $id . '"';
                    $total = $total_vat = 0;
                    $total_cbm = 0;
                    $total_weight = 0;

                    // $count_alternate_ids = InvoiceItem::model()->count(array('condition' => 'alternate_id!="" AND t.invoice_id ="' . $id . '"'));
                    // if ($count_alternate_ids > 0) {
                    //     $order_by = 'alternate_id ASC';
                    // } else {
                    $order_by = 'id ASC';
                    // }

                    $modelInvoiceItem = InvoiceItem::model()->findAll(array('condition' => $condition, 'order' => $order_by));
                    foreach ($modelInvoiceItem as $i => $modelInvoiceItem) {

                        $batch_no = '';
                        $sl_no = '';
                    ?>
                        <tr style="line-height: 1;">
                            <th colspan="1" style="padding: 0px 5px;"> <?php echo $modelInvoiceItem->description; ?></th>
                            <?php $rate = $modelInvoiceItem->rate - $modelInvoiceItem->deduction_amount; ?>
                            <th style="padding: 0px 5px;font-size:13px;"> <?php echo Yii::app()->numberFormatter->formatCurrency(($rate), " "); ?>
                            </th>
                            <th style="padding: 0px 5px;font-size:13px;"> <?php echo Yii::app()->numberFormatter->formatCurrency($modelInvoiceItem->quantity, " "); ?></th>
                            <?php $_total = $rate * $modelInvoiceItem->quantity; ?>
                            <th class="padd_right" style="padding: 0px 5px;font-size:13px;"> <?php echo Yii::app()->numberFormatter->formatCurrency($modelInvoiceItem->net_amount, " "); ?></th>

                        </tr>


                    <?php
                        $m = $m + 1;
                        $total += $modelInvoiceItem->amount;
                        $total_vat += $modelInvoiceItem->tax_vat_amount;
                        $discount += $modelInvoiceItem->deduction_amount;


                        if ($modelInvoiceItem->invoiceunit->name == 'CTN') {

                            $item_cbm = $modelInvoiceItem->product->cubic_meter;
                            $item_weight = $modelInvoiceItem->product->weight;
                            $total_cbm += $modelInvoiceItem->quantity * $item_cbm;
                            $total_weight += ($modelInvoiceItem->quantity * $item_weight);
                            $total_qty = $modelInvoiceItem->quantity;
                            $tot_cartoons += $total_qty;
                        }
                    }
                    $all_total += $discount + $total + $total_vat;
                    ?>


                </tbody>


                <tbody>
                    <tr>
                        <th class="padd_left" colspan="5" style="padding: 2px;"></th>
                    </tr>
                </tbody>

                <tbody style="font-size: 13px; border-top: 1px dashed;">
                    <tr style="line-height: 1.5;">
                        <th class="padd_left border-none" colspan="3" style="padding: 0px 5px;">Sub Total</th>

                        <th class="padd_right border-none" colspan="2" style="padding: 0px 5px;"><?php echo Yii::app()->numberFormatter->formatCurrency($all_total, " "); ?></th>
                    </tr>
                    <tr style="line-height: 1.5;">
                        <th class="padd_left border-none" colspan="3" style="padding: 0px 5px;">Discount</th>

                        <th class="padd_right border-none" colspan="2" style="padding: 0px 5px;"><?php echo Yii::app()->numberFormatter->formatCurrency($discount, " "); ?></th>
                    </tr>

                    <tr style="line-height: 1.5;">

                        <th class="padd_left border-none" colspan="3" style="padding: 0px 5px;">Total W/O VAT</th>
                        <th class="padd_right border-none" colspan="2" style="padding: 0px 5px;"><?php echo Yii::app()->numberFormatter->formatCurrency($total, " "); ?></th>
                    </tr>

                    <tr style="line-height: 1.5;">
                        <th class="padd_left border-none" colspan="3" style="padding: 0px 5px;">VAT Amount :</th>
                        <th class="padd_right border-none" colspan="2" style="padding: 0px 5px;">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($total_vat, " "); ?>
                        </th>
                    </tr>


                </tbody>


                <tbody style="font-size: 10px;">
                    <tr>
                        <th colspan="3" class="" style="padding: 0px; font-size:13px;"><b>Grand Total :</b></th>
                        <th colspan="2" class="text-right" style="padding: 0px; font-size:13px;">
                            <b> <?php echo Yii::app()->numberFormatter->formatCurrency(($total + $total_vat), " "); ?>

                            </b>
                        </th>
                    </tr>
                </tbody>
                <?php
                $modelDirectOrder = new DirectInvoice();
                $modelDirectOrder = $modelDirectOrder->findByPK((int) $modelInvoice->order_id);
                $oldbalance = $modelDirectOrder->old_balance;
                $new_balance = $oldbalance + ($total + $total_vat) - $modelDirectOrder->received_amount;
                ?>
                <tbody style="font-size: 13px;border-top: 1px dashed;">
                    <tr style="line-height: 1.5;">
                        <th class="padd_left border-none" colspan="3" style="padding: 0px 5px;">Old Balance :</th>
                        <th class="padd_right border-none" colspan="2" style="padding: 0px 5px;"><?php echo Yii::app()->numberFormatter->formatCurrency($oldbalance, " "); ?></th>
                    </tr>
                    <tr style="line-height: 1.5;">
                        <th class="padd_left border-none" colspan="3" style="padding: 0px 5px;">Amount Paid :</th>
                        <th class="padd_right border-none" colspan="2" style="padding: 0px 5px;"><?php echo Yii::app()->numberFormatter->formatCurrency($modelDirectOrder->received_amount, " "); ?></th>
                    </tr>
                    <tr style="line-height: 1.5;">
                        <th class="padd_left border-none" colspan="3" style="padding: 0px 5px;">Balance :</th>
                        <th class="padd_right border-none" colspan="2" style="padding: 0px 5px;"><?php echo Yii::app()->numberFormatter->formatCurrency($new_balance, " "); ?></th>
                    </tr>

                </tbody>
                <table border="0" cellspacing="0" cellpadding="0">

                    <tbody class="product_border" style="font-size:13px;">

                        <tr style="line-height: 2;">

                            <th colspan="1" style="padding: 0px 5px;  font-weight: 600;">Terms And Conditions:

                            </th>
                        </tr>

                        <!-- <tr style="line-height: 1.5;">
                <p style="font-size: 13px;">
                    <b>Terms And Conditions22<b/></p>
                    <th colspan="1" style="padding: 0px 5px;">
                        &#9678; The Item Can Exchangeable Within 5 Days and No Refund.
                    </th>
                </tr> -->

                        <tr style="line-height: 1.5;">
                            <th colspan="1" style="padding: 0px 5px;"> &#9678;The item/s can be exchanged within 5 days with no refund in cash..
                            </th>
                        </tr>
                        <tr style="line-height: 1.5;">
                            <th colspan="1" style="padding: 0px 5px;"> &#9678; While exchanging the item/s must be in saleable condition and not damaged.
                            </th>
                        </tr>
                        <tr style="line-height: 1.5;">
                            <th colspan="1" style="padding: 0px 5px;"> &#9678; The item/s won't be accepted without tag, label and price tag at exchange time

                            </th>
                        </tr>
                        <tr style="line-height: 1.5;">
                            <th colspan="1" style="padding: 0px 5px;"> &#9678; We are not guaranteeing the color of the cloth and hand work damaged.



                        </tr>

                    </tbody>
                </table>


                <tr style="line-height: 1.5,;">
                    <th colspan="4" class="padd_left border-none" style="padding: 10px 5px 0px; font-size:13px; font-family:'Nunito', sans-serif;">

                        Thank You.... Visit Again!
                    </th>

                </tr>
                </tfoot>
            </table>
            <br>

            <a href="javascript:window.print()" class="print-button">Print </a>


            <a style="background:#c33612;" href="javascript:window.close()" class="print-button">Close </a>


    </div>
</body>

</html>