<?php 
	require "../commonincludefiles.php";
	
	$current_year_id = $_SESSION['cYear'];
	$new_year_id = $current_year_id + 1;
	
	$sql = "SELECT * FROM ams_accountmasterdetail WHERE year_id = '".$current_year_id."' ";
	$out_current_year_id = dbQuery($sql);
	if(dbRows($out_current_year_id)>0){
		while($row = dbArray($out_current_year_id)){
			$curr_year_acc_id = $row['account_id'];
			$sql = "SELECT * FROM ams_accountmasterdetail WHERE account_id = '".$curr_year_acc_id."' AND year_id = '".$new_year_id."' ";
			$out_new_year_id = dbQuery($sql);
			if(dbRows($out_new_year_id)==0){
				
				$Qry1 = "";
				$Qry1 .= "account_id='"	        .$row['account_id']."',";
				$Qry1 .= "account_opbalance='"	.$row['account_opbalance']."',";			
				$Qry1 .= "account_crdr='"		.$row['account_crdr']."',";			
				$Qry1 .= "company_id='"	        .Escape($_SESSION['cCompany_id'])."',";			
				$Qry1 .= "year_id='"	        .$new_year_id."',";
				$Qry1 .= "blnBackup = '0',";
				$Qry1 = substr($Qry1, 0, strlen($Qry1)-1);
				
				$qry = "insert into ams_accountmasterdetail set " . $Qry1 . " ";
				dbQuery($qry);
			}
		}
	}
?>