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

        }
  @page {
        margin-top: 3cm;
        /*margin-bottom:2cm;*/
          margin-bottom:3.5cm;
        margin-left: .3cm;
        margin-right: .3cm;
        header: html_myHeader;
        header: html_otherpages;
        font-family:'Times New Roman';
        border:5px solid red;
          height: 280mm;

    }


</style>
<html>
    <?php
$modelCompanySettings = new MasCompanySettings();
$modelCompanySettings = $modelCompanySettings->find(array('condition'=>'crm_company_id='.(int) Yii::app()->user->master_user_company_id));   
if(!empty($modelCompanySettings->print_template_logo)){
    $pdf_logo = $modelCompanySettings->print_template_logo;
}
else{
    $pdf_logo = Yii::app()->user->company_logo;
}


if($modelCompanySettings->print_template_id=='R'){
    $print_template_style="width:30%;float:right";
}
elseif($modelCompanySettings->print_template_id=='M'){
    $print_template_style="width:100%;float:left";
}
else{
    $print_template_style ="width:30%;float:left";
}

?>
<?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 >

<!--<htmlpageheader name="bgWithBorder">-->
<!--  <div style="position: fixed; top: -8; left: 0; right: 0; bottom:0;-->
<!--              border: 7px solid red;-->
              
<!--              background-size: cover;-->
<!--              z-index: -100;height:100%;width:98%;">-->
<!--  </div>-->
<!--</htmlpageheader>-->

<!--<sethtmlpageheader name="bgWithBorder" value="on"  />-->


    <div  style="padding: 35px;"> 
   
    <?php
    $modelQuotation = Quotes::model()->findByPk($id);
    $model_lead = Lead::model()->find(array('condition' => 'file_id="' . $modelQuotation->file_id . '"'));
    ?>

    <!------===header section-->

    <div class="" >
        <htmlpageheader name="firstpage" style="display:none">
</htmlpageheader>

<htmlpageheader name="otherpages" style="display:none">
      <div style="position: fixed; top: -8; left: 0; right: 0; bottom:0;
              border: 7px solid red;
              
              background-size: cover;
              z-index: -100;height:100%;width:98%;"> 

    <?php //$this->renderPartial('//common/header'); ?>
     <div class="header" style="width:100%;padding-bottom:0;display:flex;margin-top:5px;padding-right:5px;">
        <img style="<?php echo $print_template_style;?>;" src="<?php echo  'uploads/logo/'.$pdf_logo; ?>"/>
    </div>
<br>
   </div>
</htmlpageheader>
        <?php //$this->renderPartial('//common/header'); ?>
        <div class="col-4">
            <?php
            $year = date('y');
            $formattedId = "RAM{$year}-Q $id";
            ?>
            <div class="input-block">
                <b><?php echo $formattedId; ?></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->customer->customer_trn_no != '') { ?>
                <small>Customer TRN # : <?php echo $modelQuotation->customer->customer_trn_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>
                <small>Email:</small>
                <small><b><?php echo strtoupper($modelQuotation->customercontact->contact_email_id); ?></b></small><br>
                <small>Phone:</small>
                <small><b><?php echo strtoupper($modelQuotation->customercontact->contact_mobile_no); ?></b></small><br>
            <?php } ?>
        </div>


        <div class="col-4">
            <div class="h3" style="margin-top: 0;margin-bottom: 0;text-align: center;font-size: 14px;">
                <?php echo "QUOTATION"; ?>
            </div>
        </div>


        <div class="col-4" style="color:#101010;">
            <table class="table" style="width:100%">
                <tr>
                    <td style="width:40%">File ID</td>
                    <td>
                        <?php echo $modelQuotation->file_id; ?>
                    </td>
                </tr>

                <tr>
                    <td style="width:40%">Reference No</td>
                    <td>
                        <?php echo $modelQuotation->enq_ref; ?>
                    </td>
                </tr>

                <tr>
                    <td style="width:40%">Customer ID</td>
                    <td>
                        <?php echo $modelQuotation->customer_id; ?>
                    </td>
                </tr>
                <tr>
                    <td style="width:40%">Customer TRN #</td>
                    <td>
                        <?php echo $modelQuotation->customer->customer_trn_no; ?>
                    </td>
                </tr>
                <tr>
                    <td style="width:40%">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 style="width:40%">Currency</td>
                    <td>
                        <?php echo $modelQuotation->currency0->currency_code; ?>
                    </td>
                </tr>
                <tr>
                    <td style="width:40%">Inco Terms</td>
                    <td>
                        <?php echo $modelQuotation->incoterm->inco_name; ?>
                    </td>
                </tr>
                <?php if ((int) $modelQuotation->ticket_id > 0) {
                    $modticket = TicketHeader::model()->findByPk((int) $modelQuotation->ticket_id);
                    ?>
                    <tr>
                        <td style="width:40%">Job</td>
                        <td>
                            <?php echo $modelQuotation->ticket_id; ?>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:40%">Building</td>
                        <td>
                            <?php echo $modticket->building_details->building_name; ?>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:40%">Unit</td>
                        <td>
                            <?php echo $modticket->unit_details->unit_name; ?>
                        </td>
                    </tr>
                    <tr>
                        <td style="width:40%">Reference No</td>
                        <td>
                            <?php echo $modelQuotation->enq_ref; ?>
                        </td>
                    </tr>
                <?php } ?>
                <tr>
                    <td colspan="2">
                        <?php echo $modelQuotation->leadowner->fullname . ' , ' . $modelQuotation->leadowner->phno; ?>
                    </td>
                </tr>
            </table>
        </div>

    </div>

    <!------===header section-->


    <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">Description</th>
                    <th class="text-center">Qty</th>
                    <th class="text-center">Unit</th>
                    <th class="text-center">Rate</th>
                    <!--  <th class="text-center" style="width:8%">Discount</th>
                    <th class="text-center">Tax(%)</th>
                    <th class="text-center">Tax(%)</th>
                    <th class="text-center bc-tr">Net Amount</th>-->
                    <th class="text-center">Total</th>
                    <th class="text-center">Tax Amt</th>
                    <th class="text-center bc-tr">Net Amt</th>
                </tr>
            </thead>
            <tbody>
            <tbody>

                <?php
                $m = 1;
                $tot_tax = 0;
                $condition .= '1=1';
                $condition .= ' AND t.quotes_id ="' . $id . '"';
                $total = 0;
                $model_Quote = QuotesItem::model()->findAll(array('condition' => $condition, 'order' => 'id ASC'));
                $totalqty = $totalrate = $totaldeduction = $totaltaxper = $totaltaxamount = $totalnetamount = 0;
                foreach ($model_Quote 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;">
                            <td colspan="7"><b><?php echo $model_Quotes->description; ?></b></td>
                        </tr>
                    <?php } else {
                        $totaldeduction += $model_Quotes->deduction_amount;

                        ?>


                        <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 class="text-right">
                                <?php echo ($model_Quotes->product->inventory_item_type == 2) ? 'N/A' : Yii::app()->numberFormatter->formatCurrency($model_Quotes->quantity, " ");

                                $totalqty += ($model_Quotes->product->inventory_item_type == 2) ? 0 : Yii::app()->numberFormatter->formatCurrency($model_Quotes->quantity, " ");
                                ?>
                            </td>

                            <td>
                                <?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">
                                <?php echo Yii::app()->numberFormatter->formatCurrency($rate, " ");
                                $totalrate += $rate;
                                ?>
                            </td>

                            <!--td class="text-right">
                                <?php $taxamount = $model_Quotes->tax_vat_amount;
                                //echo $taxamount;
                                //echo (int) $model_Quotes->tax_vat_percentage;
                                $totaltaxamount += $taxamount;

                                ?>
                            </td-->

                            <td class="text-right">
                                <?php echo Yii::app()->numberFormatter->formatCurrency(($rate * $model_Quotes->quantity), " ");
                                $totalrate += $rate;
                                ?>
                            </td>

                            <td class="text-right">
                                <?php echo Yii::app()->numberFormatter->formatCurrency($taxamount, " ");
                                $totalrate += $rate;
                                ?>
                            </td>

                            <!--td class="text-right">
                <?php //echo $model_Quotes->tax_vat_percentage;
                        //$totaltaxper += $model_Quotes->tax_vat_percentage;
                        ?>
            </td-->

                            <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';
                                }
                                ;

                                $totalnetamount += ($model_Quotes->checked == 1) ? $net_amount_ot : 0;

                                ?>
                            </td>

                        </tr>


                        <?php
                        $m = $m + 1;
                        if ($model_Quotes->checked == 1)
                            $total += $model_Quotes->amount;
                        $tot_tax += $model_Quotes->tax_vat_amount;
                    }
                } ?>



                <?php
                $col = "8";
                //if($bonus_quantity=="Y"){
//    $col = "10";
// } 
                ?>
                <?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>
                    <?php if ($totaldeduction > 0) { ?>
                        <tr>
                            <td class="text-right" colspan="<?php echo $col; ?>"><b>Discount </b></td>
                            <!--<td></td>-->
                            <td class="text-right">
                                <b><?php echo Yii::app()->numberFormatter->formatCurrency($totaldeduction, " "); ?></b>
                            </td>

                        </tr>
                        <tr>
                            <td class="text-right" colspan="<?php echo $col; ?>"><b>Total After Discount </b></td>
                            <!--<td></td>-->
                            <td class="text-right">
                                <b><?php echo Yii::app()->numberFormatter->formatCurrency($total - $totaldeduction, " "); ?></b>
                            </td>

                        </tr>
                        <?php
                        $total -= $totaldeduction;
                    } ?>
                    <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>
                    <td class="text-right" colspan="<?php echo $col + 1; ?>">
                        <b><?php echo MasCurrency::number_to_currency(number_format(($total), 2, '.', ''), $modelQuotation->currency_id); ?></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 ($modelQuotation->payment_terms_id != 0) {
        ?>
        <br>
        <div class="box" style="width: 100%">
            <!--        <small>**VAT Charges as will be applicable</small><br><br>-->
            <h5>Payment Terms</h5>
            <div class="h5sub-details">
                <?php echo nl2br($modelQuotation->paymentTerm->payment_terms); ?>
            </div>
        </div>
    <?php } ?>
    <?php if ($modelQuotation->terms_and_conditions != '') {
        ?>
        <div class="box" style="width: 100%">
            <h5>Terms and Conditions</h5>
            <div class="h5sub-details">
                <?php echo nl2br($modelQuotation->terms_and_conditions); ?>
            </div>
        </div>
        <br>
        <?php
    }
    ?>
    <?php //if($modelQuotation->remarks!='')
// {
    ?>
    <!--            <div class="box" style="width: 100%">
<h5>Remarks</h5>
<div class="h5sub-details">
    <?php // echo  nl2br($modelQuotation->remarks); 
    ?>
</div>
</div>-->
    <?php //} 
    ?>
    <?php if ($modelQuotation->notes != '') {
        ?>
        <div class="box" style="width: 100%">
            <h5>Notes</h5>
            <div class="h5sub-details">
                <?php echo nl2br($modelQuotation->notes); ?>
            </div>
        </div>
    <?php } ?>

 
<div style="display: flex; justify-content: center; align-items: center;">
  <img src="images/pdf/seal.png" alt="Ramfoam Logo" style="max-width:50%; object-fit: contain; height:120px; margin:5px 15px;">
  <img src="images/pdf/vc-logo.png" alt="Victory Cases Logo" style="max-width:18%; object-fit: contain; margin: 0 15px;">
  <img src="images/pdf/skb.png" alt="SKB Logo" style="max-width:18%; object-fit: contain; margin: 0 15px;">
</div>

    <?php $this->renderPartial("//common/footer", array('company_id' => $company_id)); ?>


       </div>
       

</body>

</html>