<?php
	include('connect.php');
	
	
	$ISBN=$_GET['ISBN'];
	$rinvNo = $_GET['invNo'];
	$poNo = $_GET['poNo'];
	$q = $_GET['q'];
	
$result4 = mysql_query("SELECT * FROM receivedinvitem WHERE invNo = '$rinvNo'");

$num_results = $result4->num_rows;

if($num_results>1){
	$result2 = mysql_query("SELECT qtotal FROM receivedinvoice WHERE rinvNo = '$rinvNo'");
	
	$row2 = mysql_fetch_array($result2);
	$o = $row2['qtotal'];
	$n = $o - $q;
	
	$query=mysql_query("delete from receivedinvitem where ISBN='$ISBN'&&invNo='$rinvNo'");
	
	$query3= "UPDATE receivedinvoice SET qtotal = '$n' WHERE rinvNo='$rinvNo'");
	
	
	echo "<script>alert('Book is deleted.')</script>";
	echo "<script language='javascript'>window.location='restockitem.php?rinvNo=$rinvNo&&poNo=$poNo'</script>";
}else{
	echo "<script>alert('You cannot remove all item.')</script>";
	echo "<script language='javascript'>window.location='restockitem.php?rinvNo=$rinvNo&&poNo=$poNo'</script>";
}
?>