2021-02-18 20:05:17 +01:00
|
|
|
class Api::V1::User::OrdergroupController < Api::V1::BaseController
|
2021-03-01 15:27:26 +01:00
|
|
|
before_action -> { doorkeeper_authorize! 'finance:user' }, only: [:financial_overview]
|
2021-02-18 20:05:17 +01:00
|
|
|
|
|
|
|
def financial_overview
|
|
|
|
ordergroup = Ordergroup.include_transaction_class_sum.find(current_ordergroup.id)
|
|
|
|
|
|
|
|
render json: {
|
|
|
|
financial_overview: {
|
|
|
|
account_balance: ordergroup.account_balance.to_f,
|
|
|
|
available_funds: ordergroup.get_available_funds.to_f,
|
2023-05-12 13:01:12 +02:00
|
|
|
financial_transaction_class_sums: FinancialTransactionClass.sorted.map do |c|
|
2021-02-18 20:05:17 +01:00
|
|
|
{
|
|
|
|
id: c.id,
|
|
|
|
name: c.display,
|
|
|
|
amount: ordergroup["sum_of_class_#{c.id}"].to_f
|
|
|
|
}
|
2023-05-12 13:01:12 +02:00
|
|
|
end
|
2021-02-18 20:05:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|