cancel
Showing results for 
Search instead for 
Did you mean: 

How to add payments with multiple invoice using di api?

0 Kudos

Im trying to post to sap from my add on application payments with multiple invoice. Im using C# in developing my add on app.
Heres my code.

foreach (var i in pay.Details)
{                                       
  InvoiceHeader inv = new InvoiceHeader();
  int r = 0;
  inv = context.InvoiceHeaders.FirstOrDefault(x => x.Id == i.TransactionDocumentNo);
  if (inv.IsPosted == "N") r = PostInvoice(inv);

  if (r > 0) inv = context.InvoiceHeaders.FirstOrDefault(x => x.Id == i.TransactionDocumentNo);
  _pay.Invoices.DocEntry = Convert.ToInt32(inv.DocumentNumber);
                                        
  errCode = _pay.Add();


  if (errCode != 0)
  {
     string _errMsg = "";
     company.GetLastError(out errCode, out _errMsg);
  }
  else
  {
    var _p = context.PaymentHeaders.FirstOrDefault(x => x.Id == pay.Id);
    _p.IsPosted = "Y";
    _p.UpdatedBy = "SAP POSTING";
    _p.UpdatedDate = DateTime.Now;
    _p.DocumentNumber = docnum;
    context.SaveChanges();
  }
}

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member185682
Active Contributor

Hi Farrah,

For pay multiples invoices, use the object Invoices inside the payment object.

A piece of sample:

                Payments oVendorPay = oCompany.GetBusinessObject(BoObjectTypes.oVendorPayments);
                oVendorPay.CardCode = "your bp";
                
                foreach(InvoiceInfo inv in lstInvoices)
                {
                    if (oVendorPay.Invoices.DocEntry != 0)
                        oVendorPay.Invoices.Add();


                    oVendorPay.Invoices.DocEntry = inv.DocEntry; //The primary key of your document
                    oVendorPay.Invoices.InvoiceType = inv.InvType; //The type of the document that you are paying
                    oVendorPay.Invoices.InstallmentId = inv.InstallmentId; //Use this property if you refer a installment of a document
                   // oVendorPay.Invoices.DocLine = 0; //Use this property if you are paying a journal entry, this property specifies what line you are paying
                    oVendorPay.Invoices.SumApplied = inv.InstallmentValue; //The value that you are paying
                }

Kind Regards,

Diego Lother