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

📄 c_allocation_reverse.sql

📁 Java写的ERP系统
💻 SQL
字号:
CREATE OR REPLACE PROCEDURE C_Allocation_Reverse
(
	p_PInstance_ID    		IN NUMBER
)
/*************************************************************************
 * 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-2001 Jorg Janke, ComPiere, Inc. All Rights Reserved.
 *************************************************************************
 * $Id: C_Allocation_Reverse.sql,v 1.2 2002/05/22 02:48:28 jjanke Exp $
 ***
 * Title:	Reverse Allocation
 * Description:
 *	- Copy Record with reversed signs
 *	- (BPartner and Invoice is updated via trigger)
 *	- Update Payment
 ************************************************************************/
AS
	--	Logistice
	v_ResultStr						VARCHAR2(2000);
	v_Message						VARCHAR2(2000);
	v_Record_ID						NUMBER;
	--	Parameter
	CURSOR Cur_Parameter (pp_PInstance NUMBER) IS
		SELECT i.Record_ID, p.ParameterName, p.P_String, p.P_Number, p.P_Date
		FROM AD_PInstance i, AD_PInstance_Para p
		WHERE i.AD_PInstance_ID=pp_PInstance
		AND i.AD_PInstance_ID=p.AD_PInstance_ID(+)
		ORDER BY p.SeqNo;
	--	Parameter Variables

BEGIN
    --  Update AD_PInstance
	DBMS_OUTPUT.PUT_LINE('Updating PInstance - Processing ' || p_PInstance_ID);
	v_ResultStr := 'PInstanceNotFound';
    UPDATE AD_PInstance
    SET Created = SysDate,
        IsProcessing = 'Y'
    WHERE AD_PInstance_ID=p_PInstance_ID;
    COMMIT;

	--	Get Parameters
	v_ResultStr := 'ReadingParameters';
	FOR p IN Cur_Parameter (p_PInstance_ID) LOOP
		v_Record_ID := p.Record_ID;
	END LOOP;	--	Get Parameter
	DBMS_OUTPUT.PUT_LINE('  Record_ID=' || v_Record_ID);

	DECLARE
		v_NextNo				NUMBER(10);
		v_Client_ID				NUMBER(10);
		v_Payment_ID			NUMBER(10);
	BEGIN
		--	Read Record
		v_ResultStr := 'ReadRecord';
		SELECT	AD_Client_ID, C_Payment_ID
		  INTO	v_Client_ID, v_Payment_ID
		FROM	C_Allocation
		WHERE	C_Allocation_ID = v_Record_ID
		FOR UPDATE;

		--	Create Reversal
		v_ResultStr := 'CreateReversal';
		AD_Sequence_Next ('C_Allocation', v_Client_ID, v_NextNo);
		INSERT INTO C_Allocation (C_Allocation_ID,
			AD_Client_ID,AD_Org_ID, IsActive, Created,CreatedBy, Updated,UpdatedBy,
			C_BPartner_ID, C_Order_ID, C_Invoice_ID,
			C_Payment_ID, C_CashLine_ID,
			Amount, DiscountAmt, WriteOffAmt,
			Processed, Posted)
		SELECT v_NextNo,
			AD_Client_ID,AD_Org_ID, 'Y', SysDate,0, SysDate,0,
			C_BPartner_ID, C_Order_ID, C_Invoice_ID,
			C_Payment_ID, C_CashLine_ID,
			Amount*-1, DiscountAmt*-1, WriteOffAmt*-1,
			'Y', 'N'
	  	FROM 	C_Allocation
		WHERE	C_Allocation_ID = v_Record_ID;

		--	Unallocate Payment
		v_ResultStr := 'UnAllocatePayment';
		IF (v_Payment_ID IS NOT NULL) THEN
			UPDATE	C_Payment
			  SET	IsAllocated = 'N'
		  	WHERE	C_Payment_ID = v_Payment_ID;
		END IF;
	END;


<<FINISH_PROCESS>>
	--  Update AD_PInstance
	DBMS_OUTPUT.PUT_LINE('Updating PInstance - Finished ' || v_Message);
    UPDATE  AD_PInstance
    SET Updated = SysDate,
        IsProcessing = 'N',
        Result = 1,                 -- success
        ErrorMsg = v_Message
    WHERE   AD_PInstance_ID=p_PInstance_ID;
    COMMIT;
    RETURN;

EXCEPTION
    WHEN  OTHERS THEN
		v_ResultStr := v_ResultStr || ': ' || SQLERRM || ' - ' || v_Message;
		DBMS_OUTPUT.PUT_LINE(v_ResultStr);
		ROLLBACK;
        UPDATE  AD_PInstance
        SET Updated = SysDate,
            IsProcessing = 'N',
            Result = 0,             -- failure
            ErrorMsg = v_ResultStr
        WHERE   AD_PInstance_ID=p_PInstance_ID;
        COMMIT;
        RETURN;

END C_Allocation_Reverse;
/

⌨️ 快捷键说明

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