How to print invoice-amount without taxes in twig-templates?

Hey guys,

I’m playing with the new templates. And it seems there’s no variable for the tax-less invoice-amount.

I tried to make a substraction, but this won’t work with the amount-variable. It seem’s it’s because it’s not just a number, even it’s declared as a number there: API-docs (look into the schematics at the bottom of this page)

Can you help?

Hi,

@david can you please advise?

invoice.amount - invoice.total_taxes

That’s what I did:

{{ invoice.amount - invoice.total_taxes }}

All I get is: “Something went wrong” (in German). :frowning:

@Schmitti

I think the correct syntax would be

{{ invoice.amount_raw - invoice.total_taxes_raw }}

These are the double values of the fields, the other ones, are the formatted strings.

Hi, @david,

I know, I already found that out. The problem is, that if I take the raw values I need a workaround for the right and variable formating of the currency.

For example: In Germany we write: “1.000,00 €”, but I heard that in Austria it’s like “€ 1.000,00” or USA “$1,000.00” or something.

At least it would be cool if we had the chance to use every important variable like totals with and without taxes and so on.

It’s really a little struggle to create fully customized templates. :-/

@Schmitti so this is certainly possible, using twigs format_currency() filter

ie.

{{ '1000000'|format_currency('EUR', locale='de') }}
{{ '1000000'|format_currency('EUR', locale='at') }}

Just to note, this will require php-intl extension to be installed. It also requires an update to the template variables so that we expose the locale, in this example the code would look like this:

{{ invoice.amount|format_currency(invoice.client.currency, locale=invoice.client.locale) }}

the locale variable will be available in 5.9.3

2 Likes

Hey @david!

Thanks a lot! Wow, this looks like a profession to learn. I would love to have the time to study and learn everything about it.

At this moment I have to thank you again for your valuable help and your enthusiasm you donate into this project!

Greets

Schmitti

1 Like

Hey, @david ,

after analysing your code I did a 'lil research and found out the right code for me:

{{ (invoice.amount_raw - invoice.total_taxes_raw)|format_currency(invoice.client.currency, locale=invoice.client.locale) }}

Thanks a lot!