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

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

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

			if($db_cr == '')
			{
				?>
            	<script language="javascript">
				alert("DR /CR not selected. Please Correct amount type as DR or CR");
				</script>
            <?
			exit;
			}
			if($account_year == '')
			{
				?>
            	<script language="javascript">
				alert("Account year not found. Please Correct");
				</script>
            	<?
			exit;
			}	

     $query ="update openbalance set opening_balance = '$opening_balance', db_cr = '$db_cr',account_year = '$account_year' 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 acctcode from ledger where acctcode = '$acctcode' ") or die(mysqli_error());
	$row = mysqli_fetch_row($result);
	if($row[0] > 0)
	{
		echo("<h3>Can't delete Opening Balance 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 openbalance where record='$record' ") or die(mysqli_error());

}

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