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

$aresult = mysqli_query($conn,"select distinct account_year from branches ") or die(mysqli_error());
$arow = mysqli_fetch_row($aresult);
$account_year = $arow[0];


if (isset($submit) && $submit == "Submit")
{
	$result="delete from salesreg where trans_id = '$mypono'  and account_year='$account_year' and compcode='$compcode' ";
		echo "Removed the Invoice and Updated Sales Register<br>";
		mysqli_query($conn,$result) or die (mysqli_error());

		$mresult = mysqli_query($conn,"select distinct purreg_record,outqty from stktrans where trans_id = '$mypono' and account_year = '$account_year' and compcode = '$compcode' ") or die(mysqli_error());
		while($mrow = mysqli_fetch_row($mresult))
		{
			mysqli_query($conn,"update purchasereg set issued_qty = issued_qty -$mrow[1] where record = '$mrow[0]' ") or die(mysqli_error());
		}
	

	$result = "delete from stktrans  where trans_id = '$mypono'  and account_year='$account_year' and compcode='$compcode' "; 
		echo "Removed from Stock Transactions and Updated<br>";
		mysqli_query($conn,$result) or die (mysqli_error());

	$result = "delete from ledger where trans_id = '$mypono'  and account_year='$account_year' and compcode='$compcode' "; 
		echo "Removed from Ledger and updated<br>";
		mysqli_query($conn,$result) or die (mysqli_error());
		
	$result = "delete from bill_patient where trans_id = '$mypono'  and account_year='$account_year' "; 
		echo "Removed from Ledger and updated<br>";
		mysqli_query($conn,$result) or die (mysqli_error());		


}




?>

<script language="JavaScript">
close();
</script>
