feat(finance): show sum of ordergroup balances
This commit is contained in:
parent
e6e2cdc2c6
commit
69c80eba3e
3 changed files with 63 additions and 1 deletions
|
|
@ -11,7 +11,10 @@ class Finance::OrdergroupsController < Finance::BaseController
|
|||
@ordergroups = Ordergroup.undeleted.order(sort)
|
||||
@ordergroups = @ordergroups.include_transaction_class_sum
|
||||
@ordergroups = @ordergroups.where('groups.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil?
|
||||
|
||||
@ordergroups = @ordergroups.page(params[:page]).per(@per_page)
|
||||
|
||||
@total_balances = FinancialTransactionClass.sorted.each_with_object({}) do |c, tmp|
|
||||
tmp[c.id] = c.financial_transactions.reduce(0) { | sum, t | sum + t.amount }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -22,3 +22,12 @@
|
|||
%td
|
||||
= link_to t('.new_transaction'), new_finance_ordergroup_transaction_path(ordergroup), class: 'btn btn-mini'
|
||||
= link_to t('.account_statement'), finance_ordergroup_transactions_path(ordergroup), class: 'btn btn-mini'
|
||||
%thead
|
||||
%tr
|
||||
%th= t 'Total'
|
||||
%th
|
||||
- FinancialTransactionClass.sorted.each do |c|
|
||||
- name = FinancialTransactionClass.has_multiple_classes ? c.display : heading_helper(Ordergroup, :account_balance)
|
||||
%th.numeric= format_currency @total_balances[c.id]
|
||||
%th.numeric
|
||||
= format_currency @total_balances.values.reduce(:+)
|
||||
Loading…
Add table
Add a link
Reference in a new issue