aba 0.1.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +27 -16
- data/aba.gemspec +4 -3
- data/lib/aba.rb +79 -40
- data/lib/aba/transaction.rb +7 -7
- data/lib/aba/validations.rb +20 -6
- data/lib/aba/version.rb +1 -1
- data/spec/aba_spec.rb +48 -27
- data/spec/transaction_spec.rb +2 -3
- metadata +23 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7db46f198fd52a43b83a85c383db00bb9c1f6c0a
|
4
|
+
data.tar.gz: cfbf7860f3f136ee259c494fe88b0015c3a9d233
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3166c7bbe642707defa8e890f915de79813e07a264d07a77c2c5a5053fce053724a2956c3627b4d0e484ea9f52613c11cacf1a5f1f3161936ef10e9790398a7a
|
7
|
+
data.tar.gz: 4cfdf45552802bcd767524524602eabcf816695b39fe1f3ade9953c2e43fdb054934adaeffa028a6dd35d546545932629d44c956bd5d469cd07b74c2841bc7e8
|
data/README.md
CHANGED
@@ -1,32 +1,43 @@
|
|
1
|
+
[ ![Codeship Status for krakendevelopments/aba](https://codeship.com/projects/982382f0-f22b-0132-a80d-0acc257ded9c/status?branch=master)](https://codeship.com/projects/85083)
|
2
|
+
|
1
3
|
# Aba
|
2
4
|
|
3
|
-
|
5
|
+
Generates ABA (Australian Banking Association) file format output
|
4
6
|
|
5
7
|
## Usage
|
6
8
|
|
7
9
|
```ruby
|
8
10
|
require 'aba'
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
+
# Initialise ABA
|
13
|
+
aba = Aba.new(
|
14
|
+
bsb: "123-345", # Optional (Not required by NAB)
|
15
|
+
financial_institution: "WPC",
|
16
|
+
user_name: "John Doe",
|
17
|
+
user_id: "466364",
|
18
|
+
description: "Payroll",
|
19
|
+
process_at: Time.now.strftime("%d%m%y")
|
20
|
+
)
|
12
21
|
|
13
22
|
# Add transactions
|
14
|
-
|
15
|
-
aba.
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
10.times do
|
24
|
+
aba.add_transaction(
|
25
|
+
Aba::Transaction.new(
|
26
|
+
bsb: "342-342",
|
27
|
+
account_number: "3244654",
|
28
|
+
amount: 10000, # Amount in cents
|
29
|
+
account_name: "John Doe",
|
30
|
+
transaction_code: 53,
|
31
|
+
lodgement_reference: "R435564",
|
32
|
+
trace_bsb: "453-543",
|
33
|
+
trace_account_number: "45656733",
|
34
|
+
name_of_remitter: "Remitter"
|
35
|
+
)
|
26
36
|
)
|
27
37
|
end
|
28
38
|
|
29
|
-
puts aba.to_s
|
39
|
+
puts aba.to_s # View output
|
40
|
+
File.write("/Users/me/dd_#{Time.now.to_i}.aba", aba.to_s) # or write output to file
|
30
41
|
```
|
31
42
|
|
32
43
|
## Installation
|
data/aba.gemspec
CHANGED
@@ -6,8 +6,8 @@ require 'aba/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "aba"
|
8
8
|
spec.version = Aba::VERSION
|
9
|
-
spec.authors = ["Andrey Bazhutkin"]
|
10
|
-
spec.email = ["andrey.bazhutkin@gmail.com"]
|
9
|
+
spec.authors = ["Andrey Bazhutkin", "Trevor Wistaff"]
|
10
|
+
spec.email = ["andrey.bazhutkin@gmail.com", "trev@a07.com.au"]
|
11
11
|
spec.summary = "ABA File Generator"
|
12
12
|
spec.description = "ABA (Australian Bankers Association) File Generator"
|
13
13
|
spec.homepage = "https://github.com/andrba/aba"
|
@@ -19,7 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
-
spec.add_development_dependency "rake"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.4"
|
23
|
+
spec.add_development_dependency "pry", "~> 0.10"
|
23
24
|
spec.add_development_dependency "rspec", "~> 3.0"
|
24
25
|
|
25
26
|
spec.required_ruby_version = '>= 1.9.2'
|
data/lib/aba.rb
CHANGED
@@ -5,25 +5,23 @@ require "aba/transaction"
|
|
5
5
|
class Aba
|
6
6
|
include Aba::Validations
|
7
7
|
|
8
|
-
attr_accessor :bsb, :
|
9
|
-
:description, :process_at, :name_of_remitter, :transactions
|
8
|
+
attr_accessor :bsb, :financial_institution, :user_name, :user_id, :description, :process_at
|
10
9
|
|
11
|
-
|
12
|
-
|
13
|
-
validates_bsb :bsb
|
10
|
+
validates_bsb :bsb, allow_blank: true
|
14
11
|
|
15
|
-
validates_max_length :account_number, 9
|
16
|
-
validates_max_length :financial_institution, 3
|
17
12
|
validates_max_length :user_name, 26
|
18
13
|
validates_max_length :user_id, 6
|
19
14
|
validates_max_length :description, 12
|
20
15
|
|
16
|
+
validates_length :financial_institution, 3
|
17
|
+
validates_length :process_at, 6
|
18
|
+
|
21
19
|
def initialize(attrs = {})
|
22
20
|
attrs.each do |key, value|
|
23
21
|
send("#{key}=", value)
|
24
22
|
end
|
25
23
|
|
26
|
-
|
24
|
+
@transactions = []
|
27
25
|
|
28
26
|
yield self if block_given?
|
29
27
|
end
|
@@ -39,56 +37,70 @@ class Aba
|
|
39
37
|
output += "\r\n#{batch_control_record}"
|
40
38
|
end
|
41
39
|
|
40
|
+
def add_transaction(transaction)
|
41
|
+
@transactions << transaction
|
42
|
+
end
|
43
|
+
|
42
44
|
private
|
43
45
|
|
44
46
|
def descriptive_record
|
45
47
|
# Record type
|
48
|
+
# Max: 1
|
49
|
+
# Char position: 1
|
46
50
|
output = "0"
|
47
51
|
|
48
|
-
#
|
49
|
-
|
50
|
-
|
51
|
-
#
|
52
|
-
output += self.
|
53
|
-
|
54
|
-
# Reserved
|
55
|
-
output += " "
|
52
|
+
# Optional branch number of the funds account with a hyphen in the 4th character position
|
53
|
+
# Char position: 2-18
|
54
|
+
# Max: 17
|
55
|
+
# Blank filled
|
56
|
+
output += self.bsb.nil? ? " " * 17 : self.bsb.to_s.ljust(17)
|
56
57
|
|
57
58
|
# Sequence number
|
59
|
+
# Char position: 19-20
|
60
|
+
# Max: 2
|
61
|
+
# Zero padded
|
58
62
|
output += "01"
|
59
63
|
|
60
|
-
#
|
61
|
-
|
64
|
+
# Name of user financial instituion
|
65
|
+
# Max: 3
|
66
|
+
# Char position: 21-23
|
67
|
+
output += self.financial_institution.to_s
|
62
68
|
|
63
69
|
# Reserved
|
70
|
+
# Max: 7
|
71
|
+
# Char position: 24-30
|
64
72
|
output += " " * 7
|
65
73
|
|
66
|
-
# Name of User supplying File
|
67
|
-
|
74
|
+
# Name of User supplying File
|
75
|
+
# Char position: 31-56
|
76
|
+
# Max: 26
|
77
|
+
# Blank filled
|
78
|
+
output += self.user_name.to_s.ljust(26)
|
68
79
|
|
69
|
-
# Direct Entry User ID
|
80
|
+
# Direct Entry User ID
|
81
|
+
# Char position: 57-62
|
82
|
+
# Max: 6
|
83
|
+
# Zero padded
|
70
84
|
output += self.user_id.to_s.rjust(6, "0")
|
71
85
|
|
72
|
-
# Description of payments in the file (e.g. Payroll, Creditors etc.)
|
73
|
-
|
86
|
+
# Description of payments in the file (e.g. Payroll, Creditors etc.)
|
87
|
+
# Char position: 63-74
|
88
|
+
# Max: 12
|
89
|
+
# Blank filled
|
90
|
+
output += self.description.to_s.ljust(12)
|
74
91
|
|
75
|
-
# Date
|
76
|
-
|
92
|
+
# Date on which the payment is to be processed
|
93
|
+
# Char position: 75-80
|
94
|
+
# Max: 6
|
95
|
+
output += self.process_at.rjust(6, "0")
|
77
96
|
|
78
97
|
# Reserved
|
79
|
-
|
98
|
+
# Max: 40
|
99
|
+
# Char position: 81-120
|
100
|
+
output += " " * 40
|
80
101
|
end
|
81
102
|
|
82
103
|
def batch_control_record
|
83
|
-
# Record type
|
84
|
-
output = "7"
|
85
|
-
|
86
|
-
# BSB Format Filler
|
87
|
-
output += "999-999"
|
88
|
-
|
89
|
-
# Reserved
|
90
|
-
output += " " * 12
|
91
|
-
|
92
104
|
net_total_amount = 0
|
93
105
|
credit_total_amount = 0
|
94
106
|
debit_total_amount = 0
|
@@ -99,22 +111,49 @@ class Aba
|
|
99
111
|
debit_total_amount += t.amount if t.amount < 0
|
100
112
|
end
|
101
113
|
|
102
|
-
#
|
114
|
+
# Record type
|
115
|
+
# Max: 1
|
116
|
+
# Char position: 1
|
117
|
+
output = "7"
|
118
|
+
|
119
|
+
# BSB Format Filler
|
120
|
+
# Max: 7
|
121
|
+
# Char position: 2-8
|
122
|
+
output += "999-999"
|
123
|
+
|
124
|
+
# Reserved
|
125
|
+
# Max: 12
|
126
|
+
# Char position: 9-20
|
127
|
+
output += " " * 12
|
128
|
+
|
129
|
+
# Net total
|
130
|
+
# Max: 10
|
131
|
+
# Char position: 21-30
|
103
132
|
output += net_total_amount.abs.to_s.rjust(10, "0")
|
104
133
|
|
105
|
-
#
|
134
|
+
# Credit Total Amount
|
135
|
+
# Max: 10
|
136
|
+
# Char position: 31-40
|
106
137
|
output += credit_total_amount.abs.to_s.rjust(10, "0")
|
107
138
|
|
108
|
-
#
|
139
|
+
# Debit Total Amount
|
140
|
+
# Max: 10
|
141
|
+
# Char position: 41-50
|
109
142
|
output += debit_total_amount.abs.to_s.rjust(10, "0")
|
110
143
|
|
111
144
|
# Reserved
|
145
|
+
# Max: 24
|
146
|
+
# Char position: 51-74
|
112
147
|
output += " " * 24
|
113
148
|
|
114
|
-
#
|
149
|
+
# Total Item Count
|
150
|
+
# Max: 6
|
151
|
+
# Char position: 75-80
|
115
152
|
output += @transactions.size.to_s.rjust(6, "0")
|
116
153
|
|
117
154
|
# Reserved
|
155
|
+
# Max: 40
|
156
|
+
# Char position: 81-120
|
118
157
|
output += " " * 40
|
119
158
|
end
|
120
|
-
end
|
159
|
+
end
|
data/lib/aba/transaction.rb
CHANGED
@@ -2,14 +2,14 @@ class Aba
|
|
2
2
|
class Transaction
|
3
3
|
include Aba::Validations
|
4
4
|
|
5
|
-
attr_accessor :account_number, :transaction_code, :amount, :account_name,
|
6
|
-
:bsb, :trace_bsb, :trace_account_number, :name_of_remitter,
|
7
|
-
:indicator, :lodgement_reference
|
5
|
+
attr_accessor :account_number, :transaction_code, :amount, :account_name,
|
6
|
+
:bsb, :trace_bsb, :trace_account_number, :name_of_remitter,
|
7
|
+
:witholding_amount, :indicator, :lodgement_reference
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
validates_bsb :bsb
|
10
|
+
validates_bsb :trace_bsb
|
11
11
|
|
12
|
-
|
12
|
+
validates_integer :amount
|
13
13
|
|
14
14
|
validates_max_length :account_number, 9
|
15
15
|
validates_max_length :indicator, 1
|
@@ -73,4 +73,4 @@ class Aba
|
|
73
73
|
output += (witholding_amount || 0).abs.to_s.rjust(8, "0")
|
74
74
|
end
|
75
75
|
end
|
76
|
-
end
|
76
|
+
end
|
data/lib/aba/validations.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
class Aba
|
2
|
+
require 'pry'
|
2
3
|
module Validations
|
3
4
|
attr_accessor :errors
|
4
5
|
|
@@ -22,9 +23,15 @@ class Aba
|
|
22
23
|
when :presence
|
23
24
|
self.errors << "#{attribute} is empty" if value.nil? || value.to_s.empty?
|
24
25
|
when :bsb
|
25
|
-
|
26
|
+
unless((param && value.nil?) || value =~ /^\d{3}-\d{3}$/)
|
27
|
+
self.errors << "#{attribute} format is incorrect"
|
28
|
+
end
|
26
29
|
when :max_length
|
27
30
|
self.errors << "#{attribute} length must not exceed #{param} characters" if value.to_s.length > param
|
31
|
+
when :length
|
32
|
+
self.errors << "#{attribute} length must be exactly #{param} characters" if value.to_s.length != param
|
33
|
+
when :integer
|
34
|
+
self.errors << "#{attribute} must be an integer" unless value.to_s =~ /\A[+-]?\d+\Z/
|
28
35
|
end
|
29
36
|
end
|
30
37
|
end
|
@@ -39,16 +46,23 @@ class Aba
|
|
39
46
|
end
|
40
47
|
end
|
41
48
|
|
42
|
-
def validates_bsb(
|
43
|
-
|
44
|
-
|
45
|
-
end
|
49
|
+
def validates_bsb(attribute, options = {})
|
50
|
+
options[:allow_blank] ||= false
|
51
|
+
add_validation_attribute(attribute, :bsb, options[:allow_blank])
|
46
52
|
end
|
47
53
|
|
48
54
|
def validates_max_length(attribute, length)
|
49
55
|
add_validation_attribute(attribute, :max_length, length)
|
50
56
|
end
|
51
57
|
|
58
|
+
def validates_length(attribute, length)
|
59
|
+
add_validation_attribute(attribute, :length, length)
|
60
|
+
end
|
61
|
+
|
62
|
+
def validates_integer(attribute)
|
63
|
+
add_validation_attribute(attribute, :integer)
|
64
|
+
end
|
65
|
+
|
52
66
|
private
|
53
67
|
|
54
68
|
def add_validation_attribute(attribute, type, param = true)
|
@@ -57,4 +71,4 @@ class Aba
|
|
57
71
|
end
|
58
72
|
end
|
59
73
|
end
|
60
|
-
end
|
74
|
+
end
|
data/lib/aba/version.rb
CHANGED
data/spec/aba_spec.rb
CHANGED
@@ -1,40 +1,61 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Aba do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
:account_name => "John Doe",
|
14
|
-
:payment_id => "P2345543",
|
15
|
-
:transaction_code => 53,
|
16
|
-
:lodgement_reference => "R435564",
|
17
|
-
:trace_bsb => "453-543",
|
18
|
-
:trace_account_number => "45656733",
|
19
|
-
:name_of_remitter => "Remitter"
|
20
|
-
)
|
4
|
+
let(:aba) { Aba.new(financial_institution: "WPC", user_name: "John Doe",
|
5
|
+
user_id: "466364", description: "Payroll", process_at: "190615") }
|
6
|
+
let(:transaction_values) { [30, -20] }
|
7
|
+
let(:transactions) do
|
8
|
+
transaction_values.map do |amount|
|
9
|
+
Aba::Transaction.new(bsb: '342-342', account_number: '3244654', amount: amount,
|
10
|
+
account_name: 'John Doe', transaction_code: 53,
|
11
|
+
lodgement_reference: 'R435564', trace_bsb: '453-543',
|
12
|
+
trace_account_number: '45656733', name_of_remitter: 'Remitter')
|
21
13
|
end
|
22
|
-
|
23
|
-
aba
|
24
14
|
end
|
15
|
+
subject { aba }
|
16
|
+
before { transactions.each { |trx| subject.add_transaction(trx) } }
|
25
17
|
|
26
18
|
describe "#to_s" do
|
27
|
-
|
28
|
-
|
19
|
+
|
20
|
+
context 'when descriptive record' do
|
21
|
+
|
22
|
+
context 'without bsb' do
|
23
|
+
it "should return a string containing the descriptive record without the bsb" do
|
24
|
+
expect(subject.to_s).to include("0 01WPC John Doe 466364Payroll 190615 \r\n")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with bsb' do
|
29
|
+
before { subject.bsb = "123-345" }
|
30
|
+
it "should return a string containing the descriptive record with the bsb" do
|
31
|
+
expect(subject.to_s).to include("0123-345 01WPC John Doe 466364Payroll 190615 \r\n")
|
32
|
+
end
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
|
37
|
+
context 'when detail record' do
|
38
|
+
|
39
|
+
it "should contain transactions records" do
|
40
|
+
expect(subject.to_s).to include("1342-342 3244654 530000000030John Doe R435564 453-543 45656733Remitter 00000000\r\n")
|
41
|
+
expect(subject.to_s).to include("1342-342 3244654 530000000020John Doe R435564 453-543 45656733Remitter 00000000\r\n")
|
42
|
+
end
|
34
43
|
end
|
35
44
|
|
36
|
-
|
37
|
-
|
45
|
+
context 'when file total record' do
|
46
|
+
|
47
|
+
context 'with unbalanced transactions' do
|
48
|
+
it "should return a string wihere the net total is not zero" do
|
49
|
+
expect(subject.to_s).to include("7999-999 000000001000000000300000000020 000002 ")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with balanced transactions' do
|
54
|
+
let(:transaction_values) { [30, 30, -60] }
|
55
|
+
it "should return a string where the net total is zero" do
|
56
|
+
expect(subject.to_s).to include("7999-999 000000000000000000600000000060 000003 ")
|
57
|
+
end
|
58
|
+
end
|
38
59
|
end
|
39
60
|
end
|
40
|
-
end
|
61
|
+
end
|
data/spec/transaction_spec.rb
CHANGED
@@ -6,7 +6,6 @@ describe Aba::Transaction do
|
|
6
6
|
:transaction_code => 53,
|
7
7
|
:amount => 50050,
|
8
8
|
:account_name => "John Doe",
|
9
|
-
:payment_id => "P30234",
|
10
9
|
:bsb => "345-453",
|
11
10
|
:witholding_amount => 87,
|
12
11
|
:indicator => "W",
|
@@ -31,7 +30,7 @@ describe Aba::Transaction do
|
|
31
30
|
it "should not be valid" do
|
32
31
|
transaction_params.delete(:bsb)
|
33
32
|
expect(subject.valid?).to eq false
|
34
|
-
expect(subject.errors).to eq ["bsb
|
33
|
+
expect(subject.errors).to eq ["bsb format is incorrect"]
|
35
34
|
end
|
36
35
|
end
|
37
|
-
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Bazhutkin
|
8
|
+
- Trevor Wistaff
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2015-06-15 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -28,16 +29,30 @@ dependencies:
|
|
28
29
|
name: rake
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
|
-
- - "
|
32
|
+
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
+
version: '10.4'
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
|
-
- - "
|
39
|
+
- - "~>"
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '10.4'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - "~>"
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0.10'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "~>"
|
39
54
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
55
|
+
version: '0.10'
|
41
56
|
- !ruby/object:Gem::Dependency
|
42
57
|
name: rspec
|
43
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -55,6 +70,7 @@ dependencies:
|
|
55
70
|
description: ABA (Australian Bankers Association) File Generator
|
56
71
|
email:
|
57
72
|
- andrey.bazhutkin@gmail.com
|
73
|
+
- trev@a07.com.au
|
58
74
|
executables: []
|
59
75
|
extensions: []
|
60
76
|
extra_rdoc_files: []
|
@@ -94,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
94
110
|
version: '0'
|
95
111
|
requirements: []
|
96
112
|
rubyforge_project:
|
97
|
-
rubygems_version: 2.
|
113
|
+
rubygems_version: 2.2.2
|
98
114
|
signing_key:
|
99
115
|
specification_version: 4
|
100
116
|
summary: ABA File Generator
|