Adding Pament to a sales order  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Adding Pament to a sales order

Postby Ernst » Mon May 01, 2017 11:50 am

Hi,
Using .net vb on JIWA7.0.175

used to have this code in JIWA6.

If .AddSalesOrderPayment("AE58311B13FF44E2B146", PaidbyReturn) = e_SalesOrderReturnCodeSuccess Then
.SalesOrderPayments(1).PaymentRef = Paidby
.SalesOrderPayments(1).AmountPaid = Val(p.Item("amountPaid"))
.SalesOrderPayments(1).PaymentDate = .InitiatedDate
.SalesOrderPayments(1).ProcessPayment = True
End If
End If

Am having trouble getting the Add payment line to work. Could you let me have a sample bit of code. That adds a payment line. Any help appreciated thanks.
User avatar
Ernst
Kohai
Kohai
 
Posts: 242
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 13

Re: Adding Pament to a sales order  Topic is solved

Postby Scott.Pearce » Mon May 01, 2017 12:07 pm

Try something like:

Code: Select all
Dim newPaymentLine As New JiwaSales.SalesOrder.Payment
newPaymentLine.PaymentType.ReadRecord("AE58311B13FF44E2B146")
_SalesOrder.SalesOrderPayments.Add(newPaymentLine)
_SalesOrder.SalesOrderPayments(1).PaymentRef = Paidby
_SalesOrder.SalesOrderPayments(1).AmountPaid = Val(p.Item("amountPaid"))
_SalesOrder.SalesOrderPayments(1).PaymentDate = .InitiatedDate
_SalesOrder.SalesOrderPayments(1).ProcessPayment = True
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Adding Pament to a sales order

Postby Ernst » Mon May 01, 2017 4:02 pm

Works Great.... Thankssssssss

'From Scott.. Thank You...:)
If Data("paidBy") = "Payment Express" Then
Paidby = Left$(Data("company"), 20)
Dim newPaymentLine As New JiwaFinancials.Jiwa.JiwaSales.SalesOrder.Payment
newPaymentLine.PaymentType.ReadRecord("AE58311B13FF44E2B146")
.SalesOrderPayments.Add(newPaymentLine)
.SalesOrderPayments(1).PaymentRef = Paidby
.SalesOrderPayments(1).AmountPaid = Val(Data("amountPaid"))
.SalesOrderPayments(1).PaymentDate = .InitiatedDate
.SalesOrderPayments(1).ProcessPayment = True
End If
User avatar
Ernst
Kohai
Kohai
 
Posts: 242
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 13

Re: Adding Pament to a sales order

Postby Ernst » Wed Oct 31, 2018 9:07 am

Hi Scott,

Having this same code. and upgrading to 7.02 is getting an error on the newPaymentLine.PaymentType.ReadRecord("AE58311B13FF44E2B146").
Would we need to change to make it work for 7.02.

Thanks,

f Data("paidBy") = "Payment Express" Then
Paidby = Left$(Data("company"), 20)
Dim newPaymentLine As New JiwaFinancials.Jiwa.JiwaSales.SalesOrder.Payment
newPaymentLine.PaymentType.ReadRecord("AE58311B13FF44E2B146")
.SalesOrderPayments.Add(newPaymentLine)
.SalesOrderPayments(1).PaymentRef = Paidby
.SalesOrderPayments(1).AmountPaid = Val(Data("amountPaid"))
.SalesOrderPayments(1).PaymentDate = .InitiatedDate
.SalesOrderPayments(1).ProcessPayment = True
End If
User avatar
Ernst
Kohai
Kohai
 
Posts: 242
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 13

Re: Adding Pament to a sales order

Postby Scott.Pearce » Wed Oct 31, 2018 10:01 am

In Jiwa 7.0.177.0 and later, you must always use a factory to instantiate Jiwa objects. See:

https://docs.jiwa.com.au/display/J7UG/How+to+convert+plugins+or+code+to+be+compatible+with+7.00.177.00+or+later

Factories are available via the Manager object. All Jiwa objects have a Manager object property, so you should always have access to a Manager object. Your code snippet does not give context, so I don't know what other objects are available. If the code was in, say, the Setup function of the FormPlugin class, I could use the Manager property of the Plugin parameter that is passed in thus:

Code: Select all
Public Sub Setup(ByVal JiwaForm As JiwaApplication.IJiwaForm, ByVal Plugin As JiwaApplication.Plugin.Plugin) Implements JiwaApplication.IJiwaFormPlugin.Setup
    Dim myManagerObject As JiwaFinancials.Jiwa.JiwaApplication.Manager = Plugin.Manager
    Dim newPaymentLine As JiwaSales.SalesOrder.Payment = myManagerObject.CollectionItemFactory.CreateCollectionItem(Of JiwaSales.SalesOrder.Payment)
End Sub


Note the use of the CollectionItemFactory to create the JiwaSales.SalesOrder.Payment object. Also note that this factory was reached via a Manager object.

If your code snippet was inside an event handler, the event handler would likely have a sender of type object passed in. This "sender" parameter is always the object that caused the event. If you were inside an event handler for SalesOrder.SaveEnd, the code would look something like this:

Code: Select all
   Public Sub SalesOrder_SaveEnd(sender As Object, e As System.EventArgs)
      Dim salesOrder As JiwaSales.SalesOrder.SalesOrder = DirectCast(sender, JiwaSales.SalesOrder.SalesOrder)
      Dim myManagerObject As JiwaFinancials.Jiwa.JiwaApplication.Manager = salesOrder.Manager
      Dim newPaymentLine As JiwaSales.SalesOrder.Payment = myManagerObject.CollectionItemFactory.CreateCollectionItem(Of JiwaSales.SalesOrder.Payment)
   End Sub


Hope this helps.
Scott Pearce
Senior Analyst/Programmer
Jiwa Financials
User avatar
Scott.Pearce
Senpai
Senpai
 
Posts: 765
Joined: Tue Feb 12, 2008 11:27 am
Location: New South Wales, Australia
Topics Solved: 230

Re: Adding Pament to a sales order

Postby Ernst » Wed Oct 31, 2018 3:03 pm

Will give it a go thx.
User avatar
Ernst
Kohai
Kohai
 
Posts: 242
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 13

Re: Adding Pament to a sales order

Postby Ernst » Wed Oct 31, 2018 4:23 pm

OK Got that Working.. Thanks Scott. Here is code in VB if anybody needs help on this one.


Dim MyManagerObject As JiwaFinancials.Jiwa.JiwaApplication.Manager = MyJiwaSalesOrder.Manager
Dim newPaymentLine As JiwaFinancials.Jiwa.JiwaSales.SalesOrder.Payment = MyManagerObject.CollectionItemFactory.CreateCollectionItem(Of JiwaFinancials.Jiwa.JiwaSales.SalesOrder.Payment)()
'
If Data("paidBy") = "VISA" Then
newPaymentLine.PaymentType.ReadRecord("686AC90587044E77BEE0")
ElseIf Data("paidBy") = "PAYPAL" Then
newPaymentLine.PaymentType.ReadRecord("FA9126399DFD42C78E20")
ElseIf Data("paidBy") = "MASTERCARD" Then
newPaymentLine.PaymentType.ReadRecord("AD234634F08F42088B8A")
End If
.SalesOrderPayments.Add(newPaymentLine)
.SalesOrderPayments(1).AmountPaid = Val(Data("amountPaid"))
.SalesOrderPayments(1).PaymentDate = .InitiatedDate
.SalesOrderPayments(1).ProcessPayment = True
User avatar
Ernst
Kohai
Kohai
 
Posts: 242
Joined: Tue Feb 19, 2008 3:43 pm
Topics Solved: 13


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 4 guests