Hi
Trigger code to add and minus stock from inventory
==========================add stock===========================
create or replace trigger TRIG_STOCK2
after insert or update on purchase
for each row
begin
update inventory
set stock=stock+:new.qty
where id=:new.id;
end;
====================Insert new stock & add previous stock======================
create or replace trigger TRIG_STOCK2
after insert or update on purchase
for each row
begin
IF inserting then
insert into inventory
values(:new.id,:new.qty,:new.unit_price);
ELSIF INSERTING THEN
update inventory
set stock=stock+:new.qty
where id=:new.id;
commit;
END IF;
end;
========================minus stock===========================
create or replace trigger TRIG_STOCK
after insert or update on Sales
for each row
begin
update inventory
set stock=stock-:new.qty
where id=:new.id;
end;
==============================================================
No comments:
Post a Comment