Redundanten Template-Code in bank_transactions/invoices.html aufgeräumt
authorJan Büren <jan@kivitendo.de>
Sun, 10 Mar 2019 16:41:05 +0000 (17:41 +0100)
committerJan Büren <jan@kivitendo.de>
Sun, 10 Mar 2019 16:41:05 +0000 (17:41 +0100)
SL/Controller/BankTransaction.pm
SL/DB/Helper/Payment.pm
templates/webpages/bank_transactions/_payment_suggestion.html
templates/webpages/bank_transactions/invoices.html

index fe21db1..60a558e 100644 (file)
@@ -309,20 +309,16 @@ sub action_ajax_payment_suggestion {
   # create an HTML blob to be used by the js function add_invoices in templates/webpages/bank_transactions/list.html
   # and return encoded as JSON
 
-  my $bt      = SL::DB::Manager::BankTransaction->find_by( id => $::form->{bt_id} );
-  my $invoice = SL::DB::Manager::Invoice->find_by( id => $::form->{prop_id} ) || SL::DB::Manager::PurchaseInvoice->find_by( id => $::form->{prop_id} );
+  croak("Need bt_id") unless $::form->{bt_id};
 
-  die unless $bt and $invoice;
+  my $invoice = SL::DB::Manager::Invoice->find_by( id => $::form->{prop_id} ) || SL::DB::Manager::PurchaseInvoice->find_by( id => $::form->{prop_id} );
 
-  my @select_options = $invoice->get_payment_select_options_for_bank_transaction($::form->{bt_id});
+  croak("No valid invoice found") unless $invoice;
 
-  my $html;
-  $html = $self->render(
+  my $html = $self->render(
     'bank_transactions/_payment_suggestion', { output => 0 },
     bt_id          => $::form->{bt_id},
-    prop_id        => $::form->{prop_id},
     invoice        => $invoice,
-    SELECT_OPTIONS => \@select_options,
   );
 
   $self->render(\ SL::JSON::to_json( { 'html' => "$html" } ), { layout => 0, type => 'json', process => 0 });
index 2f67945..073e0ec 100644 (file)
@@ -629,13 +629,17 @@ sub valid_skonto_amount {
 sub get_payment_select_options_for_bank_transaction {
   my ($self, $bt_id, %params) = @_;
 
-  # no skonto date  -> no select option
-  return { payment_type => 'without_skonto', display => t8('without skonto') , selected => 1 } unless $self->skonto_date;
-
-  my $bt = SL::DB::BankTransaction->new(id => $bt_id)->load;
 
+  # CAVEAT template code expects with_skonto_pt at position 1 for visual help
   my @options;
-
+  if(!$self->skonto_date) {
+    push(@options, { payment_type => 'without_skonto', display => t8('without skonto'), selected => 1 });
+    # wrong call to presenter or not implemented? disabled option is ignored
+    # push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), disabled => 1 });
+    return @options;
+  }
+  # valid skonto date, check if skonto is preferred
+  my $bt = SL::DB::BankTransaction->new(id => $bt_id)->load;
   if ($self->skonto_date && $self->within_skonto_period($bt->transdate)) {
     push(@options, { payment_type => 'without_skonto', display => t8('without skonto') });
     push(@options, { payment_type => 'with_skonto_pt', display => t8('with skonto acc. to pt'), selected => 1 });
index aba38af..20a437a 100644 (file)
@@ -1,10 +1,9 @@
 [%- USE P -%][%- USE HTML -%][%- USE LxERP -%]
-<span id="[% HTML.escape(bt_id) %].[% HTML.escape(prop_id) %]" data-invoice-amount="[% HTML.escape(invoice.open_amount * 1) %]">
- [% P.hidden_tag("invoice_ids." _ bt_id _ "[]", prop_id) %]
- [% LxERP.t8("Invno.") %]: [% HTML.escape(invoice.invnumber) %]
- [% LxERP.t8("Open amount") %]: [% LxERP.format_amount(invoice.open_amount, 2) %]
- [% IF SELECT_OPTIONS.size %]
-  [% P.select_tag("invoice_skontos." _ bt_id _ "[]", SELECT_OPTIONS, value_key="payment_type", title_key="display") %]
- [% END %]
- [% P.link_tag("#", "x", onclick="kivi.BankTransaction.delete_invoice(" _ bt_id _ "," _ prop_id _ ")") %]
+<span id="[% HTML.escape(bt_id) %].[% HTML.escape(invoice.id) %]" data-invoice-amount="[% HTML.escape(invoice.open_amount * 1) %]">
+ [% P.hidden_tag("invoice_ids." _ bt_id _ "[]", invoice.id) %]
+ [% SELECT_OPTIONS = invoice.get_payment_select_options_for_bank_transaction(bt_id) %]
+ [% LxERP.t8("Invno.") %]: [% HTML.escape(invoice.invnumber) %]</br>
+ [% LxERP.t8("Open amount") %]: [% LxERP.format_amount(invoice.open_amount, 2) %]</br>
+ [% P.select_tag("invoice_skontos." _ bt_id _ "[]", SELECT_OPTIONS, value_key="payment_type", title_key="display") %]
+ [% P.link_tag("#", "x", onclick="kivi.BankTransaction.delete_invoice(" _ bt_id _ "," _ invoice.id _ ")") %]
 </span>
index 3074e9f..e5976c4 100644 (file)
@@ -5,13 +5,7 @@
   <td></td>
   <td></td>
   <td id="assigned_invoices_[% bt.id %]_[% invoice.id %]">
-   <span id="[% bt_id %].[% invoice.id %]" data-invoice-amount="[% HTML.escape(invoice.open_amount * 1) %]">
-    [% P.hidden_tag("invoice_ids." _ bt_id _"[]", invoice.id) %]
-    [% LxERP.t8("Invno.") %]: [% HTML.escape(invoice.invnumber) %]
-    [% LxERP.t8("Open amount") %]: [% LxERP.format_amount(invoice.open_amount, 2) %]
-    [% P.select_tag("invoice_skontos." _ bt_id _ "[]", invoice.get_payment_select_options_for_bank_transaction(bt_id), value_key="payment_type", title_key="display") %]
-    [% P.link_tag("#", "x", onclick="kivi.BankTransaction.delete_invoice(" _ bt_id _ "," _ invoice.id _ ")") %]
-   </span>
+    [% PROCESS "bank_transactions/_payment_suggestion.html" %]
   </td>
   <td>[% P.input_tag("sources_" _ bt_id _ "_" _ invoice.id, "") %]</td>
   <td>[% P.input_tag("memos_" _ bt_id _ "_" _ invoice.id, "") %]</td>