Class: Aba::Transaction

Inherits:
Entry
  • Object
show all
Includes:
Validations
Defined in:
lib/aba/transaction.rb

Constant Summary

Constants included from Validations

Validations::BECS_PATTERN, Validations::CREDIT_TRANSACTION_CODES, Validations::DEBIT_TRANSACTION_CODES, Validations::INDICATORS

Instance Attribute Summary collapse

Attributes included from Validations

#error_collection

Instance Method Summary collapse

Methods included from Validations

included, transaction_codes, #valid?

Methods inherited from Entry

#credit?, #debit?, #initialize

Constructor Details

This class inherits a constructor from Aba::Entry

Instance Attribute Details

#account_nameObject

Returns the value of attribute account_name.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def 
  @account_name
end

#account_numberObject

Allow dashes to be input, but remove them from output



44
45
46
# File 'lib/aba/transaction.rb', line 44

def 
  @account_number
end

#amountObject

Returns the value of attribute amount.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def amount
  @amount
end

#bsbObject

Returns the value of attribute bsb.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def bsb
  @bsb
end

#indicatorObject

Sane default for majority of use cases as per BECS



49
50
51
# File 'lib/aba/transaction.rb', line 49

def indicator
  @indicator
end

#lodgement_referenceObject

Optional as per BECS



54
55
56
# File 'lib/aba/transaction.rb', line 54

def lodgement_reference
  @lodgement_reference
end

#name_of_remitterObject

Returns the value of attribute name_of_remitter.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def name_of_remitter
  @name_of_remitter
end

#trace_account_numberObject

Returns the value of attribute trace_account_number.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def 
  @trace_account_number
end

#trace_bsbObject

Returns the value of attribute trace_bsb.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def trace_bsb
  @trace_bsb
end

#transaction_codeObject

Returns the value of attribute transaction_code.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def transaction_code
  @transaction_code
end

#witholding_amountObject

Returns the value of attribute witholding_amount.



7
8
9
# File 'lib/aba/transaction.rb', line 7

def witholding_amount
  @witholding_amount
end

Instance Method Details

#to_sObject

Raises:

  • (RuntimeError)


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
# File 'lib/aba/transaction.rb', line 58

def to_s
  raise RuntimeError, 'Transaction data is invalid - check the contents of `errors`' unless valid?

  # Record type
  output = "1"

  # BSB of account
  output += bsb

  # Account number
  #raise RuntimeError, 'Transaction is missing account_number' unless account_number
  output += .to_s.rjust(9, " ")

  # Withholding Tax Indicator
  # "N" – for new or varied Bank/State/Branch number or name details, otherwise blank filled.
  # "T" - for a drawing under a Transaction Negotiation Authority.
  # "W" – dividend paid to a resident of a country where a double tax agreement is in force.
  # "X" – dividend paid to a resident of any other country.
  # "Y" – interest paid to all non-residents.
  output += indicator.to_s.ljust(1, " ")

  # Transaction Code
  # 50 General Credit.
  # 53 Payroll.
  # 54 Pension.
  # 56 Dividend.
  # 57 Debenture Interest.
  # 13 General Debit.
  output += transaction_code.to_s

  # Amount to be credited or debited
  output += amount.to_i.abs.to_s.rjust(10, "0")

  # Title of Account
  # Full BECS character set valid
  output += .to_s.ljust(32, " ")

  # Lodgement Reference Produced on the recipient’s Account Statement.
  # Full BECS character set valid
  output += lodgement_reference.to_s.ljust(18, " ")

  # Trace BSB Number
  output += trace_bsb

  # Trace Account Number
  output += .to_s.rjust(9, " ")

  # Name of Remitter Produced on the recipient’s Account Statement
  # Full BECS character set valid
  output += name_of_remitter.to_s.ljust(16, " ")

  # Withholding amount in cents
  output += (witholding_amount || 0).abs.to_s.rjust(8, "0")
end