[freeside-commits] branch master updated. 48fc9f425ec3454f4346089318994ae6c1e080a8

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


The branch, master has been updated
       via  48fc9f425ec3454f4346089318994ae6c1e080a8 (commit)
       via  fbccadc20ceb30d90ef5ab8a2e135834a1aded31 (commit)
      from  cc7638ffbd4dea4dfd4acc7c020541af710c7cf1 (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 48fc9f425ec3454f4346089318994ae6c1e080a8
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Jan 27 16:52:39 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 63ae884..165bb1a 100644
--- a/FS/FS/cust_bill.pm
+++ b/FS/FS/cust_bill.pm
@@ -1659,6 +1659,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";
   
@@ -2252,7 +2253,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)
             : '' ),
         );
   
@@ -2966,7 +2967,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',
@@ -3030,7 +3031,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),
     };
   }
@@ -3074,7 +3075,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 c71ebf4..b234d6f 100644
--- a/FS/FS/cust_bill_pkg.pm
+++ b/FS/FS/cust_bill_pkg.pm
@@ -510,6 +510,21 @@ sub regularize_details {
 
 Returns the invoice (see L<FS::cust_bill>) for this invoice line item.
 
+=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 c9724d1..c73f857 100644
--- a/FS/FS/quotation_pkg.pm
+++ b/FS/FS/quotation_pkg.pm
@@ -192,6 +192,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 fbccadc20ceb30d90ef5ab8a2e135834a1aded31
Author: Mark Wells <mark at freeside.biz>
Date:   Mon Jan 27 16:52:32 2014 -0800

    also mask EDI acct# on invoices, #26859

diff --git a/FS/FS/payinfo_Mixin.pm b/FS/FS/payinfo_Mixin.pm
index 1104e3f..e14c589 100644
--- a/FS/FS/payinfo_Mixin.pm
+++ b/FS/FS/payinfo_Mixin.pm
@@ -159,6 +159,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;
     }
@@ -269,6 +276,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