<body background="">
<?php include("../../include/dbconnect.php");
 
$filename = 'templedger';

if($filename !='')
{
	
	if($cnf=='Yes')
	{
	
		$result = mysqli_query($conn,"select max(trans_id) from tranid where account_year = '$account_year' ") or die(mysqli_error());
		$row = mysqli_fetch_row($result);
		$trans_id = $row[0]+1;
		$result = mysqli_query($conn,"insert into tranid values ( '$trans_id','$account_year')") or die(mysqli_error());
		$result = mysqli_query($conn,"update $filename set trans_id = $trans_id") or die(mysqli_error());		
		
	
		$result= mysqli_query($conn,"select sum(dbamt),sum(cramt) from `$filename` ") or die(mysqli_error());
		$row = mysqli_fetch_row($result);
		$cdbamt = $row[0];
		$ccramt = $row[1];
		if($cdbamt == $ccramt)
		{
			$query= "insert into ledger(acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year,amttype,cheqno,entered_by,voucher_no,date_of_entry,taxtype) select acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year,amttype,cheqno,entered_by,voucher_no,curdate(),cheq_date from `$filename`  ";
			mysqli_query($conn,$query) or die(mysqli_error());
			
			$query= "truncate table $filename";
			mysqli_query($conn,$query) or die(mysqli_error());
		}
		else
		{
			echo("Debit and Credit Balances are not tallying.. Please go back and correct it.");
			exit;
		}
	}
}
else
{
	?>
    	<script language="javascript">
		alert("You have closed the Main Program Browser before saving the data, due to that Data won't be saved. Please login again and enter ");
        </script>
    <?
	exit;
}
?>
<meta http-equiv="refresh" content="0 url=input2.php?compcode=<?=$compcode?>&branch=<?=$branch?>&myHead=vim">
