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 |h %></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 and $conf->config('dashboard-toplist') )
128 my $text = (driver_name =~ /^Pg/) ? 'text' : 'char';
129 # The RT API does not play nicely with aggregate queries,
130 # so we're going to go around it.
132 # optimization to keep this from taking a million years
134 "SELECT custnum, Tickets.Id, Tickets.Queue
137 Links.Target = 'freeside://freeside/cust_main/' || CAST(cust_main.custnum AS $text)
138 AND Links.Base LIKE '%rt://%/ticket/%'
139 AND Links.Type = 'MemberOf'
140 ) JOIN Tickets ON (Links.LocalBase = Tickets.Id)
142 SELECT custnum, Tickets.Id, Tickets.Queue
143 FROM cust_pkg JOIN cust_svc USING (pkgnum)
145 Links.Target = 'freeside://freeside/cust_svc/' || CAST(cust_svc.svcnum AS $text)
146 AND Links.Base LIKE '%rt://%/ticket/%'
147 AND Links.Type = 'MemberOf'
148 ) JOIN Tickets ON (Links.LocalBase = Tickets.Id)
151 if ( $custom_priority_field ) {
153 "SELECT cust_tickets.custnum AS custnum,
154 ObjectCustomFieldValues.Content as priority,
155 COUNT(DISTINCT cust_tickets.Id) AS num_tickets
156 FROM ($cust_tickets) AS cust_tickets
157 LEFT JOIN ObjectCustomFields ON (
158 ObjectCustomFields.ObjectId = '0' OR
159 ObjectCustomFields.ObjectId = cust_tickets.Queue
161 LEFT JOIN CustomFields ON (
162 ObjectCustomFields.CustomField = CustomFields.Id AND
163 CustomFields.Name = '$custom_priority_field'
165 LEFT JOIN ObjectCustomFieldValues ON (
166 ObjectCustomFieldValues.CustomField = CustomFields.Id AND
167 ObjectCustomFieldValues.ObjectType = 'RT::Ticket' AND
168 ObjectCustomFieldValues.Disabled = '0' AND
169 ObjectCustomFieldValues.ObjectId = cust_tickets.Id
171 GROUP BY cust_tickets.custnum, ObjectCustomFieldValues.Content";
172 } else { # no custom_priority_field
174 "SELECT cust_tickets.custnum,
176 COUNT(DISTINCT cust_tickets.Id) AS num_tickets
177 FROM ($cust_tickets) AS cust_tickets
178 GROUP BY cust_tickets.custnum";
180 my $sth = dbh->prepare($sql) or die dbh->errstr;
181 $sth->execute or die $sth->errstr;
182 while ( my $row = $sth->fetchrow_hashref ) {
183 $num_tickets_by_priority{ $row->{priority} }->{ $row->{custnum} } =