Sha256: 2da620f49b65c2987bdbf2c7f9866b50e8c8c6506d43afe15cc21cd97098ab57
Contents?: true
Size: 1.14 KB
Versions: 1
Compression:
Stored size: 1.14 KB
Contents
module Pacioli class Account < ActiveRecord::Base has_many :transactions, foreign_key: :pacioli_account_id def asset? false end def liability? false end def equity? false end def income? false end def expense? false end def debits transactions.where(type: 'Pacioli::Debit') end def credits transactions.where(type: 'Pacioli::Credit') end def balanced? debits.sum(&:amount) == credits.sum(&:amount) end def balance debits.sum(&:amount) - credits.sum(&:amount) end 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 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 def self.for(name) where(name: name).includes(transactions: [:journal_entry]) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pacioli-0.0.29 | lib/pacioli/account.rb |