X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=blobdiff_plain;f=httemplate%2Fsearch%2Fcust_main.cgi;h=24d49c588130828813bcdc9ab40ec983bb0f53d2;hp=d2a797c57d158a4217e30beef57522b6e863d455;hb=1fc8addc56f8daf12397da568eb1ac1b27fd3984;hpb=c4c8512adc83e2c6e6640112735e887b71222e1d diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index d2a797c57..24d49c588 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -4,6 +4,7 @@ % } else { <% $cgi->redirect(popurl(2). "view/cust_main.cgi?". $cust_main[0]->custnum) %> % } +% $m->abort; %} elsif ( scalar(@cust_main) == 0 ) { % errorpage(emt("No matching customers found!")); % } # errorpage quits, so we don't need an 'else' below @@ -37,6 +38,10 @@ ( <% mt("$linklabel canceled customers") |h %> ) % } +% unless ($cgi->param('browse')) { + <& /elements/agent_transfer_link.html, {'list' => \@cust_main} &> +% } + % if ( $cgi->param('referral_custnum') ) { % $cgi->param('referral_custnum') =~ /^(\d+)$/ % or errorpage(emt("Illegal referral_custnum")); @@ -119,8 +124,21 @@ % foreach my $cust_pkg ( @{$all_pkgs{$custnum}} ) { % my %cust_svc_by_svcpart; % my $rows = 0; +% #local($FS::part_pkg::cache_enabled) = 1; #for $cust_pkg->part_svc +% local($FS::cust_svc::cache_enabled) = 1; #for $cust_svc->part_svc +% #local($FS::pkg_svc::cache_enabled) = 1; #for $pkg_svc->part_svc % foreach my $part_svc ( -% $cust_pkg->part_svc( summarize_size=>$large_pkg_size ) +% #$cust_pkg->part_svc( summarize_size=>$large_pkg_size ) +% qsearch({ +% 'select' => 'part_svc.*, COUNT(*) AS num_cust_svc', +% 'table' => 'part_svc', +% 'addl_from' => 'LEFT JOIN cust_svc USING ( svcpart )', +% 'extra_sql' => 'WHERE pkgnum = ? '. +% ' GROUP BY '. join(', ', +% map "part_svc.$_", fields('part_svc') +% ), +% 'extra_param' => [ [$cust_pkg->pkgnum,'int'] ], +% }) % ) { % my $svcpart = $part_svc->svcpart; % my $num_cust_svc = $part_svc->num_cust_svc; @@ -132,7 +150,9 @@ % $rows += 2; % } % elsif ( $num_cust_svc ) { -% $cust_svc_by_svcpart{$svcpart} = $part_svc->cust_pkg_svc; +% #$cust_svc_by_svcpart{$svcpart} = $part_svc->cust_pkg_svc; +% #further optimization opportunities: don't need to re-pull in another $part_svc object, sorting this is expensive, etc. +% $cust_svc_by_svcpart{$svcpart} = [ $cust_pkg->cust_svc($part_svc->svcpart) ]; % $rows += $num_cust_svc; % } #if summarize % } #foreach $part_svc @@ -232,11 +252,12 @@ % 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( cust_pkg=>$_, nopkgpart=>1 ); -% my $show = $curuser->default_customer_view =~ /^(jumbo|packages)$/ +% my $show = $default_customer_view =~ /^(jumbo|packages)$/ % ? '' % : ';show=packages'; % my $frag = "cust_pkg$pkgnum"; #hack for IE ignoring real #fragment @@ -279,12 +300,13 @@ % } % 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, $cust_svc->part_svc, $cust_svc) %> + <% FS::UI::Web::svc_link($m, $part_svc, $cust_svc) %> <% $td %> - <% FS::UI::Web::svc_label_link($m, $cust_svc->part_svc, $cust_svc) %> + <% FS::UI::Web::svc_label_link($m, $part_svc, $cust_svc) %> % $n2=""; % } #foreach $cust_svc @@ -312,13 +334,16 @@ my $curuser = $FS::CurrentUser::CurrentUser; die "access denied" - unless $curuser->access_right('List all 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; @@ -331,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 = (); @@ -481,7 +508,7 @@ if ( $cgi->param('browse') ); } - @cust_main = grep { $_->num_ncancelled_pkgs || ! $_->num_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 @@ -493,30 +520,35 @@ if ( $cgi->param('browse') @cust_main = grep { !$saw{$_->custnum}++ } @cust_main; } -my $pkgs_method = $conf->exists('hidecancelledpackages') - ? 'ncancelled_pkgs' - : 'all_pkgs'; - -#false laziness w/httemplate/view/cust_main/packages.html -my $select = '*, setup_option.optionvalue AS _opt_setup_fee, '. - 'recur_option.optionvalue AS _opt_recur_fee', -my $addl_from = qq{ - LEFT JOIN part_pkg USING ( pkgpart ) - LEFT JOIN part_pkg_option AS setup_option - ON ( cust_pkg.pkgpart = setup_option.pkgpart - AND setup_option.optionname = 'setup_fee' ) - LEFT JOIN part_pkg_option AS recur_option - ON ( cust_pkg.pkgpart = recur_option.pkgpart - AND recur_option.optionname = 'recur_fee' ) -}; - -my %all_pkgs = map { $_->custnum => - [ $_->$pkgs_method({ select => $select, - addl_from => $addl_from, - }) - ]; - } - @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 { lc($a->getfield('last')) cmp lc($b->getfield('last')) @@ -557,7 +589,7 @@ sub cardsearch { my($card)=$cgi->param('card'); $card =~ s/\D//g; - $card =~ /^(\d{13,16}|\d{8,9})$/ 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'}), @@ -678,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; }