Putting a date in a transaction

106 views
Skip to first unread message

Daniel Loureiro

unread,
Feb 11, 2014, 1:52:40 AM2/11/14
to plutu...@googlegroups.com
Is there a way to put a date in a transaction?

Ex.
transaction = Plutus::Transaction.build(
               
:description => "Sold some widgets",
               
:date => '2014-04-01',
               
:debits => [
                 
{:account => "Accounts Receivable", :amount => 50],
               
:credits => [
                 
{:account => "Sales Revenue", :amount => 40},
                 
{:account => "Sales Tax Payable", :amount => 10}])
transaction
.save

And to get a balance by some date?
>> cash = Plutus::Asset.find_by_name("Cash", "2014-04-30")
>> cash.balance
=> #<BigDecimal:103259bb8,'0.2E4',4(12)>

mbulat

unread,
Feb 11, 2014, 4:14:48 PM2/11/14
to plutu...@googlegroups.com
Yes.. every transaction has a timestamp (created_at field). 

Getting the balance is not pretty at the moment but can be accomplished as follows:

First specify your date range: 

time_range = (Time.now.midnight - 30.days)..Time.now.midnight

Get the debit and credit balances via query:

Plutus::Asset.joins(:debit_transactions).where(:name => "Cash", :plutus_transactions => {:created_at => time_range}).sum(:amount)

Plutus::Asset.joins(:credit_transactions).where(:name => "Cash", :plutus_transactions => {:created_at => time_range}).sum(:amount)
Reply all
Reply to author
Forward
0 new messages