Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. tables:
  2.  
  3. -> detalle_recepcion_merk
  4. |-> trigger: add_inventario_recepcion AFTER INSERT ON detalle_recepcion_merk FOR EACH ROW EXECUTE PROCEDURE add_rec_inventario()
  5.  
  6.  
  7. # function add_rec_inventario:
  8.  
  9. CREATE OR REPLACE FUNCTION public.add_rec_inventario()
  10. RETURNS trigger
  11. LANGUAGE plpgsql
  12. AS $function$
  13. begin
  14. -- inventario: id_movto | id_cedis | id_tipo_movto | id_producto | folio_movto | lote | cantidad_entrada | cantidad_salida | id_usuario | fecha_add
  15. --
  16. insert into inventario (id_cedis, id_tipo_movto, id_producto, folio_movto, lote, cantidad_entrada, cantidad_salida, id_usuario, fecha_add) values (NEW.id_cedis, 1, NEW.id_producto, NEW.id_recepcion, NEW.lote, NEW.cantidad, 0, NEW.id_usuario, current_timestamp);
  17. return NEW;
  18. exception when others then
  19. -- log if fails;
  20. insert into function_logs(message,fecha_add) values('ERR: add_rec_inventario ' || SQLERRM, current_timestamp);
  21.  
  22. end;
  23. $function$
  24.  
  25.  
  26.  
  27.  
  28. -> inventario
  29. |-> trigger : manage_lote AFTER INSERT ON inventario FOR EACH ROW EXECUTE PROCEDURE manage_lotes()
  30.  
  31. # function manage_lotes():
  32.  
  33. CREATE OR REPLACE FUNCTION public.manage_lotes()
  34. RETURNS trigger
  35. LANGUAGE plpgsql
  36. AS $function$
  37. declare orden integer;
  38. begin
  39. select coalesce(max(priority),0) into orden from detalle_lotes where id_producto = NEW.id_producto;
  40. if (NEW.id_tipo_movto = 1) then
  41. -- add by recepcion merk
  42. insert into detalle_lotes values (NEW.id_producto, NEW.lote, NEW.cantidad, NEW.cantidad, orden+1);
  43. end if;
  44. return NEW;
  45.  
  46. exception when others then
  47. insert into function_logs(message, fecha_add) values('ERR @ manage_lotes: ' || SQLERRM, current_timestamp);
  48.  
  49. end;
  50. $function$
  51.  
  52. -----------------------------------------------
  53.  
  54. ERROR: control reached end of trigger procedure without RETURN
  55. CONTEXT: PL/pgSQL function add_rec_inventario()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement