Add option to create foodcoop transaction when creating a collection
This option can be used, if a kind of "double-entry accounting" is used and every transaction should have a corresponding transaction.
This commit is contained in:
parent
97b9145223
commit
3f25138997
4 changed files with 20 additions and 0 deletions
|
|
@ -84,6 +84,7 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
|
||||
ActiveRecord::Base.transaction do
|
||||
financial_link = FinancialLink.new if params[:create_financial_link]
|
||||
foodcoop_amount = 0
|
||||
|
||||
params[:financial_transactions].each do |trans|
|
||||
# ignore empty amount fields ...
|
||||
|
|
@ -96,9 +97,21 @@ class Finance::FinancialTransactionsController < ApplicationController
|
|||
amount -= ordergroup.financial_transaction_class_balance(type.financial_transaction_class)
|
||||
end
|
||||
ordergroup.add_financial_transaction!(amount, note, @current_user, type, financial_link)
|
||||
foodcoop_amount -= amount
|
||||
end
|
||||
end
|
||||
|
||||
if params[:create_foodcoop_transaction]
|
||||
ft = FinancialTransaction.new({
|
||||
financial_transaction_type: type,
|
||||
user: @current_user,
|
||||
amount: foodcoop_amount,
|
||||
note: params[:note],
|
||||
financial_link: financial_link,
|
||||
})
|
||||
ft.save!
|
||||
end
|
||||
|
||||
financial_link.try(&:save!)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue