foodsoft/app/controllers/finance/financial_links_controller.rb
2018-10-11 22:29:15 +02:00

36 lines
1.1 KiB
Ruby

class Finance::FinancialLinksController < Finance::BaseController
def show
@financial_link = FinancialLink.find(params[:id])
@items = @financial_link.bank_transactions.map do |bt|
{
date: bt.date,
type: t('activerecord.models.bank_transaction'),
description: bt.text,
amount: bt.amount,
link_to: finance_bank_transaction_path(bt)
}
end
@items += @financial_link.financial_transactions.map do |ft|
{
date: ft.created_on,
type: t('activerecord.models.financial_transaction'),
description: "#{ft.ordergroup.name}: #{ft.note}",
amount: ft.amount,
link_to: finance_ordergroup_transactions_path(ft.ordergroup)
}
end
@items += @financial_link.invoices.map do |invoice|
{
date: invoice.date || invoice.created_at,
type: t('activerecord.models.invoice'),
description: "#{invoice.supplier.name}: #{invoice.number}",
amount: invoice.amount,
link_to: finance_invoice_path(invoice)
}
end
@items.sort_by! { |item| item[:date] }
end
end