From: Jan Büren Date: Thu, 22 Jan 2015 14:26:33 +0000 (+0100) Subject: Angebots-Position mit Auftragsposition verknüpft (orderitems -> orderitems) X-Git-Tag: release-3.2.0beta~51 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=6b6a2ddf2b4cfeab9a207313f856b9288bfde270;p=kivitendo-erp.git Angebots-Position mit Auftragsposition verknüpft (orderitems -> orderitems) 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. --- diff --git a/SL/OE.pm b/SL/OE.pm index a60b86c5a..9d6f84962 100644 --- 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 diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 904a4b9fe..9a1da4a39 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -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 index 000000000..904f4bb10 --- /dev/null +++ b/sql/Pg-upgrade2/record_links_orderitems_delete_triggers.sql @@ -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(); + + +