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

📄 accountshelper.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2006  Open Source Strategies, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */package com.opensourcestrategies.financials.accounts;import java.math.BigDecimal;import java.sql.Timestamp;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import javolution.util.FastMap;import org.ofbiz.accounting.invoice.InvoiceWorker;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilNumber;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import com.opensourcestrategies.financials.invoice.InvoiceWithOutstandingBalance;public class AccountsHelper {    public static String module = AccountsHelper.class.getName();        public static int decimals = UtilNumber.getBigDecimalScale("fin_arithmetic.properties", "financial.statements.decimals");    public static int rounding = UtilNumber.getBigDecimalRoundingMode("fin_arithmetic.properties", "financial.statements.rounding");    protected static final BigDecimal ZERO = new BigDecimal("0"); // TODO: this will soon be UtilNumber.BD_ZERO    protected static final BigDecimal MILLISECONDS_PER_DAY = new BigDecimal("86400000");    /**     * Find the sum of transaction entry amounts by partyId for the given parameters     *      * @param organizationPartyId     * @param glAccountId     * @param glAccountTypeId     * @param glFiscalTypeId     * @param debitCreditFlag     * @param partyId     * @param roleTypeId     * @param asOfDate     * @param delegator     * @return     * @throws GenericEntityException     */    public static List getAcctgTransPartySums(String organizationPartyId, String glAccountTypeId, String glFiscalTypeId, String debitCreditFlag,             String partyId, String roleTypeId, Timestamp asOfDate, GenericDelegator delegator) throws GenericEntityException {            List conditions = UtilMisc.toList(                 new EntityExpr("organizationPartyId", EntityOperator.EQUALS, organizationPartyId),                new EntityExpr("debitCreditFlag", EntityOperator.EQUALS, debitCreditFlag),                new EntityExpr("isPosted", EntityOperator.EQUALS, "Y"),                new EntityExpr("glAccountTypeId", EntityOperator.EQUALS, glAccountTypeId),                                new EntityExpr("glFiscalTypeId", EntityOperator.EQUALS, glFiscalTypeId),                 new EntityExpr("transactionDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDate));        if (partyId != null) {            conditions.add(new EntityExpr("partyId", EntityOperator.EQUALS, partyId));        }        if (roleTypeId != null) {            conditions.add(new EntityExpr("roleTypeId", EntityOperator.EQUALS, roleTypeId));        }                EntityConditionList findConditions = new EntityConditionList(conditions, EntityOperator.AND);        List fieldsToGet = UtilMisc.toList("partyId", "amount");                List transactionEntries = delegator.findByCondition("AcctgTransEntryPartySum", findConditions,                 fieldsToGet, // get these fields                 UtilMisc.toList("partyId")); // order by these fields                return transactionEntries;    }    /**     * Canonical method to get transaction balances by glAccountTypeid.      * Use one of the helper methods defined after this method.     *     * @param   glAccountTypeId Account type to sum over. this determines the sign of the resulting balance.     *                          For instance, in the case of receivables (incoming), sum of all debit - sum of all credit.     *                          In the case of payables (outgoing),  sum of all credit - sum of all debit.     * @param   partyId         If specified, limit the search result to the given partyId     * @param   glFiscalTypeId     * @param   asOfDateTime    Timestamp to sum up to. TODO: investigate the boundary conditions     */    public static Map getBalancesHelper(String glAccountTypeId, String organizationPartyId, String partyId, String glFiscalTypeId,            Timestamp asOfDateTime, GenericDelegator delegator) throws GenericEntityException {        // set up a convenience boolean for testing receivables/payables        boolean isReceivable = (glAccountTypeId.equals("ACCOUNTS_RECEIVABLE") ? true : false);        String roleTypeId = (isReceivable ? "BILL_TO_CUSTOMER" : "BILL_FROM_VENDOR");                // query for debit and credit balances        List debitBalances = getAcctgTransPartySums(organizationPartyId, glAccountTypeId, glFiscalTypeId, "D", partyId, roleTypeId,                asOfDateTime, delegator);        List creditBalances = getAcctgTransPartySums(organizationPartyId, glAccountTypeId, glFiscalTypeId, "C", partyId, roleTypeId,                asOfDateTime, delegator);        // return map has key partyId to value balance        Map balances = FastMap.newInstance();        // go through debits and put either the (debitBalance) for receivables or (ZERO - debitBalance) for payables        for (Iterator iter = debitBalances.iterator(); iter.hasNext(); ) {            GenericValue balance = (GenericValue) iter.next();            BigDecimal balanceAmount = balance.getBigDecimal("amount").setScale(decimals, rounding);            if (!isReceivable) balanceAmount = ZERO.subtract(balanceAmount);            balances.put(balance.get("partyId"), balanceAmount);        }        // now go through credits and add to debitBalance (default ZERO) the following: (creditBalance) for payables or (ZERO - creditBalance) for receivables        for (Iterator iter = creditBalances.iterator(); iter.hasNext(); ) {            GenericValue balance = (GenericValue) iter.next();            BigDecimal balanceAmount = balance.getBigDecimal("amount").setScale(decimals, rounding);            if (isReceivable) balanceAmount = ZERO.subtract(balanceAmount);            // see if a debitBalance exists, otherwise default to ZERO            BigDecimal debitBalance = (BigDecimal) balances.get(balance.get("partyId"));            if (debitBalance == null) debitBalance = ZERO;

⌨️ 快捷键说明

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