selfservice priority sort order, #14029
[freeside.git] / httemplate / view / cust_main / tickets.html
index 2175110..adfaead 100644 (file)
@@ -12,8 +12,7 @@ function updateTicketLink() {
 <A id="CreateTicketLink" HREF="<% $new_link %>"><% mt('Create new ticket') |h %></A>
  <% mt('in queue') |h %> 
 %# fetch list of queues in which the user can create tickets
-% my $session = FS::TicketSystem->session();
-% my %queues = FS::TicketSystem->queues($session, 'CreateTicket');
+% my %queues = FS::TicketSystem->queues('', 'CreateTicket');
 % if( $conf->exists('ticket_system-force_default_queueid') ) {
 <B><% $queues{$new_param{'Queue'}} %></B>
 <INPUT TYPE="hidden" NAME="Queue" VALUE="<% $new_param{'Queue'} %>">
@@ -46,7 +45,12 @@ function updateTicketLink() {
   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Status') |h %></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Queue') |h %></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Owner') |h %></TH>
+  <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Due') |h %></TH>
+  <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Estimated Time') |h %></TH>
   <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Priority') |h %></TH>
+% if ( $ss_priority ) {
+  <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Customer Priority') |h %></TH>
+% }
 </TR>
 
 % foreach my $ticket ( @tickets ) {
@@ -78,6 +82,14 @@ function updateTicketLink() {
     <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
       <% $ticket->{owner} %>
     </TD>
+
+    <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
+      <% $date_formatter->($ticket->{due}) %>
+    </TD>
+
+    <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+      <% $ticket->{timeestimated} %>
+    </TD>
   
     <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
       <% $ticket->{content}
@@ -85,7 +97,13 @@ function updateTicketLink() {
            : $ticket->{priority}
       %>
     </TD>
-  
+
+%   if ( $ss_priority ) {
+    <TD ALIGN="right" CLASS="grid" BGCOLOR="<% $bgcolor %>">
+      <% $ticket->{"CF.{$ss_priority}"} %>
+    </TD>
+%   }
+
   </TR>
 
 % } 
@@ -93,6 +111,8 @@ function updateTicketLink() {
 </TABLE>
 
 <%init>
+use Date::Format 'time2str';
+use Date::Parse 'str2time';
 
 my( $conf ) = new FS::Conf;
 my( $cust_main ) = @_;
@@ -111,4 +131,33 @@ my( $new_base, %new_param ) =
 
 my $new_link = FS::TicketSystem->href_new_ticket( $cust_main );
 
+my $ss_priority = FS::TicketSystem->selfservice_priority;
+if ( $ss_priority ) {
+  my $dir = $conf->exists('ticket_system-priority_reverse') ? -1 : 1;
+  use sort 'stable';
+  # sort in the following way:
+  @tickets = sort { 
+    # within a severity level...
+    ( $a->{'content'} eq $b->{'content'} ) ? (
+      # no-priority tickets sort last
+      (
+        ($a->{'_selfservice_priority'} eq '') <=> 
+        ($b->{'_selfservice_priority'} eq '')
+      ) ||
+      # otherwise obey ticket_system-priority_reverse
+      ( $dir * 
+        ($b->{'_selfservice_priority'} <=> $a->{'_selfservice_priority'})
+      )
+    ) : 0; # but don't rearrange between severity levels
+  } @tickets;
+}
+
+my $format = $conf->config('date_format') || '%Y-%m-%d';
+
+my $date_formatter = sub {
+  my $time = str2time($_[0], 'GMT');
+  # exclude times within 24 hours of zero
+  ($time > 86400) ? time2str($format, $time) : '';
+};
+
 </%init>