Home Forums Support Add pre-tax variable to $subtotals at PDF Invoice

This topic contains 24 replies, has 6 voices, and was last updated by  Hillel Coren 6 days, 3 hours ago.

Viewing 25 posts - 1 through 25 (of 25 total)
  • Author
  • #16937



    inclusive taxes have been enabled in my System. I need to expand the $subtotals with the pre-tax amount respectively reduce the sub-total with the tax amount in $subtotals.

    I found something in resources/assets/js/pdf.pdfmake.js and added this:

    var netto = invoice.amount - invoice.tax_amount1;
        if (parseFloat(invoice.tax_rate1 || 0) != 0 || invoice.tax_name1) {
            data.push([{text: formatMoneyInvoice(netto, invoice)}]);

    But it doesn’t work.

    Please help me.




    After learning how to use

    gulp / bower / elexir I am able to create my variable!



    Hi psycho0verload, we are looking for this same feature, to have a pre-tax subtotal shown, especially when we include a discount. Would you be able to share how you implemented this on your system? I’m looking at the same code but unsure of how to apply my changes with the frameworks in use. Thanks!



    Ah yes. This is the same thing I just opened up a new issue about before seeing this. Would you be able to share how you managed to achieve this @psycho0verload?



    You can see my Variante at https://github.com/Cretection/invoiceninja



    Thank you! I’ll check it out!



    Hello psycho0verlord,

    i do have the exact same need for a netto variable. I replaced my code with the one from your git, but i can’t get it to work.
    Using $netto in a custom design just returns nothing and it’s also not added to $subtotals.

    How do i use it?

    Thank you very much for your efforts.



    20 hours of trial & error, no solution here. I set up another installation with just the custom code from Github. I displays “Netto: ” but the displayed value is just the negative of my inclusive tax amount!

    I guess the variable invoice.amount in “var netto = invoice.amount – invoice.tax_amount1 – invoice.tax_amount2;” is zero so it becomes negative?

    Also pdf.pdfmake.js doesn’t seem to change anything, it’s all in built.js? /update or ?clear_cache don’t seem to start the build..

    Is there anybody able to help me? I’m offering some bucks via PayPal for a working solution.



    Hi dennker,

    i have the same requirement as i need to create an invoice which is correct according to german laws.
    I am also trying to develop a solution but don’t have that much time to try.
    What i found out is, as per my opinion the files in resources are not the files which are used in the output.

    Invoice Ninja seems to be build using gulp.js which is placing the files into the public folder.

    In gulpfile.js in the root folder of the project, you can see which files are placed where.
    So if you need to change the pdfmake.js you can either change the source file (in /resources/assets/js/) and rebuild the app using gulp afterwards OR you try to make the change in the output file mentioned in the gulp.js file ( i think it is /public/built.js ).

    If i have a solution i will provide it here, currently i am struggeling in setting up the development environment.

    It would be really nice if you share your solution once you got one.



    Hi dennker,

    i created a working solution. And actually i did what @psycho0verload suggested but changed the row where put it in and also i don’t use the invoice.amount but the invoice.subtotal_amount.
    Before i had the problem that the calculation was only working after second refresh/saving of the invoice.

    Did you find another solution?



    Hi cocacoola,

    yep, i managed to develop a working solution. At first i fixed psycho0verload’s code, guess just like you did, but on invoices with more than 1 page it just went blank or threw some other errors. Maybe you can check?

    I then went for a more ‘raw’ approach and changed the built.js directly. As calulations weren’t possible with the normal variables i parsed them and made my own.. Then just style them like formatMoneyInvoice normally does.

    		var total_float = parseFloat(invoice.subtotal_amount).toFixed(2);
    		var tax_float = parseFloat(invoice.tax_amount1).toFixed(2);
    		var true_netto = (total_float - tax_float).toFixed(2).replace(".", ",");
    		true_netto += " €";

    Display with

                        text: "Netto",
                        style: ["subtotalsLabel", "tax1Label"]
                    }, {
                        text: true_netto,
                        style: ["subtotals", "tax1"]

    Using subtotal_amount works indeed well without any refresh or having the invoice amount change upon payment.
    I also removed any other unnessecary code from the whole subtotals function, so just Netto, Tax and Brutto.

    Text me when you need any help with getting it running, i spend some good amount of time figuring it out.
    Invoice Ninja is great, but has a few but severe flaws for european users..


    • This reply was modified 1 month ago by  dennker.

    Hillel Coren

    Nice, thanks for sharing the fix!

    Yeah… the app was mostly built by Americans, invoicing is much simpler in the US. We’re trying to take the lessons learned and do better in v2.



    Thanks for this fix.
    My Version was a fix dirty fix for my Situation. I will try it, too 🙂



    Currently I cannot get the development environment to work. Does anyone have a short guide on how I can build a development environment again?


    Hillel Coren


    œHillel Coren
    Which Version of NodeJS, Gulp and Bower do you use for your environment?


    Hillel Coren

    I don’t have the versions available, I mostly code in Dart/Flutter now.

    Any recent versions should work, are you seeing a specific error?



    i also had issues setting up the environment. Got it running with:

    bower -v
    gulp -v
    CLI version: 2.2.0
    Local version: 4.0.2
    node -v

    I am currently also developing a tax report which also takes expenses into account.
    Once done i will put it in my github repo and provide the link here. Also the other changes i will provide there.

    • This reply was modified 2 weeks, 3 days ago by  cocacoola. Reason: added info about development


    On macOS Catalina it my environment not working. I will try it on another machine



    Get my environment on macOS Catalina now with:

    brew doctor
    brew install node
    brew install [email protected]
    brew unlink node
    brew link [email protected]
    brew link –force [email protected]
    brew link –overwrite [email protected]
    brew link –overwrite –force [email protected]
    npm install -g bower
    npm install gulp-cli -g
    npm install gulp -D

    now gulp watch is working


    Hillel Coren

    Awesome, glad to hear it!



    I want to share my new solution with you. I will put this solution on GitHub (link from above – Branch: Casa-v4. 5. 17)

    It is my solution for the application in Germany (I use it for a guesthouse) and the option Inclusive taxes have to enabled.

    Rename subtotal to Netto

    Works and tested with:
    – Enable specifying an invoice tax
    – Enable specifying line item taxes

    Not tested or not intended:
    – Enable specifying a second tax rate
    – Include line item taxes in line total

    My changes to “NINJA.subtotals = function(invoice, hideBalance)” in “resources/assets/js/pdf.pdfmake.js” after

        var account = invoice.account;
        var data = [];
        // SECTION Netto-Betrag: Rechnung und Ausgabe
        // NOTE Zwischensumme: deaktivieren
        // data.push([{text: invoiceLabels.subtotal, style: ['subtotalsLabel', 'subtotalLabel']}, {text: formatMoneyInvoice(invoice.subtotal_amount, invoice), style: ['subtotals', 'subtotal']}]);
        // NOTE Netto-Betrag: variable Definieren
        var pretax_amount = invoice.subtotal_amount;
        // SECTION Rabatt: Ausgabe & Abzug von Netto-Betrag   
        if (invoice.discount_amount != 0) {
            // NOTE Rabatt vom Netto-Betrag abziehen
            pretax_amount -= invoice.discount_amount;
            data.push([{text: invoiceLabels.discount , style: ['subtotalsLabel', 'discountLabel']}, {text: formatMoneyInvoice(invoice.discount_amount, invoice), style: ['subtotals', 'discount']}]);
        // !SECTION
        // SECTION Artikel-Steuer: Abzug von Netto-Betrag
        for (var key in invoice.item_taxes) {
            if (invoice.item_taxes.hasOwnProperty(key)) {
                var taxRate = invoice.item_taxes[key];
                pretax_amount -= taxRate.amount;
        // !SECTION
        // SECTION Rechnungssteuer: Abzug vom Netto-Betrag
        if (parseFloat(invoice.tax_rate1 || 0) != 0 || invoice.tax_name1) {
            pretax_amount -= invoice.tax_amount1;
        if (parseFloat(invoice.tax_rate2 || 0) != 0 || invoice.tax_name2) {
            pretax_amount -= invoice.tax_amount2;
        // !SECTION
        // NOTE Ausgabe des echten Netto-Betrags als Zwischensumme
        data.push([{text: invoiceLabels.subtotal, style: ['subtotalsLabel', 'subtotalLabel']}, {text: formatMoneyInvoice(pretax_amount, invoice), style: ['subtotals', 'subtotal']}]);
        // !SECTION
    • This reply was modified 2 weeks ago by  psycho0verload. Reason: Place of change specified in more detail

    Hillel Coren

    Thanks for sharing!




    as promised i prepared a report to provide the tax VAT amount from expenses and invoices.
    The report was implemented in the following branch


    Hillel Coren

    Nice! 🙂

Viewing 25 posts - 1 through 25 (of 25 total)

You must be logged in to reply to this topic.

Posted in: