Angebots-Position mit Auftragsposition verknüpft (orderitems -> orderitems)
authorJan Büren <jan@kivitendo-premium.de>
Thu, 22 Jan 2015 14:26:33 +0000 (15:26 +0100)
committerJan Büren <jan@kivitendo-premium.de>
Thu, 22 Jan 2015 14:26:33 +0000 (15:26 +0100)
Angebot -> Workflow Auftrag

 - from_table -> to_table (tabelleneintrag)     i.O.
 - delete trigger                               i.O.
 - mittlere position löschen (vor speichern)    i.O.
 - update sicher in form                        i.O.
++++++++
 - mehrfach speichern (converted* wird nicht gelöscht)     n.i.O.

SL/OE.pm
bin/mozilla/oe.pl
sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql [new file with mode: 0644]

index a60b86c..9d6f849 100644 (file)
--- a/SL/OE.pm
+++ b/SL/OE.pm
@@ -578,6 +578,16 @@ SQL
                                   name_prefix  => 'ic_',
                                   name_postfix => "_$i",
                                   dbh          => $dbh);
+      # link quotation items with order items
+      if ($form->{"converted_from_quotation_orderitems_id_$i"}) {
+        RecordLinks->create_links('dbh'        => $dbh,
+                                  'mode'       => 'ids',
+                                  'from_table' => 'orderitems',
+                                  'from_ids'   => $form->{"converted_from_quotation_orderitems_id_$i"},
+                                  'to_table'   => 'orderitems',
+                                  'to_id'      => $orderitems_id,
+        );
+      }
     }
   }
   # search for orphaned ids
index 904a4b9..9a1da4a 100644 (file)
@@ -1820,6 +1820,7 @@ sub poso {
 
   # reset
   map { delete $form->{$_} } qw(id subject message cc bcc printed emailed queued customer vendor creditlimit creditremaining discount tradediscount oldinvtotal delivered ordnumber);
+  $form->{"converted_from_quotation_orderitems_id_$_"} = $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};  # always reset orderitems_id
   delete $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};  # always reset orderitems_id
 
   # if purchase_order was generated from sales_order, use  lastcost_$i as sellprice_$i
@@ -1896,6 +1897,7 @@ sub delivery_order {
 
   for my $i (1 .. $form->{rowcount}) {
     map { $form->{"${_}_${i}"} = $form->parse_amount(\%myconfig, $form->{"${_}_${i}"}) if ($form->{"${_}_${i}"}) } qw(ship qty sellprice listprice lastcost basefactor discount);
+    $form->{"converted_from_order_orderitems_id_$_"} = $form->{"orderitems_id_$_"} for 1 .. $form->{"rowcount"};
   }
 
   my %old_values = map { $_ => $form->{$_} } qw(customer_id oldcustomer customer vendor_id oldvendor vendor shipto_id);
diff --git a/sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql b/sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql
new file mode 100644 (file)
index 0000000..904f4bb
--- /dev/null
@@ -0,0 +1,46 @@
+-- @tag: record_links_orderitems_delete_triggers
+-- @description: delete trigger für verknüpfte invoice(items), orderitems und delivery_order_items
+-- @depends: record_links_post_delete_triggers2
+CREATE OR REPLACE FUNCTION clean_up_record_links_before_orderitems_delete() RETURNS trigger AS $$
+  BEGIN
+    DELETE FROM record_links
+      WHERE (from_table = 'orderitems' AND from_id = OLD.id)
+         OR (to_table   = 'orderitems' AND to_id   = OLD.id);
+    RETURN OLD;
+  END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION clean_up_record_links_before_delivery_order_items_delete() RETURNS trigger AS $$
+  BEGIN
+    DELETE FROM record_links
+      WHERE (from_table = 'delivery_order_items' AND from_id = OLD.id)
+         OR (to_table   = 'delivery_order_items' AND to_id   = OLD.id);
+    RETURN OLD;
+  END;
+$$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION clean_up_record_links_before_invoice_delete() RETURNS trigger AS $$
+  BEGIN
+    DELETE FROM record_links
+      WHERE (from_table = 'invoice' AND from_id = OLD.id)
+         OR (to_table   = 'invoice' AND to_id   = OLD.id);
+    RETURN OLD;
+  END;
+$$ LANGUAGE plpgsql;
+
+
+
+CREATE TRIGGER before_delete_orderitems_trigger
+BEFORE DELETE ON orderitems FOR EACH ROW EXECUTE
+PROCEDURE clean_up_record_links_before_orderitems_delete();
+
+CREATE TRIGGER before_delete_delivery_order_items_trigger
+BEFORE DELETE ON delivery_order_items FOR EACH ROW EXECUTE
+PROCEDURE clean_up_record_links_before_delivery_order_items_delete();
+
+CREATE TRIGGER before_delete_invoice_trigger
+BEFORE DELETE ON invoice FOR EACH ROW EXECUTE
+PROCEDURE clean_up_record_links_before_invoice_delete();
+
+
+