X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpay_batch%2Feft_canada.pm;h=2e89322f587dca705ece7ec8451a350f0e70784c;hb=18a1b36c6f9d66385ecfd96154b923bd544843c2;hp=0e416103447407453bba5c83d3cec74d73ce72c6;hpb=db4d8679af26c301cb66f3f3da7f7cd7a3ae4854;p=freeside.git diff --git a/FS/FS/pay_batch/eft_canada.pm b/FS/FS/pay_batch/eft_canada.pm index 0e4161034..2e89322f5 100644 --- a/FS/FS/pay_batch/eft_canada.pm +++ b/FS/FS/pay_batch/eft_canada.pm @@ -15,19 +15,56 @@ $name = 'eft_canada'; %import_info = ( filetype => 'NONE' ); # see FS/bin/freeside-eftca-download -my ($trans_code, $process_date); +my ($business_trans_code, $personal_trans_code, $trans_code, $process_date); + +#ref http://gocanada.about.com/od/canadatravelplanner/a/canada_holidays.htm +my %holiday_yearly = ( + 1 => { map {$_=>1} 1 }, #new year's + 11 => { map {$_=>1} 11 }, #remembrance day + 12 => { map {$_=>1} 25 }, #christmas + 12 => { map {$_=>1} 26 }, #boxing day +); +my %holiday = ( + 2015 => { 2 => { map {$_=>1} 16 }, #family day + 4 => { map {$_=>1} 3 }, #good friday + 4 => { map {$_=>1} 6 }, #easter monday + 5 => { map {$_=>1} 18 }, #victoria day + 7 => { map {$_=>1} 1 }, #canada day + 8 => { map {$_=>1} 3 }, #First Monday of August Civic Holiday + 9 => { map {$_=>1} 7 }, #labour day + 10 => { map {$_=>1} 12 }, #thanksgiving + }, + 2016 => { 2 => { map {$_=>1} 15 }, #family day + 3 => { map {$_=>1} 25 }, #good friday + 3 => { map {$_=>1} 28 }, #easter monday + 5 => { map {$_=>1} 23 }, #victoria day + 7 => { map {$_=>1} 1 }, #canada day + 8 => { map {$_=>1} 1 }, #First Monday of August Civic Holiday + 9 => { map {$_=>1} 5 }, #labour day + 10 => { map {$_=>1} 10 }, #thanksgiving + }, +); %export_info = ( + init => sub { my $conf = shift; - my @config = $conf->config('batchconfig-eft_canada'); + 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 - my $process_delay; - ($trans_code, $process_delay) = @config[2,3]; - $process_delay ||= 1; # days - $process_date = time2str('%D', time + ($process_delay * 86400)); + ($business_trans_code) = $config[2]; + ($personal_trans_code) = $config[3]; + + $process_date = time2str('%D', process_date($conf, $agentnum)); }, + delimiter => '', # avoid blank lines for header/footer + # EFT Upload Specification for .CSV Files, Rev. 2.0 # not a true CSV format--strings aren't quoted, so be careful row => sub { @@ -36,19 +73,28 @@ my ($trans_code, $process_date); # company + empty or first + last my $company = sprintf('%.64s', $cust_pay_batch->cust_main->company); if ( $company ) { - push @fields, $company, '' + push @fields, 'Business'; + push @fields, $company, ''; + $trans_code = $business_trans_code; } else { + push @fields, 'Personal'; push @fields, map { sprintf('%.64s', $_) } $cust_pay_batch->first, $cust_pay_batch->last; + $trans_code = $personal_trans_code; } my ($account, $aba) = split('@', $cust_pay_batch->payinfo); - # standard format for Canadian bank ID - $aba =~ /^0(\d{3})(\d{5})$/ - or die "invalid routing number '$aba'\n"; - push @fields, sprintf('%05s', $2), - sprintf('%03s', $1), - sprintf('%012s', $account), + my($bankno, $branch); + if ( $aba =~ /^0(\d{3})(\d{5})$/ ) { # standard format for Canadian bank ID + ($bankno, $branch) = ( $1, $2 ); + } elsif ( $aba =~ /^(\d{5})\.(\d{3})$/ ) { #how we store branches + ($branch, $bankno) = ( $1, $2 ); + } else { + die "invalid branch/routing number '$aba'\n"; + } + push @fields, sprintf('%05s', $branch), + sprintf('%03s', $bankno), + $account, sprintf('%.02f', $cust_pay_batch->amount); # DB = debit push @fields, 'DB', $trans_code, $process_date; @@ -60,4 +106,61 @@ my ($trans_code, $process_date); ); +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[4] || 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;