📄 financialservices.java
字号:
return ServiceUtil.returnError("Cannot get a starting date from custom time period = " + fromTimePeriodId); } else if (thruTimePeriod.get("thruDate") == null) { return ServiceUtil.returnError("Cannot get a starting date from custom time period = " + thruTimePeriodId); } // call the service and pass back the results. input.put("fromDate", UtilDateTime.toTimestamp(fromTimePeriod.getDate("fromDate"))); input.put("thruDate", UtilDateTime.toTimestamp(thruTimePeriod.getDate("thruDate"))); Map result = dispatcher.runSync(serviceName, input); return result; } catch (GenericEntityException ex) { return(ServiceUtil.returnError(ex.getMessage())); } catch (GenericServiceException ex) { return(ServiceUtil.returnError(ex.getMessage())); } } public static Map getCashFlowStatementForTimePeriods(DispatchContext dctx, Map context) { String organizationPartyId = (String) context.get("organizationPartyId"); String glFiscalTypeId = (String) context.get("glFiscalTypeId"); GenericValue userLogin = (GenericValue) context.get("userLogin"); Map input = UtilMisc.toMap("organizationPartyId", organizationPartyId, "glFiscalTypeId", glFiscalTypeId, "userLogin", userLogin); return reportServiceTimePeriodHelper(dctx, context, "getCashFlowStatementForDates", input); } public static Map getCashFlowStatementForDates(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); GenericValue userLogin = (GenericValue) context.get("userLogin"); Timestamp fromDate = (Timestamp) context.get("fromDate"); Timestamp thruDate = (Timestamp) context.get("thruDate"); String organizationPartyId = (String) context.get("organizationPartyId"); String glFiscalTypeId = (String) context.get("glFiscalTypeId"); try { Map input = UtilMisc.toMap("organizationPartyId", organizationPartyId, "glFiscalTypeId", glFiscalTypeId, "userLogin", userLogin); // run comparitive balance sheet for the date range input.put("fromDate", fromDate); input.put("thruDate", thruDate); Map comparativeResults = dispatcher.runSync("getComparativeBalanceSheet", input); if (ServiceUtil.isError(comparativeResults)) { return ServiceUtil.returnError("Faild to compute cash flow statement. ", null, null, comparativeResults); } // extract the from date balance sheet and thru date balance sheet for convenience Map fromDateAccountBalances = (Map) comparativeResults.get("fromDateAccountBalances"); Map thruDateAccountBalances = (Map) comparativeResults.get("thruDateAccountBalances"); // run income statement for same date range Map incomeResults = dispatcher.runSync("getIncomeStatementByDates", input); if (ServiceUtil.isError(incomeResults)) { return ServiceUtil.returnError("Faild to compute cash flow statement. ", null, null, incomeResults); } // extract the netIncome for convenience BigDecimal netIncome = new BigDecimal(((Double) incomeResults.get("netIncome")).doubleValue()); // compute the beginning cash amount from accounts with glAccountClassId = CASH_EQUIVALENT and make a map of these accounts for return BigDecimal beginningCashAmount = ZERO; Map beginningCashAccountBalances = FastMap.newInstance(); Map beginningSheet = (Map) fromDateAccountBalances.get("assetAccountBalances"); // beginning cash equivalents are in from date balance sheet assets for (Iterator iter = beginningSheet.keySet().iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); if (!UtilAccounting.isAccountClass(account, "CASH_EQUIVALENT")) continue; // skip non cash equivalent accounts BigDecimal amount = new BigDecimal(((Double) beginningSheet.get(account)).doubleValue()); beginningCashAccountBalances.put(account, amount); beginningCashAmount = beginningCashAmount.add(amount).setScale(decimals, rounding); } // compute the ending cash amount from accounts with glAccountClassId = CASH_EQUIVALENT and make a map of these accounts for return BigDecimal endingCashAmount = ZERO; Map endingCashAccountBalances = FastMap.newInstance(); Map endingSheet = (Map) thruDateAccountBalances.get("assetAccountBalances"); // ending cash equivalents are in thru date balance sheet assets for (Iterator iter = endingSheet.keySet().iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); if (!UtilAccounting.isAccountClass(account, "CASH_EQUIVALENT")) continue; // use our handy recursive method to test the class BigDecimal amount = new BigDecimal(((Double) endingSheet.get(account)).doubleValue()); endingCashAccountBalances.put(account, amount); endingCashAmount = endingCashAmount.add(amount).setScale(decimals, rounding); } // cash flow amounts BigDecimal operatingCashFlow = ZERO; BigDecimal investingCashFlow = ZERO; BigDecimal financingCashFlow = ZERO; // cash flow maps of accounts to amounts Map operatingCashFlowAccountBalances = FastMap.newInstance(); Map investingCashFlowAccountBalances = FastMap.newInstance(); Map financingCashFlowAccountBalances = FastMap.newInstance(); // add net income to operating cash flow operatingCashFlow = netIncome; // add non cash expense accounts to the operating cash flow Map glAccountSums = (Map) incomeResults.get("glAccountSums"); if ((glAccountSums != null) && (glAccountSums.keySet() != null)) { for (Iterator iter = glAccountSums.keySet().iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); if (UtilAccounting.isAccountClass(account, "NON_CASH_EXPENSE") && !UtilAccounting.isAccountClass(account, "INVENTORY_ADJUST")) { BigDecimal amount = new BigDecimal(((Double) glAccountSums.get(account)).doubleValue()); operatingCashFlowAccountBalances.put(account, amount.negate()); operatingCashFlow = operatingCashFlow.subtract(amount).setScale(decimals, rounding); } } } // compute the cash flows from assets Map statement = (Map) comparativeResults.get("assetAccountBalances"); if ((statement != null) && (statement.keySet() != null)) { for (Iterator iter = statement.keySet().iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); // get current assets that are not cash equivalent accounts and flip the sign of the amounts, then add to operating cash flow if (UtilAccounting.isAccountClass(account, "CURRENT_ASSET") && !UtilAccounting.isAccountClass(account, "CASH_EQUIVALENT")) { BigDecimal amount = (BigDecimal) statement.get(account); amount = ZERO.subtract(amount).setScale(decimals, rounding); // flip the sign and use this value operatingCashFlowAccountBalances.put(account, amount); operatingCashFlow = operatingCashFlow.add(amount).setScale(decimals, rounding); } // add to investing cash flow any long term assets else if (UtilAccounting.isAccountClass(account, "LONGTERM_ASSET") && !UtilAccounting.isAccountClass(account, "ACCUM_DEPRECIATION") && !UtilAccounting.isAccountClass(account, "ACCUM_AMORTIZATION")) { BigDecimal amount = (BigDecimal) statement.get(account); investingCashFlowAccountBalances.put(account, amount.negate()); investingCashFlow = investingCashFlow.subtract((BigDecimal) statement.get(account)).setScale(decimals, rounding); } } } // compute the cash flows from liabilities statement = (Map) comparativeResults.get("liabilityAccountBalances"); if ((statement != null) && (statement.keySet() != null)) { for (Iterator iter = statement.keySet().iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); // add to operating cash flow any current liabilities if (UtilAccounting.isAccountClass(account, "CURRENT_LIABILITY")) { operatingCashFlowAccountBalances.put(account, statement.get(account)); operatingCashFlow = operatingCashFlow.add((BigDecimal) statement.get(account)).setScale(decimals, rounding); } // add to financing cash flow any long term liabilities else if (UtilAccounting.isAccountClass(account, "LONGTERM_LIABILITY")) { financingCashFlowAccountBalances.put(account, statement.get(account)); financingCashFlow = financingCashFlow.add((BigDecimal) statement.get(account)).setScale(decimals, rounding); } } } // compute the cash flows from equity (sans the retained earnings accounts) statement = (Map) comparativeResults.get("equityAccountBalances"); if ((statement != null) && (statement.keySet() != null)) { for (Iterator iter = statement.keySet().iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); // add all equity to financing cash flow if (UtilAccounting.isAccountClass(account, "OWNERS_EQUITY")) { financingCashFlowAccountBalances.put(account, statement.get(account)); financingCashFlow = financingCashFlow.add((BigDecimal) statement.get(account)).setScale(decimals, rounding); } } } // handle DISTRIBUTION account transactions statement = new HashMap(); // need to clear it now because this method adds the new DISTRIBUTION accounts and sums to the Map statement = getAcctgTransAndEntriesForClass(statement, organizationPartyId, fromDate, thruDate, glFiscalTypeId, "DISTRIBUTION", userLogin, dispatcher); if ((statement != null) && (statement.keySet() != null)) { for (Iterator iter = statement.keySet().iterator(); iter.hasNext(); ) { GenericValue account = (GenericValue) iter.next(); if (statement.get(account) != null) { BigDecimal amount = new BigDecimal(((Double) statement.get(account)).doubleValue()); financingCashFlowAccountBalances.put(account, amount.negate()); financingCashFlow = financingCashFlow.subtract(amount).setScale(decimals, rounding); } } } // complementary validation that the net cash flow is equal for the two methods to compute it BigDecimal netCashFlowOne = endingCashAmount.subtract(beginningCashAmount); BigDecimal netCashFlowTwo = operatingCashFlow.add(investingCashFlow).add(financingCashFlow); if (netCashFlowOne.compareTo(netCashFlowTwo) != 0) { Debug.logWarning("Net cash flow computation yielded different values! (ending cash amount - beginning cash amount) = [" + netCashFlowOne.toString() + "]; (operating + investing + financing) = [" + netCashFlowTwo.toString() + "]", module); } Map results = ServiceUtil.returnSuccess(); results.put("beginningCashAmount", beginningCashAmount); results.put("beginningCashAccountBalances", beginningCashAccountBalances); results.put("endingCashAmount", endingCashAmount); results.put("endingCashAccountBalances", endingCashAccountBalances); results.put("operatingCashFlowAccountBalances", operatingCashFlowAccountBalances); results.put("investingCashFlowAccountBalances", investingCashFlowAccountBalances); results.put("financingCashFlowAccountBalances", financingCashFlowAccountBalances); results.put("operatingCashFlow", operatingCashFlow); results.put("investingCashFlow", investingCashFlow); results.put("financingCashFlow", financingCashFlow); results.put("netIncome", netIncome); results.put("netCashFlow", netCashFlowTwo); // return (operating + investing + financing) as the net cash flow return results; } catch (GenericServiceException e) { Debug.logError(e, "Failed to compute cash flow statement: " + e.getMessage(), module); return ServiceUtil.returnError("Failed to compute cash flow statement: " + e.getMessage()); } catch (GenericEntityException e) { Debug.logError(e, "Failed to compute cash flow statement: " + e.getMessage(), module); return ServiceUtil.returnError("Failed to compute cash flow statement: " + e.getMessage()); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -