src-db/database/model/triggers/C_INVLINE_CHK_RESTRICTIONS_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_INVLINE_CHK_RESTRICTIONS_TRG">
adrian@94
     3
    <trigger name="C_INVLINE_CHK_RESTRICTIONS_TRG" table="C_INVOICELINE" fires="before" insert="true" update="true" delete="true" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
gorkaion@239
     5
adrian@170
     6
carlos@59
     7
adrian@94
     8
adrian@94
     9
    /*************************************************************************
adrian@94
    10
    * The contents of this file are subject to the Openbravo  Public  License
adrian@94
    11
    * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    12
    * Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    13
    * file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    14
    * the License at http://www.openbravo.com/legal/license.html
adrian@94
    15
    * Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    16
    * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    17
    * License for the specific  language  governing  rights  and  limitations
adrian@94
    18
    * under the License.
adrian@94
    19
    * The Original Code is Openbravo ERP.
adrian@94
    20
    * The Initial Developer of the Original Code is Openbravo SL
adrian@94
    21
    * All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    22
    * All Rights Reserved.
adrian@94
    23
    * Contributor(s):  ______________________________________.
adrian@94
    24
    ************************************************************************/
adrian@94
    25
  v_Processed CHAR(1) ;
adrian@94
    26
  v_C_INVOICE_ID NUMBER(10) ;
antonio@735
    27
  v_Prec NUMBER:=2;
adrian@94
    28
  v_Currency     NUMBER;
adrian@94
    29
BEGIN
adrian@94
    30
  IF INSERTING THEN
adrian@94
    31
    v_C_INVOICE_ID:=:NEW.C_INVOICE_ID;
adrian@94
    32
  ELSE
adrian@94
    33
    v_C_INVOICE_ID:=:OLD.C_INVOICE_ID;
adrian@94
    34
  END IF;
adrian@94
    35
  SELECT PROCESSED,
adrian@94
    36
    C_CURRENCY_ID
adrian@94
    37
  INTO v_Processed,
adrian@94
    38
    v_Currency
adrian@94
    39
  FROM C_INVOICE
adrian@94
    40
  WHERE C_INVOICE_ID=v_C_INVOICE_ID;
adrian@94
    41
  IF UPDATING THEN
gorkaion@239
    42
    IF(v_Processed='Y' AND ((COALESCE(:OLD.LINE, 0) <> COALESCE(:NEW.LINE, 0))
gorkaion@239
    43
         OR(COALESCE(:OLD.M_PRODUCT_ID, 0) <> COALESCE(:NEW.M_PRODUCT_ID, 0))
gorkaion@239
    44
      OR(COALESCE(:OLD.QTYINVOICED, 0) <> COALESCE(:NEW.QTYINVOICED, 0))
gorkaion@239
    45
      OR(COALESCE(:old.LINE, 0) <> COALESCE(:NEW.LINE, 0))
gorkaion@239
    46
      OR(COALESCE(:OLD.PRICELIST, 0) <> COALESCE(:NEW.PRICELIST, 0))
gorkaion@239
    47
      OR(COALESCE(:OLD.PRICEACTUAL, 0) <> COALESCE(:NEW.PRICEACTUAL, 0))
gorkaion@239
    48
      OR(COALESCE(:OLD.PRICELIMIT, 0) <> COALESCE(:NEW.PRICELIMIT, 0))
gorkaion@239
    49
      OR(COALESCE(:OLD.LINENETAMT, 0) <> COALESCE(:NEW.LINENETAMT, 0))
gorkaion@239
    50
      OR(COALESCE(:OLD.C_CHARGE_ID, 0) <> COALESCE(:NEW.C_CHARGE_ID, 0))
gorkaion@239
    51
      OR(COALESCE(:OLD.CHARGEAMT, 0) <> COALESCE(:NEW.CHARGEAMT, 0))
gorkaion@239
    52
      OR(COALESCE(:OLD.C_UOM_ID, 0) <> COALESCE(:NEW.C_UOM_ID, 0))
gorkaion@239
    53
      OR(COALESCE(:OLD.C_TAX_ID, 0) <> COALESCE(:NEW.C_TAX_ID, 0))
gorkaion@239
    54
      OR(COALESCE(:OLD.TAXAMT, 0) <> COALESCE(:NEW.TAXAMT, 0))
gorkaion@239
    55
      OR(COALESCE(:OLD.M_ATTRIBUTESETINSTANCE_ID, 0) <> COALESCE(:NEW.M_ATTRIBUTESETINSTANCE_ID, 0))
gorkaion@239
    56
      OR(COALESCE(:OLD.QUANTITYORDER, 0) <> COALESCE(:NEW.QUANTITYORDER, 0))
gorkaion@239
    57
      OR(COALESCE(:OLD.C_ORDERLINE_ID, 0) <> COALESCE(:NEW.C_ORDERLINE_ID, 0))
gorkaion@239
    58
      OR(COALESCE(:OLD.M_PRODUCT_UOM_ID, 0) <> COALESCE(:NEW.M_PRODUCT_UOM_ID, 0))
gorkaion@239
    59
      OR(COALESCE(:OLD.AD_ORG_ID, 0) <> COALESCE(:NEW.AD_ORG_ID, 0))
gorkaion@239
    60
      OR(COALESCE(:OLD.AD_CLIENT_ID, 0) <> COALESCE(:NEW.AD_CLIENT_ID, 0))
adrian@94
    61
      )) THEN
adrian@94
    62
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    63
    END IF;
adrian@94
    64
  END IF;
adrian@94
    65
  IF((DELETING OR INSERTING) AND v_Processed='Y') THEN
adrian@94
    66
    RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    67
  END IF;
adrian@94
    68
  -- Rounds linenetAmt and ChargeAmt
adrian@94
    69
  IF(INSERTING OR UPDATING) THEN
adrian@94
    70
    SELECT STDPRECISION
adrian@94
    71
    INTO v_Prec
adrian@94
    72
    FROM C_CURRENCY
adrian@94
    73
    WHERE C_CURRENCY_ID=v_Currency;
adrian@94
    74
    :NEW.LineNetAmt:=ROUND(:NEW.LineNetAmt, v_Prec) ;
adrian@94
    75
    :NEW.ChargeAmt:=ROUND(:NEW.ChargeAmt, v_Prec) ;
adrian@94
    76
  END IF;
antonio@735
    77
END C_INVLINE_CHK_RESTRICTIONS_TRG
gorkaion@239
    78
]]></body>
adrian@94
    79
    </trigger>
adrian@94
    80
  </database>