From: mark Date: Fri, 12 Nov 2010 03:21:31 +0000 (+0000) Subject: better support for batch-increment_expiration, RT#10453 X-Git-Tag: TORRUS_1_0_9~100 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=cefae4ba10cf42b5fc48bc63ef9aee861f6e8b2a better support for batch-increment_expiration, RT#10453 --- diff --git a/FS/FS/pay_batch.pm b/FS/FS/pay_batch.pm index afff261a0..b5ef85b5b 100644 --- a/FS/FS/pay_batch.pm +++ b/FS/FS/pay_batch.pm @@ -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"; diff --git a/FS/FS/pay_batch/chase_canada.pm b/FS/FS/pay_batch/chase_canada.pm index 909e4ae18..5d8437dba 100644 --- a/FS/FS/pay_batch/chase_canada.pm +++ b/FS/FS/pay_batch/chase_canada.pm @@ -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; diff --git a/FS/FS/pay_batch/paymentech.pm b/FS/FS/pay_batch/paymentech.pm index a5b6f276d..f22a80f89 100644 --- a/FS/FS/pay_batch/paymentech.pm +++ b/FS/FS/pay_batch/paymentech.pm @@ -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+)@/), diff --git a/FS/FS/pay_batch/td_canada_trust.pm b/FS/FS/pay_batch/td_canada_trust.pm index 43b92371e..e80441ef8 100644 --- a/FS/FS/pay_batch/td_canada_trust.pm +++ b/FS/FS/pay_batch/td_canada_trust.pm @@ -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;