1. Variable umbenannt, in der die IDs aus OE zwischengespeichert werden, aus denen...
[kivitendo-erp.git] / bin / mozilla / oe.pl
index aea613f..a56557d 100644 (file)
@@ -33,6 +33,7 @@
 
 use POSIX qw(strftime);
 
+use SL::DO;
 use SL::FU;
 use SL::OE;
 use SL::IR;
@@ -171,11 +172,20 @@ sub edit {
   set_headings("edit");
 
   &order_links;
+
+  $form->{rowcount} = 0;
+  foreach $ref (@{ $form->{form_details} }) {
+    $form->{rowcount}++;
+    map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref};
+  }
+
   &prepare_order;
+
   if ($form->{print_and_save}) {
     $form->{language_id} = $language_id;
     $form->{printer_id} = $printer_id;
   }
+
   &display_form;
 
   $lxdebug->leave_sub();
@@ -220,8 +230,11 @@ sub order_links {
   $form->{employee}    = "$form->{employee}--$form->{employee_id}";
 
   # build vendor/customer drop down comatibility... don't ask
-  $form->{"old$form->{vc}"} = $form->{vc};
-  $form->{"select$form->{vc}"} = 1;
+  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}};
 
   $lxdebug->leave_sub();
 }
@@ -233,11 +246,6 @@ sub prepare_order {
 
   $form->{formname} ||= $form->{type};
 
-  $form->{rowcount} = 0;
-  foreach $ref (@{ $form->{form_details} }) {
-    $form->{rowcount}++;
-    map { $form->{"${_}_$form->{rowcount}"} = $ref->{$_} } keys %{$ref};
-  }
   for my $i (1 .. $form->{rowcount}) {
     $form->{"reqdate_$i"} ||= $form->{"deliverydate_$i"};
     $form->{"discount_$i"}  = $form->format_amount(\%myconfig, $form->{"discount_$i"} * ($form->{id} ? 100 : 1));
@@ -336,7 +344,7 @@ sub form_header {
   @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
   %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
   $form->{currency}            = $form->{defaultcurrency} unless $form->{currency};
-  $TMPL_VAR{show_exchangerate} = $form->{currency} ne $form->{defaultcurrency} && $form->{exchangerate};
+  $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;
   push @custom_hiddens, "forex";
@@ -388,7 +396,7 @@ sub form_header {
         max_dunning_level dunning_amount shiptoname shiptostreet shiptozipcode
         shiptocity shiptocountry shiptocontact shiptophone shiptofax
         shiptodepartment_1 shiptodepartment_2 shiptoemail
-        message email subject cc bcc taxpart taxservice taxaccounts),
+        message email subject cc bcc taxpart taxservice taxaccounts cursor_fokus),
         @custom_hiddens,
         map { $_.'_rate', $_.'_description' } split / /, $form->{taxaccounts} ];  # deleted: discount
 
@@ -492,8 +500,8 @@ sub update {
   
   $buysell              = 'buy';
   $buysell              = 'sell' if ($form->{vc} eq 'vendor');
-  $form->{exchangerate} = $exchangerate if 
-    $form->{forex} = $exchangerate = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+  $form->{forex}        = $form->check_exchangerate(\%myconfig, $form->{currency}, $form->{transdate}, $buysell);
+  $form->{exchangerate} = $form->{forex} if $form->{forex};
 
   $exchangerate = $form->{exchangerate} || 1;
 
@@ -1494,15 +1502,8 @@ sub invoice {
   &invoice_links;
 
   $form->{currency}     = $currency;
-  $form->{exchangerate} = "";
-  $form->{forex}        = "";
-  $form->{exchangerate} = $exchangerate
-    if (
-        $form->{forex} = (
-                    $exchangerate =
-                      $form->check_exchangerate(
-                      \%myconfig, $form->{currency}, $form->{invdate}, $buysell
-                      )));
+  $form->{forex}        = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{invdate}, $buysell);
+  $form->{exchangerate} = $form->{forex} || '';
 
   $form->{creditremaining} -= ($form->{oldinvtotal} - $form->{ordtotal});
 
@@ -1813,11 +1814,12 @@ sub sales_order {
     delete($form->{ordnumber});
   }
 
-  $form->{cp_id} *= 1;
+  $form->{cp_id}               *= 1;
+  $form->{convert_from_oe_ids}  = $form->{id};
 
-  $form->{title} = $locale->text('Add Sales Order');
-  $form->{vc}    = "customer";
-  $form->{type}  = "sales_order";
+  $form->{title}                = $locale->text('Add Sales Order');
+  $form->{vc}                   = "customer";
+  $form->{type}                 = "sales_order";
 
   &poso;
 
@@ -1833,30 +1835,29 @@ sub poso {
   $form->{transdate} = $form->current_date(\%myconfig);
   delete $form->{duedate};
 
-  $form->{closed} = 0;
+  $form->{closed}          = 0;
 
   $form->{old_employee_id} = $form->{employee_id};
   $form->{old_salesman_id} = $form->{salesman_id};
 
   # reset
-  map { delete $form->{$_} }
-    qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
+  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal);
 
   for $i (1 .. $form->{rowcount}) {
-    map({ $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig,
-                                                     $form->{"${_}_${i}"})
-            if ($form->{"${_}_${i}"}) }
-        qw(ship qty sellprice listprice basefactor));
+    map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor);
   }
 
+  my %saved_vars = map { $_ => $form->{$_} } grep { $form->{$_} } qw(currency);
+
   &order_links;
 
+  map { $form->{$_} = $saved_vars{$_} } keys %saved_vars;
+
   &prepare_order;
 
   # format amounts
   for $i (1 .. $form->{rowcount} - 1) {
-    map { $form->{"${_}_$i"} =~ s/\"/"/g }
-      qw(partnumber description unit);
+    map { $form->{"${_}_$i"} =~ s/\"/"/g } qw(partnumber description unit);
   }
 
   &update;
@@ -1882,17 +1883,16 @@ sub delivery_order {
 
   require "bin/mozilla/do.pl";
 
-  $form->{cp_id}           *= 1;
-  $form->{transdate}        = $form->current_date(\%myconfig);
+  $form->{cp_id}               *= 1;
+  $form->{convert_from_oe_ids}  = $form->{id};
+  $form->{transdate}            = $form->current_date(\%myconfig);
   delete $form->{duedate};
 
-  $form->{closed}           = 0;
-
   $form->{old_employee_id}  = $form->{employee_id};
   $form->{old_salesman_id}  = $form->{salesman_id};
 
   # reset
-  map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal);
+  delete @{$form}{qw(id subject message cc bcc printed emailed queued creditlimit creditremaining discount tradediscount oldinvtotal closed delivered)};
 
   for $i (1 .. $form->{rowcount}) {
     map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice basefactor);