src-db/database/model/triggers/C_INVOICEDISCOUNT_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 756 ae11e4610537
child 2078 cf88ca44cdd2
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_INVOICEDISCOUNT_TRG">
adrian@94
     3
    <trigger name="C_INVOICEDISCOUNT_TRG" table="C_INVOICE_DISCOUNT" fires="after" insert="false" 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
    ************************************************************************/
juanpablo@1605
    25
  v_ID VARCHAR2(32);
adrian@94
    26
  v_RO        NUMBER;
adrian@94
    27
  v_Processed CHAR(1) ;
adrian@94
    28
BEGIN
adrian@94
    29
  IF UPDATING THEN
adrian@94
    30
    SELECT PROCESSED
adrian@94
    31
    INTO v_Processed
adrian@94
    32
    FROM C_INVOICE
adrian@94
    33
    WHERE C_INVOICE_ID=:OLD.C_INVOICE_ID;
adrian@94
    34
    IF(v_Processed='Y') THEN
adrian@94
    35
      RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    36
    END IF;
adrian@94
    37
  END IF;
adrian@94
    38
  -- Get ID
adrian@94
    39
  IF(UPDATING OR INSERTING) THEN
adrian@94
    40
    v_ID:=:NEW.C_Invoice_ID;
adrian@94
    41
  ELSE
adrian@94
    42
    v_ID:=:OLD.C_Invoice_ID;
adrian@94
    43
  END IF;
adrian@94
    44
  -- ReadOnly Check
adrian@94
    45
  SELECT COUNT(*)
adrian@94
    46
  INTO v_RO
adrian@94
    47
  FROM C_INVOICE
adrian@94
    48
  WHERE C_Invoice_ID=v_ID
adrian@94
    49
    AND(Processed='Y'
adrian@94
    50
    OR Posted='Y') ;
gorkaion@239
    51
  IF(v_RO > 0) THEN
adrian@94
    52
    RAISE_APPLICATION_ERROR(-20501, 'Document processed/posted') ;
adrian@94
    53
  END IF;
antonio@735
    54
END C_INVOICEDISCOUNT_TRG
gorkaion@239
    55
]]></body>
adrian@94
    56
    </trigger>
adrian@94
    57
  </database>