Skip to content

Commit

Permalink
calculate block_count
Browse files Browse the repository at this point in the history
  • Loading branch information
arronmabrey committed Sep 26, 2022
1 parent 8f734e2 commit bff1d60
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/guevara/nacha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ def total
end

def file_control
entry_count = total { |b| b.batch_control.attributes[:entry_count] }
block_count = entry_count + batches.size * 2 + 2
entry_count = total { |b| b.batch_control.attributes[:entry_count] }
record_count = entry_count + batches.size * 2 + 2
block_count = (record_count/10.0).ceil # Count of the number of blocks of 10 rows within the file. https://achdevguide.nacha.org/ach-file-details

FileControl.new(
batch_count: batches.count,
block_count: block_count,
Expand Down
38 changes: 37 additions & 1 deletion test/test_file_generation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
705wellsville|KS|66092|101 2nd st| 00010000001
82000000020010310019000000001600000000000000 Ruby123 123456780000001
9000001000006000000020010310019000000001600000000000000
9000001000001000000020010310019000000001600000000000000
NACHA
nacha = Guevara::Nacha.new sample_nacha

Expand Down Expand Up @@ -50,3 +50,39 @@
nacha = Guevara::Nacha.new nacha_attributes
assert lines(nacha).size > 10
end

test 'calculate block_count (22 lines => 3 block_count)' do
expected = <<NACHA
101 12345678 123456781411281330A094101 Rubylit Zest 0
5200rubylit Ruby123PPD payments140918140921 1123456780000001
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
705wellsville|KS|66092|101 2nd st| 00010000001
82000000020010310019000000001600000000000000 Ruby123 123456780000001
5200rubylit Ruby123PPD payments140918140921 1123456780000002
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
705wellsville|KS|66092|101 2nd st| 00010000001
82000000020010310019000000001600000000000000 Ruby123 123456780000002
5200rubylit Ruby123PPD payments140918140921 1123456780000003
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
705wellsville|KS|66092|101 2nd st| 00010000001
82000000020010310019000000001600000000000000 Ruby123 123456780000003
5200rubylit Ruby123PPD payments140918140921 1123456780000004
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
705wellsville|KS|66092|101 2nd st| 00010000001
82000000020010310019000000001600000000000000 Ruby123 123456780000004
5200rubylit Ruby123PPD payments140918140921 1123456780000005
6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001
705wellsville|KS|66092|101 2nd st| 00010000001
82000000020010310019000000001600000000000000 Ruby123 123456780000005
9000005000003000000100051550095000000008000000000000000
NACHA
batches = 5.times.map do
sample_batch
end
nacha_attributes = sample_nacha.merge(:batches => batches)

nacha = Guevara::Nacha.new nacha_attributes
nacha.to_s.lines.to_a.each_with_index do |line, index|
debugger_equal line, expected.lines.to_a[index]
end
end

0 comments on commit bff1d60

Please sign in to comment.