⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 c_project_trg.sql

📁 Java写的ERP系统
💻 SQL
字号:
CREATE OR REPLACE TRIGGER C_Project_Trg
AFTER INSERT
	ON C_Project
FOR EACH ROW
DECLARE
/*************************************************************************
 * The contents of this file are subject to the Compiere License.  You may
 * obtain a copy of the License at    http://www.compiere.org/license.html
 * Software is on an  "AS IS" basis,  WITHOUT WARRANTY OF ANY KIND, either
 * express or implied. See the License for details. Code: Compiere ERP+CRM
 * Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
 *************************************************************************
 * $Id: C_Project_Trg.sql,v 1.3 2002/10/23 03:16:57 jjanke Exp $
 ***
 * Title:	Project new record
 * Description:
 *  - create default accounts
 *  - create treenode
 ************************************************************************/
    v_Tree_ID    NUMBER;
    v_Parent_ID  NUMBER;
	--
	CURSOR Cur_Defaults IS
		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);
BEGIN
	FOR cd IN Cur_Defaults LOOP
   	    --  Account
       	INSERT INTO C_Project_Acct
           	(C_Project_ID, C_AcctSchema_ID,
            AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
			PJ_Asset_Acct, PJ_WIP_Acct)
       	VALUES
           	(:new.C_Project_ID, cd.C_AcctSchema_ID,
            :new.AD_Client_ID, :new.AD_ORG_ID, 'Y', SysDate, :new.CreatedBy, SysDate, :new.UpdatedBy,
   	        cd.PJ_Asset_Acct, cd.PJ_WIP_Acct);
    END LOOP;

    --  Create TreeNode --
   	--  get AD_Tree_ID + ParentID
    SELECT  c.AD_Tree_Project_ID, n.Node_ID 
	  INTO 	v_Tree_ID, v_Parent_ID
   	FROM    AD_ClientInfo c, AD_TreeNode n
    WHERE   c.AD_Tree_Project_ID=n.AD_Tree_ID
   	    AND n.Parent_ID IS NULL
       	AND c.AD_Client_ID=:new.AD_Client_ID;

    --  DBMS_OUTPUT.PUT_LINE('Tree='||xTree_ID||'  Node='||:new.C_Project_ID||'  Parent='||xParent_ID);

    --  Insert into TreeNode
   	INSERT INTO AD_TreeNode
		(AD_Client_ID, AD_Org_ID,
		IsActive, Created, CreatedBy, Updated, UpdatedBy,
		AD_Tree_ID, Node_ID,
		Parent_ID, SeqNo)
    VALUES
   	    (:new.AD_Client_ID, :new.AD_Org_ID,
       	:new.IsActive, :new.Created, :new.CreatedBy, :new.Updated, :new.UpdatedBy,
        v_Tree_ID, :new.C_Project_ID,
   	    v_Parent_ID, DECODE(:new.IsSummary, 'Y', 100, 999));     -- Summary Nodes first

EXCEPTION
	WHEN NO_DATA_FOUND THEN
		RAISE_APPLICATION_ERROR (-20001, 'C_Project InsertTrigger Error: No ClientInfo or parent TreeNode');

END C_Project_Trg;
/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -