details: https://code.openbravo.com/erp/devel/main/rev/8b1d41a80e83
changeset: 19625:8b1d41a80e83
user: Eduardo Argal Guibert <eduardo.argal <at> openbravo.com>
date: Tue Feb 12 14:01:39 2013 +0100
summary: Fixes bug 22716
diffstat:
src/org/openbravo/erpCommon/businessUtility/AccountTree.java | 521
+++++----
src/org/openbravo/erpCommon/businessUtility/AccountTree_data.xsql | 24 +-
2 files changed, 283 insertions(+), 262 deletions(-)
diffs (truncated from 895 to 300 lines):
diff -r fb9964930645 -r 8b1d41a80e83
src/org/openbravo/erpCommon/businessUtility/AccountTree.java
--- a/src/org/openbravo/erpCommon/businessUtility/AccountTree.java Mon Feb
11 15:23:11 2013 +0100
+++ b/src/org/openbravo/erpCommon/businessUtility/AccountTree.java Tue Feb
12 14:01:39 2013 +0100
@@ -17,6 +17,7 @@
package org.openbravo.erpCommon.businessUtility;
import java.math.BigDecimal;
+import java.util.HashMap;
import java.util.Vector;
import javax.servlet.ServletException;
@@ -37,16 +38,16 @@
private static Logger log4j = Logger.getLogger(AccountTree.class);
private VariablesSecureApp vars;
private ConnectionProvider conn;
- private AccountTreeData[] accounts;
- private AccountTreeData[] elements;
- private AccountTreeData[] resultantAccounts;
- private String[] elementValueParent;
+ private AccountTreeData[] accountsFacts;
+ private AccountTreeData[] accountsTree;
+ private AccountTreeData[] reportElements;
+ private String[] reportNodes;
// Used to inform if the applySign function has reset to zero the qty values
// or not
private boolean resetFlag;
- // True when formsCalculate() calls calculateTree(), and the calculateTree()
- // calls again formsCalculte()
- private boolean recursiveForms = false;
+ // True when operandsCalculate() calls calculateTree(), and the
calculateTree()
+ // calls again operandsCalculte()
+ private boolean recursiveOperands = false;
/**
* Constructor
@@ -56,38 +57,34 @@
* @param _conn
* ConnectionProvider object with the connection methods.
* @param _elements
- * Array of account's elements.
+ * Array of element values. (structure)
* @param _accounts
- * Array of accounts.
+ * Array of accounting facts. (data)
* @param _elementValueParent
* String with the value of the parent element to evaluate.
* @throws ServletException
*/
public AccountTree(VariablesSecureApp _vars, ConnectionProvider _conn,
- AccountTreeData[] _elements, AccountTreeData[] _accounts, String
_elementValueParent)
+ AccountTreeData[] _accountsTree, AccountTreeData[] _accountsFacts,
String _reportNode)
throws ServletException {
if (log4j.isDebugEnabled())
log4j.debug("AccountTree []");
vars = _vars;
conn = _conn;
- elements = _elements;
- accounts = _accounts;
- elementValueParent = new String[1];
- elementValueParent[0] = _elementValueParent;
- resultantAccounts = updateTreeQuantitiesSign(null, 0, "D");
+ accountsTree = _accountsTree;
+ accountsFacts = _accountsFacts;
+ reportNodes = new String[1];
+ reportNodes[0] = _reportNode;
+ reportElements = updateTreeQuantitiesSign(null, 0, "D");
// Calculating forms for every elements
- if (resultantAccounts != null && resultantAccounts.length > 0) {
+ if (reportElements != null && reportElements.length > 0) {
// forms: Array of accounts with its operands.
- AccountTreeData[] forms = AccountTreeData.selectForms(conn,
+ AccountTreeData[] operands = AccountTreeData.selectOperands(conn,
Utility.getContext(conn, vars, "#User_Org", "AccountTree"),
- Utility.getContext(conn, vars, "#User_Client", "AccountTree"));
- resultantAccounts = calculateTree(forms, elementValueParent, new
Vector<Object>());
- }
- for (AccountTreeData account : resultantAccounts) {
- if ("C".equals(account.accountsign)) {
- account.qty = new BigDecimal(account.qty).negate().toString();
- account.qtyRef = new BigDecimal(account.qtyRef).negate().toString();
- }
+ Utility.getContext(conn, vars, "#User_Client", "AccountTree"),
+ OBDal.getInstance().get(ElementValue.class,
reportNodes[0]).getAccountingElement()
+ .getId());
+ reportElements = calculateTree(operands, reportNodes, new
Vector<Object>());
}
}
@@ -98,52 +95,50 @@
* VariablesSecureApp object with the session methods.
* @param _conn
* ConnectionProvider object with the connection methods.
- * @param _elements
+ * @param _accountsTree
* Array of account's elements (elementValues).
- * @param _accounts
+ * @param _accountsFacts
* Array of all the fact accts.
- * @param _elementValueParent
+ * @param _reportNodes
* Array with the value of the parent elements to evaluate (For
example, first expenses
* then revenues) Objective tree.
* @throws ServletException
*/
public AccountTree(VariablesSecureApp _vars, ConnectionProvider _conn,
- AccountTreeData[] _elements, AccountTreeData[] _accounts, String[]
_elementValueParent)
+ AccountTreeData[] _accountsTree, AccountTreeData[] _accountsFacts,
String[] _reportNodes)
throws ServletException {
if (log4j.isDebugEnabled())
log4j.debug("AccountTree []");
vars = _vars;
conn = _conn;
- elements = _elements;
- accounts = _accounts;
- elementValueParent = _elementValueParent;
+ accountsTree = _accountsTree;
+ accountsFacts = _accountsFacts;
+ reportNodes = _reportNodes;
+ applySignAsPerParent();
// Loading tree with new amounts, applying signs (Debit or Credit) and
// setting the account level (1, 2, 3,...)
- resultantAccounts = updateTreeQuantitiesSign(null, 0, "D");
- if (resultantAccounts != null && resultantAccounts.length > 0) {
+ reportElements = updateTreeQuantitiesSign(null, 0, "D");
+
+ if (reportElements != null && reportElements.length > 0) {
// Array of accounts with its operands.
// Calculating forms for every elements
- AccountTreeData[] forms = AccountTreeData.selectForms(conn,
+ AccountTreeData[] operands = AccountTreeData.selectOperands(conn,
Utility.getContext(conn, vars, "#User_Org", "AccountTree"),
- Utility.getContext(conn, vars, "#User_Client", "AccountTree"));
+ Utility.getContext(conn, vars, "#User_Client", "AccountTree"),
+ OBDal.getInstance().get(ElementValue.class,
reportNodes[0]).getAccountingElement()
+ .getId());
Vector<Object> vec = new Vector<Object>();
AccountTreeData[] r;
- for (int i = 0; i < elementValueParent.length; i++) {
- r = calculateTree(forms, elementValueParent[i], new Vector<Object>());
+ for (int i = 0; i < reportNodes.length; i++) {
+ r = calculateTree(operands, reportNodes[i], new Vector<Object>());
for (int j = 0; j < r.length; j++)
vec.addElement(r[j]);
}
- resultantAccounts = new AccountTreeData[vec.size()];
- vec.copyInto(resultantAccounts);
- }
- for (AccountTreeData account : resultantAccounts) {
- if ("C".equals(account.accountsign)) {
- account.qty = new BigDecimal(account.qty).negate().toString();
- account.qtyRef = new BigDecimal(account.qtyRef).negate().toString();
- }
+ reportElements = new AccountTreeData[vec.size()];
+ vec.copyInto(reportElements);
}
}
@@ -153,7 +148,7 @@
* @return Array with the resultant accounts.
*/
public AccountTreeData[] getAccounts() {
- return resultantAccounts;
+ return reportElements;
}
/**
@@ -167,26 +162,22 @@
* Boolean that indicates if this is a summary record.
* @return BigDecimal with the correct sign applied.
*/
- private BigDecimal applySign(BigDecimal qty, String sign, boolean isSummary,
String accountSign) {
+ private BigDecimal applyShowValueCond(BigDecimal qty, String sign, boolean
isSummary) {
// resetFlag will store whether the value has been truncated because of
// showvaluecond or not
- BigDecimal qtyWithSign = qty;
- if ("C".equals(accountSign)) {
- qtyWithSign = qtyWithSign.negate();
- }
resetFlag = false;
BigDecimal total = BigDecimal.ZERO;
if (isSummary && !sign.equalsIgnoreCase("A")) {
if (sign.equalsIgnoreCase("P")) {
- if (qtyWithSign.compareTo(total) > 0) {
- total = qtyWithSign;
+ if (qty.compareTo(total) > 0) {
+ total = qty;
} else {
total = BigDecimal.ZERO;
resetFlag = true;
}
} else if (sign.equalsIgnoreCase("N")) {
- if (qtyWithSign.compareTo(total) < 0) {
- total = qtyWithSign;
+ if (qty.compareTo(total) < 0) {
+ total = qty;
} else {
total = BigDecimal.ZERO;
resetFlag = true;
@@ -202,61 +193,66 @@
* Update the quantity and the operation quantity fields of the element,
depending on the
* isDebitCredit field.
*
- * @param element
+ * @param reportElement
* AccoutnTreeData object with the element information.
* @param isDebitCredit
* String with the parameter to evaluate if is a Debit or Credit
element.
* @return AccountTreeData object with the new element's information.
*/
- private AccountTreeData setDataQty(AccountTreeData element, String
isDebitCredit) {
- if (element == null || accounts == null || accounts.length == 0)
- return element;
- for (int i = 0; i < accounts.length; i++) {
- if (accounts[i].id.equals(element.id)) {
- element.qtyOperation = accounts[i].qty;
- element.qtyOperationRef = accounts[i].qtyRef;
- BigDecimal bdQty = new BigDecimal(element.qtyOperation);
- BigDecimal bdQtyRef = new BigDecimal(element.qtyOperationRef);
- element.qty = (applySign(bdQty, element.showvaluecond,
element.issummary.equals("Y"),
- element.accountsign)).toPlainString();
- element.qtyRef = (applySign(bdQtyRef, element.showvaluecond,
element.issummary.equals("Y"),
- element.accountsign)).toPlainString();
+ private AccountTreeData setDataQty(AccountTreeData reportElement, String
isDebitCredit) {
+ if (reportElement == null || accountsFacts == null || accountsFacts.length
== 0)
+ return reportElement;
+ for (int i = 0; i < accountsFacts.length; i++) {
+ if (accountsFacts[i].id.equals(reportElement.id)) {
+ if (isDebitCredit.equals("C")) {
+ accountsFacts[i].qty = accountsFacts[i].qtycredit;
+ accountsFacts[i].qtyRef = accountsFacts[i].qtycreditRef;
+ }
+ reportElement.qtyOperation = accountsFacts[i].qty;
+ reportElement.qtyOperationRef = accountsFacts[i].qtyRef;
+ BigDecimal bdQty = new BigDecimal(reportElement.qtyOperation);
+ BigDecimal bdQtyRef = new BigDecimal(reportElement.qtyOperationRef);
+ reportElement.qty = (applyShowValueCond(bdQty,
reportElement.showvaluecond,
+ reportElement.issummary.equals("Y"))).toPlainString();
+ reportElement.qtyRef = (applyShowValueCond(bdQtyRef,
reportElement.showvaluecond,
+ reportElement.issummary.equals("Y"))).toPlainString();
break;
}
}
- return element;
+ return reportElement;
}
/**
* This method updates all the Quantitie's signs of the tree. Is used by the
constructor to
* initialize the element's quantities. Also initializes the level of each
account
*
- * @param indice
+ * @param rootElement
* String with the index from which to start updating.
* @param level
* Integer with the level of the elements.
- * @param isDebitCredit
- * String with the is Debit or Credit value of the trunk.
+ * @param accountSign
+ * String with the is debit or credit value of the trunk.
* @return Array of AccountTreeData with the updated tree.
*/
- private AccountTreeData[] updateTreeQuantitiesSign(String indice, int level,
String isDebitCredit) {
- if (elements == null || elements.length == 0)
- return elements;
+ private AccountTreeData[] updateTreeQuantitiesSign(String rootElement, int
level,
+ String accountSign) {
+ if (accountsTree == null || accountsTree.length == 0)
+ return accountsTree;
AccountTreeData[] result = null;
Vector<Object> vec = new Vector<Object>();
// if (log4j.isDebugEnabled())
// log4j.debug("AccountTree.updateTreeQuantitiesSign() - elements: " +
// elements.length);
- if (indice == null)
- indice = "0";
- for (int i = 0; i < elements.length; i++) {
- if (elements[i].parentId.equals(indice)) {
- isDebitCredit = elements[i].accountsign;
- AccountTreeData[] dataChilds =
updateTreeQuantitiesSign(elements[i].nodeId, (level + 1),
- isDebitCredit);
- elements[i].elementLevel = Integer.toString(level);
- elements[i] = setDataQty(elements[i], isDebitCredit);
- vec.addElement(elements[i]);
+ if (rootElement == null)
+ rootElement = "0";
+ for (int i = 0; i < accountsTree.length; i++) {
+ if (accountsTree[i].parentId.equals(rootElement)) {
+ // accountSign = accountsTree[i].accountsign;
+ AccountTreeData[] dataChilds =
updateTreeQuantitiesSign(accountsTree[i].nodeId,
+ (level + 1), accountSign);
+ accountsTree[i].elementLevel = Integer.toString(level);
+ accountsTree[i] = setDataQty(accountsTree[i],
accountsTree[i].accountsign);
+ vec.addElement(accountsTree[i]);
if (dataChilds != null && dataChilds.length > 0) {
for (int j = 0; j < dataChilds.length; j++)
vec.addElement(dataChilds[j]);
@@ -277,7 +273,7 @@
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
Openbravo-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-commits