<?php 
include "../koneksi.php";
$data = mysqli_query ($koneksi, " select 
                                              plan.PlanID,
                                              plan.DatePlan,
                                              plan.MesinID,
                                              mesin.Mesin,
                                              plan.ProductID,
                                              product.ItemDescription,
                                              product.SLoc,
                                              product.QtyUnit,
                                              product.Gram,
                                              plan.QtyPlan,
                                              plan.Prioritas,
                                              plan.MaterialID,
                                              material.RawMat,
                                              material.Material,
                                              material.Qty,
                                              plan.POOR,
                                              plan.NoPBB_ID,
                                              plan.NoPBB_ID2
                                      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
                                      WHERE PlanID ='$_POST[id]'");
      
      $row = mysqli_fetch_array ($data);

 ?>
<table class="table-dtm table-bordered" style="width:100%; background-color: white; text-align: left;">
	<tr>
      <td colspan="2">POOR  :</td>
      <td colspan="2"><?php echo $row['POOR']; ?></td>
    </tr>
    <tr>
   		<td colspan="2">Tanggal Plan  :</td>
   		<td colspan="2"><?php echo date ("d-m-Y", strtotime( $row['DatePlan'])); ?></td>
   	</tr>
   	<tr>
   		<td colspan="2" width="50%">Mesin  :</td>
   		<td colspan="2"><?php echo $row['Mesin']; ?></td>
   	</tr>
   	<tr>
   		<td colspan="2">Product  :</td>
   		<td colspan="2"><?php echo $row['ItemDescription']; ?></td>
   	</tr>
   	<tr>
   		<td colspan="2">Material  :</td>
   		<td colspan="2"><?php echo $row['RawMat']; ?></td>
   	</tr>
   	<?php 
   	$no=1;
	$data1 = mysqli_query ($koneksi, "SELECT pbb.PBB_ID,
												pbb.PlanID,
												pbb.Shift,
												no_pbb.No_PBB,
												pbb.Lot,
												pbb.Bag
											FROM pbb
											INNER JOIN incoming
											ON pbb.IncomingID=incoming.IncomingID
											INNER JOIN no_pbb
											ON pbb.NoPBB_ID=no_pbb.NoPBB_ID
											INNER JOIN material
											ON incoming.MaterialID=material.MaterialID
											WHERE pbb.NoPBB_ID='$row[NoPBB_ID]'
											ORDER BY pbb.Lot, pbb.Bag, no_pbb.NoPBB_ID ASC");
	if(mysqli_num_rows($data1)>0) {
		echo '<tr><th colspan="2">Rincian Material Bahan Baku</th><th colspan="2">'.mysqli_num_rows($data1).' JB @ '.$row['Qty'].' KG</th></tr>';
		echo '<tr><td>NO.</td><td>NO LOT</td><td>NO BAG</td><td>BATCH</td></tr>';
	}

	while($row1 = mysqli_fetch_array ($data1)): ?>
	<tr>
		<td><?php echo $no; ?></td>
		<td><?php echo $row1['Lot']; ?></td>
		<td><?php echo $row1['Bag']; ?></td>
		<td><?php echo $row1['No_PBB']; ?></td>
	</tr>
<?php $no++;
endwhile; ?>

	<?php 
   	$no=1;
	$data1 = mysqli_query ($koneksi, "SELECT pbb.PBB_ID,
												pbb.PlanID,
												pbb.Shift,
												no_pbb.No_PBB,
												pbb.Lot,
												pbb.Bag
											FROM pbb
											INNER JOIN incoming
											ON pbb.IncomingID=incoming.IncomingID
											INNER JOIN no_pbb
											ON pbb.NoPBB_ID=no_pbb.NoPBB_ID
											INNER JOIN material
											ON incoming.MaterialID=material.MaterialID
											WHERE pbb.NoPBB_ID='$row[NoPBB_ID2]'
											ORDER BY pbb.Lot, pbb.Bag, no_pbb.NoPBB_ID ASC");
	if(mysqli_num_rows($data1)>0) {
		echo '<tr><th colspan="2">Rincian Material Pewarna</th><th colspan="2">'.mysqli_num_rows($data1).' PAIL @ 20 KG</th></tr>';
		echo '<tr><td>NO.</td><td>NO LOT</td><td>NO BAG</td><td>BATCH</td></tr>';
	}
	
	while($row1 = mysqli_fetch_array ($data1)): ?>
	<tr>
		<td><?php echo $no; ?></td>
		<td><?php echo $row1['Lot']; ?></td>
		<td><?php echo $row1['Bag']; ?></td>
		<td><?php echo $row1['No_PBB']; ?></td>
	</tr>
<?php $no++;
endwhile; ?>
</table>