
<?php include("../../include/dbconnect.php"); 
$filename = 'templedger';
if($cnf=='Yes')
{
	if($trans_id > 0) 
	{
		if($account_year !='')
		{	
			$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)
			{
		
		
				$uquery = "insert into deleted_ledger (select * from ledger where trans_id = '$trans_id' and account_year = '$account_year')" or die(mysqli_error());
				mysqli_query($conn,$uquery) or die(mysqli_error());
				
		
				$uquery = "update deleted_ledger set deleted_reason = '$reason_text'  where trans_id = '$trans_id' and account_year = '$account_year'";
				mysqli_query($conn,$uquery) or die(mysqli_error());
				
				$query= "delete from ledger where trans_id = '$trans_id' and account_year = '$account_year' ";
				mysqli_query($conn,$query) or die(mysqli_error());
			
				$query= "insert into ledger(acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year,cheqno,voucher_no,date_of_entry,date_of_editing,entered_by,taxtype,amttype) select acctcode,date,narration,dbamt,cramt,type,invno,compcode,branch_code,trans_id,account_year,cheqno,voucher_no,date_of_entry,curdate(),'$filename',cheq_date,amttype 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;
			}
		}
	}
	
}

?>
<meta http-equiv="refresh" content="0 url=gl_editview.php?compcode=<?=$compcode?>&branch=<?=$branch?>&status=NEW">



