src-db/database/model/triggers/GL_JOURNALLINE2_TRG.xml
author Ainhoa Pagola <ainhoa.pagola@openbravo.com>
Mon, 21 Mar 2011 16:19:08 +0100
changeset 11319 0208d57942c9
parent 9072 79e55dfc8af0
child 19528 ddafe117203b
permissions -rw-r--r--
Fixes issue 15575. Account Date in GL Journal Line deprecated.
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
priya@9072
    11
    * Version  1.1  (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.
ggi@6701
    20
    * The Initial Developer of the Original Code is Openbravo SLU
ggi@6701
    21
    * All portions are Copyright (C) 2001-2009 Openbravo SLU
adrian@94
    22
    * All Rights Reserved.
adrian@94
    23
    * Contributor(s):  ______________________________________.
adrian@94
    24
    ************************************************************************/
juanpablo@1605
    25
  v_AcctSchema_ID VARCHAR2(32) ;
juanpablo@1605
    26
  v_TargetCurrency_ID VARCHAR2(32) ;
adrian@94
    27
  v_StdPrecision      NUMBER(10) ;
adrian@94
    28
  v_rate              NUMBER;
adrian@94
    29
  v_CurrencyRate      NUMBER;
asier@2586
    30
  v_CurrencyRateType  VARCHAR(60) ;
ainhoa@11319
    31
  v_DateAcct          DATE;
asier@2084
    32
    
adrian@94
    33
BEGIN
asier@2084
    34
    
asier@2084
    35
    IF AD_isTriggerEnabled()='N' THEN RETURN;
asier@2078
    36
    END IF;
asier@2078
    37
asier@2078
    38
adrian@94
    39
  IF(UPDATING) THEN
juanpablo@1605
    40
    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
    41
      RETURN;
adrian@94
    42
    END IF;
adrian@94
    43
  END IF;
adrian@94
    44
  SELECT C_AcctSchema_ID,
adrian@94
    45
    CurrencyRate,
ainhoa@11319
    46
    COALESCE(CurrencyRateType, 'S'),
ainhoa@11319
    47
    dateacct
adrian@94
    48
  INTO v_AcctSchema_ID,
adrian@94
    49
    v_CurrencyRate,
ainhoa@11319
    50
    v_CurrencyRateType,
ainhoa@11319
    51
    v_DateAcct
adrian@94
    52
  FROM GL_Journal
adrian@94
    53
  WHERE GL_Journal_ID=:NEW.GL_Journal_ID;
juanpablo@1605
    54
  SELECT COALESCE(MAX(c.C_Currency_ID), '0'),
adrian@94
    55
    COALESCE(MAX(c.StdPrecision), 2)
adrian@94
    56
  INTO v_TargetCurrency_ID,
adrian@94
    57
    v_StdPrecision
adrian@94
    58
  FROM C_AcctSchema a,
adrian@94
    59
    C_Currency c
adrian@94
    60
  WHERE a.C_Currency_ID=c.C_Currency_ID
adrian@94
    61
    AND a.C_AcctSchema_ID=v_AcctSchema_ID;
ainhoa@11319
    62
  v_rate:=C_CURRENCY_RATE(:NEW.C_Currency_ID, v_TargetCurrency_ID, v_DateAcct, v_CurrencyRateType, :NEW.AD_CLIENT_ID, :NEW.AD_ORG_ID) ;
adrian@94
    63
  IF(v_rate IS NULL) THEN
adrian@94
    64
    v_rate:=v_CurrencyRate;
adrian@94
    65
  END IF;
adrian@94
    66
  :NEW.AMTACCTDR:=ROUND(COALESCE(:NEW.AMTSOURCEDR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    67
  :NEW.AMTACCTCR:=ROUND(COALESCE(:NEW.AMTSOURCECR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    68
  :NEW.CURRENCYRATE:=v_rate;
adrian@94
    69
  :NEW.CURRENCYRATETYPE:=v_CurrencyRateType;
antonio@735
    70
END GL_JOURNALLINE2_TRG
gorkaion@239
    71
]]></body>
adrian@94
    72
    </trigger>
adrian@94
    73
  </database>