src-db/database/model/triggers/C_DP_MANAGEMENT_CHK_RESTR_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_DP_MANAGEMENT_CHK_RESTR_TRG">
adrian@94
     3
    <trigger name="C_DP_MANAGEMENT_CHK_RESTR_TRG" table="C_DP_MANAGEMENT" 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
/*************************************************************************
adrian@94
    11
* The contents of this file are subject to the Openbravo  Public  License
adrian@94
    12
* Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    13
* Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    14
* file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    15
* the License at http://www.openbravo.com/legal/license.html
adrian@94
    16
* Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    17
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    18
* License for the specific  language  governing  rights  and  limitations
adrian@94
    19
* under the License.
adrian@94
    20
* The Original Code is Openbravo ERP.
adrian@94
    21
* The Initial Developer of the Original Code is Openbravo SL
adrian@94
    22
* All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    23
* All Rights Reserved.
adrian@94
    24
* Contributor(s):  ______________________________________.
adrian@94
    25
************************************************************************/
gorkaion@280
    26
v_DateNull DATE := TO_DATE('01-01-1900','DD-MM-YYYY');
adrian@94
    27
BEGIN
adrian@94
    28
  IF UPDATING THEN
adrian@94
    29
    IF (    :OLD.processed = 'Y'
gorkaion@239
    30
        AND (   (COALESCE (:OLD.documentno, '.') <>
adrian@94
    31
                                               COALESCE (:NEW.documentno, '.')
adrian@94
    32
                )
gorkaion@239
    33
             OR (COALESCE (:OLD.c_doctype_id, 0) <>
adrian@94
    34
                                               COALESCE (:NEW.c_doctype_id, 0)
adrian@94
    35
                )
gorkaion@280
    36
             OR (COALESCE (:OLD.datetrx, v_DateNull) <>
gorkaion@280
    37
                                         COALESCE (:NEW.datetrx, v_DateNull)
adrian@94
    38
                )
gorkaion@239
    39
             OR (COALESCE (:OLD.c_currency_id, 0) <>
adrian@94
    40
                                              COALESCE (:NEW.c_currency_id, 0)
adrian@94
    41
                )
gorkaion@239
    42
             OR (COALESCE (:OLD.user1_id, 0) <> COALESCE (:NEW.user1_id, 0))
gorkaion@239
    43
             OR (COALESCE (:OLD.user2_id, 0) <> COALESCE (:NEW.user2_id, 0))
gorka@401
    44
             OR (COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
gorka@401
    45
             OR (COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0))
adrian@94
    46
            )
adrian@94
    47
       ) THEN
antonio@735
    48
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted');
adrian@94
    49
    END IF;
adrian@94
    50
adrian@94
    51
    IF (    :OLD.posted = 'Y'
gorkaion@280
    52
        AND (   (COALESCE (:OLD.dateacct, v_DateNull) <>
gorkaion@280
    53
                                        COALESCE (:NEW.dateacct, v_DateNull)
adrian@94
    54
                )
gorkaion@239
    55
             OR (COALESCE (:OLD.c_campaign_id, 0) <>
adrian@94
    56
                                              COALESCE (:NEW.c_campaign_id, 0)
adrian@94
    57
                )
gorkaion@239
    58
             OR (COALESCE (:OLD.c_project_id, 0) <>
adrian@94
    59
                                               COALESCE (:NEW.c_project_id, 0)
adrian@94
    60
                )
gorkaion@239
    61
             OR (COALESCE (:OLD.c_activity_id, 0) <>
adrian@94
    62
                                              COALESCE (:NEW.c_activity_id, 0)
adrian@94
    63
                )
adrian@94
    64
            )
adrian@94
    65
       ) THEN
antonio@735
    66
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted');
adrian@94
    67
    END IF;
adrian@94
    68
  END IF;
adrian@94
    69
adrian@94
    70
  IF (INSERTING) THEN
adrian@94
    71
    IF (:NEW.processed = 'Y') THEN
antonio@735
    72
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted');
adrian@94
    73
 END IF;
adrian@94
    74
  END IF;
adrian@94
    75
adrian@94
    76
  IF (DELETING) THEN
adrian@94
    77
    IF (:OLD.processed = 'Y') THEN
antonio@735
    78
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted');
adrian@94
    79
 END IF;
adrian@94
    80
  END IF;
antonio@735
    81
END C_DP_MANAGEMENT_CHK_RESTR_TRG
gorkaion@239
    82
]]></body>
adrian@94
    83
    </trigger>
adrian@94
    84
  </database>