From fca946068709229a086497380cdc62d874a8e795 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Sun, 10 Mar 2019 17:41:05 +0100 Subject: [PATCH] =?utf8?q?Redundanten=20Template-Code=20in=20bank=5Ftransa?= =?utf8?q?ctions/invoices.html=20aufger=C3=A4umt?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/BankTransaction.pm | 12 ++++-------- SL/DB/Helper/Payment.pm | 14 +++++++++----- .../bank_transactions/_payment_suggestion.html | 15 +++++++-------- .../webpages/bank_transactions/invoices.html | 8 +------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index fe21db1b4..60a558e6a 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -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 }); diff --git a/SL/DB/Helper/Payment.pm b/SL/DB/Helper/Payment.pm index 2f67945d2..073e0ec52 100644 --- a/SL/DB/Helper/Payment.pm +++ b/SL/DB/Helper/Payment.pm @@ -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 }); diff --git a/templates/webpages/bank_transactions/_payment_suggestion.html b/templates/webpages/bank_transactions/_payment_suggestion.html index aba38af61..20a437a25 100644 --- a/templates/webpages/bank_transactions/_payment_suggestion.html +++ b/templates/webpages/bank_transactions/_payment_suggestion.html @@ -1,10 +1,9 @@ [%- USE P -%][%- USE HTML -%][%- USE LxERP -%] - - [% 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 _ ")") %] + + [% 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) %]
+ [% LxERP.t8("Open amount") %]: [% LxERP.format_amount(invoice.open_amount, 2) %]
+ [% 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 _ ")") %]
diff --git a/templates/webpages/bank_transactions/invoices.html b/templates/webpages/bank_transactions/invoices.html index 3074e9f52..e5976c472 100644 --- a/templates/webpages/bank_transactions/invoices.html +++ b/templates/webpages/bank_transactions/invoices.html @@ -5,13 +5,7 @@ - - [% 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 _ ")") %] - + [% PROCESS "bank_transactions/_payment_suggestion.html" %] [% P.input_tag("sources_" _ bt_id _ "_" _ invoice.id, "") %] [% P.input_tag("memos_" _ bt_id _ "_" _ invoice.id, "") %] -- 2.20.1