Add FinancialLinks
For now this is only usefull for plugins, since there is no UI.
This commit is contained in:
parent
75deec9f06
commit
53bb096046
12 changed files with 95 additions and 7 deletions
27
app/controllers/finance/financial_links_controller.rb
Normal file
27
app/controllers/finance/financial_links_controller.rb
Normal 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
|
4
app/models/financial_link.rb
Normal file
4
app/models/financial_link.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
class FinancialLink < ActiveRecord::Base
|
||||
has_many :financial_transactions
|
||||
has_many :invoices
|
||||
end
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
23
app/views/finance/financial_links/show.html.haml
Normal file
23
app/views/finance/financial_links/show.html.haml
Normal 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
|
|
@ -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)
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -894,6 +894,9 @@ de:
|
|||
without_extra_charge: 'ohne Aufschlag:'
|
||||
create:
|
||||
notice: Rechnung wurde erstellt.
|
||||
financial_links:
|
||||
show:
|
||||
title: Finanzlink %{number}
|
||||
financial_transactions:
|
||||
controller:
|
||||
create:
|
||||
|
|
|
@ -896,6 +896,9 @@ en:
|
|||
without_extra_charge: 'without extra charge:'
|
||||
create:
|
||||
notice: Invoice was created.
|
||||
financial_links:
|
||||
show:
|
||||
title: Financial link %{number}
|
||||
financial_transactions:
|
||||
controller:
|
||||
create:
|
||||
|
|
|
@ -163,6 +163,8 @@ Foodsoft::Application.routes.draw do
|
|||
get :unpaid, on: :collection
|
||||
end
|
||||
|
||||
resources :links, controller: 'financial_links', only: [:show]
|
||||
|
||||
resources :ordergroups, only: [:index] do
|
||||
resources :financial_transactions, as: :transactions
|
||||
end
|
||||
|
|
10
db/migrate/20171002000000_create_financial_links.rb
Normal file
10
db/migrate/20171002000000_create_financial_links.rb
Normal 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
|
18
db/schema.rb
18
db/schema.rb
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# 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|
|
||||
t.string "name", limit: 255, default: "", null: false
|
||||
|
@ -85,12 +85,17 @@ ActiveRecord::Schema.define(version: 20171001020000) do
|
|||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "financial_link", force: :cascade do |t|
|
||||
t.text "note"
|
||||
end
|
||||
|
||||
create_table "financial_transactions", force: :cascade do |t|
|
||||
t.integer "ordergroup_id", limit: 4, default: 0, null: false
|
||||
t.decimal "amount", precision: 8, scale: 2, default: 0, null: false
|
||||
t.text "note", limit: 65535, null: false
|
||||
t.integer "user_id", limit: 4, default: 0, null: false
|
||||
t.datetime "created_on", null: false
|
||||
t.integer "ordergroup_id", limit: 4, default: 0, null: false
|
||||
t.decimal "amount", precision: 8, scale: 2, default: 0, null: false
|
||||
t.text "note", limit: 65535, null: false
|
||||
t.integer "user_id", limit: 4, default: 0, null: false
|
||||
t.datetime "created_on", null: false
|
||||
t.integer "financial_link_id"
|
||||
end
|
||||
|
||||
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.string "attachment_mime"
|
||||
t.binary "attachment_data"
|
||||
t.integer "financial_link_id"
|
||||
end
|
||||
|
||||
add_index "invoices", ["supplier_id"], name: "index_invoices_on_supplier_id", using: :btree
|
||||
|
|
Loading…
Reference in a new issue