<!DOCTYPE html>
<html>
    <?php 
    /**
    * Last Modified By Jobin
    */
        $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_count           = $privillage_modal->count(array('condition'=>$privillage_condition));
        $privillage_settings_module = $privillage_modal->find();
        $master_permission        = $privillage_settings_module->permissions;
        $master_permission_array  = json_decode($master_permission, true);
    ?>

<head>
    <title>Quotes List</title>
</head>

<body>
    <div class="">
        <div class="col-6">
            <br>
            <?php
                         $modelQ1 = Quotes::model()->findByPk($id);
?>
                <div class="h3" style="margin-top: 0;margin-bottom: 0;">
                    <?php echo QUOTATION; ?>
                </div>
                <div class="input-block">
                    <b><?php echo $id;?></b>
                </div>
                <b><?php echo strtoupper($modelQ1->customer->customer_name); ?></b>
                <br>    
                <?php if($modelQ1->billing_address != '') {     ?>       
                <small><?php echo strtoupper(nl2br($modelQ1->billing_address)); ?></small><br>
                    <?php } ?>                
                <?php if($modelQ1->customer->customer_phone_no != '') { ?>
                <small>Phone : <?php echo strtoupper($modelQ1->customer->customer_phone_no); ?></small><br>
                <?php } ?>
                <?php if($modelQ1->customercontact->person_name != '') { ?>
                <br><small>Kind Attn:</small>
                <small><b><?php echo  strtoupper($modelQ1->customercontact->person_name); ?></b></small><br>
                <?php } ?>
        </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"-->
                <img src="<?php echo 'images/logo/'.Yii::app()->user->pdf_company_logo; ?>" class="logo">
            </div>
            <br>
            <table class="table" style="width:100%">
                <tr>
                    <?php
            $modelQ = Quotes::model()->findByPk($id);
            $model_lead=Lead::model()->find(array('condition'=>'file_id="'.$modelQ->file_id.'"'));
            ?>
                        <td class="bc-tl">File ID</td>
                        <td>
                            <?php echo $modelQ->file_id;?>
                        </td>
                </tr>
                <tr>
                    <td>Customer ID</td>
                    <td>
                        <?php echo $modelQ->customer_id;?>
                    </td>
                </tr>
                <tr>
                    <td>Customer TRN #</td>
                    <td>
                        <?php echo $modelQ->customer->customer_trn_no;?>
                    </td>
                </tr>
                <tr>
                    <td>Customer Shj. Imp. Code</td>
                    <td>
                        <?php echo $modelQ->customer->customer_shj_imp_code;?>
                    </td>
                </tr><tr>
                    <td>Qtn. Date</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelQ->qtn_start_date));?>
                    </td>
                </tr>
                <tr>
                    <td>Qtn. Validity</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelQ->qtn_validity));?>
                    </td>
                </tr>
                <tr>
                    <td>Project Reference</td>
                    <td>
                        <?php echo $modelQ->project_reference;?>
                    </td>
                </tr>
                <tr>
                    <td>Currency</td>
                    <td>
                        <?php echo $modelQ->currency0->currency_code;?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <?php echo $modelQ->leadowner->first_name.' '.$modelQ->leadowner->last_name.' , '.$modelQ->leadowner->phno;?>
                    </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%">Brand/Class</th>
                    <?php if(isset($master_permission_array['inventory_image_show_quotation'])){ ?>
                    <th class="text-center">Image</th>
                    <?php } ?>
                    <th class="text-center" style="width:4%">Qty</th>
                    <th class="text-center" style="width:4%">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
                $m=1;
                $condition .= '1=1';
                $condition .= ' AND t.quotes_id ="' . $id.'"';
                $total=0;
                $total_vat_amt  = 0;
                $model_Quotes = QuotesItem::model()->findAll(array('condition'=>$condition,'order' => 'id ASC'));
                foreach ( $model_Quotes as $i =>  $model_Quotes) { ?>
                 
                    <?php 
//                    else if($model_Quotes->checked==1)
//                    {
                       /* if($model_Quotes->product->inventory_type == '2'){
                        ?>
                        <tr class="bg-theme">
                            <td colspan="10"><?php echo $model_Quotes->description;?></td>
                        </tr>
                
                        <?php
                        }else */
                    if($model_Quotes->product_id == 999999){ ?>
                              <tr style="background-color:  #d0f5c5 ; color: white;"><td colspan="10"><b><?php echo $model_Quotes->description;?></b></td></tr>
                     <?php   }
                    else
                    { ?>
                      
              
                        <tr style="<?php if($model_Quotes->checked==0){echo 'background-color:#f0cfcf';} ?>">
                        <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 nl2br($model_Quotes->product->brand_detail->product_class);?>
                        </td>
                        <?php if(isset($master_permission_array['inventory_image_show_quotation'])){ ?>
                        <td>
                           <?php if($model_Quotes->product->item_image != ''){ ?>
                           <img width="150" src="<?php echo Yii::app()->baseUrl . '/uploads/inventoryimages/'.$model_Quotes->product->item_image; ?>">
                           <?php } ?>
                        </td>
                        <?php } ?>
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->quantity," ");?>
                        </td>
                        <td>
                            <?php 
                             if($model_Quotes->product->inventory_item_type == 2){
                                $unit_name = 'N/A';
                            }
                            elseif($model_Quotes->product->inventory_item_type == 4){
                                $unit_name = $model_Quotes->dummyquoteunit->symbol;
                            }
                            else{
                                $unit_name = $model_Quotes->quoteunit->name;
                            }
                            
                            echo $unit_name; 
                            //echo $model_Quotes->quoteunit->name;?>
                        </td>
                         <?php $rate= ( $model_Quotes->quantity > 0 ) ? ($model_Quotes->amount+$model_Quotes->addition_amount)/$model_Quotes->quantity : 0;?>
                        <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($rate," ");?>
                        </td>
                        <!--tax- start-->
			<td class="text-right">
                            <?php echo $model_Quotes->tax_vat_percentage;?>
                        </td>
			<td class="text-right">
                            <?php $taxamount=  $model_Quotes->tax_vat_amount;
							echo $taxamount;
							?>
                        </td>
			<!--tax- end-->

						
                        <td class="text-right">
                            <?php  $net_amount = $model_Quotes->net_amount/* + $model_Quotes->tax_vat_amount*/;
                            
                            $net_amount_ot= ($net_amount+$taxamount);
                            
                            if($model_Quotes->checked==1){echo Yii::app()->numberFormatter->formatCurrency($net_amount_ot," ");}else{ echo ''; };?>
                        </td>
                </tr>
                
                    <?php
                        $m=$m+1;
                        $total_vat_amt+=$model_Quotes->tax_vat_amount; 
                        if($model_Quotes->checked == 1)
                            $total+=$model_Quotes->net_amount;
                    }
       // }
        } 
        
        ?>
        <tr>
            <?php
            if(isset($master_permission_array['inventory_image_show_quotation'])){
                $col = "10";
            }else{
                  $col = "9";
            } ?>
                        <td class="text-right" colspan="<?php echo $col; ?>"><b>Grand Total Without VAT  </b></td>
                        <!--<td></td>-->
                        <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total," ");?></b></td>
                </tr>
                
                <tr >
                         <td class="text-right"  colspan="<?php echo $col; ?>"><b>VAT</b></td>
                         <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total_vat_amt," ");?></b></td>
                    </tr>
                
                <?php
                    $Addition=QuotesAddition::model()->findAll(array('condition'=>'quotes_id='.$modelQ->id.' AND calculated_value>0'));
                    $Dedution=QuotesDeduction::model()->findAll(array('condition'=>'quotes_id='.$modelQ->id.' AND calculated_value>0'));
                    if(!empty($Addition))
                    {
                        foreach ($Addition as $eachAddition)
                        {
                      ?>
                    <tr>
                        <?
                        $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>
                            <?
                        $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
                    }
                    }
                    $total+=$total_vat_amt;
                    ?>
                            <tr>
                                <td class="text-right total bc-bl" colspan="<?php echo $col; ?>"><b>Grand Total With VAT  </b></td>
                                <!--<td></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="<?php echo $col+1; ?>"><b><?php echo $modelQ->currencyname->currency . " " . 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>
     
    </div>


       <?php if($modelQ->payment_terms!=0)
       {
       ?>
    <br>
    <div  style="width: 100%">
<!--        <small>**VAT Charges as will be applicable</small><br><br>-->
            <h5>Payment Terms</h5>
            <div class="h5sub-details">
                <?php echo  nl2br($modelQ->paymentTerm->payment_terms); ?>
            </div>
        </div>
        <?php } ?>
        <?php if($modelQ->terms_and_conditions!='')
       {
       ?>
        <div  style="width: 100%">
            <h5>Terms and Conditions</h5>
            <div class="h5sub-details">
                <?php echo nl2br($modelQ->terms_and_conditions); ?>
            </div>
        </div>
        <?php
       }
      ?>
          <?php //if($modelQ->remarks!='')
      // {
       ?>
<!--            <div  style="width: 100%">
                <h5>Remarks</h5>
                <div class="h5sub-details">
                    <?php // echo  nl2br($modelQ->remarks); ?>
                </div>
            </div>-->
            <?php //} ?>
            <?php if($modelQ->notes!='')
       {
       ?>
            <div  style="width: 100%">
                <h5>Notes</h5>
                <div class="h5sub-details">
                    <?php echo  nl2br($modelQ->notes); ?>
                </div>
            </div>
            <?php } ?>
            <br>
            <div style="text-align:center;">Stock is subject to previous sale</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>-->

    <img src="<?php echo  'images/logo/pdf_logo_footer.png'; ?>"/>
<!--        <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>

    <style type="text/css">
   div { page-break-inside:auto;
    page-break-inside:avoid; 
    page-break-after:auto;

      }

</style>

</body>

</html>
