From fd421d842c43e5ed6b1d2c4b7d7299181051505a Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Mon, 19 Jan 2009 16:53:25 +0000 Subject: [PATCH] Fix [2519902] factacctreset contains a sql-statement with an error https://sourceforge.net/tracker2/?func=detail&atid=879332&aid=2519902&group_id=176962 QA for [ 2432714 ] Reset accounting ignores automatic period control https://sourceforge.net/tracker/index.php?func=detail&aid=2432714&group_id=176962&atid=879332 --- .../org/compiere/process/FactAcctReset.java | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/base/src/org/compiere/process/FactAcctReset.java b/base/src/org/compiere/process/FactAcctReset.java index 55c1ce2f8f..e3cdc863e8 100644 --- a/base/src/org/compiere/process/FactAcctReset.java +++ b/base/src/org/compiere/process/FactAcctReset.java @@ -175,19 +175,23 @@ public class FactAcctReset extends SvrProcess private void delete (String TableName, int AD_Table_ID) { Timestamp today = TimeUtil.trunc(new Timestamp (System.currentTimeMillis()), TimeUtil.TRUNC_DAY); - + MAcctSchema as = MClient.get(getCtx(), getAD_Client_ID()).getAcctSchema(); boolean autoPeriod = as != null && as.isAutoPeriodControl(); if (autoPeriod) { Timestamp temp = TimeUtil.addDays(today, - as.getPeriod_OpenHistory()); - if ( p_DateAcct_From == null || p_DateAcct_From.before(temp) ) + if ( p_DateAcct_From == null || p_DateAcct_From.before(temp) ) { p_DateAcct_From = temp; + log.info("DateAcct From set to: " + p_DateAcct_From); + } temp = TimeUtil.addDays(today, as.getPeriod_OpenFuture()); - if ( p_DateAcct_To == null || p_DateAcct_To.after(temp) ) + if ( p_DateAcct_To == null || p_DateAcct_To.after(temp) ) { p_DateAcct_To = temp; + log.info("DateAcct To set to: " + p_DateAcct_To); + } } - + reset(TableName); m_countReset = 0; // @@ -252,38 +256,41 @@ public class FactAcctReset extends SvrProcess docBaseType = " AND pc.DocBaseType " + docBaseType; // Doc - String sql1 = "UPDATE " + TableName + " doc" + String sql1 = "UPDATE " + TableName + " SET Posted='N', Processing='N' " + "WHERE AD_Client_ID=" + p_AD_Client_ID + " AND (Posted<>'N' OR Posted IS NULL OR Processing<>'N' OR Processing IS NULL)" - + " AND EXISTS (SELECT * FROM C_PeriodControl pc" - + " INNER JOIN Fact_Acct fact ON (fact.C_Period_ID=pc.C_Period_ID) " + + " AND EXISTS (SELECT 1 FROM C_PeriodControl pc" + + " INNER JOIN Fact_Acct fact ON (fact.C_Period_ID=pc.C_Period_ID) " + " WHERE fact.AD_Table_ID=" + AD_Table_ID - + " AND fact.Record_ID=doc." + TableName + "_ID"; - if ( !autoPeriod ) - sql1 += " AND pc.PeriodStatus = 'O'" + docBaseType; - if (p_DateAcct_From != null) - sql1 += " AND TRIM(fact.DateAcct) >= " + DB.TO_DATE(p_DateAcct_From); - if (p_DateAcct_To != null) - sql1 += " AND TRIM(fact.DateAcct) <= " + DB.TO_DATE(p_DateAcct_To); - sql1 += ")"; + + " AND fact.Record_ID=" + TableName + "." + TableName + "_ID"; + if ( !autoPeriod ) + sql1 += " AND pc.PeriodStatus = 'O'" + docBaseType; + if (p_DateAcct_From != null) + sql1 += " AND TRUNC(fact.DateAcct) >= " + DB.TO_DATE(p_DateAcct_From); + if (p_DateAcct_To != null) + sql1 += " AND TRUNC(fact.DateAcct) <= " + DB.TO_DATE(p_DateAcct_To); + sql1 += ")"; log.log(Level.FINE, sql1); int reset = DB.executeUpdate(sql1, get_TrxName()); // Fact - String sql2 = "DELETE Fact_Acct fact " + String sql2 = "DELETE Fact_Acct " + "WHERE AD_Client_ID=" + p_AD_Client_ID + " AND AD_Table_ID=" + AD_Table_ID; if ( !autoPeriod ) - sql2 += " AND EXISTS (SELECT * FROM C_PeriodControl pc" + sql2 += " AND EXISTS (SELECT 1 FROM C_PeriodControl pc " + "WHERE pc.PeriodStatus = 'O'" + docBaseType - + " AND fact.C_Period_ID=pc.C_Period_ID)"; + + " AND Fact_Acct.C_Period_ID=pc.C_Period_ID)"; + else + sql2 += " AND EXISTS (SELECT 1 FROM C_PeriodControl pc " + + "WHERE Fact_Acct.C_Period_ID=pc.C_Period_ID)"; if (p_DateAcct_From != null) - sql2 += " AND TRIM(fact.DateAcct) >= " + DB.TO_DATE(p_DateAcct_From); + sql2 += " AND TRUNC(Fact_Acct.DateAcct) >= " + DB.TO_DATE(p_DateAcct_From); if (p_DateAcct_To != null) - sql2 += " AND TRIM(fact.DateAcct) <= " + DB.TO_DATE(p_DateAcct_To); - + sql2 += " AND TRUNC(Fact_Acct.DateAcct) <= " + DB.TO_DATE(p_DateAcct_To); + log.log(Level.FINE, sql2); int deleted = DB.executeUpdate(sql2, get_TrxName());