Page 1 of 1

Stop Jiwa firing VerifyPayments()

PostPosted: Tue Jan 17, 2023 12:37 pm
by DannyC
I have a client who wants to set up cash debtors and just display a warning if payments on the sales order don't meet the history total when processing.
Just a warning, with a yes/no to proceed if they want to.

At the moment the VerifyPayments() routine runs so , if a cash account is set up, and the system setting AllowSalesOrderSaveForCashOnlyDebtors is true, then it displays the message from VerifyPayments and the exception stops processing.

So I want to remove Jiwa's VerifyPayments and roll my own.

Best way of doing that?

Re: Stop Jiwa firing VerifyPayments()

PostPosted: Tue Jan 17, 2023 3:58 pm
by Mike.Sheen
DannyC wrote:So I want to remove Jiwa's VerifyPayments and roll my own.

Best way of doing that?


I've logged DEV-9746 to improve the event so you can via plugin signal you don't want the built-in validation performed.

In the meantime you will need to trick the system by setting the SalesOrder.Debtor.IsCashOnly to false temporarily (after preserving existig value) in a handler for VerifyPaymentsStart, and the set it back to what it was in VerifyPaymentsEnd. This will cause the built-in validation to be skipped.

Re: Stop Jiwa firing VerifyPayments()  Topic is solved

PostPosted: Tue Jan 17, 2023 3:59 pm
by SBarnes
Below is the code for verify payments, given there is clearly a verify payment start event and verify payments end event, why not simply set AllowSalesOrderSaveForCashOnlyDebtors to true in the start and then in the end event do your own code and reset the setting.

I haven't tested it but it should work.


Code: Select all
Public Sub VerifyPayments()
            OnVerifyPaymentsStart()

            If _CreditNote = False AndAlso _Debtor.IsCashOnly Then
                If (_IsProcessing) OrElse (_IsProcessing = False AndAlso SystemSettings.AllowSalesOrderSaveForCashOnlyDebtors = False) Then
                    Dim freightAmount = SalesOrderHistorys((SelectedHistoryNo)).CartageCharge1.IncGSTAmount + SalesOrderHistorys((SelectedHistoryNo)).CartageCharge2.IncGSTAmount + SalesOrderHistorys((SelectedHistoryNo)).CartageCharge3.IncGSTAmount
                    If SalesOrderPayments.TotalPayments < (SalesOrderLines.OrderedIncGSTTotal + freightAmount) Then
                        Throw New JiwaApplication.Exceptions.CreditTermsViolationException(String.Format("'{0}' is a cash only customer - you must ensure the invoice is fully paid before continuing.", _Debtor.AccountNoDashName))
                    End If
                End If
            End If

            OnVerifyPaymentsEnd()
        End Sub

Re: Stop Jiwa firing VerifyPayments()

PostPosted: Tue Jan 17, 2023 4:01 pm
by Mike.Sheen
SBarnes wrote:why not simply set AllowSalesOrderSaveForCashOnlyDebtors to true in the start and then in the end event do your own code reset the setting.


That's even better than setting SalesOrder.Debtor.IsCashOnly as I suggested.