Class: DoubleDouble::Transaction
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- DoubleDouble::Transaction
- Defined in:
- lib/double_double/transaction.rb
Overview
Transactions are the recording of debits and credits to various accounts. This table can be thought of as a traditional accounting Journal.
Posting to a Ledger can be considered to happen automatically, since Accounts have the reverse ‘has_many’ relationship to either it’s credit or debit transactions
Class Method Summary collapse
-
.build(args) ⇒ DoubleDouble::Transaction
Simple API for building a transaction and associated debit and credit amounts.
- .create!(args) ⇒ Object
Instance Method Summary collapse
Class Method Details
.build(args) ⇒ DoubleDouble::Transaction
Simple API for building a transaction and associated debit and credit amounts
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/double_double/transaction.rb', line 56 def self.build args args.merge!({credits: args[:debits], debits: args[:credits]}) if args[:reversed] t = Transaction.new() t.description = args[:description] t.transaction_type = args[:transaction_type] if args.has_key? :transaction_type t.initiator = args[:initiator] if args.has_key? :initiator add_amounts_to_transaction(args[:debits], t, true) add_amounts_to_transaction(args[:credits], t, false) t end |
.create!(args) ⇒ Object
67 68 69 70 |
# File 'lib/double_double/transaction.rb', line 67 def self.create! args t = build args t.save! end |
Instance Method Details
#transaction_type ⇒ Object
72 73 74 |
# File 'lib/double_double/transaction.rb', line 72 def transaction_type self.transaction_type_id.nil? ? UnassignedTransactionType : TransactionType.find(self.transaction_type_id) end |