0% found this document useful (0 votes)
695 views86 pages

Igc CBC Funds Checker

This package body defines functions and procedures to perform funds checking for budget control processes. It includes private variables to store processing information, as well as functions for checking funds availability, updating budget balances and result statuses, and logging/debugging messages.

Uploaded by

Bindu Madhavi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
695 views86 pages

Igc CBC Funds Checker

This package body defines functions and procedures to perform funds checking for budget control processes. It includes private variables to store processing information, as well as functions for checking funds availability, updating budget balances and result statuses, and logging/debugging messages.

Uploaded by

Bindu Madhavi
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 86

CREATE OR REPLACE PACKAGE BODY APPS.

IGC_CBC_FUNDS_CHECKER AS
/* $Header: IGCBEFCB.pls 115.80 2005/02/15 12:45:56 rshergil ship $ */
-- Types :
TYPE g_packet_list_rec_type IS RECORD
( packet_id NUMBER,
budget_version_id NUMBER );
--List of packet_id's
TYPE g_packet_list_tbl_type IS TABLE OF g_packet_list_rec_type
INDEX BY BINARY_INTEGER;
-- Private Global Variables :
G_PKG_NAME CONSTANT VARCHAR2(30) := 'IGC_CBC_FUNDS_CKECKER';
g_debug VARCHAR2(10000);
g_packet_list g_packet_list_tbl_type;
g_packet_count NUMBER;
g_conc_proc BOOLEAN := FALSE;
g_mode VARCHAR2(1);
g_batch_id igc_cbc_je_batches.cbc_je_batch_id%TYPE;
g_cc_header_id igc_cbc_je_batches.cc_header_id%TYPE ;
g_set_of_books_id gl_sets_of_books.set_of_books_id%TYPE;
g_actual_flag VARCHAR2(1);
g_update_login igc_cbc_je_lines.last_update_login%TYPE;
g_update_by igc_cbc_je_lines.last_updated_by%TYPE;
g_resp_id NUMBER;
g_maxloops NUMBER(10) := 50;
g_seconds NUMBER(10) := 2;
g_cbc_flag BOOLEAN :=TRUE;
g_sbc_flag BOOLEAN :=TRUE;
g_date1 NUMBER;
g_date2 NUMBER;
g_summary_line_num IGC_CBC_JE_LINES.cbc_je_line_num%TYPE;
g_com_enc_id IGC_CBC_JE_LINES.encumbrance_type_id%TYPE;
g_obl_enc_id IGC_CBC_JE_LINES.encumbrance_type_id%TYPE;
g_cbc_enabled VARCHAR2(1);
g_doc_type IGC_CC_INTERFACE.document_type%TYPE;
g_validation_error BOOLEAN;
g_batch_result_code NUMBER(4); --Global maximum rank
g_efc_enabled VARCHAR2(1);
g_prod VARCHAR2(3) := 'IGC';
g_sub_comp VARCHAR2(3) := 'CBC';
g_profile_name VARCHAR2(255) := 'IGC_DEBUG_LOG_DIRECTORY';
g_group_severity_level VARCHAR2(1);
g_source VARCHAR2(255) ;
g_category VARCHAR2(255) ;
g_bc_group_id NUMBER;
g_packet_id NUMBER;
g_gl_application_id fnd_application.application_id%TYPE;
-- Variables for logging levels
--bug 3199488
g_debug_level NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
g_state_level NUMBER := FND_LOG.LEVEL_STATEMENT;
g_proc_level NUMBER := FND_LOG.LEVEL_PROCEDURE;
g_event_level NUMBER := FND_LOG.LEVEL_EVENT;
g_excep_level NUMBER := FND_LOG.LEVEL_EXCEPTION;
g_error_level NUMBER := FND_LOG.LEVEL_ERROR;
g_unexp_level NUMBER := FND_LOG.LEVEL_UNEXPECTED;
g_path VARCHAR2(255) := 'IGC.PLSQL.IGCBEFCB.IGC_CBC_FUNDS_CHECKER.';
--bug 3199488
-- ssmales 25/01/02 bug 2201905 - added g_p_packet_id
g_p_packet_id NUMBER(15) ;
g_called_from_PO BOOLEAN := FALSE;
--bug 3199488
--g_debug_mode VARCHAR2(1) := NVL(FND_PROFILE.VALUE('IGC_DEBUG_ENABLED'),'N');
g_debug_mode VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
-- Private Function Definition:
FUNCTION Check_SBC(
x_return_status OUT NOCOPY VARCHAR2
) RETURN BOOLEAN;
PROCEDURE Create_JE_Batch(
x_return_status OUT NOCOPY VARCHAR2
);
/* Update status code for all batch (SBC and CBC)*/
PROCEDURE Update_Status_Code(
p_status_code IN VARCHAR2,
x_return_status OUT NOCOPY VARCHAR2
);
/*Procedure gets the sevirity level from assigned budget group */
FUNCTION Calculate_Sevirity_Level(
p_summary_detail_code IN VARCHAR2,
p_ccid IN NUMBER,
p_source IN VARCHAR2,
p_category IN VARCHAR2,
p_ccid_level IN VARCHAR2)
RETURN VARCHAR2;
/* SBC unreservation called in case of unseccessfull
reservation when we need to unreserve several periods */
PROCEDURE Unreserve_SBC (
x_status OUT NOCOPY VARCHAR2
);
PROCEDURE Set_Batch_Result_Code(
p_code IN VARCHAR2) ;
/* Function generates batch name */
FUNCTION Get_Batch_Name(
p_period_name IN VARCHAR2)
RETURN VARCHAR2;
/* Procedure locks JE lines */
FUNCTION Lock_JE_Lines RETURN BOOLEAN ;
/*
Update results for CC interface table based on CCID, period number, amount_type.
p_result_code:
F00 {Insufficient funds (detail) }
F01 Insufficient funds (->summary)
P00 {Funds not reduced *'******'*}
P01 {Funds check not required *'*}
P10 {Passed funds check *'******'}
P20 {Advisory warning *'******'* }
P22 {Advisory warning (->summary)}
*/
PROCEDURE Update_Result_Status(
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE,
p_batch_line_num IN igc_cc_interface.batch_line_num%TYPE,
p_result_code IN VARCHAR2,
p_status_code IN VARCHAR2,
p_summary_detail IN VARCHAR2,
p_budget_version_id IN gl_budget_versions.budget_version_id%TYPE,
p_period_name IN igc_cbc_je_lines.period_name%TYPE,
p_quarter_num IN igc_cbc_je_lines.quarter_num%TYPE,
p_period_num IN igc_cbc_je_lines.period_num%TYPE,
p_period_year IN igc_cbc_je_lines.period_year%TYPE,
p_amount_type IN VARCHAR2,
p_budget_dest IN VARCHAR2,
p_budget_amt IN NUMBER,
p_com_enc_amt IN NUMBER,
p_obl_enc_amt IN NUMBER,
p_fa_amt IN NUMBER,
x_return_status OUT NOCOPY VARCHAR2
);
FUNCTION Unreserve_Batch(
p_batch_id IN NUMBER
) RETURN BOOLEAN ;
/* Procedure validates Information before creation of temporary JE */
PROCEDURE Populate_CBC_Line_Info(
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE,
p_entered_cr IN igc_cbc_je_lines.entered_cr%TYPE,
p_entered_dr IN igc_cbc_je_lines.entered_dr%TYPE,
p_je_line_num IN igc_cbc_je_lines.cbc_je_line_num%TYPE,
p_je_source IN igc_cbc_je_lines.je_source%TYPE,
p_je_category IN igc_cbc_je_lines.je_category%TYPE,
p_effective_date IN igc_cbc_je_lines.effective_date%TYPE,
p_currency_code IN igc_cbc_je_lines.currency_code%TYPE,
p_encumbrance_type IN igc_cbc_je_lines.encumbrance_type_id%TYPE,
p_budget_ver_id IN igc_cbc_je_lines.budget_version_id%TYPE,
p_description IN igc_cbc_je_lines.description%TYPE,
p_cc_acct_line_id IN igc_cc_interface.cc_acct_line_id%TYPE, -- Used for Audit Trail
p_cc_version_num IN igc_cc_interface.cc_version_num%TYPE,
p_det_sum_value IN VARCHAR2,
x_ReturnStatus OUT NOCOPY VARCHAR2
);
/* Procedure updates JE line or delete temporary JE lines */
PROCEDURE Update_CBC_JE_Line (
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE,
p_entered_cr IN igc_cbc_je_lines.entered_cr%TYPE,
p_entered_dr IN igc_cbc_je_lines.entered_dr%TYPE,
p_je_line_num IN igc_cbc_je_lines.cbc_je_line_num%TYPE,
p_det_sum_val IN igc_cbc_je_lines.detail_summary_code%TYPE,
p_update_type IN VARCHAR2,
x_return_status OUT NOCOPY VARCHAR2
);
PROCEDURE Unreserve_CBC (
x_status OUT NOCOPY VARCHAR2
);
/* Procedure returns balance for detail ID */
PROCEDURE Get_Detail_Bal (
p_dccid IN igc_cbc_je_lines.code_combination_id%TYPE, -- Detail CCID
p_amount_t IN igc_cbc_je_lines.amount_type%TYPE, -- QTD, PTD, or YTD
p_budget_ver IN igc_cbc_je_lines.budget_version_id%TYPE, -- Budget ID
p_period_yr IN igc_cbc_je_lines.period_year%TYPE, -- Period year, ie 2000
p_period_nm IN igc_cbc_je_lines.period_num%TYPE, -- Period number
p_quarter_nm IN igc_cbc_je_lines.quarter_num%TYPE, -- Quarter number (1-4)
p_funds_level IN VARCHAR2,
x_fa OUT NOCOPY NUMBER,
x_com_bal OUT NOCOPY NUMBER,
x_act_bal OUT NOCOPY NUMBER,
x_oth_bal OUT NOCOPY NUMBER,
x_bud_bal OUT NOCOPY NUMBER,
x_return_status OUT NOCOPY VARCHAR2
);
/* Procedure returns balance for summary ID */
PROCEDURE Get_Summary_Bal (
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE, -- Detail CCID
p_amount_t IN igc_cbc_je_lines.amount_type%TYPE, -- QTD, PTD, or YTD
p_budget_ver IN igc_cbc_je_lines.budget_version_id%TYPE, -- Budget ID
p_period_yr IN igc_cbc_je_lines.period_year%TYPE, -- Period year, ie 2000
p_period_nm IN igc_cbc_je_lines.period_num%TYPE, -- Period number
p_quarter_nm IN igc_cbc_je_lines.quarter_num%TYPE, -- Quarter number (1-4)
p_funds_level IN VARCHAR2,
x_fa OUT NOCOPY NUMBER,
x_com_bal OUT NOCOPY NUMBER,
x_act_bal OUT NOCOPY NUMBER,
x_oth_bal OUT NOCOPY NUMBER,
x_bud_bal OUT NOCOPY NUMBER,
x_return_status OUT NOCOPY VARCHAR2
);
/* procedure returns result code for particular parameters */
PROCEDURE Get_Result_Code (
p_funds_available IN NUMBER,
p_funds_level IN VARCHAR2,
p_amount IN NUMBER,
p_summary_detail_code IN VARCHAR2,
p_ccid IN NUMBER,
x_result_code OUT NOCOPY VARCHAR2,
x_status_code OUT NOCOPY VARCHAR2
);
--Procedure, for registering time of execution of any operation
PROCEDURE Register_time(
p_name VARCHAR2,
p_mode BOOLEAN
);
PROCEDURE Split_JE_Batch(
x_return_status OUT NOCOPY VARCHAR2
);
PROCEDURE Put_Debug_Msg (
p_path IN VARCHAR2,
p_debug_msg IN VARCHAR2
);
PROCEDURE message_token(
tokname IN VARCHAR2,
tokval IN VARCHAR2
);
PROCEDURE add_message(
appname IN VARCHAR2,
msgname IN VARCHAR2
);
/* ------------------------------------------------------------------------- */
/* */
/* Funds Check API for CC and PSB whenever Funds Check and/or Funds */
/* Funds Reservation need to be performed. */
/* */
/* This routine returns TRUE if successful; otherwise, it returns FALSE */
/* */
/* In case of failure, this routine will populate the global Message Stack */
/* using FND_MESSAGE. The calling routine will retrieve the message from */
/* the Stack */
/* */
/* External Packages which are being invoked include : */
/* */
/* FND_* */
/* */
/* GL Tables which are being used include : */
/* */
/* GL_* */
/* */
/* AOL Tables which are being used include : */
/* */
/* FND_* */
/* */
/* Return status two characters. First one for CBC, second for SBC */
/* 'S' Success, */
/* 'A' Advisory, */
/* 'F' Failure */
/* 'T' Fatal */
/* 'N' No records */
/* 'U' Unreservation failed */
/* ------------------------------------------------------------------------- */
-- Parameters :
-- p_sobid : set of books ID
-- p_header_id : CC header ID
-- p_mode : funds check mode - 'C', 'R' or 'F'
-- p_ret_status : return status of funds checking/reservation
-- p_actual_flag: 'E' for CC or 'B' for PSB
-- ssmales 25/01/02 bug 2201905 - added parameter p_packet_id

FUNCTION IGCFCK(
p_sobid IN NUMBER,
p_header_id IN NUMBER,
p_mode IN VARCHAR2,
p_actual_flag IN VARCHAR2,
p_doc_type IN VARCHAR2,
p_ret_status OUT NOCOPY VARCHAR2,
p_batch_result_code OUT NOCOPY VARCHAR2,
p_debug IN VARCHAR2:=FND_API.G_FALSE,
p_conc_proc IN VARCHAR2:=FND_API.G_FALSE,
p_packet_id IN NUMBER
) RETURN BOOLEAN IS

v_resp_id fnd_user.user_id%TYPE;
v_resp_appid fnd_user_resp_groups_direct.responsibility_application_id%TYPE;
CURSOR c_cc_interface IS --All records for CBC from interface table
SELECT cc_header_id,
cc_version_num,
cc_acct_line_id,
cc_det_pf_line_id,
code_combination_id,
batch_line_num,
cc_transaction_date,
cc_func_dr_amt ,
cc_func_cr_amt ,
je_source_name,
je_category_name,
actual_flag,
set_of_books_id,
encumbrance_type_id,
budget_version_id,
currency_code,
transaction_description,
reference_1,
reference_2 ,
reference_3 ,
reference_4 ,
reference_5 ,
reference_6 ,
reference_7 ,
reference_8 ,
reference_9 ,
reference_10
FROM igc_cc_interface_v a
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
ORDER BY cc_transaction_date;

CURSOR c_cbc_je_lines IS --All records for CBC from interface table


SELECT cbc_je_line_num,
je_source,
je_category,
currency_code,
actual_flag,
set_of_books_id,
encumbrance_type_id,
budget_version_id,
detail_summary_code,
code_combination_id,
funds_check_level_code,
amount_type,
effective_date,
period_year,
entered_dr,
entered_cr,
budget_type,
period_name,
quarter_num,
period_num,
status
FROM igc_cbc_je_lines
WHERE cbc_je_batch_id = g_batch_id
ORDER BY detail_summary_code,
period_year,
quarter_num,
period_num;
-- Bug 2885953 - amended cursor below for performance enhancements
-- CURSOR c_ent IS
-- SELECT NVL(cc_prov_encmbrnc_type_id,0),
-- NVL(cc_conf_encmbrnc_type_id,0)
-- FROM igc_cc_encmbrnc_org_v;
CURSOR c_ent IS
SELECT NVL(cc_prov_encmbrnc_type_id,0),
NVL(cc_conf_encmbrnc_type_id,0)
FROM igc_cc_encmbrnc_ctrls
WHERE NVL(org_id,NVL(TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'),1,1), ' ',
null, SUBSTRB(USERENV('CLIENT_INFO'),1,10))),-99))
=
NVL(TO_NUMBER(DECODE(SUBSTRB(USERENV('CLIENT_INFO'),1,1), ' ',
null, SUBSTRB(USERENV('CLIENT_INFO'),1,10))),-99);
-- ssmales 28/01/02 bug 2201905 - added c_cc_headers cursor
CURSOR c_cc_headers IS
SELECT distinct cc_header_id, document_type
FROM igc_cc_interface_v
WHERE reference_6 = g_p_packet_id ;
l_api_name CONSTANT VARCHAR2(30) := 'IGCFCK';
l_ccid GL_CODE_COMBINATIONS.code_combination_id%TYPE;
l_period_name GL_PERIODS.period_name%TYPE;
l_return_status VARCHAR2(1);
l_fc_return_status VARCHAR2(2);
l_batch_status VARCHAR2(1);
l_result_code VARCHAR2(3);
l_status_code VARCHAR2(1);
l_budget_amt NUMBER;
l_com_enc_amt NUMBER;
l_obl_enc_amt NUMBER;
l_oth_enc_amt NUMBER;
l_fa_amt NUMBER;
l_cbc_status VARCHAR2(1);
l_sbc_status VARCHAR2(1);
l_res BOOLEAN;
l_efc_enabled VARCHAR2(1);
l_msg_count NUMBER;
l_msg_data VARCHAR(2000);
l_cbc_flag VARCHAR2(1);
l_sbc_flag VARCHAR2(1);
l_rank NUMBER(4);
-- ssmales 28/01/02 bug 2201905 - added variables below
l_cc_header_rec IGC_CC_INTERFACE%ROWTYPE ;
l_full_path VARCHAR2(255);
BEGIN

dbms_output.put_line ('Fund Check started for '||p_header_id);

-- Inserted below by Ajay Antony, OSSI on 12-Oct-2007 as a part PR fix for FAT-PR-CC-18
-- To initialize the session if the resp id is not populated
IF FND_GLOBAL.RESP_ID = -1 THEN
BEGIN

SELECT RESPONSIBILITY_ID, responsibility_application_id


INTO v_resp_id, v_resp_appid
FROM FND_USER_RESP_GROUPS_DIRECT
WHERE user_id = FND_GLOBAL.USER_ID
AND NVL(end_date, TRUNC(SYSDATE)) >= TRUNC(SYSDATE)
AND rownum = 1;

fnd_global.APPS_INITIALIZE(FND_GLOBAL.USER_ID, v_resp_id, v_resp_appid);

EXCEPTION
WHEN OTHERS THEN
NULL;
END;
END IF;
-- Inserted Above by Ajay Antony, OSSI on 12-Oct-2007 as a part PR fix for FAT-PR-CC-18

-- Standard Start of API savepoint


SAVEPOINT IGCFCK;
l_full_path := g_path || 'IGCFCK';
-- Initialize message list
IF p_mode <> 'U' THEN
FND_MSG_PUB.initialize;
dbms_output.put_line ('Apps initialixe done');
END IF;
--Initialize global variables
-- If packet id is not null, it means the call has come from outside
-- CC module, primarily from the PO Funds Checker.
-- Bidisha S, 28 Nov 2002
IF p_packet_id IS NOT NULL
THEN
g_called_from_PO := TRUE;
dbms_output.put_line ('P_PACKET_ID NOT NULL');
END IF;
g_cbc_flag := TRUE;
g_sbc_flag := TRUE;
l_batch_status := 'A';
l_cbc_status := 'N';
l_sbc_status := 'N';
g_validation_error := FALSE;
g_mode := p_mode;
g_resp_id := FND_GLOBAL.RESP_ID;
g_update_login := FND_GLOBAL.LOGIN_ID;
g_update_by := FND_GLOBAL.USER_ID;
g_actual_flag := p_actual_flag;
g_cc_header_id := p_header_id;
g_set_of_books_id := p_sobid ;
-- IGC_MSGS_PKG.g_debug_mode := FND_API.TO_BOOLEAN(p_debug);
g_conc_proc := FND_API.TO_BOOLEAN(p_conc_proc);
g_cbc_enabled := IGC_PSB_COMMITMENTS_PVT.Is_Cbc_Enabled(g_set_of_books_id);
g_doc_type := p_doc_type;
g_batch_result_code := 9999;
g_maxloops := 50;
g_seconds := 2;
g_validation_error := FALSE;
g_bc_group_id := FND_PROFILE.VALUE('BUDGETARY_CONTROL_OPTION');
g_packet_id := NULL;
-- ssmales 25/01/02 bug 2201905 - added line below
g_p_packet_id := p_packet_id ;
-- --------------------------------------------------------------------
-- Obtain the application ID that will be used throughout this process.
-- --------------------------------------------------------------------
SELECT application_id
INTO g_gl_application_id
FROM fnd_application
WHERE application_short_name = 'SQLGL';

dbms_output.put_line ('Application id '||g_gl_application_id);


-- debug information
-- IF (NOT IGC_MSGS_PKG.g_debug_mode) AND (upper(fnd_profile.value('IGC_DEBUG_ENABLED')) ='Y')
THEN
-- IGC_MSGS_PKG.g_debug_mode:=TRUE;
-- END IF;
IF (g_debug_mode <> 'Y') AND (p_debug = FND_API.G_TRUE)
THEN
g_debug_mode := 'Y';
dbms_output.put_line ('Debug mode not equal to Y and now '||g_debug_mode);
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path,
substr('***************************************************************************************
***********',1,70));
Put_Debug_Msg(l_full_path, substr('*********Starting CBC Funds Checker '||to_char(sysdate,'DD-MON-
YY:MI:SS')||' *********************',1,70));
Put_Debug_Msg(l_full_path,
substr('***************************************************************************************
***********',1,70));
Put_Debug_Msg(l_full_path, 'Parameters SOB:' || p_sobid ||' Mode: ' || p_mode || ' HeaderID ' ||p_header_id);
END IF;
IF g_mode = 'U' THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unreserving...');
dbms_output.put_line ('Came inside unreserving ');
END IF;
Unreserve_CBC(l_fc_return_status);

IF (g_debug_mode = 'Y') THEN


Put_Debug_Msg(l_full_path, 'Returned status is: '||l_fc_return_status);
END IF;
p_ret_status := l_fc_return_status;
p_batch_result_code:=NULL;
IF l_fc_return_status <> 'SS' THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unreservation completed unsuccessfully, status: ' || l_fc_return_status);
END IF;
IF NOT g_called_from_PO
THEN
COMMIT;
END IF;
RETURN(FALSE);
END IF;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unreservation completed successfully, status: ' || l_fc_return_status);
END IF;
IF NOT g_called_from_PO
THEN
COMMIT;
END IF;
RETURN(TRUE);
ELSE
--It's possible to have result code already populated - so we need to store it
-- ssmales 28/01/02 bug 2201905 - added block to process by p_packet_id below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
SELECT min(Get_Rank(cbc_result_code))
INTO l_rank
FROM igc_cc_interface_v a
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND cbc_result_code IS NOT NULL;
ELSE
-- bug 2201905 end block
SELECT min(Get_Rank(cbc_result_code))
INTO l_rank
FROM igc_cc_interface_v a
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
AND cbc_result_code IS NOT NULL;

dbms_output.put_line ('Get Rank l_rank'||l_rank);

-- ssmales 28/01/02 bug 2201905 - added end if statement below


END IF ;
IF l_rank IS NOT NULL THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'The most severe found in the batch: '||l_rank);
END IF;
Set_Batch_Result_Code ( Get_Result_By_Rank(l_rank));
END IF;
END IF;

dbms_output.put_line ('Calling validate check efc enable');

IGC_CBC_VALIDATIONS_PKG.Validate_Check_EFC_Enabled(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_sob_id => g_set_of_books_id,
p_efc_enabled => g_efc_enabled
);

dbms_output.put_line ('The return status '||l_return_status);


dbms_output.put_line ('l_msg_data '||l_msg_data );
dbms_output.put_line ('l_msg_count'||l_msg_count);
dbms_output.put_line (' g_g_efc_enabled'|| g_efc_enabled);

IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN

dbms_output.put_line ('Error occured in validate check efc enabled');

raise FND_API.G_EXC_ERROR;

END IF;

IF g_conc_proc THEN --If concurrent process then we can try to lock many times.
g_maxloops:=g_maxloops*20;
g_seconds :=g_seconds*3;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Validating interface table..');
Register_time('',TRUE);
dbms_output.put_line ('Validating interface table');

END IF;
-- ssmales 28/01/02 bug 2201905 - added g_p_packet_id as final argument to call below

dbms_output.put_line ('Validating cc interface started');

IGC_CBC_VALIDATIONS_PKG.Validate_CC_Interface
(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_sob_id => g_set_of_books_id,
p_cbc_enabled => g_cbc_enabled,
p_cc_head_id => g_cc_header_id,
p_actl_flag => g_actual_flag,
p_documt_type => g_doc_type,
p_sum_line_num => g_summary_line_num,
p_cbc_flag => l_cbc_flag,
p_sbc_flag => l_sbc_flag,
p_packet_id => g_p_packet_id
);

dbms_output.put_line ('The return status '||l_return_status);


dbms_output.put_line ('l_msg_data '||l_msg_data );
dbms_output.put_line ('l_msg_count'||l_msg_count);
dbms_output.put_line (' l_cbc_flag '||l_cbc_flag);
dbms_output.put_line (' l_sbc_flag '||l_sbc_flag);
dbms_output.put_line (' g_summary_line_num '||g_summary_line_num);

IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN


dbms_output.put_line ('Error Validating interface table');
raise FND_API.G_EXC_ERROR;
END IF;
g_cbc_flag := FND_API.TO_BOOLEAN(l_cbc_flag);
g_sbc_flag := FND_API.TO_BOOLEAN(l_sbc_flag);

IF NOT(g_cbc_flag) AND NOT(g_sbc_flag) THEN


--No rows - return success.

dbms_output.put_line ('No rows - return success');

IF (g_debug_mode = 'Y') THEN


Put_Debug_Msg(l_full_path, 'Now rows found - return success');
dbms_output.put_line ('No rows found - return success');
END IF;
p_ret_status := 'SN';
p_batch_result_code:=NULL;

dbms_output.put_line ('P_ret_status '||p_ret_status );


dbms_output.put_line ('p_batch_result_code'||p_batch_result_code);

RETURN(TRUE);

END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN

dbms_output.put_line ('validate interface false');

Register_time('Validate interface ',FALSE);

END IF;

IF (g_cbc_flag) THEN --There are CBC transactions in the interface table


-- obtaining encumbrance iformation

dbms_output.put_line ('There are CBC transactions in the interface table ');

OPEN c_ent;
FETCH c_ent INTO g_com_enc_id,g_obl_enc_id;

dbms_output.put_line ('cursor open c_ent');

IF c_ent%NOTFOUND THEN
dbms_output.put_line ('cursor open c_ent error raise due to no data found');
CLOSE c_ent;
add_message ('IGC', 'IGC_NO_ENC_FOUND');
raise FND_API.G_EXC_ERROR;
END IF;

CLOSE c_ent;

-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'CBC records found');
dbms_output.put_line ('CBC records found');
END IF;
--Fetch sequence batch value
l_cbc_status:='S';
dbms_output.put_line ('CBC records found status l_cbc_status'||l_cbc_status);
--create batch enties
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Batch creating..');
dbms_output.put_line ('Calling Register create Batch');
Register_time('Create JE batch ',TRUE);
END IF;
dbms_output.put_line ('Calling creation Batch');
Create_JE_Batch ( x_return_status => l_return_status );
dbms_output.put_line ('Calling creation Batch status'||l_return_status );
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
dbms_output.put_line ('Calling register Create JE batch false' );
Register_time('Create JE batch ',FALSE);
Put_Debug_Msg(l_full_path, 'Locking..');
Register_time('Locking ',TRUE);
END IF;
IF NOT( Lock_JE_Lines ) THEN
dbms_output.put_line ('Error Raising lock JE line ');
raise FND_API.G_EXC_ERROR;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
dbms_output.put_line ('lock JE line false ');
Register_time('Locking ',FALSE);
Register_time('GL shared ',TRUE);
END IF;
-- ssmales 28/01/02 bug 2201905 - new processing and loop for p_packet_id
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN

dbms_output.put_line ('g_p_packet_id not null ');

FOR l_cc_header_rec IN c_cc_headers LOOP


g_cc_header_id := l_cc_header_rec.cc_header_id ;
g_doc_type := l_cc_header_rec.document_type ;
-- LOOP
FOR c_cc_interface_rec IN c_cc_interface LOOP

dbms_output.put_line ('calling populate cbc line info');

-- "GL_SHARED_INFO" AND create a temporary JE


Populate_CBC_Line_Info(
p_ccid => c_cc_interface_rec.code_combination_id,
p_entered_cr => c_cc_interface_rec.cc_func_cr_amt,
p_entered_dr => c_cc_interface_rec.cc_func_dr_amt,
p_je_line_num => c_cc_interface_rec.batch_line_num,
p_je_source => c_cc_interface_rec.je_source_name,
p_je_category => c_cc_interface_rec.je_category_name,
p_effective_date => c_cc_interface_rec.cc_transaction_date,
p_currency_code => c_cc_interface_rec.currency_code,
p_encumbrance_type => c_cc_interface_rec.encumbrance_type_id,
p_budget_ver_id => c_cc_interface_rec.budget_version_id,
p_description => c_cc_interface_rec.transaction_description,
p_cc_acct_line_id => c_cc_interface_rec.cc_acct_line_id,
p_cc_version_num => c_cc_interface_rec.cc_version_num,
p_det_sum_value => 'D',
x_ReturnStatus => l_return_status
);
dbms_output.put_line ('l_return_status populate cbc line info'||l_return_status);

IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN


dbms_output.put_line ('Raise excep error');
raise FND_API.G_EXC_ERROR;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path,
'*************************************************************');
END IF;
END LOOP ;
END LOOP ;
ELSE
-- bug 2201905 end block
-- LOOP
FOR c_cc_interface_rec IN c_cc_interface LOOP
dbms_output.put_line ('calling populate cbc line info for packet id null');
-- "GL_SHARED_INFO" AND create a temporary JE
Populate_CBC_Line_Info(
p_ccid => c_cc_interface_rec.code_combination_id,
p_entered_cr => c_cc_interface_rec.cc_func_cr_amt,
p_entered_dr => c_cc_interface_rec.cc_func_dr_amt,
p_je_line_num => c_cc_interface_rec.batch_line_num,
p_je_source => c_cc_interface_rec.je_source_name,
p_je_category => c_cc_interface_rec.je_category_name,
p_effective_date => c_cc_interface_rec.cc_transaction_date,
p_currency_code => c_cc_interface_rec.currency_code,
p_encumbrance_type => c_cc_interface_rec.encumbrance_type_id,
p_budget_ver_id => c_cc_interface_rec.budget_version_id,
p_description => c_cc_interface_rec.transaction_description,
p_cc_acct_line_id => c_cc_interface_rec.cc_acct_line_id,
p_cc_version_num => c_cc_interface_rec.cc_version_num,
p_det_sum_value => 'D',
x_ReturnStatus => l_return_status
);
dbms_output.put_line ('l_return_status populate cbc line info'||l_return_status);

IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN


dbms_output.put_line ('Raise excep error');
raise FND_API.G_EXC_ERROR;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path,
'*************************************************************');
END IF;
END LOOP; -- Interface record
-- ssmales 28/02/01 bug 2201905 - added end if below
END IF ;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
dbms_output.put_line ('register GL Shared false');
Register_time('GL shared ',FALSE);
Register_time('FA calculation ',TRUE);
END IF;
IF NOT g_validation_error THEN
-- No validation error encountered - keep processing
dbms_output.put_line ('g validation error if not');
FOR c_cbc_je_lines_rec IN c_cbc_je_lines LOOP
-- calculate FA for each CCID
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
dbms_output.put_line ('c cbc je lines cursor');
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Calculating FA for CCID:' ||
c_cbc_je_lines_rec.code_combination_id ||
' ' || c_cbc_je_lines_rec.detail_summary_code ||
' line num' || c_cbc_je_lines_rec.cbc_je_line_num);
END IF;
IF (c_cbc_je_lines_rec.detail_summary_code ='D') THEN

dbms_output.put_line ('Calling get detail bal');

Get_Detail_Bal (
p_dccid => c_cbc_je_lines_rec.code_combination_id,
p_amount_t => c_cbc_je_lines_rec.amount_type,
p_budget_ver => c_cbc_je_lines_rec.budget_version_id,
p_period_yr => c_cbc_je_lines_rec.period_year,
p_period_nm => c_cbc_je_lines_rec.period_num,
p_quarter_nm => c_cbc_je_lines_rec.quarter_num,
p_funds_level => NVL(c_cbc_je_lines_rec.funds_check_level_code,'N'),
x_fa => l_fa_amt,
x_com_bal => l_com_enc_amt,
x_act_bal => l_obl_enc_amt,
x_oth_bal => l_oth_enc_amt,
x_bud_bal => l_budget_amt,
x_return_status => l_return_status
);

dbms_output.put_line ('l_return_status'||l_return_status);

IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN


raise FND_API.G_EXC_ERROR;
END IF;
ELSE

dbms_output.put_line ('Calling get summary bal');

Get_Summary_Bal (
p_ccid => c_cbc_je_lines_rec.code_combination_id,
p_amount_t => c_cbc_je_lines_rec.amount_type,
p_budget_ver => c_cbc_je_lines_rec.budget_version_id,
p_period_yr => c_cbc_je_lines_rec.period_year,
p_period_nm => c_cbc_je_lines_rec.period_num,
p_quarter_nm => c_cbc_je_lines_rec.quarter_num,
p_funds_level => NVL(c_cbc_je_lines_rec.funds_check_level_code,'N'),
x_fa => l_fa_amt,
x_com_bal => l_com_enc_amt,
x_act_bal => l_obl_enc_amt,
x_oth_bal => l_oth_enc_amt,
x_bud_bal => l_budget_amt,
x_return_status => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
END IF;
-- Get Result code for transaction

dbms_output.put_line ('Calling get result code');


dbms_output.put_line ('l_fa_amt amount is '||l_fa_amt);
dbms_output.put_line ('c_cbc_je_lines_rec.funds_check_level_code '||
c_cbc_je_lines_rec.funds_check_level_code);
dbms_output.put_line ('c_cbc_je_lines_rec.entered_cr '||c_cbc_je_lines_rec.entered_cr);
dbms_output.put_line ('c_cbc_je_lines_rec.entered_dr '||c_cbc_je_lines_rec.entered_dr);
dbms_output.put_line ('c_cbc_je_lines_rec.detail_summary_code '||
c_cbc_je_lines_rec.detail_summary_code);
dbms_output.put_line ('c_cbc_je_lines_rec.code_combination_id '||
c_cbc_je_lines_rec.code_combination_id);

Get_Result_Code (
p_funds_available => l_fa_amt,
p_funds_level => NVL(c_cbc_je_lines_rec.funds_check_level_code,'N'),
p_amount => NVL(c_cbc_je_lines_rec.entered_dr,0)-NVL(c_cbc_je_lines_rec.entered_cr,0),
p_summary_detail_code => c_cbc_je_lines_rec.detail_summary_code,
p_ccid => c_cbc_je_lines_rec.code_combination_id,
x_result_code => l_result_code,
x_status_code => l_status_code
);

dbms_output.put_line ('l result code '||l_result_code);


dbms_output.put_line ('l status code '||l_status_code);

IF (l_result_code IS NULL) THEN


dbms_output.put_line ('l result code is null ');
add_message ('IGC', 'IGC_INVALID_RESULT_CODE');
raise FND_API.G_EXC_ERROR;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Funds calculated: AMT: ' || c_cbc_je_lines_rec.amount_type ||
', FA: ' || l_fa_amt || ', Period: ' ||
c_cbc_je_lines_rec.period_name || ' Res code: ' || l_result_code);
END IF;
--Store batch result code
dbms_output.put_line ('calling batch result code ');
Set_Batch_Result_Code(l_result_code);
dbms_output.put_line ('calling batch result code status '||l_result_code);

IF (substr(l_result_code,1,1)='F') THEN
--If any of transactions is failed - total status or batch failed.
l_batch_status :='R';
l_cbc_status :='F';
ELSIF (l_batch_status='A' AND (l_result_code IN ('P22','P20'))) THEN
-- Advisory warnings and previous transactions were successful
l_cbc_status:='A';
END IF;
-- Update status for all detail lines and failed summary lines
IF (c_cbc_je_lines_rec.detail_summary_code ='D') THEN
-- Update result for detail ccid

dbms_output.put_line ('calling update rsult status for detail summary code D ');

Update_Result_Status (
p_ccid => c_cbc_je_lines_rec.code_combination_id,
p_batch_line_num => c_cbc_je_lines_rec.cbc_je_line_num,
p_result_code => l_result_code,
p_status_code => l_status_code,
p_summary_detail => 'D',
p_budget_version_id => c_cbc_je_lines_rec.budget_version_id,
p_period_name => c_cbc_je_lines_rec.period_name,
p_quarter_num => c_cbc_je_lines_rec.quarter_num,
p_period_num => c_cbc_je_lines_rec.period_num,
p_period_year => c_cbc_je_lines_rec.period_year,
p_amount_type => c_cbc_je_lines_rec.amount_type,
p_budget_dest => 'CBC',
p_budget_amt => l_budget_amt,
p_com_enc_amt => l_com_enc_amt,
p_obl_enc_amt => l_obl_enc_amt,
p_fa_amt => l_fa_amt,
x_return_status => l_return_status
);

dbms_output.put_line ('l_return_status '||l_return_status );


dbms_output.put_line ('l_result_code '||l_result_code);
dbms_output.put_line ('l_status_code '||l_status_code);

IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN


raise FND_API.G_EXC_ERROR;
END IF;
ELSIF l_result_code IN ('P22','F01') THEN
--Update result for summary ccid only if status failed

dbms_output.put_line ('calling update rsult status for detail summary code P22 F01 ');

Update_Result_Status (
p_ccid => c_cbc_je_lines_rec.code_combination_id,
p_batch_line_num => c_cbc_je_lines_rec.cbc_je_line_num,
p_result_code => l_result_code,
p_status_code => l_status_code,
p_summary_detail => 'S',
p_budget_version_id => c_cbc_je_lines_rec.budget_version_id,
p_period_name => c_cbc_je_lines_rec.period_name,
p_quarter_num => c_cbc_je_lines_rec.quarter_num,
p_period_num => c_cbc_je_lines_rec.period_num,
p_period_year => c_cbc_je_lines_rec.period_year,
p_amount_type => c_cbc_je_lines_rec.amount_type,
p_budget_dest => 'CBC',
p_budget_amt => l_budget_amt,
p_com_enc_amt => l_com_enc_amt,
p_obl_enc_amt => l_obl_enc_amt,
p_fa_amt => l_fa_amt,
x_return_status => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
END IF;
END LOOP;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
dbms_output.put_line ('CBC FC completed FC status'||l_cbc_status );
Put_Debug_Msg(l_full_path, 'CBC FC completed FC status: ' || l_cbc_status ||
' batch status: '|| l_batch_status);
Register_time('FA calculation ',FALSE);
END IF;
ELSE
--Validaion error ocurred: delete all temporary transactions, return fatal and false

dbms_output.put_line ('Validaion error ocurred: delete all temporary transactions ');

Update_CBC_JE_Line (
p_ccid => NULL,
p_je_line_num => NULL,
p_det_sum_val => NULL,
p_update_type => 'D',
p_entered_cr => 0,
p_entered_dr => 0,
x_return_status => l_return_status
);

dbms_output.put_line (' The Return status update cbc je line '||l_return_status);

IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN


raise FND_API.G_EXC_ERROR;
END IF;

dbms_output.put_line (' calline batch result code function ');

p_batch_result_code := Get_Batch_Result_Code (g_mode,g_batch_result_code);

dbms_output.put_line (' p_batch_result_code '|| p_batch_result_code) ;

-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Validation error occured, code: ' || p_batch_result_code);
END IF;

dbms_output.put_line ('the g_called_from_PO '||g_called_from_PO);


IF NOT g_called_from_PO
THEN
COMMIT;
END IF;
dbms_output.put_line ('The p ret status is set to TN');
p_ret_status := 'TN';
dbms_output.put_line ('The p ret status is '||p_ret_status);
RETURN FALSE;
END IF;
END IF; --End of CBC FC
-- call to sbc (need for an autonomous transaction)
IF ((g_actual_flag = 'E') AND (g_sbc_flag) AND (l_batch_status='A' OR p_mode='C')) THEN
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN

dbms_output.put_line (' E G SBC FLAG BATCH STATUS A OR P MODE C ') ;

IF (g_debug_mode = 'Y') THEN


dbms_output.put_line (' SBC RECORDS FOUND') ;
Put_Debug_Msg(l_full_path, 'SBC records found');
Register_time('Pre SBC ',TRUE);
END IF;
-- Inserted by Ezhil Vidhya D, OSSI on 10-MAY-2007 as a part of 11.5.10 redevelopment
commit;

-- bug 4130976 - start

IF NOT g_called_from_PO THEN


dbms_output.put_line (' COMMIT ') ;
COMMIT;
END IF;

-- bug 4130976 - end

l_res:=Check_SBC(l_return_status);
l_sbc_status:=l_return_status;

dbms_output.put_line (' bug 4130976 l_sbc_status'||l_sbc_status) ;


dbms_output.put_line (' bug 4130976 l_res'||l_res) ;

IF l_return_status IN ('F','U','T') THEN -- SBC failed FC


l_batch_status:='R';
dbms_output.put_line (' l batch status '||l_batch_status) ;

END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN

dbms_output.put_line ('SBC FC completed FC status'||l_sbc_status ) ;

Put_Debug_Msg(l_full_path, 'SBC FC completed FC status:' || l_sbc_status ||


' batch status: ' || l_batch_status);
Register_time('Post SBC summary update ',FALSE);
END IF;
END IF;
-- autonomous transaction returns/return to main
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN

dbms_output.put_line (' update result code ');

Register_time('Update result codes ',TRUE);


END IF;
IF g_cbc_flag THEN
--perform the Je line update for CBC transactions.

dbms_output.put_line (' l_batch_status'||l_batch_status);


dbms_output.put_line (' p_mode '||p_mode);

IF (l_batch_status='R' OR p_mode='C') THEN


-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
dbms_output.put_line ('Deleting temporary transactions and updating result code');

Put_Debug_Msg(l_full_path, 'Deleting temporary transactions and updating result code');


END IF;
-- Batch failed FC or mode check: delete temporary transactions
dbms_output.put_line ('Batch failed FC or mode check: delete temporary transactions');
Update_CBC_JE_Line (
p_ccid => NULL,
p_je_line_num => NULL,
p_det_sum_val => NULL,
p_update_type => 'D',
p_entered_cr => 0,
p_entered_dr => 0,
x_return_status => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
ELSE
-- Mode reservation and batch passed FC, Update status of CC_Interface
-- and change status of temporary transactions from temporary to permanent
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
dbms_output.put_line ('commiting transaction and updating result code');
Put_Debug_Msg(l_full_path, 'Commiting transactions and updating result code');
END IF;
Update_CBC_JE_Line (
p_ccid => NULL,
p_je_line_num => NULL,
p_det_sum_val => NULL,
p_update_type => 'B',
p_entered_cr => 0,
p_entered_dr => 0,
x_return_status => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
-- If CBC is enabled, and both CBC and SBC passed the funds
-- check/reservation, then pass the batch info to the MRC package.
Split_JE_Batch(x_return_status => l_return_status );
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
END IF; -- transfer from T to P
END IF; --CBC records
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
dbms_output.put_line ('update result code false');
Register_time('Update result codes ',FALSE);
END IF;
p_batch_result_code:= Get_Batch_Result_Code (g_mode,g_batch_result_code);
dbms_output.put_line ('p_batch_result_code '||p_batch_result_code);

IF NOT g_called_from_PO
THEN
COMMIT;
END IF;

dbms_output.put_line ('l_cbc_status '||l_cbc_status);

dbms_output.put_line (' l_sbc_status '||l_sbc_status);

p_ret_status :=l_cbc_status||l_sbc_status;

dbms_output.put_line ('p_ret_status '||p_ret_status );

IF (g_debug_mode = 'Y') THEN


Put_Debug_Msg(l_full_path, 'FC completed successfully, code: ' || p_batch_result_code || ' status: ' ||
p_ret_status);
END IF;
IF l_cbc_status ='T' OR l_sbc_status IN ('U','T') THEN
p_batch_result_code:=NULL;
RETURN FALSE;
END IF;
RETURN(TRUE);
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
IF (c_cc_interface%ISOPEN) THEN
CLOSE c_cc_interface;
END IF;
IF (c_cbc_je_lines%ISOPEN) THEN
CLOSE c_cbc_je_lines;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Execution error occured');
END IF;
ROLLBACK to IGCFCK;
l_cbc_status:='T';
IF(p_mode IN ('R','F') AND l_sbc_status IN ('A','S')) THEN
--Unreserve SBC transactions, because cbc failed after cbc during update results.
--If unreservation is unseccessfull than l_sbc_status
--return status of unreservation process ('S','F'), and total ret status is TU
--If unreservation successfull than return status is TN
IF NOT g_called_from_PO
THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unreserving SBC');
END IF;
Unreserve_SBC(l_return_status);
IF l_return_status='S' THEN
l_sbc_status:='N';
ELSE
l_sbc_status:='U';
END IF;
END IF;
END IF;
p_ret_status := l_cbc_status || l_sbc_status;
p_batch_result_code:=NULL;
IF ( g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level,l_full_path,'FND_API.G_EXC_ERROR Exception Raised');
END IF;
RETURN(FALSE);
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
IF (c_cc_interface%ISOPEN) THEN
CLOSE c_cc_interface;
END IF;
IF (c_cbc_je_lines%ISOPEN) THEN
CLOSE c_cbc_je_lines;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unexpected error occured');
END IF;
ROLLBACK to IGCFCK;
l_cbc_status:='T';
IF (p_mode IN ('R','F') AND l_sbc_status IN ('A','S')) THEN
IF NOT g_called_from_PO
THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unreserving SBC');
END IF;
Unreserve_SBC(l_return_status);
IF l_return_status='S' THEN
l_sbc_status:='N';
ELSE
l_sbc_status:='U';
END IF;
END IF;
END IF;
p_ret_status := l_cbc_status || l_sbc_status;
p_batch_result_code:=NULL;
IF ( g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level,l_full_path,'FND_API.G_EXC_UNEXPECTED_ERROR Exception
Raised');
END IF;
RETURN(FALSE);
WHEN OTHERS THEN
IF (c_cc_interface%ISOPEN) THEN
CLOSE c_cc_interface;
END IF;
IF (c_cbc_je_lines%ISOPEN) THEN
CLOSE c_cbc_je_lines;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unknown error occured');
END IF;
ROLLBACK to IGCFCK;
l_cbc_status:='T';
IF (p_mode IN ('R','F') AND l_sbc_status IN ('A','S')) THEN
IF NOT g_called_from_PO
THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Unreserving SBC');
END IF;
--Unreserve SBC transactions, because cbc failed after cbc during update results.
Unreserve_SBC(l_return_status);
IF l_return_status='S' THEN
l_sbc_status:='N';
ELSE
l_sbc_status:='U';
END IF;
END IF;
END IF;
p_ret_status := l_cbc_status || l_sbc_status;
p_batch_result_code:=NULL;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
RETURN(FALSE);
END IGCFCK;
/****************************************************************************/
-- Call to Standard Budgetary Control
-- this function is fully independent - it shares nothing with the main
-- function
-- Returns S,A,F,
-- T - for fatal error
-- U - for fatal error and unable to unreserve
FUNCTION Check_SBC(
x_return_status OUT NOCOPY VARCHAR2
) RETURN BOOLEAN IS
PRAGMA AUTONOMOUS_TRANSACTION;
--local variables
l_api_name CONSTANT VARCHAR2(30) := 'Check_SBC';
l_packet_id NUMBER(15);
l_return_code VARCHAR2(15);
l_total_code VARCHAR2(1);
l_res BOOLEAN;
l_bud_ret_status VARCHAR2(1);
l_bud_res BOOLEAN;
l_budget_version_id igc_cc_interface.budget_version_id%TYPE;
l_amount_type igc_cbc_je_lines.amount_type%TYPE;
l_funds_level_code igc_cbc_je_lines.funds_check_level_code%TYPE;
l_effective_date igc_cbc_je_lines.effective_date%TYPE;
l_debug_msg VARCHAR2(2000);
-- Debug variables for BC packet insertion
l_je_source_name igc_cc_interface.je_source_name%TYPE;
l_je_category_name igc_cc_interface.je_category_name%TYPE;
l_ccid igc_cc_interface.code_combination_id%TYPE;
l_period_name gl_period_statuses.period_name%TYPE;
l_period_year gl_period_statuses.period_year%TYPE;
l_period_num gl_period_statuses.period_num%TYPE;
l_quarter_num gl_period_statuses.quarter_num%TYPE;
l_currency_code igc_cc_interface.currency_code%TYPE;
l_cc_func_dr_amt igc_cc_interface.cc_func_dr_amt%TYPE;
l_cc_func_cr_amt igc_cc_interface.cc_func_cr_amt%TYPE;
l_cc_acct_line_id igc_cc_interface.cc_acct_line_id%TYPE;
l_cc_version_num igc_cc_interface.cc_version_num%TYPE;
l_cc_det_pf_line_id igc_cc_interface.cc_det_pf_line_id%TYPE;
l_batch_line_num igc_cc_interface.batch_line_num%TYPE;
l_transaction_descr igc_cc_interface.transaction_description%TYPE;
l_encumbrance_type_id igc_cc_interface.encumbrance_type_id%TYPE;
l_status_code igc_cc_interface.status_code%TYPE;
l_result_code igc_cc_interface.cbc_result_code%TYPE;
l_rank NUMBER(4);
CURSOR c_debug_bc_packet IS
SELECT int.je_source_name,
int.je_category_name,
int.code_combination_id,
per.period_name,
per.period_year,
per.period_num,
per.quarter_num,
int.currency_code,
int.cc_func_dr_amt,
int.cc_func_cr_amt,
int.cc_acct_line_id,
int.cc_version_num,
int.cc_det_pf_line_id,
int.batch_line_num,
int.transaction_description,
int.encumbrance_type_id
FROM igc_cc_interface_v int,
gl_period_statuses per
WHERE int.budget_dest_flag = 'S'
AND int.cc_header_id = g_cc_header_id
AND int.actual_flag = g_actual_flag
AND int.document_type = g_doc_type
AND per.application_id = g_gl_application_id
AND per.adjustment_period_flag='N'
AND per.set_of_books_id = g_set_of_books_id
AND int.cc_transaction_date
BETWEEN per.start_date
AND per.end_date;
l_return_status VARCHAR2(1);
l_full_path VARCHAR2(255);
BEGIN
g_packet_count:=0;
l_total_code :='S';
l_full_path := g_path || 'Check_SBC';
-- ssmales 28/01/02 bug 2201905 - added if statement below
IF (g_p_packet_id is null) THEN
-- Get packet id
SELECT GL_BC_PACKETS_S.nextval
INTO l_packet_id
FROM dual;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
OPEN c_debug_bc_packet;
FETCH c_debug_bc_packet
INTO l_je_source_name,
l_je_category_name,
l_ccid,
l_period_name,
l_period_year,
l_period_num,
l_quarter_num,
l_currency_code,
l_cc_func_dr_amt,
l_cc_func_cr_amt,
l_cc_acct_line_id,
l_cc_version_num,
l_cc_det_pf_line_id,
l_batch_line_num,
l_transaction_descr,
l_encumbrance_type_id;
CLOSE c_debug_bc_packet;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Processing packet id: '||l_packet_id);
Put_Debug_Msg(l_full_path, ' Inserting record into GL BC Packets : ');
Put_Debug_Msg(l_full_path, ' Packet ID : ' || l_packet_id ||
' Set of Books ID : ' || g_set_of_books_id ||
' JE Source Name : ' || l_je_source_name ||
' JE Category Name : ' || l_je_category_name ||
' CCID : ' || l_ccid ||
' Actual Flag : ' || g_actual_flag ||
' Period Name : ' || l_period_name ||
' Period Year : ' || l_period_year ||
' Period Num : ' || l_period_num ||
' Quarter Num : ' || l_quarter_num ||
' Currency Code : ' || l_currency_code ||
' Mode : ' || g_mode ||
' DR Amount : ' || l_cc_func_dr_amt ||
' CR Amount : ' || l_cc_func_cr_amt ||
' CC Header ID : ' || g_cc_header_id ||
' CC Acct Line ID : ' || l_cc_acct_line_id ||
' CC Version num : ' || l_cc_version_num ||
' CC PF Line ID : ' || l_cc_det_pf_line_id ||
' Batch Line Num : ' || l_batch_line_num ||
' Trans Descr : ' || l_transaction_descr ||
' Encumbrance type ID : ' || l_encumbrance_type_id);
END IF;
END IF;
-- Insert into GL_BC_PACKETS
INSERT INTO GL_BC_PACKETS
(packet_id,
set_of_books_id,
je_source_name,
je_category_name,
code_combination_id,
actual_flag,
period_name,
period_year,
period_num,
quarter_num,
currency_code,
status_code,
last_update_date,
last_updated_by,
entered_dr,
entered_cr,
accounted_dr,
accounted_cr,
reference1,
reference2,
reference3,
reference4,
reference5,
je_line_description,
encumbrance_type_id
)
SELECT l_packet_id,
g_set_of_books_id,
int.je_source_name,
int.je_category_name,
int.code_combination_id,
g_actual_flag,
per.period_name,
per.period_year,
per.period_num,
per.quarter_num,
int.currency_code,
decode(g_mode, 'R', 'P','F', 'P', 'C', 'C'),
sysdate,
g_update_by,
int.cc_func_dr_amt,
int.cc_func_cr_amt,
int.cc_func_dr_amt,
int.cc_func_cr_amt,
g_cc_header_id,
int.cc_acct_line_id,
int.cc_version_num,
int.cc_det_pf_line_id,
int.batch_line_num,
int.transaction_description,
int.encumbrance_type_id
-- Bug 2885953 - select from igc_cc_interface rather than igc_cc_interface_v for performance enhancement
-- FROM igc_cc_interface_v int,
FROM igc_cc_interface int,
gl_period_statuses per
WHERE int.budget_dest_flag = 'S'
AND int.cc_header_id = g_cc_header_id
AND int.actual_flag = g_actual_flag
AND int.document_type = g_doc_type
AND per.application_id = g_gl_application_id
AND per.adjustment_period_flag='N'
AND per.set_of_books_id = g_set_of_books_id
AND int.cc_transaction_date
BETWEEN per.start_date
AND per.end_date;
-- ssmales 28/01/02 bug 2201905 - added else block below
-- bug 2201905 start block
ELSE
l_packet_id := g_p_packet_id ;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
OPEN c_debug_bc_packet;
FETCH c_debug_bc_packet
INTO l_je_source_name,
l_je_category_name,
l_ccid,
l_period_name,
l_period_year,
l_period_num,
l_quarter_num,
l_currency_code,
l_cc_func_dr_amt,
l_cc_func_cr_amt,
l_cc_acct_line_id,
l_cc_version_num,
l_cc_det_pf_line_id,
l_batch_line_num,
l_transaction_descr,
l_encumbrance_type_id;
CLOSE c_debug_bc_packet;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Processing packet id: '||l_packet_id);
Put_Debug_Msg(l_full_path, ' Record already exists in GL BC Packets : ');
Put_Debug_Msg(l_full_path, ' Packet ID : ' || l_packet_id ||
' Set of Books ID : ' || g_set_of_books_id ||
' JE Source Name : ' || l_je_source_name ||
' JE Category Name : ' || l_je_category_name ||
' CCID : ' || l_ccid ||
' Actual Flag : ' || g_actual_flag ||
' Period Name : ' || l_period_name ||
' Period Year : ' || l_period_year ||
' Period Num : ' || l_period_num ||
' Quarter Num : ' || l_quarter_num ||
' Currency Code : ' || l_currency_code ||
' Mode : ' || g_mode ||
' DR Amount : ' || l_cc_func_dr_amt ||
' CR Amount : ' || l_cc_func_cr_amt ||
' CC Header ID : ' || g_cc_header_id ||
' CC Acct Line ID : ' || l_cc_acct_line_id ||
' CC Version num : ' || l_cc_version_num ||
' CC PF Line ID : ' || l_cc_det_pf_line_id ||
' Batch Line Num : ' || l_batch_line_num ||
' Trans Descr : ' || l_transaction_descr ||
' Encumbrance type ID : ' || l_encumbrance_type_id);
END IF;
END IF;
END IF ;
-- bug 2201905 end block
-- Call FC
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, ' Running GL FC ');
END IF;
Register_time('Pre SBC ',FALSE);
Register_time('SBC ',TRUE);
l_res := GL_FUNDS_CHECKER_PKG.GLXFCK(g_set_of_books_id,
l_packet_id,
g_mode,
'N',
'N',
'N',
g_update_by,
g_resp_id,
l_return_code);
-- Analyze results
IF l_res AND l_return_code = 'A' THEN
-- success - store packet_id
g_packet_id := l_packet_id;
ELSIF NOT (l_res) THEN
FND_MSG_PUB.ADD;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Register_time('SBC ',FALSE);
Put_Debug_Msg (l_full_path, '***********************************************');
Put_Debug_Msg (l_full_path, 'Obtaining GL Funds Checker Debug String');
l_debug_msg := GL_FUNDS_CHECKER_PKG.get_debug;
Put_Debug_Msg (l_full_path, '***********************************************');
Put_Debug_Msg(l_full_path, l_debug_msg);
IF (l_res) THEN
Put_Debug_Msg(l_full_path, 'Return code TRUE '||l_return_code);
ELSE
Put_Debug_Msg(l_full_path, 'Return code FALSE '||l_return_code);
END IF;
Put_Debug_Msg (l_full_path, 'Processing results for the packet '||l_packet_id);
Register_time('Post SBC summary update ',TRUE);
Put_Debug_Msg (l_full_path, ' Updating result..');
END IF;
-- ssmales 28/01/02 bug 2201905 - added if statement below
IF (g_p_packet_id is null) THEN
UPDATE igc_cc_interface_v int
SET (
int.cbc_result_code ,
int.status_code ,
int.last_update_date ,
int.last_updated_by ,
int.period_name ,
int.budget_version_id,
int.result_code_source,
int.batch_id
)=
( SELECT
bcd1.result_code,
Get_Status_By_Result(bcd1.result_code),
sysdate,
g_update_by ,
bcd1.period_name ,
bcd1.funding_budget_version_id,
'C' ,
decode(bcd1.status_code,'A',decode (g_mode ,'R',l_packet_id,'F',l_packet_id,NULL),NULL)
FROM gl_bc_packets bcd1
WHERE bcd1.template_id IS NULL
AND bcd1.packet_id = l_packet_id
AND bcd1.reference5 = to_char(int.batch_line_num)
)
WHERE int.cc_header_id = g_cc_header_id
AND int.actual_flag = g_actual_flag
AND int.document_type = g_doc_type
AND int.budget_dest_flag = 'S' ;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, to_char(SQL%ROWCOUNT)||' lines updated');
END IF;
-- ssmales 28/01/02 bug 2201905 - added else block below
-- bug 2201905 start block
ELSE
UPDATE igc_cc_interface_v int
SET (
int.cbc_result_code ,
int.status_code ,
int.last_update_date ,
int.last_updated_by ,
int.period_name ,
int.budget_version_id,
int.result_code_source,
int.batch_id
)=
( SELECT
bcd1.result_code,
Get_Status_By_Result(bcd1.result_code),
sysdate,
g_update_by ,
bcd1.period_name ,
bcd1.funding_budget_version_id,
'C' ,
decode(bcd1.status_code,'A',decode (g_mode ,'R',l_packet_id,'F',l_packet_id,NULL),NULL)
FROM gl_bc_packets bcd1
WHERE bcd1.template_id IS NULL
AND bcd1.packet_id = l_packet_id
AND bcd1.reference2 = int.cc_header_id
AND bcd1.reference3 = int.cc_acct_line_id
AND bcd1.actual_flag = 'E'
-- AND bcd1.reference1 = int.document_type
AND bcd1.reference1 = int.reference_1 -- Bug 3173178
)
WHERE int.reference_6 = g_p_packet_id
AND int.actual_flag = g_actual_flag
AND int.budget_dest_flag = 'S' ;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, to_char(SQL%ROWCOUNT)||' lines updated');
END IF;
END IF ;
-- bug 2201905 end block
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Interface table updated ');
END IF;
-- Selecting Rank
SELECT min(Get_Rank(bcd1.result_code))
INTO l_rank
FROM gl_bc_packets bcd1
WHERE bcd1.packet_id = l_packet_id;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'The most severe rank from SBC is: '||l_rank);
END IF;
Set_Batch_Result_Code ( Get_Result_By_Rank(l_rank));
-- Analyze again
IF (NOT l_res) OR l_return_code = 'T' THEN
l_total_code :='T';
ELSIF l_return_code = 'F' THEN
l_total_code :='F';
ELSIF l_return_code = 'A' THEN
l_total_code :='A';
END IF;
x_return_status:= l_total_code;
IF NOT g_called_from_PO
THEN
COMMIT;
END IF;
RETURN TRUE;
EXCEPTION
WHEN OTHERS THEN
-- Inserted by Ezhil Vidhya D, OSSI on 10-MAY-2007 as a part of 11.5.10 redevelopment
put_debug_msg(l_full_path, 'FOUT IN CHECK_SBC!!!!!!!!!!!!!!!!!!!'||sqlerrm);
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF NOT g_called_from_PO
THEN
Unreserve_SBC(l_return_code);
IF l_return_code='S' THEN
x_return_status:= 'T';
COMMIT WORK;
RETURN FALSE;
ELSE
x_return_status:='U';
COMMIT WORK;
RETURN FALSE;
END IF;
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
RETURN(FALSE);
END Check_SBC;
/****************************************************************************/
-- Add Token and Value to the Message Token array
PROCEDURE message_token(
tokname IN VARCHAR2,
tokval IN VARCHAR2
) IS
BEGIN
IGC_MSGS_PKG.message_token (p_tokname => tokname,
p_tokval => tokval);
END message_token;
/****************************************************************************/
-- Sets the Message Stack
PROCEDURE add_message(
appname IN VARCHAR2,
msgname IN VARCHAR2
) IS
i BINARY_INTEGER;
BEGIN
IGC_MSGS_PKG.add_message (p_appname => appname,
p_msgname => msgname);
END add_message;
-- --------------------------------------------------------------------
-- This procedure returns amount type for summary CCID in select statement
-- ruring the generation of summary CCID list.
-- IF you change mechanism of amount_type obtaining also check and
-- change if needed Get_CCID_Budget_Info procedure
-- --------------------------------------------------------------------
FUNCTION Get_CCID_Amount_Type (
p_type_of_value IN VARCHAR,
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE,
p_currency_code IN igc_cbc_je_lines.currency_code%TYPE,
p_effective_date IN igc_cbc_je_lines.effective_date%TYPE, -- Transaction Date
p_det_sum_value IN igc_cbc_je_lines.detail_summary_code%TYPE,
p_budget_ver_id IN igc_cbc_je_lines.budget_version_id%TYPE
) RETURN VARCHAR2 IS
-- Bug 2885953 - amended cursor below for performance enhancements
-- CURSOR c_igc_je_detail_info IS
-- SELECT GBA.amount_type,
-- GBA.funds_check_level_code,
-- GBA.funding_budget_version_id
-- FROM gl_budget_assignments GBA
-- WHERE GBA.set_of_books_id = g_set_of_books_id
-- AND GBA.code_combination_id = p_ccid
-- AND GBA.currency_code = p_currency_code
-- AND GBA.range_id IN
-- ( SELECT asg.range_id
-- FROM gl_budget_assignment_ranges asg,
-- gl_budget_versions bvr,
-- gl_budgets bud,
-- gl_period_statuses fper,
-- gl_period_statuses lper
-- WHERE asg.funding_budget_version_id IS NOT NULL
-- AND asg.funding_budget_version_id = bvr.budget_version_id
-- AND bvr.budget_name = bud.budget_name
-- AND fper.set_of_books_id = g_set_of_books_id
-- AND lper.set_of_books_id = g_set_of_books_id
-- AND bud.first_valid_period_name = fper.period_name
-- AND bud.last_valid_period_name = lper.period_name
-- AND fper.application_id = g_gl_application_id
-- AND lper.application_id = g_gl_application_id
-- AND p_effective_date BETWEEN fper.start_date AND lper.end_date
-- );
CURSOR c_igc_je_detail_info IS
SELECT GBA.amount_type,
GBA.funds_check_level_code,
GBA.funding_budget_version_id
FROM gl_budget_assignments GBA,
gl_budget_assignment_ranges asg,
gl_budget_versions bvr,
gl_budgets bud,
gl_period_statuses fper,
gl_period_statuses lper
WHERE GBA.set_of_books_id = g_set_of_books_id
AND GBA.code_combination_id = p_ccid
AND GBA.currency_code = p_currency_code
AND GBA.range_id = asg.range_id
AND asg.funding_budget_version_id = bvr.budget_version_id
AND asg.set_of_books_id = g_set_of_books_id
AND asg.currency_code = p_currency_code
AND bvr.budget_name = bud.budget_name
AND fper.set_of_books_id = g_set_of_books_id
AND lper.set_of_books_id = g_set_of_books_id
AND bud.first_valid_period_name = fper.period_name
AND bud.last_valid_period_name = lper.period_name
AND fper.application_id = g_gl_application_id
AND lper.application_id = g_gl_application_id
AND p_effective_date BETWEEN fper.start_date AND lper.end_date;
CURSOR c_igc_je_summary_info IS
SELECT GST.amount_type,
GST.funds_check_level_code,
GST.funding_budget_version_id
FROM gl_summary_templates GST,
gl_account_hierarchies GAH
WHERE GAH.set_of_books_id = g_set_of_books_id
AND GAH.summary_code_combination_id = p_ccid
AND GST.template_id = GAH.template_id
AND GST.set_of_books_id = GAH.set_of_books_id;
l_amount_type igc_cbc_je_lines.amount_type%TYPE;
l_funds_level_code igc_cbc_je_lines.funds_check_level_code%TYPE;
l_api_name CONSTANT VARCHAR2(30) := 'Get_CCID_Amount_Type';
l_budget_ver_id igc_cbc_je_lines.budget_version_id%TYPE;
l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Get_CCID_Amount_Type';
-- ------------------------------------------------------------------------
-- Obtain the funds_check_level_code and amount_type for the CCID
-- for generate summary CCID list
-- ------------------------------------------------------------------------
OPEN c_igc_je_detail_info;
FETCH c_igc_je_detail_info
INTO l_amount_type,
l_funds_level_code,
l_budget_ver_id;
IF (c_igc_je_detail_info%NOTFOUND) AND p_det_sum_value ='S' THEN
OPEN c_igc_je_summary_info;
FETCH c_igc_je_summary_info
INTO l_amount_type,
l_funds_level_code,
l_budget_ver_id;
END IF;
IF (c_igc_je_detail_info%ISOPEN) THEN
CLOSE c_igc_je_detail_info;
END IF;
IF (c_igc_je_summary_info%ISOPEN) THEN
CLOSE c_igc_je_summary_info;
END IF;
RETURN l_amount_type;
END Get_CCID_Amount_Type;
-- -------------------------------------------------------------------------
-- The procedure Populate_CBC_Line_Info is designed to obtain all the info
-- that is required from the GL tables. This is the main procedure in the
-- method to get the information for funds checking and/or funds reservation
-- There are other procedures called to validate the CCID state, Insert
-- records into the IGC_CBC_JE_LINES table and update the summary account
-- records if already inserted into the IGC_CBC_JE_LINES table.
-- -------------------------------------------------------------------------
PROCEDURE Populate_CBC_Line_Info(
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE, -- Contract ID
p_entered_cr IN igc_cbc_je_lines.entered_cr%TYPE, -- CR Amount entered
p_entered_dr IN igc_cbc_je_lines.entered_dr%TYPE, -- DR Amount entered
p_je_line_num IN igc_cbc_je_lines.cbc_je_line_num%TYPE, -- Line number in CC_VIEW
p_je_source IN igc_cbc_je_lines.je_source%TYPE, -- JE source type
p_je_category IN igc_cbc_je_lines.je_category%TYPE, -- JE category from CC_VIEW
p_effective_date IN igc_cbc_je_lines.effective_date%TYPE, -- Transaction Date from CC_VIEW
p_currency_code IN igc_cbc_je_lines.currency_code%TYPE, -- Currency code from CC
p_encumbrance_type IN igc_cbc_je_lines.encumbrance_type_id%TYPE, -- Encumbrance Type
p_budget_ver_id IN igc_cbc_je_lines.budget_version_id%TYPE, -- Budget version id
p_description IN igc_cbc_je_lines.description%TYPE, -- CC Transaction Descr
p_cc_acct_line_id IN igc_cc_interface.cc_acct_line_id%TYPE, -- Used for Audit Trail
p_cc_version_num IN igc_cc_interface.cc_version_num%TYPE, -- Used for Audit Trail
p_det_sum_value IN VARCHAR2, --Detail summary code
x_ReturnStatus OUT NOCOPY VARCHAR2
) IS
-- -------------------------------------------------------------------------
-- Declare local variables used within fuction
-- -------------------------------------------------------------------------
l_api_name CONSTANT VARCHAR2(30) := 'Populate_CBC_Line_Info';
l_return_status VARCHAR2(1);
l_period_name igc_cbc_je_lines.period_name%TYPE;
l_period_set_name igc_cbc_je_lines.period_set_name%TYPE;
l_quarter_num igc_cbc_je_lines.quarter_num%TYPE;
l_period_num igc_cbc_je_lines.period_num%TYPE;
l_period_year igc_cbc_je_lines.period_year%TYPE;
l_debug_start_date gl_period_statuses.start_date%TYPE;
l_debug_end_date gl_period_statuses.end_date%TYPE;
l_debug_close_stat gl_period_statuses.closing_status%TYPE;
l_validation_error_code VARCHAR2(3);
l_amount_type igc_cbc_je_lines.amount_type%TYPE;
l_funds_level_code igc_cbc_je_lines.funds_check_level_code%TYPE;
l_budget_ver_id igc_cbc_je_lines.budget_version_id%TYPE;
l_out_budget_ver_id igc_cbc_je_lines.budget_version_id%TYPE;
l_budget_type igc_cbc_je_lines.budget_type%TYPE := 'Commitment';
l_msg_count NUMBER;
l_msg_data VARCHAR(2000);
l_rowid VARCHAR2(255);
l_validation_type VARCHAR2(2);
l_local_control_code VARCHAR2(1);
l_amount NUMBER;
-- -------------------------------------------------------------------------
-- Begin to build the cursor to get all the Summary Templates. Explode the
-- CCID into all the summary accounts that the CCID is associated to.
-- -------------------------------------------------------------------------
CURSOR c_igc_cbc_sumaccts IS
SELECT DISTINCT GAH.summary_code_combination_id
FROM gl_account_hierarchies GAH,
gl_summary_templates GST,
gl_period_statuses GPS
WHERE GST.template_id = GAH.template_id
AND GAH.detail_code_combination_id = p_ccid
AND GPS.application_id = g_gl_application_id
AND GPS.set_of_books_id = g_set_of_books_id
AND GPS.period_name = GST.start_actuals_period_name
AND GPS.application_id = g_gl_application_id
AND GPS.adjustment_period_flag = 'N'
AND p_effective_date >= GPS.start_date
AND GAH.summary_code_combination_id NOT IN
( SELECT ICJL.code_combination_id
FROM igc_cbc_je_lines ICJL
WHERE ICJL.set_of_books_id = g_set_of_books_id
AND ICJL.detail_summary_code = 'S'
AND ICJL.status = 'T'
AND ICJL.cbc_je_batch_id = g_batch_id
AND decode(Get_CCID_Amount_Type ('A',
ICJL.code_combination_id,
ICJL.currency_code,
p_effective_date,
'S',
NULL),
'QTD', ICJL.quarter_num,
'PTD', ICJL.period_num,
'YTD', ICJL.period_year)
= decode(Get_CCID_Amount_Type ('A',
ICJL.code_combination_id,
ICJL.currency_code,
p_effective_date,
'S',
NULL),
'QTD', l_quarter_num,
'PTD', l_period_num,
'YTD', l_period_year)
);

l_full_path VARCHAR2(255);
BEGIN
-- -------------------------------------------------------------------------
-- Standard Start of API savepoint
-- -------------------------------------------------------------------------
SAVEPOINT Populate_CBC_Line_Info_Pvt;
l_full_path := g_path || 'Populate_CBC_Line_Info';
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := 'Starting Populate_CBC_Line_Info';
Put_Debug_Msg (l_full_path, g_debug );
END IF;
-- -------------------------------------------------------------------------
-- Initialize variables here.
-- -------------------------------------------------------------------------
x_ReturnStatus := FND_API.G_RET_STS_SUCCESS;
-- -------------------------------------------------------------------------
-- Get the period information that is to be used in the insertion of the
-- detail account record as well as the Summary record if not already
-- present in the IGC_CBC_JE_LINES table which is checked later on.
-- -------------------------------------------------------------------------
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Populate_CBC_Line_Info for CCID ' || to_char(p_ccid) ||
' Entered CR : ' || to_char(p_entered_cr) ||
' Entered DR : ' || to_char(p_entered_dr) ||
' JE Line num : ' || to_char(p_je_line_num) ||
' JE source : ' || p_je_source ||
' JE Category : ' || p_je_category ||
' Effective Date : ' || to_char(p_effective_date) ||
' Currency : ' || p_currency_code ||
' Encumbrance Type : ' || to_char(p_encumbrance_type) ||
' Budget ID : ' || to_char(p_budget_ver_id);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
IF g_mode = 'F' THEN
l_validation_type :='LC';
ELSE
l_validation_type :='FC';
END IF;
l_validation_error_code:=NULL;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Validate period info');
END IF;
IGC_CBC_VALIDATIONS_PKG.Validate_Get_CCID_Period_Name(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_sob_id => g_set_of_books_id,
p_effect_date => p_effective_date,
p_check_type => l_validation_type,
p_period_name => l_period_name,
p_period_set_name => l_period_set_name,
p_quarter_num => l_quarter_num,
p_period_num => l_period_num,
p_period_year => l_period_year,
p_result_status => l_validation_error_code
);
IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
raise FND_API.G_EXC_ERROR;
END IF;
IF l_validation_error_code IS NULL THEN
--keep validation
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Validate CCID info');
END IF;
IGC_CBC_VALIDATIONS_PKG.Validate_CCID(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_validation_type => l_validation_type,
p_ccid => p_ccid,
p_effective_date => sysdate,
p_det_sum_value => p_det_sum_value,
p_set_of_books_id => g_set_of_books_id,
p_actual_flag => g_actual_flag,
p_result_code => l_validation_error_code
);
IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
raise FND_API.G_EXC_ERROR;
END IF;
IF l_validation_error_code IS NULL AND g_mode <> 'F' THEN
--keep validation
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Get budget info');
END IF;
IGC_CBC_VALIDATIONS_PKG.Validate_Get_CCID_Budget_Info(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_efc_enabled => g_efc_enabled,
p_set_of_books_id => g_set_of_books_id,
p_actual_flag => g_actual_flag,
p_ccid => p_ccid,
p_det_sum_value => p_det_sum_value,
p_currency_code => p_currency_code,
p_effective_date => p_effective_date,
p_budget_ver_id => p_budget_ver_id,
p_out_budget_ver_id => l_out_budget_ver_id,
p_amount_type => l_amount_type,
p_funds_level_code => l_funds_level_code
);
IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
raise FND_API.G_EXC_ERROR;
END IF;
l_local_control_code:=Calculate_Sevirity_Level(p_summary_detail_code => p_det_sum_value,
p_ccid => p_ccid,
p_source => p_je_source,
p_category => p_je_category,
p_ccid_level => l_funds_level_code);
l_funds_level_code := l_local_control_code ;
l_budget_ver_id := l_out_budget_ver_id;
END IF;
END IF;
IF l_validation_error_code IS NOT NULL THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Update result status to invalid');
END IF;
g_validation_error := TRUE;
Update_Result_Status(
p_ccid => p_ccid,
p_batch_line_num => p_je_line_num,
p_result_code => l_validation_error_code,
p_status_code => 'T',
p_summary_detail => p_det_sum_value,
p_budget_version_id => NULL,
p_period_name => NULL,
p_quarter_num => NULL,
p_period_num => NULL,
p_period_year => NULL,
p_amount_type => NULL,
p_budget_dest => 'CBC',
p_budget_amt => NULL,
p_com_enc_amt => NULL,
p_obl_enc_amt => NULL,
p_fa_amt => NULL,
x_return_status => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
ELSE
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Inserting Record JE LINES :' ||
' for CCID : ' || to_char(p_ccid) ||
' batch id : ' || to_char(g_batch_id) ||
' JE Line Num : ' || to_char(p_je_line_num) ||
' JE Source : ' || p_je_source ||
' JE Categ : ' || p_je_category ||
' Currency : ' || p_currency_code ||
' Actual Flag : ' || g_actual_flag ||
' Set Of Books : '|| to_char(g_set_of_books_id) ||
' Encum Type : ' || to_char(p_encumbrance_type) ||
' Budget ID : ' || to_char(l_budget_ver_id) ||
' Det Sum Val : ' || p_det_sum_value ||
' Funds Check Code : ' || l_funds_level_code ||
' Amount Type : ' || l_amount_type ||
' Effect Date : ' || to_char(p_effective_date) ||
' Period Year : ' || to_char(l_period_year) ||
' DR/CR Code : ' || 'N/A' ||
' Entered DR : ' || to_char(p_entered_dr) ||
' Entered CR : ' || to_char(p_entered_cr) ||
' Budget Type : ' || l_budget_type ||
' Period Name : ' || l_period_name ||
' Period Set Name : ' || l_period_set_name ||
' Quart Num : ' || to_char(l_quarter_num) ||
' Period Num : ' || to_char(l_period_num) ||
' Line Status : ' || 'T' ||
' Last Update : ' || to_char(SYSDATE) ||
' Update By : ' || to_char(g_update_by) ||
' Update Login : ' || to_char(g_update_login) ||
' Create Date : ' || to_char(SYSDATE) ||
' Created By : ' || to_char(g_update_by) ||
' CC Header ID : ' || to_char (g_cc_header_id) ||
' Acct Line ID : ' || to_char (p_cc_acct_line_id) ||
' CC Version Num : ' || to_char (p_cc_version_num);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
-- ------------------------------------------------------------------------
-- Insert the row that is required for either the detailed account record
-- or the summary record. This will be based upon the p_det_sum_value (D
-- or S).
-- ------------------------------------------------------------------------
IGC_CBC_HANDLERS_PKG.Insert_Je_Line_Row (
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_row_id => l_rowid,
p_cbc_je_batch_id => g_batch_id,
p_cbc_je_line_num => p_je_line_num,
p_je_source => p_je_source,
p_je_category => p_je_category,
p_actual_flag => g_actual_flag,
p_currency_code => p_currency_code,
p_set_of_books_id => g_set_of_books_id,
p_encumbrance_type_id => p_encumbrance_type,
p_budget_version_id => l_budget_ver_id,
p_balancing_segment_value => '',
p_detail_summary_code => p_det_sum_value,
p_code_combination_id => p_ccid,
p_funds_check_level_code => l_funds_level_code,
p_amount_type => l_amount_type,
p_effective_date => p_effective_date,
p_posted_date => p_effective_date,
p_period_year => l_period_year,
p_dr_cr_code => '',
p_entered_dr => p_entered_dr,
p_entered_cr => p_entered_cr,
p_description => p_description,
p_budget_type => l_budget_type,
p_period_set_name => l_period_set_name,
p_period_name => l_period_name,
p_quarter_num => l_quarter_num,
p_period_num => l_period_num,
p_status => 'T',
p_context => '',
p_last_update_date => sysdate,
p_last_updated_by => g_update_by,
p_last_update_login => g_update_login,
p_creation_date => sysdate,
p_created_by => g_update_by,
p_reference_1 => to_char (g_cc_header_id),
p_reference_2 => to_char (p_cc_acct_line_id),
p_reference_3 => to_char (p_cc_version_num),
p_reference_4 => '',
p_reference_5 => '',
p_reference_6 => '',
p_reference_7 => '',
p_reference_8 => '',
p_reference_9 => '',
p_reference_10 => '',
p_attribute1 => '',
p_attribute2 => '',
p_attribute3 => '',
p_attribute4 => '',
p_attribute5 => '',
p_attribute6 => '',
p_attribute7 => '',
p_attribute8 => '',
p_attribute9 => '',
p_attribute10 => '',
p_attribute11 => '',
p_attribute12 => '',
p_attribute13 => '',
p_attribute14 => '',
p_attribute15 => ''
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
RAISE FND_API.G_EXC_ERROR ;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Done Inserting Record ';
Put_Debug_Msg (l_full_path, g_debug );
END IF;
END IF;
-- -------------------------------------------------------------------------
-- Begin to build the cursor to obtain all the summary templates where the
-- CCID given is associated to if there are any present.
-- -------------------------------------------------------------------------
l_amount := NVL(p_entered_dr,0) - NVL(p_entered_cr,0);
IF g_mode <>'F'
AND (NOT g_validation_error)
AND p_det_sum_value = 'D'
AND ((g_actual_flag ='E' AND l_amount > 0) OR --Transaction doesn't reduce funds available
(g_actual_flag ='B' AND l_amount < 0)) THEN
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Obtaining Summary Account info.';
Put_Debug_Msg (l_full_path, g_debug );
END IF;
-- -------------------------------------------------------------------------
-- Loop through all the records that are found for the detailed accounts
-- based upon the CCID that has been given.
-- -------------------------------------------------------------------------
FOR c_igc_cbc_sumaccts_rec IN c_igc_cbc_sumaccts LOOP
IF g_validation_error THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Validation error, don''t process summary any further');
END IF;
return;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Found Summary account : ' ||
to_char(c_igc_cbc_sumaccts_rec.summary_code_combination_id) ||
' for CCID : ' || to_char(p_ccid);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
g_summary_line_num := g_summary_line_num + 1;
Populate_CBC_Line_Info(
p_ccid => c_igc_cbc_sumaccts_rec.summary_code_combination_id,
p_entered_cr => p_entered_cr,
p_entered_dr => p_entered_dr,
p_je_line_num => g_summary_line_num,
p_je_source => p_je_source,
p_je_category => p_je_category,
p_effective_date => p_effective_date,
p_currency_code => p_currency_code,
p_encumbrance_type => p_encumbrance_type,
p_budget_ver_id => NULL,
p_description => p_description,
p_cc_acct_line_id => p_cc_acct_line_id,
p_cc_version_num => p_cc_version_num,
p_det_sum_value => 'S',
x_ReturnStatus => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
IF g_validation_error THEN
EXIT;
END IF;
END LOOP;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' DONE with Populate_CBC_Line_Info for CCID : ' || to_char(p_ccid);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
RETURN;
-- ------------------------------------------------------------------------
-- Declare the Exception Handlers to handle potential errors that can
-- happen when obtaining the information and updating/inserting into
-- the CBC_JE_LINES table.
-- ------------------------------------------------------------------------
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
ROLLBACK to Populate_CBC_Line_Info_Pvt;
x_ReturnStatus := FND_API.G_RET_STS_ERROR;
g_validation_error := TRUE;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_ERROR Exception Raised');
END IF;
RETURN;
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
ROLLBACK to Get_Budget_Option_Info_Pvt;
x_ReturnStatus := FND_API.G_RET_STS_UNEXP_ERROR;
g_validation_error := TRUE;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_UNEXPECTED_ERROR
Exception Raised');
END IF;
RETURN;
WHEN OTHERS THEN
ROLLBACK to Populate_CBC_Line_Info_Pvt;
x_ReturnStatus := FND_API.G_RET_STS_UNEXP_ERROR;
g_validation_error := TRUE;
IF (FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
RETURN;
END Populate_CBC_Line_Info;
/**************************************************************************************/
-- --------------------------------------------------------------------------
-- This update procedure is designed to ensure that the update is ONLY done
-- to the summary template records that are stored in the IGC_CBC_JE_LINES
-- table. If there are new fields to be updated where the amount is not to
-- be summed up then the values input should be 0 for amount_cr and amount_dr
-- --------------------------------------------------------------------------
PROCEDURE Update_CBC_JE_Line (
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE,
p_entered_cr IN igc_cbc_je_lines.entered_cr%TYPE,
p_entered_dr IN igc_cbc_je_lines.entered_dr%TYPE,
p_je_line_num IN igc_cbc_je_lines.cbc_je_line_num%TYPE,
p_det_sum_val IN igc_cbc_je_lines.detail_summary_code%TYPE,
p_update_type IN VARCHAR2,
x_return_status OUT NOCOPY VARCHAR2
) IS
l_api_name CONSTANT VARCHAR2(30) := 'Update_CBC_JE_Line';
l_full_path VARCHAR2(255);
BEGIN
-- -------------------------------------------------------------------------
-- Initialize variables to be returned or used within the procedure.
-- -------------------------------------------------------------------------
l_full_path := g_path || 'Update_CBC_JE_Line';
x_return_status := FND_API.G_RET_STS_SUCCESS;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Updating JE Lines for CCID : ' || to_char(p_ccid) ||
' Update Type : ' || p_update_type;
Put_Debug_Msg (l_full_path, g_debug );
END IF;
-- -------------------------------------------------------------------------
-- Updating the IGC_CBC_JE_LINES table by batch id from temp status to perm
-- status.
-- -------------------------------------------------------------------------
IF (p_update_type = 'B') THEN
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Updating JE LINES from Temp to Perm for Batch ID : ' || to_char(g_batch_id);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
UPDATE igc_cbc_je_lines
SET status = 'P',
posted_date = SYSDATE,
last_update_date = SYSDATE,
last_updated_by = g_update_by,
last_update_login = g_update_login,
budget_version_id = DECODE(g_actual_flag,'B',budget_version_id,null)
WHERE cbc_je_batch_id = g_batch_id
AND detail_summary_code = 'D'
AND status = 'T';
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Deleting all Summary Records in JE LINES for Batch ID : ' || to_char(g_batch_id);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
DELETE
FROM igc_cbc_je_lines
WHERE cbc_je_batch_id = g_batch_id
AND detail_summary_code = 'S';
-- --------------------------------------------------------------------------
-- Delete all transactions from the CBC for the batch ID.
-- --------------------------------------------------------------------------
ELSIF (p_update_type = 'D') THEN
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Deleting ALL JE LINES for Batch ID : ' || to_char(g_batch_id);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
DELETE
FROM igc_cbc_je_lines
WHERE cbc_je_batch_id = g_batch_id;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Deleting ALL JE BATCHES for Batch ID : ' || to_char(g_batch_id);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
DELETE
FROM igc_cbc_je_batches
WHERE cbc_je_batch_id = g_batch_id;
ELSIF ((p_update_type = 'R') AND (p_det_sum_val = 'S')) THEN
-- -------------------------------------------------------------------------
-- Update the record that is stored in the IGC_CBC_JE_LINES table. Make
-- sure that only the summary record is updated and at a temporary status.
-- -------------------------------------------------------------------------
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Updating JE LINES for Summary Record ID : ' || to_char(p_ccid) ||
' Set of Books ID : ' || to_char(g_set_of_books_id) ||
' Batch ID : ' || to_char(g_batch_id);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
UPDATE igc_cbc_je_lines
SET cbc_je_line_num = p_je_line_num,
last_update_date = SYSDATE,
last_updated_by = g_update_by,
last_update_login = g_update_login,
entered_cr = NVL(p_entered_cr, 0) + NVL(entered_cr, 0),
entered_dr = NVL(p_entered_dr, 0) + NVL(entered_dr, 0)
WHERE cbc_je_batch_id = g_batch_id
AND code_combination_id = p_ccid
AND set_of_books_id = g_set_of_books_id
AND detail_summary_code = p_det_sum_val
AND status = 'T';
ELSIF ((p_update_type = 'R') AND (p_det_sum_val = 'D')) THEN
-- -------------------------------------------------------------------------
-- Update the record that is stored in the IGC_CBC_JE_LINES table. Make
-- sure that only the detail record is updated and at a temporary status.
-- -------------------------------------------------------------------------
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' Updating JE LINES for Summary Record ID : ' || to_char(p_ccid) ||
' Set of Books ID : ' || to_char(g_set_of_books_id) ||
' Batch ID : ' || to_char(g_batch_id);
Put_Debug_Msg (l_full_path, g_debug );
END IF;
UPDATE igc_cbc_je_lines
SET posted_date = SYSDATE,
last_update_date = SYSDATE,
last_updated_by = g_update_by,
last_update_login = g_update_login
WHERE cbc_je_batch_id = g_batch_id
AND code_combination_id = p_ccid
AND set_of_books_id = g_set_of_books_id
AND detail_summary_code = p_det_sum_val
AND status = 'T';
ELSE
x_return_status := FND_API.G_RET_STS_ERROR;
message_token ('VALUE', p_update_type);
add_message ('IGC', 'IGC_INVALID_UPDATE_PARAMETER');
END IF;
RETURN;
-- -------------------------------------------------------------------------
-- Exception handler section for the update_cbc_je_lines procedure.
-- -------------------------------------------------------------------------
EXCEPTION
WHEN NO_DATA_FOUND THEN
x_return_status := FND_API.G_RET_STS_ERROR;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'NO_DATA_FOUND Exception Raised');
END IF;
RETURN;
WHEN OTHERS THEN
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF (FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
RETURN;
END Update_CBC_JE_Line;
/**************************************************************************************/
/* Procedure for batch creation */
PROCEDURE Create_JE_Batch(
x_return_status OUT NOCOPY VARCHAR2
) IS
l_set_of_books_id NUMBER(15);
l_total_cr igc_cbc_je_batches.running_total_cr%TYPE;
l_total_dr igc_cbc_je_batches.running_total_dr%TYPE;
l_effective_date DATE;
l_version_id NUMBER;
l_api_name CONSTANT VARCHAR2(30) := 'Create_JE_Batch';
l_msg_count NUMBER;
l_msg_data VARCHAR(2000);
l_return_status VARCHAR(1);
l_rowid VARCHAR2(255);
l_period_name gl_period_statuses.period_name%TYPE;
CURSOR c_period_info IS
SELECT period_name
FROM gl_period_statuses per
WHERE per.application_id = g_gl_application_id
AND per.adjustment_period_flag = 'N'
AND per.set_of_books_id = g_set_of_books_id
AND l_effective_date
BETWEEN per.start_date
AND per.end_date;

l_full_path VARCHAR2(255);
BEGIN
SAVEPOINT Create_JE_Batch;
l_full_path := g_path || 'Create_JE_Batch';
x_return_status := FND_API.G_RET_STS_SUCCESS;
g_batch_id := NULL;
-- ssmales 28/01/02 bug 2201905 - added new block to process by p_packet_id
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
SELECT MIN(CC_VERSION_NUM ),
MIN(cc_transaction_date),
SUM(cc_func_cr_amt),
SUM(cc_func_dr_amt),
MIN(set_of_books_id)
INTO l_version_id,
l_effective_date,
l_total_cr,
l_total_dr,
l_set_of_books_id
FROM igc_cc_interface_v
WHERE reference_6 = g_p_packet_id
AND actual_flag = g_actual_flag
AND budget_dest_flag = 'C';
ELSE
-- bug 2201905 end block
SELECT MIN(CC_VERSION_NUM ),
MIN(cc_transaction_date),
SUM(cc_func_cr_amt),
SUM(cc_func_dr_amt),
MIN(set_of_books_id)
INTO l_version_id,
l_effective_date,
l_total_cr,
l_total_dr,
l_set_of_books_id
FROM igc_cc_interface_v
WHERE cc_header_id = g_cc_header_id
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
AND budget_dest_flag = 'C';
-- ssmales 28/01/02 bug 2201905 - added end if statement below
END IF ;
OPEN c_period_info;
FETCH c_period_info INTO l_period_name;
CLOSE c_period_info;
IGC_CBC_HANDLERS_PKG.Insert_Je_Batch_Row(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_row_id => l_rowid,
p_cbc_je_batch_id => g_batch_id,
p_set_of_books_id => l_set_of_books_id,
p_cc_header_id => g_cc_header_id,
p_name => Get_Batch_Name(l_period_name),
p_batch_status => 'P',
p_actual_flag => g_actual_flag,
p_budgetary_control_status => 'P',
p_approval_status_code => 'A',
p_description => '',
p_effective_date => l_effective_date,
p_running_total_dr => l_total_dr,
p_running_total_cr => l_total_cr,
p_context => '',
p_last_update_date => sysdate,
p_last_updated_by => g_update_by,
p_last_update_login => g_update_login,
p_creation_date => sysdate,
p_created_by => g_update_by,
p_attribute1 =>'',
p_attribute2 =>'',
p_attribute3 =>'',
p_attribute4 =>'',
p_attribute5 =>'',
p_attribute6 =>'',
p_attribute7 =>'',
p_attribute8 =>'',
p_attribute9 =>'',
p_attribute10 =>'',
p_attribute11 =>'',
p_attribute12 =>'',
p_attribute13 =>'',
p_attribute14 =>'',
p_attribute15 =>''
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
RAISE FND_API.G_EXC_ERROR ;
END IF;
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
ROLLBACK to Create_JE_Batch;
x_return_status := FND_API.G_RET_STS_ERROR;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_ERROR Exception Raised');
END IF;
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
ROLLBACK to Create_JE_Batch;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_UNEXPECTED_ERROR
Exception Raised');
END IF;
WHEN OTHERS THEN
ROLLBACK to Create_JE_Batch;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Create_JE_Batch;
PROCEDURE Update_Status_Code(
p_status_code IN VARCHAR2,
x_return_status OUT NOCOPY VARCHAR2
) IS
l_api_name CONSTANT VARCHAR2(30) := 'Update_Status_Code';
l_full_path VARCHAR2(255);
BEGIN
SAVEPOINT Update_Status_Code;
l_full_path := g_path || 'Update_Status_Code';
x_return_status := FND_API.G_RET_STS_SUCCESS;
UPDATE igc_cc_interface_v
SET status_code = p_status_code,
last_update_date = sysdate,
last_updated_by = g_update_by,
cc_encmbrnc_date = sysdate
WHERE cc_header_id = g_cc_header_id
AND actual_flag = g_actual_flag
AND document_type = g_doc_type;
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
ROLLBACK to Update_Status_Code;
x_return_status := FND_API.G_RET_STS_ERROR;
IF ( g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level,l_full_path,'FND_API.G_EXC_ERROR Exception Raised');
END IF;
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
ROLLBACK to Update_Status_Code;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF ( g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level,l_full_path,'FND_API.G_EXC_UNEXPECTED_ERROR Exception
Raised');
END IF;
WHEN OTHERS THEN
ROLLBACK to Update_Status_Code;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Update_Status_Code;
/*
Update results for CC interface table based on CCID, period number, amount_type.
p_result_code:
F00 {Insufficient funds (detail) }
F01 Insufficient funds (->summary)
P00 {Funds not reduced *'******'*}
P01 {Funds check not required *'*}
P10 {Passed funds check *'******'}
P20 {Advisory warning *'******'* }
P22 {Advisory warning (->summary)}
Require Set_Result_Code first.
*/
PROCEDURE Update_Result_Status(
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE,
p_batch_line_num IN igc_cc_interface.batch_line_num%TYPE,
p_result_code IN VARCHAR2,
p_status_code IN VARCHAR2,
p_summary_detail IN VARCHAR2 ,
p_budget_version_id IN gl_budget_versions.budget_version_id%TYPE,
p_period_name IN igc_cbc_je_lines.period_name%TYPE,
p_quarter_num IN igc_cbc_je_lines.quarter_num%TYPE,
p_period_num IN igc_cbc_je_lines.period_num%TYPE,
p_period_year IN igc_cbc_je_lines.period_year%TYPE,
p_amount_type IN VARCHAR2,
p_budget_dest IN VARCHAR2,
p_budget_amt IN NUMBER,
p_com_enc_amt IN NUMBER,
p_obl_enc_amt IN NUMBER,
p_fa_amt IN NUMBER,
x_return_status OUT NOCOPY VARCHAR2
) IS
l_return_status VARCHAR2(1);
l_api_name CONSTANT VARCHAR2(30) := 'Update_Result_Status';
l_full_path VARCHAR2(255);
BEGIN
SAVEPOINT Update_Result_Status;
l_full_path := g_path || 'Update_Result_Status';
x_return_status := FND_API.G_RET_STS_SUCCESS;
Set_Batch_Result_Code(p_result_code);
IF (p_summary_detail = 'D') THEN
-- ssmales 28/01/02 bug 2201905 - added if block below
-- bug 2201905 start
IF (g_p_packet_id is not null) THEN
UPDATE igc_cc_interface_v
SET cbc_result_code = p_result_code,
status_code = Get_Status_By_Result(p_result_code),
period_name = p_period_name,
budget_version_id = p_budget_version_id,
budget_amt = p_budget_amt-DECODE(g_actual_flag,'B',(NVL(CC_FUNC_DR_AMT,0)-
NVL(CC_FUNC_CR_AMT,0)),0) ,
commitment_encmbrnc_amt = p_com_enc_amt,
obligation_encmbrnc_amt = p_obl_enc_amt,
funds_available_amt = p_fa_amt-DECODE(g_actual_flag,'B',(NVL(CC_FUNC_DR_AMT,0)-
NVL(CC_FUNC_CR_AMT,0)),0),
last_update_date = sysdate,
last_updated_by = g_update_by,
reference_10 = p_amount_type,
cc_encmbrnc_date = sysdate,
result_code_source = 'C'
WHERE batch_line_num = p_batch_line_num
AND reference_6 = g_p_packet_id
AND actual_flag = g_actual_flag
AND cbc_result_code IS NULL;
ELSE
-- bug 2201905 end block
UPDATE igc_cc_interface_v
SET cbc_result_code = p_result_code,
status_code = Get_Status_By_Result(p_result_code),
period_name = p_period_name,
budget_version_id = p_budget_version_id,
budget_amt = p_budget_amt-DECODE(g_actual_flag,'B',(NVL(CC_FUNC_DR_AMT,0)-
NVL(CC_FUNC_CR_AMT,0)),0) ,
commitment_encmbrnc_amt = p_com_enc_amt,
obligation_encmbrnc_amt = p_obl_enc_amt,
funds_available_amt = p_fa_amt-DECODE(g_actual_flag,'B',(NVL(CC_FUNC_DR_AMT,0)-
NVL(CC_FUNC_CR_AMT,0)),0),
last_update_date = sysdate,
last_updated_by = g_update_by,
reference_10 = p_amount_type,
cc_encmbrnc_date = sysdate,
result_code_source = 'C'
WHERE batch_line_num = p_batch_line_num
AND cc_header_id = g_cc_header_id
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
AND cbc_result_code IS NULL;
-- ssmales 28/01/02 bug 2201905 - added end if statement below
END IF ;
ELSIF (p_summary_detail = 'S') THEN
-- ssmales 28/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
UPDATE igc_cc_interface_v
SET cbc_result_code = Get_Total_Result(cbc_result_code,p_result_code),
status_code = Get_Status_By_Result(Get_Total_Result(cbc_result_code,p_result_code)),
last_update_date = sysdate,
last_updated_by = g_update_by,
result_code_source = 'C'
WHERE code_combination_id IN
( SELECT detail_code_combination_id
FROM gl_account_hierarchies
WHERE summary_code_combination_id = p_ccid
AND set_of_books_id = g_set_of_books_id
)
AND reference_6 = g_p_packet_id
AND actual_flag = g_actual_flag
/* Selecting only higher rank*/
AND Get_Rank(p_result_code) < Get_Rank(cbc_result_code)
AND budget_dest_flag =decode(p_budget_dest,'CBC','C','S')
AND period_name IN
( SELECT period_name
FROM gl_period_statuses
WHERE application_id = g_gl_application_id
AND set_of_books_id = g_set_of_books_id
AND adjustment_period_flag = 'N'
AND DECODE(p_amount_type,'YTD',period_year,
'QTD',quarter_num,
'PTD',period_num,
period_year) =
DECODE(p_amount_type,'YTD',p_period_year,
'QTD',p_quarter_num,
'PTD',p_period_num,
period_year)
);
ELSE
-- bug 2201905 end block
UPDATE igc_cc_interface_v
SET cbc_result_code = Get_Total_Result(cbc_result_code,p_result_code),
status_code = Get_Status_By_Result(Get_Total_Result(cbc_result_code,p_result_code)),
last_update_date = sysdate,
last_updated_by = g_update_by,
result_code_source = 'C'
WHERE code_combination_id IN
( SELECT detail_code_combination_id
FROM gl_account_hierarchies
WHERE summary_code_combination_id = p_ccid
AND set_of_books_id = g_set_of_books_id
)
AND cc_header_id = g_cc_header_id
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
/* Selecting only higher rank*/
AND Get_Rank(p_result_code) < Get_Rank(cbc_result_code)
AND budget_dest_flag =decode(p_budget_dest,'CBC','C','S')
AND period_name IN
( SELECT period_name
FROM gl_period_statuses
WHERE application_id = g_gl_application_id
AND set_of_books_id = g_set_of_books_id
AND adjustment_period_flag = 'N'
AND DECODE(p_amount_type,'YTD',period_year,
'QTD',quarter_num,
'PTD',period_num,
period_year) =
DECODE(p_amount_type,'YTD',p_period_year,
'QTD',p_quarter_num,
'PTD',p_period_num,
period_year)
);
-- ssmales 28/01/02 bug 2201905 - added end if below
END IF ;
ELSE
message_token ('VALUE', p_summary_detail);
add_message ('IGC', 'IGC_INVALID_SUM_DETAIL_CODE');
raise FND_API.G_EXC_ERROR;
END IF;
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
ROLLBACK to Update_Result_Status;
x_return_status := FND_API.G_RET_STS_ERROR;
IF ( g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level,l_full_path,'FND_API.G_EXC_ERROR Exception Raised');
END IF;
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
ROLLBACK to Update_Result_Status;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF ( g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level,l_full_path,'FND_API.G_EXC_UNEXPECTED_ERROR Exception
Raised');
END IF;
WHEN OTHERS THEN
ROLLBACK to Update_Result_Status;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Update_Result_Status;
/*
DESCRIPTION:
Lock all accounts in CBC_JE_LINES that participate in the set of transactions
provided by the Contract Commitment(CC) module or the Public Sector
Budget(PSB) module.
The set of transactions will be inserted into IGC_CC_BC_INTERFACE by either
CC or PSB modules, and then the CBC API will be called with a number of
parameters. The CBC module, which includes this function, will first lock
down all of the accounts that are related to the incoming set of
transactions to insure that the accounts don't change while we are
calculating the funds available or reserving funds.
INPUTS:
SECONDS seconds to wait before trying again to obtain a lock,
in the case of a failure
DMODE debug mode, set to TRUE to generate debug statements
REQUIREMENTS:
DBMS_LOCK package must be installed in order to
access the dbms_lock.sleep(seconds) procedure
NOTES:
*/
FUNCTION Lock_JE_Lines
RETURN BOOLEAN IS
l_counter NUMBER(1) := 0;
l_ccid NUMBER(15);
l_sobid NUMBER(15);
l_api_name CONSTANT VARCHAR2(30) := 'Lock_JE_Lines';
/* Explode the CCIDs and lock them. */
-- Bug 2885953 - amended cursor below for performance enhancements
-- also removed reference to rowid, which is incorrect
-- CURSOR c_lock_cbc_je_lines IS
-- SELECT code_combination_id,
-- set_of_books_id
-- FROM igc_cbc_je_lines
-- WHERE ROWID IN
-- ( SELECT MIN(ROWID)
-- FROM igc_cbc_je_lines
-- WHERE code_combination_id IN
-- ( SELECT detail_code_combination_id
-- FROM gl_account_hierarchies AHI
-- WHERE AHI.summary_code_combination_id IN
-- ( SELECT AH.summary_code_combination_id
-- FROM gl_account_hierarchies AH, /* GL_ACCOUNT_HIERARCHIES */
-- igc_cc_interface_v TV
-- WHERE TV.code_combination_id = detail_code_combination_id
-- AND AH.set_of_books_id = g_set_of_books_id
-- AND TV.cc_header_id = g_cc_header_id
-- AND TV.actual_flag = g_actual_flag
-- AND TV.document_type = g_doc_type
-- )
-- /* detailed accounts - if they are not summary */
-- UNION SELECT TV2.code_combination_id
-- FROM igc_cc_interface_v TV2
-- WHERE TV2.cc_header_id = g_cc_header_id
-- AND TV2.actual_flag = g_actual_flag
-- AND TV2.document_type = g_doc_type
-- )
-- AND set_of_books_id = g_set_of_books_id
-- AND actual_flag = 'B'
-- GROUP BY code_combination_id
-- )
-- FOR UPDATE NOWAIT; /* Acquire lock, or raise error ORA-00054 */
CURSOR c_lock_cbc_je_lines IS
SELECT code_combination_id,
set_of_books_id
FROM igc_cbc_je_lines
WHERE code_combination_id IN
( SELECT AHI.detail_code_combination_id
FROM gl_account_hierarchies AHI,
gl_account_hierarchies AH, /* GL_ACCOUNT_HIERARCHIES */
igc_cc_interface_v TV
WHERE AHI.summary_code_combination_id = AH.summary_code_combination_id
AND TV.code_combination_id = AH.detail_code_combination_id
AND AH.set_of_books_id = g_set_of_books_id
AND TV.cc_header_id = g_cc_header_id
AND TV.actual_flag = g_actual_flag
AND TV.document_type = g_doc_type
/* detailed accounts - if they are not summary */
UNION
SELECT TV2.code_combination_id
FROM igc_cc_interface_v TV2
WHERE TV2.cc_header_id = g_cc_header_id
AND TV2.actual_flag = g_actual_flag
AND TV2.document_type = g_doc_type
)
AND set_of_books_id = g_set_of_books_id
AND actual_flag = 'B'
FOR UPDATE NOWAIT; /* Acquire lock, or raise error ORA-00054 */
-- ssmales 28/01/02 bug 2201905 - added new cursor below to process by p_packet_id
-- Bug 2885953 - amended cursor below for performance enhancements
-- also removed reference to rowid, which is incorrect
-- CURSOR c_lock_cbc_je_lines_pckt IS
-- SELECT code_combination_id,
-- set_of_books_id
-- FROM igc_cbc_je_lines
-- WHERE ROWID IN
-- ( SELECT MIN(ROWID)
-- FROM igc_cbc_je_lines
-- WHERE code_combination_id IN
-- ( SELECT detail_code_combination_id
-- FROM gl_account_hierarchies AHI
-- WHERE AHI.summary_code_combination_id IN
-- ( SELECT AH.summary_code_combination_id
-- FROM gl_account_hierarchies AH, /* GL_ACCOUNT_HIERARCHIES */
-- igc_cc_interface_v TV
-- WHERE TV.code_combination_id = detail_code_combination_id
-- AND AH.set_of_books_id = g_set_of_books_id
-- AND TV.reference_6 = g_p_packet_id
-- AND TV.actual_flag = g_actual_flag
-- )
-- /* detailed accounts - if they are not summary */
-- UNION SELECT TV2.code_combination_id
-- FROM igc_cc_interface_v TV2
-- WHERE TV2.reference_6 = g_p_packet_id
-- AND TV2.actual_flag = g_actual_flag
-- )
-- AND set_of_books_id = g_set_of_books_id
-- AND actual_flag = 'B'
-- GROUP BY code_combination_id
-- )
-- FOR UPDATE NOWAIT; /* Acquire lock, or raise error ORA-00054 */
CURSOR c_lock_cbc_je_lines_pckt IS
SELECT code_combination_id,
set_of_books_id
FROM igc_cbc_je_lines
WHERE code_combination_id IN
( SELECT AHI.detail_code_combination_id
FROM gl_account_hierarchies AHI,
gl_account_hierarchies AH, /* GL_ACCOUNT_HIERARCHIES */
igc_cc_interface_v TV
WHERE AHI.summary_code_combination_id = AH.summary_code_combination_id
AND TV.code_combination_id = AH.detail_code_combination_id
AND AH.set_of_books_id = g_set_of_books_id
AND TV.reference_6 = g_p_packet_id
AND TV.actual_flag = g_actual_flag
/* detailed accounts - if they are not summary */
UNION
SELECT TV2.code_combination_id
FROM igc_cc_interface_v TV2
WHERE TV2.reference_6 = g_p_packet_id
AND TV2.actual_flag = g_actual_flag
)
AND set_of_books_id = g_set_of_books_id
AND actual_flag = 'B'
FOR UPDATE NOWAIT; /* Acquire lock, or raise error ORA-00054 */

l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Lock_JE_Lines';
WHILE l_counter < g_maxloops LOOP -- Loop in case we need to retry lock
BEGIN -- loop block
-- ssmales 28/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
OPEN c_lock_cbc_je_lines_pckt;
FETCH c_lock_cbc_je_lines_pckt
INTO l_ccid,
l_sobid;
IF (c_lock_cbc_je_lines_pckt%NOTFOUND) THEN
CLOSE c_lock_cbc_je_lines_pckt;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'No records found to lock');
END IF;
RETURN TRUE;
ELSE -- lock, with records, has been obtained
CLOSE c_lock_cbc_je_lines_pckt;
RETURN TRUE;
END IF;
ELSE
-- bug 2201905 end block
OPEN c_lock_cbc_je_lines;
FETCH c_lock_cbc_je_lines
INTO l_ccid,
l_sobid;
IF (c_lock_cbc_je_lines%NOTFOUND) THEN
CLOSE c_lock_cbc_je_lines;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'No records found to lock');
END IF;
RETURN TRUE;
ELSE -- lock, with records, has been obtained
CLOSE c_lock_cbc_je_lines;
RETURN TRUE;
END IF;
-- ssmales 28/01/02 bug 2201905 - added end if statement below
END IF ;
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
IF (c_lock_cbc_je_lines%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines;
END IF;
-- ssmales 28/01/02 bug 2201905 - added 3 line if block below
IF (c_lock_cbc_je_lines_pckt%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines_pckt;
END IF;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_ERROR Exception
Raised');
END IF;
RETURN FALSE;
WHEN OTHERS THEN
IF (SQLCODE = -54) THEN -- Record(s) are already locked
l_counter := l_counter + 1;
IF (l_counter >= g_maxloops) THEN -- Tried max number of times
message_token ('VALUE', to_char(g_maxloops));
add_message('IGC', 'IGC_UNABLE_TO_LOCK');
IF (c_lock_cbc_je_lines%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines;
END IF;
-- ssmales 28/01/02 bug 2201905 - added 3 line if block below
IF (c_lock_cbc_je_lines_pckt%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines_pckt;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Maximum tries reached: unable to lock');
END IF;
RETURN FALSE;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Wait for Lock to be released. Number tries : ' || l_counter );
END IF;
DBMS_LOCK.SLEEP(g_seconds); -- Wait, then try again
ELSE
IF (c_lock_cbc_je_lines%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines;
END IF;
-- ssmales 28/01/02 bug 2201905 - added 3 line if block below
IF (c_lock_cbc_je_lines_pckt%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines_pckt;
END IF;
IF (FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
END IF;
END; -- inner block
END LOOP; -- WHILE loop
EXCEPTION
WHEN OTHERS THEN
IF (c_lock_cbc_je_lines%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines;
END IF;
-- ssmales 28/01/02 bug 2201905 - added 3 line if block below
IF (c_lock_cbc_je_lines_pckt%ISOPEN) THEN
CLOSE c_lock_cbc_je_lines_pckt;
END IF;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
RETURN FALSE;
END Lock_JE_Lines;
/*--------------------------------------------------------------------------
NAME: Get_Detail_Bal
DESCRIPTION:
Calculate the balance of a detail account, or an individual account that
participates in a summary account. The balance will be later to used to
check funds requests against funds available.
INPUTS:
p_dccid The code combination ID of the detail account
p_amount_t Amount type; 'QTD', 'PTD', or 'YTD'
p_budget_ver Budget version
p_period_yr Period year
p_period_nm Period number
p_quarter_nm Quarter number
OUTPUTS:
p_fa Amount of funds available
RETURNS:
TRUE Function succeeded.
FALSE An error was encounter.
REQUIREMENTS:
NOTES:
---------------------------------------------------------------------------*/
PROCEDURE Get_Detail_Bal (
p_dccid IN igc_cbc_je_lines.code_combination_id%TYPE, -- Detail CCID
p_amount_t IN igc_cbc_je_lines.amount_type%TYPE, -- QTD, PTD, or YTD
p_budget_ver IN igc_cbc_je_lines.budget_version_id%TYPE, -- Budget ID
p_period_yr IN igc_cbc_je_lines.period_year%TYPE, -- Period year, ie 2000
p_period_nm IN igc_cbc_je_lines.period_num%TYPE, -- Period number
p_quarter_nm IN igc_cbc_je_lines.quarter_num%TYPE, -- Quarter number (1-4)
p_funds_level IN VARCHAR2,
x_fa OUT NOCOPY NUMBER,
x_com_bal OUT NOCOPY NUMBER,
x_act_bal OUT NOCOPY NUMBER,
x_oth_bal OUT NOCOPY NUMBER,
x_bud_bal OUT NOCOPY NUMBER,
x_return_status OUT NOCOPY VARCHAR2
) IS
-- Local variables
l_budget_bal NUMBER :=0;
l_commit_bal NUMBER :=0;
l_actual_bal NUMBER :=0;
l_other_bal NUMBER :=0;
l_funds_avail NUMBER :=0;
l_api_name CONSTANT VARCHAR2(30) := 'Get_Detail_Bal';
l_full_path VARCHAR2(255);
BEGIN
x_return_status := FND_API.G_RET_STS_SUCCESS;
l_full_path := g_path || 'Get_Detail_Bal';
IF g_mode = 'F' THEN
-- mode if force - return without calculation
x_fa := 0;
x_com_bal := 0;
x_act_bal := 0;
x_bud_bal := 0;
x_oth_bal := 0;
RETURN ;
END IF;
IF p_funds_level = 'N' THEN
--Don't need to calculate FA.
x_fa := 0;
x_com_bal := 0;
x_act_bal := 0;
x_bud_bal := 0;
x_oth_bal := 0;
RETURN ;
END IF;
IF p_amount_t IS NOT NULL THEN
SELECT SUM(decode(JE.actual_flag,'B',(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_com_enc_id,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_obl_enc_id,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0),0)),
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_obl_enc_id,0,g_com_enc_id,0,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0))),0))
INTO l_budget_bal,
l_commit_bal,
l_actual_bal,
l_other_bal
FROM igc_cbc_je_lines JE
WHERE JE.code_combination_id = p_dccid
AND JE.period_year = p_period_yr
AND ( p_budget_ver IS NULL
OR (JE.budget_version_id IS NULL AND actual_flag='E')
OR (JE.budget_version_id = p_budget_ver))
AND JE.set_of_books_id = g_set_of_books_id
AND decode(p_amount_t,
'QTD', JE.quarter_num,
'PTD', JE.period_num,
'YTD', JE.period_year,
NULL) =
decode(p_amount_t,
'QTD', p_quarter_nm,
'PTD', p_period_nm,
'YTD', p_period_yr,
p_quarter_nm);
ELSIF g_actual_flag='B' THEN
--If no amount type and budget transactions - get balance for this period only
SELECT SUM(decode(JE.actual_flag,'B',(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_com_enc_id,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_obl_enc_id,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_obl_enc_id,0,g_com_enc_id,0,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0))),0))
INTO l_budget_bal,
l_commit_bal,
l_actual_bal,
l_other_bal
FROM igc_cbc_je_lines JE
WHERE JE.code_combination_id = p_dccid
AND JE.period_year = p_period_yr
AND ((JE.budget_version_id IS NULL AND actual_flag='E')
OR (JE.budget_version_id = p_budget_ver))
AND JE.set_of_books_id = g_set_of_books_id
AND JE.period_year = p_period_yr;
END IF;
-- Calculate funds available for this detail account. The formula is:
-- Budget - (Provisional Contract commmitment + Actual Contract commitment)
-- The 'Budget' source is the PSB module , and the contract source is the
-- CC module. Note that the provisional and actual contract commitments are
-- both encumbrances, so another way to view funds available is:
-- FA = (budget - encumbrances).
l_funds_avail := nvl(l_budget_bal,0) - (nvl(l_commit_bal,0) + nvl(l_actual_bal,0) +nvl(l_other_bal,0));
-- Assign the funds available to the output parameter
x_fa := l_funds_avail;
x_com_bal:= nvl(l_commit_bal,0);
x_act_bal:= nvl(l_actual_bal,0);
x_bud_bal:= nvl(l_budget_bal,0);
x_oth_bal:= nvl(l_other_bal,0);
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
x_return_status := FND_API.G_RET_STS_ERROR;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_ERROR Exception Raised');
END IF;
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_UNEXPECTED_ERROR
Exception Raised');
END IF;
WHEN OTHERS THEN
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Get_Detail_Bal;
PROCEDURE Get_Summary_Bal (
p_ccid IN igc_cbc_je_lines.code_combination_id%TYPE, -- Detail CCID
p_amount_t IN igc_cbc_je_lines.amount_type%TYPE, -- QTD, PTD, or YTD
p_budget_ver IN igc_cbc_je_lines.budget_version_id%TYPE, -- Budget ID
p_period_yr IN igc_cbc_je_lines.period_year%TYPE, -- Period year, ie 2000
p_period_nm IN igc_cbc_je_lines.period_num%TYPE, -- Period number
p_quarter_nm IN igc_cbc_je_lines.quarter_num%TYPE, -- Quarter number (1-4)
p_funds_level IN VARCHAR2,
x_fa OUT NOCOPY NUMBER,
x_com_bal OUT NOCOPY NUMBER,
x_act_bal OUT NOCOPY NUMBER,
x_oth_bal OUT NOCOPY NUMBER,
x_bud_bal OUT NOCOPY NUMBER,
x_return_status OUT NOCOPY VARCHAR2
) IS
CURSOR c_teml_date IS
SELECT GPS.start_date
FROM gl_account_hierarchies GAH,
gl_summary_templates GST,
gl_period_statuses GPS
WHERE GST.template_id = GAH.template_id
AND GPS.application_id = g_gl_application_id
AND GPS.set_of_books_id = g_set_of_books_id
AND GPS.period_name = GST.start_actuals_period_name
AND GPS.application_id = g_gl_application_id
AND GPS.adjustment_period_flag = 'N'
AND GAH.summary_code_combination_id = p_ccid;
-- Local variables
l_cutoff_date DATE;
l_budget_bal NUMBER :=0;
l_commit_bal NUMBER :=0;
l_actual_bal NUMBER :=0;
l_funds_avail NUMBER :=0;
l_other_bal NUMBER :=0;
l_api_name CONSTANT VARCHAR2(30) := 'Get_Summary_Bal';
l_full_path VARCHAR2(255);
BEGIN
x_return_status := FND_API.G_RET_STS_SUCCESS;
l_full_path := g_path || 'Get_Summary_Bal';
-- Total the debit balance of the budget from PSB
IF p_funds_level = 'N' THEN
--Don't need to calculate FA.
x_fa := 0;
x_com_bal := 0;
x_act_bal := 0;
x_bud_bal := 0;
x_oth_bal := 0;
RETURN ;
END IF;
IF p_amount_t IS NOT NULL THEN
OPEN c_teml_date;
FETCH c_teml_date INTO l_cutoff_date;
CLOSE c_teml_date;
SELECT SUM(decode(JE.actual_flag,'B',(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_com_enc_id,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_obl_enc_id,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0)),0),0)) ,
SUM(decode(JE.actual_flag,'E',decode(JE.ENCUMBRANCE_TYPE_ID,g_obl_enc_id,0,g_com_enc_id,0,
(NVL(JE.ENTERED_DR,0)-NVL(JE.ENTERED_CR,0))),0))
INTO l_budget_bal,
l_commit_bal,
l_actual_bal,
l_other_bal
FROM igc_cbc_je_lines JE
WHERE JE.code_combination_id IN
( SELECT ACH.detail_code_combination_id
FROM gl_account_hierarchies ACH
WHERE ACH.summary_code_combination_id = p_ccid
AND ACH.set_of_books_id = g_set_of_books_id
)
AND JE.period_year = p_period_yr
AND l_cutoff_date <= effective_date
AND ( p_budget_ver IS NULL
OR (JE.budget_version_id IS NULL AND actual_flag='E')
OR (JE.budget_version_id = p_budget_ver)
)
AND JE.set_of_books_id = g_set_of_books_id
AND decode(p_amount_t,
'QTD', JE.quarter_num,
'PTD', JE.period_num,
'YTD', JE.period_year,
NULL) =
decode(p_amount_t,
'QTD', p_quarter_nm,
'PTD', p_period_nm,
'YTD', p_period_yr,
p_quarter_nm);
END IF;
-- Calculate funds available for this detail account. The formula is:
-- Budget - (Provisional Contract commmitment + Actual Contract commitment)
-- The 'Budget' source is the PSB module , and the contract source is the
-- CC module. Note that the provisional and actual contract commitments are
-- both encumbrances, so another way to view funds available is:
-- FA = (budget - encumbrances).
l_funds_avail := nvl(l_budget_bal,0) - (nvl(l_commit_bal,0) + nvl(l_actual_bal,0) +nvl(l_other_bal,0));
-- Assign the funds available to the output parameter
x_fa := l_funds_avail;
x_com_bal:= nvl(l_commit_bal,0);
x_act_bal:= nvl(l_actual_bal,0);
x_bud_bal:= nvl(l_budget_bal,0);
x_oth_bal:= nvl(l_other_bal,0);
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
x_return_status := FND_API.G_RET_STS_ERROR;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_ERROR Exception Raised');
END IF;
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_excep_level, l_full_path,'FND_API.G_EXC_UNEXPECTED_ERROR
Exception Raised');
END IF;
WHEN OTHERS THEN
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Get_Summary_Bal;
PROCEDURE Get_Result_Code (
p_funds_available IN NUMBER,
p_funds_level IN VARCHAR2,
p_amount IN NUMBER,
p_summary_detail_code IN VARCHAR2,
p_ccid IN NUMBER,
x_result_code OUT NOCOPY VARCHAR2,
x_status_code OUT NOCOPY VARCHAR2
) IS
l_api_name CONSTANT VARCHAR2(30) := 'Get_Result_Code';
l_result_code VARCHAR2(3);
l_full_path VARCHAR2(255);
--D - Advisore
--B - Absolute
--N - None
BEGIN
l_result_code:=NULL; --Initialization
x_result_code:=NULL;
x_status_code:=NULL;
l_full_path := g_path || 'Get_Result_Code';
--Checking gontrol group
IF g_mode = 'F' THEN
-- mode force - return without calculation
x_result_code :='P05';
x_status_code :=Get_Status_By_Result(l_result_code);
RETURN ;
END IF;
IF p_funds_level = 'N' THEN
l_result_code:='P01'; --FC not required
ELSIF ((g_actual_flag ='E' AND p_amount <=0 AND p_summary_detail_code = 'D') OR --Transaction doesn't
reduce funds available
(g_actual_flag ='B' AND p_amount >=0 AND p_summary_detail_code = 'D')) THEN
l_result_code:='P00';
ELSIF (p_summary_detail_code = 'D') THEN
SELECT decode(g_actual_flag || sign(p_funds_available) || p_funds_level,
'B-1B', 'F00',
'B0B', 'P10',
'B1B', 'P10',
'E-1B', 'F00',
'E0B', 'P10',
'E1B', 'P10',
'B-1D', 'P20', /* Fails FC, but check is 'Advisory' */
'B0D', 'P10',
'B1D', 'P10',
'E-1D', 'P20',
'E0D', 'P10',
'E1D', 'P10', 'P01')
INTO l_result_code
FROM dual;
ELSIF (p_summary_detail_code = 'S') THEN
-- Check funds against a summary account. Note that we will check funds
-- against the summary account as a whole. That is, we will only
-- consider the balance of the entire summary account, and not pass or
-- fail the individual accounts within the summary account.
SELECT decode(g_actual_flag || sign(p_funds_available) || p_funds_level,
'B-1B', 'F01',
'B0B', 'P10',
'B1B', 'P10',
'E-1B', 'F01',
'E0B', 'P10',
'E1B', 'P10',
'B-1D', 'P22', -- Fails FC, but check is 'Advisory'
'B0D', 'P10',
'B1D', 'P10',
'E-1D', 'P22',
'E0D', 'P10',
'E1D', 'P10','P01')
INTO l_result_code
FROM dual;
END IF;
-- Get status code
x_status_code:=Get_Status_By_Result(l_result_code);
x_result_code:=l_result_code;
EXCEPTION
WHEN OTHERS THEN
x_result_code:=NULL; --NOT FOUND error will be raised by main procedure
x_status_code:=NULL;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Get_Result_Code;
PROCEDURE Put_Debug_Msg (
p_path IN VARCHAR2,
p_debug_msg IN VARCHAR2
) IS
-- Constants :
/*l_Return_Status VARCHAR2(1);
l_api_name CONSTANT VARCHAR2(30) := 'Put_Debug_Msg';*/
BEGIN
/*IGC_MSGS_PKG.Put_Debug_Msg (l_full_path, p_debug_message => p_debug_msg,
p_profile_log_name => g_profile_name,
p_prod => g_prod,
p_sub_comp => g_sub_comp,
p_filename_val => NULL,
x_Return_Status => l_Return_Status
);
IF (l_Return_Status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;*/
IF(g_state_level >= g_debug_level) THEN
FND_LOG.STRING(g_state_level, p_path, p_debug_msg);
END IF;
RETURN;
-- --------------------------------------------------------------------
-- Exception handler section for the Put_Debug_Msg procedure.
-- --------------------------------------------------------------------
EXCEPTION
/*WHEN FND_API.G_EXC_ERROR THEN
IF(g_excep_level >= g_debug_level) THEN
FND_LOG.STRING(g_state_level, l_full_path, 'FND_API.G_EXC_ERROR Exception Raised');
END IF;
RETURN;*/
WHEN OTHERS THEN
/*IF (FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;*/
NULL;
RETURN;
END Put_Debug_Msg;
PROCEDURE Register_time(
p_name VARCHAR2,
p_mode BOOLEAN
) IS
l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Register_time';
IF (p_mode) THEN
g_date1:=DBMS_UTILITY.GET_TIME;
ELSE
g_date2 := DBMS_UTILITY.GET_TIME;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Time ' || p_name || ': ' || to_char(g_date2-g_date1));
END IF;
END IF;
END Register_time;
PROCEDURE Unreserve_CBC (
x_status OUT NOCOPY VARCHAR2
) IS
CURSOR c_cbc_batch IS --All batches for CBC from interface table
SELECT DISTINCT batch_id
FROM igc_cc_interface_v a
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
ORDER BY batch_id;
CURSOR c_sbc_batch IS --All batches for CBC from interface table
SELECT DISTINCT batch_id
FROM igc_cc_interface_v a
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'S'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type;
-- ssmales 29/01/02 bug 2201905 - added two new cursors below to process by packet id
CURSOR c_cbc_batch_packet IS --All batches for CBC from interface table
SELECT DISTINCT batch_id
FROM igc_cc_interface_v a
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
ORDER BY batch_id;
CURSOR c_sbc_batch_packet IS --All batches for CBC from interface table
SELECT DISTINCT batch_id
FROM igc_cc_interface_v a
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'S'
AND actual_flag = g_actual_flag;
l_status VARCHAR2(2);
l_batch_id NUMBER;
l_return_code VARCHAR2(1);
l_res BOOLEAN;
l_full_path VARCHAR2(255);
BEGIN
SAVEPOINT Unreserve_CBC;
l_full_path := g_path || 'Unreserve_CBC';
l_status := 'SS';
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Unreserving CBC');
END IF;
--Unreserve CBC
-- ssmales 29/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
FOR c_cbc_batch_rec IN c_cbc_batch_packet LOOP
IF c_cbc_batch_rec.batch_id IS NOT NULL THEN
l_res := Unreserve_Batch( c_cbc_batch_rec.batch_id);
IF NOT l_res THEN
message_token ( 'BATCH_ID', to_char (c_cbc_batch_rec.batch_id) );
add_message ( 'IGC', 'IGC_FAILED_UNRESERVE_CBC' );
l_status := 'US';
ELSE
UPDATE igc_cc_interface_v
SET batch_id = NULL
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND batch_id = c_cbc_batch_rec.batch_id;
END IF;
END IF;
END LOOP;
ELSE
-- bug 2201905 end block
FOR c_cbc_batch_rec IN c_cbc_batch LOOP
IF c_cbc_batch_rec.batch_id IS NOT NULL THEN
l_res := Unreserve_Batch( c_cbc_batch_rec.batch_id);
IF NOT l_res THEN
message_token ( 'BATCH_ID', to_char (c_cbc_batch_rec.batch_id) );
add_message ( 'IGC', 'IGC_FAILED_UNRESERVE_CBC' );
l_status := 'US';
ELSE
UPDATE igc_cc_interface_v
SET batch_id = NULL
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
AND batch_id = c_cbc_batch_rec.batch_id;
END IF;
END IF;
END LOOP;
-- ssmales 29/01/02 bug 2201905 - added end if statement below
END IF ;
--Unreserve SBC
l_batch_id := NULL;
-- ssmales 29/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null ) THEN
OPEN c_sbc_batch_packet;
FETCH c_sbc_batch_packet INTO l_batch_id;
CLOSE c_sbc_batch_packet;
ELSE
-- bug 2201905 end block
OPEN c_sbc_batch;
FETCH c_sbc_batch INTO l_batch_id;
CLOSE c_sbc_batch;
-- ssmales 29/01/02 bug 2201905 - added end if statement below
END IF ;
IF l_batch_id IS NULL THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'No reserved SBC packets found');
END IF;
ELSE
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Unreserving SBC');
END IF;
g_packet_id := l_batch_id;
Unreserve_SBC(l_return_code);
IF l_return_code='S' THEN
--Update interface table and make packet id null
-- ssmales 29/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
UPDATE igc_cc_interface_v
SET batch_id = NULL
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'S'
AND actual_flag = g_actual_flag;
ELSE
-- bug 2201905 end block
UPDATE igc_cc_interface_v
SET batch_id = NULL
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'S'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type;
-- ssmales 29/01/02 bug 2201905 - added end if statement below
END IF ;
ELSE
l_status := substr (l_status,1,1)||'U';
END IF;
END IF;
x_status := l_status;
EXCEPTION
WHEN OTHERS THEN
x_status := 'TT';
ROLLBACK to Unreserve_CBC;
IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, 'Unreserve_CBC');
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Unreserve_CBC;
PROCEDURE Unreserve_SBC (
x_status OUT NOCOPY VARCHAR2
) IS
PRAGMA AUTONOMOUS_TRANSACTION;
l_api_name CONSTANT VARCHAR2(32) := 'Unreserve_SBC';
l_func BOOLEAN;
l_count NUMBER;
l_count_excpt NUMBER;
l_return_code VARCHAR2(1);
l_full_path VARCHAR2(255);
BEGIN
-- --------------------------------------------------------------------------
-- Initialize variables to be used in this procedure.
-- --------------------------------------------------------------------------
x_status := 'S';
l_full_path := g_path || 'Unreserve_SBC';
-- --------------------------------------------------------------------------
-- Loop through the list of Reservation packet_ids, unreserving each packet
-- that had previously been reserved.
-- --------------------------------------------------------------------------
IF g_packet_id IS NOT NULL THEN
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := 'Unreserving a reserved Packet : ' ||
'Set of books ID : ' || g_set_of_books_id ||
'Packet ID : ' || g_packet_id;
Put_Debug_Msg (l_full_path, g_debug);
END IF;
-- --------------------------------------------------------------------------
-- Call the SBC with a mode of 'Unreserve' to reverse previous reservations
-- --------------------------------------------------------------------------
l_func := GL_FUNDS_CHECKER_PKG.GLXFCK(p_sobid => g_set_of_books_id,
p_packetid => g_packet_id,
p_mode => 'U', -- Unreserve
p_partial_resv_flag => 'N',
p_override => 'N',
p_conc_flag => 'N',
p_user_id => g_update_by,
p_user_resp_id => g_resp_id,
p_return_code => l_return_code
);
-- --------------------------------------------------------------------------
-- If a FAILURE was encoutered in the unreserve process log the appropriate
-- error message for the user then set the return status as a failure.
-- Continue with the remaining packets that need to be unreserved so that
-- there is little manual cleanup to be done.
-- --------------------------------------------------------------------------
IF ((NOT l_func) OR (l_return_code = 'F') OR (l_return_code = 'T')) THEN
message_token ( 'PACKET_ID', to_char (g_packet_id) );
add_message ( 'IGC', 'IGC_FAILED_UNRESERVE_SBC' );
x_status := 'F';
ELSE
-- ssmales 28/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
UPDATE igc_cc_interface_v
SET batch_id = NULL
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'S'
AND actual_flag = g_actual_flag ;
ELSE
-- bug 2201905 end block
UPDATE igc_cc_interface_v
SET batch_id = NULL
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'S'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type;
-- ssmales 28/01/02 bug 2201905 - added end if statement below
END IF ;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
IF l_func THEN
g_debug := 'Ureservation status TRUE: '||l_return_code;
ELSE
g_debug := 'Ureservation status FALSE: '||l_return_code;
END IF;
Put_Debug_Msg (l_full_path, g_debug);
END IF;
END IF;
IF NOT g_called_from_PO
THEN
COMMIT;
END IF;
-- --------------------------------------------------------------------------
-- Exception section for the Unreserve_SBC function.
-- --------------------------------------------------------------------------
EXCEPTION
WHEN OTHERS THEN
x_status := 'F';
IF FND_MSG_PUB.Check_Msg_Level(FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME, l_api_name);
END IF;
IF NOT g_called_from_PO
THEN
COMMIT;
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Unreserve_SBC;
/* Function returns the value for the funds check level code, based on
global variable from budgetary control group and current value,
If the previous values for the detail record category and source are equal
to the curent, then the previous value of sevirity level is taken.
For the summary account Cursor makes loop through all combinations of detail S and C
for the current summary and the most severe value is taken*/
FUNCTION Calculate_Sevirity_Level(
p_summary_detail_code IN VARCHAR2,
p_ccid IN NUMBER,
p_source IN VARCHAR2,
p_category IN VARCHAR2,
p_ccid_level IN VARCHAR2)
RETURN VARCHAR2 IS
CURSOR c_bc_options_sum IS
SELECT DISTINCT je_source_name,
je_category_name
FROM igc_cc_interface_v
WHERE code_combination_id IN
(SELECT detail_code_combination_id
FROM gl_account_hierarchies
WHERE summary_code_combination_id = p_ccid
AND set_of_books_id = g_set_of_books_id
)
AND cc_header_id = g_cc_header_id
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
AND budget_dest_flag ='C';
CURSOR c_bc_options(sour VARCHAR2, cat VARCHAR2) IS
SELECT 1 rank,funds_check_level_code
FROM gl_bc_option_details
WHERE bc_option_id = g_bc_group_id
AND je_source_name = sour
AND je_category_name = cat
UNION
SELECT 2,funds_check_level_code
FROM gl_bc_option_details
WHERE bc_option_id = g_bc_group_id
AND je_source_name = sour
AND je_category_name = 'Other'
UNION
SELECT 2,funds_check_level_code
FROM gl_bc_option_details
WHERE bc_option_id = g_bc_group_id
AND je_source_name = 'Other'
AND je_category_name = cat
UNION
SELECT 2,funds_check_level_code
FROM gl_bc_option_details
WHERE bc_option_id = g_bc_group_id
AND je_source_name = 'Other'
AND je_category_name = 'Other'
ORDER BY 1;
l_level VARCHAR2(1);
l_rank NUMBER;
l_full_path VARCHAR2(255);
BEGIN
--Comparing previous data with the new one
l_full_path := g_path || 'Calculate_Sevirity_Level';
IF (g_source IS NULL OR g_source <> p_source )
OR (g_category IS NULL OR g_category <> p_category)
OR p_summary_detail_code ='S' THEN
IF (p_summary_detail_code ='S') THEN
--Summary record - need to find anyway
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Initializing budgetary control group info for
the control group: '||g_bc_group_id||' for the summary CCID '||p_ccid);
END IF;
g_group_severity_level:='';
FOR c_bc_options_sum_rec IN c_bc_options_sum LOOP
OPEN c_bc_options(c_bc_options_sum_rec.je_source_name,c_bc_options_sum_rec.je_category_name);
FETCH c_bc_options INTO l_rank,l_level;
IF l_level IS NULL OR g_group_severity_level IS NULL
OR (l_level ='B')
OR (l_level ='D' AND g_group_severity_level='N') THEN
g_group_severity_level:=l_level;
END IF;
CLOSE c_bc_options;
END LOOP;
g_source:='';
g_category:='';
ELSE
--Detail record, looking for the group
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Initializing budgetary control group info for
the control group: '||g_bc_group_id||' source '||p_source||' category '||p_category);
END IF;
OPEN c_bc_options(p_source,p_category);
FETCH c_bc_options INTO l_rank,g_group_severity_level;
IF c_bc_options%NOTFOUND THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'User source and category not found');
END IF;
g_group_severity_level:='';
END IF;
CLOSE c_bc_options;
g_source:=p_source;
g_category:=p_category;
END IF;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Budget group level: '||g_group_severity_level);
END IF;
ELSE
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'New category and source are the same, using existing data level :'||
g_group_severity_level);
END IF;
END IF;
IF g_group_severity_level IS NULL THEN
return p_ccid_level;
ELSIF p_ccid_level='N' THEN
return 'N';
ELSIF p_ccid_level='B' THEN
return 'B';
ELSE
return g_group_severity_level;
END IF;
END Calculate_Sevirity_Level;
FUNCTION Get_Batch_Result_Code (
p_mode VARCHAR2,
p_batch_result_code VARCHAR2 )
RETURN VARCHAR2
IS
l_batch_result_code VARCHAR2(3);
l_ranked_result_code VARCHAR2(3);
-- 1947176, Aug 21 2001
CURSOR c_get_msg IS
SELECT DISTINCT popup_messg_code
FROM igc_cc_result_code_ranks
WHERE action = decode(p_mode,'F','R',p_mode)
AND severity_rank = p_batch_result_code;

l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Get_Batch_Result_Code';
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'The most severe rank is: '||p_batch_result_code);
END IF;
/*
--Selecting the result_code, using the Sevirity rank
l_ranked_result_code:= Get_Result_By_Rank (p_batch_result_code);
--Selecting the ranked result code, using result_code
SELECT decode(decode(p_mode,'F','R',p_mode)||l_ranked_result_code, --substitute mode 'F' with 'R'.
'CF00','H04',
'RF00','H12',
'CF01','H04',
'RF01','H12',
'CF02','H04',
'RF02','H12',
'CF03','H04',
'RF03','H12',
'CF04','H04',
'RF04','H12',
'CF05','H04',
'RF05','H12',
'CF06','H04',
'RF06','H12',
'CF10','H04',
'RF10','H12',
'CF11','H04',
'RF11','H12',
'CF12','H04',
'RF12','H12',
'CF13','H04',
'RF13','H12',
'CF14','H04',
'RF14','H12',
'CF15','H04',
'RF15','H12',
'CF20','H00',
'RF20','H00',
'CF21','H00',
'RF21','H00',
'CF22','H00',
'RF22','H00',
'CF23','H00',
'RF23','H00',
'CF24','H00',
'RF24','H00',
'CF25','H00',
'RF25','H00',
'CF26','H00',
'RF26','H00',
'CF27','H00',
'RF27','H00',
'CF28','H00',
'RF28','H00',
'CP00','H01',
'RP00','H13',
'CP01','H01',
'RP01','H13',
'CP02','H00',
'RP02','H00',
'CP03','H01',
'RP03','H01',
'CP04','H02',
'RP04','H10',
'CP05','H02',
'RP05','H10',
'CP10','H02',
'RP10','H10',
'CP15','H02',
'RP15','H10',
'CP20','H03',
'RP20','H11',
'CP21','H04',
'RP21','H12',
'CP22','H03',
'RP22','H11',
'CP23','H02',
'RP23','H10',
'CP25','H03',
'RP25','H11',
'CP26','H02',
'RP26','H10',
'CP27','H03',
'RP27','H11',
'H00')
INTO l_batch_result_code
FROM dual;
*/
-- The values now stored in table IGC_CC_RESULT_CODE_RANKS
-- 1947176, Aug 21 2001
OPEN c_get_msg;
FETCH c_get_msg INTO l_batch_result_code;
CLOSE c_get_msg;
RETURN l_batch_result_code;
EXCEPTION
WHEN OTHERS
THEN
RETURN NULL;
END Get_Batch_Result_Code;
FUNCTION Get_Rank(
p_code IN VARCHAR2)
RETURN NUMBER
IS
l_batch_result_code NUMBER(4);
-- 1947176, Aug 21 2001
CURSOR c_get_rank IS
SELECT DISTINCT severity_rank
FROM igc_cc_result_code_ranks
WHERE funds_checker_code = p_code;

l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Get_Rank';
--Selecting the Sevirity rank for result_code
/*
SELECT decode(p_code,
'F00',2010,
'F01',2020,
'F02',2030,
'F03',2040,
'F04',2050,
'F05',2060,
'F06',2070,
'F10',2080,
'F11',2090,
'F12',2100,
'F13',2110,
'F14',2120,
'F15',2130,
'F20',1010,
'F21',1020,
'F22',1030,
'F23',1040,
'F24',1050,
'F25',1060,
'F26',1070,
'F27',1080,
'F28',1090,
'P00',3110,
'P01',4010,
'P02',4020,
'P03',4030,
'P04',4040,
'P05',3080,
'P10',3090,
'P15',3100,
'P20',3010,
'P21',3020,
'P22',3030,
'P23',3040,
'P25',3050,
'P26',3060,
'P27',3070,
9999)
INTO l_batch_result_code
FROM dual;
*/
-- The values now stored in table IGC_CC_RESULT_CODE_RANKS
-- 1947176, Aug 21 2001
OPEN c_get_rank;
FETCH c_get_rank INTO l_batch_result_code;
CLOSE c_get_rank;
RETURN l_batch_result_code;
EXCEPTION
WHEN OTHERS
THEN
RETURN NULL;
END Get_Rank;
PROCEDURE Split_JE_Batch(
x_return_status OUT NOCOPY VARCHAR2
) IS
l_set_of_books_id NUMBER(15);
l_total_cr igc_cbc_je_batches.running_total_cr%TYPE;
l_total_dr igc_cbc_je_batches.running_total_dr%TYPE;
l_effective_date DATE;
l_version_id NUMBER;
l_api_name CONSTANT VARCHAR2(30) := 'Split_JE_Batch';
l_msg_count NUMBER;
l_msg_data VARCHAR(2000);
l_return_status VARCHAR(1);
l_rowid VARCHAR2(255);
l_batch_id igc_cbc_je_batches.cbc_je_batch_id%TYPE;
l_cc_header_id NUMBER;
l_entered_dr igc_cbc_je_lines.entered_dr%TYPE;
l_entered_cr igc_cbc_je_lines.entered_cr%TYPE;
l_debug VARCHAR2(1) :='F';
CURSOR c_batch_data IS
SELECT period_name ,
quarter_num ,
period_num ,
period_year ,
MIN(effective_date) effective_date,
SUM(entered_dr) entered_dr,
SUM(entered_cr) entered_cr
FROM igc_cbc_je_lines
WHERE cbc_je_batch_id =g_batch_id
GROUP BY period_year ,
period_num ,
period_name ,
quarter_num;

l_full_path VARCHAR2(255);
BEGIN
SAVEPOINT Split_JE_Batch;
x_return_status := FND_API.G_RET_STS_SUCCESS;
l_full_path := g_path || 'Split_JE_Batch';
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Starting splitting up the batch');
END IF;
FOR c_batch_data_rec IN c_batch_data LOOP
IF l_entered_dr IS NULL AND l_entered_cr IS NULL THEN
-- first time in loop store values for the original batch
l_entered_dr := NVL(c_batch_data_rec.entered_dr,0);
l_entered_cr := NVL(c_batch_data_rec.entered_cr,0);
--Store original batch id
-- ssmales 28/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
UPDATE igc_cc_interface_v
SET batch_id = g_batch_id
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND period_name = c_batch_data_rec.period_name;
ELSE
-- bug 2201905 end block
UPDATE igc_cc_interface_v
SET batch_id = g_batch_id
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
AND period_name = c_batch_data_rec.period_name;
-- ssmales bug 2201905 - added end if statement below
END IF ;
ELSE
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'New batch found:' ||
' period name: '||c_batch_data_rec.period_name||
' effective date: '||c_batch_data_rec.effective_date||
' entered_dr: '||c_batch_data_rec.entered_dr||
' entered_cr: '||c_batch_data_rec.entered_cr );
END IF;
IGC_CBC_HANDLERS_PKG.Insert_Je_Batch_Row(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_row_id => l_rowid,
p_cbc_je_batch_id => l_batch_id,
p_set_of_books_id => g_set_of_books_id,
p_cc_header_id => g_cc_header_id,
p_name => Get_Batch_Name(c_batch_data_rec.period_name),
p_batch_status => 'P',
p_actual_flag => g_actual_flag,
p_budgetary_control_status => 'P',
p_approval_status_code => 'A',
p_description => '',
p_effective_date => c_batch_data_rec.effective_date,
p_running_total_dr => c_batch_data_rec.entered_dr,
p_running_total_cr => c_batch_data_rec.entered_cr,
p_context => '',
p_last_update_date => sysdate,
p_last_updated_by => g_update_by,
p_last_update_login => g_update_login,
p_creation_date => sysdate,
p_created_by => g_update_by,
p_attribute1 =>'',
p_attribute2 =>'',
p_attribute3 =>'',
p_attribute4 =>'',
p_attribute5 =>'',
p_attribute6 =>'',
p_attribute7 =>'',
p_attribute8 =>'',
p_attribute9 =>'',
p_attribute10 =>'',
p_attribute11 =>'',
p_attribute12 =>'',
p_attribute13 =>'',
p_attribute14 =>'',
p_attribute15 =>''
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
RAISE FND_API.G_EXC_ERROR ;
END IF;
UPDATE igc_cbc_je_lines
SET cbc_je_batch_id = l_batch_id
WHERE cbc_je_batch_id = g_batch_id
AND period_name = c_batch_data_rec.period_name
AND quarter_num = c_batch_data_rec.quarter_num
AND period_num = c_batch_data_rec.period_num
AND period_year = c_batch_data_rec.period_year ;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, ' New batch id: '||l_batch_id||', '||to_char(SQL%ROWCOUNT)||' lines
updated ');
END IF;
-- ssmales 28/01/02 bug 2201905 - added if block below
-- bug 2201905 start block
IF (g_p_packet_id is not null) THEN
UPDATE igc_cc_interface_v
SET batch_id = l_batch_id
WHERE reference_6 = g_p_packet_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND period_name = c_batch_data_rec.period_name;
ELSE
-- bug 2201905 end block
UPDATE igc_cc_interface_v
SET batch_id = l_batch_id
WHERE cc_header_id = g_cc_header_id
AND budget_dest_flag = 'C'
AND actual_flag = g_actual_flag
AND document_type = g_doc_type
AND period_name = c_batch_data_rec.period_name;
-- ssmales 28/01/02 bug 2201905 - added end if statement below
END IF ;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Processing MRC for created batch');
l_debug :='T';
END IF;
IGC_CBC_MRC.Process_CBC_MRC( p_cbc_batch_id => l_batch_id,
p_set_of_books_id => g_set_of_books_id,
p_debug_flag => l_debug,
x_return_status => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
l_batch_id := null;
END IF;
END LOOP;
IF l_rowid IS NOT NULL THEN
--the batch has more then one period, amounts need to be updated
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Updating the original batch ');
END IF;
UPDATE igc_cbc_je_batches
SET running_total_dr = l_entered_dr,
running_total_cr = l_entered_cr
WHERE cbc_je_batch_id = g_batch_id;
END IF;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg(l_full_path, 'Processing MRC for the main batch');
l_debug :='T';
END IF;
IGC_CBC_MRC.Process_CBC_MRC( p_cbc_batch_id => g_batch_id,
p_set_of_books_id => g_set_of_books_id,
p_debug_flag => l_debug,
x_return_status => l_return_status
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
raise FND_API.G_EXC_ERROR;
END IF;
IF (g_debug_mode = 'Y') THEN
Put_Debug_Msg (l_full_path, 'Batch has been splitted up successfully');
END IF;
EXCEPTION
WHEN FND_API.G_EXC_ERROR THEN
ROLLBACK to Split_JE_Batch;
x_return_status := FND_API.G_RET_STS_ERROR;
IF (g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level ,l_full_path , 'FND_API.G_EXC_ERROR Exception Raised');
END IF;
WHEN FND_API.G_EXC_UNEXPECTED_ERROR THEN
ROLLBACK to Split_JE_Batch;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF (g_excep_level >= g_debug_level ) THEN
FND_LOG.STRING (g_excep_level ,l_full_path , 'FND_API.G_EXC_UNEXPECTED_ERROR Exception
Raised');
END IF;
WHEN OTHERS THEN
ROLLBACK to Split_JE_Batch;
x_return_status := FND_API.G_RET_STS_UNEXP_ERROR;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,l_api_name);
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
END Split_JE_Batch;
FUNCTION Get_Batch_Name(
p_period_name IN VARCHAR2)
RETURN VARCHAR2 IS
CURSOR c_cc_data IS
SELECT cc_num ,
cc_version_num
FROM igc_cc_headers
WHERE cc_header_id = g_cc_header_id;
CURSOR c_po_num IS
SELECT segment1
FROM po_headers
WHERE po_header_id = g_cc_header_id;
CURSOR c_req_num IS
SELECT segment1
FROM po_requisition_headers
WHERE requisition_header_id = g_cc_header_id;
l_cc_num igc_cc_headers.cc_num%TYPE;
l_ver_num igc_cc_headers.cc_version_num%TYPE;
l_batch_name VARCHAR2(2000);
l_api_name CONSTANT VARCHAR2(30) := 'Get_Batch_Name';
l_po_num po_headers.segment1%TYPE;
l_req_num po_requisition_headers.segment1%TYPE;
l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Get_Batch_Name';
IF g_doc_type = 'CC' THEN
OPEN c_cc_data;
FETCH c_cc_data INTO l_cc_num,l_ver_num;
CLOSE c_cc_data;
FND_MESSAGE.SET_NAME('IGC', 'IGC_CBC_CC_BATCH_NAME');
FND_MESSAGE.SET_TOKEN('HEADER_ID', g_cc_header_id);
FND_MESSAGE.SET_TOKEN('PERIOD_NAME', p_period_name);
FND_MESSAGE.SET_TOKEN('CC_NUM', l_cc_num);
FND_MESSAGE.SET_TOKEN('VERSION_NUM', l_ver_num);
l_batch_name := FND_MESSAGE.Get;
ELSIF g_doc_type = 'BP' THEN
FND_MESSAGE.SET_NAME('IGC', 'IGC_CBC_BP_BATCH_NAME');
FND_MESSAGE.SET_TOKEN('DOCUMENT_ID', g_cc_header_id);
FND_MESSAGE.SET_TOKEN('PERIOD_NAME', p_period_name);
l_batch_name := FND_MESSAGE.Get;
ELSIF g_doc_type = 'BR' THEN
FND_MESSAGE.SET_NAME('IGC', 'IGC_CBC_BR_BATCH_NAME');
FND_MESSAGE.SET_TOKEN('DOCUMENT_ID', g_cc_header_id);
FND_MESSAGE.SET_TOKEN('PERIOD_NAME', p_period_name);
l_batch_name := FND_MESSAGE.Get;
ELSIF g_doc_type = 'PA' THEN
FND_MESSAGE.SET_NAME('IGC', 'IGC_CBC_PA_BATCH_NAME');
FND_MESSAGE.SET_TOKEN('DOCUMENT_ID', g_cc_header_id);
FND_MESSAGE.SET_TOKEN('PERIOD_NAME', p_period_name);
l_batch_name := FND_MESSAGE.Get;
-- ssmales 28/01/02 bug 2201905 - added new doc type block below
-- bug 2201905 start block
-- Modified to print the document numbers rather than the document id
-- Bidisha S, 28 Nov 2002
ELSIF g_doc_type = 'PO' THEN
OPEN c_po_num;
FETCH c_po_num INTO l_po_num;
CLOSE c_po_num;
FND_MESSAGE.SET_NAME('IGC', 'IGC_CBC_PO_BATCH_NAME');
FND_MESSAGE.SET_TOKEN('DOCUMENT_ID', l_po_num);
FND_MESSAGE.SET_TOKEN('PERIOD_NAME', p_period_name);
l_batch_name := FND_MESSAGE.Get ;
ELSIF g_doc_type = 'REQ' THEN
OPEN c_req_num;
FETCH c_req_num INTO l_req_num;
CLOSE c_req_num;
FND_MESSAGE.SET_NAME('IGC', 'IGC_CBC_REQ_BATCH_NAME');
FND_MESSAGE.SET_TOKEN('DOCUMENT_ID', l_req_num);
FND_MESSAGE.SET_TOKEN('PERIOD_NAME', p_period_name);
l_batch_name := FND_MESSAGE.Get ;
-- bug 2201905 end block
ELSE
message_token ('DOCUMENT_TYPE', g_doc_type);
add_message ('IGC', 'IGC_CBC_INVALID_DOC_TYPE');
END IF;
RETURN substr(l_batch_name,1,100);
END Get_Batch_Name;
/* function determines status code, using result code */
FUNCTION Get_Status_By_Result(
p_result_code IN VARCHAR2)
RETURN VARCHAR2 IS
l_status_code VARCHAR2(1);
-- 1947176, Aug 21 2001
CURSOR c_get_result IS
SELECT DISTINCT result_status_code
FROM igc_cc_result_code_ranks
WHERE funds_checker_code = p_result_code
AND action = Decode(g_mode, 'F', 'R', g_mode);

l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Get_Status_By_Result';
IF p_result_code IS NULL THEN
RETURN '';
ELSE
/*
ELSIF p_result_code BETWEEN 'F20' AND 'F28' THEN
--Check if it's failed totaly.
RETURN 'T';
ELSE
SELECT DECODE(g_mode||substr(p_result_code,1,1),
'CP','S',
'RP','A',
'FP','A',
'FF','R',
'CF','F',
'RF','R')
INTO l_status_code
FROM dual;
*/
-- The values now stored in table IGC_CC_RESULT_CODE_RANKS
-- 1947176, Aug 21 2001
OPEN c_get_result;
FETCH c_get_result INTO l_status_code;
CLOSE c_get_result;
END IF;
return l_status_code;
EXCEPTION
WHEN OTHERS
THEN
RETURN NULL;
END Get_Status_By_Result;
FUNCTION Get_Result_By_Rank(
p_rank NUMBER )
RETURN VARCHAR2
IS
l_result_code VARCHAR2(3);
-- 1947176, Aug 21 2001
CURSOR c_get_result IS
SELECT DISTINCT funds_checker_code
FROM igc_cc_result_code_ranks
WHERE severity_rank = p_rank;

l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Get_Result_By_Rank';
--Selecting the result_code, using the Sevirity rank
/*
SELECT decode(p_rank,
2010,'F00',
2020,'F01',
2030,'F02',
2040,'F03',
2050,'F04',
2060,'F05',
2070,'F06',
2080,'F10',
2090,'F11',
2100,'F12',
2110,'F13',
2120,'F14',
2130,'F15',
1010,'F20',
1020,'F21',
1030,'F22',
1040,'F23',
1050,'F24',
1060,'F25',
1070,'F26',
1080,'F27',
1090,'F28',
3110,'P00',
4010,'P01',
4020,'P02',
4030,'P03',
4040,'P04',
3080,'P05',
3090,'P10',
3100,'P15',
3010,'P20',
3020,'P21',
3030,'P22',
3040,'P23',
3050,'P25',
3060,'P26',
3070,'P27',
'')
INTO l_result_code
FROM dual;
*/
-- Selecting the ranked result code, using result_code
-- The values now stored in table IGC_CC_RESULT_CODE_RANKS
-- 1947176, Aug 21 2001
OPEN c_get_result;
FETCH c_get_result INTO l_result_code;
CLOSE c_get_result;
RETURN l_result_code;
EXCEPTION
WHEN OTHERS
THEN
RETURN NULL;
END Get_Result_By_Rank;
/* Function compares summary and detail results and return the best one.*/
FUNCTION Get_Total_Result(
p_result_code_det IN VARCHAR2,
p_result_code_sum IN VARCHAR2
)
RETURN VARCHAR2 IS
l_full_path VARCHAR2(255);
BEGIN
l_full_path := g_path || 'Get_Total_Result';
IF p_result_code_det IS NULL THEN
RETURN p_result_code_sum;
ELSIF p_result_code_det IN ('F00','F04') AND p_result_code_sum IN ('F01','F02') THEN
RETURN 'F04';
ELSIF p_result_code_sum IN ('P22','F01')
AND (Get_Rank(p_result_code_sum) < Get_Rank(p_result_code_det))
AND p_result_code_det <> 'P00' THEN
RETURN p_result_code_sum;
END IF;
RETURN p_result_code_det;
END Get_Total_Result;
PROCEDURE Set_Batch_Result_Code(
p_code IN VARCHAR2)
IS
l_batch_result_code NUMBER(4);
l_full_path VARCHAR2(255);
BEGIN
--Selecting the Sevirity rank for result_code
l_full_path := g_path || 'Set_Batch_Result_Code';
l_batch_result_code := Get_Rank (p_code);
IF g_batch_result_code > l_batch_result_code THEN
g_batch_result_code := l_batch_result_code;
END IF;
END Set_Batch_Result_Code;
FUNCTION Unreserve_Batch(
p_batch_id IN NUMBER
) RETURN BOOLEAN IS
l_new_batch_id NUMBER := NULL;
l_rowid VARCHAR2(255);
l_return_status VARCHAR2(1);
l_msg_count NUMBER;
l_msg_data VARCHAR(2000);
l_full_path VARCHAR2(255);
BEGIN
-- ------------------------------------------------------------------------------
-- Make sure that the batch ID passed in is valid being > 0.
-- ------------------------------------------------------------------------------
l_full_path := g_path || 'Unreserve_Batch';
IF (NVL(p_batch_id, -1) <= 0) THEN
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' IGCBEFCB - Unable to Unreserve Batch ID : ' || p_batch_id;
Put_Debug_Msg (l_full_path, g_debug );
END IF;
RETURN (FALSE);
END IF;
SAVEPOINT Unreserve_Batch;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' IGCBEFCB - Unreserving Batch ID : ' || p_batch_id;
Put_Debug_Msg (l_full_path, g_debug );
END IF;
-- Insert new batch
FOR c_batch_rec IN ( SELECT set_of_books_id ,
cc_header_id ,
name ,
batch_status ,
actual_flag ,
budgetary_control_status ,
approval_status_code ,
description ,
effective_date ,
running_total_dr ,
running_total_cr ,
context ,
last_update_date ,
last_updated_by ,
last_update_login ,
creation_date ,
created_by ,
attribute1 ,
attribute2 ,
attribute3 ,
attribute4 ,
attribute5 ,
attribute6 ,
attribute7 ,
attribute8 ,
attribute9 ,
attribute10 ,
attribute11 ,
attribute12 ,
attribute13 ,
attribute14 ,
attribute15
FROM igc_cbc_je_batches
WHERE cbc_je_batch_id = p_batch_id ) LOOP
IGC_CBC_HANDLERS_PKG.Insert_Je_Batch_Row(
p_api_version => 1.0,
p_return_status => l_return_status,
p_msg_count => l_msg_count,
p_msg_data => l_msg_data,
p_row_id => l_rowid,
p_cbc_je_batch_id => l_new_batch_id,
p_set_of_books_id => c_batch_rec.set_of_books_id,
p_cc_header_id => c_batch_rec.cc_header_id ,
p_name => c_batch_rec.name,
p_batch_status => c_batch_rec.batch_status,
p_actual_flag => c_batch_rec.actual_flag,
p_budgetary_control_status => c_batch_rec.budgetary_control_status,
p_approval_status_code => c_batch_rec.approval_status_code ,
p_description => c_batch_rec.description ,
p_effective_date => c_batch_rec.effective_date,
p_running_total_dr => - c_batch_rec.running_total_dr,
p_running_total_cr => - c_batch_rec.running_total_cr,
p_context => c_batch_rec.context,
p_last_update_date => sysdate,
p_last_updated_by => g_update_by,
p_last_update_login => g_update_login,
p_creation_date => sysdate,
p_created_by => g_update_by,
p_attribute1 => c_batch_rec.attribute1,
p_attribute2 => c_batch_rec.attribute2,
p_attribute3 => c_batch_rec.attribute3,
p_attribute4 => c_batch_rec.attribute4,
p_attribute5 => c_batch_rec.attribute5,
p_attribute6 => c_batch_rec.attribute6,
p_attribute7 => c_batch_rec.attribute7,
p_attribute8 => c_batch_rec.attribute8,
p_attribute9 => c_batch_rec.attribute9,
p_attribute10 => c_batch_rec.attribute10,
p_attribute11 => c_batch_rec.attribute11,
p_attribute12 => c_batch_rec.attribute12,
p_attribute13 => c_batch_rec.attribute13,
p_attribute14 => c_batch_rec.attribute14,
p_attribute15 => c_batch_rec.attribute15
);
IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
RAISE FND_API.G_EXC_ERROR ;
END IF;
END LOOP;
-- ------------------------------------------------------------------------------
-- Insert the associated MRC batches for the batch that needs to be unreserved
-- ------------------------------------------------------------------------------
INSERT INTO igc_cbc_mc_je_batches
( cbc_je_batch_id ,
reporting_set_of_books_id ,
reporting_currency_code ,
running_total_dr ,
running_total_cr ,
conversion_type ,
conversion_date ,
conversion_rate ,
creation_date ,
created_by
)
SELECT
l_new_batch_id ,
reporting_set_of_books_id ,
reporting_currency_code ,
-running_total_dr ,
-running_total_cr ,
conversion_type ,
conversion_date ,
conversion_rate ,
sysdate ,
g_update_by
FROM igc_cbc_mc_je_batches
WHERE cbc_je_batch_id = p_batch_id;
-- ------------------------------------------------------------------------------
-- Insert the associated CBC JE lines for the batch that needs to be unreserved
-- ------------------------------------------------------------------------------
INSERT INTO igc_cbc_je_lines
( cbc_je_batch_id ,
cbc_je_line_num ,
je_source ,
je_category ,
actual_flag ,
currency_code ,
set_of_books_id ,
encumbrance_type_id ,
budget_version_id ,
balancing_segment_value ,
detail_summary_code ,
code_combination_id ,
funds_check_level_code ,
amount_type ,
effective_date ,
posted_date ,
period_year ,
dr_cr_code ,
entered_dr ,
entered_cr ,
description ,
budget_type ,
period_set_name ,
period_name ,
quarter_num ,
period_num ,
status ,
context ,
last_update_date ,
last_updated_by ,
last_update_login ,
creation_date ,
created_by ,
reference_1 ,
reference_2 ,
reference_3 ,
reference_4 ,
reference_5 ,
reference_6 ,
reference_7 ,
reference_8 ,
reference_9 ,
reference_10 ,
attribute1 ,
attribute2 ,
attribute3 ,
attribute4 ,
attribute5 ,
attribute6 ,
attribute7 ,
attribute8 ,
attribute9 ,
attribute10 ,
attribute11 ,
attribute12 ,
attribute13 ,
attribute14 ,
attribute15
)
SELECT
l_new_batch_id ,
cbc_je_line_num ,
je_source ,
je_category ,
actual_flag ,
currency_code ,
set_of_books_id ,
encumbrance_type_id ,
budget_version_id ,
balancing_segment_value ,
detail_summary_code ,
code_combination_id ,
funds_check_level_code ,
amount_type ,
effective_date ,
posted_date ,
period_year ,
dr_cr_code ,
-entered_dr ,
-entered_cr ,
description ,
budget_type ,
period_set_name ,
period_name ,
quarter_num ,
period_num ,
status ,
context ,
sysdate ,
g_update_by ,
g_update_login ,
sysdate ,
g_update_by ,
reference_1 ,
reference_2 ,
reference_3 ,
reference_4 ,
reference_5 ,
reference_6 ,
reference_7 ,
reference_8 ,
reference_9 ,
reference_10 ,
attribute1 ,
attribute2 ,
attribute3 ,
attribute4 ,
attribute5 ,
attribute6 ,
attribute7 ,
attribute8 ,
attribute9 ,
attribute10 ,
attribute11 ,
attribute12 ,
attribute13 ,
attribute14 ,
attribute15
FROM igc_cbc_je_lines
WHERE cbc_je_batch_id = p_batch_id;
-- ------------------------------------------------------------------------------
-- Insert the associated MRC lines for the batch that needs to be unreserved
-- ------------------------------------------------------------------------------
INSERT INTO igc_cbc_mc_je_lines
( cbc_je_batch_id ,
cbc_je_line_num ,
reporting_set_of_books_id ,
reporting_currency_code ,
entered_dr ,
entered_cr ,
conversion_type ,
conversion_date ,
conversion_rate ,
creation_date ,
created_by
)
SELECT
l_new_batch_id ,
cbc_je_line_num ,
reporting_set_of_books_id ,
reporting_currency_code ,
-entered_dr ,
-entered_cr ,
conversion_type ,
conversion_date ,
conversion_rate ,
sysdate ,
g_update_by
FROM igc_cbc_mc_je_lines
WHERE cbc_je_batch_id = p_batch_id;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' IGCBEFCB - Unreserved Batch ID : ' || p_batch_id;
Put_Debug_Msg (l_full_path, g_debug );
END IF;
RETURN (TRUE);
EXCEPTION
WHEN OTHERS THEN
ROLLBACK to Unreserve_Batch;
-- IF (IGC_MSGS_PKG.g_debug_mode) THEN
IF (g_debug_mode = 'Y') THEN
g_debug := ' IGCBEFCB - Failure OTHERS when Unreserving Batch ID : ' || p_batch_id;
Put_Debug_Msg (l_full_path, g_debug );
END IF;
IF FND_MSG_PUB.Check_Msg_Level (FND_MSG_PUB.G_MSG_LVL_UNEXP_ERROR) THEN
FND_MSG_PUB.Add_Exc_Msg (G_PKG_NAME,'Unreserve_Batch');
END IF;
IF ( g_unexp_level >= g_debug_level ) THEN
FND_MESSAGE.SET_NAME('IGC','IGC_LOGGING_UNEXP_ERROR');
FND_MESSAGE.SET_TOKEN('CODE',SQLCODE);
FND_MESSAGE.SET_TOKEN('MSG', SQLERRM);
FND_LOG.MESSAGE ( g_unexp_level,l_full_path, TRUE);
END IF;
RETURN (FALSE);
END Unreserve_Batch;
END IGC_CBC_FUNDS_CHECKER;
/

You might also like