From 5199247a1e100dd9f8abbd60c10e2ed351db6eaa Mon Sep 17 00:00:00 2001 From: Deepak Pansheriya Date: Thu, 30 Mar 2023 16:59:38 +0530 Subject: [PATCH] IDEMPIERE-5602 : Adding PriceEntered in Expense report (#1759) --- .../oracle/202303071543_IDEMPIERE-5602.sql | 29 +++++++++++ .../202303071543_IDEMPIERE-5602.sql | 26 ++++++++++ .../compiere/model/CalloutTimeExpense.java | 48 ++++++++++++++++++- .../compiere/model/I_S_TimeExpenseLine.java | 13 +++++ .../org/compiere/model/MTimeExpenseLine.java | 18 ++++++- .../compiere/model/X_S_TimeExpenseLine.java | 20 ++++++++ 6 files changed, 150 insertions(+), 4 deletions(-) create mode 100644 migration/iD10/oracle/202303071543_IDEMPIERE-5602.sql create mode 100644 migration/iD10/postgresql/202303071543_IDEMPIERE-5602.sql diff --git a/migration/iD10/oracle/202303071543_IDEMPIERE-5602.sql b/migration/iD10/oracle/202303071543_IDEMPIERE-5602.sql new file mode 100644 index 0000000000..36f3912b2e --- /dev/null +++ b/migration/iD10/oracle/202303071543_IDEMPIERE-5602.sql @@ -0,0 +1,29 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- Added Price field in Expense Report Line +-- 07-Mar-2023, 12:49:49 PM IST +INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,DefaultValue,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Callout,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (215777,0,'Price','Price Entered - the price based on the selected price list on header','Price Entered - the price based on the selected price list on header',488,'PriceEntered','0',22,'N','N','N','N','N',0,'N',37,0,0,'Y',TO_DATE('2023-03-07 12:49:48','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2023-03-07 12:49:48','YYYY-MM-DD HH24:MI:SS'),100,'org.compiere.model.CalloutTimeExpense.priceOrQty',2588,'Y','N','D','N','N','N','Y','0d4f6687-ec2e-46a7-977a-fbb44ac8f4d3','N',0,'N','N','N') +; + +-- 07-Mar-2023, 12:50:01 PM IST +ALTER TABLE S_TimeExpenseLine ADD PriceEntered NUMBER DEFAULT 0 +; + +-- 07-Mar-2023, 12:50:35 PM IST +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) VALUES (207572,'Price','Price Entered - the price based on the selected price list on header','Price Entered - the price based on the selected price list on header',413,215777,'Y',22,95,'N','N','N','N',0,0,'Y',TO_DATE('2023-03-07 12:50:34','YYYY-MM-DD HH24:MI:SS'),100,TO_DATE('2023-03-07 12:50:34','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','e39cabde-90c0-4bac-a32a-0ac84f2cb15a','Y',95,2) +; + +-- 07-Mar-2023, 9:23:37 PM IST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutTimeExpense.priceOrQty',Updated=TO_DATE('2023-03-07 21:23:37','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=6875 +; + +-- 07-Mar-2023, 10:13:18 PM IST +UPDATE AD_Field SET AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, XPosition=4, IsToolbarButton=NULL,Updated=TO_DATE('2023-03-07 22:13:18','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5463 +; + +-- 07-Mar-2023, 9:34:04 PM IST +UPDATE AD_Field SET IsReadOnly='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2023-03-07 21:34:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5462 +; + +SELECT register_migration_script('202303071543_IDEMPIERE-5602.sql') FROM dual; \ No newline at end of file diff --git a/migration/iD10/postgresql/202303071543_IDEMPIERE-5602.sql b/migration/iD10/postgresql/202303071543_IDEMPIERE-5602.sql new file mode 100644 index 0000000000..74c2c25df9 --- /dev/null +++ b/migration/iD10/postgresql/202303071543_IDEMPIERE-5602.sql @@ -0,0 +1,26 @@ +-- Added Price field in Expense Report Line +-- 07-Mar-2023, 12:49:49 PM IST +INSERT INTO AD_Column (AD_Column_ID,Version,Name,Description,Help,AD_Table_ID,ColumnName,DefaultValue,FieldLength,IsKey,IsParent,IsMandatory,IsTranslated,IsIdentifier,SeqNo,IsEncrypted,AD_Reference_ID,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,Callout,AD_Element_ID,IsUpdateable,IsSelectionColumn,EntityType,IsSyncDatabase,IsAlwaysUpdateable,IsAutocomplete,IsAllowLogging,AD_Column_UU,IsAllowCopy,SeqNoSelection,IsToolbarButton,IsSecure,IsHtml) VALUES (215777,0,'Price','Price Entered - the price based on the selected price list on header','Price Entered - the price based on the selected price list on header',488,'PriceEntered','0',22,'N','N','N','N','N',0,'N',37,0,0,'Y',TO_TIMESTAMP('2023-03-07 12:49:48','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-07 12:49:48','YYYY-MM-DD HH24:MI:SS'),100,'org.compiere.model.CalloutTimeExpense.priceOrQty',2588,'Y','N','D','N','N','N','Y','0d4f6687-ec2e-46a7-977a-fbb44ac8f4d3','N',0,'N','N','N') +; + +-- 07-Mar-2023, 12:50:01 PM IST +ALTER TABLE S_TimeExpenseLine ADD COLUMN PriceEntered NUMERIC DEFAULT '0'::numeric +; + +-- 07-Mar-2023, 12:50:35 PM IST +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) VALUES (207572,'Price','Price Entered - the price based on the selected price list on header','Price Entered - the price based on the selected price list on header',413,215777,'Y',22,95,'N','N','N','N',0,0,'Y',TO_TIMESTAMP('2023-03-07 12:50:34','YYYY-MM-DD HH24:MI:SS'),100,TO_TIMESTAMP('2023-03-07 12:50:34','YYYY-MM-DD HH24:MI:SS'),100,'N','Y','D','e39cabde-90c0-4bac-a32a-0ac84f2cb15a','Y',95,2) +; + +-- 07-Mar-2023, 9:23:37 PM IST +UPDATE AD_Column SET Callout='org.compiere.model.CalloutTimeExpense.priceOrQty',Updated=TO_TIMESTAMP('2023-03-07 21:23:37','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Column_ID=6875 +; + +-- 07-Mar-2023, 10:13:18 PM IST +UPDATE AD_Field SET AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, XPosition=4, IsToolbarButton=NULL,Updated=TO_TIMESTAMP('2023-03-07 22:13:18','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5463 +; + +-- 07-Mar-2023, 9:34:04 PM IST +UPDATE AD_Field SET IsReadOnly='Y', AD_Reference_Value_ID=NULL, AD_Val_Rule_ID=NULL, IsToolbarButton=NULL,Updated=TO_DATE('2023-03-07 21:34:04','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=100 WHERE AD_Field_ID=5462 +; + +SELECT register_migration_script('202303071543_IDEMPIERE-5602.sql') FROM dual; \ No newline at end of file diff --git a/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java b/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java index b3c05d5037..9bd9bbff65 100644 --- a/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java +++ b/org.adempiere.base.callout/src/org/compiere/model/CalloutTimeExpense.java @@ -39,7 +39,7 @@ public class CalloutTimeExpense extends CalloutEngine /** * Expense Report Line * - called from M_Product_ID, S_ResourceAssignment_ID - * - set ExpenseAmt + * - set Price * @param ctx context * @param WindowNo current Window No * @param mTab Grid Tab @@ -163,7 +163,7 @@ public class CalloutTimeExpense extends CalloutEngine // finish if (priceActual == null) priceActual = Env.ZERO; - mTab.setValue("ExpenseAmt", priceActual); + mTab.setValue("PriceEntered", priceActual); return ""; } // Expense_Product @@ -206,5 +206,49 @@ public class CalloutTimeExpense extends CalloutEngine return ""; } // Expense_Amount + + /** + * Price or Quantity. + * - called from Price, Quantity + * - calculates Expense Amount + * @param ctx context + * @param WindowNo current Window No + * @param mTab Grid Tab + * @param mField Grid Field + * @param value New Value + * @return null or error message + */ + public String priceOrQty(Properties ctx, int WindowNo, GridTab mTab, GridField mField, Object value) + { + BigDecimal qty = Env.ZERO; + BigDecimal price = Env.ZERO; + + String columnName = mField.getColumnName(); + if (MTimeExpenseLine.COLUMNNAME_Qty.equals(columnName)) + { + qty = (BigDecimal) value; + price = (BigDecimal) mTab.getValue(MTimeExpenseLine.COLUMNNAME_PriceEntered); + } + else + { + price = (BigDecimal) value; + qty = (BigDecimal) mTab.getValue(MTimeExpenseLine.COLUMNNAME_Qty); + } + + if(qty == null) + { + qty = Env.ZERO; + } + + if(price == null) + { + price = Env.ZERO; + } + + BigDecimal expenseAmt = price.multiply(qty); + mTab.setValue(MTimeExpenseLine.COLUMNNAME_ExpenseAmt, expenseAmt); + + return ""; + } // Price or Quantity } // CalloutTimeExpense diff --git a/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java b/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java index 97eedf9b37..f82ae26926 100644 --- a/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java +++ b/org.adempiere.base/src/org/compiere/model/I_S_TimeExpenseLine.java @@ -372,6 +372,19 @@ public interface I_S_TimeExpenseLine * Optional additional user defined information */ public String getNote(); + + /** Column name PriceEntered */ + public static final String COLUMNNAME_PriceEntered = "PriceEntered"; + + /** Set Price. + * Price Entered - the price based on the selected price list on header + */ + public void setPriceEntered (BigDecimal PriceEntered); + + /** Get Price. + * Price Entered - the price based on the selected price list on header + */ + public BigDecimal getPriceEntered(); /** Column name PriceInvoiced */ public static final String COLUMNNAME_PriceInvoiced = "PriceInvoiced"; diff --git a/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java b/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java index da42d34210..ced956d0ca 100644 --- a/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java +++ b/org.adempiere.base/src/org/compiere/model/MTimeExpenseLine.java @@ -152,7 +152,7 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine */ public BigDecimal getApprovalAmt() { - return getQty().multiply(getConvertedAmt()); + return getConvertedAmt(); } // getApprovalAmt @@ -192,6 +192,20 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine log.saveError("ParentComplete", Msg.translate(getCtx(), "S_TimeExpense_ID")); return false; } + + //calculate expense amount + if(newRecord || is_ValueChanged(COLUMNNAME_Qty) || is_ValueChanged(COLUMNNAME_PriceEntered)) + { + BigDecimal price = getPriceEntered(); + if(price == null) + { + price = Env.ZERO; + } + + BigDecimal expenseAmt = price.multiply(getQty()); + setExpenseAmt(expenseAmt); + } + // Calculate Converted Amount if (newRecord || is_ValueChanged("ExpenseAmt") || is_ValueChanged("C_Currency_ID")) { @@ -297,7 +311,7 @@ public class MTimeExpenseLine extends X_S_TimeExpenseLine { String sql = "UPDATE S_TimeExpense te" + " SET ApprovalAmt = " - + "(SELECT SUM(Qty*ConvertedAmt) FROM S_TimeExpenseLine tel " + + "(SELECT SUM(ConvertedAmt) FROM S_TimeExpenseLine tel " + "WHERE te.S_TimeExpense_ID=tel.S_TimeExpense_ID) " + "WHERE S_TimeExpense_ID=" + getS_TimeExpense_ID(); @SuppressWarnings("unused") diff --git a/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java b/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java index ac81991ef7..940445e472 100644 --- a/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java +++ b/org.adempiere.base/src/org/compiere/model/X_S_TimeExpenseLine.java @@ -586,6 +586,26 @@ public class X_S_TimeExpenseLine extends PO implements I_S_TimeExpenseLine, I_Pe return (String)get_Value(COLUMNNAME_Note); } + /** Set Price. + @param PriceEntered + Price Entered - the price based on the selected price list on header + */ + public void setPriceEntered (BigDecimal PriceEntered) + { + set_Value (COLUMNNAME_PriceEntered, PriceEntered); + } + + /** Get Price. + @return Price Entered - the price based on the selected price list on header + */ + public BigDecimal getPriceEntered () + { + BigDecimal bd = (BigDecimal)get_Value(COLUMNNAME_PriceEntered); + if (bd == null) + return Env.ZERO; + return bd; + } + /** Set Price Invoiced. @param PriceInvoiced The priced invoiced to the customer (in the currency of the customer's AR price list) - 0 for default price */