diff options
author | ivan <ivan> | 2005-07-14 10:52:46 +0000 |
---|---|---|
committer | ivan <ivan> | 2005-07-14 10:52:46 +0000 |
commit | 08662d58e7b9a13cf841e9c89daa39b28655724e (patch) | |
tree | bb6415dcfc8c94a30639c8a913051a38c31780ad /httemplate | |
parent | c91e5cd4ce307d5f3573ea309cbcf03186ea3de4 (diff) |
move account search (httemplate/search/svc_acct.cgi) to new template, cust-fields configuration value to control which customer fields are shown on reports
Diffstat (limited to 'httemplate')
-rw-r--r-- | httemplate/search/cust_bill_event.cgi | 25 | ||||
-rwxr-xr-x | httemplate/search/cust_credit.html | 33 | ||||
-rwxr-xr-x | httemplate/search/cust_pay.cgi | 34 | ||||
-rw-r--r-- | httemplate/search/elements/search.html | 23 | ||||
-rwxr-xr-x | httemplate/search/report_receivables.cgi | 26 | ||||
-rwxr-xr-x | httemplate/search/svc_acct.cgi | 336 | ||||
-rwxr-xr-x | httemplate/search/svc_domain.cgi | 18 | ||||
-rwxr-xr-x | httemplate/search/svc_forward.cgi | 15 | ||||
-rwxr-xr-x | httemplate/search/svc_www.cgi | 19 |
9 files changed, 215 insertions, 314 deletions
diff --git a/httemplate/search/cust_bill_event.cgi b/httemplate/search/cust_bill_event.cgi index f34bb68f4..df4dcbf42 100644 --- a/httemplate/search/cust_bill_event.cgi +++ b/httemplate/search/cust_bill_event.cgi @@ -27,8 +27,8 @@ my $sql_query = { 'part_bill_event.event', 'cust_bill.custnum', 'cust_bill._date AS cust_bill_date', - map "cust_main.$_", qw(last first company) - + 'cust_main.custnum AS cust_main_custnum', + FS::UI::Web::cust_sql_fields(), ), 'extra_sql' => "$where ORDER BY _date ASC", 'addl_from' => 'LEFT JOIN part_bill_event USING ( eventpart ) '. @@ -71,6 +71,13 @@ push @$menubar, 'Re-fax these events' => "javascript:fax_process()" if $conf->exists('hylafax'); +my $link_cust = sub { + my $cust_bill_event = shift; + $cust_bill_event->cust_main_custnum + ? [ "${p}view/cust_main.cgi?", 'custnum' ] + : ''; +}; + %><%= include( 'elements/search.html', 'title' => $title, 'html_init' => $html_init, @@ -78,9 +85,12 @@ push @$menubar, 'Re-fax these events' => 'name' => 'billing events', 'query' => $sql_query, 'count_query' => $count_sql, - 'header' => [ qw( Event Date Status ), + 'header' => [ 'Event', + 'Date', + 'Status', #'Inv #', 'Inv Date', 'Cust #', - 'Invoice', 'Cust #', + 'Invoice', + FS::UI::Web::cust_header(), ], 'fields' => [ 'event', @@ -99,9 +109,7 @@ push @$menubar, 'Re-fax these events' => time2str("%D", $_[0]->cust_bill_date). ')'; }, - sub { FS::cust_main::name($_[0]) }, - - + \&FS::UI::Web::cust_fields, ], 'links' => [ '', @@ -113,8 +121,7 @@ push @$menubar, 'Re-fax these events' => $template .= '-' if $template; [ "${p}view/cust_bill.cgi?$template", 'invnum']; }, - [ "${p}view/cust_main.cgi?", 'custnum' ], - [ "${p}view/cust_main.cgi?", 'custnum' ], + ( map { $link_cust } FS::UI::Web::cust_header() ), ], ) %> diff --git a/httemplate/search/cust_credit.html b/httemplate/search/cust_credit.html index b978e6238..4b3da605a 100755 --- a/httemplate/search/cust_credit.html +++ b/httemplate/search/cust_credit.html @@ -46,13 +46,22 @@ my $sql_query = { 'table' => 'cust_credit', - 'select' => 'cust_credit.*, cust_main.last, cust_main.first, cust_main.company', + 'select' => join(', ', + 'cust_credit.*', + 'cust_main.custnum as cust_main_custnum', + FS::UI::Web::cust_sql_fields(), + ), 'hashref' => {}, 'extra_sql' => $where, 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', }; - my $clink = [ "${p}view/cust_main.cgi?", 'custnum' ]; + my $clink = sub { + my $cust_bill = shift; + $cust_bill->cust_main_custnum + ? [ "${p}view/cust_main.cgi?", 'custnum' ] + : ''; + }; %><%= include( 'elements/search.html', 'title' => $title, @@ -61,26 +70,26 @@ 'count_query' => $count_query, 'count_addl' => [ '$%.2f total credited', ], #'redirect' => $link, - 'header' => - [ qw(Amount Date), 'Cust #', 'Contact name', - qw(Company By Reason) ], + 'header' => [ 'Amount', + 'Date', + FS::UI::Web::cust_header(), + 'By', + 'Reason' + ], 'fields' => [ #'crednum', sub { sprintf('$%.2f', shift->amount ) }, sub { time2str('%b %d %Y', shift->_date ) }, - 'custnum', - sub { $_[0]->get('last'). ', '. $_[0]->first; }, - 'company', + \&FS::UI::Web::cust_fields, 'otaker', 'reason', ], - 'align' => 'rrrllll', + #'align' => 'rrrllll', + 'align' => 'rr', 'links' => [ '', '', - $clink, - $clink, - $clink, + ( map { $clink } FS::UI::Web::cust_header() ), '', '', ], diff --git a/httemplate/search/cust_pay.cgi b/httemplate/search/cust_pay.cgi index c23653aa9..a680479f3 100755 --- a/httemplate/search/cust_pay.cgi +++ b/httemplate/search/cust_pay.cgi @@ -73,7 +73,11 @@ $sql_query = { 'table' => 'cust_pay', - 'select' => 'cust_pay.*, cust_main.last, cust_main.first, cust_main.company', + 'select' => join(', ', + 'cust_pay.*', + 'cust_main.custnum as cust_main_custnum', + FS::UI::Web::cust_sql_fields(), + ), 'hashref' => {}, 'extra_sql' => "$search ORDER BY _date", 'addl_from' => 'LEFT JOIN cust_main USING ( custnum )', @@ -99,7 +103,12 @@ } - my $link = [ "${p}view/cust_main.cgi?", 'custnum' ]; + my $link = sub { + my $cust_pay = shift; + $cust_pay->cust_main_custnum + ? [ "${p}view/cust_main.cgi?", 'custnum' ] + : ''; + }; %><%= include( 'elements/search.html', 'title' => $title, @@ -107,9 +116,11 @@ 'query' => $sql_query, 'count_query' => $count_query, 'count_addl' => [ '$%.2f total paid', ], - 'header' => - [ qw(Payment Amount Date), 'Cust #', 'Contact name', - 'Company', ], + 'header' => [ 'Payment', + 'Amount', + 'Date', + FS::UI::Web::cust_header(), + ], 'fields' => [ sub { my $cust_pay = shift; @@ -119,24 +130,23 @@ 'E-check acct#'. $cust_pay->payinfo; } elsif ( $cust_pay->payby eq 'BILL' ) { 'Check #'. $cust_pay->payinfo; + } elsif ( $cust_pay->payby eq 'PREP' ) { + 'Prepaid card #'. $cust_pay->payinfo; } else { $cust_pay->payby. ' '. $cust_pay->payinfo; } }, sub { sprintf('$%.2f', shift->paid ) }, sub { time2str('%b %d %Y', shift->_date ) }, - 'custnum', - sub { $_[0]->get('last'). ', '. $_[0]->first; }, - 'company', + \&FS::UI::Web::cust_fields, ], - 'align' => 'lrrrll', + #'align' => 'lrrrll', + 'align' => 'rrr', 'links' => [ '', '', '', - $link, - $link, - $link, + ( map { $link } FS::UI::Web::cust_header() ), ], ) %> diff --git a/httemplate/search/elements/search.html b/httemplate/search/elements/search.html index 47d619444..78754fe00 100644 --- a/httemplate/search/elements/search.html +++ b/httemplate/search/elements/search.html @@ -152,7 +152,9 @@ # } #} if ( ref($field) eq 'CODE' ) { - $worksheet->write($r, $c++, &{$field}($row) ); + foreach my $value ( &{$field}($row) ) { + $worksheet->write($r, $c++, $value ); + } } else { $worksheet->write($r, $c++, $row->$field() ); } @@ -253,7 +255,18 @@ my $sizes = $opt{'size'} ? [ @{$opt{'size'}} ] : []; my $styles = $opt{'style'} ? [ @{$opt{'style'}} ] : []; - foreach my $field ( @{$opt{'fields'}} ) { + foreach my $field ( + + map { + if ( ref($_) eq 'CODE' ) { + &{$_}($row); + } else { + $row->$_(); + } + } + @{$opt{'fields'}} + + ) { my $align = $aligns ? shift @$aligns : ''; $align = " ALIGN=$align" if $align; @@ -294,11 +307,7 @@ } %> - <% if ( ref($field) eq 'CODE' ) { %> - <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"<%= $align %>><%= $font %><%= $a %><%= $s %><%= &{$field}($row) %><%= $es %><%= $a ? '</A>' : '' %><%= $font ? '</FONT>' : '' %></TD> - <% } else { %> - <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"<%= $align %>><%= $font %><%= $a %><%= $s %><%= $row->$field() %><%= $es %><%= $a ? '</A>' : '' %><%= $font ? '</FONT>' : '' %></TD> - <% } %> + <TD CLASS="grid" BGCOLOR="<%= $bgcolor %>"<%= $align %>><%= $font %><%= $a %><%= $s %><%= $field %><%= $es %><%= $a ? '</A>' : '' %><%= $font ? '</FONT>' : '' %></TD> <% } %> <% } else { %> <% foreach ( @$row ) { %> diff --git a/httemplate/search/report_receivables.cgi b/httemplate/search/report_receivables.cgi index 82ce5d777..535afcca0 100755 --- a/httemplate/search/report_receivables.cgi +++ b/httemplate/search/report_receivables.cgi @@ -118,14 +118,16 @@ END my $conf = new FS::Conf; my $money_char = $conf->config('money_char') || '$'; + my $align = join('', map { /#/ ? 'r' : 'l' } FS::UI::Web::cust_header() ). + 'crrrrr'; + %><%= include( 'elements/search.html', 'title' => 'Accounts Receivable Aging Summary', 'name' => 'customers', 'query' => $sql_query, 'count_query' => $count_sql, 'header' => [ - '#', - 'Customer', + FS::UI::Web::cust_header(), 'Status', # (me)', #'Status', # (cust_main)', '0-30', @@ -135,8 +137,12 @@ END 'Total', ], 'footer' => [ - '', 'Total', + ( map '', + ( 1 .. + scalar(FS::UI::Web::cust_header()-1) + ) + ), '', #'', sprintf( $money_char.'%.2f', @@ -151,8 +157,7 @@ END $row->{'owed_total'} ), ], 'fields' => [ - 'custnum', - 'name', + \&FS::UI::Web::cust_fields, sub { my $row = shift; my $status = 'Cancelled'; @@ -191,14 +196,15 @@ END '', ], #'align' => 'rlccrrrrr', - 'align' => 'rlcrrrrr', + 'align' => $align, #'size' => [ '', '', '-1', '-1', '', '', '', '', '', ], #'style' => [ '', '', 'b', 'b', '', '', '', '', 'b', ], - 'size' => [ '', '', '-1', '', '', '', '', '', ], - 'style' => [ '', '', 'b', '', '', '', '', 'b', ], + 'size' => [ ( map '', FS::UI::Web::cust_header() ), + '-1', '', '', '', '', '', ], + 'style' => [ ( map '', FS::UI::Web::cust_header() ), + 'b', '', '', '', '', 'b', ], 'color' => [ - '', - '', + ( map '', FS::UI::Web::cust_header() ), sub { my $row = shift; my $status = 'Cancelled'; diff --git a/httemplate/search/svc_acct.cgi b/httemplate/search/svc_acct.cgi index 1e4a03d84..d4565aefc 100755 --- a/httemplate/search/svc_acct.cgi +++ b/httemplate/search/svc_acct.cgi @@ -1,250 +1,37 @@ <% -my $conf = new FS::Conf; -my $maxrecords = $conf->config('maxsearchrecordsperpage'); - -my $orderby = ''; #removeme - -my $limit = ''; -$limit .= "LIMIT $maxrecords" if $maxrecords; - -my $offset = $cgi->param('offset') || 0; -$limit .= " OFFSET $offset" if $offset; - -my $total; +my $orderby = 'ORDER BY svcnum'; my($query)=$cgi->keywords; $query ||= ''; #to avoid use of unitialized value errors -my $unlinked = ''; +my $cjoin = ''; +my @extra_sql = (); if ( $query =~ /^UN_(.*)$/ ) { $query = $1; - my $empty = driver_name eq 'Pg' ? qq('') : qq(""); - if ( driver_name eq 'mysql' ) { - $unlinked = "LEFT JOIN cust_svc ON cust_svc.svcnum = svc_acct.svcnum - WHERE cust_svc.pkgnum IS NULL - OR cust_svc.pkgnum = 0 - OR cust_svc.pkgnum = $empty"; - } else { - $unlinked = " - WHERE 0 < - ( SELECT count(*) FROM cust_svc - WHERE cust_svc.svcnum = svc_acct.svcnum - AND ( pkgnum IS NULL OR pkgnum = 0 ) - ) - "; - } + $cjoin = 'LEFT JOIN cust_svc USING ( svcnum )'; + push @extra_sql, 'pkgnum IS NULL'; } -my $tblname = driver_name eq 'mysql' ? 'svc_acct.' : ''; -my(@svc_acct, $sortby); if ( $query eq 'svcnum' ) { - $sortby=\*svcnum_sort; - $orderby = "ORDER BY ${tblname}svcnum"; + #$orderby = "ORDER BY svcnum"; } elsif ( $query eq 'username' ) { - $sortby=\*username_sort; - $orderby = "ORDER BY ${tblname}username"; + $orderby = "ORDER BY LOWER(username)"; } elsif ( $query eq 'uid' ) { - $sortby=\*uid_sort; - $orderby = ( $unlinked ? ' AND' : ' WHERE' ). - " ${tblname}uid IS NOT NULL ORDER BY ${tblname}uid"; + $orderby = "ORDER BY uid"; + push @extra_sql, "uid IS NOT NULL"; } elsif ( $cgi->param('popnum') =~ /^(\d+)$/ ) { - $unlinked .= ( $unlinked ? 'AND' : 'WHERE' ). - " popnum = $1"; - $sortby=\*username_sort; - $orderby = "ORDER BY ${tblname}username"; + push @extra_sql, "popnum = $1"; + $orderby = "ORDER BY LOWER(username)"; } elsif ( $cgi->param('svcpart') =~ /^(\d+)$/ ) { - $unlinked .= ( $unlinked ? ' AND' : ' WHERE' ). - " $1 = ( SELECT svcpart FROM cust_svc ". - " WHERE cust_svc.svcnum = svc_acct.svcnum ) "; - $sortby=\*uid_sort; - #$sortby=\*svcnum_sort; + $cjoin ||= 'LEFT JOIN cust_svc USING ( svcnum )'; + push @extra_sql, "svcpart = $1"; + $orderby = "ORDER BY uid"; + #$orderby = "ORDER BY svcnum"; } else { - $sortby=\*uid_sort; - @svc_acct = @{&usernamesearch}; -} - - -if ( $query eq 'svcnum' - || $query eq 'username' - || $query eq 'uid' - || $cgi->param('popnum') =~ /^(\d+)$/ - || $cgi->param('svcpart') =~ /^(\d+)$/ - ) { - - my $statement = "SELECT COUNT(*) FROM svc_acct $unlinked"; - my $sth = dbh->prepare($statement) - or die dbh->errstr. " doing $statement"; - $sth->execute or die "Error executing \"$statement\": ". $sth->errstr; - - $total = $sth->fetchrow_arrayref->[0]; - - @svc_acct = qsearch('svc_acct', {}, '', "$unlinked $orderby $limit"); - -} - -if ( scalar(@svc_acct) == 1 ) { - my($svcnum)=$svc_acct[0]->svcnum; - print $cgi->redirect(popurl(2). "view/svc_acct.cgi?$svcnum"); #redirect - #exit; -} elsif ( scalar(@svc_acct) == 0 ) { #error -%> -<!-- mason kludge --> -<% - idiot("Account not found"); -} else { -%> -<!-- mason kludge --> -<% - $total ||= scalar(@svc_acct); - - #begin pager - my $pager = ''; - if ( $total != scalar(@svc_acct) && $maxrecords ) { - unless ( $offset == 0 ) { - $cgi->param('offset', $offset - $maxrecords); - $pager .= '<A HREF="'. $cgi->self_url. - '"><B><FONT SIZE="+1">Previous</FONT></B></A> '; - } - my $poff; - my $page; - for ( $poff = 0; $poff < $total; $poff += $maxrecords ) { - $page++; - if ( $offset == $poff ) { - $pager .= qq!<FONT SIZE="+2">$page</FONT> !; - } else { - $cgi->param('offset', $poff); - $pager .= qq!<A HREF="!. $cgi->self_url. qq!">$page</A> !; - } - } - unless ( $offset + $maxrecords > $total ) { - $cgi->param('offset', $offset + $maxrecords); - $pager .= '<A HREF="'. $cgi->self_url. - '"><B><FONT SIZE="+1">Next</FONT></B></A> '; - } - } - #end pager - - print header("Account Search Results",menubar('Main Menu'=>popurl(2))), - "$total matching accounts found<BR><BR>$pager", - &table(), <<END; - <TR> - <TH><FONT SIZE=-1>#</FONT></TH> - <TH><FONT SIZE=-1>Username</FONT></TH> - <TH><FONT SIZE=-1>Domain</FONT></TH> - <TH><FONT SIZE=-1>UID</FONT></TH> - <TH><FONT SIZE=-1>Service</FONT></TH> - <TH><FONT SIZE=-1>Cust#</FONT></TH> - <TH><FONT SIZE=-1>(bill) name</FONT></TH> - <TH><FONT SIZE=-1>company</FONT></TH> -END - if ( defined dbdef->table('cust_main')->column('ship_last') ) { - print <<END; - <TH><FONT SIZE=-1>(service) name</FONT></TH> - <TH><FONT SIZE=-1>company</FONT></TH> -END - } - print "</TR>"; + $orderby = "ORDER BY uid"; - my(%saw,$svc_acct); - my $p = popurl(2); - foreach $svc_acct ( - sort $sortby grep(!$saw{$_->svcnum}++, @svc_acct) - ) { - my $cust_svc = qsearchs('cust_svc', { 'svcnum' => $svc_acct->svcnum }) - or die "No cust_svc record for svcnum ". $svc_acct->svcnum; - my $part_svc = qsearchs('part_svc', { 'svcpart' => $cust_svc->svcpart }) - or die "No part_svc record for svcpart ". $cust_svc->svcpart; - - my $domain; - my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $svc_acct->domsvc }); - if ( $svc_domain ) { - $domain = "<A HREF=\"${p}view/svc_domain.cgi?". $svc_domain->svcnum. - "\">". $svc_domain->domain. "</A>"; - } else { - die "No svc_domain.svcnum record for svc_acct.domsvc: ". - $svc_acct->domsvc; - } - my($cust_pkg,$cust_main); - if ( $cust_svc->pkgnum ) { - $cust_pkg = qsearchs('cust_pkg', { 'pkgnum' => $cust_svc->pkgnum }) - or die "No cust_pkg record for pkgnum ". $cust_svc->pkgnum; - $cust_main = qsearchs('cust_main', { 'custnum' => $cust_pkg->custnum }) - or die "No cust_main record for custnum ". $cust_pkg->custnum; - } - my($svcnum, $username, $uid, $svc, $custnum, $last, $first, $company) = ( - $svc_acct->svcnum, - $svc_acct->getfield('username'), - $svc_acct->getfield('uid'), - $part_svc->svc, - $cust_svc->pkgnum ? $cust_main->custnum : '', - $cust_svc->pkgnum ? $cust_main->getfield('last') : '', - $cust_svc->pkgnum ? $cust_main->getfield('first') : '', - $cust_svc->pkgnum ? $cust_main->company : '', - ); - my($pcustnum) = $custnum - ? "<A HREF=\"${p}view/cust_main.cgi?$custnum\"><FONT SIZE=-1>$custnum</FONT></A>" - : "<I>(unlinked)</I>" - ; - my $pname = $custnum ? "<A HREF=\"${p}view/cust_main.cgi?$custnum\">$last, $first</A>" : ''; - my $pcompany = $custnum ? "<A HREF=\"${p}view/cust_main.cgi?$custnum\">$company</A>" : ''; - my($pship_name, $pship_company); - if ( defined dbdef->table('cust_main')->column('ship_last') ) { - my($ship_last, $ship_first, $ship_company) = ( - $cust_svc->pkgnum ? ( $cust_main->ship_last || $last ) : '', - $cust_svc->pkgnum ? ( $cust_main->ship_last - ? $cust_main->ship_first - : $first - ) : '', - $cust_svc->pkgnum ? ( $cust_main->ship_last - ? $cust_main->ship_company - : $company - ) : '', - ); - $pship_name = $custnum ? "<A HREF=\"${p}view/cust_main.cgi?$custnum\">$ship_last, $ship_first</A>" : ''; - $pship_company = $custnum ? "<A HREF=\"${p}view/cust_main.cgi?$custnum\">$ship_company</A>" : ''; - } - print <<END; - <TR> - <TD><A HREF="${p}view/svc_acct.cgi?$svcnum"><FONT SIZE=-1>$svcnum</FONT></A></TD> - <TD><A HREF="${p}view/svc_acct.cgi?$svcnum"><FONT SIZE=-1>$username</FONT></A></TD> - <TD><FONT SIZE=-1>$domain</FONT></TD> - <TD><A HREF="${p}view/svc_acct.cgi?$svcnum"><FONT SIZE=-1>$uid</FONT></A></TD> - <TD><FONT SIZE=-1>$svc</FONT></TH> - <TD><FONT SIZE=-1>$pcustnum</FONT></TH> - <TD><FONT SIZE=-1>$pname<FONT></TH> - <TD><FONT SIZE=-1>$pcompany</FONT></TH> -END - if ( defined dbdef->table('cust_main')->column('ship_last') ) { - print <<END; - <TD><FONT SIZE=-1>$pship_name<FONT></TH> - <TD><FONT SIZE=-1>$pship_company</FONT></TH> -END - } - print "</TR>"; - - } - - print "</TABLE>$pager<BR>". - '</BODY></HTML>'; - -} - -sub svcnum_sort { - $a->getfield('svcnum') <=> $b->getfield('svcnum'); -} - -sub username_sort { - $a->getfield('username') cmp $b->getfield('username'); -} - -sub uid_sort { - $a->getfield('uid') <=> $b->getfield('uid'); -} - -sub usernamesearch { - - my @svc_acct; + my @username_sql; my %username_type; foreach ( $cgi->param('username_type') ) { @@ -254,17 +41,13 @@ sub usernamesearch { $cgi->param('username') =~ /^([\w\-\.\&]+)$/; #untaint username_text my $username = $1; - if ( $username_type{'Exact'} || $username_type{'Fuzzy'} ) { - push @svc_acct, qsearch( 'svc_acct', - { 'username' => { 'op' => 'ILIKE', - 'value' => $username } } ); - } + push @username_sql, "username ILIKE '$username'" + if $username_type{'Exact'} + || $username_type{'Fuzzy'}; - if ( $username_type{'Substring'} || $username_type{'All'} ) { - push @svc_acct, qsearch( 'svc_acct', - { 'username' => { 'op' => 'ILIKE', - 'value' => "%$username%" } } ); - } + push @username_sql, "username ILIKE '\%$username\%'" + if $username_type{'Substring'} + || $username_type{'All'}; if ( $username_type{'Fuzzy'} || $username_type{'All'} ) { &FS::svc_acct::check_and_rebuild_fuzzyfiles; @@ -280,15 +63,78 @@ sub usernamesearch { #if ($username_type{'Sound-alike'}) { #} - foreach ( keys %username ) { - push @svc_acct, qsearch('svc_acct',{'username'=>$_}); - } + push @username_sql, "username = '$_'" + foreach (keys %username); } - #[ qsearch('svc_acct',{'username'=>$username}) ]; - \@svc_acct; + push @extra_sql, '( '. join( ' OR ', @username_sql). ' )'; } +my $extra_sql = + scalar(@extra_sql) + ? ' WHERE '. join(' AND ', @extra_sql ) + : ''; + +my $count_query = "SELECT COUNT(*) FROM svc_acct $cjoin $extra_sql"; +#if ( keys %svc_acct ) { +# $count_query .= ' WHERE '. +# join(' AND ', map "$_ = ". dbh->quote($svc_acct{$_}), +# keys %svc_acct +# ); +#} + +my $sql_query = { + 'table' => 'svc_acct', + 'hashref' => {}, # \%svc_acct, + 'select' => join(', ', + 'svc_acct.*', + 'cust_main.custnum', + FS::UI::Web::cust_sql_fields(), + ), + 'extra_sql' => "$extra_sql $orderby", + 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum ) '. + 'LEFT JOIN part_svc USING ( svcpart ) '. + 'LEFT JOIN cust_pkg USING ( pkgnum ) '. + 'LEFT JOIN cust_main USING ( custnum ) ', +}; + +my $link = [ "${p}view/svc_acct.cgi?", 'svcnum' ]; +my $link_cust = sub { + my $svc_acct = shift; + if ( $svc_acct->custnum ) { + [ "${p}view/cust_main.cgi?", 'custnum' ]; + } else { + ''; + } +}; + +%><%= include( 'elements/search.html', + 'title' => 'Account Search Results', + 'name' => 'accounts', + 'query' => $sql_query, + 'count_query' => $count_query, + 'redirect' => $link, + 'header' => [ '#', + 'Account', + 'UID', + 'Service', + FS::UI::Web::cust_header(), + ], + 'fields' => [ 'svcnum', + 'email', + 'uid', + 'svc', + \&FS::UI::Web::cust_fields, + ], + 'links' => [ $link, + $link, + $link, + '', + ( map { $link_cust } + FS::UI::Web::cust_header() + ), + ], + ) %> diff --git a/httemplate/search/svc_domain.cgi b/httemplate/search/svc_domain.cgi index 06041e03b..f261ea9f3 100755 --- a/httemplate/search/svc_domain.cgi +++ b/httemplate/search/svc_domain.cgi @@ -37,7 +37,6 @@ if ( keys %svc_domain ) { join(' AND ', map "$_ = ". dbh->quote($svc_domain{$_}), keys %svc_domain ); - } my $sql_query = { @@ -45,12 +44,13 @@ my $sql_query = { 'hashref' => \%svc_domain, 'select' => join(', ', 'svc_domain.*', - map "cust_main.$_", qw(custnum last first company) + 'cust_main.custnum', + FS::UI::Web::cust_sql_fields(), ), 'extra_sql' => "$extra_sql $orderby", - 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum )'. - 'LEFT JOIN cust_pkg USING ( pkgnum )'. - 'LEFT JOIN cust_main USING ( custnum )', + 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum ) '. + 'LEFT JOIN cust_pkg USING ( pkgnum ) '. + 'LEFT JOIN cust_main USING ( custnum ) ', }; my $link = [ "${p}view/svc_domain.cgi?", 'svcnum' ]; @@ -69,15 +69,17 @@ my $link_cust = sub { 'redirect' => $link, 'header' => [ '#', 'Domain', - 'Customer', + FS::UI::Web::cust_header(), ], 'fields' => [ 'svcnum', 'domain', - \&FS::svc_Common::cust_name, + \&FS::UI::Web::cust_fields, ], 'links' => [ $link, $link, - $link_cust, + ( map { $link_cust } + FS::UI::Web::cust_header() + ), ], ) %> diff --git a/httemplate/search/svc_forward.cgi b/httemplate/search/svc_forward.cgi index 1c1c6e4dd..330c0ee83 100755 --- a/httemplate/search/svc_forward.cgi +++ b/httemplate/search/svc_forward.cgi @@ -17,7 +17,8 @@ my $sql_query = { 'hashref' => {}, 'select' => join(', ', 'svc_forward.*', - map "cust_main.$_", qw(custnum last first company) + 'cust_main.custnum', + FS::UI::Web::cust_sql_fields(), ), 'extra_sql' => $orderby, 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum )'. @@ -75,7 +76,7 @@ my $link_cust = sub { $svc_x->custnum ? [ "${p}view/cust_main.cgi?", 'custnum' ] : ''; }; -%><%= include ('elements/search.html', +%><%= include( 'elements/search.html', 'title' => "Mail forward Search Results", 'name' => 'mail forwards', 'query' => $sql_query, @@ -84,17 +85,19 @@ my $link_cust = sub { 'header' => [ '#', 'Mail to', 'Forwards to', - 'Customer', + FS::UI::Web::cust_header(), ], 'fields' => [ 'svcnum', $format_src, $format_dst, - \&FS::svc_Common::cust_name, + \&FS::UI::Web::cust_fields, ], 'links' => [ $link, $link_src, $link_dst, - $link_cust, + ( map { $link_cust } + FS::UI::Web::cust_header() + ), ], - ) + ) %> diff --git a/httemplate/search/svc_www.cgi b/httemplate/search/svc_www.cgi index de1f5dd78..ae51c61fc 100755 --- a/httemplate/search/svc_www.cgi +++ b/httemplate/search/svc_www.cgi @@ -17,7 +17,8 @@ my $sql_query = { 'hashref' => {}, 'select' => join(', ', 'svc_www.*', - map "cust_main.$_", qw(custnum last first company) + 'cust_main.custnum', + FS::UI::Web::cust_sql_fields(), ), 'extra_sql' => $orderby, 'addl_from' => 'LEFT JOIN cust_svc USING ( svcnum )'. @@ -44,17 +45,25 @@ my $link_cust = sub { 'header' => [ '#', 'Zone', 'User', - 'Customer', + FS::UI::Web::cust_header(), ], 'fields' => [ 'svcnum', sub { $_[0]->domain_record->zone }, - sub { $_[0]->svc_acct->email }, - \&FS::svc_Common::cust_name, + sub { + my $svc_www = shift; + my $svc_acct = $svc_www->svc_acct; + $svc_acct + ? $svc_acct->email + : ''; + }, + \&FS::UI::Web::cust_fields, ], 'links' => [ $link, '', $ulink, - $link_cust, + ( map { $link_cust } + FS::UI::Web::cust_header() + ), ], ) %> |