Auftrags-Controller: linetotal nach Ändern von Menge/Preis/Rabatt neu berechnen.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Tue, 15 Sep 2015 10:25:53 +0000 (12:25 +0200)
committerG. Richardson <information@kivitendo-premium.de>
Mon, 16 Nov 2015 15:15:57 +0000 (16:15 +0100)
SL/Controller/Order.pm
templates/webpages/order/tabs/_row.html
templates/webpages/order/tabs/basic_data.html

index 469eb40..836351e 100644 (file)
@@ -175,6 +175,7 @@ sub action_add_item {
     ->val('#add_item_discount_as_percent', '')
     ->run('row_table_scroll_down')
     ->run('row_set_keyboard_events_by_id', $item_id)
+    ->on('.recalc', 'change', 'recalc_amounts_and_taxes')
     ->focus('#add_item_parts_id_name');
 
   $self->_js_redisplay_amounts_and_taxes;
@@ -186,10 +187,19 @@ sub action_recalc_amounts_and_taxes {
 
   $self->_recalc();
 
+  $self->_js_redisplay_linetotals;
   $self->_js_redisplay_amounts_and_taxes;
   $self->js->render($self);
 }
 
+sub _js_redisplay_linetotals {
+  my ($self) = @_;
+
+  my @data = map {$::form->format_amount(\%::myconfig, $_->{linetotal}, 2, 0)} @{ $self->order->items };
+  $self->js
+    ->run('redisplay_linetotals', \@data);
+}
+
 sub _js_redisplay_amounts_and_taxes {
   my ($self) = @_;
 
index c5892ec..fcc0b3f 100644 (file)
       [%- L.input_tag("order.orderitems[].qty_as_number",
                       ITEM.qty_as_number,
                       size = 5,
-                      style='text-align:right') %]
+                      style='text-align:right',
+                      class="recalc") %]
     </td>
     <td>
       [%- L.input_tag("order.orderitems[].price_factor",
                       ITEM.price_factor,
                       size = 5,
-                      style='text-align:right') %]
+                      style='text-align:right',
+                      class="recalc") %]
     </td>
     <td nowrap>
       [%- L.input_tag("order.orderitems[].unit",
                       ITEM.unit,
-                      size = 5) %]
+                      size = 5,
+                      class="recalc") %]
     </td>
     <td>
       [%- L.input_tag("order.orderitems[].sellprice_as_number",
                       ITEM.sellprice_as_number,
                       size = 10,
-                      style='text-align:right') %]
+                      style='text-align:right',
+                      class="recalc") %]
     </td>
     <td>
       [%- L.input_tag("order.orderitems[].discount_as_percent",
                       ITEM.discount_as_percent,
                       size = 5,
-                      style='text-align:right') %]
+                      style='text-align:right',
+                      class="recalc") %]
     </td>
     <td align="right">
       [%- L.div_tag(LxERP.format_amount(ITEM.linetotal, 2, 0), name="linetotal") %]
index 0d7362f..2c9598d 100644 (file)
@@ -216,6 +216,12 @@ function recalc_amounts_and_taxes() {
   $.post("controller.pl", data, kivi.eval_json_result);
 }
 
+function redisplay_linetotals(data) {
+  $('.row_entry [name="linetotal"]').each(function(idx, elt) {
+    $(elt).html(data[idx]);    
+  });
+}
+
 function row_table_scroll_down() {
   $('#row_table_scroll_id').scrollTop($('#row_table_scroll_id')[0].scrollHeight);
 }
@@ -264,6 +270,7 @@ $(function(){
     }
   });
   row_set_keyboard_events($('.row_entry'));
+  $('.recalc').change(recalc_amounts_and_taxes);
 });
 
 </script>