<!DOCTYPE html>
<html>
    <head>
        <title>Invoice List</title>
        <style>
            body{padding:0px!important;font-size:12px;} 
            table{
                border-collapse: collapse;}
            .item_table {
                border-collapse: collapse;
                font-size:12px!important;
                margin:0px;
            }
            table.item_table,.item_table th,.item_table td {
                border: 1px solid black; 
                font-family:'Times New Roman', Times, serif;
                padding:1px;
            } 

            .second-colom{

                height:100px;

                border-bottom:1px solid;

                text-align:center;

                width:100%;

            }


            .nobdr_table, .nobdr_table td{ border:none!important;padding:0px!important}
            @media print {
                .no-break-inside{page-break-inside: avoid;display: block;}
            }
            .table_box {
                border-collapse:separate!important;
                margin-top: 10px;                      
                padding: 10px;
                font-size:16px!important;
                border: 1px solid #7a1d8b;
                border-radius:6px;   
            }
            
        </style>

    </head>
    <body style="font-family: "Times New Roman", Times, serif">

          <div class="main" >
              <br>
              <br>
              <br>
              <br>
              <br>
         <br>
              <br>

            <sethtmlpageheader name="firstpage" value="off" show-this-page="1" />
            <sethtmlpageheader name="otherpages" value="on" /></div>
        <div >
          
            <?php
            if (Yii::app()->user->master_company_code == 'ARK') { 
                $footer_company_name =' ARK Engineering Services (ARK) ';
            }else{
                $footer_company_name =' Ace Centro Enterprises (ACE) ';
            }
            $crm_login_company_id = Yii::app()->user->master_user_company_id;
            $privillage_modal = new MasCompanySettings();
            $privillage_condition = 'crm_company_id=' . $crm_login_company_id;
            $privillage_settings_module = $privillage_modal->find(array('condition' => $privillage_condition));
            $bonus_quantity = $privillage_settings_module->bonus_quantity;

            $modelInvoice = Invoice::model()->findByPk($id);
            $settings = MasCompany::model()->findByPk(Yii::app()->user->master_user_company_id);
            ?>
            <div  style="width:100%;float: left;margin-top: 10px;font-size:11px;font-family:'Times New Roman', Times, serif;"> 

                <div style="text-align:left; float:left; width:50%;" >


                    <div style="float:left;">

                        <span style="font-weight:bold;padding-bottom: 6px;float: left;"><?php echo strtoupper($modelInvoice->customer->customer_name); ?></span><br />

                        <span style="padding-bottom: 6px;float: left;"><?php echo strtoupper(nl2br($modelInvoice->billing_address)); ?></span>

                        <table class="" style="width:100%">
                            <tr>
                                <td style="width: 100px">Tel</td>
                                <td style="width: 2px">:</td>
                                <td style="float: left;">
                                    <?php echo strtoupper($modelInvoice->customer->customer_phone_no); ?>
                                </td>
                            </tr>
                            <tr>
                                <td>Fax</td>
                                <td>:</td>
                                <td>
                                    <?php echo strtoupper($modelInvoice->customer->customer_fax); ?>
                                </td>
                            </tr>
                            <tr>
                                <td>TRN</td>
                                <td>:</td>
                                <td>
                                    <?php echo strtoupper($modelInvoice->customer->customer_trn_no); ?>
                                </td>
                            </tr>
                            <tr>
                                <td>Attn.</td>
                                <td>:</td>
                                <td>
                                    <?php echo strtoupper($modelInvoice->contact->person_name); ?>
                                </td>
                            </tr>
                            <tr>
                                <td><b>TAX INVOICE #</b></td>
                                <td>:</td>
                                <td style="text-align:left;">
                                    <b><?php echo /* $modelInvoice->invoice_no.'/'. */$modelInvoice->id; ?></b>
                                </td>
                            </tr>
                        </table>  

<!--span style="font-weight:bold;padding-bottom: 6px;float: left;"><?php echo strtoupper($modelInvoice->customer->customer_name); ?></span><br />

<span style="padding-bottom: 6px;float: left;"><?php echo strtoupper(nl2br($modelInvoice->billing_address)); ?> <br />

Tel	:	<?php echo strtoupper($modelInvoice->customer->customer_phone_no); ?><br />

Fax	:	<?php echo strtoupper($modelInvoice->customer->customer_fax); ?><br />

TRN	:   <?php echo strtoupper($modelInvoice->customer->customer_trn_no); ?></span><br />

Attn.	:	<?php echo strtoupper($modelInvoice->contact->person_name); ?></span><br />

TAX INVOICE #:	<?php echo $modelInvoice->invoice_no . '/' . $modelInvoice->id; ?></span><br /> -->

                    </div>

                </div>

                <div style="text-align:right; float:right;padding-left: 60px; width:40%;" >

                    <table class="table" style="width:100%">
                        <tr>
                            <?php
                            $modelQuotation = Quotes::model()->find(array('condition' => 'file_id="' . $modelInvoice->file_id . '"'));
                            ?>
                            <td class="bc-tl">Qtn.#/Ord.#</td>
                            <td>
                                <?php echo (!empty($modelQuotation->id)) ? $modelQuotation->id : "NA"; ?> / <?php echo (!empty($modelInvoice->order_id)) ? $modelInvoice->order_id : "NA"; ?>

                            </td>
                        </tr>
                        <tr>
                            <td>Invoice Date</td>
                            <td>
                                <?php echo date('d/m/Y', STRTOTIME($modelInvoice->invoice_date)); ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Delivery No</td>
                            <td>
                                <?php echo $modelInvoice->delivery_ids; ?>
                            </td>
                        </tr>
                        <tr>
                            <td>Delivery Date</td>
                            <td>
                        <?php 
                            $model_delivery_note_date = DeliveryNote::model()->findAll(array('condition'=>'id IN ('.$modelInvoice->delivery_ids.')'));
                            $arr_delivery_date=array();
                            foreach($model_delivery_note_date as $b=>$delivery_date){
                              $arr_delivery_date[]=date('d/m/Y',STRTOTIME($delivery_date->delivery_date));
                            }
                        echo implode(',',$arr_delivery_date);?>
                    </td>
                        </tr>
                        <tr>
                            <td>Currency</td>
                            <td>
                                <?php echo $modelInvoice->currencyname->currency_code; ?>
                            </td>
                        </tr>
                        <tr>
                            <td>LPO</td>
                            <td>
                                <?php
                                echo $modelInvoice->order_lpo_no;
                                if ($modelInvoice->order_lpo_date!= '' && $modelInvoice->order_lpo_date!= '0000-00-00') {
                                    echo ',' . date("d/m/Y", strtotime($modelInvoice->order_lpo_date));
                                }
                                ?>
                            </td>
                        </tr>
                    </table>  



  <!--span>Date	:	<?php echo date('d/m/Y', STRTOTIME($modelInvoice->invoice_date)); ?></span><br />

  <span>LPO #	:	<?php echo $modelInvoice->order_details->lpo; ?></span><br />
  
  <span>LPO Date 	:	<?php echo date('d/m/Y', STRTOTIME($modelInvoice->invoice_date)); ?></span><br />
  
  <span>DO #	:	<?php echo $modelInvoice->order_details->lpo; ?></span><br />
  
  <span>DO Date	:	<?php echo date('d/m/Y', STRTOTIME($modelInvoice->invoice_date)); ?></span><br /-->

                </div>

            </div>


            <br/>
            <br/>
            <div style="float:left; width:100%; text-align:center;padding-top: 20px;">

                <div style="float:right;margin-right: 30%; width:60%;padding: 5px 10px; border: 1px solid #7D26CD;border-radius: 4px;font-size:18px;margin-top:4px;margin-bottom:8px;width:270px;" align="center">
                    <b>TAX INVOICE / <span style="font-family:tahoma;">فاتورة ضريبية </span></b>
                </div> 

                <!--Span  style="float:left; text-align:left; font-weight:bold; border-bottom:2px solid;margin-left: 39%;margin-bottom: 15px;font-size:20px; ">TAX INVOICE / فاتورة ضريبية</Span><br /-->

            </div>
            <br/>
            <div style="width:100%;float:left;padding-top:10px;font-size:9px; font-family:'Times New Roman', Times, serif">
                <table id="" class="table">
                    <thead>
                        <tr>
                            <th class="text-center bc-tl">Sr #</th>
                            <?php if ($type == 2) { ?>
                                <th class="text-left" style="width:15%">Part No</th>
                            <?php } ?>
                            <?php if ($type == 3) { ?>
                                <th class="text-left" style="width:15%">OEM No</th>
                            <?php } ?>

                            <th class="text-center" style="width:30%">Description</th>
                            <th class="text-center" style="width:4%">Qty</th>
                            <th class="text-center">Unit</th>
                            <th class="text-center" style="width:8%">Rate</th>
                            <th class="text-center">Total Discount</th>
                            <th class="text-center">Tax(%)</th>
                            <th class="text-center">Tax Amt</th>
                            <th class="text-center bc-tr">Net Amount</th>
                        </tr>
                    </thead>
                    <tbody>

                        <?php
                        $m = 1;
                        $condition .= '1=1';
                        $col = '9';
                        if ($type == 1) {
                            $col = $col - 1;
                        }
                        $condition .= ' AND t.invoice_id ="' . $id . '"';
                        $total = $total_vat = 0;
                        $modelInvoiceItem = InvoiceItem::model()->findAll(array('condition' => $condition));
                        foreach ($modelInvoiceItem as $i => $modelInvoiceItem) {

                            $batch_no = '';
                            $sl_no = '';

                            if ($modelInvoiceItem->inventory_type == 'H') {
                                $part_number = $modelInvoiceItem->product->hiring_part_number;
                                $oem_number = $modelInvoiceItem->product->oem_number;
                            } else {
                                $part_number = $modelInvoiceItem->product->part_number;
                                $oem_number = $modelInvoiceItem->product->oem_number;
                            }
                            ?>
                            <tr>
                                <td class="text-center">
                                    <?php echo $m; ?>
                                </td>
                                <?php if ($type == 2) { ?>
                                    <td>
                                        <?php echo $part_number; ?>
                                    </td>
                                <?php } ?>
                                <?php if ($type == 3) { ?>
                                    <td>
                                        <?php echo $oem_number; ?>
                                    </td>
                                <?php } ?>
                                <td>
                                    <?php echo nl2br($modelInvoiceItem->description); ?>
                                    <?php
                                    if ($modelInvoiceItem->product->have_expiry_date == 'Y') {
                                        $batch_no = StockLedger::getBatchNoWithExpDate($modelInvoice->delivery_ids, $modelInvoiceItem->product_id, 'DELIVERY_NOTE');
                                        ?>
                                        <hr style="width:105%;">
                                        <br/>
                                        Batch No:<?php echo $batch_no; ?>
                                    <?php } ?>
                                    <?php
                                    if ($modelInvoiceItem->product->have_serial_no == 'Y') {
                                        if ($modelInvoiceItem->inventory_type == 'H') {
                                            $sl_no = HiringPackageDetails::getSerialNo($modelInvoice->delivery_ids, $modelInvoiceItem->product_id);
                                        } else {
                                            $sl_no = StockLedger::getSerialNo($modelInvoice->delivery_ids, $modelInvoiceItem->product_id, 'DELIVERY_NOTE');
                                        }
                                        ?>
                                        <hr style="width:105%;">
                                        <br/>
                                        Serial No:<?php echo $sl_no; ?>
                                    <?php } ?>
                                </td>
                                <td class="text-right">
                                    <?php echo (int) $modelInvoiceItem->quantity; ?>
                                </td>
                                <td>
                                    <?php echo $modelInvoiceItem->product->unit->symbol; ?>
                                </td>
                                <?php $rate = $modelInvoiceItem->rate; ?>
                                <td class="text-right">
                                    <?php echo Yii::app()->numberFormatter->formatCurrency((($modelInvoiceItem->net_amount + $modelInvoiceItem->deduction_amount) / $modelInvoiceItem->quantity), " "); ?>
                                </td>
                                <td class="text-right">
                                    <?php echo $modelInvoiceItem->deduction_amount; ?>
                                </td>
                                <td class="text-right">
                                    <?php echo (int) $modelInvoiceItem->tax_vat_percentage; ?>
                                </td>
                                <td class="text-right">
                                    <?php echo $modelInvoiceItem->tax_vat_amount; ?>
                                </td>
                                <td class="text-right">
                                    <?php
                                    $net_amount = $modelInvoiceItem->net_amount + $modelInvoiceItem->tax_vat_amount;
                                    echo Yii::app()->numberFormatter->formatCurrency($net_amount, " ");
                                    ?>
                                </td>
                            </tr>

                            <?php
                            $m = $m + 1;
                            $total+=$modelInvoiceItem->net_amount;
                            $total_vat+=$modelInvoiceItem->tax_vat_amount;
                        }
                        ?>
                        <tr>
                            <td class="text-left"><b>Total</b></td>
                            <td class="text-left"  colspan="<?php echo $col - 1; ?>"><b>
                                    <?php
                                    if ($total > 0) {
                                        echo $modelInvoice->currencyname->currency_code . " " . ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval(($total))))->result) . ' only';
                                    } else {
                                        echo "FOC(Free Of Cost)";
                                    }
                                    ?>
                                </b></td>
                            <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total, " "); ?></b></td>
                        </tr>
                        <tr>

                            <td class="text-center"></td>
                            <td class="text-left"  colspan="<?php echo $col - 1; ?>"><b>Value Added Tax</b></td>
                            <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total_vat, " "); ?></b></td>
                        </tr>
                        <?php
                        $Addition = InvoiceAddition::model()->findAll(array('condition' => 'invoice_id=' . $id . ' AND calculated_value>0'));
                        $Dedution = InvoiceDeduction::model()->findAll(array('condition' => 'invoice_id=' . $id . ' AND calculated_value>0'));
                        if (!empty($Addition)) {
                            foreach ($Addition as $eachAddition) {
                                ?>
                                <tr>
                                    <?php
                                    $total+=$eachAddition->calculated_value;
                                    ?>
                                    <td class="text-right"  colspan="<?php echo $col; ?>">
                                        <?php
                                        echo MasFooterItems::getFooterItemName($eachAddition->particular);
                                        ?>
                                    </td>
                                    <td class="text-right">+
                                        <?php echo Yii::app()->numberFormatter->formatCurrency($eachAddition->calculated_value, " "); ?>
                                    </td>
                                </tr>
                                <?php
                            }
                        }
                        if (!empty($Dedution)) {
                            foreach ($Dedution as $eachDed) {
                                ?>
                                <tr>
                                    <?php
                                    $total-=$eachDed->calculated_value;
                                    ?>
                                    <td class="text-right"  colspan="<?php echo $col; ?>">
                                        <?php
                                        echo MasFooterItems::getFooterItemName($eachDed->particular);
                                        ?>
                                    </td>
                                    <td class="text-right">-
                                        <?php echo Yii::app()->numberFormatter->formatCurrency($eachDed->calculated_value, " "); ?>
                                    </td>
                                </tr>
                                <?php
                            }
                        }
                        ?>
                        <tr>
                            <td class="text-left"><b>G.Total</b></td>
                            <td class="text-left"  colspan="<?php echo $col - 1; ?>"><b>
                                    <?php
                                    if ($total > 0) {
                                        //echo $modelInvoice->currencyname->currency_code . " " . ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval(($total+$total_vat))))->result) . ' only'; 
                                        echo MasCurrency::number_to_currency(number_format(($total + $total_vat), 2, '.', ''), $modelInvoice->currency);
                                    } else {
                                        echo "FOC(Free Of Cost)";
                                    }
                                    ?>
                                </b></td>
                            <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency(($total + $total_vat), " "); ?></b></td>
                        </tr>
                        <!--tr>
                            <td class="text-right" colspan="<?php echo $col + 1; ?>"><b><?php
                        if ($total > 0) {
                            //echo $modelInvoice->currencyname->currency_code . " " . ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval(($total+$total_vat))))->result) . ' only'; 
                            echo MasCurrency::number_to_currency(number_format(($total + $total_vat), 2, '.', ''), $modelInvoice->currency);
                        } else {
                            echo "FOC(Free Of Cost)";
                        }
                        ?></b></td>
                        </tr-->
                    </tbody>
                </table>
            </div>
            <div>
                <?php
                /* echo '<pre>';
                  print_r($modelInvoice); */

                if ($modelInvoice->payment_terms != 0) {
                    ?>

                    <div class="box" style="width:100%">
                        <table class="" style="width:100%; page-break-inside:avoid;">
                            <tr>
                                <td>
                                    <h5 style="color: #7a1d8b;">Payment Terms</h5>
                                    <div class="h5sub-details">
    <?php echo nl2br($modelInvoice->paymentTerm->payment_terms); ?>
                                    </div>
                                </td>
                            </tr>
                        </table>
                    </div>
                <?php } ?>

                <?php
                $model = OwnerBankDetails::model()->find(array('condition' => 'currency_id=' . $modelInvoice->currency));
                if (empty($model))
                    $model = OwnerBankDetails::model()->find(array('condition' => 'currency_id=23'));
                if (!empty($model)) {
                    ?>


                    <div class="box"  style="width: 100%;">
                        <div class="h5sub-details">

                            <table class="" style="width:100%; page-break-inside:avoid;">
                                <tr>
                                    <td colspan="6">
                                        <h5 style="color: #7a1d8b;">Bank Details</h5>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">Account Name</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_account_name; ?></td>

                                    <td style="width: 90px">Account No</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_ac_no; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">Bank Name</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank->bank_name; ?></td>

                                    <td style="width: 90px">Bank Branch</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_branch; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">IBAN #</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_iban; ?></td>

                                    <td style="width: 90px">Swift Code</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_swift; ?></td>
                                </tr>
                            </table>
                            <?php /*
                              <?= 'Account Name : '.$model->bank_account_name ?><br>
                              <?= 'Account No   : '.$model->bank_ac_no ?><br>
                              <?= 'Bank Name    : '.$model->bank->bank_name ?><br>
                              <?= 'Bank Branch  : '.$model->bank_branch ?><br>
                              <?= 'IBAN #      : '.$model->bank_iban ?><br>
                              <?= 'Swift Code     : '.$model->bank_swift */ ?>
                        </div>
                    </div>
                <?php } ?>
                <?php
                if ($modelInvoice->terms_and_conditions != '') {
                    ?>
                    <!--                    <div class="box" style="width:100%">-->
                    <table style="width:100%; page-break-inside:avoid;" class="table_box" >
                        <tr>
                            <td>
                                <h5 style="color: #7a1d8b;">Terms & Conditions</h5>
                                <div class="h5sub-details">
                                    <?php echo nl2br($modelInvoice->terms_and_conditions); ?>
                                </div>
                            </td>
                        </tr>
                    </table>
                    <!--                    </div>-->
                    <?php
                }
                ?>
                <?php
                if ($modelInvoice->notes != '') {
                    ?>

                    <div class="box" style="width:100%">
                        <h5>Notes</h5>
                        <div class="h5sub-details">
                        <?php echo nl2br($modelInvoice->notes); ?>
                        </div>
                    </div>
                <?php } ?>

            </div>

            <br>
            <br>
            <div style="width:100%;float:left;font-size:12px;margin-top:5px; font-family:'Times New Roman', Times, serif">

                <div style="width:50%;float:left;">

                    <span>For and on behalf of,</span><br />

                    <span><b>ACE CENTRO ENTERPRISES</b></span>


                </div>



                <div style="width:50%;float:left;margin-left:105px;margin-top:5px; font-family:'Times New Roman', Times, serif">

                    <span>Terms and conditions accepted by:</span><br />

                    <span><b><?php echo strtoupper($modelInvoice->customer->customer_name); ?></b></span>

                </div>

            </div>



            <div style="width:100%;float:left; text-align:center;font-size:12px;">

                <p style="padding:0px;margin:0px;">Sign</p> 
                <p style="padding:0px;margin:0px;">Date</p> 
                <p style="padding:0px;margin:0px;">Stamp</p> 

            </div>



            <div style="width:100%;float:left;font-size:12px;">

                <div style="width:50%;float:left; font-family:'Times New Roman', Times, serif">


                    <div style="border-bottom:1px solid #000;width:150px; "></div>

                    <span><b>Name:</b></span><br />

                    <em>Finance Department</em><br />

                    <span>Cell : +971 55 504 0033</span><br />

                </div>

                <div style="width:50%;float:left;font-size:12px;margin-left:105px; font-family:'Times New Roman', Times, serif">


                    <div style="border-bottom:1px solid #000;width:150px;"></div>

                    <span><b><?php echo strtoupper($modelInvoice->contact->person_name); ?></b></span><br />

                    <em><?php if(!empty($modelInvoice->contact->designation)){ echo $modelInvoice->contact->designation;}else{?>Authorized Signatory<?php } ?></em><br />
 

                    <span>Cell : <?php echo strtoupper($modelInvoice->contact->contact_mobile_no); ?></span><br />




                </div>

            </div>





        </div>

    <htmlpagefooter name="firstfooter">
        <div style="text-align:right;width:100%;"><i>Contd...</i></div> 
        <div style="text-align:center;width:100%;"><img src="images/innovating.png" /></div> 
        <div style="text-align:center;width:100%;font-size:10px;font-family:'Times New Roman', Times, serif"> This invoice has been electronically generated by<?php echo $footer_company_name;?> on
            <?php  date_default_timezone_set("Asia/Dubai");
            echo date('d/m/Y h:i:s a',strtotime($modelInvoice->created_datetime)); ?> and is valid without signature.
        </div>
    </htmlpagefooter>
    <sethtmlpagefooter name="firstfooter" page="all" value="on" />

    <htmlpagefooter name="lastfooter">
        <div style="text-align:right;width:100%;">Contd...</div> 
        <div style="text-align:center;width:100%;"><img src="images/innovating.png" /></div> 
        <div style="text-align:center;width:100%;font-size:10px;font-family:'Times New Roman', Times, serif"> This invoice has been electronically generated by<?php echo $footer_company_name;?> on
            <?php  date_default_timezone_set("Asia/Dubai");
            echo date('d/m/Y h:i:s a',strtotime($modelInvoice->created_datetime)); ?> and is valid without signature.
        </div> 
    </htmlpagefooter>
    <sethtmlpagefooter name="lastfooter" value="off" />

    <htmlpagefooter name="myfooter">
        <div style="text-align:center;width:100%;"><img src="images/innovating.png" /></div> 
        <div style="text-align:center;width:100%;font-size:10px;font-family:'Times New Roman', Times, serif"> This invoice has been electronically generated by<?php echo $footer_company_name;?> on
            <?php  date_default_timezone_set("Asia/Dubai");
            echo date('d/m/Y h:i:s a',strtotime($modelInvoice->created_datetime)); ?> and is valid without signature.
        </div> 
    </htmlpagefooter>
    <sethtmlpagefooter name="myfooter" page="all" value="on" />


</body>

</html>


<?php //exit; ?>
