X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpay_batch%2Feft_canada.pm;h=0c093214ad1e3e1b8b0a52cbe51f41eb3441a407;hb=52a824f9b11ca266be10c76894eaf6607344c8d0;hp=220fecb3d7d94e977dac2bf33d385e40156f0883;hpb=e513d7cb331d7c7d99d1ea7b5f0a5f8e08e0d725;p=freeside.git diff --git a/FS/FS/pay_batch/eft_canada.pm b/FS/FS/pay_batch/eft_canada.pm index 220fecb3d..0c093214a 100644 --- a/FS/FS/pay_batch/eft_canada.pm +++ b/FS/FS/pay_batch/eft_canada.pm @@ -25,12 +25,6 @@ my %holiday_yearly = ( 12 => { map {$_=>1} 26 }, #boxing day ); my %holiday = ( - 2012 => { - 7 => { map {$_=>1} 2 }, #canada day - 8 => { map {$_=>1} 6 }, #First Monday of August Civic Holiday - 9 => { map {$_=>1} 3 }, #labour day - 10 => { map {$_=>1} 8 }, #thanksgiving - }, 2013 => { 2 => { map {$_=>1} 18 }, #family day 3 => { map {$_=>1} 29 }, #good friday 4 => { map {$_=>1} 1 }, #easter monday @@ -64,25 +58,17 @@ my %holiday = ( init => sub { my $conf = shift; - my @config = $conf->config('batchconfig-eft_canada'); - # SFTP login, password, trans code, delay time - my $process_delay; - ($trans_code, $process_delay) = @config[2,3]; - $process_delay ||= 1; # days - - my $pt = time + ($process_delay * 86400); - my @lt = localtime($pt); - while ( $lt[6] == 0 #Sunday - || $lt[6] == 6 #Saturday - || $holiday_yearly{ $lt[4]+1 }{ $lt[3] } - || $holiday{ $lt[5]+1900 }{ $lt[4]+1 }{ $lt[3] } - ) - { - $pt += 86400; - @lt = localtime($pt); + my $agentnum = shift; + my @config; + if ( $conf->exists('batch-spoolagent') ) { + @config = $conf->config('batchconfig-eft_canada', $agentnum); + } else { + @config = $conf->config('batchconfig-eft_canada'); } + # SFTP login, password, trans code, delay time + ($trans_code) = $config[2]; - $process_date = time2str('%D', $pt); + $process_date = time2str('%D', process_date($conf, $agentnum)); }, delimiter => '', # avoid blank lines for header/footer @@ -95,9 +81,11 @@ my %holiday = ( # company + empty or first + last my $company = sprintf('%.64s', $cust_pay_batch->cust_main->company); if ( $company ) { + push @fields, 'Business'; push @fields, $company, '' } else { + push @fields, 'Personal'; push @fields, map { sprintf('%.64s', $_) } $cust_pay_batch->first, $cust_pay_batch->last; } @@ -124,4 +112,61 @@ my %holiday = ( ); +sub download_note { # is a class method + my $class = shift; + my $pay_batch = shift; + my $conf = FS::Conf->new; + my $agentnum = $pay_batch->agentnum; + my $tomorrow = (localtime(time))[2] >= 10; + my $process_date = process_date($conf, $agentnum); + my $upload_date = $process_date - 86400; + my $date_format = $conf->config('date_format') || '%D'; + + my $note = ''; + if ( $process_date - time < 86400*2 ) { + $note = 'Upload this file before 11:00 AM '. + ($tomorrow ? 'tomorrow' : 'today') . + ' (' . time2str($date_format, $upload_date) . '). '; + } else { + $note = 'Upload this file before 11:00 AM on '. + time2str($date_format, $upload_date) . '. '; + } + $note .= 'Payments will be processed on '. + time2str($date_format, $process_date) . '.'; + + $note; +} + +sub process_date { + my ($conf, $agentnum) = @_; + my @config; + if ( $conf->exists('batch-spoolagent') ) { + @config = $conf->config('batchconfig-eft_canada', $agentnum); + } else { + @config = $conf->config('batchconfig-eft_canada'); + } + + my $process_delay = $config[3] || 1; + + if ( (localtime(time))[2] >= 10 and $process_delay == 1 ) { + # If downloading the batch after 10:00 local time, it likely won't make + # the cutoff for next-day turnaround, and EFT will reject it. + $process_delay++; + } + + my $pt = time + ($process_delay * 86400); + my @lt = localtime($pt); + while ( $lt[6] == 0 #Sunday + || $lt[6] == 6 #Saturday + || $holiday_yearly{ $lt[4]+1 }{ $lt[3] } + || $holiday{ $lt[5]+1900 }{ $lt[4]+1 }{ $lt[3] } + ) + { + $pt += 86400; + @lt = localtime($pt); + } + + $pt; +} + 1;