Add FinacialTransaction create_collection for ordergroup custom fields
Custom fields of an ordergroup can set financial_transaction_source to true, to act as an source for a new collection of FinacialTransaction. A typical usecase would be a variable membership fee, which will be stored in a custom field on the ordergroup. When a new membership period begins a collection with all membership fees can be created with one click.
This commit is contained in:
parent
d73c206e29
commit
a3defc5463
4 changed files with 32 additions and 6 deletions
|
@ -58,6 +58,14 @@ class Finance::FinancialTransactionsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new_collection
|
def new_collection
|
||||||
|
@ordergroups = {}
|
||||||
|
Ordergroup.undeleted.order(:name).map do |ordergroup|
|
||||||
|
obj = { name: ordergroup.name }
|
||||||
|
Ordergroup.custom_fields.each do |field|
|
||||||
|
obj[field[:name]] = ordergroup.settings.custom_fields[field[:name]]
|
||||||
|
end
|
||||||
|
@ordergroups[ordergroup.id] = obj
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_collection
|
def create_collection
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
- content_for :javascript do
|
- content_for :javascript do
|
||||||
:javascript
|
:javascript
|
||||||
var ordergroup = $($.parseHTML("#{escape_javascript(render('ordergroup'))}"));
|
var ordergroup = $($.parseHTML("#{escape_javascript(render('ordergroup'))}"));
|
||||||
|
var ordergroups = #{raw @ordergroups.to_json};
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
$(document).on('touchclick', 'a[data-remove-transaction]', function() {
|
$(document).on('touchclick', 'a[data-remove-transaction]', function() {
|
||||||
|
@ -16,16 +17,27 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
$(document).on('touchclick', 'a[data-add-all-ordergroups]', function() {
|
$(document).on('touchclick', 'a[data-add-all-ordergroups]', function() {
|
||||||
var value = prompt("#{escape_javascript(heading_helper(FinancialTransaction, :amount))}:");
|
var customField = $(this).data('custom-field');
|
||||||
if (value === null)
|
var value;
|
||||||
|
if (!customField) {
|
||||||
|
value = prompt("#{escape_javascript(heading_helper(FinancialTransaction, :amount))}:");
|
||||||
|
if (value === null) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
$('#ordergroups > tbody > tr').remove();
|
$('#ordergroups > tbody > tr').remove();
|
||||||
var options = ordergroup.find('td > select > option').each(function() {
|
for (var id in ordergroups) {
|
||||||
|
if (!ordergroups.hasOwnProperty(id)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (customField) {
|
||||||
|
value = ordergroups[id][customField];
|
||||||
|
}
|
||||||
var row = ordergroup.clone();
|
var row = ordergroup.clone();
|
||||||
row.find('td > input').val(value);
|
row.find('td > input').val(value);
|
||||||
row.find('td > select').val(this.value);
|
row.find('td > select').val(id);
|
||||||
row.appendTo('#ordergroups');
|
row.appendTo('#ordergroups');
|
||||||
});
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -61,6 +73,10 @@
|
||||||
%label
|
%label
|
||||||
= check_box_tag :create_financial_link, true, params[:create_financial_link]
|
= check_box_tag :create_financial_link, true, params[:create_financial_link]
|
||||||
= t('.create_financial_link')
|
= t('.create_financial_link')
|
||||||
|
%p
|
||||||
|
- Ordergroup.custom_fields.each do |f|
|
||||||
|
- if f[:financial_transaction_source]
|
||||||
|
= link_to t('.add_all_ordergroups_custom_field', label: f[:label]), '#', 'data-custom-field' => f[:name], 'data-add-all-ordergroups' => true, class: 'btn'
|
||||||
.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
|
||||||
|
|
|
@ -862,6 +862,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
|
||||||
|
add_all_ordergroups_custom_field: Alle Bestellgruppen mit %{label} hinzufügen
|
||||||
create_financial_link: Erstelle einen gemeinsamen Finanzlink für die neuen Transaktionen.
|
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
|
||||||
|
|
|
@ -887,6 +887,7 @@ en:
|
||||||
title: New transaction
|
title: New transaction
|
||||||
new_collection:
|
new_collection:
|
||||||
add_all_ordergroups: Add all ordergroups
|
add_all_ordergroups: Add all ordergroups
|
||||||
|
add_all_ordergroups_custom_field: Add all ordergoups with %{label}
|
||||||
create_financial_link: Create a common financial link for the new transactions.
|
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
|
||||||
|
|
Loading…
Reference in a new issue