Advertisement
Guest User

Untitled

a guest
Mar 27th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. //bprl_inoutline_trg
  2.  
  3. CREATE OR REPLACE FUNCTION public.bprl_inoutline_trg()
  4. RETURNS trigger
  5. LANGUAGE plpgsql
  6. AS $function$ DECLARE
  7.  
  8. v_calcelmovementqty NUMERIC;
  9. v_faktorkali NUMERIC;
  10. v_bp_id varchar(32);
  11. v_bpreturn_id varchar(32);
  12. v_product_id varchar(32);
  13. v_productreturn_id varchar(32);
  14.  
  15. BEGIN
  16.  
  17. IF AD_isTriggerEnabled()='N' THEN IF TG_OP = 'DELETE' THEN RETURN OLD; ELSE RETURN NEW; END IF;
  18. END IF;
  19.  
  20.  
  21. -- trigger defintion here:
  22. /*
  23. * mencegah shipment/receipt negatif tanpa cancel ID
  24. * cek apakah movement qty <0
  25. * jika tidak, return
  26. * jika iya, cek apakah ada cancell id
  27. * jika tidak, maka exception
  28. * cek qty di cancell id, cek apakah faktor kali=-1
  29. * jika tidak, maka exception
  30. * jika iya, maka return
  31. * */
  32.  
  33. if new.ad_client_id='0BB4BA036586421AB4BA6B4272B927A0' then --khusus BPR lestari
  34. if (new.movementqty<0) then
  35. if new.canceled_inoutline_id is null then
  36. RAISE EXCEPTION '%','DATA_EXCEPTION' ;
  37. end if;
  38. select movementqty into v_calcelmovementqty from m_inoutline where m_inoutline_id=new.canceled_inoutline_id;
  39. if (v_calcelmovementqty is null or v_calcelmovementqty=0) then
  40. RAISE EXCEPTION '%','DATA_EXCEPTION' ;
  41. end if;
  42. v_faktorkali = v_calcelmovementqty/new.movementqty;
  43. if (v_faktorkali<>-1.0) then
  44. RAISE EXCEPTION '%','DATA_EXCEPTION' ;
  45. end if;
  46. select c_bpartner_id into v_bp_id
  47. from m_inoutline where m_inoutline_id=new.m_inoutline_id;
  48. select c_bpartner_id into v_bpreturn_id
  49. from m_inoutline where m_inoutline_id=new.canceled_inoutline_id;
  50. if (v_bp_id!=v_bpreturn_id) then
  51. RAISE EXCEPTION '%','DATA_EXCEPTION' ;
  52. end if;
  53. select m_product_id into v_product_id
  54. from m_inoutline where m_inoutline_id=new.m_inoutline_id;
  55. select m_product_id into v_productreturn_id
  56. from m_inoutline where m_inoutline_id=new.canceled_inoutline_id;
  57. if (v_product_id!=v_productreturn_id) then
  58. RAISE EXCEPTION '%','DATA_EXCEPTION' ;
  59. end if;
  60. end if;
  61. end if;
  62.  
  63.  
  64. IF TG_OP = 'DELETE' THEN RETURN OLD; ELSE RETURN NEW; END IF;
  65.  
  66. END
  67.  
  68. ; $function$
  69. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement