Author: jacopoc
Date: Wed Jan 13 10:44:07 2010
New Revision: 898710

URL: http://svn.apache.org/viewvc?rev=898710&view=rev
Log:
Removed old and unused services for data preparation of the balance sheet.
According to the discussion in the mailing list, moved the depreciation classes 
from Debit to Credit group; also modified data preparation script for balance 
sheet and financial time period closing.
Thanks to Adrian Crum and Mike Bates for the valuable information provided.


Modified:
    ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
    
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
    ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml
    
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/BalanceSheet.groovy

Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=898710&r1=898709&r2=898710&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Wed Jan 13 
10:44:07 2010
@@ -211,9 +211,6 @@
             |
             |___> ASSET
             |         |_________> LONGTERM_ASSET
-            |         |                       |____> ACCUM_DEPRECIATION
-            |         |                       |
-            |         |                       |____> ACCUM_AMORTIZATION
             |         |
             |         |_________> CURRENT_ASSET
             |                                 |____> CASH_EQUIVALENT
@@ -236,6 +233,11 @@
                                               |____> INVENTORY_ADJUST
 
         CREDIT
+            |___> CONTRA_ASSET
+            |              |___> ACCUM_DEPRECIATION
+            |              |
+            |              |___> ACCUM_AMORTIZATION
+            |
             |___> REVENUE
             |
             |___> INCOME
@@ -285,12 +287,13 @@
     <GlAccountClass description="Non-Cash Expense" 
glAccountClassId="NON_CASH_EXPENSE" parentClassId="EXPENSE"/>
     <GlAccountClass description="Depreciation" glAccountClassId="DEPRECIATION" 
parentClassId="NON_CASH_EXPENSE"/>
     <GlAccountClass description="Amortization" glAccountClassId="AMORTIZATION" 
parentClassId="NON_CASH_EXPENSE"/>
-    <!-- a special class for non-cash inventory adjustment expenses to avoid 
duplicating opearting cash flow adjustments for inventory
+    <!-- a special class for non-cash inventory adjustment expenses to avoid 
duplicating operating cash flow adjustments for inventory
          account transactions, which adjust operating cash flows -->
     <GlAccountClass description="Inventory Adjustment" 
glAccountClassId="INVENTORY_ADJUST" parentClassId="NON_CASH_EXPENSE"/>
-    <!-- same idea: these avoid double counting of depreciaton & amortization 
-->
-    <GlAccountClass description="Accumulated Depreciation" 
glAccountClassId="ACCUM_DEPRECIATION" parentClassId="LONGTERM_ASSET"/>
-    <GlAccountClass description="Accumulated Amortization" 
glAccountClassId="ACCUM_AMORTIZATION" parentClassId="LONGTERM_ASSET"/>
+    <!-- same idea: these avoid double counting of depreciation & amortization 
-->
+    <GlAccountClass description="Contra Asset" glAccountClassId="CONTRA_ASSET" 
parentClassId="CREDIT"/>
+    <GlAccountClass description="Accumulated Depreciation" 
glAccountClassId="ACCUM_DEPRECIATION" parentClassId="CONTRA_ASSET"/>
+    <GlAccountClass description="Accumulated Amortization" 
glAccountClassId="ACCUM_AMORTIZATION" parentClassId="CONTRA_ASSET"/>
     <GlAccountClass description="Non-Posting" glAccountClassId="NON_POSTING" 
parentClassId="DEBIT"/>
 
     <GlAccountType description="Accounts Receivable" 
glAccountTypeId="ACCOUNTS_RECEIVABLE" hasTable="N" parentTypeId=""/>

Modified: 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml?rev=898710&r1=898709&r2=898710&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
 (original)
+++ 
ofbiz/trunk/applications/accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml
 Wed Jan 13 10:44:07 2010
@@ -632,6 +632,12 @@
         <call-class-method 
class-name="org.ofbiz.accounting.util.UtilAccounting" 
method-name="getDescendantGlAccountClassIds" ret-field="assetAccountClassIds">
             <field field="assetGlAccountClass" type="GenericValue"/>
         </call-class-method>
+        <entity-one entity-name="GlAccountClass" 
value-field="contraAssetGlAccountClass">
+            <field-map field-name="glAccountClassId" value="CONTRA_ASSET"/>
+        </entity-one>
+        <call-class-method 
class-name="org.ofbiz.accounting.util.UtilAccounting" 
method-name="getDescendantGlAccountClassIds" 
ret-field="contraAssetAccountClassIds">
+            <field field="contraAssetGlAccountClass" type="GenericValue"/>
+        </call-class-method>
         <entity-one entity-name="GlAccountClass" 
value-field="liabilityGlAccountClass">
             <field-map field-name="glAccountClassId" value="LIABILITY"/>
         </entity-one>
@@ -760,7 +766,7 @@
             <store-value value-field="glAccountHistory"/>
         </iterate>
 
-        <!-- For all the accounts of class assets/liability/equity the 
endingBalance of the last time period's history is added to the one of the 
history of the period being closed -->
+        <!-- For all the accounts of class asset/contra-asset/liability/equity 
the endingBalance of the last time period's history is added to the one of the 
history of the period being closed -->
         <if-not-empty field="lastClosedTimePeriod">
             <entity-condition entity-name="GlAccountAndHistory" 
list="lastPeriodGlAccountAndHistories">
                 <condition-list combine="and">
@@ -768,6 +774,7 @@
                     <condition-expr field-name="customTimePeriodId" 
operator="equals" from-field="lastClosedTimePeriod.customTimePeriodId"/>
                     <condition-list combine="or">
                         <condition-expr field-name="glAccountClassId" 
operator="in" from-field="assetAccountClassIds"/>
+                        <condition-expr field-name="glAccountClassId" 
operator="in" from-field="contraAssetAccountClassIds"/>
                         <condition-expr field-name="glAccountClassId" 
operator="in" from-field="liabilityAccountClassIds"/>
                         <condition-expr field-name="glAccountClassId" 
operator="in" from-field="equityAccountClassIds"/>
                     </condition-list>
@@ -1027,293 +1034,6 @@
         <field-to-result field="glAccountTotalsMap" 
result-name="glAccountTotalsMap"/>
     </simple-method>
 
-    <simple-method method-name="prepareBalanceSheet" 
short-description="Prepare data for the Balance Sheet">
-        <entity-one entity-name="GlAccountClass" 
value-field="assetGlAccountClass">
-            <field-map field-name="glAccountClassId" value="ASSET"/>
-        </entity-one>
-        <call-class-method 
class-name="org.ofbiz.accounting.util.UtilAccounting" 
method-name="getDescendantGlAccountClassIds" ret-field="assetAccountClassIds">
-            <field field="assetGlAccountClass" type="GenericValue"/>
-        </call-class-method>
-        <entity-one entity-name="GlAccountClass" 
value-field="liabilityGlAccountClass">
-            <field-map field-name="glAccountClassId" value="LIABILITY"/>
-        </entity-one>
-        <call-class-method 
class-name="org.ofbiz.accounting.util.UtilAccounting" 
method-name="getDescendantGlAccountClassIds" 
ret-field="liabilityAccountClassIds">
-            <field field="liabilityGlAccountClass" type="GenericValue"/>
-        </call-class-method>
-        <entity-one entity-name="GlAccountClass" 
value-field="equityGlAccountClass">
-            <field-map field-name="glAccountClassId" value="EQUITY"/>
-        </entity-one>
-        <call-class-method 
class-name="org.ofbiz.accounting.util.UtilAccounting" 
method-name="getDescendantGlAccountClassIds" ret-field="equityAccountClassIds">
-            <field field="equityGlAccountClass" type="GenericValue"/>
-        </call-class-method>
-
-        <!-- retrieve the last closed date for the same type of time period -->
-        <set field="organizationPartyId" 
from-field="parameters.organizationPartyId"/>
-        <set field="partyIds" 
value="${groovy:org.ofbiz.party.party.PartyWorker.getAssociatedPartyIdsByRelationshipType(delegator,
 organizationPartyId, 'GROUP_ROLLUP')}" type="List"/>
-        <set field="partyIds[]" from-field="organizationPartyId"/>
-        <set field="findLastClosedDateInMap.organizationPartyId" 
from-field="organizationPartyId"/>
-        <set field="findLastClosedDateInMap.findDate" 
from-field="parameters.thruDate" type="Date"/>
-        <call-service service-name="findLastClosedDate" 
in-map-name="findLastClosedDateInMap">
-            <result-to-field result-name="lastClosedDate"/>
-            <result-to-field result-name="lastClosedTimePeriod"/>
-        </call-service>
-        <if-empty field="lastClosedDate">
-            <add-error><fail-message message="Unable to find a last closed 
date for time period for organization 
[${customTimePeriod.organizationPartyId}]"/></add-error>
-        </if-empty>
-        <check-errors/>
-
-        <if-not-empty field="lastClosedTimePeriod">
-            <entity-condition entity-name="GlAccountAndHistory" 
list="glAccountAndHistories">
-                <condition-list combine="and">
-                    <condition-expr field-name="organizationPartyId" 
operator="in" from-field="partyIds"/>
-                    <condition-expr field-name="customTimePeriodId" 
operator="equals" from-field="lastClosedTimePeriod.customTimePeriodId"/>
-                    <condition-expr field-name="glAccountClassId" 
operator="in" from-field="assetAccountClassIds"/>
-                </condition-list>
-                <order-by field-name="glAccountId"/>
-            </entity-condition>
-            <iterate list="glAccountAndHistories" entry="glAccountAndHistory">
-                <set 
field="glAccountTotalsAssetMap[glAccountAndHistory.glAccountId]" 
from-field="glAccountAndHistory.endingBalance"/>
-            </iterate>
-            <entity-condition entity-name="GlAccountAndHistory" 
list="glAccountAndHistories">
-                <condition-list combine="and">
-                    <condition-expr field-name="organizationPartyId" 
operator="in" from-field="partyIds"/>
-                    <condition-expr field-name="customTimePeriodId" 
operator="equals" from-field="lastClosedTimePeriod.customTimePeriodId"/>
-                    <condition-expr field-name="glAccountClassId" 
operator="in" from-field="liabilityAccountClassIds"/>
-                </condition-list>
-                <order-by field-name="glAccountId"/>
-            </entity-condition>
-            <iterate list="glAccountAndHistories" entry="glAccountAndHistory">
-                <set 
field="glAccountTotalsLiabilityMap[glAccountAndHistory.glAccountId]" 
from-field="glAccountAndHistory.endingBalance"/>
-            </iterate>
-            <entity-condition entity-name="GlAccountAndHistory" 
list="glAccountAndHistories">
-                <condition-list combine="and">
-                    <condition-expr field-name="organizationPartyId" 
operator="in" from-field="partyIds"/>
-                    <condition-expr field-name="customTimePeriodId" 
operator="equals" from-field="lastClosedTimePeriod.customTimePeriodId"/>
-                    <condition-expr field-name="glAccountClassId" 
operator="in" from-field="equityAccountClassIds"/>
-                </condition-list>
-                <order-by field-name="glAccountId"/>
-            </entity-condition>
-            <iterate list="glAccountAndHistories" entry="glAccountAndHistory">
-                <set 
field="glAccountTotalsEquityMap[glAccountAndHistory.glAccountId]" 
from-field="glAccountAndHistory.endingBalance"/>
-            </iterate>
-        </if-not-empty>
-
-        <entity-condition entity-name="AcctgTransAndEntries" 
list="acctgTransAndEntries">
-            <condition-list combine="and">
-                <condition-expr field-name="organizationPartyId" operator="in" 
from-field="partyIds"/>
-                <condition-expr field-name="isPosted" operator="equals" 
value="Y"/>
-                <condition-expr field-name="glFiscalTypeId" operator="equals" 
from-field="parameters.glFiscalTypeId"/>
-                <condition-expr field-name="transactionDate" 
operator="greater-equals" from-field="lastClosedDate"/>
-                <condition-expr field-name="transactionDate" operator="less" 
from-field="parameters.thruDate"/> <!-- FIXME: Date to Timestamp -->
-                <condition-expr field-name="acctgTransTypeId" 
operator="not-equals" value="PERIOD_CLOSING"/>
-                <condition-expr field-name="glAccountClassId" operator="in" 
from-field="assetAccountClassIds"/>
-            </condition-list>
-            <order-by field-name="acctgTransId"/>
-            <order-by field-name="acctgTransEntrySeqId"/>
-        </entity-condition>
-        <iterate list="acctgTransAndEntries" entry="acctgTransAndEntry">
-            <set field="amount" from-field="acctgTransAndEntry.amount"/>
-            <if-compare field="acctgTransAndEntry.debitCreditFlag" 
operator="equals" value="C">
-                <calculate field="amount">
-                    <calcop field="amount" operator="negative"/>
-                </calculate>
-            </if-compare>
-            <if-empty 
field="glAccountTotalsAssetMap[acctgTransAndEntry.glAccountId]">
-                <set 
field="glAccountTotalsAssetMap[acctgTransAndEntry.glAccountId]" value="0.0" 
type="BigDecimal"/>
-            </if-empty>
-            <calculate 
field="glAccountTotalsAssetMap[acctgTransAndEntry.glAccountId]">
-                <calcop 
field="glAccountTotalsAssetMap[acctgTransAndEntry.glAccountId]" 
operator="add"><calcop field="amount" operator="get"/></calcop>
-            </calculate>
-        </iterate>
-        <entity-condition entity-name="AcctgTransAndEntries" 
list="acctgTransAndEntries">
-            <condition-list combine="and">
-                <condition-expr field-name="organizationPartyId" operator="in" 
from-field="partyIds"/>
-                <condition-expr field-name="isPosted" operator="equals" 
value="Y"/>
-                <condition-expr field-name="glFiscalTypeId" operator="equals" 
from-field="parameters.glFiscalTypeId"/>
-                <condition-expr field-name="transactionDate" 
operator="greater-equals" from-field="lastClosedDate"/>
-                <condition-expr field-name="transactionDate" operator="less" 
from-field="parameters.thruDate"/> <!-- FIXME: Date to Timestamp -->
-                <condition-expr field-name="acctgTransTypeId" 
operator="not-equals" value="PERIOD_CLOSING"/>
-                <condition-expr field-name="glAccountClassId" operator="in" 
from-field="liabilityAccountClassIds"/>
-            </condition-list>
-            <order-by field-name="acctgTransId"/>
-            <order-by field-name="acctgTransEntrySeqId"/>
-        </entity-condition>
-        <iterate list="acctgTransAndEntries" entry="acctgTransAndEntry">
-            <set field="amount" from-field="acctgTransAndEntry.amount"/>
-            <if-compare field="acctgTransAndEntry.debitCreditFlag" 
operator="equals" value="D">
-                <calculate field="amount">
-                    <calcop field="amount" operator="negative"/>
-                </calculate>
-            </if-compare>
-            <if-empty 
field="glAccountTotalsLiabilityMap[acctgTransAndEntry.glAccountId]">
-                <set 
field="glAccountTotalsLiabilityMap[acctgTransAndEntry.glAccountId]" value="0.0" 
type="BigDecimal"/>
-            </if-empty>
-            <calculate 
field="glAccountTotalsLiabilityMap[acctgTransAndEntry.glAccountId]">
-                <calcop 
field="glAccountTotalsLiabilityMap[acctgTransAndEntry.glAccountId]" 
operator="add"><calcop field="amount" operator="get"/></calcop>
-            </calculate>
-        </iterate>
-        <entity-condition entity-name="AcctgTransAndEntries" 
list="acctgTransAndEntries">
-            <condition-list combine="and">
-                <condition-expr field-name="organizationPartyId" operator="in" 
from-field="partyIds"/>
-                <condition-expr field-name="isPosted" operator="equals" 
value="Y"/>
-                <condition-expr field-name="glFiscalTypeId" operator="equals" 
from-field="parameters.glFiscalTypeId"/>
-                <condition-expr field-name="transactionDate" 
operator="greater-equals" from-field="lastClosedDate"/>
-                <condition-expr field-name="transactionDate" operator="less" 
from-field="parameters.thruDate"/> <!-- FIXME: Date to Timestamp -->
-                <condition-expr field-name="acctgTransTypeId" 
operator="not-equals" value="PERIOD_CLOSING"/>
-                <condition-expr field-name="glAccountClassId" operator="in" 
from-field="equityAccountClassIds"/>
-            </condition-list>
-            <order-by field-name="acctgTransId"/>
-            <order-by field-name="acctgTransEntrySeqId"/>
-        </entity-condition>
-        <iterate list="acctgTransAndEntries" entry="acctgTransAndEntry">
-            <set field="amount" from-field="acctgTransAndEntry.amount"/>
-            <if-compare field="acctgTransAndEntry.debitCreditFlag" 
operator="equals" value="D">
-                <calculate field="amount">
-                    <calcop field="amount" operator="negative"/>
-                </calculate>
-            </if-compare>
-            <if-empty 
field="glAccountTotalsEquityMap[acctgTransAndEntry.glAccountId]">
-                <set 
field="glAccountTotalsEquityMap[acctgTransAndEntry.glAccountId]" value="0.0" 
type="BigDecimal"/>
-            </if-empty>
-            <calculate 
field="glAccountTotalsEquityMap[acctgTransAndEntry.glAccountId]">
-                <calcop 
field="glAccountTotalsEquityMap[acctgTransAndEntry.glAccountId]" 
operator="add"><calcop field="amount" operator="get"/></calcop>
-            </calculate>
-        </iterate>
-
-        <set field="prepareIncomeStatementInMap.organizationPartyId" 
from-field="organizationPartyId"/>
-        <set field="prepareIncomeStatementInMap.glFiscalTypeId" 
from-field="parameters.glFiscalTypeId"/>
-        <set field="prepareIncomeStatementInMap.fromDate" 
from-field="lastClosedDate"/>
-        <set field="prepareIncomeStatementInMap.thruDate" 
from-field="parameters.thruDate"/>
-        <call-service service-name="prepareIncomeStatement" 
in-map-name="prepareIncomeStatementInMap">
-            <result-to-field result-name="totalNetIncome"/>
-        </call-service>
-        <!-- get the retained earnings account -->
-        <entity-one entity-name="GlAccountTypeDefault" 
value-field="retainedEarningsAccount" use-cache="true">
-            <field-map field-name="organizationPartyId"/>
-            <field-map field-name="glAccountTypeId" value="RETAINED_EARNINGS"/>
-        </entity-one>
-        <if-not-empty field="retainedEarningsAccount">
-            <if-empty 
field="glAccountTotalsEquityMap[retainedEarningsAccount.glAccountId]">
-                <set 
field="glAccountTotalsEquityMap[retainedEarningsAccount.glAccountId]" 
value="0.0" type="BigDecimal"/>
-            </if-empty>
-            <calculate 
field="glAccountTotalsEquityMap[retainedEarningsAccount.glAccountId]">
-                <calcop 
field="glAccountTotalsEquityMap[retainedEarningsAccount.glAccountId]" 
operator="add"><calcop field="totalNetIncome" operator="get"/></calcop>
-            </calculate>
-        </if-not-empty>
-
-        <iterate-map map="glAccountTotalsAssetMap" key="glAccountId" 
value="totalAmount">
-            <clear-field field="glAccountTotalMap"/>
-            <set field="glAccountTotalMap.glAccountId" 
from-field="glAccountId"/>
-            <set field="glAccountTotalMap.totalAmount" 
from-field="totalAmount"/>
-            <set field="assetBalancesList[]" from-field="glAccountTotalMap"/>
-        </iterate-map>
-        <iterate-map map="glAccountTotalsLiabilityMap" key="glAccountId" 
value="totalAmount">
-            <clear-field field="glAccountTotalMap"/>
-            <set field="glAccountTotalMap.glAccountId" 
from-field="glAccountId"/>
-            <set field="glAccountTotalMap.totalAmount" 
from-field="totalAmount"/>
-            <set field="liabilityBalancesList[]" 
from-field="glAccountTotalMap"/>
-        </iterate-map>
-        <iterate-map map="glAccountTotalsEquityMap" key="glAccountId" 
value="totalAmount">
-            <clear-field field="glAccountTotalMap"/>
-            <set field="glAccountTotalMap.glAccountId" 
from-field="glAccountId"/>
-            <set field="glAccountTotalMap.totalAmount" 
from-field="totalAmount"/>
-            <set field="equityBalancesList[]" from-field="glAccountTotalMap"/>
-        </iterate-map>
-
-        <field-to-result field="assetBalancesList" 
result-name="assetBalancesList"/>
-        <field-to-result field="liabilityBalancesList" 
result-name="liabilityBalancesList"/>
-        <field-to-result field="equityBalancesList" 
result-name="equityBalancesList"/>
-    </simple-method>
-
-    <simple-method method-name="prepareComparativeBalanceSheet" 
short-description="Prepare data for the Comparative Balance Sheet">
-        <set field="prepareBalanceSheetInMap.organizationPartyId" 
from-field="parameters.organizationPartyId"/>
-        <set field="prepareBalanceSheetInMap.glFiscalTypeId" 
from-field="parameters.period1GlFiscalTypeId"/>
-        <set field="prepareBalanceSheetInMap.thruDate" 
from-field="parameters.period1ThruDate"/>
-        <call-service service-name="prepareBalanceSheet" 
in-map-name="prepareBalanceSheetInMap">
-            <result-to-field result-name="assetBalancesList" 
field="period1AssetBalancesList"/>
-            <result-to-field result-name="liabilityBalancesList" 
field="period1LiabilityBalancesList"/>
-            <result-to-field result-name="equityBalancesList" 
field="period1EquityBalancesList"/>
-        </call-service>
-        <set field="prepareBalanceSheetInMap.glFiscalTypeId" 
from-field="parameters.period2GlFiscalTypeId"/>
-        <set field="prepareBalanceSheetInMap.thruDate" 
from-field="parameters.period2ThruDate"/>
-        <call-service service-name="prepareBalanceSheet" 
in-map-name="prepareBalanceSheetInMap">
-            <result-to-field result-name="assetBalancesList" 
field="period2AssetBalancesList"/>
-            <result-to-field result-name="liabilityBalancesList" 
field="period2LiabilityBalancesList"/>
-            <result-to-field result-name="equityBalancesList" 
field="period2EquityBalancesList"/>
-        </call-service>
-
-        <iterate list="period2AssetBalancesList" entry="period2AssetBalance">
-            <set field="assetBalancesMap[period2AssetBalance.glAccountId]" 
from-field="period2AssetBalance.totalAmount"/>
-        </iterate>
-        <iterate list="period1AssetBalancesList" entry="period1AssetBalance">
-            <set field="amount" from-field="period1AssetBalance.totalAmount"/>
-            <calculate field="amount">
-                <calcop field="amount" operator="negative"/>
-            </calculate>
-            <if-empty 
field="assetBalancesMap[period1AssetBalance.glAccountId]">
-                <set field="assetBalancesMap[period1AssetBalance.glAccountId]" 
value="0.0" type="BigDecimal"/>
-            </if-empty>
-            <calculate 
field="assetBalancesMap[period1AssetBalance.glAccountId]">
-                <calcop 
field="assetBalancesMap[period1AssetBalance.glAccountId]" 
operator="add"><calcop field="amount" operator="get"/></calcop>
-            </calculate>
-        </iterate>
-
-        <iterate list="period2LiabilityBalancesList" 
entry="period2LiabilityBalance">
-            <set 
field="liabilityBalancesMap[period2LiabilityBalance.glAccountId]" 
from-field="period2LiabilityBalance.totalAmount"/>
-        </iterate>
-        <iterate list="period1LiabilityBalancesList" 
entry="period1LiabilityBalance">
-            <set field="amount" 
from-field="period1LiabilityBalance.totalAmount"/>
-            <calculate field="amount">
-                <calcop field="amount" operator="negative"/>
-            </calculate>
-            <if-empty 
field="liabilityBalancesMap[period1LiabilityBalance.glAccountId]">
-                <set 
field="liabilityBalancesMap[period1LiabilityBalance.glAccountId]" value="0.0" 
type="BigDecimal"/>
-            </if-empty>
-            <calculate 
field="liabilityBalancesMap[period1LiabilityBalance.glAccountId]">
-                <calcop 
field="liabilityBalancesMap[period1LiabilityBalance.glAccountId]" 
operator="add"><calcop field="amount" operator="get"/></calcop>
-            </calculate>
-        </iterate>
-
-        <iterate list="period2EquityBalancesList" entry="period2EquityBalance">
-            <set field="equityBalancesMap[period2EquityBalance.glAccountId]" 
from-field="period2EquityBalance.totalAmount"/>
-        </iterate>
-        <iterate list="period1EquityBalancesList" entry="period1EquityBalance">
-            <set field="amount" from-field="period1EquityBalance.totalAmount"/>
-            <calculate field="amount">
-                <calcop field="amount" operator="negative"/>
-            </calculate>
-            <if-empty 
field="equityBalancesMap[period1EquityBalance.glAccountId]">
-                <set 
field="equityBalancesMap[period1EquityBalance.glAccountId]" value="0.0" 
type="BigDecimal"/>
-            </if-empty>
-            <calculate 
field="equityBalancesMap[period1EquityBalance.glAccountId]">
-                <calcop 
field="equityBalancesMap[period1EquityBalance.glAccountId]" 
operator="add"><calcop field="amount" operator="get"/></calcop>
-            </calculate>
-        </iterate>
-
-        <iterate-map map="assetBalancesMap" key="glAccountId" 
value="totalAmount">
-            <clear-field field="glAccountTotalMap"/>
-            <set field="glAccountTotalMap.glAccountId" 
from-field="glAccountId"/>
-            <set field="glAccountTotalMap.totalAmount" 
from-field="totalAmount"/>
-            <set field="assetBalancesList[]" from-field="glAccountTotalMap"/>
-        </iterate-map>
-        <iterate-map map="liabilityBalancesMap" key="glAccountId" 
value="totalAmount">
-            <clear-field field="glAccountTotalMap"/>
-            <set field="glAccountTotalMap.glAccountId" 
from-field="glAccountId"/>
-            <set field="glAccountTotalMap.totalAmount" 
from-field="totalAmount"/>
-            <set field="liabilityBalancesList[]" 
from-field="glAccountTotalMap"/>
-        </iterate-map>
-        <iterate-map map="equityBalancesMap" key="glAccountId" 
value="totalAmount">
-            <clear-field field="glAccountTotalMap"/>
-            <set field="glAccountTotalMap.glAccountId" 
from-field="glAccountId"/>
-            <set field="glAccountTotalMap.totalAmount" 
from-field="totalAmount"/>
-            <set field="equityBalancesList[]" from-field="glAccountTotalMap"/>
-        </iterate-map>
-
-        <field-to-result field="assetBalancesList" 
result-name="assetBalancesList"/>
-        <field-to-result field="liabilityBalancesList" 
result-name="liabilityBalancesList"/>
-        <field-to-result field="equityBalancesList" 
result-name="equityBalancesList"/>
-    </simple-method>
-
     <!-- Services for the automatic creation of accounting transactions based 
on business transactions
          Typically, these services are triggered by SECAs -->
 

Modified: ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml?rev=898710&r1=898709&r2=898710&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml 
(original)
+++ ofbiz/trunk/applications/accounting/servicedef/services_ledger.xml Wed Jan 
13 10:44:07 2010
@@ -306,28 +306,6 @@
         <attribute name="totalNetIncome" type="BigDecimal" mode="OUT" 
optional="false"/>
         <attribute name="glAccountTotalsMap" type="Map" mode="OUT" 
optional="true"/>
     </service>
-    <service name="prepareBalanceSheet" engine="simple"
-        
location="component://accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml"
 invoke="prepareBalanceSheet" auth="true">
-        <description>Prepare the data for the Balance Sheet</description>
-        <attribute name="organizationPartyId" type="String" mode="IN" 
optional="false"/>
-        <attribute name="thruDate" type="Timestamp" mode="IN" 
optional="false"/>
-        <attribute name="glFiscalTypeId" type="String" mode="IN" 
optional="false"/>
-        <attribute name="assetBalancesList" type="List" mode="OUT" 
optional="true"/>
-        <attribute name="liabilityBalancesList" type="List" mode="OUT" 
optional="true"/>
-        <attribute name="equityBalancesList" type="List" mode="OUT" 
optional="true"/>
-    </service>
-    <service name="prepareComparativeBalanceSheet" engine="simple"
-        
location="component://accounting/script/org/ofbiz/accounting/ledger/GeneralLedgerServices.xml"
 invoke="prepareComparativeBalanceSheet" auth="true">
-        <description>Prepare the data for the Balance Sheet</description>
-        <attribute name="organizationPartyId" type="String" mode="IN" 
optional="false"/>
-        <attribute name="period1ThruDate" type="Timestamp" mode="IN" 
optional="false"/>
-        <attribute name="period1GlFiscalTypeId" type="String" mode="IN" 
optional="false"/>
-        <attribute name="period2ThruDate" type="Timestamp" mode="IN" 
optional="false"/>
-        <attribute name="period2GlFiscalTypeId" type="String" mode="IN" 
optional="false"/>
-        <attribute name="assetBalancesList" type="List" mode="OUT" 
optional="true"/>
-        <attribute name="liabilityBalancesList" type="List" mode="OUT" 
optional="true"/>
-        <attribute name="equityBalancesList" type="List" mode="OUT" 
optional="true"/>
-    </service>
 
     <!-- Miscellaneous Ledger-related services -->
     <service name="getGlAccountFromAccountType" engine="simple"

Modified: 
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/BalanceSheet.groovy
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/BalanceSheet.groovy?rev=898710&r1=898709&r2=898710&view=diff
==============================================================================
--- 
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/BalanceSheet.groovy
 (original)
+++ 
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/BalanceSheet.groovy
 Wed Jan 13 10:44:07 2010
@@ -44,6 +44,8 @@
 // Get the group of account classes that will be used to position accounts in 
the proper section of the financial statement
 GenericValue assetGlAccountClass = delegator.findOne("GlAccountClass", 
UtilMisc.toMap("glAccountClassId", "ASSET"), true);
 List assetAccountClassIds = 
UtilAccounting.getDescendantGlAccountClassIds(assetGlAccountClass);
+GenericValue contraAssetGlAccountClass = delegator.findOne("GlAccountClass", 
UtilMisc.toMap("glAccountClassId", "CONTRA_ASSET"), true);
+List contraAssetAccountClassIds = 
UtilAccounting.getDescendantGlAccountClassIds(contraAssetGlAccountClass);
 GenericValue liabilityGlAccountClass = delegator.findOne("GlAccountClass", 
UtilMisc.toMap("glAccountClassId", "LIABILITY"), true);
 List liabilityAccountClassIds = 
UtilAccounting.getDescendantGlAccountClassIds(liabilityGlAccountClass);
 GenericValue equityGlAccountClass = delegator.findOne("GlAccountClass", 
UtilMisc.toMap("glAccountClassId", "EQUITY"), true);
@@ -68,6 +70,7 @@
 GenericValue lastClosedTimePeriod = 
(GenericValue)lastClosedTimePeriodResult.lastClosedTimePeriod;
 // Get the opening balances of all the accounts
 Map assetOpeningBalances = [:];
+Map contraAssetOpeningBalances = [:];
 Map currentAssetOpeningBalances = [:];
 Map longtermAssetOpeningBalances = [:];
 Map liabilityOpeningBalances = [:];
@@ -86,6 +89,16 @@
     }
     timePeriodAndExprs = FastList.newInstance();
     
timePeriodAndExprs.add(EntityCondition.makeCondition("organizationPartyId", 
EntityOperator.IN, partyIds));
+    timePeriodAndExprs.add(EntityCondition.makeCondition("glAccountClassId", 
EntityOperator.IN, contraAssetAccountClassIds));
+    timePeriodAndExprs.add(EntityCondition.makeCondition("endingBalance", 
EntityOperator.NOT_EQUAL, BigDecimal.ZERO));
+    timePeriodAndExprs.add(EntityCondition.makeCondition("customTimePeriodId", 
EntityOperator.EQUALS, lastClosedTimePeriod.customTimePeriodId));
+    lastTimePeriodHistories = delegator.findList("GlAccountAndHistory", 
EntityCondition.makeCondition(timePeriodAndExprs, EntityOperator.AND), null, 
null, null, false);
+    lastTimePeriodHistories.each { lastTimePeriodHistory ->
+        Map accountMap = UtilMisc.toMap("glAccountId", 
lastTimePeriodHistory.glAccountId, "accountCode", 
lastTimePeriodHistory.accountCode, "accountName", 
lastTimePeriodHistory.accountName, "balance", 
lastTimePeriodHistory.getBigDecimal("endingBalance"), "D", 
lastTimePeriodHistory.getBigDecimal("postedDebits"), "C", 
lastTimePeriodHistory.getBigDecimal("postedCredits"));
+        contraAssetOpeningBalances.put(lastTimePeriodHistory.glAccountId, 
accountMap);
+    }
+    timePeriodAndExprs = FastList.newInstance();
+    
timePeriodAndExprs.add(EntityCondition.makeCondition("organizationPartyId", 
EntityOperator.IN, partyIds));
     timePeriodAndExprs.add(EntityCondition.makeCondition("glAccountClassId", 
EntityOperator.IN, liabilityAccountClassIds));
     timePeriodAndExprs.add(EntityCondition.makeCondition("endingBalance", 
EntityOperator.NOT_EQUAL, BigDecimal.ZERO));
     timePeriodAndExprs.add(EntityCondition.makeCondition("customTimePeriodId", 
EntityOperator.EQUALS, lastClosedTimePeriod.customTimePeriodId));
@@ -253,6 +266,45 @@
 context.longtermAssetBalanceTotal = balanceTotal;
 balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingLongTermAssets", 
"balance", balanceTotal));
 
+// CONTRA ASSETS
+// account balances
+accountBalanceList = [];
+transactionTotals = [];
+balanceTotal = BigDecimal.ZERO;
+List contraAssetAndExprs = FastList.newInstance(mainAndExprs);
+contraAssetAndExprs.add(EntityCondition.makeCondition("glAccountClassId", 
EntityOperator.IN, contraAssetAccountClassIds));
+transactionTotals = delegator.findList("AcctgTransEntrySums", 
EntityCondition.makeCondition(contraAssetAndExprs, EntityOperator.AND), 
UtilMisc.toSet("glAccountId", "accountName", "accountCode", "debitCreditFlag", 
"amount"), UtilMisc.toList("glAccountId"), null, false);
+
+transactionTotalsMap = [:];
+transactionTotalsMap.putAll(contraAssetOpeningBalances);
+transactionTotals.each { transactionTotal ->
+    Map accountMap = 
(Map)transactionTotalsMap.get(transactionTotal.glAccountId);
+    if (!accountMap) {
+        accountMap = UtilMisc.makeMapWritable(transactionTotal);
+        accountMap.remove("debitCreditFlag");
+        accountMap.remove("amount");
+        accountMap.put("D", BigDecimal.ZERO);
+        accountMap.put("C", BigDecimal.ZERO);
+        accountMap.put("balance", BigDecimal.ZERO);
+    }
+    UtilMisc.addToBigDecimalInMap(accountMap, 
transactionTotal.debitCreditFlag, transactionTotal.amount);
+    BigDecimal debitAmount = (BigDecimal)accountMap.get("D");
+    BigDecimal creditAmount = (BigDecimal)accountMap.get("C");
+    // contra assets are accounts of class CREDIT: the balance is given by 
credits minus debits
+    BigDecimal balance = creditAmount.subtract(debitAmount);
+    accountMap.put("balance", balance);
+    transactionTotalsMap.put(transactionTotal.glAccountId, accountMap);
+}
+accountBalanceList = UtilMisc.sortMaps(transactionTotalsMap.values().asList(), 
UtilMisc.toList("accountCode"));
+accountBalanceList.each { accountBalance ->
+    balanceTotal = balanceTotal + accountBalance.balance;
+}
+//context.contraAssetAccountBalanceList = accountBalanceList;
+context.assetAccountBalanceList.addAll(accountBalanceList);
+context.assetAccountBalanceList.add(UtilMisc.toMap("accountName", "TOTAL 
ACCUMULATED DEPRECIATION", "balance", balanceTotal));
+context.contraAssetBalanceTotal = balanceTotal;
+balanceTotalList.add(UtilMisc.toMap("totalName", 
"AccountingLongTermAssetsAtCost", "balance", (context.longtermAssetBalanceTotal 
- context.contraAssetBalanceTotal)));
+
 // LIABILITY
 // account balances
 accountBalanceList = [];


Reply via email to