From 8c5c0ecbfa71c573128521c581a3d14164c98e5a Mon Sep 17 00:00:00 2001 From: Deepak Pansheriya Date: Wed, 7 Sep 2022 19:15:23 +0530 Subject: [PATCH] =?UTF-8?q?IDEMPIERE-5326:=20Parsing=20error=20for=20repor?= =?UTF-8?q?t=20view=20if=20where=20clause=20and=20vir=E2=80=A6=20(#1385)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * IDEMPIERE-5326: Parsing error for report view if where clause and virtual column used in print format * IDEMPIERE-5326: Fixing Compilation error * IDEMPIERE-5326: Adding method back for backward compitability * IDEMPIERE-5326: Adding constructors for backward compitability --- .../src/org/compiere/print/DataEngine.java | 37 +++++++-- .../src/org/compiere/print/ReportEngine.java | 77 +++++++++++++++++-- .../compiere/print/layout/LayoutEngine.java | 52 ++++++++++--- .../adempiere/webui/apps/ProcessDialog.java | 4 +- .../src/org/adempiere/webui/apps/WReport.java | 3 +- .../adempiere/webui/apps/form/WGenForm.java | 4 +- .../adempiere/webui/apps/form/WPayPrint.java | 4 +- .../webui/panel/action/ReportAction.java | 3 +- .../org/compiere/print/DrillReportCtl.java | 3 +- .../src/org/compiere/print/ReportCtl.java | 11 +-- 10 files changed, 155 insertions(+), 43 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/DataEngine.java b/org.adempiere.base/src/org/compiere/print/DataEngine.java index cf40731ce9..79da9109c3 100644 --- a/org.adempiere.base/src/org/compiere/print/DataEngine.java +++ b/org.adempiere.base/src/org/compiere/print/DataEngine.java @@ -86,18 +86,28 @@ public class DataEngine */ public DataEngine (Language language) { - this(language, null); + this(language, null, 0); } // DataEngine /** - * Constructor - * @param language Language of the data (for translation) - * @param trxName + * Constructor + * @param language + * @param trxName */ public DataEngine (Language language, String trxName){ + this(language,trxName,0); + } + /** + * Constructor + * @param language Language of the data (for translation) + * @param trxName + * @param windowNo + */ + public DataEngine (Language language, String trxName, int windowNo){ if (language != null) m_language = language; m_trxName = trxName; + m_windowNo = windowNo; } // DataEngine /** Logger */ @@ -123,6 +133,8 @@ public class DataEngine private boolean m_summary = false; /** Key Indicator in Report */ public static final String KEY = "*"; + /** Window No */ + private int m_windowNo = 0; private Map m_summarized = new HashMap(); @@ -188,7 +200,7 @@ public class DataEngine if (whereClause.indexOf("@") == -1) { queryCopy.addRestriction(whereClause); } else { // replace context variables - queryCopy.addRestriction(Env.parseContext(ctx, 0, whereClause.toString(), false, true)); + queryCopy.addRestriction(Env.parseContext(ctx, m_windowNo, whereClause.toString(), false, true)); } } } @@ -332,7 +344,7 @@ public class DataEngine if (ColumnSQL != null && ColumnSQL.length() > 0 && ColumnSQL.startsWith("@SQL=")) ColumnSQL = "NULL"; if (ColumnSQL != null && ColumnSQL.contains("@")) - ColumnSQL = Env.parseContext(Env.getCtx(), -1, ColumnSQL, false, true); + ColumnSQL = Env.parseContext(Env.getCtx(), m_windowNo, ColumnSQL, false, true); if (ColumnSQL == null) ColumnSQL = ""; else{ @@ -412,7 +424,7 @@ public class DataEngine if (script.startsWith("@SQL=")) { script = "(" + script.replace("@SQL=", "").trim() + ")"; - script = Env.parseContext(Env.getCtx(), 0, script, false); + script = Env.parseContext(Env.getCtx(), m_windowNo, script, false); } else script = "'@SCRIPT" + script + "'"; @@ -1384,7 +1396,16 @@ public class DataEngine MQuery query = new MQuery(); query.addRestriction("AD_Table_ID", MQuery.LESS, 105); } - + + public int getWindowNo() + { + return m_windowNo; + } + + public void setWindowNo(int windowNo) + { + this.m_windowNo = windowNo; + } } // DataEngine /** diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index d5bdc3c856..5cfe86d0ae 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -190,6 +190,34 @@ public class ReportEngine implements PrintServiceAttributeListener * @param trxName */ public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info, boolean isSummary, String trxName) + { + this(ctx, pf, query, info, false, trxName, 0); + } + + /** + * Set report engine with summary = false + * @param ctx + * @param pf + * @param query + * @param info + * @param trxName + * @param windowNo + */ + public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info, String trxName, int windowNo){ + this(ctx, pf, query, info, false, trxName, windowNo); + } + + /** + * Constructor + * @param ctx context + * @param pf Print Format + * @param query Optional Query + * @param info print info + * @param isSummary + * @param trxName + * @param windowNo + */ + public ReportEngine (Properties ctx, MPrintFormat pf, MQuery query, PrintInfo info, boolean isSummary, String trxName, int windowNo) { m_summary = isSummary; if (pf == null) @@ -200,6 +228,7 @@ public class ReportEngine implements PrintServiceAttributeListener m_printFormat = pf; m_info = info; m_trxName = trxName; + m_windowNo = windowNo; initName(); setQuery(query); // loads Data @@ -320,7 +349,7 @@ public class ReportEngine implements PrintServiceAttributeListener if (m_query == null) return; - DataEngine de = new DataEngine(m_printFormat.getLanguage(),m_trxName); + DataEngine de = new DataEngine(m_printFormat.getLanguage(),m_trxName, m_windowNo); setPrintData(de.getPrintData (m_ctx, m_printFormat, m_query, m_summary)); // m_printData.dump(); } // setPrintData @@ -356,7 +385,7 @@ public class ReportEngine implements PrintServiceAttributeListener throw new IllegalStateException ("No print format"); if (m_printData == null) throw new IllegalStateException ("No print data (Delete Print Format and restart)"); - m_layout = new LayoutEngine (m_printFormat, m_printData, m_query, m_info, m_trxName); + m_layout = new LayoutEngine (m_printFormat, m_printData, m_query, m_info, m_trxName, m_windowNo); } // layout /** @@ -1791,6 +1820,18 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) * @return report engine or null */ static public ReportEngine get (Properties ctx, ProcessInfo pi) + { + return get(ctx, pi, 0); + } + + /************************************************************************** + * Get Report Engine for process info + * @param ctx context + * @param pi process info with AD_PInstance_ID + * @param windowNo Window No + * @return report engine or null + */ + static public ReportEngine get (Properties ctx, ProcessInfo pi, int windowNo) { int AD_Client_ID = pi.getAD_Client_ID(); // @@ -1921,7 +1962,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) PrintInfo info = new PrintInfo (pi); info.setAD_Table_ID(AD_Table_ID); - return new ReportEngine(ctx, format, query, info, pi.isSummary(), pi.getTransactionName()); + return new ReportEngine(ctx, format, query, info, pi.isSummary(), pi.getTransactionName(), windowNo); } // get /*************************************************************************/ @@ -1976,7 +2017,19 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) */ public static ReportEngine get (Properties ctx, int type, int Record_ID) { - return get(ctx, type, Record_ID, null); + return get(ctx, type, Record_ID, null, 0); + } + + /************************************************************************** + * Get Document Print Engine for Document Type. + * @param ctx context + * @param type document type + * @param Record_ID id + * @return Report Engine or null + */ + public static ReportEngine get (Properties ctx, int type, int Record_ID, int windowNo) + { + return get(ctx, type, Record_ID, null, windowNo); } /************************************************************************** @@ -1988,6 +2041,20 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) * @return Report Engine or null */ public static ReportEngine get (Properties ctx, int type, int Record_ID, String trxName) + { + return get(ctx, type, Record_ID, trxName, 0); + } + + /************************************************************************** + * Get Document Print Engine for Document Type. + * @param ctx context + * @param type document type + * @param Record_ID id + * @param trxName + * @param windowNo + * @return Report Engine or null + */ + public static ReportEngine get(Properties ctx, int type, int Record_ID, String trxName, int windowNo) { if (Record_ID < 1) { @@ -2215,7 +2282,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) info.setPrinterName(format.getPrinterName()); // Engine - ReportEngine re = new ReportEngine(ctx, format, query, info, trxName); + ReportEngine re = new ReportEngine(ctx, format, query, info, trxName, windowNo); return re; } // get diff --git a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java index d79265ac6c..9af368ba07 100644 --- a/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java +++ b/org.adempiere.base/src/org/compiere/print/layout/LayoutEngine.java @@ -108,25 +108,53 @@ import org.idempiere.print.StandardHeaderFooter; public class LayoutEngine implements Pageable, Printable, Doc { /** - * Detail Constructor - * @param format Print Format - * @param data Print Data - * @param query query for parameter info + * Constructor + * @param format + * @param data + * @param query + * @param info */ - public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info ) + public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info) { - this(format, data, query, info , null); - } // LayoutEngine - + this(format,data,query,info,0); + } /** * Detail Constructor * @param format Print Format * @param data Print Data * @param query query for parameter info - * @param trxName + * @param info + * @param windowNo + */ + public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info, int windowNo ) + { + this(format, data, query, info , null, windowNo); + } // LayoutEngine + + /** + * Detail Constructor + * @param format + * @param data + * @param query + * @param info + * @param trxName */ public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info , String trxName) { + this(format,data,query,info,trxName,0); + } + /** + * Detail Constructor + * @param format Print Format + * @param data Print Data + * @param query query for parameter info + * @param info + * @param trxName + * @param windowNo + */ + public LayoutEngine (MPrintFormat format, PrintData data, MQuery query, PrintInfo info , String trxName, int windowNo) + { + m_windowNo = windowNo; m_TrxName = trxName; if (log.isLoggable(Level.INFO)) log.info(format + " - " + data + " - " + query); // s_FASTDRAW = MClient.get(format.getCtx()).isUseBetaFunctions(); @@ -163,6 +191,8 @@ public class LayoutEngine implements Pageable, Printable, Doc /** PrintInfo **/ private PrintInfo m_PrintInfo = null; + /** Window No */ + private int m_windowNo = 0; /** Paper - default: standard portrait */ private CPaper m_paper; @@ -290,7 +320,7 @@ public class LayoutEngine implements Pageable, Printable, Doc // Print Context Env.setContext(m_printCtx, Page.CONTEXT_REPORTNAME, m_format.get_Translation(MPrintFormat.COLUMNNAME_Name)); - Env.setContext(m_printCtx, Page.CONTEXT_HEADER, Env.getHeader(m_printCtx, 0)); + Env.setContext(m_printCtx, Page.CONTEXT_HEADER, Env.getHeader(m_printCtx, m_windowNo)); Env.setContext(m_printCtx, Env.LANGUAGE, m_format.getLanguage().getAD_Language()); if (m_hasLayout && doLayout) @@ -1260,7 +1290,7 @@ public class LayoutEngine implements Pageable, Printable, Doc if (log.isLoggable(Level.FINE)) log.fine(query.toString()); // - DataEngine de = new DataEngine(format.getLanguage(),m_TrxName); + DataEngine de = new DataEngine(format.getLanguage(),m_TrxName, m_windowNo); PrintData includedData = de.getPrintData(data.getCtx(), format, query); if (includedData == null) return null; diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java index 835bd43625..e71e1be899 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java @@ -566,7 +566,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene for (int i = 0; i < m_ids.length; i++) { int M_InOut_ID = m_ids[i]; - ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID); + ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.SHIPMENT, M_InOut_ID, getWindowNo()); pdfList.add(re.getPDF()); } @@ -651,7 +651,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene for (int i = 0; i < m_ids.length; i++) { int C_Invoice_ID = m_ids[i]; - ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.INVOICE, C_Invoice_ID); + ReportEngine re = ReportEngine.get (Env.getCtx(), ReportEngine.INVOICE, C_Invoice_ID, getWindowNo()); pdfList.add(re.getPDF()); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WReport.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WReport.java index 2d760bfd77..9437d392b6 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WReport.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/WReport.java @@ -196,9 +196,8 @@ public class WReport implements EventListener { else { // It's a default report using the standard printing engine - ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_query, info); + ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_query, info, null, WindowNo); re.setWhereExtended(whereExtended); - re.setWindowNo(WindowNo); ReportCtl.preview(re); } } // launchReport diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WGenForm.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WGenForm.java index 748975a217..8187f1cdc0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WGenForm.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WGenForm.java @@ -423,11 +423,11 @@ public class WGenForm extends ADForm implements EventListener, WTableMode query.addRestriction(table.getTableName() + "_ID", MQuery.EQUAL, RecordID); // Engine PrintInfo info = new PrintInfo(table.getTableName(),table.get_Table_ID(), RecordID); - re = new ReportEngine(Env.getCtx(), format, query, info); + re = new ReportEngine(Env.getCtx(), format, query, info, null, m_WindowNo); } else { - re = ReportEngine.get (Env.getCtx(), genForm.getReportEngineType(), RecordID); + re = ReportEngine.get (Env.getCtx(), genForm.getReportEngineType(), RecordID, m_WindowNo); } pdfList.add(re.getPDF()); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java index 6f434521e1..c7ca4da62f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WPayPrint.java @@ -529,7 +529,7 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene MPaySelectionCheck.confirmPrint(m_checks[i], m_batch); // ReportCtrl will check BankAccountDoc for PrintFormat - ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID()); + ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.CHECK, check.get_ID(), m_WindowNo); try { MPrintFormat format = re.getPrintFormat(); @@ -602,7 +602,7 @@ public class WPayPrint extends PayPrint implements IFormController, EventListene for (int i = 0; i < m_checks.length; i++) { MPaySelectionCheck check = m_checks[i]; - ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.REMITTANCE, check.get_ID()); + ReportEngine re = ReportEngine.get(Env.getCtx(), ReportEngine.REMITTANCE, check.get_ID(), m_WindowNo); try { MPrintFormat format = re.getPrintFormat(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ReportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ReportAction.java index 5109588073..872b2527ff 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ReportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ReportAction.java @@ -373,9 +373,8 @@ public class ReportAction implements EventListener else { // It's a default report using the standard printing engine - ReportEngine re = new ReportEngine (Env.getCtx(), pf, query, info); + ReportEngine re = new ReportEngine (Env.getCtx(), pf, query, info, null, gridTab.getWindowNo()); re.setWhereExtended(gridTab.getWhereExtended()); - re.setWindowNo(gridTab.getWindowNo()); if (export) export(re); diff --git a/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java b/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java index 8f8cd76aad..2d874fa1fa 100644 --- a/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java +++ b/org.adempiere.ui/src/org/compiere/print/DrillReportCtl.java @@ -387,8 +387,7 @@ public class DrillReportCtl { info.setDescription(m_Query.getInfo()); // It's a default report using the standard printing engine - ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_Query, info); - re.setWindowNo(m_WindowNo); + ReportEngine re = new ReportEngine (Env.getCtx(), pf, m_Query, info,null,m_WindowNo); ReportCtl.preview(re); } // launchReport diff --git a/org.adempiere.ui/src/org/compiere/print/ReportCtl.java b/org.adempiere.ui/src/org/compiere/print/ReportCtl.java index 98cba9161b..0715a29e97 100644 --- a/org.adempiere.ui/src/org/compiere/print/ReportCtl.java +++ b/org.adempiere.ui/src/org/compiere/print/ReportCtl.java @@ -255,12 +255,12 @@ public class ReportCtl String TableName = MTable.getTableName(ctx, format.getAD_Table_ID()); MQuery query = MQuery.get (ctx, pi.getAD_PInstance_ID(), TableName); PrintInfo info = new PrintInfo(pi); - re = new ReportEngine(ctx, format, query, info, pi.isSummary()); + re = new ReportEngine(ctx, format, query, info, pi.isSummary(), null, WindowNo); } // // Create Report Engine normally else { - re = ReportEngine.get(Env.getCtx(), pi); + re = ReportEngine.get(Env.getCtx(), pi, WindowNo); if (re == null) { pi.setSummary("No ReportEngine"); @@ -272,7 +272,6 @@ public class ReportCtl re.setReportType(pi.getReportType()); } re.setLanguageID(pi.getLanguageID()); - re.setWindowNo(WindowNo); re.setIsReplaceTabContent(pi.isReplaceTabContent()); createOutput(re, pi.isPrintPreview(), null); return true; @@ -314,8 +313,7 @@ public class ReportCtl } PrintInfo info = new PrintInfo(pi); - ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info, pi.isSummary()); - re.setWindowNo(WindowNo); + ReportEngine re = new ReportEngine(Env.getCtx(), format, query, info, pi.isSummary(), null, WindowNo); if (pi.getReportType() != null) { re.setReportType(pi.getReportType()); } @@ -382,12 +380,11 @@ public class ReportCtl public static boolean startDocumentPrint (int type, MPrintFormat customPrintFormat, int Record_ID, IProcessUI parent, int WindowNo, boolean IsDirectPrint, String printerName) { - ReportEngine re = ReportEngine.get (Env.getCtx(), type, Record_ID); + ReportEngine re = ReportEngine.get (Env.getCtx(), type, Record_ID, WindowNo); if (re == null) { throw new AdempiereException("NoDocPrintFormat"); } - re.setWindowNo(WindowNo); if (customPrintFormat!=null) { // Use custom print format if available re.setPrintFormat(customPrintFormat);