commit f3a5bf8aa2fc64ad73eae45e4d0e28e070f5c55e
Author: Martin Helmling <martin.helmling@octosoft.eu>
Date:   Tue Feb 23 13:26:43 2016 +0100

    SEPA-Überweisungen: GUI-Verbesserung #2
    
    1. Sortierung der Liste nach Fälligkeitsdatum:
    - Für Rechnungen deren Skonto-Datum nicht überschritten wurde wird als Fälligkeitsdatum das Skontodatum verwendet
      und die Rechnung entsprechend dort einsortiert, unter den Zahlungsbedingungen wird dann auch das Fälligkeitsdatum ohne Skonto angezeigt
    - Für Rechnungen deren Skonto-Datum überschritten wurde - nur nach Fälligkeitsdatum wie gehabt
    
    2. Aktivieren/Deaktivieren der Checkbox durch anklicken der ganzen Zeile
    
    3. Einblenden der Summe der Überweisungsbeträge (oben), permanente Aktualisierung der Summe
    3.1 bei Checkbox Änderung (auch alle An/Aus)
    3.2 bei Betragänderung
    3.3 bei Auswahl anderer Skontobedingung
    
    4. Bankkonto-Auswahl in einer Zeile unterbringen, dazu
    - Text Ändern in "Bankkonto als Quelle für Überweisungen:" (bei Bankeinzügen: Bankkonto als Ziel für Einzüge)
    - danach Pulldownliste ohne Zeilenumbruch dazwischen
    - "Überweisungsbetrag" weiter nach Rechts, ca. in Höhe von der Spalte "Überweisungsbetrag"
    
    5. Spaltenüberschrift "Überweisungs-betrag" kürzen in "Zahlungs-Betrag", Spaltenbreite verringert.
    
    6. Optische Erkennung durch Grünfärbung der Buchungen bis aktuellem Termin
    
    7.  In "Schritt Zwei" - (Überprüfung der Kontoinformationen):
    - Spalte Kontoinhaber passt sich dynamisch der Breite von Lieferant an
    
    -- Herausnahme des Setzens der Zahlungsbedingungen
    fix #4483

diff --git a/bin/mozilla/sepa.pl b/bin/mozilla/sepa.pl
index 601fa7fd8..c31ac7972 100755
--- a/bin/mozilla/sepa.pl
+++ b/bin/mozilla/sepa.pl
@@ -54,7 +54,9 @@ sub bank_transfer_add {
   my $translation_list = GenericTranslations->list(translation_type => 'sepa_remittance_info_pfx');
   my %translations     = map { ( ($_->{language_id} || 'default') => $_->{translation} ) } @{ $translation_list };
   my $current_date     = DateTime->today_local;
-
+  my %sorted_invoices;
+  my $sec = 0;
+  
   foreach my $invoice (@{ $invoices }) {
     my $prefix                    = $translations{ $invoice->{language_id} } || $translations{default} || $::locale->text('Invoice');
     $prefix                      .= ' ' unless $prefix =~ m/ $/;
@@ -66,13 +68,34 @@ sub bank_transfer_add {
     my $prefix_vc_number             = $translations{ $invoice->{language_id} } || $translations{default} || $vc_no;
     $prefix_vc_number               .= ' ' unless $prefix_vc_number =~ m/ $/;
     $invoice->{reference_prefix_vc}  = ' '  . $prefix_vc_number unless $prefix_vc_number =~ m/^ /;
-  }
 
+    my $vc_prefix                 = $invoice->{vc_number} eq '' ? ''
+                                  : $vc eq 'customer'           ? $translations{ $invoice->{language_id} } || $translations{default} || ' ' . $::locale->text('Ven.nr.')  . ' '
+                                  :                               $translations{ $invoice->{language_id} } || $translations{default} || ' ' . $::locale->text('Cust.nr.') . ' ';
+    $invoice->{vc_prefix}         = $vc_prefix;
+
+    # Check due date for SEPA bank collections.
+    if ((DateTime->from_kivitendo($invoice->{duedate}) < $current_date) && ($vc eq 'customer')) {
+      $invoice->{vc_bank_info_ok}   = '2' if  $invoice->{vc_bank_info_ok};
+    }
+    $invoice->{duedate} = $invoice->{transdate} if !$invoice->{duedate};
+    $invoice->{is_before_today} = 0;
+    if ( $invoice->{within_skonto_period} ) {
+        $invoice->{is_before_today} = 1 if DateTime->from_kivitendo($invoice->{skonto_date}) <= $current_date;
+        $sorted_invoices{DateTime->from_kivitendo($invoice->{skonto_date})->add_duration(DateTime::Duration->new(seconds => $sec))} = $invoice;
+    } else {
+        $invoice->{is_before_today} = 1 if DateTime->from_kivitendo($invoice->{duedate}) <= $current_date;
+        $sorted_invoices{DateTime->from_kivitendo($invoice->{duedate})->add_duration(DateTime::Duration->new(seconds => $sec))} = $invoice;
+    }
+    $sec++;
+  }
+  my $newinvoices;
+  @{ $newinvoices } = map { $sorted_invoices{$_} } sort keys %sorted_invoices;
   $::request->layout->use_javascript('js/kivi.Sepa.js');
 
   $form->header();
   print $form->parse_html_template('sepa/bank_transfer_add',
-                                   { 'INVOICES'           => $invoices,
+                                   { 'INVOICES'           => $newinvoices,
                                      'BANK_ACCOUNTS'      => $bank_accounts,
                                      'vc'                 => $vc,
                                      'show_empty'         => $show_empty,
diff --git a/js/kivi.Sepa.js b/js/kivi.Sepa.js
index d0631616e..6dba46816 100644
--- a/js/kivi.Sepa.js
+++ b/js/kivi.Sepa.js
@@ -1,5 +1,5 @@
 namespace('kivi.Sepa', function(ns) {
-  this.paymentTypeChanged = function() {
+  ns.paymentTypeChanged = function() {
     var type_id = $(this).attr('id');
     var id      = type_id.match(/\d*$/);
 
@@ -13,9 +13,10 @@ namespace('kivi.Sepa', function(ns) {
 
     else if ( $(this).val() == "with_skonto_pt" )
       $('#' + id).val( $('#amount_less_skonto_' + id).val() );
+    kivi.Sepa.updateSumAmount();
   };
 
-  this.verifyBankAccountSelected = function() {
+  ns.verifyBankAccountSelected = function() {
     if ($('#bank_account').val())
       return true;
 
@@ -23,9 +24,35 @@ namespace('kivi.Sepa', function(ns) {
     return false;
   };
 
-  this.initBankTransferAdd = function(vc) {
+  ns.selectRow = function(elem) {
+    if ( elem.target.localName != 'td' )
+	return true;
+    if ($(this).find('INPUT[name="bank_transfers[].selected"]').prop('checked'))
+      $(this).find('INPUT[name="bank_transfers[].selected"]').prop('checked', false);
+    else
+      $(this).find('INPUT[name="bank_transfers[].selected"]').prop('checked', true);
+    kivi.Sepa.updateSumAmount();
+    return false;
+  };
+
+  ns.updateSumAmount = function() {
+    var sum_amount=0;
+    $('INPUT[name="bank_transfers[].selected"]:checked').each(function(idx,elem)
+       {
+	   var $trans = $(elem).closest('tr').find('INPUT[name="bank_transfers[].amount"]');
+           sum_amount += kivi.parse_amount($trans.val());
+       });
+    $('#sepa_sum_amount').text(kivi.format_amount(sum_amount,2));
+    return false;
+  };
+
+  ns.initBankTransferAdd = function(vc) {
     $("#select_all").checkall('INPUT[name="bank_transfers[].selected"]');
+    $("#select_all").change(kivi.Sepa.updateSumAmount);
+    $('INPUT[name="bank_transfers[].selected"]').change(kivi.Sepa.updateSumAmount);
+    $('INPUT[name="bank_transfers[].amount"]').change(kivi.Sepa.updateSumAmount);
     $(".type_target").change(kivi.Sepa.paymentTypeChanged);
+    $('.invoice_row').click(kivi.Sepa.selectRow);
     $('[type=submit]').click(kivi.Sepa.verifyBankAccountSelected);
   };
 });
diff --git a/locale/de/all b/locale/de/all
index 3b32782fe..6127e1877 100644
--- a/locale/de/all
+++ b/locale/de/all
@@ -390,7 +390,7 @@ $self->{texts} = {
   'Bank transfer amount'        => 'Überweisungssumme',
   'Bank transfer payment list for export #1' => 'Überweisungszahlungsliste für SEPA-Export #1',
   'Bank transfer via SEPA'      => 'Überweisung via SEPA',
-  'Bank transfer<br>amount'     => 'Überweisungs-<br>betrag',
+  'Bank transfer<br>amount'     => 'Zahlungs-<br>betrag',
   'Bank transfers via SEPA'     => 'Überweisungen via SEPA',
   'Base unit'                   => 'Basiseinheit',
   'Basic Data'                  => 'Basisdaten',
@@ -946,6 +946,7 @@ $self->{texts} = {
   'Description of #1'           => 'Beschreibung von #1',
   'Destination BIC'             => 'Ziel-BIC',
   'Destination IBAN'            => 'Ziel-IBAN',
+  'Destination bank account for the collections:' => 'Bankkonto als Ziel für Einzüge:',
   'Destination bin'             => 'Ziellagerplatz',
   'Destination warehouse'       => 'Ziellager',
   'Destination warehouse and bin' => 'Ziellager und -lagerplatz',
@@ -2706,6 +2707,7 @@ $self->{texts} = {
   'Source BIC'                  => 'Quell-BIC',
   'Source IBAN'                 => 'Quell-IBAN',
   'Source bank account'         => 'Quellkonto',
+  'Source bank account for the transfers:' => 'Bankkonto als Quelle für Überweisungen:',
   'Source bin'                  => 'Quelllagerplatz',
   'Space'                       => 'Leerzeichen',
   'Split entry detected. The values you have entered will result in an entry with more than one position on both debit and credit. Due to known problems involving accounting software kivitendo does not allow these.' => 'Splitbuchung! Die eingebenen Werte würden eine Buchung auslösen, die jeweils mehr als eine Position auf Soll und Haben hätte. Um Kompatibilität mit DATEV zu gewährleisten erlaubt kivitendo keine Splitbuchungen.',
@@ -3586,6 +3588,7 @@ $self->{texts} = {
   'You do not have permission to access this entry.' => 'Sie verfügen nicht über die Berechtigung, auf diesen Eintrag zuzugreifen.',
   'You do not have the permissions to access this function.' => 'Sie verfügen nicht über die notwendigen Rechte, um auf diese Funktion zuzugreifen.',
   'You don\'t have the rights to edit this customer.' => 'Sie verfügen nicht über die erforderlichen Rechte, um diesen Kunden zu bearbeiten.',
+  'You have changed the currency. Please check and corrrect prices if necessary.' => 'Sie haben die Währung gewechselt. Bitte prüfen und korrigieren Sie gegebenenfalls die Preise',
   'You have entered or selected the following shipping address for this customer:' => 'Sie haben die folgende Lieferadresse eingegeben oder ausgew&auml;hlt:',
   'You have never worked with currencies.' => 'Sie haben noch nie  mit Währungen gearbeitet.',
   'You have not added bank accounts yet.' => 'Sie haben noch keine Bankkonten angelegt.',
diff --git a/templates/webpages/sepa/bank_transfer_add.html b/templates/webpages/sepa/bank_transfer_add.html
index 811aaace0..0a97d42cf 100644
--- a/templates/webpages/sepa/bank_transfer_add.html
+++ b/templates/webpages/sepa/bank_transfer_add.html
@@ -14,22 +14,29 @@
  <p><div class="listtop">[% title %]</div></p>
 
  <form action="sepa.pl" method="post">
-  <p>
+   <table border="0">
+    <tr>
+     <th style='text-align:left;'>
    [%- IF is_vendor %]
-    [% 'Please select the source bank account for the transfers:' | $T8 %]
+    [% 'Source bank account for the transfers:' | $T8 %]
    [%- ELSE %]
-    [% 'Please select the destination bank account for the collections:' | $T8 %]
+    [% 'Destination bank account for the collections:' | $T8 %]
    [%- END %]
-   <br>
-   [% L.select_tag('bank_account',
+    </th><th style='width:800px; text-align:left;'>
+     [% L.select_tag('bank_account',
        BANK_ACCOUNTS,
        title_key='displayable_name',
        with_empty=show_empty,
        style='width:450px',
    ) %]
-  </p>
-
-  <p>
+    </th>
+    <th>
+   [%- IF is_vendor %][% 'Bank transfer amount' | $T8 %][%- ELSE %][%-
+    LxERP.t8('Bank collection amount') %][%- END %]:
+    </th>
+    <td><span id="sepa_sum_amount">0</span> € </td>
+   </tr>
+   </table>
    <table border="0">
     <tr>
      <th class="listheading" align="center"><input type="checkbox" id="select_all"></th>
@@ -47,19 +54,20 @@
     </tr>
 
     [%- FOREACH invoice = INVOICES %]
-     <input type="hidden" name="bank_transfers[+].[% arap %]_id" value="[% HTML.escape(invoice.id) %]">
-     <input type="hidden" id="amount_less_skonto_[% loop.count %]" name="amount_less_skonto_[% loop.count %]" value="[% LxERP.format_amount(invoice.amount_less_skonto, 2) %]">
-     <input type="hidden" id="invoice_open_amount_[% loop.count %]" name="invoice_open_amount_[% loop.count %]" value="[% LxERP.format_amount(invoice.open_amount - invoice.open_sepa_transfer_amount, 2) %]">
-     <input type="hidden" id="skonto_amount_[% loop.count %]" name="skonto_amount_[% loop.count %]" value="[% LxERP.format_amount(invoice.skonto_amount, 2) %]">
+     <tr class="[%- IF invoice.is_before_today %]listrow_highlight[%- ELSE %]listrow[%- END %][% loop.count % 2 %] invoice_row">
+      <td align="center">
+
+       <input type="hidden" name="bank_transfers[+].[% arap %]_id" value="[% HTML.escape(invoice.id) %]">
+       <input type="hidden" id="amount_less_skonto_[% loop.count %]" name="amount_less_skonto_[% loop.count %]" value="[% LxERP.format_amount(invoice.amount_less_skonto, 2) %]">
+       <input type="hidden" id="invoice_open_amount_[% loop.count %]" name="invoice_open_amount_[% loop.count %]" value="[% LxERP.format_amount(invoice.open_amount - invoice.open_sepa_transfer_amount, 2) %]">
+       <input type="hidden" id="skonto_amount_[% loop.count %]" name="skonto_amount_[% loop.count %]" value="[% LxERP.format_amount(invoice.skonto_amount, 2) %]">
 
 
-     <tr class="listrow[% loop.count % 2 %]">
-      <td align="center">
        [%- IF invoice.vc_bank_info_ok && (invoice.vc_bank_info_ok != '2') %]
         <input type="checkbox" name="bank_transfers[].selected" value="1"[% IF invoice.checked %] checked[% END %]>
        [%- END %]
       </td>
-      <td align="right">[% invoice.duedate %]</td>
+      <td align="right">[%- IF invoice.within_skonto_period %][% invoice.skonto_date %][%- ELSE %][% invoice.duedate %][%- END %]</td>
       <td>
        [%- IF loop.first || (previous_vcname != invoice.vcname) %]
         <a href="controller.pl?action=CustomerVendor/edit&db=[% vc %]&id=[% HTML.url(invoice.vc_id) %]&callback=[% HTML.url('sepa.pl?action=bank_transfer_add&vc=' _ vc) %]">
@@ -85,7 +93,7 @@
       <td align="right">[% LxERP.format_amount(invoice.invoice_amount-invoice.open_sepa_transfer_amount, 2) %]</td>
       <td align="right">[% LxERP.format_amount(invoice.open_amount-invoice.open_sepa_transfer_amount, 2) %]</td>
       <td align="right">[% invoice.transdate %]</td>
-      <td align="left">[% HTML.escape(invoice.pt_description) %]</td>
+      <td align="left">[% HTML.escape(invoice.pt_description) %][%- IF invoice.within_skonto_period %] bis [% invoice.duedate %][%- END %]</td>
       <td align="left" [%- IF invoice.within_skonto_period %]style="background-color: LightGreen"[%- END %]>[%- IF invoice.skonto_amount %] [% LxERP.format_amount(invoice.percent_skonto, 2) %] % = [% LxERP.format_amount(invoice.skonto_amount, 2) %] € bis [% invoice.skonto_date %] [%- END %]</td>
       <td>
     [% IF INSTANCE_CONF.get_sepa_reference_add_vc_vc_id %]
@@ -97,7 +105,7 @@
       [% L.select_tag('bank_transfers[].payment_type', invoice.payment_select_options, value_key => 'payment_type', title_key => 'display', id => 'payment_type_' _ loop.count, class => 'type_target' ) %]
       </td>
       <td align="right">
-        <input id=[% loop.count %] name="bank_transfers[].amount" id="amount_[% loop.count %]" value="[% LxERP.format_amount(invoice.invoice_amount_suggestion, 2) %]" style="text-align: right" size="12">
+        <input id=[% loop.count %] name="bank_transfers[].amount" id="amount_[% loop.count %]" value="[% LxERP.format_amount(invoice.invoice_amount_suggestion, 2) %]" style="text-align: right" size="8">
       </td>
       <td>
       [%- SET reference = invoice.reference_prefix _ invoice.invnumber _ invoice.substitution _ invoice.vc_prefix _ invoice.vc_number %]
diff --git a/templates/webpages/sepa/bank_transfer_create.html b/templates/webpages/sepa/bank_transfer_create.html
index 83b37fba4..d756342a7 100644
--- a/templates/webpages/sepa/bank_transfer_create.html
+++ b/templates/webpages/sepa/bank_transfer_create.html
@@ -44,8 +44,8 @@
    <br>
    <table>
     <tr>
-     <th class="listheading">[%- IF is_vendor %][% 'Vendor' | $T8 %][%- ELSE %][%- LxERP.t8('Customer') %][%- END %]</th>
-     <th class="listheading">[% 'Depositor' | $T8 %]</th>
+     <th class="listheading" id='cv' style="min-width:250px">[%- IF is_vendor %][% 'Vendor' | $T8 %][%- ELSE %][%- LxERP.t8('Customer') %][%- END %]</th>
+     <th class="listheading" id='depo'>[% 'Depositor' | $T8 %]</th>
      <th class="listheading">[% 'IBAN' | $T8 %]</th>
      <th class="listheading">[% 'BIC' | $T8 %]</th>
      <th class="listheading">[% 'Bank' | $T8 %]</th>
@@ -54,7 +54,6 @@
       <th class="listheading">[% 'Mandate Date of Signature' | $T8 %]</th>
      [%- END %]
     </tr>
-
     [%- FOREACH vbi = VC_BANK_INFO %]
     <tr class="listrow[% loop.count % 1 %]">
      <td>
@@ -62,7 +61,7 @@
       <input type="hidden" name="vc_bank_info[].name" value="[% HTML.escape(vbi.name) %]">
       [% HTML.escape(vbi.name) %]
      </td>
-     <td><input name="vc_bank_info[].depositor" size="20" value="[% HTML.escape(vbi.depositor) %]"></td>
+     <td><input name="vc_bank_info[].depositor" style="width:97%;" size="20" value="[% HTML.escape(vbi.depositor) %]"></td>
      <td><input name="vc_bank_info[].iban" size="34" value="[% HTML.escape(vbi.iban.substr(0, 34)) %]" maxlength="34"></td>
      <td><input name="vc_bank_info[].bic" size="20" value="[% HTML.escape(vbi.bic.substr(0, 20)) %]" maxlength="20"></td>
      <td><input name="vc_bank_info[].bank" size="30" value="[% HTML.escape(vbi.bank) %]"></td>
@@ -74,7 +73,9 @@
     [%- END %]
    </table>
   </p>
-
+   <script type='text/javascript'>
+      $("#depo").css("width",$("#cv").width()+"px");
+   </script>
   <p>
    3. [% 'Enter the requested execution date or leave empty for the quickest possible execution:' | $T8 %]
    <br>
