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 class FinancialTransaction < ActiveRecord::Base
belongs_to :ordergroup belongs_to :ordergroup
belongs_to :user belongs_to :user
belongs_to :financial_link
validates_presence_of :amount, :note, :user_id, :ordergroup_id validates_presence_of :amount, :note, :user_id, :ordergroup_id
validates_numericality_of :amount, greater_then: -100_000, validates_numericality_of :amount, greater_then: -100_000,

View file

@ -3,6 +3,7 @@ class Invoice < ActiveRecord::Base
belongs_to :supplier belongs_to :supplier
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id' belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
belongs_to :financial_link
has_many :deliveries has_many :deliveries
has_many :orders 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 %tbody
- @financial_transactions.each do |t| - @financial_transactions.each do |t|
%tr %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 - if with_ordergroup
%td= h link_to t.ordergroup.name, finance_ordergroup_transactions_path(t.ordergroup) %td= h link_to t.ordergroup.name, finance_ordergroup_transactions_path(t.ordergroup)
%td= h show_user(t.user) %td= h show_user(t.user)

View file

@ -65,6 +65,10 @@
%p %p
%b= heading_helper(Invoice, :note) + ':' %b= heading_helper(Invoice, :note) + ':'
=h @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) - if @invoice.user_can_edit?(current_user)
= link_to t('ui.edit'), edit_finance_invoice_path(@invoice), class: 'btn' = link_to t('ui.edit'), edit_finance_invoice_path(@invoice), class: 'btn'

View file

@ -894,6 +894,9 @@ de:
without_extra_charge: 'ohne Aufschlag:' without_extra_charge: 'ohne Aufschlag:'
create: create:
notice: Rechnung wurde erstellt. notice: Rechnung wurde erstellt.
financial_links:
show:
title: Finanzlink %{number}
financial_transactions: financial_transactions:
controller: controller:
create: create:

View file

@ -896,6 +896,9 @@ en:
without_extra_charge: 'without extra charge:' without_extra_charge: 'without extra charge:'
create: create:
notice: Invoice was created. notice: Invoice was created.
financial_links:
show:
title: Financial link %{number}
financial_transactions: financial_transactions:
controller: controller:
create: create:

View file

@ -163,6 +163,8 @@ Foodsoft::Application.routes.draw do
get :unpaid, on: :collection get :unpaid, on: :collection
end end
resources :links, controller: 'financial_links', only: [:show]
resources :ordergroups, only: [:index] do resources :ordergroups, only: [:index] do
resources :financial_transactions, as: :transactions resources :financial_transactions, as: :transactions
end end

View file

@ -0,0 +1,10 @@
class CreateFinancialLinks < ActiveRecord::Migration
def change
create_table :financial_links do |t|
t.text :note
end
add_column :financial_transactions, :financial_link_id, :integer, index: true
add_column :invoices, :financial_link_id, :integer, index: true
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20171001020000) do ActiveRecord::Schema.define(version: 20171002000000) do
create_table "article_categories", force: :cascade do |t| create_table "article_categories", force: :cascade do |t|
t.string "name", limit: 255, default: "", null: false t.string "name", limit: 255, default: "", null: false
@ -85,12 +85,17 @@ ActiveRecord::Schema.define(version: 20171001020000) do
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "financial_link", force: :cascade do |t|
t.text "note"
end
create_table "financial_transactions", force: :cascade do |t| create_table "financial_transactions", force: :cascade do |t|
t.integer "ordergroup_id", limit: 4, default: 0, null: false t.integer "ordergroup_id", limit: 4, default: 0, null: false
t.decimal "amount", precision: 8, scale: 2, default: 0, null: false t.decimal "amount", precision: 8, scale: 2, default: 0, null: false
t.text "note", limit: 65535, null: false t.text "note", limit: 65535, null: false
t.integer "user_id", limit: 4, default: 0, null: false t.integer "user_id", limit: 4, default: 0, null: false
t.datetime "created_on", null: false t.datetime "created_on", null: false
t.integer "financial_link_id"
end end
add_index "financial_transactions", ["ordergroup_id"], name: "index_financial_transactions_on_ordergroup_id", using: :btree add_index "financial_transactions", ["ordergroup_id"], name: "index_financial_transactions_on_ordergroup_id", using: :btree
@ -180,6 +185,7 @@ ActiveRecord::Schema.define(version: 20171001020000) do
t.integer "created_by_user_id" t.integer "created_by_user_id"
t.string "attachment_mime" t.string "attachment_mime"
t.binary "attachment_data" t.binary "attachment_data"
t.integer "financial_link_id"
end end
add_index "invoices", ["supplier_id"], name: "index_invoices_on_supplier_id", using: :btree add_index "invoices", ["supplier_id"], name: "index_invoices_on_supplier_id", using: :btree