kivitendo/js/kivi.BankTransaction.js @ bc928a5a
96c33451 | Moritz Bunkus | namespace('kivi.BankTransaction', function(ns) {
|
||
"use strict";
|
||||
ns.assign_invoice = function(bank_transaction_id) {
|
||||
kivi.popup_dialog({
|
||||
url: 'controller.pl?action=BankTransaction/assign_invoice',
|
||||
data: '&bt_id=' + bank_transaction_id,
|
||||
type: 'POST',
|
||||
id: 'assign_invoice_window',
|
||||
dialog: { title: kivi.t8('Assign invoice') }
|
||||
});
|
||||
return true;
|
||||
};
|
||||
ns.add_invoices = function(bank_transaction_id, proposal_id) {
|
||||
$.ajax({
|
||||
url: 'controller.pl?action=BankTransaction/ajax_payment_suggestion&bt_id=' + bank_transaction_id + '&prop_id=' + proposal_id,
|
||||
success: function(data) {
|
||||
e9775242 | Moritz Bunkus | $('#assigned_invoices_' + bank_transaction_id + "_" + proposal_id).html(data.html);
|
||
$('#sources_' + bank_transaction_id + "_" + proposal_id + ',' +
|
||||
'#memos_' + bank_transaction_id + "_" + proposal_id).show();
|
||||
$('[data-proposal-id=' + proposal_id + ']').hide();
|
||||
33d579af | Moritz Bunkus | ns.update_invoice_amount(bank_transaction_id);
|
||
96c33451 | Moritz Bunkus | }
|
||
});
|
||||
};
|
||||
ns.delete_invoice = function(bank_transaction_id, proposal_id) {
|
||||
e9775242 | Moritz Bunkus | var $inputs = $('#sources_' + bank_transaction_id + "_" + proposal_id + ',' +
|
||
'#memos_' + bank_transaction_id + "_" + proposal_id);
|
||||
04a484b3 | Moritz Bunkus | $('[data-proposal-id=' + proposal_id + ']').show();
|
||
e9775242 | Moritz Bunkus | $('#assigned_invoices_' + bank_transaction_id + "_" + proposal_id).html('');
|
||
$('#extra_row_' + bank_transaction_id + '_' + proposal_id).remove();
|
||||
$inputs.hide();
|
||||
$inputs.val('');
|
||||
33d579af | Moritz Bunkus | ns.update_invoice_amount(bank_transaction_id);
|
||
96c33451 | Moritz Bunkus | };
|
||
ns.create_invoice = function(bank_transaction_id) {
|
||||
23d55c85 | Bernd Bleßmann | $.post('controller.pl?action=BankTransaction/create_invoice',
|
||
'&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
|
||||
kivi.eval_json_result);
|
||||
};
|
||||
ns.show_create_invoice_dialog = function(dialog_html) {
|
||||
96c33451 | Moritz Bunkus | kivi.popup_dialog({
|
||
23d55c85 | Bernd Bleßmann | html: dialog_html,
|
||
96c33451 | Moritz Bunkus | id: 'create_invoice_window',
|
||
dialog: { title: kivi.t8('Create invoice') }
|
||||
});
|
||||
};
|
||||
ns.filter_invoices = function() {
|
||||
var url="controller.pl?action=BankTransaction/ajax_add_list&" + $("#assign_invoice_window form").serialize();
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(data) {
|
||||
$("#record_list_filtered_list").html(data.html);
|
||||
}
|
||||
});
|
||||
}
|
||||
ns.add_selected_invoices = function() {
|
||||
var bank_transaction_id = $("#assign_invoice_window_form").data("bank-transaction-id");
|
||||
var url ="controller.pl?action=BankTransaction/ajax_accept_invoices&bt_id=" + bank_transaction_id + '&' + $("#assign_invoice_window form").serialize();
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(new_html) {
|
||||
e9775242 | Moritz Bunkus | $('#bt_rows_' + bank_transaction_id).append(new_html);
|
||
96c33451 | Moritz Bunkus | $('#assign_invoice_window').dialog('close');
|
||
33d579af | Moritz Bunkus | ns.update_invoice_amount(bank_transaction_id);
|
||
96c33451 | Moritz Bunkus | }
|
||
});
|
||||
}
|
||||
33d579af | Moritz Bunkus | ns.update_invoice_amount = function(bank_transaction_id) {
|
||
var $container = $('#invoice_amount_' + bank_transaction_id);
|
||||
var amount = $container.data('invoice-amount') * 1;
|
||||
$('[id^="' + bank_transaction_id + '."]').each(function(idx, elt) {
|
||||
798aed39 | Jan Büren | if ($("input[name='skonto_pt." + elt.id + "']").val() == 1) {
|
||
// skonto payment term
|
||||
amount += $(elt).data('invoice-amount-less-skonto');
|
||||
} else {
|
||||
// normal amount
|
||||
amount += $(elt).data('invoice-amount');
|
||||
//subtract free skonto if checked (no check for number!)
|
||||
if ($("input[name='skonto_pt." + elt.id + "']").val() == 'free_skonto') {
|
||||
amount -= $("input[name='free_skonto_amount." + elt.id + "']").val();
|
||||
}
|
||||
}
|
||||
33d579af | Moritz Bunkus | });
|
||
$container.html(kivi.format_amount(amount, 2));
|
||||
};
|
||||
96c33451 | Moritz Bunkus | ns.init_list = function(ui_tab) {
|
||
$('#check_all').checkall('INPUT[name^="proposal_ids"]');
|
||||
33d579af | Moritz Bunkus | |||
96c33451 | Moritz Bunkus | $('.sort_link').each(function() {
|
||
var _href = $(this).attr("href");
|
||||
$(this).attr("href", _href + "&filter.fromdate=" + $('#filter_fromdate').val() + "&filter.todate=" + $('#filter_todate').val());
|
||||
});
|
||||
$.cookie('jquery_ui_tab_bt_tabs', ui_tab);
|
||||
};
|
||||
c4d3f82d | Moritz Bunkus | |||
ns.show_set_all_sources_memos_dialog = function(sources_selector, memos_selector) {
|
||||
var dlg_id = 'set_all_sources_memos_dialog';
|
||||
var $dlg = $('#' + dlg_id);
|
||||
$dlg.data('sources-selector', sources_selector);
|
||||
$dlg.data('memos-selector', memos_selector);
|
||||
$('#set_all_sources').val('');
|
||||
$('#set_all_memos').val('');
|
||||
kivi.popup_dialog({
|
||||
id: dlg_id,
|
||||
dialog: {
|
||||
title: kivi.t8('Set all source and memo fields')
|
||||
}
|
||||
});
|
||||
};
|
||||
ns.set_all_sources_memos = function(sources_selector, memos_selector) {
|
||||
var $dlg = $('#set_all_sources_memos_dialog');
|
||||
['sources', 'memos'].forEach(function(type) {
|
||||
var value = $('#set_all_' + type).val();
|
||||
if (value !== '')
|
||||
$($dlg.data(type + '-selector')).each(function(idx, input) {
|
||||
$(input).val(value);
|
||||
});
|
||||
});
|
||||
$dlg.dialog('close');
|
||||
};
|
||||
32dc7476 | Moritz Bunkus | |||
ns.filter_templates = function() {
|
||||
var url="controller.pl?action=BankTransaction/filter_templates&" + $("#create_invoice_window form").serialize();
|
||||
$.ajax({
|
||||
url: url,
|
||||
success: function(new_data) {
|
||||
$("#templates").html(new_data.error || new_data.html);
|
||||
}
|
||||
});
|
||||
};
|
||||
6c0095f1 | Jan Büren | ns.update_skonto = function(caller, bt_id, prop_id, formatted_amount_with_skonto_pt) {
|
||
798aed39 | Jan Büren | |||
6c0095f1 | Jan Büren | if (caller.value === 'free_skonto') {
|
||
$('#free_skonto_amount_' + bt_id + '_' + prop_id).val("");
|
||||
$('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', false);
|
||||
798aed39 | Jan Büren | $("input[name='skonto_pt." + bt_id + '.' + prop_id + "']").val('free_skonto');
|
||
6c0095f1 | Jan Büren | $('#free_skonto_amount_' + bt_id + '_' + prop_id).focus();
|
||
}
|
||||
if (caller.value === 'without_skonto') {
|
||||
$('#free_skonto_amount_' + bt_id + '_' + prop_id).val(kivi.format_amount(0,2));
|
||||
$('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', true);
|
||||
798aed39 | Jan Büren | $("input[name='skonto_pt." + bt_id + '.' + prop_id + "']").val(0);
|
||
6c0095f1 | Jan Büren | }
|
||
if (caller.value === 'with_skonto_pt') {
|
||||
$('#free_skonto_amount_' + bt_id + '_' + prop_id).val(formatted_amount_with_skonto_pt);
|
||||
$('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', true);
|
||||
798aed39 | Jan Büren | $("input[name='skonto_pt." + bt_id + '.' + prop_id + "']").val(1);
|
||
6c0095f1 | Jan Büren | }
|
||
798aed39 | Jan Büren | // recalc assigned amount
|
||
ns.update_invoice_amount(bt_id);
|
||||
6c0095f1 | Jan Büren | };
|
||
96c33451 | Moritz Bunkus | });
|