<!DOCTYPE html>
<html>

<head>
    <title>Purchase Invoice</title>
</head>

<body>
    <!--mpdf
    <htmlpagefooter name="html_myfooter">
        <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; ">
            <div style="text-align:center;width:100%">
                <b><?php// echo Yii::app()->user->master_company_name; ?></b>
                <br/>
                <?php //echo $model_Company->company_address; ?>
                <?php //echo '  '.$model_Company->company_location; ?>
                <?php //echo ' '.$model_Company->country->country_name; ?>
                <?php //echo 'Phone : '.Yii::app()->user->company_general_phone_no; ?> ,
                <?php //echo 'Email : '.Yii::app()->user->company_general_email; ?>
            </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div>
    </htmlpagefooter>
    <sethtmlpagefooter name="html_myfooter" value="on" />
    mpdf-->

    <!-- <div class="heading">
        <div class="logo col-6">

        </div>
        <div class="companay_name col-6 text-right">
        </div>
    </div> -->
    <div class="">
        <div class="col-6">
            <br>
            <?php $modelDirectOrder = DirectPurchaseOrderGeneral::model()->findByPk($id); ?>
                <div class="h3" style="margin-top: 0;margin-bottom: 0;">
                    <?php echo "PURCHASE INVOICE"; ?>
                </div>
                <div class="input-block">
                    <b><?php echo $id;?></b>
                </div>
                <b><?php echo $modelDirectOrder->vendor_details->vendor_name; ?></b>
                <br/>
                <small><?php echo  $modelDirectOrder->vendor_details->vendor_address; ?></small><br/>
                <small><?php echo  'PO Box : '.$modelDirectOrder->vendor_details->vendor_postal_code.', '.$modelDirectOrder->vendor_details->vendor_location; ?></small><br/>
                <small><?php echo  $modelDirectOrder->vendor_details->vendor_city.', '.$modelDirectOrder->vendor_details->country->country_name; ?></small><br/>
                <small><?php echo  $modelDirectOrder->vendor_details->vendor_phone_no; ?></small><br/>
                
        </div>
        <div class="col-5 offset-1" style="color:#101010;">
            <div class="text-right">
                <img src="<?php echo Yii::app()->baseUrl . '/images/logo/'.Yii::app()->user->pdf_company_logo; ?>" class="logo">
            </div>
            <br>
            <table class="table" style="width:100%">
                    <tr>
                        <td class="bc-tl">File ID</td>
                        <td>
                            <?php echo $modelDirectOrder->file_id;?>
                        </td>
                    </tr>
                <tr>
                    <td>Vendor ID</td>
                    <td>
                        <?php echo $modelDirectOrder->vendor_details->id;?>
                    </td>
                </tr>
                 <tr>
                    <td>Vendor TRN#</td>
                    <td><?php echo $modelDirectOrder->vendor_details->vendor_trn_no;?></td>
                </tr>
                <tr>
                    <td>Invoice No</td>
                    <td>
                        <?php echo $modelDirectOrder->invoice_no;?>
                    </td>
                </tr>

                <tr>
                    <td>Date</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelDirectOrder->purchase_order_date));?>
                    </td>
                </tr>
                <tr>
                    <td>Currency</td>
                    <td>
                        <?php echo $modelDirectOrder->purchase_currency->currency_code;?>
                    </td>
                </tr>
             
                
            </table>
        </div>
    </div>
    <br>
    <div class="col-md-12">
        <table id="" class="table">
            <thead>
                <tr>
                    <th class="text-center bc-tl">No</th>
                    <th class="text-center">Part No</th>
                    <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">VAT</th>
                    <th class="text-center" style="width:8%">Rate</th>
                    <th class="text-center bc-tr">Net Amount</th>
                </tr>
            </thead>
            <tbody>
               
                    <?php
              
               echo  $condition = 'purchase_order_id ="' .$id.'"';
                $total=0;
               
                $items = DirectPurchaseOrderItems::model()->findAll(array('condition'=>$condition));
                $m =1;
                foreach ( $items as $i =>  $model_Quotes) { ?>
         
                 <tr>
                        <td>
                            <?php echo $m;?>
                        </td>
                       <td>
                            <?php echo $model_Quotes->product->part_number;?>
                        </td>
                        <td>
                            <?php echo nl2br($model_Quotes->product_description);?>
                        </td>
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->quantity," ");?>
                        </td>
                        <td>
                            <?php echo $model_Quotes->unitdetails->name.'(1x'.$model_Quotes->unitdetails->factor.')';?>
                        </td>
                        <td>
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->tax_amount," ")." ( ".$model_Quotes->tax_percentage."% )";?>
                        </td>
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->rate," ");?>
                        </td>
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->net_amount," ");?>
                        </td>
                </tr>
                
                    <?php
                        $m=$m+1;
                        $total+=$model_Quotes->net_amount;
       
        }
        ?>
                    <tr>
                        <td class="text-right" colspan="7"><b>Net Total  </b></td>
                        <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total," ");?></b></td>
                    </tr>
                <?php
                    echo $condition='purchasing_order_id="'.$modelDirectOrder->id.'" AND calculated_value>0';
                    $Addition=DirectPurchasingOrderAddition::model()->findAll(array('condition'=>$condition));
                    $Dedution=DirectPurchasingOrderDeduction::model()->findAll(array('condition'=>$condition));
                    if(!empty($Addition))
                    {
                        foreach ($Addition as $eachAddition)
                        {
                      ?>
                    <tr>
                        <?
                        $total+=$eachAddition->calculated_value;
         ?>
                            <td class="text-right" colspan="7">
                                <?php
                        echo FooterItems::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>
                            <?
                        $total-=$eachDed->calculated_value;
         ?>
                                <td class="text-right" colspan="7">
                                    <?php
                        echo FooterItems::getFooterItemName($eachDed->particular);
                        ?>
                                </td>
                                <td class="text-right">-
                                    <?php echo Yii::app()->numberFormatter->formatCurrency($eachDed->calculated_value," ");?>
                                </td>
                        </tr>
                        <?php
                    }
                    }
                    ?>
                             <tr>
                                <td class="text-right" colspan="7"><b>VAT</b></td>
                                <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($modelDirectOrder->total_tax_amount," ");?></b></td>
                            </tr>
                            <tr>
                                <td class="text-right" colspan="8"><b>VAT Amount in AED  <?php 
                                    $model_currency=MasCurrency::model()->findByPk($modelDirectOrder->purchase_currency->id);
                                    $vat_base=$model_currency->exchange_rate*$modelDirectOrder->total_tax_amount;
                                echo Yii::app()->numberFormatter->formatCurrency($vat_base," "); ?>; <?php
                              
                                echo  "AED " . ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval(($vat_base))))->result) . ' only';  ?></b></td>
                            </tr>
                            <?php  $total+=$modelDirectOrder->total_tax_amount; ?>
                            <tr>
                                <td class="text-right total bc-bl" colspan="7"><b>Grand Total  </b></td>
                                <td class="text-right total bc-br"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total," ");?></b></td>
                                
                            </tr>
                            <tr>
                                <td class="text-right" colspan="8"><b><?php 
                                 echo MasCurrency::number_to_currency(number_format(($total), 2, '.', ''), $modelDirectOrder->currency_id);
                                //echo $modelDirectOrder->purchase_currency->currency_code . " " . ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval($total)))->result) . ' only'; ?></b></td>
                            </tr>
                            <!--          <tr>
       <td class="text-right" colspan="8"><b><?php //echo ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval($total)))->result) . ' only';  ?></b></td>
                    </tr>-->
            </tbody>
        </table>
        
        <?php if($modelDirectOrder->terms_and_conditions!='')
       {
       ?>
        <div class="box">
            <h5>Terms and Conditions</h5>
            <div class="h5sub-details">
                <?php echo nl2br($modelDirectOrder->terms_and_conditions); ?>
            </div>
        </div>
        <?php
       }
      ?>
        <?php if($modelDirectOrder->remarks!='')
       {
       ?>
        <div class="box">
            <h5>Remarks</h5>
            <div class="h5sub-details">
                <?php echo nl2br($modelDirectOrder->remarks); ?>
            </div>
        </div>
        <?php } ?>
            <?php if($modelDirectOrder->notes!='')
       {
       ?>
            <div class="box">
                <h5>Notes</h5>
                <div class="h5sub-details">
                    <?php echo  nl2br($modelDirectOrder->notes); ?>
                </div>
            </div>
            <?php } ?>
    </div>


<!--     <div style="text-align:center;width:100%;font-size:10px;">This report is auto generated by Bluesky ERP on
        <?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')." ".date("h:i:sa"); ?>
    </div> -->
    <htmlpagefooter name="myfooter">


    <div style="text-align:center;width:100%;font-size:10px;">This report is auto generated by Bluesky ERP on
        <?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')." ".date("h:i:sa"); ?>
    </div>



         <div style="border-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; background-color: #d7faeb;">
        <div style="binvoice-top: 1px dotted #000000; font-size: 12px; text-align: center; padding-top: 10px; ">
            <div style="text-align:center;width:100%">
                   <?php 
                $model_Company = MasCompany::model()->find(); ?>
                <b><?php echo $model_Company->company_name; ?></b>
                <br/>
             <?php 
                echo $model_Company->billing_address; ?>
                <?php echo '  '.$model_Company->billing_city; ?>
                <?php// echo ' '.$model_Company->country->country_name; ?>
                <?php echo 'Phone : '.$model_Company->genral_phno ; ?> ,
                <?php echo 'Email : '.$model_Company->genral_email; ?>
            </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div></div>
    </htmlpagefooter>
        <sethtmlpagefooter name="myfooter" page="all" value="on" />
</body>

</html>
