Add edit functionality for financial links
This commit is contained in:
parent
f0a55fb951
commit
707501e3f8
13 changed files with 169 additions and 6 deletions
|
@ -1,15 +1,15 @@
|
|||
class Finance::FinancialLinksController < Finance::BaseController
|
||||
before_filter :find_financial_link, except: [:create]
|
||||
|
||||
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)
|
||||
link_to: finance_bank_transaction_path(bt),
|
||||
remove_path: remove_bank_transaction_finance_link_path(@financial_link, bt)
|
||||
}
|
||||
end
|
||||
@items += @financial_link.financial_transactions.map do |ft|
|
||||
|
@ -18,7 +18,8 @@ class Finance::FinancialLinksController < Finance::BaseController
|
|||
type: t('activerecord.models.financial_transaction'),
|
||||
description: "#{ft.ordergroup.name}: #{ft.note}",
|
||||
amount: ft.amount,
|
||||
link_to: finance_ordergroup_transactions_path(ft.ordergroup)
|
||||
link_to: finance_ordergroup_transactions_path(ft.ordergroup),
|
||||
remove_path: remove_financial_transaction_finance_link_path(@financial_link, ft)
|
||||
}
|
||||
end
|
||||
@items += @financial_link.invoices.map do |invoice|
|
||||
|
@ -27,10 +28,74 @@ class Finance::FinancialLinksController < Finance::BaseController
|
|||
type: t('activerecord.models.invoice'),
|
||||
description: "#{invoice.supplier.name}: #{invoice.number}",
|
||||
amount: invoice.amount,
|
||||
link_to: finance_invoice_path(invoice)
|
||||
link_to: finance_invoice_path(invoice),
|
||||
remove_path: remove_invoice_finance_link_path(@financial_link, invoice)
|
||||
}
|
||||
end
|
||||
@items.sort_by! { |item| item[:date] }
|
||||
end
|
||||
|
||||
def create
|
||||
@financial_link = FinancialLink.new
|
||||
if params[:bank_transaction] then
|
||||
bank_transaction = BankTransaction.find(params[:bank_transaction])
|
||||
bank_transaction.update_attribute :financial_link, @financial_link
|
||||
end
|
||||
redirect_to finance_link_url(@financial_link), notice: I18n.t('finance.bank_transactions.controller.create.notice')
|
||||
end
|
||||
|
||||
def index_bank_transaction
|
||||
@bank_transactions = BankTransaction.without_financial_link
|
||||
end
|
||||
|
||||
def add_bank_transaction
|
||||
bank_transaction = BankTransaction.find(params[:bank_transaction])
|
||||
bank_transaction.update_attribute :financial_link, @financial_link
|
||||
redirect_to finance_link_url(@financial_link), notice: I18n.t('finance.bank_transactions.controller.create.notice')
|
||||
end
|
||||
|
||||
def remove_bank_transaction
|
||||
bank_transaction = BankTransaction.find(params[:bank_transaction])
|
||||
bank_transaction.update_attribute :financial_link, nil
|
||||
redirect_to finance_link_url(@financial_link), notice: I18n.t('finance.bank_transactions.controller.destroy.notice')
|
||||
end
|
||||
|
||||
def index_financial_transaction
|
||||
@financial_transactions = FinancialTransaction.without_financial_link
|
||||
end
|
||||
|
||||
def add_financial_transaction
|
||||
financial_transaction = FinancialTransaction.find(params[:financial_transaction])
|
||||
financial_transaction.update_attribute :financial_link, @financial_link
|
||||
redirect_to finance_link_url(@financial_link), notice: I18n.t('finance.financial_transactions.controller.create.notice')
|
||||
end
|
||||
|
||||
def remove_financial_transaction
|
||||
financial_transaction = FinancialTransaction.find(params[:financial_transaction])
|
||||
financial_transaction.update_attribute :financial_link, nil
|
||||
redirect_to finance_link_url(@financial_link), notice: I18n.t('finance.financial_transactions.controller.destroy.notice')
|
||||
end
|
||||
|
||||
def index_invoice
|
||||
@invoices = Invoice.without_financial_link
|
||||
end
|
||||
|
||||
def add_invoice
|
||||
invoice = Invoice.find(params[:invoice])
|
||||
invoice.update_attribute :financial_link, @financial_link
|
||||
redirect_to finance_link_url(@financial_link), notice: I18n.t('finance.financial_transactions.controller.create.notice')
|
||||
end
|
||||
|
||||
def remove_invoice
|
||||
invoice = Invoice.find(params[:invoice])
|
||||
invoice.update_attribute :financial_link, nil
|
||||
redirect_to finance_link_url(@financial_link), notice: I18n.t('finance.financial_transactions.controller.destroy.notice')
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_financial_link
|
||||
@financial_link = FinancialLink.find(params[:id])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -25,6 +25,8 @@ class BankTransaction < ActiveRecord::Base
|
|||
validates_presence_of :date, :amount, :bank_account_id
|
||||
validates_numericality_of :amount
|
||||
|
||||
scope :without_financial_link, -> { where(financial_link: nil) }
|
||||
|
||||
# Replace numeric seperator with database format
|
||||
localize_input_of :amount
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@ class FinancialTransaction < ActiveRecord::Base
|
|||
validates_numericality_of :amount, greater_then: -100_000,
|
||||
less_than: 100_000
|
||||
|
||||
scope :without_financial_link, -> { where(financial_link: nil) }
|
||||
|
||||
localize_input_of :amount
|
||||
|
||||
after_initialize do
|
||||
|
|
|
@ -12,6 +12,7 @@ class Invoice < ActiveRecord::Base
|
|||
validate :valid_attachment
|
||||
|
||||
scope :unpaid, -> { where(paid_on: nil) }
|
||||
scope :without_financial_link, -> { where(financial_link: nil) }
|
||||
|
||||
attr_accessor :delete_attachment
|
||||
|
||||
|
|
|
@ -20,3 +20,6 @@
|
|||
%td
|
||||
- if t.financial_link
|
||||
= link_to t('ui.show'), finance_link_path(t.financial_link)
|
||||
- else
|
||||
= link_to t('.add_financial_link'), finance_links_path(bank_transaction: t.id),
|
||||
method: :post, class: 'btn btn-success btn-mini'
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
.modal-header
|
||||
= close_button :modal
|
||||
%h3= t('.add_invoice')
|
||||
.modal-body
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
%tr
|
||||
%th= heading_helper BankTransaction, :date
|
||||
%th= heading_helper BankTransaction, :text
|
||||
%th= heading_helper BankTransaction, :reference
|
||||
%th= heading_helper BankTransaction, :amount
|
||||
%tbody
|
||||
- for t in @bank_transactions
|
||||
%tr
|
||||
%td= link_to format_time(t.date), add_bank_transaction_finance_link_path(@financial_link, bank_transaction: t.id), method: :put
|
||||
%td= t.text
|
||||
%td= t.reference
|
||||
%td= number_to_currency t.amount
|
||||
.modal-footer
|
||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
|
@ -0,0 +1,22 @@
|
|||
.modal-header
|
||||
= close_button :modal
|
||||
%h3= t('.add_invoice')
|
||||
.modal-body
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
%tr
|
||||
%th= heading_helper FinancialTransaction, :created_on
|
||||
%th= heading_helper FinancialTransaction, :ordergroup
|
||||
- if FinancialTransactionType.has_multiple_types
|
||||
%th= heading_helper FinancialTransaction, :financial_transaction_type
|
||||
%th= heading_helper FinancialTransaction, :amount
|
||||
%tbody
|
||||
- for t in @financial_transactions
|
||||
%tr
|
||||
%td= link_to format_time(t.created_on), add_financial_transaction_finance_link_path(@financial_link, financial_transaction: t.id), method: :put
|
||||
%td= t.ordergroup.name
|
||||
- if FinancialTransactionType.has_multiple_types
|
||||
%td= h t.financial_transaction_type.name
|
||||
%td= number_to_currency t.amount
|
||||
.modal-footer
|
||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
20
app/views/finance/financial_links/_index_invoice.html.haml
Normal file
20
app/views/finance/financial_links/_index_invoice.html.haml
Normal file
|
@ -0,0 +1,20 @@
|
|||
.modal-header
|
||||
= close_button :modal
|
||||
%h3= t('.add_invoice')
|
||||
.modal-body
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
%tr
|
||||
%th= heading_helper Invoice, :number
|
||||
%th= heading_helper Invoice, :supplier
|
||||
%th= heading_helper Invoice, :date
|
||||
%th= heading_helper Invoice, :amount
|
||||
%tbody
|
||||
- for invoice in @invoices
|
||||
%tr
|
||||
%td= link_to h(invoice.number), add_invoice_finance_link_path(@financial_link, invoice: invoice.id), method: :put
|
||||
%td= invoice.supplier.name
|
||||
%td= format_date invoice.date
|
||||
%td= number_to_currency invoice.amount
|
||||
.modal-footer
|
||||
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
|
|
@ -0,0 +1,2 @@
|
|||
$('#modalContainer').html('#{j(render("index_bank_transaction"))}');
|
||||
$('#modalContainer').modal();
|
|
@ -0,0 +1,2 @@
|
|||
$('#modalContainer').html('#{j(render("index_financial_transaction"))}');
|
||||
$('#modalContainer').modal();
|
2
app/views/finance/financial_links/index_invoice.js.haml
Normal file
2
app/views/finance/financial_links/index_invoice.js.haml
Normal file
|
@ -0,0 +1,2 @@
|
|||
$('#modalContainer').html('#{j(render("index_invoice"))}');
|
||||
$('#modalContainer').modal();
|
|
@ -1,5 +1,10 @@
|
|||
- title t('.title', number: @financial_link.id)
|
||||
|
||||
- content_for :actionbar do
|
||||
= link_to t('.add_bank_transaction'), index_bank_transaction_finance_link_path(@financial_link), remote: true, class: 'btn'
|
||||
= link_to t('.add_financial_transaction'), index_financial_transaction_finance_link_path(@financial_link), remote: true, class: 'btn'
|
||||
= link_to t('.add_invoice'), index_invoice_finance_link_path(@financial_link), remote: true, class: 'btn'
|
||||
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
%tr
|
||||
|
@ -7,6 +12,7 @@
|
|||
%th= t '.type'
|
||||
%th= t '.description'
|
||||
%th= t '.amount'
|
||||
%th
|
||||
%tbody
|
||||
- @items.each do |item|
|
||||
%tr
|
||||
|
@ -18,6 +24,8 @@
|
|||
%td= item[:type]
|
||||
%td= item[:description]
|
||||
%td.numeric{style: 'width:5em'}= format_currency item[:amount]
|
||||
%td= link_to t('ui.delete'), item[:remove_path], :data => {:confirm => t('ui.confirm_delete', name: item[:description])}, :method => :delete,
|
||||
class: 'btn btn-danger btn-mini'
|
||||
|
||||
%p
|
||||
= @financial_link.note
|
||||
|
|
|
@ -167,7 +167,21 @@ Foodsoft::Application.routes.draw do
|
|||
get :unpaid, on: :collection
|
||||
end
|
||||
|
||||
resources :links, controller: 'financial_links', only: [:show]
|
||||
resources :links, controller: 'financial_links', only: [:create, :show] do
|
||||
member do
|
||||
get :index_bank_transaction
|
||||
put 'bank_transactions/:bank_transaction', action: 'add_bank_transaction', as: 'add_bank_transaction'
|
||||
delete 'bank_transactions/:bank_transaction', action: 'remove_bank_transaction', as: 'remove_bank_transaction'
|
||||
|
||||
get :index_financial_transaction
|
||||
put 'financial_transactions/:financial_transaction', action: 'add_financial_transaction', as: 'add_financial_transaction'
|
||||
delete 'financial_transactions/:financial_transaction', action: 'remove_financial_transaction', as: 'remove_financial_transaction'
|
||||
|
||||
get :index_invoice
|
||||
put 'invoices/:invoice', action: 'add_invoice', as: 'add_invoice'
|
||||
delete 'invoices/:invoice', action: 'remove_invoice', as: 'remove_invoice'
|
||||
end
|
||||
end
|
||||
|
||||
resources :ordergroups, only: [:index] do
|
||||
resources :financial_transactions, as: :transactions
|
||||
|
|
Loading…
Reference in a new issue