toolbar to show hours billed today

Dont create your support topics here! No new topics with questions allowed!

Moderator: crythias

Post Reply
User avatar
Posts: 10011
Joined: 04 May 2010, 18:38
OTRS Version?: 5.0.x
Location: SouthWest Florida, USA

toolbar to show hours billed today

Post by crythias » 19 Dec 2017, 04:42

What this does: Puts a $ in the toolbar under which it shows you your billed hours today.

Why is it useful? If you're using time_units to collect your billable time, it may be of interest to show if you're on track for the billable time for the day.

How to install:
(Version 5)
1) You need Kernel/Output/HTML/ToolBar/ :

Code: Select all

# --
# Kernel/Output/HTML/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see
# --

package Kernel::Output::HTML::ToolBar::myToolBarTicketHours;

use strict;
use warnings;

use Kernel::Language qw(Translatable);

our @ObjectDependencies = (

sub new {
    my ( $Type, %Param ) = @_;

    # allocate new hash for object
    my $Self = {};
    bless( $Self, $Type );

    # get needed objects
#    for (qw(ConfigObject LogObject DBObject TicketObject LayoutObject UserID))                {
#        $Self->{$_} = $Param{$_} || die "Got no $_!";
#    }
    # get UserID param
    $Self->{UserID} = $Param{UserID} || die "Got no UserID!";

    return $Self;

sub Run {
    my ( $Self, %Param ) = @_;

    # check needed stuff
        for (qw(Config)) {
                if (!$Param{$_} ) {

                Priority => 'error',
                Message  => "Need $_!"

    # get ticket object
    my $TicketObject = $Kernel::OM->Get('Kernel::System::Ticket');
    my $Class        = $Param{Config}->{CssClass};
    my $ClassNew     = $Param{Config}->{CssClassNew};
    my $ClassReached = $Param{Config}->{CssClassReached};

    my $Icon        = $Param{Config}->{Icon};
    my $IconNew     = $Param{Config}->{IconNew};
    my $IconReached = $Param{Config}->{IconReached};

    my $URL = $Kernel::OM->Get('Kernel::Output::HTML::Layout')->{Baselink};
    my %Return;
    my $Priority = $Param{Config}->{Priority};
    my $DBObject = $Kernel::OM->Get('Kernel::System::DB');

    # db query
    return if !$DBObject->Prepare(
        SQL  => 'SELECT sum(time_unit) FROM time_accounting WHERE DATE(create_time) = CURDATE() AND create_by = ?',
        Bind => [ \$Self->{UserID} ],

        my $Hours = 0;
        while ( my @Row = $DBObject->FetchrowArray() ) {
                $Row[0] =~ s/,/./g;
                $Hours = $Hours + $Row[0];
        $Return{ $Priority } = {
                Block => 'ToolBarItem',
                Count => $Hours,
                Class => $Class,
                Description => Translatable('Todays billable hours'),
                Icon => $Icon,

    return %Return;

2) The Kernel/Config/Files/myToolBarHours.xml to turn it on:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<otrs_config version="1.0" init="Application">
    <ConfigItem Name="Frontend::ToolBarModule###99-Ticket::TicketHours" Required="0" Valid="1">
        <Description Translatable="1">Agent interface notification module to see the number of
hours an Agent has billed today.</Description>
                <Item Key="Module">Kernel::Output::HTML::ToolBar::myToolBarTicketHours</Item>
                <Item Key="CssClass">Hours</Item>
                <Item Key="Icon">fa fa-dollar</Item>
                <Item Key="AccessKey">q</Item>
                <Item Key="Priority">1030090</Item>
Feedback is appreciated, especially any bug or security reports herein. Use at your own risk. If it doesn't work for you, let me know what you're encountering in the other forums.
OTRS 5.0.x (private/testing/public) on Linux with MySQL database. Also on github.
Please edit your signature to include your OTRS version, Operating System, and database type.
Click Subscribe Topic below to get notifications. Consider amending your topic title to include [SOLVED] if it is so.
Need help? Before you ask

Post Reply