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
    Posts
  • #16937

    psycho0verload
    Participant

    Hi,

    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.

    Thanks

    #16938

    psycho0verload
    Participant

    After learning how to use

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

    #20372

    superkaybee
    Participant

    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!

    #20394

    julianengel
    Participant

    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?

    #20396

    psycho0verload
    Participant

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

    #20399

    julianengel
    Participant

    Thank you! I’ll check it out!

    #22853

    dennker
    Participant

    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.

    #22880

    dennker
    Participant

    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.

    #22883

    cocacoola
    Participant

    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.

    #22989

    cocacoola
    Participant

    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?

    #23031

    dennker
    Participant

    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

            data.push([{
                        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..

    Greetings
    dennker

    • This reply was modified 1 month ago by  dennker.
    #23048

    Hillel Coren
    Keymaster

    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.

    #23157

    psycho0verload
    Participant

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

    #23163

    psycho0verload
    Participant

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

    #23164

    Hillel Coren
    Keymaster
    #23165

    psycho0verload
    Participant

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

    #23166

    Hillel Coren
    Keymaster

    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?

    #23167

    cocacoola
    Participant

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

    bower -v
    1.8.8
    gulp -v
    CLI version: 2.2.0
    Local version: 4.0.2
    node -v
    v10.18.0

    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
    #23169

    psycho0verload
    Participant

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

    #23170

    psycho0verload
    Participant

    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

    #23180

    Hillel Coren
    Keymaster

    Awesome, glad to hear it!

    #23191

    psycho0verload
    Participant

    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
    #23194

    Hillel Coren
    Keymaster

    Thanks for sharing!

    #23264

    cocacoola
    Participant

    Hey,

    as promised i prepared a report to provide the tax VAT amount from expenses and invoices.
    The report was implemented in the following branch
    https://github.com/roterBulle/invoiceninja/tree/taxAmountreport

    #23265

    Hillel Coren
    Keymaster

    Nice! 🙂

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

You must be logged in to reply to this topic.

Posted in: