Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calculate block_count #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/guevara/nacha.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def total

def file_control
entry_count = total { |b| b.batch_control.attributes[:entry_count] }
block_count = entry_count + batches.size * 2 + 2
total_count = entry_count + batches.size * 2 + 2
block_count = (total_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