<?php include "../koneksi.php"; ?>
<table class="table table-bordered">
		<tr>
			<th width="5%">
				#
			</th>
			<th width="35%">
				Kode
			</th>
			<th width="20%">
				NoLot
			</th>

			<th width="15%">
				Pack
			</th>
			<th width="5%" >
				Opsi
			</th>
		</tr>
			<?php 
				$no = 1;
				$data = mysqli_query ($koneksi, " select 
														stpj.STPJ_ID,
														plan.PlanID,
														plan.DatePlan,
														plan.POOR,
														product.QtyUnit,
														product.SLoc,
														stpj.Kode,
														stpj.Material,
														stpj.NoLot,
														stpj.Nick,
														stpj.Qty,
														plan.WH_Conf
												from 
												stpj 
												INNER JOIN plan
												ON stpj.PlanID=plan.PlanID
												INNER JOIN product
												ON plan.ProductID=product.ProductID
												WHERE stpj.PlanID ='$_GET[id]' AND stpj.Shift=0 OR stpj.PlanID ='$_GET[id]' AND stpj.Shift>0 AND plan.WH_Conf=1
												GROUP BY stpj.STPJ_ID	
												order by stpj.Shift, stpj.Kode, stpj.NoLot ASC");
				
	

				while($row = mysqli_fetch_array ($data)): ?>
		<tr>
			<td width="5%">
				<?php echo $no++; ?>
			</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="10%">
				<?php 
				if ($row['SLoc']=='NTN2') {
				echo $row['Nick'];
				} else {
				echo $row['Qty'].' ';
				echo substr($row['SLoc'], 0, 3); } ?>
			</td>
			<td width="15%">
				<a href="#" style="color: #DC143C" data-href="hapus_stpj.php?id=<?php echo $row['STPJ_ID']; ?>&plan_id=<?php echo $row['PlanID']; ?>" data-toggle="modal" data-target="#confirm-delete"><i class="bi bi-trash-fill"></i></a> 
			</td>
		</tr>
			<?php endwhile; ?>
	</table>


		<!-- Modal -->
		<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
            
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="myModalLabel">Kofirmasi Hapus</h4>
                </div>
            
                <div class="modal-body">
                    <p>Apakah anda mau melanjutkan menghapus data?</p>
                    <p class="debug-url"></p>
                </div>
                
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                    <a class="btn btn-danger btn-ok">Delete</a>
                </div>
            </div>
        </div>
    </div>

	<script>
        $('#confirm-delete').on('show.bs.modal', function(e) {
            $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
            
        });
    </script>
