toolbar to show hours billed today

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

Moderator: crythias

User avatar
crythias
Moderator
Posts: 9965
Joined: 04 May 2010, 18:38
OTRS Version?: 5.0.x
Location: SouthWest Florida, USA
Contact:

toolbar to show hours billed today

Postby 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/myToolBarTicketHours.pm :

Code: Select all

# --
# Kernel/Output/HTML/myToolBarTicketHours.pm
# --
# 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 http://www.gnu.org/licenses/agpl.txt.
# --

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

use strict;
use warnings;

use Kernel::Language qw(Translatable);

our @ObjectDependencies = (
        'Kernel::System::Log',
        'Kernel::System::Ticket',
        'Kernel::System::DB',
        'Kernel::Output::HTML::Layout',
);

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{$_} ) {

            $Kernel::OM->Get('Kernel::System::Log')->Log(
                Priority => 'error',
                Message  => "Need $_!"
            );
            return;
        }
    }

    # 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;
}

1;


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>
        <Group>Ticket</Group>
        <SubGroup>Frontend::Agent::ToolBarModule</SubGroup>
        <Setting>
            <Hash>
                <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>
            </Hash>
        </Setting>
    </ConfigItem>
</otrs_config>


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

Return to “Howtos”

Who is online

Users browsing this forum: No registered users and 2 guests