⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 financialservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                isClosed = true;            }            // first, find all the gl accounts' GlAccountHistory record for this time period            EntityConditionList conditions = new EntityConditionList(UtilMisc.toList(                    new EntityExpr("organizationPartyId", EntityOperator.EQUALS, organizationPartyId),                    new EntityExpr("customTimePeriodId", EntityOperator.EQUALS, customTimePeriodId),                    new EntityConditionList(UtilMisc.toList(                        UtilFinancial.getAssetExpr(delegator),                        UtilFinancial.getLiabilityExpr(delegator),                        UtilFinancial.getEquityExpr(delegator)), EntityOperator.OR)),                     EntityOperator.AND);            List selectedFields = UtilMisc.toList("glAccountId", "glAccountTypeId", "glAccountClassId", "accountName", "postedDebits", "postedCredits");            selectedFields.add("endingBalance");            List accounts = delegator.findByCondition("GlAccountAndHistory", conditions, selectedFields, UtilMisc.toList("glAccountId"));            // now, create the separate account balance Maps and see if this period has been closed.            // if the period has been closed, then just get the accounts' balances from the endingBalance            // otherwise, get it by calculating the net of posted debits and credits            Map assetAccountBalances = new HashMap();            Map liabilityAccountBalances = new HashMap();            Map equityAccountBalances = new HashMap();            for (Iterator ai = accounts.iterator(); ai.hasNext(); ) {                GenericValue account = (GenericValue) ai.next();                double balance = 0.0;                if (!isClosed) {                    // has not been closed - net of debit minus credit for debit accounts, credit minus debit for credit accounts                   Double netBalance = UtilAccounting.getNetBalance(account, module);                   if (netBalance != null) {                       balance = netBalance.doubleValue();                   } else {                       return ServiceUtil.returnError("Cannot get a net balance for " + account);                   }                } else {                    // has been closed, use endingBalance                   balance = account.getDouble("endingBalance").doubleValue();                }                // classify and put into the appropriate Map                if (UtilAccounting.isAssetAccount(account)) {                   assetAccountBalances.put(account.getRelatedOne("GlAccount"), new Double(balance));                } else if (UtilAccounting.isLiabilityAccount(account)) {                   liabilityAccountBalances.put(account.getRelatedOne("GlAccount"), new Double(balance));                } else if (UtilAccounting.isEquityAccount(account)) {                   equityAccountBalances.put(account.getRelatedOne("GlAccount"), new Double(balance));                }             }            // not closed.  need to get a provisional net income and add it to p&l account            GenericValue retainedEarningsGlAccount = null;            Double interimNetIncome = null;            if (!isClosed) {                // calculate provisional income                Map tmpResult = dispatcher.runSync("getActualNetIncomeSinceLastClosing", UtilMisc.toMap("organizationPartyId", organizationPartyId, "thruDate",                         UtilDateTime.toTimestamp(currentTimePeriod.getDate("thruDate")), "userLogin", userLogin));                if (tmpResult.get("netIncome") == null) {                    return tmpResult;                } else {                    // put provisional net income into the equity accounts Map                    interimNetIncome = (Double) tmpResult.get("netIncome");                    retainedEarningsGlAccount = (GenericValue) tmpResult.get("retainedEarningsGlAccount");                    UtilMisc.addToDoubleInMap(equityAccountBalances, retainedEarningsGlAccount, interimNetIncome);                }            }            // all done            Map result = ServiceUtil.returnSuccess();            result.put("assetAccountBalances", assetAccountBalances);            result.put("liabilityAccountBalances", liabilityAccountBalances);            result.put("equityAccountBalances", equityAccountBalances);            result.put("isClosed", new Boolean(isClosed));            result.put("retainedEarningsGlAccount", retainedEarningsGlAccount);            result.put("interimNetIncomeAmount", interimNetIncome);            return result;        } catch (GenericEntityException ex) {            return(ServiceUtil.returnError(ex.getMessage()));        } catch (GenericServiceException ex) {            return(ServiceUtil.returnError(ex.getMessage()));        }    }    /**     * Generates balance sheet as of a particular date, by working forward from the last closed time period,     *       or, if none, from the beginning of the earliest time period.     */        public static Map getBalanceSheetForDate(DispatchContext dctx, Map context) {        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericDelegator delegator = dctx.getDelegator();        String organizationPartyId = (String) context.get("organizationPartyId");        Timestamp asOfDate = (Timestamp) context.get("asOfDate");        GenericValue userLogin = (GenericValue) context.get("userLogin");        String glFiscalTypeId = (String) context.get("glFiscalTypeId");        // default to generating "ACTUAL" balance sheets        if ((glFiscalTypeId == null) || (glFiscalTypeId.equals(""))) {             glFiscalTypeId = "ACTUAL";        }                // balances of the asset, liability, and equity GL accounts, initially empty        Map assetAccountBalances = new HashMap();        Map liabilityAccountBalances = new HashMap();        Map equityAccountBalances = new HashMap();        try {//          find the last closed time period             Map tmpResult = dispatcher.runSync("findLastClosedDate", UtilMisc.toMap("organizationPartyId", organizationPartyId, "findDate", asOfDate, "userLogin", userLogin));            // figure the date and the last closed time period            Timestamp lastClosedDate = null;            GenericValue lastClosedTimePeriod = null;            if ((tmpResult == null) || (tmpResult.get("lastClosedDate") == null)) {                return ServiceUtil.returnError("Cannot get a closed time period before " + asOfDate);            } else {                lastClosedDate = (Timestamp) tmpResult.get("lastClosedDate");            }            if (tmpResult.get("lastClosedTimePeriod") != null) {                lastClosedTimePeriod = (GenericValue) tmpResult.get("lastClosedTimePeriod");            }            // if there was a previously closed time period, then get a balance sheet as of the end of that time period.  This balance sheet is our starting point             if (tmpResult.get("lastClosedTimePeriod") != null) {                tmpResult = dispatcher.runSync("getBalanceSheetForTimePeriod", UtilMisc.toMap("organizationPartyId", organizationPartyId,                         "customTimePeriodId", lastClosedTimePeriod.getString("customTimePeriodId"), "userLogin", userLogin));                if (tmpResult != null) {                    assetAccountBalances = (Map) tmpResult.get("assetAccountBalances");                    liabilityAccountBalances = (Map) tmpResult.get("liabilityAccountBalances");                    equityAccountBalances = (Map) tmpResult.get("equityAccountBalances");                }            }             // now add the new asset, liability, and equity transactions            assetAccountBalances = getAcctgTransAndEntriesForClass(assetAccountBalances, organizationPartyId, lastClosedDate, asOfDate, glFiscalTypeId, "ASSET", userLogin, dispatcher);            liabilityAccountBalances = getAcctgTransAndEntriesForClass(liabilityAccountBalances, organizationPartyId, lastClosedDate, asOfDate, glFiscalTypeId, "LIABILITY", userLogin, dispatcher);            equityAccountBalances = getAcctgTransAndEntriesForClass(equityAccountBalances, organizationPartyId, lastClosedDate, asOfDate, glFiscalTypeId, "EQUITY", userLogin, dispatcher);            // calculate a net income since the last closed date and add it to our equity account balances             tmpResult = dispatcher.runSync("getIncomeStatementByDates", UtilMisc.toMap("organizationPartyId", organizationPartyId, "fromDate", lastClosedDate,                     "glFiscalTypeId", glFiscalTypeId, "thruDate", asOfDate, "userLogin", userLogin));            GenericValue retainedEarningsGlAccount = (GenericValue) tmpResult.get("retainedEarningsGlAccount");            Double interimNetIncome = (Double) tmpResult.get("netIncome");            UtilMisc.addToDoubleInMap(equityAccountBalances, retainedEarningsGlAccount, interimNetIncome);            // TODO: This is just copied over from getIncomeStatementByDates for now.  We should implement a good version at some point.            boolean isClosed = true;            EntityConditionList conditions = new EntityConditionList(UtilMisc.toList(               new EntityExpr("organizationPartyId", EntityOperator.EQUALS, organizationPartyId),               new EntityExpr("isClosed", EntityOperator.NOT_EQUAL, "Y"),               new EntityConditionList(UtilMisc.toList(                   new EntityExpr("fromDate", EntityOperator.GREATER_THAN_EQUAL_TO, lastClosedDate),                   new EntityExpr("thruDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDate)), EntityOperator.OR)), EntityOperator.AND);                        List timePeriods = delegator.findByCondition("CustomTimePeriod", conditions, UtilMisc.toList("customTimePeriodId"), UtilMisc.toList("customTimePeriodId"));            if (timePeriods.size() > 0) {                isClosed = false;            }                        // all done            Map result = ServiceUtil.returnSuccess();            result.put("assetAccountBalances", assetAccountBalances);            result.put("liabilityAccountBalances", liabilityAccountBalances);            result.put("equityAccountBalances", equityAccountBalances);            result.put("isClosed", new Boolean(isClosed));            result.put("retainedEarningsGlAccount", retainedEarningsGlAccount);            result.put("interimNetIncomeAmount", interimNetIncome);            return(result);        } catch (GenericEntityException ex) {            return(ServiceUtil.returnError(ex.getMessage()));        } catch (GenericServiceException ex) {            return(ServiceUtil.returnError(ex.getMessage()));        }            }    /**     * Finds and returns a List of AcctgTransAndEntries based on organizationPartyId, fromDate, thruDate, fiscalTypeId,     *       subject to the glAccountClassIds in the glAccountClasses List.     */    public static Map getAcctgTransAndEntriesByType(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        Timestamp fromDate = (Timestamp) context.get("fromDate");        Timestamp thruDate = (Timestamp) context.get("thruDate");        String organizationPartyId = (String) context.get("organizationPartyId");        String glFiscalTypeId = (String) context.get("glFiscalTypeId");        List glAccountClasses = (List) context.get("glAccountClasses");        try {            // build a condition list of all the GlAccountClasses considered            List glAccountClassesConsidered = new ArrayList();            for (Iterator gACi = glAccountClasses.iterator(); gACi.hasNext(); ) {                String glAccountClassId = (String) gACi.next();                glAccountClassesConsidered.add(UtilFinancial.getGlAccountClassExpr(glAccountClassId, delegator));            }                        // find all accounting transaction entries for this organizationPartyId and falling into this time period which are             // of the specified types.  Note we are only getting posted transactions here.  This might change at some point.            EntityConditionList conditions = new EntityConditionList(UtilMisc.toList(                    new EntityExpr("organizationPartyId", EntityOperator.EQUALS, organizationPartyId),                    new EntityExpr("isPosted", EntityOperator.EQUALS, "Y"),                    new EntityExpr("glFiscalTypeId", EntityOperator.EQUALS, glFiscalTypeId),                    new EntityConditionList(glAccountClassesConsidered, EntityOperator.OR),                    new EntityExpr("transactionDate", EntityOperator.GREATER_THAN_EQUAL_TO, fromDate),                    new EntityExpr("transactionDate", EntityOperator.LESS_THAN_EQUAL_TO, thruDate)),                     EntityOperator.AND);            List fieldsToGet = UtilMisc.toList("acctgTransId", "acctgTransTypeId", "acctgTransEntrySeqId", "glAccountId", "glAccountClassId", "amount");            fieldsToGet.add("debitCreditFlag");            List transactionEntries = delegator.findByCondition("AcctgTransAndEntries", conditions,                     fieldsToGet, // get these fields                     UtilMisc.toList("acctgTransId", "acctgTransEntrySeqId")); // order by these fields                        Map result = ServiceUtil.returnSuccess();            result.put("transactionEntries", transactionEntries);            return(result);        }  catch (GenericEntityException ex) {            return(ServiceUtil.returnError(ex.getMessage()));        }    }        /**     * gets a Map of glAccount -> sum of transactions for all income statement accounts (REVENUE, EXPENSE, INCOME) over a period of dates for an organization.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -