Get the CreditorID in Creditor Cheque payment  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Get the CreditorID in Creditor Cheque payment

Postby dimuthu » Fri Feb 06, 2015 5:04 pm

Hi Mike,

Could you please provide me a sample syntax code for Creditor Cheque payment plugin .

My requirement is, On Save i need to get the CreditorID's in a FOR loop. Currently in V6 i use the following breakout code

For Each lCreditor In ChequePaymentObject.Creditors
SQL = "select AltAccountNo from CR_Main where CreditorID = '" & Trim(lCreditor.CreditorID) & "'"
Next

Also please tell me how to get the BatchNo. I tried in the plugin but couldn't.

Thanks
Dimuthu
dimuthu
Occasional Contributor
Occasional Contributor
 
Posts: 34
Joined: Fri Feb 06, 2015 3:03 pm

Re: Get the CreditorID in Creditor Cheque payment  Topic is solved

Postby Mike.Sheen » Fri Feb 06, 2015 6:19 pm

Hi Dimuthu,

Attached is a sample plugin showing this.

Plugin Cheque Payment sample.xml
Sample plugin
(32.01 KiB) Downloaded 149 times


I note you seem to be iterating the creditors and constructing a query to get the alternate account number - you don't need to use a SQL query to get the creditor AlternateAccountNo, as it is exposed in the object model now.

Code: Select all
Public Sub SaveStart(sender As Object, e As System.EventArgs)
    Dim chequepayment As JiwaCreditorChqPay.CreditorChequePayment = DirectCast(sender, JiwaCreditorChqPay.CreditorChequePayment)
    For Each creditor As JiwaCreditorChqPay.Creditor In chequepayment.Creditors
   ' creditor.Creditor.CreditorID  <-- this is the creditorID
   ' creditor.Creditor.AccountNo <-- We also have access to many other properties of the creditor, like AccountNo and AlternateAccountNo
    Next
End Sub


I also note your construction of your SQL query is using string concatenation. The recommended method is to now use parameterised queries, so instead of:

Code: Select all
SQL = "select AltAccountNo from CR_Main where CreditorID = '" & Trim(lCreditor.CreditorID) & "'"


We recommend:

Code: Select all
Dim SQLReader As SqlDataReader = Nothing
Dim SQLParam As SqlParameter = Nothing

Dim SQL As String = "SELECT TOP 1 AltAccountNo FROM CR_Main WHERE CreditorID = @CreditorID"
With JiwaApplication.Manager.Instance.Database
   Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
      SQLParam = New SqlParameter("@CreditorID", System.Data.SqlDbType.Char)
      SQLParam.Value = creditor.Creditor.CreditorID
      SQLCmd.Parameters.Add(SQLParam)

      SQLReader = SQLCmd.ExecuteReader()
      If SQLReader.Read = True Then
         Dim AltAccountNo As String = .Sanitise(SQLReader, "AltAccountNo ")
      Else
         Throw New JiwaApplication.Exceptions.RecordNotFoundException("creditor record not found.")
      End If
      SQLReader.Close()
   End Using
End With


The parameterised query will protect you from SQL Injection.

Mike
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2440
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 755

Re: Get the CreditorID in Creditor Cheque payment

Postby dimuthu » Mon Feb 09, 2015 9:50 am

Thanks Mike.
dimuthu
Occasional Contributor
Occasional Contributor
 
Posts: 34
Joined: Fri Feb 06, 2015 3:03 pm


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 6 guests

cron