<?php
include "koneksi.php";
//$ids[]=$row->id;

// var_dump($_POST["id"]);
isset($_POST["id"]);

//$a = "SELECT * FROM data_gabungan_pr WHERE id='1'";
//$res = mysqli_query($conn, $a);	
//$row = mysqli_fetch_assoc($res);
//$gabungan = $row["gabungan"];
//$hasil = $gabungan;
//$tanggal =  date('dmY');
//$hasilTanggal = $hasil.$tanggal;

//echo"gabungan hasil dan tanggal ".$hasilTanggal."<br>";
//echo"hasil ".$hasil."<br>";
//$tambah = $hasil + 1;
//echo "tambah".$tambah;
//echo "id = ".$id;
$a = 1;
//$as = "UPDATE advance SET advance = '2' WHERE id='1'";
//$insertas = mysqli_query($conn, $as);
//$s = "UPDATE data_purchasing_requisition SET advance='2' WHERE advance == '3'";
//$inserts = mysqli_query($conn, $s);
//$r = "DELETE FROM advance";
//$insertr = mysqli_query($conn, $r);

//$ad = "ALTER advance id AUTO_INCREMENT = 1";
//$insertad = mysqli_query($conn, $ad);

$t = "SELECT * FROM advance_no WHERE id ='1'";
$insertt = mysqli_query($conn, $t);
$rowt = mysqli_fetch_assoc($insertt);
$no_advance = $rowt["no_advance"];

echo "advance = ".$no_advance;

if ($no_advance == 3)
{
	if (isset($_POST["id"])) 
	{
		foreach ($_POST["id"] as $id) 
		{
		
			$q = "INSERT advance SET advance='4', id_advance=".$id;
			echo $q;
			$insert = mysqli_query($conn, $q);
			
			$u = "UPDATE advance_no SET no_advance = '4' WHERE id='1'";
			echo $u;
			$insertu = mysqli_query($conn, $u);
			
			$d = "DELETE FROM advance WHERE advance='3'";
			echo $d;
			$insertd = mysqli_query($conn, $d);
		
			//$tambah = $hasil + 1;
			//$d = "UPDATE data_gabungan_pr SET gabungan='$tambah'";
			//mysqli_query($conn, $d);	    
			//header("location:prAdvancePDF.php?id=".$id);
			
        			
		}
	}
}
if ($no_advance == 4)
{
	if (isset($_POST["id"])) 
	{
		foreach ($_POST["id"] as $id) 
		{
			$q = "INSERT advance SET advance='3', id_advance=".$id;
			echo $q;
			$insert = mysqli_query($conn, $q);
		
			$u = "UPDATE advance_no SET no_advance = '3' WHERE id='1'";
			echo $u;
			$insertu = mysqli_query($conn, $u);
			
			$d = "DELETE FROM advance WHERE advance='4'";
			echo $d;
			$insertd = mysqli_query($conn, $d);
		
			//$tambah = $hasil + 1;
			//$d = "UPDATE data_gabungan_pr SET gabungan='$tambah'";
			//mysqli_query($conn, $d);	    
			//header("location:prAdvancePDF.php?id=".$id);
			
			
		}
	}
}
if ($a == 1)
{
		header("location:prAdvancePDF.php?");
}




?>