Währung in Verkaufs-/Einkaufsrechnungj
[kivitendo-erp.git] / bin / mozilla / ir.pl
index 780b8ea..f909d86 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,28 +280,28 @@ 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"};
 
-  $form->get_lists("contacts"      => "ALL_CONTACTS",
-                   "shipto"        => "ALL_SHIPTO",
-                   "projects"      => { "key"    => "ALL_PROJECTS",
+  $form->get_lists("projects"      => { "key"    => "ALL_PROJECTS",
                                         "all"    => 0,
                                         "old_id" => \@old_project_ids },
-                   "employees"     => "ALL_EMPLOYEES",
                    "taxzones"      => "ALL_TAXZONES",
                    "currencies"    => "ALL_CURRENCIES",
                    "vendors"       => "ALL_VENDORS",
                    "departments"   => "all_departments",
                    "price_factors" => "ALL_PRICE_FACTORS");
 
-  $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
-#  $TMPL_VAR{shipto_labels}         = sub { join "; ", grep { $_ } map { $_[0]->{"shipto${_}" } } qw(name department_1 street city) };
-  $TMPL_VAR{contact_labels}        = sub { join(', ', $_[0]->{"cp_name"}, $_[0]->{"cp_givenname"}) . ($_[0]->{cp_abteilung} ? " ($_[0]->{cp_abteilung})" : "") };
+  $TMPL_VAR{ALL_EMPLOYEES}         = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{employee_id},  deleted => 0 ] ]);
+  $TMPL_VAR{ALL_CONTACTS}          = SL::DB::Manager::Contact->get_all(query => [
+    or => [
+      cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
+      and      => [
+        cp_cv_id => undef,
+        cp_id    => $::form->{cp_id} * 1
+      ]
+    ]
+  ]);
   $TMPL_VAR{department_labels}     = sub { "$_[0]->{description}--$_[0]->{id}" };
 
   # customer
@@ -310,9 +316,12 @@ sub form_header {
   my @values = map { $_       } @{ $form->{ALL_CURRENCIES} };
   my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
   $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
-  $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency};
+  # show_exchangerate is also later needed in another template
+  $form->{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};
 
@@ -459,10 +468,11 @@ sub update {
 
   $main::auth->assert('vendor_invoice_edit');
 
-#  map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate creditlimit creditremaining);
-
   &check_name('vendor');
 
+  if (!$form->{forex}) {        # read exchangerate from input field (not hidden)
+    $form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
+  }
   $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{invdate}, 'sell');
   $form->{exchangerate} = $form->{forex} if $form->{forex};
 
@@ -820,14 +830,15 @@ sub yes {
   $main::lxdebug->leave_sub();
 }
 
-sub set_duedate_vendor {
-  $main::lxdebug->enter_sub();
+sub get_duedate_vendor {
+  $::lxdebug->enter_sub;
 
-  my $form     = $main::form;
+  my $result = IR->get_duedate(
+    vendor_id => $::form->{vendor_id},
+    invdate   => $::form->{invdate},
+    default   => $::form->{old_duedate},
+  );
 
-  print $form->ajax_response_header(), 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;
 }