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

    //mengambil nama
	 $d="SELECT * FROM data_karyawan WHERE nik=".$nik;
						$resi=mysqli_query($conn,$d);
						$dataUser1=mysqli_fetch_assoc($resi);				
						$nama = $dataUser1["nama_karyawan"];
						echo "NAMA :".$nama."<br>";
						
	// mengambil nomor terakhir nomor PR
	$p="SELECT * FROM nomor_otomatis_pr WHERE id='1'";
						$resp=mysqli_query($conn,$p);
						$dataUserp=mysqli_fetch_assoc($resp);
					
						$pr = $dataUserp["nomor_pr"];
						$tambah = $pr + 1;
						echo "pr :".$pr;
						
						$quryPr = "UPDATE nomor_otomatis_pr SET nomor_pr = $tambah WHERE id = '1'";
						$resultPr = mysqli_query($conn, $quryPr);


	//$id=mysqli_real_escape_string($conn,$_POST["id"]);
	
	// mengambil data inputan dari tambah pengajuan purchasing
	$nik = $dataUser["nik_data_karyawan"];
	$nama = $dataUser1["nama_karyawan"];
	$pr_no=$_POST["pr_no"];
	$type_of_material=$_POST["type_of_material"];
    $prt=$_POST["prt"];
	$document_no='MHB-FR-PRC-001-01';
	$pr_date = date('d-m-Y');
	$note = $_POST["note"];
	
	//barang 1
	$matr_master1=$_POST["matr_master1"];
	$description1=$_POST["description1"];
	$part_no1=$_POST["part_no1"];
	$qty1=$_POST["qty1"];
	$unit1=$_POST["unit1"];
	$justification1=$_POST["justification1"];
	$acc_code1=$_POST["acc_code1"];
	
	//barang 2
	$matr_master2=$_POST["matr_master2"];
	$description2=$_POST["description2"];
	$part_no2=$_POST["part_no2"];
	$qty2=$_POST["qty2"];
	$unit2=$_POST["unit2"];
	$justification2=$_POST["justification2"];
	$acc_code2=$_POST["acc_code2"];
	
	//barang 3
	$matr_master3=$_POST["matr_master3"];
	$description3=$_POST["description3"];
	$part_no3=$_POST["part_no3"];
	$qty3=$_POST["qty3"];
	$unit3=$_POST["unit3"];
	$justification3=$_POST["justification3"];
	$acc_code3=$_POST["acc_code3"];
	
	//barang 4
	$matr_master4=$_POST["matr_master4"];
	$description4=$_POST["description4"];
	$part_no4=$_POST["part_no4"];
	$qty4=$_POST["qty4"];
	$unit4=$_POST["unit4"];
	$justification4=$_POST["justification4"];
	$acc_code4=$_POST["acc_code4"];

    //barang 5
	$matr_master5=$_POST["matr_master5"];
	$description5=$_POST["description5"];
	$part_no5=$_POST["part_no5"];
	$qty5=$_POST["qty5"];
	$unit5=$_POST["unit5"];
	$justification5=$_POST["justification5"];
	$acc_code5=$_POST["acc_code5"];	
	
	 //barang 6
	$matr_master6=$_POST["matr_master6"];
	$description6=$_POST["description6"];
	$part_no6=$_POST["part_no6"];
	$qty6=$_POST["qty6"];
	$unit6=$_POST["unit6"];
	$justification6=$_POST["justification6"];
	$acc_code6=$_POST["acc_code6"];	
	
	//barang 7
	$matr_master7=$_POST["matr_master7"];
	$description7=$_POST["description7"];
	$part_no7=$_POST["part_no7"];
	$qty7=$_POST["qty7"];
	$unit7=$_POST["unit7"];
	$justification7=$_POST["justification7"];
	$acc_code7=$_POST["acc_code7"];	
	
	//barang 8
	$matr_master8=$_POST["matr_master8"];
	$description8=$_POST["description8"];
	$part_no8=$_POST["part_no8"];
	$qty8=$_POST["qty8"];
	$unit8=$_POST["unit8"];
	$justification8=$_POST["justification8"];
	$acc_code8=$_POST["acc_code8"];	
	
	//barang 9
	$matr_master9=$_POST["matr_master9"];
	$description9=$_POST["description9"];
	$part_no9=$_POST["part_no9"];
	$qty9=$_POST["qty9"];
	$unit9=$_POST["unit9"];
	$justification9=$_POST["justification9"];
	$acc_code9=$_POST["acc_code9"];	
	
	//barang 10
	$matr_master10=$_POST["matr_master10"];
	$description10=$_POST["description10"];
	$part_no10=$_POST["part_no10"];
	$qty10=$_POST["qty10"];
	$unit10=$_POST["unit10"];
	$justification10=$_POST["justification10"];
	$acc_code10=$_POST["acc_code10"];
	
	//1
	if ($description1 == !NULL)
	{
		echo"query 1"."<br>";
		$query1 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master1','$description1','$part_no1','$qty1','$unit1','$justification1','$acc_code1','$nik','0','0','0','$level')";
			   
			   $result1 = mysqli_query($conn, $query1);
			   //echo "query".$query1;
			   
			   if($result1)
	            {
		             echo "Data berhasil masuk".$query1;
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             //die("Error");
					 echo "gagal 1". $query1;
	            }
		
		//2
		if ($description2 == !NULL AND $description3 == NULL)
		{
			echo"query 2"."<br>";
			$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master2','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   
			   $result2 = mysqli_query($conn, $query2);
			   //echo "query".$query1;
			   
			   if($result2)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
		}
		//3
		if ($description3 == !NULL AND $description4 == NULL)
		{
			if($description2 == NULL)
	     	{
		       echo "<br>"."2 kosong, isi dengan berurut";
			   $tidak_query = 1;
			   header("location:tambahPengajuanPurchasing.php?p=3");
		             die("Error");
		    }
			else
			{
			   echo"query 2,3"."<br>";
			   $query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   if($result2 AND $result3)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
		    }
		}
		//4
		if ($description4 == !NULL AND $description5 == NULL)
		{
			if($description3 == NULL OR $description2 == NULL)
			{
				echo "<br>"."3,2 kosong isi dengan berurut";
				$tidak_query = 1;
				 {
		             header("location:tambahPengajuanPurchasing.php?p=3");
		             die("Error");
	            }
			}
			else
			{
				echo"query 2,3,4"."<br>";
				$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   $query4 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master4','$description4','$part_no4','$qty4','$unit4','$justification4','$acc_code4','$nik','0','0','0','$level')";
			   $result4 = mysqli_query($conn, $query4);
			   
			   if($result2 AND $result3 AND $result4)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
			}
		}
		//5
		if ($description5 == !NULL AND $description6 == NULL)
		{
			if($description4 == NULL OR $description3 == NULL OR $description2 == NULL)
			{
				echo "<br>"."4,3,2 kosong isi dengan berurut";
				$tidak_query = 1;
				header("location:tambahPengajuanPurchasing.php?p=3");
		        die("Error");
			}
			else
			{
				echo"query 2,3,4,5"."<br>";
				$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   $query4 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master4','$description4','$part_no4','$qty4','$unit4','$justification4','$acc_code4','$nik','0','0','0','$level')";
			   $result4 = mysqli_query($conn, $query4);
			   
			   $query5 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master5','$description5','$part_no5','$qty5','$unit5','$justification5','$acc_code5','$nik','0','0','0','$level')";
			   $result5 = mysqli_query($conn, $query5);
			   
			   if($result2 AND $result3 AND $result4 AND $result5)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
			}
		}
		//6
		if ($description6 == !NULL AND $description7 == NULL)
		{
			if($description5 == NULL OR $description4 == NULL OR $description3 == NULL OR $description2 == NULL)
			{
				echo "<br>"."5,4,3,2 kosong, isi dengan berurut";
				$tidak_query = 1;
				header("location:tambahPengajuanPurchasing.php?p=3");
		        die("Error");
			}
			else
			{
				echo"query 2,3,4,5,6"."<br>";
				$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   $query4 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master4','$description4','$part_no4','$qty4','$unit4','$justification4','$acc_code4','$nik','0','0','0','$level')";
			   $result4 = mysqli_query($conn, $query4);
			   
			   $query5 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master5','$description5','$part_no5','$qty5','$unit5','$justification5','$acc_code5','$nik','0','0','0','$level')";
			   $result5 = mysqli_query($conn, $query5);
			   
			   $query6 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master6','$description6','$part_no6','$qty6','$unit6','$justification6','$acc_code6','$nik','0','0','0','$level')";
			   $result6 = mysqli_query($conn, $query6);
			   
			   if($result2 AND $result3 AND $result4 AND $result5 AND $result6)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
			}
		}
		//7
		if ($description7 == !NULL AND $description8 == NULL)
		{
			if($description6 == NULL OR $description5 == NULL OR $description4 == NULL OR $description3 == NULL OR $description2 == NULL)
			{
				echo "<br>"."6,5,4,3,2 kosong, isi dengan berurut ";
				$tidak_query = 1;
				header("location:tambahPengajuanPurchasing.php?p=3");
		        die("Error");
			}
			else
			{
				echo "query 2,3,4,5,6,7"."<br>";
				$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   $query4 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master4','$description4','$part_no4','$qty4','$unit4','$justification4','$acc_code4','$nik','0','0','0','$level')";
			   $result4 = mysqli_query($conn, $query4);
			   
			   $query5 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master5','$description5','$part_no5','$qty5','$unit5','$justification5','$acc_code5','$nik','0','0','0','$level')";
			   $result5 = mysqli_query($conn, $query5);
			   
			   $query6 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master6','$description6','$part_no6','$qty6','$unit6','$justification6','$acc_code6','$nik','0','0','0','$level')";
			   $result6 = mysqli_query($conn, $query6);
			   
			   $query7 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master7','$description7','$part_no7','$qty7','$unit7','$justification7','$acc_code7','$nik','0','0','0','$level')";
			   $result7 = mysqli_query($conn, $query7);
			   
			   if($result2 AND $result3 AND $result4 AND $result5 AND $result6 AND $result7)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
			}
		}
		//8
		if ($description8 == !NULL AND $description9 == NULL)
		{
			if($description7 == NULL OR $description6 == NULL OR $description5 == NULL OR $description4 == NULL OR $description3 == NULL OR $description2 == NULL)
			{
				echo "<br>"."7,6,5,4,3,2 kosong, isi dengan berurut ";
				$tidak_query = 1;
				header("location:tambahPengajuanPurchasing.php?p=3");
		        die("Error");
			}
			else
			{
				echo "query 2,3,4,5,6,7,8"."<br>";
				$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   $query4 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master4','$description4','$part_no4','$qty4','$unit4','$justification4','$acc_code4','$nik','0','0','0','$level')";
			   $result4 = mysqli_query($conn, $query4);
			   
			   $query5 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master5','$description5','$part_no5','$qty5','$unit5','$justification5','$acc_code5','$nik','0','0','0','$level')";
			   $result5 = mysqli_query($conn, $query5);
			   
			   $query6 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master6','$description6','$part_no6','$qty6','$unit6','$justification6','$acc_code6','$nik','0','0','0','$level')";
			   $result6 = mysqli_query($conn, $query6);
			   
			   $query7 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master7','$description7','$part_no7','$qty7','$unit7','$justification7','$acc_code7','$nik','0','0','0','$level')";
			   $result7 = mysqli_query($conn, $query7);
			   
			   $query8 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master8','$description8','$part_no8','$qty8','$unit8','$justification8','$acc_code8','$nik','0','0','0','$level')";
			   $result8 = mysqli_query($conn, $query8);
			   
			   if($result2 AND $result3 AND $result4 AND $result5 AND $result6 AND $result7 AND $result8)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
			}
		}
		//9
		if ($description9 == !NULL AND $description10 == NULL)
		{
			if($description8 == NULL OR $description7 == NULL OR $description6 == NULL OR $description5 == NULL OR $description4 == NULL OR $description3 == NULL OR $description2 == NULL)
			{
				echo "<br>"."8,7,6,5,4,3,2 kosong, isi dengan berurut ";
				$tidak_query = 1;
				header("location:tambahPengajuanPurchasing.php?p=3");
		        die("Error");
			}
			else
			{
				echo "query 2,3,4,5,6,7,8,9"."<br>";
				$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   $query4 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master4','$description4','$part_no4','$qty4','$unit4','$justification4','$acc_code4','$nik','0','0','0','$level')";
			   $result4 = mysqli_query($conn, $query4);
			   
			   $query5 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master5','$description5','$part_no5','$qty5','$unit5','$justification5','$acc_code5','$nik','0','0','0','$level')";
			   $result5 = mysqli_query($conn, $query5);
			   
			   $query6 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master6','$description6','$part_no6','$qty6','$unit6','$justification6','$acc_code6','$nik','0','0','0','$level')";
			   $result6 = mysqli_query($conn, $query6);
			   
			   $query7 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master7','$description7','$part_no7','$qty7','$unit7','$justification7','$acc_code7','$nik','0','0','0','$level')";
			   $result7 = mysqli_query($conn, $query7);
			   
			   $query8 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master8','$description8','$part_no8','$qty8','$unit8','$justification8','$acc_code8','$nik','0','0','0','$level')";
			   $result8 = mysqli_query($conn, $query8);
			   
			   $query9 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master9','$description9','$part_no9','$qty9','$unit9','$justification9','$acc_code9','$nik','0','0','0','$level')";
			   $result9 = mysqli_query($conn, $query9);
			   
			   if($result2 AND $result3 AND $result4 AND $result5 AND $result6 AND $result7 AND $result8 AND $result9)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             header("location:tambahPengajuanPurchasing.php?p=2");
		             die("Error");
	            }
			}
		}
		//10
		if ($description10 == !NULL)
		{
			if($description9 == NULL OR $description8 == NULL OR $description7 == NULL OR $description6 == NULL OR $description5 == NULL OR $description4 == NULL OR $description3 == NULL OR $description2 == NULL)
			{
				echo "<br>"."9,8,7,6,5,4,3,2 kosong, isi dengan berurut ";
				$tidak_query = 1;
				header("location:tambahPengajuanPurchasing.php?p=3");
		        die("Error");
			}
			else
			{
				echo "query 2,3,4,5,6,7,8,9,10"."<br>";
				$query2 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master12','$description2','$part_no2','$qty2','$unit2','$justification2','$acc_code2','$nik','0','0','0','$level')";
			   $result2 = mysqli_query($conn, $query2);
			   
			   $query3 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master3','$description3','$part_no3','$qty3','$unit3','$justification3','$acc_code3','$nik','0','0','0','$level')";
			   $result3 = mysqli_query($conn, $query3);
			   
			   $query4 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master4','$description4','$part_no4','$qty4','$unit4','$justification4','$acc_code4','$nik','0','0','0','$level')";
			   $result4 = mysqli_query($conn, $query4);
			   
			   $query5 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master5','$description5','$part_no5','$qty5','$unit5','$justification5','$acc_code5','$nik','0','0','0','$level')";
			   $result5 = mysqli_query($conn, $query5);
			   
			   $query6 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master6','$description6','$part_no6','$qty6','$unit6','$justification6','$acc_code6','$nik','0','0','0','$level')";
			   $result6 = mysqli_query($conn, $query6);
			   
			   $query7 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master7','$description7','$part_no7','$qty7','$unit7','$justification7','$acc_code7','$nik','0','0','0','$level')";
			   $result7 = mysqli_query($conn, $query7);
			   
			   $query8 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master8','$description8','$part_no8','$qty8','$unit8','$justification8','$acc_code8','$nik','0','0','0','$level')";
			   $result8 = mysqli_query($conn, $query8);
			   
			   $query9 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master9','$description9','$part_no9','$qty9','$unit9','$justification9','$acc_code9','$nik','0','0','0','$level')";
			   $result9 = mysqli_query($conn, $query9);
			   
			   $query10 = "INSERT INTO data_purchasing_requisition (pr_no,pr_date,type_of_material,document_no,note,purchase_request_type,
	            matr_master,description,part_no,quantity,unit,justification,acc_code,user_request,status_spv,status_hcga,status_direktur,level_spv)
			    VALUE
			   ('$pr','$pr_date','$type_of_material','$document_no','$note','$prt',
			    '$matr_master10','$description10','$part_no10','$qty10','$unit10','$justification10','$acc_code10','$nik','0','0','0','$level')";
			   $result10 = mysqli_query($conn, $query10);
			   
		        if($result2 AND $result3 AND $result4 AND $result5 AND $result6 AND $result7 AND $result8 AND $result9 AND $result10)
	            {
		             echo "Data berhasil masuk";
	   	             header("location:tambahPengajuanPurchasing.php?p=1");
	            }
	            else
	            {
		             //header("location:tambahPengajuanPurchasing.php?p=2");
		             //die("Error");
					 echo "gagal";
	            } 
			}
		}
	}
	else if($description1 == NULL)
	{
		echo "<br>"."1 kosong, isi dengan berurut";
		echo "<br>"."ini".$description1;
		header("location:tambahPengajuanPurchasing.php?p=3");
		die("Error");
	}
	//$tidak_query;
	//echo $tidak_query;	
?>