<?php
include "Connection.php";
include "../global.php";
require_once(dirname(__FILE__)."/_api/global.php");
$conn = new Connection();
                
$db = $conn->getConnection();  
$token = escape_str($_REQUEST["token"]);                
 
$check_arr=$conn->selectQuery(TABLE_QUOTATIONSHARE ,"*","sharetoken='".$token."'","1");   
if(!$check_arr['nr']>0)
{      
    $client_ip=globalfunc::getIp($conn);
    $sec=LOCK_ACCESS_MINUTES*60;
    $expiry_time=date('Y-m-d H:i:s',strtotime('-'.$sec.' seconds',strtotime(NOW)));
    $lock_qry_str="SELECT SUM(lock_count) lock_count FROM ".TABLE_LOCK_ACCESS." WHERE is_deleted='0' AND modified_on>='".$expiry_time."' AND ip='".$client_ip."' GROUP BY ip LIMIT 1";
    $lock_value=$conn->getQueryValue($lock_qry_str);   
    if(count($lock_value)>0 && $lock_value[0]->lock_count>=3)
    {       
        header("HTTP/1.1 404 Page Not Found");
        header('Access-Control-Allow-Origin: *');  
        echo 'Sorry Invalid Access. Access Blocked For 10 min.'; exit;                      
    } 
    globalfunc::insertLockLog($conn,$token); 
    header("HTTP/1.1 404 Page Not Found");
    header('Access-Control-Allow-Origin: *');  
    echo  'PAGE NOT FOUND'; exit;                      
     
     
}

//GET DEALER
$dealer_arr=$conn->selectQuery(DMS_DEALER ,"dealer_code,dealer_name,phone,email,address,state,city"," dealer_code='".$check_arr['result'][0]->dealer_code."'  ","1");
$dealer_name=($dealer_arr['nr']>0)?$dealer_arr['result'][0]->dealer_name:'';
$dealer_address=($dealer_arr['nr']>0 && $dealer_arr['result'][0]->address!='')?$dealer_arr['result'][0]->address:$dealer_name;
$dealer_phone=($dealer_arr['nr']>0 && $dealer_arr['result'][0]->phone!='')?$dealer_arr['result'][0]->phone:'';
$dealer_email=($dealer_arr['nr']>0 && $dealer_arr['result'][0]->email!='')?$dealer_arr['result'][0]->email:'';

//GET MODEL
$model_arr=$conn->selectQuery(DMS_ENQUIRY_MODEL ,"title,title_code,variant,variant_code"," title_code='".$check_arr['result'][0]->model."' AND variant_code='".$check_arr['result'][0]->variant."'  ","1");
$model_str=($model_arr['nr']>0)?$model_arr['result'][0]->title:'';
$variant_str=($model_arr['nr']>0)?$model_arr['result'][0]->variant:'';

$check_arr['result'][0]->exsh_price=($check_arr['result'][0]->exsh_price)?$check_arr['result'][0]->exsh_price:0;
$check_arr['result'][0]->rto_price=($check_arr['result'][0]->rto_price)?$check_arr['result'][0]->rto_price:0;
$check_arr['result'][0]->insurance_price=($check_arr['result'][0]->insurance_price)?$check_arr['result'][0]->insurance_price:0;
$check_arr['result'][0]->access_price=($check_arr['result'][0]->access_price)?$check_arr['result'][0]->access_price:0;
$check_arr['result'][0]->exwarr_price=($check_arr['result'][0]->exwarr_price)?$check_arr['result'][0]->exwarr_price:0;
$check_arr['result'][0]->other_price=($check_arr['result'][0]->other_price)?$check_arr['result'][0]->other_price:0;
$check_arr['result'][0]->total_price=($check_arr['result'][0]->total_price)?$check_arr['result'][0]->total_price:0;
 
// print_r($check_arr);

$quotationhtml ='<!doctype html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
	<title>Hyper-M</title>
	<base href="'.SITE_URL.'">

	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="icon" type="image/x-icon" href="images/loc-logo.png">
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
	<style>
		body{
			float: left;
			width: 100%;
			background: #ececec;
		}
		.section {
			width: 100%;
			max-width: 900px;
			margin: 0px auto;
			display: block;
		}
		.top-section{
			padding: 30px;
			float: left;
			width: 100%;
		}
		.top-section .box-type {
			box-shadow: 0 0px 8px rgba(0, 0, 0, 0.3);
			padding: 25px;
			float: left;
			width: 100%;
			border-radius: 5px;
			background: #fff;
		}

		.wid100 {
			width: 100%;
			float: left;
		}

		.dis p {
			color: #0397d7 !important;
		}
		.form-group1 {
			display: initial;
			margin-bottom: 0px;
		}

		.form-group1 input {
			padding: 0;
			height: initial;
			width: initial;
			margin-bottom: 0;
			display: none;
			cursor: pointer;
		}

		.form-group1 label {
			position: relative;
			cursor: pointer;
		}

		.form-group1 label:before {
			content: \'\';
			-webkit-appearance: none;
			background-color: transparent;
			border: 2px solid #0079bf;
			box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), inset 0px -15px 10px -12px rgba(0, 0, 0, 0.05);
			padding: 6px;
			display: inline-block;
			position: relative;
			vertical-align: middle;
			cursor: pointer;
			margin-right: 5px;
		}

		.form-group1 input:checked+label:after {
			content: \'\';
			display: block;
			position: absolute;
			top: 5px;
			left: 6px;
			width: 5px;
			height: 9px;
			border: solid #0079bf;
			border-width: 0 2px 2px 0;
			-webkit-transform: rotate(45deg);
			transform: rotate(45deg);
		}

		.section .w100 {
			float: left;
			width: 100%;
		}

		.section .w100 .back {
			display: inline-block;
			cursor: pointer;
		}

		.section .w100 .back img {
			width: 14px;
			padding-right: 5px;
		}

		.section .w100 .back:hover,
		.section .w100 .back:focus,
		.section .w100 .back:active {
			outline: none;
		}

		.section .w100 .monthly-det {
			float: right;
			margin: 0 10px 15px 10px;
		}

		.section .w100 .monthly-det img {
			width: 12px;
			cursor: pointer;
		}

		.section .w100 .monthly-det p {
			margin: 0;
			display: inline-block;
			padding: 0 5px;
			min-width: 120px;
			text-align: center;
		}

		.section .w100 .btns {
			width: auto;
			border-radius: 100px;
			float: right;
			margin: 0;
			padding: 6px 40px;
			font-size: 14px;
			height: auto;
			font-weight: 500;
		}

		.section .w100 .btns.blue {
			color: #00334c !important;
			border: 2px solid #00334c;
			width: 100%;
		}

		.section h5.tit {
			color: #003d58;
		}


		.section .task-left .logo img {
			max-width: 140px;
		}

		.section .showroom {
			text-align: center;
		}

		.section .showroom h5 {
			font-size: 16px;
		}

		.section .showroom address {
			font-size: 14px;
		}

		.section .quote-detail {
			padding: 15px;
		}

		.section .quote-detail .form-group {
			width: 100%;
			float: left;
		}

		.section .quote-detail .form-group label {
			width: 35%;
			float: left;
			line-height: 3;
			font-weight: 500;
			font-size: 14px;
		}

		.section .quote-detail .form-group .form-control {
			width: 65%;
			float: left;
			font-size: 14px;
			font-weight: 500;
			color: #333;
		}

		.section .quote-table {
			border: 1px solid #dee2e6;
		}

		.section .quote-table thead th {
			background: #00334c;
			color: #fff;
			white-space: nowrap;
			min-width: 160px;
			text-align: left;
			font-size: 14px;
		}

		.section .quote-table tbody tr td {
			font-size: 14px;
			font-weight: 500;
			border: none;
			vertical-align: middle;
			text-align: left;
		}

		.section .quote-table tbody tr td .form-group {
			margin-bottom: 0;
		}

		.section .quote-table tbody tr td .form-group .form-control {
			font-size: 14px;
			font-weight: 500;
		}

		.section .quote-table tbody tr td textarea.form-control {
			height: 38px;
		}

		.section .quote-table tbody tr td:before {
			display: none;
		}

		.section .quote-table tbody tr:last-child {
			background: #e0e0e0;
		}

		.section .quote-table tbody tr:nth-child(even) {
			background: none;
		}

		.section .terms h5 {
			font-size: 16px;
		}

		.section .terms p {
			margin: 0;
			padding: 0;
			margin-bottom: 10px;
			font-size: 14px;
			font-weight: 500;
		}

	</style>
</head>

<body>
	<div class="section task-section">
		<div class="top-section">
		
			<div class="box-type task-left">

				<div class="row">

					<div class="col-sm-3 logo text-center">
						<img src="images/logo.png" alt="Logo">
					</div>
					<div class="col-sm-6 showroom">
						<h5>'.$dealer_name.'</h5>
						<address>
							Showroom : '.$dealer_address.'<br>';
							$quotationhtml.=($dealer_phone)?'Tel. : '.$dealer_phone:'';
                            $quotationhtml.=($dealer_phone && $dealer_email)?", ":'';
                            $quotationhtml.=($dealer_email)?'Email: '.$dealer_email:'';
						$quotationhtml.='</address>
					</div>
					<div class="col-sm-3 text-center">
						<!--h5>'.$dealer_name.'</h5-->
					</div>

					<div class="col-sm-12 text-center">
						<h5 class="tit">QUOTATION FORM</h5>
					</div>

					<div class="col-sm-12 quote-detail">
						<div class="form-group">
							<label>Customer Name</label>
							<div class="form-control">'.$check_arr['result'][0]->name.'</div>
						</div>
						<div class="form-group" id="boot-select">
							<label> Model</label>
							<div class="form-control">'.$model_str.'</div>
						</div>
						<div class="form-group" id="boot-select">
							<label> Variant</label>
							<div class="form-control">'.$variant_str.'</div>
						</div>
						<div class="form-group">
							<label>Contact No</label>
							<div class="form-control">'.$check_arr['result'][0]->mobile.'</div>
						</div>
						<div class="form-group">
							<label>E-mail</label>
							<div class="form-control">'.$check_arr['result'][0]->email.'</div>
						</div>
						<div class="form-group">
							<label>Date</label>
							<div class="form-control">'. strtoupper(date('d-M-Y',strtotime($check_arr['result'][0]->created_on))).'</div>
						</div>
					</div>

					<div class="col-sm-12 table-responsive">
						<table class="table bordered quote-table">
							<thead>
								<tr>
									<th>Vehicle Quotation</th>
									<th>Unit Price</th>
									<th>Remarks if any</th>
								</tr>
							</thead>
							<tbody>

								<tr>
									<td>Ex. Showroom Price</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->exsh_price.'</div>
										</div>
									</td>
									<td>';
                                //EXSH REMARKS    
                                $quotationhtml.=($check_arr['result'][0]->exsh_remark!='')?'<div class="form-group">
                                <div class="form-control">'.$check_arr['result'][0]->exsh_remark.'</div>
                                </div>':''; 
                                $quotationhtml.='</td>
								</tr>

								<tr>
									<td>Road Tax/ RTO Charges</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->rto_price.'</div>
										</div>
									</td>
									<td>';
                                    //RTO REMARKS 
                                    $quotationhtml.=($check_arr['result'][0]->rto_remark!='')?'<div class="form-group">
                                        <div class="form-control">'.$check_arr['result'][0]->rto_remark.'</div>
                                    </div>':'';
									$quotationhtml.='</td>
								</tr>

								<tr>
									<td>Insurance</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->insurance_price.'</div>
										</div>
									</td>
									<td>';
                                    //INSURANCE
                                    $quotationhtml.=($check_arr['result'][0]->insurance_remark!='')?'<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->insurance_remark.'</div>
										</div>':'';
									$quotationhtml.='</td>
								</tr>

								<tr>
									<td>Accessories</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->access_price.'</div>
										</div>
									</td>
									<td>';
                                    //ACCESSORIES
                                    $quotationhtml.=($check_arr['result'][0]->access_remark!='')?'<div class="form-group">
                                       <div class="form-control">'.$check_arr['result'][0]->access_remark.'</div>
                                   </div>':'';
									$quotationhtml.='</td>
								</tr>
								<tr>
									<td>Extended Warranty</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->exwarr_price.'</div>
										</div>
									</td>
									<td>';
                                    //EXTENDED WARRANTY
                                    $quotationhtml.=($check_arr['result'][0]->access_remark!='')?'<div class="form-group">
                                        <div class="form-control">'.$check_arr['result'][0]->exwarr_remark.'</div>
                                    </div>':'';
									$quotationhtml.='</td>
								</tr>

								<tr>
									<td>Others</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->other_price.'</div>
										</div>
									</td>
									<td>';
                                    //OTHERS
                                    $quotationhtml.=($check_arr['result'][0]->other_remark!='')?'<div class="form-group">
                                        <div class="form-control">'.$check_arr['result'][0]->other_remark.'</div>
                                    </div>':'';
									$quotationhtml.='</td>
								</tr>

								<tr>
									<td>Total On-Road Price</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->total_price.'</div>
										</div>
									</td>
									<td>
									</td>
								</tr>';
                                $quotationhtml.=($check_arr['result'][0]->discount!='')?'<tr>
									<td>Offer/Discount</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->discount.'</div>
										</div>
									</td>
									<td>
									</td>
								</tr>':'';
                                $quotationhtml.=($check_arr['result'][0]->discount!='')?'<tr>
									<td>Price after Discount</td>
									<td>
										<div class="form-group">
											<div class="form-control">'.$check_arr['result'][0]->final_price.'</div>
										</div>
									</td>
									<td>
									</td>
								</tr>':'';
							$quotationhtml.='</tbody>
						</table>
					</div>

					<div class="col-sm-12 terms">
						<h5>T&C:</h5>
						<p>1) The above prices are inclusive of all Taxes</p>
						<p>2) This Quote is valid till '.date('d-m-Y',strtotime($check_arr['result'][0]->validity_date)).' Only</p>
						<p>3) The above prices are subject to change without any notice & the prices prevailing at the time
							of delivery shall be charged</p>
						<p>This is system generated vehicle quotation only, does not require any signature.</p>
					</div>

				</div>
			</div>

		</div>
	</div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>

</html>';
echo $quotationhtml; 
 
exit;
?>