src-db/database/model/triggers/C_ORDER_CHK_RESTRINCTIONS_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Mon, 28 Apr 2008 09:28:08 +0000
changeset 785 8dba91261590
parent 756 ae11e4610537
child 1605 8a0fe0193bef
permissions -rw-r--r--
Fix last update of copyright years in database files
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_ORDER_CHK_RESTRINCTIONS_TRG">
adrian@94
     3
    <trigger name="C_ORDER_CHK_RESTRINCTIONS_TRG" table="C_ORDER" fires="before" insert="true" update="true" delete="true" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
gorkaion@239
     5
adrian@170
     6
adrian@94
     7
adrian@94
     8
gorka@401
     9
adrian@94
    10
v_n NUMBER;
adrian@94
    11
v_OrderLine_Offer_Id NUMBER;
adrian@94
    12
v_Price NUMBER;
adrian@94
    13
v_lineNo NUMBER;
adrian@94
    14
v_PriceNew NUMBER;
adrian@94
    15
v_amt NUMBER;
gorkaion@280
    16
v_DateNull DATE := TO_DATE('01-01-1900','DD-MM-YYYY');
adrian@94
    17
adrian@94
    18
BEGIN
adrian@94
    19
  IF UPDATING THEN
antonio@737
    20
    IF(:OLD.Processed='Y' AND :OLD.Docaction <> 'CL'
antonio@737
    21
          AND(
gorka@401
    22
               (COALESCE(:OLD.C_BPartner_ID, 0) <> COALESCE(:NEW.C_BPartner_ID, 0))
gorka@401
    23
               OR(COALESCE(:OLD.DOCUMENTNO, '.') <> COALESCE(:NEW.DOCUMENTNO, '.'))
gorkaion@239
    24
               OR(COALESCE(:OLD.C_DOCTYPE_ID, 0) <> COALESCE(:NEW.C_DOCTYPE_ID, 0))
gorkaion@239
    25
               OR(COALESCE(:OLD.C_DOCTYPETARGET_ID, 0) <> COALESCE(:NEW.C_DOCTYPETARGET_ID, 0))
gorkaion@280
    26
               OR(COALESCE(:OLD.DATEORDERED, v_DateNull) <> COALESCE(:NEW.DATEORDERED, v_DateNull))
gorkaion@239
    27
               OR(COALESCE(:OLD.C_BPARTNER_LOCATION_ID, 0) <> COALESCE(:NEW.C_BPARTNER_LOCATION_ID, 0))
gorkaion@239
    28
               OR(COALESCE(:OLD.PAYMENTRULE, '.') <> COALESCE(:NEW.PAYMENTRULE, '.'))
gorkaion@239
    29
               OR(COALESCE(:OLD.C_PAYMENTTERM_ID, 0) <> COALESCE(:NEW.C_PAYMENTTERM_ID, 0))
gorkaion@239
    30
               OR(COALESCE(:OLD.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0))
gorkaion@239
    31
               OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0))
gorkaion@239
    32
               OR(COALESCE(:OLD.TOTALLINES, 0) <> COALESCE(:NEW.TOTALLINES, 0))
gorkaion@239
    33
               OR(COALESCE(:OLD.GRANDTOTAL, 0) <> COALESCE(:NEW.GRANDTOTAL, 0))
gorkaion@280
    34
               OR(COALESCE(:OLD.DATEPROMISED, v_DateNull) <> COALESCE(:NEW.DATEPROMISED, v_DateNull))
gorkaion@239
    35
               OR(COALESCE(:OLD.BILLTO_ID, 0) <> COALESCE(:NEW.BILLTO_ID, 0))
gorkaion@239
    36
               OR(COALESCE(:OLD.DELIVERYRULE, '.') <> COALESCE(:NEW.DELIVERYRULE, '.'))
gorkaion@239
    37
               OR(COALESCE(:OLD.M_PRICELIST_ID, 0) <> COALESCE(:NEW.M_PRICELIST_ID, 0))
gorkaion@239
    38
               OR(COALESCE(:OLD.AD_USER_ID, 0) <> COALESCE(:NEW.AD_USER_ID, 0))
gorkaion@239
    39
               OR(COALESCE(:OLD.AD_ORGTRX_ID, 0) <> COALESCE(:NEW.AD_ORGTRX_ID, 0))
gorkaion@239
    40
               OR(COALESCE(:OLD.USER1_ID, 0) <> COALESCE(:NEW.USER1_ID, 0))
gorkaion@239
    41
               OR(COALESCE(:OLD.M_WAREHOUSE_ID, 0) <> COALESCE(:NEW.M_WAREHOUSE_ID, 0))
gorkaion@239
    42
               OR(COALESCE(:OLD.DROPSHIP_USER_ID, 0) <> COALESCE(:NEW.DROPSHIP_USER_ID, 0))
gorkaion@239
    43
               OR(COALESCE(:OLD.USER2_ID, 0) <> COALESCE(:NEW.USER2_ID, 0))
gorkaion@239
    44
               OR(COALESCE(:OLD.DROPSHIP_BPARTNER_ID, 0) <> COALESCE(:NEW.DROPSHIP_BPARTNER_ID, 0))
gorkaion@239
    45
               OR(COALESCE(:OLD.DROPSHIP_LOCATION_ID, 0) <> COALESCE(:NEW.DROPSHIP_LOCATION_ID, 0))
gorkaion@239
    46
               OR(COALESCE(:OLD.DELIVERYVIARULE, '.') <> COALESCE(:NEW.DELIVERYVIARULE, '.'))
gorka@401
    47
               OR(COALESCE(:OLD.PRIORITYRULE,'.') <> COALESCE(:NEW.PRIORITYRULE, '.'))
gorka@401
    48
               OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
gorka@401
    49
               OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0))
gorka@401
    50
          )
gorka@401
    51
    )THEN
adrian@94
    52
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    53
    END IF;
gorkaion@280
    54
    IF(:OLD.Posted='Y' AND ((COALESCE(:OLD.DATEACCT, v_DateNull) <> COALESCE(:NEW.DATEACCT, v_DateNull)) OR(COALESCE(:OLD.C_CAMPAIGN_ID, 0) <> COALESCE(:NEW.C_CAMPAIGN_ID, 0)) OR(COALESCE(:OLD.C_PROJECT_ID, 0) <> COALESCE(:NEW.C_PROJECT_ID, 0)) OR(COALESCE(:OLD.C_ACTIVITY_ID, 0) <> COALESCE(:NEW.C_ACTIVITY_ID, 0)))) THEN
adrian@94
    55
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    56
    END IF;
adrian@94
    57
adrian@94
    58
adrian@94
    59
adrian@94
    60
    IF (COALESCE(:OLD.C_BPartner_ID, 0)!=COALESCE(:NEW.C_BPartner_ID, 0)) OR (COALESCE(:OLD.M_PriceList_ID,0) != COALESCE(:NEW.M_PriceList_ID,0))  THEN
adrian@94
    61
      SELECT COUNT(*)
adrian@94
    62
        INTO v_n
adrian@94
    63
        FROM C_ORDERLINE
adrian@94
    64
       WHERE C_Order_ID = :NEW.C_Order_ID;
adrian@94
    65
gorkaion@239
    66
       IF v_n>0 THEN
adrian@94
    67
         RAISE_APPLICATION_ERROR(-20502, 'Cannot change bussiness partner or price list if there are lines') ;
adrian@94
    68
       END IF;
adrian@94
    69
     END IF;
adrian@94
    70
  END IF;
adrian@94
    71
adrian@94
    72
adrian@94
    73
  IF(DELETING) THEN
adrian@94
    74
    IF :OLD.Processed='Y' THEN
adrian@94
    75
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    76
    END IF;
adrian@94
    77
  END IF;
adrian@94
    78
  IF(INSERTING) THEN
adrian@94
    79
    IF :NEW.Processed='Y' THEN
adrian@94
    80
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    81
    END IF;
adrian@94
    82
  END IF;
antonio@735
    83
END C_ORDER_CHK_RESTRINCTIONS_TRG
gorkaion@239
    84
]]></body>
adrian@94
    85
    </trigger>
adrian@94
    86
  </database>