Bei der Umwandlung von Angeboten/Anfragen in Auftraege wurden verschiedene Felder...
[kivitendo-erp.git] / bin / mozilla / oe.pl
index b4760b2..f9907cb 100644 (file)
@@ -140,7 +140,7 @@ sub order_links {
   # if multiple rowcounts (== collective order) then check if the
   # there were more than one customer (in that case OE::retrieve removes 
   # the content from the field)
-  if ($form->{rowcount} && $form->{type} eq 'sales_order' && $form->{customer} eq '') {
+  if ($form->{rowcount} && $form->{type} eq 'sales_order' && defined $form->{customer} && $form->{customer} eq '') {
 #    $main::lxdebug->message(0, "Detected Edit order with concurrent customers");
     $form->error($locale->text('Collective Orders only work for orders from one customer!'));
   }
@@ -217,7 +217,7 @@ sub order_links {
 
 sub prepare_order {
   $lxdebug->enter_sub();
-  $form->{format}   = "html";
+  $form->{format}   = "pdf";
   $form->{media}    = "screen";
   $form->{formname} = $form->{type};
 
@@ -229,18 +229,24 @@ sub prepare_order {
 
       map { $form->{"${_}_$i"} = $ref->{$_} } keys %{$ref};
     }
-    
     for my $i (1 .. $form->{rowcount}) {
-       $form->{"discount_$i"} =
-        $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
-
+      if ($form->{id}) {
+        $form->{"discount_$i"} =
+          $form->format_amount(\%myconfig, $form->{"discount_$i"} * 100);
+      } else {
+        $form->{"discount_$i"} =
+          $form->format_amount(\%myconfig, $form->{"discount_$i"});
+      }
       ($dec) = ($form->{"sellprice_$i"} =~ /\.(\d+)/);    
       $dec           = length $dec;
       $decimalplaces = ($dec > 2) ? $dec : 2;
 
+      # copy reqdate from deliverydate for invoice -> order conversion
+      $form->{"reqdate_$i"} = $form->{"deliverydate_$i"} unless $form->{"reqdate_$i"};
+
       $form->{"sellprice_$i"} =
         $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
-                             $decimalplaces);
+                            $decimalplaces);
       
       (my $dec_qty) = ($form->{"qty_$i"} =~ /\.(\d+)/);
       $dec_qty      = length $dec_qty;
@@ -828,10 +834,15 @@ Bearbeiten des $form->{heading}<br>
       . $locale->text('Save as new') . qq|">
 <input class=submit type=submit name=action value="|
       . $locale->text('Delete') . qq|">|;
-    if ($form->{type} =~ /quotation$/) {
+    if ($form->{type} =~ /sales_quotation$/) {
       print qq|
 <input class=submit type=submit name=action value="|
-        . $locale->text('Order') . qq|">|;
+        . $locale->text('Sales Order') . qq|">|;
+    }
+    if ($form->{type} =~ /request_quotation$/) {
+      print qq|
+<input class=submit type=submit name=action value="|
+        . $locale->text('Purchase Order') . qq|">|;
     }
     print qq|
 <input class=submit type=submit name=action value="|
@@ -1913,6 +1924,9 @@ sub invoice {
     $dec           = length $dec;
     $decimalplaces = ($dec > 2) ? $dec : 2;
 
+    # copy delivery date from reqdate for order -> invoice conversion
+    $form->{"deliverydate_$i"} = $form->{"reqdate_$i"} unless $form->{"deliverydate_$i"};
+
     $form->{"sellprice_$i"} =
       $form->format_amount(\%myconfig, $form->{"sellprice_$i"},
                            $decimalplaces);
@@ -2094,6 +2108,15 @@ sub save_as_new {
 sub purchase_order {
   $lxdebug->enter_sub();
 
+  if (   $form->{type} eq 'sales_quotation'
+      || $form->{type} eq 'request_quotation') {
+    $form->{closed} = 1;
+    OE->save(\%myconfig, \%$form);
+  }
+
+  ($null, $form->{cp_id}) = split /--/, $form->{contact};
+  $form->{cp_id} *= 1;
+
   $form->{title} = $locale->text('Add Purchase Order');
   $form->{vc}    = "vendor";
   $form->{type}  = "purchase_order";