Commit db889ed2 authored by Hugo Hörnquist's avatar Hugo Hörnquist

Updated diff_view transfer trigger

parent 29b12338
......@@ -408,12 +408,24 @@ INNER JOIN diff_help d ON p.id = d.product_id;
-- WHERE p.sale_status = 0 OR s.active != 0;
-- where p.sale_status in (0, 1);
/*
* delete from the view to transfer,
* delete from the underlying table (diff_help) if
* a transfer is not desired.
*/
CREATE TRIGGER diff_view_transfer
INSTEAD OF DELETE ON diff_view
BEGIN
UPDATE stock SET active = OLD.amount WHERE product_id = OLD.product_id;
UPDATE stock SET active = OLD.actual
WHERE OLD.actual IS NOT NULL
AND product_id = OLD.product_id;
INSERT INTO stock_diff (product_id, expected, actual)
SELECT OLD.product_id, OLD.expected, OLD.actual;
SELECT OLD.product_id, OLD.expected, OLD.actual
WHERE OLD.actual IS NOT NULL;
DELETE FROM diff_help WHERE id = OLD.id;
END;
CREATE TRIGGER update_view_trigger
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment