src-db/database/model/triggers/GL_JOURNAL_CHK_RESTRICT_TRG.xml
author Javier Etxarri <javier.echarri@openbravo.com>
Fri, 20 Dec 2013 13:03:18 +0100
changeset 21682 337545057885
parent 18880 aa594e52b24d
child 21737 fcb87e990fcd
permissions -rw-r--r--
Fixes issue 24755: Little problem when you change the G/L journal header
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER GL_JOURNAL_CHK_RESTRICT_TRG">
adrian@94
     3
    <trigger name="GL_JOURNAL_CHK_RESTRICT_TRG" table="GL_JOURNAL" 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
priya@9072
    12
    * Version  1.1  (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.
ggi@6701
    21
    * The Initial Developer of the Original Code is Openbravo SLU
naiara@16390
    22
    * All portions are Copyright (C) 2001-2012 Openbravo SLU
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');
asier@2084
    27
        
asier@2078
    28
BEGIN
asier@2084
    29
    
asier@2084
    30
    IF AD_isTriggerEnabled()='N' THEN RETURN;
asier@2078
    31
    END IF;
asier@2078
    32
asier@2078
    33
javier@21682
    34
    IF UPDATING THEN  
javier@21682
    35
      IF(:old.Processed='Y'
javier@21682
    36
        AND ((COALESCE(:old.DATEDOC, v_DateNull) <> COALESCE(:new.DATEDOC, v_DateNull))
javier@21682
    37
        OR(COALESCE(:old.C_PERIOD_ID, '0') <> COALESCE(:new.C_PERIOD_ID, '0'))
javier@21682
    38
        OR(COALESCE(:old.CURRENCYRATE, 0) <> COALESCE(:new.CURRENCYRATE, 0))
javier@21682
    39
        OR(COALESCE(:old.CURRENCYRATETYPE, '.') <> COALESCE(:new.CURRENCYRATETYPE, '.'))
javier@21682
    40
        OR(COALESCE(:old.CONTROLAMT, 0) <> COALESCE(:new.CONTROLAMT, 0))
javier@21682
    41
        OR(COALESCE(:old.AD_ORG_ID, '0') <> COALESCE(:new.AD_ORG_ID, '0'))
javier@21682
    42
        OR(COALESCE(:old.AD_CLIENT_ID, '0') <> COALESCE(:new.AD_CLIENT_ID, '0'))))
javier@21682
    43
        THEN  RAISE_APPLICATION_ERROR(-20000, '@20501@') ;
javier@21682
    44
      END IF;
javier@21682
    45
    
javier@21682
    46
      IF(:old.Posted='Y' 
javier@21682
    47
        AND ((COALESCE(:old.DATEACCT, v_DateNull) <> COALESCE(:new.DATEACCT, v_DateNull)) 
javier@21682
    48
        OR(COALESCE(:old.C_ACCTSCHEMA_ID, '0') <> COALESCE(:new.C_ACCTSCHEMA_ID, '0')) 
javier@21682
    49
        OR(COALESCE(:old.GL_CATEGORY_ID, '0') <> COALESCE(:new.GL_CATEGORY_ID, '0')) 
javier@21682
    50
        OR(COALESCE(:old.POSTINGTYPE, '.') <> COALESCE(:new.POSTINGTYPE, '.'))
javier@21682
    51
        OR(COALESCE(:OLD.User1_ID, '0') <> COALESCE(:NEW.User1_ID, '0'))
javier@21682
    52
        OR(COALESCE(:OLD.User2_ID, '0') <> COALESCE(:NEW.User2_ID, '0'))
javier@21682
    53
        OR(COALESCE(:OLD.C_Campaign_ID, '0') <> COALESCE(:NEW.C_Campaign_ID, '0'))
javier@21682
    54
        OR(COALESCE(:OLD.C_Project_ID, '0') <> COALESCE(:NEW.C_Project_ID, '0'))
javier@21682
    55
        OR(COALESCE(:OLD.A_Asset_ID, '0') <> COALESCE(:NEW.A_Asset_ID, '0'))
javier@21682
    56
        OR(COALESCE(:OLD.C_Costcenter_ID, '0') <> COALESCE(:NEW.C_Costcenter_ID, '0'))
javier@21682
    57
        OR(COALESCE(:OLD.C_BPartner_ID, '0') <> COALESCE(:NEW.C_BPartner_ID, '0'))
javier@21682
    58
        OR(COALESCE(:OLD.M_Product_ID, '0') <> COALESCE(:NEW.M_Product_ID, '0'))
javier@21682
    59
        )) 
javier@21682
    60
        THEN RAISE_APPLICATION_ERROR(-20000, '@20501@') ;
javier@21682
    61
      END IF;
javier@21682
    62
    
javier@21682
    63
      IF (:old.c_currency_id <> :new.c_currency_id) THEN
javier@21682
    64
        UPDATE gl_journalline SET c_currency_id = :new.c_currency_id where gl_journal_id = :old.gl_journal_id;
javier@21682
    65
      END IF;
adrian@94
    66
    END IF;
javier@21682
    67
    IF(DELETING) THEN
javier@21682
    68
      IF(:old.Processed='Y') THEN
javier@21682
    69
        RAISE_APPLICATION_ERROR(-20000, '@20501@') ;
javier@21682
    70
      END IF;
pandeeswari@18880
    71
    END IF;
javier@21682
    72
    IF(INSERTING) THEN
javier@21682
    73
      IF(:NEW.Processed='Y') THEN
javier@21682
    74
        RAISE_APPLICATION_ERROR(-20000, '@20501@') ;
javier@21682
    75
      END IF;
javier@21682
    76
    END IF;
javier@21682
    77
    END GL_JOURNAL_CHK_RESTRICT_TRG
gorkaion@239
    78
]]></body>
adrian@94
    79
    </trigger>
adrian@94
    80
  </database>