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 89016fa Improved: Converted getPaymentRunningTotal service from mini-lang to groovy DSL (OFBIZ-11488) Thanks Nitish Mishra for the patch and Devanshu Vyas for reporting and review. 89016fa is described below commit 89016fa71e85820b3ef19134f14238baf53c2acf Author: Suraj Khurana <[hidden email]> AuthorDate: Sat May 23 10:27:50 2020 +0530 Improved: Converted getPaymentRunningTotal service from mini-lang to groovy DSL (OFBIZ-11488) Thanks Nitish Mishra for the patch and Devanshu Vyas for reporting and review. --- .../groovyScripts/payment/PaymentServices.groovy | 37 ++++++++++++++++++++++ .../minilang/payment/PaymentServices.xml | 21 ------------ .../accounting/servicedef/services_payment.xml | 4 +-- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy index 56c653b..b71c419 100644 --- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy +++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy @@ -18,7 +18,10 @@ */ 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 +import org.apache.ofbiz.entity.condition.EntityCondition +import org.apache.ofbiz.entity.condition.EntityOperator import org.apache.ofbiz.entity.GenericValue MODULE = "PaymentServices.groovy" @@ -57,3 +60,37 @@ def createPayment() { result.paymentId = paymentId return result } + +def getPaymentRunningTotal(){ + paymentIds = parameters.paymentIds; + runningTotal = 0; + payments = from("Payment").where(EntityCondition.makeCondition("paymentId", EntityOperator.IN, paymentIds)).queryList() + if (payments) { + for (GenericValue payment : payments) { + runningTotal = runningTotal + payment.amount; + } + } + + if (parameters.organizationPartyId) { + serviceCtx = [ + organizationPartyId: parameters.organizationPartyId, + userLogin: userLogin + ] + serviceResult = dispatcher.runSync('getPartyAccountingPreferences', serviceCtx); + partyAcctgPreference = serviceResult.partyAccountingPreference; + + if (partyAcctgPreference.baseCurrencyUomId) { + currencyUomId = partyAcctgPreference.baseCurrencyUomId; + } else { + currencyUomId = UtilProperties.getPropertyValue('general.properties', 'currency.uom.id.default'); + } + } else { + currencyUomId = UtilProperties.getPropertyValue('general.properties', 'currency.uom.id.default'); + } + + paymentRunningTotal = UtilFormatOut.formatCurrency(runningTotal, currencyUomId, locale); + + result = success() + result.paymentRunningTotal = paymentRunningTotal + return result +} diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml index 3d6f961..3811bf7 100644 --- a/applications/accounting/minilang/payment/PaymentServices.xml +++ b/applications/accounting/minilang/payment/PaymentServices.xml @@ -512,27 +512,6 @@ under the License. </iterate> </simple-method> - <simple-method method-name="getPaymentRunningTotal" short-description="calculate running total for payments"> - <set field="paymentIds" from-field="parameters.paymentIds"/> - <set field="runningTotal" type="BigDecimal" value="0"/> - <entity-condition entity-name="Payment" list="payments"> - <condition-expr field-name="paymentId" operator="in" from-field="paymentIds"/> - </entity-condition> - <iterate list="payments" entry="payment"> - <set field="runningTotal" value="${runningTotal + payment.amount}" type="BigDecimal"/> - </iterate> - <set-service-fields service-name="getPartyAccountingPreferences" map="parameters" to-map="getPartyAccountingPreferencesMap"/> - <call-service service-name="getPartyAccountingPreferences" in-map-name="getPartyAccountingPreferencesMap"> - <result-to-field result-name="partyAccountingPreference"/> - </call-service> - <set field="currencyUomId" from-field="partyAccountingPreference.baseCurrencyUomId"/> - <if-empty field="currencyUomId"> - <property-to-field resource="general" property="currency.uom.id.default" field="currencyUomId"/> - </if-empty> - <set field="paymentRunningTotal" value="${groovy:org.apache.ofbiz.base.util.UtilFormatOut.formatCurrency(runningTotal, currencyUomId, parameters.locale)}"/> - <field-to-result field="paymentRunningTotal"/> - </simple-method> - <simple-method method-name="cancelPaymentBatch" short-description="cancel payment batch"> <entity-and entity-name="PmtGrpMembrPaymentAndFinAcctTrans" list="paymentGroupMemberAndTransList"> <field-map field-name="paymentGroupId" from-field="parameters.paymentGroupId"/> diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml index ba0cacd..a7d9554 100644 --- a/applications/accounting/servicedef/services_payment.xml +++ b/applications/accounting/servicedef/services_payment.xml @@ -151,8 +151,8 @@ under the License. <attribute name="finAccountTransId" type="String" mode="OUT" optional="true"/> <attribute name="statusId" type="String" mode="OUT" optional="true"/> </service> - <service name="getPaymentRunningTotal" engine="simple" - location="component://accounting/minilang/payment/PaymentServices.xml" invoke="getPaymentRunningTotal" auth="true"> + <service name="getPaymentRunningTotal" engine="groovy" + location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="getPaymentRunningTotal" auth="true"> <description>calculate running total for payments</description> <attribute name="paymentIds" type="List" mode="IN" optional="false"/> <attribute name="organizationPartyId" type="String" mode="IN" optional="true"/> |
Free forum by Nabble | Edit this page |