Advertisement
tko_pb

trigger

Jan 17th, 2019
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. <?xml version="1.0"?>
  2. <database name="TRIGGER M_REQUISITIONORDER_TRG">
  3. <trigger name="M_REQUISITIONORDER_TRG" table="M_REQUISITIONORDER" fires="before" insert="true" update="true" delete="true" foreach="row">
  4. <body><![CDATA[
  5.  
  6. /*************************************************************************
  7. * The contents of this file are subject to the Openbravo Public License
  8. * Version 1.1 (the "License"), being the Mozilla Public License
  9. * Version 1.1 with a permitted attribution clause; you may not use this
  10. * file except in compliance with the License. You may obtain a copy of
  11. * the License at http://www.openbravo.com/legal/license.html
  12. * Software distributed under the License is distributed on an "AS IS"
  13. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing rights and limitations
  15. * under the License.
  16. * The Original Code is Openbravo ERP.
  17. * The Initial Developer of the Original Code is Openbravo SLU
  18. * All portions are Copyright (C) 2008-2014 Openbravo SLU
  19. * All Rights Reserved.
  20. * Contributor(s): ______________________________________.
  21. ************************************************************************/
  22. v_DocStatus VARCHAR(60);
  23. v_ReqStatus VARCHAR(60);
  24. v_Count NUMBER;
  25.  
  26. BEGIN
  27.  
  28. IF AD_isTriggerEnabled()='N' THEN RETURN;
  29. END IF;
  30.  
  31.  
  32.  
  33. IF INSERTING THEN
  34. SELECT DocStatus, ReqStatus INTO v_DocStatus, v_reqstatus
  35. FROM M_Requisition, M_RequisitionLine
  36. WHERE M_REquisitionLine_ID = :new.M_RequisitionLine_ID
  37. AND M_Requisition.M_Requisition_ID = M_RequisitionLine.M_Requisition_ID;
  38. ELSE
  39. SELECT DocStatus, ReqStatus INTO v_DocStatus, v_reqstatus
  40. FROM M_Requisition, M_RequisitionLine
  41. WHERE M_REquisitionLine_ID = :old.M_RequisitionLine_ID
  42. AND M_Requisition.M_Requisition_ID = M_RequisitionLine.M_Requisition_ID;
  43. END IF;
  44.  
  45. IF (INSERTING) THEN
  46. SELECT COUNT(*) INTO v_Count
  47. FROM M_REQUISITIONLINE A, C_ORDERLINE B
  48. WHERE A.M_REQUISITIONLINE_ID = :new.M_REQUISITIONLINE_ID
  49. AND B.C_ORDERLINE_ID = :new.C_ORDERLINE_ID
  50. AND A.M_PRODUCT_ID = B.M_PRODUCT_ID;
  51. IF (v_Count = 0) THEN
  52. RAISE_APPLICATION_ERROR(-20000, '@20524@');
  53. END IF;
  54. END IF;
  55.  
  56. IF ((v_DocStatus <> 'CO') OR (v_ReqStatus <> 'O')) THEN
  57. RAISE_APPLICATION_ERROR(-20000, '@RequisitionProcessed@');
  58. END IF;
  59.  
  60. IF (UPDATING OR DELETING) THEN
  61. UPDATE M_REQUISITIONLINE
  62. SET ORDEREDQTY = COALESCE(ORDEREDQTY,0) - :OLD.QTY
  63. WHERE M_REQUISITIONLINE_ID = :OLD.M_REQUISITIONLINE_ID;
  64. END IF;
  65. IF (INSERTING OR UPDATING) THEN
  66. UPDATE M_REQUISITIONLINE
  67. SET ORDEREDQTY = COALESCE(ORDEREDQTY,0) + :NEW.QTY
  68. WHERE M_REQUISITIONLINE_ID = :NEW.M_REQUISITIONLINE_ID;
  69. END IF;
  70. END M_REQUISITIONORDER_TRG
  71. ]]></body>
  72. </trigger>
  73. </database>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement