[freeside-commits] branch FREESIDE_3_BRANCH updated. a119361314fa44afc1af3a5a89f0296cca16e20c

Mark Wells mark at 420.am
Mon Jan 27 16:52:56 PST 2014


The branch, FREESIDE_3_BRANCH has been updated
       via  a119361314fa44afc1af3a5a89f0296cca16e20c (commit)
       via  22df3382a4cd84771550dad390321b150509138f (commit)
      from  af68f26e1a7c15fa506e38393aac95c4e572928e (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 a119361314fa44afc1af3a5a89f0296cca16e20c
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Jan 27 16:51:50 2014 -0800

    localize dates that will appear on invoices, #24850

diff --git a/FS/FS/TemplateItem_Mixin.pm b/FS/FS/TemplateItem_Mixin.pm
index 7df75d4..6644329 100644
--- a/FS/FS/TemplateItem_Mixin.pm
+++ b/FS/FS/TemplateItem_Mixin.pm
@@ -98,16 +98,19 @@ sub time_period_pretty {
 
   my $time_period;
   if ( defined($date_style) && $date_style eq 'month_of' ) {
-    $time_period = time2str('The month of %B', $self->sdate);
+    # (now watch, someone's going to make us do Chinese)
+    $time_period = $self->mt('The month of [_1]',
+                      $self->time2str_local('The month of %B', $self->sdate)
+                   );
   } elsif ( defined($date_style) && $date_style eq 'X_month' ) {
     my $desc = $conf->config( 'cust_bill-line_item-date_description',
                                $agentnum
                             );
     $desc .= ' ' unless $desc =~ /\s$/;
-    $time_period = $desc. time2str('%B', $self->sdate);
+    $time_period = $desc. $self->time2str_local('%B', $self->sdate);
   } else {
-    $time_period =      time2str($date_format, $self->sdate).
-                 " - ". time2str($date_format, $self->edate);
+    $time_period =      $self->time2str_local($date_format, $self->sdate).
+                 " - ". $self->time2str_local($date_format, $self->edate);
   }
 
   " ($time_period)";
diff --git a/FS/FS/Template_Mixin.pm b/FS/FS/Template_Mixin.pm
index 990f31f..c8e5546 100644
--- a/FS/FS/Template_Mixin.pm
+++ b/FS/FS/Template_Mixin.pm
@@ -498,9 +498,9 @@ sub print_generic {
     '_date'           => ( $params{'no_date'} ? '' : $self->_date ),
     'date'            => ( $params{'no_date'}
                              ? ''
-                             : time2str($date_format, $self->_date)
+                             : $self->time2str_local($date_format, $self->_date)
                          ),
-    'today'           => time2str($date_format_long, $today),
+    'today'           => $self->time2str_local($date_format_long, $today),
     'terms'           => $self->terms,
     'template'        => $template, #params{'template'},
     'notice_name'     => $notice_name, # escape?
@@ -545,15 +545,9 @@ sub print_generic {
   );
  
   #localization
-  my $lh = FS::L10N->get_handle( $locale );
   $invoice_data{'emt'} = sub { &$escape_function($self->mt(@_)) };
-  my %info = FS::Locales->locale_info($cust_main->locale || 'en_US');
-  # eval to avoid death for unimplemented languages
-  my $dh = eval { Date::Language->new($info{'name'}) } ||
-           Date::Language->new(); # fall back to English
   # prototype here to silence warnings
-  $invoice_data{'time2str'} = sub ($;$$) { $dh->time2str(@_) };
-  # eventually use this date handle everywhere in here, too
+  $invoice_data{'time2str'} = sub ($;$$) { $self->time2str_local(@_) };
 
   my $min_sdate = 999999999999;
   my $max_edate = 0;
@@ -566,8 +560,9 @@ sub print_generic {
   }
 
   $invoice_data{'bill_period'} = '';
-  $invoice_data{'bill_period'} = time2str('%e %h', $min_sdate) 
-    . " to " . time2str('%e %h', $max_edate)
+  $invoice_data{'bill_period'} = $self->time2str_local('%e %h', $min_sdate) 
+                                 . " to " .
+                                 $self->time2str_local('%e %h', $max_edate)
     if ($max_edate != 0 && $min_sdate != 999999999999);
 
   $invoice_data{finance_section} = '';
@@ -1721,7 +1716,7 @@ sub due_date {
 
 sub due_date2str {
   my $self = shift;
-  $self->due_date ? time2str(shift, $self->due_date) : '';
+  $self->due_date ? $self->time2str_local(shift, $self->due_date) : '';
 }
 
 sub balance_due_msg {
@@ -1743,7 +1738,7 @@ sub balance_due_date {
   my $duedate = '';
   if (    $conf->exists('invoice_default_terms') 
        && $conf->config('invoice_default_terms')=~ /^\s*Net\s*(\d+)\s*$/ ) {
-    $duedate = time2str($rdate_format, $self->_date + ($1*86400) );
+    $duedate = $self->time2str_local($rdate_format, $self->_date + ($1*86400) );
   }
   $duedate;
 }
@@ -1761,7 +1756,7 @@ Returns a string with the date, for example: "3/20/2008"
 
 sub _date_pretty {
   my $self = shift;
-  time2str($date_format, $self->_date);
+  $self->time2str_local($date_format, $self->_date);
 }
 
 =item _items_sections OPTIONS
@@ -2761,8 +2756,8 @@ sub _items_cust_bill_pkg {
         if ( $cust_bill_pkg->recur != 0 ) {
           push @b, {
             'description' => "$desc (".
-                             time2str($date_format, $cust_bill_pkg->sdate). ' - '.
-                             time2str($date_format, $cust_bill_pkg->edate). ')',
+                             $self->time2str_local($date_format, $cust_bill_pkg->sdate). ' - '.
+                             $self->time2str_local($date_format, $cust_bill_pkg->edate). ')',
             'amount'      => sprintf("%.2f", $cust_bill_pkg->recur),
           };
         }
diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm
index 8f1e07e..4f8cb1d 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -1677,6 +1677,7 @@ sub send_csv {
   my $spooldir = "/usr/local/etc/freeside/export.". datasrc. "/cust_bill";
   mkdir $spooldir, 0700 unless -d $spooldir;
 
+  # don't localize dates here, they're a defined format
   my $tracctnum = $self->invnum. time2str('-%Y%m%d%H%M%S', time);
   my $file = "$spooldir/$tracctnum.csv";
   
@@ -2270,7 +2271,7 @@ sub print_csv {
             ? time2str("%x", $cust_bill_pkg->sdate)
             : '' ),
           ($cust_bill_pkg->edate 
-            ?time2str("%x", $cust_bill_pkg->edate)
+            ? time2str("%x", $cust_bill_pkg->edate)
             : '' ),
         );
   
@@ -2984,7 +2985,7 @@ sub _items_previous {
   foreach ( @pr_cust_bill ) {
     my $date = $conf->exists('invoice_show_prior_due_date')
                ? 'due '. $_->due_date2str($date_format)
-               : time2str($date_format, $_->_date);
+               : $self->time2str_local($date_format, $_->_date);
     push @b, {
       'description' => $self->mt('Previous Balance, Invoice #'). $_->invnum. " ($date)",
       #'pkgpart'     => 'N/A',
@@ -3048,7 +3049,7 @@ sub _items_credits {
       #                 " (". time2str("%x",$_->cust_credit->_date) .")".
       #                 $reason,
       'description' => $self->mt('Credit applied').' '.
-                       time2str($date_format,$obj->_date). $reason,
+                       $self->time2str_local($date_format,$obj->_date). $reason,
       'amount'      => sprintf("%.2f",$obj->amount),
     };
   }
@@ -3092,7 +3093,7 @@ sub _items_payments {
   foreach my $obj (@objects) {
     my $cust_pay = $obj->isa('FS::cust_pay') ? $obj : $obj->cust_pay;
     my $desc = $self->mt('Payment received').' '.
-               time2str($date_format, $cust_pay->_date );
+               $self->time2str_local($date_format, $cust_pay->_date );
     $desc .= $self->mt(' via ') .
              $cust_pay->payby_payinfo_pretty( $self->cust_main->locale )
       if $detailed;
diff --git a/FS/FS/cust_bill_pkg.pm b/FS/FS/cust_bill_pkg.pm
index acbaded..dc0ae2d 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -512,6 +512,21 @@ sub cust_bill {
   qsearchs( 'cust_bill', { 'invnum' => $self->invnum } );
 }
 
+=item cust_main
+
+Returns the customer (L<FS::cust_main> object) for this line item.
+
+=cut
+
+sub cust_main {
+  # required for cust_main_Mixin equivalence
+  # and use cust_bill instead of cust_pkg because this might not have a 
+  # cust_pkg
+  my $self = shift;
+  my $cust_bill = $self->cust_bill or return '';
+  $cust_bill->cust_main;
+}
+
 =item previous_cust_bill_pkg
 
 Returns the previous cust_bill_pkg for this package, if any.
diff --git a/FS/FS/cust_main_Mixin.pm b/FS/FS/cust_main_Mixin.pm
index f584b41..92dea28 100644
--- a/FS/FS/cust_main_Mixin.pm
+++ b/FS/FS/cust_main_Mixin.pm
@@ -582,6 +582,28 @@ sub mt {
   return $lh->maketext(@_);
 }
 
+=item time2str_local FORMAT, TIME
+
+Localizes a date (see L<Date::Language>) for the customer's locale.
+
+=cut
+
+sub time2str_local {
+  # renamed so that we don't have to change every single reference to 
+  # time2str everywhere
+  my $self = shift;
+  if (!exists($self->{_dh})) {
+    my $cust_main = $self->cust_main;
+    my $locale = $cust_main->locale  if $cust_main;
+    $locale ||= 'en_US';
+    my %info = FS::Locales->locale_info($locale);
+    my $dh = eval { Date::Language->new($info{'name'}) } ||
+             Date::Language->new(); # fall back to English
+    $self->{_dh} = $dh;
+  }
+  $self->{_dh}->time2str(@_);
+}
+
 =back
 
 =head1 BUGS
diff --git a/FS/FS/quotation_pkg.pm b/FS/FS/quotation_pkg.pm
index efff968..83c7320 100644
--- a/FS/FS/quotation_pkg.pm
+++ b/FS/FS/quotation_pkg.pm
@@ -201,6 +201,18 @@ sub cust_bill_pkg_display {
 
 }
 
+=item cust_main
+
+Returns the customer (L<FS::cust_main> object).
+
+=cut
+
+sub cust_main {
+  my $self = shift;
+  my $quotation = FS::quotation->by_key($self->quotationnum) or return '';
+  $quotation->cust_main;
+}
+
 =back
 
 =head1 BUGS

commit 22df3382a4cd84771550dad390321b150509138f
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Jan 27 16:06:31 2014 -0800

    also mask EDI acct# on invoices, #26859

diff --git a/FS/FS/payinfo_Mixin.pm b/FS/FS/payinfo_Mixin.pm
index 8e139f7..b030bd7 100644
--- a/FS/FS/payinfo_Mixin.pm
+++ b/FS/FS/payinfo_Mixin.pm
@@ -163,6 +163,13 @@ sub mask_payinfo {
              substr($account,(length($account)-2)).
              ( length($aba) ? "@".$aba : '');
 
+    } elsif ($payby eq 'EDI') {
+      # EDI.
+      # These numbers have been seen anywhere from 8 to 30 digits, and 
+      # possibly more.  Lacking any better idea I'm going to mask all but
+      # the last 4 digits.
+      return 'x' x (length($payinfo) - 4) . substr($payinfo, -4);
+
     } else { # Tie up loose ends
       return $payinfo;
     }
@@ -273,6 +280,8 @@ sub payby_payinfo_pretty {
     $lh->maketext('Western Union');
   } elsif ( $self->payby eq 'MCRD' ) {
     $lh->maketext('Manual credit card');
+  } elsif ( $self->payby eq 'EDI' ) {
+    $lh->maketext('EDI') . ' ' . $self->paymask;
   } elsif ( $self->payby eq 'PPAL' ) {
     $lh->maketext('PayPal transaction#') . $self->order_number;
   } else {

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

Summary of changes:
 FS/FS/TemplateItem_Mixin.pm |   11 +++++++----
 FS/FS/Template_Mixin.pm     |   27 +++++++++++----------------
 FS/FS/cust_bill.pm          |    9 +++++----
 FS/FS/cust_bill_pkg.pm      |   15 +++++++++++++++
 FS/FS/cust_main_Mixin.pm    |   22 ++++++++++++++++++++++
 FS/FS/payinfo_Mixin.pm      |    9 +++++++++
 FS/FS/quotation_pkg.pm      |   12 ++++++++++++
 7 files changed, 81 insertions(+), 24 deletions(-)




More information about the freeside-commits mailing list