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



if ($submit == "Submit")
{
	if ($opening_balance>0)
	{
	
		$result = mysqli_query($conn,"select account_year from branches where code = '$branch' ") or die(mysqli_error());
		$row = mysqli_fetch_row($result);
		$account_year = $row[0];
		
		$result = mysqli_query($conn,"select acctcode from openbalance where acctcode = '$accthead' and branch_code = '$branch' and account_year = '$account_year' ") or die(mysqli_error());
		$row = mysqli_fetch_row($result);
		if($row[0] >0)
		{
			?>
            	<script language="javascript">
				alert("Entry for this GL for current year found in Opening Balance. Please edit the entry");
				</script>
            <?
			exit;
		}
		else
		{
			if($db_cr == '')
			{
				?>
            	<script language="javascript">
				alert("DR /CR not selected. Please select");
				</script>
            <?
			exit;
			}
			if($account_year == '')
			{
				?>
            	<script language="javascript">
				alert("Account year not found. Please Check Branch master");
				</script>
            	<?
			exit;
			}			
		}
		$query="insert into openbalance values ('$compcode','$accthead','$branch','$opening_balance','$db_cr','$account_year',NULL)";
		mysqli_query($conn,$query) or die(mysqli_error());
	}
}

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

