Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. create or replace trigger trig_itemnf_valores
  2. before insert on itemnf
  3. for each row
  4. declare
  5. cursor c is
  6. select valorCompra,ValorVenda
  7. from Produto
  8. where codproduto = :new.codproduto;
  9. begin
  10. open c;
  11. fetch c into :new.ValorUnidCusto, :new.ValorUnidVenda;
  12. close c;
  13. end;
  14. /
  15.  
  16. create or replace trigger trig_itemnf_estoque
  17. after insert on itemnf
  18. for each row
  19. declare
  20. cursor c is
  21. select quantEstoque
  22. from produto
  23. where codproduto = :new.codproduto;
  24. total int;
  25. begin
  26. open c;
  27. fetch c into total;
  28. if total - :new.quant >= 0 then
  29. update Produto
  30. set quantEstoque = quantEstoque -
  31. :new.quant
  32. where codproduto = :new.codproduto;
  33. else
  34. rollback;
  35. end if;
  36. close c;
  37. end;
  38. /
  39.  
  40. create or replace trigger trig_itemnf_ins_totalnf
  41. after insert on itemnf
  42. for each row
  43. begin
  44. update notafiscal
  45. set valorTotal = valorTotal +
  46. :new.quant * :new.valorUnidVenda
  47. where NumNFiscal = :new.NumNFiscal;
  48. end;
  49. /
  50.  
  51. create or replace trigger trig_itemnf_del_totalnf
  52. after delete on itemnf
  53. for each row
  54. begin
  55. update notafiscal
  56. set valorTotal = valorTotal -
  57. :old.quant * :old.valorUnidVenda
  58. where NumNFiscal = :old.NumNFiscal;
  59. end;
  60. /
  61.  
  62. create or replace trigger trig_itemnf_upd_totalnf
  63. after update on itemnf
  64. for each row
  65. begin
  66. update notafiscal
  67. set valorTotal = valorTotal -
  68. :old.quant * :old.valorUnidVenda +
  69. :new.quant * :new.valorUnidVenda
  70. where NumNFiscal = :old.NumNFiscal;
  71. end;
  72. /
  73.  
  74. create or replace trigger trig_notaFiscal_upd_totalfatura
  75. after update on NotaFiscal
  76. for each row
  77. begin
  78. update Fatura
  79. set valortotal = valortotal -
  80. :old.valortotal + :new.valortotal
  81. where numfatura = :new.numfatura;
  82. end;
  83. /
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement