
<div class="pagetitle">
    <nav>
    <ol class="breadcrumb">
		<li class="breadcrumb-item">Purchase Order</li>
        <li class="breadcrumb-item">Detail PO</li>
    </ol>
</nav>
</div><!-- End Page Title -->

<p>
	<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modal-tambah">
	<i class="bi bi-plus-square"></i>&ensp;Tambah Data</button>
</p>
<div style="width:100%;height500px;overflow:scroll;" >
<table class="table table-bordered">
		<tr>
			<th>
				#
			</th>
			<th>
				Nomor PO
			</th>
			<th>
				Customer
			</th>
			<th>
				Product
			</th>
			<th>
				Quantity
			</th>
			<th>
				Opsi
			</th>
		</tr>
			<?php 
				include '../assets/pagination.php';
				include"koneksi.php";
				$reload = "ho/data.php?pagination=true";
				$no = 1;
				$data = mysqli_query ($koneksi, " select 
														detail_po.DetailPO_ID,
														po_tbl.No_PO,
														customer.CustomerName,
														product.ItemDescription,
														detail_po.QtyPO
												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
												order by DetailPO_ID DESC");
				
				$page=0;
				//pagination config start
				$rpp = 18; // jumlah record per halaman
				$reload;
				if (isset($_GET['page'])) {
					$page = intval($_GET["page"]);
				}
				if($page<=0) $page = 1;  
				$tcount = mysqli_num_rows($data);
				$tpages = ($tcount) ? ceil($tcount/$rpp) : 1; // total pages, last page number
				$count = 0;
				$i = ($page-1)*$rpp;
				$no_urut = ($page-1)*$rpp;
				//pagination config end

				while(($count<$rpp) && ($i<$tcount)):
					mysqli_data_seek($data,$i);
					$row = mysqli_fetch_array ($data);
			?>
		<tr>
			<td>
				<?php echo $no++; ?>
			</td>
			<td>
				<?php echo $row['No_PO']; ?>
			</td>
			<td>
				<?php echo $row['CustomerName']; ?>
			</td>
			<td>
				<?php echo $row['ItemDescription']; ?>
			</td>
			<td>
				<?php echo $row['QtyPO']; ?>
			</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> Edit</a>&ensp;|&ensp; 
				<a href="#" style="color: #DC143C" data-href="detail_po/hapus.php?id=<?php echo $row['DetailPO_ID']; ?>" data-toggle="modal" data-target="#confirm-delete"><i class="bi bi-trash-fill"></i> Hapus</a> 
			</td>
		</tr>
			<?php 
			$i++; 
			$count++;
			endwhile; ?>
	</table>
	<div style="text-align: center"><?php echo paginate_one($reload, $page, $tpages); ?></div>
	</div>
		<!-- 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>
