src-db/database/model/triggers/GL_JOURNALLINE2_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 GL_JOURNALLINE2_TRG">
adrian@94
     3
    <trigger name="GL_JOURNALLINE2_TRG" table="GL_JOURNALLINE" fires="before" insert="true" update="true" delete="false" 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_AcctSchema_ID NUMBER(10) ;
adrian@94
    26
  v_TargetCurrency_ID NUMBER(10) ;
adrian@94
    27
  v_StdPrecision      NUMBER(10) ;
adrian@94
    28
  v_rate              NUMBER;
adrian@94
    29
  v_CurrencyRate      NUMBER;
adrian@94
    30
  v_CurrencyRateType  CHAR(1) ;
adrian@94
    31
BEGIN
adrian@94
    32
  IF(UPDATING) THEN
gorkaion@239
    33
    IF NOT((COALESCE(:old.AMTSOURCEDR, 0) <> COALESCE(:NEW.AMTSOURCEDR, 0) OR COALESCE(:old.AMTSOURCECR, 0) <> COALESCE(:NEW.AMTSOURCECR, 0) OR COALESCE(:old.C_CURRENCY_ID, 0) <> COALESCE(:NEW.C_CURRENCY_ID, 0))) THEN
adrian@94
    34
      RETURN;
adrian@94
    35
    END IF;
adrian@94
    36
  END IF;
adrian@94
    37
  SELECT C_AcctSchema_ID,
adrian@94
    38
    CurrencyRate,
adrian@94
    39
    COALESCE(CurrencyRateType, 'S')
adrian@94
    40
  INTO v_AcctSchema_ID,
adrian@94
    41
    v_CurrencyRate,
adrian@94
    42
    v_CurrencyRateType
adrian@94
    43
  FROM GL_Journal
adrian@94
    44
  WHERE GL_Journal_ID=:NEW.GL_Journal_ID;
adrian@94
    45
  SELECT COALESCE(MAX(c.C_Currency_ID), 0),
adrian@94
    46
    COALESCE(MAX(c.StdPrecision), 2)
adrian@94
    47
  INTO v_TargetCurrency_ID,
adrian@94
    48
    v_StdPrecision
adrian@94
    49
  FROM C_AcctSchema a,
adrian@94
    50
    C_Currency c
adrian@94
    51
  WHERE a.C_Currency_ID=c.C_Currency_ID
adrian@94
    52
    AND a.C_AcctSchema_ID=v_AcctSchema_ID;
adrian@94
    53
  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
    54
  IF(v_rate IS NULL) THEN
adrian@94
    55
    v_rate:=v_CurrencyRate;
adrian@94
    56
  END IF;
adrian@94
    57
  :NEW.AMTACCTDR:=ROUND(COALESCE(:NEW.AMTSOURCEDR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    58
  :NEW.AMTACCTCR:=ROUND(COALESCE(:NEW.AMTSOURCECR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    59
  :NEW.CURRENCYRATE:=v_rate;
adrian@94
    60
  :NEW.CURRENCYRATETYPE:=v_CurrencyRateType;
antonio@735
    61
END GL_JOURNALLINE2_TRG
gorkaion@239
    62
]]></body>
adrian@94
    63
    </trigger>
adrian@94
    64
  </database>