<?php include "../koneksi.php"; ?>
<nav>
    <ol class="breadcrumb">
		<li class="breadcrumb-item">Produksi</li>
        <li class="breadcrumb-item">Table Data Product</li>
    </ol>
</nav>
<div style="width:100%;height500px;overflow:scroll;" >
<table id="example" class="display nowrap" style="width:100%">
        <thead>
		<tr>
			<th width="5%">
				#
			</th>
			<th width="25%">
				Product 
			</th>
			<th width="15%">
				Batch
			</th>
			<th width="25%">
				Material
			</th>
			<th width="25%">
				Quantity
			</th>
			<th width="10%">
				Opsi
			</th>
		</tr>
		</thead>
		<tbody>
			<?php 
				$no = 1;
				$data = mysqli_query ($koneksi, " SELECT 
														COUNT(stpj.STPJ_ID) AS jumlah,
														plan.ProductID,
														product.ItemDescription,
														product.Sloc,
														product.QtyUnit,
														sum(stpj.Qty) as jml,
											DATE_FORMAT(plan.DatePlan, '%y%m') AS dateplan,
											material.MaterialID,
											material.RawMat,
											stpj.Lock
										FROM stpj 
										INNER JOIN plan
										ON stpj.PlanID=plan.PlanID
										INNER JOIN product
										ON plan.ProductID=product.ProductID
										INNER JOIN material
										ON plan.MaterialID=material.MaterialID
											where stpj.Del_ID IS NULL
											GROUP BY material.MaterialID ,DATE_FORMAT(plan.DatePlan, '%y%m'), plan.ProductID
										Order BY product.ProductID ,plan.DatePlan, material.MaterialID ASC");
				
				while($row = mysqli_fetch_array ($data)):
			?>
		<tr>
			<td width="5%">
				<?php echo $no++; ?>
			</td>
			<td width="25%">
				<?php echo $row['ItemDescription']; ?>
			</td>
			<td width="15%">
				<?php echo $row['dateplan']; ?>
			</td>
			<td width="25%">
				<?php echo $row['RawMat']; ?>
			</td>
			<td width="25%">
				<?php echo $row['jml']; ?>
				<?php echo substr($row['Sloc'], 0, 3); ?> @
				<?php echo $row['QtyUnit']; ?> pcs
			</td>
			<td width="10%">
			<?php if($row['Lock']==='1'){ ?>
			<a href="stok/unlock.php?mat_id=<?php echo $row['MaterialID']; ?>&date_plan=<?php echo $row['dateplan']; ?>&prod_id=<?php echo $row['ProductID']; ?>" style="color: #00008B" ><i class="bi bi-unlock-fill"></i>UnLock</a>
			<?php } else { ?>
			<a href="stok/lock.php?mat_id=<?php echo $row['MaterialID']; ?>&date_plan=<?php echo $row['dateplan']; ?>&prod_id=<?php echo $row['ProductID']; ?>" style="color: #00008B" ><i class="bi bi-lock-fill"></i>Lock</a>
			<?php } ?> 
			</td>
		</tr>
			<?php endwhile; ?>
		</tbody>
	</table>
	</div>
	
	<script>
    
        $(document).ready(function () {
		$('#example').DataTable({
			scrollX: true,
			scrollY: true,
		});
	});
    </script>
