<?php include "../koneksi.php";
include "../nik.php";
$datauser = mysqli_query ($koneksi, "SELECT *
FROM user
WHERE Nik ='$nik'");
$row2= mysqli_fetch_array($datauser);
?>
<table class="table table-bordered">
        <thead>
		<tr>
			<th width="12%">
				Tanggal
			</th>
			<th width="10%">
				Mesin
			</th>
			<th width="24%">
				Product
			</th>
			<th width="24%">
				Material
			</th>
			<th width="5%">
				SLoc
			</th>
			<th width="5%">
				Quantity
			</th>
			<th width="7%">
				POOR
			</th>
			<th width="13%">
				Opsi
			</th>
		</tr>
		</thead>
		<tbody>
			<?php
				if( isset( $_GET['tgl'] )){
				//$tgl = preg_replace('/[^A-Za-z0-9]/', '', $_GET['tgl']); 
				$no = 1;
				$data = mysqli_query ($koneksi, " select 
														plan.PlanID,
														plan.DatePlan,
														plan.MesinID,
														mesin.Mesin,
														plan.ProductID,
														product.ItemDescription,
														product.SLoc,
														plan.QtyPlan,
														plan.Prioritas,
														plan.MaterialID,
														material.RawMat,
														plan.POOR
												  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 plan.DatePlan = '$_GET[tgl]'
												  order by plan.Prioritas ASC");
				} if( isset( $_GET['week'] )){
				$data = mysqli_query ($koneksi, " select 
													plan.PlanID,
													plan.DatePlan,
													plan.MesinID,
													mesin.Mesin,
													plan.ProductID,
													product.ItemDescription,
													product.SLoc,
													plan.QtyPlan,
													plan.Prioritas,
													plan.MaterialID,
													material.RawMat,
													plan.POOR
											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 plan.Week = '$_GET[week]'
											order by plan.DatePlan, plan.Prioritas ASC");

				}
				
				while($row = mysqli_fetch_array ($data)):
			?>
		<tr>
			<td width="12%">
				<?php 
				$tanggal = $row['DatePlan'];
				$day = date('D', strtotime($tanggal));
				$dayList = array(
					'Sun' => 'Minggu',
					'Mon' => 'Senin',
					'Tue' => 'Selasa',
					'Wed' => 'Rabu',
					'Thu' => 'Kamis',
					'Fri' => 'Jumat',
					'Sat' => 'Sabtu'
				);
				echo date ("d-m-Y", strtotime($tanggal)).' '.$dayList[$day]; ?>
			</td>
			<td width="10%">
				<?php echo $row['Mesin']; ?>
			</td>
			<td width="24%">
				<?php echo $row['ItemDescription']; ?>
			</td>
			<td width="24%">
				<?php echo $row['RawMat']; ?>
			</td>
			<td width="5%">
				<?php echo $row['SLoc']; ?>
			</td>
			<td width="5%">
				<?php echo $row['QtyPlan']; ?>
			</td>
			<td width="7%">
				<?php echo $row['POOR']; ?>
			</td>
			<td width="13%">
			<?php if($row2['Kasta']=='0' || $row2['Kasta']=='1'){ ?>
			    <a href="../plan/stpj.php?id=<?php echo $row['PlanID']; ?>&qty=<?php echo $row['QtyPlan']; ?>" style="color: #00008B" ><i class="bi bi-clipboard-check"></i> STPJ</a>&ensp;|&ensp;
			    <a href="../plan/pbb.php?id=<?php echo $row['PlanID']; ?>&mat=<?php echo $row['MaterialID']; ?>" style="color: #00008B" ><i class="bi bi-cart4"></i> PBB</a>
			<?php } else if ($row2['Kasta']=='2' || $row2['Kasta']=='3') { ?>
				<a href="lap_prod.php?id=<?php echo $row['PlanID']; ?>&shift=1" style="color: #00008B" ><i class="bi bi-clipboard-check"></i> Lap. Produksi</a>
			<?php } ?>
			</td>
		</tr>
			<?php endwhile; ?>
		</tbody>
	</table>