<?php include "../koneksi.php"; ?>
<!DOCTYPE html>
<!-- Designined by CodingLab | www.youtube.com/codinglabyt -->
<html lang="en" dir="ltr">
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="bootstrap.css">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <style type="text/css">
     	@media all{
		    .table-print tr td{
		        border:1px solid black;
			}
			.table-print tr th{
		        border:1px solid black;
			}
     </style>
   </head>
<?php
	include "../koneksi.php";
	$data0 = mysqli_query ($koneksi, " SELECT coa.PlanID,
											 coa.Date_COA,
											 coa.Lot_COA,
											 coa.Shift,
											 coa.Material as MaterialCOA,
							 				 product.ProductID,
											 product.ItemDescription,
											 product.Material,
											 product.Pewarna,
											 plan.MaterialID
										from coa
										INNER JOIN plan
										ON coa.PlanID=plan.PlanID
										INNER JOIN product
										ON plan.ProductID=product.ProductID
										WHERE COA_ID=$_GET[coa_id]");
	$row0 = mysqli_fetch_array($data0);

	$data = mysqli_query ($koneksi, " SELECT standard.StdID,
		SUBSTRING_INDEX(REPLACE(REPLACE(REPLACE(spec.Spec,',',' '),')',' '),'(',' '),' ',-1) AS 'diameter',
											standard.SpecID,
											standard.ProductID,
											standard.CL,
											standard.Allowance,
											spec.Kode2,
											spec.Spec2,
											product.ItemDescription
									FROM standard
									INNER JOIN spec
									ON standard.SpecID=spec.SpecID
									INNER JOIN product
									ON standard.ProductID=product.ProductID
									where standard.ProductID = $row0[ProductID] and spec.SpecID!=43");

	$data1 = mysqli_query ($koneksi, " SELECT * from add_coa
										WHERE COA_ID=$_GET[coa_id]");

	$data2 = mysqli_query ($koneksi, " SELECT spec.Spec,
										add_std.AddStdID,
										add_std.Type_Cek,
										add_std.CL,
										add_std.Allowance
										FROM add_std
										INNER JOIN spec
										ON add_std.SpecID=spec.SpecID
										WHERE add_std.ProductID=$row0[ProductID]");
?>
<body style="font-size: 12px">
<h4 style="font-family: Britannic; font-size: 21px; font-weight: bold; text-align: center; margin-top: 60px;"><u>CERTIFICATE OF ANALYIS</u></h4>
<h5 style="font-family: Britannic; font-weight: bold; text-align: center; margin-top: -2px;">PET <?php echo $row0['ItemDescription']; ?></h5>
<h5 style="font-family: Britannic; font-weight: bold; text-align: center; margin-top: -2px;">CoA No : <?php echo substr($row0['Date_COA'], 0, 4); ?> - <?php echo $row0['Material']; ?> - <?php echo $row0['Lot_COA']; ?></h5>
<table style="width: 90%; font-size: 12px; margin-top: 35px; margin-right: 5%; margin-left: 5%;">
	<tr>
		<td width="19%" style="text-align: left;">Production Date</td>
		<td width="1%">:</td>
		<td width="40%" style="letter-spacing: 2px; font-size: 13px;"><?php echo substr($row0['Date_COA'], 5, 2); ?><?php echo substr($row0['Date_COA'], 8, 2); ?><?php echo substr($row0['Date_COA'], 2, 2); ?></td>
		<td width="19%" style="text-align: left;">Lot Number</td>
		<td width="1%">:</td>
		<td width="20%"><?php echo $row0['Lot_COA']; ?></td>
	</tr>
	<?php if($row0['Pewarna']==NULL) {} else { ?>
	<tr>
		<td width="19%" style="text-align: left;">Colour Material</td>
		<td width="1%">:</td>
		<?php $data8 = mysqli_query ($koneksi, " select RawMat
	                                      from 
	                                      material 
	                                      where MaterialID=$row0[Pewarna]");
	    $row8=mysqli_fetch_array($data8);

	    $data10 = mysqli_query ($koneksi, " select pbbused.Pewarna,
	    									pbb.Lot,
	    									pbb.Bag
	                                      from 
	                                      pbbused
	                                      INNER JOIN pbb
	                                      ON pbbused.Pewarna=pbb.PBB_ID
	                                      where pbbused.PlanID=$row0[PlanID] and pbbused.Shift=$row0[Shift] ");
	    $row10=mysqli_fetch_array($data10);
	    ?>
		<td width="40%"><?php echo $row8['RawMat']; ?></td>
		<td width="19%" style="text-align: left;">No. Batch Colour</td>
		<td width="1%">:</td>
		<td width="20%"><?php echo $row10['Lot'].' - '.$row10['Bag']; ?></td>
	</tr>
	<?php } ?>
	<tr>
		<td width="19%" style="text-align: left;" valign="top">Resin Material</td>
		<td width="1%" valign="top">:</td>
		<td width="40%" valign="top"><?php echo $row0['MaterialCOA']; ?></td>
		<td width="19%" style="text-align: left;" valign="top">No. Batch Resin</td>
		<td width="1%" valign="top">:</td>
		<td width="20%" style="line-height: 15px;" ><?php 
		$noResin = array();
	    $data9 = mysqli_query ($koneksi, " select *
	                                      from 
	                                      pbb 
	                                      INNER JOIN incoming
                                      	  ON pbb.IncomingID=incoming.IncomingID
	                                      where PlanID=$row0[PlanID] AND Shift=$row0[Shift] AND incoming.MaterialID=$row0[MaterialID]");
	    while ($row9=mysqli_fetch_array($data9)) {
	    	 echo $row9['Lot'].' - '.$row9['Bag'].',<br>';
	    }

	    ?>
    </td>
	</tr>
</table>
<table class="table-print" style="width:100%; font-size: 10px; border-collapse: collapse; text-align: center;">
	<tr>
		<th rowspan="2" width="35%" style="padding-top: 5px;">PROPERTIES</th>
		<th rowspan="2" width="10%" style="padding-top: 5px;">UNIT</th>
		<th rowspan="2" width="19%"style="padding-top: 5px;">SPECIFICATION</th>
		<th colspan="3" width="21%">RESULT</th>
		<th rowspan="2" style="padding-top: 5px;" width="15%">TEST METHOD</th>
	</tr>

	<tr>
		<th width="7%">MAX</th>
		<th width="7%">AVG</th>
		<th width="7%">MIN</th>
	</tr>
	<?php $j = 1;
	while( $row = mysqli_fetch_array ($data) ) : ?>
	<tr>
		<?php if ($j==1) {
			echo '<td style="text-align: left;">WEIGHT</td><td>grams</td>';
		} else { ?>
		<td style="text-align: left;">
			<table style="width: 100%; border: hidden;">
				<tr style="border: hidden;">
					<td width="6%" style="text-align: center; border: hidden;">-</td>
					<td width="15%" style="text-align: center; border: hidden;"><?php echo $row['diameter']=='DIAMETER' ? '<text style="font-size: 11px;">⌀</text>' : ''; ?><?php echo $row['Kode2']; ?></td>
					<td width="79%" style="border: hidden;"><?php echo $row['Spec2']; ?></td>
				</tr>
			</table>
		</td>
		<td>mm</td>
		<?php } ?>
		<td style="text-align: center;">
			<?php echo number_format($row['CL'],2); ?>&ensp; &#177; &ensp;<?php echo number_format($row['Allowance'],2); ?>
		</td>
		<?php $data3 = mysqli_query ($koneksi, " SELECT MAX(dimensi.Nilai) AS MAX,
												AVG(dimensi.Nilai) AS AVG,
												MIN(dimensi.Nilai) AS MIN
												FROM dimensi
												WHERE dimensi.COA_ID=$_GET[coa_id] AND dimensi.StdID=$row[StdID]");
		$row3 = mysqli_fetch_array($data3);
		?>
		<td style="text-align: center;">
			<?php echo number_format($row3['MAX'], 2); ?>
		</td>
        <td style="text-align: center;">
        	<?php echo number_format($row3['AVG'], 2); ?>
		</td>
        <td style="text-align: center;">
        	<?php echo number_format($row3['MIN'], 2); ?>
		</td>
		<td>ITA Method</td>
	<tr>
	<?php if ($j==1) { 
	echo '<tr><td colspan="7" style="text-align: left;">DIMENSION</td></tr>';
	} ?>
	<?php $j++;
	 endwhile;
	 $ovality = array();
			$e2max = array();
			$data6 = mysqli_query ($koneksi, " select Nilai FROM dimensi
									INNER JOIN standard
									ON dimensi.StdID=standard.StdID
                                    where COA_ID = $_GET[coa_id] AND SpecID=5");
    		while($row6 = mysqli_fetch_array($data6)) {
    			array_push($e2max, $row6['Nilai']);
    		}
    		$e2min = array();
			$data7 = mysqli_query ($koneksi, " select Nilai FROM dimensi
									INNER JOIN standard
									ON dimensi.StdID=standard.StdID
                                    where COA_ID = $_GET[coa_id] AND SpecID=43");
    		while($row7 = mysqli_fetch_array($data7)) {
    			array_push($e2min, $row7['Nilai']);
    		}
    		for ($y=0; $y < count($e2max) ; $y++) { 
    			array_push($ovality, round($e2min[$y]-$e2max[$y],2));
    		}
	 ?>
	 <tr>
	 	<td style="text-align: left;">Ovality</td>
	 	<td>mm</td>
	 	<td><0.2 mm</td>			
		<td style="text-align: center;"><?php echo max($ovality); ?></td>
		<td style="text-align: center;"><?php echo round(array_sum($ovality)/count($ovality),2); ?></td>
		<td style="text-align: center;"><?php echo min($ovality); ?></td>
	 	<td>ITA Method</td>
	 </tr>
	<?php $i=1;
	 while($row2 = mysqli_fetch_array ($data2)) {
				$row1 = mysqli_fetch_assoc($data1);
				?>
	<tr>
		<td style="text-align: left;"><?php echo $row2['Spec']; ?></td>
		<?php if ($i==1) {
			echo '<td>%</td>';
		} else if ($i==2){
			echo '<td>dl/g</td>';
		} else if ($i==3) {
			echo '<td>ppm</td>';
		} else {
			echo '<td style="font-size: 9px;">COLONI / 3pcs</td>';
		} ?>
		<?php if ($row2['Type_Cek']=='MAXIMUM') { ?>
			<td style="text-align: center;">MAX <?php echo $row2['CL']; ?></td>
		<?php } else if ($row2['Type_Cek']=='MINIMUM') { ?>
			<td style="text-align: center;">MIN <?php echo $row2['CL']; ?></td>
		<?php } else if ($row2['Type_Cek']=='BOOLEAN') { ?>
			<td style="text-align: center;">Negatif</td>
		<?php } else { ?> 
		<td style="text-align: center;"><?php echo $row2['CL']; ?> &#177; <?php echo $row2['Allowance']; ?> </td>
		<?php } ?>
		<?php if ($row2['Type_Cek']=='BOOLEAN') { ?>
			<td colspan="3"><?php if ($row1['Nilai']=='1') { echo 'Negatif'; } else if ($row1['Nilai']=='2') { echo 'Positif'; } else { echo 'NA'; }; ?></td>
		<?php } else {
			if ($row1['Nilai']!='') {
				echo '<td colspan="3">'.$row1['Nilai'].'</td>';	
			} else if ($i>3) {
				echo '<td colspan="3">NA</td>';
			} else {
				echo '<td colspan="3"></td>';
			}
		} ?>
		<?php if ( $i>1 && $i<=3) {
			echo "<td>External Lab</td>";
		} else {
			echo "<td>ITA Method</td>";
		} ?>
	</tr>
	<?php $i++; 
	} ?>
</table>
<table style="width: 100%">
	<tr>
		<td width="60%">
			<br><br><br><br>
			<u>EDI PURNOMO</u><br>
			QUALITY EXECUTIVE<br><br>
			Note :<br>
			<text style="font-size: 9px;">*  NA : Microbiology test result will release on 72 hours after production</text><br><br>
			011/FORM-CORP/SOP0504/QAC/REV.02
		</td>
		<td width="40%"><img src="../image/14,2clear.jpg" alt="" width="200" height="300"></td>
	</tr>
</table>
</body>
</html>