<style type="text/css">

@media print {
}
</style>
<!DOCTYPE html>
<html>
    <?php 

        $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(array('condition'=>$privillage_condition));
        $master_permission        = $privillage_settings_module->permissions;
        $master_permission_array  = json_decode($master_permission, true);
        
        $bonus_quantity             = $privillage_settings_module->bonus_quantity;
    ?>

<head>
    <title>Quotes</title>
    <style>
        .table_box {
            border-collapse:separate!important;
            margin-top: 10px;                      
            padding: 10px;
            font-size:16px!important;
            border: 1px solid #0066ff;
            border-radius:6px;   
        }
    </style> 
</head>

<body>  
   <?php $this->renderPartial("//common/header");?>
    <div class="main">
        <div class="col-4">
            <?php
                $modelQuotation = Quotes::model()->findByPk($id);
               
            ?>
                <div class="input-block">
                    <b> QTN # : <?php echo $id;?></b>
                </div>
                <b><?php echo strtoupper($modelQuotation->customer->customer_name); ?></b>
                <br>    
                <?php if($modelQuotation->billing_address != '') {     ?>       
                <small><?php echo strtoupper(nl2br($modelQuotation->billing_address)); ?></small><br>
                    <?php } ?>                
                <?php if($modelQuotation->customer->customer_phone_no != '') { ?>
                <small>Phone : <?php echo strtoupper($modelQuotation->customer->customer_phone_no); ?></small><br>
                <?php } ?>
                <?php if($modelQuotation->customercontact->person_name != '') { ?>
                <br><small>Kind Attn:</small>
                <small><b><?php echo  strtoupper($modelQuotation->customercontact->person_name); ?></b></small><br>
                <?php } ?>
                <?php if ($modelQuotation->rfq_title != '') { ?>
                    <br><small>RFQ No:</small>
                    <small><b><?php echo $modelQuotation->rfq_title; ?></b></small><br>
                <?php } ?>
                 <?php if ($modelQuotation->file_title != '') { ?>
                    <br><small>RFQ Title:</small>
                    <small><b><?php echo $modelQuotation->file_title; ?></b></small><br>
                <?php } ?>
        </div>
            <div class="col-4">
                <div class="h3" style="margin-top: 0;margin-bottom: 0;text-align: center;color: #000000;font-size: 14px;">
                    <?php echo 'QUOTATION'; ?>
                </div>
            </div>
        <div class="col-4" style="color:#101010;">
            <table class="table" style="width:100%">
<!--                <tr>
                    <?php
            $model_lead=Lead::model()->find(array('condition'=>'file_id="'.$modelQuotation->file_id.'"'));
            ?>
                        <td class="bc-tl">File ID</td>
                        <td>
                            <?php echo $modelQuotation->file_id;?>
                        </td>
                </tr>
                <tr>
                    <td>Customer ID</td>
                    <td>
                        <?php echo $modelQuotation->customer_id;?>
                    </td>
                </tr>-->
                <tr>
                    <td>Customer TRN #</td>
                    <td>
                        <?php echo $modelQuotation->customer->customer_trn_no;?>
                    </td>
                </tr>
                <tr>
                    <td>Qtn. Date</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelQuotation->qtn_start_date));?>
                    </td>
                </tr>
                <tr>
                    <td>Qtn. Validity</td>
                    <td>
                        <?php echo date('d/m/Y',STRTOTIME($modelQuotation->qtn_validity));?>
                    </td>
                </tr>
                <tr>
                    <td>Currency</td>
                    <td>
                        <?php echo $modelQuotation->currency0->currency_code;?>
                    </td>
                </tr>
                <?php if ($modelQuotation->revision != '') { ?>
                <tr>
                    <td>Revision#</td>
                    <td>
                        <?php echo $modelQuotation->revision;?>
                    </td>
                </tr>
                <?php } ?>
                <tr>
                    <td>Payment Terms</td>
                    <td>
                        <?php echo $modelQuotation->paymentTerm->payment_terms;?>
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                    <?php echo $modelQuotation->leadowner->fullname.' , '.$modelQuotation->leadowner->phno.' , '; ?>
                    <br>
                    <?php echo $modelQuotation->leadowner->email; ?>
                    </td>
                </tr>
            </table>
        </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" style="width:15%">Part No</th>
                    <th class="text-center" style="width:20%">Description</th>
                    <?php if(isset($master_permission_array['inventory_image_show_quotation']) && $type==2){ ?>
                    <th class="text-center">Image</th>
                    <?php } ?>
                    <th class="text-center">Qty</th>
                    <?php if($bonus_quantity=="Y"){ ?>
                     <th class="text-center">Bonus Qty</th>                     
                     <?php } ?>
                     <th class="text-center">Unit</th>
                    <th class="text-center">Unit Price</th>
                    <th class="text-center">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;
                $tot_tax = 0;
                $condition .= '1=1';
                $condition .= ' AND t.quotes_id ="' . $id.'"';
                $total=0;
                $total_cbm=0;
                $total_weight=0;
                $count_alternate_ids = QuotesItem::model()->count(array('condition'=>'alternate_id!="" AND t.quotes_id ="' . $id.'"'));
                if($count_alternate_ids>0){
                    $order_by='alternate_id ASC';
                }
                else{
                    $order_by='id ASC';
                }
                $model_Quotes = QuotesItem::model()->findAll(array('condition'=>$condition,'order' => $order_by));
                foreach ( $model_Quotes as $i =>  $model_Quotes) { ?>
                    <?php   ( $model_Quotes->tax_vat_percentage > 0 )  ? $model_Quotes->tax_vat_amount = $model_Quotes->tax_vat_amount : $model_Quotes->tax_vat_amount = '0.00'; ?>
                    <?php
                    if($model_Quotes->product->inventory_item_type == 3){//memo ?>
                              <tr style="background-color:  #d0f5c5 ; color: white;"><td colspan="11"><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 
                            if($count_alternate_ids>0){
                                echo $model_Quotes->alternate_id;
                            }
                            else
                            {
                                echo $m;
                            }
                            ?>
                        </td>
                        <td>
                            <?php echo $model_Quotes->product->part_number;?>
                        </td>
                        <td>
                            <?php echo nl2br($model_Quotes->description); ?>
                        </td>
                       <?php if(isset($master_permission_array['inventory_image_show_quotation']) && $type==2){ ?>
                        <td>
                          <?php if($model_Quotes->product->item_image != ''){ ?>
                           <img width="120" height="120" src="<?php echo 'uploads/inventoryimages/thumbs/'.$model_Quotes->product->item_image; ?>">
                           <?php }
                           elseif($model_Quotes->image_file_name != ''){ ?>
                           <img width="120" height="120" src="<?php echo 'uploads/quotationimage/'.$model_Quotes->image_file_name; ?>">
                           <?php }?>
                        </td>
                        <?php } ?>
                        <td class="text-right">
                            <?php echo ( $model_Quotes->product->inventory_item_type == 2 ) ? 'N/A' : (float) $model_Quotes->quantity;?>
                        </td>
                        <?php if($bonus_quantity=="Y"){ ?>
                            <td class="text-right">
                                <?php echo ( $model_Quotes->product->inventory_item_type == 2 ) ? 'N/A' : (float) $model_Quotes->bonus_qty;?>
                            </td>
                        <?php } ?>
                        <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; ?>
                        </td>
                        <!-- <td  class="text-right" >
                       <?php 
                    //    $ava_qty=$model_Quotes->product->totalQuantity;
                    //     $exStock = $model_Quotes->quantity<=$ava_qty ? (float) $model_Quotes->quantity: (float) $ava_qty;
                        
                    //    echo ( $model_Quotes->product->inventory_item_type == 2 ) ? 'N/A' :  $exStock ?></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>
                         <td class="text-right">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->deduction_amount," ");?>
                        </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 'N/A'; };?>
                        </td>
                        
                </tr>
                
                    <?php
                        $m=$m+1;
                        if($model_Quotes->checked == 1)
                        
                         if($unit_name=='Carton'){
                                
                                $item_cbm = $model_Quotes->product->cubic_meter;
                                $item_weight = $model_Quotes->product->weight;
                                $total_cbm+=($model_Quotes->quantity * $item_cbm);
                                $total_weight+=($model_Quotes->quantity * $item_weight);
                            }
                            $total+=$model_Quotes->net_amount;
                            $tot_tax += $model_Quotes->tax_vat_amount;
                    }
       // }
        } ?>
                    <?php
                $col = "9";
                if($type==2){
                    $col = "10";
                }
                if($bonus_quantity=="Y"){
                    $col = "11";
                } ?>
                <?php if( $modelQuotation->total_tax_amount > 0 ) : ?> 
                <tr>
                        <td class="text-right" colspan="<?php echo $col; ?>"><b>Total</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($tot_tax," ");?></b></td>
                </tr>
                <?php endif; ?>
                <?php
                    $Addition=QuotesAddition::model()->findAll(array('condition'=>'quotes_id='.$modelQuotation->id.' AND calculated_value>0'));
                    $Dedution=QuotesDeduction::model()->findAll(array('condition'=>'quotes_id='.$modelQuotation->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
                    }
                    }
                    ?>
                            <tr>
                                <td class="text-right total bc-bl" colspan="<?php echo $col; ?>"><b>Grand Total</b></td>
                                <!--<td></td>-->
                                <?php $total += $tot_tax; ?>
                                <td class="text-right total bc-br"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total," ");?></b></td>
                            </tr>
                            <tr>
                                <?php
      $fcurrency=new MasCurrency();
   ?>
                                <td class="text-right" colspan="<?php echo $col+1; ?>"><b><?php echo $fcurrency->number_to_currency(number_format(($total), 2, '.', ''), $modelQuotation->currency); ?></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>
      
    </div>
    <!--
    <div class="box" style="width:100%">   
            <h5>Please ensure that all items are quoted in Carton</h5>
            <div class="h5sub-details" style="font-size: 10px;">Total CBM : <b><?php //echo $total_cbm;?> </b>CBM</div>
            <div class="h5sub-details" style="font-size: 10px;">Total Weight : <b><?php //echo $total_weight;?> </b>KG</div>
            
    </div>-->
    
      <?php
        if ($modelQuotation->terms_and_conditions != '') {
            ?>
            <div class="box" style="width:100%">    <h5>Terms and Conditions</h5>
                <div class="h5sub-details" style="font-size: 10px;">
            <?php echo nl2br($modelQuotation->terms_and_conditions); ?>
                </div>
            </div>
            <?php
        }
        
        if ($modelQuotation->notes != '') {  ?>
            <div class="box" style="width:100%">    <h5>Notes</h5>
                <div class="h5sub-details" style="font-size: 10px;">
                    <?php echo nl2br($modelQuotation->notes); ?>
                </div>
            </div>
        <?php } ?>
        
         <?php   if ($modelQuotation->remarks != '') {  ?>
            <div class="box" style="width:100%">    <h5>Remarks</h5>
                <div class="h5sub-details" style="font-size: 10px;">
                    <?php echo nl2br($modelQuotation->remarks); ?>
                </div>
            </div>
        <?php } ?>
    
<?php $this->renderPartial("//common/footer",array('company_id'=>$company_id));?>

</body>

</html>
