src-db/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 799 fef2c5e2feb7
child 2078 cf88ca44cdd2
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_ORDLINE_CHK_RESTRICTIONS_TRG">
adrian@94
     3
    <trigger name="C_ORDLINE_CHK_RESTRICTIONS_TRG" table="C_ORDERLINE" fires="before" insert="true" update="true" delete="true" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
asier@799
     5
/*************************************************************************
asier@799
     6
* The contents of this file are subject to the Openbravo  Public  License
asier@799
     7
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
asier@799
     8
* Version 1.1  with a permitted attribution clause; you may not  use this
asier@799
     9
* file except in compliance with the License. You  may  obtain  a copy of
asier@799
    10
* the License at http://www.openbravo.com/legal/license.html
asier@799
    11
* Software distributed under the License  is  distributed  on  an "AS IS"
asier@799
    12
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
asier@799
    13
* License for the specific  language  governing  rights  and  limitations
asier@799
    14
* under the License.
asier@799
    15
* The Original Code is Openbravo ERP.
asier@799
    16
* The Initial Developer of the Original Code is Openbravo SL
asier@799
    17
* All portions are Copyright (C) 2001-2008 Openbravo SL
asier@799
    18
* All Rights Reserved.
asier@799
    19
* Contributor(s):  ______________________________________.
asier@799
    20
************************************************************************/
gorkaion@239
    21
adrian@94
    22
  v_Processed CHAR(1) ;
juanpablo@1605
    23
  v_C_ORDER_ID VARCHAR2(32) ;
adrian@94
    24
  v_Docaction NVARCHAR2(2) ;
adrian@94
    25
BEGIN
adrian@94
    26
  IF INSERTING THEN
adrian@94
    27
    v_C_ORDER_ID:=:NEW.C_ORDER_ID;
adrian@94
    28
  ELSE
adrian@94
    29
    v_C_ORDER_ID:=:OLD.C_ORDER_ID;
antonio@737
    30
  END IF;
rafael@407
    31
  IF UPDATING THEN
juanpablo@1605
    32
    IF((COALESCE(:old.LINE, 0) <> COALESCE(:NEW.LINE, 0) OR COALESCE(:old.M_PRODUCT_ID, '0') <> COALESCE(:NEW.M_PRODUCT_ID, '0') OR COALESCE(:old.QTYORDERED, 0) <> COALESCE(:NEW.QTYORDERED, 0) OR COALESCE(:old.PRICELIST, 0) <> COALESCE(:NEW.PRICELIST, 0) OR COALESCE(:old.PRICEACTUAL, 0) <> COALESCE(:NEW.PRICEACTUAL, 0) OR COALESCE(:old.PRICELIMIT, 0) <> COALESCE(:NEW.PRICELIMIT, 0) OR COALESCE(:old.LINENETAMT, 0) <> COALESCE(:NEW.LINENETAMT, 0) OR COALESCE(:old.C_CHARGE_ID, '0') <> COALESCE(:NEW.C_CHARGE_ID, '0') OR COALESCE(:old.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0) OR COALESCE(:old.C_TAX_ID, '0') <> COALESCE(:NEW.C_TAX_ID, '0')  OR COALESCE(:old.DIRECTSHIP, '.') <> COALESCE(:NEW.DIRECTSHIP, '.') OR COALESCE(:old.M_ATTRIBUTESETINSTANCE_ID, '0') <> COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, '0') OR COALESCE(:old.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0) OR COALESCE(
juanpablo@1605
    33
      :old.M_PRODUCT_UOM_ID, '0') <> COALESCE(:NEW.M_PRODUCT_UOM_ID, '0') )) THEN
rafael@407
    34
      SELECT PROCESSED,
adrian@94
    35
    DOCACTION
adrian@94
    36
  INTO v_Processed,
adrian@94
    37
    v_Docaction
adrian@94
    38
  FROM C_ORDER
adrian@94
    39
  WHERE C_ORDER_ID=v_C_ORDER_ID;
antonio@737
    40
      IF(v_Processed='Y'
asier@799
    41
        AND v_Docaction <> 'CL' 
gorka@401
    42
        AND (
antonio@737
    43
          (COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0))
juanpablo@1605
    44
          OR(COALESCE(:OLD.M_PRODUCT_ID, '0') <> COALESCE(:NEW.M_PRODUCT_ID, '0'))
gorka@401
    45
          OR(COALESCE(:OLD.QTYORDERED, 0) <> COALESCE(:NEW.QTYORDERED, 0))
gorka@401
    46
          OR(COALESCE(:OLD.PRICELIST, 0) <> COALESCE(:NEW.PRICELIST, 0))
gorka@401
    47
          OR(COALESCE(:OLD.PRICEACTUAL, 0) <> COALESCE(:NEW.PRICEACTUAL, 0))
gorka@401
    48
          OR(COALESCE(:OLD.PRICELIMIT, 0) <> COALESCE(:NEW.PRICELIMIT, 0))
gorka@401
    49
          OR(COALESCE(:OLD.LINENETAMT, 0) <> COALESCE(:NEW.LINENETAMT, 0))
juanpablo@1605
    50
          OR(COALESCE(:OLD.C_CHARGE_ID, '0') <> COALESCE(:NEW.C_CHARGE_ID, '0'))
gorka@401
    51
          OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0))
juanpablo@1605
    52
          OR(COALESCE(:OLD.C_TAX_ID, '0') <> COALESCE(:NEW.C_TAX_ID, '0'))
gorka@401
    53
          OR(COALESCE(:OLD.DIRECTSHIP, '.') <> COALESCE(:NEW.DIRECTSHIP, '.'))
juanpablo@1605
    54
          OR(COALESCE(:OLD.M_ATTRIBUTESETINSTANCE_ID, '0') <> COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, '0'))
gorka@401
    55
          OR(COALESCE(:OLD.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0))
juanpablo@1605
    56
          OR(COALESCE(:OLD.M_PRODUCT_UOM_ID, '0') <> COALESCE(:NEW.M_PRODUCT_UOM_ID, '0'))
juanpablo@1605
    57
          OR(COALESCE(:old.AD_ORG_ID, '0') <> COALESCE(:new.AD_ORG_ID, '0'))
juanpablo@1605
    58
          OR(COALESCE(:old.AD_CLIENT_ID, '0') <> COALESCE(:new.AD_CLIENT_ID, '0'))
gorka@401
    59
        )
gorka@401
    60
      )THEN
adrian@94
    61
        RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    62
      END IF;
adrian@94
    63
    END IF;
adrian@94
    64
  END IF;
rafael@407
    65
  IF(DELETING OR INSERTING) THEN
rafael@407
    66
  SELECT PROCESSED,
rafael@407
    67
    DOCACTION
rafael@407
    68
  INTO v_Processed,
rafael@407
    69
    v_Docaction
rafael@407
    70
  FROM C_ORDER
rafael@407
    71
  WHERE C_ORDER_ID=v_C_ORDER_ID;
rafael@407
    72
    IF (v_Processed='Y') THEN
adrian@94
    73
    RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    74
  END IF;
rafael@407
    75
  END IF;
antonio@735
    76
END C_ORDLINE_CHK_RESTRICTIONS_TRG
gorkaion@239
    77
]]></body>
adrian@94
    78
    </trigger>
adrian@94
    79
  </database>