%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC %# %# %# (Except where explicitly superseded by other copyright notices) %# %# %# LICENSE: %# %# This work is made available to you under the terms of Version 2 of %# the GNU General Public License. A copy of that license should have %# been provided with this software, but in any event can be snarfed %# from www.gnu.org. %# %# This work is distributed in the hope that it will be useful, but %# WITHOUT ANY WARRANTY; without even the implied warranty of %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU %# General Public License for more details. %# %# You should have received a copy of the GNU General Public License %# along with this program; if not, write to the Free Software %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA %# 02110-1301 or visit their web page on the internet at %# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html. %# %# %# CONTRIBUTION SUBMISSION POLICY: %# %# (The following paragraph is not intended to limit the rights granted %# to you to modify and distribute this software under the terms of %# the GNU General Public License and is only of importance to you if %# you choose to contribute your changes and enhancements to the %# community by submitting them to Best Practical Solutions, LLC.) %# %# By intentionally submitting any modifications, corrections or %# derivatives to this work, or any other work intended for use with %# Request Tracker, to Best Practical Solutions, LLC, you confirm that %# you are the copyright holder for those contributions and you grant %# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable, %# royalty-free, perpetual, license to use, copy, create derivative %# works based on those contributions, and sublicense and distribute %# those contributions and any derivatives thereof. %# %# END BPS TAGGED BLOCK }}} <& /Elements/Header, Title => loc("User Time Worked") &> <& /Elements/Tabs &> <& /Elements/ListActions, actions => \@results &>
" Value = <% $User %> >
<& /Elements/SelectDate, ShowTime => 1, Name => 'StartDate', Default => $StartDate &>
<& /Elements/SelectDate, ShowTime => 1, Name => 'EndDate', Default => $EndDate &>
<& /Elements/SelectQueue, Name => 'Queue', Id => 'queue', Default => $Queue &>
% if ( $data ) {
% foreach my $delimeter (@delimeters) {

<% $data->{$delimeter}[0]{Head} %>

% my $line_type = "oddline"; % my ($total_time_mins, $total_time_hours); % foreach my $time (@{$data->{$delimeter} }) { % $line_type = $line_type eq "oddline" ? "evenline" : "oddline"; % $total_time_mins += $time->{TimeMin}; % $total_time_hours += $time->{TimeHours}; % }
<&|/l&>Id <&|/l&>Subject <&|/l&>Queue <&|/l&>Status <&|/l&>Owner <&|/l&>Time Worked <&|/l&>Worked By
{Id}" %>"><% $time->{Id} %> {Id}" %>"><% $time->{Subject} %> <% $time->{Queue} %> <% $time->{Status} %> % if ( $time->{OwnerId} != RT->Nobody->Id ) { {OwnerId}" %>"><% $time->{Owner} %> % } else { <% $time->{Owner} %> % } <% $time->{Time} %> {WorkerId}" %>"><% $time->{Worker} %>
% }
% } % elsif ( $StartDate && $EndDate ) { <&|/l&>No tickets found. % } <%INIT> my @results; my $data; my @delimeters; # if we are just getting here and the form values are empty, we are done if ( $StartDate && $EndDate ) { #### DATES #### my $start_date = RT::Date->new( $session{'CurrentUser'} ); my $end_date = RT::Date->new( $session{'CurrentUser'} ); # If we have a value for start date, parse it into an RT::Date object if ($StartDate) { $start_date->Set( Format => 'unknown', Value => $StartDate, Timezone => 'User' ); # And then get it back as an ISO string for display purposes, in the form field and # report header $StartDate = $start_date->AsString( Format => 'ISO', Timezone => 'User' ); } # Same treatment for end date if ($EndDate) { $end_date->Set( Format => 'unknown', Value => $EndDate ); $EndDate = $end_date->AsString( Format => 'ISO', Timezone => 'User' ); } # Get a new transactions object to hold transaction search results for this ticket my $trans = RT::Transactions->new( $session{'CurrentUser'} ); my $txns = RT::Transactions->new($session{CurrentUser}); $txns->Limit( FIELD => 'ObjectType', VALUE => 'RT::Ticket' ); if ( $User ) { my $user = RT::User->new( $session{'CurrentUser'} ); my ($ret, $msg) = $user->Load( $User ); if ( $ret && $user->Id ) { $txns->Limit( FIELD => 'Creator', VALUE => $user->id ) } else { push @results, loc("Could not load user, report is not limited to user: [_1]", $User); } } $txns->Limit( FIELD => 'TimeTaken', VALUE => 0, OPERATOR => '!=' ); $txns->Limit( FIELD => 'Created', VALUE => $start_date->ISO(Timezone => 'user'), OPERATOR => '>=' ); $txns->Limit( FIELD => 'Created', VALUE => $end_date->ISO(Timezone => 'user'), OPERATOR => '<', ENTRYAGGREGATOR => 'AND'); my $total_time_worked = 0; while ( my $txn = $txns->Next ) { my $ticket = $txn->TicketObj; my $worker = RT::User->new($session{'CurrentUser'}); my ($ret, $msg) = $worker->Load( $txn->Creator ); push @results, $msg unless $ret; if ( $Queue && $ticket->QueueObj ) { next unless $Queue eq $ticket->QueueObj->Id; } $total_time_worked = $total_time_worked + $txn->TimeTaken; my $time_hours = sprintf '%.2f', $txn->TimeTaken / 60; my ( $head, $delimeter ); if ( $SortBy eq 'User' ) { $head = $delimeter = loc( 'User: [_1]', $worker->Name ); } elsif ( $SortBy eq 'Ticket' ) { $head = $ticket->Id . ': ' . $ticket->Subject; $delimeter = $ticket->Id; } elsif ( $SortBy eq 'Queue' ) { $head = $delimeter = loc( 'Queue: [_1]', $ticket->QueueObj->Name ); } else { $head = $txn->CreatedObj->RFC2822( Time => 0, Timezone => 'user' ); $delimeter = $txn->CreatedObj->iCal( Time => 0 ); } push @{ $data->{$delimeter} }, { Head => $head, Id => $ticket->Id, Subject => $ticket->Subject, Queue => $ticket->QueueObj->Name, Status => $ticket->Status, OwnerId => $ticket->OwnerObj->Id, Owner => $ticket->OwnerObj->Name, Time => $time_hours > 1 ? loc( '[_1] hours ([_2] minutes)', $time_hours, $txn->TimeTaken ) : loc( '[_1] minutes', $txn->TimeTaken ), TimeMin => $txn->TimeTaken, TimeHours => $time_hours, Worker => $worker->Name, WorkerId => $worker->Id, }; } @delimeters = keys %$data; if ( $SortBy =~ /Ticket|Date/ ) { @delimeters = sort { $a <=> $b } keys %$data; } else { @delimeters = sort { lc $a cmp lc $b } keys %$data; } } <%ARGS> $StartDate => '' $EndDate => '' $User => '' $SortBy => 'Date' $Queue => ''