<style type="text/css">

@media print {
  @page {
    margin-top: 4.2cm;
    margin-bottom: 4.4cm;
  }
}
</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 List</title>
</head>

<body>
        <!--mpdf
<htmlpageheader name="myHeader">
  <div class="">
    <img src="<?php echo  'images/logo/'.Yii::app()->user->pdf_company_logo; ?>"/> 
  </div>
</htmlpageheader>
<sethtmlpageheader name="myHeader" value="on" />        mpdf-->
    <div class="">
        <div class="col-4">
            <?php
                $modelQuotation = Quotes::model()->findByPk($id);
               
            ?>
                <div class="input-block">
                    <b><?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: #0000b3;font-size: 18px;">
                    <?php echo 'QUOTATION'; ?>
                </div>
            </div>
        <div class="col-4" style="color:#101010;">
            <div class="text-right">
                <img src="<?php echo  'images/logo/'.Yii::app()->user->pdf_company_logo; ?>" class="logo">
            </div>
            <br>
            <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 colspan="2">
                        <?php echo $modelQuotation->leadowner->first_name.' '.$modelQuotation->leadowner->last_name.' , '.$modelQuotation->leadowner->phno;//.' , '.$modelQuotation->leadowner->email?>
                    </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>
                    <?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>
                     <?php if($bonus_quantity=="Y"){ ?>
                     <th class="text-center" style="width:4%">Bonus Qty</th>                     
                     <?php } ?>
                     <th class="text-center">Unit</th>
                     <!-- <th class="text-center">Ex-Stock</th> -->
                    <th class="text-center" style="width:8%">Unit Price</th>
                    <th class="text-center" style="width:8%">Discount</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;
                $tot_tax = 0;
                $condition .= '1=1';
                $condition .= ' AND t.quotes_id ="' . $id.'"';
                $total=0;$tot_discount=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 
//                    else if($model_Quotes->checked==1)
//                    {
                        /*if($model_Quotes->product->inventory_type == '2'){
                        ?>
                        <tr class="bg-theme">
                            <td colspan="7"><?php echo $model_Quotes->description;?></td>
                        </tr>
                
                        <?php
                        }else */
                    if($model_Quotes->product_id == 999999){ ?>
                              <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 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'])){ ?>
                        <td>
                           <?php if($model_Quotes->product->item_image != ''){ ?>
                           <img width="120" height="120"  src="<?php echo 'uploads/inventoryimages/'.$model_Quotes->product->item_image; ?>">
                           <?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 echo ( $model_Quotes->product->inventory_item_type == 2 ) ? 'N/A' : $model_Quotes->quoteunit->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)
                            $total+=$model_Quotes->net_amount;
                            $tot_discount+=$model_Quotes->deduction_amount;
                            $tot_tax += $model_Quotes->tax_vat_amount;
                    }
       // }
        } ?>
        <?php
            $col = "9";
            if(isset($master_permission_array['inventory_image_show_quotation'])){
                $col = $col+1;
            } 
            if($bonus_quantity=="Y"){
                    $col = $col+1;
            }
                ?>        
                <?php if($tot_discount > 0 ) : ?>        
                    <tr>
                            <td class="text-right" colspan="<?php echo $col; ?>"><b>Amount</b></td>
                            <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($total + $tot_discount, " "); ?></b></td>
                        </tr>
                        <tr>
                            <td class="text-right" colspan="<?php echo $col; ?>"><b>Discount</b></td>
                            <td class="text-right"><b><?php echo Yii::app()->numberFormatter->formatCurrency($tot_discount, " "); ?></b></td>
                        </tr>
                <?php endif; ?>
                <?php if( $modelQuotation->total_tax_amount > 0 ) : ?>                            
                <tr>
            
            
                        <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($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 With VAT    </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>
                                <td class="text-right" colspan="<?php echo $col+1; ?>"><b><?php echo MasCurrency::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>


       <br/>
        <?php
        if ($modelQuotation->payment_terms != 0) {?>
            <h5><U>Payment Terms</U></h5>
                <div class="h5sub-details">
            <?php echo nl2br($modelQuotation->paymentTerm->payment_terms); ?>
                </div>
            <?php } ?>
        
       
        <?php
        if ($modelQuotation->terms_and_conditions != '') {
            ?>
                <h5><U>Terms and Conditions</U></h5>
                <div class="h5sub-details">
            <?php echo nl2br($modelQuotation->terms_and_conditions); ?>
                </div>
            <?php
        }
        ?>
        <?php
        if ($modelQuotation->notes != '') {
            ?>
                <h5><U>Notes</U></h5>
                <div class="h5sub-details">
            <?php echo nl2br($modelQuotation->notes); ?>
                </div>
<?php } ?>
        <?php
                $model = OwnerBankDetails::model()->find(array('condition' => 'currency_id=' . Yii::app()->user->company_base_currency));
                if (!empty($model)) {
                    ?>


                        <div class="h5sub-details">

                            <table class="" style="width:100%; page-break-inside:avoid;">
                                <tr>
                                    <td colspan="6">
                                        <h5><U>Bank Details</U></h5>
                                    </td>
                                </tr>
                                <tr>
                                    <td style="width: 130px">Account Name</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_account_name; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">Account No</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_ac_no; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">Bank Name</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank->bank_name; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">Bank Branch</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_branch; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">IBAN #</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_iban; ?></td>
                                </tr>
                                <tr>
                                    <td style="width: 90px">Swift Code</td>
                                    <td style="width: 2px">:</td>
                                    <td style="float: left;"><?php echo $model->bank_swift; ?></td>
                                </tr>
                            </table>
                        </div>
                <?php } ?>


    <htmlpagefooter name="myfooter">

    <img src="<?php echo  'images/logo/pdf_logo_footer.png'; ?>"/>
        <div style="font-size: 12px; text-align: center; padding-top: 10px;">
            <div style="font-size: 9px; text-align: center;">
            <?php echo Yii::app()->user->footer_autogenerated; ?><?php
                  date_default_timezone_set("Asia/Dubai");
                 echo date('d/m/Y')." ".date("h:i:sa"); ?>
            </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>
