Jump to content

Make Unpaid Invoices sticky


ST4R

Recommended Posts

Hi.

 

I want to make Unpaid Invoices's Panel sticky, in other words, I want to change its conditions for display to "always display" instead of "At least one unpaid". So it must show even if there's no unpaid invoices.

 

Also if there's no unpaid invoices, it should return "There's no unpaid invoice, Thanks".

 

Please help me.

Link to comment
Share on other sites

I want to make Unpaid Invoices's Panel sticky, in other words, I want to change its conditions for display to "always display" instead of "At least one unpaid". So it must show even if there's no unpaid invoices.

Also if there's no unpaid invoices, it should return "There's no unpaid invoice, Thanks".

quick answer is that you can't make it sticky - because you can't edit the conditions under which the panel is shown.

 

therefore, I suspect your only realistic option would be to delete the panel (using an action hook) and recreate it again with your own conditions (e.g always shown).

 

recreating the panel could be done in one of two ways - either via an action hook (query the database or using the API to determine if there are unpaid invoices, their number and values), or potentially in the template... doing it in the template would be complicated, but you should already have access to the variables you require to do this.

 

however, of the two methods, the better way would be the action hook. :idea:

 

https://docs.whmcs.com/Working_With_Client_Area_Home_Page_Panels

Link to comment
Share on other sites

Yes, I got same idea. I'd rather go with the action hook :)

 

I've read your mentioned article. To recreate it, how can I define the conditions? (If there are unpaid invoices show them as regular ELSE return "There's no unpaid invoice, Thanks")

Link to comment
Share on other sites

I don't mean the Panel Conditions for display!

 

How can I do the following for a new Panel?

IF there are unpaid invoices show the number of unpaid invoices and the total amount (Ex: You have $number unpaid invoices. please pay $total_amount) ELSE return "There's no unpaid invoice"

 

Can you please help me with that? I'm not a seasoned programmer.

Link to comment
Share on other sites

when you say help, you mean you want me to write it for you? :roll:

 

well just this once as the variables already exist...

 

<?php

use WHMCS\View\Menu\Item as Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
   GLOBAL $smarty;
   $numunpaidinvoices = $smarty->getVariable('clientsstats')->value['numunpaidinvoices'];
   $unpaidinvoicesamount = $smarty->getVariable('clientsstats')->value['unpaidinvoicesamount'];
   $numoverdueinvoices = $smarty->getVariable('clientsstats')->value['numoverdueinvoices'];
   $overdueinvoicesbalance = $smarty->getVariable('clientsstats')->value['overdueinvoicesbalance'];
   if ($numunpaidinvoices > 0) {
       $bodyhtml = '<p>You have '.$numunpaidinvoices.' unpaid invoice(s) with a total balance due of '.$unpaidinvoicesamount.'</p>';
   }
   elseif ($numoverdueinvoices > 0) {
       $bodyhtml = '<p>You have '.$numoverdueinvoices.' overdue invoice(s) with a total balance due of '.$overdueinvoicesbalance.' - Pay them now to avoid any interruptions in service.</p>';
   }
   else {
       $bodyhtml = '<p>You have no unpaid or overdue invoices!</p>';
   }
   $creditPanel = $homePagePanels->addChild( 'Invoices', array(
           'label' => Lang::trans('invoices'),
           'icon' => 'fa-money',
           'extras' => array(
               'color' => 'red',
               'btn-link' => 'clientarea.php?action=invoices',
               'btn-text' => Lang::trans('viewAll'),
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml
           ));

});

you'll still need to remove the default panel with a hook, but you can do that via code in the documentation or code i've previously posted.

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