Class: Pacioli::Account

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/pacioli/account.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.for(name) ⇒ Object



51
52
53
# File 'lib/pacioli/account.rb', line 51

def self.for(name)
  where(name: name).includes(transactions: [:journal_entry])
end

Instance Method Details

#asset?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/pacioli/account.rb', line 5

def asset?
  false
end

#balanceObject



37
38
39
# File 'lib/pacioli/account.rb', line 37

def balance
  debits.sum(&:amount) - credits.sum(&:amount)
end

#balanced?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/pacioli/account.rb', line 33

def balanced?
  debits.sum(&:amount) == credits.sum(&:amount)
end

#credited_with_source_document?(source) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
44
# File 'lib/pacioli/account.rb', line 41

def credited_with_source_document?(source)
  # has this account recorded a credit entry for the source document
  self.transactions.select(&:credit?).map(&:journal_entry).select {|je| je.source == source}.any?
end

#creditsObject



29
30
31
# File 'lib/pacioli/account.rb', line 29

def credits
  transactions.where(type: 'Pacioli::Credit')
end

#debited_with_source_document?(source) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
# File 'lib/pacioli/account.rb', line 46

def debited_with_source_document?(source)
  # has this account recorded a debit entry for the source document
  self.transactions.select(&:debit?).map(&:journal_entry).select {|je| je.source == source}.any?
end

#debitsObject



25
26
27
# File 'lib/pacioli/account.rb', line 25

def debits
  transactions.where(type: 'Pacioli::Debit')
end

#equity?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/pacioli/account.rb', line 13

def equity?
  false
end

#expense?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/pacioli/account.rb', line 21

def expense?
  false
end

#income?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/pacioli/account.rb', line 17

def income?
  false
end

#liability?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/pacioli/account.rb', line 9

def liability?
  false
end