Class: Xeroizer::Record::BankTransaction

Inherits:
Base
  • Object
show all
Defined in:
lib/xeroizer/models/bank_transaction.rb

Constant Summary collapse

BANK_TRANSACTION_STATUS =
{
  'ACTIVE'  =>          'Active bank transactions',
  'DELETED' =>          'Deleted bank transactions',
}
BANK_TRANSACTION_STATUSES =
BANK_TRANSACTION_STATUS.keys.sort
BANK_TRANSFER_TYPES =
[ 'SPEND-TRANSFER', 'RECEIVE-TRANSFER' ]

Instance Attribute Summary

Attributes inherited from Base

#attributes, #complete_record_downloaded, #errors, #model, #parent

Instance Method Summary collapse

Methods inherited from Base

#[], #[]=, #as_json, build, #complete_record_downloaded?, #download_complete_record!, #inspect, #new_model_class, #new_record?, #non_calculated_attributes, #save, #saved!, #to_h, #to_json, #update_attributes

Methods included from XmlHelper

included

Methods included from ValidationHelper

included

Methods included from RecordAssociationHelper

included

Methods included from ModelDefinitionHelper

included

Methods included from ClassLevelInheritableAttributes

included

Constructor Details

#initialize(parent) ⇒ BankTransaction

Returns a new instance of BankTransaction.



20
21
22
23
# File 'lib/xeroizer/models/bank_transaction.rb', line 20

def initialize(parent)
  super parent
  self.line_amount_types = "Exclusive"
end

Instance Method Details

#currency_rateObject



66
67
68
69
70
71
72
# File 'lib/xeroizer/models/bank_transaction.rb', line 66

def currency_rate
  if attributes[:currency_rate]
    BigDecimal.new(attributes[:currency_rate])
  else
    BigDecimal.new('1.0')
  end
end

#is_transfer?Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/xeroizer/models/bank_transaction.rb', line 100

def is_transfer?
  BANK_TRANSFER_TYPES.include? attributes[:type]
end

#sub_totalObject



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/xeroizer/models/bank_transaction.rb', line 80

def sub_total
  return attributes[:total] if is_transfer?

  if ought_to_recalculate_totals?
    result = LineItemSum.sub_total(self.line_items)
    result -= total_tax if line_amount_types == 'Inclusive'
    result
  else
    attributes[:sub_total]
  end
end

#sub_total=(value) ⇒ Object



74
# File 'lib/xeroizer/models/bank_transaction.rb', line 74

def sub_total=(value); raise SettingTotalDirectlyNotSupported.new(:sub_total); end

#totalObject



78
# File 'lib/xeroizer/models/bank_transaction.rb', line 78

def total; sub_total + total_tax; end

#total=(value) ⇒ Object



76
# File 'lib/xeroizer/models/bank_transaction.rb', line 76

def total=(value);     raise SettingTotalDirectlyNotSupported.new(:total);     end

#total_taxObject



92
93
94
95
96
97
98
# File 'lib/xeroizer/models/bank_transaction.rb', line 92

def total_tax
  return BigDecimal.new('0') if is_transfer?

  return ought_to_recalculate_totals? ?
    LineItemSum.total_tax(self.line_items) :
    attributes[:total_tax]
end

#total_tax=(value) ⇒ Object



75
# File 'lib/xeroizer/models/bank_transaction.rb', line 75

def total_tax=(value); raise SettingTotalDirectlyNotSupported.new(:total_tax); end