karpstrucking Posted January 29, 2017 Share Posted January 29, 2017 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>' )); }); 0 Quote Link to comment Share on other sites More sharing options...
AffordableDomainsCanada Posted January 29, 2017 Share Posted January 29, 2017 (edited) Here is a screenshot of the panel which is created in the client area. Edited January 29, 2017 by AffordableDomainsCanada 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 30, 2017 Share Posted January 30, 2017 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. <?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 )); } }); 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted January 30, 2017 Share Posted January 30, 2017 added link to this implementation in the mentioned thread https://forum.whmcs.com/showthread.php?106891-Display-Credit-Balance-In-Six-Template&p=500650#post500650 0 Quote Link to comment Share on other sites More sharing options...
shaplahost Posted February 26, 2017 Share Posted February 26, 2017 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. 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. <?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 )); } }); 0 Quote Link to comment Share on other sites More sharing options...
sentq Posted February 27, 2017 Share Posted February 27, 2017 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 )); }); 1 Quote Link to comment Share on other sites More sharing options...
Argoz Posted July 14, 2017 Share Posted July 14, 2017 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 )); }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 15, 2017 Share Posted July 15, 2017 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 )); }); 0 Quote Link to comment Share on other sites More sharing options...
Dhush Posted July 15, 2017 Share Posted July 15, 2017 How to hide the panel if client has no or 0 credit? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 15, 2017 Share Posted July 15, 2017 How to hide the panel if client has no or 0 credit? the code in post #3 will do that. https://forum.whmcs.com/showthread.php?124790-Adding-a-quot-Credit-Balance-quot-panel-to-the-client-area-home-page&p=500630#post500630 1 Quote Link to comment Share on other sites More sharing options...
Dhush Posted July 15, 2017 Share Posted July 15, 2017 Thank you Brain, already got it forgot to update. can you look in this thread https://forums.whmcs.com/showthread.php?128295-Need-Improvement-in-Standard-Cart-Order-Template/page3 ? 1 Quote Link to comment Share on other sites More sharing options...
brian! Posted July 15, 2017 Share Posted July 15, 2017 can you look in this thread https://forums.whmcs.com/showthread.php?128295-Need-Improvement-in-Standard-Cart-Order-Template/page3 ? I already have! 0 Quote Link to comment Share on other sites More sharing options...
papak011 Posted June 7, 2021 Share Posted June 7, 2021 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. <?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 )); } }); 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? 0 Quote Link to comment Share on other sites More sharing options...
papak011 Posted June 7, 2021 Share Posted June 7, 2021 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? Found solution, %s and not :creditBalance should be in language variable 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted June 8, 2021 Share Posted June 8, 2021 17 hours ago, papak011 said: Found solution, %s and not :creditBalance should be in language variable it is a 4-year old thread, but the hook as written still works for me... 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.