Class: Account
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Account
show all
- Defined in:
- lib/bookkeeper/account.rb,
lib/immutable-attribute-plugin/test/rails_root/app/models/account.rb
Defined Under Namespace
Classes: Asset, Expense, Liability, Revenue
Class Method Summary
collapse
Instance Method Summary
collapse
Class Method Details
.accounts_payable ⇒ Object
60
|
# File 'lib/bookkeeper/account.rb', line 60
def accounts_payable; roots.find_by_name('Accounts Payable'); end
|
.accounts_receivable ⇒ Object
61
|
# File 'lib/bookkeeper/account.rb', line 61
def accounts_receivable; roots.find_by_name('Accounts Receivable'); end
|
Instance Method Details
#account_type ⇒ Object
31
32
33
|
# File 'lib/bookkeeper/account.rb', line 31
def account_type
self.class::ACCOUNT_TYPE
end
|
#balance ⇒ Object
44
45
46
47
48
49
|
# File 'lib/bookkeeper/account.rb', line 44
def balance
postings.inject(0) { |balance, p|
amount_from_account_perspective = [:asset,:expense].include?(account_type) ? -p.amount : p.amount
balance + amount_from_account_perspective
}
end
|
#credit(amount, options = {}) ⇒ Object
16
17
18
|
# File 'lib/bookkeeper/account.rb', line 16
def credit(amount, options = {})
new_posting(:credit, amount, options)
end
|
#debit(amount, options = {}) ⇒ Object
12
13
14
|
# File 'lib/bookkeeper/account.rb', line 12
def debit(amount, options = {})
new_posting(:debit, amount, options)
end
|
#deposit(transaction) ⇒ Object
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/bookkeeper/account.rb', line 20
def deposit(transaction)
gross = transaction.notification.amount.cents.to_f / 100
journal = Journal::Deposit.new(:transactable => transaction)
journal.postings |= transaction.to_postings
journal.postings << self.credit(gross)
journal.save!
end
|
#destroy ⇒ Object
55
56
57
|
# File 'lib/bookkeeper/account.rb', line 55
def destroy
raise ActiveRecord::IndestructibleRecord
end
|
#is_subaccount ⇒ Object
51
52
53
|
# File 'lib/bookkeeper/account.rb', line 51
def is_subaccount
self != self.root
end
|
#name ⇒ Object
35
36
37
|
# File 'lib/bookkeeper/account.rb', line 35
def name
accountable_has_own_name ? accountable.name : self[:name]
end
|
#postings_with_recursion ⇒ Object
39
40
41
|
# File 'lib/bookkeeper/account.rb', line 39
def postings_with_recursion
(self_and_all_children.collect { |account| account.postings_without_recursion }).flatten
end
|