<body background="../../images/blater01.gif"  topmargin=0>
<?php include("../../include/dbconnect.php"); 

if ( isset($submit) && $submit == "Update")
{

	$query = "update buy set name='$bname',address1='$baddress1', address2='$baddress2', city='$bcity', state='$bstate',incentive='$incentive',credit_days='$credit', country='$country', pin='$bpin', std='$bstd', telno='$btelno', mobile='$mobile', email='$bemail', contact='$contact',  cst='$bcst',tin='$tin',gstin='$gstin',buyertype='$buyertype',active = '$active',discount = '$discount',taxtype = '$ttype',state_code = '$state_code' where record='$record1' ";
	mysqli_query($conn,$query)  or   die(mysqli_error());
  
	$query ="update acctmast set description ='$bname',active = '$active' where record ='$acctmast_record' ";
	mysqli_query($conn,$query) or die(mysqli_error());
  
 }
elseif (isset($submit) && $submit == "Delete")
{


	$result = mysqli_query($conn,"select bcode from  buy where record = '$record1'  ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	$acctcode = $row[0];
	

	$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 = "delete from buy where record='$record1' ";
	 mysqli_query($conn,$query) or die(mysqli_error());  
  	$query = mysqli_query($conn,"delete from acctmast where record='$acctmast_record' ") or die(mysqli_error());


}
?>

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