cancel
Showing results for 
Search instead for 
Did you mean: 

invoice + Multiple Incoming Payment

kennedy_shabola
Explorer
0 Kudos

Hi  Experts ,

i have  the  code  below  that   only works   for the  First  Payment method   CASH  and   doesn't   (LOOP)  work for  the  Rest . It obtains the Doc entry  of an invoice already posted   in SAP business  one  attempts  to apply Separated  Incoming  payments  Documents  to the Invoice  tagged  to a Customer   . But   it only  applies the  First  amount       what  am i doing  wrong

      For Each row As DataGridViewRow In DgrApMultiplepayment.Rows

            If Not row.IsNewRow Then

                PAYMENTTYPE = row.Cells.Item("PAYMENTTYPE").Value.ToString()

                ACCOUNT = row.Cells.Item("ACCOUNT").Value.ToString()

                AMOUNT = row.Cells.Item("AMOUNT").Value.ToString()

                TRSFRDATE = row.Cells.Item("TRSFRDATE").Value.ToString()

                TRSFRREF = row.Cells.Item("REFERENCE").Value.ToString()

                CREDITCARD = row.Cells.Item("CREDITCARDNAME").Value.ToString()

                CREDITCARDNUMBER = row.Cells.Item("CREDITCARDNUMBER").Value.ToString()

                CARDVALIDUNTIL = row.Cells.Item("CARDVALIDUNTIL").Value.ToString()

                Dim oPmt As SAPbobsCOM.Payments = Nothing

                '

                Dim InvoiceObject As Recordset = DirectCast(vCompany.GetBusinessObject(BoObjectTypes.BoRecordset), Recordset)

                InvoiceObject.DoQuery("SELECT  TOP 1 DocEntry FROM OINV   WHERE Comments = '" & Trim(UNIQUEID) & "'  ORDER BY DocEntry DESC  ")

                sNum = InvoiceObject.Fields.Item(0).Value.ToString()

                oPmt = vCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oIncomingPayments)

                Select Case PAYMENTTYPE

                    

                    Case "CASH"

                            oPmt.Invoices.DocEntry = sNum

                            oPmt.CardCode = oDoc.CardCode

                            oPmt.DocTypte = SAPbobsCOM.BoRcptTypes.rCustomer

                            oPmt.TaxDate = TRSFRDATE

                            oPmt.CashAccount = ACCOUNT

                            oPmt.CashSum = AMOUNT

                            oPmt.ApplyVAT = SAPbobsCOM.BoYesNoEnum.tNO

                        oPmt.Add()

                    Case "CRDCARD"

                            oPmt.Invoices.DocEntry = sNum

                            oPmt.CardCode = oDoc.CardCode

                            oPmt.DocTypte = SAPbobsCOM.BoRcptTypes.rCustomer

                            oPmt.CreditCards.CardValidUntil = Month(Now) & "/" & Year(Now)

                            oPmt.CreditCards.CreditAcct = ACCOUNT

                            oPmt.CreditCards.CreditCard = 1

                            oPmt.CreditCards.VoucherNum = VOUCHERNUMBER

                            oPmt.CreditCards.CreditSum = AMOUNT

                            oPmt.CreditCards.FirstPaymentDue = Date.Now

                            oPmt.CreditCards.NumOfPayments = 1

                           oPmt.Add()

                    Case "CHEQUE"

                        oPmt.Invoices.DocEntry = sNum

                        oPmt.CardCode = oDoc.CardCode

                        oPmt.DocTypte = SAPbobsCOM.BoRcptTypes.rCustomer

                        oPmt.Checks.CheckAccount = ACCOUNT

                        oPmt.Checks.DueDate = TRSFRDATE

                        oPmt.Checks.CheckNumber = TRSFRREF

                        oPmt.Checks.BankCode = "36"

                        oPmt.Checks.CheckSum = AMOUNT

                        oPmt.ApplyVAT = BoYesNoEnum.tNO

                        oPmt.Add()

          END  SELECT

   NEXT

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I don't know the answer to your problem right offhand, but I do see a couple of problems in your code that might help resolve things.

First, at the end of every loop, you should ALWAYS be correctly disposing all DI API objects using Marshal services. Since the SAP COM object don't clean themselves up very well, it can cause memory leaks. You'll want to add something like to following to your code after every loop:


If SAPBobsCOMobject IsNot Nothing Then

    System.Runtime.InteropServices.Marshal.ReleaseComObject(SAPBobsCOMobject)

    SAPBobsCOMobject = Nothing

End If

Might want to throw it into a basic method so that you can call it with one line of code every time. This should be run at the end of EVERY one of your loops (best within the Finally block of a Try Catch so that it always runs).

Secondly, and more importantly, you're entirely missing error trapping within your code. This is probably why you don't know what the problem is. You should replace your oPmt.Add() method calls with something like this:


Dim errCode As Integer

errCode = oPmt.Add()

If errCode <> 0 Then

    Dim errMsg As String = ""

    SBO_Company_Object.GetLastError(errCode, errMsg)

    MsgBox(errCode.ToString & errMsg)

End If

This will give you the very last error that occurred, and should help you find what the problem is. You'll want to use a similar method EVERY time you Add or Update to the database, and capture that error.

Answers (0)