36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
# File 'lib/ach/creator.rb', line 36
def self.create_file(structure,iterator,ach_filename)
@create_ach_file = File.new(ach_filename,"w+")
@create_ach_file.close
@addenda_count = 1
@addenda_record_count = Array.new
@trace_number = 0
@trace_number_counter = Array.new
@sequence_number = 1
@entry_hash_collector = Array.new
@filecontrol_debits = []
@filecontrol_credits = []
@entrydetails_counter= []
SecurityHeaderRecord.new(
:security_header => structure[:bank_params][:security_header],
:write_to_file => @create_ach_file)
= FileHeaderRecord.new(
:record_type => "1",
:priority_code => "01",
:record_size => "094",
:blocking_factor => "10",
:file_creation_date => structure[:file_header_record][:file_creation_date],
:file_creation_time => structure[:file_header_record][:file_creation_time],
:format_code => "1",
:file_id => structure[:bank_params][:file_id_yml],
:bank_name => structure[:bank_params][:name],
:company_name => structure[:file_header_record][:company_name],
:file_id_modifier => structure[:file_header_record][:file_id_modifier],
:origination_bank => "WELLS FARGO",
:wellsfargo_routing_number => " 091000019",
:write_to_file => @create_ach_file)
structure[:batch_header_records].each_with_index do |bhr,index|
@batch_debit_collector = []
@batch_credit_collector = []
@batch_header_obj = BatchHeaderRecord.new(
:record_type => '5',
:service_class_code => bhr[:service_class_code],
:company_name => bhr[:company_name],
:company_discretionary_data => (bhr[:company_discretionary_data] ? bhr[:company_discretionary_data] : nil),
:company_id => structure[:bank_params][:company_id_yml],
:standard_entry_class_code => bhr[:standard_entry_class_code],
:company_entry_description => bhr[:company_entry_description],
:company_descriptive_date => (bhr[:company_descriptive_date] ? bhr[:company_descriptive_date] : nil),
:effective_entry_date => bhr[:effective_entry_date],
:batch_number => (index+1).to_s,
:originator_status_code => "1",
:wellsfargo_routing_number => structure[:bank_params][:routing_num_originating_dfi_yml],
:write_to_file => @create_ach_file)
@entry_details = iterator.get_entry_details
@entrydetails_counter << @entry_details.size.to_i
@entry_details.each do |i|
@receiving_dfi_routing_num = i[:receiving_dfi_routing_number]
rt_num_check_mod = mod_operation(@receiving_dfi_routing_num)
@trace_number_counter.push @trace_number
@trace_number+=1
entry_detail = EntryDetailRecord.new(
:transaction_code => i[:transaction_code],
:receiving_dfi_routing_num => @receiving_dfi_routing_num,
:rt_num_check => rt_num_check_mod,
:receiving_dfi_acc_num => i[:receiving_dfi_account_number],
:amount => i[:amount].to_s.sub(/[.]/,''),
:individual_id => i[:individual_id],
:individual_name => (i[:individual_name].nil? ? "" : i[:individual_name]),
:routing_number => structure[:bank_params][:routing_num_originating_dfi_yml],
:trace_number => @trace_number,
:settlement_id => i.respond_to?(:settlement_id) ? i[:settlement_id] : nil,
:loan_payment_id => i.respond_to?(:loan_payment_id) ? i[:loan_payment_id] : nil,
:write_to_file => @create_ach_file,
:db_entry_amount => i[:amount])
if (i[:transaction_code]=="22" or i[:transaction_code]=="32")
@batch_credit_collector.push i[:amount].to_f
else
@batch_debit_collector.push i[:amount].to_f
end
@rdfi_rtn_split = @receiving_dfi_routing_num.slice(0..7)
@rdfi_rtn_split.each {|i| @entry_hash_collector.push i.to_i}
@addenda_count+=1
@addenda_record_count.push @addenda_count
end
batch_control = BatchControlRecord.new(
:service_class_code => bhr[:service_class_code],
:addenda_count => @entry_details.size,
:entry_hash => @entry_hash_collector.inject(0) {|sum,i| sum+i},
:total_debits => @batch_debit_collector.inject(0) {|sum,i| sum+i}.to_s.sub(/[.]/,''),
:total_credits => @batch_credit_collector.inject(0) {|sum,i| sum+i}.to_s.sub(/[.]/,''),
:company_id => structure[:bank_params][:company_id_yml],
:routing_num => structure[:bank_params][:routing_num_originating_dfi_yml],
:batch_number => (index+1).to_s,
:write_to_file => @create_ach_file)
@batch_credit_collector.each {|x| @filecontrol_credits << x}
@batch_debit_collector.each {|x| @filecontrol_debits << x}
end
@count_filelines = %x(wc -l #{"#{ach_filename}"}).split.first.to_i
@block_count = block_count(@count_filelines)
file_control = FileControlRecord.new(
:batch_count => structure[:batch_header_records].size,
:block_count => @block_count,
:entry_addenda => @entrydetails_counter.inject(0) {|sum,i| sum+i},
:entry_hash_total => @entry_hash_collector.inject(0) {|sum,i| sum+i},
:total_debits => @filecontrol_debits.inject(0) {|sum,i| sum+i}.to_s.sub(/[.]/,''),
:total_credits => @filecontrol_credits.inject(0) {|sum,i| sum+i}.to_s.sub(/[.]/,''),
:write_to_file => @create_ach_file)
end
|