Class: Absa::H2h::Transmission::Eft
- Inherits:
-
Set
- Object
- Set
- Absa::H2h::Transmission::Eft
show all
- Defined in:
- lib/absa-h2h/eft.rb
Defined Under Namespace
Classes: ContraRecord, Header, StandardRecord, Trailer
Instance Attribute Summary
Attributes inherited from Set
#records
Instance Method Summary
collapse
Methods inherited from Set
build, for_record, hash_from_s, #header, #initialize, is_trailer_record?, layout_rules, module_name, partial_class_name, process_record, record_type, record_types, #to_s, #trailer, trailer_id, #transactions
Instance Method Details
#calculate_contra_record_total(contra_record) ⇒ Object
138
139
140
|
# File 'lib/absa-h2h/eft.rb', line 138
def calculate_contra_record_total(contra_record)
transactions_for_contra_record(contra_record).map(&:amount).map(&:to_i).inject(&:+)
end
|
#contra_records ⇒ Object
100
101
102
|
# File 'lib/absa-h2h/eft.rb', line 100
def contra_records
transactions.select {|t| t.contra_record? }
end
|
#credit_contra_records ⇒ Object
122
123
124
|
# File 'lib/absa-h2h/eft.rb', line 122
def credit_contra_records
transactions.select {|t| t.contra_record? && t.bankserv_record_identifier.to_i == 12}
end
|
#credit_records ⇒ Object
113
114
115
116
|
# File 'lib/absa-h2h/eft.rb', line 113
def credit_records
transactions.select {|t| t.bankserv_record_identifier.to_i == 10 }
end
|
#debit_contra_records ⇒ Object
118
119
120
|
# File 'lib/absa-h2h/eft.rb', line 118
def debit_contra_records
transactions.select {|t| t.contra_record? && t.bankserv_record_identifier.to_i == 52}
end
|
#debit_records ⇒ Object
108
109
110
111
|
# File 'lib/absa-h2h/eft.rb', line 108
def debit_records
transactions.select {|t| t.bankserv_record_identifier.to_i == 50 }
end
|
#homing_numbers_hash_total ⇒ Object
158
159
160
161
162
163
|
# File 'lib/absa-h2h/eft.rb', line 158
def homing_numbers_hash_total
ns_homing_account_number_total = self.standard_records.map(&:non_standard_homing_account_number).empty? ? 0 : self.standard_records.map(&:non_standard_homing_account_number).map(&:to_i).inject(&:+)
field9 = transactions.map(&:homing_account_number).map(&:to_i).inject(&:+) + ns_homing_account_number_total
field9.to_s.reverse[0,11].reverse.to_i
end
|
#standard_records ⇒ Object
104
105
106
|
# File 'lib/absa-h2h/eft.rb', line 104
def standard_records
transactions.select {|t| !t.contra_record? }
end
|
#total_credit_transactions ⇒ Object
132
133
134
135
136
|
# File 'lib/absa-h2h/eft.rb', line 132
def total_credit_transactions
dcr = self.debit_contra_records == [] ? 0 : self.debit_contra_records.map(&:amount).map(&:to_i).inject(&:+)
(self.credit_records.map(&:amount).map(&:to_i).inject(&:+) || 0) + dcr
end
|
#total_debit_transactions ⇒ Object
126
127
128
129
130
|
# File 'lib/absa-h2h/eft.rb', line 126
def total_debit_transactions
ccr = self.credit_contra_records == [] ? 0 : self.credit_contra_records.map(&:amount).map(&:to_i).inject(&:+)
(self.debit_records.map(&:amount).map(&:to_i).inject(&:+) || 0) + ccr
end
|
#transactions_for_contra_record(contra_record) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
# File 'lib/absa-h2h/eft.rb', line 142
def transactions_for_contra_record(contra_record)
contra_records = self.contra_records.map(&:user_sequence_number)
sequence = transactions.map(&:user_sequence_number)
if contra_records.index(contra_record.user_sequence_number) == 0 previous_contra_record = contra_record.user_sequence_number
start_point = 0
else
previous_contra_record = contra_records[contra_records.index(contra_record.user_sequence_number)-1]
start_point = sequence.index(previous_contra_record) + 1
end
end_point = sequence.index(contra_record.user_sequence_number)-1
transactions[start_point..end_point]
end
|
#validate! ⇒ Object
93
94
95
96
97
98
|
# File 'lib/absa-h2h/eft.rb', line 93
def validate!
validate_standard_transactions!
validate_contra_records!
validate_trailer_transactions!
end
|
#validate_contra_records! ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/absa-h2h/eft.rb', line 35
def validate_contra_records!
transactions.select{|t| t.contra_record? }.each do |transaction|
unless calculate_contra_record_total(transaction) == transaction.amount.to_i
raise "amount: Contra record amount must be the sum amount of all preceeding transactions. Expected #{calculate_contra_record_total(transaction)}. Got #{transaction.amount}."
end
transactions = transactions_for_contra_record(transaction)
if transactions.map(&:action_date).uniq.length > 1
raise "action_date: Contra records action date must be equal to all preceeding standard transactions action date. Got #{transactions_for_contra_record(transaction).map(&:action_date)}."
end
if (transactions.map(&:user_nominated_account).uniq.length > 1) or (transactions.map(&:user_nominated_account).first != transaction.user_nominated_account)
raise "user_nominated_account: Contra records user nominated account must match all preceeding standard transactions user nominated accounts. Got #{transactions.map(&:user_nominated_account)}."
end
if (transactions.map(&:user_branch).uniq.length > 1) or (transactions.map(&:user_branch).first != transaction.user_branch)
raise "user_branch_code: Contra records user branch must match all preceeding standard transactions user branch. Got #{transactions.map(&:user_branch)}."
end
raise "user_code: Contra records user code must match the headers users code. Got #{transaction.user_code}. Expected #{.bankserv_user_code}." unless transaction.user_code == .bankserv_user_code
end
end
|
27
28
29
30
31
32
33
|
# File 'lib/absa-h2h/eft.rb', line 27
def
raise "rec_status: Trailer and Header record status must be equal" if .rec_status != trailer.rec_status
raise "bankserv_user_code: Trailer and Header user code must be equal." if .bankserv_user_code != trailer.bankserv_user_code
raise "first_sequence_number: Trailer and Header sequence number must be equal." if .first_sequence_number != trailer.first_sequence_number
raise "first_action_date: Trailer and Header first action date must be equal." if .first_action_date != trailer.first_action_date
raise "last_action_date: Trailer and Header last action date must be equal." if .last_action_date != trailer.last_action_date
end
|
#validate_standard_transactions! ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/absa-h2h/eft.rb', line 6
def validate_standard_transactions!
if transactions.first.user_sequence_number != .first_sequence_number
raise "user_sequence_number: 1st Standard transactions user sequence number and the headers first sequence number must be equal."
end
raise "user_sequence_number: Duplicate user sequence number. Transactions must have unique sequence numbers!" unless transactions.map(&:user_sequence_number).uniq.length == transactions.length
unless transactions.map(&:user_sequence_number) == ((transactions.first.user_sequence_number.to_i)..(transactions.first.user_sequence_number.to_i + transactions.length-1)).map(&:to_s).to_a
raise "user_sequence_number: Transactions must increment sequentially. Got: #{transactions.map(&:user_sequence_number)}"
end
transactions.each do |transaction|
first_action_date = Date.strptime(.first_action_date, "%y%m%d")
last_action_date = Date.strptime(.last_action_date, "%y%m%d")
action_date = Date.strptime(transaction.action_date, "%y%m%d")
raise "action_date: Must be within the range of the headers first_action_date and last_action_date" unless (first_action_date..last_action_date).cover?(action_date)
raise "rec_status: Transaction and Header record status must be equal" if .rec_status != transaction.rec_status
end
end
|
#validate_trailer_transactions! ⇒ Object
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
|
# File 'lib/absa-h2h/eft.rb', line 60
def validate_trailer_transactions!
unless trailer.last_sequence_number == transactions.last.user_sequence_number
raise "last_sequence_number: Trailer records last sequence number must match the last contra records sequence number. Got #{trailer.last_sequence_number}. Expected #{transactions.last.user_sequence_number}"
end
debit_records = transactions.select {|t| t.bankserv_record_identifier.to_i == 50 }
credit_records = transactions.select {|t| t.bankserv_record_identifier.to_i == 10 }
unless trailer.no_debit_records.to_i == self.debit_records.count + self.credit_contra_records.count
raise "no_debit_records: Trailer records number of debit records must match the number of debit records. Expected #{debit_records.count}. Got #{trailer.no_debit_records}."
end
unless trailer.no_credit_records.to_i == self.credit_records.count + self.debit_contra_records.count
raise "no_credit_records: Trailer records number of credit records must match the number of credit records and contra debit records. Expected #{self.credit_records.count + self.debit_contra_records.count}. Got #{trailer.no_credit_records}."
end
unless trailer.no_contra_records.to_i == self.contra_records.count
raise "no_contra_records: Trailer records number of contra records must match the number of contra records. Expected #{self.contra_records.count}. Got #{trailer.no_contra_records}."
end
unless trailer.total_debit_value.to_i == self.total_debit_transactions
raise "total_debit_value: Trailer records total debit value must equal the sum amount of all transactions and credit contra records. Expected #{self.total_debit_transactions}. Got #{trailer.total_debit_value.to_i}."
end
unless trailer.total_credit_value.to_i == self.total_credit_transactions
raise "total_credit_value: Trailer records total credit value must equal the sum amount of all transactions and debit contra records. Expected #{self.total_credit_transactions}. Got #{trailer.total_credit_value.to_i}."
end
unless trailer.hash_total_of_homing_account_numbers.to_i == self.homing_numbers_hash_total
raise "hash_total_of_homing_account_numbers: Trailers hash total of homing account numbers does not match. Expected #{self.homing_numbers_hash_total}. Got #{trailer.hash_total_of_homing_account_numbers}."
end
end
|