<?xml version="1.0"?>
<database name="TRIGGER C_TAX_TRG">
<trigger name="C_TAX_TRG" table="C_TAX" fires="after" insert="true" update="true" delete="false" foreach="row">
<body><![CDATA[
/*************************************************************************
* The contents of this file are subject to the Compiere Public
* License 1.1 ("License"); You may not use this file except in
* compliance with the License. You may obtain a copy of the License in
* the legal folder of your Openbravo installation.
* Software distributed under the License is distributed on an
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing rights
* and limitations under the License.
* The Original Code is Compiere ERP & Business Solution
* The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
* Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke,
* parts created by ComPiere are Copyright (C) ComPiere, Inc.;
* All Rights Reserved.
* Contributor(s): Openbravo SL
* Contributions are Copyright (C) 2001-2008 Openbravo, S.
*
* Specifically, this derivative work is based upon the following Compiere
* file and version.
*************************************************************************
* $Id: C_Tax_Trg.sql,v 1.2 2003/02/18 03:33:22 jjanke Exp $
***
* Title: Tax Changes
* Description:
* - New Accounting Defaults
* - Translation
************************************************************************/
TYPE RECORD IS REF CURSOR;
Cur_Defaults RECORD;
BEGIN
IF(INSERTING) THEN
-- Tax Account Defaults
FOR Cur_Defaults IN
(
SELECT *
FROM C_AcctSchema_Default d
WHERE EXISTS
(
SELECT *
FROM AD_ClientInfo c
WHERE d.C_AcctSchema_ID IN(c.C_AcctSchema1_ID, c.C_AcctSchema2_ID, c.C_AcctSchema3_ID)
AND AD_Client_ID=:new.AD_Client_ID
)
)
LOOP
INSERT
INTO C_Tax_Acct
(
C_Tax_ID, C_AcctSchema_ID, AD_Client_ID,
AD_Org_ID, IsActive, Created,
CreatedBy, Updated, UpdatedBy,
T_Due_Acct, T_Liability_Acct, T_Credit_Acct,
T_Receivables_Acct, T_Expense_Acct
)
VALUES
(
:new.C_Tax_ID, Cur_Defaults.C_AcctSchema_ID, :new.AD_Client_ID,
:new.AD_ORG_ID, 'Y', now(),
:new.CreatedBy, now(), :new.UpdatedBy,
Cur_Defaults.T_Due_Acct, Cur_Defaults.T_Liability_Acct, Cur_Defaults.T_Credit_Acct,
Cur_Defaults.T_Receivables_Acct, Cur_Defaults.T_Expense_Acct
)
;
END LOOP;
-- Create Translation Rows
INSERT
INTO C_Tax_Trl
(
C_Tax_ID, AD_Language, AD_Client_ID,
AD_Org_ID, IsActive, Created,
CreatedBy, Updated, UpdatedBy,
Name, Description, TaxIndicator,
IsTranslated
)
SELECT :new.C_Tax_ID,
AD_Language, :new.AD_Client_ID, :new.AD_Org_ID,
:new.IsActive, :new.Created, :new.CreatedBy,
:new.Updated, :new.UpdatedBy, :new.Name,
:new.Description, :new.TaxIndicator, 'N'
FROM AD_Language
WHERE IsActive='Y'
AND IsSystemLanguage='Y';
END IF;
-- Inserting
IF(UPDATING) THEN
IF((COALESCE(:old.TaxIndicator, '.') <> COALESCE(:NEW.TaxIndicator, '.')
OR COALESCE(:old.Name, '.') <> COALESCE(:NEW.Name, '.')
OR COALESCE(:old.Description, '.') <> COALESCE(:NEW.Description, '.')))
THEN
UPDATE C_Tax_Trl
SET IsTranslated='N',
Updated=now()
WHERE C_Tax_ID=:new.C_Tax_ID;
END IF;
END IF;
-- Updating
END C_TAX_TRG
]]></body>
</trigger>
</database>