<?php
include "koneksi.php";
if (!isset($_SESSION["UserID"])) {
	header("location:login.php?p=3");
}
$q="SELECT * FROM user WHERE id='". $_SESSION["UserID"] ."'";
						$res=mysqli_query($conn,$q);
						$dataUser=mysqli_fetch_assoc($res);
					
						$nik = $dataUser["nik_data_karyawan"];

?>
<!DOCTYPE html>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="icon" type="image/png" href="images/mhb.jpeg">
<html>

	<head>
		<title> PT. MULTI HIDRACHROME BALIKPAPAN </title>
		<?php
				include "part/menu2.php";
				?>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<?php
		include "part/jss.php";
		?>
		

	</head>

	<body>

		<div style="width:1280px; height:220px" class="container" >

			
				<div class="alert alert-info" style='background-color:#F8F8FF' href="#">
				<div style="display: block; margin-left: auto; margin-right: auto; width: 1000px;  height:100px;"><img style="width: 1000px;  height:180px;" src="images/hd.jpg"></div>
				<div>
					<center>
						<h1>PT. MULTI HIDRACHROM BALIKPAPAN</h1>
					</center>
				</div>
				<div>
					<center>
						<h4 >PROFESIONAL INFORMATION SYSTEM</h4>
					</center>
				</div>
			</div>
				<div class="alert alert-info" align='center' >
					<h3>DAFTAR PR DIPROSES ALL LIST</h3>
					<h5>menampilkan seluruh list pr yang telah diproses dan mendapatkan suplier / harga</h5>
					<h5>tekan SELESAI jika hanya barang sudah sampai ke user</h5>
					<?php
					if (isset($_GET["p"])) 
					{
						$p = $_GET["p"];
						if ($p == "1") 
						{
						?>
						<div class="alert alert-success">
							PR CLOSE
						</div>
						<?php
						} 
						else if ($p == "3") 
						{
						?>
							<div class="alert alert-danger">
								PR GAGAL!
							</div>
						<?php
						}
					}
					?>
					<?php
					$z = 1;
					?>
					<table class="table table-bordered">
						<thead>
							<tr>
							    <th>
									NO 
								</th>
								<th>
									NIK
								</th>
								<th>
									PR NO
								</th>
								<th>
									DESC
								</th>
								<th>
									PR DATE
								</th>
								<th>
									SUPLIER / VENDOR
								</th>
								<th>
									DUE DATE USER
								</th>
								<th>
									HARGA
								</th>
								<th>
									GABUNG
								</th>
							</tr>
						</thead>
						<tbody>
							<?php
							$status = '1';
							$q = "SELECT * FROM data_purchasing_requisition WHERE status_spv = '2' AND (status_hcga = '2' OR status_operasional = '2') AND status_direktur = '2' AND status_proses = '1' AND jadikan_satu ='1'";
							$res = mysqli_query($conn, $q);
							while ($row = mysqli_fetch_assoc($res)) {
							?>
								<tr>
									<td>
									     <?php
									         echo $z;
									         $z = $z + 1;
											 //echo $row["id"];
									     ?>
								    </td>
									<td>
										<?php
										echo $row["user_request"];
										?>
									</td>
									<td>
										<?php
										echo $row["pr_no"];
										?>
									</td>
									<td>
										<?php
										echo $row["description"];
										?>
									</td>
									<td>
										<?php
										echo $row["pr_date"];
										?>
									</td>
									<td>
										<?php
										$id_suplier = $row['id_suplier'];
                                        $s = "SELECT * FROM data_suplier WHERE id=" .$row['id_suplier'];
                                        $resi = mysqli_query($conn,$s);
                                        $rowi = mysqli_fetch_array($resi);
										echo $rowi['nama_suplier'];
										?>
									</td>
									<td>
										<?php
										echo $row["acc_code"]; //acc code = due date, blm diganti nama saja
										?>
									</td>
									<td>
										<?php
										echo number_format($row["harga_total_pcs"]);
										?>
									</td>
									<td>
									<?php
									echo " <input type='checkbox' name='id[]' class'delete' value=" . $row['id'] . " />";
									?>
									</td>
								</tr>
							<?php
							}
							?>
						</tbody>
						
					</table>
					<Button type='button' id='btnGabung' class='btn btn-danger'>Advance</Button>
				</div>
				
		<center><h5 class="form-signin">Copyright &copy; <a href="#" data-toggle="modal" data-target="#contact">SatrioPringgondani</a></h5></center>  
	</body>
</html>

<script>
$(document).ready(function()
{
	 $('.table-bordered').DataTable();
});

function gabungPr(id) {
	$.ajax({
		url: "simpanPrAdvance.php",
		type: 'POST',
		data: {
			id: id
		},
		success: function(data) {
			alert("Data berhasil digabung");
			//window.location='test.php';
		},
		error: function(request, status, error) {
			alert(request.responseText);
		}
	});
}

$(document).ready(function() {
	$('#btnGabung').click(function() {
		if (confirm("Apakah anda yakin untuk menggabungkan?")) {
			var id = [];
			$(':checkbox:checked').each(function(i) {
				id[i] = $(this).val();
				//console.log(id[i]);
			});
			if (id.length === 0) //tell you if the array is empty
			{
				alert("Please Select atleast one checkbox");
			} else {
				alert("Gabungkan");
				$.ajax({
					url: 'simpanPrAdvance.php',
					method: 'POST',
					data: {
						id: id
					},
					success: function() {
						for (var i = 0; i < id.length; i++) {
							$('tr#' + id[i] + '').css('background-color', '#ccc');
							$('tr#' + id[i] + '').fadeOut('slow');
						}
						//window.location='prProsesPrcGabung.php'; 
						//ini diganti 
						//window.location='prDiprosesPrc.php';
						window.location='simpanPrAdvance.php';
					}
				});
			}
		} else {
			return false;
		}
	});
});





</script>