From 511292c8b93d956837086b0164f17b09b024e9a8 Mon Sep 17 00:00:00 2001 From: Deepak Pansheriya Date: Wed, 29 Jan 2020 21:05:49 +0530 Subject: [PATCH] IDEMPIERE-4070: Adding print format item -> Display logic support in XLSX, XLS and HTML report. (#11) --- .../impexp/AbstractExcelExporter.java | 11 ++++++++++- .../adempiere/impexp/AbstractXLSXExporter.java | 13 +++++++++++-- .../adempiere/impexp/ArrayExcelExporter.java | 6 ++++++ .../adempiere/impexp/GridTabExcelExporter.java | 6 ++++++ .../adempiere/impexp/GridTabXLSXExporter.java | 7 ++++++- .../print/export/PrintDataExcelExporter.java | 15 +++++++++++++++ .../print/export/PrintDataXLSXExporter.java | 18 +++++++++++++++++- .../src/org/compiere/print/ReportEngine.java | 14 ++++++++++++-- .../report/core/RModelExcelExporter.java | 6 ++++++ .../org/adempiere/webui/info/InfoWindow.java | 8 +++++++- 10 files changed, 96 insertions(+), 8 deletions(-) diff --git a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java index 461436cfaa..3b8130bc48 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/AbstractExcelExporter.java @@ -119,6 +119,15 @@ public abstract class AbstractExcelExporter */ public abstract boolean isPageBreak(int row, int col); + /** + * Check if there is a display logic + * + * @param row row index + * @param col column index + * @return true if there is no logic or evaluate logic specified in print item + */ + public abstract boolean isDisplayed(int row, int col); + /** Logger */ protected final transient CLogger log = CLogger.getCLogger(getClass()); // @@ -497,7 +506,7 @@ public abstract class AbstractExcelExporter } int displayType = getDisplayType(rownum, col); - if (obj == null){ + if (obj == null || !isDisplayed(rownum, col)){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ preValues[printColIndex] = null; } diff --git a/org.adempiere.base/src/org/adempiere/impexp/AbstractXLSXExporter.java b/org.adempiere.base/src/org/adempiere/impexp/AbstractXLSXExporter.java index 58e1fbcf6c..45bb7841c7 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/AbstractXLSXExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/AbstractXLSXExporter.java @@ -128,7 +128,16 @@ public abstract class AbstractXLSXExporter * @return true if there is a page break */ public abstract boolean isPageBreak(int row, int col); - + + /** + * Check if there is a display logic + * + * @param row row index + * @param col column index + * @return true if there is no logic or evaluate logic specified in print item + */ + public abstract boolean isDisplayed(int row, int col); + /** Logger */ protected final CLogger log = CLogger.getCLogger(getClass()); // @@ -457,7 +466,7 @@ public abstract class AbstractXLSXExporter // line row Object obj = getValueAt(rownum, col); int displayType = getDisplayType(rownum, col); - if (obj == null) + if (obj == null || !isDisplayed(rownum, col)) { if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]) { diff --git a/org.adempiere.base/src/org/adempiere/impexp/ArrayExcelExporter.java b/org.adempiere.base/src/org/adempiere/impexp/ArrayExcelExporter.java index a43094e881..0dfff3c175 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/ArrayExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/ArrayExcelExporter.java @@ -117,4 +117,10 @@ public class ArrayExcelExporter extends AbstractXLSXExporter { protected int getCurrentRow() { return 0; } + + @Override + public boolean isDisplayed(int row, int col) + { + return true; + } } diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java index 39a9eebacd..7ff72ac138 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabExcelExporter.java @@ -191,4 +191,10 @@ public class GridTabExcelExporter extends AbstractExcelExporter implements IGrid public boolean isExportableTab(GridTab gridTab) { return false; } + + @Override + public boolean isDisplayed(int row, int col) + { + return true; + } } diff --git a/org.adempiere.base/src/org/adempiere/impexp/GridTabXLSXExporter.java b/org.adempiere.base/src/org/adempiere/impexp/GridTabXLSXExporter.java index b77891c4b6..f26149f3de 100644 --- a/org.adempiere.base/src/org/adempiere/impexp/GridTabXLSXExporter.java +++ b/org.adempiere.base/src/org/adempiere/impexp/GridTabXLSXExporter.java @@ -26,7 +26,6 @@ import org.compiere.model.MLookupFactory; import org.compiere.util.DisplayType; import org.compiere.util.Env; import org.compiere.util.Msg; -import org.compiere.util.Util; /** * Excel Exporter Adapter for GridTab @@ -199,4 +198,10 @@ public class GridTabXLSXExporter extends AbstractXLSXExporter implements IGridTa { return false; } + + @Override + public boolean isDisplayed(int row, int col) + { + return true; + } } diff --git a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java index 6746c2b640..eda2f39d01 100644 --- a/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java +++ b/org.adempiere.base/src/org/adempiere/print/export/PrintDataExcelExporter.java @@ -38,9 +38,11 @@ import org.compiere.print.MPrintPaper; import org.compiere.print.PrintData; import org.compiere.print.PrintDataElement; import org.compiere.print.layout.PrintDataEvaluatee; +import org.compiere.print.layout.PrintDataEvaluatee; import org.compiere.util.DisplayType; import org.compiere.util.Evaluator; import org.compiere.util.Msg; +import org.compiere.util.Evaluator; import org.compiere.util.Util; /** @@ -533,4 +535,17 @@ extends AbstractExcelExporter } return super.isVisible(row, col); } + + @Override + public boolean isDisplayed(int row, int col) + { + if (m_printData.getRowIndex() != row) + m_printData.setRowIndex(row); + + MPrintFormatItem item = m_printFormat.getItem(col); + if (Util.isEmpty(item.getDisplayLogic())) + return true; + + return Evaluator.evaluateLogic(new PrintDataEvaluatee(null, m_printData), item.getDisplayLogic()); + } } diff --git a/org.adempiere.base/src/org/adempiere/print/export/PrintDataXLSXExporter.java b/org.adempiere.base/src/org/adempiere/print/export/PrintDataXLSXExporter.java index 93fed0da02..68c4192d7f 100644 --- a/org.adempiere.base/src/org/adempiere/print/export/PrintDataXLSXExporter.java +++ b/org.adempiere.base/src/org/adempiere/print/export/PrintDataXLSXExporter.java @@ -26,7 +26,9 @@ import org.compiere.print.MPrintFormatItem; import org.compiere.print.MPrintPaper; import org.compiere.print.PrintData; import org.compiere.print.PrintDataElement; - +import org.compiere.print.layout.PrintDataEvaluatee; +import org.compiere.util.Evaluator; +import org.compiere.util.Util; /** * Export PrintData to Excel (XLSX) file * @@ -213,4 +215,18 @@ public class PrintDataXLSXExporter extends AbstractXLSXExporter sheet.setMargin(HSSFSheet.LeftMargin, ((double) paper.getMarginLeft()) / 72); sheet.setMargin(HSSFSheet.BottomMargin, ((double) paper.getMarginBottom()) / 72); } + + + @Override + public boolean isDisplayed(int row, int col) + { + if (m_printData.getRowIndex() != row) + m_printData.setRowIndex(row); + + MPrintFormatItem item = m_printFormat.getItem(col); + if ( Util.isEmpty(item.getDisplayLogic())) + return true; + + return Evaluator.evaluateLogic(new PrintDataEvaluatee(null, m_printData), item.getDisplayLogic()); + } } diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index ec052feccf..adc5e05976 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -91,12 +91,14 @@ import org.compiere.model.MRole; import org.compiere.model.MTable; import org.compiere.model.PrintInfo; import org.compiere.print.layout.LayoutEngine; +import org.compiere.print.layout.PrintDataEvaluatee; import org.compiere.process.ProcessInfo; import org.compiere.process.ServerProcessCtl; import org.compiere.util.CLogger; import org.compiere.util.DB; import org.compiere.util.DisplayType; import org.compiere.util.Env; +import org.compiere.util.Evaluator; import org.compiere.util.Ini; import org.compiere.util.Language; import org.compiere.util.Msg; @@ -847,7 +849,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) td td = new td(); tr.addElement(td); Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); - if (obj == null){ + if (obj == null || !isDisplayPFItem(item)){ td.addElement(" "); if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ preValues[printColIndex] = null; @@ -1064,7 +1066,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) printColIndex++; Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); String data = ""; - if (obj == null){ + if (obj == null || !isDisplayPFItem(item)){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ preValues[printColIndex] = null; } @@ -2391,5 +2393,13 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount) return String.format(CSS_SELECTOR_TEMPLATE, index + 1); } } + + private boolean isDisplayPFItem(MPrintFormatItem item) + { + if(Util.isEmpty(item.getDisplayLogic())) + return true; + + return Evaluator.evaluateLogic(new PrintDataEvaluatee(null, m_printData), item.getDisplayLogic()); + } } // ReportEngine diff --git a/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java b/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java index a21a1370d7..ed98d126df 100644 --- a/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java +++ b/org.adempiere.base/src/org/compiere/report/core/RModelExcelExporter.java @@ -78,4 +78,10 @@ extends AbstractExcelExporter protected int getCurrentRow() { return m_currentRow; } + + @Override + public boolean isDisplayed(int row, int col) + { + return true; + } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java index 8266e1236b..75bb31126b 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/info/InfoWindow.java @@ -2707,6 +2707,12 @@ public class InfoWindow extends InfoPanel implements ValueChangeListener, EventL public boolean isPageBreak(int row, int col) { return false; - } + } + + @Override + public boolean isDisplayed(int row, int col) + { + return true; + } } }