commit aa2fcd5856ab091ba61071dee265c46adde4793c
Author: Tamino Steinert <tamino.steinert@tamino.st>
Date:   Thu Sep 28 14:34:49 2023 +0200

    Workflow Auftrag → Lieferschein auf neuen Controller umgestellt

diff --git a/SL/Controller/DeliveryOrder.pm b/SL/Controller/DeliveryOrder.pm
index e63d2f6d4..6937b725d 100644
--- a/SL/Controller/DeliveryOrder.pm
+++ b/SL/Controller/DeliveryOrder.pm
@@ -1426,7 +1426,7 @@ sub make_order {
     $order = SL::DB::DeliveryOrder->new(
       orderitems  => [],
       currency_id => $::instance_conf->get_currency_id(),
-      record_type => $self->type_data->validate
+      record_type => $self->type
     );
   }
 
diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm
index 4b3bcb9fd..c27f755bb 100644
--- a/SL/Controller/Order.pm
+++ b/SL/Controller/Order.pm
@@ -797,24 +797,6 @@ sub action_save_and_new_record {
   );
 }
 
-# save the order and redirect to the frontend subroutine for a new
-# delivery order
-sub action_save_and_delivery_order {
-  my ($self) = @_;
-
-  my %params;
-
-  if ($::form->{convert_to_purchase_delivery_order_selected_items_only}) {
-    $params{only_items} = join(',', @{ $::form->{purchase_delivery_order_item_selection_indexes} || [] });
-  }
-
-  $self->save_and_redirect_to(
-    controller => 'oe.pl',
-    action     => 'oe_delivery_order_from_order',
-    %params,
-  );
-}
-
 # save the order and redirect to the frontend subroutine for a new
 # invoice
 sub action_save_and_invoice {
@@ -2334,25 +2316,48 @@ sub setup_edit_action_bar {
           disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
         ],
         action => [
-          t8('Save and Delivery Order'),
+          t8('Save and Sales Delivery Order'),
           call      => [ 'kivi.Order.save', {
-              action             => 'save_and_delivery_order',
+              action             => 'save_and_new_record',
               warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts,
               warn_on_reqdate    => $::instance_conf->get_order_warn_no_deliverydate,
+              form_params        => [
+                { name => 'to_type', value => SALES_DELIVERY_ORDER_TYPE() },
+              ],
             }],
           checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
                          @req_trans_cost_art, @req_cusordnumber,
           ],
-          only_if   => $self->type_data->show_menu('save_and_delivery_order'),
+          only_if   => $self->type_data->show_menu('save_and_sales_delivery_order'),
           disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
         ],
         action => [
-          t8('Save and Delivery Order with item selection'),
-          call      => [ 'kivi.Order.convert_to_purchase_delivery_order_select_items',
-                         { action             => 'save_and_delivery_order',
-                           warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts,
-                           warn_on_reqdate    => $::instance_conf->get_order_warn_no_deliverydate },
-                       ],
+          t8('Save and Purchase Delivery Order'),
+          call      => [ 'kivi.Order.save', {
+              action             => 'save_and_new_record',
+              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts,
+              warn_on_reqdate    => $::instance_conf->get_order_warn_no_deliverydate,
+              form_params        => [
+                { name => 'to_type', value => PURCHASE_DELIVERY_ORDER_TYPE() },
+              ],
+            }],
+          checks    => [ 'kivi.Order.check_save_active_periodic_invoices',
+                         @req_trans_cost_art, @req_cusordnumber,
+          ],
+          only_if   => $self->type_data->show_menu('save_and_purchase_delivery_order'),
+          disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
+        ],
+        action => [
+          t8('Save and Purchase Delivery Order with item selection'),
+          call      => [
+            'kivi.Order.show_purchase_delivery_order_select_items', {
+              action             => 'save_and_new_record',
+              warn_on_duplicates => $::instance_conf->get_order_warn_duplicate_parts,
+              warn_on_reqdate    => $::instance_conf->get_order_warn_no_deliverydate,
+              form_params        => [
+                { name => 'to_type', value => PURCHASE_DELIVERY_ORDER_TYPE() },
+              ],
+            }],
           checks    => [ @req_trans_cost_art, @req_cusordnumber ],
           only_if   => (any { $self->type eq $_ } (PURCHASE_ORDER_TYPE())),
           disabled  => !$may_edit_create ? t8('You do not have the permissions to access this function.') : undef,
diff --git a/SL/DB/Order/TypeData.pm b/SL/DB/Order/TypeData.pm
index c22d9d36d..e9654d630 100644
--- a/SL/DB/Order/TypeData.pm
+++ b/SL/DB/Order/TypeData.pm
@@ -38,7 +38,8 @@ my %type_data = (
       save_and_sales_order_intake          => 0,
       save_and_sales_order                 => 0,
       save_and_purchase_order              => 1,
-      save_and_delivery_order              => 1,
+      save_and_sales_delivery_order        => 1,
+      save_and_purchase_delivery_order     => 0,
       save_and_supplier_delivery_order     => 0,
       save_and_reclamation                 => 1,
       save_and_invoice_for_advance_payment => 1,
@@ -89,7 +90,8 @@ my %type_data = (
       save_and_sales_order_intake          => 0,
       save_and_sales_order                 => 1,
       save_and_purchase_order              => 0,
-      save_and_delivery_order              => 1,
+      save_and_sales_delivery_order        => 0,
+      save_and_purchase_delivery_order     => 1,
       save_and_supplier_delivery_order     => 1,
       save_and_reclamation                 => 1,
       save_and_invoice_for_advance_payment => 0,
@@ -133,7 +135,8 @@ my %type_data = (
       save_and_sales_order_intake          => 1,
       save_and_sales_order                 => 1,
       save_and_purchase_order              => 0,
-      save_and_delivery_order              => 0,
+      save_and_sales_delivery_order        => 0,
+      save_and_purchase_delivery_order     => 0,
       save_and_supplier_delivery_order     => 0,
       save_and_reclamation                 => 0,
       save_and_invoice_for_advance_payment => 0,
@@ -184,7 +187,8 @@ my %type_data = (
       save_and_sales_order_intake          => 0,
       save_and_sales_order                 => 1,
       save_and_purchase_order              => 1,
-      save_and_delivery_order              => 0,
+      save_and_sales_delivery_order        => 0,
+      save_and_purchase_delivery_order     => 0,
       save_and_supplier_delivery_order     => 0,
       save_and_reclamation                 => 0,
       save_and_invoice_for_advance_payment => 0,
@@ -228,7 +232,8 @@ my %type_data = (
       save_and_sales_order_intake          => 0,
       save_and_sales_order                 => 1,
       save_and_purchase_order              => 1,
-      save_and_delivery_order              => 0,
+      save_and_sales_delivery_order        => 0,
+      save_and_purchase_delivery_order     => 0,
       save_and_supplier_delivery_order     => 0,
       save_and_reclamation                 => 0,
       save_and_invoice_for_advance_payment => 0,
@@ -272,7 +277,8 @@ my %type_data = (
       save_and_sales_order_intake          => 0,
       save_and_sales_order                 => 1,
       save_and_purchase_order              => 1,
-      save_and_delivery_order              => 0,
+      save_and_sales_delivery_order        => 0,
+      save_and_purchase_delivery_order     => 0,
       save_and_supplier_delivery_order     => 0,
       save_and_reclamation                 => 0,
       save_and_invoice_for_advance_payment => 0,
diff --git a/js/kivi.Order.js b/js/kivi.Order.js
index d73ebba05..ae0411e6a 100644
--- a/js/kivi.Order.js
+++ b/js/kivi.Order.js
@@ -965,7 +965,7 @@ namespace('kivi.Order', function(ns) {
     window.open("controller.pl?action=CustomerVendor/edit&db=" + encodeURIComponent(db) + "&id=" + encodeURIComponent($(id_selector).val()), '_blank');
   };
 
-  ns.convert_to_purchase_delivery_order_select_items = function(params) {
+  ns.show_purchase_delivery_order_select_items = function(params) {
     var data = $('#order_form').serializeArray();
     data.push({ name: 'action', value: 'Order/show_conversion_to_purchase_delivery_order_item_selection' });
 
@@ -981,15 +981,27 @@ namespace('kivi.Order', function(ns) {
     });
   };
 
-  ns.convert_to_purchase_delivery_order = function() {
-    var params = $("body").data("convert_to_purchase_delivery_order_item_selection_params");
-    params.form_params.convert_to_purchase_delivery_order_selected_items_only = 1;
+  ns.convert_to_purchase_delivery_order_item_selection = function() {
+    let params = $("body").data("convert_to_purchase_delivery_order_item_selection_params");
 
-    var $dlg    = $("#convert_to_purchase_delivery_order_item_selection");
-    params.data = $dlg.find("tbody input").serializeArray();
+    let $dialog = $("#convert_to_purchase_delivery_order_item_selection");
+    let selected_items = $dialog.find("tbody input.item_selection_checkall").serializeArray();
+    params.data = selected_items;
 
-    $dlg.dialog('close');
-    $dlg.remove();
+    additional_param = { name: 'only_selected_items', value: 1 };
+    if (params.form_params) {
+      if (Array.isArray(params.form_params)) {
+        params.form_params.push(additional_param);
+      } else {
+        params.form_params = [params.form_params];
+        params.form_params.push(additional_param);
+      }
+    } else {
+      params.form_params = [additional_param];
+    }
+
+    $dialog.dialog('close');
+    $dialog.remove();
 
     kivi.Order.save(params);
   };
diff --git a/locale/de/all b/locale/de/all
index e44f232b9..9eb4316a0 100644
--- a/locale/de/all
+++ b/locale/de/all
@@ -3321,14 +3321,14 @@ $ ./scripts/installation_check.pl',
   'Save and AR Transaction'     => 'Speichern und Debitorenbuchung erfassen',
   'Save and Close'              => 'Speichern und schließen',
   'Save and Credit Note'        => 'Speichern und Gutschrift erfassen',
-  'Save and Delivery Order'     => 'Speichern und Lieferschein',
-  'Save and Delivery Order with item selection' => 'Speichern und Lieferschein mit Positionsauswahl',
   'Save and E-mail'             => 'Speichern und E-Mail',
   'Save and Final Invoice'      => 'Speichern und Schlussrechnung',
   'Save and Further Invoice for Advance Payment' => 'Speichern und weitere Anzahlungsrechnung',
   'Save and Invoice'            => 'Speichern und Rechnung erfassen',
   'Save and Invoice for Advance Payment' => 'Speichern und Anzahlungsrechnung',
   'Save and Order'              => 'Speichern und Auftrag erfassen',
+  'Save and Purchase Delivery Order' => 'Speichern und Lieferschein (Einkauf)',
+  'Save and Purchase Delivery Order with item selection' => 'Speichern und Lieferschein (Einkauf) mit Artikelauswahl',
   'Save and Purchase Order'     => 'Speichern und Lieferantenauftrag',
   'Save and Purchase Quotation Intake' => 'Speichern und Angebotseingang',
   'Save and Purchase Reclamation' => 'Speichern und Einkaufsreklamation',
@@ -3336,6 +3336,7 @@ $ ./scripts/installation_check.pl',
   'Save and RFQ'                => 'Speichern und Lieferantenanfrage',
   'Save and RMA Delivery Order' => 'Speichern und Retourenlieferschein',
   'Save and Reclamation'        => 'Speichern und Reklamation',
+  'Save and Sales Delivery Order' => 'Speichern und Lieferschein (Verkauf)',
   'Save and Sales Order Confirmation' => 'Speichern und Auftragsbestätigung',
   'Save and Sales Order Intake' => 'Speichern und Auftragseingang',
   'Save and Sales Reclamation'  => 'Speichern und Verkaufsreklamation',
diff --git a/locale/en/all b/locale/en/all
index ce8d0fae9..06bf358cf 100644
--- a/locale/en/all
+++ b/locale/en/all
@@ -3320,14 +3320,14 @@ $self->{texts} = {
   'Save and AR Transaction'     => '',
   'Save and Close'              => '',
   'Save and Credit Note'        => '',
-  'Save and Delivery Order'     => '',
-  'Save and Delivery Order with item selection' => '',
   'Save and E-mail'             => '',
   'Save and Final Invoice'      => '',
   'Save and Further Invoice for Advance Payment' => '',
   'Save and Invoice'            => '',
   'Save and Invoice for Advance Payment' => '',
   'Save and Order'              => '',
+  'Save and Purchase Delivery Order' => '',
+  'Save and Purchase Delivery Order with item selection' => '',
   'Save and Purchase Order'     => '',
   'Save and Purchase Quotation Intake' => '',
   'Save and Purchase Reclamation' => '',
@@ -3335,6 +3335,7 @@ $self->{texts} = {
   'Save and RFQ'                => '',
   'Save and RMA Delivery Order' => '',
   'Save and Reclamation'        => '',
+  'Save and Sales Delivery Order' => '',
   'Save and Sales Order Confirmation' => '',
   'Save and Sales Order Intake' => '',
   'Save and Sales Reclamation'  => '',
diff --git a/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html b/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html
index 4ad5294f2..5d3e710aa 100644
--- a/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html
+++ b/templates/design40_webpages/order/tabs/_purchase_delivery_order_item_selection.html
@@ -1,13 +1,13 @@
 [%- USE LxERP -%][%- USE L -%][%- USE HTML -%]
 <div class="wrapper">
-  [% L.button_tag("kivi.Order.convert_to_purchase_delivery_order()", LxERP.t8("Create delivery order")) %]
+  [% L.button_tag("kivi.Order.convert_to_purchase_delivery_order_item_selection()", LxERP.t8("Create delivery order")) %]
 </div>
 
 <div class="wrapper">
   <table class="tbl-list">
     <thead>
       <tr class="listheading">
-        <th>[% L.checkbox_tag("purchase_delivery_order_item_selection_checkall", checkall="input.purchase_delivery_order_item_selection_checkall") %]</th>
+        <th>[% L.checkbox_tag("item_selection_checkall", checkall="input.item_selection_checkall") %]</th>
         <th>[% LxERP.t8("Position") %]</th>
         <th>[% LxERP.t8("Partnumber") %]</th>
         <th>[% LxERP.t8("Vendor Part Number") %]</th>
@@ -17,10 +17,10 @@
       </tr>
     </thead>
 
-    <tbody id="convert_to_purchase_delivery_order_item_selection_items" class="row_entry listrow">
+    <tbody id="item_selection" class="row_entry listrow">
       [% FOREACH item = ITEMS %]
         <tr class="listrow">
-          <td>[% L.checkbox_tag("purchase_delivery_order_item_selection_indexes[+]", class="purchase_delivery_order_item_selection_checkall", value=loop.count, checked="checked") %]</td>
+          <td>[% L.checkbox_tag("selected_items[+]", class="item_selection_checkall", value=item.id, checked="checked") %]</td>
           <td class="numeric">[% loop.count %]</td>
           <td>[% HTML.escape(item.partnumber) %]</td>
           <td>[% HTML.escape(item.vendor_partnumber) %]</td>
diff --git a/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html b/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html
index d46ebf7a7..6eea23638 100644
--- a/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html
+++ b/templates/webpages/order/tabs/_purchase_delivery_order_item_selection.html
@@ -1,13 +1,13 @@
 [%- USE LxERP -%][%- USE L -%][%- USE HTML -%]
 <div>
-  [% L.button_tag("kivi.Order.convert_to_purchase_delivery_order()", LxERP.t8("Create delivery order")) %]
+  [% L.button_tag("kivi.Order.convert_to_purchase_delivery_order_item_selection()", LxERP.t8("Create delivery order")) %]
 </div>
 
 <div>
   <table>
     <thead>
       <tr class="listheading">
-        <th>[% L.checkbox_tag("purchase_delivery_order_item_selection_checkall", checkall="input.purchase_delivery_order_item_selection_checkall", checked="checked") %]</th>
+        <th>[% L.checkbox_tag("item_selection_checkall", checkall="input.item_selection_checkall") %]</th>
         <th>[% LxERP.t8("Position") %]</th>
         <th>[% LxERP.t8("Partnumber") %]</th>
         <th>[% LxERP.t8("Vendor Part Number") %]</th>
@@ -17,10 +17,10 @@
       </tr>
     </thead>
 
-    <tbody>
+    <tbody id="item_selection" class="row_entry listrow">
       [% FOREACH item = ITEMS %]
         <tr class="listrow">
-          <td>[% L.checkbox_tag("purchase_delivery_order_item_selection_indexes[+]", class="purchase_delivery_order_item_selection_checkall", value=loop.count, checked="checked") %]</td>
+          <td>[% L.checkbox_tag("selected_items[+]", class="item_selection_checkall", value=item.id, checked="checked") %]</td>
           <td align="right">[% loop.count %]</td>
           <td>[% HTML.escape(item.partnumber) %]</td>
           <td>[% HTML.escape(item.vendor_partnumber) %]</td>
