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 amount += $(elt).data('invoice-amount');
88 $container.html(kivi.format_amount(amount, 2));
91 ns.init_list = function(ui_tab) {
92 $('#check_all').checkall('INPUT[name^="proposal_ids"]');
94 $('.sort_link').each(function() {
95 var _href = $(this).attr("href");
96 $(this).attr("href", _href + "&filter.fromdate=" + $('#filter_fromdate').val() + "&filter.todate=" + $('#filter_todate').val());
99 $.cookie('jquery_ui_tab_bt_tabs', ui_tab);
102 ns.show_set_all_sources_memos_dialog = function(sources_selector, memos_selector) {
103 var dlg_id = 'set_all_sources_memos_dialog';
104 var $dlg = $('#' + dlg_id);
106 $dlg.data('sources-selector', sources_selector);
107 $dlg.data('memos-selector', memos_selector);
109 $('#set_all_sources').val('');
110 $('#set_all_memos').val('');
115 title: kivi.t8('Set all source and memo fields')
120 ns.set_all_sources_memos = function(sources_selector, memos_selector) {
121 var $dlg = $('#set_all_sources_memos_dialog');
123 ['sources', 'memos'].forEach(function(type) {
124 var value = $('#set_all_' + type).val();
126 $($dlg.data(type + '-selector')).each(function(idx, input) {
131 $dlg.dialog('close');
134 ns.filter_templates = function() {
135 var url="controller.pl?action=BankTransaction/filter_templates&" + $("#create_invoice_window form").serialize();
138 success: function(new_data) {
139 $("#templates").html(new_data.error || new_data.html);