svn commit: r1003465 - /ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy

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

svn commit: r1003465 - /ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy

hansbak-2
Author: hansbak
Date: Fri Oct  1 10:24:56 2010
New Revision: 1003465

URL: http://svn.apache.org/viewvc?rev=1003465&view=rev
Log:
In “IncomeStatement.groovy” file, add new gl account class for “DEPRECIATION”

Modified:
    ofbiz/trunk/applications/accounting/webapp/accounting/WEB-INF/actions/reports/IncomeStatement.groovy

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=1003465&r1=1003464&r2=1003465&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 Fri Oct  1 10:24:56 2010
@@ -52,6 +52,8 @@ GenericValue cogsExpenseGlAccountClass =
 List cogsExpenseAccountClassIds = UtilAccounting.getDescendantGlAccountClassIds(cogsExpenseGlAccountClass);
 GenericValue sgaExpenseGlAccountClass = delegator.findOne("GlAccountClass", UtilMisc.toMap("glAccountClassId", "SGA_EXPENSE"), true);
 List sgaExpenseAccountClassIds = UtilAccounting.getDescendantGlAccountClassIds(sgaExpenseGlAccountClass);
+GenericValue depreciationGlAccountClass = delegator.findOne("GlAccountClass", UtilMisc.toMap("glAccountClassId", "DEPRECIATION"), true);
+List depreciationAccountClassIds = UtilAccounting.getDescendantGlAccountClassIds(depreciationGlAccountClass);
 
 List mainAndExprs = FastList.newInstance();
 mainAndExprs.add(EntityCondition.makeCondition("organizationPartyId", EntityOperator.IN, partyIds));
@@ -105,7 +107,7 @@ if (transactionTotals) {
 context.revenueAccountBalanceList = accountBalanceList;
 context.revenueAccountBalanceList.add(UtilMisc.toMap("accountName", "TOTAL REVENUES", "balance", balanceTotal));
 context.revenueBalanceTotal = balanceTotal;
-balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingNetSales", "balance", balanceTotal));
+balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingTotalNetSales", "balance", balanceTotal));
 
 // EXPENSE
 // account balances
@@ -233,6 +235,47 @@ if (transactionTotals) {
 }
 sgaExpense = balanceTotal;
 
+//DEPRECIATION (DEPRECIATION)
+//account balances
+accountBalanceList = [];
+transactionTotals = [];
+balanceTotal = BigDecimal.ZERO;
+List depreciationAndExprs = FastList.newInstance(mainAndExprs);
+depreciationAndExprs.add(EntityCondition.makeCondition("glAccountClassId", EntityOperator.IN, depreciationAccountClassIds));
+transactionTotals = delegator.findList("AcctgTransEntrySums", EntityCondition.makeCondition(depreciationAndExprs, 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");
+   // expenses 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"));
+// expenses are accounts of class DEBIT: the balance is given by debits minus credits
+balanceTotal = balanceTotalDebit.subtract(balanceTotalCredit);
+}
+depreciation = balanceTotal;
+
 // INCOME
 // account balances
 accountBalanceList = [];
@@ -282,6 +325,9 @@ balanceTotalList.add(UtilMisc.toMap("tot
 // OPERATING EXPENSES
 context.sgaExpense = sgaExpense;
 balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingOperatingExpenses", "balance", context.sgaExpense));
+// DEPRECIATION
+context.depreciation = depreciation;
+balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingDepreciation", "balance", context.depreciation));
 // INCOME FROM OPERATIONS = GROSS MARGIN - OPERATING EXPENSES
 context.incomeFromOperations = (context.grossMargin).subtract(context.sgaExpense);
 balanceTotalList.add(UtilMisc.toMap("totalName", "AccountingIncomeFromOperations", "balance", context.incomeFromOperations));