<?php include "../koneksi.php"; ?>
<table class="table table-bordered">
		<tr>
			<th>
				#
			</th>
			<th>
				Product
			</th>
			<th>
				Quantity
			</th>
			<th>
				BalancePO
			</th>
			<th>
				Opsi
			</th>
		</tr>
			<?php 
				$no = 1;
				$data = mysqli_query ($koneksi, " select 
														detail_po.DetailPO_ID,
														po_tbl.PO_ID,
														po_tbl.No_PO,
														customer.CustomerName,
														product.ItemDescription,
														product.SLoc,
														detail_po.QtyPO,
														detail_po.BalancePO
												from 
												detail_po 
												INNER JOIN po_tbl
												ON detail_po.PO_ID=po_tbl.PO_ID
												INNER JOIN product
												ON detail_po.ProductID=product.ProductID
												INNER JOIN customer
												ON po_tbl.CustomerID=customer.CustomerID
												WHERE detail_po.PO_ID ='$_GET[id]'");
				

				while($row = mysqli_fetch_array ($data)):
			?>
		<tr>
			<td>
				<?php echo $no++; ?>
			</td>
			<td>
				<?php echo $row['ItemDescription']; ?>
			</td>
			<td>
				<?php echo $row['QtyPO']; ?>
			</td>
			<td>
				<?php echo $row['BalancePO']; ?>
				<?php echo substr($row['SLoc'], 0, 3); ?>
			</td>
			<td>
				<a href="#"  style="color: #DAA520" class='editbtn' id="edit" data-id="<?php echo $row['DetailPO_ID']; ?>"><i class="bi bi-pen-fill"></i></i> Edit</a>
				<a href="#" style="color: #DC143C" data-href="hapusdetailpo.php?id=<?php echo $row['DetailPO_ID']; ?>&po_id=<?php echo $row['PO_ID']; ?>" data-toggle="modal" data-target="#confirm-delete"><i class="bi bi-trash-fill"></i> Hapus</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>

    <div id="modal-edit" class="modal fade" role="dialog">
		<div class="modal-dialog modal-md">
			<div class="modal-content">
				<form role="form" id="form-edit" method="post" action="edit_detailpo.php" autocomplete="off">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">&times;</button>
					<h4 class="modal-title">Edit Purchasing Order</h4>
				</div>
					<div class="modal-body">
						<div id="data-edit">
						
						</div>				
					</div>
					
					<div class="modal-footer">
						<button type="button" class="btn btn-info" data-dismiss="modal">Batal</button>
						<button type="submit" class="btn btn-primary" >Simpan</button>
					</div>
				</form>		
			</div>
		</div>
	</div> 

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

        $(document).on('click','#edit',function(e){
		e.preventDefault();
		$("#modal-edit").modal('show');
		$.post('things.php',
			{id:$(this).attr('data-id')},
			function(html){
				$("#data-edit").html(html);
			}   
		);
	});

        
    </script>
