-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcr_tgfnoplata.sql
53 lines (44 loc) · 1.46 KB
/
cr_tgfnoplata.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
-- Function: arc_energo."fntr_Счет_Резерв_Склад"()
-- DROP FUNCTION arc_energo."fntr_Счет_Резерв_Склад"();
CREATE OR REPLACE FUNCTION arc_energo."fntr_Счет_Резерв_Склад"()
RETURNS trigger AS
$BODY$
DECLARE
rs record;
invoice INTEGER;
suminvoice numeric;
BEGIN
If TG_OP ='DELETE' THEN
invoice:= OLD.Счет;
ELSE
invoice:=NEW.Счет;
END IF;
FOR rs IN
SELECT КодСодержания FROM "Содержание счета" WHERE "№ счета" = invoice
LOOP
PERFORM fn_set_stock_status(rs.КодСодержания,'t');
END LOOP;
If TG_OP ='UPDATE' THEN
IF NEW.Счет <> OLD.Счет THEN
invoice:= OLD.Счет;
FOR rs IN
SELECT КодСодержания FROM "Содержание счета" WHERE "№ счета" = invoice
LOOP
PERFORM fn_set_stock_status(rs.КодСодержания,'t');
END LOOP;
END IF;
END IF;
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION arc_energo."fntr_Счет_Резерв_Склад"()
OWNER TO arc_energo;
-- Trigger: tgoplata on arc_energo."ОплатыНТУ"
-- DROP TRIGGER tgoplata ON arc_energo."ОплатыНТУ";
CREATE TRIGGER tgoplata
AFTER INSERT OR UPDATE OF "Счет", "Сумма" OR DELETE
ON arc_energo."ОплатыНТУ"
FOR EACH ROW
EXECUTE PROCEDURE arc_energo."fntr_Счет_Резерв_Склад"();