Jump to content
akust0m

Conditional language overrides

Recommended Posts

Posted (edited)

Hi there!

It's required in Australia if GST is charged to have the wording 'Tax Invoice' instead of just 'Invoice'.

We achieve this with a language override in the file 'lang/overrides/english.php'.

$_LANG["invoicenumber"] = "Tax Invoice #";
$_LANG['invoicefilename'] = "Tax-Invoice-";

However, we have some overseas clients that we don't charge GST to. These customers have the 'Exempt from Tax' option set to 'Yes' in their account.

Is there a way to ensure that those that are exempt from tax have the wording 'Invoice' but those that are not exempt from tax have the wording 'Tax Invoice'?

Thanks!

Edited by akust0m

Share this post


Link to post
Share on other sites

Hey @akust0m Out of the box I cant think of a way to do this, the only thing I can suggest is possibly a hook but that wouldn't help with the pdf

I'll move this to the Developer Board where someone might be abole to provide a creative solution

Share this post


Link to post
Share on other sites
8 hours ago, akust0m said:

Is there a way to ensure that those that are exempt from tax have the wording 'Invoice' but those that are not exempt from tax have the wording 'Tax Invoice'?

where exactly are you trying to do this? the language string 'invoicenumber' isn't used in the invoice templates (pdf or html) by default, though is used at the complete stage after ordering.

8 hours ago, akust0m said:

Is there a way to ensure that those that are exempt from tax have the wording 'Invoice' but those that are not exempt from tax have the wording 'Tax Invoice'? 

you'd be able to access the $clientsdetails array (either at complete or when they're viewing an invoice) and that will contain their tax exempt status (1 for yes, 0 for no) and that could be used for your conditional, e.g if 1, then you strip 'Tax ' from the string, or use a different string entirely... that could be achieved in the templates or using a hook.

altering the filename could be trickier and would certainly require a hook, but does the actual filename matter for tax purposes ?

Share this post


Link to post
Share on other sites
Posted (edited)

Hi @brian!, thank you for your reply.

We have the term 'Tax Invoice' currently set when viewing an invoice in HTML and PDF. This is also reflected in the PDF filename as well.

This was achieved using the following language overrides in 'lang/overrides/english.php':

$_LANG["invoicenumber"] = "Tax Invoice #";
$_LANG['invoicefilename'] = "Tax-Invoice-";

The filename doesn't matter so much, but we'd like to have just 'Invoice' for tax exempt customers for HTML and PDF invoice copies.

Can an 'if' statement be used directly in the language overrides file to check if their tax exempt status is 1 or 0? So, if not exempt, then apply what we have above.

Edited by akust0m

Share this post


Link to post
Share on other sites
9 hours ago, akust0m said:

Can an 'if' statement be used directly in the language overrides file to check if their tax exempt status is 1 or 0? So, if not exempt, then apply what we have above.

no - you'd get errors if you try to add an if statement as you describe into the language files... don't do it! ⚠️

9 hours ago, akust0m said:

We have the term 'Tax Invoice' currently set when viewing an invoice in HTML and PDF. This is also reflected in the PDF filename as well. 

if we take the PDF as an example, in invoicepdf.tpl you might have changed...

$pdf->Cell(0, 8, $pagetitle, 0, 1, 'L', '1');

to...

$pdf->Cell(0, 8, Lang::trans('invoicenumber'), 0, 1, 'L', '1');

what I might have been tempted to do instead would be to have two different language override strings - i'd have kept invoicenumber as it is by default (so delete your override), but created a new string for tax exempt customers...

$_LANG["invoicenumber"] = "Invoice #";
$_LANG["taxinvoicenumber"] = "Tax Invoice #";

and then in invoicepdf.tpl, added the logic in there as to which string to use...

if ($clientsdetails["taxexempt"] == "1") {
	$invoicenumber = Lang::trans('taxinvoicenumber').$invoicenum;
} else {
	$invoicenumber = Lang::trans('invoicenumber').$invoicenum;
}
$pdf->Cell(0, 8, $invoicenumber, 0, 1, 'L', '1');

with regards to viewinvoice.tpl, then one option would have been an action hook to modify $pagetitle, but seeing as you've already edited the template to add this new language string, you could do this instead...

{if $clientsdetails.taxexempt eq '1'}{$LANG.taxinvoicenumber}{else}{$LANG.invoicenumber}{/if}{$invoicenum}

which is basically the Smarty equivalent code of what i've done in the PDF template.

as I explained previously, if your site only uses one language, then you could employ alternate methods to do this, but if your site uses multiple languages, then the above solution should work consistently for you. 🙂

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated