<?php include("../../include/dbconnect.php"); 

$aresult = mysql_query("select distinct account_year from company ") or die(mysql_error());
$arow = mysql_fetch_row($aresult);
$account_year = $arow[0];

$invnos = $mypono;
if (isset($submit) && $submit == "Submit")
{


				$result = mysql_query("select cust_record from salesreg where invno='$invnos'  and drawing_no ='TOTAL' and account_year = '$account_year' ") or die(mysql_error());
				$row = mysql_fetch_row($result);
				$cust_record=$row[0];


				$salresult = mysql_query("select order_record,remarks,quantity,record from salesreg where invno='$invnos'  and drawing_no !='TOTAL'  and account_year='$account_year' ") or die(mysql_error());
				while($salrow = mysql_fetch_row($salresult))
				{	
						$order_record=$salrow[0];
						$s_remarks = $salrow[1];
						$quantity = $salrow[2];
						$record = $salrow[3];
					
						$result = mysql_query("select issued_qty,balance_qty,remarks from orders where record= '$order_record' ") or die(mysql_error());
						$row = mysql_fetch_row($result);
				
						$issued_qty=$row[0]- $quantity;
						$balance_qty=$row[1]+$quantity;
			
						$query="update orders set  issued_qty ='$issued_qty',balance_qty = '$balance_qty' where record = '$order_record' ";
						mysql_query($query) or die(mysql_error());
				}		

					$query =" delete from salesreg where invno='$invnos'  and account_year='$account_year'  ";
					 mysql_query($query) or die(mysql_error());


					$query =" delete from custledger where record = '$cust_record' ";
					 mysql_query($query) or die(mysql_error());
					
										
				echo(" Invoice amount removed from Customer Ledger also<br>");				
				


}
?>
<meta http-equiv="refresh" content="0 url=index.html">