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

📄 invoiceworker.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                Debug.logError("Trouble getting contact party purpose list", module);                       }            //if still not found get it from the general location            if (locations == null || locations.size() == 0)    {                try {                    locations = EntityUtil.filterByDate(delegator.findByAnd("PartyContactMechPurpose",                             UtilMisc.toMap("partyId", destinationPartyId, "contactMechPurposeTypeId", "GENERAL_LOCATION")));                } catch (GenericEntityException e) {                    Debug.logError("Trouble getting contact party purpose list", module);                           }            }        }                        // now return the first PostalAddress from the locations        GenericValue postalAddress = null;        GenericValue contactMech = null;        if (locations != null && locations.size() > 0) {            try {                contactMech = ((GenericValue) locations.get(0)).getRelatedOne("ContactMech");            } catch (GenericEntityException e) {                Debug.logError(e, "Trouble getting Contact for contactMechId: " + contactMech.getString("contactMechId"), module);            }                        if (contactMech.getString("contactMechTypeId").equals("POSTAL_ADDRESS"))    {                try {                    postalAddress = contactMech.getRelatedOne("PostalAddress");                    return postalAddress;                } catch (GenericEntityException e) {                    Debug.logError(e, "Trouble getting PostalAddress for contactMechId: " + contactMech.getString("contactMechId"), module);                }            }        }        return contactMech;    }            private static GenericValue getAddressFromParty(GenericValue party, String purposeTypeId) {        if (party == null) return null;                GenericValue contactMech = null;        GenericValue postalAddress = null;        try {            List mecs = party.getRelated("PartyContactMechPurpose",                 UtilMisc.toMap("contactMechPurposeTypeId", purposeTypeId), null);            if (mecs != null) {                            List filteredMecs = EntityUtil.filterByDate(mecs);                GenericValue mecPurpose = EntityUtil.getFirst(filteredMecs);                if (mecPurpose != null)                    contactMech = mecPurpose.getRelatedOne("ContactMech");            }        } catch (GenericEntityException e) {            Debug.logError(e, "Trouble getting current ContactMech for Party/Purpose", module);        }                if (contactMech != null) {            if (contactMech.getString("contactMechTypeId").equals("POSTAL_ADDRESS")) {                try {                    postalAddress = contactMech.getRelatedOne("PostalAddress");                                               } catch (GenericEntityException e) {                    Debug.logError(e, "Trouble getting PostalAddress from ContactMech", module);                }            }        }                if (postalAddress != null)            return postalAddress;        return null;            }        /**     * Method to return the total amount of an invoice which is not yet applied to a payment     * @param invoice GenericValue object of the Invoice     * @return the invoice total as double     */    public static BigDecimal getInvoiceNotApplied(GenericDelegator delegator, String invoiceId) {    	return InvoiceWorker.getInvoiceTotalBd(delegator, invoiceId).subtract(getInvoiceAppliedBd(delegator, invoiceId));    }    public static BigDecimal getInvoiceNotApplied(GenericValue invoice) {    	return InvoiceWorker.getInvoiceTotalBd(invoice).subtract(getInvoiceAppliedBd(invoice));    }    /**     * Returns amount not applied (ie, still outstanding) of an invoice at an asOfDate, based on Payment.effectiveDate <= asOfDateTime     *      * @param invoice     * @param asOfDateTime     * @return     */    public static BigDecimal getInvoiceNotApplied(GenericValue invoice, Timestamp asOfDateTime) {    	return InvoiceWorker.getInvoiceTotalBd(invoice).subtract(getInvoiceAppliedBd(invoice, asOfDateTime));    }        /**     * Method to return the total amount of an invoice which is applied to a payment     * @param invoice GenericValue object of the Invoice     * @return the invoice total as double     */    public static double getInvoiceApplied(GenericDelegator delegator, String invoiceId) {    	return getInvoiceAppliedBd(delegator, invoiceId).doubleValue();    }    	    public static BigDecimal getInvoiceAppliedBd(GenericDelegator delegator, String invoiceId) {        return getInvoiceAppliedBd(delegator, invoiceId, UtilDateTime.nowTimestamp());    }        /**     * Returns amount applied to invoice before an asOfDateTime, based on Payment.effectiveDate <= asOfDateTime     *      * @param delegator     * @param invoiceId     * @param asOfDateTime - a Timestamp     * @return     */    public static BigDecimal getInvoiceAppliedBd(GenericDelegator delegator, String invoiceId, Timestamp asOfDateTime) {        if (delegator == null) {            throw new IllegalArgumentException("Null delegator is not allowed in this method");        }                BigDecimal invoiceApplied = new BigDecimal("0");        List paymentApplications = null;                // lookup payment applications which took place before the asOfDateTime for this invoice        EntityConditionList dateCondition = new EntityConditionList(UtilMisc.toList(                new EntityExpr("effectiveDate", EntityOperator.EQUALS, null),                new EntityExpr("effectiveDate", EntityOperator.LESS_THAN_EQUAL_TO, asOfDateTime)), EntityOperator.OR);        EntityConditionList conditions = new EntityConditionList(UtilMisc.toList(                dateCondition,                new EntityExpr("invoiceId", EntityOperator.EQUALS, invoiceId)),                EntityOperator.AND);         try {        	paymentApplications = delegator.findByCondition("PaymentAndApplication", conditions, null, UtilMisc.toList("effectiveDate"));        } catch (GenericEntityException e) {            Debug.logError(e, "Trouble getting paymentApplicationlist", module);                    }        if (paymentApplications != null && paymentApplications.size() > 0) {            Iterator p = paymentApplications.iterator();            while (p.hasNext()) {                GenericValue paymentApplication = (GenericValue) p.next();                invoiceApplied = invoiceApplied.add(paymentApplication.getBigDecimal("amountApplied")).setScale(decimals,rounding);            }        }        return invoiceApplied;    }    /**     * Method to return the total amount of an invoice which is applied to a payment     * @param invoice GenericValue object of the Invoice     * @return the applied total as double     */    public static double getInvoiceApplied(GenericValue invoice) {    	return getInvoiceAppliedBd(invoice).doubleValue();    }    /**     * Big decimal version of getInvoiceApplied     *      * @param delegator     * @param invoiceId     * @param invoiceItemSeqId     * @return     */    public static BigDecimal getInvoiceAppliedBd(GenericValue invoice, Timestamp asOfDateTime) {        return getInvoiceAppliedBd(invoice.getDelegator(), invoice.getString("invoiceId"), asOfDateTime);    }    public static BigDecimal getInvoiceAppliedBd(GenericValue invoice) {        return getInvoiceAppliedBd(invoice, UtilDateTime.nowTimestamp());    }        /**     * Method to return the amount of an invoiceItem which is applied to a payment     * @param invoice GenericValue object of the Invoice     * @return the invoice total as double     */    public static double getInvoiceItemApplied(GenericDelegator delegator, String invoiceId, String invoiceItemSeqId) {    	return getInvoiceItemAppliedBd(delegator, invoiceId, invoiceItemSeqId).doubleValue();    }        /**     * Big decimal version of getInvoiceApplied     *      * @param delegator     * @param invoiceId     * @param invoiceItemSeqId     * @return     */    public static BigDecimal getInvoiceItemAppliedBd(GenericDelegator delegator, String invoiceId, String invoiceItemSeqId) {        if (delegator == null) {            throw new IllegalArgumentException("Null delegator is not allowed in this method");        }                GenericValue invoiceItem = null;        try {            invoiceItem = delegator.findByPrimaryKey("Invoice", UtilMisc.toMap("invoiceId", invoiceId,"invoiceItemSeqId", invoiceItemSeqId));            } catch (GenericEntityException e) {            Debug.logError(e, "Problem getting InvoiceItem", module);        }                if (invoiceItem == null) {            throw new IllegalArgumentException("The invoiceId/itemSeqId passed does not match an existing invoiceItem");        }                return getInvoiceItemAppliedBd(invoiceItem);    }        /**     * Method to return the total amount of an invoiceItem which is applied to a payment     * @param invoice GenericValue object of the Invoice     * @return the applied total as double     */    public static double getInvoiceItemApplied(GenericValue invoiceItem) {    	return getInvoiceItemAppliedBd(invoiceItem).doubleValue();    }    public static BigDecimal getInvoiceItemAppliedBd(GenericValue invoiceItem) {        BigDecimal invoiceItemApplied = new BigDecimal("0");        List paymentApplications = null;        try {        	paymentApplications = invoiceItem.getRelated("PaymentApplication");        } catch (GenericEntityException e) {            Debug.logError(e, "Trouble getting paymentApplicationlist", module);                    }        if (paymentApplications != null && paymentApplications.size() > 0) {            Iterator p = paymentApplications.iterator();            while (p.hasNext()) {                GenericValue paymentApplication = (GenericValue) p.next();                invoiceItemApplied = invoiceItemApplied.add(paymentApplication.getBigDecimal("amountApplied")).setScale(decimals,rounding);            }        }        return invoiceItemApplied;            }       }

⌨️ 快捷键说明

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