API Forum

This forum is in read-only mode.
Please refer to our API support in case you have any questions.
We can be reached at api@e-conomic.com
e-conomic API developer forum

How do i create a "indbetaling" through the api?

0
How do i create a "indbetaling"?

I have looked at the cashbook_findbynumber(), what is the number put into the function?

Is it debtor number? invoice number or ?

I want to create a customer payment.
created Sep 29, 2014 by jakobdo
0% Accept Rate
Q 4 A 4 C 0

1 Answer

0

Hi Jakob,

Here's a code example in c# of how to create an invoice and pay it.

public static void CreateInvoiceAndPayIt()
        {
            using (var session = new EconomicWebServiceSoapClient())
            {
                Connect(session);
 
                var someDebtor = session.Debtor_GetAll().First();
                Console.WriteLine("Fetched some debtor: {0}", someDebtor.Number);
                var someProduct = session.Product_GetAll().First();
                Console.WriteLine("Fetched some product: {0}", someProduct.Number);
                var someTermOfPayment = session.TermOfPayment_GetAll().First();
                Console.WriteLine("Fetched some term of payment: {0}", someTermOfPayment.Id);
                var someCurrency = new CurrencyHandle {Code = "DKK"};
                Console.WriteLine("Fetched some currency: {0}", someCurrency.Code);
 
                var data = new CurrentInvoiceData
                    {
                        DebtorHandle = someDebtor,
                        CurrencyHandle = someCurrency,
                        DebtorName = "Selleri",
                        Date = DateTime.Now,
                        DueDate = DateTime.Now.AddDays(14),
                        TermOfPaymentHandle = someTermOfPayment
                    };
 
                var invoice = session.CurrentInvoice_CreateFromData(data);
 
                Console.WriteLine("Created current invoice: {0}", invoice.Id);
 
                var dataLine = new CurrentInvoiceLineData
                    {
                        ProductHandle = someProduct,
                        UnitNetPrice = 20,
                        Description = session.Product_GetData(someProduct).Name,
                        Quantity = 1,
                        InvoiceHandle = invoice
                    };
 
                var lineHandle = session.CurrentInvoiceLine_CreateFromData(dataLine);
                Console.WriteLine("Created a current invoice line on position: {0}", lineHandle.Number);
                var bookedInvoiceHandle = session.CurrentInvoice_Book(invoice);
                Console.WriteLine("Booked current invoice and booked invoice no is: {0}", bookedInvoiceHandle.Number);
                var bookedInvoiceData = session.Invoice_GetData(bookedInvoiceHandle);
                Console.WriteLine("The remainder is: {0}", bookedInvoiceData.Remainder);
 
                var someCashBook = session.CashBook_GetAll().First();
                Console.WriteLine("Fetching some cashbook: {0}", someCashBook.Number);
                session.CashBook_DeleteAllEntries(someCashBook);
                Console.WriteLine("Emptying cash book: {0}", someCashBook.Number);
 
                
                var someAccount = session.Account_GetDataArray(session.Account_GetAll()).First(p => p.Type == AccountType.ProfitAndLoss && p.IsAccessible);
 
                var entryData = new CashBookEntryData
                    {
                        CashBookHandle = someCashBook,
                        Type = CashBookEntryType.DebtorPayment,
                        ContraAccountHandle = someAccount.Handle,
                        Amount = -10,
                        DebtorInvoiceNumber = bookedInvoiceHandle.Number,
                        DebtorHandle = someDebtor,
                        Date = DateTime.Now,
                        CurrencyHandle = someCurrency
                    };
 
                session.CashBookEntry_CreateFromData(entryData);
                Console.WriteLine("Paying {0} {1} on invoice no: {2}", entryData.Amount, entryData.CurrencyHandle.Code, entryData.DebtorInvoiceNumber);
                session.CashBook_Book(someCashBook);
 
                var invoiceAfterPayment = session.Invoice_GetData(bookedInvoiceHandle);
                Console.WriteLine("On invoice #{0} there's now a remainder of {1}", invoiceAfterPayment.Handle.Number, invoiceAfterPayment.Remainder);
            }
        }
answered Oct 15, 2014 by mortenanders
Visma e-conomic A/S
...