<?php 
	include "../koneksi.php";
	$data2 = mysqli_query ($koneksi, " SELECT count(pbb.PBB_ID) AS jml,
												pbb.PlanID,
												sum(material.Qty) AS total
										FROM pbb
										INNER JOIN plan
										ON pbb.PlanID=plan.PlanID
										INNER JOIN material
										ON plan.MaterialID=material.MaterialID
										WHERE pbb.PlanID='$_GET[id]'");

	$row2 = mysqli_fetch_array ($data2)
?>
<!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="../delivery/bootstrap.css">
     <meta name="viewport" content="width=device-width, initial-scale=1.0">
   </head>
<body style="font-size: 14px">
	<div style="height: 10px"></div>
<?php 
$data1 = mysqli_query ($koneksi, " SELECT 
											plan.PlanID,
											plan.DatePlan,
											plan.MaterialID,
											no_pbb.No_PBB,
											mesin.Mesin,
											material.RawMat,
											product.QtyUnit,
											plan.QtyPlan
									FROM plan
									INNER JOIN mesin
									ON plan.MesinID=mesin.MesinID
									INNER JOIN product
									ON plan.ProductID=product.ProductID
									INNER JOIN material
									ON plan.MaterialID=material.MaterialID
									INNER JOIN no_pbb
									ON plan.NoPBB_ID=no_pbb.NoPBB_ID
                                    WHERE PlanID ='$_GET[id]'");

$row1 = mysqli_fetch_array ($data1)
?>

<table style="width:100%; font-size: 13px">
<tr>
	<td width="20%"></td>
	<td width="40%" style="text-align: left">
		<?php echo $row1['No_PBB']; ?>
	</td>
	<td width="20%">
		<?php echo date ("d M Y", strtotime( $row1['DatePlan'])); ?>
	</td>
</tr>
<table style="width:100%; font-size: 13px; margin-top: 20px">
<tr>
	<td width="20%"></td>
	<td width="40%" style="text-align: left">
		<?php echo $row1['Mesin']; ?>
	</td>
	<td width="20%">
		<?php echo $row2['total']; ?>
	</td>
</tr>
<table style="width:100%; font-size: 13px; margin-top: 10px">
<tr>
	<td width="20%"></td>
	<td width="40%" style="text-align: left">
		<?php echo $row1['RawMat']; ?>
	</td>
	<td width="20%">
	</td>
</tr>
</table>
<?php if($row1['MaterialID']==='1' || $row1['MaterialID']==='2' ) { ?>
<table class="table" style="width:100%; text-align: left; font-size: 12px; margin-top: 15px">
		</tr>
<?php 
	$no = 1;
	$data = mysqli_query ($koneksi, " SELECT pbb.PBB_ID,
												pbb.IncomingID,
												incoming.MaterialID,
												incoming.Date_Inc,
												material.Qty,
												pbb.Lot,
												pbb.Material,
												pbb.Bag
									FROM pbb
									INNER JOIN incoming
									ON pbb.IncomingID=incoming.IncomingID
									INNER JOIN material
									ON incoming.MaterialID=material.MaterialID
									WHERE pbb.PlanID='$_GET[id]'
									ORDER BY pbb.Lot, pbb.Bag ASC
									LIMIT 12");

	while($row = mysqli_fetch_array ($data)): ?>
		<tr>
			<td width="10%">
				<?php echo $no++; ?>
			</td>
			<td width="40%" style="text-align: left">
				<?php echo $row['Bag']; ?>&emsp;&emsp;
				<?php echo $row['Lot']; ?>
			</td>
			<td width="15%">
				<?php echo $row['Qty']; ?>
			</td>
			<td width="25%" style="text-align: right">
				<?php echo $row['Material']; ?>&emsp;&emsp;
				<?php echo date ("d/m/Y", strtotime($row['Date_Inc'])); ?>&emsp;&emsp;
			</td>
		</tr>
			<?php endwhile; ?>
	</table>
	<?php } else { ?>
	<table class="table" style="width:100%; text-align: left; font-size: 13px; margin-top: 15px">
		</tr>
	<?php
		$no = 1;
		$data = mysqli_query ($koneksi, " SELECT pbb.PBB_ID,
													pbb.IncomingID,
													incoming.MaterialID,
													incoming.Date_Inc,
													material.Qty,
													pbb.Lot,
													pbb.Bag
										FROM pbb
										INNER JOIN incoming
										ON pbb.IncomingID=incoming.IncomingID
										INNER JOIN material
										ON incoming.MaterialID=material.MaterialID
										WHERE pbb.PlanID='$_GET[id]'
										ORDER BY pbb.Lot, pbb.Bag ASC
										LIMIT 12");

	while($row = mysqli_fetch_array ($data)): ?>
		<tr>
			<td width="10%">
				<?php echo $no++; ?>
			</td>
			<td width="45%" style="text-align: left">
				<?php echo $row['Lot']; ?>&emsp;&emsp;
				<?php echo $row['Bag']; ?>
			</td>
			<td width="15%">
				<?php echo $row['Qty']; ?>
			</td>
			<td width="25%" style="text-align: right">
				<?php echo date ("d/m/Y", strtotime($row['Date_Inc'])); ?>&emsp;&emsp;
			</td>
		</tr>
			<?php endwhile; ?>
	</table>
	<?php } ?>

<div style="height: 650px"></div>

<table style="width:100%; font-size: 13px">
<tr>
	<td width="20%"></td>
	<td width="40%" style="text-align: left">
		<?php echo $row1['No_PBB']; ?>
	</td>
	<td width="20%">
		<?php echo date ("d M Y", strtotime( $row1['DatePlan'])); ?>
	</td>
</tr>
<table style="width:100%; font-size: 13px; margin-top: 20px">
<tr>
	<td width="20%"></td>
	<td width="40%" style="text-align: left">
		<?php echo $row1['Mesin']; ?>
	</td>
	<td width="20%">
		<?php echo $row2['total']; ?>
	</td>
</tr>
<table style="width:100%; font-size: 13px; margin-top: 10px">
<tr>
	<td width="20%"></td>
	<td width="40%" style="text-align: left">
		<?php echo $row1['RawMat']; ?>
	</td>
	<td width="20%">
	</td>
</tr>
</table>
<?php if($row1['MaterialID']==='1' || $row1['MaterialID']==='2' ) { ?>
<table class="table" style="width:100%; text-align: left; font-size: 12px; margin-top: 15px">
		</tr>
<?php
	$no = 13;
	$data1 = mysqli_query ($koneksi, " SELECT pbb.PBB_ID,
												pbb.IncomingID,
												incoming.MaterialID,
												incoming.Date_Inc,
												material.Qty,
												pbb.Lot,
												pbb.Material,
												pbb.Bag
									FROM pbb
									INNER JOIN incoming
									ON pbb.IncomingID=incoming.IncomingID
									INNER JOIN material
									ON incoming.MaterialID=material.MaterialID
									WHERE pbb.PlanID='$_GET[id]'
									ORDER BY pbb.Lot, pbb.Bag ASC");

	mysqli_data_seek($data1, 12);
	while($row = mysqli_fetch_assoc($data1)): ?>
		<tr>
			<td width="10%">
				<?php echo $no++; ?>
			</td>
			<td width="40%" style="text-align: left">
				<?php echo $row['Bag']; ?>&emsp;&emsp;
				<?php echo $row['Lot']; ?>
			</td>
			<td width="15%">
				<?php echo $row['Qty']; ?>
			</td>
			<td width="25%" style="text-align: right">
				<?php echo $row['Material']; ?>&emsp;&emsp;
				<?php echo date ("d/m/Y", strtotime($row['Date_Inc'])); ?>&emsp;&emsp;
			</td>
		</tr>
			<?php endwhile; ?>
	</table>
	<?php } else { ?>
	<table class="table" style="width:100%; text-align: left; font-size: 13px; margin-top: 15px">
		</tr>
			<?php
		$no = 13;
		$data1 = mysqli_query ($koneksi, " SELECT pbb.PBB_ID,
													pbb.IncomingID,
													incoming.MaterialID,
													incoming.Date_Inc,
													material.Qty,
													pbb.Lot,
													pbb.Bag
										FROM pbb
										INNER JOIN incoming
										ON pbb.IncomingID=incoming.IncomingID
										INNER JOIN material
										ON incoming.MaterialID=material.MaterialID
										WHERE pbb.PlanID='$_GET[id]'
										ORDER BY pbb.Lot, pbb.Bag ASC");

		mysqli_data_seek($data1, 12);
		while($row = mysqli_fetch_assoc($data1)): ?>
		<tr>
			<td width="10%">
				<?php echo $no++; ?>
			</td>
			<td width="45%" style="text-align: left">
				<?php echo $row['Lot']; ?>&emsp;&emsp;
				<?php echo $row['Bag']; ?>
			</td>
			<td width="15%">
				<?php echo $row['Qty']; ?>
			</td>
			<td width="25%" style="text-align: right">
				<?php echo date ("d/m/Y", strtotime($row['Date_Inc'])); ?>&emsp;&emsp;
			</td>
		</tr>
			<?php endwhile; ?>
	</table>
	<?php } ?>
	
</body>
</html>