Angebote/Aufträge: Kunden-/Lieferantenwahl via Picker
[kivitendo-erp.git] / bin / mozilla / oe.pl
index e1f7f3a..ebbc997 100644 (file)
@@ -241,9 +241,6 @@ sub order_links {
 
   check_oe_access();
 
-  # get customer/vendor
-  $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
-
   # retrieve order/quotation
   my $editing = $form->{id};
 
@@ -256,8 +253,6 @@ sub order_links {
     if          $form->{rowcount}  && $form->{type}     eq 'sales_order'
      && defined $form->{customer}  && $form->{customer} eq '';
 
-  $form->{"$form->{vc}_id"} ||= $form->{"all_$form->{vc}"}->[0]->{id} if $form->{"all_$form->{vc}"};
-
   $form->backup_vars(qw(payment_id language_id taxzone_id salesman_id taxincluded cp_id intnotes shipto_id delivery_term_id currency));
 
   # get customer / vendor
@@ -271,18 +266,6 @@ sub order_links {
   $form->{forex}       = $form->{exchangerate};
   $form->{employee}    = "$form->{employee}--$form->{employee_id}";
 
-  # build vendor/customer drop down comatibility... don't ask
-  if (@{ $form->{"all_$form->{vc}"} || [] }) {
-    $form->{"select$form->{vc}"} = 1;
-    $form->{$form->{vc}}         = qq|$form->{$form->{vc}}--$form->{"$form->{vc}_id"}|;
-  }
-
-  $form->{"old$form->{vc}"}  = $form->{$form->{vc}};
-
-  if ($form->{"old$form->{vc}"} !~ m/--\d+$/ && $form->{"$form->{vc}_id"}) {
-    $form->{"old$form->{vc}"} .= qq|--$form->{"$form->{vc}_id"}|
-  }
-
   $main::lxdebug->leave_sub();
 }
 
@@ -354,8 +337,6 @@ sub form_header {
 
   $form->get_lists("taxzones"      => ($form->{id} ? "ALL_TAXZONES" : "ALL_ACTIVE_TAXZONES"),
                    "currencies"    => "ALL_CURRENCIES",
-                   $vc             => { key   => "ALL_" . uc($vc),
-                                        limit => $myconfig{vclimit} + 1 },
                    "price_factors" => "ALL_PRICE_FACTORS");
   $form->{ALL_PAYMENTS} = SL::DB::Manager::PaymentTerm->get_all( where => [ or => [ obsolete => 0, id => $form->{payment_id} || undef ] ]);
 
@@ -399,14 +380,6 @@ sub form_header {
   ]);
   $TMPL_VAR{sales_employee_labels} = sub { $_[0]->{name} || $_[0]->{login} };
 
-  # vendor/customer
-  $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
-  $TMPL_VAR{vclimit} = $myconfig{vclimit};
-  $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('$form->{vc}', '', @{[ $form->{vc} eq 'vendor' ? 1 : 0 ]}, 0)";
-  push @custom_hiddens, "$form->{vc}_id";
-  push @custom_hiddens, "old$form->{vc}";
-  push @custom_hiddens, "select$form->{vc}";
-
   # currencies and exchangerate
   my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
   my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
@@ -604,7 +577,13 @@ sub update {
 
   $form->{update} = 1;
 
-  &check_name($form->{vc});
+  my $vc = $form->{vc};
+  if (($form->{"previous_${vc}_id"} || $form->{"${vc}_id"}) != $form->{"${vc}_id"}) {
+    $::form->{salesman_id} = SL::DB::Manager::Employee->current->id if exists $::form->{salesman_id};
+
+    IS->get_customer(\%myconfig, $form) if $vc eq 'customer';
+    IR->get_vendor(\%myconfig, $form)   if $vc eq 'vendor';
+  }
 
   if (!$form->{forex}) {        # read exchangerate from input field (not hidden)
     map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(exchangerate) unless $recursive_call;
@@ -774,9 +753,7 @@ sub search {
   }
 
   # setup vendor / customer data
-  $form->all_vc(\%myconfig, $form->{vc}, ($form->{vc} eq 'customer') ? "AR" : "AP");
   $form->get_lists("projects"     => { "key" => "ALL_PROJECTS", "all" => 1 },
-                   "$form->{vc}s" => "ALL_VC",
                    "taxzones"     => "ALL_TAXZONES",
                    "business_types" => "ALL_BUSINESS_TYPES",);
   $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]);
@@ -1182,7 +1159,7 @@ sub save_and_close {
   $form->{$idx} =~ s/\s*$//g;
 
   my $msg = ucfirst $form->{vc};
-  $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
+  $form->isblank($form->{vc} . '_id', $locale->text($msg . " missing!"));
 
   # $locale->text('Customer missing!');
   # $locale->text('Vendor missing!');
@@ -1192,17 +1169,14 @@ sub save_and_close {
 
   &validate_items;
 
-  my $payment_id;
-  if($form->{payment_id}) {
-    $payment_id = $form->{payment_id};
-  }
+  my $vc = $form->{vc};
+  if (($form->{"previous_${vc}_id"} || $form->{"${vc}_id"}) != $form->{"${vc}_id"}) {
+    $::form->{salesman_id} = SL::DB::Manager::Employee->current->id if exists $::form->{salesman_id};
 
-  # if the name changed get new values
-  if (&check_name($form->{vc})) {
-    if($form->{payment_id} eq "") {
-      $form->{payment_id} = $payment_id;
-    }
-    &update;
+    IS->get_customer(\%myconfig, $form) if $vc eq 'customer';
+    IR->get_vendor(\%myconfig, $form)   if $vc eq 'vendor';
+
+    update();
     $::dispatcher->end_request;
   }
 
@@ -1289,7 +1263,7 @@ sub save {
   $form->{$idx} =~ s/\s*$//g;
 
   my $msg = ucfirst $form->{vc};
-  $form->isblank($form->{vc}, $locale->text($msg . " missing!"));
+  $form->isblank($form->{vc} . '_id', $locale->text($msg . " missing!"));
 
   # $locale->text('Customer missing!');
   # $locale->text('Vendor missing!');
@@ -1300,17 +1274,14 @@ sub save {
   remove_emptied_rows();
   &validate_items;
 
-  my $payment_id;
-  if($form->{payment_id}) {
-    $payment_id = $form->{payment_id};
-  }
+  my $vc = $form->{vc};
+  if (($form->{"previous_${vc}_id"} || $form->{"${vc}_id"}) != $form->{"${vc}_id"}) {
+    $::form->{salesman_id} = SL::DB::Manager::Employee->current->id if exists $::form->{salesman_id};
 
-  # if the name changed get new values
-  if (&check_name($form->{vc})) {
-    if($form->{payment_id} eq "") {
-      $form->{payment_id} = $payment_id;
-    }
-    &update;
+    IS->get_customer(\%myconfig, $form) if $vc eq 'customer';
+    IR->get_vendor(\%myconfig, $form)   if $vc eq 'vendor';
+
+    update();
     $::dispatcher->end_request;
   }
 
@@ -1453,15 +1424,14 @@ sub invoice {
     $form->{quodate}      = $form->{transdate};
   }
 
-  my $payment_id;
-  if ($form->{payment_id}) {
-    $payment_id = $form->{payment_id};
-  }
+  my $vc = $form->{vc};
+  if (($form->{"previous_${vc}_id"} || $form->{"${vc}_id"}) != $form->{"${vc}_id"}) {
+    $::form->{salesman_id} = SL::DB::Manager::Employee->current->id if exists $::form->{salesman_id};
+
+    IS->get_customer(\%myconfig, $form) if $vc eq 'customer';
+    IR->get_vendor(\%myconfig, $form)   if $vc eq 'vendor';
 
-  # if the name changed get new values
-  if (&check_name($form->{vc})) {
-    $form->{payment_id} = $payment_id if $form->{payment_id} eq "";
-    &update;
+    update();
     $::dispatcher->end_request;
   }