fix accidental removal of "last_bill" from invoice data hash, #34217, from #31273
[freeside.git] / FS / FS / Template_Mixin.pm
index 1a57754..14fc7fc 100644 (file)
@@ -570,7 +570,7 @@ sub print_generic {
     )),
 
     #global config
-    'ship_enable'     => $conf->exists('invoice-ship_address'),
+    'ship_enable'     => $cust_main->invoice_ship_address || $conf->exists('invoice-ship_address'),
     'unitprices'      => $conf->exists('invoice-unitprice'),
     'smallernotes'    => $conf->exists('invoice-smallernotes'),
     'smallerfooter'   => $conf->exists('invoice-smallerfooter'),
@@ -698,6 +698,10 @@ sub print_generic {
     # XXX should be an FS::cust_bill method to set the defaults, instead
     # of checking the type here
 
+    # info from customer's last invoice before this one, for some 
+    # summary formats
+    $invoice_data{'last_bill'} = {};
     my $last_bill = $self->previous_bill;
     if ( $last_bill ) {
 
@@ -758,9 +762,7 @@ sub print_generic {
       # ($pr_total is used elsewhere but not as $previous_balance)
       $invoice_data{'previous_balance'} = sprintf("%.2f", $pr_total);
 
-      $invoice_data{'last_bill'} = {
-        '_date'     => $last_bill->_date, #unformatted
-      };
+      $invoice_data{'last_bill'}{'_date'} = $last_bill->_date; #unformatted
       my (@payments, @credits);
       # for formats that itemize previous payments
       foreach my $cust_pay ( qsearch('cust_pay', {
@@ -802,11 +804,7 @@ sub print_generic {
       $invoice_data{'previous_payments'} = [];
       $invoice_data{'previous_credits'} = [];
     }
-
-    # info from customer's last invoice before this one, for some 
-    # summary formats
-    $invoice_data{'last_bill'} = {};
-  
     if ( $conf->exists('invoice_usesummary', $agentnum) ) {
       $invoice_data{'summarypage'} = $summarypage = 1;
     }
@@ -1371,7 +1369,7 @@ sub print_generic {
       # credits
       my $credittotal = 0;
       foreach my $credit (
-        $self->_items_credits( 'template' => $template, 'trim_len' => 60 )
+        $self->_items_credits( 'template' => $template, 'trim_len' => 40 )
       ) {
 
         my $total;
@@ -2860,6 +2858,7 @@ sub _items_fee {
     my %base_invnums; # invnum => invoice date
     foreach ($cust_bill_pkg->cust_bill_pkg_fee) {
       if ($_->base_invnum) {
+        # XXX what if base_bill has been voided?
         my $base_bill = FS::cust_bill->by_key($_->base_invnum);
         my $base_date = $self->time2str_local('short', $base_bill->_date)
           if $base_bill;
@@ -3010,7 +3009,7 @@ sub _items_cust_bill_pkg {
   my $multisection = defined($category) || defined($locationnum);
   my $discount_show_always = 0;
 
-  my $maxlength = $conf->config('cust_bill-latex_lineitem_maxlength') || 50;
+  my $maxlength = $conf->config('cust_bill-latex_lineitem_maxlength') || 40;
 
   my $cust_main = $self->cust_main;#for per-agent cust_bill-line_item-ate_style
 
@@ -3027,7 +3026,10 @@ sub _items_cust_bill_pkg {
     }) || $cust_main;
     $default_locationnum = $h_cust_main->ship_locationnum;
   } elsif ( $self->prospectnum ) {
-    $default_locationnum = $self->prospect_main->cust_location->locationnum;
+    my $cust_location = qsearchs('cust_location',
+      { prospectnum => $self->prospectnum,
+        disabled => '' });
+    $default_locationnum = $cust_location->locationnum if $cust_location;
   }
 
   my @b = (); # accumulator for the line item hashes that we'll return