a3defc5463
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.
82 lines
3 KiB
Text
82 lines
3 KiB
Text
- title t('.title')
|
|
|
|
- content_for :javascript do
|
|
:javascript
|
|
var ordergroup = $($.parseHTML("#{escape_javascript(render('ordergroup'))}"));
|
|
var ordergroups = #{raw @ordergroups.to_json};
|
|
|
|
$(function() {
|
|
$(document).on('touchclick', 'a[data-remove-transaction]', function() {
|
|
$(this).parents('tr').remove();
|
|
return false;
|
|
});
|
|
|
|
$(document).on('touchclick', 'a[data-add-transaction]', function() {
|
|
ordergroup.clone().appendTo('#ordergroups');
|
|
return false;
|
|
});
|
|
|
|
$(document).on('touchclick', 'a[data-add-all-ordergroups]', function() {
|
|
var customField = $(this).data('custom-field');
|
|
var value;
|
|
if (!customField) {
|
|
value = prompt("#{escape_javascript(heading_helper(FinancialTransaction, :amount))}:");
|
|
if (value === null) {
|
|
return false;
|
|
}
|
|
}
|
|
$('#ordergroups > tbody > tr').remove();
|
|
for (var id in ordergroups) {
|
|
if (!ordergroups.hasOwnProperty(id)) {
|
|
continue;
|
|
}
|
|
if (customField) {
|
|
value = ordergroups[id][customField];
|
|
}
|
|
var row = ordergroup.clone();
|
|
row.find('td > input').val(value);
|
|
row.find('td > select').val(id);
|
|
row.appendTo('#ordergroups');
|
|
}
|
|
return false;
|
|
});
|
|
});
|
|
|
|
- content_for :sidebar do
|
|
.well.well-small= t('.sidebar')
|
|
|
|
= form_tag finance_create_transaction_collection_path do
|
|
- if FinancialTransactionType.has_multiple_types
|
|
%p
|
|
%b= heading_helper FinancialTransaction, :financial_transaction_type
|
|
= select_tag :type_id, options_for_select(FinancialTransactionType.order(:name).map { |t| [ t.name, t.id ] }, params[:type_id])
|
|
%p
|
|
%b= heading_helper FinancialTransaction, :note
|
|
= 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
|
|
%table#ordergroups{:style => "width:20em"}
|
|
%thead
|
|
%tr
|
|
%th= heading_helper FinancialTransaction, :ordergroup
|
|
%th= heading_helper FinancialTransaction, :amount
|
|
%tbody
|
|
= render :partial => 'ordergroup', :collection => [1, 2, 3]
|
|
%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')
|
|
%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
|
|
= submit_tag t('.save'), class: 'btn btn-primary'
|
|
= link_to t('ui.or_cancel'), finance_ordergroups_path
|