svn commit: r604154 - in /ofbiz/trunk/applications/accounting: src/org/ofbiz/accounting/util/UtilAccounting.java widget/GlSetupForms.xml

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r604154 - in /ofbiz/trunk/applications/accounting: src/org/ofbiz/accounting/util/UtilAccounting.java widget/GlSetupForms.xml

jacopoc
Author: jacopoc
Date: Fri Dec 14 02:45:45 2007
New Revision: 604154

URL: http://svn.apache.org/viewvc?rev=604154&view=rev
Log:
Implemented util methods to get a list of descendant gl account class ids.
Fixed bug reported in OFBIZ-412

Modified:
    ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java
    ofbiz/trunk/applications/accounting/widget/GlSetupForms.xml

Modified: ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java?rev=604154&r1=604153&r2=604154&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java (original)
+++ ofbiz/trunk/applications/accounting/src/org/ofbiz/accounting/util/UtilAccounting.java Fri Dec 14 02:45:45 2007
@@ -19,6 +19,9 @@
 
 package org.ofbiz.accounting.util;
 
+import java.util.Iterator;
+import java.util.List;
+
 import org.ofbiz.accounting.AccountingException;
 import org.ofbiz.base.util.Debug;
 import org.ofbiz.base.util.UtilMisc;
@@ -26,6 +29,9 @@
 import org.ofbiz.entity.GenericEntityException;
 import org.ofbiz.entity.GenericValue;
 
+import javolution.util.FastList;
+
+
 public class UtilAccounting {
 
     public static String module = UtilAccounting.class.getName();
@@ -93,17 +99,35 @@
      */
     public static Double getNetBalance(GenericValue account, String debugModule) {
         try {
-            GenericValue glAccount = account.getRelatedOne("GlAccount");
-            double balance = 0.0;
-            if (isDebitAccount(glAccount)) {
-                balance = account.getDouble("postedDebits").doubleValue() - account.getDouble("postedCredits").doubleValue();
-            } else if (isCreditAccount(glAccount)) {
-                balance = account.getDouble("postedCredits").doubleValue() - account.getDouble("postedDebits").doubleValue();
-            }
-            return new Double(balance);    
+            return getNetBalance(account);
         } catch (GenericEntityException ex) {
             Debug.logError(ex.getMessage(), debugModule);
             return null;
+        }
+    }
+    public static Double getNetBalance(GenericValue account) throws GenericEntityException {
+        GenericValue glAccount = account.getRelatedOne("GlAccount");
+        double balance = 0.0;
+        if (isDebitAccount(glAccount)) {
+            balance = account.getDouble("postedDebits").doubleValue() - account.getDouble("postedCredits").doubleValue();
+        } else if (isCreditAccount(glAccount)) {
+            balance = account.getDouble("postedCredits").doubleValue() - account.getDouble("postedDebits").doubleValue();
+        }
+        return new Double(balance);    
+    }
+
+    public static List getDescendantGlAccountClassIds(GenericValue glAccountClass) throws GenericEntityException {
+        List glAccountClassIds = FastList.newInstance();
+        getGlAccountClassChildren(glAccountClass, glAccountClassIds);
+        return glAccountClassIds;
+    }
+    private static void getGlAccountClassChildren(GenericValue glAccountClass, List glAccountClassIds) throws GenericEntityException {
+        glAccountClassIds.add(glAccountClass.getString("glAccountClassId"));
+        List glAccountClassChildren = glAccountClass.getRelatedCache("ChildGlAccountClass");
+        Iterator glAccountClassChildrenIt = glAccountClassChildren.iterator();
+        while (glAccountClassChildrenIt.hasNext()) {
+            GenericValue glAccountClassChild = (GenericValue) glAccountClassChildrenIt.next();
+            getGlAccountClassChildren(glAccountClassChild, glAccountClassIds);
         }
     }
 

Modified: ofbiz/trunk/applications/accounting/widget/GlSetupForms.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/widget/GlSetupForms.xml?rev=604154&r1=604153&r2=604154&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/widget/GlSetupForms.xml (original)
+++ ofbiz/trunk/applications/accounting/widget/GlSetupForms.xml Fri Dec 14 02:45:45 2007
@@ -283,6 +283,12 @@
         <field name="remove" title="${uiLabelMap.CommonEmptyHeader}"><hyperlink target="removeSalInvoiceItemTypeGlAssignment?organizationPartyId=${organizationPartyId}&amp;invoiceItemTypeId=${invoiceItemTypeId}" description="${remove}"/></field>
     </form>
     <form name="AddSalInvoiceItemTypeGlAssignment" type="single" target="addSalInvoiceItemTypeGlAssignment">
+        <actions>
+            <entity-one entity-name="GlAccountClass" value-name="revenueGlAccountClass">
+                <field-map field-name="glAccountClassId" value="REVENUE"/>
+            </entity-one>
+            <set field="revenueAccountClassIds" value="${bsh:org.ofbiz.accounting.util.UtilAccounting.getDescendantGlAccountClassIds(revenueGlAccountClass)}" type="List"/>
+        </actions>
         <auto-fields-service service-name="addInvoiceItemTypeGlAssignment"/>
         <field name="organizationPartyId"><hidden value="${organizationPartyId}"/></field>
         <field name="invoiceItemTypeId">
@@ -297,7 +303,7 @@
             <drop-down>
                 <entity-options entity-name="GlAccountOrganizationAndClass" description="${accountName}[${glAccountId}]">
                     <entity-constraint name="organizationPartyId" operator="equals" value="${organizationPartyId}"/>
-                    <entity-constraint name="glAccountClassId" operator="equals" value="REVENUE"></entity-constraint>
+                    <entity-constraint name="glAccountClassId" operator="in" env-name="revenueAccountClassIds"></entity-constraint>
                     <entity-order-by field-name="description"/>
                 </entity-options>
             </drop-down>
@@ -320,6 +326,12 @@
         <field name="remove" title="${uiLabelMap.CommonEmptyHeader}"><hyperlink target="removePurInvoiceItemTypeGlAssignment?organizationPartyId=${organizationPartyId}&amp;invoiceItemTypeId=${invoiceItemTypeId}" description="${remove}"/></field>
     </form>
     <form name="AddPurInvoiceItemTypeGlAssignment" type="single" target="addPurInvoiceItemTypeGlAssignment">
+        <actions>
+            <entity-one entity-name="GlAccountClass" value-name="expenseGlAccountClass">
+                <field-map field-name="glAccountClassId" value="EXPENSE"/>
+            </entity-one>
+            <set field="expenseAccountClassIds" value="${bsh:org.ofbiz.accounting.util.UtilAccounting.getDescendantGlAccountClassIds(expenseGlAccountClass)}" type="List"/>
+        </actions>
         <auto-fields-service service-name="addInvoiceItemTypeGlAssignment"/>
         <field name="organizationPartyId"><hidden value="${organizationPartyId}"/></field>
         <field name="invoiceItemTypeId" title="Purchase invoice Item Type">
@@ -332,14 +344,13 @@
         </field>
         <field name="glAccountId" title="Override Expense Gl Account Id">
             <drop-down>
-                <entity-options entity-name="GlAccountOrganizationAndClass" description="${accountName}[${glAccountId}]">
+                <entity-options entity-name="GlAccountOrganizationAndClass" description="${accountName} [${glAccountId}]">
                     <entity-constraint name="organizationPartyId" operator="equals" value="${organizationPartyId}"/>
-                    <entity-constraint name="glAccountClassId" operator="equals" value="EXPENSE"></entity-constraint>
+                    <entity-constraint name="glAccountClassId" operator="in" env-name="expenseAccountClassIds"></entity-constraint>
                     <entity-order-by field-name="description"/>
                 </entity-options>
             </drop-down>
         </field>
-        
         <field name="submitButton" title="${uiLabelMap.CommonSave}"><submit/></field>
     </form>
     
@@ -437,6 +448,7 @@
         <field name="parentPeriodId">
           <display-entity entity-name="CustomTimePeriod" key-field-name="customTimePeriodId" description="[${customTimePeriodId}] ${periodName} ${uiLabelMap.CommonFrom} ${fromDate} ${uiLabelMap.CommonTo} ${thruDate}"/>
         </field>
+        <field name="close" title="${uiLabelMap.CommonEmptyHeader}"><hyperlink target="closeFinancialTimePeriod?organizationPartyId=${organizationPartyId}&amp;customTimePeriodId=${customTimePeriodId}" description="Close"/></field>
     </form>
     <form name="CreateTimePeriod" type="single" title="" target="createCustomTimePeriod">
         <auto-fields-service service-name="createCustomTimePeriod"/>