src-db/database/model/triggers/C_ORDER_CHK_RESTRINCTIONS_TRG.xml
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
child 2078 cf88ca44cdd2
equal deleted inserted replaced
1604:a1c518e6ed93 1605:8a0fe0193bef
     6 
     6 
     7 
     7 
     8 
     8 
     9 
     9 
    10 v_n NUMBER;
    10 v_n NUMBER;
    11 v_OrderLine_Offer_Id NUMBER;
    11 v_OrderLine_Offer_ID VARCHAR2(32);
    12 v_Price NUMBER;
    12 v_Price NUMBER;
    13 v_lineNo NUMBER;
    13 v_lineNo NUMBER;
    14 v_PriceNew NUMBER;
    14 v_PriceNew NUMBER;
    15 v_amt NUMBER;
    15 v_amt NUMBER;
    16 v_DateNull DATE := TO_DATE('01-01-1900','DD-MM-YYYY');
    16 v_DateNull DATE := TO_DATE('01-01-1900','DD-MM-YYYY');
    17 
    17 
    18 BEGIN
    18 BEGIN
    19   IF UPDATING THEN
    19   IF UPDATING THEN
    20     IF(:OLD.Processed='Y' AND :OLD.Docaction <> 'CL'
    20     IF(:OLD.Processed='Y' AND :OLD.Docaction <> 'CL'
    21           AND(
    21           AND(
    22                (COALESCE(:OLD.C_BPartner_ID, 0) <> COALESCE(:NEW.C_BPartner_ID, 0))
    22                (COALESCE(:OLD.C_BPartner_ID, '0') <> COALESCE(:NEW.C_BPartner_ID, '0'))
    23                OR(COALESCE(:OLD.DOCUMENTNO, '.') <> COALESCE(:NEW.DOCUMENTNO, '.'))
    23                OR(COALESCE(:OLD.DOCUMENTNO, '.') <> COALESCE(:NEW.DOCUMENTNO, '.'))
    24                OR(COALESCE(:OLD.C_DOCTYPE_ID, 0) <> COALESCE(:NEW.C_DOCTYPE_ID, 0))
    24                OR(COALESCE(:OLD.C_DOCTYPE_ID, '0') <> COALESCE(:NEW.C_DOCTYPE_ID, '0'))
    25                OR(COALESCE(:OLD.C_DOCTYPETARGET_ID, 0) <> COALESCE(:NEW.C_DOCTYPETARGET_ID, 0))
    25                OR(COALESCE(:OLD.C_DOCTYPETARGET_ID, '0') <> COALESCE(:NEW.C_DOCTYPETARGET_ID, '0'))
    26                OR(COALESCE(:OLD.DATEORDERED, v_DateNull) <> COALESCE(:NEW.DATEORDERED, v_DateNull))
    26                OR(COALESCE(:OLD.DATEORDERED, v_DateNull) <> COALESCE(:NEW.DATEORDERED, v_DateNull))
    27                OR(COALESCE(:OLD.C_BPARTNER_LOCATION_ID, 0) <> COALESCE(:NEW.C_BPARTNER_LOCATION_ID, 0))
    27                OR(COALESCE(:OLD.C_BPARTNER_LOCATION_ID, '0') <> COALESCE(:NEW.C_BPARTNER_LOCATION_ID, '0'))
    28                OR(COALESCE(:OLD.PAYMENTRULE, '.') <> COALESCE(:NEW.PAYMENTRULE, '.'))
    28                OR(COALESCE(:OLD.PAYMENTRULE, '.') <> COALESCE(:NEW.PAYMENTRULE, '.'))
    29                OR(COALESCE(:OLD.C_PAYMENTTERM_ID, 0) <> COALESCE(:NEW.C_PAYMENTTERM_ID, 0))
    29                OR(COALESCE(:OLD.C_PAYMENTTERM_ID, '0') <> COALESCE(:NEW.C_PAYMENTTERM_ID, '0'))
    30                OR(COALESCE(:OLD.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0))
    30                OR(COALESCE(:OLD.C_CHARGE_ID, '0') <> COALESCE(:NEW.C_CHARGE_ID, '0'))
    31                OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0))
    31                OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0))
    32                OR(COALESCE(:OLD.TOTALLINES, 0) <> COALESCE(:NEW.TOTALLINES, 0))
    32                OR(COALESCE(:OLD.TOTALLINES, 0) <> COALESCE(:NEW.TOTALLINES, 0))
    33                OR(COALESCE(:OLD.GRANDTOTAL, 0) <> COALESCE(:NEW.GRANDTOTAL, 0))
    33                OR(COALESCE(:OLD.GRANDTOTAL, 0) <> COALESCE(:NEW.GRANDTOTAL, 0))
    34                OR(COALESCE(:OLD.DATEPROMISED, v_DateNull) <> COALESCE(:NEW.DATEPROMISED, v_DateNull))
    34                OR(COALESCE(:OLD.DATEPROMISED, v_DateNull) <> COALESCE(:NEW.DATEPROMISED, v_DateNull))
    35                OR(COALESCE(:OLD.BILLTO_ID, 0) <> COALESCE(:NEW.BILLTO_ID, 0))
    35                OR(COALESCE(:OLD.BILLTO_ID, '0') <> COALESCE(:NEW.BILLTO_ID, '0'))
    36                OR(COALESCE(:OLD.DELIVERYRULE, '.') <> COALESCE(:NEW.DELIVERYRULE, '.'))
    36                OR(COALESCE(:OLD.DELIVERYRULE, '.') <> COALESCE(:NEW.DELIVERYRULE, '.'))
    37                OR(COALESCE(:OLD.M_PRICELIST_ID, 0) <> COALESCE(:NEW.M_PRICELIST_ID, 0))
    37                OR(COALESCE(:OLD.M_PRICELIST_ID, '0') <> COALESCE(:NEW.M_PRICELIST_ID, '0'))
    38                OR(COALESCE(:OLD.AD_USER_ID, 0) <> COALESCE(:NEW.AD_USER_ID, 0))
    38                OR(COALESCE(:OLD.AD_USER_ID, '0') <> COALESCE(:NEW.AD_USER_ID, '0'))
    39                OR(COALESCE(:OLD.AD_ORGTRX_ID, 0) <> COALESCE(:NEW.AD_ORGTRX_ID, 0))
    39                OR(COALESCE(:OLD.AD_ORGTRX_ID, '0') <> COALESCE(:NEW.AD_ORGTRX_ID, '0'))
    40                OR(COALESCE(:OLD.USER1_ID, 0) <> COALESCE(:NEW.USER1_ID, 0))
    40                OR(COALESCE(:OLD.USER1_ID, '0') <> COALESCE(:NEW.USER1_ID, '0'))
    41                OR(COALESCE(:OLD.M_WAREHOUSE_ID, 0) <> COALESCE(:NEW.M_WAREHOUSE_ID, 0))
    41                OR(COALESCE(:OLD.M_WAREHOUSE_ID, '0') <> COALESCE(:NEW.M_WAREHOUSE_ID, '0'))
    42                OR(COALESCE(:OLD.DROPSHIP_USER_ID, 0) <> COALESCE(:NEW.DROPSHIP_USER_ID, 0))
    42                OR(COALESCE(:OLD.DROPSHIP_USER_ID, '0') <> COALESCE(:NEW.DROPSHIP_USER_ID, '0'))
    43                OR(COALESCE(:OLD.USER2_ID, 0) <> COALESCE(:NEW.USER2_ID, 0))
    43                OR(COALESCE(:OLD.USER2_ID, '0') <> COALESCE(:NEW.USER2_ID, '0'))
    44                OR(COALESCE(:OLD.DROPSHIP_BPARTNER_ID, 0) <> COALESCE(:NEW.DROPSHIP_BPARTNER_ID, 0))
    44                OR(COALESCE(:OLD.DROPSHIP_BPARTNER_ID, '0') <> COALESCE(:NEW.DROPSHIP_BPARTNER_ID, '0'))
    45                OR(COALESCE(:OLD.DROPSHIP_LOCATION_ID, 0) <> COALESCE(:NEW.DROPSHIP_LOCATION_ID, 0))
    45                OR(COALESCE(:OLD.DROPSHIP_LOCATION_ID, '0') <> COALESCE(:NEW.DROPSHIP_LOCATION_ID, '0'))
    46                OR(COALESCE(:OLD.DELIVERYVIARULE, '.') <> COALESCE(:NEW.DELIVERYVIARULE, '.'))
    46                OR(COALESCE(:OLD.DELIVERYVIARULE, '.') <> COALESCE(:NEW.DELIVERYVIARULE, '.'))
    47                OR(COALESCE(:OLD.PRIORITYRULE,'.') <> COALESCE(:NEW.PRIORITYRULE, '.'))
    47                OR(COALESCE(:OLD.PRIORITYRULE,'.') <> COALESCE(:NEW.PRIORITYRULE, '.'))
    48                OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
    48                OR(COALESCE(:old.AD_ORG_ID, '0') <> COALESCE(:new.AD_ORG_ID, '0'))
    49                OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0))
    49                OR(COALESCE(:old.AD_CLIENT_ID, '0') <> COALESCE(:new.AD_CLIENT_ID, '0'))
    50           )
    50           )
    51     )THEN
    51     )THEN
    52       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
    52       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
    53     END IF;
    53     END IF;
    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
    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
    55       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
    55       RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
    56     END IF;
    56     END IF;
    57 
    57 
    58 
    58 
    59 
    59 
    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
    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
    61       SELECT COUNT(*)
    61       SELECT COUNT(*)
    62         INTO v_n
    62         INTO v_n
    63         FROM C_ORDERLINE
    63         FROM C_ORDERLINE
    64        WHERE C_Order_ID = :NEW.C_Order_ID;
    64        WHERE C_Order_ID = :NEW.C_Order_ID;
    65 
    65