Class: FeideeUtils::Account
- Inherits:
-
Record
- Object
- Record
- FeideeUtils::Account
show all
- Defined in:
- lib/feidee_utils/account.rb
Defined Under Namespace
Classes: ModifiedAccount
Constant Summary
collapse
- 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
Instance Attribute Summary
Attributes inherited from Record
#field, #field_type
#child_classes
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Record
#initialize
#define_accessors
#collect_subclass, #generate_namespaced_record_classes
#all, #find, #find_by_id, #genereate_names
#last_update_time, #poid
Class Method Details
.validate_integrity_globally ⇒ Object
15
16
17
18
19
20
|
# File 'lib/feidee_utils/account.rb', line 15
def self.validate_integrity_globally
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
#account_group ⇒ Object
68
69
70
|
# File 'lib/feidee_utils/account.rb', line 68
def account_group
self.class.environment::AccountGroup.find_by_id(account_group_poid)
end
|
#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.
52
53
54
|
# File 'lib/feidee_utils/account.rb', line 52
def balance
to_bigdecimal(raw_balance) + credit - debit
end
|
#children ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/feidee_utils/account.rb', line 92
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(result.columns, result.types, raw_row)
end
end
arr
end
|
#credit ⇒ Object
56
57
58
|
# File 'lib/feidee_utils/account.rb', line 56
def credit
to_bigdecimal(raw_credit)
end
|
#debit ⇒ Object
60
61
62
|
# File 'lib/feidee_utils/account.rb', line 60
def debit
to_bigdecimal(raw_debit)
end
|
#flagged_as_parent? ⇒ Boolean
81
82
83
84
85
86
|
# File 'lib/feidee_utils/account.rb', line 81
def flagged_as_parent?
parent_poid == -1
end
|
#flat_parent_hierachy? ⇒ Boolean
88
89
90
|
# File 'lib/feidee_utils/account.rb', line 88
def flat_parent_hierachy?
!has_parent? or parent.flagged_as_parent?
end
|
#has_parent? ⇒ Boolean
77
78
79
|
# File 'lib/feidee_utils/account.rb', line 77
def has_parent?
parent_poid != 0 && !flagged_as_parent?
end
|
#hidden? ⇒ Boolean
64
65
66
|
# File 'lib/feidee_utils/account.rb', line 64
def hidden?
raw_hidden == 1
end
|
#parent ⇒ Object
73
74
75
|
# File 'lib/feidee_utils/account.rb', line 73
def parent
self.class.find_by_id(parent_poid)
end
|
#validate_integrity ⇒ Object
7
8
9
10
11
12
13
|
# File 'lib/feidee_utils/account.rb', line 7
def validate_integrity
raise "Account type should always be 0, but it's #{field["type"]}.\n" + inspect unless field["type"] == 0
raise "Account usedCount should always be 0, but it's #{field["usedCount"]}.\n" + inspect unless field["usedCount"] == 0
raise "Account uuid should always be empty, but it's #{field["uuid"]}.\n" + inspect unless field["uuid"].to_s.empty?
raise "Account hierachy contains more than 2 levels.\n" + inspect unless flat_parent_hierachy?
raise "Account hidden should be either 0 or 1, but it's #{raw_hidden}.\n" + inspect unless (raw_hidden == 1 or raw_hidden == 0)
end
|