Add pre-tax variable to $subtotals at PDF Invoice

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

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

        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

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 :slight_smile:

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

There’s a bit of info here:

https://invoice-ninja.readthedocs.io/en/latest/developer_guide.html#code

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

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
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.

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 node@10
brew unlink node
brew link node@10
brew link --force node@10
brew link --overwrite node@10
brew link --overwrite --force node@10
npm install -g bower
npm install gulp-cli -g
npm install gulp -D

now gulp watch is working