Class: Appydave::Tools::BankReconciliation::Models::Transaction
- Inherits:
-
Object
- Object
- Appydave::Tools::BankReconciliation::Models::Transaction
- Defined in:
- lib/appydave/tools/bank_reconciliation/models/transaction.rb
Overview
Unified transaction model for raw and reconciled data
Instance Attribute Summary collapse
-
#account_name ⇒ Object
Returns the value of attribute account_name.
-
#account_number ⇒ Object
Returns the value of attribute account_number.
-
#balance ⇒ Object
Returns the value of attribute balance.
-
#bsb_number ⇒ Object
Returns the value of attribute bsb_number.
-
#cheque_number ⇒ Object
Returns the value of attribute cheque_number.
-
#coa_code ⇒ Object
Returns the value of attribute coa_code.
-
#coa_match_type ⇒ Object
Returns the value of attribute coa_match_type.
-
#credit ⇒ Object
Returns the value of attribute credit.
-
#debit ⇒ Object
Returns the value of attribute debit.
-
#fin_year ⇒ Object
Returns the value of attribute fin_year.
-
#narration ⇒ Object
Returns the value of attribute narration.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#source_files ⇒ Object
Returns the value of attribute source_files.
-
#transaction_date ⇒ Object
Returns the value of attribute transaction_date.
-
#transaction_type ⇒ Object
Returns the value of attribute transaction_type.
Class Method Summary collapse
Instance Method Summary collapse
- #add_source_file(source_file) ⇒ Object
- #clean_amount(amount) ⇒ Object
-
#initialize(bsb_number: nil, account_number: nil, transaction_date: nil, narration: nil, cheque_number: nil, debit: nil, credit: nil, balance: nil, transaction_type: nil, platform: nil, coa_code: nil, coa_match_type: nil, account_name: nil) ⇒ Transaction
constructor
A new instance of Transaction.
-
#swap_plus_minus_for_transactions ⇒ Object
Returns true if this transaction’s amount should have its sign flipped based on the per-account, per-FY, per-COA rules stored in config.
- #to_csv_row ⇒ Object
Constructor Details
#initialize(bsb_number: nil, account_number: nil, transaction_date: nil, narration: nil, cheque_number: nil, debit: nil, credit: nil, balance: nil, transaction_type: nil, platform: nil, coa_code: nil, coa_match_type: nil, account_name: nil) ⇒ Transaction
Returns a new instance of Transaction.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 25 def initialize(bsb_number: nil, account_number: nil, transaction_date: nil, narration: nil, cheque_number: nil, debit: nil, credit: nil, balance: nil, transaction_type: nil, platform: nil, coa_code: nil, coa_match_type: nil, account_name: nil) account_number = account_number&.strip @bsb_number = bsb_number&.strip @account_number = account_number @transaction_date = parse_date(transaction_date) @narration = narration&.gsub(/\s{2,}/, ' ')&.strip @cheque_number = cheque_number&.strip @debit = debit # clean_amount(debit, account_number, coa_code) @credit = credit # clean_amount(credit, account_number, coa_code) @balance = balance&.strip @transaction_type = transaction_type&.strip @platform = platform @coa_code = coa_code @coa_match_type = coa_match_type @account_name = account_name @source_files = [] @fin_year = determine_fin_year(@transaction_date) end |
Instance Attribute Details
#account_name ⇒ Object
Returns the value of attribute account_name.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def account_name @account_name end |
#account_number ⇒ Object
Returns the value of attribute account_number.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def account_number @account_number end |
#balance ⇒ Object
Returns the value of attribute balance.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def balance @balance end |
#bsb_number ⇒ Object
Returns the value of attribute bsb_number.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def bsb_number @bsb_number end |
#cheque_number ⇒ Object
Returns the value of attribute cheque_number.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def cheque_number @cheque_number end |
#coa_code ⇒ Object
Returns the value of attribute coa_code.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def coa_code @coa_code end |
#coa_match_type ⇒ Object
Returns the value of attribute coa_match_type.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def coa_match_type @coa_match_type end |
#credit ⇒ Object
Returns the value of attribute credit.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def credit @credit end |
#debit ⇒ Object
Returns the value of attribute debit.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def debit @debit end |
#fin_year ⇒ Object
Returns the value of attribute fin_year.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def fin_year @fin_year end |
#narration ⇒ Object
Returns the value of attribute narration.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def narration @narration end |
#platform ⇒ Object
Returns the value of attribute platform.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def platform @platform end |
#source_files ⇒ Object
Returns the value of attribute source_files.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def source_files @source_files end |
#transaction_date ⇒ Object
Returns the value of attribute transaction_date.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def transaction_date @transaction_date end |
#transaction_type ⇒ Object
Returns the value of attribute transaction_type.
9 10 11 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 9 def transaction_type @transaction_type end |
Class Method Details
.csv_headers ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 60 def self.csv_headers %i[ platform account_name bsb_number account_number transaction_date narration debit credit balance transaction_type coa_code coa_match_type source_files fin_year ] end |
Instance Method Details
#add_source_file(source_file) ⇒ Object
56 57 58 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 56 def add_source_file(source_file) @source_files << source_file.strip unless @source_files.include?(source_file.strip) end |
#clean_amount(amount) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 98 def clean_amount(amount) return nil if amount.nil? || amount.strip.empty? cleaned_amount = amount.to_f.round(2) if swap_plus_minus_for_transactions if cleaned_amount.negative? cleaned_amount = cleaned_amount.abs # else # cleaned_amount *= -1 end puts "Fixed negative amount for account: #{account_number} and COA: #{coa_code}, original amount: #{amount}, fixed amount: #{cleaned_amount}" if coa_code == 'DANCE' end cleaned_amount end |
#swap_plus_minus_for_transactions ⇒ Object
Returns true if this transaction’s amount should have its sign flipped based on the per-account, per-FY, per-COA rules stored in config.
Rules live in ~/.config/appydave/bank-reconciliation.json under ‘sign_flip_rules` — see BankReconciliationConfig::SignFlipRule. Personal account numbers MUST NOT be hardcoded here; the config file is local-only and never committed to the repo.
121 122 123 124 125 126 127 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 121 def swap_plus_minus_for_transactions sign_flip_rules.any? do |rule| (rule.fin_year.nil? || rule.fin_year == fin_year) && rule.account_number == account_number && rule.coa_codes.include?(coa_code) end end |
#to_csv_row ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/appydave/tools/bank_reconciliation/models/transaction.rb', line 79 def to_csv_row [ @platform, @account_name, @bsb_number, @account_number, @transaction_date, @narration, @debit ? format('%.2f', @debit) : '', @credit ? format('%.2f', @credit) : '', @balance, @transaction_type, @coa_code, @coa_match_type, @source_files.join('; '), @fin_year ] end |