Author: jacopoc
Date: Mon Nov 1 10:18:19 2010
New Revision: 1029600
URL: http://svn.apache.org/viewvc?rev=1029600&view=rev
Log:
Implemented support for "contra revenue" classes in the Income Statement: this
will fix the incomplete information in financial reports for returns
Modified:
ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy
Modified: ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml?rev=1029600&r1=1029599&r2=1029600&view=diff
==============================================================================
--- ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml (original)
+++ ofbiz/trunk/applications/accounting/data/AccountingTypeData.xml Mon Nov 1
10:18:19 2010
@@ -211,6 +211,8 @@ under the License.
DEBIT
|___> NON_POSTING
|
+ |___> CONTRA_REVENUE
+ |
|___> ASSET
| |_________> LONGTERM_ASSET
| |
Modified:
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy
URL:
http://svn.apache.org/viewvc/ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy?rev=1029600&r1=1029599&r2=1029600&view=diff
==============================================================================
---
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy
(original)
+++
ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy
Mon Nov 1 10:18:19 2010
@@ -44,6 +44,8 @@ partyIds.add(organizationPartyId);
// Get the group of account classes that will be used to position accounts in
the proper section of the financial statement
GenericValue revenueGlAccountClass = delegator.findOne("GlAccountClass",
UtilMisc.toMap("glAccountClassId", "REVENUE"), true);
List revenueAccountClassIds =
UtilAccounting.getDescendantGlAccountClassIds(revenueGlAccountClass);
+GenericValue contraRevenueGlAccountClass = delegator.findOne("GlAccountClass",
UtilMisc.toMap("glAccountClassId", "CONTRA_REVENUE"), true);
+List contraRevenueAccountClassIds =
UtilAccounting.getDescendantGlAccountClassIds(contraRevenueGlAccountClass);
GenericValue incomeGlAccountClass = delegator.findOne("GlAccountClass",
UtilMisc.toMap("glAccountClassId", "INCOME"), true);
List incomeAccountClassIds =
UtilAccounting.getDescendantGlAccountClassIds(incomeGlAccountClass);
GenericValue expenseGlAccountClass = delegator.findOne("GlAccountClass",
UtilMisc.toMap("glAccountClassId", "EXPENSE"), true);
@@ -107,7 +109,48 @@ if (transactionTotals) {
context.revenueAccountBalanceList = accountBalanceList;
context.revenueAccountBalanceList.add(UtilMisc.toMap("accountName", "TOTAL
REVENUES", "balance", balanceTotal));
context.revenueBalanceTotal = balanceTotal;
-balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingTotalNetSales",
"balance", balanceTotal));
+
+// CONTRA REVENUE
+// account balances
+accountBalanceList = [];
+transactionTotals = [];
+balanceTotal = BigDecimal.ZERO;
+List contraRevenueAndExprs = FastList.newInstance(mainAndExprs);
+contraRevenueAndExprs.add(EntityCondition.makeCondition("glAccountClassId",
EntityOperator.IN, contraRevenueAccountClassIds));
+transactionTotals = delegator.findList("AcctgTransEntrySums",
EntityCondition.makeCondition(cogsExpenseAndExprs, EntityOperator.AND),
UtilMisc.toSet("glAccountId", "accountName", "accountCode", "debitCreditFlag",
"amount"), UtilMisc.toList("glAccountId"), null, false);
+if (transactionTotals) {
+ Map transactionTotalsMap = [:];
+ balanceTotalCredit = BigDecimal.ZERO;
+ balanceTotalDebit = BigDecimal.ZERO;
+ 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);
+ if ("D".equals(transactionTotal.debitCreditFlag)) {
+ balanceTotalDebit = balanceTotalDebit.add(transactionTotal.amount);
+ } else {
+ balanceTotalCredit =
balanceTotalCredit.add(transactionTotal.amount);
+ }
+ BigDecimal debitAmount = (BigDecimal)accountMap.get("D");
+ BigDecimal creditAmount = (BigDecimal)accountMap.get("C");
+ // contra revenues are accounts of class DEBIT: the balance is given
by debits minus credits
+ BigDecimal balance = debitAmount.subtract(creditAmount);
+ accountMap.put("balance", balance);
+ transactionTotalsMap.put(transactionTotal.glAccountId, accountMap);
+ }
+ accountBalanceList =
UtilMisc.sortMaps(transactionTotalsMap.values().asList(),
UtilMisc.toList("accountCode"));
+ // contra revenues are accounts of class DEBIT: the balance is given by
debits minus credits
+ balanceTotal = balanceTotalDebit.subtract(balanceTotalCredit);
+}
+context.contraRevenueBalanceTotal = balanceTotal;
+balanceTotalList.add(UtilMisc.toMap("totalName", "TOTAL CONTRA REVENUE",
"balance", balanceTotal));
// EXPENSE
// account balances
@@ -319,8 +362,11 @@ context.incomeAccountBalanceList = accou
context.incomeAccountBalanceList.add(UtilMisc.toMap("accountName", "TOTAL
INCOME", "balance", balanceTotal));
context.incomeBalanceTotal = balanceTotal;
+// NET SALES = REVENUES - CONTRA REVENUES
+context.netSales =
(context.revenueBalanceTotal).subtract(context.contraRevenueBalanceTotal);
+balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingTotalNetSales",
"balance", context.netSales));
// GROSS MARGIN = NET SALES - COSTS OF GOODS SOLD
-context.grossMargin =
(context.revenueBalanceTotal).subtract(context.cogsExpense);
+context.grossMargin = (context.netSales).subtract(context.cogsExpense);
balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingGrossMargin",
"balance", context.grossMargin));
// OPERATING EXPENSES
context.sgaExpense = sgaExpense;
@@ -332,8 +378,7 @@ balanceTotalList.add(UtilMisc.toMap("tot
context.incomeFromOperations =
(context.grossMargin).subtract(context.sgaExpense);
balanceTotalList.add(UtilMisc.toMap("totalName",
"AccountingIncomeFromOperations", "balance", context.incomeFromOperations));
// NET INCOME
-context.netIncome =
(context.revenueBalanceTotal).add(context.incomeBalanceTotal).subtract(context.expenseBalanceTotal);
+context.netIncome =
(context.netSales).add(context.incomeBalanceTotal).subtract(context.expenseBalanceTotal);
balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingNetIncome",
"balance", context.netIncome));
context.balanceTotalList = balanceTotalList;
-