Class: FeideeUtils::Account
- Inherits:
-
Record
- Object
- Record
- FeideeUtils::Account
show all
- Defined in:
- lib/feidee_utils/account.rb
Constant Summary
collapse
- NullPOID =
0
- FieldMappings =
{
name: "name",
raw_balance: "balance",
raw_credit: "amountOfCredit",
raw_debit: "amountOfLiability",
currency: "currencyType",
parent_poid: "parent",
memo: "memo",
ordered: "ordered",
account_group_poid: "accountGroupPOID",
raw_hidden: "hidden",
}.freeze
- IgnoredFields =
[
"tradingEntityPOID", "type", "usedCount", "uuid", "code", "clientID", ].freeze
Record::Utils::AssumedTimezone
Instance Attribute Summary
#child_classes
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Record
generate_subclasses, #initialize
#computed
#all, #column_names, #columns, #find, #find_by_id
#last_update_time, #poid
Class Method Details
.validate_global_integrity ⇒ Object
32
33
34
35
36
37
|
# File 'lib/feidee_utils/account.rb', line 32
def self.validate_global_integrity
if self.find_by_id(-1) != nil
raise "-1 is used as the parent POID placeholder of a parent account." +
" Account of POID -1 should not exist."
end
end
|
Instance Method Details
#balance ⇒ Object
NOTE: balance is not set for credit cards etc. Instead credit/debit are used. Guess: The special behavior is be controlled by account_group_poid. Again, the code can work in all cases, thus no check is done.
72
73
74
|
# File 'lib/feidee_utils/account.rb', line 72
def balance
to_bigdecimal(raw_balance) + credit - debit
end
|
#children ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/feidee_utils/account.rb', line 108
def children
arr = []
self.class.database.query(
"SELECT * FROM #{self.class.table_name} WHERE parent = ?", poid
) do |result|
result.each do |raw_row|
arr << self.class.new(raw_row)
end
end
arr
end
|
#credit ⇒ Object
76
77
78
|
# File 'lib/feidee_utils/account.rb', line 76
def credit
to_bigdecimal(raw_credit)
end
|
#debit ⇒ Object
80
81
82
|
# File 'lib/feidee_utils/account.rb', line 80
def debit
to_bigdecimal(raw_debit)
end
|
#flagged_as_parent? ⇒ Boolean
97
98
99
100
101
102
|
# File 'lib/feidee_utils/account.rb', line 97
def flagged_as_parent?
parent_poid == -1
end
|
#flat_parent_hierachy? ⇒ Boolean
104
105
106
|
# File 'lib/feidee_utils/account.rb', line 104
def flat_parent_hierachy?
!has_parent? or parent.flagged_as_parent?
end
|
#has_parent? ⇒ Boolean
93
94
95
|
# File 'lib/feidee_utils/account.rb', line 93
def has_parent?
parent_poid != NullPOID && !flagged_as_parent?
end
|
#hidden? ⇒ Boolean
84
85
86
|
# File 'lib/feidee_utils/account.rb', line 84
def hidden?
raw_hidden == 1
end
|
#parent ⇒ Object
89
90
91
|
# File 'lib/feidee_utils/account.rb', line 89
def parent
self.class.find_by_id(parent_poid)
end
|
#to_s ⇒ Object
120
121
122
|
# File 'lib/feidee_utils/account.rb', line 120
def to_s
"#{name} (Account/#{poid})"
end
|
#validate_integrity ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/feidee_utils/account.rb', line 7
def validate_integrity
unless not column("type") or column("type") == 0
raise "Account type should always be 0, but it's #{column("type")}.\n" +
inspect
end
unless column("usedCount") == 0
raise "Account usedCount should always be 0," +
" but it's #{column("usedCount")}.\n"+
inspect
end
unless column("uuid").to_s.empty?
raise "Account uuid should always be empty,"+
" but it's #{column("uuid")}.\n" +
inspect
end
unless flat_parent_hierachy?
raise "Account hierachy contains more than 2 levels.\n" + inspect
end
unless (raw_hidden == 1 or raw_hidden == 0)
raise "Account hidden should be either 0 or 1," +
" but it's #{raw_hidden}.\n" +
inspect
end
end
|