You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by su...@apache.org on 2020/05/23 10:28:32 UTC
[ofbiz-framework] branch trunk updated: Improved: Converted
createPaymentAndApplicationForParty service from mini-lang to groovy
(OFBIZ-11491) Thanks Devanshu Vyas for reporting and Sourabh Punyani for
providing the patch.
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 9e194b0 Improved: Converted createPaymentAndApplicationForParty service from mini-lang to groovy (OFBIZ-11491) Thanks Devanshu Vyas for reporting and Sourabh Punyani for providing the patch.
new 2ac82b4 Merge branch 'trunk' of https://gitbox.apache.org/repos/asf/ofbiz-framework into trunk
9e194b0 is described below
commit 9e194b0e9ae0ada8ef2f0078f4dc6b71ecc922c6
Author: Suraj Khurana <su...@apache.org>
AuthorDate: Sat May 23 15:57:21 2020 +0530
Improved: Converted createPaymentAndApplicationForParty service from mini-lang to groovy
(OFBIZ-11491)
Thanks Devanshu Vyas for reporting and Sourabh Punyani for providing the patch.
---
.../groovyScripts/payment/PaymentServices.groovy | 61 +++++++++++++++++++++-
.../minilang/payment/PaymentServices.xml | 59 ---------------------
.../accounting/servicedef/services_payment.xml | 4 +-
3 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
index 212207d..5e2749b 100644
--- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy
+++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy
@@ -23,6 +23,7 @@ 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
+import org.apache.ofbiz.service.ModelService
import org.apache.ofbiz.service.ServiceUtil
import java.sql.Timestamp
@@ -62,7 +63,65 @@ def createPayment() {
result.paymentId = paymentId
return result
}
-
+def createPaymentAndApplicationForParty() {
+ paymentAmount = 0
+ List invoiceIds = []
+ Map result = success()
+ parameters.invoices.each { invoice ->
+ if ("INVOICE_READY" == invoice.statusId) {
+ Map serviceContext = dispatcher.getDispatchContext().makeValidContext('getInvoicePaymentInfoList', ModelService.IN_PARAM, invoice)
+ serviceContext.userLogin = userLogin
+ serviceResult = run service: 'getInvoicePaymentInfoList', with: serviceContext
+ if (ServiceUtil.isError(serviceResult)) return serviceResult
+ invoicePaymentInfo = serviceResult.invoicePaymentInfoList[0]
+ paymentAmount += invoicePaymentInfo.outstandingAmount
+ } else {
+ return error(UtilProperties.getMessage("AccountingUiLabels", "AccountingInvoicesRequiredInReadyStatus", parameters.locale))
+ }
+ }
+ if (paymentAmount > 0) {
+ serviceResult = run service: 'getPartyAccountingPreferences', with: parameters
+ if (ServiceUtil.isError(serviceResult)) return serviceResult
+ partyAcctgPreference = serviceResult.partyAccountingPreference
+ Map createPaymentMap = [:]
+ createPaymentMap.paymentTypeId = "VENDOR_PAYMENT"
+ createPaymentMap.partyIdFrom = parameters.organizationPartyId
+ createPaymentMap.currencyUomId = partyAcctgPreference.baseCurrencyUomId
+ createPaymentMap.partyIdTo = parameters.partyId
+ createPaymentMap.statusId = "PMNT_SENT"
+ createPaymentMap.amount = paymentAmount
+ createPaymentMap.paymentMethodTypeId = parameters.paymentMethodTypeId
+ createPaymentMap.paymentMethodId = parameters.paymentMethodId
+ createPaymentMap.paymentRefNum = parameters.checkStartNumber
+ createPaymentMap.userLogin = userLogin
+ serviceResult = run service: 'createPayment', with: createPaymentMap
+ if (ServiceUtil.isError(serviceResult)) return serviceResult
+ paymentId = serviceResult.paymentId
+ result.paymentId = paymentId
+
+ parameters.invoices.each {invoice ->
+ if ("INVOICE_READY" == invoice.statusId) {
+ Map serviceContext = dispatcher.getDispatchContext().makeValidContext('getInvoicePaymentInfoList', ModelService.IN_PARAM, invoice)
+ serviceContext.userLogin = userLogin
+ serviceResult = run service: 'getInvoicePaymentInfoList', with: serviceContext
+ if (ServiceUtil.isError(serviceResult)) return serviceResult
+ invoicePaymentInfo = serviceResult.invoicePaymentInfoList[0]
+ if (invoicePaymentInfo.outstandingAmount > 0) {
+ Map createPaymentApplicationMap = [:]
+ createPaymentApplicationMap.paymentId = paymentId
+ createPaymentApplicationMap.amountApplied = invoicePaymentInfo.outstandingAmount
+ createPaymentApplicationMap.invoiceId = invoice.invoiceId
+ serviceResult = run service: 'createPaymentApplication', with: createPaymentApplicationMap
+ if (ServiceUtil.isError(serviceResult)) return serviceResult
+ }
+ }
+ invoiceIds.add(invoice.invoiceId)
+ }
+ }
+ result.invoiceIds = invoiceIds
+ result.amount = paymentAmount
+ return result
+}
def getPaymentRunningTotal(){
paymentIds = parameters.paymentIds;
runningTotal = 0;
diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml
index ae862251..9ce7e3b 100644
--- a/applications/accounting/minilang/payment/PaymentServices.xml
+++ b/applications/accounting/minilang/payment/PaymentServices.xml
@@ -593,65 +593,6 @@ under the License.
</if-empty>
</simple-method>
- <simple-method method-name="createPaymentAndApplicationForParty" short-description="create Payment and PaymentApplications for multiple invoices for one party">
- <set field="paymentAmount" type="BigDecimal" value="0"/>
- <iterate list="parameters.invoices" entry="invoice">
- <if-compare field="invoice.statusId" operator="equals" value="INVOICE_READY" type="String">
- <set-service-fields service-name="getInvoicePaymentInfoList" map="invoice" to-map="getInvoicePaymentInfoListCtx"/>
- <call-service service-name="getInvoicePaymentInfoList" in-map-name="getInvoicePaymentInfoListCtx">
- <result-to-field result-name="invoicePaymentInfoList"/>
- </call-service>
- <first-from-list list="invoicePaymentInfoList" entry="invoicePaymentInfo"/>
- <set field="paymentAmount" value="${paymentAmount + invoicePaymentInfo.outstandingAmount}"/>
- <else>
- <add-error>
- <fail-property resource="AccountingUiLabels" property="AccountingInvoicesRequiredInReadyStatus"/>
- </add-error>
- <check-errors/>
- </else>
- </if-compare>
- </iterate>
- <if-compare field="paymentAmount" operator="greater" type="BigDecimal" value="0">
- <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" field="partyAcctgPreference"/>
- </call-service>
- <set field="createPaymentMap.paymentTypeId" value="VENDOR_PAYMENT"/>
- <set field="createPaymentMap.partyIdFrom" from-field="parameters.organizationPartyId"/>
- <set field="createPaymentMap.currencyUomId" from-field="partyAcctgPreference.baseCurrencyUomId"/>
- <set field="createPaymentMap.partyIdTo" from-field="parameters.partyId"/>
- <set field="createPaymentMap.statusId" value="PMNT_SENT"/>
- <set field="createPaymentMap.amount" type="BigDecimal" from-field="paymentAmount"/>
- <set field="createPaymentMap.paymentMethodTypeId" from-field="parameters.paymentMethodTypeId"/>
- <set field="createPaymentMap.paymentMethodId" from-field="parameters.paymentMethodId"/>
- <set field="createPaymentMap.paymentRefNum" type="String" from-field="parameters.checkStartNumber"/>
- <call-service service-name="createPayment" in-map-name="createPaymentMap">
- <result-to-field result-name="paymentId"/>
- <result-to-result result-name="paymentId"/>
- </call-service>
- <iterate list="parameters.invoices" entry="invoice">
- <if-compare field="invoice.statusId" operator="equals" value="INVOICE_READY">
- <set-service-fields service-name="getInvoicePaymentInfoList" map="invoice" to-map="getInvoicePaymentInfoListCtx"/>
- <call-service service-name="getInvoicePaymentInfoList" in-map-name="getInvoicePaymentInfoListCtx">
- <result-to-field result-name="invoicePaymentInfoList" field="invoicePaymentInfoList"/>
- </call-service>
- <first-from-list list="invoicePaymentInfoList" entry="invoicePaymentInfo"/>
- <if-compare field="invoicePaymentInfo.outstandingAmount" operator="greater" value="0">
- <set field="createPaymentApplicationMap.paymentId" from-field="paymentId"/>
- <set field="createPaymentApplicationMap.amountApplied" from-field="invoicePaymentInfo.outstandingAmount"/>
- <set field="createPaymentApplicationMap.invoiceId" from-field="invoice.invoiceId"/>
- <call-service service-name="createPaymentApplication" in-map-name="createPaymentApplicationMap"/>
- </if-compare>
- </if-compare>
- <field-to-list field="invoice.invoiceId" list="invoiceIds"/>
- <clear-field field="createPaymentApplicationMap"/>
- </iterate>
- </if-compare>
- <field-to-result field="invoiceIds"/>
- <set field="amount" type="BigDecimal" from-field="paymentAmount"/>
- <field-to-result field="amount"/>
- </simple-method>
-
<simple-method method-name="createFinAccoutnTransFromPayment" short-description="Creates a record for FinAccountTrans on creation of payment.">
<set-service-fields service-name="createFinAccountTrans" map="parameters" to-map="createFinAccountTransMap"/>
<set field="createFinAccountTransMap.finAccountTransTypeId" value="WITHDRAWAL"/>
diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml
index e1c8344..00099dd 100644
--- a/applications/accounting/servicedef/services_payment.xml
+++ b/applications/accounting/servicedef/services_payment.xml
@@ -174,8 +174,8 @@ under the License.
<attribute name="paymentGroupId" type="String" mode="OUT" optional="true"/>
<attribute name="errorMessage" type="String" optional="true" mode="OUT"/>
</service>
- <service name="createPaymentAndApplicationForParty" engine="simple"
- location="component://accounting/minilang/payment/PaymentServices.xml" invoke="createPaymentAndApplicationForParty" auth="true">
+ <service name="createPaymentAndApplicationForParty" engine="groovy"
+ location="component://accounting/groovyScripts/payment/PaymentServices.groovy" invoke="createPaymentAndApplicationForParty" auth="true">
<description>create Payment and PaymentApplications for multiple invoices for one party</description>
<attribute name="organizationPartyId" type="String" mode="INOUT" optional="true"/>
<attribute name="partyId" type="String" mode="IN" optional="false"/>