advanced customer report rearrangement
authorjeff <jeff>
Wed, 28 Nov 2007 18:49:20 +0000 (18:49 +0000)
committerjeff <jeff>
Wed, 28 Nov 2007 18:49:20 +0000 (18:49 +0000)
FS/FS/ConfDefaults.pm
FS/FS/UI/Web.pm
httemplate/search/cust_main_ADV.cgi
httemplate/search/report_cust_main.html

index baee0bb..21da302 100644 (file)
@@ -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
index 29e06bc..3f786dd 100644 (file)
@@ -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 = (
index 17b1748..1889b6c 100755 (executable)
@@ -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;
-                                    };!;
-}
 
 </%init>
index f32c3aa..57b84cb 100755 (executable)
         <TD><INPUT TYPE="checkbox" NAME="cancelled_pkgs"></TD>
     </TR>
 
+    <TR>
+      <TH BGCOLOR="#e8e8e8" COLSPAN=2 ALIGN="left"><FONT SIZE="+1">Display options</FONT></TH>
+    </TR>
+    <% include( '/elements/tr-select-cust-fields.html' ) %>
+
+    <TR>
+      <TD ALIGN="right" VALIGN="center">Add package columns</TD>
+        <TD><INPUT TYPE="checkbox" NAME="flattened_pkgs"></TD>
+    </TR>
   </TABLE>
 
 <BR>