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
|
||||
raise I18n.t('finance.financial_transactions.controller.create_collection.error_note_required') if params[:note].blank?
|
||||
type = FinancialTransactionType.find_by_id(params[:type_id])
|
||||
params[:financial_transactions].each do |trans|
|
||||
# ignore empty amount fields ...
|
||||
unless trans[:amount].blank?
|
||||
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)
|
||||
financial_link = nil
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
financial_link = FinancialLink.new if params[:create_financial_link]
|
||||
|
||||
params[:financial_transactions].each do |trans|
|
||||
# ignore empty amount fields ...
|
||||
unless trans[:amount].blank?
|
||||
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
|
||||
ordergroup.add_financial_transaction!(amount, note, @current_user, type)
|
||||
end
|
||||
|
||||
financial_link.try(&:save!)
|
||||
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
|
||||
flash.now[:alert] = error.message
|
||||
render action: :new_collection
|
||||
|
|
|
@ -56,6 +56,11 @@
|
|||
%p
|
||||
= link_to t('.new_ordergroup'), '#', 'data-add-transaction' => 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
|
||||
= submit_tag t('.save'), class: 'btn btn-primary'
|
||||
= link_to t('ui.or_cancel'), finance_ordergroups_path
|
||||
|
|
|
@ -838,6 +838,7 @@ de:
|
|||
title: Neue Transaktion
|
||||
new_collection:
|
||||
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
|
||||
save: Transaktionen speichern
|
||||
set_balance: Setze den Kontostand der Bestellgrupppe auf den eingegebenen Betrag.
|
||||
|
|
|
@ -863,6 +863,7 @@ en:
|
|||
title: New transaction
|
||||
new_collection:
|
||||
add_all_ordergroups: Add all ordergroups
|
||||
create_financial_link: Create a common financial link for the new transactions.
|
||||
new_ordergroup: Add new ordergroup
|
||||
save: Save transaction
|
||||
set_balance: Set the balance of the ordergroup to the entered amount.
|
||||
|
|
Loading…
Reference in a new issue