Files
matrix/src/matrix/nimble/operation/output/model/PartWiseReporting.java
2025-04-19 17:50:17 +05:30

464 lines
19 KiB
Java

package matrix.nimble.operation.output.model;
import java.io.File;
import java.util.Hashtable;
import java.util.Set;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Image;
import matrix.nimble.utilities.DBFunctions;
import matrix.nimble.utilities.GlobalClass;
import matrix.nimble.utilities.PDFFormatter;
public class PartWiseReporting {
private String ErrMsg;
private String ErrDesc;
private String ErrCode;
private boolean ProcessFlag;
private String UserId;
private String PrevBranch;
private String CurBranch;
private Image QRCodeFile;
private String FileName;
private String FilePath;
private String SignPath;
private PDFFormatter PDFFile;
private Hashtable<String, String> QValsTab;
public String getErrMsg() {
return ErrMsg;
}
public void setErrMsg(String errMsg) {
ErrMsg = errMsg;
}
public String getErrDesc() {
return ErrDesc;
}
public void setErrDesc(String errDesc) {
ErrDesc = errDesc;
}
public String getErrCode() {
return ErrCode;
}
public void setErrCode(String errCode) {
ErrCode = errCode;
}
public boolean isProcessFlag() {
return ProcessFlag;
}
public void setProcessFlag(boolean processFlag) {
ProcessFlag = processFlag;
}
public PDFFormatter getPDFFile() {
return PDFFile;
}
public void setPDFFile(PDFFormatter pDFFile) {
PDFFile = pDFFile;
}
public String getPrevBranch() {
return PrevBranch;
}
public void setPrevBranch(String prevBranch) {
PrevBranch = prevBranch;
}
public String getCurBranch() {
return CurBranch;
}
public void setCurBranch(String curBranch) {
CurBranch = curBranch;
}
public String getFileName() {
return FileName;
}
public void setFileName(String fileName) {
FileName = fileName;
}
public String getFilePath() {
return FilePath;
}
public void setFilePath(String filePath) {
FilePath = filePath;
}
public String getSignPath() {
return SignPath;
}
public void setSignPath(String signPath) {
SignPath = signPath;
}
public Image getQRCodeFile() {
return QRCodeFile;
}
public void setQRCodeFile(Image qRCodeFile) {
QRCodeFile = qRCodeFile;
}
public Hashtable<String, String> getQValsTab() {
return QValsTab;
}
public void setQValsTab(Hashtable<String, String> qValsTab) {
QValsTab = qValsTab;
}
public String getUserId() {
return UserId;
}
public void setUserId(String userId) {
UserId = userId;
}
public void GenerateBankReports(ReportSettings RS,BankReportHandler RFH,String UserId,String BranchId)
{
Hashtable<String, String> QValsTab=new Hashtable<String, String>();
setQValsTab(QValsTab);
setUserId(UserId);
BankReportHandler rfh=RFH;
ReportSettings rs=RS;
setSignPath(rfh.getSignPath());
if(rfh.getRreport()!=null && rfh.getRreport().length > 0)
{
CreateReport(rfh.getRreport(),rfh.getResilayout(),"RES",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(rfh.getOreport()!=null && rfh.getOreport().length > 0)
{
CreateReport(rfh.getOreport(),rfh.getOfflayout(),"OFF",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(rfh.getOsareport()!=null && rfh.getOsareport().length > 0)
{
CreateReport(rfh.getOsareport(),rfh.getOffsalayout(),"OFF",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(rfh.getTreport()!=null && rfh.getTreport().length > 0)
{
CreateReport(rfh.getTreport(),rfh.getTvrlayout(),"TEL",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(rfh.getRtreport()!=null && rfh.getRtreport().length > 0)
{
CreateReport(rfh.getRtreport(),rfh.getReflayout(),"REF",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(rfh.getPreport()!=null && rfh.getPreport().length > 0)
{
CreateReport(rfh.getPreport(),rfh.getProplayout(),"OTH",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(rfh.getDdreport()!=null && rfh.getDdreport().length > 0)
{
CreateReport(rfh.getDdreport(),rfh.getDedlayout(),"DED",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(rfh.getExtrareport()!=null && rfh.getExtrareport().length > 0)
{
CreateReport(rfh.getExtrareport(),rfh.getExtralayout(),"EXT",rfh.getRootPath(),rfh.getCurDate(),rfh.getProcessedOn(),rs.getReportby(),rs.getReporttype(),UserId,BranchId,RS.isArchivebatch(),rfh.getRunningmode(),RS.getPortfolioid());
}
if(isProcessFlag())
{
FinalizeBanklist(getQValsTab(), RS.isAutoemail(),RFH.getProcessedOn(),BranchId,RFH.getRunningmode());
}
if(isProcessFlag())
{
setErrMsg(getErrCode()+"REPGEN:Info:Reports generated successfully."+(RS.isAutoemail() ? "\n\nEmail sent successfully.\n" : ""));
}
}
private boolean CreateReport(String [][] reportData,String [][] reportlayout,String reportType,String rootPath,String curDate,String processedOn,String reportBy,String repType,String UserId,String BranchId,boolean isArchive,String runningMode,String portfolioid)
{
String subPath="";
String Uuids="";
setPrevBranch("");
setFilePath("");
String filePrefix="";
PDFFormatter PDFF=new PDFFormatter();
PDFF.setErrCode(getErrCode());
PDFF.setProcessFlag(true);
for(int Index=0;Index<reportData.length;Index++)
{
Uuids=reportData[Index][0];
filePrefix=repType.equals("1") ? (reportData[Index][6].replaceAll("/| |&", "_")+"_"+reportData[Index][5].replaceAll("\\s", "_")+"_") : "";
if(reportBy.equals("1"))
{
setCurBranch(reportData[Index][3]+""+reportData[Index][1]+""+filePrefix);
subPath=(reportData[Index][3].replaceAll("\\s", "_"))+"/"+(processedOn.replaceAll("/| |:", "_"))+"/"+(reportData[Index][1].replaceAll("\\s", "_"));
}
else if(reportBy.equals("2"))
{
setCurBranch(reportData[Index][3]+""+reportData[Index][5]+""+filePrefix);
subPath=(reportData[Index][3].replaceAll("\\s", "_"))+"/"+(processedOn.replaceAll("/| |:", "_"))+"/"+(reportData[Index][5].replaceAll("\\s", "_"));
}
else if(reportBy.equals("3"))
{
setCurBranch(reportData[Index][3]+""+reportData[Index][1]+""+reportData[Index][5]+""+filePrefix);
subPath=(reportData[Index][3].replaceAll("\\s", "_"))+"/"+(processedOn.replaceAll("/| |:", "_"))+"/"+(reportData[Index][1].replaceAll("\\s", "_"))+"/"+(reportData[Index][5].replaceAll("\\s", "_"));
}
else
{
setCurBranch(reportData[Index][3]+""+filePrefix);
subPath=(reportData[Index][3].replaceAll("\\s", "_"))+"/"+(processedOn.replaceAll("/| |:", "_"));
}
if (getQValsTab().containsKey(rootPath+curDate+"/"+portfolioid+"/"+subPath+"/"))
{
Uuids=Uuids+","+getQValsTab().get(rootPath+curDate+"/"+portfolioid+"/"+subPath+"/").split(GlobalClass.ColDelim)[1];
}
QValsTab.put(rootPath+curDate+"/"+portfolioid+"/"+subPath+"/", processedOn+GlobalClass.ColDelim+Uuids+GlobalClass.ColDelim+(rootPath+curDate+"/"+portfolioid+"/"+subPath+"/")+GlobalClass.ColDelim+UserId+GlobalClass.ColDelim+BranchId+GlobalClass.ColDelim+reportData[Index][7]+GlobalClass.ColDelim+(isArchive ? "1":"0")+GlobalClass.ColDelim+runningMode+GlobalClass.ColDelim);
if(!getCurBranch().equals(getPrevBranch()))
{
if(PDFF.getOutput()!=null)
{
PDFF.closeDocument();
}
setFilePath(rootPath+curDate+"/"+portfolioid+"/"+subPath+"/");
if(CreateDirectory(getFilePath()))
{
CreateReportFile(reportType, PDFF,filePrefix);
if(!isProcessFlag())
{
return false;
}
}
else
{
setProcessFlag(false);
return false;
}
setPrevBranch(getCurBranch());
}
PDFF.createTable(120);
PDFF.setFontBlack();
DesignReport(reportData[Index],reportlayout,PDFF);
PDFF.addTable();
PDFF.addPageBreak();
PDFF.createTable(120);
}
if(PDFF.getOutput()!=null)
{
PDFF.closeDocument();
}
return true;
}
private void DesignReport(String [] reportData,String [][] reportlayout,PDFFormatter PDFF)
{
int layoutIndex=0;
for(int cindx=8;cindx<reportData.length;cindx++)
{
Image img=null;
PDFF.SetFont(reportlayout[layoutIndex][13], Integer.parseInt(reportlayout[layoutIndex][11]));
PDFF.setFontColor(new BaseColor(Integer.parseInt(reportlayout[layoutIndex][12].split(",")[0]), Integer.parseInt(reportlayout[layoutIndex][12].split(",")[1]), Integer.parseInt(reportlayout[layoutIndex][12].split(",")[2])));
PDFF.setBackColor(new BaseColor(Integer.parseInt(reportlayout[layoutIndex][14].split(",")[0]), Integer.parseInt(reportlayout[layoutIndex][14].split(",")[1]), Integer.parseInt(reportlayout[layoutIndex][14].split(",")[2])));
PDFF.setBorderColor(new BaseColor(Integer.parseInt(reportlayout[layoutIndex][16].split(",")[0]), Integer.parseInt(reportlayout[layoutIndex][16].split(",")[1]), Integer.parseInt(reportlayout[layoutIndex][16].split(",")[2])));
PDFF.setBorderWidth(Integer.parseInt(reportlayout[layoutIndex][17]));
PDFF.setRounderCorners(reportlayout[layoutIndex][18]);
if(reportData[cindx].equals("{SK!PTH15D@TA}"))
{
layoutIndex++;
continue;
}
if(reportlayout[layoutIndex][2].equals("image"))
{
try
{
img=Image.getInstance(getSignPath()+""+reportData[cindx]);
int imgscale = Integer.parseInt(reportlayout[layoutIndex][11]);
if(imgscale > 30) {
img.scalePercent(imgscale);
}
}catch(Exception exce){
}
PDFF.createCell(img, Integer.parseInt(reportlayout[layoutIndex][3]), Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}
else if(reportlayout[layoutIndex][2].equals("barcode"))
{
PDFF.createBCodeCell(reportData[cindx], Integer.parseInt(reportlayout[layoutIndex][3]), Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}
else if(reportlayout[layoutIndex][2].equals("pagebreak"))
{
PDFF.addTable();
PDFF.addPageBreak();
PDFF.createTable(120);
}
else if(reportlayout[layoutIndex][2].equals("photographs"))
{
if(reportData[cindx].length() > 10)
{
String StoragePath = GlobalClass.getStoragePath();
reportData[cindx] = reportData[cindx].substring(0,reportData[cindx].length()-1);
String [] ImgArr = reportData[cindx].split(",");
File f = null;
int vimg=0;
for(int arrIndx=0; arrIndx < ImgArr.length; arrIndx++)
{
f=new File(StoragePath+ImgArr[arrIndx]);
if(f.exists())
{
try
{
img=Image.getInstance(StoragePath+ImgArr[arrIndx]);
img.scalePercent(30f);
PDFF.createCell(img, Integer.parseInt(reportlayout[layoutIndex][3]), Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
vimg++;
}catch(Exception exce){
System.out.println("Image Exception:" + exce.getMessage());
}
}
}
if(vimg != 0 && vimg%2 != 0)
{
PDFF.createCell("", Integer.parseInt(reportlayout[layoutIndex][3]), Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}
}
else
{
PDFF.createCell("NO IMAGE", Integer.parseInt(reportlayout[layoutIndex][3]), 120, Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],15,Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}
}else if(reportlayout[layoutIndex][2].equals("inlinephoto")) {
if(reportData[cindx].length() > 10)
{
try
{
String StoragePath = GlobalClass.getStoragePath();
img=Image.getInstance(StoragePath+reportData[cindx]);
int imgscale = Integer.parseInt(reportlayout[layoutIndex][11]);
if(imgscale >= 30) {
img.scalePercent(imgscale); //Using FontSize Layout Filed's value to scale the image
}
PDFF.createCell(img, Integer.parseInt(reportlayout[layoutIndex][3]), Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}catch(Exception exce) {
System.out.println(exce.getMessage());
PDFF.createCell("No Image Available", 1, Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}
}
}
else
{
int fstyle=Integer.parseInt(reportlayout[layoutIndex][3]);
if(reportData[cindx].toUpperCase().startsWith("<B>") && reportData[cindx].toUpperCase().endsWith("</B>"))
{
fstyle=1;
reportData[cindx]=reportData[cindx].replace("<b>", "");
reportData[cindx]=reportData[cindx].replace("</b>", "");
}
if(reportlayout[layoutIndex][2].equals("link")) { //To create data with hyperlink the data in reportData[cindx] should be delimited with '|' (pipe character) left side text on left side and link url on right
PDFF.createLinkCell(reportData[cindx], fstyle, Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}else if(reportlayout[layoutIndex][2].equals("chunk")){
PDFF.createChunkCell(reportData[cindx], fstyle, Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}else {
PDFF.createCell(reportData[cindx], fstyle, Integer.parseInt(reportlayout[layoutIndex][10]), Integer.parseInt(reportlayout[layoutIndex][4]),reportlayout[layoutIndex][8],Integer.parseInt(reportlayout[layoutIndex][9]),Integer.parseInt(reportlayout[layoutIndex][5]),Integer.parseInt(reportlayout[layoutIndex][7]),Integer.parseInt(reportlayout[layoutIndex][6]),Integer.parseInt(reportlayout[layoutIndex][15]));
}
}
layoutIndex++;
}
String disclaimer = " This report is based on information gathered by our field executive/telecaller";
disclaimer += " and Bank is requested to corelate the same with other documents/information on record/gathered";
disclaimer += " by the Bank in the course of complete due diligence/appraisal undertaken by the Bank.";
disclaimer += " Our report should not be the sole criteria for sanction of the loan under reference.";
PDFF.SetFont("TIMES", 6);
PDFF.setFontColor(new BaseColor(0,0,0));
//PDFF.createCell("Disclaimer:",5,8,3,"L",108,3,3,0,0);
//PDFF.createCell(disclaimer,0,112,3,"L",107,3,3,0,0);
PDFF.createCell("Disclaimer:",5,8,3,"L",0,3,3,0,0);
PDFF.createCell(disclaimer,0,112,3,"L",0,3,3,0,0);
}
private void CreateReportFile(String reportType,PDFFormatter PDFF,String filePrefix)
{
int i=0;
setFileName(filePrefix+reportType+"_REP_"+i+".pdf");
while(CheckFileExistence(getFilePath()+getFileName()))
{
i++;
setFileName(filePrefix+reportType+"_REP_"+i+".pdf");
}
if(isProcessFlag())
{
PDFF.CreateFile(getFilePath()+getFileName());
if(!PDFF.isProcessFlag())
{
setProcessFlag(false);
setErrDesc(PDFF.getErrDesc());
setErrMsg(PDFF.getErrMsg());
}
}
}
public void FinalizeBanklist(Hashtable<String, String> QValsTab,boolean isAutoemail,String processedOn,String BranchId,String runningMode)
{
DBFunctions dbf=new DBFunctions(getErrCode());
Set<String> keys=QValsTab.keySet();
for(String key : keys)
{
dbf.setProcessFlag(true);
String []Qvals=QValsTab.get(key).split(GlobalClass.ColDelim);
Qvals[1]="uuid=''"+Qvals[1].replace(",", "'' or uuid=''")+"''";
dbf.FetchRunQuery(118, Qvals);
if(!dbf.isProcessFlag())
{
setErrMsg(dbf.getErrMsg());
setErrDesc(dbf.getErrDesc());
setProcessFlag(dbf.isProcessFlag());
break;
}
}
if(!isProcessFlag())
{
setErrMsg(getErrMsg()+" Updation failed for some or all cases.");
}
else
{
if(isAutoemail)
{
SendReports SR=new SendReports();
SR.setErrCode(getErrCode());
SR.setProcessFlag(true);
SR.SendReportsByBatch(processedOn, BranchId, UserId,runningMode);
if (!SR.isProcessFlag())
{
setErrMsg(SR.getErrMsg().replace(getErrCode()+"SEML:warning:", getErrCode()+"SEML:warning:Bank Reports generated successfully.\n\n"));
setErrDesc(SR.getErrDesc());
setProcessFlag(SR.isProcessFlag());
}
}
}
}
private boolean CreateDirectory(String DirPath)
{
try
{
File f=new File(DirPath);
if(!f.isDirectory())
{
return f.mkdirs();
}
else
{
return true;
}
}catch(Exception exce)
{
setErrMsg(getErrCode()+"MKDIR:Error:"+exce.getMessage());
setErrDesc(exce.getLocalizedMessage());
setProcessFlag(false);
return false;
}
}
private boolean CheckFileExistence(String PathToFile)
{
try
{
File f=new File(PathToFile);
if(!f.isFile())
{
return false;
}
else
{
return true;
}
}catch(Exception exce)
{
setErrMsg(getErrCode()+"MKDIR:Error:"+exce.getMessage());
setErrDesc(exce.getLocalizedMessage());
setProcessFlag(false);
return false;
}
}
}