- >
+ | >
<% $cust_main->display_custnum %>
|
- >
- <% ucfirst($status) %>
+ | >
+ <% $status_label %>
|
- >
- <% "$last, $first" %>
+ | >
+ <% "$last, $first" |h %>
|
- >
+ | >
<% $pcompany %>
|
-% if ( defined dbdef->table('cust_main')->column('ship_last') ) {
-% my($ship_last,$ship_first,$ship_company)=(
-% $cust_main->ship_last || $cust_main->getfield('last'),
-% $cust_main->ship_last ? $cust_main->ship_first : $cust_main->first,
-% $cust_main->ship_last ? $cust_main->ship_company : $cust_main->company,
-% );
-% my $pship_company = $ship_company
-% ? qq!$ship_company!
-% : ' ';
-%
-
- >
- <% "$ship_last, $ship_first" %>
- |
- >
- <% $pship_company %>
- |
-% }
-%
% foreach my $addl_col ( @addl_cols ) {
% if ( $addl_col eq 'tickets' ) {
% if ( @custom_priorities ) {
- ALIGN=right>
+ | ALIGN=right>
% foreach my $priority ( @custom_priorities, '' ) {
@@ -203,7 +219,7 @@
% } else {
- | ALIGN=right>
+ | ALIGN=right>
% }
% my $ahref = '';
@@ -227,7 +243,7 @@
|
% } else {
- ALIGN=right>
+ | ALIGN=right>
<% $cust_main->get($addl_col) %>
|
@@ -236,38 +252,68 @@
% my $n1 = '';
% foreach ( @{$all_pkgs{$custnum}} ) {
+% local($FS::cust_svc::cache_enabled) = 1; #for $cust_svc->part_svc
% my $pkgnum = $_->pkgnum;
% my $part_pkg = $_->part_pkg;
%
-% my $pkg_comment = $part_pkg->pkg_comment(nopkgpart => 1);
-% my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/
+% my $pkg_comment = $part_pkg->pkg_comment( cust_pkg=>$_, nopkgpart=>1 );
+% my $show = $default_customer_view =~ /^(jumbo|packages)$/
% ? ''
% : ';show=packages';
% my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment
% my $pkgview = "${p}view/cust_main.cgi?custnum=$custnum$show;fragment=$frag#$frag";
-% my @cust_svc = @{shift @lol_cust_svc};
-% my $rowspan = scalar(@cust_svc) || 1;
+% # cust_svc stuff, built earlier
+% my %cust_svc_by_svcpart = %{ shift @all_cust_svc };
+% my $pkg_rowspan = shift @pkg_rowspans;
- <% $n1 %>
- <% $pkg_comment %>
+ <% $n1 %> |
+ <% $pkg_comment |h %>
|
% my $n2 = '';
-% foreach my $cust_svc ( @cust_svc ) {
-% my($label, $value, $svcdb) = $cust_svc->label;
-% my($svcnum) = $cust_svc->svcnum;
-% my($sview) = $p.'view';
- <% $n2 %>
-
- <% FS::UI::Web::svc_link($m, $cust_svc->part_svc, $cust_svc) %>
+% my $td = ' | ';
+%
+% foreach my $svcpart ( sort keys %cust_svc_by_svcpart ) { #sort order?
+% my $these = $cust_svc_by_svcpart{$svcpart};
+% if ( $these->[0] eq 'summarize' ) {
+% my $part_svc = $these->[1];
+% my $num_cust_svc = $these->[2];
+ <% $n2 %>
+% # summarize
+% # link opens a new search for this pkgnum/svcpart combo
+% my $href = $p.'search/cust_pkg_svc.html?svcpart='.$svcpart.
+% ';pkgnum='.$pkgnum;
+ <% $td %>
+ <% $part_svc->svc %>
+ |
+ <% $td %>
+ (<% mt("view all [_1]", $num_cust_svc) |h %>)
+
+
+ <% $td %>
+ <% $td %><& /elements/search-cust_svc.html,
+ 'svcpart' => $svcpart,
+ 'pkgnum' => $pkgnum,
+ 'svcdb' => $part_svc->svcdb,
+ &>
+% $n2=" ";
+% }
+% elsif ( scalar @$these ) { # do not summarize
+% foreach my $cust_svc ( @$these ) {
+% my $part_svc = $cust_svc->part_svc;
+ <% $n2 %>
+ <% $td %>
+ <% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %>
-
- <% FS::UI::Web::svc_label_link($m, $cust_svc->part_svc, $cust_svc) %>
+ <% $td %>
+ <% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %>
|
-% $n2=" ";
-% }
+% $n2=" ";
+% } #foreach $cust_svc
+% }
+% } # foreach $svcpart
%
-% unless ( @cust_svc ) {
+% unless ( %cust_svc_by_svcpart ) {
|
% }
%
@@ -275,7 +321,7 @@
% }
%
% unless ( @{$all_pkgs{$custnum}} ) {
- | !;
+ |
% }
%
@@ -288,10 +334,15 @@
my $curuser = $FS::CurrentUser::CurrentUser;
die "access denied"
- unless $curuser->access_right('List customers');
+ unless $curuser->access_right('List all customers')
+ || $curuser->access_right('List customers');
my $conf = new FS::Conf;
-my $maxrecords = $conf->config('maxsearchrecordsperpage');
+my $maxrecords = $conf->config('maxsearchrecordsperpage') || 100;
+# summarize more than this many services of the same svcpart
+my $large_pkg_size = $conf->config('cust_pkg-large_pkg_size') || 0;
+
+my $default_customer_view = $curuser->default_customer_view;
my $limit = '';
$limit .= "LIMIT $maxrecords" if $maxrecords;
@@ -305,9 +356,11 @@ 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')
+if ( ( $cgi->param('browse')
+ || $cgi->param('otaker_on')
+ || $cgi->param('agentnum_on')
+ )
+ and $curuser->access_right('List all customers')
) {
my %search = ();
@@ -317,7 +370,12 @@ if ( $cgi->param('browse')
if ( $query eq 'custnum' ) {
if ( $conf->exists('cust_main-default_agent_custid') ) {
$sortby=\*display_custnum_sort;
- $orderby = "ORDER BY CASE WHEN agent_custid IS NOT NULL AND agent_custid != '' THEN CAST(agent_custid AS BIGINT) ELSE custnum END";
+ $orderby = "ORDER BY CASE WHEN agent_custid IS NOT NULL
+ AND agent_custid != ''
+ AND agent_custid ". regexp_sql. " '^[0-9]+\$'
+ THEN CAST(agent_custid AS BIGINT)
+ ELSE custnum
+ END";
} else {
$sortby=\*custnum_sort;
$orderby = "ORDER BY custnum";
@@ -369,6 +427,7 @@ if ( $cgi->param('browse')
push @qual, FS::cust_main->cancel_sql if $cgi->param('cancelled');
push @qual, FS::cust_main->prospect_sql if $cgi->param('prospect');
+ push @qual, FS::cust_main->ordered_sql if $cgi->param('ordered');
push @qual, FS::cust_main->active_sql if $cgi->param('active');
push @qual, FS::cust_main->inactive_sql if $cgi->param('inactive');
push @qual, FS::cust_main->susp_sql if $cgi->param('suspended');
@@ -444,12 +503,12 @@ if ( $cgi->param('browse')
if ( $cgi->param('search_cust') ) {
$sortby = \*company_sort;
$orderby = "ORDER BY LOWER(company || ' ' || last || ' ' || first )";
- push @cust_main, smart_search( 'search' => scalar($cgi->param('search_cust')),
- 'no_fuzzy_on_exact' => 1, #pref?
- );
+ push @cust_main, smart_search(
+ 'search' => scalar($cgi->param('search_cust')),
+ );
}
- @cust_main = grep { $_->ncancelled_pkgs || ! $_->all_pkgs } @cust_main
+ @cust_main = grep { $_->status ne 'cancelled' } @cust_main
if ! $cgi->param('cancelled')
&& (
$cgi->param('showcancelledcustomers') eq '0' #see if it was set by me
@@ -461,11 +520,34 @@ if ( $cgi->param('browse')
@cust_main = grep { !$saw{$_->custnum}++ } @cust_main;
}
-my %all_pkgs;
-if ( $conf->exists('hidecancelledpackages' ) ) {
- %all_pkgs = map { $_->custnum => [ $_->ncancelled_pkgs ] } @cust_main;
-} else {
- %all_pkgs = map { $_->custnum => [ $_->all_pkgs ] } @cust_main;
+my %all_pkgs = ();
+if ( scalar(@cust_main) > 1 || $cgi->param('referral_custnum') ) {
+
+ my $pkgs_method = $conf->exists('hidecancelledpackages')
+ ? 'ncancelled_pkgs'
+ : 'all_pkgs';
+
+ #false laziness w/httemplate/view/cust_main/packages.html
+ my $select = join(',',
+ 'cust_pkg.*',
+ 'part_pkg.*',
+ 'setup_option.optionvalue AS _opt_setup_fee',
+ 'recur_option.optionvalue AS _opt_recur_fee',
+ );
+
+ my $addl_from = ' LEFT JOIN part_pkg USING ( pkgpart ) '.
+ FS::part_pkg->join_options_sql;
+
+ local($FS::cust_pkg::cache_enabled) = 1; #for $cust_pkg->part_pkg
+ %all_pkgs = map { $_->custnum =>
+ [ $_->$pkgs_method({ select => $select,
+ addl_from => $addl_from,
+ skip_label_sort => 1,
+ })
+ ];
+ }
+ @cust_main;
+
}
sub last_sort {
@@ -507,7 +589,7 @@ sub cardsearch {
my($card)=$cgi->param('card');
$card =~ s/\D//g;
- $card =~ /^(\d{13,16})$/ or errorpage(emt("Illegal card number"));
+ $card =~ /^(\d{13,19}|\d{8,9})$/ or errorpage(emt("Illegal card number"));
my($payinfo)=$1;
[ qsearch('cust_main',{'payinfo'=>$payinfo, 'payby'=>'CARD'}),
@@ -628,12 +710,20 @@ sub address2search {
or errorpage(emt("Illegal address2"));
my $address2 = $1;
- push @cust_main, qsearch( 'cust_main',
- { 'address2' => { 'op' => 'ILIKE',
- 'value' => $address2 } } );
- push @cust_main, qsearch( 'cust_main',
- { 'ship_address2' => { 'op' => 'ILIKE',
- 'value' => $address2 } } );
+ # matching at the start or end of an address, but not in the middle
+ my @where;
+ foreach my $toggle (0,1) {
+ push @where, 'LOWER(cust_location.address2) LIKE LOWER('
+ . dbh->quote($toggle ? $address2 . '%' : '%' . $address2)
+ . ')';
+ }
+
+ push @cust_main, qsearch({
+ 'debug' => 1,
+ 'table' => 'cust_main',
+ 'addl_from' => 'JOIN cust_location ON (cust_location.locationnum IN (cust_main.bill_locationnum, cust_main.ship_locationnum))',
+ 'extra_sql' => 'WHERE ' . join(' OR ',@where),
+ });
\@cust_main;
}
|