<!DOCTYPE html>
<html>

<head>
    <title>Quote List</title>
	<style>
	
.table {
	border-collapse: collapse !important;
	font-size: 10px;
	color: #101010;
	width: 100%;
}
.table thead th{
	background: #ccc;
	color: #343434;
}
.table th,
.table td {
	border: 1px solid #ccc !important;
	text-align: left;
	padding: 2px 5px;
}
.table th.text-left,
.table td.text-left{
	text-align: left;
	text-align: left !important;
}
.table th.text-right,
.table td.text-right{
	text-align: right;
	text-align: right !important;
}
.table th.text-center,
.table td.text-center{
	text-align: center;
	text-align: center !important;
}
.table tbody tr:nth-child(even){
	background: #f4fef3;
}
.table th.Table-Title,
.table td.Table-Title{
    padding:6px 5px !important;
    font-size:1rem;
    color:green;
    font-weight:500;
    text-transform:uppercase;
}
.table th.total,
.table td.total{
	background: #fff !important;
	color: #343434 !important;
	font-size: 10px;
}
	</style>
</head>

<body>
    <br>
    <div class="heading" style="padding-top:-20px !important;">
        <!--<div class="logo col-6" >
                <img src="images/pdf/logo.png">
            </div>-->
        <div class="col-12 text-center" style="margin: 0 auto;">
            <h3><u>QUOTATION LIST</u></h3>
        </div>
        <div class="col-12" style="">
            <div class="details-box">
                <table class="table" style="width:100%;border-color:#000;">
                    <?php  if($qtn_start_from_date !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;" ><b>Quotation From </b></td>
                        <td>
                            <?php echo date('d/m/Y', strtotime($qtn_start_from_date)); ?>
                        </td>
                    </tr>
                    <?php } ?>
                    <?php if($qtn_start_to_date !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Quotation To </b></td>
                        <td>
                            <?php echo date('d/m/Y', strtotime($qtn_start_to_date)); ?>
                        </td>
                    </tr>
                    <?php } ?>
                    <?php if($qtn_validity_from_date !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Valid From</b></td>
                        <td>
                            <?php echo date('d/m/Y', strtotime($qtn_validity_from_date)); ?>
                        </td>
                    </tr>
                    <?php } ?>
                    <?php if($qtn_validity_to_date !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Valid To </b></td>
                        <td>
                            <?php echo date('d/m/Y', strtotime($qtn_validity_to_date)); ?>
                        </td>
                    </tr>
                    <?php } ?>
                    <?php  if($sales_group !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Sales Group </b></td>
                        <td>
                            <?php $s= MasSalesGroup::model()->findByPK($sales_group);
                              echo $s->group_name;?>
                        </td>
                    </tr>
                    <?php } ?>
                     <?php if($customer_id !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Customer</b></td>
                        <td>
                            <?php $c = Customer::model()->findByPK($customer_id);
                              echo $c->customer_name;?>
                        </td>
                    </tr>
                    <?php } ?>
                    <?php if($leadowner_id >0){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Lead Owner</b></td>
                        <td>
                            <?php $l = User::model()->findByPK($leadowner_id);
                                echo $l->first_name." ".$l->last_name;?>
                        </td>
                    </tr>
                    <?php }?>
                    <?php if($qtn_country >0){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Country</b></td>
                        <td>
                            <?php $country1 = MasCountry::model()->findByPK($qtn_country);
                                    echo $country1['country_name'];?>
                        </td>
                    </tr>
                    <?php }?>
                    <?php if($qtn_part_no_id >0){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Part No </b></td>
                        <td>
                            <?php $part_no_model = Store::model()->findByPK($qtn_part_no_id);
                            echo $part_no_model->part_number;?>
                        </td>
                    </tr>
                    <?php }?>
                    <?php if($brand >0){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Brand</b></td>
                        <td>
                            <?php $mod_brand = new ProductClass();
                                  $mod_brand = $mod_brand->findByPK($brand);
                                    echo $mod_brand['product_class'];?>
                        </td>
                    </tr>
                    <?php }?>
                    <?php if($value_from!=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Value From</b></td>
                        <td>
                            <?php echo $value_from;?>
                        </td>
                    </tr>
                    <?php }?>
                    <?php if($value_to !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Value To</b></td>
                        <td>
                            <?php echo $value_to;?>
                        </td>
                    </tr>
                    <?php }?>
                     <?php if($status !=''){  ?>
                    <tr>
                        <td style="width: 20%;font-size:10px;"><b>Status</b></td>
                        <td>
                            <?php $status_name='';
                            if($status =='Y'){
                                $status_name='Open';
                            }
                            
                            if($status =='C'){
                                $status_name='Closed';
                            }
                            if($status =='O'){
                                $status_name='Others';
                            }
                            if($status =='L'){
                                $status_name='Lost';
                            }
                            echo $status_name ; ?>                        </td>
                    </tr>
                    <?php } ?>
             </table>


                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        
           
    
         <?php 
        $settings_module = MasCompanySettings::model()->find(array('condition'=>'crm_company_id='.Yii::app()->user->master_user_company_id));
        $bonus_quantity  = $settings_module->bonus_quantity;
       $condition = '1=1'; ;
            if($qtn_start_from_date != ''){
                $condition .= ' AND t.qtn_date >="'.$qtn_start_from_date.'"';
            }
            if($qtn_start_to_date != ''){
                $condition .= ' AND t.qtn_date <="'.$qtn_start_to_date.'"';
            }
            if($qtn_validity_from_date != ''){
                $condition .= ' AND t.qtn_validity >="' . $qtn_validity_from_date.'"';
            }
            if($qtn_validity_to_date != ''){
                $condition .= ' AND t.qtn_validity <="' . $qtn_validity_to_date.'"';
            }
            if($sales_group != ''){
                $condition .= ' AND t.sales_group ="' . $sales_group.'"';
            }
             if($customer_id != ''){
                $condition .= ' AND t.customer_id ="' . $customer_id.'"';
            }
            if($leadowner_id >0){
                $condition .= ' AND t.lead_owner_id ="' . $leadowner_id.'"';
            }
            if($probability!=''){
                $condition .= ' AND t.probability ="' . $probability.'"';
            }
            if($qtn_part_no_id != ''){

                $condition .= ' AND items.product_id ="' . $qtn_part_no_id.'"';
            }
            if($qtn_country != ''){

                $condition .= ' AND customer.customer_country ="' . $qtn_country.'"';
            }
            if($qtn_location != ''){

                $condition .= ' AND customer.customer_location ="' . $qtn_location.'"';
            }
            if($brand >0){

                $condition .= ' AND product.brand_class_id ="' . $brand.'"';
            }
             if($status != ''){
                $condition .= ' AND t.status ="' . $status.'"';
            }
            
            
             if($value_from != ''){

                $condition .= ' AND t.grand_total >="' . $value_from.'"';
            }
            if($value_to != ''){

                $condition .= ' AND t.grand_total <="' . $value_to.'"';
            }
            
            $total=0;
            $model_quote = Quotes::model()->with('file','customer','probability_details','customercontact','items.product')->findAll(array('condition'=>$condition));
        foreach ($model_quote as $i => $model) {
            $id=$model->id;
            ?>
        
        
        <div class="col-12">
        <div class="table-body">
        <table style="" id="tbl_qtn_table" class="table ">
        
       <thead>
           <tr>
                 <th style="backgound-color:#ccc !important;" >No</th>
                <th style="backgound-color:#ccc !important;">Qtn No</th>
                <th style="backgound-color:#ccc !important;">File No</th>
                <th style="backgound-color:#ccc !important;">Customer Name</th>
                <th style="backgound-color:#ccc !important;">Currency</th>
                <th style="backgound-color:#ccc !important;">Lead Owner</th>
                <th style="backgound-color:#ccc !important;">Quotation Date</th>
                <th style="backgound-color:#ccc !important;">Validity Date</th>
                <th style="backgound-color:#ccc !important;">Sales Group</th>
                <th style="backgound-color:#ccc !important;">Probability</th>
                <th style="backgound-color:#ccc !important;">Status</th>
               <th style="backgound-color:#ccc !important;">Grand Total(BC)</th>
                <th style="backgound-color:#ccc !important;">Remarks</th>

           </tr>
       </thead>
       <tbody>
  	 	<tr>
  	 	<td><?php echo $i+1;?></td>
                <td><?php echo $model->id;?></td>
                <td><?php echo $model->file_id;?></td>
  	 			<td width="40%"><?php echo $model->customer->customer_name;?></td>
                <td><?php echo $model->currencyname->currency_code;?></td>
                <td><?php echo $model->leadowner->fullname;?></td>
              
                <?php if($model->qtn_date!='0000-00-00'){ ?>
                <td><?php echo date("d/m/Y", strtotime($model->qtn_date));?></td>
                <?php }else{ ?>
                <td>&nbsp;</td>
                <?php } ?>
                <?php if($model->qtn_validity!='0000-00-00'){ ?>
                <td><?php echo date("d/m/Y", strtotime($model->qtn_validity));?></td>
                <?php }else{ ?>
                <td>&nbsp;</td>
                <?php } ?>

              
                <td><?php echo $model->salesgroup->group_name;?></td>
                <td><?php echo $model->probability;?></td>
                 <?php
                      if($model->status == 'Y')
                       $state="Open";
                      if($model->status == 'C')
                       $state="Closed";
                      if($model->status == 'O')
                       $state="Others";
                      if($model->status == 'L')
                       $state="Lost";
                    ?>
                <td><?php echo $state;?></td>
                <?php $model_currency = MasCurrency::model()->findByPk($model->currency);
                $total_bc = $model->grand_total*$model_currency->exchange_rate;
                $total += $total_bc?>
                <td class="text-right"><?php echo Yii::app()->numberFormatter->formatCurrency($total_bc, " ");?></td>
                
                <td><?php echo $model->remarks;?></td>
                </tr>
               
                
       </tbody>
   </table>
   </div>
</div>

<div class="col-12">
   <table id="" class="table" >
            <thead>
                <tr>
                    <th class="text-center bc-tl" style="font-size:6px !important;">No</th>
                    <th class="text-center" style="font-size:6px !important;">Part No</th>
                    <th class="text-center" style="width:30%;font-size:6px !important;">Description</th>
                    <th class="text-center" style="width:4%;font-size:6px !important;">Qty</th>
                    <?php if($bonus_quantity=="Y"){ ?>
                     <th class="text-center" style="width:4%;font-size:6px !important;">Bonus</th>                     
                     <?php } ?>
                     <th class="text-center" style="font-size:6px !important;">Unit</th>
                    <th class="text-center" style="width:8%;font-size:6px !important;">Unit Price</th>
                    <th class="text-center" style="width:8%;font-size:6px !important;">Discount</th>
                    <th class="text-center" style="font-size:6px !important;">Tax(%)</th>
                    <th class="text-center" style="font-size:6px !important;">Tax Amount</th>
                    <th class="text-center bc-tr" style="font-size:6px !important;">Net Amount</th>
                </tr>
            </thead>
            <tbody>
                
                    <?php
                $m=1;
                $tot_tax = 0;
                $condition = ' t.quotes_id ="' . $id.'"';
                $total=0;
                $model_Quotes = QuotesItem::model()->findAll(array('condition'=>$condition,'order' => 'id ASC'));
                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_id == 999999){ ?>
                              <tr style="background-color:  #d0f5c5 ; color: white;font-size:8px !important;"><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 style="font-size:8px !important;">
                            <?php echo $m;?>
                        </td>
                        <td style="font-size:8px !important;">
                            <?php echo $model_Quotes->product->part_number;?>
                        </td>
                        <td style="font-size:8px !important;">
                            <?php echo nl2br($model_Quotes->description);?>
                        </td style="font-size:8px !important;">
                       
                        <td class="text-right" style="font-size:8px !important;">
                            <?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" style="font-size:8px !important;">
                                <?php echo ( $model_Quotes->product->inventory_item_type == 2 ) ? 'N/A' : (float) $model_Quotes->bonus_qty;?>
                            </td>
                        <?php } ?>
                        <td style="font-size:8px !important;">
                            <?php echo ( $model_Quotes->product->inventory_item_type == 2 ) ? 'N/A' : $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" style="font-size:8px !important;">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($rate," ");?>
                        </td>
                         <td class="text-right" style="font-size:8px !important;">
                            <?php echo Yii::app()->numberFormatter->formatCurrency($model_Quotes->deduction_amount," ");?>
                        </td>
						<!--tax- start-->
						<td class="text-right" style="font-size:8px !important;">
                            <?php echo $model_Quotes->tax_vat_percentage;?>
                        </td>
						<td class="text-right" style="font-size:8px !important;">
                            <?php $taxamount=  $model_Quotes->tax_vat_amount;
							echo $taxamount;
							?>
                        </td>
						<!--tax- end-->
                        <td class="text-right" style="font-size:8px !important;">
                            <?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)
                            $total+=$model_Quotes->net_amount;
                            $tot_tax += $model_Quotes->tax_vat_amount;
                    }
       // }
        } ?>
                    <?php
                $col = "9";
                if($bonus_quantity=="Y"){
                    $col = "10";
                } ?>
                <?php if( $modelQuotation->total_tax_amount > 0 ) : ?> 
                <tr>
                        <!--<td class="text-right" colspan="<?php //echo $col-6; ?>"><b>Grand Total Without VAT</b></td>-->
                        <!--<td></td>-->
                        <td class="text-right" colspan="<?php echo $col-5; ?>" style="font-size:8px !important;"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total," ");?></b></td>
						<!--<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='.$id.' AND calculated_value>0'));
                    $Dedution=QuotesDeduction::model()->findAll(array('condition'=>'quotes_id='.$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; ?>" style="font-size:8px !important;">
                                <?php
                        echo MasFooterItems::getFooterItemName($eachAddition->particular);
                        ?>
                            </td>
                            <td class="text-right" style="font-size:8px !important;">+
                                <?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 Without VAT</b></td>-->
                                <td class="text-right total bc-br" colspan="<?php echo $col-5; ?>" style="font-size:8px !important;"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total," ");?></b></td>
								<!--<td class="text-right total bc-bl" colspan="<?php //echo $col; ?>"><b>VAT</b></td>-->
                                <td class="text-right total bc-br" colspan="<?php echo $col-5; ?>" style="font-size:8px !important;"><b><?php echo Yii::app()->numberFormatter->formatCurrency($tot_tax," ");?></b></td>
								<!--<td class="text-right total bc-bl" colspan="<?php //echo $col; ?>"><b>Grand Total With VAT</b></td>-->
                                <?php $total += $tot_tax; ?>
                                <td class="text-right total bc-br" colspan="<?php echo $col-9; ?>" style="font-size:8px !important;"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total," ");?></b></td>
                            </tr>
                            <!-- <tr>
                                <td class="text-right" colspan="<?php echo $col+1; ?>"><b><?php //echo 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 } ?>
 
    <html pagefooter name="myfooter">
        <div style="text-align:center;width:100%;font-size:6.5px"><?= 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: 6.5px; text-align: center; padding-top:-1px; 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>
    </html pagefooter>
<sethtmlpagefooter name="myfooter" page="all" value="on" />
</body>

</html>