<!DOCTYPE html>
<html>

<head>
    <title>PURCHASE TAX INVOICE</title>
</head>

<body>

    <div class="">
        <div class="col-6">
            <br>
            <?php
                         $modelDirectOrder = DirectPurchaseOrderGeneral::model()->findByPk($id);
                         
                         if($modelDirectOrder->purchase_invoice_id > 0){
                            $modelQ1 = PurchasingInvoice::model()->findByPk($modelDirectOrder->purchase_invoice_id);
                            $invoice_type = $modelQ1->invoice_type;
                            $invoice_no = $modelQ1->invoice_no;
                             $invoice_type_name="";
                             if((int) $invoice_type > 0){
                                $modelInvoiceType = new MasInvoiceType();
                                $arr_invoice_type_details = $modelInvoiceType->findByPk((int) $invoice_type);
                                $inv_code      = $arr_invoice_type_details->inv_code;
                                
                                //$invoice_no=$inv_code.$invoice_no;
                                $invoice_type_name = $arr_invoice_type_details->inv_name;
                            }
                         }
                         
                         
                       
//                   $model_cust = Customers::model()->findByPk($modelDirectOrder->cust_id);
?>
                <!--<span style="color:#1e62a3;font-size: 18px;margin-bottom: 25px"><b><?php// echo $title." # ".$model->id;?></b></span><br>-->
                <div class="h3" style="margin-top: 0;margin-bottom: 0;">
                    <?php echo "PURCHASE TAX INVOICE"; ?>
                </div>
                <div class="input-block">
                    <b><?php echo $invoice_no;?></b>
                </div>
                <b><?php echo $modelDirectOrder->vendor_details->vendor_name; ?></b>
                <br/>
                <small><?php echo  ' '.$modelDirectOrder->vendor_details->vendor_address; ?><br/></small>
                <?php 
                if($modelDirectOrder->vendor_details->vendor_postal_code!="" || $modelDirectOrder->vendor_details->vendor_location!=""){
                ?>    
                <small>
                <?php echo  'PO Box : ';
                if(isset($modelDirectOrder->vendor_details->vendor_postal_code) && $modelDirectOrder->vendor_details->vendor_postal_code!=""){
                    echo  $modelDirectOrder->vendor_details->vendor_postal_code;
                }
                if($modelDirectOrder->vendor_details->vendor_postal_code!="" && $modelDirectOrder->vendor_details->vendor_location!=""){
                    echo ", ";
                }
                if(isset($modelDirectOrder->vendor_details->vendor_location) && $modelDirectOrder->vendor_details->vendor_location!=""){
                    echo $modelDirectOrder->vendor_details->vendor_location; 
                }
                ?><br/></small>
                <?php 
                }
                ?>
                
                <small><?php echo  $modelDirectOrder->vendor_details->vendor_city.', '.$modelDirectOrder->vendor_details->country->country_name; ?><br/></small>
                <small><?php echo  $modelDirectOrder->vendor_details->vendor_phone_no; ?><br/></small>
                
        </div>
        <div class="col-5 offset-1" style="color:#101010;">
            <?php $this->renderPartial("//common/header");?>
            <br>
            <table class="table" style="width:100%">
                <tr>
                    <td>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>
                 <?php if($modelDirectOrder->vendor_details->vendor_trn_no !='') { ?>     
                 <tr>
                    <td>Vendor TRN#</td>
                    <td><?php echo $modelDirectOrder->vendor_details->vendor_trn_no;?></td>
                </tr>
             <?php } ?>

                <tr>
                    <td>Order Date</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelDirectOrder->purchase_order_date));?>
                    </td>
                </tr>
                <tr>
                    <td>Invoice Date</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelQ1->invoice_date));?>
                    </td>
                </tr>
                
                <tr>
                    <td>REF#</td>
                    <td>
                        <?php echo $id; ?>
                    </td>
                </tr>
                
                <tr>
                    <td>Currency</td>
                    <td>
                        <?php 
                        $modelCurrency = new MasCurrency();
                        $modelCurrency = $modelCurrency->getCurrencyDetails($modelDirectOrder->currency);
                        echo $modelCurrency->currency_code;
                        if($modelCurrency->currency_code!="AED" && $modelQ->exchange_rate!=""){
                            echo "/".$modelQ->exchange_rate;
                        }
                        ?>
                    </td>
                </tr>
                <tr>
                    <td>Invoice Type</td>
                    <td>
                        <?php echo $invoice_type_name;?>
                    </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">Brand</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">Tax(%)</th>
                    <th class="text-center">Tax Amount</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>
                            <?php // echo $model_Quotes->product->brand_detail->brand_class_name;?>
                        </td>-->
                        <td class="text-right">
                            <?php echo (float)$model_Quotes->quantity;?>
                        </td>
                        <td>
                            <?php echo $model_Quotes->unit;?>
                        </td>
                        <?php //$rate=$model_Quotes->net_amount/$model_Quotes->quantity;?>
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->rate," ");?>
                        </td>
                         <td>
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->tax_percentage,"");?>
                        </td>
                        <td>
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->tax_amount,"");?>
                        </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></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 
                               $currency_id=1;
                               if((int) $modelDirectOrder->currency>0){
                                   $currency_id = $modelDirectOrder->currency;
                               }
                                
                                    $model_currency=MasCurrency::model()->findByPk($currency_id);
                                    $vat_base=$model_currency->exchange_rate*$modelDirectOrder->total_tax_amount;
                                echo "(".Yii::app()->numberFormatter->formatCurrency($vat_base," ")."), "; ?> <?php
                              
                                echo 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);
                                //echo $model_currency->currency_code." ". ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval($total)))->result) . ' only'; 
                                
                                ?></b></td>
                            </tr>
                            <!--          <tr>
       <td class="text-right" colspan="5"><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>
    
           <?php 
           if((int) $modelDirectOrder->currency>0){
           $model =  MasCompanyBankDetails::model()->find(array('condition' => 'currency_id='.$modelDirectOrder->currency)); 
          if(empty($model))
              $model =  MasCompanyBankDetails::model()->find(array('condition' => 'currency_id=1'));   
          
          if(!empty($model)){
    ?>
   

            <div class="box"  style="width: 100%;">
                <h5>Bank Details</h5>
                <div class="h5sub-details">
                    <?= '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 No      : '.$model->bank_iban ?><br>
                    <?= 'Swift No     : '.$model->bank_swift ?>
                </div>
            </div>
          <?php } 
           }
          ?>


<!--     <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> -->
     <?php $this->renderPartial("//common/footer");?>
</body>

</html>
