Jump to content

Admin home page panel badge hook


Recommended Posts

Hello All,

As whmcs removed the toolbar from v8, and thanks to Brian's hook I am able to adjust it and add back overdue invoices to just the admin home page. In the image attached, you will see it above the panel badges (by default the 4 whmcs provided badges).  I am able to adjust the css to add a 5th panel badge as the image will show.

Question does any knows how I can hook into the panel badges, as whmcs support does not have an answer.  All I want to do is a) from the image remove Brian's modified hook, and hook into the panel badge as display total overdue invoices.

Thanks in advance.

Brian

 

layout.png

Link to comment
Share on other sites

On 06/01/2021 at 16:23, actionhosting said:

Question does any knows how I can hook into the panel badges, as whmcs support does not have an answer.

wow! 🙄

On 06/01/2021 at 16:23, actionhosting said:

All I want to do is a) from the image remove Brian's modified hook

just rename the extension on the hook from .php to .php9 and that will stop it from loading (or delete the file if you think you'll never need it again).

On 06/01/2021 at 16:23, actionhosting said:

and hook into the panel badge as display total overdue invoices.

the simplest way to do this would be to...

  1. duplicate the Badges.php file in /modules/widgets and call it Badges2.php - do not edit the original Badges.php file as your changes would get overwritten during an update.
  2. in Badges2.php, insert the following code...
    <?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 Badges2 extends AbstractWidget
    {
        protected $title = 'Badges (Modified)';
        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(),
                'ticketsAwaitingReply' => $ticketCounts['awaitingReply'],
                'cancellations' => $clients->getNumberOfOpenCancellationRequests(),
                'moduleQueueCount' => ModuleQueue::incomplete()->count(),
            );
        }
    
        public function generateOutput($data)
        {
            $pendingOrders = (int) $data['pendingOrders'];
            $awaitingReply = (int) $data['ticketsAwaitingReply'];
            $pendingCancellations = (int) $data['cancellations'];
            $moduleQueueCount = (int) $data['moduleQueueCount'];
    		$overdueinvoices = Invoice::overdue()->count();
    
            return <<<EOF
    <div class="row home-status-badge-row">
        <div class="col-sm-2">
    
            <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-2">
    
            <div class="health-status-block status-badge-pink clearfix">
                <div class="icon">
                    <a href="supporttickets.php">
                        <i class="fas fa-comment"></i>
                    </a>
                </div>
                <div class="detail">
                    <a href="supporttickets.php">
                        <span class="count">{$awaitingReply}</span>
                        <span class="desc">Tickets Waiting</span>
                    </a>
                </div>
            </div>
    
        </div>
        <div class="col-sm-2">
    
            <div class="health-status-block status-badge-orange clearfix">
                <div class="icon">
                    <a href="cancelrequests.php">
                        <i class="fas fa-ban"></i>
                    </a>
                </div>
                <div class="detail">
                    <a href="cancelrequests.php">
                        <span class="count">{$pendingCancellations}</span>
                        <span class="desc">Pending Cancellations</span>
                    </a>
                </div>
            </div>
    
        </div>
        <div class="col-sm-2">
    
            <div class="health-status-block status-badge-cyan clearfix">
                <div class="icon">
                    <a href="modulequeue.php">
                        <i class="fas fa-exclamation-triangle"></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 class="col-sm-2">
    
            <div class="health-status-block status-badge-pink clearfix">
                <div class="icon">
                    <a href="invoices.php?status=Overdue">
                        <i class="fas fa-sack-dollar"></i>
                    </a>
                </div>
                <div class="detail">
                    <a href="modulequeue.php">
                        <span class="count">{$overdueinvoices}</span>
                        <span class="desc">Overdue Invoices</span>
                    </a>
                </div>
            </div>
    
        </div>	
    </div>
    EOF;
        }
    }
    

     

  3. save the file.

  4. in the admin area, disable the original Badges widget.
    FcN9A3t.png

the screenshot below shows the default Badges widget on top, and the modified one below it.... then it's just a case of disabling the Badges widget and either playing with the CSS of the badges, or adding a 6th to fill the space.

2HhBhLG.png

there is a way to do this as a hook and put the file in /includes/hooks instead, but I always prefer to put widget code in the widgets folder.

Edited by brian!
Link to comment
Share on other sites

On 09/01/2021 at 09:52, tangogc said:

I discovered a little bug in this hook

look the screenshot

if you click on the red circle it go to modulequeue

if you click on the red arrow it work correctly

yeah good spot - it was just a quick copy&paste job to  give @actionhosting a starting point from which to work from.... I can't edit the code in my original post.

Link to comment
Share on other sites

Thanks Brian, I did notice it and fixed it. I didnt advise as the pending module action is similar.  Here is my updated code .

 

<?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 WSIBadges extends AbstractWidget
{
    protected $title = 'WSIBadges';
    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(),
            'ticketsAwaitingReply' => $ticketCounts['awaitingReply'],
            'cancellations' => $clients->getNumberOfOpenCancellationRequests(),
            'moduleQueueCount' => ModuleQueue::incomplete()->count(),
        );
    }

    public function generateOutput($data)
    {
        $pendingOrders = (int) $data['pendingOrders'];
        $awaitingReply = (int) $data['ticketsAwaitingReply'];
        $pendingCancellations = (int) $data['cancellations'];
        $moduleQueueCount = (int) $data['moduleQueueCount'];
		$overdueinvoices = Invoice::overdue()->count();

        return <<<EOF
<div class="row home-status-badge-row">
    <div class="col-wsm-2">

        <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-wsm-2">

        <div class="health-status-block status-badge-pink clearfix">
            <div class="icon">
                <a href="supporttickets.php">
                    <i class="fas fa-comment"></i>
                </a>
            </div>
            <div class="detail">
                <a href="supporttickets.php">
                    <span class="count">{$awaitingReply}</span>
                    <span class="desc">Tickets Waiting</span>
                </a>
            </div>
        </div>

    </div>
    <div class="col-wsm-2">

        <div class="health-status-block status-badge-orange clearfix">
            <div class="icon">
                <a href="cancelrequests.php">
                    <i class="fas fa-ban"></i>
                </a>
            </div>
            <div class="detail">
                <a href="cancelrequests.php">
                    <span class="count">{$pendingCancellations}</span>
                    <span class="desc">Pending Cancellations</span>
                </a>
            </div>
        </div>

    </div>
    <div class="col-wsm-2">

        <div class="health-status-block status-badge-cyan clearfix">
            <div class="icon">
                <a href="modulequeue.php">
                    <i class="fas fa-exclamation-triangle"></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 class="col-wsm-2">

        <div class="health-status-block status-badge-red clearfix">
            <div class="icon">
                <a href="invoices.php?status=Overdue">
                    <i class="fas fa-sack-dollar"></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>
EOF;
    }
}
.col-wsm-2 {
    width: 20%;
    float: left;
    padding: 0 5px;
} 
.status-badge-red {
    background-color: #ff0000;
}
.status-badge-red .icon {
    background-color: #e40707;
}
.health-status-block .detail {
    float: left;
    display: inline-block;
    padding: 8px 15px;
    width: 79%;
    height: 70px;
    border-radius: 0 4px 4px 0;
    text-align: center;
}
.health-status-block .icon {
    float: left;
    display: inline-block;
    width: 20%;
    height: 70px;
    font-size: 2em;
    line-height: 70px;
    text-align: center;
    border-radius: 4px 0 0 4px;
}

But I will also revert back to badges,.php and remove the pending module action as it is duplicated in the system health widget and use that location for the overdue invoice. So no css changes will be needed. With the above this is how it looks at this time.

whmcs modified dash.png

Link to comment
Share on other sites

18 minutes ago, actionhosting said:

Thanks Brian, I did notice it and fixed it. I didnt advise as the pending module action is similar.  Here is my updated code .

 


<?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 WSIBadges extends AbstractWidget
{
    protected $title = 'WSIBadges';
    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(),
            'ticketsAwaitingReply' => $ticketCounts['awaitingReply'],
            'cancellations' => $clients->getNumberOfOpenCancellationRequests(),
            'moduleQueueCount' => ModuleQueue::incomplete()->count(),
        );
    }

    public function generateOutput($data)
    {
        $pendingOrders = (int) $data['pendingOrders'];
        $awaitingReply = (int) $data['ticketsAwaitingReply'];
        $pendingCancellations = (int) $data['cancellations'];
        $moduleQueueCount = (int) $data['moduleQueueCount'];
		$overdueinvoices = Invoice::overdue()->count();

        return <<<EOF
<div class="row home-status-badge-row">
    <div class="col-wsm-2">

        <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-wsm-2">

        <div class="health-status-block status-badge-pink clearfix">
            <div class="icon">
                <a href="supporttickets.php">
                    <i class="fas fa-comment"></i>
                </a>
            </div>
            <div class="detail">
                <a href="supporttickets.php">
                    <span class="count">{$awaitingReply}</span>
                    <span class="desc">Tickets Waiting</span>
                </a>
            </div>
        </div>

    </div>
    <div class="col-wsm-2">

        <div class="health-status-block status-badge-orange clearfix">
            <div class="icon">
                <a href="cancelrequests.php">
                    <i class="fas fa-ban"></i>
                </a>
            </div>
            <div class="detail">
                <a href="cancelrequests.php">
                    <span class="count">{$pendingCancellations}</span>
                    <span class="desc">Pending Cancellations</span>
                </a>
            </div>
        </div>

    </div>
    <div class="col-wsm-2">

        <div class="health-status-block status-badge-cyan clearfix">
            <div class="icon">
                <a href="modulequeue.php">
                    <i class="fas fa-exclamation-triangle"></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 class="col-wsm-2">

        <div class="health-status-block status-badge-red clearfix">
            <div class="icon">
                <a href="invoices.php?status=Overdue">
                    <i class="fas fa-sack-dollar"></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>
EOF;
    }
}

.col-wsm-2 {
    width: 20%;
    float: left;
    padding: 0 5px;
} 
.status-badge-red {
    background-color: #ff0000;
}
.status-badge-red .icon {
    background-color: #e40707;
}
.health-status-block .detail {
    float: left;
    display: inline-block;
    padding: 8px 15px;
    width: 79%;
    height: 70px;
    border-radius: 0 4px 4px 0;
    text-align: center;
}
.health-status-block .icon {
    float: left;
    display: inline-block;
    width: 20%;
    height: 70px;
    font-size: 2em;
    line-height: 70px;
    text-align: center;
    border-radius: 4px 0 0 4px;
}

But I will also revert back to badges,.php and remove the pending module action as it is duplicated in the system health widget and use that location for the overdue invoice. So no css changes will be needed. With the above this is how it looks at this time.

whmcs modified dash.png

thanks but it not work on my 8.0.4 installation Badges3 failed to load. Could not include file: D:\inetpub\vhosts\gamesclan.net\httpdocs\billing/modules/widgets/Badges3.php. Error: syntax error, unexpected '.', expecting end of file

Edited by tangogc
Link to comment
Share on other sites

21 hours ago, actionhosting said:

But I will also revert back to badges,.php and remove the pending module action as it is duplicated in the system health widget and use that location for the overdue invoice. So no css changes will be needed. With the above this is how it looks at this time.

if you've edited the original badges.php file, then it will likely get overwritten during an update.

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.

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