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
# 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
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);
--- /dev/null
+-- @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();
+
+
+