X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fsearch%2Frt_transaction.html;h=aace4e9b23b1185d2f9598041dfaed7a0147eedb;hp=ab563634725b2b7ddaf9acb11296b9f11152c777;hb=3146245f510ef873c4176bc06dc891f990db8f1e;hpb=0fb307c305e4bc2c9c27dc25a3308beae3a4d33c diff --git a/httemplate/search/rt_transaction.html b/httemplate/search/rt_transaction.html index ab5636347..aace4e9b2 100644 --- a/httemplate/search/rt_transaction.html +++ b/httemplate/search/rt_transaction.html @@ -1,14 +1,15 @@ -<% include('elements/search.html', +<& elements/search.html, 'title' => 'Time worked', 'name_singular' => 'transaction', 'query' => $query, 'count_query' => $count_query, - 'count_addl' => [ $format_seconds_sub, $format_seconds_sub, ], + 'count_addl' => [ $format_seconds_sub, + $applied_time ? $format_seconds_sub : () ], 'header' => [ 'Ticket #', 'Ticket', 'Date', 'Time', - 'Applied', + $applied_time ? 'Applied' : (), ], 'fields' => [ 'ticketid', sub { encode_entities(shift->get('subject')) }, @@ -16,9 +17,10 @@ sub { my $seconds = shift->get('transaction_time'); &{ $format_seconds_sub }( $seconds ); }, - sub { my $seconds = shift->get('support'); + ($applied_time ? + sub { my $seconds = shift->get('applied_time'); &{ $format_seconds_sub }( $seconds ); - }, + } : () ), ], 'links' => [ $link, @@ -27,8 +29,7 @@ '', '', ], - ) -%> +&> <%once> my $format_seconds_sub = sub { @@ -44,33 +45,70 @@ $seconds)%3600)/60)."m"; die "access denied" unless $FS::CurrentUser::CurrentUser->access_right('List rating data'); +local $FS::Record::nowarn_classload = 1; #some amount of false laziness w/timeworked.html... -my $transactiontime = " - CASE transactions.type when 'Set' - THEN (to_number(newvalue,'999999')-to_number(oldvalue, '999999')) * 60 - ELSE timetaken*60 - END -"; +my @select = ( + 'Transactions.*', + 'Tickets.Id AS ticketid', + 'Tickets.Subject', + 'Users.name AS otaker', +); +my @select_total = ( 'COUNT(*)' ); +my $transaction_time; +my $applied_time = ''; my $join = 'JOIN Tickets ON Transactions.ObjectId = Tickets.Id '. - 'JOIN Users ON Transactions.Creator = Users.Id '; #. -# 'LEFT JOIN acct_rt_transaction '. -# ' ON Transactions.Id = acct_rt_transaction.transaction_id'; -my $where = " - WHERE objecttype='RT::Ticket' - AND ( ( Transactions.Type = 'Set' - AND Transactions.Field = 'TimeWorked' - AND Transactions.NewValue != Transactions.OldValue ) - OR ( ( Transactions.Type='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' ) - AND Transactions.TimeTaken > 0 - ) - ) + 'JOIN Users ON Transactions.Creator = Users.Id '. + "LEFT JOIN ( + SELECT DISTINCT ON (ObjectId) + ObjectId, Content + FROM ObjectCustomFieldValues + JOIN CustomFields + ON (ObjectCustomFieldValues.CustomField = CustomFields.Id) + WHERE CustomFields.Name = 'TimeType' + AND ObjectCustomFieldValues.ObjectType = 'RT::Ticket' + AND ObjectCustomFieldValues.Disabled = 0 + ORDER BY ObjectId ASC, ObjectCustomFieldValues.LastUpdated DESC + ) AS ocfv_TimeType ON (Tickets.Id = ocfv_TimeType.ObjectId) + "; + +my $where = "WHERE Transactions.ObjectType = 'RT::Ticket'"; + +# the intrinsic TimeWorked/TimeTaken fields +$transaction_time = "CASE Transactions.Type when 'Set' + THEN (to_number(NewValue,'999999')-to_number(OldValue, '999999')) * 60 + ELSE TimeTaken*60 + END"; + +my $applied = ''; +if ( $cgi->param('svcnum') =~ /^\s*(\d+)\s*$/ ) { + $where .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )"; + $applied = "AND svcnum = $1"; +} + +$applied_time = "( SELECT SUM(support) from acct_rt_transaction where transaction_id = Transactions.id $applied )"; + +$where .= " + AND ( ( Transactions.Type = 'Set' + AND Transactions.Field = 'TimeWorked' + AND Transactions.NewValue != Transactions.OldValue ) + OR ( ( Transactions.Type='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' OR Transactions.Type='Touch' ) + AND Transactions.TimeTaken > 0 + ) + ) "; -#AND transaction_time != 0 -#AND $wheretimeleft -my $support = ''; +if ( $cgi->param('category') =~ /^(\w+)$/ ) { + $where .= " AND ocfv_TimeType.Content = '$1'"; +} + +push @select, "($transaction_time) AS transaction_time"; +push @select_total, "SUM($transaction_time)"; +if ( $applied_time ) { + push @select, "($applied_time) AS applied_time"; + push @select_total, "SUM($applied_time)"; +} my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi); # TIMESTAMP is Pg-specific... ? @@ -91,22 +129,8 @@ if ( $cgi->param('ticketid') =~ /^\s*(\d+)\s*$/ ) { $where .= " AND Tickets.Id = $1"; } -if ( $cgi->param('svcnum') =~ /^\s*(\d+)\s*$/ ) { - $where .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )"; - $support = "AND svcnum = $1"; -} - -my $support_time = "( SELECT SUM(support) from acct_rt_transaction where transaction_id = Transactions.id $support )"; - my $query = { - 'select' => join(', ', - 'Transactions.*', - 'Tickets.Id AS ticketid', - 'Tickets.Subject', - 'Users.name AS otaker', - "$transactiontime AS transaction_time", - "$support_time AS support", - ), + 'select' => join(', ', @select), 'table' => 'transactions', #Pg-ism #'table' => 'Transactions', 'addl_from' => $join, @@ -114,12 +138,7 @@ my $query = { 'order by' => 'ORDER BY Created', }; -my $count_query = - #"SELECT COUNT(*), SUM($transactiontime), SUM(acct_rt_transaction.support) FROM Transactions $join $where"; - "SELECT COUNT(*), - SUM($transactiontime), - SUM($support_time) - FROM Transactions $join $where"; +my $count_query = 'SELECT '.join(', ', @select_total). " FROM Transactions $join $where"; my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('ticketid'); } ];