database/model/triggers/GL_JOURNALLINE2_TRG.xml
author Adrián Romero <adrian.romero@openbravo.com>
Tue, 20 Nov 2007 16:27:14 +0000
changeset 94 4e7ba7b8a4ad
parent 59 85aab40b7d24
child 132 33c5ca45fcff
permissions -rw-r--r--
fix: Changed check constraint names and foreign key names to fit in to
30 characteres.
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER GL_JOURNALLINE2_TRG">
adrian@94
     3
    <trigger name="GL_JOURNALLINE2_TRG" table="GL_JOURNALLINE" fires="before" insert="true" update="true" delete="false" foreach="row">
adrian@94
     4
      <body>
carlos@59
     5
adrian@94
     6
adrian@94
     7
    /*************************************************************************
adrian@94
     8
    * The contents of this file are subject to the Openbravo  Public  License
adrian@94
     9
    * Version  1.0  (the  "License"),  being   the  Mozilla   Public  License
adrian@94
    10
    * Version 1.1  with a permitted attribution clause; you may not  use this
adrian@94
    11
    * file except in compliance with the License. You  may  obtain  a copy of
adrian@94
    12
    * the License at http://www.openbravo.com/legal/license.html
adrian@94
    13
    * Software distributed under the License  is  distributed  on  an "AS IS"
adrian@94
    14
    * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
adrian@94
    15
    * License for the specific  language  governing  rights  and  limitations
adrian@94
    16
    * under the License.
adrian@94
    17
    * The Original Code is Openbravo ERP.
adrian@94
    18
    * The Initial Developer of the Original Code is Openbravo SL
adrian@94
    19
    * All portions are Copyright (C) 2001-2006 Openbravo SL
adrian@94
    20
    * All Rights Reserved.
adrian@94
    21
    * Contributor(s):  ______________________________________.
adrian@94
    22
    ************************************************************************/
adrian@94
    23
  v_AcctSchema_ID NUMBER(10) ;
adrian@94
    24
  v_TargetCurrency_ID NUMBER(10) ;
adrian@94
    25
  v_StdPrecision      NUMBER(10) ;
adrian@94
    26
  v_rate              NUMBER;
adrian@94
    27
  v_CurrencyRate      NUMBER;
adrian@94
    28
  v_CurrencyRateType  CHAR(1) ;
adrian@94
    29
BEGIN
adrian@94
    30
  IF(UPDATING) THEN
adrian@94
    31
    IF NOT((COALESCE(:old.AMTSOURCEDR, 0) &lt;&gt; COALESCE(:NEW.AMTSOURCEDR, 0) OR COALESCE(:old.AMTSOURCECR, 0) &lt;&gt; COALESCE(:NEW.AMTSOURCECR, 0) OR COALESCE(:old.C_CURRENCY_ID, 0) &lt;&gt; COALESCE(:NEW.C_CURRENCY_ID, 0))) THEN
adrian@94
    32
      RETURN;
adrian@94
    33
    END IF;
adrian@94
    34
  END IF;
adrian@94
    35
  SELECT C_AcctSchema_ID,
adrian@94
    36
    CurrencyRate,
adrian@94
    37
    COALESCE(CurrencyRateType, 'S')
adrian@94
    38
  INTO v_AcctSchema_ID,
adrian@94
    39
    v_CurrencyRate,
adrian@94
    40
    v_CurrencyRateType
adrian@94
    41
  FROM GL_Journal
adrian@94
    42
  WHERE GL_Journal_ID=:NEW.GL_Journal_ID;
adrian@94
    43
  SELECT COALESCE(MAX(c.C_Currency_ID), 0),
adrian@94
    44
    COALESCE(MAX(c.StdPrecision), 2)
adrian@94
    45
  INTO v_TargetCurrency_ID,
adrian@94
    46
    v_StdPrecision
adrian@94
    47
  FROM C_AcctSchema a,
adrian@94
    48
    C_Currency c
adrian@94
    49
  WHERE a.C_Currency_ID=c.C_Currency_ID
adrian@94
    50
    AND a.C_AcctSchema_ID=v_AcctSchema_ID;
adrian@94
    51
  v_rate:=C_CURRENCY_RATE(:NEW.C_Currency_ID, v_TargetCurrency_ID, :NEW.DateAcct, v_CurrencyRateType, :NEW.AD_CLIENT_ID, :NEW.AD_ORG_ID) ;
adrian@94
    52
  IF(v_rate IS NULL) THEN
adrian@94
    53
    v_rate:=v_CurrencyRate;
adrian@94
    54
  END IF;
adrian@94
    55
  :NEW.AMTACCTDR:=ROUND(COALESCE(:NEW.AMTSOURCEDR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    56
  :NEW.AMTACCTCR:=ROUND(COALESCE(:NEW.AMTSOURCECR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    57
  :NEW.CURRENCYRATE:=v_rate;
adrian@94
    58
  :NEW.CURRENCYRATETYPE:=v_CurrencyRateType;
adrian@94
    59
END GL_JournalLine2_Trg
adrian@94
    60
adrian@94
    61
</body>
adrian@94
    62
    </trigger>
adrian@94
    63
  </database>