Class: Ach::Creator

Inherits:
Object
  • Object
show all
Defined in:
lib/ach/creator.rb

Class Method Summary collapse

Class Method Details

.block_count(filelines) ⇒ Object



6
7
8
9
# File 'lib/ach/creator.rb', line 6

def self.block_count(filelines)
  filelines = ((filelines.to_f+1)/10)
  return filelines.round
end

.create_file(structure, iterator, ach_filename) ⇒ Object



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)
  # records = iterator.get_entry_details

  @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)

  file_header_obj = 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)

    #chunk which supports creation of entry_detail db entries. Send in batch db entry's id
    @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]) #amount for storing the ach_@entry_details_table

      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
    #TODO: REPLACE addendacount!!! @entry_details[:records].size
    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

  #      rt_num_check_mod =  mod_operation(structure[:bank_params][:receiving_dfi_routing_num])

  @count_filelines = %x(wc -l #{"#{ach_filename}"}).split.first.to_i
  @block_count = block_count(@count_filelines)
  #((@trace_number_counter.last-1)+(@addenda_record_count.last-1)), #TODO: REPLACE THIS!!! @entry_details[:records].size
  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

.mod_operation(routing_num_mod) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ach/creator.rb', line 17

def self.mod_operation(routing_num_mod)
  @rtnum = routing_num_mod.to_s.split(//)
  @multiply = Array.new
  @multiply.push(@rtnum[0].to_i * 3)
  @multiply.push(@rtnum[1].to_i * 7)
  @multiply.push(@rtnum[2].to_i * 1)
  @multiply.push(@rtnum[3].to_i * 3)
  @multiply.push(@rtnum[4].to_i * 7)
  @multiply.push(@rtnum[5].to_i * 1)
  @multiply.push(@rtnum[6].to_i * 3)
  @multiply.push(@rtnum[7].to_i * 7)
  @add = (@multiply[0] + @multiply[1] + @multiply[2] + @multiply[3] + @multiply[4] + @multiply[5] + @multiply[6] + @multiply[7])
  if (@add % 10) == 0
  return (@add % 10)
  else
  return ((@add + 10 - (@add % 10)) - @add)
  end
end

.write_header(content, ach_filename) ⇒ Object



11
12
13
14
15
# File 'lib/ach/creator.rb', line 11

def self.write_header(content,ach_filename)
  ach_file = File.new(ach_filename.path,"a+")
  ach_file.puts(content)
  ach_file.close
end