cancel
Showing results for 
Search instead for 
Did you mean: 

Create a Credit Memo from purchase invoice

Former Member
0 Kudos

¡¡Happy New Year!!

How can I Create a Credit Memo from purchase invoice ?

Thanks

Accepted Solutions (1)

Accepted Solutions (1)

former_member184566
Active Contributor
0 Kudos

Hi Joe

happy new year to you to, you will use the document object like you would usualy do, but to base it on the invoice you must use basetype (Document type),baseentry (Document number),baseline (row in the matrix). There is some sample code, this will create a AP credit note with one line from the AP Invoice. If you want more lines you'll have to adjust it accordingly.

Dim oCredit As SAPbobsCOM.Documents

oCredit = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oPurchaseCreditNotes)

oCredit.CardCode = "ADA001-S"

oCredit.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oPurchaseInvoices

oCredit.Lines.BaseEntry = 1055

oCredit.Lines.BaseLine = 0

If oCredit.Add() <> 0 Then

oCompany.GetLastError(lRetCode, sErrMsg)

MsgBox(sErrMsg)

End If

Hope this helps

Former Member
0 Kudos

Hi, Louis

I tried that code, but it sent the next error

"Ninguna coincidencia con documento base"

Thanks

Former Member
0 Kudos

This is the message:

"No coincidence with document bases"

Joe Martinez

Thanks

former_member184566
Active Contributor
0 Kudos

have no idea what that error os from, only thing i can think of is that the document number that you want to base it on doesn't exist or is for a different BP. But i'm assuming you have solved it as you gave me the points.

Let me know if you still can't get it working.

Former Member
0 Kudos

Dear Louis,

Really, I haven´t been able to solve then problem, but I am doing another test So I can know What the problem is.

Joe Martinez

Answers (1)

Answers (1)

Former Member
0 Kudos

How Can I Create a Credit Memo from oInvoice ?

regards,

Joe Martinez

Thanks

former_member184566
Active Contributor
0 Kudos

Hi Joe

The code above is adding a credit memo based on a invoice. The above code does work, i just tried it. Something else is wrong. have you created an invoice you wish to make into a credit note? If you do the credit note from the front end does it work? Also the error....i don't understand it, if you could translate to english i might be able to help you. I've added another exampl which i have used before....it will add a AR Sales Order the convert it to a Ar Invoice. The reason i'm showing you this is because im using oCompany.GetNewObjectCode(OrderStr) to get the do number of last one added. I've seen ones where it differs from the front end sometimes. Please test carefully as all of it works on my side.

Dim oBP As SAPbobsCOM.BusinessPartners

Dim BPCodeStr As String

oBP = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners)

Dim oOrderDoc As SAPbobsCOM.Documents

oOrderDoc = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oOrders)

BPCodeStr = "Your Customer code"

If oBP.GetByKey(BPCodeStr) Then

oOrderDoc.CardCode = BPCodeStr

oOrderDoc.DocDueDate = Now

oOrderDoc.Lines.ItemCode = "Code" oOrderDoc.Lines.Quantity = 1

oOrderDoc.Lines.Add()

oOrderDoc.Lines.ItemCode = "Code" oOrderDoc.Lines.Quantity = "11

lRetCode = oOrderDoc.Add

If lRetCode <> 0 Then

MessageBox.Show("Not Added")

ElseIf lRetCode = 0 Then

oCompany.GetNewObjectCode(OrderStr)

MsgBox(OrderStr)

End If

End If

Dim oInvoice As SAPbobsCOM.Documents

Dim OrderStr as string

oCompany.GetNewObjectCode(OrderStr)

oInvoice = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices)

oInvoice.CardCode = "Customer Code"

oInvoice.DocDueDate = Now

oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders

oInvoice.Lines.BaseEntry = CInt(OrderStr)

oInvoice.Lines.BaseLine = 0

oInvoice.Lines.Add()

oInvoice.Lines.BaseType = SAPbobsCOM.BoObjectTypes.oOrders

oInvoice.Lines.BaseEntry = CInt(OrderStr)

oInvoice.Lines.BaseLine = 1

lRetCode = oInvoice.Add

oCompany.GetLastError(lErrCode, sErrMsg)

If lRetCode <> 0 Then

MessageBox.Show("Not Added" & lErrCode & " " & sErrMsg)

ElseIf lRetCode = 0 Then

'oCompany.GetNewObjectCode(OrderStr)

MsgBox("Added Invoice")

End If

Hope this helps