diff --git a/migration/i9/oracle/202201271630_IDEMPIERE-1104.sql b/migration/i9/oracle/202201271630_IDEMPIERE-1104.sql new file mode 100644 index 0000000000..3b1706ecd7 --- /dev/null +++ b/migration/i9/oracle/202201271630_IDEMPIERE-1104.sql @@ -0,0 +1,14 @@ +SET SQLBLANKLINES ON +SET DEFINE OFF + +-- IDEMPIERE-1104 +-- Jan 27, 2022, 4:33:43 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','The date on line {0} is not in the same period as header''''s date',0,0,'Y',TO_DATE('2022-01-27 16:33:43','YYYY-MM-DD HH24:MI:SS'),0,TO_DATE('2022-01-27 16:33:43','YYYY-MM-DD HH24:MI:SS'),0,200725,'BankStatementLinePeriodNotSameAsHeader','D','2d919960-34f1-4ef4-a159-f0ae40e4d3bc') +; + +-- Jan 27, 2022, 4:34:08 PM CET +INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200192,0,0,TO_DATE('2022-01-27 16:34:07','YYYY-MM-DD HH24:MI:SS'),TO_DATE('2022-01-27 16:34:07','YYYY-MM-DD HH24:MI:SS'),0,0,'Y','BANK_STATEMENT_POST_WITH_DATE_FROM_LINE','N','Setting it to Y can lead to potential issues if a bank statement cover several periods (see https://idempiere.atlassian.net/browse/IDEMPIERE-480 and https://idempiere.atlassian.net/browse/IDEMPIERE-1104)','D','C','2c5f249e-2e08-4e02-a390-f7573443e0fe') +; + +SELECT register_migration_script('202201271630_IDEMPIERE-1104.sql') FROM dual +; diff --git a/migration/i9/postgresql/202201271630_IDEMPIERE-1104.sql b/migration/i9/postgresql/202201271630_IDEMPIERE-1104.sql new file mode 100644 index 0000000000..7ced6a8b62 --- /dev/null +++ b/migration/i9/postgresql/202201271630_IDEMPIERE-1104.sql @@ -0,0 +1,11 @@ +-- IDEMPIERE-1104 +-- Jan 27, 2022, 4:33:43 PM CET +INSERT INTO AD_Message (MsgType,MsgText,AD_Client_ID,AD_Org_ID,IsActive,Created,CreatedBy,Updated,UpdatedBy,AD_Message_ID,Value,EntityType,AD_Message_UU) VALUES ('I','The date on line {0} is not in the same period as header''''s date',0,0,'Y',TO_TIMESTAMP('2022-01-27 16:33:43','YYYY-MM-DD HH24:MI:SS'),0,TO_TIMESTAMP('2022-01-27 16:33:43','YYYY-MM-DD HH24:MI:SS'),0,200725,'BankStatementLinePeriodNotSameAsHeader','D','2d919960-34f1-4ef4-a159-f0ae40e4d3bc') +; + +-- Jan 27, 2022, 4:34:08 PM CET +INSERT INTO AD_SysConfig (AD_SysConfig_ID,AD_Client_ID,AD_Org_ID,Created,Updated,CreatedBy,UpdatedBy,IsActive,Name,Value,Description,EntityType,ConfigurationLevel,AD_SysConfig_UU) VALUES (200192,0,0,TO_TIMESTAMP('2022-01-27 16:34:07','YYYY-MM-DD HH24:MI:SS'),TO_TIMESTAMP('2022-01-27 16:34:07','YYYY-MM-DD HH24:MI:SS'),0,0,'Y','BANK_STATEMENT_POST_WITH_DATE_FROM_LINE','N','Setting it to Y can lead to potential issues if a bank statement cover several periods (see https://idempiere.atlassian.net/browse/IDEMPIERE-480 and https://idempiere.atlassian.net/browse/IDEMPIERE-1104)','D','C','2c5f249e-2e08-4e02-a390-f7573443e0fe') +; + +SELECT register_migration_script('202201271630_IDEMPIERE-1104.sql') FROM dual +; diff --git a/org.adempiere.base/src/org/compiere/acct/DocLine_Bank.java b/org.adempiere.base/src/org/compiere/acct/DocLine_Bank.java index 9a49c8a873..94b6a2ee7f 100644 --- a/org.adempiere.base/src/org/compiere/acct/DocLine_Bank.java +++ b/org.adempiere.base/src/org/compiere/acct/DocLine_Bank.java @@ -18,6 +18,7 @@ package org.compiere.acct; import java.math.BigDecimal; +import org.compiere.model.MBankStatement; import org.compiere.model.MBankStatementLine; import org.compiere.util.DB; import org.compiere.util.Env; @@ -46,7 +47,7 @@ public class DocLine_Bank extends DocLine m_TrxAmt = line.getTrxAmt(); // setDateDoc(line.getValutaDate()); - setDateAcct(doc.getDateAcct()); // adaxa-pb use statement date + setDateAcct(MBankStatement.isPostWithDateFromLine(doc.getAD_Client_ID()) ? line.getDateAcct() : doc.getDateAcct()); setC_BPartner_ID(line.getC_BPartner_ID()); } // DocLine_Bank diff --git a/org.adempiere.base/src/org/compiere/model/MBankStatement.java b/org.adempiere.base/src/org/compiere/model/MBankStatement.java index d835da478f..72d9eb2146 100644 --- a/org.adempiere.base/src/org/compiere/model/MBankStatement.java +++ b/org.adempiere.base/src/org/compiere/model/MBankStatement.java @@ -52,7 +52,7 @@ public class MBankStatement extends X_C_BankStatement implements DocAction /** * */ - private static final long serialVersionUID = 4286511528899179483L; + private static final long serialVersionUID = -5635804381201264475L; /** * Standard Constructor @@ -313,6 +313,12 @@ public class MBankStatement extends X_C_BankStatement implements DocAction MBankStatementLine line = lines[i]; if (!line.isActive()) continue; + + if (!line.isDateConsistentIfUsedForPosting()) { + m_processMsg = Msg.getMsg(getCtx(), "BankStatementLinePeriodNotSameAsHeader", new Object[] {line.getLine()}); + return DocAction.STATUS_Invalid; + } + total = total.add(line.getStmtAmt()); } setStatementDifference(total); @@ -644,5 +650,9 @@ public class MBankStatement extends X_C_BankStatement implements DocAction || DOCSTATUS_Closed.equals(ds) || DOCSTATUS_Reversed.equals(ds); } // isComplete + + public static boolean isPostWithDateFromLine(int clientID) { + return MSysConfig.getBooleanValue(MSysConfig.BANK_STATEMENT_POST_WITH_DATE_FROM_LINE, false, Env.getAD_Client_ID(Env.getCtx())); + } } // MBankStatement diff --git a/org.adempiere.base/src/org/compiere/model/MBankStatementLine.java b/org.adempiere.base/src/org/compiere/model/MBankStatementLine.java index 928be41b53..ca061e5d6b 100644 --- a/org.adempiere.base/src/org/compiere/model/MBankStatementLine.java +++ b/org.adempiere.base/src/org/compiere/model/MBankStatementLine.java @@ -44,7 +44,7 @@ import org.compiere.util.Msg; /** * */ - private static final long serialVersionUID = 3809130336412385420L; + private static final long serialVersionUID = -4479911757321927051L; /** * Standard Constructor @@ -163,6 +163,15 @@ import org.compiere.util.Msg; log.saveError("ParentComplete", Msg.translate(getCtx(), "C_BankStatement_ID")); return false; } + + // Make sure date is on the same period as header if used for posting + if (newRecord || is_ValueChanged(COLUMNNAME_DateAcct)) { + if (!isDateConsistentIfUsedForPosting()) { + log.saveError("SaveError", Msg.getMsg(getCtx(), "BankStatementLinePeriodNotSameAsHeader", new Object[] {getLine()})); + return false; + } + } + // Calculate Charge = Statement - trx - Interest BigDecimal amt = getStmtAmt(); amt = amt.subtract(getTrxAmt()); @@ -269,5 +278,19 @@ import org.compiere.util.Msg; } return true; } // updateHeader + + + /** + * If the posting is based on the date of the line (ie SysConfig BANK_STATEMENT_POST_WITH_DATE_FROM_LINE = Y), make sure line and header dates are on the same period + */ + public boolean isDateConsistentIfUsedForPosting() { + if (MBankStatement.isPostWithDateFromLine(getAD_Client_ID())) { + MPeriod headerPeriod = MPeriod.get(getCtx(), getParent().getDateAcct(), getParent().getAD_Org_ID(), get_TrxName()); + MPeriod linePeriod = MPeriod.get(getCtx(), getDateAcct(), getParent().getAD_Org_ID(), get_TrxName()); + + return headerPeriod != null && linePeriod != null && headerPeriod.getC_Period_ID() == linePeriod.getC_Period_ID(); + } + return true; + } } // MBankStatementLine diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index 408683bf0d..037643172a 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -44,7 +44,7 @@ public class MSysConfig extends X_AD_SysConfig /** * */ - private static final long serialVersionUID = 7257949078651339908L; + private static final long serialVersionUID = -3851200335563922376L; public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION"; public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS"; @@ -75,6 +75,7 @@ public class MSysConfig extends X_AD_SysConfig public static final String BACKGROUND_JOB_MAX_IN_SYSTEM = "BACKGROUND_JOB_MAX_IN_SYSTEM"; public static final String BACKGROUND_JOB_MAX_PER_CLIENT = "BACKGROUND_JOB_MAX_PER_CLIENT"; public static final String BACKGROUND_JOB_MAX_PER_USER = "BACKGROUND_JOB_MAX_PER_USER"; + public static final String BANK_STATEMENT_POST_WITH_DATE_FROM_LINE = "BANK_STATEMENT_POST_WITH_DATE_FROM_LINE"; public static final String BPARTNER_QUICK_ENTRY_OPTIONAL_LOCATION_TABLES = "BPARTNER_QUICK_ENTRY_OPTIONAL_LOCATION_TABLES"; public static final String CALENDAR_ALTERNATE_TIMEZONE = "CALENDAR_ALTERNATE_TIMEZONE"; public static final String CASH_AS_PAYMENT = "CASH_AS_PAYMENT";