CREATE OR REPLACE PROCEDURE C302.RJ_GenCashLine_P (p_Pinstance_ID IN NUMBER)
AS
v_Resultstr VARCHAR2 (2000);
v_Message VARCHAR2 (2000);
v_Result NUMBER := 1;
v_Record_ID NUMBER;
v_AD_User_ID NUMBER;
CURSOR cur_parameter (pp_pinstance NUMBER)
IS
SELECT i.AD_Client_ID,
i.AD_Org_ID,
i.Record_id,
i.AD_User_ID,
p.ParameterName,
p.p_String, p.p_String_TO,
p.p_Number, p.p_Number_TO,
p.p_Date , p.p_Date_TO
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;
CURSOR cur_Line (x_C_Cash_ID NUMBER)
IS
SELECT *
FROM C_CashLine
WHERE C_Cash_ID = x_C_Cash_ID;
CURSOR cur_Cash (x_C_BankStatemen_ID NUMBER)
IS
SELECT *
FROM C_Cash
WHERE C_Cash_ID = x_C_BankStatemen_ID;
v_DocumentNo VARCHAR(20) := NULL;
v_NextHeader_ID NUMBER;
v_Next_ID NUMBER;
v_AD_Client_ID NUMBER;
v_AD_Org_ID NUMBER;
v_Line NUMBER;
p_Ref_Cash VARCHAR(22);
p_Ref_Cash_ID NUMBER(10,0);
No_C_Cash EXCEPTION;
BEGIN
v_resultstr := 'PInstanceNotFound';
UPDATE AD_PInstance
SET Created = SYSDATE,
IsProcessing = 'Y'
WHERE AD_PInstance_ID = p_Pinstance_ID;
COMMIT;
v_resultstr := 'ReadingParameters';
FOR P IN cur_parameter (p_pinstance_id)
LOOP
v_Record_ID := p.Record_ID;
v_AD_User_ID := P.AD_User_ID;
v_AD_Client_ID := P.AD_Client_ID;
v_AD_Org_ID := P.AD_Org_ID;
END LOOP;
v_message:='測試是否有 v_Record_ID';
IF NVL(v_Record_ID,0)=0 THEN
RAISE No_C_Cash;
END IF;
p_Ref_Cash_ID := 0;
FOR p IN cur_Cash (v_Record_ID)
LOOP
p_Ref_Cash := p.Ref_Cash;
END LOOP;
p_Ref_Cash_ID:= TO_NUMBER(p_Ref_Cash,'9999999999');
v_Line:=0;
FOR p IN cur_Line (p_Ref_Cash_ID)
LOOP
v_Line := v_Line + 10;
--@SQL=SELECT COALESCE(MAX(Line),0)+10 FROM C_CashLine WHERE C_Cash_ID=@C_Cash_ID@
AD_Sequence_Next ('C_CashLine',1000000, v_Next_ID);
INSERT INTO C_CashLine(
AD_Client_ID, AD_Org_ID, IsActive, Created, CreatedBy, Updated, UpdatedBy,
C_CashLine_ID,C_Cash_ID, Line,
Description, --:=來源C_CashLine.Description
CashType, --:=來源C_CashLine.CashType:
C_Currency_ID, --:=來源C_CashLine.C_Currency_ID
Amount, --:=0
C_BankAccount_ID, --:=來源C_CashLine.C_BankAccount_ID
C_Charge_ID, --:=來源C_CashLine.C_Charge_ID
C_Invoice_ID, --:=來源C_CashLine.C_Invoice_ID
DiscountAmt, --:=0
WriteoffAmt --:=0
)VALUES(
v_AD_Client_ID, v_AD_Org_ID, 'Y', SYSDATE, v_AD_User_ID, SYSDATE, v_AD_User_ID,
v_Next_ID, v_Record_ID, v_Line,
p.Description, --:=來源C_CashLine.Description
p.CashType, --:=來源C_CashLine.CashType:
p.C_Currency_ID, --:=來源C_CashLine.C_Currency_ID
0, --Amount:=0
p.C_BankAccount_ID, --:=來源C_CashLine.C_BankAccount_ID
p.C_Charge_ID, --:=來源C_CashLine.C_Charge_ID
p.C_Invoice_ID, --:=來源C_CashLine.C_Invoice_ID
0, --DiscountAmt:=0
0 --WriteoffAmt:=0
);
END LOOP;
<<finish_process>>
DBMS_OUTPUT.put_line ('Updating PInstance - Finished ' || v_message);
UPDATE ad_pinstance
SET updated = SYSDATE,
isprocessing = 'N',
result = v_result,
errormsg = v_message
WHERE ad_pinstance_id = p_pinstance_id;
COMMIT;
RETURN;
EXCEPTION
WHEN No_C_Cash
THEN -- does not handle RAISEd exception
v_message := v_resultstr || ': ' || SQLERRM || ' - ' || v_message;
DBMS_OUTPUT.put_line (v_message);
WHEN OTHERS
THEN
v_message := v_resultstr || ': ' || SQLERRM || ' - ' || v_message;
DBMS_OUTPUT.put_line (v_message);
ROLLBACK;
UPDATE ad_pinstance
SET updated = SYSDATE,
isprocessing = 'N',
RESULT = 0,
errormsg = v_message
WHERE ad_pinstance_id = p_pinstance_id;
COMMIT;
RETURN;
END RJ_GenCashLine_P ;
/
沒有留言:
張貼留言