package com.bankaudit.rest.process.service;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bankaudit.dto.process.DeriveStatementDto;
import com.bankaudit.model.MaintReportDerivedStmt;
import com.bankaudit.process.model.AuditReportStmt;
import com.bankaudit.process.model.IfcBatchProcessStatus;
import com.bankaudit.process.model.IfcEnsureBaasData;
import com.bankaudit.process.model.IfcEnsureBaasIRProcessData;
import com.bankaudit.rest.process.dao.BatchProcessingDao;

@Service("batchProcessingService")
@Transactional("transactionManager")
public class BatchProcessingServiceImpl implements BatchProcessingService{
	
	@Autowired
	BatchProcessingDao batchProcessingDao;
	
	static final Logger logger = Logger.getLogger(BatchProcessingServiceImpl.class);

	@Override
	public Boolean executeBPforDynamicStatement(Integer legalEntityCode, String auditId, String auditTypeCode) {
		boolean execute= true;
		// 1. records from ifcEnsureBaasData 
		// 2. keep the params in 3 HashMaps, with key as (1+ParamName) or (2+ParamName) or (3+ParamName)
		
		// 3.1 get the derived stmnts based on on inspection type
		// 3.2 and keep them in a Map=> drvMap as key as (derivedStmntId) value as (derivedStmntObject)
		
		// 4. records from auditReportStmts, 
		// 4.1 iterate through derived statements
		// 4.2 pick the derived stmnt, scan in drvMap
		//	=> if (c1!=null && c2!=null && c3!=null && c4!=null)
		//			c1 <c2 && c3 <c4 ---->1        c1 <c2 && c3 >c4 ---->2        c1 <c2 && c3 =c4 ---->3
		//          c1 >c2 && c3 <c4 ---->4        c1 >c2 && c3 >c4 ---->5        c1 >c2 && c3 =c4 ---->6
		//          c1 =c2 && c3 <c4 ---->7        c1 =c2 && c3 >c4 ---->8        c1 =c2 && c3 =c4 ---->9
		//     else if(c1!=null && c2!=null)
		// 			c1 <c2  ---->1                 c1 >c2 ---->2                 c1 =c2  ---->3
		//    else ------->0
		// 4.3 Now replace the tokens sequentially from fill1 onwards 
		// 4.4 Update the Derive statement in AuditReportStmt table
		
		try {
			Boolean batchUpdate=updateBatchProcessStatus( legalEntityCode, auditId, auditTypeCode, true); // true indicates, Batch process execution in progress
			
			//STEP-1  records from ifcEnsureBaasIRProcessData 
			List<IfcEnsureBaasIRProcessData> ifcParams = batchProcessingDao.getIfcParameterDataFromProcess(legalEntityCode, auditId, "");
			
			//STEP-2  keep the params in 2 HashMaps, with key as (dpi+ParamName) and (dli+ParamName)
			Map<String, Map<String, String>> paramMap= paramMaps(ifcParams);
			Map<String, String> dpiMap = paramMap.get("DPI");
			Map<String, String> dliMap = paramMap.get("DLI");
			Map<String, String> allParamMap = new HashMap<>();
			allParamMap.putAll(dpiMap); allParamMap.putAll(dliMap); // Keeping all the parameters in one Map
			
			//STEP-2.1  records from ifcEnsureBaasData 
			List<IfcEnsureBaasData> ifcParams1 = batchProcessingDao.getIfcBaasParameterDataFromProcess(legalEntityCode, auditId, "");
			
			//STEP-2.2  keep the params in 2 HashMaps, with key as (dpi+ParamName) and (dli+ParamName)
			Map<String, Map<String, String>> paramMap1= paramMaps1(ifcParams1);
			Map<String, String> fstYrMap = paramMap1.get("FSTYR");
			logger.info("fstYrMap .. "+ fstYrMap);
			allParamMap.putAll(fstYrMap); // adding all the Year1 data to the Map
			
			//STEP-3 get the derived stmnts based on inspection type
			List<MaintReportDerivedStmt> drStmtLst = batchProcessingDao.getDerivedStmts(legalEntityCode, auditTypeCode, "");
			logger.info("drStmtLst size .. "+ drStmtLst!=null?drStmtLst.size():"0");
			Map<String, MaintReportDerivedStmt> drMap = new HashMap<String, MaintReportDerivedStmt>();
			for(MaintReportDerivedStmt rptDrStmt: drStmtLst) {
				drMap.put(rptDrStmt.getStatementId(), rptDrStmt);
			}
			logger.info("Derived Map ##.."+drMap);
			
			//STEP-4 get the derived stmnts based on on inspection type and replace them 
			List<AuditReportStmt> auditStmtLst = batchProcessingDao.getAuditDerivedStmts(legalEntityCode, auditId, "");
			//List<AuditReportStmt> auditStmtLst = batchProcessingDao.getAuditDerivedStmtsByStatementId(legalEntityCode, auditId, "","XXRRBTSDS");
			
			int i=0;
			for(AuditReportStmt auditReportStmt: auditStmtLst) { // 4.1 Iterating through the Derived statements
				String drStmtId= auditReportStmt.getStatementId(); String drStmt=null; String drStmtHindi=null;
				DeriveStatementDto drStmtDto=null;
				logger.info("");
				logger.info("=====================================================================>> drStmtId.... "+i++ +":: "+ drStmtId);
				MaintReportDerivedStmt drStmntVo =drMap.get(drStmtId);
				if(drStmntVo!=null) {
					logger.info("drStmntVo.getStatementId() .... "+ drStmntVo.getStatementId());
					//String drStmt=getSelectDerivedStmnt( drStmntVo, allParamMap); // 4.2 pick the derived stmnt, using Compare parameter
					drStmtDto=getSelectDerivedStmnt( drStmntVo, allParamMap); // 4.2 pick the derived stmnt, using Compare parameter
					drStmt= (drStmtDto!=null)?drStmtDto.getDrStmt():null;
					drStmtHindi= (drStmtDto!=null)?drStmtDto.getDrStmtHindi():null;
					logger.info("drStmt .. "+ drStmt );
					logger.info("drStmtHindi .. "+ drStmtHindi );
					if(drStmt !=null && drStmntVo !=null && allParamMap!=null) {
						//String drStmtFinal=replaceTokenInDerivedStmnt( drStmntVo, allParamMap, drStmt);// 4.3 Now replace the tokens sequentially from fill1 onwards
						DeriveStatementDto drStmtDtoTmp=replaceTokenInDerivedStmnt( drStmntVo, allParamMap, drStmt, drStmtHindi);// 4.3 Now replace the tokens sequentially from fill1 onwards
						//ByteBuffer buffer = StandardCharsets.UTF_8.encode(drStmtFinal); 

						//String utf8EncodedString = StandardCharsets.UTF_8.decode(buffer).toString();
						//auditReportStmt.setStatement(StandardCharsets.UTF_8.decode(buffer).toString());
						//auditReportStmt.setStatement(drStmtFinal);
						auditReportStmt.setStatement(drStmtDtoTmp.getDrStmt());
						auditReportStmt.setStatementHindi(drStmtDtoTmp.getDrStmtHindi());
						auditReportStmt.setPrintFlag(drStmtDtoTmp.getDrStmtPrint()); // To indicate whether to print the the Derive statement or not.
						if(drStmtDto!=null) logger.info(" Derive stmnt OP picked:: "+drStmntVo.getStatementId()+" :: "+ drStmtDto.getDrStmtPickedNo() +" :: "+drStmtDtoTmp.getDrStmtPrint());
						auditReportStmt.setDeriveStatementOPStmnt(drStmtDto!=null?drStmtDto.getDrStmtPickedNo():"0"); // to store which derive statement finally picked
						batchProcessingDao.updateAuditReportStmt(auditReportStmt, auditReportStmt.getId(), drStmtId); // 4.4 Update the Derive statement in AuditReportStmt table
						//batchProcessingDao.update(auditReportStmt);
					}
				}else {
					logger.info("The statement ID "+drStmtId +" not present in Derive statement table");
				}
				
			}
			//batchProcessingDao.updateAuditReportStmntRupeeSymbl(legalEntityCode, auditTypeCode, auditId);
			applyDependencyRule(legalEntityCode, auditTypeCode, auditId, allParamMap);
			batchUpdate=updateBatchProcessStatus( legalEntityCode, auditId, auditTypeCode, false); // false indicates, Batch process execution completed
		}catch(Exception e) {
			e.printStackTrace(System.out);
			execute=false;
		}
		return execute;
	}
	
	
	// Method to keep the parameters in Map
	public static Map<String, Map<String, String>> paramMaps(List<IfcEnsureBaasIRProcessData> ifcParams){		
		Map finalMap = new HashMap<String, Map<String, String>>();
		Map dpiMap= new HashMap();  // DPI => Previous Inspection
		Map dliMap= new HashMap();  // DLI => Latest Inspection
		
		for(IfcEnsureBaasIRProcessData ifcp: ifcParams) {
			dpiMap.put("2"+ifcp.getParameterName(), ifcp.getSubmittedValueOldest()); // for the old year the Parameters prefixed with 2
			dliMap.put("3"+ifcp.getParameterName(), ifcp.getSubmittedValueLatest()); // for the latest year the Parameters prefixed with 3
		}	
		finalMap.put("DPI", dpiMap);
		finalMap.put("DLI", dliMap);
		
		return finalMap;
	}
	
	// Method to keep 1st year data in Map, also can be used this method for all (latest, mid, oldest)
	public static Map<String, Map<String, String>> paramMaps1(List<IfcEnsureBaasData> ifcParams){		
		Map fstYrMap = new HashMap<String, Map<String, String>>();
		Map fMap= new HashMap(); 
		
		for(IfcEnsureBaasData ifcp: ifcParams) {
			fMap.put("1"+ifcp.getParameterName(), ifcp.getSubmittedValueOldest()); // for the old year the Parameters prefixed with 1
			fMap.put("2Y"+ifcp.getParameterName(), ifcp.getSubmittedValueMiddest()); // for getting the 2nd year data
		}			
		fstYrMap.put("FSTYR", fMap);
		return fstYrMap;
	}
	
	// Method to choose the Derived statement based on comparison 
	public static DeriveStatementDto getSelectDerivedStmnt(MaintReportDerivedStmt drStmntVo, Map<String, String> paramMap){
		String drStmt=null; String drStmtHindi=null; String drStmtNo="0";
		DeriveStatementDto drvDto=null;
		// C1 < C2 =>1   C1 > C2 =>2   C1=C2 =>0
		//1	1 1=> 1		2	1	1=>	10		0	1	1=>	19 				// 	1	1=>1			// 	1=>1
		//1	1 2=> 2		2	1	2=>	11 		0	1	2=>	20 				// 	1	2=>2			// 	2=>2
		//1	1 0=> 3		2	1	0=>	12 		0	1	0=>	21 				// 	1	0=>3			// 	0=>3
		//1	2 1=> 4		2	2	1=>	13 		0	2	1=>	22 				// 	2	1=>4
		//1	2 2=> 5		2	2	2=>	14 		0	2	2=>	23 				// 	2	2=>5
		//1	2 0=> 6		2	2	0=>	15 		0	2	0=>	24 				// 	2	0=>6
		//1	0 1=> 7		2	0	1=>	16 		0	0	1=>	25 				// 	0	1=>7
		//1	0 2=> 8		2	0	2=>	17 		0	0	2=>	26 				// 	0	2=>8
		//1	0 0=> 9		2	0	0=>	18 		0	0	0=>	27 				// 	0	0=>9
		
		//SimpleDateFormat myFormat = new SimpleDateFormat("dd-mm-yyyy");
		DateFormat myFormat = new SimpleDateFormat("dd/MM/yyyy");
		try {
			String c1e1=drStmntVo.getComp1Elemt1(), c1e2=drStmntVo.getComp1Elemt2();  // Comp1 Element 1 and 2
			String c2e1=drStmntVo.getComp2Elemt1(), c2e2=drStmntVo.getComp2Elemt2();  // Comp2 Element 1 and 2
			String c3e1=drStmntVo.getComp3Elemt1(), c3e2=drStmntVo.getComp3Elemt2();  // Comp3 Element 1 and 2
			logger.info("Inside getSelectDerivedStmnt Compared val.."+ c1e1 +" "+ c1e2+" "+ c2e1+" "+c2e2 +" "+c3e1+" "+c3e2);
			if (c1e1!=null && c1e2!=null && c2e1!=null && c2e2!=null && c3e1!=null && c3e2!=null) { // For 3 comparison
				double c1e1d=0, c1e2d=0, c2e1d=0, c2e2d=0, c3e1d=0, c3e2d=0;
				try { 	
					c1e1d=Double.parseDouble(drStmntVo.getComp1Elemt1()); //To get the number directly from Comparison field
				}catch(Exception e) {
					try {
						c1e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt1())); //To get the value from ifc_process table with the Comparison parameter
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp1Elemt1()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp1Elemt1()));
							long c1e1dl=date1.getTime();
							c1e1d=Math.abs(Double.parseDouble(String.valueOf(c1e1dl)));
						}
					}
				}
				try { 	
					c1e2d=Double.parseDouble(drStmntVo.getComp1Elemt2());
				}catch(Exception e) {
					try {
					c1e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt2())); 
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp1Elemt2()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp1Elemt2()));
							c1e2d=Math.abs(Double.parseDouble(String.valueOf(date1.getTime())));
						}
					}
				}
				try {
					c2e1d=Double.parseDouble(drStmntVo.getComp2Elemt1());
				}catch(Exception e) {
					try {
						c2e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp2Elemt1())); 
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp2Elemt1()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp2Elemt1()));
							c2e1d=Math.abs(Double.parseDouble(String.valueOf(date1.getTime())));
						}
					}					
				}
				try { 	
					c2e2d=Double.parseDouble(drStmntVo.getComp2Elemt2());
				}catch(Exception e) {
					try {
						c2e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp2Elemt2())); 
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp2Elemt2()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp2Elemt2()));
							c2e2d=Math.abs(Double.parseDouble(String.valueOf(date1.getTime())));
						}
					}	
				}
				try { 	
					c3e1d=Double.parseDouble(drStmntVo.getComp3Elemt1());
				}catch(Exception e) {
					try {
						c3e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp3Elemt1())); 
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp3Elemt1()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp3Elemt1()));
							c3e1d=Math.abs(Double.parseDouble(String.valueOf(date1.getTime())));
						}
					}
				}
				try { 	
					c3e2d=Double.parseDouble(drStmntVo.getComp3Elemt2());
				}catch(Exception e) {
					try {
						c3e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp3Elemt2())); 
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp3Elemt2()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp3Elemt2()));
							c3e2d=Math.abs(Double.parseDouble(String.valueOf(date1.getTime())));
						}
					}
				}				
				logger.info("Compared val final..c1=>"+ c1e1d +"::"+ c1e2d+" c2=>"+ c2e1d+"::"+c2e2d +" c3=>"+c3e1d+"::"+c3e2d);
				if(c1e1d < c1e2d) { // 1XX
					if(c2e1d < c2e2d) { // 11X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt1(); // OP=111
							drStmtHindi = drStmntVo.getDerivedStmt1Hindi();
							drStmtNo="1";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt2(); // OP=112
							drStmtHindi = drStmntVo.getDerivedStmt2Hindi();
							drStmtNo="2";
						}else{
							drStmt= drStmntVo.getDerivedStmt3(); // OP=110
							drStmtHindi = drStmntVo.getDerivedStmt3Hindi();
							drStmtNo="3";
						}
					}else if(c2e1d > c2e2d) { // 12X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt4(); // OP=121
							drStmtHindi = drStmntVo.getDerivedStmt4Hindi();
							drStmtNo="4";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt5(); // OP=122
							drStmtHindi = drStmntVo.getDerivedStmt5Hindi();
							drStmtNo="5";
						}else{
							drStmt= drStmntVo.getDerivedStmt6(); // OP=120
							drStmtHindi = drStmntVo.getDerivedStmt6Hindi();
							drStmtNo="6";
						}
					}else { // 10X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt7(); // OP=101
							drStmtHindi = drStmntVo.getDerivedStmt7Hindi();
							drStmtNo="7";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt8(); // OP=102
							drStmtHindi = drStmntVo.getDerivedStmt8Hindi();
							drStmtNo="8";
						}else{
							drStmt= drStmntVo.getDerivedStmt9(); // OP=100
							drStmtHindi = drStmntVo.getDerivedStmt9Hindi();
							drStmtNo="9";
						}
					}
				}else if (c1e1d > c1e2d) { // 2XX
					if(c2e1d < c2e2d) { // 21X
						if(c3e1d < c3e2d) { 
							drStmt= drStmntVo.getDerivedStmt10(); // OP=211
							drStmtHindi = drStmntVo.getDerivedStmt10Hindi();
							drStmtNo="10";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt11(); // OP=212
							drStmtHindi = drStmntVo.getDerivedStmt11Hindi();
							drStmtNo="11";
						}else{
							drStmt= drStmntVo.getDerivedStmt12(); // OP=210
							drStmtHindi = drStmntVo.getDerivedStmt12Hindi();
							drStmtNo="12";
						}
					}else if(c2e1d > c2e2d) { // 22X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt13(); // OP=221
							drStmtHindi = drStmntVo.getDerivedStmt13Hindi();
							drStmtNo="13";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt14(); // OP=222
							drStmtHindi = drStmntVo.getDerivedStmt14Hindi();
							drStmtNo="14";
						}else{
							drStmt= drStmntVo.getDerivedStmt15(); // OP=220
							drStmtHindi = drStmntVo.getDerivedStmt15Hindi();
							drStmtNo="15";
						}
					}else { // 20X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt16(); // OP=201
							drStmtHindi = drStmntVo.getDerivedStmt16Hindi();
							drStmtNo="16";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt17(); // OP=202
							drStmtHindi = drStmntVo.getDerivedStmt17Hindi();
							drStmtNo="17";
						}else{
							drStmt= drStmntVo.getDerivedStmt18(); // OP=200
							drStmtHindi = drStmntVo.getDerivedStmt18Hindi();
							drStmtNo="18";
						}
					}
				}else { // c1e1d = c1e2d  // 0XX
					if(c2e1d < c2e2d) { // 01X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt19(); // OP=011
							drStmtHindi = drStmntVo.getDerivedStmt19Hindi();
							drStmtNo="19";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt20(); // OP=012
							drStmtHindi = drStmntVo.getDerivedStmt20Hindi();
							drStmtNo="20";
						}else{
							drStmt= drStmntVo.getDerivedStmt21(); // OP=010
							drStmtHindi = drStmntVo.getDerivedStmt21Hindi();
							drStmtNo="21";
						}
					}else if(c2e1d > c2e2d) { // 02X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt22(); // OP=021
							drStmtHindi = drStmntVo.getDerivedStmt22Hindi();
							drStmtNo="22";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt23(); // OP=022
							drStmtHindi = drStmntVo.getDerivedStmt23Hindi();
							drStmtNo="23";
						}else{
							drStmt= drStmntVo.getDerivedStmt24(); // OP=020
							drStmtHindi = drStmntVo.getDerivedStmt24Hindi();
							drStmtNo="24";
						}
					}else { // 00X
						if(c3e1d < c3e2d) {
							drStmt= drStmntVo.getDerivedStmt25(); // OP=001
							drStmtHindi = drStmntVo.getDerivedStmt25Hindi();
							drStmtNo="25";
						}else if(c3e1d > c3e2d) {
							drStmt= drStmntVo.getDerivedStmt26(); // OP=002
							drStmtHindi = drStmntVo.getDerivedStmt26Hindi();
							drStmtNo="26";
						}else{
							drStmt= drStmntVo.getDerivedStmt27(); // OP=000
							drStmtHindi = drStmntVo.getDerivedStmt27Hindi();
							drStmtNo="27";
						}
					}
				}
								
			}else if (c1e1!=null && c1e2!=null && c2e1!=null && c2e2!=null) {  // For 2 comparison
				double c1e1d=0, c1e2d=0, c2e1d=0, c2e2d=0;
				try { 	
					c1e1d=Double.parseDouble(drStmntVo.getComp1Elemt1()); //To get the number directly from Comparison field
				}catch(Exception e) {
					try {
						c1e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt1())); //To get the value from ifc_process table with the Comparison parameter
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp1Elemt1()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp1Elemt1()));
							long c1e1dl=date1.getTime();
							c1e1d=Math.abs(Double.parseDouble(String.valueOf(c1e1dl)));
						}
					}
				}
				
				try { 	c1e2d=Double.parseDouble(drStmntVo.getComp1Elemt2());
				}catch(Exception e) {
					try {
						c1e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt2())); //To get the value from ifc_process table with the Comparison parameter
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp1Elemt2()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp1Elemt2()));
							long c1e2dl=date1.getTime();
							c1e2d=Math.abs(Double.parseDouble(String.valueOf(c1e2dl)));
						}
					}
				}
				
				try { 	c2e1d=Double.parseDouble(drStmntVo.getComp2Elemt1());
				}catch(Exception e) {
					try {
						c2e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp2Elemt1())); //To get the value from ifc_process table with the Comparison parameter
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp2Elemt1()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp2Elemt1()));
							long c2e1dl=date1.getTime();
							c2e1d=Math.abs(Double.parseDouble(String.valueOf(c2e1dl)));
						}
					}
				}
				
				try { 	c2e2d=Double.parseDouble(drStmntVo.getComp2Elemt2());
				}catch(Exception e) {
					try {
						logger.info("Comp Elm2 => "+drStmntVo.getComp2Elemt2());
						logger.info("Comp Elm2 Param Val => "+paramMap.get(drStmntVo.getComp2Elemt2()));
						c2e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp2Elemt2()));  //To get the value from ifc_process table with the Comparison parameter
						logger.info("c2e2d .. "+c2e2d);
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp2Elemt2()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp2Elemt2()));
							long c2e2dl=date1.getTime();
							c2e2d=Math.abs(Double.parseDouble(String.valueOf(c2e2dl)));
						}
					}
				}
				
				//double c1e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt1()));
				//double c1e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt2())); 
				//double c2e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp2Elemt1()));
				//double c2e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp2Elemt2()));
				logger.info("Derive stmnt :: "+drStmntVo.getStatementId() +" C1="+c1e1d+" C2="+ c1e2d+" C3="+ c2e1d+" C4="+c2e2d);
				if(c1e1d < c1e2d) {
					if(c2e1d < c2e2d) {
						drStmt= drStmntVo.getDerivedStmt1(); // OP=11
						drStmtHindi = drStmntVo.getDerivedStmt1Hindi();
						drStmtNo="1";
					}else if(c2e1d > c2e2d) {
						drStmt= drStmntVo.getDerivedStmt2(); // OP=12
						drStmtHindi = drStmntVo.getDerivedStmt2Hindi();
						drStmtNo="2";
					}else {
						drStmt= drStmntVo.getDerivedStmt3(); // OP=10
						drStmtHindi = drStmntVo.getDerivedStmt3Hindi();
						drStmtNo="3";
					}
				}else if (c1e1d > c1e2d) {
					if(c2e1d < c2e2d) {
						drStmt= drStmntVo.getDerivedStmt4(); // OP=21
						drStmtHindi = drStmntVo.getDerivedStmt4Hindi();
						drStmtNo="4";
					}else if(c2e1d > c2e2d) {
						drStmt= drStmntVo.getDerivedStmt5(); // OP=22
						drStmtHindi = drStmntVo.getDerivedStmt5Hindi();
						drStmtNo="5";
					}else {
						drStmt= drStmntVo.getDerivedStmt6();  // OP=20
						drStmtHindi = drStmntVo.getDerivedStmt6Hindi();
						drStmtNo="6";
					}
				}else { // c1e1d = c1e2d
					if(c2e1d < c2e2d) {
						drStmt= drStmntVo.getDerivedStmt7();  // OP=01
						drStmtHindi = drStmntVo.getDerivedStmt7Hindi();
						drStmtNo="7";
					}else if(c2e1d > c2e2d) {
						drStmt= drStmntVo.getDerivedStmt8(); // OP=02
						drStmtHindi = drStmntVo.getDerivedStmt8Hindi();
						drStmtNo="8";
					}else {
						drStmt= drStmntVo.getDerivedStmt9();  // OP=00
						drStmtHindi = drStmntVo.getDerivedStmt9Hindi();
						drStmtNo="9";
					}
				}
				
			}else if(c1e1!=null && c1e2!=null) {
				double c1e1d=0, c1e2d=0;
				try { 	c1e1d=Double.parseDouble(drStmntVo.getComp1Elemt1());
				}catch(Exception e) {
					try {
						c1e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt1())); //To get the value from ifc_process table with the Comparison parameter
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp1Elemt1()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp1Elemt1()));
							long c1e1dl=date1.getTime();
							c1e1d=Math.abs(Double.parseDouble(String.valueOf(c1e1dl)));
						}
					}
				}
				
				try { 	c1e2d=Double.parseDouble(drStmntVo.getComp1Elemt2());
				}catch(Exception e) {
					try {
						c1e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt2()));  //To get the value from ifc_process table with the Comparison parameter
					}catch(Exception e1) {
						if(paramMap.get(drStmntVo.getComp1Elemt2()).split("/").length==3) {
							Date date1 = myFormat.parse(paramMap.get(drStmntVo.getComp1Elemt2()));
							long c1e2dl=date1.getTime();
							c1e2d=Math.abs(Double.parseDouble(String.valueOf(c1e2dl)));
						}
					}
				}
				//double c1e1d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt1()));
				//double c1e2d=Double.parseDouble(paramMap.get(drStmntVo.getComp1Elemt2())); 
				logger.info("Derive stmnt :: "+drStmntVo.getStatementId() +" C1="+c1e1d+" C2="+ c1e2d);
				if(c1e1d < c1e2d) { // OP=1
					drStmt= drStmntVo.getDerivedStmt1();
					drStmtHindi = drStmntVo.getDerivedStmt1Hindi();
					drStmtNo="1";
				}else if (c1e1d > c1e2d) {  // OP=2
					drStmt= drStmntVo.getDerivedStmt2();
					drStmtHindi = drStmntVo.getDerivedStmt2Hindi();
					drStmtNo="2";
				}else if (c1e1d == c1e2d && c1e1d > 0){ // Only for +ve values
					drStmt= drStmntVo.getDerivedStmt3(); // OP=3
					drStmtHindi = drStmntVo.getDerivedStmt3Hindi();
					drStmtNo="3";
				}else {
					drStmt= drStmntVo.getDerivedStmt(); // OP=0
					drStmtHindi = drStmntVo.getDerivedStmtHindi();
					drStmtNo="0";
				}				
			}else {
				drStmt=drStmntVo.getDerivedStmt(); // OP=99
				drStmtHindi = drStmntVo.getDerivedStmtHindi();
				drStmtNo="0";
			}
			drvDto= new DeriveStatementDto();
			drvDto.setDrStmt(drStmt);
			drvDto.setDrStmtHindi(drStmtHindi);
			drvDto.setDrStmtPickedNo(drStmtNo);
		}catch(Exception e) {
			e.printStackTrace(System.out);
			drStmt=drStmntVo.getDerivedStmt();
		}
		return drvDto;
	}
	
	// Method to replace the tokens of the Derived statements.
	public static DeriveStatementDto replaceTokenInDerivedStmnt(MaintReportDerivedStmt drStmntVo, Map<String, String> paramMap, String drStmt, String drStmtHindi){
		DeriveStatementDto drvDtoTmp=null;
		String drStmtFinal=drStmt;
		String drStmtFinalHindi=drStmtHindi;
		int cnt=1; int tokenCnt=0; int nullCnt=0;
		logger.info("====================> replaceTokenInDerivedStmnt drStmt .. "+drStmntVo.getStatementId()+ "=>"+drStmt);
		
		try {
			String drStmntOPPick=drStmntVo.getCompResultPick();
			boolean drStmntPick=(drStmntVo.getCompResultPick().equals("99")?true:false);	 // The logic to eliminate 0 fill's only for 99 statements.	
			logger.info("drStmntOPPick .."+drStmntOPPick+" drStmntPick.."+drStmntPick);
			if(drStmtFinalHindi==null)drStmtFinalHindi="No Hindi statements maintained.";
			
			drvDtoTmp=new DeriveStatementDto();
			
			if(drStmt.contains("₹")) {
				drStmt=drStmt.replace("₹", "AXXXA");
			}drStmtFinal=drStmt;
			String token="@#"; 
			while(drStmtFinal.contains(token)) {
				try {
					logger.info("Token cnt ==============>  "+drStmntVo.getStatementId()+" ==>"+ cnt);
					if(cnt==1) {
						logger.info("param fill 1=>"+drStmntVo.getFill1()+"  2=> "+drStmntVo.getFill2() +"  3=> "+drStmntVo.getFill3() +" 4=> "+drStmntVo.getFill4());
						logger.info("param value 1=>"+paramMap.get(drStmntVo.getFill1())+" 2=> "+paramMap.get(drStmntVo.getFill2())+" 3=> "+paramMap.get(drStmntVo.getFill3())+" 4=> "+paramMap.get(drStmntVo.getFill4 ())+" 5=> "+paramMap.get(drStmntVo.getFill5()));
						
						logger.info("PARAM FILL1=>["+drStmntVo.getFill1() +"] VALUE1=>["+paramMap.get(drStmntVo.getFill1()) +"]");
						String fill1=paramMap.get(drStmntVo.getFill1()); 
						if(fill1 ==null || "".equalsIgnoreCase(fill1.trim()) || "0".equalsIgnoreCase(fill1) || "0.00".equalsIgnoreCase(fill1) ) nullCnt=nullCnt+1; // logic to chek 
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill1()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill1()));
					}else if(cnt==2) {
						logger.info("PARAM FILL2=>["+drStmntVo.getFill2() +"] VALUE2=>["+paramMap.get(drStmntVo.getFill2()) +"]");
						String fill2=paramMap.get(drStmntVo.getFill2());
						if(fill2 ==null || "".equalsIgnoreCase(fill2.trim()) || "0".equalsIgnoreCase(fill2) || "0.00".equalsIgnoreCase(fill2) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill2()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill2()));
					}else if(cnt==3) {
						logger.info("PARAM FILL3=>["+drStmntVo.getFill3() +"] VALUE3=>["+paramMap.get(drStmntVo.getFill3()) +"]");
						String fill3=paramMap.get(drStmntVo.getFill3());
						if(fill3 ==null || "".equalsIgnoreCase(fill3.trim()) || "0".equalsIgnoreCase(fill3) || "0.00".equalsIgnoreCase(fill3) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill3()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill3()));
				    }else if(cnt==4) {
						logger.info("PARAM FILL4=>["+drStmntVo.getFill4() +"] VALUE4=>["+paramMap.get(drStmntVo.getFill4()) +"]");
						String fill4=paramMap.get(drStmntVo.getFill4());
						if(fill4 ==null || "".equalsIgnoreCase(fill4.trim()) || "0".equalsIgnoreCase(fill4) || "0.00".equalsIgnoreCase(fill4) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill4()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill4()));
				    }else if(cnt==5) {
						logger.info("PARAM FILL5=>["+drStmntVo.getFill5() +"] VALUE5>["+paramMap.get(drStmntVo.getFill5()) +"]");
						String fill5=paramMap.get(drStmntVo.getFill5());
						if(fill5 ==null || "".equalsIgnoreCase(fill5.trim()) || "0".equalsIgnoreCase(fill5) || "0.00".equalsIgnoreCase(fill5) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill5()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill5()));
				   }else if(cnt==6) {
						logger.info("PARAM FILL6=>["+drStmntVo.getFill6() +"] VALUE6=>["+paramMap.get(drStmntVo.getFill6()) +"]");
						String fill6=paramMap.get(drStmntVo.getFill6());
						if(fill6 ==null || "".equalsIgnoreCase(fill6.trim()) || "0".equalsIgnoreCase(fill6) || "0.00".equalsIgnoreCase(fill6) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill6()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill6()));
				   }else if(cnt==7) {
						logger.info("PARAM FILL7=>["+drStmntVo.getFill7() +"] VALUE7=>["+paramMap.get(drStmntVo.getFill7()) +"]");
						String fill7=paramMap.get(drStmntVo.getFill7());
						if(fill7 ==null || "".equalsIgnoreCase(fill7.trim()) || "0".equalsIgnoreCase(fill7) || "0.00".equalsIgnoreCase(fill7) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill7()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill7()));
				   }else if(cnt==8) {
						logger.info("PARAM FILL8=>["+drStmntVo.getFill8() +"] VALUE8=>["+paramMap.get(drStmntVo.getFill8()) +"]");
						String fill8=paramMap.get(drStmntVo.getFill8());
						if(fill8 ==null || "".equalsIgnoreCase(fill8.trim()) || "0".equalsIgnoreCase(fill8) || "0.00".equalsIgnoreCase(fill8) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill8()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill8()));
				   }else if(cnt==9) {
						logger.info("PARAM FILL9=>["+drStmntVo.getFill9() +"] VALUE9=>["+paramMap.get(drStmntVo.getFill9()) +"]");
						String fill9=paramMap.get(drStmntVo.getFill5());
						if(fill9 ==null || "".equalsIgnoreCase(fill9.trim()) || "0".equalsIgnoreCase(fill9) || "0.00".equalsIgnoreCase(fill9) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill9()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill9()));
				   }else if(cnt==10) {
						logger.info("PARAM FILL10=>["+drStmntVo.getFill10() +"] VALUE10=>["+paramMap.get(drStmntVo.getFill10()) +"]");
						String fill10=paramMap.get(drStmntVo.getFill10());
						if(fill10 ==null || "".equalsIgnoreCase(fill10.trim()) || "0".equalsIgnoreCase(fill10) || "0.00".equalsIgnoreCase(fill10) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill10()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill10()));
					}else if(cnt==11) {
						String fill11=paramMap.get(drStmntVo.getFill11());
						if(fill11 ==null || "".equalsIgnoreCase(fill11.trim()) || "0".equalsIgnoreCase(fill11) || "0.00".equalsIgnoreCase(fill11) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill11()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill11()));
					}else if(cnt==12) {
						String fill12=paramMap.get(drStmntVo.getFill12());
						if(fill12 ==null || "".equalsIgnoreCase(fill12.trim()) || "0".equalsIgnoreCase(fill12) || "0.00".equalsIgnoreCase(fill12) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill12()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill12()));
					}else if(cnt==13) {
						String fill13=paramMap.get(drStmntVo.getFill13());
						if(fill13 ==null || "".equalsIgnoreCase(fill13.trim()) || "0".equalsIgnoreCase(fill13) || "0.00".equalsIgnoreCase(fill13) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill13()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill13()));
					}else if(cnt==14) {
						String fill14=paramMap.get(drStmntVo.getFill14());
						if(fill14 ==null || "".equalsIgnoreCase(fill14.trim()) || "0".equalsIgnoreCase(fill14) || "0.00".equalsIgnoreCase(fill14) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill14()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill14()));
					}else if(cnt==15) {
						String fill15=paramMap.get(drStmntVo.getFill15());
						if(fill15 ==null || "".equalsIgnoreCase(fill15.trim()) || "0".equalsIgnoreCase(fill15) || "0.00".equalsIgnoreCase(fill15) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill15()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill15()));
					}else if(cnt==16) {
						String fill16=paramMap.get(drStmntVo.getFill16());
						if(fill16 ==null || "".equalsIgnoreCase(fill16.trim()) || "0".equalsIgnoreCase(fill16) || "0.00".equalsIgnoreCase(fill16) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill16()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill16()));
					}else if(cnt==17) {
						String fill17=paramMap.get(drStmntVo.getFill17());
						if(fill17 ==null || "".equalsIgnoreCase(fill17.trim()) || "0".equalsIgnoreCase(fill17) || "0.00".equalsIgnoreCase(fill17) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill17()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill17()));
					}else if(cnt==18) {
						String fill18=paramMap.get(drStmntVo.getFill18());
						if(fill18 ==null || "".equalsIgnoreCase(fill18.trim()) || "0".equalsIgnoreCase(fill18) || "0.00".equalsIgnoreCase(fill18) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill18()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill18()));
					}else if(cnt==19) {
						String fill19=paramMap.get(drStmntVo.getFill19());
						if(fill19 ==null || "".equalsIgnoreCase(fill19.trim()) || "0".equalsIgnoreCase(fill19) || "0.00".equalsIgnoreCase(fill19) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill19()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill19()));
					}else if(cnt==20) {
						String fill20=paramMap.get(drStmntVo.getFill20());
						if(fill20 ==null || "".equalsIgnoreCase(fill20.trim()) || "0".equalsIgnoreCase(fill20) || "0.00".equalsIgnoreCase(fill20) ) nullCnt=nullCnt+1;
						drStmtFinal=drStmtFinal.replaceFirst(token, paramMap.get(drStmntVo.getFill20()));
						drStmtFinalHindi=drStmtFinalHindi.replaceFirst(token, paramMap.get(drStmntVo.getFill20()));
				    }else if(cnt>=21) drStmtFinal=drStmtFinal.replaceAll(token, "XXX"); // To stop getting into an infinite loop
				}catch(Exception e) {
					logger.error("Error/Exception occured ...."+drStmntVo.getStatementId() + " Error on Token =>"+ cnt + " is " +e.toString());
					e.printStackTrace(System.out);
					cnt++;tokenCnt++;
				}
				cnt++;tokenCnt++;
			}
			logger.info("drStmt cnt .... "+drStmntVo.getStatementId() +" TokenCnt.."+tokenCnt+" Null Param.."+nullCnt);
			if(drStmntPick && tokenCnt==nullCnt) drvDtoTmp.setDrStmtPrint("No");
			else drvDtoTmp.setDrStmtPrint("Yes");
			logger.info("drStmtFinal .... "+drStmtFinal);	
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}drvDtoTmp.setDrStmt(drStmtFinal);
		drvDtoTmp.setDrStmtHindi(drStmtFinalHindi);
		return drvDtoTmp;
	}	
	
	@Override
	public Boolean updateBatchProcessStatus(Integer legalEntityCode, String auditId, String auditTypeCode, boolean inProgress){
		boolean execute= true;
		logger.info("legalEntityCode .. "+legalEntityCode +" auditId .. "+auditId +" auditTypeCode .. "+auditTypeCode +" inProgress .. "+inProgress);
		try {
			Map<String,Object> properties=new HashMap<String,Object>();
			properties.put("legalEntityCode", legalEntityCode);
			properties.put("auditId", auditId);
			properties.put("auditTypeCode", auditTypeCode);
			IfcBatchProcessStatus ifc=(IfcBatchProcessStatus) batchProcessingDao.getUniqueEntityByMatchingProperties(IfcBatchProcessStatus.class, properties);
			if(ifc !=null) {
				ifc.setBatchInprogressStatus(inProgress); // In progress true means => Batch process going on
				if(inProgress)	ifc.setBatchStartTimestamp(new Timestamp(System.currentTimeMillis()));
				else ifc.setBatchEndTimestamp(new Timestamp(System.currentTimeMillis()));
			}else {
				ifc= new IfcBatchProcessStatus();
				ifc.setLegalEntityCode(legalEntityCode);
				ifc.setAuditTypeCode(auditTypeCode);
				ifc.setAuditId(auditId);
				ifc.setBatchInprogressStatus(inProgress); // In progress true means => Batch process going on
				ifc.setBatchStartTimestamp(new Timestamp(System.currentTimeMillis()));
			}
		}catch(Exception e) {
			e.printStackTrace(System.out);
			return execute=false;
		}		
		return execute;
		
	}
	
	@Override
	public Boolean getBatchInProgressStatus(Integer legalEntityCode, String auditId, String auditTypeCode){
		boolean batchInProgressStatus= true;
		logger.info("getBatchInProgressStatus legalEntityCode .. "+legalEntityCode +" auditId .. "+auditId +" auditTypeCode .. "+auditTypeCode );
		try {
			IfcBatchProcessStatus ifcBtch= batchProcessingDao.getBatchProcessStatus(legalEntityCode, auditId, auditTypeCode);
			if(ifcBtch !=null) batchInProgressStatus=ifcBtch.isBatchInprogressStatus();
			else batchInProgressStatus=false;
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}		
		return batchInProgressStatus;
		
	}
	
	@Override
	public void updateAuditReportStmntRupeeSymbl(int legalEntityCode,String auditTypeCode,String auditId){
		logger.info("In ServiceIMPL updateAuditReportStmntRupeeSymbl legalEntityCode .. "+legalEntityCode +" auditId .. "+auditId +" auditTypeCode .. "+auditTypeCode );
		try {
			batchProcessingDao.updateAuditReportStmntRupeeSymbl(legalEntityCode, auditTypeCode, auditId);
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
		
	}
	
	// Method to modify the -ve number, and display as +ve one.
	public String verifyAndConvert2Positive(String tokenFill) {
		logger.info("verifyAndConvert2Positive tokenFill .. "+ tokenFill);
		try { 	
			double d=Double.parseDouble(tokenFill); //To get the number directly from Comparison field
			if(d < 0) {
				tokenFill=tokenFill.replace("-", "");
			}return tokenFill;
		}catch(Exception e) {
			return tokenFill;
		}
	}
	
	//Method to apply dependency type
	public void applyDependencyRule(int legalEntityCode,String auditTypeCode,String auditId, Map<String, String> paramMap){
		logger.info("In ServiceIMPL applyDependencyRule legalEntityCode .. "+legalEntityCode +" auditId .. "+auditId +" auditTypeCode .. "+auditTypeCode );
		try {
			if(paramMap!=null)logger.info("3BOMD610 :: "+paramMap.get("3BOMD610"));  // BOMD610=1 Annual, =2 BiAnnual
			if(paramMap!=null && "1".equals(paramMap.get("3BOMD610"))) {
				batchProcessingDao.suppressInterveningYrDeriveStmnts(legalEntityCode, auditTypeCode, auditId);
			}			
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
		
	}
}
