toolbar to show hours billed today

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

Moderator: crythias

Forum rules
Dont create your support topics here! No new topics with questions allowed!
Post Reply
crythias
Moderator
Posts: 10169
Joined: 04 May 2010, 18:38
Znuny Version: 5.0.x
Location: SouthWest Florida, USA
Contact:

toolbar to show hours billed today

Post by crythias »

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 6.0.x (private/testing/public) on Linux with MySQL database.
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
zerozone74
Znuny newbie
Posts: 12
Joined: 30 Jan 2019, 15:20
Znuny Version: 6.0.12
Real Name: Przemysław Słomianski
Company: None

Re: toolbar to show hours billed today

Post by zerozone74 »

For 6 Version:

myToolBarTicketHours.pm
Modify (current_date):

Code: Select all

SQL  => 'SELECT sum(time_unit) FROM time_accounting WHERE DATE(create_time) = current_date AND create_by = ?',
If You have time in DD:HH:MM add in file:

Code: Select all

sub Min2String
{
    use integer;
    my $min = shift;
    return "$min" if $min < 60;

    my $hrs = $min / 60, $min %= 60;
    $min = "0$min" if $min < 10;
    return "$hrs:$min" if $hrs < 24;

    my $days = $hrs / 24, $hrs %= 24;
    $hrs = "0$hrs" if $hrs < 10;
    return "$days:$hrs:$min";
}
and change:

Code: Select all

       #Count => $Hours,
       Count => Min2String($Hours),

XML in Kernel\Config\Files\XML\myToolBarHours.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8" ?>
<otrs_config version="2.0" init="Application">
    <Setting 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>
        <Navigation>Frontend::Agent::ToolBarModule</Navigation>
        <Value>
            <Hash>
                <Item Key="Module">Kernel::Output::HTML::ToolBar::myToolBarTicketHours</Item>
                <Item Key="Title">Hours</Item>
                <Item Key="Icon">fa fa-dollar</Item>
                <Item Key="AccessKey">q</Item>
                <Item Key="Priority">1030090</Item>
            </Hash>
        </Value>
    </Setting>
</otrs_config>
Post Reply