Add UI to show and create financial transactions for the foodcoop
This commit is contained in:
parent
1a49bee42d
commit
602f663245
12 changed files with 66 additions and 29 deletions
|
@ -18,7 +18,7 @@ class Finance::FinancialLinksController < Finance::BaseController
|
||||||
type: t('activerecord.models.financial_transaction'),
|
type: t('activerecord.models.financial_transaction'),
|
||||||
description: "#{ft.ordergroup_name}: #{ft.note}",
|
description: "#{ft.ordergroup_name}: #{ft.note}",
|
||||||
amount: ft.amount,
|
amount: ft.amount,
|
||||||
link_to: finance_ordergroup_transactions_path(ft.ordergroup),
|
link_to: finance_group_transactions_path(ft.ordergroup),
|
||||||
remove_path: remove_financial_transaction_finance_link_path(@financial_link, ft)
|
remove_path: remove_financial_transaction_finance_link_path(@financial_link, ft)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,6 +23,7 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
@financial_transactions_all = @q.result(distinct: true).includes(:user).order(sort)
|
@financial_transactions_all = @q.result(distinct: true).includes(:user).order(sort)
|
||||||
@financial_transactions_all = @financial_transactions_all.visible unless params[:show_hidden]
|
@financial_transactions_all = @financial_transactions_all.visible unless params[:show_hidden]
|
||||||
@financial_transactions_all = @financial_transactions_all.where(ordergroup_id: @ordergroup.id) if @ordergroup
|
@financial_transactions_all = @financial_transactions_all.where(ordergroup_id: @ordergroup.id) if @ordergroup
|
||||||
|
@financial_transactions_all = @financial_transactions_all.where(ordergroup: nil) if @foodcoop
|
||||||
@financial_transactions = @financial_transactions_all.page(params[:page]).per(@per_page)
|
@financial_transactions = @financial_transactions_all.page(params[:page]).per(@per_page)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
@ -38,14 +39,22 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
|
if @ordergroup
|
||||||
@financial_transaction = @ordergroup.financial_transactions.build
|
@financial_transaction = @ordergroup.financial_transactions.build
|
||||||
|
else
|
||||||
|
@financial_transaction = FinancialTransaction.new
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@financial_transaction = FinancialTransaction.new(params[:financial_transaction])
|
@financial_transaction = FinancialTransaction.new(params[:financial_transaction])
|
||||||
@financial_transaction.user = current_user
|
@financial_transaction.user = current_user
|
||||||
|
if @financial_transaction.ordergroup
|
||||||
@financial_transaction.add_transaction!
|
@financial_transaction.add_transaction!
|
||||||
redirect_to finance_ordergroup_transactions_url(@ordergroup), notice: I18n.t('finance.financial_transactions.controller.create.notice')
|
else
|
||||||
|
@financial_transaction.save!
|
||||||
|
end
|
||||||
|
redirect_to finance_group_transactions_path(@ordergroup), notice: I18n.t('finance.financial_transactions.controller.create.notice')
|
||||||
rescue ActiveRecord::RecordInvalid => error
|
rescue ActiveRecord::RecordInvalid => error
|
||||||
flash.now[:alert] = error.message
|
flash.now[:alert] = error.message
|
||||||
render :action => :new
|
render :action => :new
|
||||||
|
@ -54,7 +63,7 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
def destroy
|
def destroy
|
||||||
transaction = FinancialTransaction.find(params[:id])
|
transaction = FinancialTransaction.find(params[:id])
|
||||||
transaction.revert!(current_user)
|
transaction.revert!(current_user)
|
||||||
redirect_to finance_ordergroup_transactions_url(transaction.ordergroup), notice: t('finance.financial_transactions.controller.destroy.notice')
|
redirect_to finance_group_transactions_path(transaction.ordergroup), notice: t('finance.financial_transactions.controller.destroy.notice')
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_collection
|
def new_collection
|
||||||
|
@ -103,7 +112,11 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
protected
|
protected
|
||||||
|
|
||||||
def find_ordergroup
|
def find_ordergroup
|
||||||
|
if params[:ordergroup_id]
|
||||||
@ordergroup = Ordergroup.include_transaction_class_sum.find(params[:ordergroup_id])
|
@ordergroup = Ordergroup.include_transaction_class_sum.find(params[:ordergroup_id])
|
||||||
|
else
|
||||||
|
@foodcoop = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#
|
#
|
||||||
# Methods added to this helper will be available to all templates in the application.
|
# Methods added to this helper will be available to all templates in the application.
|
||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
include PathHelper
|
||||||
|
|
||||||
def format_time(time = Time.now)
|
def format_time(time = Time.now)
|
||||||
I18n.l(time, :format => "%d.%m.%Y %H:%M") unless time.nil?
|
I18n.l(time, :format => "%d.%m.%Y %H:%M") unless time.nil?
|
||||||
|
|
11
app/helpers/path_helper.rb
Normal file
11
app/helpers/path_helper.rb
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
module PathHelper
|
||||||
|
|
||||||
|
def finance_group_transactions_path(ordergroup)
|
||||||
|
if ordergroup
|
||||||
|
finance_ordergroup_transactions_path(ordergroup)
|
||||||
|
else
|
||||||
|
finance_foodcoop_financial_transactions_path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -47,7 +47,7 @@ class FinancialTransaction < ApplicationRecord
|
||||||
rt.reverts = self
|
rt.reverts = self
|
||||||
rt.user = user
|
rt.user = user
|
||||||
rt.save!
|
rt.save!
|
||||||
ordergroup.update_balance!
|
ordergroup.update_balance! if ordergroup
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
- else
|
- else
|
||||||
= format_time(t.created_on)
|
= 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_group_transactions_path(t.ordergroup)
|
||||||
%td= h show_user(t.user)
|
%td= h show_user(t.user)
|
||||||
- if FinancialTransactionType.has_multiple_types
|
- if FinancialTransactionType.has_multiple_types
|
||||||
%td= h t.financial_transaction_type.name
|
%td= h t.financial_transaction_type.name
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
- if with_hidden
|
- if with_hidden
|
||||||
%td.actions{style: 'width:1em'}
|
%td.actions{style: 'width:1em'}
|
||||||
- unless t.hidden?
|
- unless t.hidden?
|
||||||
= link_to finance_ordergroup_transaction_path(t.ordergroup, t), method: :delete,
|
= link_to finance_transaction_path(t), method: :delete,
|
||||||
data: {confirm: t('.confirm_revert', name: t.note)}, title: t('.revert_title'),
|
data: {confirm: t('.confirm_revert', name: t.note)}, title: t('.revert_title'),
|
||||||
class: 'btn btn-danger btn-mini' do
|
class: 'btn btn-danger btn-mini' do
|
||||||
= glyph :remove
|
= glyph :remove
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
- title t('.title', name: @ordergroup.name)
|
- title @ordergroup ? t('.title', name: @ordergroup.name) : t('.title_foodcoop')
|
||||||
|
|
||||||
- content_for :actionbar do
|
- content_for :actionbar do
|
||||||
= link_to t('.new_transaction'), new_finance_ordergroup_transaction_path(@ordergroup), class: 'btn btn-primary'
|
- url = @ordergroup ? new_finance_ordergroup_transaction_path(@ordergroup) : new_finance_foodcoop_financial_transaction_path
|
||||||
|
= link_to t('.new_transaction'), url, class: 'btn btn-primary'
|
||||||
|
|
||||||
|
- if @ordergroup
|
||||||
- content_for :sidebar do
|
- content_for :sidebar do
|
||||||
.well.well-small
|
.well.well-small
|
||||||
%strong= t('.balance', balance: number_to_currency(@ordergroup.account_balance))
|
%strong= t('.balance', balance: number_to_currency(@ordergroup.account_balance))
|
||||||
|
@ -20,6 +22,6 @@
|
||||||
= number_to_currency(@ordergroup["sum_of_class_#{c.id}"])
|
= number_to_currency(@ordergroup["sum_of_class_#{c.id}"])
|
||||||
|
|
||||||
|
|
||||||
= render 'transactions_search', url: finance_ordergroup_transactions_path(@ordergroup)
|
= render 'transactions_search', url: finance_group_transactions_path(@ordergroup)
|
||||||
|
|
||||||
#transactions= render 'transactions', with_csv: true, with_hidden: true
|
#transactions= render 'transactions', with_csv: true, with_hidden: true
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
- title t('.title')
|
- title t('.title')
|
||||||
|
|
||||||
|
- if @ordergroup
|
||||||
%p!= t('.paragraph', name: @ordergroup.name)
|
%p!= t('.paragraph', name: @ordergroup.name)
|
||||||
|
- else
|
||||||
|
%p!= t('.paragraph_foodcoop')
|
||||||
|
|
||||||
= simple_form_for @financial_transaction, :url => finance_ordergroup_transactions_path(@ordergroup),
|
= simple_form_for @financial_transaction, :url => finance_group_transactions_path(@ordergroup),
|
||||||
:validate => true do |f|
|
:validate => true do |f|
|
||||||
= f.hidden_field :ordergroup_id
|
= f.hidden_field :ordergroup_id
|
||||||
- if FinancialTransactionType.has_multiple_types
|
- if FinancialTransactionType.has_multiple_types
|
||||||
|
@ -11,4 +14,4 @@
|
||||||
= f.input :note, :as => :text
|
= f.input :note, :as => :text
|
||||||
.form-actions
|
.form-actions
|
||||||
= f.submit class: 'btn btn-primary'
|
= f.submit class: 'btn btn-primary'
|
||||||
= link_to t('ui.or_cancel'), finance_ordergroup_transactions_path(@ordergroup)
|
= link_to t('ui.or_cancel'), finance_group_transactions_path(@ordergroup)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
- content_for :actionbar do
|
- content_for :actionbar do
|
||||||
= link_to t('.show_all'), finance_transactions_path, class: 'btn'
|
= link_to t('.show_all'), finance_transactions_path, class: 'btn'
|
||||||
|
= link_to t('.show_foodcoop'), finance_foodcoop_financial_transactions_path, class: 'btn'
|
||||||
= link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary'
|
= link_to t('.new_transaction'), finance_new_transaction_collection_path, class: 'btn btn-primary'
|
||||||
|
|
||||||
.well.well-small
|
.well.well-small
|
||||||
|
|
|
@ -868,6 +868,7 @@ de:
|
||||||
title: Kontotransaktionen
|
title: Kontotransaktionen
|
||||||
new:
|
new:
|
||||||
paragraph: Hier kannst du der Bestellgruppe <b>%{name}</b> Geld gutschreiben/abziehen.
|
paragraph: Hier kannst du der Bestellgruppe <b>%{name}</b> Geld gutschreiben/abziehen.
|
||||||
|
paragraph_foodcoop: Hier kannst du der <b>Foodcooop</b> Geld gutschreiben/abziehen.
|
||||||
title: Neue Transaktion
|
title: Neue Transaktion
|
||||||
new_collection:
|
new_collection:
|
||||||
add_all_ordergroups: Alle Bestellgruppen hinzufügen
|
add_all_ordergroups: Alle Bestellgruppen hinzufügen
|
||||||
|
@ -916,6 +917,7 @@ de:
|
||||||
index:
|
index:
|
||||||
new_transaction: Neue Überweisungen eingeben
|
new_transaction: Neue Überweisungen eingeben
|
||||||
show_all: Alle Transaktionen
|
show_all: Alle Transaktionen
|
||||||
|
show_foodcoop: Foodcoop Transaktionen
|
||||||
title: Konten verwalten
|
title: Konten verwalten
|
||||||
ordergroups:
|
ordergroups:
|
||||||
account_statement: Kontoauszug
|
account_statement: Kontoauszug
|
||||||
|
|
|
@ -891,6 +891,7 @@ en:
|
||||||
title: Financial transactions
|
title: Financial transactions
|
||||||
new:
|
new:
|
||||||
paragraph: Here you can credit and debit money for the ordergroup <b>%{name}</b>.
|
paragraph: Here you can credit and debit money for the ordergroup <b>%{name}</b>.
|
||||||
|
paragraph_foodcoop: Here you can credit and debit money for the <b>foodcoop</b>.
|
||||||
title: New transaction
|
title: New transaction
|
||||||
new_collection:
|
new_collection:
|
||||||
add_all_ordergroups: Add all ordergroups
|
add_all_ordergroups: Add all ordergroups
|
||||||
|
@ -939,6 +940,7 @@ en:
|
||||||
index:
|
index:
|
||||||
new_transaction: Add new transactions
|
new_transaction: Add new transactions
|
||||||
show_all: All transactions
|
show_all: All transactions
|
||||||
|
show_foodcoop: Foodcoop transaktions
|
||||||
title: Manage accounts
|
title: Manage accounts
|
||||||
ordergroups:
|
ordergroups:
|
||||||
account_statement: Account statement
|
account_statement: Account statement
|
||||||
|
|
|
@ -191,7 +191,9 @@ Foodsoft::Application.routes.draw do
|
||||||
resources :ordergroups, only: [:index] do
|
resources :ordergroups, only: [:index] do
|
||||||
resources :financial_transactions, as: :transactions
|
resources :financial_transactions, as: :transactions
|
||||||
end
|
end
|
||||||
get 'transactions' => 'financial_transactions#index_collection'
|
resources :financial_transactions, as: :foodcoop_financial_transactions, path: 'foodcoop/financial_transactions', only: [:index, :new, :create]
|
||||||
|
get :transactions, controller: :financial_transactions, action: :index_collection
|
||||||
|
delete 'transactions/:id', controller: :financial_transactions, action: :destroy, as: :transaction
|
||||||
|
|
||||||
get 'transactions/new_collection' => 'financial_transactions#new_collection', as: 'new_transaction_collection'
|
get 'transactions/new_collection' => 'financial_transactions#new_collection', as: 'new_transaction_collection'
|
||||||
post 'transactions/create_collection' => 'financial_transactions#create_collection', as: 'create_transaction_collection'
|
post 'transactions/create_collection' => 'financial_transactions#create_collection', as: 'create_transaction_collection'
|
||||||
|
|
Loading…
Reference in a new issue