src-db/database/model/triggers/C_CONVERSION_RATE_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 785 8dba91261590
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_CONVERSION_RATE_TRG">
adrian@94
     3
    <trigger name="C_CONVERSION_RATE_TRG" table="C_CONVERSION_RATE" fires="before" insert="true" update="true" delete="false" foreach="row">
gorkaion@239
     4
      <body><![CDATA[
juanpablo@771
     5
    /*************************************************************************
juanpablo@771
     6
    * The contents of this file are subject to the Compiere Public
juanpablo@771
     7
    * License 1.1 ("License"); You may not use this file except in
juanpablo@771
     8
    * compliance with the License. You may obtain a copy of the License in
juanpablo@771
     9
    * the legal folder of your Openbravo installation.
antonio@737
    10
    * Software distributed under the License is distributed on an
antonio@737
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
antonio@737
    12
    * implied. See the License for the specific language governing rights
antonio@737
    13
    * and limitations under the License.
juanpablo@778
    14
    * The Original Code is  Compiere  ERP &  Business Solution
juanpablo@771
    15
    * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
antonio@737
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
antonio@737
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
antonio@737
    18
    * All Rights Reserved.
antonio@737
    19
    * Contributor(s): Openbravo SL
juanpablo@785
    20
    * Contributions are Copyright (C) 2001-2008 Openbravo, S.L.
juanpablo@771
    21
    *
juanpablo@771
    22
    * Specifically, this derivative work is based upon the following Compiere
juanpablo@771
    23
    * file and version.
antonio@737
    24
    *************************************************************************
antonio@737
    25
    * $Id: C_Conversion_Rate_Trg.sql,v 1.3 2002/10/08 13:25:46 jjanke Exp $
antonio@737
    26
    ***
antonio@737
    27
    * Title: Set ToDate
antonio@737
    28
    * Description:
antonio@737
    29
    * If there is no valid ToDate set it to arbitrary end date
antonio@737
    30
    ************************************************************************/
antonio@737
    31
      v_Count NUMBER;
antonio@737
    32
  BEGIN
antonio@737
    33
  --RAISE_APPLICATION_ERROR (-20506, 'Cannot modify used rate');
antonio@737
    34
  IF(:new.ValidTo IS NULL) THEN
antonio@737
    35
    -- If there is no end date, set it to X
gorkaion@280
    36
      :new.ValidTo:=TO_DATE('31-12-9999', 'DD-MM-YYYY') ;
antonio@737
    37
  END IF;
antonio@737
    38
  --Check for invalid dates
antonio@737
    39
  IF :new.ValidTo < :new.ValidFrom THEN
antonio@735
    40
    RAISE_APPLICATION_ERROR(-20505, 'Date To is lower than Date From');
antonio@737
    41
  END IF;
antonio@737
    42
antonio@737
    43
  IF UPDATING THEN
antonio@737
    44
     --Check for changes of used rates
antonio@737
    45
    /*select count(*)
antonio@737
    46
      into v_Count
antonio@737
    47
      from c_bankstatement     b,
antonio@737
    48
          c_bankstatementline bs,
antonio@737
    49
          c_debt_payment      p
antonio@737
    50
     where bs.c_debt_payment_id = p.c_debt_payment_id
antonio@737
    51
       and b.c_bankstatement_id = bs.c_bankstatement_id
antonio@737
    52
       and p.C_currency_id  = :old.C_Currency_ID
antonio@737
    53
      and bs.C_currency_id = :old.C_Currency_ID_TO
antonio@737
    54
      and b.StatementDate between :old.ValidFrom and :old.ValidTo
antonio@737
    55
      and ((not (b.StatementDate between :new.ValidFrom and :new.ValidTo))
antonio@737
    56
          or (:new.C_Currency_ID    != :old.C_Currency_ID)
antonio@737
    57
        or (:new.C_Currency_ID_To != :old.C_Currency_ID_To)
antonio@737
    58
        or (:new.MultiplyRate     != :old.MultiplyRate)
antonio@737
    59
      )
antonio@737
    60
      and processed ='Y';*/
antonio@737
    61
antonio@737
    62
    select count(*)
antonio@737
    63
    into v_count
antonio@737
    64
     from fact_acct    f,
antonio@737
    65
         c_acctschema s
antonio@737
    66
    where f.c_acctschema_id = s.c_acctschema_id
antonio@737
    67
      and f.c_currency_id = :old.C_Currency_ID
antonio@737
    68
     and s.c_currency_id = :old.C_Currency_ID_TO
antonio@737
    69
     and f.dateacct between :old.ValidFrom and :old.ValidTo
antonio@737
    70
     and ((not (f.dateacct between :new.ValidFrom and :new.ValidTo))
antonio@737
    71
          or (:new.C_Currency_ID    != :old.C_Currency_ID)
antonio@737
    72
        or (:new.C_Currency_ID_To != :old.C_Currency_ID_To)
antonio@737
    73
        or (:new.MultiplyRate     != :old.MultiplyRate)
antonio@737
    74
      );
antonio@737
    75
antonio@737
    76
    IF v_count>0 THEN
antonio@735
    77
      RAISE_APPLICATION_ERROR(-20506, 'Cannot modify used rate');
antonio@737
    78
    END IF;
antonio@737
    79
  END IF;
antonio@737
    80
  IF DELETING THEN
antonio@737
    81
    /*select count(*)
antonio@737
    82
      into v_Count
antonio@737
    83
      from c_bankstatement     b,
antonio@737
    84
          c_bankstatementline bs,
antonio@737
    85
          c_debt_payment      p
antonio@737
    86
     where bs.c_debt_payment_id = p.c_debt_payment_id
antonio@737
    87
       and b.c_bankstatement_id = bs.c_bankstatement_id
antonio@737
    88
       and p.C_currency_id  = :old.C_Currency_ID
antonio@737
    89
      and bs.C_currency_id = :old.C_Currency_ID_TO
antonio@737
    90
      and b.StatementDate between :old.ValidFrom and :old.ValidTo
antonio@737
    91
      and processed ='Y';*/
antonio@737
    92
   select count(*)
antonio@737
    93
    into v_count
antonio@737
    94
     from fact_acct    f,
antonio@737
    95
         c_acctschema s
antonio@737
    96
    where f.c_acctschema_id = s.c_acctschema_id
antonio@737
    97
      and f.c_currency_id = :old.C_Currency_ID
antonio@737
    98
     and s.c_currency_id = :old.C_Currency_ID_TO
antonio@737
    99
     and f.dateacct between :old.ValidFrom and :old.ValidTo;
antonio@737
   100
    IF v_count>0 THEN
antonio@735
   101
      RAISE_APPLICATION_ERROR(-20506, 'Cannot modify used rate');
antonio@737
   102
    END IF;
antonio@737
   103
  END IF;
antonio@737
   104
antonio@735
   105
END C_CONVERSION_RATE_TRG
gorkaion@239
   106
]]></body>
adrian@94
   107
    </trigger>
adrian@94
   108
  </database>