Jump to content

bugs in latest version


Recommended Posts

Hi,

I am just sharing you my experiences that is found by me. 

After change my new Billing address with  new Tax no, all existing paid/ unpaid invoices are showing new address with new Tax no. That is major bugs. All existing paid invoices should be  unchanged.  Just like the Client information.   

 

Link to comment
Share on other sites

That's not a bug but how WHMCS works. Your company details on invoices come "live" from database. Changing the address will result in changes on all the issued proformas and invoices. Here is how you can solve your problem. First off use this hook point to override Company Details from viewinvoice.tpl depending on dates. The script is commented. Change it to match your needs.

<?php

use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaPageViewInvoice', 1, function($vars)
{
    $InvoiceDate = Capsule::table('tblinvoices')->where('id', $vars['invoiceid'])->value('date');

    if ($InvoiceDate <= '2016-12-31')
    {
        // Company Details for all invoices/proformas issued until 2016-12-31
        return array('payto' => 'Milan Ltd.<br>Address 100<br>Metropolis, MM<br>US');
    }
    elseif ($InvoiceDate <= '2017-12-31')
    {
        // Company Details for all invoices/proformas issued from 2017-01-01 to 2017-12-31
        return array('payto' => 'Juventus Ltd.<br>Address 200<br>Atlantis, AA<br>GR');
    }
    elseif ($InvoiceDate <= '2018-12-31')
    {
        // Company Details for all invoices/proformas issued from 2018-01-01 to 2018-12-31
        return array('payto' => 'Inter Ltd.<br>Address 300<br>Gotham City, GC<br>US');
    }

    // What happens in 2019, 2020, 2021 and so on? The default Pay To Text will be used (Setup > General Settings > General > Pay To Text)
});

Open templates/{YOUR_TEMPLATE}/invoicepdf.tpl and place the code provided below anywhere you want before this statement:

foreach ($companyaddress as $addressLine) {

Code:

# Conditional Company Details
if (date('Y-m-d', strtotime($datecreated)) <= '2016-12-31')
{
	$companyaddress[] = 'Milan Ltd.';
	$companyaddress[] = 'Address 100';
	$companyaddress[] = 'Metropolis, MM';
	$companyaddress[] = 'US';
}
elseif (date('Y-m-d', strtotime($datecreated)) <= '2017-12-31')
{
	$companyaddress[] = 'Juventus Ltd.';
	$companyaddress[] = 'Address 200';
	$companyaddress[] = 'Atlantis, AA';
	$companyaddress[] = 'GR';
}
elseif (date('Y-m-d', strtotime($datecreated)) <= '2018-12-31')
{
	$companyaddress[] = 'Inter Ltd.';
	$companyaddress[] = 'Address 300';
	$companyaddress[] = 'Gotham City, US';
	$companyaddress[] = 'US';
}

There are commercial addons that take a snapshot of your own company details  but they're expensive. No need to buy them for such a simple thing.

Edited by Kian
Link to comment
Share on other sites

44 minutes ago, Kian said:

There are commercial addons that take a snapshot of your own company details  but they're expensive. No need to buy them for such a simple thing.

i'd agree on that - there is a built-in feature called "Store Client Data Snapshot" that locks the client details to as they were when the invoice was first created - but it's only effectively for invoices created *after* you enable the feature, so it wouldn't help with your situation of dealing with existing invoices.

Link to comment
Share on other sites

4 minutes ago, brian! said:

i'd agree on that - there is a built-in feature called "Store Client Data Snapshot" that locks the client details to as they were when the invoice was first created - but it's only effectively for invoices created *after* you enable the feature, so it wouldn't help with your situation of dealing with existing invoices.

He can't do anything with Snapshots ☹️ The address of his own company has changed.

Link to comment
Share on other sites

Just now, Kian said:

He can't do anything with Snapshots ☹️ The address of his own company has changed.

aaahh my bad. 😎

that said, you will probably want to be careful when posting code like you did, cos users will blindly just copy & paste it, complain when it doesn't work, and then you'll have to spend longer replying with specific correct code (if you choose to) - welcome to life as a GearHead. ☺️

Link to comment
Share on other sites

2 hours ago, Kian said:

That's not a bug but how WHMCS works. Your company details on invoices come "live" from database. Changing the address will result in changes on all the issued proformas and invoices. You need to edit your invoicepdf.tpl, quotepdf.tpl, viewinvoice.tpl, viewquote.tpl and place your company details inside an if like follows (it's pseudo-code):


if (INVOICE_DATE <= REFERENCE_DATE)
{
    // My Company Ltd.
    // Old Address 555
    // Atlantia, AA
    // GR
}
else
{
    // My Company Ltd.
    // New Address 999
    // Metropolis, MM
    // US
}

There are commercial addons that take a snapshot of your own company details  but they're expensive. No need to buy them for such a simple thing.

Thanks for guide.

But It`s complicated .  On update , it is not good that all previous  paid invoices updation.  Store Client Data Snapshot - is  only for client data . This is known as bugs.

 

 

Link to comment
Share on other sites

22 minutes ago, webhostingpeople said:

But It`s complicated .

it's not really - granted, Kian hasn't given you the precise code for each template, but his suggestion is absolutely logical.

32 minutes ago, webhostingpeople said:

On update , it is not good that all previous  paid invoices updation.

if you mean that after every WHMCS update, you'll have to update the templates with these changes, then yes - I can see no simple way around that - although actually you could use an action hook for the html invoice/quote templates (and that might be preferable than editing those templates to avoid update issues), but certainly not for their PDF template equivalents as they don't use hooks.

as Kian says, all invoices are generated from the current values in the database, so if you change your company address today, and view an old invoice from last year, it will use the new address... that's definitely not a bug, it's how WHMCS has always worked... and probably will for the foreseeable future.

Link to comment
Share on other sites

2 hours ago, brian! said:

that said, you will probably want to be careful when posting code like you did, cos users will blindly just copy & paste it, complain when it doesn't work, and then you'll have to spend longer replying with specific correct code (if you choose to) - welcome to life as a GearHead. ☺️

True. Updated.

1 hour ago, webhostingpeople said:

But It`s complicated .  On update , it is not good that all previous  paid invoices updation.  Store Client Data Snapshot - is  only for client data . This is known as bugs.

Take a look here.

Link to comment
Share on other sites

5 hours ago, Kian said:

That's not a bug but how WHMCS works. Your company details on invoices come "live" from database. Changing the address will result in changes on all the issued proformas and invoices. Here is how you can solve your problem. First off use this hook point to override Company Details from viewinvoice.tpl depending on dates. The script is commented. Change it to match your needs.


<?php

use Illuminate\Database\Capsule\Manager as Capsule;

add_hook('ClientAreaPageViewInvoice', 1, function($vars)
{
    $InvoiceDate = Capsule::table('tblinvoices')->where('id', $vars['invoiceid'])->value('date');

    if ($InvoiceDate <= '2016-12-31')
    {
        // Company Details for all invoices/proformas issued until 2016-12-31
        return array('payto' => 'Milan Ltd.<br>Address 100<br>Metropolis, MM<br>US');
    }
    elseif ($InvoiceDate <= '2017-12-31')
    {
        // Company Details for all invoices/proformas issued from 2017-01-01 to 2017-12-31
        return array('payto' => 'Juventus Ltd.<br>Address 200<br>Atlantis, AA<br>GR');
    }
    elseif ($InvoiceDate <= '2018-12-31')
    {
        // Company Details for all invoices/proformas issued from 2018-01-01 to 2018-12-31
        return array('payto' => 'Inter Ltd.<br>Address 300<br>Gotham City, GC<br>US');
    }

    // What happens in 2019, 2020, 2021 and so on? The default Pay To Text will be used (Setup > General Settings > General > Pay To Text)
});

Open templates/{YOUR_TEMPLATE}/invoicepdf.tpl and place the code provided below anywhere you want before this statement:


foreach ($companyaddress as $addressLine) {

Code:


# Conditional Company Details
if (date('Y-m-d', strtotime($datecreated)) <= '2016-12-31')
{
	$companyaddress[] = 'Milan Ltd.';
	$companyaddress[] = 'Address 100';
	$companyaddress[] = 'Metropolis, MM';
	$companyaddress[] = 'US';
}
elseif (date('Y-m-d', strtotime($datecreated)) <= '2017-12-31')
{
	$companyaddress[] = 'Juventus Ltd.';
	$companyaddress[] = 'Address 200';
	$companyaddress[] = 'Atlantis, AA';
	$companyaddress[] = 'GR';
}
elseif (date('Y-m-d', strtotime($datecreated)) <= '2018-12-31')
{
	$companyaddress[] = 'Inter Ltd.';
	$companyaddress[] = 'Address 300';
	$companyaddress[] = 'Gotham City, US';
	$companyaddress[] = 'US';
}

There are commercial addons that take a snapshot of your own company details  but they're expensive. No need to buy them for such a simple thing.

Thanks for your effort but not perfect.

Link to comment
Share on other sites

2 minutes ago, brian! said:

what do you want it to do that it isn't doing ?

It  is using in invoicepdf.tpl  .  Everytime  maintain  invoicepdf.tpl  after updation whmcs. 

  Pay To Text  would be empty in Setup> General

Code  -  if (date('Y-m-d', strtotime($datecreated)) <= '2016-12-31')  is correct but what will be code   after the date  2016-12-31 ?

Link to comment
Share on other sites

14 minutes ago, webhostingpeople said:

It  is using in invoicepdf.tpl  .  Everytime  maintain  invoicepdf.tpl  after updation whmcs. 

That's why...

Before you begin customising it for your needs, the first step is to create your own copy of the template. This ensures your customisations are not lost when updating.

The complete article is here. Now given that you created your own copy of the template, you won't have any issue with updates of WHMCS.

14 minutes ago, webhostingpeople said:

  Pay To Text  would be empty in Setup> General 

Why? Here you just need to keep your company details up to date.

14 minutes ago, webhostingpeople said:

Code  -  if (date('Y-m-d', strtotime($datecreated)) <= '2016-12-31')  is correct but what will be code   after the date  2016-12-31 ? 

Did you read comments?

// Company Details for all invoices/proformas issued until 2016-12-31 --> MILAN LTD.
// Company Details for all invoices/proformas issued from 2017-01-01 to 2017-12-31 --> JUVENTUS.LTD
// Company Details for all invoices/proformas issued from 2018-01-01 to 2018-12-31 --> INTER LTD.
// The default Pay To Text will be used (Setup > General Settings > General > Pay To Text) for invoices/proformas issued from 2019-01-01

In other words in my example I was Milan in 2016, Juventus in 2017, Inter in 2018 and what you have in Pay To Text for 2019, 2020, 2021, 2022 etc.

Edited by Kian
Link to comment
Share on other sites

2 minutes ago, Kian said:

Now given that you created your own copy of the template, you won't have any issue with updates of WHMCS.

until WHMCS update their template with new variables/coding, and your custom template becomes outdated and bugged.

Link to comment
Share on other sites

  • 1 year later...

Thanks for the help! I'm in the same situation.

In invoicepdf.tpl I've added the code before the foreach, but no matter what I try it displayed both the set pay-to text address and after it the address from the condition.

I've also tried the following as my dev suggested:

# Conditional Company Details
if (date('Y-m-d', strtotime(str_replace('/', '-', $datecreated))) <= '2020-09-08')
{
	$companyaddress[] = '1';
	$companyaddress[] = '2';
	$companyaddress[] = '3';
	$companyaddress[] = '4';
	$companyaddress[] = '5';	
}
	

but no luck.. still shows both address one below the other.

 

Any idea? 

 

--

Regarding the hook for viewinvoice, I've managed to make it work but I had to tweak it to:

add_hook('ClientAreaPageViewInvoice', 1, function($vars)
{
    $invoice = Capsule::table('tblinvoices')->where('id', $vars['invoiceid'])->first();

    if ($invoice && $invoice->date <= '2020-09-08')
    {
        // Company Details for all invoices/proformas issued until 2016-12-31
        return array('payto' => 'company<br>details.');
    }
});

Just posting it here in case it would help someone in the future.. 

 

Link to comment
Share on other sites

On 9/9/2020 at 11:01 AM, Zenmaster said:

In invoicepdf.tpl I've added the code before the foreach, but no matter what I try it displayed both the set pay-to text address and after it the address from the condition.

If you add it before, the default pay-to-text always shows. It has to be and if/else statement...

if (date('Y-m-d', strtotime(str_replace('/', '-', $datecreated))) <= '2020-09-08')
{
	$companyaddress[] = '1';
	$companyaddress[] = '2';
	$companyaddress[] = '3';
	$companyaddress[] = '4';
	$companyaddress[] = '5';	
}
else
{
	// Default Pay to Text
}

p.s. If you want you can use invocie ID instead of date in your condition

Edited by Kian
Link to comment
Share on other sites

6 hours ago, Kian said:

If you add it before, the default pay-to-text always shows. It has to be and if/else statement...


if (date('Y-m-d', strtotime(str_replace('/', '-', $datecreated))) <= '2020-09-08')
{
	$companyaddress[] = '1';
	$companyaddress[] = '2';
	$companyaddress[] = '3';
	$companyaddress[] = '4';
	$companyaddress[] = '5';	
}
else
{
	// Default Pay to Text
}

p.s. If you want you can use invocie ID instead of date in your condition

 

I've put it above the "for each" because that's what I understood from what's posted in the thread.. 

I tried the if but it still shows the first the pay-to settings details and then the condition details... 

It's like it gets the details from the settings somewhere.. 

The code is:

 

# Company Details
$pdf->SetXY(15, 42);
$pdf->SetFont($pdfFont, '', 13);

if (date('Y-m-d', strtotime(str_replace('/', '-', $datecreated))) <= '2020-09-08')
{
	$companyaddress[] = 'Company details old';
	$companyaddress[] = '1';
	$companyaddress[] = '2';
	$companyaddress[] = '3';
	$companyaddress[] = '4';	
}
else
{
	$companyaddress[] = 'Company details new';
	$companyaddress[] = '1';
	$companyaddress[] = '2';
	$companyaddress[] = '3';
	$companyaddress[] = '4';	
}

foreach ($companyaddress as $addressLine) {
    $pdf->Cell(180, 4, trim($addressLine), 0, 1, 'R');
    $pdf->SetFont($pdfFont, '', 9);
}
$pdf->Ln(5);

 

 

Link to comment
Share on other sites

15 hours ago, Zenmaster said:

I tried the if but it still shows the first the pay-to settings details and then the condition details... 

for what it's worth, i'd suggest this...

if (date('Y-m-d', strtotime(str_replace('/', '-', $datecreated))) <= '2020-09-08')
{
	$companyaddress = array();
	$companyaddress[] = 'Company details old';
	$companyaddress[] = '1';
	$companyaddress[] = '2';
	$companyaddress[] = '3';
	$companyaddress[] = '4';	
}

that first line empties the array (I suppose you could unset the array instead, but shouldn't really be necessary in this case), and then the subsequent lines adds elements to the array containing the old address.

i've removed the else because it probably makes more sense to pull the new address from the Pay To value as per normal without additional coding... e.g only if the created date is before the one specified in the if statement, will it use the old address; for later invoices, it uses the current address.

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.

×
×
  • 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