Jump to content

This code works in any php file but don't in viewinvoice.tpl


honesting

Recommended Posts

I come to the forum as WHMCS told me that it's not possible to change the name of my business for the invoices, but after a few lines I did it for invoicepdf.tpl but the same code don't work with viewinvoice.tpl. I think this it's an WHMCS problem and also a miss in a basic funtion but anyway, my question it's, why this code don't work at viewinvoice.tpl and it works in any other php file?

 

My company had NAME_2014 last year and this we moved to NAME_2015 so I search for 2015 in the $datepaid variable to see if it's present:

 

{php}
if (strpos($datepaid, "2015") !== false) { 
echo "NAME_2015";
} else {
echo "NAME_2014";
}
{/php}


if (strpos($datepaid, "2015") !== false) { 
$pdf->Cell(160,6,trim($NAME_2015[0]),0,1,'R');
} else {
$pdf->Cell(160,6,trim($NAME_2014),0,1,'R');	
}

 

 

I also add this feature request, if you think it will be useful, please vote:

Fixed Invoice Data for company name | WHMCS Feature Requests https://requests.whmcs.com/responses/fixed-invoice-data-for-company-name

Edited by honesting
Link to comment
Share on other sites

I come to the forum as WHMCS told me that it's not possible to change the name of my business for the invoices, but after a few lines I did it for invoicepdf.tpl but the same code don't work with viewinvoice.tpl. I think this it's an WHMCS problem and also a miss in a basic funtion but anyway, my question it's, why this code don't work at viewinvoice.tpl and it works in any other php file?

this will be because the templates use Smarty - http://docs.whmcs.com/Template_Syntax - you can easily do what you want to do, you just need to slightly modify your code for Smarty...

 

in the default/viewinvoice.tpl, the company name is shown using...

 

{if $logo}<p><img src="{$logo}" title="{$companyname}" /></p>{else}<h1>{$companyname}</h1>{/if}

you might want to change that to something along the lines of...

 

{if $datepaid|strpos:"2015" !== false OR $datepaid|strpos:$date_year !== false}{if $logo}<p><img src="{$logo}" title="{$companyname}" /></p>{else}<h1>{$companyname}</h1>{/if}{else}{if $logo}<p><img src="{$logo}" title="NAME_2014" /></p>{else}<h1>NAME_2014</h1>{/if}{/if}

this is slightly different to your invoicepdf code in that it checks to see if the $datepaid variable contains "2015" or the current year ($date_year) - so it should continue to work correctly in 2016, 2017 etc...

 

when using your original code, when you get to 2016, it will use your 2014 company name rather than the current one...

 

I would doubt you can automatically use $date_year in your invoicepdf.tpl code, so you might need to create the variable to store the current year and then add it to your IF code to check for future years.

Link to comment
Share on other sites

Thank yo brian for your help. I did it as you told me using the smarty sintax and it works exactly that it did in the invoicepdf.tpl. When I put the ifs between {} it started working. I'm also thinking about a better implementation for the next years, perhaps WHMCS do anything about this ¿?

 

Thank you again!

Link to comment
Share on other sites

one further thought on this - the above code won't work in the long-term...

 

e.g, if it was 2017 and you were looking at an invoice from 2016, it would use the 2014 address - which is not what you wanted.

 

from a logic point of view, it is probably easier to define the invoice year(s) that you want to use the 2014 address for (e.g 2014, 2013, 2012 etc) and then for years other than them, use the current 2015 address - that way you won't constantly have to add new years to the {if} statement each year.

 

once you've defined the years to use the 2014 address, you should never have to alter the code again.

 

btw - I wouldn't expect WHMCS to do anything to fix this when a solution can be so easily achieved by modifying the template(s).

Link to comment
Share on other sites

Thank you for your suggestion, I'll do it so I have the system working without any future change. Actually I'm using WHMCS for 7-8 years so I only have to add those.

 

However, I think this it's an importan fix/improvement for WHMCS as if not, they can offer multi-company or even change the street address for your company as this data it's taken on the fly. Data for invoices must be fixed every time it's send to the customer no matter what future data you change.

Link to comment
Share on other sites

However, I think this it's an importan fix/improvement for WHMCS as if not, they can offer multi-company or even change the street address for your company as this data it's taken on the fly. Data for invoices must be fixed every time it's send to the customer no matter what future data you change.

there are a couple of addons that may help your situation...

 

Fixed Invoice Data - https://www.whmcs.com/appstore/306/Fixed-Invoice-Data.html

 

a free addon from WHMCS - not sure if it still works with the latest version... seems to only store client details - so I don't know if it would handle a change in your company address...

 

M-Bit Cached Invoices Addon - http://forum.whmcs.com/showthread.php?95294-M-BIT-Cached-Invoices-Addon-Module-for-WHMCS

 

I think this addon, which is only a couple of months old so should work with the latest WHMCS release, will do what you want.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

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