<?php include "../koneksi.php"; ?>
<div class="row">
<div class="col-md-6">
<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>
<div class="col-md-6">
	 <nav>
    <ol class="breadcrumb">
		<li class="breadcrumb-item">Produksi</li>
        <li class="breadcrumb-item">Table Planning</li>
    </ol>
</nav>
</div>
</div>
<div style="width:100%;height500px;overflow:scroll;" >
<table id="example" class="display nowrap" style="width:100%">
        <thead>
		<tr>
			<th width="5%">
				Tanggal
			</th>
			<th width="5%">
				Mesin
			</th>
			<th width="25%">
				Product
			</th>
			<th width="25%">
				Material
			</th>
			<th width="5%">
				SLoc
			</th>
			<th width="5%">
				Quantity
			</th>
			<th width="10%">
				POOR
			</th>
			<th width="20%">
				Opsi
			</th>
		</tr>
		</thead>
		<tbody>
			<?php 
				$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
												  order by plan.DatePlan DESC");
				
				while($row = mysqli_fetch_array ($data)):
			?>
		<tr>
			<td width="5%">
				<?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="5%">
				<?php echo $row['Mesin']; ?>
			</td>
			<td width="25%">
				<?php echo $row['ItemDescription']; ?>
			</td>
			<td width="25%">
				<?php echo $row['RawMat']; ?>
			</td>
			<td width="5%">
				<?php echo $row['SLoc']; ?>
			</td>
			<td width="5%">
				<?php echo $row['QtyPlan']; ?>
			</td>
			<td width="10%">
				<?php echo $row['POOR']; ?>
			</td>
			<td width="20%">
			    <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="#" style="color: #DAA520" class='editbtn' id="edit" data-id="<?php echo $row['PlanID']; ?>"><i class="bi bi-pen-fill"></i> Edit</a>&ensp;|&ensp; 
				<a href="#" style="color: #DC143C" data-href="plan/hapus.php?id=<?php echo $row['PlanID']; ?>" data-toggle="modal" data-target="#confirm-delete"><i class="bi bi-trash-fill"></i> Hapus</a> 
			</td>
		</tr>
			<?php endwhile; ?>
		</tbody>
	</table>
	</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'));
            
        });

		$.fn.dataTableExt.oSort['time-date-sort-pre'] = function(value) {      
		return Date.parse(value);
		};
		$.fn.dataTableExt.oSort['time-date-sort-asc'] = function(a,b) {      
			return a-b;
		};
		$.fn.dataTableExt.oSort['time-date-sort-desc'] = function(a,b) {
			return b-a;
		};

		var table = $('#example').DataTable({
			columnDefs : [
				{ type: 'time-date-sort', 
				targets: [0],
				}
			],
			order: [[ 0, "desc" ]]
		});
    </script>
