my $total = 0;
my(@cust_main, $sortby, $orderby);
+my @select = ();
+my @addl_headers = ();
+my @addl_cols = ();
if ( $cgi->param('browse')
|| $cgi->param('otaker_on')
|| $cgi->param('agentnum_on')
) {
my %search = ();
+
if ( $cgi->param('browse') ) {
my $query = $cgi->param('browse');
if ( $query eq 'custnum' ) {
} elsif ( $query eq 'company' ) {
$sortby=\*company_sort;
$orderby = "ORDER BY LOWER(company || ' ' || last || ' ' || first )";
+ } elsif ( $query eq 'tickets' ) {
+ $sortby = \*tickets_sort;
+ $orderby = "ORDER BY tickets DESC";
+ push @select, FS::TicketSystem->sql_num_customer_tickets. " as tickets";
+ push @addl_headers, 'Tickets';
+ push @addl_cols, 'tickets';
} else {
die "unknown browse field $query";
}
} else {
$sortby = \*last_sort; #??
$orderby = "ORDER BY LOWER(last || ' ' || first)"; #??
- if ( $cgi->param('otaker_on') ) {
- $cgi->param('otaker') =~ /^(\w{1,32})$/ or eidiot "Illegal otaker\n";
- $search{otaker} = $1;
- } elsif ( $cgi->param('agentnum_on') ) {
- $cgi->param('agentnum') =~ /^(\d+)$/ or eidiot "Illegal agentnum\n";
- $search{agentnum} = $1;
- } else {
- die "unknown query...";
- }
+ }
+
+ if ( $cgi->param('otaker_on') ) {
+ $cgi->param('otaker') =~ /^(\w{1,32})$/ or eidiot "Illegal otaker\n";
+ $search{otaker} = $1;
+ } elsif ( $cgi->param('agentnum_on') ) {
+ $cgi->param('agentnum') =~ /^(\d+)$/ or eidiot "Illegal agentnum\n";
+ $search{agentnum} = $1;
+# } else {
+# die "unknown query...";
}
my @qual = ();
&& ! $cgi->param('showcancelledcustomers') )
) {
#grep { $_->ncancelled_pkgs || ! $_->all_pkgs }
- push @qual, "
- ( 0 < ( SELECT COUNT(*) FROM cust_pkg
- WHERE cust_pkg.custnum = cust_main.custnum
- AND ( cust_pkg.cancel IS NULL
- OR cust_pkg.cancel = 0
- )
- )
- OR 0 = ( SELECT COUNT(*) FROM cust_pkg
- WHERE cust_pkg.custnum = cust_main.custnum
- )
- )
- ";
+ push @qual, FS::cust_main->uncancel_sql;
+
}
push @qual, FS::cust_main->cancel_sql if $cgi->param('cancelled');
my $addl_qual = join(' AND ', @qual);
+ #here is the agent virtualization
+ $addl_qual .= ( $addl_qual ? ' AND ' : '' ).
+ $FS::CurrentUser::CurrentUser->agentnums_sql;
+
if ( $addl_qual ) {
$qual .= ' AND ' if $qual;
$qual .= $addl_qual;
}
}
- @cust_main = qsearch('cust_main', \%search, '',
+ my $select;
+ if ( @select ) {
+ $select = 'cust_main.*, '. join (', ', @select);
+ } else {
+ $select = '*';
+ }
+
+ @cust_main = qsearch('cust_main', \%search, $select,
"$addl_qual $orderby $limit" );
# foreach my $cust_main ( @just_cust_main ) {
push @cust_main, @{&companysearch};
}
+ if ( $cgi->param('search_cust') ) {
+ $sortby = \*company_sort;
+ $orderby = "ORDER BY LOWER(company || ' ' || last || ' ' || first )";
+ warn "smart searching for: ". $cgi->param('search_cust');
+ push @cust_main, smart_search( 'search' => $cgi->param('search_cust') );
+ }
+
@cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main
if ! $cgi->param('cancelled')
&& (
eidiot "No matching customers found!\n";
} else {
%>
-<!-- mason kludge -->
-<%
+<%= include('/elements/header.html', "Customer Search Results", '' ) %>
- $total ||= scalar(@cust_main);
- print header("Customer Search Results",menubar(
- 'Main Menu', popurl(2)
- )), "$total matching customers found ";
+ <% $total ||= scalar(@cust_main); %>
+ <%= $total %> matching customers found
+
+ <%
#begin pager
my $pager = '';
if ( $total != scalar(@cust_main) && $maxrecords ) {
}
print ' cancelled customers</a> )';
}
+
if ( $cgi->param('referral_custnum') ) {
$cgi->param('referral_custnum') =~ /^(\d+)$/
or eidiot "Illegal referral_custnum\n";
my $referral_custnum = $1;
my $cust_main = qsearchs('cust_main', { custnum => $referral_custnum } );
- print '<FORM METHOD=POST>'.
+ print '<FORM METHOD="GET">'.
qq!<INPUT TYPE="hidden" NAME="referral_custnum" VALUE="$referral_custnum">!.
'referrals of <A HREF="'. popurl(2).
"view/cust_main.cgi?$referral_custnum\">$referral_custnum: ".
'</FORM>';
}
- print "<BR><BR>". $pager. &table(). <<END;
+ my @custom_priorities = ();
+ if ( $conf->config('ticket_system-custom_priority_field')
+ && @{[ $conf->config('ticket_system-custom_priority_field-values') ]} ) {
+ @custom_priorities =
+ $conf->config('ticket_system-custom_priority_field-values');
+ }
+
+ print "<BR><BR>". $pager. include('/elements/table-grid.html'). <<END;
<TR>
- <TH></TH>
- <TH>(bill) name</TH>
- <TH>company</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc"></TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">(bill) name</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
END
if ( defined dbdef->table('cust_main')->column('ship_last') ) {
print <<END;
- <TH>(service) name</TH>
- <TH>company</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">(service) name</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">company</TH>
END
}
+foreach my $addl_header ( @addl_headers ) {
+ print '<TH CLASS="grid" BGCOLOR="#cccccc">'. "$addl_header</TH>";
+}
+
print <<END;
- <TH>Packages</TH>
- <TH COLSPAN=2>Services</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc">Packages</TH>
+ <TH CLASS="grid" BGCOLOR="#cccccc" COLSPAN=2>Services</TH>
</TR>
END
+ my $bgcolor1 = '#eeeeee';
+ my $bgcolor2 = '#ffffff';
+ my $bgcolor;
+
my(%saw,$cust_main);
- my $p = popurl(2);
foreach $cust_main (
sort $sortby grep(!$saw{$_->custnum}++, @cust_main)
) {
+
+ if ( $bgcolor eq $bgcolor1 ) {
+ $bgcolor = $bgcolor2;
+ } else {
+ $bgcolor = $bgcolor1;
+ }
+
my($custnum,$last,$first,$company)=(
$cust_main->custnum,
$cust_main->getfield('last'),
my $pcompany = $company
? qq!<A HREF="$view"><FONT SIZE=-1>$company</FONT></A>!
: '<FONT SIZE=-1> </FONT>';
- print <<END;
+ %>
+
<TR>
- <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$custnum</FONT></A></TD>
- <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$last, $first</FONT></A></TD>
- <TD ROWSPAN=$rowspan>$pcompany</TD>
-END
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= $custnum %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$last, $first" %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><%= $pcompany %></TD>
+
+ <%
if ( defined dbdef->table('cust_main')->column('ship_last') ) {
my($ship_last,$ship_first,$ship_company)=(
$cust_main->ship_last || $cust_main->getfield('last'),
my $pship_company = $ship_company
? qq!<A HREF="$view"><FONT SIZE=-1>$ship_company</FONT></A>!
: '<FONT SIZE=-1> </FONT>';
- print <<END;
- <TD ROWSPAN=$rowspan><A HREF="$view"><FONT SIZE=-1>$ship_last, $ship_first</FONT></A></TD>
- <TD ROWSPAN=$rowspan>$pship_company</A></TD>
-END
+ %>
+
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><A HREF="<%= $view %>"><FONT SIZE=-1><%= "$ship_last, $ship_first" %></FONT></A></TD>
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %>><%= $pship_company %></A></TD>
+
+ <% }
+
+ foreach my $addl_col ( @addl_cols ) { %>
+
+ <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>" ROWSPAN=<%= $rowspan || 1 %> ALIGN=right><FONT SIZE=-1>
+
+ <% if ( $addl_col eq 'tickets' ) {
+ if ( @custom_priorities ) {
+ print &itable('', 0);
+ foreach my $priority ( @custom_priorities, '' ) {
+
+ my $num =
+ FS::TicketSystem->num_customer_tickets($custnum,$priority);
+ my $ahref = '';
+ $ahref= '<A HREF="'.
+ FS::TicketSystem->href_customer_tickets($custnum,$priority).
+ '">'
+ if $num;
+
+ print '<TR>'.
+ " <TD ALIGN=right><FONT SIZE=-1>$ahref$num</A></FONT></TD>".
+ "<TD ALIGN=left><FONT SIZE=-1>$ahref".
+ ( $priority || '<i>(none)</i>' ).
+ "</A></FONT></TD></TR>";
+
+ }
+ print '<TR><TD BGCOLOR="#000000" COLSPAN=2></TD></TR>'.
+ '<TR><TD ALIGN=right><FONT SIZE=-1>';
+ }
+
+ my $ahref = '';
+ $ahref = '<A HREF="'.
+ FS::TicketSystem->href_customer_tickets($custnum).
+ '">'
+ if $cust_main->get($addl_col);
+
+ print $ahref. $cust_main->get($addl_col). '</A>';
+ print "</FONT></TD><TD ALIGN=left>".
+ "<FONT SIZE=-1>${ahref}Total</A><FONT>".
+ "</TD></TR></TABLE>"
+ if @custom_priorities;
+
+ } else {
+ print $cust_main->get($addl_col);
+ }
+ print "</FONT></TD>";
}
my($n1)='';
#my(@cust_svc) = qsearch( 'cust_svc', { 'pkgnum' => $_->pkgnum } );
my $rowspan = scalar(@cust_svc) || 1;
- print $n1, qq!<TD ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg - $comment</FONT></A></TD>!;
+ print $n1, qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ROWSPAN=$rowspan><A HREF="$pkgview"><FONT SIZE=-1>$pkg - $comment</FONT></A></TD>!;
+
my($n2)='';
foreach my $cust_svc ( @cust_svc ) {
my($label, $value, $svcdb) = $cust_svc->label;
my($svcnum) = $cust_svc->svcnum;
my($sview) = $p.'view';
- print $n2,qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
- qq!<TD><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
+ print $n2,qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$label</FONT></A></TD>!,
+ qq!<TD CLASS="grid" BGCOLOR="$bgcolor" ><A HREF="$sview/$svcdb.cgi?$svcnum"><FONT SIZE=-1>$value</FONT></A></TD>!;
$n2="</TR><TR>";
}
+
+ unless ( @cust_svc ) {
+ print qq!<TD CLASS="grid" BGCOLOR="$bgcolor" COLSPAN=2> </TD>!;
+ }
+
#print qq!</TR><TR>\n!;
$n1="</TR><TR>";
}
+
+ unless ( @{$all_pkgs{$custnum}} ) {
+ print qq!<TD CLASS="grid" BGCOLOR="$bgcolor" COLSPAN=3> </TD>!;
+ }
+
print "</TR>";
}
+
+ %>
- print "</TABLE>$pager</BODY></HTML>";
+ </TABLE><%= $pager %>
-}
+ <%= include('/elements/footer.html') %>
+
+<% }
#undef $cache; #does this help?
$a->getfield('custnum') <=> $b->getfield('custnum');
}
+sub tickets_sort {
+ $b->getfield('tickets') <=> $a->getfield('tickets');
+}
+
sub custnumsearch {
my $custnum = $cgi->param('custnum_text');