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

📄 c_allocation_trg.sql

📁 Java写的ERP系统
💻 SQL
字号:
CREATE OR REPLACE TRIGGER C_Allocation_Trg
AFTER INSERT OR UPDATE 
	ON C_Allocation
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+CPM
 * Copyright (C) 1999-2002 Jorg Janke, ComPiere, Inc. All Rights Reserved.
 *************************************************************************
 * $Id: C_Allocation_Trg.sql,v 1.9 2003/03/17 20:32:23 jjanke Exp $
 ***
 * Title:	 Allocation Processing
 * Description:
 *	When inserting (from creating CashBook, Payment or Allocation)
 *		- Update BPartner (SO_CreditUsed). 
 *		  The amount has the correct sign
 *	When updating 
 *	- Update BPartner when changed
 *	This is reversing the creditline increase in C_Invoice_Post
 *  Issue:
 *  - If the amount is not allocated, CreditUsed is not changed
 ************************************************************************/

	v_IsSOTrx		C_Invoice.IsSOTrx%TYPE;
	v_DocBaseType	C_DocType.DocBaseType%TYPE;
BEGIN
	IF (INSERTING OR UPDATING) THEN
		IF (:new.C_Invoice_ID IS NOT NULL) THEN
			--	Is it a Sales Transaction / credit memo
			SELECT	i.IsSOTrx, d.DocBaseType
			  INTO	v_IsSOTrx, v_DocBaseType
			FROM	C_DocType d, C_Invoice i
			WHERE	d.C_DocType_ID=i.C_DocType_ID
			  AND	i.C_Invoice_ID = :new.C_Invoice_ID;
		END IF;
	END IF;
	--	Only Sales Trx
	IF (v_IsSOTrx = 'N') THEN
		RETURN;
	END IF;

	IF (INSERTING) THEN
		--	Update BPartner CreditUsed
		IF (:new.C_BPartner_ID IS NOT NULL) THEN
			UPDATE	C_BPartner
			   SET	SO_CreditUsed = SO_CreditUsed - C_Base_Convert (
					(:new.Amount + :new.DiscountAmt + :new.WriteOffAmt),
					:new.C_Currency_ID, :new.AD_Client_ID, :new.DateTrx, :new.AD_Org_ID) 
			WHERE	C_BPartner_ID = :new.C_BPartner_ID;
		END IF;
	END IF;	--	Inserting

	--
	IF (UPDATING) THEN
		--	BPartner changed
		IF (:old.C_BPartner_ID <> :new.C_BPartner_ID) THEN
			IF (:old.C_BPartner_ID IS NOT NULL) THEN
				UPDATE	C_BPartner
				   SET	SO_CreditUsed = SO_CreditUsed + C_Base_Convert (
					(:old.Amount + :old.DiscountAmt + :old.WriteOffAmt),
					:old.C_Currency_ID, :old.AD_Client_ID, :old.DateTrx, :old.AD_Org_ID) 
				WHERE	C_BPartner_ID = :old.C_BPartner_ID;
			END IF;
			--
			IF (:new.C_BPartner_ID IS NOT NULL) THEN
				UPDATE	C_BPartner
				   SET	SO_CreditUsed = SO_CreditUsed - C_Base_Convert (
					(:new.Amount + :new.DiscountAmt + :new.WriteOffAmt),
					:new.C_Currency_ID, :new.AD_Client_ID, :new.DateTrx, :new.AD_Org_ID) 
				WHERE	C_BPartner_ID = :new.C_BPartner_ID;
			END IF;
		END IF;
	END IF;	--	Updating

END C_Allocation_Trg;
/

⌨️ 快捷键说明

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