src-db/database/model/triggers/C_INVOICE_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 931 75e954c00ac0
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_INVOICE_TRG">
adrian@94
     3
    <trigger name="C_INVOICE_TRG" table="C_INVOICE" 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@402
     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
    ************************************************************************/
adrian@94
    26
    /*************************************************************************
adrian@94
    27
    * Title: Check in deleting, invoice not processed
adrian@94
    28
    ************************************************************************/
adrian@94
    29
   v_n NUMBER;
adrian@94
    30
    BEGIN
adrian@94
    31
    -- If invoice is processed, is not allowed to change C_BPartner
adrian@94
    32
    IF UPDATING
adrian@94
    33
    THEN  IF(:OLD.Processed='Y'
gorkaion@239
    34
    AND ((COALESCE(:OLD.C_BPartner_ID, 0) <> COALESCE(:NEW.C_BPartner_ID, 0))
gorkaion@239
    35
    OR(COALESCE(:OLD.DOCUMENTNO, '.') <> COALESCE(:NEW.DOCUMENTNO, '.'))
gorkaion@239
    36
    OR(COALESCE(:OLD.C_DOCTYPE_ID, 0) <> COALESCE(:NEW.C_DOCTYPE_ID, 0))
gorkaion@239
    37
    OR(COALESCE(:OLD.C_DOCTYPETARGET_ID, 0) <> COALESCE(:NEW.C_DOCTYPETARGET_ID, 0))
gorkaion@280
    38
    OR(COALESCE(:OLD.DATEINVOICED, TO_DATE('31-12-9999', 'DD-MM-YYYY')) <> COALESCE(:NEW.DATEINVOICED, TO_DATE('31-12-9999', 'DD-MM-YYYY')))
gorkaion@239
    39
    OR(COALESCE(:OLD.C_BPARTNER_LOCATION_ID, 0) <> COALESCE(:NEW.C_BPARTNER_LOCATION_ID, 0))
gorkaion@239
    40
    OR(COALESCE(:OLD.PAYMENTRULE, '.') <> COALESCE(:NEW.PAYMENTRULE, '.'))
gorkaion@239
    41
    OR(COALESCE(:OLD.C_PAYMENTTERM_ID, 0) <> COALESCE(:NEW.C_PAYMENTTERM_ID, 0))
gorkaion@239
    42
    OR(COALESCE(:OLD.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0))
gorkaion@239
    43
    OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0))
gorkaion@239
    44
    OR(COALESCE(:OLD.M_PRICELIST_ID, 0) <> COALESCE(:NEW.M_PRICELIST_ID, 0))
gorkaion@239
    45
    OR(COALESCE(:OLD.AD_USER_ID, 0) <> COALESCE(:NEW.AD_USER_ID, 0))
gorkaion@239
    46
    OR(COALESCE(:OLD.AD_ORGTRX_ID, 0) <> COALESCE(:NEW.AD_ORGTRX_ID, 0))
gorkaion@239
    47
    OR(COALESCE(:OLD.USER1_ID, 0) <> COALESCE(:NEW.USER1_ID, 0))
gorka@402
    48
    OR(COALESCE(:OLD.USER2_ID, 0) <> COALESCE(:NEW.USER2_ID, 0))
gorka@402
    49
    OR(COALESCE(:old.AD_ORG_ID, 0) <> COALESCE(:new.AD_ORG_ID, 0))
gorka@402
    50
    OR(COALESCE(:old.AD_CLIENT_ID, 0) <> COALESCE(:new.AD_CLIENT_ID, 0))))
adrian@94
    51
    THEN  RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    52
    END IF;
adrian@94
    53
adrian@94
    54
      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
    55
      SELECT COUNT(*)
adrian@94
    56
        INTO v_n
adrian@94
    57
        FROM C_INVOICELINE
adrian@94
    58
       WHERE C_Invoice_ID = :NEW.C_Invoice_ID;
adrian@94
    59
gorkaion@239
    60
       IF v_n>0 THEN
adrian@94
    61
         RAISE_APPLICATION_ERROR(-20502, 'Cannot change bussiness partner or price list if there are lines') ;
adrian@94
    62
       END IF;
adrian@94
    63
     END IF;
adrian@94
    64
adrian@94
    65
adrian@94
    66
gorkaion@280
    67
   IF(:OLD.Posted='Y' AND ((COALESCE(:OLD.DATEACCT,  TO_DATE('31-12-9999', 'DD-MM-YYYY')) <> COALESCE(:NEW.DATEACCT, TO_DATE('31-12-9999', 'DD-MM-YYYY'))) 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
    68
    RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    69
   END IF;
adrian@94
    70
  END IF;
adrian@94
    71
  IF(INSERTING) THEN
adrian@94
    72
   IF(:NEW.PROCESSED='Y') THEN
adrian@94
    73
     RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    74
   END IF;
adrian@94
    75
  END IF;
adrian@94
    76
  IF(DELETING) THEN
adrian@94
    77
   IF(:OLD.PROCESSED='Y') THEN
adrian@94
    78
     RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    79
   END IF;
adrian@94
    80
  END IF;
antonio@735
    81
END C_INVOICE_TRG
gorkaion@239
    82
]]></body>
adrian@94
    83
    </trigger>
adrian@94
    84
  </database>