BankTransaction: Kreditorenvorlagen: Vorlage direkt laden, wenn genau 1 Treffer
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 11 May 2022 09:15:23 +0000 (11:15 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 11 May 2022 10:22:35 +0000 (12:22 +0200)
SL/Controller/BankTransaction.pm
js/kivi.BankTransaction.js

index 48f35ed..e38f8a9 100644 (file)
@@ -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 {
index b756217..2441aa1 100644 (file)
@@ -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;
   };