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

📄 ledgerservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            }                                                                                                                                                // step 0 figure out which party is debit vs. credit            if (UtilAccounting.isDisbursement(payment)) {                organizationPartyId = payment.getString("partyIdFrom");                transactionPartyId = payment.getString("partyIdTo");            } else if (UtilAccounting.isReceipt(payment)) {                organizationPartyId = payment.getString("partyIdTo");                transactionPartyId = payment.getString("partyIdFrom");            } else {                return ServiceUtil.returnError("Payment with paymentId " + paymentId + " has a type which is not DISBURSEMENT or RECEIPT.");            }            result.put("organizationPartyId", organizationPartyId);            result.put("transactionPartyId", transactionPartyId);            // step one, look for glAccountId in PaymentMethod            GenericValue paymentMethod = payment.getRelatedOne("PaymentMethod");            if (paymentMethod != null) {                glAccountId = paymentMethod.getString("glAccountId");                if (glAccountId != null) {                    result.put("glAccountId", glAccountId);                    return result;                }            }            // step two: glAccountId from CreditCardTypeGlAccount or PaymentMethodTypeGlAccount            if ("CREDIT_CARD".equals(payment.getString("paymentMethodTypeId"))) {                GenericValue cc = payment.getRelatedOne("CreditCard");                if (cc == null) {                    return ServiceUtil.returnError("Credit Card not found for Payment with paymentId " + payment.getString("paymentId"));                }                GenericValue ccGlAccount = delegator.findByPrimaryKey("CreditCardTypeGlAccount", UtilMisc.toMap("organizationPartyId", organizationPartyId, "cardType", cc.getString("cardType")));                if (ccGlAccount != null) {                    result.put("glAccountId", ccGlAccount.getString("glAccountId"));                    return result;                }            }            List tmpList = payment.getRelatedOne("PaymentMethodType").getRelatedByAnd("PaymentMethodTypeGlAccount",                     UtilMisc.toMap("organizationPartyId", organizationPartyId));            if (tmpList.size() > 0) {                GenericValue paymentMethodTypeGlAccount = (GenericValue) tmpList.get(0);                glAccountId = paymentMethodTypeGlAccount.getString("glAccountId");                if (glAccountId != null) {                    result.put("glAccountId", glAccountId);                    return result;                }            }                        // step three: defaultGlAccountId            GenericValue paymentMethodType = payment.getRelatedOne("PaymentMethodType");            if (paymentMethodType != null) {                glAccountId = paymentMethodType.getString("defaultGlAccountId");                if (glAccountId != null) {                    result.put("glAccountId", glAccountId);                    return result;                }            }                        return ServiceUtil.returnError("No GL Account found for Payment with paymentId " + paymentId);        } catch (GenericEntityException ex) {            return(ServiceUtil.returnError(ex.getMessage()));        }    }    /**     *  Service to match a Payment to an Invoice for a particular PaymentApplication.     */    public static Map matchPaymentInvoiceGlPosts(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String paymentApplicationId = (String) context.get("paymentApplicationId");        try {            GenericValue paymentApplication = delegator.findByPrimaryKey("PaymentApplication", UtilMisc.toMap("paymentApplicationId", paymentApplicationId));            GenericValue payment = paymentApplication.getRelatedOne("Payment");            GenericValue invoice = paymentApplication.getRelatedOne("Invoice");            String paymentId = payment.getString("paymentId");            String invoiceId = invoice.getString("invoiceId");            if (invoice == null) {                throw new GenericServiceException("Could not find Invoice with ID [" + invoiceId + "]");            }            // transaction information            String organizationPartyId = null;            String paymentOffsetDebitCreditFlag = null;            String invoiceOffsetDebitCreditFlag = null;            String invoiceOffsettingGlAccountTypeId = null;            String transactionPartyId = payment.getString("partyIdTo");            String transactionPartyRoleTypeId = payment.getString("roleTypeIdTo");            String acctgTransTypeId = "OTHER_INTERNAL_ACCTG";            // determine the organization, offsetting account type, and debitCreditFlags, but first make sure that we're only            // doing this for SALES invoices and payment receipts or PURCHASE invoices and disbursements            if ((UtilAccounting.isDisbursement(payment)) && (invoice.getString("invoiceTypeId").equals("PURCHASE_INVOICE"))) {                organizationPartyId = payment.getString("partyIdFrom");                paymentOffsetDebitCreditFlag = "D";                invoiceOffsetDebitCreditFlag = "C";                invoiceOffsettingGlAccountTypeId = "ACCOUNTS_PAYABLE";            } else if ((UtilAccounting.isReceipt(payment)) && (invoice.getString("invoiceTypeId").equals("SALES_INVOICE"))) { // Receipt                organizationPartyId = payment.getString("partyIdTo");                paymentOffsetDebitCreditFlag = "C";                invoiceOffsetDebitCreditFlag = "D";                invoiceOffsettingGlAccountTypeId = "ACCOUNTS_RECEIVABLE";            } else {                // possibly other types of payments or invoices involved, such as Customer Return Invoices and Customer Refunds.                return ServiceUtil.returnSuccess();            }            // get the offsetting account of the payment            String paymentOffsettingGlAccountId = getOffsettingPaymentGlAccount(dispatcher, payment, organizationPartyId, userLogin);            // get the offsetting gl account of the invoice            String invoiceOffsettingGlAccountId = UtilAccounting.getDefaultAccountId(invoiceOffsettingGlAccountTypeId, organizationPartyId, delegator);            // if the accounts are the same, there's no need to match            if (paymentOffsettingGlAccountId == invoiceOffsettingGlAccountId) {                if (Debug.verboseOn()) {                    Debug.logVerbose("Matching payment to invoice: Payment and Invoice offsetting accounts were identical. No need to match.", module);                }                return ServiceUtil.returnSuccess();            }            // make the transaction entry for the offsetting payment account            Map input = new HashMap();            input.put("glAccountId", paymentOffsettingGlAccountId);            input.put("acctgTransEntrySeqId", "1");            input.put("organizationPartyId", organizationPartyId);            input.put("partyId", transactionPartyId);            input.put("roleTypeId", transactionPartyRoleTypeId);            input.put("debitCreditFlag", invoiceOffsetDebitCreditFlag); // want opposite flag            input.put("amount", paymentApplication.getDouble("amountApplied"));            input.put("acctgTransEntryTypeId", "_NA_");            input.put("description", "Matching GL accounts for invoice " + invoiceId + " and payment " + paymentId);            GenericValue paymentEntry = delegator.makeValue("AcctgTransEntry", input);            // make the transaction entry for the offsetting invoice account            input = new HashMap();            input.put("glAccountId", invoiceOffsettingGlAccountId);            input.put("acctgTransEntrySeqId", "2");            input.put("organizationPartyId", organizationPartyId);            input.put("partyId", transactionPartyId);            input.put("roleTypeId", transactionPartyRoleTypeId);            input.put("debitCreditFlag", paymentOffsetDebitCreditFlag); // want opposite flag            input.put("amount", paymentApplication.getDouble("amountApplied"));            input.put("acctgTransEntryTypeId", "_NA_");            input.put("description", "Matching GL accounts for invoice " + invoiceId + " and payment " + paymentId);            GenericValue invoiceEntry = delegator.makeValue("AcctgTransEntry", input);            // prepare the transaction             input = new HashMap();            input.put("acctgTransEntries", UtilMisc.toList(paymentEntry, invoiceEntry));            input.put("invoiceId", invoiceId);            input.put("partyId", transactionPartyId);            input.put("roleTypeId", transactionPartyRoleTypeId);            input.put("glFiscalTypeId", "ACTUAL");            input.put("acctgTransTypeId", acctgTransTypeId);            input.put("userLogin", userLogin);            // create the transaction and return the acctgTransId            return dispatcher.runSync("createAcctgTransAndEntries", input);        } catch (GenericEntityException ee) {            return ServiceUtil.returnError(ee.getMessage());        } catch (GenericServiceException se) {            return ServiceUtil.returnError(se.getMessage());        }    }    /**      * Service to post an inventory variance transaction to the General Ledger      * @param   inventoryItemId     * @param   physicalInventoryId     * @return     * @author  Leon Torres     */    public static Map postInventoryVarianceToGl(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String inventoryItemId = (String) context.get("inventoryItemId");        String physicalInventoryId = (String) context.get("physicalInventoryId");        try {            Map tmpMap = new HashMap();            GenericValue inventoryVariance = delegator.findByPrimaryKey("InventoryItemVariance",                     UtilMisc.toMap("inventoryItemId", inventoryItemId, "physicalInventoryId", physicalInventoryId));            if (inventoryVariance == null) {                return ServiceUtil.returnError("No InventoryVariance entity record for inventoryItemId " + inventoryItemId + " and physicalInventoryId " + physicalInventoryId);            }                        BigDecimal quantityOnHandVar = inventoryVariance.getBigDecimal("quantityOnHandVar");            if (quantityOnHandVar == null || quantityOnHandVar.compareTo(ZERO) == 0) {                // no actual inventory loss or gain to account for                return ServiceUtil.returnSuccess();            }                        GenericValue inventoryItem = inventoryVariance.getRelatedOne("InventoryItem");            String productId = inventoryItem.getString("productId");            // owner of inventory item            String ownerPartyId = inventoryItem.getString("ownerPartyId");            // get the inventory item unit cost            BigDecimal unitCost = inventoryItem.getBigDecimal("unitCost");            // get the currency conversion factor            BigDecimal conversionFactor = new BigDecimal(UtilFinancial.determineUomConversionFactor(delegator, dispatcher, ownerPartyId, inventoryItem.getString("currencyUomId")));            // validate the unitCost and compute transaction amount            if (unitCost == null) {                 return ServiceUtil.returnError("Could not determine unitCost of product [" + productId +                                               "] for inventory variance [" + physicalInventoryId +                                               "] and inventory item [" + inventoryItemId + "]");            }            // convert the intentory item's unit cost into the owner's currency            unitCost = unitCost.multiply(conversionFactor).setScale(decimals, rounding);            // The transaction amount is: amount = quantityOnHandVar * unitCost            BigDecimal transactionAmount = unitCost.multiply(quantityOnHandVar).setScale(decimals, rounding);                        // get owner's party COGS method            GenericValue acctgPref = delegator.findByPrimaryKeyCache("PartyAcctgPreference", UtilMisc.toMap("partyId", ownerPartyId));            String cogsMethodId = acctgPref.getString("cogsMethodId");            

⌨️ 快捷键说明

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