diff --git a/applications/accounting/groovyScripts/payment/PaymentServices.groovy b/applications/accounting/groovyScripts/payment/PaymentServices.groovy index b3b6b6a77f..50e44e1021 100644 --- a/applications/accounting/groovyScripts/payment/PaymentServices.groovy +++ b/applications/accounting/groovyScripts/payment/PaymentServices.groovy @@ -319,6 +319,48 @@ def massChangePaymentStatus() { } return serviceResult } +def voidPayment() { + GenericValue payment = from("Payment").where("paymentId", parameters.paymentId).queryOne() + finAccountTransId = payment.finAccountTransId + transStatusId = 'FINACT_TRNS_CANCELED' + statusId = transStatusId + if (!payment) { + return error(UtilProperties.getResourceBundleMap("AccountingUiLabels", locale)?.AccountingNoPaymentsfound) + } + paymentId = parameters.paymentId + Map paymentStatusCtx = [:] + paymentStatusCtx.paymentId = paymentId + paymentStatusCtx.statusId = 'PMNT_VOID' + run service: 'setPaymentStatus', with: paymentStatusCtx + paymentApplications = from("PaymentApplication").where('paymentId', paymentId).queryList() + if (paymentApplications) { + paymentApplications.each{ paymentApplication -> + updateInvoiceCtx = from("Invoice").where('invoiceId', paymentApplication.invoiceId).queryOne() + if (updateInvoiceCtx.statusId == 'INVOICE_PAID') { + Map invoiceStatusCtx = dispatcher.getDispatchContext().makeValidContext('setInvoiceStatus', ModelService.IN_PARAM, updateInvoiceCtx) + invoiceStatusCtx.paidDate = '' + invoiceStatusCtx.statusId = 'INVOICE_READY' + run service: 'setInvoiceStatus', with: invoiceStatusCtx + } + Map removePaymentApplicationCtx = [:] + removePaymentApplicationCtx.paymentApplicationId = paymentApplication.paymentApplicationId + run service: 'removePaymentApplication', with: removePaymentApplicationCtx + } + acctgTransPaymentList = from('AcctgTrans').where('invoiceId', '', 'paymentId', paymentId).queryList() + acctgTransPaymentList.each{ acctgTransPayment -> + Map copyAcctgTransCtx = [:] + copyAcctgTransCtx.fromAcctgTransId = acctgTransPayment.acctgTransId + copyAcctgTransCtx.revert = 'Y' + acctgTransId = run service: 'copyAcctgTransAndEntries', with: copyAcctgTransCtx + if (acctgTransPayment.isPosted == 'Y') { + Map postAcctgTransMap = [:] + postAcctgTransMap.acctgTransId = acctgTransId + run service: 'postAcctgTrans', with: postAcctgTransMap + } + } + } + return success() +} def getPaymentGroupReconciliationId() { paymentGroupMember = from("PaymentGroupMember").where("paymentGroupId", parameters.paymentGroupId).queryFirst() diff --git a/applications/accounting/minilang/payment/PaymentServices.xml b/applications/accounting/minilang/payment/PaymentServices.xml index eb05f11eeb..157ee840d1 100644 --- a/applications/accounting/minilang/payment/PaymentServices.xml +++ b/applications/accounting/minilang/payment/PaymentServices.xml @@ -267,53 +267,6 @@ under the License. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/applications/accounting/servicedef/services_payment.xml b/applications/accounting/servicedef/services_payment.xml index 5a4d03af11..a34ff87237 100644 --- a/applications/accounting/servicedef/services_payment.xml +++ b/applications/accounting/servicedef/services_payment.xml @@ -142,8 +142,8 @@ under the License. - + Sets payment status to PMNT_VOID, removes all PaymentApplications, changes related invoice statuses to INVOICE_READY if status is INVOICE_PAID, and reverses related AcctgTrans by calling copyAcctgTransAndEntries service