<?php include "../koneksi.php";
$datasloc = mysqli_query ($koneksi, "SELECT SLoc
                              FROM product
                                WHERE ProductID='$_GET[prod]'");
$row2= mysqli_fetch_array($datasloc);
?>
<table class="table table-bordered">
		<tr>

			<th width="5%" >
				#
			</th>
			<th width="30%">
				Kode
			</th>
			<th width="20%">
				NoLot
			</th>
			<th width="20%">
				Date
			</th>
		<?php if($row2['SLoc']==='BOX2') { ?>
			<th width="25%">
				Quantity
			</th>
		<?php } else { ?>
			<th width="25%">
				Nick
			</th>
		<?php } ?>
			
		</tr>
			<?php 
				$data = mysqli_query ($koneksi, " SELECT 
                                        stpj.STPJ_ID,
                                        plan.PlanID,
                                        plan.DatePlan,
                                        plan.POOR,
                                        product.ProductID,
                                        product.ItemDescription,
                                        product.SLoc,
                                        product.QtyUnit,
                                        stpj.Kode,
                                        stpj.NoLot,
                                        stpj.Nick,
                                        stpj.Qty
                                FROM stpj 
                                INNER JOIN plan
                                ON stpj.PlanID=plan.PlanID
                                INNER JOIN product
                                ON plan.ProductID=product.ProductID
                                where product.ProductID='$_GET[prod]' AND stpj.Del_ID IS NULL AND stpj.`Lock`='0'
                                Order by plan.DatePlan, stpj.kode ASC");
	

				while($row = mysqli_fetch_array ($data)): ?>
		<tr>
			<td width="5%" >
				<a href="out.php?id=<?php echo $row['STPJ_ID']; ?>&del_id=<?php echo $_GET['id']; ?>&prod=<?php echo $row['ProductID']; ?>" style="color: black;" ><i class="bi bi-arrow-left-square-fill"></i></a>
			</td>
			<td width="30%">
				
			<?php echo $row['POOR']; ?>-<?php if ($row['Kode']<10) {
					echo '00'.$row['Kode'];
				} else if ($row['Kode']<100) {
				    echo '0'.$row['Kode'];
				} else {
					echo $row['Kode'];
				} 
				?>-<?php echo substr(preg_replace('/[^A-Za-z0-9]/', '', $row['DatePlan']), 2, 4); ?>
			</td>
			<td width="20%">
				<?php echo $row['NoLot']; ?>
			</td>
			<td width="20%">
				<?php echo date ("d-m-Y", strtotime($row['DatePlan'])); ?>
			</td>
		<?php if($row2['SLoc']==='BOX2') { ?>
			<td width="25%">
				<?php echo $row['Qty']; ?> <?php echo substr($row['SLoc'], 0, 3); ?>@<?php echo $row['QtyUnit']*$row['Qty']; ?>pcs
			</td>
		<?php } else { ?>
			<td width="25%">
				<?php echo $row['Nick']; ?>
			</td>
		<?php } ?>

		</tr>
			<?php endwhile; ?>
	</table>
