Auto calculate total in invoice

Is it possible to make the total automatically calculated when entering the quantity and price of the product or service on the invoice, so that it is not necessary to press the SAVE button to calculate the total?

well, you need to do a little bit of Ajax during the entering of those prices.
So when you enter a price, there’s an ajax call that calculates the price for you and then returns it to the frontend.

Maybe a better way is to bind CTRL+S to the save button.
Something similar to this:

Instead of finding the ESC key, you need to find the CTRL and the S key.

But hey, maybe you’ll find the way to do that Ajax call.
Contributions are open, Pull-requests are welcome

In this app they find solution with js. You can see in invoice.php class calculate and in scripts.js code for calculation. If you know hoe to do it, maybe this can halp you and help us :smiley:
invoice.php (18.5 KB)
scripts.js.php (27.4 KB)

I renamed the js file to .php so I could attach it.

1 Like

Great, if you can implement it into InvoicePlane, just make a pull-request and I’ll take a look at it

Haha, that’s the point, I don’t know hit to do it :grin:

1 Like

Step 1 is to fork the github repository to your own “user space” within github.
Let’s say you did that, you’ll now have

Step 2 is to clone your own invoiceplane repository
git clone
you’re now in the development branch of invoiceplane. The point is to create a new branch and add your code.
git checkout -b feature/add-ajax-to-invoice-calculation (something like that)

You’re now in your own personal branch on your own personal repository. Whatever you’ll add you won’t break anything.

Step 3:
Add your code. The invoices module is located in /application/modules/invoices and the “Ajax Controller” is in /application/modules/invoices/controllers
That piece of javascript you posted will go to this controller, to a specific function

The views are located in /application/modules/invoices/views, that piece of javascript will go in 1 of these views

So … add javascript and adjust the example javascript to something that matches the page.
The “target” is a function within the “ajax controller”

You’ll find examples on this same view page, since the “save” button also executes an ajax action.

So for example: your javascript will go to a function “recalculate” within the AjaxController
Then make sure your javascript will target that function within that controller. Check all those examples on that page.

After that test your results.

If you’re happy with the results, just tell us and we’ll do the next steps.