Jump to content

Admin Stats for WHMCS v8


Kian

Recommended Posts

As you probably know WHMCS v8 no longer provides statistics on top of the page about pending orders, overdue invoices and tickets awaiting reply. This action hook adds them back to interface as you can see from the following screenshot.

whmcs-admin-bar-stats-navbar.png.1f7385f7ff0db01d926957803630be29.png

whmcs-admin-bar-stats-sidebar.png.ffdcd9881207925aea2ea5487650eaab.png

This badge is fully responsive and appears if there's at least one pending order, overdue invoice or ticket awaiting reply. If there's nothing to show it disappears. To avoid any possibility of confusion, the hook automatically detects if you're running v8.

Get the Code »

Link to comment
Share on other sites

  • 2 months later...

Thanks, this is very useful, I just updated to v8 and was disappointed to see that the pending orders/tickets had been hidden making it more work for admins!

I wondered if there was a way to change it so that it doesn't show the Overdue Invoices just keeps the Pending Orders and Tickets?

I did have a go at this but ended up with some whitespace left over.

Screenshot 2020-12-30 at 11.39.42.png

Link to comment
Share on other sites

  • 4 years later...

Hi there.  That script is very useful! Thanks.

I've added a little modification. 
This script will not show a notification for the invoices that are due the same day, but not expired yet.
All the best

<?php

/**
 * Admin Stats for WHMCS v8
 *
 * @package     WHMCS
 * @copyright   Katamaze
 * @link        https://katamaze.com
 * @author      Davide Mantenuto <info@katamaze.com>
 */

use WHMCS\Database\Capsule;

add_hook('AdminAreaHeaderOutput', 1, function($vars)
{
    $v8 = Capsule::select(Capsule::raw('SELECT value FROM tblconfiguration WHERE setting = "Version" LIMIT 1'))[0]->value;
    if (explode('.', $v8)[0] != '8'): return; endif;
    $showZero = true;

    $ordersTotal = Capsule::select(Capsule::raw('SELECT COUNT(t1.id) AS total FROM tblorders AS t1 LEFT JOIN tblorderstatuses AS t2 ON t1.status = t2.title WHERE t2.showpending = "1"'))[0]->total;
$invoicesTotal = Capsule::select(Capsule::raw('
    SELECT COUNT(id) AS total 
    FROM tblinvoices 
    WHERE status = "Unpaid" 
    AND duedate < CURDATE()
'))[0]->total;
    $ticketsTotal = Capsule::select(Capsule::raw('SELECT COUNT(t1.id) AS total FROM tbltickets AS t1 LEFT JOIN tblticketstatuses AS t2 ON t1.status = t2.title WHERE t2.showawaiting = "1" AND merged_ticket_id = "0"'))[0]->total;
    if (!$ordersTotal AND !$invoicesTotal AND !$ticketsTotal): return; endif;
    $notificationsLabel = AdminLang::trans('setup.notifications');
    $orderText = AdminLang::trans('stats.pendingorders');
    $invoiceText = AdminLang::trans('stats.overdueinvoices');
    $ticketText = AdminLang::trans('stats.ticketsawaitingreply');

    if ($ordersTotal OR $showZero)
    {
        $pendingOrdersJS = <<<HTML
        $('#v8fallback').next('ul').append('<li><a href="orders.php?status=Pending" data-toggle="tooltip" data-placement="bottom" title="{$orderText}" data-original-title="{$orderText}" style="word-wrap:break-word"><small><span class="ico-container"><i class="fad fa-shopping-cart"></i></span><span class="v8fallback">{$ordersTotal}</span> {$orderText}</small></a></li>');
HTML;
    }

    if ($invoicesTotal OR $showZero)
    {
        $overdueInvoicesJS = <<<HTML
        $('#v8fallback').next('ul').append('<li><a href="invoices.php?status=Overdue" data-toggle="tooltip" data-placement="bottom" title="{$invoiceText}" data-original-title="{$invoiceText}" style="word-wrap:break-word"><small><span class="ico-container"><i class="fad fa-sack-dollar"></i></span><span class="v8fallback">{$invoicesTotal}</span> {$invoiceText}</small></a></li>');
HTML;
    }

    if ($ticketsTotal OR $showZero)
    {
        $awaitingTicketsJS = <<<HTML
        $('#v8fallback').next('ul').append('<li><a href="supporttickets.php" data-toggle="tooltip" data-placement="bottom" title="{$ticketText}" data-original-title="{$ticketText}" style="word-wrap:break-word"><small><span class="ico-container"><i class="fad fa-question-circle"></i></span><span class="v8fallback">{$ticketsTotal}</span> {$ticketText}</small></a></li>');
HTML;
    }

    return <<<HTML
<script type="text/javascript">
$(document).on('ready', function() {
    $('ul.right-nav').first('li').prepend('<li class="bt has-dropdown"><a id="v8fallback" href="#"><div class="badge-container"><i class="fas fa-exclamation-triangle always"></i><span class="badge"><span class="fas fa-times"></span></span></div><span class="visible-sidebar">&nbsp;{$notificationsLabel}</span></a><ul class="drop-icons"></ul></li>');
    $("*[id=\'v8fallback\']").on("click", function(e) {
        e.preventDefault();
        $(e.currentTarget).parent("li").toggleClass("expanded");
    });
    {$pendingOrdersJS}
    {$overdueInvoicesJS}
    {$awaitingTicketsJS}
    $('#v8fallback').next('ul').css({"width": "340px", "left": "-134px"});
    $('span.v8fallback').css({"font-weight": "700"});
});
</script>
HTML;
});

 

Link to comment
Share on other sites

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