src-db/database/model/triggers/C_TAX_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Mon, 28 Apr 2008 09:28:08 +0000
changeset 785 8dba91261590
parent 781 d68cf344696f
child 1067 4a05c922c488
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 C_TAX_TRG">
adrian@94
     3
    <trigger name="C_TAX_TRG" table="C_TAX" fires="after" 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.
adrian@94
    10
    * Software distributed under the License is distributed on an
adrian@94
    11
    * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
adrian@94
    12
    * implied. See the License for the specific language governing rights
adrian@94
    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.
adrian@94
    16
    * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
adrian@94
    17
    * parts created by ComPiere are Copyright (C) ComPiere, Inc.;
adrian@94
    18
    * All Rights Reserved.
adrian@94
    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.
adrian@94
    24
    *************************************************************************
adrian@94
    25
    * $Id: C_Tax_Trg.sql,v 1.2 2003/02/18 03:33:22 jjanke Exp $
adrian@94
    26
    ***
adrian@94
    27
    * Title: Tax Changes
adrian@94
    28
    * Description:
adrian@94
    29
    *  - New Accounting Defaults
adrian@94
    30
    *  - Translation
adrian@94
    31
    ************************************************************************/
adrian@94
    32
    TYPE RECORD IS REF CURSOR;
adrian@94
    33
  Cur_Defaults RECORD;
adrian@94
    34
BEGIN
adrian@94
    35
  IF(INSERTING) THEN
adrian@94
    36
    -- Tax Account Defaults
adrian@94
    37
    FOR Cur_Defaults IN
adrian@94
    38
      (
adrian@94
    39
      SELECT *
adrian@94
    40
      FROM C_AcctSchema_Default d
adrian@94
    41
      WHERE EXISTS
adrian@94
    42
        (
adrian@94
    43
        SELECT *
adrian@94
    44
        FROM AD_ClientInfo c
adrian@94
    45
        WHERE d.C_AcctSchema_ID IN(c.C_AcctSchema1_ID, c.C_AcctSchema2_ID, c.C_AcctSchema3_ID)
adrian@94
    46
          AND AD_Client_ID=:new.AD_Client_ID
adrian@94
    47
        )
adrian@94
    48
      )
adrian@94
    49
    LOOP
adrian@94
    50
      INSERT
adrian@94
    51
      INTO C_Tax_Acct
adrian@94
    52
        (
adrian@94
    53
          C_Tax_ID, C_AcctSchema_ID, AD_Client_ID,
adrian@94
    54
          AD_Org_ID, IsActive, Created,
adrian@94
    55
          CreatedBy, Updated, UpdatedBy,
adrian@94
    56
          T_Due_Acct, T_Liability_Acct, T_Credit_Acct,
adrian@94
    57
          T_Receivables_Acct, T_Expense_Acct
adrian@94
    58
        )
adrian@94
    59
        VALUES
adrian@94
    60
        (
adrian@94
    61
          :new.C_Tax_ID, Cur_Defaults.C_AcctSchema_ID, :new.AD_Client_ID,
antonio@735
    62
          :new.AD_ORG_ID,  'Y', now(),
antonio@735
    63
          :new.CreatedBy, now(), :new.UpdatedBy,
adrian@94
    64
          Cur_Defaults.T_Due_Acct, Cur_Defaults.T_Liability_Acct, Cur_Defaults.T_Credit_Acct,
adrian@94
    65
          Cur_Defaults.T_Receivables_Acct, Cur_Defaults.T_Expense_Acct
adrian@94
    66
        )
adrian@94
    67
        ;
adrian@94
    68
    END LOOP;
adrian@94
    69
    --  Create Translation Rows
adrian@94
    70
    INSERT
adrian@94
    71
    INTO C_Tax_Trl
adrian@94
    72
      (
adrian@94
    73
        C_Tax_ID, AD_Language, AD_Client_ID,
adrian@94
    74
        AD_Org_ID, IsActive, Created,
adrian@94
    75
        CreatedBy, Updated, UpdatedBy,
adrian@94
    76
        Name, Description, TaxIndicator,
adrian@94
    77
        IsTranslated
adrian@94
    78
      )
adrian@94
    79
    SELECT :new.C_Tax_ID,
adrian@94
    80
      AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
adrian@94
    81
      :new.IsActive, :new.Created, :new.CreatedBy,
adrian@94
    82
      :new.Updated, :new.UpdatedBy, :new.Name,
adrian@94
    83
      :new.Description, :new.TaxIndicator,  'N'
adrian@94
    84
    FROM AD_Language
adrian@94
    85
    WHERE IsActive='Y'
adrian@94
    86
      AND IsSystemLanguage='Y';
adrian@94
    87
  END IF;
adrian@94
    88
  -- Inserting
adrian@94
    89
  IF(UPDATING) THEN
gorkaion@239
    90
    IF((COALESCE(:old.TaxIndicator, '.') <> COALESCE(:NEW.TaxIndicator, '.')
gorkaion@239
    91
   OR COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
gorkaion@239
    92
   OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')))
adrian@94
    93
  THEN
adrian@94
    94
      UPDATE C_Tax_Trl
adrian@94
    95
        SET IsTranslated='N',
antonio@735
    96
        Updated=now()
adrian@94
    97
      WHERE C_Tax_ID=:new.C_Tax_ID;
adrian@94
    98
    END IF;
adrian@94
    99
  END IF;
adrian@94
   100
  -- Updating
antonio@735
   101
END C_TAX_TRG
gorkaion@239
   102
]]></body>
adrian@94
   103
    </trigger>
adrian@94
   104
  </database>