<?php
include "../koneksi.php";

$pbb_id = $_GET['pbb_id'];
$plan_id = $_GET['id'];
$mat = $_GET['mat'];
$query1 = "UPDATE plan SET
								NoPBB_ID=NULL
							WHERE PlanID ='$plan_id'";

mysqli_query($koneksi, $query1)
or die ("Gagal Perintah SQL".mysql_error());

$data = mysqli_query ($koneksi, " SELECT pbb.PBB_ID
												FROM pbb
												INNER JOIN incoming
												ON pbb.IncomingID=incoming.IncomingID
												INNER JOIN material
												ON incoming.MaterialID=material.MaterialID
												WHERE material.MaterialID='$mat' AND pbb.NoPBB_ID='$pbb_id'");
while($row = mysqli_fetch_array ($data)) {

	$query2 = "UPDATE pbb SET
								NoPBB_ID=NULL,
								POOR=NULL
							WHERE PBB_ID ='$row[PBB_ID]'";

	mysqli_query($koneksi, $query2)
	or die ("Gagal Perintah SQL".mysql_error());

}

$query = "DELETE FROM no_pbb 
							WHERE NoPBB_ID ='$pbb_id'
								";

mysqli_query($koneksi, $query)
or die ("Gagal Perintah SQL".mysql_error());

header('Location:pbb.php?id='.$plan_id.'&mat='.$mat);

?>

