mirror of
https://github.com/internetee/registry.git
synced 2025-08-05 01:11:43 +02:00
Merge pull request #1821 from internetee/1819-improve-credit-account-balance-overview
Registrar / REPP: Preserve balance after billable action
This commit is contained in:
commit
98bbc52c71
6 changed files with 68 additions and 3 deletions
|
@ -4,8 +4,28 @@ module Repp
|
|||
def balance
|
||||
resp = { balance: current_user.registrar.cash_account.balance,
|
||||
currency: current_user.registrar.cash_account.currency }
|
||||
resp[:transactions] = activities if params[:detailed] == 'true'
|
||||
render_success(data: resp)
|
||||
end
|
||||
|
||||
def activities
|
||||
arr = []
|
||||
registrar_activities.each do |a|
|
||||
arr << { created_at: a.created_at, description: a.description,
|
||||
type: a.activity_type == 'add_credit' ? 'credit' : 'debit',
|
||||
sum: a.sum, balance: a.new_balance }
|
||||
end
|
||||
|
||||
arr
|
||||
end
|
||||
|
||||
def registrar_activities
|
||||
activities = current_user.registrar.cash_account.activities.order(created_at: :desc)
|
||||
activities = activities.where('created_at >= ?', params[:from]) if params[:from]
|
||||
activities = activities.where('created_at <= ?', params[:until]) if params[:until]
|
||||
|
||||
activities
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,6 +13,9 @@ class AccountActivity < ApplicationRecord
|
|||
def update_balance
|
||||
account.balance += sum
|
||||
account.save
|
||||
|
||||
self.new_balance = account.balance
|
||||
save
|
||||
end
|
||||
|
||||
class << self
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<table class="table table-hover table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="col-xs-5">
|
||||
<th class="col-xs-3">
|
||||
<%= sort_link(@q, 'description') %>
|
||||
</th>
|
||||
<th class="col-xs-2">
|
||||
|
@ -26,6 +26,9 @@
|
|||
<th class="col-xs-2">
|
||||
<%= sort_link(@q, 'sum') %>
|
||||
</th>
|
||||
<th class="col-xs-2">
|
||||
<%= sort_link(@q, 'new_balance', 'New balance') %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -45,6 +48,9 @@
|
|||
<td class="<%= c %>">
|
||||
<%= s %>
|
||||
</td>
|
||||
<td>
|
||||
<%= x.new_balance.present? ? "#{currency(x.new_balance)} EUR" : 'N/A' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue