Add FinancialLinks

For now this is only usefull for plugins, since there is no UI.
This commit is contained in:
Patrick Gansterer 2017-10-13 14:36:56 +02:00
parent 75deec9f06
commit 53bb096046
12 changed files with 95 additions and 7 deletions

View file

@ -0,0 +1,27 @@
class Finance::FinancialLinksController < Finance::BaseController
def show
@financial_link = FinancialLink.find(params[:id])
@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

View file

@ -0,0 +1,4 @@
class FinancialLink < ActiveRecord::Base
has_many :financial_transactions
has_many :invoices
end

View file

@ -3,6 +3,7 @@
class FinancialTransaction < ActiveRecord::Base
belongs_to :ordergroup
belongs_to :user
belongs_to :financial_link
validates_presence_of :amount, :note, :user_id, :ordergroup_id
validates_numericality_of :amount, greater_then: -100_000,

View file

@ -3,6 +3,7 @@ class Invoice < ActiveRecord::Base
belongs_to :supplier
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
belongs_to :financial_link
has_many :deliveries
has_many :orders

View file

@ -0,0 +1,23 @@
- title t('.title', number: @financial_link.id)
%table.table.table-striped
%thead
%tr
%th= t '.date'
%th= t '.type'
%th= t '.description'
%th= t '.amount'
%tbody
- @items.each do |item|
%tr
%td
- if item[:link_to]
= link_to format_date(item[:date]), item[:link_to]
- else
= format_date item[:date]
%td= item[:type]
%td= item[:description]
%td.currency{:style => "color:#{item[:amount] < 0 ? 'red' : 'black'}; width:5em"}= number_to_currency(item[:amount])
%p
= @financial_link.note

View file

@ -21,7 +21,11 @@
%tbody
- @financial_transactions.each do |t|
%tr
%td= format_time(t.created_on)
%td
- if t.financial_link
= link_to format_time(t.created_on), finance_link_path(t.financial_link)
- else
= format_time(t.created_on)
- if with_ordergroup
%td= h link_to t.ordergroup.name, finance_ordergroup_transactions_path(t.ordergroup)
%td= h show_user(t.user)

View file

@ -65,6 +65,10 @@
%p
%b= heading_helper(Invoice, :note) + ':'
=h @invoice.note
- if @invoice.financial_link
%p
%b= heading_helper(Invoice, :financial_link) + ':'
= link_to t('ui.show'), finance_link_path(@invoice.financial_link)
- if @invoice.user_can_edit?(current_user)
= link_to t('ui.edit'), edit_finance_invoice_path(@invoice), class: 'btn'