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

Want to create an invoice?

0
No matter what kind of integration you want to build to e-conomic, chances are that you need a mechanism for creating invoices. To help you with that, we've created a simple code example that allows you to do the following:

?    Create invoice
?    Add invoice lines
?    Book invoice
?    Get invoice PDF

This is what the code looks like (in .NET/C#):

[color=#0000FF:2l32mzok]private void[/color:2l32mzok] InvoiceTest()
{
                         [color=#00BF40:2l32mzok]// Create current invoice[/color:2l32mzok]
                         [color=#80BFFF:2l32mzok]IDebtor[/color:2l32mzok] debtor = session.Debtor.FindByNumber([color=#BF4040:2l32mzok]1[/color:2l32mzok]);
                         [color=#80BFFF:2l32mzok]ICurrentInvoice[/color:2l32mzok] cinv = session.CurrentInvoice.Create(debtor);
                         cinv.Heading = [color=#BF4040:2l32mzok]Test invoice[/color:2l32mzok];

                         [color=#00BF40:2l32mzok]// Add first line[/color:2l32mzok]
                         [color=#80BFFF:2l32mzok]IProduct[/color:2l32mzok] prod1 = session.Product.FindByNumber([color=#BF4040:2l32mzok]101[/color:2l32mzok]);
                         [color=#80BFFF:2l32mzok]ICurrentInvoiceLine[/color:2l32mzok] line1 = session.CurrentInvoiceLine.Create(cinv);
                         line1.Product = prod1;
                         line1.Description = prod1.Name;
                         line1.Quantity = 2.0m;
                         line1.UnitNetPrice = prod1.SalesPrice;

                         [color=#00BF40:2l32mzok]// Add second line
[/color:2l32mzok]                         [color=#80BFFF:2l32mzok]IProduct[/color:2l32mzok] prod2 = session.Product.FindByNumber([color=#BF4040:2l32mzok]102[/color:2l32mzok]);
                         [color=#80BFFF:2l32mzok]ICurrentInvoiceLine[/color:2l32mzok] line2 = session.CurrentInvoiceLine.Create(cinv);
                         line2.Product = prod2;
                         line2.Description = prod2.Name;
                         line2.Quantity = 1.0m;
                         line2.UnitNetPrice = prod2.SalesPrice;

                         [color=#00BF40:2l32mzok]// Book invoice[/color:2l32mzok]
                         [color=#80BFFF:2l32mzok]IInvoice[/color:2l32mzok] inv = cinv.Book();

                         [color=#00BF40:2l32mzok]// Retrieve PDF[/color:2l32mzok]
                         [color=#0000FF:2l32mzok]byte[/color:2l32mzok][] pdfData = inv.GetPdf();

                         [color=#00BF40:2l32mzok]// save PDF[/color:2l32mzok]
                         [color=#0000FF:2l32mzok]string[/color:2l32mzok] fileName = [color=#BF4040:2l32mzok]@d:\invoice_[/color:2l32mzok] + inv.Number.ToString() + [color=#BF4040:2l32mzok].pdf[/color:2l32mzok];
                         [color=#0000FF:2l32mzok]int[/color:2l32mzok] length = pdfData.Length;
                         [color=#0000FF:2l32mzok]using[/color:2l32mzok] (System.IO.[color=#80BFFF:2l32mzok]FileStream[/color:2l32mzok] stream = [color=#0000FF:2l32mzok]new[/color:2l32mzok] System.IO.[color=#80BFFF:2l32mzok]FileStream[/color:2l32mzok](fileName, System.IO.[color=#80BFFF:2l32mzok]FileMode[/color:2l32mzok].Create))
                         {
                                     stream.Write(pdfData, 0, length);
                         }
            }

Note that this code only works if you have set up customers, products and sales prices. Also, error handling has not been incorporated into this example.
created Jun 8, 2011 by Michael Hammer
0% Accept Rate
Q 6 A 2 C 0

Visma e-conomic A/S
...