]> wagnertech.de Git - mfinanz.git/blobdiff - SL/IS.pm
Weitere Positionen verknüpft II
[mfinanz.git] / SL / IS.pm
index e09c08c31352e2b226ea32303c808eb660d2baff..7c6aac74e369ba0e9ac66f9bad9c5a858c57dc16 100644 (file)
--- a/SL/IS.pm
+++ b/SL/IS.pm
@@ -578,13 +578,6 @@ sub post_invoice {
   $form->{defaultcurrency} = $form->get_default_currency($myconfig);
   my $defaultcurrency = $form->{defaultcurrency};
 
-  # Seit neuestem wird die department_id schon übergeben UND $form->department nicht mehr
-  # korrekt zusammengebaut. Sehr wahrscheinlich beim Umstieg auf T8 kaputt gegangen
-  # Ich lass den Code von 2005 erstmal noch stehen ;-) jb 03-2011
-  if (!$form->{department_id}){
-    ($null, $form->{department_id}) = split(/--/, $form->{department});
-  }
-
   my $all_units = AM->retrieve_units($myconfig, $form);
 
   if (!$payments_only) {
@@ -803,6 +796,19 @@ SQL
                                   name_postfix => "_$i",
                                   dbh          => $dbh);
     }
+    # link previous items with invoice items
+    foreach (qw(delivery_order_items orderitems invoice)) {
+      if ($form->{"converted_from_${_}_id_$i"}) {
+        RecordLinks->create_links('dbh'        => $dbh,
+                                  'mode'       => 'ids',
+                                  'from_table' => $_,
+                                  'from_ids'   => $form->{"converted_from_${_}_id_$i"},
+                                  'to_table'   => 'invoice',
+                                  'to_id'      => $form->{"invoice_id_$i"},
+        );
+        delete $form->{"converted_from_${_}_id_$i"};
+      }
+    }
   }
 
   # total payments, don't move we need it here
@@ -1200,14 +1206,16 @@ SQL
   }
 
   # Link this record to the records it was created from.
-  RecordLinks->create_links('dbh'        => $dbh,
-                            'mode'       => 'ids',
-                            'from_table' => 'oe',
-                            'from_ids'   => $form->{convert_from_oe_ids},
-                            'to_table'   => 'ar',
-                            'to_id'      => $form->{id},
-    );
-  delete $form->{convert_from_oe_ids};
+  if ($form->{convert_from_oe_ids}) {
+    RecordLinks->create_links('dbh'        => $dbh,
+                              'mode'       => 'ids',
+                              'from_table' => 'oe',
+                              'from_ids'   => $form->{convert_from_oe_ids},
+                              'to_table'   => 'ar',
+                              'to_id'      => $form->{id},
+      );
+    delete $form->{convert_from_oe_ids};
+  }
 
   my @convert_from_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{convert_from_do_ids};