IDEMPIERE-5307 - Report Summary Functions Not Working Properly (#1355)

* IDEMPIERE-5307 - Report Summary Functions Not Working Properly
This commit is contained in:
Peter Takács 2022-06-07 06:56:13 +02:00 committed by GitHub
parent e0bef13fc4
commit 0e4cb62479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 33 deletions

View File

@ -970,9 +970,9 @@ public class DataEngine
else if (m_group.isFunctionColumn(pdc.getAD_PrintFormatItem_ID(), functions[f]))
{
pd.addNode(new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(),
m_group.getValue(group_pdc.getAD_PrintFormatItem_ID(),
pdc.getAD_PrintFormatItem_ID(), functions[f]),
PrintDataFunction.getFunctionDisplayType(functions[f], pdc.getDisplayType()),
m_group.getValue(group_pdc.getAD_PrintFormatItem_ID(),
pdc.getAD_PrintFormatItem_ID(), functions[f]),
PrintDataFunction.getFunctionDisplayType(functions[f], pdc.getDisplayType()),
false, pdc.isPageBreak(), pdc.getFormatPattern()));
}
} // for all columns
@ -1191,9 +1191,9 @@ public class DataEngine
else if (m_group.isFunctionColumn(pdc.getAD_PrintFormatItem_ID(), functions[f]))
{
pd.addNode(new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(),
m_group.getValue(group_pdc.getAD_PrintFormatItem_ID(),
pdc.getAD_PrintFormatItem_ID(), functions[f]),
PrintDataFunction.getFunctionDisplayType(functions[f],
m_group.getValue(group_pdc.getAD_PrintFormatItem_ID(),
pdc.getAD_PrintFormatItem_ID(), functions[f]),
PrintDataFunction.getFunctionDisplayType(functions[f],
pdc.getDisplayType()),pdc.getFormatPattern()));
}
}
@ -1228,9 +1228,9 @@ public class DataEngine
else if (m_group.isFunctionColumn(pdc.getAD_PrintFormatItem_ID(), functions[f]))
{
pd.addNode(new PrintDataElement(pdc.getAD_PrintFormatItem_ID(), pdc.getColumnName(),
m_group.getValue(PrintDataGroup.TOTAL,
pdc.getAD_PrintFormatItem_ID(), functions[f]),
PrintDataFunction.getFunctionDisplayType(functions[f], pdc.getDisplayType()), pdc.getFormatPattern()));
m_group.getValue(PrintDataGroup.TOTAL,
pdc.getAD_PrintFormatItem_ID(), functions[f]),
PrintDataFunction.getFunctionDisplayType(functions[f], pdc.getDisplayType()), pdc.getFormatPattern()));
}
} // for all columns
} // for all functions

View File

@ -164,7 +164,7 @@ public class PrintDataElement implements Serializable
* Get Function Value
* @return length or numeric value
*/
public BigDecimal getFunctionValue()
public Serializable getFunctionValue()
{
if (m_value == null)
return Env.ZERO;
@ -184,6 +184,10 @@ public class PrintDataElement implements Serializable
return Env.ZERO;
}
// Timestamp
if (m_value instanceof Timestamp)
return m_value;
// Return Length
String s = m_value.toString();
return new BigDecimal(s.length());

View File

@ -16,8 +16,10 @@
*****************************************************************************/
package org.compiere.print;
import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
@ -51,6 +53,10 @@ public class PrintDataFunction
private BigDecimal m_min = null;
/** Maximum */
private BigDecimal m_max = null;
/** Minimum Date */
private Timestamp m_minDate = null;
/** Maximum Date */
private Timestamp m_maxDate = null;
/** Sum of Squares */
private BigDecimal m_sumSquare = Env.ZERO;
@ -82,26 +88,38 @@ public class PrintDataFunction
/**
* Add Value to Counter
* @param bd data
* @param s data
*/
public void addValue (BigDecimal bd)
public void addValue (Serializable s)
{
if (bd != null)
if (s != null)
{
// Sum
m_sum = m_sum.add(bd);
// Count
m_count++;
// Min
if (m_min == null)
m_min = bd;
m_min = m_min.min(bd);
// Max
if (m_max == null)
m_max = bd;
m_max = m_max.max(bd);
// Sum of Squares
m_sumSquare = m_sumSquare.add (bd.multiply(bd));
if(s instanceof BigDecimal) {
BigDecimal bdVaue =(BigDecimal)s;
// Sum
m_sum = m_sum.add(bdVaue);
// Min
if (m_min == null)
m_min = bdVaue;
m_min = m_min.min(bdVaue);
// Max
if (m_max == null)
m_max = bdVaue;
m_max = m_max.max(bdVaue);
// Sum of Squares
m_sumSquare = m_sumSquare.add (bdVaue.multiply(bdVaue));
}
else if(s instanceof Timestamp) {
Timestamp t = (Timestamp) s;
// Min Timestamp
if ((m_minDate == null) || (m_minDate.after(t)))
m_minDate = t;
// Max Timestamp
if ((m_maxDate == null) || (m_maxDate.before(t)))
m_maxDate = t;
}
}
m_totalCount++;
} // addValue
@ -111,16 +129,24 @@ public class PrintDataFunction
* @param function function
* @return function value
*/
public BigDecimal getValue(char function)
public Serializable getValue(char function)
{
// Sum
if (function == F_SUM)
return m_sum;
// Min/Max
if (function == F_MIN)
return m_min;
if (function == F_MAX)
return m_max;
if (function == F_MIN) {
if(m_minDate != null)
return m_minDate;
else
return m_min;
}
if (function == F_MAX) {
if(m_maxDate != null)
return m_maxDate;
else
return m_max;
}
// Count
BigDecimal count = new BigDecimal(m_count);
if (function == F_COUNT)
@ -166,6 +192,8 @@ public class PrintDataFunction
m_sumSquare = Env.ZERO;
m_min = null;
m_max = null;
m_minDate = null;
m_maxDate = null;
} // reset
/**

View File

@ -16,7 +16,7 @@
*****************************************************************************/
package org.compiere.print;
import java.math.BigDecimal;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@ -201,7 +201,7 @@ public class PrintDataGroup
* @param functionColumnId function column
* @param functionValue value
*/
public void addValue (int functionColumnId, BigDecimal functionValue)
public void addValue (int functionColumnId, Serializable functionValue)
{
if (!isFunctionColumn(functionColumnId))
return;
@ -225,7 +225,7 @@ public class PrintDataGroup
* @param function function
* @return value
*/
public BigDecimal getValue (int groupId, int functionColumnId,
public Serializable getValue (int groupId, int functionColumnId,
char function)
{
String key = groupId + DELIMITER + functionColumnId;