[freeside-commits] branch master updated. 1b84c08aa4c0d92120150dc27b5af6deca484c38

Mark Wells mark at 420.am
Tue Apr 14 13:23:29 PDT 2015


The branch, master has been updated
       via  1b84c08aa4c0d92120150dc27b5af6deca484c38 (commit)
      from  7ce5e2e87811cacb77633369b9cb7f60df60abbc (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 1b84c08aa4c0d92120150dc27b5af6deca484c38
Author: Mark Wells <mark at freeside.biz>
Date:   Tue Apr 14 13:23:00 2015 -0700

    when previous invoice due dates are shown on invoice, change placement of current due date, #31382

diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index 2479ef6..c5a416b 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -1292,15 +1292,6 @@ sub print_generic {
   }
   $invoice_data{'taxtotal'} = sprintf('%.2f', $taxtotal);
 
-  push @buf,['','-----------'];
-  push @buf,[$self->mt( 
-              (!$self->enable_previous)
-               ? 'Total Charges'
-               : 'Total New Charges'
-             ),
-             $money_char. sprintf("%10.2f",$self->charged) ];
-  push @buf,['',''];
-
   ###
   # Totals
   ###
@@ -1312,50 +1303,37 @@ sub print_generic {
   );
   my $embolden_function = $embolden_functions{$format};
 
-  if ( $self->can('_items_total') ) { # quotations
-
-    my @new_total_items = $self->_items_total;
+  if ( $multisection ) {
 
-    foreach ( @new_total_items ) {
-      $_->{'total_item'}   = &$embolden_function( $_->{'total_item'} );
-      $_->{'total_amount'} = &$embolden_function( $other_money_char.$_->{'total_amount'});
-      push @total_items, $_;
+    if ( $adjust_section->{'sort_weight'} ) {
+      $adjust_section->{'posttotal'} = $self->mt('Balance Forward').' '.
+        $other_money_char.  sprintf("%.2f", ($self->billing_balance || 0) );
+    } else{
+      $adjust_section->{'pretotal'} = $self->mt('New charges total').' '.
+        $other_money_char.  sprintf('%.2f', $self->charged );
     }
 
-  } else { #normal invoice case
+  }
+  
+  if ( $self->can('_items_total') ) { # should always be true now
 
-    # calculate total, possibly including total owed on previous
-    # invoices
-    my $total = {};
-    my $item = 'Total';
-    $item = $conf->config('previous_balance-exclude_from_total')
-         || 'Total New Charges'
-      if $conf->exists('previous_balance-exclude_from_total');
-    my $amount = $self->charged;
-    if ( $self->enable_previous and !$conf->exists('previous_balance-exclude_from_total') ) {
-      $amount += $pr_total;
-    }
+    # even for multisection, need plain text version
+
+    my @new_total_items = $self->_items_total;
 
-    $total->{'total_item'} = &$embolden_function($self->mt($item));
-    $total->{'total_amount'} =
-      &$embolden_function( $other_money_char.  sprintf( '%.2f', $amount ) );
-    if ( $multisection ) {
-      if ( $adjust_section->{'sort_weight'} ) {
-        $adjust_section->{'posttotal'} = $self->mt('Balance Forward').' '.
-          $other_money_char.  sprintf("%.2f", ($self->billing_balance || 0) );
-      } else {
-        $adjust_section->{'pretotal'} = $self->mt('New charges total').' '.
-          $other_money_char.  sprintf('%.2f', $self->charged );
-      } 
-    } else {
-      push @total_items, $total;
-    }
     push @buf,['','-----------'];
-    push @buf,[$item,
-               $money_char.
-               sprintf( '%10.2f', $amount )
-              ];
-    push @buf,['',''];
+
+    foreach ( @new_total_items ) {
+      my ($item, $amount) = ($_->{'total_item'}, $_->{'total_amount'});
+      $_->{'total_item'}   = &$embolden_function( $item );
+      $_->{'total_amount'} = &$embolden_function( $other_money_char.$amount );
+      # but if it's multisection, don't append to @total_items. the adjust
+      # section has all this stuff
+      push @total_items, $_ if !$multisection;
+      push @buf, [ $item, $money_char.sprintf('%10.2f',$amount) ];
+    }
+
+    push @buf, [ '', '' ];
 
     # if we're showing previous invoices, also show previous
     # credits and payments 
@@ -1363,7 +1341,6 @@ sub print_generic {
           and $self->can('_items_credits')
           and $self->can('_items_payments') )
       {
-      #foreach my $thing ( sort { $a->_date <=> $b->_date } $self->_items_credits, $self->_items_payments
     
       # credits
       my $credittotal = 0;
@@ -1455,7 +1432,7 @@ sub print_generic {
         if ( $multisection && !$adjust_section->{sort_weight} ) {
           $adjust_section->{'posttotal'} = $total->{'total_item'}. ' '.
                                            $total->{'total_amount'};
-        }else{
+        } else {
           push @total_items, $total;
         }
         push @buf,['','-----------'];
@@ -1921,12 +1898,18 @@ sub due_date2str {
 sub balance_due_msg {
   my $self = shift;
   my $msg = $self->mt('Balance Due');
-  return $msg unless $self->terms;
-  if ( $self->due_date ) {
-    $msg .= ' - ' . $self->mt('Please pay by'). ' '.
-      $self->due_date2str('short');
-  } elsif ( $self->terms ) {
-    $msg .= ' - '. $self->terms;
+  return $msg unless $self->terms; # huh?
+  if ( !$self->conf->exists('invoice_show_prior_due_date')
+       or $self->conf->exists('invoice_sections') ) {
+    # if enabled, the due date is shown with Total New Charges (see 
+    # _items_total) and not here
+    # (yes, or if invoice_sections is enabled; this is just for compatibility)
+    if ( $self->due_date ) {
+      $msg .= ' - ' . $self->mt('Please pay by'). ' '.
+        $self->due_date2str('short');
+    } elsif ( $self->terms ) {
+      $msg .= ' - '. $self->mt($self->terms);
+    }
   }
   $msg;
 }
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 033f199..6e40ef5 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -447,16 +447,20 @@ followed by the previous outstanding invoices (as FS::cust_bill objects also).
 
 sub previous {
   my $self = shift;
-  my $total = 0;
-  my @cust_bill = sort { $a->_date <=> $b->_date }
-    grep { $_->owed != 0 }
-      qsearch( 'cust_bill', { 'custnum' => $self->custnum,
-                              #'_date'   => { op=>'<', value=>$self->_date },
-                              'invnum'   => { op=>'<', value=>$self->invnum },
-                            } ) 
-  ;
-  foreach ( @cust_bill ) { $total += $_->owed; }
-  $total, @cust_bill;
+  # simple memoize; we use this a lot
+  if (!$self->get('previous')) {
+    my $total = 0;
+    my @cust_bill = sort { $a->_date <=> $b->_date }
+      grep { $_->owed != 0 }
+        qsearch( 'cust_bill', { 'custnum' => $self->custnum,
+                                #'_date'   => { op=>'<', value=>$self->_date },
+                                'invnum'   => { op=>'<', value=>$self->invnum },
+                              } ) 
+    ;
+    foreach ( @cust_bill ) { $total += $_->owed; }
+    $self->set('previous', [$total, @cust_bill]);
+  }
+  return @{ $self->get('previous') };
 }
 
 =item enable_previous
@@ -2802,6 +2806,55 @@ sub _items_payments {
 
 }
 
+sub _items_total {
+  my $self = shift;
+  my $conf = $self->conf;
+
+  my @items;
+  my ($pr_total) = $self->previous;
+  if ( $conf->exists('previous_balance-exclude_from_total') ) {
+    # then return separate lines for previous balance and total new charges
+    if ( $pr_total ) {
+      push @items,
+        { total_item    => $self->mt('Previous Balance'),
+          total_amount  => sprintf('%.2f',$pr_total)
+        };
+    }
+    my $new_charges_desc = $self->mt(
+      $conf->config('previous_balance-exclude_from_total')
+       || 'Total New Charges'
+    ); # localize 'Total New Charges' or whatever's in the config
+
+    if ( $conf->exists('invoice_show_prior_due_date') ) {
+      # then the due date should be shown with Total New Charges,
+      # and should NOT be shown with the Balance Due message.
+      if ( $self->due_date ) {
+        # localize the "Please pay by" message and the date itself
+        # (grammar issues with this, yeah)
+        $new_charges_desc .= ' - ' . $self->mt('Please pay by') . ' ' .
+                             $self->due_date2str('short');
+      } elsif ( $self->terms ) {
+        # phrases like "due on receipt" should be localized
+        $new_charges_desc .= ' - ' . $self->mt($self->terms);
+      }
+    }
+
+    push @items,
+      { total_item    => $self->mt($new_charges_desc),
+        total_amount  => $self->charged
+      };
+
+  } else {
+    push @items,
+      { total_item    => $self->mt('Total Charges'),
+        total_amount  => sprintf('%.2f',$self->charged + $pr_total)
+      };
+  }
+  @items;
+}
+
+
+
 =item call_details [ OPTION => VALUE ... ]
 
 Returns an array of CSV strings representing the call details for this invoice

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

Summary of changes:
 FS/FS/Template_Mixin.pm |   93 +++++++++++++++++++----------------------------
 FS/FS/cust_bill.pm      |   73 ++++++++++++++++++++++++++++++++-----
 2 files changed, 101 insertions(+), 65 deletions(-)




More information about the freeside-commits mailing list