IDEMPIERE-4709 - Print Format Item: implement script column (expression) (#644)

* IDEMPIERE-4709 - Print Format Item: implement script column (expression)

* IDEMPIERE-4709 - Translated comments

* IDEMPIERE-4709 - Check Advanced Access, Null Script before save

* IDEMPIERE-4709 - Changed Naming

Changed Naming for Scripts.

* IDEMPIERE-4709 Remove Migration script mistake

* IDEMPIERE-4709 Logic and Value Name Fixes
This commit is contained in:
igorpojzl 2021-04-22 21:13:10 +02:00 committed by GitHub
parent ad3debdd0e
commit f74e6c7824
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 348 additions and 7 deletions

View File

@ -0,0 +1,44 @@
SET SQLBLANKLINES ON
SET DEFINE OFF
-- Feb 20, 2021, 1:45:25 PM BRT
INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200504,'Script',255,'S',0,0,'Y',TO_DATE('2021-02-20 13:45:25','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-20 13:45:25','YYYY-MM-DD HH24:MI:SS'),100,'D','f3acb050-7407-481a-9177-022c134cf3a5')
;
-- Feb 20, 2021, 1:46:44 PM BRT
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (214413,0,'Script','Dynamic Java Language Script to calculate result','Use Java language constructs to define the result of the calculation',489,'Script',2000,'N','N','N','N','N',0,'N',14,0,0,'Y',TO_DATE('2021-02-20 13:46:44','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-20 13:46:44','YYYY-MM-DD HH24:MI:SS'),100,1718,'Y','N','D','N','N','N','Y','d0873a87-64d0-4d21-bf51-5b5b6ce1645a','Y',0,'N','N','N')
;
-- Feb 20, 2021, 1:46:46 PM BRT
ALTER TABLE AD_PrintFormatItem ADD Script VARCHAR2(2000 CHAR) DEFAULT NULL
;
-- Feb 20, 2021, 1:51:41 PM BRT
INSERT INTO AD_Field (AD_Field_ID,Name,Description,Help,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan,NumLines) VALUES (206598,'Script','Dynamic Java Language Script to calculate result','Use Java language constructs to define the result of the calculation',426,214413,'Y',2000,570,'N','N','N','N',0,0,'Y',TO_DATE('2021-02-20 13:51:41','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2021-02-20 13:51:41','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','c0a3c732-4ea1-4597-8a6f-c26cac7715e6','Y',570,5,3)
;
-- Feb 20, 2021, 1:51:58 PM BRT
UPDATE AD_Field SET DisplayLogic='@PrintFormatType@=''S''', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-20 13:51:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206598
;
-- Feb 20, 2021, 1:52:53 PM BRT
UPDATE AD_Field SET AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, ReadOnlyLogic='@PrintFormatType@=''S''', IsToolbarButton=NULL,Updated=TO_DATE('2021-02-20 13:52:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5668
;
-- Feb 20, 2021, 1:58:50 PM BRT
UPDATE AD_Field SET DisplayLogic='@PrintFormatType@=F | @PrintFormatType@=S', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-20 13:58:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=56373
;
-- Feb 20, 2021, 1:59:31 PM BRT
UPDATE AD_Field SET DisplayLogic='@PrintFormatType@=S', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, MandatoryLogic='@PrintFormatType@=S', IsToolbarButton=NULL,Updated=TO_DATE('2021-02-20 13:59:31','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206598
;
-- Feb 20, 2021, 2:00:40 PM BRT
UPDATE AD_Field SET AD_FieldGroup_ID=200015, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2021-02-20 14:00:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206598
;
SELECT register_migration_script('202102201441_IDEMPIERE-4709.sql') FROM dual
;

View File

@ -0,0 +1,40 @@
-- Feb 20, 2021, 1:45:25 PM BRT
INSERT INTO AD_Ref_List (AD_Ref_List_ID,Name,AD_Reference_ID,Value,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,EntityType,AD_Ref_List_UU) VALUES (200504,'Script',255,'S',0,0,'Y',TO_TIMESTAMP('2021-02-20 13:45:25','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-20 13:45:25','YYYY-MM-DD HH24:MI:SS'),100,'D','f3acb050-7407-481a-9177-022c134cf3a5')
;
-- Feb 20, 2021, 1:46:44 PM BRT
INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (214413,0,'Script','Dynamic Java Language Script to calculate result','Use Java language constructs to define the result of the calculation',489,'Script',2000,'N','N','N','N','N',0,'N',14,0,0,'Y',TO_TIMESTAMP('2021-02-20 13:46:44','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-20 13:46:44','YYYY-MM-DD HH24:MI:SS'),100,1718,'Y','N','D','N','N','N','Y','d0873a87-64d0-4d21-bf51-5b5b6ce1645a','Y',0,'N','N','N')
;
-- Feb 20, 2021, 1:46:46 PM BRT
ALTER TABLE AD_PrintFormatItem ADD COLUMN Script VARCHAR(2000) DEFAULT NULL
;
-- Feb 20, 2021, 1:51:41 PM BRT
INSERT INTO AD_Field (AD_Field_ID,Name,Description,Help,AD_Tab_ID,AD_Column_ID,IsDisplayed,DisplayLength,SeqNo,IsSameLine,IsHeading,IsFieldOnly,IsEncrypted,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,IsReadOnly,IsCentrallyMaintained,EntityType,AD_Field_UU,IsDisplayedGrid,SeqNoGrid,ColumnSpan,NumLines) VALUES (206598,'Script','Dynamic Java Language Script to calculate result','Use Java language constructs to define the result of the calculation',426,214413,'Y',2000,570,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2021-02-20 13:51:41','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2021-02-20 13:51:41','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','c0a3c732-4ea1-4597-8a6f-c26cac7715e6','Y',570,5,3)
;
-- Feb 20, 2021, 1:51:58 PM BRT
UPDATE AD_Field SET DisplayLogic='@PrintFormatType@=''S''', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-20 13:51:58','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206598
;
-- Feb 20, 2021, 1:52:53 PM BRT
UPDATE AD_Field SET AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, ReadOnlyLogic='@PrintFormatType@=''S''', IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-20 13:52:53','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5668
;
-- Feb 20, 2021, 1:58:50 PM BRT
UPDATE AD_Field SET DisplayLogic='@PrintFormatType@=F | @PrintFormatType@=S', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-20 13:58:50','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=56373
;
-- Feb 20, 2021, 1:59:31 PM BRT
UPDATE AD_Field SET DisplayLogic='@PrintFormatType@=S', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, MandatoryLogic='@PrintFormatType@=S', IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-20 13:59:31','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206598
;
-- Feb 20, 2021, 2:00:40 PM BRT
UPDATE AD_Field SET AD_FieldGroup_ID=200015, AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2021-02-20 14:00:40','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=206598
;
SELECT register_migration_script('202102201441_IDEMPIERE-4709.sql') FROM dual
;

View File

@ -94,6 +94,17 @@
tableName="AD_InfoColumn"> tableName="AD_InfoColumn">
</callout> </callout>
</extension> </extension>
<extension
id="org.adempiere.model.CalloutPrintFormatType.printformattype"
point="org.adempiere.base.IColumnCallout">
<callout
class="org.adempiere.model.CalloutPrintFormatType"
columnName="PrintFormatType"
priority="0"
tableName="AD_PrintFormatItem">
</callout>
</extension>
<extension <extension
id="org.compiere.model.StandardTaxProvider" id="org.compiere.model.StandardTaxProvider"
name="Standard Tax Provider" name="Standard Tax Provider"

View File

@ -0,0 +1,29 @@
package org.adempiere.model;
import java.util.Properties;
import org.adempiere.base.IColumnCallout;
import org.compiere.model.GridField;
import org.compiere.model.GridTab;
import org.compiere.model.X_AD_PrintFormatItem;
import org.compiere.util.DB;
public class CalloutPrintFormatType implements IColumnCallout {
@Override
public String start(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value, Object oldValue) {
String printFormatType = (String)value;
if(!X_AD_PrintFormatItem.PRINTFORMATTYPE_Script.equals(printFormatType))
return null;
int AD_PrintFormat_ID = (Integer) mTab.getValue("AD_PrintFormat_ID");
int count = DB.getSQLValue(null, "SELECT count(*) FROM AD_PrintFormatItem WHERE PrintFormatType = 'S' AND AD_PrintFormat_ID = ?",AD_PrintFormat_ID);
mTab.setValue("Name", "SCRIPTCOLUMN"+count );
return null;
}
}

View File

@ -105,6 +105,12 @@ extends AbstractExcelExporter
obj = m_printData.getNode(Integer.valueOf(AD_Column_ID)); obj = m_printData.getNode(Integer.valueOf(AD_Column_ID));
} }
/** DEVCOFFEE: script column **/
if (item.isTypeScript())
{
obj = m_printData.getNode(item.getName());
}
if (obj != null && obj instanceof PrintDataElement) { if (obj != null && obj instanceof PrintDataElement) {
return (PrintDataElement)obj; return (PrintDataElement)obj;
} }

View File

@ -762,6 +762,19 @@ public interface I_AD_PrintFormatItem
*/ */
public int getRunningTotalLines(); public int getRunningTotalLines();
/** Column name Script */
public static final String COLUMNNAME_Script = "Script";
/** Set Script.
* Dynamic Java Language Script to calculate result
*/
public void setScript (String Script);
/** Get Script.
* Dynamic Java Language Script to calculate result
*/
public String getScript();
/** Column name SeqNo */ /** Column name SeqNo */
public static final String COLUMNNAME_SeqNo = "SeqNo"; public static final String COLUMNNAME_SeqNo = "SeqNo";

View File

@ -30,7 +30,7 @@ public class X_AD_PrintFormatItem extends PO implements I_AD_PrintFormatItem, I_
/** /**
* *
*/ */
private static final long serialVersionUID = 20201220L; private static final long serialVersionUID = 20210220L;
/** Standard Constructor */ /** Standard Constructor */
public X_AD_PrintFormatItem (Properties ctx, int AD_PrintFormatItem_ID, String trxName) public X_AD_PrintFormatItem (Properties ctx, int AD_PrintFormatItem_ID, String trxName)
@ -1303,6 +1303,8 @@ public class X_AD_PrintFormatItem extends PO implements I_AD_PrintFormatItem, I_
public static final String PRINTFORMATTYPE_Rectangle = "R"; public static final String PRINTFORMATTYPE_Rectangle = "R";
/** Line = L */ /** Line = L */
public static final String PRINTFORMATTYPE_Line = "L"; public static final String PRINTFORMATTYPE_Line = "L";
/** Script = S */
public static final String PRINTFORMATTYPE_Script = "S";
/** Set Format Type. /** Set Format Type.
@param PrintFormatType @param PrintFormatType
Print Format Type Print Format Type
@ -1375,6 +1377,23 @@ public class X_AD_PrintFormatItem extends PO implements I_AD_PrintFormatItem, I_
return ii.intValue(); return ii.intValue();
} }
/** Set Script.
@param Script
Dynamic Java Language Script to calculate result
*/
public void setScript (String Script)
{
set_Value (COLUMNNAME_Script, Script);
}
/** Get Script.
@return Dynamic Java Language Script to calculate result
*/
public String getScript ()
{
return (String)get_Value(COLUMNNAME_Script);
}
/** Set Sequence. /** Set Sequence.
@param SeqNo @param SeqNo
Method of ordering records; lowest number comes first Method of ordering records; lowest number comes first

View File

@ -17,6 +17,7 @@
package org.compiere.print; package org.compiere.print;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Clob; import java.sql.Clob;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -24,6 +25,8 @@ import java.sql.ResultSetMetaData;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -46,6 +49,9 @@ import org.compiere.util.Msg;
import org.compiere.util.Util; import org.compiere.util.Util;
import org.compiere.util.ValueNamePair; import org.compiere.util.ValueNamePair;
import bsh.EvalError;
import bsh.Interpreter;
/** /**
* Data Engine. * Data Engine.
* Creates SQL and laods data into PrintData (including totals/etc.) * Creates SQL and laods data into PrintData (including totals/etc.)
@ -116,6 +122,7 @@ public class DataEngine
/** Key Indicator in Report */ /** Key Indicator in Report */
public static final String KEY = "*"; public static final String KEY = "*";
private Map<Object, Object> m_summarized = new HashMap<Object, Object>();
/************************************************************************** /**************************************************************************
* Load Data * Load Data
@ -272,11 +279,12 @@ public class DataEngine
.append("pfi.IsVarianceCalc, pfi.IsDeviationCalc, ") // 22..23 .append("pfi.IsVarianceCalc, pfi.IsDeviationCalc, ") // 22..23
.append("c.ColumnSQL, COALESCE(pfi.FormatPattern, c.FormatPattern) ") // 24, 25 .append("c.ColumnSQL, COALESCE(pfi.FormatPattern, c.FormatPattern) ") // 24, 25
//BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153 //BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153
.append(" , pfi.isDesc ") //26 /** START DEVCOFFEE: script column **/
.append(" , pfi.isDesc, pfi.Script, pfi.Name ") //26
//END //END
.append("FROM AD_PrintFormat pf") .append("FROM AD_PrintFormat pf")
.append(" INNER JOIN AD_PrintFormatItem pfi ON (pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID)") .append(" INNER JOIN AD_PrintFormatItem pfi ON (pf.AD_PrintFormat_ID=pfi.AD_PrintFormat_ID)")
.append(" INNER JOIN AD_Column c ON (pfi.AD_Column_ID=c.AD_Column_ID)") .append(" LEFT JOIN AD_Column c ON (pfi.AD_Column_ID=c.AD_Column_ID)")
.append(" LEFT OUTER JOIN AD_ReportView_Col rvc ON (pf.AD_ReportView_ID=rvc.AD_ReportView_ID AND c.AD_Column_ID=rvc.AD_Column_ID) ") .append(" LEFT OUTER JOIN AD_ReportView_Col rvc ON (pf.AD_ReportView_ID=rvc.AD_ReportView_ID AND c.AD_Column_ID=rvc.AD_Column_ID) ")
.append("WHERE pf.AD_PrintFormat_ID=?") // #1 .append("WHERE pf.AD_PrintFormat_ID=?") // #1
.append(" AND pfi.IsActive='Y' AND (pfi.IsPrinted='Y' OR c.IsKey='Y' OR pfi.SortNo > 0 ") .append(" AND pfi.IsActive='Y' AND (pfi.IsPrinted='Y' OR c.IsKey='Y' OR pfi.SortNo > 0 ")
@ -288,6 +296,8 @@ public class DataEngine
+ MPrintFormatItem.PRINTFORMATTYPE_Image + MPrintFormatItem.PRINTFORMATTYPE_Image
+ "','" + "','"
+ MPrintFormatItem.PRINTFORMATTYPE_PrintFormat + MPrintFormatItem.PRINTFORMATTYPE_PrintFormat
+ "','"
+ MPrintFormatItem.PRINTFORMATTYPE_Script
+ "') ") + "') ")
.append("ORDER BY pfi.IsPrinted DESC, pfi.SeqNo"); // Functions are put in first column .append("ORDER BY pfi.IsPrinted DESC, pfi.SeqNo"); // Functions are put in first column
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
@ -373,6 +383,10 @@ public class DataEngine
//BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153 //BEGIN http://jira.idempiere.com/browse/IDEMPIERE-153
boolean isDesc = "Y".equals(rs.getString(26)); boolean isDesc = "Y".equals(rs.getString(26));
//END //END
/** START DEVCOFFEE: script column **/
String script = rs.getString(27);
String pfiName = rs.getString(28);
// Fully qualified Table.Column for ordering // Fully qualified Table.Column for ordering
String orderName = tableName + "." + ColumnName; String orderName = tableName + "." + ColumnName;
@ -387,6 +401,31 @@ public class DataEngine
groupByColumns.add(tableName+"."+ColumnName); groupByColumns.add(tableName+"."+ColumnName);
pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, KEY, isPageBreak); // KeyColumn pdc = new PrintDataColumn(AD_Column_ID, ColumnName, AD_Reference_ID, FieldLength, KEY, isPageBreak); // KeyColumn
} }
/** START DEVCOFFEE: script column **/
else if (ColumnName == null || script != null && !script.isEmpty())
{
// => (..) AS AName, Table.ID,
if (script != null && !script.isEmpty())
{
if (script.startsWith("@SQL="))
{
script = "(" + script.replace("@SQL=", "") + ")";
}
else
script = "'@SCRIPT" + script + "'";
}
else
script = "";
if (ColumnName == null && script.isEmpty())
continue;
sqlSELECT.append(script).append(" AS ").append(m_synonym).append(pfiName).append(",")
.append("''").append(" AS ").append(pfiName).append(",");
//
pdc = new PrintDataColumn(-1, pfiName, DisplayType.Text, FieldLength, orderName, isPageBreak);
synonymNext();
}
// -- Parent, TableDir (and unqualified Search) -- // -- Parent, TableDir (and unqualified Search) --
else if ( /* (IsParent && DisplayType.isLookup(AD_Reference_ID)) || <-- IDEMPIERE-71 Carlos Ruiz - globalqss */ else if ( /* (IsParent && DisplayType.isLookup(AD_Reference_ID)) || <-- IDEMPIERE-71 Carlos Ruiz - globalqss */
AD_Reference_ID == DisplayType.TableDir AD_Reference_ID == DisplayType.TableDir
@ -763,7 +802,13 @@ public class DataEngine
length++; length++;
} }
else else
{
cc++; cc++;
// Refs #6532
if (cc == 'X')
cc++;
}
// //
m_synonym = String.valueOf(cc); m_synonym = String.valueOf(cc);
for (int i = 1; i < length; i++) { for (int i = 1; i < length; i++) {
@ -998,8 +1043,23 @@ public class DataEngine
String id = rs.getString(counter++); String id = rs.getString(counter++);
if (display != null && !rs.wasNull()) if (display != null && !rs.wasNull())
{ {
/** START DEVCOFFEE: script column **/
int displayType = pdc.getDisplayType();
if (display.startsWith("@SCRIPT"))
{
displayType = DisplayType.Number;
display = display.replace("@SCRIPT", "");
display = parseVariable(display, pdc, pd);
Interpreter bsh = new Interpreter ();
try {
display = bsh.eval(display).toString();
} catch (EvalError e) {
log.severe(e.getMessage());
}
}
ValueNamePair pp = new ValueNamePair(id, display); ValueNamePair pp = new ValueNamePair(id, display);
pde = new PrintDataElement(pdc.getColumnName(), pp, pdc.getDisplayType(), pdc.getFormatPattern()); pde = new PrintDataElement(pdc.getColumnName(), pp, displayType, pdc.getFormatPattern());
} }
} }
} }
@ -1226,7 +1286,71 @@ public class DataEngine
} // two lines } // two lines
} // printRunningTotal } // printRunningTotal
/**
* Parse expression, replaces @tag@ with pdc values and/or execute functions
* @param expression
* @param pdc
* @param pd
* @return String
*/
public String parseVariable(String expression, PrintDataColumn pdc, PrintData pd) {
if (expression == null || expression.length() == 0)
return "";
log.info("Analyzing Expression " + expression);
String token;
String inStr = new String(expression);
StringBuffer outStr = new StringBuffer();
int i = inStr.indexOf('@');
while (i != -1)
{
outStr.append(inStr.substring(0, i)); // up to @
inStr = inStr.substring(i+1, inStr.length()); // from first @
int j = inStr.indexOf('@'); // next @
if (j < 0)
{
return ""; // no second tag
}
token = inStr.substring(0, j);
//format string
int f = token.indexOf('<');
if (f > 0 && token.endsWith(">")) {
token = token.substring(0, f);
}
if (token.startsWith("ACCUMULATE/")) {
token = token.replace("ACCUMULATE/", "");
BigDecimal value = (BigDecimal) ((PrintDataElement)pd.getNode(token)).getValue();
if (m_summarized.containsKey(pdc))
{
value= ((BigDecimal) m_summarized.get(pdc)).add(value);
m_summarized.remove(pdc);
}
m_summarized.put(pdc, value);
outStr.append(value);
}
else if (token.startsWith("COL/"))
{
token = token.replace("COL/", "");
BigDecimal value = (BigDecimal) ((PrintDataElement)pd.getNode(token)).getValue();
outStr.append(value);
}
inStr = inStr.substring(j+1, inStr.length()); // from second @
i = inStr.indexOf('@');
}
outStr.append(inStr); // add the rest of the string
return outStr.toString();
}
/************************************************************************* /*************************************************************************
* Test * Test
* @param args args * @param args args

View File

@ -24,6 +24,7 @@ import java.util.Properties;
import java.util.logging.Level; import java.util.logging.Level;
import org.compiere.model.GridField; import org.compiere.model.GridField;
import org.compiere.model.MRole;
import org.compiere.model.X_AD_PrintFormatItem; import org.compiere.model.X_AD_PrintFormatItem;
import org.compiere.util.CCache; import org.compiere.util.CCache;
import org.compiere.util.CLogger; import org.compiere.util.CLogger;
@ -31,6 +32,8 @@ import org.compiere.util.DB;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Env; import org.compiere.util.Env;
import org.compiere.util.Language; import org.compiere.util.Language;
import org.compiere.util.Msg;
import org.compiere.util.Util;
import org.idempiere.cache.ImmutablePOSupport; import org.idempiere.cache.ImmutablePOSupport;
/** /**
@ -246,6 +249,14 @@ public class MPrintFormatItem extends X_AD_PrintFormatItem implements ImmutableP
} }
} // loadTranslations } // loadTranslations
/**
* Type Script
* @return true if script
*/
public boolean isTypeScript()
{
return getPrintFormatType().equals(PRINTFORMATTYPE_Script);
}
/** /**
* Type Field * Type Field
@ -721,6 +732,17 @@ public class MPrintFormatItem extends X_AD_PrintFormatItem implements ImmutableP
if (!isTypeField() && !isTypePrintFormat() && !isImageField()) { if (!isTypeField() && !isTypePrintFormat() && !isImageField()) {
setAD_Column_ID(0); setAD_Column_ID(0);
} }
if(!isTypeScript() && !Util.isEmpty(getScript())) {
setScript(null);
}
if(!Util.isEmpty(getScript()) && is_ValueChanged(MPrintFormatItem.COLUMNNAME_Script)
&& getScript().contains("@SQL") && !MRole.getDefault().isAccessAdvanced()) {
log.saveError("Error", Msg.getMsg(getCtx(), "ActionNotAllowedHere"));
return false;
}
return true; return true;
} // beforeSave } // beforeSave

View File

@ -849,7 +849,16 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
{ {
td td = new td(); td td = new td();
tr.addElement(td); tr.addElement(td);
Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); Object obj = null;
/** START DEVCOFFEE: script column **/
if (item.isTypeScript())
{
obj = m_printData.getNode(item.getName());
}
else
{
obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID()));
}
if (obj == null || !isDisplayPFItem(item)){ if (obj == null || !isDisplayPFItem(item)){
td.addElement("&nbsp;"); td.addElement("&nbsp;");
if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){
@ -1067,6 +1076,11 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
printColIndex++; printColIndex++;
Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID())); Object obj = m_printData.getNode(Integer.valueOf(item.getAD_Column_ID()));
String data = ""; String data = "";
/** START DEVCOFFEE: script column **/
if (item.isTypeScript())
{
obj = m_printData.getNode(item.getName());
}
if (obj == null || !isDisplayPFItem(item)){ if (obj == null || !isDisplayPFItem(item)){
if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){ if (colSuppressRepeats != null && colSuppressRepeats[printColIndex]){
preValues[printColIndex] = null; preValues[printColIndex] = null;

View File

@ -1145,6 +1145,13 @@ public class LayoutEngine implements Pageable, Printable, Doc
element.setMaxWidth(maxWidth); element.setMaxWidth(maxWidth);
} }
} }
/** START DEVCOFFEE: Script print format type **/
else if (item.getPrintFormatType().equals(MPrintFormatItem.PRINTFORMATTYPE_Script))
{
element = createStringElement (item.getName(),
item.getAD_PrintColor_ID (), item.getAD_PrintFont_ID (),
maxWidth, item.getMaxHeight (), item.isHeightOneLine (), alignment, true);
}
else // (item.isTypeText()) //** Text else // (item.isTypeText()) //** Text
{ {
String printName = item.getPrintName (m_format.getLanguage ()); String printName = item.getPrintName (m_format.getLanguage ());
@ -1246,6 +1253,13 @@ public class LayoutEngine implements Pageable, Printable, Doc
newLine(); newLine();
PrintElement element = null; PrintElement element = null;
// //
// COF #10540 - avoid error when generating PDF due to inconsistency in the configuration
if (item.getAD_PrintFormatChild_ID() <= 0)
{
log.log(Level.SEVERE, "Included format not configured. AD_PrintFormat_ID = " + item.getAD_PrintFormat_ID() + ", AD_PrintFormatItem_ID=" + item.getAD_PrintFormatItem_ID());
return element;
}
MPrintFormat format = MPrintFormat.get (getCtx(), item.getAD_PrintFormatChild_ID(), false); MPrintFormat format = MPrintFormat.get (getCtx(), item.getAD_PrintFormatChild_ID(), false);
format.setLanguage(m_format.getLanguage()); format.setLanguage(m_format.getLanguage());
if (m_format.isTranslationView()) if (m_format.isTranslationView())
@ -1800,11 +1814,16 @@ public class LayoutEngine implements Pageable, Printable, Doc
{ {
columnElement = item.getPrintName(format.getLanguage()); columnElement = item.getPrintName(format.getLanguage());
} }
else if (item.isTypeField()) else if (item.isTypeField() || item.getPrintFormatType().equals(MPrintFormatItem.PRINTFORMATTYPE_Script))
{ {
Object obj = null; Object obj = null;
if (item.getAD_Column_ID() > 0) // teo_sarca, [ 1673542 ] if (item.getAD_Column_ID() > 0) // teo_sarca, [ 1673542 ]
obj = printData.getNode(Integer.valueOf(item.getAD_Column_ID())); obj = printData.getNode(Integer.valueOf(item.getAD_Column_ID()));
/** START DEVCOFFEE: Script print format type **/
if (item.getPrintFormatType().equals(MPrintFormatItem.PRINTFORMATTYPE_Script))
{
obj = printData.getNode(item.getName());
}
if (obj == null) if (obj == null)
; ;
else if (obj instanceof PrintDataElement) else if (obj instanceof PrintDataElement)