IDEMPIERE-3996 Implement DisplayLogic for PrintFormatItem

This commit is contained in:
Heng Sin Low 2019-06-26 15:22:38 +08:00
parent d3fd2e8547
commit 7187a2570e
3 changed files with 123 additions and 3 deletions

View File

@ -229,6 +229,19 @@ public interface I_AD_PrintFormatItem
*/
public int getCreatedBy();
/** Column name DisplayLogic */
public static final String COLUMNNAME_DisplayLogic = "DisplayLogic";
/** Set Display Logic.
* If the Field is displayed, the result determines if the field is actually displayed
*/
public void setDisplayLogic (String DisplayLogic);
/** Get Display Logic.
* If the Field is displayed, the result determines if the field is actually displayed
*/
public String getDisplayLogic();
/** Column name FieldAlignmentType */
public static final String COLUMNNAME_FieldAlignmentType = "FieldAlignmentType";

View File

@ -30,7 +30,7 @@ public class X_AD_PrintFormatItem extends PO implements I_AD_PrintFormatItem, I_
/**
*
*/
private static final long serialVersionUID = 20190403L;
private static final long serialVersionUID = 20190626L;
/** Standard Constructor */
public X_AD_PrintFormatItem (Properties ctx, int AD_PrintFormatItem_ID, String trxName)
@ -445,6 +445,23 @@ public class X_AD_PrintFormatItem extends PO implements I_AD_PrintFormatItem, I_
return ii.intValue();
}
/** Set Display Logic.
@param DisplayLogic
If the Field is displayed, the result determines if the field is actually displayed
*/
public void setDisplayLogic (String DisplayLogic)
{
set_Value (COLUMNNAME_DisplayLogic, DisplayLogic);
}
/** Get Display Logic.
@return If the Field is displayed, the result determines if the field is actually displayed
*/
public String getDisplayLogic ()
{
return (String)get_Value(COLUMNNAME_DisplayLogic);
}
/** FieldAlignmentType AD_Reference_ID=253 */
public static final int FIELDALIGNMENTTYPE_AD_Reference_ID=253;
/** Default = D */

View File

@ -50,6 +50,7 @@ import javax.print.DocFlavor;
import javax.print.attribute.DocAttributeSet;
import org.compiere.model.MClientInfo;
import org.compiere.model.MColumn;
import org.compiere.model.MQuery;
import org.compiere.model.MSysConfig;
import org.compiere.model.MTable;
@ -71,6 +72,8 @@ import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Evaluatee;
import org.compiere.util.Evaluator;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.compiere.util.NamePair;
@ -1098,7 +1101,11 @@ public class LayoutEngine implements Pageable, Printable, Doc
// Type
PrintElement element = null;
if (item.isTypePrintFormat()) //** included PrintFormat
if ( !isDisplayed(item) )
{
;
}
else if (item.isTypePrintFormat()) //** included PrintFormat
{
element = includeFormat (item, m_data);
}
@ -1717,7 +1724,11 @@ public class LayoutEngine implements Pageable, Printable, Doc
Serializable dataElement = null;
if (item.isPrinted()) // Text Columns
{
if (item.isTypeImage())
if ( !isDisplayed(item) )
{
;
}
else if (item.isTypeImage())
{
if (item.isImageField())
columnElement = createImageElement (item, printData);
@ -1994,6 +2005,85 @@ public class LayoutEngine implements Pageable, Printable, Doc
return childPrintFormatDetails;
}
private boolean isDisplayed(MPrintFormatItem item) {
if ( Util.isEmpty(item.getDisplayLogic() ))
return true;
boolean display = Evaluator.evaluateLogic(new Evaluatee() {
@Override
public String get_ValueAsString(String variableName) {
if (Page.CONTEXT_PAGE.equals(variableName)) {
return String.valueOf(getPageNo());
} else if (Page.CONTEXT_PAGECOUNT.equals(variableName)) {
return String.valueOf(getNumberOfPages());
}
//ref column
String foreignColumn = "";
int f = variableName.indexOf('.');
if (f > 0) {
foreignColumn = variableName.substring(f+1, variableName.length());
variableName = variableName.substring(0, f);
}
Object obj = m_data.getNode(variableName);
if ( obj == null || !(obj instanceof PrintDataElement))
return "";
PrintDataElement data = (PrintDataElement) obj;
if (data.isNull() )
return "";
String value = null;
if (data.getValue() instanceof Boolean)
value = ((Boolean)data.getValue()).booleanValue() ? "Y" : "N";
else
value = data.getValueAsString();
if (!Util.isEmpty(value) && !Util.isEmpty(foreignColumn) && variableName.endsWith("_ID")) {
String refValue = "";
int id = 0;
try {
id = Integer.parseInt(value);
} catch (Exception e){}
if (id > 0) {
String tableName = null;
if (!Util.isEmpty(m_data.getTableName()))
tableName = m_data.getTableName();
else
tableName = variableName.substring(0, variableName.length()-3);
MColumn column = MColumn.get(m_data.getCtx(), tableName, variableName);
if (column != null) {
String foreignTable = column.getReferenceTableName();
refValue = DB.getSQLValueString(null,
"SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE "
+ foreignTable + "_ID = ?", id);
} else {
if (variableName.startsWith("#") || variableName.startsWith("$")) {
variableName = variableName.substring(1);
} else if (variableName.indexOf("|") > 0) {
variableName = variableName.substring(variableName.lastIndexOf("|")+1);
}
String foreignTable = null;
if (foreignColumn.indexOf(".") > 0) {
foreignTable = foreignColumn.substring(0, foreignColumn.indexOf("."));
} else {
foreignTable = variableName.substring(0, variableName.length()-3);
}
MTable t = MTable.get(Env.getCtx(), foreignTable);
if (t != null) {
refValue = DB.getSQLValueString(null,
"SELECT " + foreignColumn + " FROM " + foreignTable + " WHERE "
+ foreignTable + "_ID = ?", id);
}
}
}
return refValue;
}
return value;
}
}, item.getDisplayLogic());
return display;
}
public static Boolean [] getColSuppressRepeats (MPrintFormat format){
if (format.isForm())
return null;