1 % if ( $conf->exists('dashboard-toplist') ) {
3 <& /elements/table-grid.html &>
5 % my $bgcolor1 = '#eeeeee';
6 % my $bgcolor2 = '#ffffff';
7 % my $bgcolor = $bgcolor2;
9 % foreach my $line ( $conf->config('dashboard-toplist') ) {
11 % if ( $bgcolor eq $bgcolor1 ) {
12 % $bgcolor = $bgcolor2;
14 % $bgcolor = $bgcolor1;
17 % if ( $line =~ /^\s*cust_main:\s*(\d+)\s*$/ ) { #customer line
19 % my $cust_main = qsearchs('cust_main', { 'custnum' => $custnum } );
23 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
24 <A HREF="view/cust_main.cgi?<% $custnum %>"><% $cust_main->name %></A>
26 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
27 <& /elements/mcp_lint.html, 'cust_main'=>$cust_main &>
29 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="right">
31 <A HREF="<% FS::TicketSystem->href_new_ticket($cust_main) %>"><% mt('(new ticket)') |h %></A>
35 % foreach my $priority ( @custom_priorities ) {
36 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>" ALIGN="right">
37 % my $num = $num_tickets_by_priority{$priority}->{$custnum};
40 FS::TicketSystem->href_customer_tickets($custnum,$priority)
43 % exists($num_tickets_by_priority{''}{$custnum}) ) {
44 % # decrement the customer's total by the number in
46 % $num_tickets_by_priority{''}{$custnum} -= $num;
56 <TD CLASS="grid" BGCOLOR="<% $bgcolor %>">
57 <% mt("Unknown customer number [_1]", $custnum) |h %>
63 % } elsif ( $line =~ /^\-\-+$/ ) { #divider
66 <TH CLASS="grid" COLSPAN="<% scalar(@custom_priorities) + 4 %>"></TH>
71 % } elsif ( $line =~ /^\s*$/ ) {
74 <TD CLASS="grid" COLSPAN="<% scalar(@custom_priorities) + 4 %>" BGCOLOR="<% $bgcolor %>"> </TD>
77 % } elsif ( $line =~ /^\S/ ) { #label line
80 <TH CLASS="grid" BGCOLOR="#cccccc"><% $line %></TH>
81 <TH CLASS="grid" BGCOLOR="#cccccc"><% mt('Lint') |h %></TH>
82 <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
83 % foreach my $priority ( @custom_priorities ) {
84 <TH CLASS="grid" BGCOLOR="#cccccc">
85 <% $priority || '<i>(none)</i>'%>
90 % } else { #regular line
93 <TD CLASS="grid" COLSPAN="<% scalar(@custom_priorities) + 4 %>" BGCOLOR="<% $bgcolor %>"><% $line %></TD>
107 my $conf = new FS::Conf;
109 #false laziness w/httemplate/search/cust_main.cgi... care if
110 # custom_priority_field becomes anything but a local hack...
112 my @custom_priorities = ();
113 my $custom_priority_field = $conf->config('ticket_system-custom_priority_field');
114 if ( $custom_priority_field
115 && @{[ $conf->config('ticket_system-custom_priority_field-values') ]} ) {
117 $conf->config('ticket_system-custom_priority_field-values');
119 push @custom_priorities, '';
121 my %num_tickets_by_priority = map { $_ => {} } @custom_priorities;
122 # "optimization" (i.e. "terrible hack") to avoid constructing
123 # (@custom_priorities) x (cust_main) queries with a bazillion
124 # joins each just to count tickets
125 if ( $FS::TicketSystem::system eq 'RT_Internal' ) {
126 my $text = (driver_name =~ /^Pg/) ? 'text' : 'char';
127 # The RT API does not play nicely with aggregate queries,
128 # so we're going to go around it.
130 "SELECT cust_main.custnum AS custnum,
131 ObjectCustomFieldValues.Content as priority,
132 COUNT(DISTINCT Tickets.Id) AS num_tickets
134 LEFT JOIN cust_pkg USING (custnum)
135 LEFT JOIN cust_svc USING (pkgnum)
137 ( Links.Target = 'freeside://freeside/cust_main/' || CAST(cust_main.custnum AS $text) OR
138 Links.Target = 'freeside://freeside/cust_svc/' || CAST(cust_svc.svcnum AS $text)
140 Links.Base LIKE '%rt://%/ticket/%' AND
141 Links.Type = 'MemberOf'
143 JOIN Tickets ON (Links.LocalBase = Tickets.Id)
144 LEFT JOIN ObjectCustomFields ON (
145 ObjectCustomFields.ObjectId = '0' OR
146 ObjectCustomFields.ObjectId = Tickets.Queue
148 LEFT JOIN CustomFields ON (
149 ObjectCustomFields.CustomField = CustomFields.Id AND
150 CustomFields.Name = '$custom_priority_field'
152 LEFT JOIN ObjectCustomFieldValues ON (
153 ObjectCustomFieldValues.CustomField = CustomFields.Id AND
154 ObjectCustomFieldValues.ObjectType = 'RT::Ticket' AND
155 ObjectCustomFieldValues.Disabled = '0' AND
156 ObjectCustomFieldValues.ObjectId = Tickets.Id
158 GROUP BY cust_main.custnum, ObjectCustomFieldValues.Content";
160 my $sth = dbh->prepare($sql) or die dbh->errstr;
161 $sth->execute or die $sth->errstr;
162 while ( my $row = $sth->fetchrow_hashref ) {
163 #warn to_json($row)."\n";
164 $num_tickets_by_priority{ $row->{priority} }->{ $row->{custnum} } =