payment_dta 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +45 -0
  3. data/VERSION +1 -0
  4. data/generators/payment/USAGE +5 -0
  5. data/generators/payment/payment_generator.rb +76 -0
  6. data/generators/payment/templates/model.rb.erb +39 -0
  7. data/generators/payment/templates/spec.rb.erb +48 -0
  8. data/lib/payment_dta.rb +4 -0
  9. data/lib/payment_dta/character_conversion.rb +251 -0
  10. data/lib/payment_dta/dta_file.rb +55 -0
  11. data/lib/payment_dta/payment_sorting.rb +19 -0
  12. data/lib/payment_dta/payments/bank_cheque_payment.rb +60 -0
  13. data/lib/payment_dta/payments/base.rb +288 -0
  14. data/lib/payment_dta/payments/domestic_chf_payment.rb +67 -0
  15. data/lib/payment_dta/payments/esr_payment.rb +48 -0
  16. data/lib/payment_dta/payments/financial_institution_payment.rb +56 -0
  17. data/lib/payment_dta/payments/iban_payment.rb +76 -0
  18. data/lib/payment_dta/payments/special_financial_institution_payment.rb +64 -0
  19. data/lib/payment_dta/payments/total_record.rb +31 -0
  20. data/script/destroy +14 -0
  21. data/script/generate +14 -0
  22. data/spec/factory.rb +82 -0
  23. data/spec/lib/bank_cheque_payment_spec.rb +178 -0
  24. data/spec/lib/character_conversion_spec.rb +280 -0
  25. data/spec/lib/domestic_chf_payment_spec.rb +189 -0
  26. data/spec/lib/dta_file_spec.rb +81 -0
  27. data/spec/lib/esr_payment_spec.rb +157 -0
  28. data/spec/lib/financial_institution_payment_spec.rb +229 -0
  29. data/spec/lib/iban_payment_spec.rb +201 -0
  30. data/spec/lib/payment_header_spec.rb +221 -0
  31. data/spec/lib/payment_spec.rb +15 -0
  32. data/spec/lib/special_financial_institution_payment_spec.rb +238 -0
  33. data/spec/lib/total_record_spec.rb +20 -0
  34. data/spec/spec_helper.rb +9 -0
  35. metadata +107 -0
@@ -0,0 +1,55 @@
1
+ require 'set'
2
+ require 'payment_dta/payments/total_record'
3
+ class DTAFile
4
+ attr_reader :records
5
+
6
+ def initialize(path, transaction_number = rand(100000000000).to_s)
7
+ @transaction_number = transaction_number.to_s
8
+ @path = path
9
+ @records = SortedSet.new
10
+ end
11
+
12
+ def write_file
13
+ File.open(@path,"w") do |file|
14
+ @records.each{|record| file.puts record.to_dta}
15
+ file.puts build_total_record.to_dta
16
+ end
17
+ end
18
+
19
+ def total
20
+ @records.inject(0) do |sum, record|
21
+ sum + record.amount.to_f
22
+ end
23
+ end
24
+
25
+ def <<(record)
26
+ record.transaction_number = @transaction_number
27
+ @records << record
28
+ recalculate_output_sequence_numbers
29
+ end
30
+
31
+ def self.create(path)
32
+ dta_file = self.new(path)
33
+ yield dta_file
34
+ dta_file.write_file
35
+ dta_file
36
+ end
37
+
38
+ private
39
+
40
+ def recalculate_output_sequence_numbers
41
+ start = 1
42
+ @records.each do |record|
43
+ record.output_sequence_number = start
44
+ start += 1
45
+ end
46
+ end
47
+
48
+ def build_total_record
49
+ TotalRecord.new(
50
+ :total_amount => total,
51
+ :data_file_sender_identification => @records.first.data_file_sender_identification
52
+ )
53
+ end
54
+
55
+ end
@@ -0,0 +1,19 @@
1
+ module DTA
2
+ module Payment
3
+ module Sortable
4
+ include Comparable
5
+
6
+ def <=>(other)
7
+ if requested_processing_date == other.requested_processing_date
8
+ if issuer_identification == other.issuer_identification
9
+ return ordering_party_bank_clearing_number <=> other.ordering_party_bank_clearing_number
10
+ else
11
+ return issuer_identification <=> other.issuer_identification
12
+ end
13
+ else
14
+ return requested_processing_date <=> other.requested_processing_date
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,60 @@
1
+ require 'payment_dta/payments/base'
2
+ require 'payment_dta/payment_sorting'
3
+
4
+ class BankChequePayment < DTA::Payments::Base
5
+ include DTA::Payment::Sortable
6
+
7
+ def record
8
+ @record ||= segment1 + segment2 + segment3 + segment4 + segment5
9
+ end
10
+
11
+ def transaction_type
12
+ '832'
13
+ end
14
+
15
+ def payment_type
16
+ '0'
17
+ end
18
+
19
+ def requested_processing_date
20
+ '000000'
21
+ end
22
+
23
+ def payment_amount_value
24
+ @data[:payment_amount].to_s.ljust(15)
25
+ end
26
+
27
+ def payment_amount_value_date
28
+ @data[:payment_amount_value_date].to_s.ljust(6)
29
+ end
30
+
31
+ def convertion_rate
32
+ @data[:convertion_rate].to_s.ljust(12)
33
+ end
34
+
35
+ def beneficiary_bank_account_number
36
+ '/C/'.ljust(24)
37
+ end
38
+
39
+ protected
40
+
41
+ def build_segment1
42
+ super + reference_number + account_to_be_debited + payment_amount + reserve_field(11)
43
+ end
44
+
45
+ def build_segment2
46
+ super + convertion_rate + ordering_partys_address(24) + reserve_field(18)
47
+ end
48
+
49
+ def build_segment3
50
+ super + beneficiary_bank_account_number + beneficiary_address(24) + reserve_field(6)
51
+ end
52
+
53
+ def build_segment4
54
+ super + reason_for_payment_message(28) + reserve_field(14)
55
+ end
56
+
57
+ def build_segment5
58
+ super + bank_payment_instructions + reserve_field(6)
59
+ end
60
+ end
@@ -0,0 +1,288 @@
1
+ require 'date'
2
+ require 'payment_dta/character_conversion'
3
+
4
+ module DTA
5
+ module Payments
6
+ class Base
7
+ include DTA::CharacterConversion
8
+
9
+ def initialize(data = {})
10
+ @data = data
11
+ end
12
+
13
+ def to_dta
14
+ dta_string(record)
15
+ end
16
+
17
+ def segment1
18
+ @segment1 ||= build_segment1
19
+ end
20
+
21
+ def segment2
22
+ @segment2 ||= build_segment2
23
+ end
24
+
25
+ def segment3
26
+ @segment3 ||= build_segment3
27
+ end
28
+
29
+ def segment4
30
+ @segment4 ||= build_segment4
31
+ end
32
+
33
+ def segment5
34
+ @segment5 ||= build_segment5
35
+ end
36
+
37
+ def segment6
38
+ @segment6 ||= build_segment6
39
+ end
40
+
41
+ def record
42
+ @record ||= segment1 + segment2 + segment3 + segment4 + segment5 + segment6
43
+ end
44
+
45
+ def header
46
+ @header ||= build_header
47
+ end
48
+
49
+ def requested_processing_date
50
+ @data[:requested_processing_date].to_s
51
+ end
52
+
53
+ def beneficiary_bank_clearing_number
54
+ @data[:beneficiary_bank_clearing_number].to_s.ljust(12,' ')
55
+ end
56
+
57
+ def output_sequence_number
58
+ @output_sequence_number.to_s.rjust(5,'0')
59
+ end
60
+
61
+ def output_sequence_number=(output_sequence_number)
62
+ @output_sequence_number = output_sequence_number
63
+ end
64
+
65
+ def creation_date
66
+ Date.today.strftime('%y%m%d')
67
+ end
68
+
69
+ def ordering_party_bank_clearing_number
70
+ @data[:ordering_party_bank_clearing_number].to_s.ljust(7,'0')
71
+ end
72
+
73
+ def data_file_sender_identification
74
+ if @data[:data_file_sender_identification].nil?
75
+ raise 'No file identification'
76
+ else
77
+ @data[:data_file_sender_identification]
78
+ end
79
+ end
80
+
81
+ def entry_sequence_number
82
+ @data[:entry_sequence_number].to_s.rjust(5,'0')
83
+ end
84
+
85
+ def payment_type
86
+ '1'
87
+ end
88
+
89
+ def processing_flag
90
+ '0'
91
+ end
92
+
93
+ def issuer_identification
94
+ @data[:issuer_identification].to_s
95
+ end
96
+
97
+ def transaction_number
98
+ (@transaction_number || @data[:transaction_number]).to_s.ljust(11,'0')
99
+ end
100
+
101
+ def transaction_number=(transaction_number)
102
+ @transaction_number = transaction_number
103
+ end
104
+
105
+ def reference_number
106
+ issuer_identification + transaction_number
107
+ end
108
+
109
+ def account_to_be_debited
110
+ @data[:account_to_be_debited].to_s.ljust(24)
111
+ end
112
+
113
+ def payment_amount
114
+ payment_amount_value_date + payment_amount_currency + payment_amount_value
115
+ end
116
+
117
+ def payment_amount_value_date
118
+ ''.ljust(6)
119
+ end
120
+
121
+ def payment_amount_currency
122
+ @data[:payment_amount_currency].to_s
123
+ end
124
+
125
+ def amount
126
+ @data[:payment_amount]
127
+ end
128
+
129
+ def payment_amount_value
130
+ @data[:payment_amount].to_s.ljust(12)
131
+ end
132
+
133
+ def ordering_partys_address(line_size=24)
134
+ ordering_partys_address_line1(line_size) + ordering_partys_address_line2(line_size) + ordering_partys_address_line3(line_size) + ordering_partys_address_line4(line_size)
135
+ end
136
+
137
+ def ordering_partys_address_line1(line_size = 24)
138
+ @data[:ordering_partys_address_line1].to_s.ljust(line_size)
139
+ end
140
+
141
+ def ordering_partys_address_line2(line_size = 24)
142
+ @data[:ordering_partys_address_line2].to_s.ljust(line_size)
143
+ end
144
+
145
+ def ordering_partys_address_line3(line_size = 24)
146
+ @data[:ordering_partys_address_line3].to_s.ljust(line_size)
147
+ end
148
+
149
+ def ordering_partys_address_line4(line_size = 24)
150
+ @data[:ordering_partys_address_line4].to_s.ljust(line_size)
151
+ end
152
+
153
+ def beneficiary_address(line_size=24)
154
+ beneficiary_address_line1(line_size) + beneficiary_address_line2(line_size) + beneficiary_address_line3(line_size) + beneficiary_address_line4(line_size)
155
+ end
156
+
157
+ def beneficiary_address_line1(line_size=24)
158
+ @data[:beneficiary_address_line1].to_s.ljust(line_size)
159
+ end
160
+
161
+ def beneficiary_address_line2(line_size=24)
162
+ @data[:beneficiary_address_line2].to_s.ljust(line_size)
163
+ end
164
+
165
+ def beneficiary_address_line3(line_size=24)
166
+ @data[:beneficiary_address_line3].to_s.ljust(line_size)
167
+ end
168
+
169
+ def beneficiary_address_line4(line_size=24)
170
+ @data[:beneficiary_address_line4].to_s.ljust(line_size)
171
+ end
172
+
173
+ def reason_for_payment_message(line_size=24)
174
+ reason_for_payment_message_line1(line_size) + reason_for_payment_message_line2(line_size) + reason_for_payment_message_line3(line_size) + reason_for_payment_message_line4(line_size)
175
+ end
176
+
177
+ def reason_for_payment_message_line1(line_size=24)
178
+ @data[:reason_for_payment_message_line1].to_s.ljust(line_size)
179
+ end
180
+
181
+ def reason_for_payment_message_line2(line_size=24)
182
+ @data[:reason_for_payment_message_line2].to_s.ljust(line_size)
183
+ end
184
+
185
+ def reason_for_payment_message_line3(line_size=24)
186
+ @data[:reason_for_payment_message_line3].to_s.ljust(line_size)
187
+ end
188
+
189
+ def reason_for_payment_message_line4(line_size=24)
190
+ @data[:reason_for_payment_message_line4].to_s.ljust(line_size)
191
+ end
192
+
193
+ def bank_payment_instructions
194
+ @data[:bank_payment_instructions].to_s.ljust(120)
195
+ end
196
+
197
+ def identification_bank_address
198
+ @data[:identification_bank_address].to_s
199
+ end
200
+
201
+ def beneficiary_bank_account_number
202
+ "/C/#{@data[:beneficiary_bank_account_number].to_s}".ljust(24)
203
+ end
204
+
205
+ def beneficiary_institution_bank_account_number
206
+ "/C/#{@data[:beneficiary_institution_bank_account_number]}".ljust(24)
207
+ end
208
+
209
+ def beneficiary_institution_address(line_size=24)
210
+ if identification_bank_address == 'A'
211
+ @data[:beneficiarys_institution_swift_address_].to_s.ljust(24) + ''.ljust(72)
212
+ else
213
+ beneficiary_institution_address_line1 + beneficiary_institution_address_line2 + beneficiary_institution_address_line3 + beneficiary_institution_address_line4
214
+ end
215
+ end
216
+
217
+ def beneficiary_institution_address_line1
218
+ @data[:beneficiary_institution_address_line1].to_s.ljust(24)
219
+ end
220
+
221
+ def beneficiary_institution_address_line2
222
+ @data[:beneficiary_institution_address_line2].to_s.ljust(24)
223
+ end
224
+
225
+ def beneficiary_institution_address_line3
226
+ @data[:beneficiary_institution_address_line3].to_s.ljust(24)
227
+ end
228
+
229
+ def beneficiary_institution_address_line4
230
+ @data[:beneficiary_institution_address_line4].to_s.ljust(24)
231
+ end
232
+
233
+ def beneficiary_iban_number
234
+ @data[:beneficiary_iban_number].to_s.ljust(34)
235
+ end
236
+
237
+ def identification_purpose
238
+ @data[:identification_purpose].to_s[0,1]
239
+ end
240
+
241
+ def purpose
242
+ if identification_purpose == 'I'
243
+ @data[:purpose_structured_reference_number].to_s.ljust(105)
244
+ else
245
+ @data[:purpose_line_1].to_s.ljust(35) + @data[:purpose_line_2].to_s.ljust(35) + @data[:purpose_line_3].to_s.ljust(35)
246
+ end
247
+ end
248
+
249
+ def rule_of_charge
250
+ @data[:rule_of_charge].to_s[0,1]
251
+ end
252
+
253
+ protected
254
+
255
+ def build_segment1
256
+ '01'+ header
257
+ end
258
+
259
+ def build_segment2
260
+ '02'
261
+ end
262
+
263
+ def build_segment3
264
+ '03'
265
+ end
266
+
267
+ def build_segment4
268
+ '04'
269
+ end
270
+
271
+ def build_segment5
272
+ '05'
273
+ end
274
+
275
+ def build_segment6
276
+ '06'
277
+ end
278
+
279
+ def build_header
280
+ requested_processing_date + beneficiary_bank_clearing_number + output_sequence_number + creation_date + ordering_party_bank_clearing_number + data_file_sender_identification + entry_sequence_number + transaction_type + payment_type + processing_flag
281
+ end
282
+
283
+ def reserve_field(length = 14)
284
+ ''.ljust(length)
285
+ end
286
+ end
287
+ end
288
+ end
@@ -0,0 +1,67 @@
1
+ require 'payment_dta/payments/base'
2
+ require 'payment_dta/payment_sorting'
3
+
4
+ class DomesticCHFPayment < DTA::Payments::Base
5
+ include DTA::Payment::Sortable
6
+
7
+ def record
8
+ @record ||= segment1 + segment2 + segment3 + segment4 + segment5
9
+ end
10
+
11
+ def transaction_type
12
+ '827'
13
+ end
14
+
15
+ def payment_type
16
+ '0'
17
+ end
18
+
19
+ def beneficiarys_bank_account_number
20
+ "/C/#{@data[:beneficiarys_bank_account_number]}".ljust(30)
21
+ end
22
+
23
+ def end_beneficiary_address
24
+ end_beneficiary_address_line1 + end_beneficiary_address_line2 + end_beneficiary_address_line3 + end_beneficiary_address_line4
25
+ end
26
+
27
+ def end_beneficiary_address_line1
28
+ @data[:end_beneficiary_address_line1].to_s.ljust(24)
29
+ end
30
+
31
+ def end_beneficiary_address_line2
32
+ @data[:end_beneficiary_address_line2].to_s.ljust(24)
33
+ end
34
+
35
+ def end_beneficiary_address_line3
36
+ @data[:end_beneficiary_address_line3].to_s.ljust(24)
37
+ end
38
+
39
+ def end_beneficiary_address_line4
40
+ @data[:end_beneficiary_address_line4].to_s.ljust(24)
41
+ end
42
+
43
+ def end_beneficiarys_bank_account_number
44
+ "/C/#{@data[:end_beneficiarys_bank_account_number]}".ljust(30)
45
+ end
46
+ protected
47
+
48
+ def build_segment1
49
+ super + reference_number + account_to_be_debited + payment_amount + reserve_field(14)
50
+ end
51
+
52
+ def build_segment2
53
+ super + ordering_partys_address + reserve_field(30)
54
+ end
55
+
56
+ def build_segment3
57
+ super + beneficiarys_bank_account_number + beneficiary_address
58
+ end
59
+
60
+ def build_segment4
61
+ super + reason_for_payment_message(28) + reserve_field(14)
62
+ end
63
+
64
+ def build_segment5
65
+ super + end_beneficiarys_bank_account_number + end_beneficiary_address
66
+ end
67
+ end