X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=httemplate%2Fsearch%2Fcust_main.cgi;h=cce4f0d7d48ee1af1fb0c84b6d7ba086e72409f4;hb=1d94d421c28cb157e6cb2f8ff30d1ac85b399b57;hp=e6ab19565ded13b19f6606afbbfa3878e736793f;hpb=791e374dc2f6d6cecd51e2fad52d74587bf879bf;p=freeside.git diff --git a/httemplate/search/cust_main.cgi b/httemplate/search/cust_main.cgi index e6ab19565..cce4f0d7d 100755 --- a/httemplate/search/cust_main.cgi +++ b/httemplate/search/cust_main.cgi @@ -120,11 +120,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::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 +% #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; @@ -136,7 +146,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 @@ -236,6 +248,7 @@ % 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; % @@ -317,10 +330,11 @@ 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; @@ -338,9 +352,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 = (); @@ -488,7 +504,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 @@ -569,7 +585,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'}), @@ -690,12 +706,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; }