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

    <div class="">
        <?php $this->renderPartial("//common/header"); ?>
        <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: #0000b3;font-size: 18px;">
                <?php echo 'TECHNICAL OFFER'; ?>
            </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 colspan="2">
                        <?php echo $modelQuotation->leadowner->fullname . ' , ' . $modelQuotation->leadowner->phno . ' , '; ?>
                        <br>
                        <?php echo $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" style="width:30%">Description</th>
                    <?php if (isset($master_permission_array['inventory_image_show_quotation']) && $type == 5) { ?>
                        <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>
                </tr>
            </thead>
            <tbody>

                <?php
                $m = 1;
                $tot_tax = 0;
                $condition .= '1=1';
                $condition .= ' AND t.quotes_id ="' . $id . '"';
                $total = 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="5"><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 nl2br($model_Quotes->description); ?>
                            </td>
                            <?php if (isset($master_permission_array['inventory_image_show_quotation']) && $type == 5): ?>
                                <td>
                                    <?php if (!empty($model_Quotes->product->item_image)): ?>
                                        <img width="120" height="120"
                                            src="<?php echo Yii::app()->baseUrl . '/uploads/inventoryimages/thumbs/' . CHtml::encode($model_Quotes->product->item_image); ?>"
                                            alt="Product Image">
                                    <?php elseif (!empty($model_Quotes->image_file_name)): ?>
                                        <img width="120" height="120"
                                            src="<?php echo Yii::app()->baseUrl . '/uploads/quotationimage/' . CHtml::encode($model_Quotes->image_file_name); ?>"
                                            alt="Quotation Image">
                                    <?php endif; ?>
                                </td>
                            <?php endif; ?>
                            <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; 
                                        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>

                        </tr>

                        <?php
                    }
                    // }
                    $m++;
                }
                ?>
            </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 } ?>

    <br>
    <?php $this->renderPartial("//common/footer"); ?>

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

        }
    </style>

</body>

</html>