Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / bin / mozilla / is.pl
index beb6093..f438f1c 100644 (file)
@@ -146,7 +146,7 @@ sub invoice_links {
 
   my $editing = $form->{id};
 
-  $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes id shipto_id));
+  $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded currency cp_id intnotes id shipto_id));
 
   IS->get_customer(\%myconfig, \%$form);
 
@@ -158,7 +158,7 @@ sub invoice_links {
   $form->restore_vars(qw(id));
 
   IS->retrieve_invoice(\%myconfig, \%$form);
-  $form->restore_vars(qw(payment_id language_id taxzone_id intnotes cp_id shipto_id));
+  $form->restore_vars(qw(payment_id language_id taxzone_id currency intnotes cp_id shipto_id));
   $form->restore_vars(qw(taxincluded)) if $form->{id};
   $form->restore_vars(qw(salesman_id)) if $editing;
 
@@ -332,7 +332,9 @@ sub form_header {
   $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
   $form->{show_exchangerate}   = $form->{currency} ne $form->{defaultcurrency};
   $TMPL_VAR{currencies}        = NTI($::request->{cgi}->popup_menu('-name' => 'currency', '-default' => $form->{"currency"},
-                                                      '-values' => \@values, '-labels' => \%labels)) if scalar @values;
+                                                      '-values' => \@values, '-labels' => \%labels,
+                                                      '-onchange' => "document.getElementById('update_button').click();"
+                                     )) if scalar @values;
   push @custom_hiddens, "forex";
   push @custom_hiddens, "exchangerate" if $form->{forex};
 
@@ -385,7 +387,6 @@ sub form_footer {
   $main::auth->assert('invoice_edit');
 
   $form->{invtotal}    = $form->{invsubtotal};
-  $form->{oldinvtotal} = $form->{invtotal};
 
   # note rows
   $form->{rows} = max 2,
@@ -445,6 +446,8 @@ sub form_footer {
     $totalpaid += $form->{"paid_$i"};
   }
 
+  $form->{oldinvtotal} = $form->{invtotal};
+
   print $form->parse_html_template('is/form_footer', {
     is_type_credit_note => ($form->{type} eq "credit_note"),
     totalpaid           => $totalpaid,
@@ -482,8 +485,6 @@ sub update {
 
   my ($recursive_call) = @_;
 
-  $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}) unless $recursive_call;
-
   $form->{print_and_post} = 0         if $form->{second_run};
   my $taxincluded         = $form->{taxincluded} ? "checked" : '';
   $form->{update} = 1;
@@ -492,6 +493,9 @@ sub update {
 
   $form->{taxincluded} ||= $taxincluded;
 
+  if (!$form->{forex}) {        # read exchangerate from input field (not hidden)
+    $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate}) unless $recursive_call;
+  }
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'buy');
   $form->{exchangerate} = $form->{forex} if $form->{forex};