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

<body background="../../images/blater01.gif" topmargin=0>
<?

if ( isset($submit) && $submit == "Update")
{
     $query ="update product set stprodcode ='$stprodcode',minimum_qty='$minimum_qty',catcode = '$catcode',prodname ='$prodname',packing='$packing',schedule = '$schedule',weight ='$weight',active = '$active',rate = '$rate',tax_rate = '$tax_rate' where record ='$record' ";
	 mysqli_query($conn,$query) or die(mysqli_error());

     $query ="update acctmast set description ='$prodname',active = '$active' where record ='$acctmast_record' ";
	 mysqli_query($conn,$query) or die(mysqli_error());


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


	$result = mysqli_query($conn,"select prodcode from  product where record = '$record'  ") 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 = mysqli_query($conn,"delete from product where record='$record' ") 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">