Auftrags-Controller: taxincluded vom Kunden oder aus Benutzereinstellung holen.
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 30 Sep 2015 10:25:31 +0000 (12:25 +0200)
committerG. Richardson <information@kivitendo-premium.de>
Mon, 16 Nov 2015 15:15:58 +0000 (16:15 +0100)
SL/Controller/Order.pm
templates/webpages/order/tabs/basic_data.html

index f275f87..1933827 100644 (file)
@@ -243,31 +243,37 @@ sub action_save_and_delivery_order {
 sub action_customer_vendor_changed {
   my ($self) = @_;
 
-  if ($self->cv eq 'customer') {
-    $self->order->customer(SL::DB::Manager::Customer->find_by_or_create(id => $::form->{cv_id}));
-
-  } elsif ($self->cv eq 'vendor') {
-    $self->order->vendor(SL::DB::Manager::Vendor->find_by_or_create(id => $::form->{cv_id}));
-  }
+  my $cv_method = $self->cv;
 
-  if ($self->order->{$self->cv}->contacts && scalar @{ $self->order->{$self->cv}->contacts } > 0) {
+  if ($self->order->$cv_method->contacts && scalar @{ $self->order->$cv_method->contacts } > 0) {
     $self->js->show('#cp_row');
   } else {
     $self->js->hide('#cp_row');
   }
 
-  if ($self->order->{$self->cv}->shipto && scalar @{ $self->order->{$self->cv}->shipto } > 0) {
+  if ($self->order->$cv_method->shipto && scalar @{ $self->order->$cv_method->shipto } > 0) {
     $self->js->show('#shipto_row');
   } else {
     $self->js->hide('#shipto_row');
   }
 
+  $self->order->taxzone_id($self->order->$cv_method->taxzone_id);
+
+  $self->order->taxincluded(defined($self->order->$cv_method->taxincluded_checked)
+                            ? $self->order->$cv_method->taxincluded_checked
+                            : $::myconfig{taxincluded_checked});
+
+  $self->_recalc();
+
   $self->js
-    ->replaceWith('#order_cp_id',     $self->build_contact_select)
-    ->replaceWith('#order_shipto_id', $self->build_shipto_select)
-    ->val('#order_taxzone_id', $self->order->{$self->cv}->taxzone_id)
-    ->focus('#order_' . $self->cv . '_id')
-    ->render($self);
+    ->replaceWith('#order_cp_id',       $self->build_contact_select)
+    ->replaceWith('#order_shipto_id',   $self->build_shipto_select)
+    ->val(        '#order_taxzone_id',  $self->order->taxzone_id)
+    ->val(        '#order_taxincluded', $self->order->taxincluded)
+    ->focus(      '#order_' . $self->cv . '_id');
+
+  $self->_js_redisplay_amounts_and_taxes;
+  $self->js->render();
 }
 
 sub action_add_item {
index f0928aa..5368bd7 100644 (file)
 
 <script type='text/javascript'>
 function reload_cv_dependend_selections() {
-  $.post("controller.pl", { 'action': 'Order/customer_vendor_changed',
-                            'cv_id':  function(){ return $('#order_[%- cv_id%]').val() },
-                            'type':   function(){ return $('#type').val() },
-                          }, kivi.eval_json_result);
+  var data = $('#order_form').serialize();
+  data += '&action=Order/customer_vendor_changed';
+
+  $.post("controller.pl", data, kivi.eval_json_result);
 }
 
 function add_item() {