Skip to Content
0

How to add payments with multiple invoice using di api?

Dec 01, 2016 at 01:20 AM

173

avatar image

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();
  }
}
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

DIEGO LOTHER Dec 01, 2016 at 11:24 AM
1

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

Share
10 |10000 characters needed characters left characters exceeded