Merge branch 'master' of vc.linet-services.de:public/lx-office-erp
[kivitendo-erp.git] / bin / mozilla / ir.pl
index 6b09b5b..2ace9a7 100644 (file)
@@ -116,7 +116,7 @@ sub invoice_links {
     }
   }
 
-  my ($payment_id, $language_id, $taxzone_id);
+  my ($payment_id, $language_id, $taxzone_id, $currency);
   if ($form->{payment_id}) {
     $payment_id = $form->{payment_id};
   }
@@ -126,6 +126,9 @@ sub invoice_links {
   if ($form->{taxzone_id}) {
     $taxzone_id = $form->{taxzone_id};
   }
+  if ($form->{currency}) {
+    $currency = $form->{currency};
+  }
 
   my $cp_id = $form->{cp_id};
   IR->get_vendor(\%myconfig, \%$form);
@@ -141,6 +144,9 @@ sub invoice_links {
   if ($taxzone_id) {
     $form->{taxzone_id} = $taxzone_id;
   }
+  if ($currency) {
+    $form->{currency} = $currency;
+  }
 
   my @curr = split(/:/, $form->{currencies}); #seems to be missing
   map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
@@ -262,7 +268,7 @@ sub form_header {
   my $form     = $main::form;
   my %myconfig = %main::myconfig;
   my $locale   = $main::locale;
-  my $cgi      = $main::cgi;
+  my $cgi      = $::request->{cgi};
 
   $main::auth->assert('vendor_invoice_edit');
 
@@ -274,10 +280,6 @@ sub form_header {
 
   $form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
 
-  my $set_duedate_url = "$form->{script}?action=set_duedate";
-
-  push @ { $form->{AJAX} }, new CGI::Ajax( 'set_duedate' => $set_duedate_url );
-
   my @old_project_ids = ($form->{"globalproject_id"});
   map { push @old_project_ids, $form->{"project_id_$_"} if $form->{"project_id_$_"}; } 1..$form->{"rowcount"};
 
@@ -312,7 +314,9 @@ sub form_header {
   $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
   $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
   $TMPL_VAR{currencies}        = NTI($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};
 
@@ -411,7 +415,7 @@ sub form_footer {
       $form->{"changeable_$i"} = ($form->{"acc_trans_id_$i"})? 0 : 1;
     } elsif ($::lx_office_conf{features}->{payments_changeable} == 2) {
       # on the same day
-      $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') || 
+      $form->{"changeable_$i"} = (($form->{"gldate_$i"} eq '') ||
                                   ($form->current_date(\%myconfig) eq $form->{"gldate_$i"}));
     }
 
@@ -820,14 +824,15 @@ sub yes {
   $main::lxdebug->leave_sub();
 }
 
-sub set_duedate_vendor {
-  $main::lxdebug->enter_sub();
-
-  my $form     = $main::form;
+sub get_duedate_vendor {
+  $::lxdebug->enter_sub;
 
-  print $form->ajax_response_header(), IR->get_duedate('vendor_id' => $form->{vendor_id},
-                                                       'invdate'   => $form->{invdate},
-                                                       'default'   => $form->{old_duedate});
+  my $result = IR->get_duedate(
+    vendor_id => $::form->{vendor_id},
+    invdate   => $::form->{invdate},
+    default   => $::form->{old_duedate},
+  );
 
-  $main::lxdebug->leave_sub();
+  print $::form->ajax_response_header, $result;
+  $::lxdebug->leave_sub;
 }