This is an automated email from the ASF dual-hosted git repository.
surajk pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new 18b21c1 [Improved] Convert getInvoicePaymentInfoList service from mini-lang to groovy DSL (#148) 18b21c1 is described below commit 18b21c1e948f213e82682677a75839ddc0419456 Author: Priya Sharma <[hidden email]> AuthorDate: Sat Jul 4 14:57:53 2020 +0530 [Improved] Convert getInvoicePaymentInfoList service from mini-lang to groovy DSL (#148) (OFBIZ-11485) Done following: - removed the mini-lang implementation of the service - updated the service definition to point the groovy service - added the groovy implementation of the service --- .../groovyScripts/payment/PaymentServices.groovy | 66 +++++++++++++ .../minilang/payment/PaymentServices.xml | 106 --------------------- .../accounting/servicedef/services_payment.xml | 4 +- 3 files changed, 68 insertions(+), 108 deletions(-) diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy index d416292..02846d7 100644 --- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy +++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy @@ -16,6 +16,8 @@ * specific language governing permissions and limitations * under the License. */ +import org.apache.ofbiz.accounting.invoice.InvoiceWorker +import org.apache.ofbiz.base.util.Debug import org.apache.ofbiz.base.util.UtilDateTime import org.apache.ofbiz.base.util.UtilFormatOut import org.apache.ofbiz.base.util.UtilProperties @@ -62,6 +64,70 @@ def createPayment() { result.paymentId = paymentId return result } +def getInvoicePaymentInfoList() { + // Create a list with information on payment due dates and amounts for the invoice + GenericValue invoice; + List invoicePaymentInfoList = [] + if (!parameters.invoice) { + invoice = from("Invoice").where("invoiceId", parameters.invoiceId).queryOne() + } else { + invoice = parameters.invoice + } + + BigDecimal invoiceTotalAmount = InvoiceWorker.getInvoiceTotal(invoice) + BigDecimal invoiceTotalAmountPaid = InvoiceWorker.getInvoiceApplied(invoice) + + List invoiceTerms = from("InvoiceTerm").where("invoiceId", invoice.invoiceId).queryList() + + BigDecimal remainingAppliedAmount = invoiceTotalAmountPaid + BigDecimal computedTotalAmount = (BigDecimal) 0 + + Map invoicePaymentInfo = [:] + + for (invoiceTerm in invoiceTerms) { + termType = from("TermType").where("termTypeId", invoiceTerm.termTypeId).cache(true).queryOne() + if ("FIN_PAYMENT_TERM" == termType.parentTypeId) { + invoicePaymentInfo.clear() + invoicePaymentInfo.invoiceId = invoice.invoiceId + invoicePaymentInfo.invoiceTermId = invoiceTerm.invoiceTermId + invoicePaymentInfo.termTypeId = invoiceTerm.termTypeId + invoicePaymentInfo.dueDate = UtilDateTime.getDayEnd(invoice.invoiceDate, invoiceTerm.termDays) + + BigDecimal invoiceTermAmount = (invoiceTerm.termValue * invoiceTotalAmount ) / 100 + invoicePaymentInfo.amount = invoiceTermAmount + computedTotalAmount = computedTotalAmount + (BigDecimal) invoicePaymentInfo.amount + + if (remainingAppliedAmount >= invoiceTermAmount) { + invoicePaymentInfo.paidAmount = invoiceTermAmount + remainingAppliedAmount = remainingAppliedAmount - invoiceTermAmount + } else { + invoicePaymentInfo.paidAmount = remainingAppliedAmount + remainingAppliedAmount = (BigDecimal) 0 + } + invoicePaymentInfo.outstandingAmount = invoicePaymentInfo.amount - invoicePaymentInfo.paidAmount + invoicePaymentInfoList.add(invoicePaymentInfo) + } + } + + if (remainingAppliedAmount > 0.0 || invoiceTotalAmount <= 0.0 || computedTotalAmount < invoiceTotalAmount) { + invoicePaymentInfo.clear() + invoiceTerm = from("InvoiceTerm").where("invoiceId", invoice.invoiceId, "termTypeId", "FIN_PAYMENT_TERM").queryFirst() + if (invoiceTerm) { + invoicePaymentInfo.termTypeId = invoiceTerm.termTypeId + invoicePaymentInfo.dueDate = UtilDateTime.getDayEnd(invoice.invoiceDate, invoiceTerm.termDays) + } else { + invoicePaymentInfo.dueDate = UtilDateTime.getDayEnd(invoice.invoiceDate) + } + invoicePaymentInfo.invoiceId = invoice.invoiceId + invoicePaymentInfo.amount = invoiceTotalAmount - computedTotalAmount + invoicePaymentInfo.paidAmount = remainingAppliedAmount + invoicePaymentInfo.outstandingAmount = invoicePaymentInfo.amount - invoicePaymentInfo.paidAmount + invoicePaymentInfoList.add(invoicePaymentInfo) + } + Map result = success() + result.invoicePaymentInfoList = invoicePaymentInfoList + return result +} def updatePayment() { Map lookupPayment = makeValue("Payment") lookupPayment.setPKFields(parameters) diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml index 9f059cb..a848315 100644 --- a/applications/accounting/minilang/payment/PaymentServices.xml +++ b/applications/accounting/minilang/payment/PaymentServices.xml @@ -245,112 +245,6 @@ under the License. <field-to-result field="paymentApplicationId" result-name="paymentApplicationId"/> </simple-method> - <simple-method method-name="getInvoicePaymentInfoList" short-description="Create a list with information on payment due dates and amounts for the invoice"> - <if-empty field="parameters.invoice"> - <entity-one entity-name="Invoice" value-field="invoice"/> - <else> - <set field="invoice" from-field="parameters.invoice"/> - </else> - </if-empty> - <call-class-method class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" method-name="getInvoiceTotal" ret-field="invoiceTotalAmount"> - <field field="invoice" type="org.apache.ofbiz.entity.GenericValue"/> - </call-class-method> - <call-class-method class-name="org.apache.ofbiz.accounting.invoice.InvoiceWorker" method-name="getInvoiceApplied" ret-field="invoiceTotalAmountPaid"> - <field field="invoice" type="org.apache.ofbiz.entity.GenericValue"/> - </call-class-method> - <get-related relation-name="InvoiceTerm" value-field="invoice" list="invoiceTerms"/> - <set field="remainingAppliedAmount" from-field="invoiceTotalAmountPaid" type="BigDecimal"/> - <set field="computedTotalAmount" value="0.0" type="BigDecimal"/> - <iterate list="invoiceTerms" entry="invoiceTerm"> - <get-related-one relation-name="TermType" value-field="invoiceTerm" to-value-field="termType" use-cache="true"/> - <if-compare field="termType.parentTypeId" operator="equals" value="FIN_PAYMENT_TERM"> - <clear-field field="invoicePaymentInfo"/> - <set field="invoicePaymentInfo.invoiceId" from-field="invoice.invoiceId"/> - <set field="invoicePaymentInfo.invoiceTermId" from-field="invoiceTerm.invoiceTermId"/> - <set field="invoicePaymentInfo.termTypeId" from-field="invoiceTerm.termTypeId"/> - <call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="getDayEnd" ret-field="invoicePaymentInfo.dueDate"> - <field field="invoice.invoiceDate" type="Timestamp"/> - <field field="invoiceTerm.termDays" type="Long"/> - </call-class-method> - <calculate field="invoiceTermAmount" type="BigDecimal"> - <calcop operator="multiply" field="invoiceTotalAmount"> - <calcop operator="get" field="invoiceTerm.termValue"/> - </calcop> - </calculate> - <calculate field="invoiceTermAmount" type="BigDecimal"> - <calcop operator="divide" field="invoiceTermAmount"> - <number value="100"/> - </calcop> - </calculate> - <set field="invoicePaymentInfo.amount" from-field="invoiceTermAmount"/> - <calculate field="computedTotalAmount" type="BigDecimal"> - <calcop operator="add" field="computedTotalAmount"> - <calcop operator="get" field="invoicePaymentInfo.amount"/> - </calcop> - </calculate> - <if-compare-field field="remainingAppliedAmount" to-field="invoiceTermAmount" operator="greater-equals" type="BigDecimal"> - <set field="invoicePaymentInfo.paidAmount" from-field="invoiceTermAmount" type="BigDecimal"/> - <calculate field="remainingAppliedAmount" type="BigDecimal"> - <calcop operator="subtract" field="remainingAppliedAmount"> - <calcop operator="get" field="invoiceTermAmount"/> - </calcop> - </calculate> - <else> - <set field="invoicePaymentInfo.paidAmount" from-field="remainingAppliedAmount" type="BigDecimal"/> - <set field="remainingAppliedAmount" value="0.0" type="BigDecimal"/> - </else> - </if-compare-field> - <calculate field="invoicePaymentInfo.outstandingAmount" type="BigDecimal"> - <calcop operator="subtract" field="invoicePaymentInfo.amount"> - <calcop operator="get" field="invoicePaymentInfo.paidAmount"/> - </calcop> - </calculate> - <set field="invoicePaymentInfoList[]" from-field="invoicePaymentInfo"/> - </if-compare> - </iterate> - <if> - <condition> - <or> - <if-compare field="remainingAppliedAmount" operator="greater" value="0.0" type="BigDecimal"/> - <if-compare field="invoiceTotalAmount" operator="less-equals" value="0.0" type="BigDecimal"/> - <if-compare-field field="computedTotalAmount" to-field="invoiceTotalAmount" operator="less" type="BigDecimal"/> - </or> - </condition> - <then> - <clear-field field="invoicePaymentInfo"/> - <set field="andMap.termTypeId" value="FIN_PAYMENT_TERM"/> - <filter-list-by-and list="invoiceTerms" map="andMap"/> - <first-from-list list="invoiceTerms" entry="invoiceTerm"/> - <if-not-empty field="invoiceTerm"> - <set field="invoicePaymentInfo.termTypeId" from-field="invoiceTerm.termTypeId"/> - <call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="getDayEnd" ret-field="invoicePaymentInfo.dueDate"> - <field field="invoice.invoiceDate" type="Timestamp"/> - <field field="invoiceTerm.termDays" type="Long"/> - </call-class-method> - <else> - <call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="getDayEnd" ret-field="invoicePaymentInfo.dueDate"> - <field field="invoice.invoiceDate" type="Timestamp"/> - </call-class-method> - </else> - </if-not-empty> - <set field="invoicePaymentInfo.invoiceId" from-field="invoice.invoiceId"/> - <calculate field="invoicePaymentInfo.amount" type="BigDecimal"> - <calcop operator="subtract" field="invoiceTotalAmount"> - <calcop operator="get" field="computedTotalAmount"/> - </calcop> - </calculate> - <set field="invoicePaymentInfo.paidAmount" from-field="remainingAppliedAmount" type="BigDecimal"/> - <calculate field="invoicePaymentInfo.outstandingAmount" type="BigDecimal"> - <calcop operator="subtract" field="invoicePaymentInfo.amount"> - <calcop operator="get" field="invoicePaymentInfo.paidAmount"/> - </calcop> - </calculate> - <set field="invoicePaymentInfoList[]" from-field="invoicePaymentInfo"/> - </then> - </if> - <field-to-result field="invoicePaymentInfoList" result-name="invoicePaymentInfoList"/> - </simple-method> - <simple-method method-name="getInvoicePaymentInfoListByDueDateOffset" short-description="Select a list with information on payment due dates and amounts for invoices."> <now-timestamp field="nowTimestamp"/> <call-class-method class-name="org.apache.ofbiz.base.util.UtilDateTime" method-name="getDayEnd" ret-field="asOfDate"> diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml index 8a0dae3..0e44ee4 100644 --- a/applications/accounting/servicedef/services_payment.xml +++ b/applications/accounting/servicedef/services_payment.xml @@ -126,8 +126,8 @@ under the License. <override name="amount" optional="false"/> </service> - <service name="getInvoicePaymentInfoList" engine="simple" - location="component://accounting/minilang/payment/PaymentServices.xml" invoke="getInvoicePaymentInfoList" auth="true"> + <service name="getInvoicePaymentInfoList" engine="groovy" + location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="getInvoicePaymentInfoList" auth="true"> <description>Create a list with information on payment due dates and amounts for the invoice; one of invoiceId or invoice must be provided.</description> <attribute name="invoiceId" type="String" mode="IN" optional="true"/> <attribute name="invoice" type="org.apache.ofbiz.entity.GenericValue" mode="IN" optional="true"/> |
Free forum by Nabble | Edit this page |