Einkaufsstornos auch verknüpfen
authorJan Büren <jan@kivitendo-premium.de>
Thu, 9 Jun 2016 15:13:46 +0000 (17:13 +0200)
committerJan Büren <jan@kivitendo-premium.de>
Thu, 9 Jun 2016 15:13:46 +0000 (17:13 +0200)
Analog zur Verkaufs-Ansicht auch die Einkaufsrechnungen bei
Stornos verknüpfn

SL/IR.pm
bin/mozilla/ir.pl

index aa2ed31..620fa18 100644 (file)
--- a/SL/IR.pm
+++ b/SL/IR.pm
@@ -418,7 +418,7 @@ SQL
                                 dbh          => $dbh);
 
     # link previous items with invoice items See IS.pm (no credit note -> no invoice item)
-    foreach (qw(delivery_order_items orderitems)) {
+    foreach (qw(delivery_order_items orderitems invoice)) {
       if (!$form->{useasnew} && $form->{"converted_from_${_}_id_$i"}) {
         RecordLinks->create_links('dbh'        => $dbh,
                                   'mode'       => 'ids',
@@ -758,16 +758,18 @@ SQL
 
   Common::webdav_folder($form);
 
-  # Link this record to the records it was created from.
-  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'   => 'ap',
-                              'to_id'      => $form->{id},
+  # Link this record to the records it was created from order or invoice (storno)
+  foreach (qw(oe ap)) {
+    if ($form->{"convert_from_${_}_ids"}) {
+      RecordLinks->create_links('dbh'        => $dbh,
+                                'mode'       => 'ids',
+                                'from_table' => $_,
+                                'from_ids'   => $form->{"convert_from_${_}_ids"},
+                                'to_table'   => 'ap',
+                                'to_id'      => $form->{id},
       );
-    delete $form->{convert_from_oe_ids};
+      delete $form->{"convert_from_${_}_ids"};
+    }
   }
 
   my @convert_from_do_ids = map { $_ * 1 } grep { $_ } split m/\s+/, $form->{convert_from_do_ids};
index e08c435..5ec505a 100644 (file)
@@ -334,7 +334,7 @@ sub form_header {
     max_dunning_level dunning_amount
     shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact shiptophone shiptofax
     shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
-    convert_from_do_ids convert_from_oe_ids show_details gldate useasnew
+    convert_from_do_ids convert_from_oe_ids convert_from_ap_ids show_details gldate useasnew
   ), @custom_hiddens,
   map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
 
@@ -626,7 +626,8 @@ sub storno {
   $form->{paidaccounts} = 0;
   map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
   # set new ids for storno invoice
-  delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
+  # set new persistent ids for storno invoice items
+  $form->{"converted_from_invoice_id_$_"} = delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
 
   # saving the history
   if(!exists $form->{addition} && $form->{id} ne "") {
@@ -637,6 +638,8 @@ sub storno {
   }
   # /saving the history
 
+  # record link invoice to storno
+  $form->{convert_from_ap_ids} = $form->{id};
   $form->{storno_id} = $form->{id};
   $form->{storno} = 1;
   $form->{id} = "";