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

<body background="../../images/blater01.gif" topmargin=0>
<?
echo("ACCTCODE : $acctcode<br>");
if ( isset($submit) && $submit == "Update")
{

     $query ="update acctmast set description ='$description',active = '$active',reserved_word = '$reserved_word',opening_balance = '$opb',acctgroup = '$acgroup' where record ='$record' ";
	 echo("$query<br>");
	 mysqli_query($conn,$query) or die(mysqli_error());


}
	
elseif (isset($submit) && $submit == "Delete")
{

	$result = mysqli_query($conn,"select distinct prodcode from product where prodcode = '$acctcode' ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	if($row[0] > 0)
	{
		echo("<h3>This Product acct head can't be deleted from here. Please delete from Product master</h3><br>");
		?>		
		<br><br><font size=1><center>
		  <font face="Arial, Helvetica, sans-serif"><a href= "view.php">Return to View
		  page</font>
		</center>		
		<?
		exit;
	}
	$result = mysqli_query($conn,"select distinct bcode from buy where bcode = '$acctcode' ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	if($row[0] > 0)
	{
		echo("<h3>This Customer Acct head can't be deleted from here. Please delete from Customer master</h3><br>");
?>		
<br><br><font size=1><center>
  <font face="Arial, Helvetica, sans-serif"><a href= "view.php">Return to View
  page</font>
</center>		
<?
		exit;

	}


	$result = mysqli_query($conn,"select distinct acctcode from ledger where acctcode = '$acctcode' ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	if($row[0] > 0)
	{
		echo("<h3>Can't remove the Account head.  Found Transactions for this Account.</h3><br>");
		?>		
		<br><br><font size=1><center>
		  <font face="Arial, Helvetica, sans-serif"><a href= "view.php">Return to View
		  page</font>
		</center>		
		<?
		exit;
	}


  $query = mysqli_query($conn,"delete from acctmast where record='$record' ") or die(mysqli_error());

}

?>
<meta http-equiv="refresh" content="0 url=view.php">

