src-db/database/model/triggers/C_BP_GROUP_TRG.xml
author Juan Pablo Aroztegi <juanpablo.aroztegi@openbravo.com>
Wed, 03 Sep 2008 17:55:37 +0000
changeset 1605 8a0fe0193bef
parent 1067 4a05c922c488
child 1929 ad0353d93b0f
permissions -rw-r--r--
Merge r2.5x intro trunk
adrian@94
     1
<?xml version="1.0"?>
adrian@94
     2
  <database name="TRIGGER C_BP_GROUP_TRG">
eduardo@1067
     3
    <trigger name="C_BP_GROUP_TRG" table="C_BP_GROUP" 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_BP_Group_Trg.sql,v 1.2 2001/11/26 05:25:19 jjanke Exp $
adrian@94
    26
    ***
adrian@94
    27
    * Title:  New Accounting Defaults
adrian@94
    28
    * Description:
adrian@94
    29
    ************************************************************************/
adrian@94
    30
    TYPE RECORD IS REF CURSOR;
adrian@94
    31
  Cur_Defaults RECORD;
juanpablo@1605
    32
  v_acc_ID VARCHAR2(32) ;
adrian@94
    33
BEGIN
eduardo@1067
    34
  IF(INSERTING) THEN
eduardo@1067
    35
    FOR Cur_Defaults IN
adrian@94
    36
      (
adrian@94
    37
      SELECT *
eduardo@1067
    38
      FROM C_AcctSchema_Default d
eduardo@1067
    39
      WHERE EXISTS
eduardo@1067
    40
        (
eduardo@1067
    41
        SELECT *
eduardo@1067
    42
        FROM AD_ClientInfo c
eduardo@1067
    43
        WHERE d.C_AcctSchema_ID IN(c.C_AcctSchema1_ID, c.C_AcctSchema2_ID, c.C_AcctSchema3_ID)
eduardo@1067
    44
          AND AD_Client_ID=:new.AD_Client_ID
eduardo@1067
    45
        )
adrian@94
    46
      )
eduardo@1067
    47
    LOOP
eduardo@1067
    48
      Ad_Sequence_Next('C_BP_Group_Acct', Cur_Defaults.AD_Org_Id, v_acc_id) ;
eduardo@1067
    49
      INSERT
eduardo@1067
    50
      INTO C_BP_Group_Acct
eduardo@1067
    51
        (
eduardo@1067
    52
          C_BP_Group_Acct_ID, C_BP_Group_ID, C_AcctSchema_ID,
eduardo@1067
    53
          AD_Client_ID, AD_Org_ID, IsActive,
eduardo@1067
    54
          Created, CreatedBy, Updated,
eduardo@1067
    55
          UpdatedBy, C_Receivable_Acct, C_PrePayment_Acct,
eduardo@1067
    56
          V_Liability_Acct, V_Liability_Services_Acct, V_PrePayment_Acct,
eduardo@1067
    57
          PayDiscount_Exp_Acct, PayDiscount_Rev_Acct, WriteOff_Acct,
eduardo@1067
    58
          UnRealizedGain_Acct, UnRealizedLoss_Acct, RealizedGain_Acct,
eduardo@1067
    59
          RealizedLoss_Acct, NotInvoicedReceipts_Acct, UnEarnedRevenue_Acct,
eduardo@1067
    60
          NotInvoicedRevenue_Acct, NotInvoicedReceivables_Acct
eduardo@1067
    61
        )
eduardo@1067
    62
        VALUES
eduardo@1067
    63
        (
eduardo@1067
    64
          v_acc_id, :new.C_BP_Group_ID, Cur_Defaults.C_AcctSchema_ID,
eduardo@1067
    65
          :new.AD_Client_ID, :new.AD_ORG_ID, 'Y',
eduardo@1067
    66
          now(), :new.CreatedBy, now(),
eduardo@1067
    67
          :new.UpdatedBy, Cur_Defaults.C_Receivable_Acct, Cur_Defaults.C_PrePayment_Acct,
eduardo@1067
    68
          Cur_Defaults.V_Liability_Acct, Cur_Defaults.V_Liability_Services_Acct, Cur_Defaults.V_PrePayment_Acct,
eduardo@1067
    69
          Cur_Defaults.PayDiscount_Exp_Acct, Cur_Defaults.PayDiscount_Rev_Acct, Cur_Defaults.WriteOff_Acct,
eduardo@1067
    70
          Cur_Defaults.UnRealizedGain_Acct, Cur_Defaults.UnRealizedLoss_Acct, Cur_Defaults.RealizedGain_Acct,
eduardo@1067
    71
          Cur_Defaults.RealizedLoss_Acct, Cur_Defaults.NotInvoicedReceipts_Acct, Cur_Defaults.UnEarnedRevenue_Acct,
eduardo@1067
    72
          Cur_Defaults.NotInvoicedRevenue_Acct, Cur_Defaults.NotInvoicedReceivables_Acct
eduardo@1067
    73
        )
eduardo@1067
    74
        ;
eduardo@1067
    75
    END LOOP;
eduardo@1067
    76
  ELSIF (UPDATING) THEN
eduardo@1067
    77
    UPDATE C_BP_GROUP_ACCT SET AD_ORG_ID = :new.AD_ORG_ID  
eduardo@1067
    78
    WHERE C_BP_GROUP_ID = :new.C_BP_GROUP_ID;
eduardo@1067
    79
  END IF;
antonio@735
    80
END C_BP_GROUP_TRG
gorkaion@239
    81
]]></body>
adrian@94
    82
    </trigger>
adrian@94
    83
  </database>