Create and send invoice from external app

I want to use invoiceplane by an external (asp) application.

As far as I can see I can simply create a customer by adding a row to the mysql table.

What’s the best way to create an Invoice? There is an ajax function, but Items aren’t added as far as I can see.

Of course I can also create the rows in the tables via mysql query. But how can I create the PDF, Invoice number, and send the mail? I can’t find the code.

The code for invoices is distributed into multiple files, functions and helpers. For example is you send an invoice this is done by the mailer module.
But there are some urls you can use for some actions. PDFs are generated by http://yourdomain.com/quotes/generate_pdf/9 which opens the generated PDF of the quote with the id 9 in the browser window.

Let’s say I added the rows to the invoice tables. Can I just send the mail with pdf by http post calling:

/mailer/send_invoice/13

with form data

  btn_send:1
to_email:info@mymail.de
email_template:1
etc...

Will the pdf and guest-url be created then? Do I need to login first and save the cookies?

I digged a bit deeper into the code:

I think the easiest way would be setting all values (including guest_url and invoice ID) via mysql queries and then generating the PDF via: http://invoice.myurl.de/guest/view/generate_invoice_pdf/mygeneratedguest_url
After that I can send the mail by myself and nothing will be overwritten when user open guest url.

I am looking to do something similar.
Trying to create a invoice based on information sent to a PHP file.

Would you mind sharing the mysql queries you used on creating the invoice and client ?

There are no single MySQL queries that create an invoice. You have to pass the needed information to the app as some calculations and inserts are handled by IP itself.

I would not recommend adding invoices manually with simple SQL…

Then how would one add invoices from an outside source?
Or automatically import them?
For instances orders are made on my website, I would like to sent those people a quote on what they ordered.

InvoicePlane saves Invoices by using various functions and methods. You should check the Ajax methods in the Main menu that creates a new invoice and the method that saves the invoice.

At this point I really can’t support you with this.

Just look what is created in the database.

The database scheme isn’t that complex. Some of my c# code:

    // add invoice 
    MySqlCommand comm = conn.CreateCommand();
    comm.CommandText = "INSERT INTO ip_invoices";
    comm.Parameters.AddWithValue("@user_id", "1");
    comm.Parameters.AddWithValue("@client_id", clientID);
    comm.Parameters.AddWithValue("@invoice_group_id", "2");
    comm.Parameters.AddWithValue("@invoice_status_id", "2");
    comm.Parameters.AddWithValue("@invoice_date_created", DateTime.Now.ToString("yyyy-MM-dd"));
    comm.Parameters.AddWithValue("@invoice_date_modified", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
    comm.Parameters.AddWithValue("@invoice_date_due", DateTime.Now.ToString("yyyy-MM-dd"));
    comm.Parameters.AddWithValue("@invoice_number", "MYNUMBER");
    comm.Parameters.AddWithValue("@invoice_url_key", "f6d42fddb8c5094054e9a7021c97357e");
    comm.ExecuteNonQuery();

    long invoice_id = comm.LastInsertedId;

    // invoice group next id setzen  MySqlCommand comm = conn.CreateCommand();
    MySqlCommand cmd2 = conn.CreateCommand(); invoiceNr++;
    cmd2.CommandText = "UPDATE ip_invoice_groups SET invoice_group_next_id='" + invoiceNr + "' WHERE name='John Smith'"; ;
    cmd2.ExecuteNonQuery();

    // invoice item und amount hinzufügen
    MySqlCommand comm2 = conn.CreateCommand();
    comm2.CommandText = "INSERT INTO ip_invoice_items";
    comm2.Parameters.AddWithValue("@invoice_id", "1");
    comm2.Parameters.AddWithValue("@item_tax_rate_id", clientID);
    comm2.Parameters.AddWithValue("@invoice_group_id", "2");
    comm2.Parameters.AddWithValue("@item_date_added", "2");
    comm2.Parameters.AddWithValue("@item_name", "2015-03-02");
    comm2.Parameters.AddWithValue("@item_description", "2015-03-02");
    comm2.Parameters.AddWithValue("@item_quantity", "2015-03-02 17:08:03");
    comm2.Parameters.AddWithValue("@item_price", "EOE201503011");
    comm2.Parameters.AddWithValue("@item_order", "0");
    comm2.ExecuteNonQuery();

    comm2.CommandText = "INSERT INTO ip_invoice_amounts";
    comm2.Parameters.AddWithValue("@invoice_id", "1");
    comm2.Parameters.AddWithValue("@invoice_item_subtotal", clientID);
    comm2.Parameters.AddWithValue("@invoice_item_tax_total", "2");
    comm2.Parameters.AddWithValue("@invoice_tax_total", "2");
    comm2.Parameters.AddWithValue("@invoice_total", "2015-03-02");
    comm2.Parameters.AddWithValue("@invoice_paid", "2015-03-02");
    comm2.Parameters.AddWithValue("@invoice_balance", "2015-03-02 17:08:03");
    comm2.ExecuteNonQuery();
    conn.Close();

Would have been ideal really if bulk upload of Invoices is possible from a csv file for example or through an API integration wit InvoicePlane.

BTW: you can use the import function of InvoicePlane: https://wiki.invoiceplane.com/en/1.0/system/importing-data

Yea aware of this function though a bit cumbersome because one needs to place the file in the uploads folder before it can be imported into the application. Allowing a direct file location on one’s computer system would be great.

However, what ikbennino wants is one through which an invoice can be generated on submission of an application for service (for example) through a service provider’s platform.

This means, a customer requests service, submits an application and that process triggers an information exchange between the platform and InvoicePlane leading to generation of an invoice dispatched to the customer.

Hi @bigtt

What you describe here requires the implementation of an full API to work properly in a general way. I don’t know if this Feature is planned for the future i.e InvoicePlane v2. But of course this is a nice additional Feature, but irrelevant for the most users.

Maybe it is easier to program a small api that only generates pdf and send them to customers. Because all required data will be send by the third Party application anyway…

Best regards
Patrick

Hi Kovah. I could not find any documentation for the Ajax methods. I was trying to use the https://demo.invoiceplane.com and there was no reference of ajax method in the Main Menu. Can you please redirect me to the right place. Thank you.

There is no centralized documentation about the ajax methods InvoicePlane uses. Please check the Ajax controllers for every module.