Jump to content

Adding a "Credit Balance" panel to the client area home page


karpstrucking

Recommended Posts

Found a thread detailing how to do this for a sidebar, but not a panel, so cobbled that together with the documentation examples:

 

use Carbon\Carbon;
use WHMCS\User\Client;
use Illuminate\Database\Capsule\Manager as Capsule;

add_hook( 'ClientAreaHomepagePanels', 1, function ( Item $homePagePanels ) {
$client = Menu::context( "client" );
$clientid = intval( $client->id );
if ( ( $clientid === 0 ) || ( $client->credit <= 0 ) ) return;
$getCurrency = Capsule::table( 'tblcurrencies' )->where( 'id', $client->currency )->get();
$creditPanel = $homePagePanels->addChild( 'Credit Balance', array(
	'label' => 'Available Credit Balance',
	'icon' => 'fa-usd',
	'extras' => array(
		'color' => 'green',
	),
	'bodyHtml' => '<p>You have a credit balance of ' . $getCurrency['0']->prefix . $client->credit . ' ' . $getCurrency['0']->suffix . ' and this will be automatically applied to any new invoices.</p>'
));
});

Link to comment
Share on other sites

Found a thread detailing how to do this for a sidebar, but not a panel, so cobbled that together with the documentation examples.

you can trim that code down, remove the need to query the database and make it multilingual by using the language files of the client instead of hard-coding it in English. :idea:

 

<?php

use WHMCS\View\Menu\Item as Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
   $client = Menu::context( "client" );
   $clientid = intval( $client->id );
   if ($client->credit > 0) {
       $currencyData = getCurrency($clientid);
       $bodyhtml = '<p>'.sprintf(Lang::trans('availcreditbaldesc'),formatCurrency($client->credit, $currencyData)).'</p>';
       $creditPanel = $homePagePanels->addChild( 'Credit Balance', array(
           'label' => Lang::trans('availcreditbal'),
           'icon' => 'fa-money',
           'extras' => array(
               'color' => 'red',
               'btn-link' => 'clientarea.php?action=addfunds',
               'btn-text' => Lang::trans('addfunds'),
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml
       ));
   }
});

GckODsj.pngPOnJ39q.png

Link to comment
Share on other sites

  • 4 weeks later...

Thanks for help, it's working for me. but if clients don't have balance then it's don't show :( i want to show if have to credit balance or don't have. always show that widget/sidebar, You can see this screenshot, this account don't have balance but still show that with 0 balance. b6c82f9.png

http://prnt.sc/edmf2o

 

How can i do that? can you help me please?

 

 

 

 

you can trim that code down, remove the need to query the database and make it multilingual by using the language files of the client instead of hard-coding it in English. :idea:

 

<?php

use WHMCS\View\Menu\Item as Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
   $client = Menu::context( "client" );
   $clientid = intval( $client->id );
   if ($client->credit > 0) {
       $currencyData = getCurrency($clientid);
       $bodyhtml = '<p>'.sprintf(Lang::trans('availcreditbaldesc'),formatCurrency($client->credit, $currencyData)).'</p>';
       $creditPanel = $homePagePanels->addChild( 'Credit Balance', array(
           'label' => Lang::trans('availcreditbal'),
           'icon' => 'fa-money',
           'extras' => array(
               'color' => 'red',
               'btn-link' => 'clientarea.php?action=addfunds',
               'btn-text' => Lang::trans('addfunds'),
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml
       ));
   }
});

GckODsj.pngPOnJ39q.png

Link to comment
Share on other sites

Thanks for help, it's working for me. but if clients don't have balance then it's don't show :( i want to show if have to credit balance or don't have. always show that widget/sidebar, You can see this screenshot, this account don't have balance but still show that with 0 balance. [ATTACH=CONFIG]13270[/ATTACH]

http://prnt.sc/edmf2o

 

How can i do that? can you help me please?

 

try this:

 

<?php 

use WHMCS\View\Menu\Item as Item; 

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) 
{ 
   $client = Menu::context( "client" ); 
   $clientid = intval( $client->id ); 
   $currencyData = getCurrency($clientid); 
   $bodyhtml = '<p>'.sprintf(Lang::trans('availcreditbaldesc'),formatCurrency($client->credit, $currencyData)).'</p>'; 
   $creditPanel = $homePagePanels->addChild( 'Credit Balance', array( 
           'label' => Lang::trans('availcreditbal'), 
           'icon' => 'fa-money', 
           'extras' => array( 
               'color' => 'red', 
               'btn-link' => 'clientarea.php?action=addfunds', 
               'btn-text' => Lang::trans('addfunds'), 
               'btn-icon' => 'fa-plus', 
           ), 
           'bodyHtml' => $bodyhtml 
   ));  
});

Link to comment
Share on other sites

  • 4 months later...

Hi all,

 

I used this code and I would like to know how i can change the order of the credits widget? I would like it to the third place.

 

<?php 

use WHMCS\View\Menu\Item as Item; 

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) 
{ 
   $client = Menu::context( "client" ); 
   $clientid = intval( $client->id ); 
   $currencyData = getCurrency($clientid); 
   $bodyhtml = '<p>'.sprintf(Lang::trans('availcreditbaldesc'),formatCurrency($client->credit, $currencyData)).'</p>'; 
   $creditPanel = $homePagePanels->addChild( 'Credit Balance', array( 
           'label' => Lang::trans('availcreditbal'), 
           'icon' => 'fa-money', 
           'extras' => array( 
               'color' => 'red', 
               'btn-link' => 'clientarea.php?action=addfunds', 
               'btn-text' => Lang::trans('addfunds'), 
               'btn-icon' => 'fa-plus', 
           ), 
           'bodyHtml' => $bodyhtml 
   ));  
});

Link to comment
Share on other sites

I used this code and I would like to know how i can change the order of the credits widget? I would like it to the third place.

you can't really specify a position with these homepage panels, the best you can do is to give the panel an order weighting that would put it roughly in the right place - the problem being that you don't know what other panels are going to be shown as most of them are only visible when triggered by a specific condition.

 

so the documentation tells you the order of the default panels is...

 

https://docs.whmcs.com/Working_With_Client_Area_Home_Page_Panels#Default_Panels

 

10 - Unpaid/Overdue Invoices *

50 - Domains Expiring Soon *

100 - Active Products/Services

150 - Recent Support Tickets

 

* the first two panels are conditional and will only be shown if the client has unpaid invoices or domains expiring...

 

under those circumstances, an order value of 99 would put it third... if the two conditions don't apply, then you'd need an order value of 151 to put the panel third... in other words, if you give it an order value of 101, it will either by 2nd/3rd/4th... that's also assuming you don't have any other custom homepage panels in play either! :)

 

<?php 

use WHMCS\View\Menu\Item as Item; 

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels) 
{ 
   $client = Menu::context( "client" ); 
   $clientid = intval( $client->id ); 
   $currencyData = getCurrency($clientid); 
   $bodyhtml = '<p>'.sprintf(Lang::trans('availcreditbaldesc'),formatCurrency($client->credit, $currencyData)).'</p>'; 
   $creditPanel = $homePagePanels->addChild( 'Credit Balance', array( 
           'label' => Lang::trans('availcreditbal'), 
           'icon' => 'fa-money', 
           'extras' => array( 
               'color' => 'red', 
               'btn-link' => 'clientarea.php?action=addfunds', 
               'btn-text' => Lang::trans('addfunds'), 
               'btn-icon' => 'fa-plus', 
           ), 
           'bodyHtml' => $bodyhtml,
           'order' => 101
   ));  
});

Link to comment
Share on other sites

  • 3 years later...
On 1/30/2017 at 12:02 PM, brian! said:

you can trim that code down, remove the need to query the database and make it multilingual by using the language files of the client instead of hard-coding it in English. :idea:

 

 


<?php

use WHMCS\View\Menu\Item as Item;

add_hook('ClientAreaHomepagePanels', 1, function (Item $homePagePanels)
{
   $client = Menu::context( "client" );
   $clientid = intval( $client->id );
   if ($client->credit > 0) {
       $currencyData = getCurrency($clientid);
       $bodyhtml = '<p>'.sprintf(Lang::trans('availcreditbaldesc'),formatCurrency($client->credit, $currencyData)).'</p>';
       $creditPanel = $homePagePanels->addChild( 'Credit Balance', array(
           'label' => Lang::trans('availcreditbal'),
           'icon' => 'fa-money',
           'extras' => array(
               'color' => 'red',
               'btn-link' => 'clientarea.php?action=addfunds',
               'btn-text' => Lang::trans('addfunds'),
               'btn-icon' => 'fa-plus',
           ),
           'bodyHtml' => $bodyhtml
       ));
   }
});
 

 

 

GckODsj.pngPOnJ39q.png

 

 

 

Hi, added you hook and it's working fine, but translation doesn't show amount. Language value is:

$_LANG['availcreditbaldesc'] = "Sie haben ein Guthaben von :creditBalance und dieses wird automatisch auf alle neuen Rechnungen angewendet.";

Any idea what could be wrong?

 

07-06-_2021_18-20-47.png

Link to comment
Share on other sites

3 hours ago, papak011 said:

 

Hi, added you hook and it's working fine, but translation doesn't show amount. Language value is:

$_LANG['availcreditbaldesc'] = "Sie haben ein Guthaben von :creditBalance und dieses wird automatisch auf alle neuen Rechnungen angewendet.";

Any idea what could be wrong?

 

07-06-_2021_18-20-47.png

 

Found solution, %s and not :creditBalance should be in language variable

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