From 7ff0f2f2b90b2f098c4cd211a1f30c4a89c58bea Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Wed, 28 Feb 2024 04:25:12 +0100 Subject: [PATCH] IDEMPIERE-6052 Print Format: Format Pattern is not Applied on Grouping/Summary SCRIPT rows (#2252) --- .../src/org/compiere/print/DataEngine.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/org.adempiere.base/src/org/compiere/print/DataEngine.java b/org.adempiere.base/src/org/compiere/print/DataEngine.java index b2e5a2900a..416ea7c7d4 100644 --- a/org.adempiere.base/src/org/compiere/print/DataEngine.java +++ b/org.adempiere.base/src/org/compiere/print/DataEngine.java @@ -24,6 +24,8 @@ import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.SQLException; import java.sql.Timestamp; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -443,7 +445,8 @@ public class DataEngine // Warning here: Oracle treats empty strings '' as NULL and the code below checks for wasNull on this column .append("' '").append(" AS \"").append(pfiName).append("\","); // - pdc = new PrintDataColumn(AD_PrintFormatItem_ID, -1, pfiName, DisplayType.Text, FieldLength, orderName, isPageBreak); + int scriptDisplayType = getDisplayTypeFromPattern(formatPattern); + pdc = new PrintDataColumn(AD_PrintFormatItem_ID, -1, pfiName, scriptDisplayType, FieldLength, orderName, isPageBreak); synonymNext(); } // -- Parent, TableDir (and unqualified Search) -- @@ -805,6 +808,31 @@ public class DataEngine return pd; } // getPrintDataInfo + /** + * Try to determine the display type from a pattern + * - try a DecimalFormat if the pattern contains any of the characters # 0 + * - try a SimpleDateFormat if the pattern contains any of the characters y M d h H m s S + * - otherwise (or if the format is not valid) return Text + * @param pattern + * @return DateTime for a SimpleDateFormat, Number for a DecimalFormat, otherwise Text + */ + private int getDisplayTypeFromPattern(String pattern) { + if (! Util.isEmpty(pattern, true)) { + if (pattern.matches(".*[#0].*")) { + try { + new DecimalFormat(pattern); + return DisplayType.Number; + } catch (Exception ex) {} + } else if (pattern.matches(".*[yMdhHmsS].*")) { + try { + new SimpleDateFormat(pattern); + return DisplayType.DateTime; + } catch (Exception ex) {} + } + } + return DisplayType.Text; + } + /** * Next Synonym. * Creates next synonym A..Z AA..ZZ AAA..ZZZ