Merge branch 'master' of git.freeside.biz:/home/git/freeside
[freeside.git] / httemplate / search / customer_accounting_summary.html
index 5575283..0dab7ce 100644 (file)
@@ -9,8 +9,7 @@
   http_header('Content-Disposition' => qq!attachment;filename="$filename"!);
 
   my $output = '';
-  use IO::String;
-  my $XLS = IO::String->new($output);;
+  my $XLS = IO::String->new($output);
   my $workbook = $format->{class}->new($XLS)
     or die "Error opening .xls file: $!";
 
@@ -88,7 +87,7 @@ as <A HREF="<% "$myself;_type=xls" %>">Excel spreadsheet</A><BR>
 <style type="text/css">
 .report * {
   background-color: #f8f8f8;
-  border: 1px solid black;
+  border: 1px solid #999999;
   padding: 2px;
 }
 .report td {
@@ -108,7 +107,7 @@ as <A HREF="<% "$myself;_type=xls" %>">Excel spreadsheet</A><BR>
 %     my $style = '';
 %     $style .= " rowspan=".$cell->{rowspan} if $cell->{rowspan} > 1;
 %     $style .= " colspan=".$cell->{colspan} if $cell->{colspan} > 1;
-      <<%$td%><%$style%>><% $cell->{value} %></<%$td%>>
+      <<%$td%><%$style%>><% $cell->{value} |h %></<%$td%>>
 %   }
   </tr>
 % }
@@ -122,10 +121,7 @@ die "access denied"
   unless $FS::CurrentUser::CurrentUser->access_right('Financial reports');
 
 my ($agentnum,$sel_agent);
-if ( $cgi->param('agentnum') eq 'all' ) {
-  $agentnum = 0;
-}
-elsif ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
+if ( $cgi->param('agentnum') =~ /^(\d+)$/ ) {
   $agentnum = $1;
   $sel_agent = qsearchs('agent', { 'agentnum' => $agentnum } );
   die "agentnum $agentnum not found!" unless $sel_agent;
@@ -143,9 +139,6 @@ $title .=  $sel_part_referral->referral.' '
 
 $title .= 'Customer Accounting Summary Report';
 
-my @custs = ();
-@custs = qsearch('cust_main', {} );
-
 my @items  = ('netsales', 'cashflow');
 my @params = ( [], [] );
 my $setuprecur = '';
@@ -163,19 +156,23 @@ if ( $cgi->param('setuprecur') ) {
 }
 my @labels = ();
 my @cross_params = ();
-my @custnames = ();
 
 my $status = $cgi->param('status');
 die "invalid status" unless $status =~ /^\w+|$/;
 
-foreach my $cust_main ( @custs ) {
-  # XXX should do this in the qsearch
-  next unless ($status eq '' || $status eq $cust_main->status); 
-  next unless ($agentnum == 0 || $cust_main->agentnum eq $agentnum);
-  next unless ($refnum   == 0 || $cust_main->refnum eq $refnum);
+my %search_hash;
+foreach (qw(agentnum refnum status)) {
+  if ( defined $cgi->param($_) ) {
+    $search_hash{$_} = $cgi->param($_);
+  }
+}
+$search_hash{'classnum'} = [ $cgi->param('cust_classnum') ] 
+  if grep { $_ eq 'cust_classnum' } $cgi->param;
 
-  push @custnames, $cust_main->name;
+my $query = FS::cust_main::Search->search(\%search_hash);
+my @cust_main = qsearch($query);
 
+foreach my $cust_main (@cust_main) {
   push @cross_params, [ ('custnum' => $cust_main->custnum) ];
 }
 
@@ -208,7 +205,7 @@ my @cells; # arrayrefs of cell info
 # header row
 $rows[0] = {};
 $cells[0] = [
-  { header => 1, rowspan => 2, colspan => ($setuprecur ? 2 : 1) },
+  { header => 1, rowspan => 2, colspan => ($setuprecur ? 4 : 3) },
   ($setuprecur ? '' : ()),
   map {
     { header => 1, colspan => 2, value => time2str('%b %Y', $_) },
@@ -228,7 +225,7 @@ $cells[1] = [ '',
 
 # use PDL; # ha ha, I just might.
 my $row = 0;
-foreach my $name (@custnames) { # correspond to cross_params
+foreach my $cust_main (@cust_main) { # correspond to cross_params
   my $skip = 1; # skip the customer iff ALL of their values are zero
   for my $subrow (0..($setuprecur ? 1 : 0)) { # the setup/recur axis
     push @rows, { class => $subrow ? 'shaded' : '' };
@@ -236,9 +233,19 @@ foreach my $name (@custnames) { # correspond to cross_params
     if ( $subrow == 0 ) {
       # customer name
       push @thisrow,
-        { value => $name,
-          header => 1,
-          rowspan => ($setuprecur ? 2 : 1) };
+        { value   => $cust_main->name,
+          header  => 1,
+          rowspan => ($setuprecur ? 2 : 1),
+        },
+        { value   => $cust_main->state, #cust_main->bill_location->state,
+          header  => 1,
+          rowspan => ($setuprecur ? 2 : 1),
+        },
+        { value => $cust_main->salesnum ? $cust_main->sales->salesperson : '',
+          header  => 1,
+          rowspan => ($setuprecur ? 2 : 1),
+        },
+      ;
     } else {
       push @thisrow, '';
     }
@@ -277,6 +284,7 @@ for my $subrow (0..($setuprecur ? 1 : 0)) {
     push @thisrow,
       { value => mt('Total'),
         header => 1,
+        colspan => 3,
         rowspan => ($setuprecur ? 2 : 1), };
   } else {
     push @thisrow, '';