Add option to create a financial_link when creating financial_transaction
If multiple financial transaction belong to a bank transaction, it is sometimes easier to create them as a collection and add the bank transaction instead of adding all financial transaction to a link created via a bank transaction.
This commit is contained in:
parent
ef613300e0
commit
260ef90f6b
4 changed files with 28 additions and 11 deletions
|
@ -56,20 +56,30 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
def create_collection
|
def create_collection
|
||||||
raise I18n.t('finance.financial_transactions.controller.create_collection.error_note_required') if params[:note].blank?
|
raise I18n.t('finance.financial_transactions.controller.create_collection.error_note_required') if params[:note].blank?
|
||||||
type = FinancialTransactionType.find_by_id(params[:type_id])
|
type = FinancialTransactionType.find_by_id(params[:type_id])
|
||||||
params[:financial_transactions].each do |trans|
|
financial_link = nil
|
||||||
# ignore empty amount fields ...
|
|
||||||
unless trans[:amount].blank?
|
ActiveRecord::Base.transaction do
|
||||||
amount = trans[:amount].to_f
|
financial_link = FinancialLink.new if params[:create_financial_link]
|
||||||
note = params[:note]
|
|
||||||
ordergroup = Ordergroup.find(trans[:ordergroup_id])
|
params[:financial_transactions].each do |trans|
|
||||||
if params[:set_balance]
|
# ignore empty amount fields ...
|
||||||
note += " (#{amount})"
|
unless trans[:amount].blank?
|
||||||
amount -= ordergroup.financial_transaction_class_balance(type.financial_transaction_class)
|
amount = trans[:amount].to_f
|
||||||
|
note = params[:note]
|
||||||
|
ordergroup = Ordergroup.find(trans[:ordergroup_id])
|
||||||
|
if params[:set_balance]
|
||||||
|
note += " (#{amount})"
|
||||||
|
amount -= ordergroup.financial_transaction_class_balance(type.financial_transaction_class)
|
||||||
|
end
|
||||||
|
ordergroup.add_financial_transaction!(amount, note, @current_user, type, financial_link)
|
||||||
end
|
end
|
||||||
ordergroup.add_financial_transaction!(amount, note, @current_user, type)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
financial_link.try(&:save!)
|
||||||
end
|
end
|
||||||
redirect_to finance_ordergroups_url, notice: I18n.t('finance.financial_transactions.controller.create_collection.notice')
|
|
||||||
|
url = financial_link ? finance_link_url(financial_link.id) : finance_ordergroups_url
|
||||||
|
redirect_to url, notice: I18n.t('finance.financial_transactions.controller.create_collection.notice')
|
||||||
rescue => error
|
rescue => error
|
||||||
flash.now[:alert] = error.message
|
flash.now[:alert] = error.message
|
||||||
render action: :new_collection
|
render action: :new_collection
|
||||||
|
|
|
@ -56,6 +56,11 @@
|
||||||
%p
|
%p
|
||||||
= link_to t('.new_ordergroup'), '#', 'data-add-transaction' => true, class: 'btn'
|
= link_to t('.new_ordergroup'), '#', 'data-add-transaction' => true, class: 'btn'
|
||||||
= link_to t('.add_all_ordergroups'), '#', 'data-add-all-ordergroups' => true, class: 'btn'
|
= link_to t('.add_all_ordergroups'), '#', 'data-add-all-ordergroups' => true, class: 'btn'
|
||||||
|
- if BankAccount.any?
|
||||||
|
%p
|
||||||
|
%label
|
||||||
|
= check_box_tag :create_financial_link, true, params[:create_financial_link]
|
||||||
|
= t('.create_financial_link')
|
||||||
.form-actions
|
.form-actions
|
||||||
= submit_tag t('.save'), class: 'btn btn-primary'
|
= submit_tag t('.save'), class: 'btn btn-primary'
|
||||||
= link_to t('ui.or_cancel'), finance_ordergroups_path
|
= link_to t('ui.or_cancel'), finance_ordergroups_path
|
||||||
|
|
|
@ -838,6 +838,7 @@ de:
|
||||||
title: Neue Transaktion
|
title: Neue Transaktion
|
||||||
new_collection:
|
new_collection:
|
||||||
add_all_ordergroups: Alle Bestellgruppen hinzufügen
|
add_all_ordergroups: Alle Bestellgruppen hinzufügen
|
||||||
|
create_financial_link: Erstelle einen gemeinsamen Finanzlink für die neuen Transaktionen.
|
||||||
new_ordergroup: Weitere Bestellgruppe hinzufügen
|
new_ordergroup: Weitere Bestellgruppe hinzufügen
|
||||||
save: Transaktionen speichern
|
save: Transaktionen speichern
|
||||||
set_balance: Setze den Kontostand der Bestellgrupppe auf den eingegebenen Betrag.
|
set_balance: Setze den Kontostand der Bestellgrupppe auf den eingegebenen Betrag.
|
||||||
|
|
|
@ -863,6 +863,7 @@ en:
|
||||||
title: New transaction
|
title: New transaction
|
||||||
new_collection:
|
new_collection:
|
||||||
add_all_ordergroups: Add all ordergroups
|
add_all_ordergroups: Add all ordergroups
|
||||||
|
create_financial_link: Create a common financial link for the new transactions.
|
||||||
new_ordergroup: Add new ordergroup
|
new_ordergroup: Add new ordergroup
|
||||||
save: Save transaction
|
save: Save transaction
|
||||||
set_balance: Set the balance of the ordergroup to the entered amount.
|
set_balance: Set the balance of the ordergroup to the entered amount.
|
||||||
|
|
Loading…
Reference in a new issue