Kontoauszug verbuchen: JavaScript-Code in eigene js-Datei ausgelagert
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 30 Jan 2017 11:57:51 +0000 (12:57 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 31 Jan 2017 13:14:46 +0000 (14:14 +0100)
SL/Controller/BankTransaction.pm
js/kivi.BankTransaction.js [new file with mode: 0644]
templates/webpages/bank_transactions/assign_invoice.html
templates/webpages/bank_transactions/invoices.html
templates/webpages/bank_transactions/list.html
templates/webpages/bank_transactions/tabs/all.html

index 98975e9..f413b73 100644 (file)
@@ -252,7 +252,7 @@ sub action_list {
   $bank_transactions = [ sort { $a->{agreement} <=> $b->{agreement} } @{ $bank_transactions } ] if $::form->{sort_by} eq 'proposal' and $::form->{sort_dir} == 1;
   $bank_transactions = [ sort { $b->{agreement} <=> $a->{agreement} } @{ $bank_transactions } ] if $::form->{sort_by} eq 'proposal' and $::form->{sort_dir} == 0;
 
-
+  $::request->layout->add_javascripts("kivi.BankTransaction.js");
   $self->render('bank_transactions/list',
                 title             => t8('Bank transactions MT940'),
                 BANK_TRANSACTIONS => $bank_transactions,
@@ -337,7 +337,7 @@ sub action_ajax_payment_suggestion {
                                      value_key => 'payment_type',
                                      title_key => 'display' )
     if @select_options;
-  $html .= '<a href=# onclick="delete_invoice(' . $::form->{bt_id} . ',' . $::form->{prop_id} . ');">x</a>';
+  $html .= '<a href=# onclick="kivi.BankTransaction.delete_invoice(' . $::form->{bt_id} . ',' . $::form->{prop_id} . ');">x</a>';
   $html = SL::Presenter->html_tag('div', $html, id => $::form->{bt_id} . '.' . $::form->{prop_id});
 
   $self->render(\ SL::JSON::to_json( { 'html' => $html } ), { layout => 0, type => 'json', process => 0 });
diff --git a/js/kivi.BankTransaction.js b/js/kivi.BankTransaction.js
new file mode 100644 (file)
index 0000000..730e07a
--- /dev/null
@@ -0,0 +1,74 @@
+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) {
+    $('[name=' + proposal_id + ']').remove();
+
+    $.ajax({
+      url: 'controller.pl?action=BankTransaction/ajax_payment_suggestion&bt_id=' + bank_transaction_id  + '&prop_id=' + proposal_id,
+      success: function(data) {
+        $('#assigned_invoices_' + bank_transaction_id).append(data.html);
+      }
+    });
+  };
+
+  ns.delete_invoice = function(bank_transaction_id, proposal_id) {
+    $( "#" + bank_transaction_id + "\\." + proposal_id ).remove();
+  };
+
+  ns.create_invoice = function(bank_transaction_id) {
+    kivi.popup_dialog({
+      url:    'controller.pl?action=BankTransaction/create_invoice',
+      data:   '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bankaccount').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
+      type:   'POST',
+      id:     'create_invoice_window',
+      dialog: { title: kivi.t8('Create invoice') }
+    });
+    return true;
+  };
+
+
+  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) {
+        $('#assigned_invoices_' + bank_transaction_id).append(new_html);
+        $('#assign_invoice_window').dialog('close');
+      }
+    });
+  }
+
+  ns.init_list = function(ui_tab) {
+    $('#check_all').checkall('INPUT[name^="proposal_ids"]');
+    $('.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);
+  };
+});
index 967a1ea..d169c35 100644 (file)
@@ -2,7 +2,7 @@
 
 [% SET debug = 0 %]
 
-<form method="post" action="javascript:filter_invoices();" id="assign_invoice_window_form">
+<form method="post" action="javascript:kivi.BankTransaction.filter_invoices();" id="assign_invoice_window_form" data-bank-transaction-id="[% HTML.escape(SELF.transaction.id) %]">
   <b>[%- LxERP.t8("Bank transaction") %]:</b>
   <table>
    <tr class="listheading">
@@ -55,7 +55,7 @@
 
   <p>
    [% L.submit_tag('', LxERP.t8("Search")) %]
-   [% L.button_tag('add_selected_invoices()', LxERP.t8("Add invoices"), id='add_selected_record_links_button') %]
+   [% L.button_tag('kivi.BankTransaction.add_selected_invoices()', LxERP.t8("Add invoices"), id='add_selected_record_links_button') %]
    [% L.button_tag('$("#assign_invoice_window_form").resetForm()', LxERP.t8('Reset')) %]
    <a href="#" onclick="$('#assign_invoice_window').dialog('close');">[% LxERP.t8("Cancel") %]</a>
   </p>
 
 <script type="text/javascript">
 <!--
-
-function filter_invoices() {
-  var url="controller.pl?action=BankTransaction/ajax_add_list&" + $("#assign_invoice_window form").serialize();
-  $.ajax({
-    url: url,
-    success: function(new_data) {
-      $("#record_list_filtered_list").html(new_data['html']);
-    }
-  });
-}
-
-function add_selected_invoices() {
-  var url="controller.pl?action=BankTransaction/ajax_accept_invoices&" + 'bt_id=[% SELF.transaction.id %]&' + $("#assign_invoice_window form").serialize();
-  $.ajax({
-    url: url,
-    success: function(new_html) {
-      var invoices = document.getElementById('assigned_invoices_[% SELF.transaction.id %]');
-      if (invoices.innerHTML == '') {
-        invoices.innerHTML = new_html;
-      } else {
-        invoices.innerHTML += '<br />' + new_html;
-      }
-      $('#assign_invoice_window').dialog('close');
-    }
-  });
-}
-
 $(function() {
   $('#invnumber').focus();
 });
index dfa1b6f..6f251f9 100644 (file)
@@ -6,6 +6,6 @@
     [% L.hidden_tag('invoice_ids.' _ bt_id _'[]', invoice.id) %]
     [% 'Invno.' | $T8 %]: [% invoice.invnumber %]
     [% 'Open amount' | $T8 %]: [% LxERP.format_amount(invoice.open_amount, 2) %]
-    <a href=# onclick="delete_invoice([% bt_id %], [% invoice.id %])">x</a>
+    <a href=# onclick="kivi.BankTransaction.delete_invoice([% bt_id %], [% invoice.id %])">x</a>
   </div>
 [% END %]
index 54351a9..d5abbcd 100644 (file)
@@ -12,6 +12,9 @@
 <p>
 [% IF FORM.filter.fromdate %] [% 'From' | $T8 %] [% FORM.filter.fromdate %] [% END %]
 [% IF FORM.filter.todate %]   [% 'to (date)' | $T8 %] [% FORM.filter.todate %][% END %]
+[% L.hidden_tag("filter_bankaccount", FORM.filter.bankaccount) %]
+[% L.hidden_tag("filter_fromdate", FORM.filter.fromdate) %]
+[% L.hidden_tag("filter_todate", FORM.filter.todate) %]
 </p>
 
 <div id="bt_tabs" class="tabwidget">
 
 <script type="text/javascript">
 <!--
-
 $(function() {
-  $('#check_all').checkall('INPUT[name^="proposal_ids"]');
+  kivi.BankTransaction.init_list([% ui_tab %]);
 });
-
-$(function() {
-  $('.sort_link').each(function() {
-    var _href = $(this).attr("href");
-    $(this).attr("href", _href + "&filter.fromdate=" + "[% FORM.filter.fromdate %]" + "&filter.todate=" + "[% FORM.filter.todate %]");
-  });
-});
-
-function assign_invoice(bt_id) {
-  kivi.popup_dialog({
-    url:    'controller.pl?action=BankTransaction/assign_invoice',
-    data:   '&bt_id=' + bt_id,
-    type:   'POST',
-    id:     'assign_invoice_window',
-    dialog: { title: kivi.t8('Assign invoice') }
-  });
-  return true;
-}
-
-function add_invoices(bt_id, prop_id, prop_invnumber) {
-  // prop_id is a proposed invoice_id
-  // remove the added invoice from all the other suggestions
-  var number_of_elements = document.getElementsByName(prop_id).length;
-  for( var i = 0; i < number_of_elements; i++ ) {
-    var node = document.getElementsByName(prop_id)[0];
-    node.parentNode.removeChild(node);
-  }
-  var invoices = document.getElementById('assigned_invoices_' + bt_id);
-
-  $.ajax({
-    url: 'controller.pl?action=BankTransaction/ajax_payment_suggestion&bt_id=' + bt_id  + '&prop_id=' + prop_id,
-    success: function(data) {
-      invoices.innerHTML += data.html;
-    }
-  });
-}
-
-function delete_invoice(bt_id, prop_id) {
-  $( "#" + bt_id + "\\." + prop_id ).remove();
-}
-
-function create_invoice(bt_id) {
-  kivi.popup_dialog({
-    url:    'controller.pl?action=BankTransaction/create_invoice',
-    data:   '&bt_id=' + bt_id + "&filter.bank_account=[% FORM.filter.bank_account %]&filter.todate=[% FORM.filter.todate %]&filter.fromdate=[% FORM.filter.fromdate %]",
-    type:   'POST',
-    id:     'create_invoice_window',
-    dialog: { title: kivi.t8('Create invoice') }
-  });
-  return true;
-}
-
-$.cookie('jquery_ui_tab_bt_tabs', [% ui_tab %] );
 //-->
 </script>
index 8b7efdf..04287be 100644 (file)
@@ -83,8 +83,8 @@
   <tbody>
    [%- FOREACH bt = BANK_TRANSACTIONS %]
     <tr class="listrow" id="bt_id_[% bt.id %]">
-     <td><a href=# onclick="assign_invoice('[% bt.id %]'); return false;">[% 'Assign invoice' | $T8 %]</a></td>
-     <td><a href=# onclick="create_invoice('[% bt.id %]'); return false;">[% 'Create invoice' | $T8 %]</a></td>
+     <td><a href=# onclick="kivi.BankTransaction.assign_invoice('[% bt.id %]'); return false;">[% 'Assign invoice' | $T8 %]</a></td>
+     <td><a href=# onclick="kivi.BankTransaction.create_invoice('[% bt.id %]'); return false;">[% 'Create invoice' | $T8 %]</a></td>
      <td id="assigned_invoices_[% bt.id %]" nowrap></td>
      [% IF debug %]
      <td class="tooltipster-html" title="[% FOREACH match = bt.rule_matches %] [% match %]<br> [% END %]">[% bt.agreement %]</td>
@@ -92,7 +92,7 @@
      <td>
       [% FOREACH prop = bt.proposals %]
         <div name='[% prop.id %]'>
-         <a href=# onclick="add_invoices('[% bt.id %]', '[% prop.id %]', '[% HTML.escape(prop.invnumber) %]');"
+         <a href=# onclick="kivi.BankTransaction.add_invoices('[% bt.id %]', '[% prop.id %]');"
             title="<table><tr><th></th><th>[% 'Suggested invoice' | $T8 %][% IF !prop.is_sales %] ([% 'AP' | $T8 %])[% END %]</th><th>[% 'Bank transaction' | $T8 %]</th></tr><tr><th>[% 'Amount' | $T8 %]</th><td>[% prop.realamount %] ([% 'open' | $T8 %]: [% LxERP.format_amount(prop.open_amount, 2) %])</td><td>[% LxERP.format_amount(bt.amount, 2) %]</td></tr>[% IF prop.skonto_date %]<tr><th>[% 'Payment terms' | $T8 %]</th><td>[% LxERP.format_amount(prop.amount_less_skonto, 2) %] [% 'until' | $T8 %] [% HTML.escape(prop.skonto_date.to_kivitendo) %] ([% prop.percent_skonto * 100 %] %)</td><td></td></tr>[% END %]<tr><th>[% 'Customer/Vendor' | $T8 %]</th><td>[% HTML.escape(prop.customer.displayable_name) %][% HTML.escape(prop.vendor.displayable_name) %]</td><td>[% HTML.escape(bt.remote_name) %]</td></tr><tr><th>[% 'Invoice Date' | $T8 %]</th><td>[% HTML.escape(prop.transdate_as_date) %]</td><td>[% HTML.escape(bt.transdate_as_date) %] ([% HTML.escape(bt.transdate.utc_rd_days - prop.transdate.utc_rd_days) %])</td></tr><tr><th>[% 'Invoice Number' | $T8 %]</th><td>[% HTML.escape(prop.invnumber) %]</td><td>[% HTML.escape(bt.purpose) %]</td></tr></table>"
               class="[% IF bt.agreement >= 5 %]green[% ELSIF bt.agreement < 5 and bt.agreement >= 3 %]orange[% ELSE %]red[% END %] tooltipster-html">&larr;[% HTML.escape(prop.invnumber)%]</a></div>
       [% END %]