1 namespace('kivi.BankTransaction', function(ns) {
4 ns.assign_invoice = function(bank_transaction_id) {
6 url: 'controller.pl?action=BankTransaction/assign_invoice',
7 data: '&bt_id=' + bank_transaction_id,
9 id: 'assign_invoice_window',
10 dialog: { title: kivi.t8('Assign invoice') }
15 ns.add_invoices = function(bank_transaction_id, proposal_id) {
18 url: 'controller.pl?action=BankTransaction/ajax_payment_suggestion&bt_id=' + bank_transaction_id + '&prop_id=' + proposal_id,
19 success: function(data) {
20 $('#assigned_invoices_' + bank_transaction_id + "_" + proposal_id).html(data.html);
21 $('#sources_' + bank_transaction_id + "_" + proposal_id + ',' +
22 '#memos_' + bank_transaction_id + "_" + proposal_id).show();
23 $('[data-proposal-id=' + proposal_id + ']').hide();
25 ns.update_invoice_amount(bank_transaction_id);
30 ns.delete_invoice = function(bank_transaction_id, proposal_id) {
31 var $inputs = $('#sources_' + bank_transaction_id + "_" + proposal_id + ',' +
32 '#memos_' + bank_transaction_id + "_" + proposal_id);
34 $('[data-proposal-id=' + proposal_id + ']').show();
35 $('#assigned_invoices_' + bank_transaction_id + "_" + proposal_id).html('');
36 $('#extra_row_' + bank_transaction_id + '_' + proposal_id).remove();
41 ns.update_invoice_amount(bank_transaction_id);
44 ns.create_invoice = function(bank_transaction_id) {
46 url: 'controller.pl?action=BankTransaction/create_invoice',
47 data: '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
49 id: 'create_invoice_window',
50 dialog: { title: kivi.t8('Create invoice') }
56 ns.filter_invoices = function() {
57 var url="controller.pl?action=BankTransaction/ajax_add_list&" + $("#assign_invoice_window form").serialize();
60 success: function(data) {
61 $("#record_list_filtered_list").html(data.html);
66 ns.add_selected_invoices = function() {
67 var bank_transaction_id = $("#assign_invoice_window_form").data("bank-transaction-id");
68 var url ="controller.pl?action=BankTransaction/ajax_accept_invoices&bt_id=" + bank_transaction_id + '&' + $("#assign_invoice_window form").serialize();
72 success: function(new_html) {
73 $('#bt_rows_' + bank_transaction_id).append(new_html);
74 $('#assign_invoice_window').dialog('close');
75 ns.update_invoice_amount(bank_transaction_id);
80 ns.update_invoice_amount = function(bank_transaction_id) {
81 var $container = $('#invoice_amount_' + bank_transaction_id);
82 var amount = $container.data('invoice-amount') * 1;
84 $('[id^="' + bank_transaction_id + '."]').each(function(idx, elt) {
85 if ($("input[name='skonto_pt." + elt.id + "']").val() == 1) {
86 // skonto payment term
87 amount += $(elt).data('invoice-amount-less-skonto');
90 amount += $(elt).data('invoice-amount');
91 //subtract free skonto if checked (no check for number!)
92 if ($("input[name='skonto_pt." + elt.id + "']").val() == 'free_skonto') {
93 amount -= $("input[name='free_skonto_amount." + elt.id + "']").val();
98 $container.html(kivi.format_amount(amount, 2));
101 ns.init_list = function(ui_tab) {
102 $('#check_all').checkall('INPUT[name^="proposal_ids"]');
104 $('.sort_link').each(function() {
105 var _href = $(this).attr("href");
106 $(this).attr("href", _href + "&filter.fromdate=" + $('#filter_fromdate').val() + "&filter.todate=" + $('#filter_todate').val());
109 $.cookie('jquery_ui_tab_bt_tabs', ui_tab);
112 ns.show_set_all_sources_memos_dialog = function(sources_selector, memos_selector) {
113 var dlg_id = 'set_all_sources_memos_dialog';
114 var $dlg = $('#' + dlg_id);
116 $dlg.data('sources-selector', sources_selector);
117 $dlg.data('memos-selector', memos_selector);
119 $('#set_all_sources').val('');
120 $('#set_all_memos').val('');
125 title: kivi.t8('Set all source and memo fields')
130 ns.set_all_sources_memos = function(sources_selector, memos_selector) {
131 var $dlg = $('#set_all_sources_memos_dialog');
133 ['sources', 'memos'].forEach(function(type) {
134 var value = $('#set_all_' + type).val();
136 $($dlg.data(type + '-selector')).each(function(idx, input) {
141 $dlg.dialog('close');
144 ns.filter_templates = function() {
145 var url="controller.pl?action=BankTransaction/filter_templates&" + $("#create_invoice_window form").serialize();
148 success: function(new_data) {
149 $("#templates").html(new_data.error || new_data.html);
153 ns.update_skonto = function(caller, bt_id, prop_id, formatted_amount_with_skonto_pt) {
155 if (caller.value === 'free_skonto') {
156 $('#free_skonto_amount_' + bt_id + '_' + prop_id).val("");
157 $('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', false);
158 $("input[name='skonto_pt." + bt_id + '.' + prop_id + "']").val('free_skonto');
159 $('#free_skonto_amount_' + bt_id + '_' + prop_id).focus();
161 if (caller.value === 'without_skonto') {
162 $('#free_skonto_amount_' + bt_id + '_' + prop_id).val(kivi.format_amount(0,2));
163 $('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', true);
164 $("input[name='skonto_pt." + bt_id + '.' + prop_id + "']").val(0);
166 if (caller.value === 'with_skonto_pt') {
167 $('#free_skonto_amount_' + bt_id + '_' + prop_id).val(formatted_amount_with_skonto_pt);
168 $('#free_skonto_amount_' + bt_id + '_' + prop_id).prop('disabled', true);
169 $("input[name='skonto_pt." + bt_id + '.' + prop_id + "']").val(1);
171 // recalc assigned amount
172 ns.update_invoice_amount(bt_id);