monsterit Posted January 15, 2020 Share Posted January 15, 2020 (edited) Hi, is it possible to change these so instead of tickets waiting we can have unpaid invoices? just a though to make things easier for us. as we do not use the ticketing system at all. we are using 7.9.1 and have setup a custom admin theme. Edited January 15, 2020 by monsterit 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 15, 2020 Share Posted January 15, 2020 11 minutes ago, monsterit said: so instead of tickets waiting we can have unpaid invoices? just a though to make things easier for us. as we do not use the ticketing system at all. we are using 7.9.1 and have setup a custom admin theme. they're generated by the Badges widget in /modules/widgets - it's not encrypted, so you will be able to edit it to tweak the output. 0 Quote Link to comment Share on other sites More sharing options...
monsterit Posted January 15, 2020 Author Share Posted January 15, 2020 Thank you Brian, i'll check it out. 0 Quote Link to comment Share on other sites More sharing options...
monsterit Posted January 15, 2020 Author Share Posted January 15, 2020 @brian! whats the string i need to view unpaid invoices? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 15, 2020 Share Posted January 15, 2020 4 hours ago, monsterit said: whats the string i need to view unpaid invoices? do you mean the language string, or the db query to get the actual value ? if it's the database query to get the unpaid invoices count, then it should need... use WHMCS\Billing\Invoice; and the pendingorders value is calculated using... 'pendingOrders' => (int) Invoice::where('status', '=', 'Unpaid')->count(), yeah, forget that i'm still calling the variable pendingorders when it's really calculating the count of unpaid invoices - i'm being lazy because as I mentioned in that other thread, it would have meant replacing all occurrences of pendingorders in the code - but you can do that if it makes it clearer. ... and don't forget not to edit the original badges.php file as that will just get overwritten during an update. 0 Quote Link to comment Share on other sites More sharing options...
monsterit Posted January 16, 2020 Author Share Posted January 16, 2020 @brian! So far i've got it looking like this. <?php namespace WHMCS\Module\Widget; use WHMCS\Carbon; use WHMCS\Clients; use WHMCS\Module\AbstractWidget; use WHMCS\Module\Queue as ModuleQueue; use WHMCS\Orders; use WHMCS\Billing\Invoice; /** * Badges Widget. * * @copyright Copyright (c) WHMCS Limited 2005-2018 * @license https://www.whmcs.com/license/ WHMCS Eula */ class Badges extends AbstractWidget { protected $title = 'Badges'; protected $description = ''; protected $columns = 3; protected $weight = 0; protected $wrapper = false; protected $cache = true; protected $cacheExpiry = 120; protected $draggable = false; public function getData() { $clients = new Clients(); $orders = new Orders(); $ticketCounts = localApi('GetTicketCounts', array()); return array( 'pendingOrders' => $orders->getPendingCount(), 'unpaidOrders' => (int) Invoice::where('status', '=', 'Unpaid')->count(), 'cancellations' => $clients->getNumberOfOpenCancellationRequests(), 'moduleQueueCount' => ModuleQueue::incomplete()->count(), ); } public function generateOutput($data) { $pendingOrders = (int) $data['pendingOrders']; $unpaidOrders = (int) $data['unpaidOrders']; $pendingCancellations = (int) $data['cancellations']; $moduleQueueCount = (int) $data['moduleQueueCount']; return <<<EOF <div class="row home-status-badge-row"> <div class="col-sm-3"> <div class="health-status-block status-badge-green clearfix"> <div class="icon"> <a href="orders.php"> <i class="fas fa-shopping-cart"></i> </a> </div> <div class="detail"> <a href="orders.php?status=Pending"> <span class="count">{$pendingOrders}</span> <span class="desc">Pending Orders</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-pink clearfix"> <div class="icon"> <a href="invoices.php?status=Unpaid"> <i class="fas fa-file-invoice-dollar"></i> </a> </div> <div class="detail"> <a href="invoices.php?status=Unpaid"> <span class="count">{$unpaidOrders}</span> <span class="desc">Unpaid Orders</span> </a> </div> </div> </div> 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 16, 2020 Share Posted January 16, 2020 5 hours ago, monsterit said: So far i've got it looking like this. I assume you know there are a few lines at the end missing from the above post.... i'm assuming that's just an issue with your copy&paste and not the original file. 🙂 also, have you renamed the file yet, or are you still editing the original badges.php ?? 0 Quote Link to comment Share on other sites More sharing options...
monsterit Posted January 17, 2020 Author Share Posted January 17, 2020 im editing the badges-new.php but struggling with it. tbh.everytime i edit it i loose everything. 0 Quote Link to comment Share on other sites More sharing options...
monsterit Posted January 17, 2020 Author Share Posted January 17, 2020 (edited) This is my whole output. <?php add_hook('AdminHomeWidgets', 1, function() { return new InvoicesWidget(); }); use WHMCS\Carbon; use WHMCS\Clients; use WHMCS\Module\AbstractWidget; use WHMCS\Module\Queue as ModuleQueue; use WHMCS\Orders; use WHMCS\Billing\Invoice; /** * Badges Widget. * * @copyright Copyright (c) WHMCS Limited 2005-2018 * @license https://www.whmcs.com/license/ WHMCS Eula */ class InvoicesWidget extends \WHMCS\Module\AbstractWidget { protected $title = "Invoices Widget"; protected $description = 'Invoices'; protected $columns = 3; protected $weight = 0; protected $wrapper = false; protected $cache = true; protected $cacheExpiry = 120; protected $draggable = false; public function getData() { $clients = new Clients(); $orders = new Orders(); return array( 'pendingOrders' => $orders->getPendingCount(), 'unpaidInvoices' => (int) Invoice::where('status', '=', 'Unpaid')->count(), 'overdueInvoices' => (int) Invoice::where('status', '=', 'Overdue')->count(), 'moduleQueueCount' => ModuleQueue::incomplete()->count(), ); } public function generateOutput($data) { $pendingOrders = (int) $data['pendingOrders']; $unpaidInvoices = (int) $data['unpaidInvoices']; $overdueInvoices = (int) $data['overdueInvoices']; $moduleQueueCount = (int) $data['moduleQueueCount']; return <<<EOF <div class="row home-status-badge-row"> <div class="col-sm-3"> <div class="health-status-block status-badge-green clearfix"> <div class="icon"> <a href="orders.php"> <i class="fas fa-shopping-cart"></i> </a> </div> <div class="detail"> <a href="orders.php?status=Pending"> <span class="count">{$pendingOrders}</span> <span class="desc">Active Clients</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-pink clearfix"> <div class="icon"> <a href="invoices.php"> <i class="fas fa-file-invoice-dollar"></i> </a> </div> <div class="detail"> <a href="invoices.php?status=Unpaid"> <span class="count">{$unpaidInvoices}</span> <span class="desc">Unpaid Invoices</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-orange clearfix"> <div class="icon"> <a href="invoices.php"> <i class="fas fa-business-time"></i> </a> </div> <div class="detail"> <a href="invoices.php?status=Overdue"> <span class="count">{$overdueInvoices}</span> <span class="desc">Overdue Invoices</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-cyan clearfix"> <div class="icon"> <a href="modulequeue.php"> <i class="fas fa-ban"></i> </a> </div> <div class="detail"> <a href="modulequeue.php"> <span class="count">{$moduleQueueCount}</span> <span class="desc">Pending Module Actions</span> </a> </div> </div> </div> </div> EOF; } } I can see unpaid invoices now but no over invoices. above is the code and below is my screen shot. Edited January 17, 2020 by monsterit 0 Quote Link to comment Share on other sites More sharing options...
monsterit Posted January 17, 2020 Author Share Posted January 17, 2020 Sorry ignore the above one. i've managed to put alot in but for some reason it's only showing one module counting and i cannot put my finger on it. see the image below. Heres my very long winded coding section. (complete). <?php add_hook('AdminHomeWidgets', 1, function() { return new InvoicesWidget(); }); use WHMCS\Carbon; use WHMCS\Clients; use WHMCS\Module\AbstractWidget; use WHMCS\Module\Queue as ModuleQueue; use WHMCS\Orders; use WHMCS\Billing\Invoice; use WHMCS\User\Client; /** * Badges Widget. * * @copyright Copyright (c) WHMCS Limited 2005-2018 * @license https://www.whmcs.com/license/ WHMCS Eula */ class InvoicesWidget extends \WHMCS\Module\AbstractWidget { protected $title = "Invoices Widget"; protected $description = 'Invoices'; protected $columns = 3; protected $weight = 0; protected $wrapper = false; protected $cache = true; protected $cacheExpiry = 120; protected $draggable = false; public function getData() { $clients = new Clients(); $orders = new Orders(); $incomeStats = getAdminHomeStats('income'); foreach ($incomeStats['income'] as $key => $value) { $incomeStats['income'][$key] = $value->toPrefixed(); } return $incomeStats; return array( 'activeCount' => (int) Client::where('status', '=', 'Active')->count(), 'unpaidInvoices' => (int) Invoice::where('status', '=', 'Unpaid')->count(), 'overdueInvoices' => (int) Invoice::where('status', '=', 'Overdue')->count(), ); } public function generateOutput($data) { $activeClients = number_format((int) $data['activeCount']); $unpaidInvoices = (int) $data['unpaidInvoices']; $overdueInvoices = (int) $data['overdueInvoices']; $incomeThisMonth = $data['income']['thismonth']; return <<<EOF <div class="row home-status-badge-row"> <div class="col-sm-3"> <div class="health-status-block status-badge-green clearfix"> <div class="icon"> <a href="clients.php?status=Active"> <i class="fas fa-user-friends"></i> </a> </div> <div class="detail"> <a href="clients.php?status=Active"> <span class="count">{$activeClients}</span> <span class="desc">Active Clients</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-pink clearfix"> <div class="icon"> <a href="invoices.php"> <i class="fas fa-file-invoice-dollar"></i> </a> </div> <div class="detail"> <a href="invoices.php?status=Unpaid"> <span class="count">{$unpaidInvoices}</span> <span class="desc">Unpaid Invoices</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-orange clearfix"> <div class="icon"> <a href="invoices.php"> <i class="fas fa-business-time"></i> </a> </div> <div class="detail"> <a href="invoices.php?status=Overdue"> <span class="count">{$overdueInvoices}</span> <span class="desc">Overdue Invoices</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-cyan clearfix"> <div class="icon"> <a href="modulequeue.php"> <i class="fas fa-wallet"></i> </a> </div> <div class="detail"> <a href="modulequeue.php"> <span class="count">{$incomeThisMonth}</span> <span class="desc">Income This Month</span> </a> </div> </div> </div> </div> EOF; } } 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 17, 2020 Share Posted January 17, 2020 48 minutes ago, monsterit said: Sorry ignore the above one. i've managed to put alot in but for some reason it's only showing one module counting and i cannot put my finger on it. I don't like that getData has two returns - the widget will only see the first (the one taken from the billing widget code) and ignore the second (hence your output). btw, some of the queries can be improved too... public function getData() { $incomeStats = getAdminHomeStats('income'); foreach ($incomeStats['income'] as $key => $value) { $incomeStats['income'][$key] = $value->toPrefixed(); } return array( 'activeCount' => Client::where('status', '=', 'Active')->count('id'), 'unpaidInvoices' => Invoice::unpaid()->count('id'), 'overdueInvoices' => Invoice::overdue()->count('id'), 'incomestats' => $incomeStats, ); } public function generateOutput($data) { $activeCount = (int) $data['activeCount']; $unpaidInvoices = (int) $data['unpaidInvoices']; $overdueInvoices = (int) $data['overdueInvoices']; $incomeThisMonth = $data['incomestats']['income']['thismonth']; 1 Quote Link to comment Share on other sites More sharing options...
monsterit Posted January 17, 2020 Author Share Posted January 17, 2020 Great thank you. I've changed a part below too as it was clients, so changed that to count. 🙂 <?php add_hook('AdminHomeWidgets', 1, function() { return new InvoicesWidget(); }); use WHMCS\Carbon; use WHMCS\Clients; use WHMCS\Module\AbstractWidget; use WHMCS\Module\Queue as ModuleQueue; use WHMCS\Orders; use WHMCS\Billing\Invoice; use WHMCS\User\Client; /** * Badges Widget. * * @copyright Copyright (c) WHMCS Limited 2005-2018 * @license https://www.whmcs.com/license/ WHMCS Eula */ class InvoicesWidget extends \WHMCS\Module\AbstractWidget { protected $title = "Invoices Widget"; protected $description = 'Invoices'; protected $columns = 3; protected $weight = 0; protected $wrapper = false; protected $cache = false; protected $cacheExpiry = 120; protected $draggable = false; public function getData() { $incomeStats = getAdminHomeStats('income'); foreach ($incomeStats['income'] as $key => $value) { $incomeStats['income'][$key] = $value->toPrefixed(); } return array( 'activeCount' => Client::where('status', '=', 'Active')->count('id'), 'unpaidInvoices' => Invoice::unpaid()->count('id'), 'overdueInvoices' => Invoice::overdue()->count('id'), 'incomestats' => $incomeStats, ); } public function generateOutput($data) { $activeCount = (int) $data['activeCount']; $unpaidInvoices = (int) $data['unpaidInvoices']; $overdueInvoices = (int) $data['overdueInvoices']; $incomeThisMonth = $data['incomestats']['income']['thismonth']; return <<<EOF <div class="row home-status-badge-row"> <div class="col-sm-3"> <div class="health-status-block status-badge-red clearfix"> <div class="icon"> <a href="clients.php?status=Active"> <i class="fas fa-user-friends"></i> </a> </div> <div class="detail"> <a href="clients.php?status=Active"> <span class="count">{$activeCount}</span> <span class="desc">Active Clients</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-purple clearfix"> <div class="icon"> <a href="invoices.php"> <i class="fas fa-file-invoice-dollar"></i> </a> </div> <div class="detail"> <a href="invoices.php?status=Unpaid"> <span class="count">{$unpaidInvoices}</span> <span class="desc">Unpaid Invoices</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-teal clearfix"> <div class="icon"> <a href="invoices.php"> <i class="fas fa-business-time"></i> </a> </div> <div class="detail"> <a href="invoices.php?status=Overdue"> <span class="count">{$overdueInvoices}</span> <span class="desc">Overdue Invoices</span> </a> </div> </div> </div> <div class="col-sm-3"> <div class="health-status-block status-badge-gold clearfix"> <div class="icon"> <a href="modulequeue.php"> <i class="fas fa-wallet"></i> </a> </div> <div class="detail"> <a href="modulequeue.php"> <span class="count">{$incomeThisMonth}</span> <span class="desc">Income This Month</span> </a> </div> </div> </div> </div> EOF; } } all working perfectly. Thank you once again. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 17, 2020 Share Posted January 17, 2020 3 minutes ago, monsterit said: all working perfectly. Thank you once again. we got there in the end. 🙂 btw, this isn't important, but you could probably trim those uses at the start to just the 3 below - everything else you are seemingly no longer using... use WHMCS\Module\AbstractWidget; use WHMCS\User\Client; use WHMCS\Billing\Invoice; .. or could you leave them in for future use, e.g if you're planning on having more than 4 badges any time soon. 1 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.