[freeside-commits] branch FREESIDE_3_BRANCH updated. 23b21291aa61a439aee71efb5b3b1e0057f6b1ed

Mark Wells mark at 420.am
Fri Jul 3 15:32:10 PDT 2015


The branch, FREESIDE_3_BRANCH has been updated
       via  23b21291aa61a439aee71efb5b3b1e0057f6b1ed (commit)
       via  811a439e2a3600dc563e976f5d783e7881faff54 (commit)
      from  83303105b038082cdb800a4f7322b4dd08b6fe89 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 23b21291aa61a439aee71efb5b3b1e0057f6b1ed
Author: Mark Wells <mark at freeside.biz>
Date:   Fri Jul 3 15:29:00 2015 -0700

    make new gross sales calculation optional (and non-default on 3.x), #25943

diff --git a/FS/FS/Report/Table/Monthly.pm b/FS/FS/Report/Table/Monthly.pm
index 0ff7efd..f4ba020 100644
--- a/FS/FS/Report/Table/Monthly.pm
+++ b/FS/FS/Report/Table/Monthly.pm
@@ -182,9 +182,15 @@ sub data {
     push @{$data{label}}, "$smonth/$syear"; # sprintf?
 
     my $speriod = timelocal(0,0,0,1,$smonth-1,$syear);
-    push @{$data{speriod}}, $speriod;
     if ( ++$smonth == 13 ) { $syear++; $smonth=1; }
     my $eperiod = timelocal(0,0,0,1,$smonth-1,$syear);
+    # 12-month mode: show results in a sliding window ending at $eperiod,
+    # but starting 12 months before.
+    if ( $self->{'12mo'}) {
+      $speriod = timelocal(0,0,0,1,$smonth-1,$syear-1);
+    }
+
+    push @{$data{speriod}}, $speriod;
     push @{$data{eperiod}}, $eperiod;
 
     my $col = 0; # a "column" here is the data corresponding to an item
diff --git a/FS/FS/cust_bill/Search.pm b/FS/FS/cust_bill/Search.pm
index b9649cd..726d5bc 100644
--- a/FS/FS/cust_bill/Search.pm
+++ b/FS/FS/cust_bill/Search.pm
@@ -7,6 +7,7 @@ use FS::Record qw( qsearchs dbh );
 use FS::cust_main;
 use FS::access_user;
 use FS::Conf;
+use charnames ':full';
                                                                                 
 =item search HASHREF                                                            
                                                                                 
@@ -18,7 +19,9 @@ following additional parameters valid:
 
 =over 4                                                                         
 
-=item newest_percust
+=item newest_percust - only show the most recent invoice for each customer
+
+=item invoiced - show the invoiced amount (excluding discounts) instead of gross sales
 
 =back
 
@@ -27,7 +30,8 @@ following additional parameters valid:
 sub search {
   my( $class, $params ) = @_;
 
-  my( $count_query, $count_addl ) = ( '', '' );
+  my $count_query = '';
+  my @count_addl;
 
   #some false laziness w/cust_bill::re_X
 
@@ -77,21 +81,30 @@ sub search {
 
     my $money = (FS::Conf->new->config('money_char') || '$') . '%.2f';
 
-    $count_query = 'SELECT COUNT(*), '. join(', ',
-                     map "SUM($_)",
-                         ( 'charged + discounted',
-                           'discounted',
-                           'credited',
-                           'charged - credited',
-                           'charged - credited - paid',
-                         )
-                   );
-    $count_addl = [ "$money sales (gross)",
-                    "− $money discounted",
-                    "− $money credited",
-                    "= $money sales (net)",
+    my @sums = ( 'credited',                  # credits
+                 'charged - credited',        # net sales
+                 'charged - credited - paid', # balance due
+               );
+
+    @count_addl = ( "\N{MINUS SIGN} $money credited",
+                    "= $money net sales",
                     "$money outstanding balance",
-                  ];
+                  );
+
+    if ( $params->{'invoiced'} ) {
+
+      unshift @sums, 'charged';
+      unshift @count_addl, "$money invoiced";
+
+    } else {
+
+      unshift @sums, 'charged + discounted', 'discounted';
+      unshift @count_addl, "$money gross sales",
+                           "\N{MINUS SIGN} $money discounted";
+
+    }
+
+    $count_query = 'SELECT COUNT(*), '. join(', ', map "SUM($_)", @sums);
   }
   $count_query .=  " FROM cust_bill $join $extra_sql";
 
@@ -115,7 +128,7 @@ sub search {
     'order_by'  => 'ORDER BY '. ( $params->{'order_by'} || 'cust_bill._date' ),
 
     'count_query' => $count_query,
-    'count_addl'  => $count_addl,
+    'count_addl'  => \@count_addl,
   };
 
 }
diff --git a/httemplate/graph/elements/monthly.html b/httemplate/graph/elements/monthly.html
index 4b988f1..1a94281 100644
--- a/httemplate/graph/elements/monthly.html
+++ b/httemplate/graph/elements/monthly.html
@@ -27,7 +27,7 @@ Example:
     'start_year'      => $syear,
     'end_month'       => $emonth,
     'end_year'        => $eyear,
-
+    '12mo'            => 0,
 
     #optional, pulled from CGI params if not specified, 
     #only if 'daily' option is given
@@ -96,6 +96,8 @@ $opt{'start_year'}  ||= $cgi->param('start_year'); # || 1899+$curyear;
 $opt{'end_month'} ||= $cgi->param('end_month'); # || $curmon+1;
 $opt{'end_year'}  ||= $cgi->param('end_year'); # || 1900+$curyear;
 
+$opt{'12mo'} ||= $cgi->param('12mo') ? 1 : 0;
+
 $opt{'projection'} ||= $cgi->param('projection') ? 1 : 0;
 
 if ( $opt{'daily'} ) { # daily granularity
@@ -119,6 +121,7 @@ my %reportopts = (
       'end_day'      => $opt{'end_day'},
       'end_month'    => $opt{'end_month'},
       'end_year'     => $opt{'end_year'},
+      '12mo'         => $opt{'12mo'},
       'projection'   => $opt{'projection'},
       'agentnum'     => $opt{'agentnum'},
       'refnum'       => $opt{'refnum'},
diff --git a/httemplate/graph/money_time.cgi b/httemplate/graph/money_time.cgi
index b44adea..aa17eb2 100644
--- a/httemplate/graph/money_time.cgi
+++ b/httemplate/graph/money_time.cgi
@@ -41,35 +41,35 @@ my $referralname = $part_referral ? $part_referral->referral.' ' : '';
 
 # need to clean this up. the false symmetry of "gross" and "net" everything
 # makes it aesthetically hard to make this report more useful.
-my @items = qw( gross    netsales
-                discounted
+my @items = ($cgi->param('exclude_discount') ? 'invoiced' : 'gross');
+push @items,
+            qw( discounted   netsales
                 credits  netcredits
                 payments receipts
                 refunds  netrefunds
                 cashflow netcashflow
-              );
-if ( $cgi->param('12mo') == 1 ) {
-  @items = map $_.'_12mo', @items;
-}
+            );
 
 my %label = (
   'gross'       => 'Gross Sales',
-  'netsales'    =>   'Net Sales',
+  'invoiced'    => 'Invoiced Sales',
+  'netsales'    => 'Net Sales',
   'discounted'  => 'Discounts',
   'credits'     => 'Gross Credits',
-  'netcredits'  =>   'Net Credits',
+  'netcredits'  => 'Net Credits',
   'payments'    => 'Gross Receipts',
-  'receipts'    =>   'Net Receipts',
+  'receipts'    => 'Net Receipts',
   'refunds'     => 'Gross Refunds',
-  'netrefunds'  =>   'Net Refunds',
+  'netrefunds'  => 'Net Refunds',
   'cashflow'    => 'Gross Cashflow',
-  'netcashflow' =>   'Net Cashflow',
+  'netcashflow' => 'Net Cashflow',
 );
 
 my %graph_suffix = (
  'gross'       => ' (invoiced + discounts)', 
+ 'invoiced'    => '',
  'netsales'    => ' (invoiced - applied credits)',
- 'discounted'  => ' (discounts)',
+ 'discounted'  => '',
  'credits'     => ' (credited)',
  'netcredits'  => ' (applied credits)',
  'payments'    => ' (payments)',
@@ -81,14 +81,9 @@ my %graph_suffix = (
 );
 my %graph_label = map { $_ => $label{$_}.$graph_suffix{$_} } keys %label;
 
-$label{$_.'_12mo'} = $label{$_}. " (prev 12 months)"
-  foreach keys %label;
-
-$graph_label{$_.'_12mo'} = $graph_label{$_}. " (prev 12 months)"
-  foreach keys %graph_label;
-
 my %color = (
   'gross'       => '9999ff', #light blue
+  'invoiced'    => '9999ff', #light blue
   'netsales'    => '0000cc', #blue
   'credits'     => 'ff9999', #light red
   'netcredits'  => 'cc0000', #red
@@ -108,6 +103,7 @@ $ar .= ";cust_classnum=$_" foreach @classnums;
 
 my %link = (
   'gross'      => "${p}search/cust_bill.html?$ar;",
+  'invoiced'   => "${p}search/cust_bill.html?$ar;invoiced=1;",
   'netsales'   => "${p}search/cust_bill.html?$ar;net=1;",
   'credits'    => "${p}search/cust_credit.html?$ar;",
   'netcredits' => "${p}search/cust_credit_bill.html?$ar;",
@@ -119,4 +115,12 @@ my %link = (
 );
 # XXX link 12mo?
 
+if ( $cgi->param('12mo') ) {
+  $label{$_} .= " (prev 12 months)"
+    foreach keys %label;
+
+  $graph_label{$_} .= " (prev 12 months)"
+    foreach keys %graph_label;
+}
+
 </%init>
diff --git a/httemplate/graph/report_money_time.html b/httemplate/graph/report_money_time.html
index 315d31b..64fab14 100644
--- a/httemplate/graph/report_money_time.html
+++ b/httemplate/graph/report_money_time.html
@@ -36,9 +36,25 @@
           )
 %>
 
-<TR>
-  <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="12mo" VALUE="1"></TD>
-  <TD>Show 12 month totals instead of monthly values</TD>
+<tr>
+  <td />
+  <td>
+    <& /elements/checkbox.html,
+      field => '12mo',
+      value => 1,
+    &>
+    <% emt('Show 12 month totals instead of monthly values') %>
+  </td>
+</tr>
+  <td />
+  <td>
+    <& /elements/checkbox.html,
+      field => 'exclude_discount',
+      value => 1,
+      curr_value => 1, #3.x only
+    &>
+    <% emt('Exclude discounts from total sales') %>
+  </td>
 </TR>
 
 </TABLE>
diff --git a/httemplate/search/cust_bill.html b/httemplate/search/cust_bill.html
index 368120d..62f5f7a 100755
--- a/httemplate/search/cust_bill.html
+++ b/httemplate/search/cust_bill.html
@@ -8,7 +8,7 @@
   'count_addl'  => $count_addl,
   'redirect'    => $link,
   'header'      => [ emt('Invoice #'),
-                     emt('Gross Amount'),
+                     emt($invoiced ? 'Charged' : 'Gross Amount'),
                      emt('Discount'),
                      emt('Credits'),
                      emt('Net Amount'),
@@ -18,7 +18,7 @@
                    ],
   'fields'      => [
     'display_invnum',
-    'gross',
+    $invoiced ? 'charged' : 'gross',
     'discounted',
     'credited',
     'net',
@@ -28,7 +28,7 @@
   ],
   'sort_fields' => [
     'COALESCE( agent_invid, invnum )',
-    'gross',
+    $invoiced ? 'charged' : 'gross',
     'discounted',
     'credited',
     'net',
@@ -87,6 +87,9 @@ my( $count_query, $sql_query );
 my $count_addl = '';
 my %search = ();
 
+# show invoiced amount (charged) instead of gross sales
+my $invoiced = $cgi->param('invoiced') ? 1 : 0;
+
 if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
 
   my $join_cust_main = FS::UI::Web::join_cust_main('cust_bill');
@@ -128,11 +131,12 @@ if ( $cgi->param('invnum') =~ /^\s*(FS-)?(\d+)\s*$/ ) {
     ($search{'days'}, my $field) = ($2, $3);
     $field = "_date" if $field eq 'date';
     $search{'order_by'} = "cust_bill.$field";
+    $search{'invoiced'} = 1; # preserve old behavior under 3.x
   }
 
   #scalars
   for (qw( agentnum custnum cust_status refnum invnum_min invnum_max
-           open net newest_percust 
+           open net newest_percust invoiced
 
       )) 
   {
diff --git a/httemplate/search/report_cust_bill.html b/httemplate/search/report_cust_bill.html
index b8ba982..92f619b 100644
--- a/httemplate/search/report_cust_bill.html
+++ b/httemplate/search/report_cust_bill.html
@@ -99,7 +99,12 @@
 <TR>
     <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="open" VALUE="1" CHECKED></TD>
     <TD><% mt('Show only open invoices') |h %></TD>
-  </TR>
+</TR>
+
+<TR>
+    <TD ALIGN="right"><INPUT TYPE="checkbox" NAME="invoiced" VALUE="1" CHECKED></TD>
+    <TD><% emt('Exclude discounts from gross amount billed'), %></TD>
+</TR>
 
 % unless ( $custnum ) {
   <TR>

commit 811a439e2a3600dc563e976f5d783e7881faff54
Author: Mark Wells <mark at freeside.biz>
Date:   Fri Jul 3 11:42:02 2015 -0700

    include discounts in gross sales reports, #25943

diff --git a/FS/FS/Report/Table.pm b/FS/FS/Report/Table.pm
index 4797473..eef983d 100644
--- a/FS/FS/Report/Table.pm
+++ b/FS/FS/Report/Table.pm
@@ -266,6 +266,36 @@ sub netrefunds {
   );
 }
 
+=item discounted: The sum of discounts on invoices in the period.
+
+=cut
+
+sub discounted {
+  my( $self, $speriod, $eperiod, $agentnum, %opt) = @_;
+  $self->scalar_sql('SELECT SUM(cust_bill_pkg_discount.amount)
+    FROM cust_bill_pkg_discount
+      JOIN cust_bill_pkg USING  ( billpkgnum )
+      JOIN cust_bill     USING  ( invnum )
+      JOIN cust_main     USING  ( custnum )
+    WHERE '. $self->in_time_period_and_agent( $speriod,
+                                              $eperiod,
+                                              $agentnum,
+                                              'cust_bill._date'
+                                            ).
+              $self->for_opts(%opt)
+  );
+}
+
+=item gross: invoiced + discounted
+
+=cut
+
+sub gross {
+  my( $self, $speriod, $eperiod, $agentnum, %opt) = @_;
+    $self->invoiced(   $speriod, $eperiod, $agentnum, %opt)
+  + $self->discounted( $speriod, $eperiod, $agentnum, %opt);
+}
+
 #XXX docs
 
 #these should be auto-generated or $AUTOLOADed or something
diff --git a/FS/FS/cust_bill/Search.pm b/FS/FS/cust_bill/Search.pm
index 1fc818d..b9649cd 100644
--- a/FS/FS/cust_bill/Search.pm
+++ b/FS/FS/cust_bill/Search.pm
@@ -6,14 +6,15 @@ use FS::UI::Web;
 use FS::Record qw( qsearchs dbh );
 use FS::cust_main;
 use FS::access_user;
+use FS::Conf;
                                                                                 
 =item search HASHREF                                                            
                                                                                 
 (Class method)                                                                  
                                                                                 
-Returns a qsearch hash expression to search for parameters specified in HASHREF.
-In addition to all parameters accepted by search_sql_where, the following
-additional parameters valid:
+Returns a qsearch hash expression to search for parameters specified in
+HASHREF.  In addition to all parameters accepted by search_sql_where, the
+following additional parameters valid:
 
 =over 4                                                                         
 
@@ -38,35 +39,77 @@ sub search {
 
   my $join_cust_main = FS::UI::Web::join_cust_main('cust_bill');
 
+  # get discounted, credited, and paid amounts here, for use in report
+  #
+  # Testing shows that this is by far the most efficient way to do the 
+  # joins. In particular it's almost 100x faster to join to an aggregate
+  # query than to put the subquery in a select expression. It also makes
+  # it more convenient to do arithmetic between columns, use them as sort
+  # keys, etc.
+  #
+  # Each ends with a RIGHT JOIN cust_bill so that it includes all invnums,
+  # even if they have no discounts/credits/payments; the total amount is then
+  # coalesced to zero.
+  my $join = "$join_cust_main
+  JOIN (
+    SELECT COALESCE(SUM(cust_bill_pkg_discount.amount), 0) AS discounted,
+      invnum
+      FROM cust_bill_pkg_discount
+        JOIN cust_bill_pkg USING (billpkgnum)
+        RIGHT JOIN cust_bill USING (invnum)
+      GROUP BY invnum
+    ) AS _discount USING (invnum)
+  JOIN (
+    SELECT COALESCE(SUM(cust_credit_bill.amount), 0) AS credited, invnum
+      FROM cust_credit_bill
+        RIGHT JOIN cust_bill USING (invnum)
+      GROUP BY invnum
+    ) AS _credit USING (invnum)
+  JOIN (
+    SELECT COALESCE(SUM(cust_bill_pay.amount), 0) AS paid, invnum
+      FROM cust_bill_pay
+        RIGHT JOIN cust_bill USING (invnum)
+      GROUP BY invnum
+    ) AS _pay USING (invnum)
+  ";
+
   unless ( $count_query ) {
+
+    my $money = (FS::Conf->new->config('money_char') || '$') . '%.2f';
+
     $count_query = 'SELECT COUNT(*), '. join(', ',
                      map "SUM($_)",
-                         ( 'charged',
-                           FS::cust_bill->net_sql,
-                           FS::cust_bill->owed_sql,
+                         ( 'charged + discounted',
+                           'discounted',
+                           'credited',
+                           'charged - credited',
+                           'charged - credited - paid',
                          )
                    );
-    $count_addl = [ '$%.2f invoiced (gross)',
-                    '$%.2f invoiced (net)',
-                    '$%.2f outstanding balance',
+    $count_addl = [ "$money sales (gross)",
+                    "− $money discounted",
+                    "− $money credited",
+                    "= $money sales (net)",
+                    "$money outstanding balance",
                   ];
   }
-  $count_query .=  " FROM cust_bill $join_cust_main $extra_sql";
+  $count_query .=  " FROM cust_bill $join $extra_sql";
 
   #$sql_query =
   +{
     'table'     => 'cust_bill',
-    'addl_from' => $join_cust_main,
+    'addl_from' => $join,
     'hashref'   => {},
     'select'    => join(', ',
                      'cust_bill.*',
                      #( map "cust_main.$_", qw(custnum last first company) ),
                      'cust_main.custnum as cust_main_custnum',
                      FS::UI::Web::cust_sql_fields(),
-                     #$class->owed_sql. ' AS owed',
-                     #$class->net_sql.  ' AS net',
-                     FS::cust_bill->owed_sql. ' AS owed',
-                     FS::cust_bill->net_sql.  ' AS net',
+                     '(charged + discounted) as gross',
+                     'discounted',
+                     'credited',
+                     '(charged - credited) as net',
+                     '(charged - credited - paid) as owed',
                    ),
     'extra_sql' => $extra_sql,
     'order_by'  => 'ORDER BY '. ( $params->{'order_by'} || 'cust_bill._date' ),
@@ -183,13 +226,7 @@ sub search_sql_where {
     @classnum = grep /^(\d*)$/, @classnum;
 
     if ( @classnum ) {
-      push @search, '( '. join(' OR ', map {
-                                             $_ ? "cust_main.classnum = $_"
-                                                : "cust_main.classnum IS NULL"
-                                           }
-                                           @classnum
-                              ).
-                    ' )';
+      push @search, 'COALESCE(cust_main.classnum, 0) IN ('.join(',', @classnum).')';
     }
 
   }
@@ -218,6 +255,7 @@ sub search_sql_where {
     push @search, "cust_bill.invnum <= $1";
   }
 
+  # these are from parse_lt_gt, and should already be sanitized
   #charged
   if ( $param->{charged} ) {
     my @charged = ref($param->{charged})
@@ -228,21 +266,22 @@ sub search_sql_where {
                       @charged;
   }
 
-  my $owed_sql = FS::cust_bill->owed_sql;
+  #my $owed_sql = FS::cust_bill->owed_sql;
+  my $owed_sql = '(cust_bill.charged - credited - paid)';
+  my $net_sql = '(cust_bill.charged - credited)';
 
   #owed
   if ( $param->{owed} ) {
     my @owed = ref($param->{owed})
                  ? @{ $param->{owed} }
                  : ($param->{owed});
-    push @search, map { s/^owed/$owed_sql/; $_; }
-                      @owed;
+    push @search, map { s/^owed/$owed_sql/ } @owed;
   }
 
   #open/net flags
   push @search, "0 != $owed_sql"
     if $param->{'open'};
-  push @search, '0 != '. FS::cust_bill->net_sql
+  push @search, "0 != $net_sql"
     if $param->{'net'};
 
   #days
diff --git a/httemplate/graph/money_time.cgi b/httemplate/graph/money_time.cgi
index 9071fc7..b44adea 100644
--- a/httemplate/graph/money_time.cgi
+++ b/httemplate/graph/money_time.cgi
@@ -39,8 +39,10 @@ if ( $cgi->param('refnum') =~ /^(\d+)$/ ) {
 }
 my $referralname = $part_referral ? $part_referral->referral.' ' : '';
 
-
-my @items = qw( invoiced netsales
+# need to clean this up. the false symmetry of "gross" and "net" everything
+# makes it aesthetically hard to make this report more useful.
+my @items = qw( gross    netsales
+                discounted
                 credits  netcredits
                 payments receipts
                 refunds  netrefunds
@@ -51,8 +53,9 @@ if ( $cgi->param('12mo') == 1 ) {
 }
 
 my %label = (
-  'invoiced'    => 'Gross Sales',
+  'gross'       => 'Gross Sales',
   'netsales'    =>   'Net Sales',
+  'discounted'  => 'Discounts',
   'credits'     => 'Gross Credits',
   'netcredits'  =>   'Net Credits',
   'payments'    => 'Gross Receipts',
@@ -64,8 +67,9 @@ my %label = (
 );
 
 my %graph_suffix = (
- 'invoiced'    => ' (invoiced)', 
+ 'gross'       => ' (invoiced + discounts)', 
  'netsales'    => ' (invoiced - applied credits)',
+ 'discounted'  => ' (discounts)',
  'credits'     => ' (credited)',
  'netcredits'  => ' (applied credits)',
  'payments'    => ' (payments)',
@@ -84,7 +88,7 @@ $graph_label{$_.'_12mo'} = $graph_label{$_}. " (prev 12 months)"
   foreach keys %graph_label;
 
 my %color = (
-  'invoiced'    => '9999ff', #light blue
+  'gross'       => '9999ff', #light blue
   'netsales'    => '0000cc', #blue
   'credits'     => 'ff9999', #light red
   'netcredits'  => 'cc0000', #red
@@ -94,6 +98,7 @@ my %color = (
   'netrefunds'  => 'ff9900', #orange
   'cashflow'    => '99cc33', #light olive
   'netcashflow' => '339900', #olive
+  'discounted'  => 'cc33cc', #purple-ish?
 );
 $color{$_.'_12mo'} = $color{$_}
   foreach keys %color;
@@ -102,7 +107,7 @@ my $ar = "agentnum=$agentnum;refnum=$refnum";
 $ar .= ";cust_classnum=$_" foreach @classnums;
 
 my %link = (
-  'invoiced'   => "${p}search/cust_bill.html?$ar;",
+  'gross'      => "${p}search/cust_bill.html?$ar;",
   'netsales'   => "${p}search/cust_bill.html?$ar;net=1;",
   'credits'    => "${p}search/cust_credit.html?$ar;",
   'netcredits' => "${p}search/cust_credit_bill.html?$ar;",
@@ -110,6 +115,7 @@ my %link = (
   'receipts'   => "${p}search/cust_bill_pay.html?$ar;",
   'refunds'    => "${p}search/cust_refund.html?magic=_date;$ar;",
   'netrefunds' => "${p}search/cust_credit_refund.html?$ar;",
+  'discounted' => "${p}search/cust_bill_pkg_discount.html?$ar;",
 );
 # XXX link 12mo?
 
diff --git a/httemplate/search/cust_bill.html b/httemplate/search/cust_bill.html
index bd302c6..368120d 100755
--- a/httemplate/search/cust_bill.html
+++ b/httemplate/search/cust_bill.html
@@ -1,61 +1,82 @@
 <& elements/search.html,
-                 'title'       => emt('Invoice Search Results'),
-                 'html_init'   => $html_init,
-                 'menubar'     => $menubar,
-                 'name'        => 'invoices',
-                 'query'       => $sql_query,
-                 'count_query' => $count_query,
-                 'count_addl'  => $count_addl,
-                 'redirect'    => $link,
-                 'header'      => [ emt('Invoice #'),
-                                    emt('Balance'),
-                                    emt('Net Amount'),
-                                    emt('Gross Amount'),
-                                    emt('Date'),
-                                    FS::UI::Web::cust_header(),
-                                  ],
-                 'fields'      => [
-                   'display_invnum',
-                   sub { sprintf($money_char.'%.2f', shift->get('owed') ) },
-                   sub { sprintf($money_char.'%.2f', shift->get('net') ) },
-                   sub { sprintf($money_char.'%.2f', shift->charged     ) },
-                   sub { time2str('%b %d %Y', shift->_date ) },
-                   \&FS::UI::Web::cust_fields,
-                 ],
-                 'sort_fields' => [
-                   'COALESCE( agent_invid, invnum )',
-                   FS::cust_bill->owed_sql,
-                   FS::cust_bill->net_sql,
-                   'charged',
-                   '_date',
-                 ],
-                 'align' => 'rrrrl'.FS::UI::Web::cust_aligns(),
-                 'links' => [
-                   $link,
-                   $link,
-                   $link,
-                   $link,
-                   $link,
-                   ( map { $_ ne 'Cust. Status' ? $clink : '' }
-                         FS::UI::Web::cust_header()
-                   ),
-                 ],
-                 'color' => [ 
-                              '',
-                              '',
-                              '',
-                              '',
-                              '',
-                              FS::UI::Web::cust_colors(),
-                            ],
-                 'style' => [ 
-                              '',
-                              '',
-                              '',
-                              '',
-                              '',
-                              FS::UI::Web::cust_styles(),
-                            ],
+  'title'       => emt('Invoice Search Results'),
+  'html_init'   => $html_init,
+  'menubar'     => $menubar,
+  'name'        => 'invoices',
+  'query'       => $sql_query,
+  'count_query' => $count_query,
+  'count_addl'  => $count_addl,
+  'redirect'    => $link,
+  'header'      => [ emt('Invoice #'),
+                     emt('Gross Amount'),
+                     emt('Discount'),
+                     emt('Credits'),
+                     emt('Net Amount'),
+                     emt('Balance'),
+                     emt('Date'),
+                     FS::UI::Web::cust_header(),
+                   ],
+  'fields'      => [
+    'display_invnum',
+    'gross',
+    'discounted',
+    'credited',
+    'net',
+    'owed',
+    sub { time2str('%b %d %Y', shift->_date ) },
+    \&FS::UI::Web::cust_fields,
+  ],
+  'sort_fields' => [
+    'COALESCE( agent_invid, invnum )',
+    'gross',
+    'discounted',
+    'credited',
+    'net',
+    'owed',
+    '_date',
+  ],
+  'format' => [
+    '',
+    $money_char.'%.2f',
+    $money_char.'%.2f',
+    $money_char.'%.2f',
+    $money_char.'%.2f',
+    $money_char.'%.2f',
+    '',
+  ],
+  'align' => 'rrrrrrl'.FS::UI::Web::cust_aligns(),
+  'links' => [
+    $link,
+    $link,
+    $link,
+    $link,
+    $link,
+    $link,
+    $link,
+    ( map { $_ ne 'Cust. Status' ? $clink : '' }
+          FS::UI::Web::cust_header()
+    ),
+  ],
+  'color' => [ 
+               '',
+               '',
+               '',
+               '',
+               '',
+               '',
+               '',
+               FS::UI::Web::cust_colors(),
+             ],
+  'style' => [ 
+               '',
+               '',
+               '',
+               '',
+               '',
+               '',
+               '',
+               FS::UI::Web::cust_styles(),
+             ],
 &>
 <%init>
 
diff --git a/httemplate/search/elements/search-html.html b/httemplate/search/elements/search-html.html
index 1348995..12f6c1e 100644
--- a/httemplate/search/elements/search-html.html
+++ b/httemplate/search/elements/search-html.html
@@ -378,9 +378,16 @@ $rows => []
 %     my $sizes    = $opt{'size'}  ? [ @{$opt{'size'}}  ] : [];
 %     my $styles   = $opt{'style'} ? [ @{$opt{'style'}} ] : [];
 %     my $cstyles  = $opt{'cell_style'} ? [ @{$opt{'cell_style'}} ] : [];
+%     my $formats  = $opt{'format'} ? [ @{$opt{'format'}} ] : [];
 %
 %     foreach my $field (
 %
+%       # if the value of the field is an arrayref, then construct a table in
+%       # the cell.
+%       # if it's a (non-empty) scalar, and a format has been specified, then
+%       # format the scalar with that.
+%       # otherwise, just output the value.
+%       # XXX we should also do date formats like this
 %       map {
 %             if ( ref($_) eq 'ARRAY' ) {
 %
@@ -444,10 +451,17 @@ $rows => []
 %               '</table>';
 %
 %             } else {
+%               if ( length($_) > 0 and my $format = shift @$formats ) {
+%                 $_ = sprintf($format, $_);
+%               }
 %               $_;
 %             }
 %           }
 %
+%       # get the value of the field spec:
+%       # - if the spec is a coderef, evaluate the coderef
+%       # - if the spec is a string, call that string as a method
+%       # - if the spec is an integer, get the field in that position
 %       map {
 %             if ( ref($_) eq 'CODE' ) {
 %               &{$_}($row);
diff --git a/httemplate/search/report_cust_bill.html b/httemplate/search/report_cust_bill.html
index 8734467..b8ba982 100644
--- a/httemplate/search/report_cust_bill.html
+++ b/httemplate/search/report_cust_bill.html
@@ -29,8 +29,7 @@
       label         => mt('Customer Class'),
       field         => 'cust_classnum',
       multiple      => 1,
-     'pre_options'  => [ '' => emt('(none)') ],
-     'all_selected' => 1,
+     'pre_options'  => [ 0 => emt('(none)') ],
   &>
 
 %   if ( $cust_main ) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/Report/Table.pm                       |   30 ++++++
 FS/FS/Report/Table/Monthly.pm               |    8 +-
 FS/FS/cust_bill/Search.pm                   |  120 ++++++++++++++++-------
 httemplate/graph/elements/monthly.html      |    5 +-
 httemplate/graph/money_time.cgi             |   50 ++++++----
 httemplate/graph/report_money_time.html     |   22 ++++-
 httemplate/search/cust_bill.html            |  141 ++++++++++++++++-----------
 httemplate/search/elements/search-html.html |   14 +++
 httemplate/search/report_cust_bill.html     |   10 +-
 9 files changed, 280 insertions(+), 120 deletions(-)




More information about the freeside-commits mailing list