* Make always delete + insert to resolved Feature Request [ 1557707 ] and bug [1619917]
This commit is contained in:
parent
5dc571f21c
commit
4877817953
|
@ -114,7 +114,7 @@ public class FactAcctReset extends SvrProcess
|
|||
}
|
||||
// Balances
|
||||
if (p_DeletePosting)
|
||||
FinBalance.updateBalanceClient(getCtx(), p_AD_Client_ID, true); // delete
|
||||
FinBalance.updateBalanceClient(getCtx(), p_AD_Client_ID); // delete
|
||||
//
|
||||
return "@Updated@ = " + m_countReset + ", @Deleted@ = " + m_countDelete;
|
||||
} // doIt
|
||||
|
|
|
@ -29,6 +29,9 @@ import org.compiere.util.*;
|
|||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: FinBalance.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
||||
* @author Low Heng Sin
|
||||
* - Make always delete + insert to resolved Feature Request [ 1557707 ] and
|
||||
* bug [1619917]
|
||||
*/
|
||||
public class FinBalance extends SvrProcess
|
||||
{
|
||||
|
@ -45,7 +48,6 @@ public class FinBalance extends SvrProcess
|
|||
protected static CLogger s_log = CLogger.getCLogger (FinBalance.class);
|
||||
|
||||
private int p_C_AcctSchema_ID = 0;
|
||||
private boolean p_IsRecreate = false;
|
||||
|
||||
/**
|
||||
* Prepare - e.g., get Parameters.
|
||||
|
@ -61,8 +63,6 @@ public class FinBalance extends SvrProcess
|
|||
;
|
||||
else if (name.equals("C_AcctSchema_ID"))
|
||||
p_C_AcctSchema_ID = ((BigDecimal)para[i].getParameter()).intValue();
|
||||
else if (name.equals("IsRecreate"))
|
||||
p_IsRecreate = "Y".equals(para[i].getParameter());
|
||||
else
|
||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||
}
|
||||
|
@ -76,12 +76,11 @@ public class FinBalance extends SvrProcess
|
|||
*/
|
||||
protected String doIt() throws java.lang.Exception
|
||||
{
|
||||
log.fine("C_AcctSchema_ID=" + p_C_AcctSchema_ID
|
||||
+ ", IsRecreate=" + p_IsRecreate);
|
||||
log.fine("C_AcctSchema_ID=" + p_C_AcctSchema_ID);
|
||||
if (p_C_AcctSchema_ID != 0)
|
||||
updateBalance(p_C_AcctSchema_ID, p_IsRecreate);
|
||||
updateBalance(p_C_AcctSchema_ID);
|
||||
else
|
||||
updateBalanceClient(getCtx(), getAD_Client_ID(), p_IsRecreate);
|
||||
updateBalanceClient(getCtx(), getAD_Client_ID());
|
||||
return "";
|
||||
} // doIt
|
||||
|
||||
|
@ -110,60 +109,16 @@ public class FinBalance extends SvrProcess
|
|||
* @param deleteFirst delete (all) balances first
|
||||
* @return Message to be translated
|
||||
*/
|
||||
public static String updateBalance (int C_AcctSchema_ID, boolean deleteFirst)
|
||||
public static String updateBalance (int C_AcctSchema_ID)
|
||||
{
|
||||
s_log.info("C_AcctSchema_ID=" + C_AcctSchema_ID + " - DeleteFirst=" + deleteFirst);
|
||||
s_log.info("C_AcctSchema_ID=" + C_AcctSchema_ID);
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
if (deleteFirst)
|
||||
{
|
||||
int no = DB.executeUpdate("DELETE Fact_Acct_Balance WHERE C_AcctSchema_ID=?",
|
||||
C_AcctSchema_ID, null);
|
||||
s_log.fine("Deleted=" + no);
|
||||
}
|
||||
|
||||
|
||||
// Update existing
|
||||
String sql = "UPDATE Fact_Acct_Balance ab "
|
||||
+ "SET (AmtAcctDr, AmtAcctCr, Qty)= "
|
||||
+ "(SELECT COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), COALESCE(SUM(Qty),0) "
|
||||
+ "FROM Fact_Acct a "
|
||||
+ "WHERE a.AD_Client_ID=ab.AD_Client_ID AND a.AD_Org_ID=ab.AD_Org_ID"
|
||||
+ " AND a.C_AcctSchema_ID=ab.C_AcctSchema_ID AND TRUNC(a.DateAcct)=TRUNC(ab.DateAcct)"
|
||||
+ " AND a.Account_ID=ab.Account_ID AND a.PostingType=ab.PostingType"
|
||||
+ " AND COALESCE(a.M_Product_ID,0)=COALESCE(ab.M_Product_ID,0) AND COALESCE(a.C_BPartner_ID,0)=COALESCE(ab.C_BPartner_ID,0)"
|
||||
+ " AND COALESCE(a.C_Project_ID,0)=COALESCE(ab.C_Project_ID,0) AND COALESCE(a.AD_OrgTrx_ID,0)=COALESCE(ab.AD_OrgTrx_ID,0)"
|
||||
+ " AND COALESCE(a.C_SalesRegion_ID,0)=COALESCE(ab.C_SalesRegion_ID,0) AND COALESCE(a.C_Activity_ID,0)=COALESCE(ab.C_Activity_ID,0)"
|
||||
+ " AND COALESCE(a.C_Campaign_ID,0)=COALESCE(ab.C_Campaign_ID,0) AND COALESCE(a.C_LocTo_ID,0)=COALESCE(ab.C_LocTo_ID,0) AND COALESCE(a.C_LocFrom_ID,0)=COALESCE(ab.C_LocFrom_ID,0)"
|
||||
+ " AND COALESCE(a.User1_ID,0)=COALESCE(ab.User1_ID,0) AND COALESCE(a.User2_ID,0)=COALESCE(ab.User2_ID,0) AND COALESCE(a.GL_Budget_ID,0)=COALESCE(ab.GL_Budget_ID,0) "
|
||||
+ "GROUP BY AD_Client_ID,AD_Org_ID, C_AcctSchema_ID, TRUNC(DateAcct),"
|
||||
+ " Account_ID, PostingType, M_Product_ID, C_BPartner_ID,"
|
||||
+ " C_Project_ID, AD_OrgTrx_ID, C_SalesRegion_ID, C_Activity_ID,"
|
||||
+ " C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID, User1_ID, User2_ID, GL_Budget_ID) "
|
||||
+ "WHERE C_AcctSchema_ID=" + C_AcctSchema_ID
|
||||
+ " AND EXISTS (SELECT 1 FROM Fact_Acct a "
|
||||
+ "WHERE a.AD_Client_ID=ab.AD_Client_ID AND a.AD_Org_ID=ab.AD_Org_ID"
|
||||
+ " AND a.C_AcctSchema_ID=ab.C_AcctSchema_ID AND TRUNC(a.DateAcct)=TRUNC(ab.DateAcct)"
|
||||
+ " AND a.Account_ID=ab.Account_ID AND a.PostingType=ab.PostingType"
|
||||
+ " AND COALESCE(a.M_Product_ID,0)=COALESCE(ab.M_Product_ID,0) AND COALESCE(a.C_BPartner_ID,0)=COALESCE(ab.C_BPartner_ID,0)"
|
||||
+ " AND COALESCE(a.C_Project_ID,0)=COALESCE(ab.C_Project_ID,0) AND COALESCE(a.AD_OrgTrx_ID,0)=COALESCE(ab.AD_OrgTrx_ID,0)"
|
||||
+ " AND COALESCE(a.C_SalesRegion_ID,0)=COALESCE(ab.C_SalesRegion_ID,0) AND COALESCE(a.C_Activity_ID,0)=COALESCE(ab.C_Activity_ID,0)"
|
||||
+ " AND COALESCE(a.C_Campaign_ID,0)=COALESCE(ab.C_Campaign_ID,0) AND COALESCE(a.C_LocTo_ID,0)=COALESCE(ab.C_LocTo_ID,0) AND COALESCE(a.C_LocFrom_ID,0)=COALESCE(ab.C_LocFrom_ID,0)"
|
||||
+ " AND COALESCE(a.User1_ID,0)=COALESCE(ab.User1_ID,0) AND COALESCE(a.User2_ID,0)=COALESCE(ab.User2_ID,0) AND COALESCE(a.GL_Budget_ID,0)=COALESCE(ab.GL_Budget_ID,0) "
|
||||
+ "GROUP BY AD_Client_ID,AD_Org_ID,"
|
||||
+ " C_AcctSchema_ID, TRUNC(DateAcct),"
|
||||
+ " Account_ID, PostingType,"
|
||||
+ " M_Product_ID, C_BPartner_ID,"
|
||||
+ " C_Project_ID, AD_OrgTrx_ID,"
|
||||
+ " C_SalesRegion_ID, C_Activity_ID,"
|
||||
+ " C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID,"
|
||||
+ " User1_ID, User2_ID, GL_Budget_ID)";
|
||||
if (!deleteFirst)
|
||||
{
|
||||
int no = DB.executeUpdate(sql, null);
|
||||
s_log.fine("Updates=" + no);
|
||||
}
|
||||
int no = DB.executeUpdate("DELETE FROM Fact_Acct_Balance WHERE C_AcctSchema_ID=?",
|
||||
C_AcctSchema_ID, null);
|
||||
s_log.fine("Deleted=" + no);
|
||||
|
||||
String sql = null;
|
||||
/** Insert **/
|
||||
sql = "INSERT INTO Fact_Acct_Balance "
|
||||
+ "(AD_Client_ID, AD_Org_ID, C_AcctSchema_ID, DateAcct,"
|
||||
|
@ -179,22 +134,12 @@ public class FinBalance extends SvrProcess
|
|||
+ " COALESCE(SUM(AmtAcctDr),0), COALESCE(SUM(AmtAcctCr),0), COALESCE(SUM(Qty),0) "
|
||||
+ "FROM Fact_Acct a "
|
||||
+ "WHERE C_AcctSchema_ID=" + C_AcctSchema_ID;
|
||||
if (!deleteFirst)
|
||||
sql += " AND NOT EXISTS (SELECT 1 "
|
||||
+ "FROM Fact_Acct_Balance x "
|
||||
+ "WHERE a.AD_Client_ID=x.AD_Client_ID AND a.AD_Org_ID=x.AD_Org_ID"
|
||||
+ " AND a.C_AcctSchema_ID=x.C_AcctSchema_ID AND TRUNC(a.DateAcct)=TRUNC(x.DateAcct)"
|
||||
+ " AND a.Account_ID=x.Account_ID AND a.PostingType=x.PostingType"
|
||||
+ " AND COALESCE(a.M_Product_ID,0)=COALESCE(x.M_Product_ID,0) AND COALESCE(a.C_BPartner_ID,0)=COALESCE(x.C_BPartner_ID,0)"
|
||||
+ " AND COALESCE(a.C_Project_ID,0)=COALESCE(x.C_Project_ID,0) AND COALESCE(a.AD_OrgTrx_ID,0)=COALESCE(x.AD_OrgTrx_ID,0)"
|
||||
+ " AND COALESCE(a.C_SalesRegion_ID,0)=COALESCE(x.C_SalesRegion_ID,0) AND COALESCE(a.C_Activity_ID,0)=COALESCE(x.C_Activity_ID,0)"
|
||||
+ " AND COALESCE(a.C_Campaign_ID,0)=COALESCE(x.C_Campaign_ID,0) AND COALESCE(a.C_LocTo_ID,0)=COALESCE(x.C_LocTo_ID,0) AND COALESCE(a.C_LocFrom_ID,0)=COALESCE(x.C_LocFrom_ID,0)"
|
||||
+ " AND COALESCE(a.User1_ID,0)=COALESCE(x.User1_ID,0) AND COALESCE(a.User2_ID,0)=COALESCE(x.User2_ID,0) AND COALESCE(a.GL_Budget_ID,0)=COALESCE(x.GL_Budget_ID,0) )";
|
||||
|
||||
sql += " GROUP BY AD_Client_ID,AD_Org_ID, C_AcctSchema_ID, TRUNC(DateAcct),"
|
||||
+ " Account_ID, PostingType, M_Product_ID, C_BPartner_ID,"
|
||||
+ " C_Project_ID, AD_OrgTrx_ID, C_SalesRegion_ID, C_Activity_ID,"
|
||||
+ " C_Campaign_ID, C_LocTo_ID, C_LocFrom_ID, User1_ID, User2_ID, GL_Budget_ID";
|
||||
int no = DB.executeUpdate(sql, null);
|
||||
no = DB.executeUpdate(sql, null);
|
||||
s_log.fine("Inserts=" + no);
|
||||
|
||||
start = System.currentTimeMillis() - start;
|
||||
|
@ -209,11 +154,11 @@ public class FinBalance extends SvrProcess
|
|||
* @param deleteFirst delete first
|
||||
* @return error or ""
|
||||
*/
|
||||
public static String updateBalanceClient (Properties ctx, int AD_Client_ID, boolean deleteFirst)
|
||||
public static String updateBalanceClient (Properties ctx, int AD_Client_ID)
|
||||
{
|
||||
MAcctSchema[] ass = MAcctSchema.getClientAcctSchema(ctx, AD_Client_ID);
|
||||
for (int i = 0; i < ass.length; i++)
|
||||
updateBalance(ass[i].getC_AcctSchema_ID(), deleteFirst);
|
||||
updateBalance(ass[i].getC_AcctSchema_ID());
|
||||
return "";
|
||||
} // updateBalanceClient
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ public class FinReport extends SvrProcess
|
|||
|
||||
// Update AcctSchema Balances
|
||||
if (p_UpdateBalances)
|
||||
FinBalance.updateBalance (m_report.getC_AcctSchema_ID(), false);
|
||||
FinBalance.updateBalance (m_report.getC_AcctSchema_ID());
|
||||
|
||||
// ** Get Data ** Segment Values
|
||||
m_columns = m_report.getColumnSet().getColumns();
|
||||
|
|
|
@ -30,6 +30,9 @@ import org.compiere.util.*;
|
|||
*
|
||||
* @author Jorg Janke
|
||||
* @version $Id: FinStatement.java,v 1.2 2006/07/30 00:51:05 jjanke Exp $
|
||||
* @author Low Heng Sin
|
||||
* - Remove update balance option to resolved Feature Request [ 1557707 ] and
|
||||
* bug [1619917]
|
||||
*/
|
||||
public class FinStatement extends SvrProcess
|
||||
{
|
||||
|
@ -233,7 +236,7 @@ public class FinStatement extends SvrProcess
|
|||
{
|
||||
// Update AcctSchema Balances
|
||||
if (p_UpdateBalances)
|
||||
FinBalance.updateBalance (p_C_AcctSchema_ID, false);
|
||||
FinBalance.updateBalance (p_C_AcctSchema_ID);
|
||||
|
||||
createBalanceLine();
|
||||
createDetailLines();
|
||||
|
|
Loading…
Reference in New Issue