<!DOCTYPE html>
<html>

<head>
    <title>SALES INVOICE</title>
</head>

<body>
    <div class="">
        <div class="col-6">
            <br>
            <?php
                         $modelDirectOrder = DirectOrder::model()->findByPk($id);
?>

                <div class="h3" style="margin-top: 0;margin-bottom: 0;">
                    <?php echo "SALES INVOICE"; ?>
                </div>
                <div class="input-block">
                    <b><?php echo $id;?></b>
                </div>
                <b><?php echo $modelDirectOrder->customer_details->customer_name; ?></b>
                <br/>
                <small><?php echo  ' '.$modelDirectOrder->customer_details->customer_address; ?><br/></small>
                <?php 
                if($modelDirectOrder->customer_details->customer_postal_code!="" || $modelDirectOrder->customer_details->customer_location!=""){
                ?>    
                <small>
                <?php echo  'PO Box : ';
                if(isset($modelDirectOrder->customer_details->customer_postal_code) && $modelDirectOrder->customer_details->customer_postal_code!=""){
                    echo  $modelDirectOrder->customer_details->customer_postal_code;
                }
                if($modelDirectOrder->customer_details->customer_postal_code!="" && $modelDirectOrder->customer_details->customer_location!=""){
                    echo ", ";
                }
                if(isset($modelDirectOrder->customer_details->customer_location) && $modelDirectOrder->customer_details->customer_location!=""){
                    echo $modelDirectOrder->customer_details->customer_location; 
                }
                ?><br/></small>
                <?php 
                }
                ?>
                
                <small><?php echo  $modelDirectOrder->customer_details->customer_city.', '.$modelDirectOrder->customer_details->country->country_name; ?><br/></small>
                <small><?php echo  $modelDirectOrder->customer_details->customer_phone_no; ?><br/></small>
                
        </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>Customer ID</td>
                    <td>
                        <?php echo $modelDirectOrder->customer_details->id;?>
                    </td>
                </tr>
                 <tr>
                    <td>TRN No.</td>
                    <td>
                        <?php echo $modelDirectOrder->customer_details->customer_trn_no;?>
                    </td>
                </tr>

                <tr>
                    <td>Date</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelDirectOrder->order_date));?>
                    </td>
                </tr>
             
                
            </table>
        </div>
    </div>
    <br>
    <div class="col-md-12">
        <table id="" class="table">
            <thead>
                <tr>
                    <th class="text-center">No</th>
<!--                    <th class="text-center">Part No</th>-->
                    <th class="text-center">Description</th>
                    <!--<th class="text-center">Brand</th>-->
                    <th class="text-center">Qty</th>
<!--                    <th class="text-center">Unit</th>-->
                    <th class="text-center">Rate</th>
                     <th class="text-center">Tax</th>
                    <th class="text-center">Net Amount</th>
                </tr>
            </thead>
            <tbody>
               
                    <?php
              
               echo  $condition = 'order_id ="' .$id.'"';
                $total=$total_vat=0;
               
                $items = DirectOrderItem::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->description);?>
                        </td>
<!--                        <td>
                            <?php // echo $model_Quotes->product->brand_detail->brand_class_name;?>
                        </td>-->
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->quantity," ");?>
                        </td>
<!--                        <td>
                            <?php// echo $model_Quotes->invoiceunit->symbol;?>
                        </td>-->
                        <?php //$rate=$model_Quotes->amount/$model_Quotes->quantity;?>
                        <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->tax_amount," ");?> (<?= $model_Quotes->tax_percentage.'%' ?>)
                        </td>
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->amount," ");?>
                        </td>
                </tr>
                
                    <?php
                        $m=$m+1;
                        $total+=$model_Quotes->amount;
                        $total_vat+=$model_Quotes->tax_amount;
       
        }
        ?>
                    <tr>
                        <td class="text-right" colspan="5"><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='order_id="'.$modelDirectOrder->id.'" AND calculated_value>0';
                    $Addition=DirectOrderAddition::model()->findAll(array('condition'=>$condition));
                    $Dedution=DirectOrderDeduction::model()->findAll(array('condition'=>$condition));
                    if(!empty($Addition))
                    {
                        foreach ($Addition as $eachAddition)
                        {
                      ?>
                    <tr>
                        <?
                        $total+=$eachAddition->calculated_value;
         ?>
                            <td class="text-right" colspan="5">
                                <?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="5">
                                    <?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="5"><b>VAT  </b></td>
                            <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total_vat," ");?></b></td>
                        </tr>
                        <tr>
                            <td class="text-right" colspan="6"><b>VAT IN WORDS</b></td>
                        </tr>
                            <tr>
                                <td class="text-right total bc-bl" colspan="5"><b>Grand Total  </b></td>
                                <!--<td></td>-->
                                <td class="text-right total bc-br"><b><?php echo Yii::app()->numberFormatter->formatCurrency(($total+$total_vat)," ");?></b></td>
                            </tr>
                            <tr>
                                <td class="text-right" colspan="6"><b><?php echo $modelDirectOrder->currency_details->currency . " " . ucfirst($this->widget('ext.NumtoWord.NumtoWord', array('num' => floatval(($total+$total_vat))))->result) . ' only'; ?></b></td>
                            </tr>
            </tbody>
        </table>
 
    </div>
 

  
   <htmlpagefooter name="myfooter">

      <div style="text-align:center;width:100%;font-size:10px"><?= Yii::app()->user->footer_autogenerated; ?>
        <?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="text-align:center;width:100%">
                <b><?= Yii::app()->user->footer_line_1 ?></b><br>
                <?= Yii::app()->user->footer_line_2 ?>
            </div>
            <div style="text-align:center;width:100%">Page {PAGENO} of {nb} </div>
        </div>
    </htmlpagefooter>
</body>

</html>
