From 23d55c8535d9eecc415791d42ec05a7d9cb5c8e0 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Wed, 11 May 2022 11:15:23 +0200 Subject: [PATCH] BankTransaction: Kreditorenvorlagen: Vorlage direkt laden, wenn genau 1 Treffer --- SL/Controller/BankTransaction.pm | 23 +++++++++++++++-------- js/kivi.BankTransaction.js | 11 +++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/SL/Controller/BankTransaction.pm b/SL/Controller/BankTransaction.pm index 48f35ed04..e38f8a997 100644 --- a/SL/Controller/BankTransaction.pm +++ b/SL/Controller/BankTransaction.pm @@ -299,14 +299,21 @@ sub action_create_invoice { 'filter.fromdate' => $::form->{filter}->{fromdate}, )); - $self->render( - 'bank_transactions/create_invoice', - { layout => 0 }, - title => t8('Create invoice'), - TEMPLATES_GL => $use_vendor_filter && @{ $templates_ap } ? undef : $templates_gl, - TEMPLATES_AP => $templates_ap, - vendor_name => $use_vendor_filter && @{ $templates_ap } ? $vendor_of_transaction->name : undef, - ); + # if we have exactly one ap match, use this directly + if (1 == scalar @{ $templates_ap }) { + $self->redirect_to($self->load_ap_record_template_url($templates_ap->[0])); + + } else { + my $dialog_html = $self->render( + 'bank_transactions/create_invoice', + { layout => 0, output => 0 }, + title => t8('Create invoice'), + TEMPLATES_GL => $use_vendor_filter && @{ $templates_ap } ? undef : $templates_gl, + TEMPLATES_AP => $templates_ap, + vendor_name => $use_vendor_filter && @{ $templates_ap } ? $vendor_of_transaction->name : undef, + ); + $self->js->run('kivi.BankTransaction.show_create_invoice_dialog', $dialog_html)->render; + } } sub action_ajax_payment_suggestion { diff --git a/js/kivi.BankTransaction.js b/js/kivi.BankTransaction.js index b75621721..2441aa1dc 100644 --- a/js/kivi.BankTransaction.js +++ b/js/kivi.BankTransaction.js @@ -42,14 +42,17 @@ namespace('kivi.BankTransaction', function(ns) { }; ns.create_invoice = function(bank_transaction_id) { + $.post('controller.pl?action=BankTransaction/create_invoice', + '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(), + kivi.eval_json_result); + }; + + ns.show_create_invoice_dialog = function(dialog_html) { kivi.popup_dialog({ - url: 'controller.pl?action=BankTransaction/create_invoice', - data: '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(), - type: 'POST', + html: dialog_html, id: 'create_invoice_window', dialog: { title: kivi.t8('Create invoice') } }); - return true; }; -- 2.20.1