X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpay_batch%2Fnacha.pm;h=0361304e384a7d1cd2b9213752cd42b6c2546a84;hb=725118b4ae55c06cefb2d0b2ef41c7addf4a3a97;hp=c069082c7945e62a4c85a0867efec31499fcca74;hpb=ded0ab5cac02f099b387de360fb6dd6bd8cbb6b4;p=freeside.git diff --git a/FS/FS/pay_batch/nacha.pm b/FS/FS/pay_batch/nacha.pm index c069082c7..0361304e3 100644 --- a/FS/FS/pay_batch/nacha.pm +++ b/FS/FS/pay_batch/nacha.pm @@ -7,7 +7,7 @@ use Date::Format; #use FS::Conf; $name = 'NACHA'; - +my $i; $DEBUG = 0; %import_info = ( @@ -79,7 +79,7 @@ $DEBUG = 0; '1'. #Format code $dest_name. #Immediate Destination Name / 23 char bank name $company. #Immediate Origin Name / 23 char company name - $refcode. #Reference Code (internal/optional) + $refcode. "\n". #Reference Code (internal/optional) ### # Batch Header Record @@ -110,7 +110,7 @@ $DEBUG = 0; (' 'x3). #Settlement Date / Reserved '1'. #Originator Status Code substr($dest, 0, 8). #Originating Financial Institution - $batchnum #Batch Number ("number batches sequentially") + $batchnum. "\n" #Batch Number ("number batches sequentially") }, @@ -119,6 +119,10 @@ $DEBUG = 0; my ($account, $aba) = split('@', $cust_pay_batch->payinfo); + $conf->config('batchconfig-nacha-destination') =~ /^\s*(\d{9})\s*$/ + or die 'illegal NACHA Destination'; + my $dest = $1; + # "Total of all positions 4-11 on each 6 record" $entry_hash += substr($aba,0,8); @@ -130,7 +134,8 @@ $DEBUG = 0; my $transaction_code = ( $cust_main->paytype =~ /savings/i ? '37' : '27' ); my $cust_name = substr($cust_main->name. (' 'x22), 0, 22); - + $i++; + my $tracenum = $dest. substr(('0'x7). $i, -6); #non-PPD transactions? future warn "building PPD Record\n" if $DEBUG; @@ -143,13 +148,14 @@ $DEBUG = 0; $transaction_code. #Transaction Code $aba. #Receiving DFI Identification, check digit substr($account.(' 'x17), 0, 17). #DFI Account number (Left justify) - sprintf('%010d', $cust_pay_batch->amount * 100). #Amount + sprintf('%010.0f', $cust_pay_batch->amount * 100). #Amount $cust_identifier. #Individual Identification Number, 15 char $cust_name. #Individual name (22-char) ' '. #2 char "company internal use if desired" '0'. #Addenda Record Indicator - (' 'x15) #15 digit "bank will assign trace number" - # (00000?) +# (' 'x15). #15 digit "bank will assign trace number" + $tracenum. + "\n" # (00000?) }, 'footer' => sub { @@ -168,6 +174,15 @@ $DEBUG = 0; my $batchnum = substr( ('0'x7). $pay_batch->batchnum, -7); + my $lines = $batchcount + 4; + my $blocks = int($lines/10); + my $fill = ''; + + if ( my $remainder = $lines % 10 ) { + $blocks++; + $fill = ("\n".('9'x94))x( 10 - $remainder ); + } + warn "building Batch & File Control Records\n" if $DEBUG; ### @@ -179,13 +194,13 @@ $DEBUG = 0; # 200 mixed debits&credits) sprintf('%06d', $batchcount). #Entry / Addenda Count $entry_hash. - sprintf('%012d', $batchtotal * 100). #Debit total + sprintf('%012.0f', $batchtotal * 100). #Debit total '000000000000'. #Credit total $origin. #Company Identification (Immediate Origin) (' 'x19). #Message Authentication Code (19 char blank) (' 'x6). #Federal Reserve Use (6 char blank) substr($dest, 0, 8). #Originating Financial Institution - $batchnum. #Batch Number ("number batches sequentially") + $batchnum. "\n". #Batch Number ("number batches sequentially") ### # File Control Record @@ -193,12 +208,18 @@ $DEBUG = 0; '9'. #Record Type Code '000001'. #Batch Counter (# of batch header recs) - sprintf('%06d', $batchcount + 4). #num of physical blocks on the file..? + sprintf('%06d', $blocks). #num of physical blocks on the file sprintf('%08d', $batchcount). #total # of entry detail and addenda $entry_hash. - sprintf('%012d', $batchtotal * 100). #Debit total + sprintf('%012.0f', $batchtotal * 100). #Debit total '000000000000'. #Credit total - ( ' 'x39 ) #Reserved / blank + ( ' 'x39 ). #Reserved / blank + + ### + # Pad with 9999 records to blocks of 10 + ### + + $fill },