From d5967ae3ecfdb0bb1ead8176cfb2760a65c51f2d Mon Sep 17 00:00:00 2001 From: jeff Date: Wed, 28 Nov 2007 18:49:20 +0000 Subject: [PATCH] advanced customer report rearrangement --- FS/FS/ConfDefaults.pm | 3 ++ FS/FS/UI/Web.pm | 2 + httemplate/search/cust_main_ADV.cgi | 85 +++++++++++++++------------------ httemplate/search/report_cust_main.html | 9 ++++ 4 files changed, 52 insertions(+), 47 deletions(-) diff --git a/FS/FS/ConfDefaults.pm b/FS/FS/ConfDefaults.pm index baee0bb08..21da302b8 100644 --- a/FS/FS/ConfDefaults.pm +++ b/FS/FS/ConfDefaults.pm @@ -51,6 +51,9 @@ sub cust_fields_avail { ( 'Cust# | Cust. Status | Name | Company | Address 1 | Address 2 | City | State | Zip | Country | Day phone | Night phone | Invoicing email(s)' => 'custnum | Status | Last, First | Company | (all address fields ) | Day phone | Night phone | Invoicing email(s)', + 'Cust# | Name | Address 1 | Address 2 | City | State | Zip | Country | Day phone | Night phone | Fax number | Invoicing email(s) | Payment Type' => + 'custnum | Last, First | (all address fields ) | ( all phones ) | Invoicing email(s) | Payment Type', + ); } =back diff --git a/FS/FS/UI/Web.pm b/FS/FS/UI/Web.pm index 29e06bcc6..3f786dd0e 100644 --- a/FS/FS/UI/Web.pm +++ b/FS/FS/UI/Web.pm @@ -220,7 +220,9 @@ sub cust_header { 'Country' => 'country_full', 'Day phone' => 'daytime', # XXX should use msgcat, but how? 'Night phone' => 'night', # XXX should use msgcat, but how? + 'Fax number' => 'fax', 'Invoicing email(s)' => 'invoicing_list_emailonly_scalar', + 'Payment Type' => 'payby', ); my %header2colormethod = ( diff --git a/httemplate/search/cust_main_ADV.cgi b/httemplate/search/cust_main_ADV.cgi index 17b17488b..1889b6c82 100755 --- a/httemplate/search/cust_main_ADV.cgi +++ b/httemplate/search/cust_main_ADV.cgi @@ -3,32 +3,13 @@ 'name' => 'customers', 'query' => $sql_query, 'count_query' => $count_query, - 'header' => [ '#', - 'Name', - 'Address', - 'Phone', - 'Night', - 'Fax', - 'Email', - 'Payment Type', + 'header' => [ FS::UI::Web::cust_header( + $cgi->param('cust_fields') + ), @extra_headers, ], 'fields' => [ - 'custnum', - 'name', - sub { my $c = shift; - $c->address1 . - ($c->address2 ? ' '.$c->address2 : ''). - $c->city. ', '. $c->state. ' '. $c->zip. - ($c->country ne $countrydefault ? ' '. $c->country - : '' - ); - }, - 'daytime', - 'night', - 'fax', - 'email', - 'payby', + \&FS::UI::Web::cust_fields, @extra_fields, ], ) @@ -102,15 +83,41 @@ my $addl_from = 'LEFT JOIN cust_pkg USING ( custnum ) '; my $count_query = "SELECT COUNT(*) FROM cust_main $extra_sql"; -my $select; -if ($dbh->{Driver}->{Name} eq 'Pg') { - $select = "*, array_to_string(array(select pkg from cust_pkg left join part_pkg using ( pkgpart ) where cust_main.custnum = cust_pkg.custnum $pkgwhere),'|') as magic"; -}elsif ($dbh->{Driver}->{Name} =~ /^mysql/i) { - $select = "*, GROUP_CONCAT(pkg SEPARATOR '|') as magic"; -}else{ - warn "warning: unknown database type ". $dbh->{Driver}->{Name}. - "omitting packing information from report."; +my $select = '*'; +my (@extra_headers) = (); +my (@extra_fields) = (); + +if ($cgi->param('flattened_pkgs')) { + + if ($dbh->{Driver}->{Name} eq 'Pg') { + + $select .= ", array_to_string(array(select pkg from cust_pkg left join part_pkg using ( pkgpart ) where cust_main.custnum = cust_pkg.custnum $pkgwhere),'|') as magic"; + + }elsif ($dbh->{Driver}->{Name} =~ /^mysql/i) { + $select .= ", GROUP_CONCAT(pkg SEPARATOR '|') as magic"; + $addl_from .= " LEFT JOIN part_pkg using ( pkgpart )"; + }else{ + warn "warning: unknown database type ". $dbh->{Driver}->{Name}. + "omitting packing information from report."; + } + + my $header_query = "SELECT COUNT(cust_pkg.custnum = cust_main.custnum) AS count FROM cust_main $addl_from $extra_sql $pkgwhere group by cust_main.custnum order by count desc limit 1"; + + my $sth = dbh->prepare($header_query) or die dbh->errstr; + $sth->execute() or die $sth->errstr; + my $headerrow = $sth->fetchrow_arrayref; + my $headercount = $headerrow ? $headerrow->[0] : 0; + while($headercount) { + unshift @extra_headers, "Package ". $headercount; + unshift @extra_fields, eval q!sub {my $c = shift; + my @a = split '\|', $c->magic; + my $p = $a[!.--$headercount. q!]; + $p; + };!; + } + } + my $sql_query = { 'table' => 'cust_main', 'select' => $select, @@ -118,21 +125,5 @@ my $sql_query = { 'extra_sql' => "$extra_sql $orderby", }; -my $header_query = "SELECT COUNT(cust_pkg.custnum = cust_main.custnum) AS count FROM cust_main $addl_from $extra_sql $pkgwhere group by cust_main.custnum order by count desc limit 1"; - -my $sth = dbh->prepare($header_query) or die dbh->errstr; -$sth->execute() or die $sth->errstr; -my $headerrow = $sth->fetchrow_arrayref; -my $headercount = $headerrow ? $headerrow->[0] : 0; -my (@extra_headers) = (); -my (@extra_fields) = (); -while($headercount) { - unshift @extra_headers, "Package ". $headercount; - unshift @extra_fields, eval q!sub {my $c = shift; - my @a = split '\|', $c->magic; - my $p = $a[!.--$headercount. q!]; - $p; - };!; -} diff --git a/httemplate/search/report_cust_main.html b/httemplate/search/report_cust_main.html index f32c3aa18..57b84cb37 100755 --- a/httemplate/search/report_cust_main.html +++ b/httemplate/search/report_cust_main.html @@ -35,6 +35,15 @@ + + Display options + + <% include( '/elements/tr-select-cust-fields.html' ) %> + + + Add package columns + +
-- 2.11.0