Add set_balance to FinancialTransactions#new_collection (fixes #438)
A new checkbox will allow user to set the balance to a given ABSOLUTE value in addition to changing it by a RELATIVE value. This can be used if the balance is tracked outside of foodsoft and should be syncroniced or for setting the balance to zero for multiple ordergroups.
This commit is contained in:
parent
abe847c0ee
commit
389f205a6b
5 changed files with 24 additions and 3 deletions
|
@ -59,12 +59,20 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
params[:financial_transactions].each do |trans|
|
params[:financial_transactions].each do |trans|
|
||||||
# ignore empty amount fields ...
|
# ignore empty amount fields ...
|
||||||
unless trans[:amount].blank?
|
unless trans[:amount].blank?
|
||||||
Ordergroup.find(trans[:ordergroup_id]).add_financial_transaction!(trans[:amount], params[:note], @current_user, type)
|
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)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
redirect_to finance_ordergroups_url, notice: I18n.t('finance.financial_transactions.controller.create_collection.notice')
|
redirect_to finance_ordergroups_url, notice: I18n.t('finance.financial_transactions.controller.create_collection.notice')
|
||||||
rescue => error
|
rescue => error
|
||||||
redirect_to finance_new_transaction_collection_url, alert: I18n.t('finance.financial_transactions.controller.create_collection.alert', error: error.to_s)
|
flash.now[:alert] = error.message
|
||||||
|
render action: :new_collection
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
|
@ -65,6 +65,13 @@ class Ordergroup < Group
|
||||||
account_balance - value_of_open_orders(exclude) - value_of_finished_orders(exclude)
|
account_balance - value_of_open_orders(exclude) - value_of_finished_orders(exclude)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def financial_transaction_class_balance(klass)
|
||||||
|
financial_transactions
|
||||||
|
.joins(:financial_transaction_type)
|
||||||
|
.where(financial_transaction_types: {financial_transaction_class_id: klass})
|
||||||
|
.sum(:amount)
|
||||||
|
end
|
||||||
|
|
||||||
# Creates a new FinancialTransaction for this Ordergroup and updates the account_balance accordingly.
|
# Creates a new FinancialTransaction for this Ordergroup and updates the account_balance accordingly.
|
||||||
# Throws an exception if it fails.
|
# Throws an exception if it fails.
|
||||||
def add_financial_transaction!(amount, note, user, transaction_type, link = nil)
|
def add_financial_transaction!(amount, note, user, transaction_type, link = nil)
|
||||||
|
|
|
@ -37,10 +37,14 @@
|
||||||
- if FinancialTransactionType.has_multiple_types
|
- if FinancialTransactionType.has_multiple_types
|
||||||
%p
|
%p
|
||||||
%b= heading_helper FinancialTransaction, :financial_transaction_type
|
%b= heading_helper FinancialTransaction, :financial_transaction_type
|
||||||
= select_tag :type, options_for_select(FinancialTransactionType.order(:name).map { |t| [ t.name, t.id ] })
|
= select_tag :type, options_for_select(FinancialTransactionType.order(:name).map { |t| [ t.name, t.id ] }, params[:type])
|
||||||
%p
|
%p
|
||||||
%b= heading_helper FinancialTransaction, :note
|
%b= heading_helper FinancialTransaction, :note
|
||||||
= text_field_tag :note, params[:note], class: 'input-xlarge', required: 'required'
|
= text_field_tag :note, params[:note], class: 'input-xlarge', required: 'required'
|
||||||
|
%p
|
||||||
|
%label
|
||||||
|
= check_box_tag :set_balance, true, params[:set_balance]
|
||||||
|
= t('.set_balance')
|
||||||
%p
|
%p
|
||||||
%table#ordergroups{:style => "width:20em"}
|
%table#ordergroups{:style => "width:20em"}
|
||||||
%thead
|
%thead
|
||||||
|
|
|
@ -930,6 +930,7 @@ de:
|
||||||
add_all_ordergroups: Alle Bestellgruppen hinzufügen
|
add_all_ordergroups: Alle Bestellgruppen hinzufügen
|
||||||
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.
|
||||||
sidebar: Hier kannst Du mehrere Konten gleichzeitig aktualsieren. Z.B. alle Überweisungen der Bestellgruppen aus einem Kontoauszug.
|
sidebar: Hier kannst Du mehrere Konten gleichzeitig aktualsieren. Z.B. alle Überweisungen der Bestellgruppen aus einem Kontoauszug.
|
||||||
title: Mehrere Konten aktualisieren
|
title: Mehrere Konten aktualisieren
|
||||||
ordergroup:
|
ordergroup:
|
||||||
|
|
|
@ -947,6 +947,7 @@ en:
|
||||||
add_all_ordergroups: Add all ordergroups
|
add_all_ordergroups: Add all ordergroups
|
||||||
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.
|
||||||
sidebar: Here you can update more accounts at the same time. For example all transfers of the ordergroup from one account statement.
|
sidebar: Here you can update more accounts at the same time. For example all transfers of the ordergroup from one account statement.
|
||||||
title: Updating more accounts
|
title: Updating more accounts
|
||||||
ordergroup:
|
ordergroup:
|
||||||
|
|
Loading…
Reference in a new issue