mirror of
https://github.com/internetee/registry.git
synced 2025-06-10 14:44:47 +02:00
Add detailed balance to REPP
This commit is contained in:
parent
9a7acf7c33
commit
416390a3c4
1 changed files with 28 additions and 0 deletions
|
@ -2,10 +2,38 @@ module Repp
|
|||
module V1
|
||||
class AccountsController < BaseController
|
||||
def balance
|
||||
return activity if params[:detailed] == 'true'
|
||||
|
||||
resp = { balance: current_user.registrar.cash_account.balance,
|
||||
currency: current_user.registrar.cash_account.currency }
|
||||
render_success(data: resp)
|
||||
end
|
||||
|
||||
def activity
|
||||
resp = { balance: current_user.registrar.cash_account.balance,
|
||||
currency: current_user.registrar.cash_account.currency }
|
||||
resp[:activities] = activities
|
||||
render_success(data: resp)
|
||||
end
|
||||
|
||||
def activities
|
||||
bal = current_user.registrar.cash_account.balance
|
||||
act = []
|
||||
activities = current_user.registrar.cash_account.activities.order(created_at: :desc)
|
||||
activities.each do |a|
|
||||
act << {
|
||||
created_at: a.created_at,
|
||||
description: a.description,
|
||||
type: a.activity_type == 'add_credit' ? 'credit' : 'debit',
|
||||
sum: a.sum,
|
||||
balance: bal,
|
||||
}
|
||||
|
||||
bal = a.activity_type == 'add_credit' ? bal = bal + a.sum : bal - a.sum
|
||||
end
|
||||
|
||||
act
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue