Page 1 of 1

Sales Order Payments - Cash Book Rcts change

PostPosted: Fri Jul 22, 2016 2:31 pm
by DannyC
Hi,

When a sales order payment is created, Jwia automatically creates a Cash Book Receipts batch in the background.
I need to change the bank account on the created cash book receipt.
I can't work out how to do it.

The bank account change will be based on the sales order branch/division, so a different back acct for each division.
It would also mean a new batch (on the same day) would need to be created for different divisions.

Can you point me in the right direction?

Cheers

Danny

Re: Sales Order Payments - Cash Book Rcts change  Topic is solved

PostPosted: Sun Jul 31, 2016 2:33 pm
by Mike.Sheen
Hi Danny,

In the payment processing part of the code, we do the following:

Code: Select all
For Each payment As Payment In SalesOrderPayments
                RaiseEvent PaymentProcessingStart(Me, payment)

                If payment.Processed = False AndAlso payment.ProcessPayment Then
                    If SystemSettings.UsePaymentTypeBankAccounts Then
                        BankAccount = payment.PaymentType.LedgerAccount
                    Else
                        If SystemSettings.ChildDebtorsUseChildGLAccounts OrElse Debtor.ParentDebtor.DebtorID = "" Then
                            BankAccount = Debtor.LedgerDebtorSourcedReceipts
                        Else
                            BankAccount = Debtor.ParentDebtor.LedgerDebtorSourcedReceipts
                        End If
                    End If


So, you can add a handler for the PaymentProcessingStart event and in there set the Debtor.LedgerDebtorSourcedReceipts or payment.PaymentType.LedgerAccount (depending on how your UsePaymentTypeBankAccounts system setting is set) account by doing a Read on that entity - and then our payment processing code will use that account.

For example - after adding the "Sales Order Entry" to the business logic tab of your plugin, use the following code:

Code: Select all
Public Class BusinessLogicPlugin
    Inherits System.MarshalByRefObject
    Implements JiwaApplication.IJiwaBusinessLogicPlugin

    Public Overrides Function InitializeLifetimeService() As Object
        ' returning null here will prevent the lease manager
        ' from deleting the Object.
        Return Nothing
    End Function

    Public Sub Setup(ByVal JiwaBusinessLogic As JiwaApplication.IJiwaBusinessLogic, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaBusinessLogicPlugin.Setup
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = JiwaBusinessLogic
      AddHandler salesOrder.PaymentProcessingStart, AddressOf PaymentProcessingStart
    End Sub
   
   Private Sub PaymentProcessingStart(SalesOrder As JiwaSales.SalesOrder.SalesOrder, Payment As JiwaSales.SalesOrder.Payment)
      If SalesOrder.Branch.Description = "Perth" Then
         ' Override the bank account
         If SalesOrder.SystemSettings.UsePaymentTypeBankAccounts Then
            If SalesOrder.SystemSettings.ChildDebtorsUseChildGLAccounts OrElse SalesOrder.Debtor.ParentDebtor.DebtorID = "" Then
               SalesOrder.Debtor.LedgerDebtorSourcedReceipts.ReadRecordFromAccountNo("1000-000-01")
            Else               
               SalesOrder.Debtor.ParentDebtor.LedgerDebtorSourcedReceipts.ReadRecordFromAccountNo("1000-000-01")
            End If
         Else
            payment.PaymentType.LedgerAccount.ReadRecordFromAccountNo("1000-000-01")
         End If
      End If
   End Sub

End Class


Let us know if that works for you.

Mike

Re: Sales Order Payments - Cash Book Rcts change

PostPosted: Tue Aug 30, 2016 5:06 pm
by indikad
Hi Mike,

I have taken this project over from Danny.
have tried the code you supplied and cannot get it to work - not sure if its running too as the debug msgbox too does not pop up
( is it because its on the Business Logic plugin ?)
see my code below - only difference is the gl code and the message box.
can you advise pls ? What we want is the Bank Legder code to change - ( under the description field on header on a Cash Book receipt )
thanks.
Code: Select all
 Public Sub Setup(ByVal JiwaBusinessLogic As JiwaApplication.IJiwaBusinessLogic, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaBusinessLogicPlugin.Setup
'      If TypeOf JiwaBusinessLogic Is JiwaSales.SalesOrder.SalesOrder
'         Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = JiwaBusinessLogic
'            AddHandler salesOrder.PaymentProcessingStart, AddressOf PaymentProcessingStart   
'      End If
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = JiwaBusinessLogic
      AddHandler salesOrder.PaymentProcessingStart, AddressOf PaymentProcessingStart
    End Sub
   Private Sub PaymentProcessingStart(SalesOrder As JiwaSales.SalesOrder.SalesOrder, Payment As JiwaSales.SalesOrder.Payment)
      msgbox (" att_Bakery_CashBookReceiptDefaultGL  - at work ")
      If SalesOrder.Branch.Description = "Perth" Then
         ' Override the bank account
         If SalesOrder.SystemSettings.UsePaymentTypeBankAccounts Then
            If SalesOrder.SystemSettings.ChildDebtorsUseChildGLAccounts OrElse SalesOrder.Debtor.ParentDebtor.DebtorID = "" Then
               SalesOrder.Debtor.LedgerDebtorSourcedReceipts.ReadRecordFromAccountNo("1200-200-00")
            Else               
               SalesOrder.Debtor.ParentDebtor.LedgerDebtorSourcedReceipts.ReadRecordFromAccountNo("1200-200-00")
            End If
         Else
            payment.PaymentType.LedgerAccount.ReadRecordFromAccountNo("1200-200-00")
         End If
      End If
   End Sub

Re: Sales Order Payments - Cash Book Rcts change

PostPosted: Mon Jan 23, 2017 9:38 am
by indikad
attn Mike - Just trying to get attention to my reply above. Could you advise pls ?

Re: Sales Order Payments - Cash Book Rcts change

PostPosted: Mon Jan 23, 2017 9:48 am
by Mike.Sheen
Instead of a messagebox, put in a System.Diagnostics.Debugger.Launch() to determine if your code is actually running. Messageboxes will still display if invoked in business logic - but you've got to be mindful that there won't always be a user to display the messagebox to (e.g.: services).

If the debugger does not launch, then the PaymentProcessingStart event is not being raised by the sales order processing - which would occur if there were no payments on the sales order - there are payments on the sales order, right?

I missed your question because this was marked as answered after a few weeks of inactivity after I responded - Danny should have marked this topic as unanswered, or responded!

Re: Sales Order Payments - Cash Book Rcts change

PostPosted: Mon Jan 23, 2017 10:11 am
by indikad
Thanks Mike. I will follow your recommendations.