Kontoauszug verbuchen: Spalte »Zugewiesen« bei Zuweisungsänderung neu berechnen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 30 Jan 2017 13:24:00 +0000 (14:24 +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
templates/webpages/bank_transactions/invoices.html
templates/webpages/bank_transactions/tabs/all.html

index f413b73..e416998 100644 (file)
@@ -337,8 +337,8 @@ sub action_ajax_payment_suggestion {
                                      value_key => 'payment_type',
                                      title_key => 'display' )
     if @select_options;
-  $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});
+  $html .= SL::Presenter->html_tag('a', 'x', href => '#', onclick => "kivi.BankTransaction.delete_invoice(" . $::form->{bt_id} . ',' . $::form->{prop_id} . ")");
+  $html = SL::Presenter->html_tag('div', $html, id => $::form->{bt_id} . '.' . $::form->{prop_id}, 'data-invoice-amount' => $invoice->open_amount * 1);
 
   $self->render(\ SL::JSON::to_json( { 'html' => $html } ), { layout => 0, type => 'json', process => 0 });
 };
index 08f5133..7e3fb2e 100644 (file)
@@ -19,6 +19,7 @@ namespace('kivi.BankTransaction', function(ns) {
       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.update_invoice_amount(bank_transaction_id);
       }
     });
   };
@@ -26,6 +27,7 @@ namespace('kivi.BankTransaction', function(ns) {
   ns.delete_invoice = function(bank_transaction_id, proposal_id) {
     $( "#" + bank_transaction_id + "\\." + proposal_id ).remove();
     $('[data-proposal-id=' + proposal_id + ']').show();
+    ns.update_invoice_amount(bank_transaction_id);
   };
 
   ns.create_invoice = function(bank_transaction_id) {
@@ -59,12 +61,25 @@ namespace('kivi.BankTransaction', function(ns) {
       success: function(new_html) {
         $('#assigned_invoices_' + bank_transaction_id).append(new_html);
         $('#assign_invoice_window').dialog('close');
+        ns.update_invoice_amount(bank_transaction_id);
       }
     });
   }
 
+  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) {
+      amount += $(elt).data('invoice-amount');
+    });
+
+    $container.html(kivi.format_amount(amount, 2));
+  };
+
   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());
index 6f251f9..4605a60 100644 (file)
@@ -1,8 +1,8 @@
 [% USE L %]
 [% USE T8 %]
-[% USE LxERP %]
+[% USE LxERP %][%- USE HTML -%]
 [% FOREACH invoice = INVOICES %]
-  <div id="[% bt_id %].[% invoice.id %]">
+  <div id="[% bt_id %].[% invoice.id %]" data-invoice-amount="[% HTML.escape(invoice.open_amount * 1) %]">
     [% L.hidden_tag('invoice_ids.' _ bt_id _'[]', invoice.id) %]
     [% 'Invno.' | $T8 %]: [% invoice.invnumber %]
     [% 'Open amount' | $T8 %]: [% LxERP.format_amount(invoice.open_amount, 2) %]
index 529b1dc..c7c3b8d 100644 (file)
@@ -99,7 +99,7 @@
      </td>
      <td align=right>[% bt.transdate_as_date %]</td>
      <td align=right>[% LxERP.format_amount(bt.amount, 2) %]</td>
-     <td align=right>[% LxERP.format_amount(bt.invoice_amount, 2) %]</td>
+     <td align=right id="invoice_amount_[% HTML.escape(bt.id) %]" data-invoice-amount="[% HTML.escape(bt.invoice_amount) %]">[% HTML.escape(LxERP.format_amount(bt.invoice_amount, 2)) %]</td>
      <td>[% HTML.escape(bt.remote_name) %]</td>
      <td>[% HTML.escape(bt.purpose) %]</td>
      <td>[% HTML.escape(bt.transaction_text) %]</td>