2012-11-10 16:44:05 +01:00
|
|
|
class Finance::OrdergroupsController < Finance::BaseController
|
2011-06-09 21:35:05 +02:00
|
|
|
def index
|
2023-05-12 13:01:12 +02:00
|
|
|
m = /^(?<col>name|sum_of_class_\d+)(?<reverse>_reverse)?$/.match params['sort']
|
2017-03-04 14:15:39 +01:00
|
|
|
if m
|
|
|
|
sort = m[:col]
|
|
|
|
sort += ' DESC' if m[:reverse]
|
2011-06-09 21:35:05 +02:00
|
|
|
else
|
2023-05-12 13:01:12 +02:00
|
|
|
sort = 'name'
|
2011-06-09 21:35:05 +02:00
|
|
|
end
|
|
|
|
|
2013-03-16 17:53:24 +01:00
|
|
|
@ordergroups = Ordergroup.undeleted.order(sort)
|
2017-03-04 14:15:39 +01:00
|
|
|
@ordergroups = @ordergroups.include_transaction_class_sum
|
|
|
|
@ordergroups = @ordergroups.where('groups.name LIKE ?', "%#{params[:query]}%") unless params[:query].nil?
|
2012-11-10 16:44:05 +01:00
|
|
|
@ordergroups = @ordergroups.page(params[:page]).per(@per_page)
|
2023-02-17 12:40:26 +01:00
|
|
|
|
|
|
|
@total_balances = FinancialTransactionClass.sorted.each_with_object({}) do |c, tmp|
|
2023-10-02 23:00:24 +02:00
|
|
|
tmp[c.id] = c.financial_transactions.reduce(0) { |sum, t| sum + (t.amount || 0) }
|
2023-02-17 12:40:26 +01:00
|
|
|
end
|
2011-06-09 21:35:05 +02:00
|
|
|
end
|
|
|
|
end
|