package com.bankaudit.report.v3.service;
 
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.apache.pdfbox.multipdf.PDFMergerUtility;
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.constants.BankAuditConstant;
import com.bankaudit.model.User;
import com.bankaudit.process.model.AuditLetterReportDocumentDetails;
import com.bankaudit.process.model.AuditSchedule;
import com.bankaudit.process.model.AuditTeam;
//import com.bankaudit.model.AuditReportCoverPage;
import com.bankaudit.report.v3.dao.AuditBookReportDaoV3;
import com.bankaudit.report.v3.dto.AuditBookReportDataModel;
import com.bankaudit.report.v3.dto.BackCoverPageDto;
import com.bankaudit.report.v3.dto.ChapterDto;
import com.bankaudit.report.v3.dto.CheckListDto;
import com.bankaudit.report.v3.dto.CoverPageDto;
import com.bankaudit.report.v3.dto.PartDto;
import com.bankaudit.report.v3.dto.ProcessDto;
import com.bankaudit.report.v3.dto.ProductDto;
import com.bankaudit.report.v3.dto.Profile;
import com.bankaudit.report.v3.dto.ProfileBankDetails;
import com.bankaudit.report.v3.dto.ProfileDetails;
import com.bankaudit.report.v3.dto.SectionDto;
import com.bankaudit.report.v3.dto.StaticDerivedStatementDTO;
import com.bankaudit.report.v3.dto.TableDataColumnNumberDto;
import com.bankaudit.rest.process.dao.AuditScheduleDao;
import com.bankaudit.service.BusinessDateService;
import com.bankaudit.service.GeneralParameterService;
import com.bankaudit.service.UserService;
import com.bankaudit.spring.config.BankAuditConfig;
import com.bankaudit.util.BankAuditUtil;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
//import com.mysql.fabric.xmlrpc.base.Array;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; 

@Service("auditBookReportServiceV3")
@Transactional("transactionManager")
public class AuditBookReportServiceImplV3 implements AuditBookReportServiceV3 {

	static final Logger logger = Logger.getLogger(AuditBookReportServiceImplV3.class);
	
	@Autowired
	AuditBookReportDaoV3 auditBookReportDaoV3 ;
	
	@Autowired
	BusinessDateService businessDateService;
	
	@Autowired
	GeneralParameterService generalParameterService;
	
	@Autowired
	AuditScheduleDao auditScheduleDao;
	
	@Autowired
	UserService userService;
	
	public List<PartDto> processIRGlobal(String legalEntityCode, String auditId, String auditTypeCode, String reportLanguage, String userId) {
		
		auditBookReportDaoV3.getIRSession();	
		List<ChapterDto> chapterDtoList = auditBookReportDaoV3.getChapter(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> sectionData = auditBookReportDaoV3.getSection(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> productData = auditBookReportDaoV3.getProduct(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> processData = auditBookReportDaoV3.getProcess(legalEntityCode, auditId, auditTypeCode);
		
		Map<String,String> checklistPartAB = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, "C,N");
		Map<String,String> checklistPartA = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, "N");
		//Map<String,String> checklistPartB = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, "C");
		
		Map<String,String> stmtPartA = auditBookReportDaoV3.getStandardStatement(legalEntityCode, auditId, auditTypeCode, "N");
		Map<String,String> stmtPartB = auditBookReportDaoV3.getStandardStatement(legalEntityCode, auditId, auditTypeCode, "C");
		
		Map<String,String> remarkPartA = auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, "N", BankAuditConstant.FOR_REMARKS);
		Map<String,String> remarkPartB =auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, "C", BankAuditConstant.FOR_REMARKS);	

		Map<String,String> derivedStaticStatementData = auditBookReportDaoV3.getDerivedStaticStatementAll(legalEntityCode, auditId, auditTypeCode);
		 
		String[] parts ={"Part A","Part B"}; 
		String[] standardStmtSequence ={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
								"aa","ab","ac","ad","ae","af","ag","ah","ai","aj","ak","al","am","an","ao","ap","aq","ar","as","at","au","av","aw","ax","ay","az",
								"ba","bb","bc","bd","be","bf","bg","bh","bi","bj","bk","bl","bm","bn","bo","bp","bq","br","bs","bt","bu","bv","bw","bx","by","bz",
								"ca","cb","cc","cd","ce","cf","cg","ch","ci","cj","ck","cl","cm","cn","co","cp","cq","cr","cs","ct","cu","cv","cw","cx","cy","cz"};
		
		int chapterSeq  = 1;
		int sectionSeq  = 1;
		int productSeq  = 1;		 
		int standardStmtSeqIndex = 0;
		boolean isStandardStmtSequence =false; 
		
		boolean isChapterDetailsAvail =false; 
		boolean isSectionDetailsAvail =false; 
		boolean isProductDetailsAvail =false;  
		
		List<PartDto>  listPart =  new ArrayList<PartDto>();
		 
		for (String partName : parts) {
			
			PartDto partDto =new PartDto();
			partDto.setPartName(partName);
				 	 
			List<ChapterDto>  listChapterDtoUpdated = new ArrayList<ChapterDto>(); 
								
			for (ChapterDto  chapterDto: chapterDtoList) {
				 
				isChapterDetailsAvail =false; 
				sectionSeq  = 1;
				productSeq  = 1; 
				String auditGroupCode = chapterDto.getAuditGroupCode();
				ChapterDto chapterDtoUpdated = new ChapterDto();
				chapterDtoUpdated.setAuditGroupCode(auditGroupCode);
				chapterDtoUpdated.setChapterName(chapterDto.getChapterName());	
				chapterDtoUpdated.setChapterNameHindi(chapterDto.getChapterNameHindi());	
				chapterDtoUpdated.setSequenceNumber(chapterSeq+".");   
				 
				if(partName.equalsIgnoreCase("Part B")){
					String derivedStaticStmtStringList = derivedStaticStatementData.get(auditGroupCode);
					String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
					List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
					List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
					
					chapterDtoUpdated.setStatements(derivedStaticStmtList);
					chapterDtoUpdated.setStatementsHindi(derivedStaticStmtListHindi);
					if(!chapterDtoUpdated.getStatements().isEmpty() && chapterDtoUpdated.getStatements().size()>0){
						isChapterDetailsAvail = true;
					}
				}
				 
				String sectionList = sectionData.get(auditGroupCode);					
				String[] section = sectionList!=null?sectionList.split("#@::@#"):null;
				//List<String> listSectionDto = sortArray(section);
				SortedMap<Integer, String> listSectionDto = sortedArray(section);
				List<SectionDto> listSectionDtoUpdated = new ArrayList<SectionDto>(); 
				
				//for (String sectionDto : listSectionDto){ 
				for (Map.Entry<Integer, String> sectionDto : listSectionDto.entrySet()){ 
					String[] sectionRec=sectionDto.getValue().split("#::#");					
					String sectionName = sectionRec[2]; 
					isSectionDetailsAvail =false; 
					productSeq  = 1; 
					String auditSubGroupCode = auditGroupCode+sectionRec[1];
					
					SectionDto sectionDtoUpdate = new SectionDto();
					sectionDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+".");
					sectionDtoUpdate.setAuditSubGroupCode(sectionRec[1]);
					sectionDtoUpdate.setSectionName(sectionName);
					sectionDtoUpdate.setSectionNameHindi(sectionRec[3]);
										
					if(partName.equalsIgnoreCase("Part B")){
						String derivedStaticStmtStringList = derivedStaticStatementData.get(auditSubGroupCode);
						String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
						List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
						List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
						
						sectionDtoUpdate.setStatements(derivedStaticStmtList);
						sectionDtoUpdate.setStatementsHindi(derivedStaticStmtListHindi);
						if(!sectionDtoUpdate.getStatements().isEmpty() && sectionDtoUpdate.getStatements().size()>0){
							isSectionDetailsAvail = true;
							isChapterDetailsAvail = true;
						}
					}
					
					String[] product = productData.get(auditSubGroupCode)!=null?productData.get(auditSubGroupCode).split("#@::@#"):null;
					//List<String> listProductDto = sortArray(product);
					SortedMap<Integer, String> listProductDto = sortedArray(product);
					List<ProductDto> listProductDtoUpdated = new ArrayList<ProductDto>(); 
					
					//for (String productDto : listProductDto) {
					for(Map.Entry<Integer, String> productDto : listProductDto.entrySet()){
						String[] productRec=productDto.getValue().split("#::#");
						String productName = productRec[2]; 
						isProductDetailsAvail=false; 						
						String activityCode = auditSubGroupCode+productRec[1];							
						ProductDto productDtoUpdate = new ProductDto();
						productDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+"."+productSeq+".");  
						productDtoUpdate.setActivityCode(productRec[1]);
						productDtoUpdate.setProductName(productName);
						productDtoUpdate.setProductNameHindi(productRec[3]);
					  
						if(partName.equalsIgnoreCase("Part B")){
							String derivedStaticStmtStringList = derivedStaticStatementData.get(activityCode);
							String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
							List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
							List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
							
							productDtoUpdate.setStatements(derivedStaticStmtList);
							productDtoUpdate.setStatementsHindi(derivedStaticStmtListHindi);
							if(!productDtoUpdate.getStatements().isEmpty() && productDtoUpdate.getStatements().size()>0){
								isProductDetailsAvail = true;
								isSectionDetailsAvail = true;
								isChapterDetailsAvail = true;
							}
						}
						
						 String[] process = processData.get(activityCode)!=null?processData.get(activityCode).split("#@::@#"):null; 
						 SortedMap<Integer, String> listProcessDto = sortedArray(process);
						 List<ProcessDto> listProcessDtoUpdated = new ArrayList<ProcessDto>();
						  
						 for (Map.Entry<Integer, String> processDto : listProcessDto.entrySet()) {
							 String[] processRec=processDto.getValue().split("#::#");  
							 String processCode = activityCode+processRec[1];
							 ProcessDto processDtoUpdate = new ProcessDto();
							 	  
							  
							 //Used for checklist data  
							 List<CheckListDto>  listCheckListDtoUpdated = new ArrayList<CheckListDto>();
							 standardStmtSeqIndex =0;
							 
							 //Get standard statement, remarks for Compliance Item
							 if(partName.equalsIgnoreCase("Part B")){  
								   
								 String[] cheklistPartAB = checklistPartAB.get(processCode)!=null?checklistPartAB.get(processCode).split("#@::@#"):null; 
								 SortedMap<Integer, String> listCheckListDto = sortedArray(cheklistPartAB);
								 								 
								 for (Map.Entry<Integer, String> checkListDto : listCheckListDto.entrySet()) {
									 String[] checklistRec=checkListDto.getValue().split("#::#");										 
									 isStandardStmtSequence = false;
									 String findingCode = processCode+checklistRec[1]; 
									 CheckListDto checkListDtoUpdate = new CheckListDto();											 
									 checkListDtoUpdate.setChecklist("");
									 checkListDtoUpdate.setChecklistHindi("");

									 if("C".equalsIgnoreCase(checklistRec[3])){
										 //get Standard statement
										 if(stmtPartB!=null && stmtPartB.size()>0 && stmtPartB.get(findingCode)!=null){
											 String  standardStatement = stmtPartB.get(findingCode).split("#::#")[0];
											 String  standardStatementHindi = stmtPartB.get(findingCode).split("#::#")[1];
											 if(!BankAuditUtil.isEmptyString(standardStatement) && !standardStatement.equalsIgnoreCase("null")){
												 checkListDtoUpdate.setStandardStatement(standardStatement.trim());
												 checkListDtoUpdate.setStandardStatementHindi(standardStatementHindi.trim());
												 checkListDtoUpdate.setSequenceNumberStandardStmt(standardStmtSequence[standardStmtSeqIndex]+".");
												 standardStmtSeqIndex++;
												 isStandardStmtSequence = true;
												 
												 isProductDetailsAvail = true;
												 isSectionDetailsAvail = true;
												 isChapterDetailsAvail = true;
											 }	
										 }
										 
										 //get remarks 
										 if(remarkPartB!=null && remarkPartB.size()>0 && remarkPartB.get(findingCode)!=null){
											 String  remarks =  remarkPartB.get(findingCode).split("#::#")[0];
											 String  remarksHindi =  remarkPartB.get(findingCode).split("#::#")[1];
											 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null"))
													 || (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
												 checkListDtoUpdate.setRemarks(remarks.trim());
												 checkListDtoUpdate.setRemarksHindi(remarksHindi.trim());
												 if(!isStandardStmtSequence){
													 checkListDtoUpdate.setSequenceNumberRemarks(standardStmtSequence[standardStmtSeqIndex]+".");
													 standardStmtSeqIndex++;
													 isStandardStmtSequence = false;
													 
													 isProductDetailsAvail = true;
													 isSectionDetailsAvail = true;
													 isChapterDetailsAvail = true;
												 }
											 } 
										 }
									 }
									  
									 //Get Derived/Static Statement  			 
									 String derivedStaticStmtStringList = derivedStaticStatementData.get(findingCode);
									 String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
									 List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
									 List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
									
									 checkListDtoUpdate.setStatements(derivedStaticStmtList);
									 checkListDtoUpdate.setStatementsHindi(derivedStaticStmtListHindi);
									 if(!checkListDtoUpdate.getStatements().isEmpty() && checkListDtoUpdate.getStatements().size()>0){
										 isProductDetailsAvail = true;
										 isSectionDetailsAvail = true;
										 isChapterDetailsAvail = true;
									 } 								 
									 
									 listCheckListDtoUpdated.add(checkListDtoUpdate);	 
										  
								}											 
							 }
							 else{	
								 //Get Derived, standard statement, remarks for Non Compliance Item									  
								 String[] cheklistPartA = checklistPartA.get(processCode)!=null?checklistPartA.get(processCode).split("#@::@#"):null; 
								 SortedMap<Integer, String> listCheckListDto = sortedArray(cheklistPartA); 
								 for (Map.Entry<Integer, String> checkListDto : listCheckListDto.entrySet()) {
									 String[] checklistRec=checkListDto.getValue().split("#::#");										 
									 isStandardStmtSequence = false;
									 String findingCode = processCode+checklistRec[1]; 
									 CheckListDto checkListDtoUpdate = new CheckListDto();											 
									 checkListDtoUpdate.setChecklist("");										 
									 
									 //get Standard statement										 
									 if(stmtPartA!=null && stmtPartA.size()>0 && stmtPartA.get(findingCode)!=null){
										 String  standardStatement = stmtPartA.get(findingCode).split("#::#")[0];
										 String  standardStatementHindi = stmtPartA.get(findingCode).split("#::#")[1];
										 if(!BankAuditUtil.isEmptyString(standardStatement) && !standardStatement.equalsIgnoreCase("null")){
											 checkListDtoUpdate.setStandardStatement(standardStatement.trim());
											 checkListDtoUpdate.setStandardStatementHindi(standardStatementHindi.trim());
											 checkListDtoUpdate.setSequenceNumberStandardStmt(standardStmtSequence[standardStmtSeqIndex]+".");
											 standardStmtSeqIndex++;
											 isStandardStmtSequence = true;
											 
											 isProductDetailsAvail = true;
											 isSectionDetailsAvail = true;
											 isChapterDetailsAvail = true;
											 											  
										 } 	
									 }
									 //get remarks 
									 if(remarkPartA!=null && remarkPartA.size()>0 && remarkPartA.get(findingCode)!=null){
										 String  remarks =  remarkPartA.get(findingCode).split("#::#")[0];
										 String  remarksHindi =  remarkPartA.get(findingCode).split("#::#")[1];
										 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
												|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
											 checkListDtoUpdate.setRemarks(remarks.trim());
											 checkListDtoUpdate.setRemarksHindi(remarksHindi.trim());
											 if(!isStandardStmtSequence){
												 checkListDtoUpdate.setSequenceNumberRemarks(standardStmtSequence[standardStmtSeqIndex]+".");
												 standardStmtSeqIndex++;
												 isStandardStmtSequence = false;
												 
												 isProductDetailsAvail = true;
												 isSectionDetailsAvail = true;
												 isChapterDetailsAvail = true;												  
											 }
										 }  
									}
									 listCheckListDtoUpdated.add(checkListDtoUpdate);											 									 
								 }	 
							 }									  
							 processDtoUpdate.setCheckList(listCheckListDtoUpdated);
							 
							 listProcessDtoUpdated.add(processDtoUpdate); 
						}				
						productDtoUpdate.setProcessList(listProcessDtoUpdated);
						if(isProductDetailsAvail){
							listProductDtoUpdated.add(productDtoUpdate);
							productSeq++;
						} 						
					} 
					
					sectionDtoUpdate.setProductList(listProductDtoUpdated);						 
					if(isSectionDetailsAvail){
						listSectionDtoUpdated.add(sectionDtoUpdate);
						sectionSeq++;
					}
				}
				chapterDtoUpdated.setSectionList(listSectionDtoUpdated); 									 
				chapterDtoUpdated.setChapterDetailsAvail(isChapterDetailsAvail);   
				chapterSeq++;
				listChapterDtoUpdated.add(chapterDtoUpdated);
				 
			} 
			partDto.setChapterList(listChapterDtoUpdated);
		//}
			 
			listPart.add(partDto); 
			chapterSeq  = 1;
		}  
		
		return listPart;
	}
	
	public List<PartDto> processIR(String legalEntityCode, String auditId, String auditTypeCode, String reportLanguage, String userId) {
		try{		
		auditBookReportDaoV3.getIRSession();	
		List<ChapterDto> chapterDtoList = auditBookReportDaoV3.getChapter(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> sectionData = auditBookReportDaoV3.getSection(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> productData = auditBookReportDaoV3.getProduct(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> processData = auditBookReportDaoV3.getProcess(legalEntityCode, auditId, auditTypeCode);
		
		Map<String,String> checklistPartAB = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, "C,N");
		Map<String,String> checklistPartA = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, "N");
		//Map<String,String> checklistPartB = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, "C");
		
		Map<String,String> stmtPartA = auditBookReportDaoV3.getStandardStatement(legalEntityCode, auditId, auditTypeCode, "N");
		Map<String,String> stmtPartB = auditBookReportDaoV3.getStandardStatement(legalEntityCode, auditId, auditTypeCode, "C");
		
		Map<String,String> remarkPartA = auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, "N", BankAuditConstant.FOR_REMARKS);
		Map<String,String> remarkPartB =auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, "C", BankAuditConstant.FOR_REMARKS);	

		Map<String,String> derivedStaticStatementData = auditBookReportDaoV3.getDerivedStaticStatementAll(legalEntityCode, auditId, auditTypeCode);
		 
		String[] parts ={"Part A","Part B"}; 
		String[] standardStmtSequence ={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
								"aa","ab","ac","ad","ae","af","ag","ah","ai","aj","ak","al","am","an","ao","ap","aq","ar","as","at","au","av","aw","ax","ay","az",
								"ba","bb","bc","bd","be","bf","bg","bh","bi","bj","bk","bl","bm","bn","bo","bp","bq","br","bs","bt","bu","bv","bw","bx","by","bz",
								"ca","cb","cc","cd","ce","cf","cg","ch","ci","cj","ck","cl","cm","cn","co","cp","cq","cr","cs","ct","cu","cv","cw","cx","cy","cz"};
		
		int chapterSeq  = 1;
		int sectionSeq  = 1;
		int productSeq  = 1;
		int processSeq  = 1;
		int checkListSeq  = 1;
		int isCompliedIndex = 0;
		int standardStmtSeqIndex = 0;
		boolean isStandardStmtSequence =false; 
		
		boolean isChapterDetailsAvail =false; 
		boolean isSectionDetailsAvail =false; 
		boolean isProductDetailsAvail =false;   		
		
		List<PartDto>  listPart =  new ArrayList<PartDto>();
		 
		for (String partName : parts) {
			
			PartDto partDto =new PartDto();
			partDto.setPartName(partName);
			  
		//if(!partName.equalsIgnoreCase("Part C")){ 	 
			List<ChapterDto>  listChapterDtoUpdated = new ArrayList<ChapterDto>(); 
								
			for (ChapterDto  chapterDto: chapterDtoList) {
				 
				isChapterDetailsAvail =false; 
				sectionSeq  = 1;
				productSeq  = 1;
				processSeq  = 1;
				checkListSeq  = 1;
				String auditGroupCode = chapterDto.getAuditGroupCode();
				ChapterDto chapterDtoUpdated = new ChapterDto();
				chapterDtoUpdated.setAuditGroupCode(auditGroupCode);
				chapterDtoUpdated.setChapterName(chapterDto.getChapterName());	
				chapterDtoUpdated.setChapterNameHindi(chapterDto.getChapterNameHindi());	
				chapterDtoUpdated.setSequenceNumber(chapterSeq+".");   
				 
				if(partName.equalsIgnoreCase("Part B")){
					String derivedStaticStmtStringList = derivedStaticStatementData.get(auditGroupCode);
					String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
					List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
					List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
					
					chapterDtoUpdated.setStatements(derivedStaticStmtList);
					chapterDtoUpdated.setStatementsHindi(derivedStaticStmtListHindi);
					if(!chapterDtoUpdated.getStatements().isEmpty() && chapterDtoUpdated.getStatements().size()>0){
						isChapterDetailsAvail = true;
					}
				}
				 
				String sectionList = sectionData.get(auditGroupCode);					
				String[] section = sectionList!=null?sectionList.split("#@::@#"):null;
				//List<String> listSectionDto = sortArray(section);
				SortedMap<Integer, String> listSectionDto = sortedArray(section);
				List<SectionDto> listSectionDtoUpdated = new ArrayList<SectionDto>(); 
				
				//for (String sectionDto : listSectionDto){ 
				for (Map.Entry<Integer, String> sectionDto : listSectionDto.entrySet()){ 
					String[] sectionRec=sectionDto.getValue().split("#::#");
					isSectionDetailsAvail =false; 
					productSeq  = 1;
					processSeq  = 1;
					checkListSeq  = 1; 
					String auditSubGroupCode = auditGroupCode+sectionRec[1];
					SectionDto sectionDtoUpdate = new SectionDto();
					sectionDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+".");
					sectionDtoUpdate.setAuditSubGroupCode(sectionRec[1]);
					sectionDtoUpdate.setSectionName(sectionRec[2]);
					sectionDtoUpdate.setSectionNameHindi(sectionRec[3]);
										
					if(partName.equalsIgnoreCase("Part B")){
						String derivedStaticStmtStringList = derivedStaticStatementData.get(auditSubGroupCode);
						String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
						List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
						List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
						
						sectionDtoUpdate.setStatements(derivedStaticStmtList);
						sectionDtoUpdate.setStatementsHindi(derivedStaticStmtListHindi);
						if(!sectionDtoUpdate.getStatements().isEmpty() && sectionDtoUpdate.getStatements().size()>0){
							isSectionDetailsAvail = true;
							isChapterDetailsAvail = true;
						}
					}
					
					String[] product = productData.get(auditSubGroupCode)!=null?productData.get(auditSubGroupCode).split("#@::@#"):null;
					//List<String> listProductDto = sortArray(product);
					SortedMap<Integer, String> listProductDto = sortedArray(product);
					List<ProductDto> listProductDtoUpdated = new ArrayList<ProductDto>(); 
					
					//for (String productDto : listProductDto) {
					for(Map.Entry<Integer, String> productDto : listProductDto.entrySet()){
						String[] productRec=productDto.getValue().split("#::#");
						isProductDetailsAvail=false;
						processSeq  = 1;
						checkListSeq  = 1; 							
						String activityCode = auditSubGroupCode+productRec[1];							
						ProductDto productDtoUpdate = new ProductDto();
						productDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+"."+productSeq+".");  
						productDtoUpdate.setActivityCode(productRec[1]);
						productDtoUpdate.setProductName(productRec[2]);
						productDtoUpdate.setProductNameHindi(productRec[3]);
					  
						if(partName.equalsIgnoreCase("Part B")){
							String derivedStaticStmtStringList = derivedStaticStatementData.get(activityCode);
							String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
							List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
							List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
							
							productDtoUpdate.setStatements(derivedStaticStmtList);
							productDtoUpdate.setStatementsHindi(derivedStaticStmtListHindi);
							if(!productDtoUpdate.getStatements().isEmpty() && productDtoUpdate.getStatements().size()>0){
								isProductDetailsAvail = true;
								isSectionDetailsAvail = true;
								isChapterDetailsAvail = true;
							}
						}
						
						 String[] process = processData.get(activityCode)!=null?processData.get(activityCode).split("#@::@#"):null; 
						 SortedMap<Integer, String> listProcessDto = sortedArray(process);
						 List<ProcessDto> listProcessDtoUpdated = new ArrayList<ProcessDto>();
						  
						 for (Map.Entry<Integer, String> processDto : listProcessDto.entrySet()) {
							 String[] processRec=processDto.getValue().split("#::#");
							 checkListSeq  = 1;
							 String processCode = activityCode+processRec[1];
							 ProcessDto processDtoUpdate = new ProcessDto();
							 	  
							  
							 //Used for checklist data  
							 List<CheckListDto>  listCheckListDtoUpdated = new ArrayList<CheckListDto>();
							 standardStmtSeqIndex =0;
							 
							 //Get standard statement, remarks for Compliance Item
							 if(partName.equalsIgnoreCase("Part B")){  
								   
								 String[] cheklistPartAB = checklistPartAB.get(processCode)!=null?checklistPartAB.get(processCode).split("#@::@#"):null;	
								 //List<String> listCheckListDto = sortArray(cheklistPartAB);
								 SortedMap<Integer, String> listCheckListDto = sortedArray(cheklistPartAB);
								 
								// for (String checkListDto : listCheckListDto) {
								 for (Map.Entry<Integer, String> checkListDto : listCheckListDto.entrySet()) {
									 String[] checklistRec=checkListDto.getValue().split("#::#");										 
									 isStandardStmtSequence = false;
									 String findingCode = processCode+checklistRec[1]; 
									 CheckListDto checkListDtoUpdate = new CheckListDto();											 
									 checkListDtoUpdate.setChecklist("");
									 checkListDtoUpdate.setChecklistHindi("");

									 if(BankAuditConstant.COMPLIANCE_YES.equalsIgnoreCase(checklistRec[3])){
										 //get Standard statement
										 if(stmtPartB!=null && stmtPartB.size()>0 && stmtPartB.get(findingCode)!=null){
											 String  standardStatement = stmtPartB.get(findingCode).split("#::#")[0];
											 String  standardStatementHindi = stmtPartB.get(findingCode).split("#::#")[1];
											 if(!BankAuditUtil.isEmptyString(standardStatement) && !standardStatement.equalsIgnoreCase("null")){
												 checkListDtoUpdate.setStandardStatement(standardStatement.trim());
												 checkListDtoUpdate.setStandardStatementHindi(standardStatementHindi.trim());
												 checkListDtoUpdate.setSequenceNumberStandardStmt(standardStmtSequence[standardStmtSeqIndex]+".");
												 standardStmtSeqIndex++;
												 isStandardStmtSequence = true;
												 
												 isProductDetailsAvail = true;
												 isSectionDetailsAvail = true;
												 isChapterDetailsAvail = true;
											 }	
										 }
										 
										 //get remarks 
										 if(remarkPartB!=null && remarkPartB.size()>0 && remarkPartB.get(findingCode)!=null){
											 String  remarks =  remarkPartB.get(findingCode).split("#::#")[0];
											 String  remarksHindi =  remarkPartB.get(findingCode).split("#::#")[1];
											 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null"))
													 || (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
												 checkListDtoUpdate.setRemarks(remarks.trim());
												 checkListDtoUpdate.setRemarksHindi(remarksHindi.trim());
												 if(!isStandardStmtSequence){
													 checkListDtoUpdate.setSequenceNumberRemarks(standardStmtSequence[standardStmtSeqIndex]+".");
													 standardStmtSeqIndex++;
													 isStandardStmtSequence = false;
													 
													 isProductDetailsAvail = true;
													 isSectionDetailsAvail = true;
													 isChapterDetailsAvail = true;
												 }
											 } 
										 }
									 }
									  
									 //Get Derived/Static Statement  			 
									 String derivedStaticStmtStringList = derivedStaticStatementData.get(findingCode);
									 String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
									 List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
									 List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
									
									 checkListDtoUpdate.setStatements(derivedStaticStmtList);
									 checkListDtoUpdate.setStatementsHindi(derivedStaticStmtListHindi);
									 if(!checkListDtoUpdate.getStatements().isEmpty() && checkListDtoUpdate.getStatements().size()>0){
										 isProductDetailsAvail = true;
										 isSectionDetailsAvail = true;
										 isChapterDetailsAvail = true;
									 } 									 
									 listCheckListDtoUpdated.add(checkListDtoUpdate);	
								}											 
							 }
							 else{	
								 //Get Derived, standard statement, remarks for Non Compliance Item									  
								 String[] cheklistPartA = checklistPartA.get(processCode)!=null?checklistPartA.get(processCode).split("#@::@#"):null; 
								 SortedMap<Integer, String> listCheckListDto = sortedArray(cheklistPartA); 
								 for (Map.Entry<Integer, String> checkListDto : listCheckListDto.entrySet()) {
									 String[] checklistRec=checkListDto.getValue().split("#::#");										 
									 isStandardStmtSequence = false;
									 String findingCode = processCode+checklistRec[1]; 
									 CheckListDto checkListDtoUpdate = new CheckListDto();											 
									 checkListDtoUpdate.setChecklist("");										 
									 
									 //get Standard statement										 
									 if(stmtPartA!=null && stmtPartA.size()>0 && stmtPartA.get(findingCode)!=null){
										 String  standardStatement = stmtPartA.get(findingCode).split("#::#")[0];
										 String  standardStatementHindi = stmtPartA.get(findingCode).split("#::#")[1];
										 if(!BankAuditUtil.isEmptyString(standardStatement) && !standardStatement.equalsIgnoreCase("null")){
											 checkListDtoUpdate.setStandardStatement(standardStatement.trim());
											 checkListDtoUpdate.setStandardStatementHindi(standardStatementHindi.trim());
											 checkListDtoUpdate.setSequenceNumberStandardStmt(standardStmtSequence[standardStmtSeqIndex]+".");
											 standardStmtSeqIndex++;
											 isStandardStmtSequence = true;
											 
											 isProductDetailsAvail = true;
											 isSectionDetailsAvail = true;
											 isChapterDetailsAvail = true;
										 } 	
									 }
									 //get remarks 
									 if(remarkPartA!=null && remarkPartA.size()>0 && remarkPartA.get(findingCode)!=null){
										 String  remarks =  remarkPartA.get(findingCode).split("#::#")[0];
										 String  remarksHindi =  remarkPartA.get(findingCode).split("#::#")[1];
										 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
												|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
											 checkListDtoUpdate.setRemarks(remarks.trim());
											 checkListDtoUpdate.setRemarksHindi(remarksHindi.trim());
											 if(!isStandardStmtSequence){
												 checkListDtoUpdate.setSequenceNumberRemarks(standardStmtSequence[standardStmtSeqIndex]+".");
												 standardStmtSeqIndex++;
												 isStandardStmtSequence = false;
												 
												 isProductDetailsAvail = true;
												 isSectionDetailsAvail = true;
												 isChapterDetailsAvail = true;
											 }
										 }  
									}
									 listCheckListDtoUpdated.add(checkListDtoUpdate);											 									 
								 }									     
							 }									  
							 processDtoUpdate.setCheckList(listCheckListDtoUpdated); 
								 
							 listProcessDtoUpdated.add(processDtoUpdate);
							 processSeq++;
						}				
						productDtoUpdate.setProcessList(listProcessDtoUpdated);
						if(isProductDetailsAvail){
							listProductDtoUpdated.add(productDtoUpdate);
							productSeq++;
						} 						
					} 
					
					sectionDtoUpdate.setProductList(listProductDtoUpdated);						 
					if(isSectionDetailsAvail){
						listSectionDtoUpdated.add(sectionDtoUpdate);
						sectionSeq++;
					}
				}
				chapterDtoUpdated.setSectionList(listSectionDtoUpdated); 	
									 
				chapterDtoUpdated.setChapterDetailsAvail(isChapterDetailsAvail); 
				listChapterDtoUpdated.add(chapterDtoUpdated);				
				chapterSeq++;
			} 
			partDto.setChapterList(listChapterDtoUpdated);
		//}
			 
			listPart.add(partDto);
			isCompliedIndex++;
			chapterSeq  = 1;
		}
		 
		//System.out.println("Time Taken ==>> "+(System.currentTimeMillis() -  startTime));
		return listPart;
		}catch (Exception e) {
			logger.error(e.getStackTrace());
			e.printStackTrace(System.out);
		}return null;
	}
	
	public List<PartDto> processCR(String legalEntityCode, String auditId, String auditTypeCode, String reportLanguage, String userId, String actionType, String role) {
		try{
		auditBookReportDaoV3.getIRSession();	
		List<ChapterDto> chapterDtoList = auditBookReportDaoV3.getChapter(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> sectionData = auditBookReportDaoV3.getSection(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> productData = auditBookReportDaoV3.getProduct(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> processData = auditBookReportDaoV3.getProcess(legalEntityCode, auditId, auditTypeCode);
		 
		Map<String,String> checklistPartA = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, "N"); 		
		Map<String,String> stmtPartA = auditBookReportDaoV3.getStandardStatement(legalEntityCode, auditId, auditTypeCode, "N"); 		
		Map<String,String> remarkPartA = auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, "N", BankAuditConstant.FOR_REMARKS); 
		Map<String,String> remarkBankPartA = auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, "N", BankAuditConstant.FOR_REMARKS_BANK); 
 		 
		Map<String,String> remarkClosureAllPartA = null; 
		if(actionType.equalsIgnoreCase(BankAuditConstant.CR_CLOSURE)){
			remarkClosureAllPartA = auditBookReportDaoV3.getRemarksClosure(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, null, null);			 
		}	
		String[] parts ={"Part A"}; 
		String[] isComplied ={"N"};
		String[] standardStmtSequence ={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
								"aa","ab","ac","ad","ae","af","ag","ah","ai","aj","ak","al","am","an","ao","ap","aq","ar","as","at","au","av","aw","ax","ay","az",
								"ba","bb","bc","bd","be","bf","bg","bh","bi","bj","bk","bl","bm","bn","bo","bp","bq","br","bs","bt","bu","bv","bw","bx","by","bz",
								"ca","cb","cc","cd","ce","cf","cg","ch","ci","cj","ck","cl","cm","cn","co","cp","cq","cr","cs","ct","cu","cv","cw","cx","cy","cz"};
		
		int chapterSeq  = 1;
		int sectionSeq  = 1;
		int productSeq  = 1;
		int processSeq  = 1;
		int checkListSeq  = 1;
		int isCompliedIndex = 0;
		int standardStmtSeqIndex = 0;
		boolean isStandardStmtSequence =false; 		
		
		boolean isChapterDetailsAvail =false; 
		boolean isSectionDetailsAvail =false; 
		boolean isProductDetailsAvail =false;   		
		
		List<PartDto>  listPart =  new ArrayList<PartDto>();
		 
		//for (String partName : parts) {
			
			PartDto partDto =new PartDto();
			//partDto.setPartName(partName);
			partDto.setPartName("Part A");	
			
		//if(!partName.equalsIgnoreCase("Part C")){ 	 
			List<ChapterDto>  listChapterDtoUpdated = new ArrayList<ChapterDto>(); 
								
			for (ChapterDto  chapterDto: chapterDtoList) {
				 
				isChapterDetailsAvail =false; 
				sectionSeq  = 1;
				productSeq  = 1;
				processSeq  = 1;
				checkListSeq  = 1;
				String auditGroupCode = chapterDto.getAuditGroupCode();
				ChapterDto chapterDtoUpdated = new ChapterDto();
				chapterDtoUpdated.setAuditGroupCode(auditGroupCode);
				chapterDtoUpdated.setChapterName(chapterDto.getChapterName());	
				chapterDtoUpdated.setChapterNameHindi(chapterDto.getChapterNameHindi());	
				chapterDtoUpdated.setSequenceNumber(chapterSeq+".");   
				
				 
				//Get Section Details
				String sectionList = sectionData.get(auditGroupCode);					
				String[] section = sectionList!=null?sectionList.split("#@::@#"):null; 
				SortedMap<Integer, String> listSectionDto = sortedArray(section);
				List<SectionDto> listSectionDtoUpdated = new ArrayList<SectionDto>(); 
				
				for (Map.Entry<Integer, String> sectionDto : listSectionDto.entrySet()){ 
					String[] sectionRec=sectionDto.getValue().split("#::#");
					isSectionDetailsAvail =false; 
					productSeq  = 1;
					processSeq  = 1;
					checkListSeq  = 1; 
					String auditSubGroupCode = auditGroupCode+sectionRec[1];
					SectionDto sectionDtoUpdate = new SectionDto();
					sectionDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+".");
					sectionDtoUpdate.setAuditSubGroupCode(sectionRec[1]);
					sectionDtoUpdate.setSectionName(sectionRec[2]);
					sectionDtoUpdate.setSectionNameHindi(sectionRec[3]);
										
					//Get Product Details 					
					String[] product = productData.get(auditSubGroupCode)!=null?productData.get(auditSubGroupCode).split("#@::@#"):null; 
					SortedMap<Integer, String> listProductDto = sortedArray(product);
					List<ProductDto> listProductDtoUpdated = new ArrayList<ProductDto>(); 
					 
					for(Map.Entry<Integer, String> productDto : listProductDto.entrySet()){
						String[] productRec=productDto.getValue().split("#::#");
						isProductDetailsAvail=false;
						processSeq  = 1;
						checkListSeq  = 1; 							
						String activityCode = auditSubGroupCode+productRec[1];							
						ProductDto productDtoUpdate = new ProductDto();
						productDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+"."+productSeq+".");  
						productDtoUpdate.setActivityCode(productRec[1]);
						productDtoUpdate.setProductName(productRec[2]);
						productDtoUpdate.setProductNameHindi(productRec[3]);

						//Get Process Details
						 String[] process = processData.get(activityCode)!=null?processData.get(activityCode).split("#@::@#"):null; 
						 SortedMap<Integer, String> listProcessDto = sortedArray(process);
						 List<ProcessDto> listProcessDtoUpdated = new ArrayList<ProcessDto>();
						 						 
						 for (Map.Entry<Integer, String> processDto : listProcessDto.entrySet()) {
							 String[] processRec=processDto.getValue().split("#::#");
							 checkListSeq  = 1;
							 String processCode = activityCode+processRec[1];
							 ProcessDto processDtoUpdate = new ProcessDto();
							 	  
							  
							 //Used for checklist data  
							 List<CheckListDto>  listCheckListDtoUpdated = new ArrayList<CheckListDto>();
							 standardStmtSeqIndex =0;
							 
							 //Get Remarks, Standard stmt for Non Compliance Item 							  										  
							 String[] cheklistPartA = checklistPartA.get(processCode)!=null?checklistPartA.get(processCode).split("#@::@#"):null;	 
							 SortedMap<Integer, String> listCheckListDto = sortedArray(cheklistPartA); 
							 for (Map.Entry<Integer, String> checkListDto : listCheckListDto.entrySet()) {
								 String[] checklistRec=checkListDto.getValue().split("#::#");										 
								 isStandardStmtSequence = false;
								 String findingCode = processCode+checklistRec[1]; 
								 CheckListDto checkListDtoUpdate = new CheckListDto();											 
								 checkListDtoUpdate.setChecklist("");										 
								 
								 //get Standard statement										 
								 if(stmtPartA!=null && stmtPartA.size()>0 && stmtPartA.get(findingCode)!=null){
									 String  standardStatement = stmtPartA.get(findingCode).split("#::#")[0];
									 String  standardStatementHindi = stmtPartA.get(findingCode).split("#::#")[1];
									 if(!BankAuditUtil.isEmptyString(standardStatement) && !standardStatement.equalsIgnoreCase("null")){
										 checkListDtoUpdate.setStandardStatement(standardStatement.trim());
										 checkListDtoUpdate.setStandardStatementHindi(standardStatementHindi.trim());
										 checkListDtoUpdate.setSequenceNumberStandardStmt(standardStmtSequence[standardStmtSeqIndex]+".");
										 standardStmtSeqIndex++;
										 isStandardStmtSequence = true;
										 
										 isProductDetailsAvail = true;
										 isSectionDetailsAvail = true;
										 isChapterDetailsAvail = true;
									 } 	
								 }
								 //get IO remarks
								if(remarkPartA!=null && remarkPartA.size()>0 && remarkPartA.get(findingCode)!=null){
									 String  remarks =  remarkPartA.get(findingCode).split("#::#")[0];
									 String  remarksHindi =  remarkPartA.get(findingCode).split("#::#")[1];
									 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
											|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
										 checkListDtoUpdate.setRemarks(remarks.trim());
										 checkListDtoUpdate.setRemarksHindi(remarksHindi.trim());
										 if(!isStandardStmtSequence){
											 checkListDtoUpdate.setSequenceNumberRemarks(standardStmtSequence[standardStmtSeqIndex]+".");
											 standardStmtSeqIndex++;
											 isStandardStmtSequence = false;
											 
											 isProductDetailsAvail = true;
											 isSectionDetailsAvail = true;
											 isChapterDetailsAvail = true;
										 }
									 }  
								}
								
								//get Bank remarks	
								if(BankAuditUtil.isEmptyString(actionType) || actionType.equalsIgnoreCase(BankAuditConstant.CR_SUBMIT)){
									if(remarkBankPartA!=null && remarkBankPartA.size()>0 && remarkBankPartA.get(findingCode)!=null){
										 String  remarks =  remarkBankPartA.get(findingCode).split("#::#")[0];
										 String  remarksHindi =  remarkBankPartA.get(findingCode).split("#::#")[1];
										 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
												|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
											 
											List<String> bankRemarks =  new ArrayList<String>();
											bankRemarks.add("Compliance:");
											bankRemarks.add(remarks);
											checkListDtoUpdate.setBankRemarks(bankRemarks);  
											
											List<String> bankRemarksHindi =  new ArrayList<String>();
											bankRemarksHindi.add("Compliance:");
											bankRemarksHindi.add(remarksHindi);
											checkListDtoUpdate.setBankRemarksHindi(bankRemarksHindi);  
											
											isProductDetailsAvail = true;
											isSectionDetailsAvail = true;
											isChapterDetailsAvail = true;									 
											  
										 }  
									} 
								}else if(actionType.equalsIgnoreCase(BankAuditConstant.CR_CLOSURE)){  //Start from here to change the Compliance closure report
									checkListDtoUpdate = processObservationsClosureReport(remarkClosureAllPartA, null, checkListDtoUpdate, findingCode, role, false);
									isProductDetailsAvail = true;
									isSectionDetailsAvail = true;
									isChapterDetailsAvail = true; 
								}
								 
								listCheckListDtoUpdated.add(checkListDtoUpdate);											 									 
							 }									     
							 									  
							 processDtoUpdate.setCheckList(listCheckListDtoUpdated); 
								 
							 listProcessDtoUpdated.add(processDtoUpdate);
							 processSeq++;
						}				
						productDtoUpdate.setProcessList(listProcessDtoUpdated);
						if(isProductDetailsAvail){
							listProductDtoUpdated.add(productDtoUpdate);
							productSeq++;
						} 						
					} 
					
					sectionDtoUpdate.setProductList(listProductDtoUpdated);						 
					if(isSectionDetailsAvail){
						listSectionDtoUpdated.add(sectionDtoUpdate);
						sectionSeq++;
					}
				}
				chapterDtoUpdated.setSectionList(listSectionDtoUpdated); 	
									 
				chapterDtoUpdated.setChapterDetailsAvail(isChapterDetailsAvail); 
				listChapterDtoUpdated.add(chapterDtoUpdated);				
				chapterSeq++;
			} 
			partDto.setChapterList(listChapterDtoUpdated);
		//}
			 
			listPart.add(partDto);
			isCompliedIndex++;
			chapterSeq  = 1;
		//}
		 
		//System.out.println("Time Taken ==>> "+(System.currentTimeMillis() -  startTime));
		return listPart;
		}catch (Exception e) {
			logger.error(e.getStackTrace());
			e.printStackTrace(System.out);
		}return null;
	}
	
	public List<PartDto> processSR(String legalEntityCode, String auditId, String auditTypeCode, String reportLanguage, String userId, String actionType, String role, 
			Boolean IsFinalizedReport) {
		try{
		auditBookReportDaoV3.getIRSession();	
		List<ChapterDto> chapterDtoList = auditBookReportDaoV3.getChapter(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> sectionData = auditBookReportDaoV3.getSection(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> productData = auditBookReportDaoV3.getProduct(legalEntityCode, auditId, auditTypeCode);
		Map<String,String> processData = auditBookReportDaoV3.getProcess(legalEntityCode, auditId, auditTypeCode);
		 
		Map<String,String> checklistPartA = auditBookReportDaoV3.getChecklist(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO); 		
		Map<String,String> stmtPartA = auditBookReportDaoV3.getStandardStatement(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO); 		
		Map<String,String> remarkPartA = auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, BankAuditConstant.FOR_REMARKS); 
		Map<String,String> remarkBankPartA = auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, BankAuditConstant.FOR_REMARKS_BANK); 
		Map<String,String> remarkScrutinyPartA = auditBookReportDaoV3.getRemarks(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, BankAuditConstant.FOR_REMARKS_SCRUTINY);
		
		//Map<String,String> remarkClosureBankPartA = auditBookReportDaoV3.getRemarksClosure(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, BankAuditConstant.FOR_REMARKS_BANK); 
		//Map<String,String> remarkClosureScrutinyPartA = auditBookReportDaoV3.getRemarksClosure(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, BankAuditConstant.FOR_REMARKS_SCRUTINY);
		Map<String,String> remarkClosureAllPartA = auditBookReportDaoV3.getRemarksClosure(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, null, null);
		Map<String,String> remarkClosureAllAuthPartA = auditBookReportDaoV3.getRemarksClosure(legalEntityCode, auditId, auditTypeCode, BankAuditConstant.COMPLIANCE_NO, null, BankAuditConstant.STATUS_AUTH);
 		 
		String[] parts ={"Part A"}; 
		String[] isComplied ={"N"};
		String[] standardStmtSequence ={"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z",
								"aa","ab","ac","ad","ae","af","ag","ah","ai","aj","ak","al","am","an","ao","ap","aq","ar","as","at","au","av","aw","ax","ay","az",
								"ba","bb","bc","bd","be","bf","bg","bh","bi","bj","bk","bl","bm","bn","bo","bp","bq","br","bs","bt","bu","bv","bw","bx","by","bz",
								"ca","cb","cc","cd","ce","cf","cg","ch","ci","cj","ck","cl","cm","cn","co","cp","cq","cr","cs","ct","cu","cv","cw","cx","cy","cz"};
		
		int chapterSeq  = 1;
		int sectionSeq  = 1;
		int productSeq  = 1;
		int processSeq  = 1;
		int checkListSeq  = 1;
		int isCompliedIndex = 0;
		int standardStmtSeqIndex = 0;
		boolean isStandardStmtSequence =false; 		
		
		boolean isChapterDetailsAvail =false; 
		boolean isSectionDetailsAvail =false; 
		boolean isProductDetailsAvail =false;   		
		
		List<PartDto>  listPart =  new ArrayList<PartDto>();
		 
		//for (String partName : parts) {
			
			PartDto partDto =new PartDto();
			//partDto.setPartName(partName);
			partDto.setPartName("Part A");	
			
		//if(!partName.equalsIgnoreCase("Part C")){ 	 
			List<ChapterDto>  listChapterDtoUpdated = new ArrayList<ChapterDto>(); 
								
			for (ChapterDto  chapterDto: chapterDtoList) {
				 
				isChapterDetailsAvail =false; 
				sectionSeq  = 1;
				productSeq  = 1;
				processSeq  = 1;
				checkListSeq  = 1;
				String auditGroupCode = chapterDto.getAuditGroupCode();
				ChapterDto chapterDtoUpdated = new ChapterDto();
				chapterDtoUpdated.setAuditGroupCode(auditGroupCode);
				chapterDtoUpdated.setChapterName(chapterDto.getChapterName());	
				chapterDtoUpdated.setChapterNameHindi(chapterDto.getChapterNameHindi());	
				chapterDtoUpdated.setSequenceNumber(chapterSeq+".");   
				
				 
				//Get Section Details
				String sectionList = sectionData.get(auditGroupCode);					
				String[] section = sectionList!=null?sectionList.split("#@::@#"):null; 
				SortedMap<Integer, String> listSectionDto = sortedArray(section);
				List<SectionDto> listSectionDtoUpdated = new ArrayList<SectionDto>(); 
				
				for (Map.Entry<Integer, String> sectionDto : listSectionDto.entrySet()){ 
					String[] sectionRec=sectionDto.getValue().split("#::#");
					isSectionDetailsAvail =false; 
					productSeq  = 1;
					processSeq  = 1;
					checkListSeq  = 1; 
					String auditSubGroupCode = auditGroupCode+sectionRec[1];
					String auditSubGroupCodeActual =  sectionRec[1];
					SectionDto sectionDtoUpdate = new SectionDto();
					sectionDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+".");
					sectionDtoUpdate.setAuditSubGroupCode(sectionRec[1]);
					sectionDtoUpdate.setSectionName(sectionRec[2]);
					sectionDtoUpdate.setSectionNameHindi(sectionRec[3]);
										
					//Get Product Details 					
					String[] product = productData.get(auditSubGroupCode)!=null?productData.get(auditSubGroupCode).split("#@::@#"):null; 
					SortedMap<Integer, String> listProductDto = sortedArray(product);
					List<ProductDto> listProductDtoUpdated = new ArrayList<ProductDto>(); 
					 
					for(Map.Entry<Integer, String> productDto : listProductDto.entrySet()){
						String[] productRec=productDto.getValue().split("#::#");
						isProductDetailsAvail=false;
						processSeq  = 1;
						checkListSeq  = 1; 							
						String activityCode = auditSubGroupCode+productRec[1];	
						String activityCodeActual = productRec[1];	
						ProductDto productDtoUpdate = new ProductDto();
						productDtoUpdate.setSequenceNumber(chapterSeq+"."+sectionSeq+"."+productSeq+".");  
						productDtoUpdate.setActivityCode(productRec[1]);
						productDtoUpdate.setProductName(productRec[2]);
						productDtoUpdate.setProductNameHindi(productRec[3]);

						//Get Process Details
						 String[] process = processData.get(activityCode)!=null?processData.get(activityCode).split("#@::@#"):null; 
						 SortedMap<Integer, String> listProcessDto = sortedArray(process);
						 List<ProcessDto> listProcessDtoUpdated = new ArrayList<ProcessDto>();
						 						 
						 for (Map.Entry<Integer, String> processDto : listProcessDto.entrySet()) {
							 String[] processRec=processDto.getValue().split("#::#");
							 checkListSeq  = 1;
							 String processCode = activityCode+processRec[1];
							 String processCodeActual =  processRec[1];
							 ProcessDto processDtoUpdate = new ProcessDto();
							 	  
							  
							 //Used for checklist data  
							 List<CheckListDto>  listCheckListDtoUpdated = new ArrayList<CheckListDto>();
							 standardStmtSeqIndex =0;
							 
							 //Get Remarks, Standard stmt for Non Compliance Item 							  										  
							 String[] cheklistPartA = checklistPartA.get(processCode)!=null?checklistPartA.get(processCode).split("#@::@#"):null;	 
							 SortedMap<Integer, String> listCheckListDto = sortedArray(cheklistPartA); 
							 for (Map.Entry<Integer, String> checkListDto : listCheckListDto.entrySet()) {
								 String[] checklistRec=checkListDto.getValue().split("#::#");										 
								 isStandardStmtSequence = false;
								 String findingCode = processCode+checklistRec[1]; 
								 String findingCodeActual =  checklistRec[1]; 
								 CheckListDto checkListDtoUpdate = new CheckListDto();											 
								 checkListDtoUpdate.setChecklist("");										 
								 
								 //get Standard statement										 
								 if(stmtPartA!=null && stmtPartA.size()>0 && stmtPartA.get(findingCode)!=null){
									 String  standardStatement = stmtPartA.get(findingCode).split("#::#")[0];
									 String  standardStatementHindi = stmtPartA.get(findingCode).split("#::#")[1];
									 if(!BankAuditUtil.isEmptyString(standardStatement) && !standardStatement.equalsIgnoreCase("null")){
										 checkListDtoUpdate.setStandardStatement(standardStatement.trim());
										 checkListDtoUpdate.setStandardStatementHindi(standardStatementHindi.trim());
										 checkListDtoUpdate.setSequenceNumberStandardStmt(standardStmtSequence[standardStmtSeqIndex]+".");
										 standardStmtSeqIndex++;
										 isStandardStmtSequence = true;
										 
										 isProductDetailsAvail = true;
										 isSectionDetailsAvail = true;
										 isChapterDetailsAvail = true;
									 } 	
								 }
								 //get IO remarks
								if(remarkPartA!=null && remarkPartA.size()>0 && remarkPartA.get(findingCode)!=null){
									 String  remarks =  remarkPartA.get(findingCode).split("#::#")[0];
									 String  remarksHindi =  remarkPartA.get(findingCode).split("#::#")[1];
									 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
											|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
										 checkListDtoUpdate.setRemarks(remarks.trim());
										 checkListDtoUpdate.setRemarksHindi(remarksHindi.trim());
										 if(!isStandardStmtSequence){
											 checkListDtoUpdate.setSequenceNumberRemarks(standardStmtSequence[standardStmtSeqIndex]+".");
											 standardStmtSeqIndex++;
											 isStandardStmtSequence = false;
											 
											 isProductDetailsAvail = true;
											 isSectionDetailsAvail = true;
											 isChapterDetailsAvail = true;
										 }
									 }  
								}
								 
								//Call On scrutiny submit
								if(BankAuditUtil.isEmptyString(actionType) || actionType.equalsIgnoreCase(BankAuditConstant.SR_SUBMIT) ){
									//get Bank remarks								
									if(remarkBankPartA!=null && remarkBankPartA.size()>0 && remarkBankPartA.get(findingCode)!=null){
										 String  remarks =  remarkBankPartA.get(findingCode).split("#::#")[0];
										 String  remarksHindi =  remarkBankPartA.get(findingCode).split("#::#")[1];
										 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
												|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
											 
											List<String> bankRemarks =  new ArrayList<String>();
											bankRemarks.add("Compliance:");
											bankRemarks.add(remarks);
											checkListDtoUpdate.setBankRemarks(bankRemarks);  
											
											List<String> bankRemarksHindi =  new ArrayList<String>();
											bankRemarksHindi.add("Compliance:");
											bankRemarksHindi.add(remarksHindi);
											checkListDtoUpdate.setBankRemarksHindi(bankRemarksHindi);  
											
											isProductDetailsAvail = true;
											isSectionDetailsAvail = true;
											isChapterDetailsAvail = true;									 
											  
										 }  
									}  
									 
									//get Scrutiny remarks								
									if(remarkScrutinyPartA!=null && remarkScrutinyPartA.size()>0 && remarkScrutinyPartA.get(findingCode)!=null){
										 String  remarks =  remarkScrutinyPartA.get(findingCode).split("#::#")[0];
										 String  remarksHindi =  remarkScrutinyPartA.get(findingCode).split("#::#")[1];
										 if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
												|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
											 
											 List<String> scrutinyRemarks =  new ArrayList<String>();
											 String[] scrutinyRemarkArr = remarks.split(":#@:");												  
											 if(scrutinyRemarkArr.length==2){											 
												 scrutinyRemarks.add("Scrutiny Status: "+scrutinyRemarkArr[0]);
												 scrutinyRemarks.add(scrutinyRemarkArr[1]); 
												 //scrutinyRemarks.remove(2);
											 }else{
												// scrutinyRemarks.add(0,  ""); 
												 scrutinyRemarks.add("Scrutiny Status: "+scrutinyRemarkArr[0]);
												 //scrutinyRemarks.remove(2);
											 }
											 checkListDtoUpdate.setScrutinyRemarks(scrutinyRemarks);
											 
											 List<String> scrutinyRemarksHindi =  new ArrayList<String>();
											 String[] scrutinyRemarkHindiArr = remarksHindi.split(":#@:");												  
											 if(scrutinyRemarkHindiArr.length==2){											 
												 scrutinyRemarksHindi.add("Scrutiny Status: "+scrutinyRemarkHindiArr[0]);
												 scrutinyRemarksHindi.add(scrutinyRemarkHindiArr[1]);
												 //scrutinyRemarks.remove(2);
											 }else{
												// scrutinyRemarks.add(0,  ""); 
												 scrutinyRemarksHindi.add("Scrutiny Status: "+scrutinyRemarkHindiArr[0]);
												 //scrutinyRemarks.remove(2);
											 }
											 checkListDtoUpdate.setScrutinyRemarksHindi(scrutinyRemarksHindi);
											  
											 isProductDetailsAvail = true;
											 isSectionDetailsAvail = true;
											 isChapterDetailsAvail = true;
										 }  
									} 	
								}else if(actionType.equalsIgnoreCase(BankAuditConstant.SR_CLOSURE)){  //Start from here to change the Scrutiny closure report
									checkListDtoUpdate = processObservationsClosureReport(remarkClosureAllPartA, remarkClosureAllAuthPartA, checkListDtoUpdate, findingCode, role, IsFinalizedReport);
									isProductDetailsAvail = true;
									isSectionDetailsAvail = true;
									isChapterDetailsAvail = true; 
								} 								
								listCheckListDtoUpdated.add(checkListDtoUpdate);											 									 
							 }									     
							 									  
							 processDtoUpdate.setCheckList(listCheckListDtoUpdated); 								 
							 listProcessDtoUpdated.add(processDtoUpdate);
							 processSeq++;
						}				
						productDtoUpdate.setProcessList(listProcessDtoUpdated);
						if(isProductDetailsAvail){
							listProductDtoUpdated.add(productDtoUpdate);
							productSeq++;
						} 						
					} 
					
					sectionDtoUpdate.setProductList(listProductDtoUpdated);						 
					if(isSectionDetailsAvail){
						listSectionDtoUpdated.add(sectionDtoUpdate);
						sectionSeq++;
					}
				}
				chapterDtoUpdated.setSectionList(listSectionDtoUpdated); 	
									 
				chapterDtoUpdated.setChapterDetailsAvail(isChapterDetailsAvail); 
				listChapterDtoUpdated.add(chapterDtoUpdated);				
				chapterSeq++;
			} 
			partDto.setChapterList(listChapterDtoUpdated);
		//}
			 
			listPart.add(partDto);
			isCompliedIndex++;
			chapterSeq  = 1;
		//}
		 
		//System.out.println("Time Taken ==>> "+(System.currentTimeMillis() -  startTime));
		return listPart;
		}catch (Exception e) {
			logger.error(e.getStackTrace());
			e.printStackTrace(System.out);
		}return null;
	} 
	
	private CheckListDto processObservationsClosureReport(Map<String,String> remarkClosureAllPartA, Map<String,String> remarkClosureAllAuthPartA, CheckListDto checkListDtoUpdate, 
			String findingCode, String role, Boolean IsFinalizedReport){		  									
			List<String> remarksList =  new ArrayList<String>();
			List<String> remarksHindiList =  new ArrayList<String>();																			
			List<String> rolesListCompliance = Arrays.asList(("G3,G31").split(","));	//Compliance or Response 
			List<String> rolesListScrutiny = Arrays.asList(("G4,G7").split(","));	//Scrutiny/review 
			int furtherComplianceCountScrutiny = 0;
			int furtherComplianceCountBank = 0;
			if(IsFinalizedReport){
				if(remarkClosureAllAuthPartA!=null && remarkClosureAllAuthPartA.size()>0 && remarkClosureAllAuthPartA.get(findingCode)!=null){
					String remarkClosurePartAList[] = remarkClosureAllAuthPartA.get(findingCode).split("#@::@#");
					for (String remarks : remarkClosurePartAList) {
						String  remark =   remarks.split("#::#")[0] ;
						String  remarkHindi =  remarks.split("#::#")[1] ;											
						String remarksByRole = remarks.split("#::#")[3];
						System.out.println(remarks.split("#::#")[0]);	 														
						if(rolesListCompliance.contains(remarksByRole.trim())){
							if(furtherComplianceCountBank==0){
								remark = "<br/><b>Compliance Remarks: </b><br/> "+remark;
								remarkHindi = "<br/><b>Compliance Remarks: </b><br/> "+remarkHindi;
							}
							else{
								remark = "<br/><b>Further Compliance Remarks "+furtherComplianceCountBank+": </b><br/> "+remark;
								remarkHindi = "<br/><b>Further Compliance Remarks: "+furtherComplianceCountBank+": </b><br/> "+remarkHindi;
							}
							furtherComplianceCountBank++;
						}else{
							furtherComplianceCountScrutiny++;
							String scrutinyStatus = remarks.split("#::#")[2]==null||remarks.split("#::#")[2].trim().equalsIgnoreCase("")||remarks.split("#::#")[2].trim().equalsIgnoreCase("Further Compliance")?"Further Compliance "+furtherComplianceCountScrutiny: remarks.split("#::#")[2] ;
							remark = "<br/><b>Scrutiny Status: "+scrutinyStatus+"</b><br/> "+remark;
							remarkHindi = "<br/><b>Scrutiny Status: "+scrutinyStatus+"</b><br/> "+remarkHindi;
						}
						remarksList.add(remark);
						remarksHindiList.add(remarkHindi);	  
					}
				} 
			}else{
				if(remarkClosureAllPartA!=null && remarkClosureAllPartA.size()>0 && remarkClosureAllPartA.get(findingCode)!=null){
					String remarkClosurePartAList[] = remarkClosureAllPartA.get(findingCode).split("#@::@#");
					for (String remarks : remarkClosurePartAList) {
						String remark =   null;
						String remarkHindi =  null;											
						String remarksByRole = remarks.split("#::#")[3];
						String status = remarks.split("#::#")[4].trim();												  												 
						if(rolesListCompliance.contains(remarksByRole.trim())){													
							if(rolesListScrutiny.contains(role.trim()) && BankAuditConstant.STATUS_AUTH.equalsIgnoreCase(status)){
								if(furtherComplianceCountBank==0){
									remark = "<br/><b>Compliance Remarks: </b><br/> "+remarks.split("#::#")[0];
									remarkHindi = "<br/><b>Compliance Remarks: </b><br/> "+remarks.split("#::#")[1];
									furtherComplianceCountBank++;
								}
								else{
									remark = "<br/><b>Further Compliance Remarks "+furtherComplianceCountBank+": </b><br/> "+remarks.split("#::#")[0];
									remarkHindi = "<br/><b>Further Compliance Remarks: "+furtherComplianceCountBank+": </b><br/> "+remarks.split("#::#")[1];															
								}														
							}else if(rolesListCompliance.contains(role.trim())){
								if(furtherComplianceCountBank==0){
									remark = "<br/><b>Compliance Remarks: </b><br/> "+remarks.split("#::#")[0];
									remarkHindi = "<br/><b>Compliance Remarks: </b><br/> "+remarks.split("#::#")[1];
									furtherComplianceCountBank++;
								}
								else{
									remark = "<br/><b>Further Compliance Remarks "+furtherComplianceCountBank+": </b><br/> "+remarks.split("#::#")[0];
									remarkHindi = "<br/><b>Further Compliance Remarks: "+furtherComplianceCountBank+": </b><br/> "+remarks.split("#::#")[1]; 
								}														
							}													
						}else{
							if(rolesListCompliance.contains(role.trim()) && BankAuditConstant.STATUS_AUTH.equalsIgnoreCase(status)){
								furtherComplianceCountScrutiny++;
								String scrutinyStatus = remarks.split("#::#")[2]==null||remarks.split("#::#")[2].trim().equalsIgnoreCase("")||remarks.split("#::#")[2].trim().equalsIgnoreCase("Further Compliance")?"Further Compliance "+furtherComplianceCountScrutiny: remarks.split("#::#")[2] ;
								remark = "<br/><b>Scrutiny Status: "+scrutinyStatus+"</b><br/> "+remarks.split("#::#")[0];
								remarkHindi = "<br/><b>Scrutiny Status: "+scrutinyStatus+"</b><br/> "+remarks.split("#::#")[1];
							}else if(rolesListScrutiny.contains(role.trim())){
								furtherComplianceCountScrutiny++;
								String scrutinyStatus = remarks.split("#::#")[2]==null||remarks.split("#::#")[2].trim().equalsIgnoreCase("")||remarks.split("#::#")[2].trim().equalsIgnoreCase("Further Compliance")?"Further Compliance "+furtherComplianceCountScrutiny: remarks.split("#::#")[2] ;
								remark = "<br/><b>Scrutiny Status: "+scrutinyStatus+"</b><br/> "+remarks.split("#::#")[0];
								remarkHindi = "<br/><b>Scrutiny Status: "+scrutinyStatus+"</b><br/> "+remarks.split("#::#")[1];
							}
						}
						remarksList.add(remark);
						remarksHindiList.add(remarkHindi);														 										  
					}
				}
			}
			checkListDtoUpdate.setBankRemarks(remarksList);  
			checkListDtoUpdate.setBankRemarksHindi(remarksHindiList);
			return checkListDtoUpdate;
	}
	 	
 	private List<AuditBookReportDataModel> generateAuditBookReport(Integer legalEntityCode, String auditId,  String auditTypeCode, String reportLanguage,
			String userId, String reportCode, Boolean finalizedReport,  String actionType, String role ){
		try{
		Map<String, Object>	properties = new HashMap<String, Object>();	
		properties.put("legalEntityCode", legalEntityCode);
		properties.put("auditTypeCode", auditTypeCode);
		//properties.put("planId", planId);
		properties.put("auditId", auditId);
		AuditSchedule auditSchedule = (AuditSchedule) auditScheduleDao.getUniqueEntityByMatchingProperties(AuditSchedule.class, properties);			
		
		Map<String, String> generalParameter =  new HashMap<>();
		String pageInfoStatus = "";
		
		List<PartDto> listPart = new ArrayList<PartDto>();
		if((auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_BRANCHI)
				|| auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_ITISI))
				&& 	reportCode.equalsIgnoreCase(BankAuditConstant.REPORT_CODE_IR)){
			listPart = processIRGlobal(legalEntityCode+"", auditId, auditTypeCode, reportLanguage, userId);
			generalParameter = generalParameterService.getGeneralParameterKeyValue(legalEntityCode, "", "", "STATUS", "REPORT_STATUS", "", "");
			pageInfoStatus = generalParameter.get(auditSchedule.getReportStatus());
		} else if(reportCode.equalsIgnoreCase(BankAuditConstant.REPORT_CODE_IR)){
			listPart = processIR(legalEntityCode+"", auditId, auditTypeCode, reportLanguage, userId);
			generalParameter = generalParameterService.getGeneralParameterKeyValue(legalEntityCode, "", "", "STATUS", "REPORT_STATUS", "", "");
			pageInfoStatus = generalParameter.get(auditSchedule.getReportStatus());
		}else if(reportCode.equalsIgnoreCase(BankAuditConstant.REPORT_CODE_CR)){
			listPart = processCR(legalEntityCode+"", auditId, auditTypeCode, reportLanguage, userId, actionType, role);
			generalParameter = generalParameterService.getGeneralParameterKeyValue(legalEntityCode, "", "", "STATUS", "AUDIT_STATUS", "", "");
			pageInfoStatus = generalParameter.get(auditSchedule.getRespondStatus());
		}else if(reportCode.equalsIgnoreCase(BankAuditConstant.REPORT_CODE_SR)){
			listPart = processSR(legalEntityCode+"", auditId, auditTypeCode, reportLanguage, userId, actionType, role, finalizedReport);
			generalParameter = generalParameterService.getGeneralParameterKeyValue(legalEntityCode, "", "", "STATUS", "AUDIT_STATUS", "", "");
			pageInfoStatus = generalParameter.get(auditSchedule.getReviewStatus());
		} 
		
		//Get All the parameter mapped values
		Map<String, String[]> parameterMapProfile =  auditBookReportDaoV3.getParameterVeluesForProfile(legalEntityCode, auditId, auditTypeCode);
		Map<String, String> parameterMap =  auditBookReportDaoV3.getProfileParameterMap(legalEntityCode, auditId, auditTypeCode);
		
		Object[] coverPageParameter =  auditBookReportDaoV3.getCoverPageDynamicData(legalEntityCode, auditId); 	
		CoverPageDto coverPageDto = new CoverPageDto();
		String financialYearStr = "";
		if(coverPageParameter!=null){ 
			String romanInspectionNumber ="";
			if(parameterMapProfile!=null && parameterMapProfile.size()>0){
				if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_RRB_CONTAINS)){
					romanInspectionNumber = (parameterMapProfile.get("STAINS")!=null && parameterMapProfile.get("STAINS").length==2)?parameterMapProfile.get("STAINS")[1]:"";
				}else if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_DCCB_CONTAIN)){
					romanInspectionNumber = (parameterMapProfile.get("BOMD1")!=null && parameterMapProfile.get("BOMD1").length==2)?parameterMapProfile.get("BOMD1")[1]:"";
				}else if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_StCB_CONTAIN)){
					romanInspectionNumber = (parameterMapProfile.get("BOMS1")!=null && parameterMapProfile.get("BOMS1").length==2)?parameterMapProfile.get("BOMS1")[1]:"";
				}else if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_SCARDB_CONTAIN)){
					romanInspectionNumber = (parameterMapProfile.get("BOMSC1")!=null && parameterMapProfile.get("BOMSC1").length==2)?parameterMapProfile.get("BOMSC1")[1]:"";
				}
			}
			
			Date financialYear = (Date) coverPageParameter[3];
			Date dateOfIssue = (Date) coverPageParameter[6];
			financialYearStr =financialYear==null ?"XX XXX XXXX": new SimpleDateFormat("dd MMMMM yyyy").format(financialYear);
			if(!financialYearStr.startsWith("XX")){
				parameterMap.put("financialYear", financialYearStr);				
				Integer dateNum = Integer.valueOf(financialYearStr.substring(0,2));
				financialYearStr = dateNum+"<sup>"+getSuperScript(dateNum)+"</sup>"+financialYearStr.substring(2);
			}
			String dateOfIssueStr =dateOfIssue==null ?"XX XXX XXXX": BankAuditUtil.parseDateToStringddMMMyyyy(dateOfIssue);
			String parentUnitState = coverPageParameter[7]+"";//Parent State Name
			String parentUnitName = coverPageParameter[9]+"";//Parent Unit Name
			String unitName = coverPageParameter[1]+"";//Unit Name
			String cityOrStateForHeader =  coverPageParameter[2]+"" ; //City Name
			
			String parentOfParentUnitName = coverPageParameter[10]+"";
			String parentOfParentUnitState = coverPageParameter[11]+"";
			
			
			if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_DCCB_CONTAIN)){  
				cityOrStateForHeader = coverPageParameter[8]+"" ; //State name
			}
			
			if(reportCode.equalsIgnoreCase(BankAuditConstant.REPORT_CODE_CR) 
					&& !auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_ITISI)){	
				if(!BankAuditUtil.isEmptyString(actionType) && BankAuditConstant.CR_CLOSURE.equalsIgnoreCase(actionType)){
					coverPageDto.setHeader(" Closure Report of"+" <br>" +
							romanInspectionNumber						
							+ " Statutory Inspection of"+" <br>"  
							+ coverPageParameter[1] +", "+ cityOrStateForHeader +" <br>"
							+ " With reference to its financial position as on"+" <br>"
							+ financialYearStr); 
				}else{
					coverPageDto.setHeader(" Compliance to"+" <br>" +
						romanInspectionNumber						
						+ " Statutory Inspection of"+" <br>"  
						+ coverPageParameter[1] +", "+ cityOrStateForHeader +" <br>"
						+ " With reference to its financial position as on"+" <br>"
						+ financialYearStr); 	
				}
			}else{ 				
				coverPageDto.setSubHeaderA("With reference to its financial position as on"); 
				coverPageDto.setSubHeaderB(financialYearStr); //Financial Year 
				
				coverPageDto.setIssuedByA("National Bank for Agriculture and Rural Development");
				coverPageDto.setIssueDate("Date of issue: "+dateOfIssueStr);
				
				if(auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_BRANCHI)){
					coverPageDto.setHeader(unitName +" Inspection"); 	
					parameterMap.put("bankName", parentUnitName);
					parameterMap.put("branchName", unitName);
					parameterMap.put("financialYear", financialYearStr);
					
					coverPageDto.setIssuedByB(parentOfParentUnitName+" Regional Office");
					coverPageDto.setIssuedByC(parentOfParentUnitState+"");//Parent of Parent state Name  					
				}else if(auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_ITISI)){					 
					properties.put("userType", "L");
					AuditTeam  auditTeam = (AuditTeam) auditScheduleDao.getUniqueEntityByMatchingProperties(AuditTeam.class, properties);	 
					User user = userService.getUserByLegalEntityCodeAndUserId(legalEntityCode, auditTeam.getUserId());										
					String unitType = user.getUnitCode().equalsIgnoreCase("HO")?"HO":"RO"; 
					 
					coverPageDto.setAuditDetailsInfo(unitType.equalsIgnoreCase("HO")?"CSITE, DoS, HO":("DoS, "+parentUnitName+" RO "));					
					Integer inspNumber = coverPageParameter[0]!=null?Integer.parseInt(coverPageParameter[0].toString()):0;					
					coverPageDto.setHeader(inspNumber+"<sup>"+getSuperScript(inspNumber)+"</sup>  IT/IS Examination Report of "+unitName);
					coverPageDto.setIssuedByA("National Bank for Agriculture and Rural Development <br/>Department of Supervision <br/><br/>");
					coverPageDto.setIssuedByB((unitType.equalsIgnoreCase("")?"":(unitType.equalsIgnoreCase("RO")?(parentUnitName +" Regional Office"):("CSITE, Head Office, Mumbai"))));
					coverPageDto.setActualStartDate((Date)coverPageParameter[14]==null ?"XX XX XXXX": BankAuditUtil.parseDateToString((Date)coverPageParameter[14], "dd-MM-yyyy"));
					coverPageDto.setActualEndDate((Date)coverPageParameter[15]==null ?"XX XX XXXX": BankAuditUtil.parseDateToString((Date)coverPageParameter[15], "dd-MM-yyyy"));
				}else{
					coverPageDto.setHeader(romanInspectionNumber+" Statutory Inspection of <br>"
							+ coverPageParameter[1] +", "
							+ cityOrStateForHeader );
					 
					coverPageDto.setIssuedByB(parentUnitName+" Regional Office");
					coverPageDto.setIssuedByC(coverPageParameter[5]+"");//Parent City Name					
				} 			 				
			}
		}else{
			coverPageDto.setHeader(" Statutory Inspection of <br>"+	 ", ") ;
			coverPageDto.setSubHeaderA("With reference to its financial position as on"); 
			coverPageDto.setSubHeaderB(""); //Financial Year 
			
			//coverPageDto.setIssuedByA("National Bank for Agriculture and Rural Development");
			coverPageDto.setIssuedByA("National Bank for Agriculture and Rural Development");
			coverPageDto.setIssuedByB("Regional Office");
			coverPageDto.setIssuedByC("");
			coverPageDto.setIssueDate("Date of issue: "); 
			//coverPageDto.setIssueDate("Date of issue: "); 
		}
		
		coverPageDto.setUserId(userId);	
		//coverPageDto.setPageInfo(new SimpleDateFormat("ddMMyyyyHHmm").format(new Date()));
		if(!finalizedReport){
			coverPageDto.setPageInfo(new SimpleDateFormat("ddMMyyyy-HHmm").format(new Date())+"-"+userId);	
			coverPageDto.setPageInfoAlign("L");
		}else{ 			
			coverPageDto.setPageInfo(new SimpleDateFormat("ddMMyyyy").format(new Date())+"-"+userId+"-"+pageInfoStatus);
			coverPageDto.setPageInfoAlign("R");
		}
		
		List<CoverPageDto> listCoverPage = new ArrayList<>();
		listCoverPage.add(coverPageDto);		

		ChapterDto introduction = new ChapterDto();
		if(BankAuditConstant.REPORT_LANGUAGE_EN.equalsIgnoreCase(reportLanguage)){		
			introduction.setChapterName("Introduction");
			if(auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_ITISI)){				
				introduction.setStatements(auditBookReportDaoV3.getAuditReportDynamicTable(legalEntityCode, auditId, auditTypeCode,
						"", null, null, null, null, BankAuditConstant.FOR_CHAPTER , BankAuditConstant.FOR_PREDEFINED_OR_EXTERNAL_INPUT_OR_REMARK, "1ITISIER"));
			}else{ 
				introduction.setStatements(auditBookReportDaoV3.getDerivedAndStaticStatementForIntroduction(legalEntityCode, auditId, auditTypeCode));
			}		
		}else{
			Map<String, String> derivedStaticStatementData = auditBookReportDaoV3.getDerivedAndStaticStatementForIntroduction(legalEntityCode+"", auditId, auditTypeCode);
			
			Optional<String> chapterNameKey = derivedStaticStatementData.keySet().stream().findFirst();
			String chapterName[] = null ;
			if (chapterNameKey.isPresent()) {
				chapterName = chapterNameKey.get().split("#::#");
				introduction.setChapterName(chapterName[0]);
				introduction.setChapterNameHindi(chapterName.length==2?chapterName[1]:"");
			}
			String derivedStaticStmtStringList = derivedStaticStatementData.get(chapterName);
			
			String[] derivedStaticStmt = derivedStaticStmtStringList!=null?derivedStaticStmtStringList.split("#@::@#"):null;
			List<String> derivedStaticStmtList = sortedDerivedStaticStmt(derivedStaticStmt);
			List<String> derivedStaticStmtListHindi = sortedDerivedStaticStmtHindi(derivedStaticStmt);
			
			introduction.setStatements(derivedStaticStmtList);
			introduction.setStatementsHindi(derivedStaticStmtListHindi); 
		}
		
		List<ChapterDto> listIntroduction = new ArrayList<>();
		introduction.setParameterMap(parameterMap);	
		listIntroduction.add(introduction);
		
		List<Profile> profileList =  null;
		if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_RRB_CONTAINS)){
			profileList = getProfileDetails(legalEntityCode, auditId, auditTypeCode, parameterMapProfile);
		}
		else{			  
			profileList = new ArrayList<Profile>();
			Profile profile = new Profile(); 
			profile.setProfileParameterMap(parameterMap);
			profileList.add(profile);
		} 				
			
		AuditBookReportDataModel auditBookReportDataModel = new  AuditBookReportDataModel();		 
		auditBookReportDataModel.setCoverPageList(listCoverPage);	
		auditBookReportDataModel.setIntroduction(listIntroduction);
		auditBookReportDataModel.setProfileList(profileList); 
		auditBookReportDataModel.setPartList(listPart);   
		
		List<AuditBookReportDataModel> listAuditBookReportDataModel= new ArrayList<AuditBookReportDataModel>();
		listAuditBookReportDataModel.add(auditBookReportDataModel);
	
		 return listAuditBookReportDataModel;
		}catch (Exception e) {
			logger.error(e.getStackTrace());
			e.printStackTrace(System.out);
		}return null;
	}
	
	//Generate IR
	@Override
	public String generatePDFReport(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String userId, Boolean isFinalReport,
			String planId,  String unitId, String reportCode, String reportLanguage ){
		try{
		logger.info("generatePDFReport() called...IR");
		 
		String[] reportPath = getReportPathByReportLanguage(reportLanguage, auditTypeCode).split("##"); 		
		String jasperReportName = reportPath[0];
		String jasperReportPath = reportPath[1];
		String jasperSubReportPath = reportPath[2];
		 
		List<AuditBookReportDataModel> jasperReportBeanDataSourceList = generateAuditBookReport(legalEntityCode,   auditId, auditTypeCode, reportLanguage,
											userId, BankAuditConstant.REPORT_CODE_IR, isFinalReport, "", "role");
		 
		InputStream stream = this.getClass().getResourceAsStream(jasperReportPath + jasperReportName);
		 
		JasperReport jasperReport = null;

		//try  {			
					
			jasperReport = JasperCompileManager.compileReport(stream);
			params.put("SUB_REPORT_DIR", jasperSubReportPath); 	
			params.put("REPORT_CODE", BankAuditConstant.REPORT_CODE_IR); 
			params.put("isAbridgedReport", "N");
			params.put("hasProfile", true);
			params.put("auditTypeCode", auditTypeCode);
			params.put("OTHERS_CH_SC_PD_PC_CK", "");
			params.put("hasIndex", true);		
			params.put("PRINT_PRODUCT", true);		
			if(isFinalReport){
				params.put("pageInfoAlign", "R");
			}else{
				params.put("pageInfoAlign", "L");
			}
			if(BankAuditConstant.INSPECTION_TYPE_BRANCHI.equalsIgnoreCase(auditTypeCode)){ 				
				 params.put("OTHERS_CH_SC_PD_PC_CK", BankAuditConstant.OTHERS_CH_SC_PD_PC_CK);
				 params.put("hasIndex", false);				 
			}else if(BankAuditConstant.INSPECTION_TYPE_ITISI.equalsIgnoreCase(auditTypeCode)){
				params.put("PRINT_PRODUCT", false);	
				params.put("hasIndex", false);	
			}
			
			JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(jasperReportBeanDataSourceList);
			JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource);			 
			
			//String uploadFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_InspectionReportPartAB"+".pdf";
			String uploadFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_AssessmentInspectionReportPartAB"+".pdf";
			String partABFile = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +uploadFileName;
			 			 
			JasperExportManager.exportReportToPdfFile(print,partABFile);				 
			
			String partCFile = generatePDFReportPartC(params, legalEntityCode, auditId, auditTypeCode, jasperSubReportPath, BankAuditConstant.REPORT_TYPE_PART_C_DETAILED); 
			String partCHeader = generatePartCHeader(params, legalEntityCode, auditId, auditTypeCode, userId, jasperSubReportPath, "Part C");
			String backCoverFile = generateBackCoverPage(params, legalEntityCode, auditId, auditTypeCode, userId, jasperReportPath);			
			
			String uploadPath = mergeAll(legalEntityCode, auditId, auditTypeCode, partABFile, partCFile, backCoverFile, partCHeader, isFinalReport, "_Assessment");

			if(isFinalReport){
				//String fileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_InspectionReport"+".pdf";
				String fileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_InspectionReport_Assessment"+".pdf";
				saveAuditReports(legalEntityCode,  auditTypeCode, auditId, planId, reportCode, uploadPath, fileName, unitId, userId);
				
				//Start Generating the Abridged IR - Actual IR - available to bank user			
				PartDto partDto = jasperReportBeanDataSourceList.get(0).getPartList().get(0);
				partDto.setPartName("Part I");				
				List<PartDto> partDtoList= new ArrayList<>();
				partDtoList.add(partDto);				
				AuditBookReportDataModel  auditBookReportDataModel = jasperReportBeanDataSourceList.get(0);
				auditBookReportDataModel.setPartList(partDtoList);
				List<AuditBookReportDataModel> jasperReportBeanDataSourceListPartA = new ArrayList<>();
				jasperReportBeanDataSourceListPartA.add(auditBookReportDataModel);				
				params.put("isAbridgedReport", "Y"); 
				
				return generatePDFReportIRAbridged(params, jasperReport, legalEntityCode, auditTypeCode, auditId, planId, reportCode, userId, unitId,  
						reportPath, jasperReportBeanDataSourceListPartA);					
			}
			
			
			System.out.println("uploadPath .. "+ uploadPath);
			return uploadPath;				 	
			 
		} catch (JRException  e) {
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@Override
	public String generatePDFReportCR(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String userId, Boolean isFinalReport, 
			String planId,  String unitId, String reportCode, String reportLanguage, String actionType, String role){
		try{
		logger.info("generatePDFReportCR() called...");
		 
		String[] reportPath = getReportPathByReportLanguage(reportLanguage, auditTypeCode).split("##"); 		
		String jasperReportName = reportPath[0];
		String jasperReportPath = reportPath[1];
		String jasperSubReportPath = reportPath[2];
	 		
		List<AuditBookReportDataModel> jasperReportBeanDataSourceList =generateAuditBookReport(legalEntityCode, auditId, auditTypeCode, reportLanguage, 
										userId, BankAuditConstant.REPORT_CODE_CR, isFinalReport, actionType, role);		 
		InputStream stream = this.getClass().getResourceAsStream(jasperReportPath + jasperReportName);		 
		JasperReport jasperReport = null;

		//try  {				
			jasperReport = JasperCompileManager.compileReport(stream);
			params.put("SUB_REPORT_DIR", jasperSubReportPath); 	
			params.put("REPORT_CODE", BankAuditConstant.REPORT_CODE_CR); 
			params.put("isAbridgedReport", "N");
			params.put("hasProfile", true);
			params.put("auditTypeCode", auditTypeCode);
			params.put("OTHERS_CH_SC_PD_PC_CK", "");
			params.put("hasIndex", true);		
			params.put("PRINT_PRODUCT", true);				
			if(isFinalReport){
				params.put("pageInfoAlign", "R");
			}else{
				params.put("pageInfoAlign", "L");
			}			
			
			if(BankAuditConstant.INSPECTION_TYPE_ITISI.equalsIgnoreCase(auditTypeCode)){
				params.put("PRINT_PRODUCT", false);	
				params.put("hasIndex", false);	
			}
		 		 
			JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(jasperReportBeanDataSourceList);
			JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource);			 
			
			String uploadFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_"+actionType+"_ComplianceReportTmp"+".pdf";    		 
			String uploadPathTmp = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +uploadFileName;
			 			 
			JasperExportManager.exportReportToPdfFile(print, uploadPathTmp);		 	 
			
			//Add Page number to generated report	
			String CR_FilePathFinal =legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_"+actionType+"_ComplianceReport"+".pdf";
			
			if(isFinalReport){
				CR_FilePathFinal = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_REPORTS)+ "/"+CR_FilePathFinal ;
			}else{
				CR_FilePathFinal = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/"+CR_FilePathFinal ;
			}
		
		 		 			
			PdfReader reader = new PdfReader(uploadPathTmp);
			int pageCount = (reader.getNumberOfPages());
			PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(CR_FilePathFinal));
			int pageNumber = 0;
			PdfContentByte over ;
			BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
			while (pageNumber < pageCount) {
				pageNumber++;
				if (pageNumber > 1 ) {
					over = stamp.getOverContent(pageNumber);
					over.beginText();
					over.setFontAndSize(bf, 10);
					//over.setTextMatrix(465, 70);
			//over.showText(String.format("page %s of %s", pageNumber-1, pageCount-1));
			over.showTextAligned(PdfContentByte.ALIGN_LEFT, String.format("page %s of %s", pageNumber-1, pageCount-1), 72, 55, 0); 
					over.endText(); 
				}
			}
			stamp.close();					
			try{ 	
				 File IR_fileToDelete = new File(uploadPathTmp)  ;
				 IR_fileToDelete.delete();
			}catch (Exception e) {  }
			
			if(isFinalReport){
				String fileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_ComplianceReport"+".pdf";
				return saveAuditReports(legalEntityCode, auditTypeCode, auditId, planId, reportCode, CR_FilePathFinal, fileName, unitId, userId);
			}
		
		System.out.println("uploadPath .. "+ CR_FilePathFinal);
		return CR_FilePathFinal;				 	
		 
		} catch (JRException  e) {
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	private String generatePDFReportIRAbridged(Map<String, Object> params, JasperReport jasperReport, Integer legalEntityCode, 
			 String auditTypeCode, String auditId, String planId, String reportCode, String userId, String unitId,
			 String[] reportPath, List<AuditBookReportDataModel> jasperReportBeanDataSourceListPartA) throws Exception{
		
		logger.info("generatePDFReportIRAbridged() called...IR");
		
		//String jasperReportName = reportPath[0];
		String jasperReportPath = reportPath[1];
		String jasperSubReportPath = reportPath[2];
		params.put("SUB_REPORT_DIR", jasperSubReportPath); 	
		JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(jasperReportBeanDataSourceListPartA);
		JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource);			 
		
		String uploadFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_InspectionReportAbridgedPartAB"+".pdf";    		 
		String partABFile = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +uploadFileName;
		 			 
		JasperExportManager.exportReportToPdfFile(print,partABFile);				 
		 
		
		String partCFile = generatePDFReportPartC(params, legalEntityCode, auditId, auditTypeCode, jasperSubReportPath, BankAuditConstant.REPORT_TYPE_PART_C_ABRIDGED); 
		String partCHeader = generatePartCHeader(params, legalEntityCode, auditId, auditTypeCode, userId, jasperSubReportPath, "Part II");
		String backCoverFile = generateBackCoverPage(params, legalEntityCode, auditId, auditTypeCode, userId, jasperReportPath);			
		
		String uploadPath = mergeAll(legalEntityCode, auditId, auditTypeCode, partABFile, partCFile, backCoverFile, partCHeader, true, "_Abridged");
		 
		String fileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_InspectionReport_Abridged"+".pdf";
		return saveAuditReports(legalEntityCode,  auditTypeCode, auditId, planId, reportCode+"_ABRIDGED", uploadPath, fileName, unitId, userId);
	}
		
	@Override
	public String generatePDFReportSR(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String userId, Boolean isFinalReport, 
			String planId,  String unitId, String reportCode, String reportLanguage, String actionType, String role ){
		try{
		logger.info("generatePDFReportSR() called...");
		 
		String[] reportPath = getReportPathByReportLanguage(reportLanguage, auditTypeCode).split("##"); 		
		String jasperReportName = reportPath[0];
		String jasperReportPath = reportPath[1];
		String jasperSubReportPath = reportPath[2];
		
		List<AuditBookReportDataModel> jasperReportBeanDataSourceList =generateAuditBookReport(legalEntityCode,  auditId, auditTypeCode, reportLanguage, 
															userId, BankAuditConstant.REPORT_CODE_SR, isFinalReport, actionType, role);		 
		InputStream stream = this.getClass().getResourceAsStream(jasperReportPath + jasperReportName);		 
		JasperReport jasperReport = null;
		//try{				
			jasperReport = JasperCompileManager.compileReport(stream);
			params.put("SUB_REPORT_DIR", jasperSubReportPath); 	
			params.put("REPORT_CODE", BankAuditConstant.REPORT_CODE_SR);
			params.put("isAbridgedReport", "N");
			params.put("hasProfile", true);
			params.put("auditTypeCode", auditTypeCode);
			params.put("OTHERS_CH_SC_PD_PC_CK", "");
			params.put("hasIndex", true);		
			params.put("PRINT_PRODUCT", true);	
			if(isFinalReport){
				params.put("pageInfoAlign", "R");
			}else{
				params.put("pageInfoAlign", "L");
			}
			
			if(BankAuditConstant.INSPECTION_TYPE_ITISI.equalsIgnoreCase(auditTypeCode)){
				params.put("PRINT_PRODUCT", false);	
				params.put("hasIndex", false);	
			}
			 		 
			JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(jasperReportBeanDataSourceList);
			JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource);			 
			
			String uploadFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_"+actionType+"_ReportTmp"+".pdf";    		 
			String uploadPathTmp = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +uploadFileName;
			 			 
			JasperExportManager.exportReportToPdfFile(print, uploadPathTmp);	 
						
			//Add Page number to generated report	
			String SR_FilePathFinal =legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_"+actionType+"_Report"+".pdf";
			if(isFinalReport){
				SR_FilePathFinal = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_REPORTS)+ "/"+SR_FilePathFinal ;
			}else{
				SR_FilePathFinal = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/"+SR_FilePathFinal ;
			}
			 		 			
			PdfReader reader = new PdfReader(uploadPathTmp);
			int pageCount = (reader.getNumberOfPages());
			PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(SR_FilePathFinal));
			int pageNumber = 0;
			PdfContentByte over ;
			BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
			while (pageNumber < pageCount) {
				pageNumber++;
				if (pageNumber > 1 ) {
					over = stamp.getOverContent(pageNumber);
					over.beginText();
					over.setFontAndSize(bf, 10);
					//over.setTextMatrix(465, 70);
					//over.showText(String.format("page %s of %s", pageNumber-1, pageCount-1));
					over.showTextAligned(PdfContentByte.ALIGN_LEFT, String.format("page %s of %s", pageNumber-1, pageCount-1), 72, 55, 0);
					over.endText(); 
				}
			}
			stamp.close();					
			try{ 	
				 File IR_fileToDelete = new File(uploadPathTmp)  ;
				 IR_fileToDelete.delete();
			}catch (Exception e) {  } 
			 
			System.out.println("uploadPath .. "+ SR_FilePathFinal);
			
			if(isFinalReport){
				String fileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_ScrutinyReport"+".pdf";
				if(actionType.equalsIgnoreCase(BankAuditConstant.SR_CLOSURE)){
					reportCode = actionType;
					fileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+actionType+"_ClosureReport"+".pdf";
				}				
				return saveAuditReports(legalEntityCode, auditTypeCode, auditId, planId, reportCode, SR_FilePathFinal, fileName, unitId, userId);
			}
			
			return SR_FilePathFinal;				 	
			 
		} catch (JRException  e) {
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	 
	
	@Override
	public String storeReportDataIntoReportTable(Integer legalEntityCode, String auditId, String auditTypeCode, String reportLanguage) throws Exception{		
		 	
		//try{
			Integer sequenceNumber = 1; 
			String staticDerivedStmt =null;
			String staticDerivedStmtHindi= null;
			//Delete Existing before initiate 					
			auditBookReportDaoV3.deleteExistingBeforeInitiate(legalEntityCode, auditId, auditTypeCode);			 
			auditBookReportDaoV3.getIRSession();			
			
			/*****Store Introduction Chapter Details Start*****/
			ChapterDto chapterIntroduction = auditBookReportDaoV3.getIntroductionChapterForReportTable(legalEntityCode, auditId, auditTypeCode);
			if(chapterIntroduction!=null && !BankAuditUtil.isEmptyString(chapterIntroduction.getAuditGroupCode())){
				String auditGroupCodeIntroduction = chapterIntroduction.getAuditGroupCode();
				String reportQueryIntro= "Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, "
						+ "audit_group_code, audit_group_name, applicable_for, audit_group_name_hindi ) "
						+ " values( '"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', "
										+ " '"+auditGroupCodeIntroduction+"', '"+chapterIntroduction.getChapterName()+"' ,"
										+ "  '"+BankAuditConstant.FOR_CHAPTER+"', '"+chapterIntroduction.getChapterNameHindi()+"' )";
				auditBookReportDaoV3.insertIntoReportTable(reportQueryIntro);
				sequenceNumber ++;
				
				List<StaticDerivedStatementDTO> listStatementForChapter= auditBookReportDaoV3.getDerivedAndStaticStatementForChapterForReportTable(legalEntityCode, auditId,  auditTypeCode, auditGroupCodeIntroduction);
				if(listStatementForChapter.size()>0){
					StaticDerivedStatementDTO statement =listStatementForChapter.get(0);
					staticDerivedStmt =  "	"+(statement.getStatement().replace("'", "''")); //Add tab for first line
					staticDerivedStmtHindi = "	"+(statement.getStatementHindi()==null?null:statement.getStatementHindi().replace("'", "''")); //Add tab for first line 					
					if(!BankAuditUtil.isEmptyString(staticDerivedStmt)){
						reportQueryIntro="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
								+ " audit_group_name, audit_group_name_hindi, "
								+ " statement_type, statement , applicable_for, "
								+ " statement_id, statement_hindi) "
								+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCodeIntroduction+"', "
										+ " '"+chapterIntroduction.getChapterName()+"', '"+chapterIntroduction.getChapterNameHindi()+"', "
										+ "  '"+statement.getStatementType()+"', '"+staticDerivedStmt+"','"+BankAuditConstant.FOR_CHAPTER+"', "
										+ " '"+statement.getStatementId()+"', '"+staticDerivedStmtHindi+"'  )";
						auditBookReportDaoV3.insertIntoReportTable(reportQueryIntro);
						sequenceNumber ++;
					}
					listStatementForChapter.remove(0);
				}
				for (StaticDerivedStatementDTO statement : listStatementForChapter) {
					staticDerivedStmt = statement.getStatement().replace("'", "''");
					staticDerivedStmtHindi = statement.getStatementHindi()==null?null:statement.getStatementHindi().replace("'", "''");
					if(!BankAuditUtil.isEmptyString(staticDerivedStmt)){
						reportQueryIntro="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
								+ " audit_group_name, audit_group_name_hindi, statement_type, "
								+ " statement , applicable_for, "
								+ " statement_id, statement_hindi) "
								+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCodeIntroduction+"',"
										+ " '"+chapterIntroduction.getChapterName()+"', '"+chapterIntroduction.getChapterNameHindi()+"',  "
										+ "  '"+statement.getStatementType()+"', '"+staticDerivedStmt+"','"+BankAuditConstant.FOR_CHAPTER+"', "
										+ " '"+statement.getStatementId()+"', '"+staticDerivedStmtHindi+"')";
						auditBookReportDaoV3.insertIntoReportTable(reportQueryIntro);
						sequenceNumber ++;
					}
				}	
			} 			
			/*****Store Introduction Chapter Details End*****/	
			
			/***** START Get All the Chapter for tables, derives/static stmt and IO remark Start, which does not have checklist *****/	
			List<CheckListDto> grpSubGrpActProcForReportTableList = auditBookReportDaoV3.getAllGrpSubGrpActProcForReportTable(legalEntityCode, auditTypeCode);
			Map<String,String>  grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap = auditBookReportDaoV3.getAllGrpSubGrpActProcForReportTableForStatementTablesAndIOInput(legalEntityCode, auditTypeCode);
 
			StringBuilder strQueryGrpSubGrpActProcForTablesAndIOInputStmt = new StringBuilder("Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
					+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
					+ " statement_type, statement, applicable_for , statement_id , maint_report_sequence  )   values ");
 		
			List<CheckListDto> chapterDataList = grpSubGrpActProcForReportTableList.stream()
					.filter(a-> a.getApplicableFor().equalsIgnoreCase(BankAuditConstant.FOR_CHAPTER) 
							&& (chapterIntroduction==null?true:!a.getAuditGroupCode().equalsIgnoreCase(chapterIntroduction.getAuditGroupCode())))
					.collect(Collectors.toList());			
			List<CheckListDto> sectionDataList  = grpSubGrpActProcForReportTableList.stream()
					.filter(a-> a.getApplicableFor().equalsIgnoreCase(BankAuditConstant.FOR_SECTION)).collect(Collectors.toList());
			List<CheckListDto> productDataList  = grpSubGrpActProcForReportTableList.stream()
					.filter(a-> a.getApplicableFor().equalsIgnoreCase(BankAuditConstant.FOR_PRODUCT)).collect(Collectors.toList());
			List<CheckListDto> processDataList = grpSubGrpActProcForReportTableList.stream()
					.filter(a-> a.getApplicableFor().equalsIgnoreCase(BankAuditConstant.FOR_PROCESS)).collect(Collectors.toList());
		
			int chapterStatementsTablesAndIOInputIndex = 1;
			int sectionStatementsTablesAndIOInputIndex = 1;
			int productStatementsTablesAndIOInputIndex = 1;
			int processStatementsTablesAndIOInputIndex = 1;
			Boolean isGrpSubGrpActProcForTablesAndIOInputStmt = false;
			for (CheckListDto checkListDtoChapter : chapterDataList) {		 
				isGrpSubGrpActProcForTablesAndIOInputStmt = true;
				String chapterCode = checkListDtoChapter.getAuditGroupCode();
				String chapterName = checkListDtoChapter.getAuditGroupName();
				String[] statementChapter = grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode)!=null?
						grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode).split("#@::@#"):new String[]{};
				
				strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
						+ " '"+chapterName+"','','','','','','',"
						+ " '', '', '"+BankAuditConstant.FOR_CHAPTER+"', '',"+(chapterStatementsTablesAndIOInputIndex++)+" ),");	
				sequenceNumber ++;
				
				for (String statement : statementChapter) {
					String[] statementArr = statement.split("#:@@:#");
					if(statementArr.length>3){
						strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
								+ " '"+chapterName+"','','','','','','',"
								+ " '"+statementArr[2]+"', '"+statementArr[3]+"', '"+BankAuditConstant.FOR_CHAPTER+"', '"+statementArr[0]+"','"+statementArr[1]+"'),");	
						sequenceNumber ++;
					}
				}
				for (CheckListDto checkListDtoSection : sectionDataList) {
					if(checkListDtoSection.getAuditGroupCode().equalsIgnoreCase(chapterCode)){
						String sectionCode = checkListDtoSection.getAuditSubGroupCode();
						String sectionName = checkListDtoSection.getAuditSubGroupName();
						String[] statementSection = grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode+sectionCode)!=null?
								grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode+sectionCode).split("#@::@#"):new String[]{};
						
						strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
								+ " '"+chapterName+"','"+sectionCode+"','"+sectionName+"','','','','',"
								+ " '', '', '"+BankAuditConstant.FOR_SECTION+"', '', "+(sectionStatementsTablesAndIOInputIndex++)+" ),");	
						sequenceNumber ++;
						for (String statement : statementSection) {
							String[] statementArr = statement.split("#:@@:#");
							strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
									+ " '"+chapterName+"','"+sectionCode+"','"+sectionName+"','','','','',"
									+ " '"+statementArr[2]+"', '"+statementArr[3]+"', '"+BankAuditConstant.FOR_SECTION+"', '"+statementArr[0]+"','"+statementArr[1]+"'),");	
							sequenceNumber ++;
						}	
						
						for (CheckListDto checkListDtoProduct : productDataList) {
							if(checkListDtoProduct.getAuditSubGroupCode().equalsIgnoreCase(sectionCode)){
								String productCode = checkListDtoProduct.getActivityCode();
								String productName = checkListDtoProduct.getActivityName();
								String[] statementProduct = grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode+sectionCode+productCode)!=null?
										grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode+sectionCode+productCode).split("#@::@#"):new String[]{};
								
								strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
										+ " '"+chapterName+"','"+sectionCode+"','"+sectionName+"','"+productCode+"','"+productName+"','','',"
										+ " '', '', '"+BankAuditConstant.FOR_PRODUCT+"', '', "+(productStatementsTablesAndIOInputIndex++)+"),");	
								sequenceNumber ++;
								for (String statement : statementProduct) {
									String[] statementArr = statement.split("#:@@:#");
									strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
											+ " '"+chapterName+"','"+sectionCode+"','"+sectionName+"','"+productCode+"','"+productName+"','','',"
											+ " '"+statementArr[2]+"', '"+statementArr[3]+"', '"+BankAuditConstant.FOR_PRODUCT+"', '"+statementArr[0]+"','"+statementArr[1]+"'),");	
									sequenceNumber ++;
								}
								
								for (CheckListDto checkListDtoProcss : processDataList) {
									String prpcessCode = checkListDtoProcss.getProcessCode();
									String prpcessName = checkListDtoProcss.getProcessName();
									String[] statementProcess = grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode+sectionCode+productCode+prpcessCode)!=null?
											grpSubGrpActProcForReportTableForStatementTablesAndIOInputMap.get(chapterCode+sectionCode+productCode+prpcessCode).split("#@::@#"):new String[]{};
									
									strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
											+ " '"+chapterName+"','"+sectionCode+"','"+sectionName+"','"+productCode+"','"+productName+"','"+prpcessCode+"','"+prpcessName+"',"
											+ " '', '', '"+BankAuditConstant.FOR_PROCESS+"', '',"+(processStatementsTablesAndIOInputIndex++)+"),");	
									sequenceNumber ++;
									for (String statement : statementProcess) {
										String[] statementArr = statement.split("#:@@:#");
										strQueryGrpSubGrpActProcForTablesAndIOInputStmt.append("('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+chapterCode+"',"
												+ " '"+chapterName+"','"+sectionCode+"','"+sectionName+"','"+productCode+"','"+productName+"','"+prpcessCode+"','"+prpcessName+"',"
												+ " '"+statementArr[2]+"', '"+statementArr[3]+"', '"+BankAuditConstant.FOR_PROCESS+"', '"+statementArr[0]+"','"+statementArr[1]+"'),");	
										sequenceNumber ++;
									}
								}
							}
						}
					}
				}				
			}
			String queryGrpSubGrpActProcForTablesAndIOInputStmt  = strQueryGrpSubGrpActProcForTablesAndIOInputStmt.toString().trim();
			if(isGrpSubGrpActProcForTablesAndIOInputStmt){
				auditBookReportDaoV3.insertIntoReportTable(queryGrpSubGrpActProcForTablesAndIOInputStmt.substring(0,queryGrpSubGrpActProcForTablesAndIOInputStmt.length()-1)+";");
			}			
			/***** END Get All the Chapter for tables, derives/static stmt and IO remark Start, which does not have checklist *****/	
					
			//Get All the Chapter
			List<ChapterDto> listChapterDto = auditBookReportDaoV3.getChapterForReportTable(legalEntityCode, auditId, auditTypeCode);
			for (ChapterDto chapterDto : listChapterDto) {
				
				String auditGroupCode = chapterDto.getAuditGroupCode(); 
				String chapterName = chapterDto.getChapterName().replace("'", "''");
				String chapterNameHindi = chapterDto.getChapterNameHindi()==null?null:chapterDto.getChapterNameHindi().replace("'", "''");
				String reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, audit_group_name,"
						+ " applicable_for, audit_group_name_hindi ) "
						+ " values( '"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"', "
								+ " '"+BankAuditConstant.FOR_CHAPTER+"', '"+chapterNameHindi+"')";
				auditBookReportDaoV3.insertIntoReportTable(reportQuery);
				sequenceNumber ++;
				
				List<StaticDerivedStatementDTO> listStatementForChapter= auditBookReportDaoV3.getDerivedAndStaticStatementForChapterForReportTable(legalEntityCode, auditId,  auditTypeCode, auditGroupCode);
				for (StaticDerivedStatementDTO statement : listStatementForChapter) {
					staticDerivedStmt = statement.getStatement().replace("'", "''");
					staticDerivedStmtHindi = statement.getStatementHindi()==null?null:statement.getStatementHindi().replace("'", "''");
					if(!BankAuditUtil.isEmptyString(staticDerivedStmt)){
						reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
								+ " audit_group_name, statement_type, statement , applicable_for, statement_id, "
								+ " audit_group_name_hindi, statement_hindi) "
								+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
								+ "  '"+statement.getStatementType()+"', '"+staticDerivedStmt+"','"+BankAuditConstant.FOR_CHAPTER+"','"+statement.getStatementId()+"', "
								+ "  '"+chapterNameHindi+"', '"+staticDerivedStmtHindi+"' )";
						auditBookReportDaoV3.insertIntoReportTable(reportQuery);
						sequenceNumber ++;
					}
				}	
				/*List<String> listStaticStatement= auditBookReportDaoV3.getStaticStatementForChapterForReportTable(legalEntityCode, auditId, auditGroupCode);
				for (String staticStatement : listStaticStatement) {
					reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
							+ " audit_group_name, statement_type, statement , applicable_for) "
							+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
									+ "  '"+BankAuditConstant.FOR_STATIC_STMT+"', '"+staticStatement+"','"+BankAuditConstant.FOR_CHAPTER+"')";
					auditBookReportDaoV3.insertIntoReportTable(reportQuery);
					sequenceNumber ++;
				}	*/
				
				
				List<SectionDto> listSectionDto = auditBookReportDaoV3.getSectionForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode);
				for (SectionDto sectionDto : listSectionDto) {
					String auditSubGroupCode = sectionDto.getAuditSubGroupCode();
					String sectionName = sectionDto.getSectionName().replace("'", "''"); 
					String sectionNameHindi = sectionDto.getSectionNameHindi()==null?null:sectionDto.getSectionNameHindi().replace("'", "''");  
					reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, audit_group_name, "
							+ " audit_sub_group_code, audit_sub_group_name, applicable_for, "
							+ " audit_group_name_hindi, audit_sub_group_name_hindi ) "
							+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
									+ " '"+auditSubGroupCode+"', '"+sectionName+"' ,'"+BankAuditConstant.FOR_SECTION+"', "
									+ " '"+chapterNameHindi+"',  '"+sectionNameHindi+"' )";
					auditBookReportDaoV3.insertIntoReportTable(reportQuery);
					sequenceNumber ++;
					
					List<StaticDerivedStatementDTO> listStatementForSection= auditBookReportDaoV3.getDerivedAndStaticStatementForSectionForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode);
					for (StaticDerivedStatementDTO statement : listStatementForSection) {
						staticDerivedStmt = statement.getStatement().replace("'", "''");
						staticDerivedStmtHindi = statement.getStatementHindi()==null?null:statement.getStatementHindi().replace("'", "''");
						if(!BankAuditUtil.isEmptyString(staticDerivedStmt)){
							reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code,  audit_group_name, "
									+ " audit_sub_group_code, audit_sub_group_name, statement_type, statement, applicable_for,statement_id,"
									+ " audit_group_name_hindi, audit_sub_group_name_hindi, statement_hindi  ) "
									+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
											+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+statement.getStatementType()+"', '"+staticDerivedStmt+"',"
											+ " '"+BankAuditConstant.FOR_SECTION+"',  '"+statement.getStatementId()+"', "
											+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"',  '"+staticDerivedStmtHindi+"' )";
							auditBookReportDaoV3.insertIntoReportTable(reportQuery);
							sequenceNumber ++;
						}
					}					
					/*List<String> listStaticStatementForSection= auditBookReportDaoV3.getStaticStatementForSectionForReportTable(legalEntityCode, auditId, auditGroupCode, auditSubGroupCode);
					for (String staticStatement : listStaticStatementForSection) {
						reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code,  audit_group_name, "
								+ " audit_sub_group_code, audit_sub_group_name, statement_type, statement, applicable_for ) "
								+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
										+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+BankAuditConstant.FOR_STATIC_STMT+"', '"+staticStatement+"', '"+BankAuditConstant.FOR_SECTION+"')";
						auditBookReportDaoV3.insertIntoReportTable(reportQuery);
						sequenceNumber ++;
					}*/
					
					List<ProductDto> listProductDto = auditBookReportDaoV3.getProductForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode);
					for (ProductDto productDto : listProductDto) {
						String activityCode = productDto.getActivityCode();
												
						String productName  = productDto.getProductName().replace("'", "''");
						String productNameHindi = productDto.getProductNameHindi()==null?null:productDto.getProductNameHindi().replace("'", "''");
						reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, audit_group_name, "
								+ " audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, applicable_for,"
								+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi ) "
								+ " values( '"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
											+ " '"+auditSubGroupCode+"', '"+sectionName+"', '"+activityCode+"', '"+productName+"','"+BankAuditConstant.FOR_PRODUCT+"' , "
											+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"' )";
						auditBookReportDaoV3.insertIntoReportTable(reportQuery);
						sequenceNumber ++; 
						
						List<StaticDerivedStatementDTO> listStatementForProduct= auditBookReportDaoV3.getDerivedAndStaticStatementForProductForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode, activityCode);
						for (StaticDerivedStatementDTO statement : listStatementForProduct) {
							staticDerivedStmt = statement.getStatement().replace("'", "''");
							staticDerivedStmtHindi = statement.getStatementHindi()==null?null:statement.getStatementHindi().replace("'", "''");
							if(!BankAuditUtil.isEmptyString(staticDerivedStmt)){
								reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
										+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, "
										+ " statement_type, statement, applicable_for, statement_id, "
										+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi, statement_hindi ) "
										+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
												+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"',  "
												+ " '"+statement.getStatementType()+"', '"+staticDerivedStmt+"', '"+BankAuditConstant.FOR_PRODUCT+"',  '"+statement.getStatementId()+"', "
												+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+staticDerivedStmtHindi+"' )";
								auditBookReportDaoV3.insertIntoReportTable(reportQuery);
								sequenceNumber ++;
							}	
						}
						/*List<String> listStaticStatementForProduct= auditBookReportDaoV3.getStaticStatementForProductForReportTable(legalEntityCode, auditId, auditGroupCode, auditSubGroupCode, activityCode);
						for (String staticStatement : listStaticStatementForProduct) {
							reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
									+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, "
									+ " statement_type, statement, applicable_for ) "
									+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
											+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"',  "
											+ " '"+BankAuditConstant.FOR_STATIC_STMT+"', '"+staticStatement+"', '"+BankAuditConstant.FOR_PRODUCT+"')";
							auditBookReportDaoV3.insertIntoReportTable(reportQuery);
							sequenceNumber ++;
						}*/
						
						List<ProcessDto> listProcessDto = auditBookReportDaoV3.getProcessForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode, activityCode);
						for (ProcessDto processDto : listProcessDto) {
							String processCode = processDto.getProcessCode();
							 
							String processName = processDto.getProcessName().replace("'", "''"); 
							String processNameHindi = processDto.getProcessNameHindi()==null?null:processDto.getProcessNameHindi().replace("'", "''"); 
							reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, audit_group_name, "
									+ " audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, applicable_for,"
									+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi, process_name_hindi ) "
									+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
											+ " '"+auditSubGroupCode+"', '"+sectionName+"', '"+activityCode+"', '"+productName+"', "
											+ " '"+processCode+"', '"+processName+"',  '"+BankAuditConstant.FOR_PROCESS+"', "
											+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"')";
							auditBookReportDaoV3.insertIntoReportTable(reportQuery);
							sequenceNumber ++;
							
							List<StaticDerivedStatementDTO> listStatementForProcess = auditBookReportDaoV3.getDerivedAndStaticStatementForProcessForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode, activityCode, processCode);
							for (StaticDerivedStatementDTO statement : listStatementForProcess) {
								staticDerivedStmt = statement.getStatement().replace("'", "''");
								staticDerivedStmtHindi = statement.getStatementHindi()==null?null:statement.getStatementHindi().replace("'", "''");
								if(!BankAuditUtil.isEmptyString(staticDerivedStmt)){
									reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
											+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
											+ " statement_type, statement, applicable_for, statement_id, "
											+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi, process_name_hindi, statement_hindi  ) "
											+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
												+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',  "
												+ " '"+statement.getStatementType()+"', '"+staticDerivedStmt+"','"+BankAuditConstant.FOR_PROCESS+"',   '"+statement.getStatementId()+"', "
												+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"', '"+staticDerivedStmtHindi+"' )";
									auditBookReportDaoV3.insertIntoReportTable(reportQuery);
									sequenceNumber ++;
								}
							}
							/*List<String> listStaticStatementForProcess = auditBookReportDaoV3.getStaticStatementForProcessForReportTable(legalEntityCode, auditId, auditGroupCode, auditSubGroupCode, activityCode, processCode);
							for (String staticStatement : listStaticStatementForProcess) {
								reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
										+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
										+ " statement_type, statement, applicable_for ) "
										+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
												+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',  "
												+ " '"+BankAuditConstant.FOR_STATIC_STMT+"', '"+staticStatement+"','"+BankAuditConstant.FOR_PROCESS+"')";
								auditBookReportDaoV3.insertIntoReportTable(reportQuery);
								sequenceNumber ++;
							}*/
							
							//Get Checklist Data
							String isComplied = ""; 
							List<CheckListDto> listCheckListDto = auditBookReportDaoV3.getChecklistForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode, activityCode, processCode, isComplied);
							for (CheckListDto checkListDto : listCheckListDto) { 
							    isComplied = checkListDto.getIsComplied();
								String findingCode = checkListDto.getFindingCode();
								String checklist   = checkListDto.getChecklist().replace("'", "''");
								String checklistHindi   = checkListDto.getChecklistHindi()==null?null:checkListDto.getChecklistHindi().replace("'", "''");
								String mappingId = checkListDto.getMappingId();
								
								if(checklist!=null){
									reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, audit_group_name, "
											+ " audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
											+ " finding_code, finding_name, compliance_category , "
											+ " applicable_for, statement_type, mapping_id,"
											+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi,  process_name_hindi, finding_name_hindi ) "
											+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
													+ " '"+auditSubGroupCode+"', '"+sectionName+"', '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',"
													+ " '"+findingCode+"', '"+checklist.replace("'", "''")+"', '"+isComplied+"', "
													+ " '"+BankAuditConstant.FOR_CHECKLIST+"' , '"+BankAuditConstant.FOR_CHECKLIST+"' , '"+mappingId+"', "
													+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"', '"+checklistHindi+"' )";
									auditBookReportDaoV3.insertIntoReportTable(reportQuery);
									sequenceNumber ++;
								
									//Get Derived and Standard statement
									List<StaticDerivedStatementDTO> listStatementForChecklist = auditBookReportDaoV3.getDerivedAndStaticStatementForChecklistForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode, activityCode, processCode, findingCode);
									for (StaticDerivedStatementDTO statement : listStatementForChecklist) {										
										staticDerivedStmt = statement.getStatement()==null?null:statement.getStatement().replace("'", "''");										
										staticDerivedStmtHindi = statement.getStatementHindi()==null?null:statement.getStatementHindi().replace("'", "''");
										
										if(!BankAuditUtil.isEmptyString(staticDerivedStmt)){
											reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
													+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
													+ " finding_code,  compliance_category, statement_type,"
													+ "  statement, applicable_for , statement_id , mapping_id, "
													+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi,  process_name_hindi, statement_hindi ) "
													+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
															+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',  "
															+ " '"+findingCode+"', '"+isComplied+"', '"+statement.getStatementType()+"', "
															+ "  '"+staticDerivedStmt+"', '"+BankAuditConstant.FOR_CHECKLIST+"',  '"+statement.getStatementId()+"', '"+mappingId+"',"
															+ "  '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"', '"+staticDerivedStmtHindi+"'   )";
											auditBookReportDaoV3.insertIntoReportTable(reportQuery);
											sequenceNumber ++;
										}
									} 
									
									//Get Standard Statement
									List<CheckListDto> listStandardStmt = auditBookReportDaoV3.getStandardStatementForReportTable(legalEntityCode, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode, activityCode, processCode, findingCode);
									for (CheckListDto standardStmtData : listStandardStmt) {
										
										String standardStmt = standardStmtData.getStandardStatement()==null?null:standardStmtData.getStandardStatement().replace("'", "''");	
										String standardStmtHindi = standardStmtData.getStandardStatementHindi()==null?null:standardStmtData.getStandardStatementHindi().replace("'", "''"); 
										/*if(standardStmt!=null){
											standardStmt= standardStmt.replace("'", "''");
										} */
										reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, audit_group_name, "
												+ " audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
												+ " finding_code, compliance_category , statement_type, "
												+ " statement, applicable_for, mapping_id,"
												+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi,  process_name_hindi, statement_hindi  ) "
												+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
														+ " '"+auditSubGroupCode+"', '"+sectionName+"', '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',"
														+ " '"+findingCode+"',  '"+isComplied+"', '"+BankAuditConstant.FOR_STANDARD_STMT+"', "
														+ " '"+standardStmt+"', '"+BankAuditConstant.FOR_CHECKLIST+"' , '"+mappingId+"' , "
														+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"', '"+standardStmtHindi+"'  )"; 
										auditBookReportDaoV3.insertIntoReportTable(reportQuery);  
										sequenceNumber ++;										
									}										

									//Get Remarks									
									List<CheckListDto> listRemarksForChecklist = auditBookReportDaoV3.getRemarksForChecklistForReportTable(legalEntityCode, auditId, auditGroupCode, auditSubGroupCode, activityCode, processCode, findingCode, isComplied);
									for (CheckListDto remarksData : listRemarksForChecklist) { 
										String remarks = remarksData.getRemarks()==null?null:remarksData.getRemarks().replace("'", "''");
										String remarksHindi = remarksData.getRemarksHindi()==null?null:remarksData.getRemarksHindi().replace("'", "''");
										
										/*if(remarks!=null){
											remarks =	remarks.replace("'", "''");
										}
										if(remarksHindi!=null){
											remarksHindi =	remarksHindi.replace("'", "''");
										}*/
										reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
												+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
												+ " finding_code, compliance_category ,"
												+ " statement_type, statement, applicable_for, mapping_id, "
												+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi,  process_name_hindi, statement_hindi  ) "
												+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
														+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',  "
														+ " '"+findingCode+"', '"+isComplied+"', "
														+ " '"+BankAuditConstant.FOR_REMARKS+"', '"+remarks+"', '"+BankAuditConstant.FOR_CHECKLIST+"',  '"+mappingId+"', "
														+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"', '"+remarksHindi+"'  )";
										auditBookReportDaoV3.insertIntoReportTable(reportQuery);
										sequenceNumber ++; 
									}
									
									//Place Holder for Bank Comment
									reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
											+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
											+ " finding_code, compliance_category ,"
											+ " statement_type, statement, applicable_for, mapping_id, "
											+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi,  process_name_hindi, statement_hindi  ) "
											+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
													+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',  "
													+ " '"+findingCode+"', '"+isComplied+"', "
													+ " '"+BankAuditConstant.FOR_REMARKS_BANK+"', '', '"+BankAuditConstant.FOR_CHECKLIST+"',  '"+mappingId+"', "
													+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"', '' )";
									auditBookReportDaoV3.insertIntoReportTable(reportQuery);
									sequenceNumber ++;
									
									//Place Holder for Scrutiny Comment
									reportQuery="Insert Into audit_report_stmt(sequence, legal_entity_code, audit_id, audit_type_code, audit_group_code, "
											+ " audit_group_name, audit_sub_group_code, audit_sub_group_name, activity_code, activity_name, process_code, process_name, "
											+ " finding_code, compliance_category ,"
											+ " statement_type, statement, applicable_for, mapping_id, "
											+ " audit_group_name_hindi, audit_sub_group_name_hindi, activity_name_hindi,  process_name_hindi, statement_hindi ) "
											+ " values('"+sequenceNumber+"', '"+legalEntityCode+"', '"+auditId+"', '"+auditTypeCode+"', '"+auditGroupCode+"', '"+chapterName+"',"
													+ " '"+auditSubGroupCode+"', '"+sectionName+"' , '"+activityCode+"', '"+productName+"', '"+processCode+"', '"+processName+"',  "
													+ " '"+findingCode+"', '"+isComplied+"', "
													+ " '"+BankAuditConstant.FOR_REMARKS_SCRUTINY+"', '', '"+BankAuditConstant.FOR_CHECKLIST+"',  '"+mappingId+"', "
													+ " '"+chapterNameHindi+"', '"+sectionNameHindi+"', '"+productNameHindi+"', '"+processNameHindi+"', '' )";
									auditBookReportDaoV3.insertIntoReportTable(reportQuery);
									sequenceNumber ++;
									
								} 
							}					
						}				
					}				
				}			
			}			
		/*}catch (Exception e) {
			logger.error(e.getStackTrace()); 
			return BankAuditConstant.FAILED; 
		}*/
		return BankAuditConstant.SUCCESS;
	}
    
	/**************** TO update Report related data to master table from UI  (from capture/inspection screen) Start **************/
	
	 @Override
	 public void updateChecklistForReportTable(Integer legalEntityCode, String mappingId,  String auditId, String auditTypeCode, String auditGroupCode, 
				String auditSubGroupCode, String activityCode, String processCode, String findingCode, String isComplied, String reportLanguage, 
				String nonCompliancePersistence, String criticality){
		 auditBookReportDaoV3.updateChecklistForReportTable(legalEntityCode, mappingId, auditId, auditTypeCode, auditGroupCode,
				 auditSubGroupCode, activityCode, processCode, findingCode, isComplied, reportLanguage, nonCompliancePersistence, criticality);		 
	 }
	 
	 @Override
	 public void updateStandardStatementForReportTable(Integer legalEntityCode, String mappingId,  String auditId, String auditTypeCode, String auditGroupCode, 
			String auditSubGroupCode, String activityCode, String processCode, String findingCode, String isComplied, String statement, 
			String statementHindi, String reportLanguage){
		 auditBookReportDaoV3.updateStandardStatementForReportTable(legalEntityCode, mappingId, auditId, auditTypeCode, auditGroupCode, 
				 auditSubGroupCode, activityCode, processCode, findingCode, isComplied, statement, statementHindi, reportLanguage);
	 }
	
	 @Override
	 public void updateRemarksForReportTable(Integer legalEntityCode, String mappingId,  String auditId, String auditTypeCode, String auditGroupCode, 
			String auditSubGroupCode, String activityCode, String processCode, String findingCode, String isComplied, String statement, String reportLanguage){
		 auditBookReportDaoV3.updateRemarksForReportTable(legalEntityCode, mappingId, auditId, auditTypeCode, auditGroupCode,
				 auditSubGroupCode, activityCode, processCode, findingCode, isComplied, statement, reportLanguage);
	 }
	 
	 @Override
	 public void updateBankRemarksForReportTable(Integer legalEntityCode, String mappingId,  String auditId, String auditTypeCode, String auditGroupCode, 
				String auditSubGroupCode, String activityCode, String processCode, String findingCode, String isComplied, String statement, String reportLanguage){
		 auditBookReportDaoV3.updateBankRemarksForReportTable(legalEntityCode, mappingId, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode,
				 activityCode, processCode, findingCode, isComplied, statement, reportLanguage);
	 }
		
	 @Override
	 public void updateScrutinyRemarksForReportTable(Integer legalEntityCode, String mappingId,  String auditId, String auditTypeCode, String auditGroupCode, 
				String auditSubGroupCode, String activityCode, String processCode, String findingCode, String isComplied, String statement, String reportLanguage){
		 auditBookReportDaoV3.updateScrutinyRemarksForReportTable(legalEntityCode, mappingId, auditId, auditTypeCode, auditGroupCode, auditSubGroupCode,
				 activityCode, processCode, findingCode, isComplied, statement, reportLanguage);
	 }
		
	/**************** TO update Report related data to master table from UI  (from capture/inspection screen) End **************/
	/******************** Generate Profile PDF Start ***************************/
	
	@Override  
	public String generatePDFProfile(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String userId,
				String planId,  String unitId,  String reportLanguage ){
		try{	
		logger.info("generatePDFProfile() called...PDF Profile Generation...");
		 
		String[] reportPath = getReportPathByReportLanguage(reportLanguage, auditTypeCode).split("##");  
		String jasperReportPath = reportPath[1];  
		String jasperSubReportPath = reportPath[2]; 
		String jasperReportProfileName = reportPath[3];   
		List<Profile> jasperReportProfileBeanDataSourceList =  getProfileData(legalEntityCode, auditId, auditTypeCode, reportLanguage, userId);	
		
		params.put("SUB_REPORT_DIR", jasperSubReportPath); 	
		InputStream stream = this.getClass().getResourceAsStream(jasperReportPath + jasperReportProfileName);		 
		JasperReport jasperReport = null;
		//try{								
			jasperReport = JasperCompileManager.compileReport(stream);  
			 		 
			JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(jasperReportProfileBeanDataSourceList);
			JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource);			 
			
			String uploadFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_Profile"+".pdf";    		 
			String profilePath = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +uploadFileName;				 			 
			JasperExportManager.exportReportToPdfFile(print,profilePath);	 		 
			
			System.out.println("uploadPath .. "+ profilePath);
			return profilePath;				 	
			 
		} catch (JRException  e) {
			e.printStackTrace();
		}catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	} 
	
	private List<Profile> getProfileData(Integer legalEntityCode, String auditId, String auditTypeCode, String reportLanguage, String userId){
			
		//Get All the parameter mapped values
		Map<String, String[]> parameterMap =  auditBookReportDaoV3.getParameterVeluesForProfile(legalEntityCode, auditId, auditTypeCode);		
		List<Profile> profileList =  null;
		if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_RRB_CONTAINS)){
			profileList = getProfileDetails(legalEntityCode, auditId, auditTypeCode, parameterMap);
		}
		else{
			Map<String, String> profileParameterMap =  auditBookReportDaoV3.getProfileParameterMap(legalEntityCode, auditId, auditTypeCode); 
			profileList = new ArrayList<Profile>();
			Profile profile = new Profile(); 
			profile.setProfileParameterMap(profileParameterMap);
			profileList.add(profile);
		}  
	
		 return profileList;
	}
	 
	/******************** Generate Profile PDF End ***************************/ 
	 
	
	 
	 /**************** Generation of Part-C Start **************/
 	  
	 private String generatePDFReportPartC(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String jasperSubReportPath, String reportTypePartC){
			 	
			String tempDir = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+"/"+legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+BankAuditUtil.parseDateToStringToCreateFileName(new Date()); 			
			
			Path path = Paths.get(tempDir);
			try{
				Files.createDirectory(path);
			}catch (Exception e) {
				logger.error("generatePDFReportPartC():: Failed to create directory...");
				return null;
			}					
			
			List<TableDataColumnNumberDto>  listTableDataColumnNumberDto = auditBookReportDaoV3.getTableDataForPartC(legalEntityCode, auditId, auditTypeCode);			
			if(listTableDataColumnNumberDto.isEmpty() || listTableDataColumnNumberDto==null || listTableDataColumnNumberDto.size()==0){
				//Merge uploaded pdf and table
				String partCFileNamePath = mergePartCTableAndPartCPdf(legalEntityCode, auditId, auditTypeCode, tempDir, reportTypePartC);
				return partCFileNamePath;
			}
			
			List<TableDataColumnNumberDto> jasperReportBeanDataSourceList = new ArrayList<>();			
     		Boolean isGeneratePortrait =false; 
			Boolean isGenerateLandscape =false; 
			String jasperFileName="";
			int fileNumber = 1;
			for(TableDataColumnNumberDto tableDataColumnNumberDto : listTableDataColumnNumberDto) {				
				if(tableDataColumnNumberDto.getNumberOfColumn()<=5 && isGenerateLandscape){ 
					String status = generatePartCTable(params, jasperReportBeanDataSourceList, jasperFileName, legalEntityCode, auditId, auditTypeCode, tempDir, fileNumber++, jasperSubReportPath);
					if(status.equals(BankAuditConstant.FAILED)){
						return null;
					}
					jasperReportBeanDataSourceList = new ArrayList<>();
					isGenerateLandscape =false;
				}	
			    if(tableDataColumnNumberDto.getNumberOfColumn()<=5){
					jasperReportBeanDataSourceList.add(tableDataColumnNumberDto);						
					isGeneratePortrait =true;
					jasperFileName = "table_portrait.jrxml";
				} 
				
				if(tableDataColumnNumberDto.getNumberOfColumn()>=6 && isGeneratePortrait){ 
					String status = generatePartCTable(params, jasperReportBeanDataSourceList,jasperFileName , legalEntityCode, auditId, auditTypeCode, tempDir, fileNumber++, jasperSubReportPath);					
					if(status.equals(BankAuditConstant.FAILED)){
						return null;
					}
					jasperReportBeanDataSourceList = new ArrayList<>();
					isGeneratePortrait =false; 
				}	
				if(tableDataColumnNumberDto.getNumberOfColumn()>=6){
					jasperReportBeanDataSourceList.add(tableDataColumnNumberDto);						
						isGenerateLandscape=true;
						jasperFileName = "table_landscape.jrxml";
				}				 			
			}
			
			//Add Last Iterated tables to jasper 
			if(!jasperFileName.trim().equals("")){
				String status = generatePartCTable(params, jasperReportBeanDataSourceList, jasperFileName, legalEntityCode, auditId, auditTypeCode, tempDir, fileNumber++, jasperSubReportPath);					
				if(status.equals(BankAuditConstant.FAILED)){
					logger.error("generatePDFReportPartC():: Failed to generate part C...");
					return null;
				} 
			}
			 		
			//Merge uploaded pdf and table
			String partCFileNamePath = mergePartCTableAndPartCPdf(legalEntityCode, auditId, auditTypeCode, tempDir, reportTypePartC);
			return partCFileNamePath;
		}
	 	 
	 private String generatePartCTable(Map<String, Object> params, List<TableDataColumnNumberDto> jasperReportBeanDataSourceList,  String jasperReportName, 			
				Integer legalEntityCode, String auditId, String auditTypeCode, String tempDir, int fileNumber, String jasperSubReportPath ){		 
		  
				try {
					params.put("SUB_REPORT_DIR", jasperSubReportPath+"tablePartC/"); 
					params.put("auditTypeCode", auditTypeCode); 
					
					InputStream stream = this.getClass().getResourceAsStream(jasperSubReportPath+"tablePartC/" + jasperReportName);				 
					JasperReport jasperReport = null;
					jasperReport = JasperCompileManager.compileReport(stream);				
					
					JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(jasperReportBeanDataSourceList);
					JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource); 
					 
					 String uploadPath = tempDir+"/"+fileNumber+"_"+"_InspectionReportTablePartC"+".pdf";  				 
					 JasperExportManager.exportReportToPdfFile(print,uploadPath);	 				  
					 
				}catch (JRException e) {
					logger.error("generatePartCTable():: Exception- "+e);
					return BankAuditConstant.FAILED;
				}catch (Exception e) {
					logger.error("generatePartCTable():: Exception- "+e);
					return BankAuditConstant.FAILED;
				}	
				//System.out.println("A");
				return BankAuditConstant.SUCCESS;
	}
	 
	 private String generatePartCHeader(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String userId, String jasperSubReportPath, String partC_Name){		 
		
		    PartDto partDto = new PartDto();
			partDto.setPartName(partC_Name);
			List<PartDto>  jasperReportBeanDataSourceList =  new ArrayList<PartDto>();
			jasperReportBeanDataSourceList.add(partDto); 	
			 	
			String partCHeaderName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_InspectionReportPartCHeader"+".pdf";  
			String partCHeaderPath = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +partCHeaderName;
			
		 
				try {
					params.put("SUB_REPORT_DIR", jasperSubReportPath+"tablePartC/"); 
					
					InputStream stream = this.getClass().getResourceAsStream(jasperSubReportPath+"tablePartC/" + "PartC.jrxml");				 
					JasperReport jasperReport = null;
					jasperReport = JasperCompileManager.compileReport(stream);				
					
					JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(jasperReportBeanDataSourceList);
					JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource); 
					   				 
					 JasperExportManager.exportReportToPdfFile(print,partCHeaderPath);	 				  
					 
				}catch (JRException e) {
					logger.error("generatePartCTable():: Exception- "+e);
					return BankAuditConstant.FAILED;
				}catch (Exception e) {
					logger.error("generatePartCTable():: Exception- "+e);
					return BankAuditConstant.FAILED;
				}	
				//System.out.println("A");
				return partCHeaderPath;
	} 
 
	private String mergePartCTableAndPartCPdf(Integer legalEntityCode, String auditId, String auditTypeCode, String tempDir, String reportTypePartC)  {
		 
		String partCFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_InspectionReportPartC"+".pdf";  
		String partCFileNamePath = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +partCFileName;
		Boolean partCExist = false;
		try{
			PDFMergerUtility pdfMerger = new PDFMergerUtility();
			
			pdfMerger.setDestinationFileName(partCFileNamePath);
			 
			//Merge PartC Pdfs			
			List<String>  listPartCPdf = auditBookReportDaoV3.getPartCPdfFiles(legalEntityCode, auditId, auditTypeCode, reportTypePartC);
			for (String partCPdf : listPartCPdf) {			
				File pdfFile = new File(partCPdf); 
				//PDDocument pdDocument = PDDocument.load(pdfFile);  
			    pdfMerger.addSource(pdfFile); 	   
			    //pdDocument.close();
			    partCExist=true;
			}
			
			//Merge PartC tables
			File directoryPath = new File(tempDir); 
		    File filesList[] = directoryPath.listFiles();
		     for (File pdfFile : filesList) {
				if(pdfFile.isFile()){
					//PDDocument pdDocument = PDDocument.load(pdfFile); 
				    pdfMerger.addSource(pdfFile); 	   
				    //pdDocument.close();
				    partCExist=true;
				}
			}    
			if(partCExist)
				pdfMerger.mergeDocuments(null); 
			 
			//delete tmps
			try{
				FileUtils.deleteDirectory(new File(tempDir));  	 
			}catch (Exception e) { }
				 
		}catch (Exception ex) { 
			logger.error("mergePartCTableAndPartCPdf():: Exception- "+ex);
			return null;
		}
		return partCExist?partCFileNamePath:BankAuditConstant.IR_PART_C_NOT_EXIST;
	 }	 
	 

	 
	public String generateBackCoverPage(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String userId, String jasperReportPath){
		
		String backCoverPage = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_backCoverPage"+".pdf";  
		String backCoverPagePath = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +backCoverPage;
			try {
				
				BackCoverPageDto backCoverPageDto = new BackCoverPageDto();
				backCoverPageDto.setBackCoverTitle("End of Report"); 
				backCoverPageDto.setUserId(userId);		
				backCoverPageDto.setPageInfo(new SimpleDateFormat("ddMMyyyyHHmm").format(new Date()));
	 			List<BackCoverPageDto> listBackCoverPageDto = new ArrayList<>();
	 			listBackCoverPageDto.add(backCoverPageDto);
	 			
				String jasperReportName="BackCoverPage.jrxml";
				params.put("SUB_REPORT_DIR", jasperReportPath); 
				
				InputStream stream = this.getClass().getResourceAsStream(jasperReportPath + jasperReportName);				 
				JasperReport jasperReport = null;
				jasperReport = JasperCompileManager.compileReport(stream);				
				
				JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(listBackCoverPageDto);
				JasperPrint print = JasperFillManager.fillReport(jasperReport, params, dataSource); 
				   				 
				JasperExportManager.exportReportToPdfFile(print,backCoverPagePath);	 				  
				 
			}catch (JRException e) {
				logger.error("generateBackCoverPage():: Exception- "+e);
				return null;
			}catch (Exception e) {
				logger.error("generateBackCoverPage():: Exception- "+e);
				return null;
			}	
			 
			return backCoverPagePath;
	 }
	
	 public String mergeAll(Integer legalEntityCode, String auditId, String auditTypeCode,   String partABFile, String partCFile, String backCoverFile, 
			 String partCHeaderFile, Boolean isFinalReport, String reportNameSuffix)  {
		  
			String IR_FileName_TMP = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_InspectionReport_tmp"+reportNameSuffix+".pdf";  
			String IR_FilePath = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +IR_FileName_TMP;
			
			String IR_FilePathFinal =legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_"+new SimpleDateFormat("ddMMyyyy").format(new Date())+"_InspectionReport"+reportNameSuffix+".pdf";
			if(isFinalReport){ 
				IR_FilePathFinal = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_REPORTS)+ "/"+IR_FilePathFinal ;						
	 		}else{ 
	 			IR_FilePathFinal = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/"+IR_FilePathFinal;
	 		}
			
			PDFMergerUtility pdfMerger = new PDFMergerUtility();		
			try{						
				pdfMerger.setDestinationFileName(IR_FilePath); 				 	   
				
				//Part AB
				 
				/*PdfReader reader = new PdfReader(partABFile);
				reader.selectPages("1-"+reader.getNumberOfPages());
				PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(partABFile));
				stamp.close();*/
				
				File pdfFileAB = new File(partABFile); 
			    pdfMerger.addSource(pdfFileAB);
			    if(!auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_ITISI)){
			    	pdfMerger.addSource(partCHeaderFile);
				}
			   //Part C
			    File pdfFileC = null;
				if(!auditTypeCode.equalsIgnoreCase(BankAuditConstant.INSPECTION_TYPE_ITISI) 
						&& partCFile!=null && !partCFile.trim().equals("") && !partCFile.equals(BankAuditConstant.IR_PART_C_NOT_EXIST)){
					pdfFileC = new File(partCFile);  
					pdfMerger.addSource(pdfFileC); 
				}				
				
				//add End of Report Page
				File pdfFileBackCOver =null;
				if(backCoverFile!=null && !backCoverFile.trim().equals("")){
					pdfFileBackCOver =  new File(backCoverFile); 
					pdfMerger.addSource(pdfFileBackCOver); 				 
				}
				pdfMerger.mergeDocuments(null); 
					 
				try{
					if(pdfFileAB.exists())	
						pdfFileAB.delete();  
					if(pdfFileC!=null && pdfFileC.exists())	
						pdfFileC.delete();  
					if(pdfFileBackCOver!=null && pdfFileBackCOver.exists())	
						pdfFileBackCOver.delete(); 
					
					new File(partCHeaderFile).delete();
				}catch (Exception e) { 
					System.out.println(e);
				}
			}catch (Exception e) { 
				logger.error("mergeAll():: Exception- "+e);
				return null;
			}
			 
				//Add Page number to generated report				
				try { 
					PdfReader reader = new PdfReader(IR_FilePath);
					int pageCount = (reader.getNumberOfPages())-1 ;
					PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(IR_FilePathFinal));
					int pageNumber = 0;
					PdfContentByte over ;
					BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.EMBEDDED);
					while (pageNumber < pageCount) {
						pageNumber++;
						if (pageNumber > 1 ) {
							over = stamp.getOverContent(pageNumber);
							over.beginText();
							over.setFontAndSize(bf, 10);
							//over.setTextMatrix(72, 70);
							//over.showText(String.format("page %s of %s", pageNumber-1, pageCount-1));
							over.showTextAligned(PdfContentByte.ALIGN_LEFT, String.format("page %s of %s", pageNumber-1, pageCount-1), 72, 55, 0);
							over.endText(); 
						}
					}
					stamp.close();					
					try{ 	
						 File IR_fileToDelete = new File(IR_FilePath)  ;
						 IR_fileToDelete.delete();
					}catch (Exception e) {  
					}
					
				} catch (Exception e) {  
					logger.error("mergeAll():: Exception- "+e);
					return null;
				} 
			return IR_FilePathFinal;
		 }
	 
	 /**************** Generation of Part-C End **************/
	 
	 /**************** Generation of Profile Start **************/	 
	 private List<Profile> getProfileDetails(Integer legalEntityCode, String auditId, String auditTypeCode,  Map<String, String[]> parameterMap){
		
		 if(parameterMap.isEmpty() || parameterMap==null || parameterMap.size()<=0){
			 return null;
		 }
		 
		 List<Profile> profileList = new ArrayList<>();	
		 
		 String[] alphaBetSequence ={"A","B","C","D","E","F","L","M"};
		 String[] alphaBetSequenceWithDliDpi ={"G","H","I","J","K", "N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};

		 List<String> alphaBetSequenceList = Arrays.asList(alphaBetSequence);
		 List<String> alphaBetSequenceWithDliDpiList = Arrays.asList(alphaBetSequenceWithDliDpi);
 
		  
		 String[] profileBankDetailsHeaderA	= {"A:Bank Details:  ",
				 "Sr.No.:Particulars:As on DPI"};
		 String[] profileBankDetailsA	= {/*"A:Bank Details: ------ ",
				 "Sr.No.:Particulars:AS on DPI",*/ 
		 		 "1:Name of the Bank/Institution:BANKNAME",
		 		 "2:Bank Type :BANKTYPE",
				 "3:Name of the Chairman of the Bank:MANAGENAME2",
				 
				 "4:Term of the Chairman of the Bank(in years):BOM-675",
				 "5:Start Date of tenure of the Chairman:BOM-676",
				 "6:End Date of tenure of the Chairman:BOM-677",
				 
				 "7:Name of the Sponsor Bank:NAMSPOBANK",
				 "8:Name of the State/UT:STATE",
				 "9:Date of Establishment / Incorporation / Date of Amalgamation:ESTBDATE",
				 "10:Area of Operation (No. of districts):NUMOFDIST",
				 "11:Date of Licence:DATEOFLICENSE",
				 "12:Licence Number:LICENSENUM",
				 "13:Date of Scheduling:INCDATE",
				// "11:Total number of offices:TOTOFFICECOUNT",
				 "14:Total Number of Offices:BOM-671", // BRANCHTOTCOUNT
				 "15:Number of Branches / ROs visited during inspection:BOM-678##CONTROFFCOUNT"};  //  BRANCHNAMES1
		 
		 String[] profileDetailsA1 = {"1:Total No. of Branches:2BRANCHTOTCOUNT:3BRANCHTOTCOUNT",
		 "2:Total No. of Staff:2TOTNUBOFSTAFF:3TOTNUBOFSTAFF"}; 
		 String[] profileDetailsB = {"B:Financial Indicators:  :  ",
				 "Sr.No.:Particulars:DLI:DPI",
				 "1:Net Worth (Rs. lakh):2REV:3REV",				 
				 "2:CRAR (Regulatory minimum requirement - 9 %):2CRARIO:3CRARIO", // CRARA
				 "3:Tier-1 Capital (Regulatory minimum requirement - 7 %):2TIER1CAR:3TIER1CAR",
				 "4:Total Assets (Rs. lakh):2Assets:3Assets",
				// "5:Total Deposits (Rs. lakh):2TDTOTAMT:3TDTOTAMT", 
				 "5:Total Deposits (Rs. lakh):2TOTDEPAMT:3TOTDEPAMT",
				 "6:Total advances (Rs. lakh):2TOTADVAMT:3TOTADVAMT",
				 "7:Profit (+)/Loss (-) (Rs. lakh):2PROFIT:3PROFIT",  //2PROFITLOSSAMT:3PROFITLOSSAMT
				 //"8:Shortfall in Provision (Rs. lakh):2BOM- 51:3BOM- 51",
				 "8:Profit (+)/Loss (-) as per IO (Rs. lakh):2IOPROFITAMT:3IOPROFITAMT",			 
				 "9:Accumulated Loss (Rs. lakh):2ACCLOSSAMT:3ACCLOSSAMT",
				 "10:Gross NPAs (Rs. lakh):2GROSSNPAAMT:3GROSSNPAAMT", //2GROSSNPAP:3GROSSNPAP
				 "11:Gross NPAs to Gross Advances (%) (Tolerance level - 5 %):2GROSSNPAP:3GROSSNPAP",
				 "12:Net NPAs to Net Advances (%) (Tolerance level - 3 %):2NETNPAPTOTAL:3NETNPAPTOTAL",
				 "13:Provision Coverage Ratio (PCR) (%) (Benchmark - 70%):2PCRR:3PCRR",
				 //"13:Total Provision Required (Rs. lakh):2TOTPROREQ:3TOTPROREQ",
				 //"14:Total Provision made (Rs. lakh):2PROVAMT:3PROVAMT",
				 "14:Total Provision Required to be made for NPA (Rs. lakh):2TOTPROREQ:3TOTPROREQ",
				 "15:Total Provision made for NPA (Rs. lakh):2BOM-672:3BOM-672",
				 "16:Net Interest Margin (NIM) (%):2NIM:3NIM",
				 "17:Return on Assets (RoA) (%):2ROA:3ROA"};
		 String[] profileDetailsC = {"NOD: : : ",
				 //"C:Total Erosion:2EROSION:3EROSION",
				// "C:Total Erosion: : ",
				 "C:Erosion in assets and un-provided liabilities: : ",
				 "Sr.No.:Particulars:DLI:DPI",
				 //":Total Erosion (Rs. lakh):2EROSION:3EROSION", //06 03 2023
				 ":Total Erosion (Rs. lakh):2BOM-724:3BOM-724", 
				 ":Erosion affected the following:  :  ",				
				 "1:Loss Provisions including Revaluation Reserve (%):2LOSSPROINCREVRES:3LOSSPROINCREVRES",
				 "2:Provision for standard assets (%):2PROSA:3PROSA",
				 "3:Balance in Profit and Loss account (%):2PROFITLOSSAMT:3PROFITLOSSAMT",
				 "4:Free Reserves (%):2FREERESAMTP:3FREERESAMTP",
				 "5:Paid-up Capital (%):2PAIDUPAMTP:3PAIDUPAMTP",
				 "6:Deposits (%):2TOTDEPP:3TOTDEPP"}; // TDTOTAMT
		 
		 String[] profileDetailsD = {"D:Compliance with BR Act, 1949:  :  ",
				 "Sr.No.:Particulars:DLI:DPI",
				// "1:Compliance with Section 6 (From & business in which Banking Companies may engage):2COMSEC6BRACT1949:3COMSEC6BRACT1949",
				// "2:Compliance with Section 8 (Prohibition of trading):2COMSEC8BRACT1949:3COMSEC8BRACT1949",
				// "3:Compliance with Section 9 (Disposal of non-banking assets):2COMSEC9BRACT1949:3COMSEC9BRACT1949",
				 "1:Compliance with Section 14A (Prohibition of floating charge on assets):2COMSEC14ABRACT1949:3COMSEC14ABRACT1949",
				 "2:Compliance with Section 17 (Creation of Reserve Fund):2COMSEC17BRACT1949:2COMSEC17BRACT1949",
				 "3:Compliance with Section 19 (Restriction on nature of subsidiary companies):2COMSEC19BRACT1949:3COMSEC19BRACT1949",
				 "4:Compliance with Section 20 (Restriction on loans & advances):2COMSEC20BRACT1949:3COMSEC20BRACT1949",
				 "5:Compliance with Section 21 (Power of RBI to control advances):2COMSEC21BRACT1949:3COMSEC21BRACT1949",
				 "6:Compliance with Section 23 (Opening of new branches / transfer of existing branches):2COMSEC23BRACT1949:3COMSEC23BRACT1949",
				 "7:Compliance with Section 24 (Maintenance of SLR):2COMSEC24BRACT1949:3COMSEC24BRACT1949",
				 "8:Compliance with Section 26 (Return of un-claimed deposit):2COMSEC26BRACT1949:3COMSEC26BRACT1949",
				 "9:Compliance with Section 26A (transfer to DEAF):2COMSEC26ABRACT1949:3COMSEC26ABRACT1949",
				 "10:Compliance with Section 27(3) (Submission of returns):2COMSEC27(3)BRACT1949:3COMSEC27(3)BRACT1949",
				 "11:Compliance with Section 29 (Preparation of accounts and Balance Sheet):2COMSEC29BRACT1949:3COMSEC29BRACT1949",
				 "12:Compliance with Section 31 (Submission of Returns):2COMSEC31BRACT1949:3COMSEC31BRACT1949",
				 "13:Compliance with Section 35A (Issue of Directions):2COMSEC35ABRACT1949:3COMSEC35ABRACT1949"};
		 
		 String[] profileDetailsE = {"E:Compliance with RBI Act, 1934:  :  ",
				 "Sr.No.:Particulars:DLI:DPI",
				 "1:Compliance with Section 42(1)  (Maintenance of CRR):2COMSEC42(1)RBICT1934:3COMSEC42(1)RBICT1934",
				 "2:Compliance with Section 42(2) (Submission of returns):2COMSEC42(2)RBICT1934:3COMSEC42(2)RBICT1934",
				 "3:Compliance with Section 42(6)(a)(i) (Networth/ REV):2COMSEC42(6)(a)(1)RBICT1934:3COMSEC42(6)(a)(1)RBICT1934",
				 "4:Compliance with Section 42(6)(a)(ii) (Interest of depositors):2COMSEC42(6)(a)(2)RBICT1934:3COMSEC42(6)(a)(2)RBICT1934"};
		 String[] profileDetailsF = {"NOD: : : ",
				 "F:Compliance with RRB Act, 1976:  :  ",
				 "Sr.No.:Particulars:DLI:DPI",
				 //"1:Compliance with RRB Act, 1976:2COMSEC14RRBACT1976:3COMSEC14RRBACT1976",
				 "1:Compliance with Section 14 (Conduct of Board Meetings):2COMSEC14RRBACT1976:3COMSEC14RRBACT1976",
				 "2:Compliance with Section 18 (Business which RRBs may transact):2COMSEC18RRBACT1976:3COMSEC18RRBACT1976",
				 "3:Compliance with Section 20 (Annual Report to shareholders):2COMSEC20RRBACT1976:3COMSEC20RRBACT1976"};
		 
		 String[] profileDetailsG = {"NOD: : : ",
		 			"G:Compliance with Section 15(1) of CIC (R) Act, 2005 to be read with Section 11(1) of CIC (R) Act, 2015 (membership & uploading of credit information):2COMSEC15(1)CICACT:3COMSEC15(1)CICACT"};
				 // "G:Compliance with Section 11(1) of CIC (R) Act,  2005 (membership & uploading of credit information):2COMSEC15(1)CICACT:3COMSEC15(1)CICACT"};
		 		 //"G:Compliance with Section 15(1) of CIC (R) Act, 2005 (membership & uploading of credit information):2COMSEC15(1)CICACT:3COMSEC15(1)CICACT"};
		 String[] profileDetailsH = {"H:Compliance with SAF-PCA:2SAFPCA:3SAFPCA"}; 
		 String[] profileDetailsI = {"I:Divergence (Rs. lakh):2COMSAFPCADIVE:3COMSAFPCADIVE"}; 
		 String[] profileDetailsJ = {"J:DICGC coverage (Y/N):2COMSAFPCADICGCCOV:3COMSAFPCADICGCCOV"}; 
		 String[] profileDetailsK = {"K:Uploading of information to NeSL:2OMSAFPCAUPLINFONeSL:3OMSAFPCAUPLINFONeSL"}; 
		 String[] profileDetailsL = {"NOD: : : ",
				 "L:Regulatory action taken against the bank:  :  ",
				 "Sr.No.:Particulars:DLI:DPI",
				 "1:Whether RBI has imposed any direction?:2REGACRBIIMDIR:3REGACRBIIMDIR",
				 "2:Whether RBI has imposed any penalty?:2REGACRBIIMPEN:3REGACRBIIMPEN"}; 
		 String[] profileDetailsM = {"M:Committees:  :  ",
				 "Sr.No.:Particulars:DLI:DPI",
				 "1:Audit Committee:2AUDITCCOM:3AUDITCCOM",
				 "2:ALCO Committee:2ALCOCCOM:3ALCOCCOM",
				 "3:Investment Committee:2NVESTCCOM:3NVESTCCOM",
				// "4:Credit Committee:2CREDITCCOM:3CREDITCCOM",
				 "4:Risk Management Committee:2RISKMCCOM:3RISKMCCOM",
				 "5:Fraud Prevention and Monitoring Committee:2FPMOCCOM:3FPMOCCOM"}; 
		 String[] profileDetailsN = {"NOD: : : ",
				 "N:Whether NPAs are system generated?:2NPASYSG:3NPASYSG"};
		// String[] profileDetailsO = {"O:Membership of all 4 Credit Information Companies:2MEM4CREDITINFOCO:3MEM4CREDITINFOCO"};
		 String[] profileDetailsO = {"O:Vulnerability Index for Cyber Security Framework - VICS Score:2VICSSCORE:3VICSSCORE"};
		 String[] profileDetailsP = {"P:VINFRA Score:2VICATSCORE:3VICATSCORE"};
		 String[] profileDetailsQ = {"Q:Audited by (CA firm):2AUDITCO:3AUDITCO"};
		 String[] profileDetailsR = {"R:Compliance Rating - Field Level (%) (Above 50% is assessed as \"Satisfactory\"):2OBSCRP:3OBSCRP"}; //  OBSCRP
		 String[] profileDetailsS = {"S:Whether the Bank has KYC Policy duly approved by the Board of Directors?:2KYCPOLAPPOBOD:3KYCPOLAPPOBOD"};
		 /*String[] profileDetailsU = {"U:Whether Bank violated of exposure norms (single party - 15% of CF / Group - 40% of CF)?:2BKVIOEXNORMS:3BKVIOEXNORMS"};
		 String[] profileDetailsV = {"V:Any Cyber incidents?:2ANYCYBINCI:3ANYCYBINCI"};*/ 
		 String[] profileDetailsT = {"T:Whether Bank violated single party exposure norms (15% of CF)?:2BKVIOEXNORMS:3BKVIOEXNORMS",
				 " :Whether Bank violated group exposure norms (40% of CF)?:2BKVIOGEXNORMS:3BKVIOGEXNORMS"};
		 String[] profileDetailsU = {"U:Any Cyber incidents?:2ANYCYBINCI:3ANYCYBINCI"};
		 		  
		 
		 Profile profileA = new Profile(); 
		 List<ProfileDetails>  profileDetailsListA = new ArrayList<>();		 
		 List<ProfileBankDetails>  profileBankDetailsList = new ArrayList<>();
		 
		 for(String profileBankDetailsStr :profileBankDetailsHeaderA){
			    String[] profileBankDetailsStrArr=profileBankDetailsStr.split(":"); 				
				ProfileBankDetails profileBankDetails = new ProfileBankDetails();					 
				profileBankDetails.setSrNo(profileBankDetailsStrArr[0]);			
			    profileBankDetails.setParticular(profileBankDetailsStrArr[1]);		
				profileBankDetails.setDpi(profileBankDetailsStrArr[2]); 	
				profileBankDetailsList.add(profileBankDetails);
		 }
		 
		 for(String profileBankDetailsStr :profileBankDetailsA){			 
			String[] profileBankDetailsStrArr=profileBankDetailsStr.split(":");
			String[] parameterValue = null;
			String[] parameterValue1 = null;
			if(profileBankDetailsStrArr[2]!=null && profileBankDetailsStrArr[2].contains("##")) {
				parameterValue =  parameterMap.get(profileBankDetailsStrArr[2].split("##")[0]);
				parameterValue1 =  parameterMap.get(profileBankDetailsStrArr[2].split("##")[1]);
			}else
				parameterValue =  parameterMap.get(profileBankDetailsStrArr[2]);
		// "15:Number of Branches / ROs visited during inspection:BOM-678##CONTROFFCOUNT"};
			ProfileBankDetails profileBankDetails = new ProfileBankDetails();				
			profileBankDetails.setSrNo(profileBankDetailsStrArr[0]);			
			profileBankDetails.setParticular(profileBankDetailsStrArr[1]);	
			if(parameterValue!=null){					
				profileBankDetails.setDpi(parameterValue[1]); 
				if(parameterValue1!=null)profileBankDetails.setDpi(profileBankDetails.getDpi()+" / "+parameterValue1[1]);
			}			
			profileBankDetailsList.add(profileBankDetails);			
		 } 
		 
		 ProfileDetails  profileDetails = new ProfileDetails();
		 profileDetails.setProfileBankDetails(profileBankDetailsList); 
		 profileDetails.setSrNo("");
		 profileDetails.setParticular("");
		 profileDetails.setDli("DLI");
		 profileDetails.setDpi("DPI");
		 profileDetailsListA.add(profileDetails);	 
		  
		 for(String profileDetailsStr :profileDetailsA1){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }			 
			 profileDetailsListA.add(profileDetailsX);			 
		 } 
		 profileA.setProfileDetails(profileDetailsListA);
		 profileA.setAlphaBetSequence(alphaBetSequenceList);
		 profileA.setAlphaBetSequenceWithDliDpi(alphaBetSequenceWithDliDpiList);
		// profileA.setDpi("AAAAAAAAAAA");
		 profileA.setPageNumber("1");
		 profileList.add(profileA);
		 
		 Profile profileB = new Profile();
		 List<ProfileDetails>  profileDetailsListB = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsB){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI");
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){  
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 } 
			 profileDetailsListB.add(profileDetailsX);		 
		 }//profileB.setProfileDetails(profileDetailsListB);
		// profileB.setDpi("BBBBBBBBBB");
		 
		 
		/* Profile profileC = new Profile();*/
		 List<ProfileDetails>  profileDetailsListC = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsC){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListC.add(profileDetailsX);			 
		}//profileC.setProfileDetails(profileDetailsListC);
		// profileC.setDpi("CCCCCCCC");
		// profileList.add(profileC);
		 profileDetailsListB.addAll(profileDetailsListC);
		 profileB.setProfileDetails(profileDetailsListB);
		 profileB.setAlphaBetSequence(alphaBetSequenceList);
		 profileB.setAlphaBetSequenceWithDliDpi(alphaBetSequenceWithDliDpiList);
		 profileB.setPageNumber("2");
		 profileList.add(profileB);
		 
		 Profile profileD = new Profile();
		 List<ProfileDetails>  profileDetailsListD = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsD){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListD.add(profileDetailsX);			 
		 }
		 profileD.setProfileDetails(profileDetailsListD);
		 profileD.setAlphaBetSequence(alphaBetSequenceList);
		 profileD.setAlphaBetSequenceWithDliDpi(alphaBetSequenceWithDliDpiList);
		 profileD.setPageNumber("3");
		// profileD.setDpi("DDDDDDDDDDDDDD");
		 profileList.add(profileD);
		 
		 Profile profileE = new Profile();
		 List<ProfileDetails>  profileDetailsListE = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsE){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListE.add(profileDetailsX);			  
		 } 
		 
		// Profile profileF = new Profile();
		 List<ProfileDetails>  profileDetailsListF = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsF){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else  if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListF.add(profileDetailsX);			 
		 } 
		 
		// Profile profileG = new Profile();
		 List<ProfileDetails>  profileDetailsListG = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsG){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListG.add(profileDetailsX);			 
		 } 
		 
		// Profile profileH = new Profile();
		 List<ProfileDetails>  profileDetailsListH = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsH){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListH.add(profileDetailsX);			 
		 } 
		 
		// Profile profileI = new Profile();
		 List<ProfileDetails>  profileDetailsListI = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsI){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));			 
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListI.add(profileDetailsX);
		 } 
		 
		// Profile profileJ = new Profile();
		 List<ProfileDetails>  profileDetailsListJ = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsJ){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListJ.add(profileDetailsX);
			 
		 } 
		 
		// Profile profileK = new Profile();
		 List<ProfileDetails>  profileDetailsListK = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsK){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListK.add(profileDetailsX);
		 } 
		 
		// Profile profileL = new Profile();
		 List<ProfileDetails>  profileDetailsListL = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsL){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListL.add(profileDetailsX);
		 }
		 profileDetailsListE.addAll(profileDetailsListF);
		 profileDetailsListE.addAll(profileDetailsListG);
		 profileDetailsListE.addAll(profileDetailsListH);
		 profileDetailsListE.addAll(profileDetailsListI);
		 profileDetailsListE.addAll(profileDetailsListJ);
		 profileDetailsListE.addAll(profileDetailsListK);
		 profileDetailsListE.addAll(profileDetailsListL);		 
		 
		 profileE.setProfileDetails(profileDetailsListE);	
		 profileE.setAlphaBetSequence(alphaBetSequenceList); 
		 profileE.setAlphaBetSequenceWithDliDpi(alphaBetSequenceWithDliDpiList);
		 profileE.setPageNumber("4");
		 profileList.add(profileE);
		 
		  
		 List<ProfileDetails>  profileDetailsListM = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsM){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListM.add(profileDetailsX);
		 } 
		  
		 List<ProfileDetails>  profileDetailsListN = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsN){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListN.add(profileDetailsX);
		 } 
		  
		 List<ProfileDetails>  profileDetailsListO = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsO){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListO.add(profileDetailsX);
		 } 
		 
		 
		 List<ProfileDetails>  profileDetailsListP = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsP){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListP.add(profileDetailsX);
		 } 		 
		  
		 List<ProfileDetails>  profileDetailsListQ = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsQ){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListQ.add(profileDetailsX);
		 } 
		 
		 List<ProfileDetails>  profileDetailsListR = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsR){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListR.add(profileDetailsX);
		 } 
		 
		 List<ProfileDetails>  profileDetailsListS = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsS){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListS.add(profileDetailsX);
		 } 
		 
		 List<ProfileDetails>  profileDetailsListT = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsT){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();	
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);		
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){ 
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListT.add(profileDetailsX);
		 } 
		 
		 List<ProfileDetails>  profileDetailsListU = new ArrayList<>();
		 for(String profileDetailsStr :profileDetailsU){
			 String[] profileDetailStrArr = profileDetailsStr.split(":");
			 String[] parameterValue =  parameterMap.get(profileDetailStrArr[2].substring(1));
			 ProfileDetails  profileDetailsX = new ProfileDetails();
			 profileDetailsX.setSrNo(profileDetailStrArr[0]);
			 profileDetailsX.setParticular(profileDetailStrArr[1]);
			 if(profileDetailStrArr[2].equalsIgnoreCase("DLI")){
				 profileDetailsX.setDpi("DPI"); 
				 profileDetailsX.setDli("DLI");  
			 }			
			 else if(parameterValue!=null){
				 profileDetailsX.setDli(parameterValue[0]);
				 profileDetailsX.setDpi(parameterValue[1]);
			 }
			 profileDetailsListU.add(profileDetailsX);
		 }  
		 
		 profileDetailsListM.addAll(profileDetailsListN);
		 profileDetailsListM.addAll(profileDetailsListO);
		 profileDetailsListM.addAll(profileDetailsListP);
		 profileDetailsListM.addAll(profileDetailsListQ);
		 profileDetailsListM.addAll(profileDetailsListR);
		 profileDetailsListM.addAll(profileDetailsListS);
		 profileDetailsListM.addAll(profileDetailsListT);
		 profileDetailsListM.addAll(profileDetailsListU);
		// profileDetailsListM.addAll(profileDetailsListV);
		  
		 Profile profileM = new Profile();
		 profileM.setProfileDetails(profileDetailsListM); 
		 profileM.setAlphaBetSequence(alphaBetSequenceList);
		 profileM.setAlphaBetSequenceWithDliDpi(alphaBetSequenceWithDliDpiList);
		 profileM.setPageNumber("5");
	     profileList.add(profileM);			 
	     
		 return profileList;		 
	 }
	  
	 
	 /**************** Generation of Profile End **************/
	 
	 /**************** finalized IR/CR/SR Start****************/
	 private String saveAuditReports(int legalEntityCode, String auditTypeCode, String auditId, String planId, String reportCode, String referencePath, 
			 String fileName,  String unitId, String userId){
		  
		 auditBookReportDaoV3.updateFinalizedReportStatus(legalEntityCode, auditId, auditTypeCode, reportCode);
			//try{
				AuditLetterReportDocumentDetails auditLettersReportsDocumentDetails =  new AuditLetterReportDocumentDetails();
				auditLettersReportsDocumentDetails.setLegalEntityCode(legalEntityCode);
				auditLettersReportsDocumentDetails.setAuditTypeCode(auditTypeCode); 
				auditLettersReportsDocumentDetails.setAuditId(auditId);
				auditLettersReportsDocumentDetails.setPlanId(planId);
				auditLettersReportsDocumentDetails.setUnitId(unitId);  		
				auditLettersReportsDocumentDetails.setDocumentType("Report");  
				auditLettersReportsDocumentDetails.setDocumentName(reportCode);   
				auditLettersReportsDocumentDetails.setMaker(userId);  			 
				auditLettersReportsDocumentDetails.setMakerTimestamp(businessDateService.getBusinessDateTimestampByLegalEntityCode(legalEntityCode));
				auditLettersReportsDocumentDetails.setUserRoleId("");					
				auditLettersReportsDocumentDetails.setLetterCode(reportCode); 
				auditLettersReportsDocumentDetails.setChecker(userId);
				auditLettersReportsDocumentDetails.setCheckerTimestamp(businessDateService.getBusinessDateTimestampByLegalEntityCode(legalEntityCode));
				auditLettersReportsDocumentDetails.setStatus(BankAuditConstant.STATUS_ACTIVE);
				auditLettersReportsDocumentDetails.setAuthRejRemarks("");
				auditLettersReportsDocumentDetails.setReferencePath(referencePath); 
				auditLettersReportsDocumentDetails.setFileName(fileName);			
				auditBookReportDaoV3.save(auditLettersReportsDocumentDetails);			
			/*}catch (Exception e) {
				logger.error("Error .." + e.getMessage()+" :: "+e.getCause());
				return  BankAuditConstant.FAILED;
			}*/
			return BankAuditConstant.SUCCESS;		
		}
	 
	 @Override
	 public String getFinalizedReport(Integer legalEntityCode, String auditId, String auditTypeCode, String reportCode){
		 return auditBookReportDaoV3.getFinalizedReport(legalEntityCode, auditId, auditTypeCode, reportCode);
	 }
	 /****************  finalized IR/CR/SR End****************/
	 
	 /******************Start out standing ITISI****************/
	 
	 @Override
		public String generateOutStandingReport(Map<String, Object> params, Integer legalEntityCode, String auditId, String auditTypeCode, String userId, Boolean isFinalReport,
				String planId,  String unitId, String reportCode, String reportLanguage, String role ){
			try{
				logger.info("generateOutStandingReport() called...");
			
				String jasperReportName ="ReportOutStandingMaster.jasper";   			
				String jasperReportPath = "/reports/";
				String jasperSubReportPath = "/reports/IR_Reports/"; 
				
				AuditBookReportDataModel auditBookReportDataModel = processOutstandingReport(legalEntityCode+"", auditId, auditTypeCode);
				List<AuditBookReportDataModel> JasperDataBean = new ArrayList<>();
				JasperDataBean.add(auditBookReportDataModel);
				
				String uploadFileName = legalEntityCode+"_"+auditId+"_"+auditTypeCode+"_OutStandingReport"+".pdf";
				String outStandingFile = BankAuditConfig.getInstance().getConfigValue(BankAuditConstant.DIR_DOC_UPLOAD_JASPER_TMP)+ "/" +uploadFileName;
				 			
				params.put("SUB_REPORT_DIR", jasperSubReportPath); 	
				params.put("REPORT_CODE", BankAuditConstant.REPORT_CODE_IR); 
				params.put("isAbridgedReport", "N");
				params.put("hasProfile", true);
				params.put("auditTypeCode", auditTypeCode);
				params.put("OTHERS_CH_SC_PD_PC_CK", "");
				params.put("hasIndex", false);		
				params.put("PRINT_PRODUCT", false);	 
							
				InputStream stream = this.getClass().getResourceAsStream(jasperReportPath + jasperReportName);			 
				//JasperReport jasperReport = JasperCompileManager.compileReport(stream);
				JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(JasperDataBean);
				JasperPrint print = JasperFillManager.fillReport(stream, params, dataSource);			 
				
				JasperExportManager.exportReportToPdfFile(print,outStandingFile);				 
				System.out.println("uploadPath .. "+ outStandingFile);
				return outStandingFile;				 	
				 
			} catch (JRException  e) {
				e.printStackTrace();
			}catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		}
	 
	    private AuditBookReportDataModel processOutstandingReport(String legalEntityCode, String auditId, String auditTypeCode){ 
	    	
	    	List<SectionDto>  sectionDataList = auditBookReportDaoV3.getOutstandingSection(legalEntityCode, auditTypeCode, auditId);
			Map<String,String> productData = auditBookReportDaoV3.getProduct(legalEntityCode, auditId, auditTypeCode);
			Map<String,String> processData = auditBookReportDaoV3.getProcess(legalEntityCode, auditId, auditTypeCode);
			
			Map<String,String> outstandingChecklist = auditBookReportDaoV3.getOutstandingChecklist(legalEntityCode, auditTypeCode, auditId);
			Map<String,String> outstandingStandardStmt = auditBookReportDaoV3.getOutstandingStandardStmt(legalEntityCode, auditTypeCode, auditId);
			Map<String,String> outstandingRemarks = auditBookReportDaoV3.getOutstandingRemarks(legalEntityCode, auditTypeCode, auditId);
					 
			int sectionSeq  = 1;
			int productSeq  = 1;		 
			int standardStmtSeqIndex = 0;
			boolean isStandardStmtSequence =false; 		
			boolean isSectionDetailsAvail =false; 
			boolean isProductDetailsAvail =false;  
	 
			List<SectionDto>  listSectionDtoUpdated = new ArrayList<SectionDto>(); 
			for (SectionDto sectionDto : sectionDataList) {
				isSectionDetailsAvail=false; 
				sectionDto.setSequenceNumber(sectionSeq+"."); 				
				String auditGroupCode = sectionDto.getAuditGroupCode(); 	
				String auditSubGroupCode = auditGroupCode+sectionDto.getAuditSubGroupCode(); 	
				String[] product = productData.get(auditSubGroupCode)!=null?productData.get(auditSubGroupCode).split("#@::@#"):null; 
				SortedMap<Integer, String> listProductDto = sortedArray(product);
				List<ProductDto> listProductDtoUpdated = new ArrayList<ProductDto>(); 
				standardStmtSeqIndex = 1; 
				for(Map.Entry<Integer, String> productDto : listProductDto.entrySet()){
					String[] productRec=productDto.getValue().split("#::#");
					String productName = productRec[2]; 
					isProductDetailsAvail=false; 						
					String activityCode = auditSubGroupCode+productRec[1];							
					ProductDto productDtoUpdate = new ProductDto();
					productDtoUpdate.setSequenceNumber(sectionSeq+"."+productSeq+".");  
					productDtoUpdate.setActivityCode(productRec[1]);
					productDtoUpdate.setProductName(productName);			 
					
					String[] process = processData.get(activityCode)!=null?processData.get(activityCode).split("#@::@#"):null; 
					SortedMap<Integer, String> listProcessDto = sortedArray(process);
					List<ProcessDto> listProcessDtoUpdated = new ArrayList<ProcessDto>();
					  
					for (Map.Entry<Integer, String> processDto : listProcessDto.entrySet()) {
						String[] processRec=processDto.getValue().split("#::#");  
						String processCode = activityCode+processRec[1];
						ProcessDto processDtoUpdate = new ProcessDto();
						 	    
						List<CheckListDto>  listCheckListDtoUpdated = new ArrayList<CheckListDto>();
						//standardStmtSeqIndex = 1; 						  	 							  
						String[] cheklistPartA = outstandingChecklist.get(processCode)!=null?outstandingChecklist.get(processCode).split("#@::@#"):null; 
						SortedMap<Integer, String> listCheckListDto = sortedArray(cheklistPartA); 
						for (Map.Entry<Integer, String> checkListDto : listCheckListDto.entrySet()) {
							String[] checklistRec=checkListDto.getValue().split("#::#");										 
							isStandardStmtSequence = false;
							String findingCode = processCode+checklistRec[1]; 
							CheckListDto checkListDtoUpdate = new CheckListDto();											 
							checkListDtoUpdate.setChecklist("");										 
						
							//get Standard statement										 
							if(outstandingStandardStmt!=null && outstandingStandardStmt.size()>0 && outstandingStandardStmt.get(findingCode)!=null){
								String  standardStatement = outstandingStandardStmt.get(findingCode).split("#::#")[0];
								String  standardStatementHindi = outstandingStandardStmt.get(findingCode).split("#::#")[1];
								if(!BankAuditUtil.isEmptyString(standardStatement) && !standardStatement.equalsIgnoreCase("null")){
									checkListDtoUpdate.setStandardStatement(standardStatement.trim());
									checkListDtoUpdate.setStandardStatementHindi(standardStatementHindi.trim());
									checkListDtoUpdate.setSequenceNumberStandardStmt(sectionSeq+"."+standardStmtSeqIndex);
									standardStmtSeqIndex++;
									isStandardStmtSequence = true;								
									isProductDetailsAvail = true;
									isSectionDetailsAvail = true;									 											  
								} 	
							}
							//get remarks 
							if(outstandingRemarks!=null && outstandingRemarks.size()>0 && outstandingRemarks.get(findingCode)!=null){
								String  remarks =  outstandingRemarks.get(findingCode).split("#::#")[0];
								String  remarksHindi =  outstandingRemarks.get(findingCode).split("#::#")[1];
								if((!BankAuditUtil.isEmptyString(remarks) &&  !remarks.equalsIgnoreCase("null")) 
										|| (!BankAuditUtil.isEmptyString(remarksHindi) &&  !remarksHindi.equalsIgnoreCase("null"))){
									checkListDtoUpdate.setRemarks(remarks.trim());
									checkListDtoUpdate.setRemarksHindi(remarksHindi.trim());
									if(!isStandardStmtSequence){
										checkListDtoUpdate.setSequenceNumberRemarks(sectionSeq+"."+standardStmtSeqIndex);
										standardStmtSeqIndex++;
										isStandardStmtSequence = false;										 
										isProductDetailsAvail = true;
										isSectionDetailsAvail = true;												  
									}
								}  
							}
							listCheckListDtoUpdated.add(checkListDtoUpdate);											 									 
						}						 							  
						processDtoUpdate.setCheckList(listCheckListDtoUpdated);
						listProcessDtoUpdated.add(processDtoUpdate); 
					}				
					productDtoUpdate.setProcessList(listProcessDtoUpdated);
					if(isProductDetailsAvail){
						listProductDtoUpdated.add(productDtoUpdate);
						productSeq++;
					} 						
				} 
			
				sectionDto.setProductList(listProductDtoUpdated);						 
				if(isSectionDetailsAvail){
					listSectionDtoUpdated.add(sectionDto);
					sectionSeq++;
				}		
			}
			
			AuditBookReportDataModel auditBookReportDataModel = new AuditBookReportDataModel();
			auditBookReportDataModel.setSectionDtoOutStandingReportList(listSectionDtoUpdated);
			
			Object[] auditData= auditBookReportDaoV3.getCoverPageDynamicData(Integer.parseInt(legalEntityCode), auditId);
			Map<String, String> auditDetailsMap = new HashMap<>();
			if(auditData!=null && auditData.length>0){
				auditDetailsMap.put("bankName", auditData[1].toString());
				auditDetailsMap.put("actualStartDate", BankAuditUtil.parseDateToString((Date)auditData[14], "dd-MM-yyyy"));
				auditDetailsMap.put("actualEndDate", BankAuditUtil.parseDateToString((Date)auditData[15], "dd-MM-yyyy"));			
				auditDetailsMap.put("reportDispatchDate", BankAuditUtil.parseDateToString((Date)auditData[6], "dd-MM-yyyy"));
			}
			auditBookReportDataModel.setAuditDetailsMap(auditDetailsMap);		
			return auditBookReportDataModel;
	    }
	    
	 /******************End out standing ITISI****************/
	 
	 
	 /**************** To Generate Roman Number Start *********************/
	  private  String getRoman(Integer number){		  
		  int l =  romanNumMap.floorKey(number);
	        if ( number == l ) {
	            return romanNumMap.get(number);
	        }
	        return romanNumMap.get(l) + getRoman(number-l);		  
	  }
	 
	  private final static TreeMap<Integer, String> romanNumMap = new TreeMap<Integer, String>();
	    static {
	    	romanNumMap.put(1000, "M");
	    	romanNumMap.put(900, "CM");
	    	romanNumMap.put(500, "D");
	    	romanNumMap.put(400, "CD");
	    	romanNumMap.put(100, "C");
	    	romanNumMap.put(90, "XC");
	    	romanNumMap.put(50, "L");
	    	romanNumMap.put(40, "XL");
	    	romanNumMap.put(10, "X");
	    	romanNumMap.put(9, "IX");
	        romanNumMap.put(5, "V");
	        romanNumMap.put(4, "IV");
	        romanNumMap.put(1, "I");
	    }
	    /**************** To Generate Roman Number End *********************/
	    
    private  String getSuperScript(Integer number){	 
    	if(number>=10 && number<=20){
    		return "th";	
    	}
    	number = number%10;
    	switch (number){
	    	case 1 :
	    		return "st";
	    	case 2 :
	    		return "nd";
	    	case 3 :
	    		return "rd";		    		
	    	default: 
	    		return "th";	
    	}
	} 
    
    private  SortedMap<Integer, String> sortedArray(String[] unsortedArray){
		if(unsortedArray==null){
			return new TreeMap<Integer, String>();
		} 
		 
		SortedMap<Integer, String> sortedStatements =  new TreeMap<Integer, String>();
    	for(String string : unsortedArray) {				
    		sortedStatements.put(Integer.parseInt(string.split("#::#")[0]), string);
		} 
		
		return sortedStatements;
	} 
    
    private  List<String> sortedDerivedStaticStmt(String[] unsortedArray){
		if(unsortedArray==null){
			return new ArrayList<String> ();
		} 
		 
		SortedMap<Integer, String> sortedStatements =  new TreeMap<Integer, String>();
    	for(String stmt : unsortedArray) {	
    		String[] stmtArr = stmt.split("#::#");
    		sortedStatements.put(Integer.parseInt(stmtArr[0]), stmtArr[1]);
		} 
		
    	List<String> sortedStatementList = new ArrayList<String>(sortedStatements.values());
    	
		return sortedStatementList;
	} 
    private  List<String> sortedDerivedStaticStmtHindi(String[] unsortedArray){
		if(unsortedArray==null){
			return new ArrayList<String> ();
		} 
		 
		SortedMap<Integer, String> sortedStatements =  new TreeMap<Integer, String>();
    	for(String stmt : unsortedArray) {	
    		String[] stmtArr = stmt.split("#::#");
    		if(stmtArr.length==3 && stmtArr[2]!=null && !stmtArr[2].trim().equalsIgnoreCase("null") && !stmtArr[2].trim().equalsIgnoreCase("") ){
    			sortedStatements.put(Integer.parseInt(stmtArr[0]), stmtArr[2]);
    		}
		} 
		
    	List<String> sortedStatementList = new ArrayList<String>(sortedStatements.values());
    	
		return sortedStatementList;
	} 
    
    private String getReportPathByReportLanguage(String reportLanguage, String  auditTypeCode ){
    	
    	String pathAppender = "/";;
    	if(BankAuditConstant.REPORT_LANGUAGE_HI.equalsIgnoreCase(reportLanguage)){
    		pathAppender = "_RajBhasha/";
    	}	    	
    	
    	String jasperReportName ="IRReport.jrxml";
		String jasperReportPath = "/reports/RRB_IR_Report"+pathAppender;
		String jasperSubReportPath = "/reports/RRB_IR_Report"+pathAppender;
		String jasperProfileName = "Profile.jrxml";
		if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_DCCB_CONTAIN)){
			jasperReportPath = "/reports/DCCB_IR_Report"+pathAppender+"DCCB_";
			jasperSubReportPath = "/reports/DCCB_IR_Report"+pathAppender; 
		}else if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_StCB_CONTAIN)){
			jasperReportPath = "/reports/StCB_IR_Report"+pathAppender+"StCB_";
			jasperSubReportPath = "/reports/StCB_IR_Report"+pathAppender; 
		}else if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_SCARDB_CONTAIN)){
			jasperReportPath = "/reports/SCARDB_IR_Report"+pathAppender+"SCARDB_";
			jasperSubReportPath = "/reports/SCARDB_IR_Report"+pathAppender; 
		}else if(auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_BRANCHI)
				|| auditTypeCode.startsWith(BankAuditConstant.INSPECTION_TYPE_ITISI)){				
			jasperReportPath = "/reports/IR_Reports"+pathAppender;
			jasperSubReportPath = "/reports/IR_Reports"+pathAppender;
		}
		 
		return jasperReportName+"##"+jasperReportPath+"##"+jasperSubReportPath+"##"+jasperProfileName;
    	
    }
    
}
