<?php

$where = " WHERE 1=1";
$next_page_condition = "";

if($_REQUEST['hide_top']){
	$next_page_condition.="&hide_top=1";
}
if($_REQUEST['hide_left']){
	$next_page_condition.="&hide_left=1";
}

$qot_id = $_REQUEST['id'];
$query = "SELECT * FROM quotation where id  = '".$qot_id."' ";
$sql= mysqli_query($conn,$query);
$result= mysqli_num_rows($sql);
$row = mysqli_fetch_assoc($sql);
$row = utility::validate_crypt_data($row);
$customer_name = $gsi->getCustomerById($row['customer_id']);
$part_number =  $row['part_number'];
$part_description =  $row['part_description']; 
$drawing_issue =  $row['drawing_issue']; 
$model_number =  $row['model_number'];
$volume =  $row['volume']; 
$quotation_number =  $row['quotation_number']; 

$query_brought_out_part = "SELECT * FROM quot_brought WHERE quot_id ='".$qot_id."' ";
$sql_brought_out_part= mysqli_query($conn,$query_brought_out_part);
$result_brought_out_part= mysqli_num_rows($sql_brought_out_part);

$query_brought_total = "SELECT * FROM quot_brought_total WHERE quot_id ='".$qot_id."' ";
$sql_brought_total= mysqli_query($conn,$query_brought_total);
$result_brought_total= mysqli_num_rows($sql_brought_total);
$row_brought_total = mysqli_fetch_assoc($sql_brought_total);
$row_brought_total = utility::validate_crypt_data($row_brought_total);
$totals_brought =  $row_brought_total['totals_brought'];
$average_brought =  $row_brought_total['average_brought'];

$query_tooling = "SELECT * FROM quot_tooling WHERE quot_id ='".$qot_id."' ";
$sql_tooling= mysqli_query($conn,$query_tooling);
$result_tooling= mysqli_num_rows($sql_tooling);

$hide_button  = $_REQUEST['hide_top'];
if($hide_button == 1){
	$hide ="hide";
}else{
	$hide ="";
}

?>

<style type="text/css">
	.custom-bordered td {
			border: 1px solid #dee2e6;
		}

	.custom-bordered tfoot td[colspan="6"].text-end {
			border-left: none !important;
			border-bottom: none !important;
		}
    .label {
			display: inline-block;
			width: 120px; /* Adjust this width as needed */
			font-weight: ;
		}
	@page {
		margin: 0;
		/* size: landscape; */
		size: potrait;
		/* DIN A4 standard, Europe */
	}

	@media print {
		.bgblack {
			background-color: #000;
		}

		.font50print40 {
			font-size: 40px;
		}

		.content-wrapper,
		.right-side {
			background-color: #fff;
		}

		.box {
			border-top: 0 solid #d2d6de !important;
			box-shadow: none !important;
		}

		p {
			white-space: inherit !important;
		}

		.col-sm-1,
		.col-sm-2,
		.col-sm-3,
		.col-sm-4,
		.col-sm-5,
		.col-sm-6,
		.col-sm-7,
		.col-sm-8,
		.col-sm-9,
		.col-sm-10,
		.col-sm-11,
		.col-sm-12 {
			float: left;
		}

		.col-sm-12 {
			width: 100%;
		}

		.col-sm-11 {
			width: 91.66666667%;
		}

		.col-sm-10 {
			width: 83.33333333%;
		}

		.col-sm-9 {
			width: 75%;
		}

		.col-sm-8 {
			width: 66.66666667%;
		}

		.col-sm-7 {
			width: 58.33333333%;
		}

		.col-sm-6 {
			width: 50%;
		}

		.col-sm-5 {
			width: 41.66666667%;
		}

		.col-sm-4 {
			width: 33.33333333%;
		}

		.col-sm-3 {
			width: 25%;
		}

		.col-sm-2 {
			width: 16.66666667%;
		}

		.col-sm-1 {
			width: 8.33333333%;
		}
	}

	.col-sm-1,
	.col-sm-2,
	.col-sm-3,
	.col-sm-4,
	.col-sm-5,
	.col-sm-6,
	.col-sm-7,
	.col-sm-8,
	.col-sm-9,
	.col-sm-10,
	.col-sm-11,
	.col-sm-12 {
		float: left;
	}

	.col-sm-12 {
		width: 100%;
	}

	.col-sm-11 {
		width: 91.66666667%;
	}

	.col-sm-10 {
		width: 83.33333333%;
	}

	.col-sm-9 {
		width: 75%;
	}

	.col-sm-8 {
		width: 66.66666667%;
	}

	.col-sm-7 {
		width: 58.33333333%;
	}

	.col-sm-6 {
		width: 50%;
	}

	.col-sm-5 {
		width: 41.66666667%;
	}

	.col-sm-4 {
		width: 33.33333333%;
	}

	.col-sm-3 {
		width: 25%;
	}

	.col-sm-2 {
		width: 16.66666667%;
	}

	.col-sm-1 {
		width: 8.33333333%;
	}
</style>
<div class="container mt-3">
	<div class="row justify-content-center">
		<div class="col-sm-12">
			<div class="card">
				<div class="card-body">
					<div class="row pb-2 p-2">
						<div class="col-sm-10">
							<h3 class="text-center font-weight-bold mb-1">Quotation Analysis Form</h3>

						</div>
						<div class="col-sm-2">
							<h3 class="text-right font-weight-bold mb-1"><?php echo $quotation_number;?></h3>

						</div>
					</div>
					<div class="row" style="margin-left: -2.5px;">    
						<div class="col-sm-4">
							<p class="mb-0"><strong>Thermotec Plastics Ltd</strong></p>
							<p class="mb-0">Unit 8A, Electra Park Ind Est</p>
							<p class="mb-0">Electric Avenue</p>
							<p class="mb-0">Witton, Birmingham.</p>
							<p>B6 7EB</p>
							<p class="mb-0">Tel: 0121 327 7800</p>
							<p>Fax: 0121 327 4799</p>
						</div>
						<div class="col-sm-4">
							<p class="mb-0"><span class="label">Customer:</span> <?php echo $customer_name; ?></p>
							<p class="mb-0"><span class="label">Supplier Code:</span> <?php echo $hh; ?></p>
							<p class="mb-0"><span class="label">Part Number:</span> <?php echo $part_number; ?></p>
							<p class="mb-0"><span class="label">Description:</span> <?php echo $part_description; ?></p>
							<p class="mb-0"><span class="label">Drawing Issue:</span> <?php echo $drawing_issue; ?></p>
							<p class="mb-0"><span class="label">Model:</span> <?php echo $model_number; ?></p>
							<p class="mb-0"><span class="label">Pcr/Aims:</span> <?php echo $hh; ?></p>
							<p class="mb-0"><span class="label">Vol:</span> <?php echo $volume; ?></p>
						</div>

						<div class="col-sm-4">
							<p class="mb-0"><span class="label">Quote:</span> <?php echo $quote; ?></p>
							<p class="mb-0"><span class="label">Sheet:</span> <?php echo $sheet; ?></p><br>
							<p class="mb-0"><span class="label">Economic Level:</span> <?php echo $economic_level; ?></p>
							<p class="mb-0"><span class="label">Currency:</span> GB STERLING</p>
							<p class="mb-0"><span class="label">Pack:</span> <?php echo $pack; ?></p>
							<p class="mb-0"><span class="label">Manager:</span> Gary Hingley</p>
						</div>
					</div>
					<div class="my-4"></div>
					<div class="my-4"></div>
					<div class="container" style="width:100%; float:left; margin-top:12px;">
						<div><h5>1. Procured Parts / Process & Made in Parts</h5></div>
							<table class="table custom-bordered">
								<thead>
									<tr>
										<td>Part Number / Description / Process</td>
										<td>Exchange Rate</td>
										<td>Duty (%) </td>
										<td>Price</td>
										<td>Num Off</td>
										<td>Scrap (%)</td>
										<td>Handle (%)</td>
										<td>Total Cost (£)</td>
									</tr>
								</thead>
								<tbody>
								<?
								while($row_brought_out_part =mysqli_fetch_array($sql_brought_out_part)){ 
									$row_brought_out_part=utility::validate_crypt_data($row_brought_out_part);
					         	?>
									<tr>
										<td>
											<?php echo  $row_brought_out_part['part'] . '<br>' . ' Supplier: ' . $row_brought_out_part['supplier'] . '&nbsp;&nbsp;&nbsp;Currency: ' . $row_brought_out_part['currency']; ?>
										</td>
										<td><?php echo $row_brought_out_part['exch_rate']?></td>
										<td><?php echo $row_brought_out_part['duty_percent']?></td>
										<td><?php echo $row_brought_out_part['price']?></td>
										<td><?php echo $row_brought_out_part['number']?></td>
										<td><?php echo $row_brought_out_part['scrap_percent']?></td>
										<td><?php echo $row_brought_out_part['handling_percent']?></td>
										<td><?php echo $row_brought_out_part['total']?></td>
									</tr>
								<? } ?>	
								</tbody>
								<tfoot>
									<tr>
										<td colspan="1" class="text-end" style="border-left: none !important; border-bottom: none !important;"></td>
										<td colspan="3" class="text-end" style="text-align: center;"><strong>Procured Scrap Value = <?php echo !empty($average_brought) ? $average_brought : 0; ?></strong> </td>
										<td colspan="4" class="text-end" style="text-align: center;">
											<strong>Sub Total (1) Procured Parts = <?php echo !empty($totals_brought) ? $totals_brought : 0; ?></strong>
										</td>

									</tr>
								</tfoot>
							</table>
					</div>					
					<div class="my-4"></div>
				<div class="container" style="width:100%; float:left; margin-top:10px;">
						<div><h5>4. Tooling</h5></div>
							<table class="table custom-bordered">
								<thead>
									<tr>
										<td>Tooling Description</td>
										<td>Supplier</td>
										<td>Lead Time (weeks)</td>
										<td>Parts per Tool</td>
										<td>Tool Life (Parts)</td>
										<td>Unit Costs</td>
										<td>Number Off</td>
										<td>Other Cost</td>
										<td>Total Cost</td>
									</tr>
								</thead>
								<tbody>
								<?
								$total_cost_sum = 0;
								while($row_tooling =mysqli_fetch_array($sql_tooling)){ 
									$row_tooling=utility::validate_crypt_data($row_tooling);
									 $total_cost_sum += $row_tooling['total_cost'];
					         	?>
									<tr>
										<td><?php echo $row_tooling['tool_description']?></td>
										<td><?php echo $row_tooling['supplier']?></td>
										<td><?php echo $row_tooling['lead_time']?></td>
										<td><?php echo $row_tooling['parts_per_tool']?></td>
										<td><?php echo $row_tooling['tool_life']?></td>
										<td><?php echo $row_tooling['cost']?></td>
										<td><?php echo $row_tooling['number']?></td>
										<td><?php echo $row_tooling['other']?></td>
										<td><?php echo $row_tooling['total_cost']?></td>
									</tr>
								<? } ?>	
								</tbody>
								<tfoot>
									<tr>
										<td colspan="6" class="text-end" style="border-left: none !important; border-bottom: none !important;"></td>
										<td colspan="3" class="text-end"  style="text-align: right;"><strong>&nbsp;<?php echo $total_cost_sum;?></strong></td>
									</tr>
								</tfoot>

							</table>
					</div>
					<br>
					<div class="my-4" style="font-style: italic; width:100%; float:left; margin-top:10px;">
						<p>All quotations and subsequent orders are subject to our terms & conditions, a master copy of which has been sent to your Purchase Department.</p>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>