Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create or replace trigger trig_itemnf_valores
- before insert on itemnf
- for each row
- declare
- cursor c is
- select valorCompra,ValorVenda
- from Produto
- where codproduto = :new.codproduto;
- begin
- open c;
- fetch c into :new.ValorUnidCusto, :new.ValorUnidVenda;
- close c;
- end;
- /
- create or replace trigger trig_itemnf_estoque
- after insert on itemnf
- for each row
- declare
- cursor c is
- select quantEstoque
- from produto
- where codproduto = :new.codproduto;
- total int;
- begin
- open c;
- fetch c into total;
- if total - :new.quant >= 0 then
- update Produto
- set quantEstoque = quantEstoque -
- :new.quant
- where codproduto = :new.codproduto;
- else
- rollback;
- end if;
- close c;
- end;
- /
- create or replace trigger trig_itemnf_ins_totalnf
- after insert on itemnf
- for each row
- begin
- update notafiscal
- set valorTotal = valorTotal +
- :new.quant * :new.valorUnidVenda
- where NumNFiscal = :new.NumNFiscal;
- end;
- /
- create or replace trigger trig_itemnf_del_totalnf
- after delete on itemnf
- for each row
- begin
- update notafiscal
- set valorTotal = valorTotal -
- :old.quant * :old.valorUnidVenda
- where NumNFiscal = :old.NumNFiscal;
- end;
- /
- create or replace trigger trig_itemnf_upd_totalnf
- after update on itemnf
- for each row
- begin
- update notafiscal
- set valorTotal = valorTotal -
- :old.quant * :old.valorUnidVenda +
- :new.quant * :new.valorUnidVenda
- where NumNFiscal = :old.NumNFiscal;
- end;
- /
- create or replace trigger trig_notaFiscal_upd_totalfatura
- after update on NotaFiscal
- for each row
- begin
- update Fatura
- set valortotal = valortotal -
- :old.valortotal + :new.valortotal
- where numfatura = :new.numfatura;
- end;
- /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement