How to calculate yearly expense and revenue

229 views
Skip to first unread message

Prashanta Mahato

unread,
Aug 14, 2013, 6:33:52 AM8/14/13
to plutu...@googlegroups.com
 For preparing companies Trading and profit and loss account how should i calculate yearly expense and revenue. and yearly opening and closing balance.
 How should i get account balance depending on transaction date. 

mbulat

unread,
Aug 14, 2013, 11:37:07 AM8/14/13
to plutu...@googlegroups.com
Hi Prashanta, 

This is a feature that is on the list of things to add to Plutus. At the moment, it needs to be done manually by querying the records. Here's an example of a method to obtain a balance of a certain revenue account for a specific time period. It makes use of the ActiveRecord Query Interface which you can read more about here: http://guides.rubyonrails.org/active_record_querying.html  You should be able to do all your reporting with similar types of queries.

First what account are we balancing

revenue_account = Plutus::Revenue.find_by_name("Widget Sales")

Next we need to get all the transactions for the period we are reporting. We only need the IDs, so i'm specifying :id in the select (assumes a start_date and end_date)

period_transactions = Plutus::Transaction.where('created_at >= ?', start_date).where('created_at < ?', end_date).select(:id)


Next we'll find all of the amounts for that account and period (this performs a basic SQL "IN" query with the array of transaction ids)

# map the ids to a string for the next sql query
transaction_id_string
= period_transactions.map {|t| t.id}.join(', ')

period_amounts
= Plutus::Amount.where(:account_id => revenue_account.id).where("transaction_id IN (#{transaction_id_string})")


You can then loop through all the amount records to add up the balance for that account, something like this:

balance = BigDecimal.new('0')

period_amounts
.each do |amount_record|
 
if amount_record.type == "Plutus::DebitAmount"
    balance
-= amount_record.amount
 
else
    balance
+= amount_record.amount
 
end
end


You'll need to switch the +/- depending on the account type standard balance.

-- Mike

Don Wildman

unread,
Jan 9, 2019, 5:18:08 AM1/9/19
to plutus-gem
Has this been implemented yet?
It's a vital function and to be honest this approach breaks the other features of the Gem!
In the income statement for instance, the number of transactions will still show the total number of transactions, not the number of filtered transactions... 

Von Christian Halip

unread,
Jan 10, 2019, 7:48:20 AM1/10/19
to plutus-gem


You can try calling Plutus::Revenue.balance(from_date: params[:from_date], to_date: params[:to_date)) - Plutus::Expense.balance(from_date: params[:from_date], to_date: params[:to_date)) . to get the profit

Don Wildman

unread,
Jan 10, 2019, 12:15:06 PM1/10/19
to plutu...@googlegroups.com
Thanks, that's what I'm doing, but it feels hacky as I need to make many fixes to change the behaviour of the totals etc in the reports - it just feels like a workaround and not a solution...


On Thu, 10 Jan 2019, 2:48 PM Von Christian Halip, <vc.h...@gmail.com> wrote:


You can try calling Plutus::Revenue.balance(from_date: params[:from_date], to_date: params[:to_date)) - Plutus::Expense.balance(from_date: params[:from_date], to_date: params[:to_date)) . to get the profit

--
You received this message because you are subscribed to the Google Groups "plutus-gem" group.
To unsubscribe from this group and stop receiving emails from it, send an email to plutus-gem+...@googlegroups.com.
To post to this group, send email to plutu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/plutus-gem/8fed6fe6-d3f2-41bb-9fd8-dc4fcbeadd7e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Von Christian Halip

unread,
Jan 11, 2019, 12:44:28 AM1/11/19
to plutu...@googlegroups.com
Can you post a gist of your code we can look into?

You received this message because you are subscribed to a topic in the Google Groups "plutus-gem" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/plutus-gem/i3tlfwpwz0A/unsubscribe.
To unsubscribe from this group and all its topics, send an email to plutus-gem+...@googlegroups.com.

To post to this group, send email to plutu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages