[freeside-commits] branch FREESIDE_2_3_BRANCH updated. 6eb0f0051879bef89f5bbe6118021e475a929876
Mark Wells
mark at 420.am
Tue Apr 10 16:05:34 PDT 2012
The branch, FREESIDE_2_3_BRANCH has been updated
via 6eb0f0051879bef89f5bbe6118021e475a929876 (commit)
from 80bca2a25e82138ee74329721a534d849e408ecd (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 6eb0f0051879bef89f5bbe6118021e475a929876
Author: Mark Wells <mark at freeside.biz>
Date: Tue Apr 10 16:05:00 2012 -0700
time worked reports for RT custom fields, #17230
diff --git a/httemplate/elements/select-rt-customfield.html b/httemplate/elements/select-rt-customfield.html
new file mode 100644
index 0000000..7a45bb1
--- /dev/null
+++ b/httemplate/elements/select-rt-customfield.html
@@ -0,0 +1,34 @@
+<SELECT NAME="<% $opt{name} %>">
+% while ( @fields ) {
+<OPTION VALUE="<% shift @fields %>"><% shift @fields %></OPTION>
+% }
+</SELECT>
+<%once>
+RT::Init();
+</%once>
+<%init>
+my %opt = @_;
+my $lookuptype = $opt{lookuptype};
+my $valuetype = $opt{valuetype};
+# get a list of TimeValue-type custom fields
+my $CurrentUser = RT::CurrentUser->new();
+$CurrentUser->LoadByName($FS::CurrentUser::CurrentUser->username);
+die "RT not configured" unless $CurrentUser->id;
+my $CFs = RT::CustomFields->new($CurrentUser);
+
+$CFs->Limit(FIELD => 'LookupType',
+ OPERATOR => 'ENDSWITH',
+ VALUE => $lookuptype)
+ if $lookuptype;
+
+$CFs->Limit(FIELD => 'Type',
+ VALUE => $valuetype)
+ if $valuetype;
+
+my @fields;
+push @fields, '', $opt{empty_label} if exists($opt{empty_label});
+
+while (my $CF = $CFs->Next) {
+ push @fields, $CF->Name, ($CF->Description || $CF->Name);
+}
+</%init>
diff --git a/httemplate/search/report_rt_ticket.html b/httemplate/search/report_rt_ticket.html
index 79a601b..f0d7a42 100644
--- a/httemplate/search/report_rt_ticket.html
+++ b/httemplate/search/report_rt_ticket.html
@@ -6,10 +6,20 @@
<% include ( '/elements/tr-input-beginning_ending.html' ) %>
+ <& /elements/tr-td-label.html, label => 'Time category:' &>
+ <TD>
+ <& /elements/select-rt-customfield.html,
+ name => 'cfname',
+ lookuptype => 'RT::Transaction',
+ valuetype => 'TimeValue',
+ empty_label => 'Worked',
+ &>
+ </TD></TR>
+
<% include ( '/elements/tr-select-otaker.html' ) %>
<TR>
- <TD>Account</TD>
+ <TD ALIGN="right">Account:</TD>
<TD>
<SELECT NAME="svcnum">
<OPTION VALUE="">(all)
@@ -48,4 +58,24 @@ if ( @pkgparts ) {
});
}
+# get a list of TimeValue-type custom fields
+RT::Init();
+my $CurrentUser = RT::CurrentUser->new();
+$CurrentUser->LoadByName($FS::CurrentUser::CurrentUser->username);
+die "RT not configured" unless $CurrentUser->id;
+my $CFs = RT::CustomFields->new($CurrentUser);
+
+$CFs->Limit(FIELD => 'LookupType',
+ OPERATOR => 'ENDSWITH',
+ VALUE => 'RT::Transaction');
+
+$CFs->Limit(FIELD => 'Type',
+ VALUE => 'TimeValue');
+
+my @time_fields = ('', 'Worked');
+while (my $CF = $CFs->Next) {
+ push @time_fields, $CF->Name, ($CF->Description || $CF->Name);
+}
+
+
</%init>
diff --git a/httemplate/search/report_rt_transaction.html b/httemplate/search/report_rt_transaction.html
index 0232b80..b8454d9 100644
--- a/httemplate/search/report_rt_transaction.html
+++ b/httemplate/search/report_rt_transaction.html
@@ -6,6 +6,17 @@
<% include ( '/elements/tr-input-beginning_ending.html' ) %>
+ <& /elements/tr-td-label.html, label => 'Time category:' &>
+ <TD>
+ <& /elements/select-rt-customfield.html,
+ name => 'cfname',
+ lookuptype => 'RT::Transaction',
+ valuetype => 'TimeValue',
+ empty_label => 'Worked',
+ &>
+ </TD></TR>
+
+
<% include ( '/elements/tr-select-otaker.html' ) %>
<% include ( '/elements/tr-input-text.html',
@@ -15,7 +26,7 @@
%>
<TR>
- <TD>Account</TD>
+ <TD ALIGN="right">Account:</TD>
<TD>
<SELECT NAME="svcnum">
<OPTION VALUE="">(all)
diff --git a/httemplate/search/rt_ticket.html b/httemplate/search/rt_ticket.html
index 7ffe55f..1ed5a38 100644
--- a/httemplate/search/rt_ticket.html
+++ b/httemplate/search/rt_ticket.html
@@ -3,25 +3,27 @@
'name_singular' => 'ticket',
'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',
'Time',
- 'Applied',
+ $applied_time ? 'Applied' : (),
],
'fields' => [ 'ticketid',
sub { encode_entities(shift->get('subject')) },
- sub { my $seconds = shift->get('transaction_time');
+ sub { my $seconds = shift->get('ticket_time');
&{ $format_seconds_sub }( $seconds );
},
- sub { my $seconds = shift->get('support');
+ ($applied_time ?
+ sub { my $seconds = shift->get('applied_time');
&{ $format_seconds_sub }( $seconds );
- },
+ } : () ),
],
'sort_fields' => [ 'ticketid',
'subject',
'transaction_time',
- 'support_time',
+ $applied_time ? 'applied_time' : (),
],
'links' => [
$link,
@@ -48,34 +50,87 @@ $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 = (
+ 'Tickets.Id AS ticketid',
+ 'Tickets.Subject'
+);
+my @select_total = ( 'COUNT(*)' );
+my ($transaction_time, $applied_time);
my $join = 'JOIN Users ON Transactions.Creator = Users.Id '; #.
-# 'LEFT JOIN acct_rt_transaction '.
-# ' ON Transactions.Id = acct_rt_transaction.transaction_id';
my $twhere = "
- WHERE objecttype='RT::Ticket'
- AND Transactions.ObjectId = Tickets.Id
+ WHERE Transactions.ObjectType = 'RT::Ticket'
+ AND Transactions.ObjectId = Tickets.Id
+";
+
+my $cfname = '';
+if ( $cgi->param('cfname') =~ /^\w(\w|\s)*$/ ) {
+
+ $cfname = $cgi->param('cfname');
+
+ $transaction_time = "(CASE Transactions.Type
+ WHEN 'CustomField' THEN
+ ( coalesce(to_number(ocfv_new.Content,'999999'),0)
+ - coalesce(to_number(ocfv_old.Content,'999999'),0) )
+ ELSE ( to_number(ocfv_main.Content,'999999') )
+ END) * 60";
+
+ $join .= "
+ LEFT JOIN ObjectCustomFieldValues ocfv_new
+ ON ( ocfv_new.Id = Transactions.NewReference )
+ LEFT JOIN ObjectCustomFieldValues ocfv_old
+ ON ( ocfv_old.Id = Transactions.OldReference )
+ LEFT JOIN ObjectCustomFieldValues ocfv_main
+ ON ( ocfv_main.ObjectType = 'RT::Transaction'
+ AND ocfv_main.ObjectId = Transactions.Id )
+ JOIN CustomFields
+ ON ( ( CustomFields.LookupType = 'RT::Queue-RT::Ticket-RT::Transaction'
+ AND CustomFields.Id = ocfv_main.CustomField
+ AND ocfv_main.Id IS NOT NULL
+ )
+ OR
+ ( CustomFields.LookupType = 'RT::Queue-RT::Ticket'
+ AND (CustomFields.Id = ocfv_new.CustomField OR ocfv_new.Id IS NULL)
+ AND (CustomFields.Id = ocfv_old.CustomField OR ocfv_old.Id IS NULL)
+ AND ocfv_main.Id IS NULL
+ ) )
+ ";
+
+ $twhere .= " AND CustomFields.Name = '$cfname'
+ AND (ocfv_new.Id IS NOT NULL OR ocfv_old.Id IS NOT NULL OR ocfv_main.Id IS NOT NULL)";
+
+}
+else {
+ $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*$/ ) {
+ $twhere .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )";
+ $applied = "AND svcnum = $1";
+ }
+
+ $twhere .= "
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='Create' OR Transactions.Type='Comment' OR Transactions.Type='Correspond' OR Transactions.Type='Touch' )
AND Transactions.TimeTaken > 0
)
- )
-";
-#AND transaction_time != 0
-#AND $wheretimeleft
+ )";
+
+ $applied_time = "( SELECT SUM(support) FROM acct_rt_transaction LEFT JOIN Transactions ON ( transaction_id = Id ) $twhere $applied )";
+
+}
-my $support = '';
my($beginning, $ending) = FS::UI::Web::parse_beginning_ending($cgi);
# TIMESTAMP is Pg-specific... ?
@@ -92,25 +147,21 @@ if ( $cgi->param('otaker') && $cgi->param('otaker') =~ /^([\w\.\-]+)$/ ) {
$twhere .= " AND Users.name = '$1' ";
}
-if ( $cgi->param('svcnum') =~ /^\s*(\d+)\s*$/ ) {
- $twhere .= " AND EXISTS( SELECT 1 FROM acct_rt_transaction WHERE acct_rt_transaction.transaction_id = Transactions.id AND svcnum = $1 )";
- $support = "AND svcnum = $1";
-}
-
my $transactions = "FROM Transactions $join $twhere";
my $where = "WHERE EXISTS ( SELECT 1 $transactions )";
-my $transaction_time = "( SELECT SUM($transactiontime) $transactions )";
-my $support_time = "( SELECT SUM(support) FROM acct_rt_transaction LEFT JOIN Transactions ON ( transaction_id = Id ) $twhere $support )";
+my $ticket_time = "( SELECT SUM($transaction_time) $transactions )";
+push @select, "$ticket_time AS ticket_time";
+push @select_total, "SUM($ticket_time)";
+
+if ( $applied_time) {
+ push @select, "$applied_time AS applied_time";
+ push @select_total, "SUM($applied_time)";
+}
my $query = {
- 'select' => join(', ',
- 'Tickets.Id AS ticketid',
- 'Tickets.Subject',
- "$transaction_time AS transaction_time",
- "$support_time AS support",
- ),
+ 'select' => join(', ', @select),
'table' => 'tickets', #Pg-ism
#'table' => 'Tickets',
'addl_from' => '', #$join,
@@ -118,13 +169,9 @@ my $query = {
'order by' => 'ORDER BY Created',
};
-my $count_query =
+my $count_query = "SELECT ".join(', ', @select_total)." FROM Tickets $where";
#"SELECT COUNT(*), SUM($transactiontime), SUM(acct_rt_transaction.support) FROM Transactions $join $where";
#"SELECT COUNT(*), ( SUM($transactiontime) $transactions ) FROM Tickets"; # $join $where";
- "SELECT COUNT(*),
- SUM( $transaction_time ),
- SUM( $support_time )
- FROM Tickets $where"; # $join $where";
my $link = [ "${p}rt/Ticket/Display.html?id=", sub { shift->get('ticketid'); } ];
diff --git a/httemplate/search/rt_transaction.html b/httemplate/search/rt_transaction.html
index ab56363..1ae607b 100644
--- a/httemplate/search/rt_transaction.html
+++ b/httemplate/search/rt_transaction.html
@@ -3,12 +3,13 @@
'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,
@@ -44,33 +46,99 @@ $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, $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'
+
+my $where = "WHERE Transactions.ObjectType = 'RT::Ticket'";
+
+my $cfname = '';
+if ( $cgi->param('cfname') =~ /^\w(\w|\s)*$/ ) {
+
+ # a TimeValue-type custom field
+ $cfname = $cgi->param('cfname');
+
+ $transaction_time = "(CASE Transactions.Type
+ WHEN 'CustomField' THEN
+ ( coalesce(to_number(ocfv_new.Content,'999999'),0)
+ - coalesce(to_number(ocfv_old.Content,'999999'),0) )
+ ELSE ( to_number(ocfv_main.Content,'999999') )
+ END) * 60";
+
+ # complicated because we have to deal with the case of editing the
+ # ticket custom field directly (OldReference/NewReference) as well as
+ # entering a transaction with a custom field value (ObjectId)
+ $join .= "
+ LEFT JOIN ObjectCustomFieldValues ocfv_new
+ ON ( ocfv_new.Id = Transactions.NewReference )
+ LEFT JOIN ObjectCustomFieldValues ocfv_old
+ ON ( ocfv_old.Id = Transactions.OldReference )
+ LEFT JOIN ObjectCustomFieldValues ocfv_main
+ ON ( ocfv_main.ObjectType = 'RT::Transaction'
+ AND ocfv_main.ObjectId = Transactions.Id )
+ JOIN CustomFields
+ ON ( ( CustomFields.LookupType = 'RT::Queue-RT::Ticket-RT::Transaction'
+ AND CustomFields.Id = ocfv_main.CustomField
+ AND ocfv_main.Id IS NOT NULL
+ )
+ OR
+ ( CustomFields.LookupType = 'RT::Queue-RT::Ticket'
+ AND (CustomFields.Id = ocfv_new.CustomField OR ocfv_new.Id IS NULL)
+ AND (CustomFields.Id = ocfv_old.CustomField OR ocfv_old.Id IS NULL)
+ AND ocfv_main.Id IS NULL
+ ) )
+ ";
+
+ $where .= " AND CustomFields.Name = '$cfname'
+ AND (ocfv_new.Id IS NOT NULL OR ocfv_old.Id IS NOT NULL OR ocfv_main.Id IS NOT NULL)";
+
+}
+else {
+
+ # 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='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 = '';
+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 +159,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 +168,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'); } ];
-----------------------------------------------------------------------
Summary of changes:
httemplate/elements/select-rt-customfield.html | 34 +++++++
httemplate/search/report_rt_ticket.html | 32 ++++++-
httemplate/search/report_rt_transaction.html | 13 +++-
httemplate/search/rt_ticket.html | 127 ++++++++++++++++--------
httemplate/search/rt_transaction.html | 127 ++++++++++++++++-------
5 files changed, 252 insertions(+), 81 deletions(-)
create mode 100644 httemplate/elements/select-rt-customfield.html
More information about the freeside-commits
mailing list