better support for batch-increment_expiration, RT#10453
authormark <mark>
Fri, 12 Nov 2010 03:21:31 +0000 (03:21 +0000)
committermark <mark>
Fri, 12 Nov 2010 03:21:31 +0000 (03:21 +0000)
FS/FS/pay_batch.pm
FS/FS/pay_batch/chase_canada.pm
FS/FS/pay_batch/paymentech.pm
FS/FS/pay_batch/td_canada_trust.pm

index afff261..b5ef85b 100644 (file)
@@ -7,6 +7,7 @@ use Text::CSV_XS;
 use FS::Record qw( dbh qsearch qsearchs );
 use FS::cust_pay;
 use FS::Conf;
+use Date::Parse qw(str2time);
 use Business::CreditCard qw(cardtype);
 
 @ISA = qw(FS::Record);
@@ -481,7 +482,20 @@ sub export_batch {
 
   my @cust_pay_batch = sort { $a->paybatchnum <=> $b->paybatchnum }
                       qsearch('cust_pay_batch', { batchnum => $self->batchnum } );
-
+  
+  # handle batch-increment_expiration option
+  if ( $self->payby eq 'CARD' ) {
+    my ($cmon, $cyear) = (localtime(time))[4,5];
+    foreach (@cust_pay_batch) {
+      my $etime = str2time($_->exp) or next;
+      my ($day, $mon, $year) = (localtime($etime))[3,4,5];
+      if( $conf->exists('batch-increment_expiration') ) {
+        $year++ while( $year < $cyear or ($year == $cyear and $mon <= $cmon) );
+        $_->exp( sprintf('%4u-%02u-%02u', $year + 1900, $mon+1, $day) );
+      }
+      $_->setfield('expmmyy', sprintf('%02u%02u', $mon+1, $year % 100));
+    }
+  }
   my $h = $info->{'header'};
   if(ref($h) eq 'CODE') {
     $batch .= &$h($self, \@cust_pay_batch) . "\n";
index 909e4ae..5d8437d 100644 (file)
@@ -73,7 +73,7 @@ $name = 'csv-chase_canada-E-xactBatch';
       '00',
       $cust_pay_batch->payinfo,
       $cust_pay_batch->amount,
-      expdate($cust_pay_batch->exp),
+      $cust_pay_batch->expmmyy,
       '',
       ''
     );
@@ -86,19 +86,4 @@ sub sdate {
   sprintf('%02d/%02d/%02d', $date[5] % 100, $date[4] + 1, $date[3]);
 }
 
-sub expdate {
-  my $exp = shift;
-  $exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
-  my ($mon, $y) = ($2, $1);
-  if($conf->exists('batch-increment_expiration')) {
-    my ($curmon, $curyear) = (localtime(time))[4,5];
-    $curmon++;
-    $curyear -=  100;
-    $y++ while $y < $curyear || ($y == $curyear && $mon < $curmon);
-  }
-  $mon = "0$mon" if $mon =~ /^\d$/;
-  $y = "0$y" if $y =~ /^\d$/;
-  return "$mon$y";
-}
-
 1;
index a5b6f27..f22a80f 100644 (file)
@@ -107,7 +107,7 @@ my %paytype = (
         terminalID   => $terminalID,
         ($_->payby eq 'CARD') ? (
           ccAccountNum => $_->payinfo,
-          ccExp        => time2str('%m%y', str2time($_->exp))
+          ccExp        => $_->expmmyy,
         ) : (
           ecpCheckRT      => ($_->payinfo =~ /@(\d+)/),
           ecpCheckDDA     => ($_->payinfo =~ /(\d+)@/),
index 43b9237..e80441e 100644 (file)
@@ -77,7 +77,7 @@ $name = 'csv-td_canada_trust-merchant_pc_batch';
       '',
       '', 
       $cust_pay_batch->payinfo,
-      expdate($cust_pay_batch->exp),
+      $cust_pay_batch->expmmyy,
       $cust_pay_batch->amount,
       $cust_pay_batch->paybatchnum
       );
@@ -85,20 +85,6 @@ $name = 'csv-td_canada_trust-merchant_pc_batch';
 # no footer
 );
 
-sub expdate {
-  my $exp = shift;
-  $exp =~ /^\d{2}(\d{2})[\/\-](\d+)[\/\-]\d+$/;
-  my ($mon, $y) = ($2, $1);
-  if($conf->exists('batch-increment_expiration')) {
-    my ($curmon, $curyear) = (localtime(time))[4,5];
-    $curmon++;
-    $curyear -=  100;
-    $y++ while $y < $curyear || ($y == $curyear && $mon < $curmon);
-  }
-  $mon = "0$mon" if $mon =~ /^\d$/;
-  $y = "0$y" if $y =~ /^\d$/;
-  return "$mon$y";
-}
 
 1;