commit a62d4e40c363e5decee538a5e37039a2ac002365
Author: Sven Schöling <s.schoeling@googlemail.com>
Date:   Fri Aug 13 13:45:17 2021 +0200

    DeliveryOrder: taxes und recalc Mechanismus entfernt

diff --git a/SL/Controller/DeliveryOrder.pm b/SL/Controller/DeliveryOrder.pm
index bb88a0d28..8813b1b6f 100644
--- a/SL/Controller/DeliveryOrder.pm
+++ b/SL/Controller/DeliveryOrder.pm
@@ -52,10 +52,6 @@ use Rose::Object::MakeMethods::Generic
 # safety
 __PACKAGE__->run_before('check_auth');
 
-__PACKAGE__->run_before('recalc',
-                        only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction
-                                     print send_email) ]);
-
 __PACKAGE__->run_before('get_unalterable_data',
                         only => [ qw(save save_as_new save_and_delivery_order save_and_invoice save_and_ap_transaction
                                      print send_email) ]);
@@ -107,7 +103,6 @@ sub action_edit {
     $_->{render_second_row} = 1 for @{ $self->order->items_sorted };
   }
 
-  $self->recalc();
   $self->pre_render();
   $self->render(
     'order/form',
@@ -579,7 +574,6 @@ sub action_customer_vendor_changed {
   my ($self) = @_;
 
   setup_order_from_cv($self->order);
-  $self->recalc();
 
   my $cv_method = $self->cv;
 
@@ -612,7 +606,6 @@ sub action_customer_vendor_changed {
     ->focus(      '#order_' . $self->cv . '_id')
     ->run('kivi.Order.update_exchangerate');
 
-  $self->js_redisplay_amounts_and_taxes;
   $self->js_redisplay_cvpartnumbers;
   $self->js->render();
 }
@@ -661,12 +654,9 @@ sub action_unit_changed {
   my $old_unit_obj = SL::DB::Unit->new(name => $::form->{old_unit})->load;
   $item->sellprice($item->unit_obj->convert_to($item->sellprice, $old_unit_obj));
 
-  $self->recalc();
-
   $self->js
     ->run('kivi.Order.update_sellprice', $::form->{item_id}, $item->sellprice_as_number);
   $self->js_redisplay_line_values;
-  $self->js_redisplay_amounts_and_taxes;
   $self->js->render();
 }
 
@@ -684,8 +674,6 @@ sub action_add_item {
 
   $self->order->add_items($item);
 
-  $self->recalc();
-
   $self->get_item_cvpartnumber($item);
 
   my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
@@ -717,7 +705,6 @@ sub action_add_item {
       $item->discount(1) unless $assortment_item->charge;
 
       $self->order->add_items( $item );
-      $self->recalc();
       $self->get_item_cvpartnumber($item);
       my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
       my $row_as_html = $self->p->render('order/tabs/_row',
@@ -743,7 +730,6 @@ sub action_add_item {
 
   $self->js->run('kivi.Order.row_table_scroll_down') if !$::form->{insert_before_item_id};
 
-  $self->js_redisplay_amounts_and_taxes;
   $self->js->render();
 }
 
@@ -775,8 +761,6 @@ sub action_add_multi_items {
   }
   $self->order->add_items(@items);
 
-  $self->recalc();
-
   foreach my $item (@items) {
     $self->get_item_cvpartnumber($item);
     my $item_id = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
@@ -803,18 +787,6 @@ sub action_add_multi_items {
 
   $self->js->run('kivi.Order.row_table_scroll_down') if !$::form->{insert_before_item_id};
 
-  $self->js_redisplay_amounts_and_taxes;
-  $self->js->render();
-}
-
-# recalculate all linetotals, amounts and taxes and redisplay them
-sub action_recalc_amounts_and_taxes {
-  my ($self) = @_;
-
-  $self->recalc();
-
-  $self->js_redisplay_line_values;
-  $self->js_redisplay_amounts_and_taxes;
   $self->js->render();
 }
 
@@ -912,7 +884,6 @@ sub action_return_from_create_part {
     $item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000);
   }
 
-  $self->recalc();
   $self->get_unalterable_data();
   $self->pre_render();
 
@@ -937,8 +908,6 @@ sub action_return_from_create_part {
 sub action_load_second_rows {
   my ($self) = @_;
 
-  $self->recalc() if $self->order->is_sales; # for margin calculation
-
   foreach my $item_id (@{ $::form->{item_ids} }) {
     my $idx  = first_index { $_ eq $item_id } @{ $::form->{orderitem_ids} };
     my $item = $self->order->items_sorted->[$idx];
@@ -994,9 +963,7 @@ sub action_update_row_from_master_data {
     }
   }
 
-  $self->recalc();
   $self->js_redisplay_line_values;
-  $self->js_redisplay_amounts_and_taxes;
 
   $self->js->render();
 }
@@ -1046,41 +1013,6 @@ sub js_redisplay_line_values {
     ->run('kivi.Order.redisplay_line_values', $is_sales, \@data);
 }
 
-sub js_redisplay_amounts_and_taxes {
-  my ($self) = @_;
-
-  if (scalar @{ $self->{taxes} }) {
-    $self->js->show('#taxincluded_row_id');
-  } else {
-    $self->js->hide('#taxincluded_row_id');
-  }
-
-  if ($self->order->taxincluded) {
-    $self->js->hide('#subtotal_row_id');
-  } else {
-    $self->js->show('#subtotal_row_id');
-  }
-
-  if ($self->order->is_sales) {
-    my $is_neg = $self->order->marge_total < 0;
-    $self->js
-      ->html('#marge_total_id',   $::form->format_amount(\%::myconfig, $self->order->marge_total,   2))
-      ->html('#marge_percent_id', $::form->format_amount(\%::myconfig, $self->order->marge_percent, 2))
-      ->action_if( $is_neg, 'addClass',    '#marge_total_id',        'plus0')
-      ->action_if( $is_neg, 'addClass',    '#marge_percent_id',      'plus0')
-      ->action_if( $is_neg, 'addClass',    '#marge_percent_sign_id', 'plus0')
-      ->action_if(!$is_neg, 'removeClass', '#marge_total_id',        'plus0')
-      ->action_if(!$is_neg, 'removeClass', '#marge_percent_id',      'plus0')
-      ->action_if(!$is_neg, 'removeClass', '#marge_percent_sign_id', 'plus0');
-  }
-
-  $self->js
-    ->html('#netamount_id', $::form->format_amount(\%::myconfig, $self->order->netamount, -2))
-    ->html('#amount_id',    $::form->format_amount(\%::myconfig, $self->order->amount,    -2))
-    ->remove('.tax_row')
-    ->insertBefore($self->build_tax_rows, '#amount_row_id');
-}
-
 sub js_redisplay_cvpartnumbers {
   my ($self) = @_;
 
@@ -1243,19 +1175,6 @@ sub build_business_info_row
   $_[0]->p->render('order/tabs/_business_info_row', SELF => $_[0]);
 }
 
-# build the rows for displaying taxes
-#
-# Called if amounts where recalculated and redisplayed.
-sub build_tax_rows {
-  my ($self) = @_;
-
-  my $rows_as_html;
-  foreach my $tax (sort { $a->{tax}->rate cmp $b->{tax}->rate } @{ $self->{taxes} }) {
-    $rows_as_html .= $self->p->render('order/tabs/_tax_row', TAX => $tax, TAXINCLUDED => $self->order->taxincluded);
-  }
-  return $rows_as_html;
-}
-
 
 sub render_price_dialog {
   my ($self, $record_item) = @_;
@@ -1488,25 +1407,6 @@ sub setup_custom_shipto_from_form {
   }
 }
 
-# recalculate prices and taxes
-#
-# Using the PriceTaxCalculator. Store linetotals in the item objects.
-sub recalc {
-  my ($self) = @_;
-
-  my %pat = $self->order->calculate_prices_and_taxes();
-
-  $self->{taxes} = [];
-  foreach my $tax_id (keys %{ $pat{taxes_by_tax_id} }) {
-    my $netamount = sum0 map { $pat{amounts}->{$_}->{amount} } grep { $pat{amounts}->{$_}->{tax_id} == $tax_id } keys %{ $pat{amounts} };
-
-    push(@{ $self->{taxes} }, { amount    => $pat{taxes_by_tax_id}->{$tax_id},
-                                netamount => $netamount,
-                                tax       => SL::DB::Tax->new(id => $tax_id)->load });
-  }
-  pairwise { $a->{linetotal} = $b->{linetotal} } @{$self->order->items_sorted}, @{$pat{items}};
-}
-
 # get data for saving, printing, ..., that is not changed in the form
 #
 # Only cvars for now.
@@ -1624,7 +1524,6 @@ sub workflow_sales_or_request_for_quotation {
   $self->cv  ($self->init_cv);
   $self->check_auth;
 
-  $self->recalc();
   $self->get_unalterable_data();
   $self->pre_render();
 
@@ -1688,7 +1587,6 @@ sub workflow_sales_or_purchase_order {
   $self->cv  ($self->init_cv);
   $self->check_auth;
 
-  $self->recalc();
   $self->get_unalterable_data();
   $self->pre_render();
 
diff --git a/js/kivi.DeliveryOrder.js b/js/kivi.DeliveryOrder.js
index 0b71b9a80..ea6e14ba5 100644
--- a/js/kivi.DeliveryOrder.js
+++ b/js/kivi.DeliveryOrder.js
@@ -233,13 +233,6 @@ namespace('kivi.Order', function(ns) {
     }
   };
 
-  ns.recalc_amounts_and_taxes = function() {
-    var data = $('#order_form').serializeArray();
-    data.push({ name: 'action', value: 'Order/recalc_amounts_and_taxes' });
-
-    $.post("controller.pl", data, kivi.eval_json_result);
-  };
-
   ns.unit_change = function(event) {
     var row           = $(event.target).parents("tbody").first();
     var item_id_dom   = $(row).find('[name="orderitem_ids[+]"]');
@@ -328,10 +321,6 @@ namespace('kivi.Order', function(ns) {
   };
 
   ns.init_row_handlers = function() {
-    kivi.run_once_for('.recalc', 'on_change_recalc', function(elt) {
-      $(elt).change(ns.recalc_amounts_and_taxes);
-    });
-
     kivi.run_once_for('.reformat_number', 'on_change_reformat', function(elt) {
       $(elt).change(ns.reformat_number);
     });
@@ -489,7 +478,6 @@ namespace('kivi.Order', function(ns) {
     $(row).remove();
 
     ns.renumber_positions();
-    ns.recalc_amounts_and_taxes();
   };
 
   ns.row_table_scroll_down = function() {
@@ -557,7 +545,6 @@ namespace('kivi.Order', function(ns) {
       var html_elt  = $(row).find('[name="sellprice_text"]');
       price_elt.val(price_str);
       html_elt.html(price_str);
-      ns.recalc_amounts_and_taxes();
     }
 
     kivi.io.close_dialog();
@@ -592,7 +579,6 @@ namespace('kivi.Order', function(ns) {
       var html_elt     = $(row).find('[name="discount_text"]');
       discount_elt.val(discount_str);
       html_elt.html(discount_str);
-      ns.recalc_amounts_and_taxes();
     }
 
     kivi.io.close_dialog();
diff --git a/templates/webpages/delivery_order/tabs/_row.html b/templates/webpages/delivery_order/tabs/_row.html
index 0c29b3b5b..60d6cf18a 100644
--- a/templates/webpages/delivery_order/tabs/_row.html
+++ b/templates/webpages/delivery_order/tabs/_row.html
@@ -71,7 +71,7 @@
       [%- L.input_tag("order.orderitems[].qty_as_number",
                       ITEM.qty_as_number,
                       size = 5,
-                      class="recalc reformat_number numeric") %]
+                      class="reformat_number numeric") %]
       [%- IF ITEM.part.formel -%]
         [%- L.button_tag("kivi.Order.show_calculate_qty_dialog(this)", LxERP.t8("*/")) %]
         [%- L.hidden_tag("formula[+]", ITEM.part.formel) -%]
@@ -82,8 +82,7 @@
                        SELF.all_price_factors,
                        default = ITEM.price_factor_id,
                        title_key = 'description',
-                       with_empty = 1,
-                       class="recalc") %]
+                       with_empty = 1) %]
     </td>
     <td nowrap>
       [%- L.select_tag("order.orderitems[].unit",
@@ -113,7 +112,7 @@
                         ITEM.sellprice_as_number,
                         size = 10,
                         disabled=(EDIT_PRICE? '' : 1),
-                        class="recalc reformat_number numeric") %]
+                        class="reformat_number numeric") %]
       </div>
       <div name="not_editable_price" [%- IF EDIT_PRICE %]style="display:none"[%- END %]>
         [%- L.div_tag(ITEM.sellprice_as_number, name="sellprice_text", class="numeric") %]
@@ -130,7 +129,7 @@
                         ITEM.discount_as_percent,
                         size = 5,
                         disabled=(EDIT_DISCOUNT? '' : 1),
-                        class="recalc reformat_number numeric") %]
+                        class="reformat_number numeric") %]
       </div>
       <div name="not_editable_discount" [%- IF EDIT_DISCOUNT %]style="display:none"[%- END %]>
         [%- L.div_tag(ITEM.discount_as_percent, name="discount_text", class="numeric") %]
diff --git a/templates/webpages/delivery_order/tabs/basic_data.html b/templates/webpages/delivery_order/tabs/basic_data.html
index 7efe969a5..a2ffd717c 100644
--- a/templates/webpages/delivery_order/tabs/basic_data.html
+++ b/templates/webpages/delivery_order/tabs/basic_data.html
@@ -336,54 +336,6 @@
               </table>
             </td>
 
-            [%- IF (SELF.type == "sales_order" || SELF.type == "sales_quotation") -%]
-            [%- SET marge_class = (SELF.order.marge_total < 0) ? 'plus0' : '' -%]
-            <td>
-              <table>
-                <tr>
-                  <th  align="left">[% 'Ertrag' | $T8 %]</th>
-                  <td align="right">
-                    [%- L.div_tag(SELF.order.marge_total_as_number, id='marge_total_id', class=marge_class) %]
-                  </td>
-                </tr>
-                <tr>
-                  <th  align="left">[% 'Ertrag prozentual' | $T8 %]</th>
-                  <td align="right">
-                    [%- L.div_tag(LxERP.format_amount(SELF.order.marge_percent, 2), id='marge_percent_id', class=marge_class) %]
-                  </td>
-                  <td>[%- L.div_tag('%', id='marge_percent_sign_id', class=marge_class) %]</td>
-                </tr>
-              </table>
-            </td>
-            [%- END %]
-
-            <td align="right">
-              <table>
-                <tr id="taxincluded_row_id" [%- IF !SELF.taxes.size %]style="display:none"[%- END %]>
-                  <td align=right colspan="2">
-                    <label for="order.taxincluded"><b>[% 'Tax Included' | $T8 %]</b></label>
-                    [% L.yes_no_tag('order.taxincluded', SELF.order.taxincluded, class='recalc') %]
-                  </td>
-                </tr>
-
-                <tr id="subtotal_row_id" [%- IF SELF.order.taxincluded %]style="display:none"[%- END %]>
-                  <th align="right">[%- 'Subtotal' | $T8 %]</th>
-                  <td align="right">
-                    [%- L.div_tag(SELF.order.netamount_as_number, id='netamount_id') %]
-                  </td>
-                </tr>
-                [%- FOREACH tax = SELF.taxes %]
-                  [%- PROCESS order/tabs/_tax_row.html TAX=tax TAXINCLUDED=SELF.order.taxincluded %]
-                [%- END %]
-                <tr id="amount_row_id">
-                  <th align="right">[%- 'Total' | $T8 %]</th>
-                  <td align="right">
-                    [%- L.div_tag(SELF.order.amount_as_number, id='amount_id') %]
-                  </td>
-                </tr>
-              </table>
-            </td>
-
           </tr>
         </table>
       </td>
