src-db/database/model/triggers/GL_JOURNALLINE2_TRG.xml
author Javier Etxarri <javier.echarri@openbravo.com>
Tue, 31 Dec 2013 17:08:12 +0100
changeset 21737 fcb87e990fcd
parent 20217 d62cb5baa0c1
child 25470 7c00db2d6532
permissions -rw-r--r--
Fixes issue 25414, fixes issue 25415:
Wrong currency rate is applied when posting a GL Journal line
G/L Journal lines accounting amounts are not updated when changing the header rate
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;
adrian@94
    37
  IF(UPDATING) THEN
javier@21737
    38
    IF NOT((COALESCE(:old.AMTSOURCEDR, 0) <> COALESCE(:NEW.AMTSOURCEDR, 0) OR COALESCE(:old.AMTSOURCECR, 0) <> COALESCE(:NEW.AMTSOURCECR, 0) 
javier@21737
    39
            OR COALESCE(:old.C_CURRENCY_ID, '0') <> COALESCE(:NEW.C_CURRENCY_ID, '0') OR  COALESCE(:old.currencyrate, '0') <> COALESCE(:NEW.currencyrate, '0'))) THEN
adrian@94
    40
      RETURN;
adrian@94
    41
    END IF;
adrian@94
    42
  END IF;
adrian@94
    43
  SELECT C_AcctSchema_ID,
adrian@94
    44
    CurrencyRate,
ainhoa@11319
    45
    COALESCE(CurrencyRateType, 'S'),
ainhoa@11319
    46
    dateacct
adrian@94
    47
  INTO v_AcctSchema_ID,
adrian@94
    48
    v_CurrencyRate,
ainhoa@11319
    49
    v_CurrencyRateType,
ainhoa@11319
    50
    v_DateAcct
adrian@94
    51
  FROM GL_Journal
adrian@94
    52
  WHERE GL_Journal_ID=:NEW.GL_Journal_ID;
juanpablo@1605
    53
  SELECT COALESCE(MAX(c.C_Currency_ID), '0'),
adrian@94
    54
    COALESCE(MAX(c.StdPrecision), 2)
adrian@94
    55
  INTO v_TargetCurrency_ID,
adrian@94
    56
    v_StdPrecision
adrian@94
    57
  FROM C_AcctSchema a,
adrian@94
    58
    C_Currency c
adrian@94
    59
  WHERE a.C_Currency_ID=c.C_Currency_ID
adrian@94
    60
    AND a.C_AcctSchema_ID=v_AcctSchema_ID;
ioritz@19528
    61
  v_rate:=v_CurrencyRate;
eduardo@20217
    62
  IF(v_rate IS NULL OR v_rate = 0) THEN
ioritz@19528
    63
    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
    64
  END IF;
adrian@94
    65
  :NEW.AMTACCTDR:=ROUND(COALESCE(:NEW.AMTSOURCEDR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    66
  :NEW.AMTACCTCR:=ROUND(COALESCE(:NEW.AMTSOURCECR, 0) *v_rate, v_StdPrecision) ;
adrian@94
    67
  :NEW.CURRENCYRATE:=v_rate;
adrian@94
    68
  :NEW.CURRENCYRATETYPE:=v_CurrencyRateType;
antonio@735
    69
END GL_JOURNALLINE2_TRG
gorkaion@239
    70
]]></body>
adrian@94
    71
    </trigger>
adrian@94
    72
  </database>