Skip to content
Merged
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
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ GEM
PLATFORMS
ruby
x86_64-darwin-20
x86_64-linux

DEPENDENCIES
ach!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ bh.company_name = 'Company Name'
bh.company_identification = '123456789' # Use 10 characters if you're not using an EIN
bh.standard_entry_class_code = 'PPD'
bh.company_entry_description = 'DESCRIPTION'
bh.company_descriptive_date = Date.today
bh.company_descriptive_date = Date.today # Or string with 'SDHHMM' for same day ACH
bh.effective_entry_date = ACH::NextFederalReserveEffectiveDate.new(Date.today).result
bh.originating_dfi_identification = '00000000'
ach.batches << batch
Expand Down
16 changes: 15 additions & 1 deletion lib/ach/ach_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def parse data
bh.full_company_identification = line[40..49]
bh.standard_entry_class_code = line[50..52].strip
bh.company_entry_description = line[53..62].strip
bh.company_descriptive_date = Date.parse(line[63..68]) rescue nil # this can be various formats
bh.company_descriptive_date = parse_descriptive_date(line[63..68].strip)
bh.effective_entry_date = Date.parse(line[69..74])
bh.originating_dfi_identification = line[79..86].strip
when '6'
Expand Down Expand Up @@ -156,5 +156,19 @@ def parse data
self.batches << batch unless batch.nil?
to_s
end

def parse_descriptive_date(date_string)
return if date_string.empty?

date_time = date_string.match(/^SD(\d{2})(\d{2})$/) do
same_day_hour, same_day_minute = _1.captures.map(&:to_f)

Date.today.to_datetime + (same_day_hour + same_day_minute/60) / 24
end

date_time || Data.parse(date_string)
rescue
date_string
end
end
end
7 changes: 5 additions & 2 deletions lib/ach/string_formatting_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ module StringFormattingHelper
# Passing in SD to the date signifies same-day to banks. This is used for the company_descriptive_date
def self.stringify_with_same_day(f)
return f.upcase if f.to_s.upcase.match(/^SD\d+$/)
f.strftime('%y%m%d')

Date.strptime(f, '%y%m%d')
rescue
f
end
end
end
end
4 changes: 2 additions & 2 deletions spec/ach/fixtures/return_noc.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
101 191001234 9922222261210151518A094101Certification Bank-SiliCERTIFICATION BANK-SILIRETURNS
5200COMPANY INC DISC DATA 1412345678CORDESCRIPT 1210151210150001992222220000001
5200COMPANY INC DISC DATA 1412345678CORDESCRIPT SD19321210150001992222220000001
6211211403993300911569 0000000000A38LTNY2 NAME ONE 1121140390280747
798C05992222220280489 1211403932 121140390280747
820000000200121140390000000000000000000000001412345678 992222220000001
5200COMPANY INC DISC DATA 1412345678PPDDESCRIPT 1210151210150001992222220000002
6261211403993300911569 0000002536GKGQT9VK NAME TWO 1121140390280738
799R07992222220280393 12114039INVALID 121140390280738
820000000200121140390000000025360000000000001412345678 992222220000002
5200COMPANY INC DISC DATA 1412345678PPDDESCRIPT 1210150001992222220000003
5200COMPANY INC DISC DATA 1412345678PPDDESCRIPT nodate1210150001992222220000003
6261211403993300911569 0000002417KYU341VP NAME THREE 1121140390280729
799R03992222220280389 12114039 121140390280729
820000000200121140390000000024170000000000001412345678 992222220000003
Expand Down
28 changes: 27 additions & 1 deletion spec/ach/parse_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
end

it "should parse return/notification of change file" do
fake_current_datetime = Date.new(2012, 10, 15)
expected_datetime = DateTime.new(2012, 10, 15, 19, 32)
allow(Date).to receive(:today).and_return(fake_current_datetime)

ach = ACH::ACHFile.new(@data)
fh = ach.header
expect(fh.immediate_destination).to eq("191001234")
Expand All @@ -38,7 +42,29 @@
expect(bh.full_company_identification).to eq("1412345678")
expect(bh.standard_entry_class_code).to eq('COR')
expect(bh.company_entry_description).to eq("DESCRIPT")
expect(bh.company_descriptive_date).to eq(Date.parse('121015'))
expect(bh.company_descriptive_date).to eq(expected_datetime)
expect(bh.effective_entry_date).to eq(Date.parse('121015'))
expect(bh.originating_dfi_identification).to eq("99222222")

second_batch = ach.batches[1]
bh = second_batch.header
expect(bh.company_name).to eq("COMPANY INC")
expect(bh.company_identification).to eq("412345678")
expect(bh.full_company_identification).to eq("1412345678")
expect(bh.standard_entry_class_code).to eq('PPD')
expect(bh.company_entry_description).to eq("DESCRIPT")
expect(bh.company_descriptive_date).to eq('121015')
expect(bh.effective_entry_date).to eq(Date.parse('121015'))
expect(bh.originating_dfi_identification).to eq("99222222")

third_batch = ach.batches[2]
bh = third_batch.header
expect(bh.company_name).to eq("COMPANY INC")
expect(bh.company_identification).to eq("412345678")
expect(bh.full_company_identification).to eq("1412345678")
expect(bh.standard_entry_class_code).to eq('PPD')
expect(bh.company_entry_description).to eq("DESCRIPT")
expect(bh.company_descriptive_date).to eq('nodate')
expect(bh.effective_entry_date).to eq(Date.parse('121015'))
expect(bh.originating_dfi_identification).to eq("99222222")

Expand Down