1 package body PA_FUNDS_CONTROL_PKG as
2 -- $Header: PABCFCKB.pls 120.56.12020000.3 2013/03/06 09:10:44 admarath ship $
3
4 /**-----------------------------------------------------------------------
5 --- Declare Global Variables
6 ----------------------------------------------------------------------***/
7 --g_debug_mode VARCHAR2(10); -- Moved to Spec ..
8 g_adv_result_code VARCHAR2(10); -- Added for bug 9156359
9 g_mode VARCHAR2(100);
10 g_calling_module VARCHAR2(100);
11 g_partial_flag VARCHAR2(100);
12 g_return_status VARCHAR2(1000);
13 g_pa_gl_return_status VARCHAR2(1000);
14 g_pa_cbc_return_status VARCHAR2(1000);
15 g_doc_type VARCHAR2(1000);
16 g_error_stage VARCHAR2(1000);
17 g_error_msg VARCHAR2(2000);
18 g_packet_id PA_BC_PACKETS.PACKET_ID%TYPE;
19 g_cbc_packet_id PA_BC_PACKETS.PACKET_ID%TYPE;
20 g_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
21 g_task_id PA_BC_PACKETS.TASK_ID%type := null;
22 g_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
23 g_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
24 g_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
25 g_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
26 g_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
27 g_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
28 g_entry_level_code VARCHAR2(200) := null;
29 g_start_date DATE := null;
30 g_end_date DATE := null;
31 g_time_phase_code VARCHAR2(20) := null;
32 g_pre_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
33 g_pre_task_id PA_BC_PACKETS.TASK_ID%type := null;
34 g_pre_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
35 g_pre_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
36 g_pre_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
37 g_pre_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
38 g_pre_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
39 g_pre_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
40 g_pre_entry_level_code VARCHAR2(200) := null;
41 g_pre_start_date DATE := null;
42 g_pre_end_date DATE := null;
43 g_pre_time_phase_code VARCHAR2(20) := null;
44 g_bdgt_ccid PA_BC_PACKETS.budget_ccid%type := null;
45 g_pre_bdgt_ccid PA_BC_PACKETS.budget_ccid%type := null;
46 g_r_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
47 g_r_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
48 g_r_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
49 g_r_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
50 g_r_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
51 g_r_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
52 g_r_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
53 g_rg_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
54 g_rg_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
55 g_rg_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
56 g_rg_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
57 g_rg_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
58 g_rg_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
59 g_rg_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
60 g_t_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
61 g_t_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
62 g_t_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
63 g_t_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
64 g_t_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
65 g_t_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
66 g_t_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
67 g_tt_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
68 g_tt_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
69 g_tt_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
70 g_tt_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
71 g_tt_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
72 g_tt_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
73 g_tt_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
74 g_p_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
75 g_p_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
76 g_p_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
77 g_p_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
78 g_p_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
79 g_p_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
80 g_p_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
81 g_r_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
82 g_rg_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
83 g_t_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
84 g_tt_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
85 g_p_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
86 g_p_acct_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
87 g_r_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
88 g_rg_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
89 g_t_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
90 g_tt_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
91 g_p_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
92 g_p_acct_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
93 g_p_acct_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
94 g_p_acct_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
95 g_exp_project_id pa_bc_packets.project_id%type := null;
96 g_exp_burden_method pa_bc_packets.expenditure_type%type := null;
97
98 -----These variables are added for performance testing
99 g_bal_r_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
100 g_bal_r_task_id PA_BC_PACKETS.TASK_ID%type := null;
101 g_bal_r_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
102 g_bal_r_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
103 g_bal_r_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
104 g_bal_r_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
105 g_bal_r_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
106 g_bal_r_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
107 g_bal_r_entry_level_code VARCHAR2(200) := null;
108 g_bal_r_start_date DATE := null;
109 g_bal_r_end_date DATE := null;
110 g_bal_r_time_phase_code VARCHAR2(20) := null;
111
112 g_pkt_r_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
113 g_pkt_r_task_id PA_BC_PACKETS.TASK_ID%type := null;
114 g_pkt_r_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
115 g_pkt_r_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
116 g_pkt_r_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
117 g_pkt_r_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
118 g_pkt_r_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
119 g_pkt_r_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
120 g_pkt_r_entry_level_code VARCHAR2(200) := null;
121 g_pkt_r_start_date DATE := null;
122 g_pkt_r_end_date DATE := null;
123 g_pkt_r_time_phase_code VARCHAR2(20) := null;
124
125 g_bal_rg_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
126 g_bal_rg_task_id PA_BC_PACKETS.TASK_ID%type := null;
127 g_bal_rg_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
128 g_bal_rg_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
129 g_bal_rg_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
130 g_bal_rg_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
131 g_bal_rg_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
132 g_bal_rg_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
133 g_bal_rg_entry_level_code VARCHAR2(200) := null;
134 g_bal_rg_start_date DATE := null;
135 g_bal_rg_end_date DATE := null;
136 g_bal_rg_time_phase_code VARCHAR2(20) := null;
137
138 g_pkt_rg_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
139 g_pkt_rg_task_id PA_BC_PACKETS.TASK_ID%type := null;
140 g_pkt_rg_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
141 g_pkt_rg_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
142 g_pkt_rg_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
143 g_pkt_rg_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
144 g_pkt_rg_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
145 g_pkt_rg_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
146 g_pkt_rg_entry_level_code VARCHAR2(200) := null;
147 g_pkt_rg_start_date DATE := null;
148 g_pkt_rg_end_date DATE := null;
149 g_pkt_rg_time_phase_code VARCHAR2(20) := null;
150
151 g_bal_t_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
152 g_bal_t_task_id PA_BC_PACKETS.TASK_ID%type := null;
153 g_bal_t_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
154 g_bal_t_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
155 g_bal_t_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
156 g_bal_t_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
157 g_bal_t_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
158 g_bal_t_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
159 g_bal_t_entry_level_code VARCHAR2(200) := null;
160 g_bal_t_start_date DATE := null;
161 g_bal_t_end_date DATE := null;
162 g_bal_t_time_phase_code VARCHAR2(20) := null;
163
164 g_pkt_t_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
165 g_pkt_t_task_id PA_BC_PACKETS.TASK_ID%type := null;
166 g_pkt_t_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
167 g_pkt_t_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
168 g_pkt_t_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
169 g_pkt_t_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
170 g_pkt_t_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
171 g_pkt_t_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
172 g_pkt_t_entry_level_code VARCHAR2(200) := null;
173 g_pkt_t_start_date DATE := null;
174 g_pkt_t_end_date DATE := null;
175 g_pkt_t_time_phase_code VARCHAR2(20) := null;
176
177 g_bal_tt_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
178 g_bal_tt_task_id PA_BC_PACKETS.TASK_ID%type := null;
179 g_bal_tt_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
180 g_bal_tt_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
181 g_bal_tt_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
182 g_bal_tt_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
183 g_bal_tt_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
184 g_bal_tt_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
185 g_bal_tt_entry_level_code VARCHAR2(200) := null;
186 g_bal_tt_start_date DATE := null;
187 g_bal_tt_end_date DATE := null;
188 g_bal_tt_time_phase_code VARCHAR2(20) := null;
189
190 g_pkt_tt_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
191 g_pkt_tt_task_id PA_BC_PACKETS.TASK_ID%type := null;
192 g_pkt_tt_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
193 g_pkt_tt_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
194 g_pkt_tt_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
195 g_pkt_tt_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
196 g_pkt_tt_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
197 g_pkt_tt_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
198 g_pkt_tt_entry_level_code VARCHAR2(200) := null;
199 g_pkt_tt_start_date DATE := null;
200 g_pkt_tt_end_date DATE := null;
201 g_pkt_tt_time_phase_code VARCHAR2(20) := null;
202
203 g_bal_p_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
204 g_bal_p_task_id PA_BC_PACKETS.TASK_ID%type := null;
205 g_bal_p_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
206 g_bal_p_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
207 g_bal_p_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
208 g_bal_p_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
209 g_bal_p_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
210 g_bal_p_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
211 g_bal_p_entry_level_code VARCHAR2(200) := null;
212 g_bal_p_start_date DATE := null;
213 g_bal_p_end_date DATE := null;
214 g_bal_p_time_phase_code VARCHAR2(20) := null;
215
216 g_pkt_p_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
217 g_pkt_p_task_id PA_BC_PACKETS.TASK_ID%type := null;
218 g_pkt_p_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
219 g_pkt_p_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
220 g_pkt_p_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
221 g_pkt_p_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
222 g_pkt_p_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
223 g_pkt_p_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
224 g_pkt_p_entry_level_code VARCHAR2(200) := null;
225 g_pkt_p_start_date DATE := null;
226 g_pkt_p_end_date DATE := null;
227 g_pkt_p_time_phase_code VARCHAR2(20) := null;
228
229
230 g_pkt_p_acct_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
231 g_pkt_p_acct_task_id PA_BC_PACKETS.TASK_ID%type := null;
232 g_pkt_p_acct_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
233 g_pkt_p_acct_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
234 g_pkt_p_acct_bdgt_ccid PA_BC_PACKETS.budget_ccid%type := null;
235 g_pkt_p_acct_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
236 g_pkt_p_acct_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
237 g_pkt_p_acct_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
238 g_pkt_p_acct_entry_level_code VARCHAR2(200) := null;
239 g_pkt_p_acct_start_date DATE := null;
240 g_pkt_p_acct_end_date DATE := null;
241 g_pkt_p_acct_time_phase_code VARCHAR2(20) := null;
242 ------- end of performance varibales declrartions
243
244 --Bug 5964934
245 g_fclc_budget_version_id pa_budget_versions.budget_version_id%type := null;
246 g_fclc_project_id pa_budgetary_controls.project_id%type := null;
247 g_fclc_top_task_id pa_budgetary_controls.top_task_id%type := null;
248 g_fclc_task_id pa_budgetary_controls.task_id%type := null;
249 g_fclc_parent_member_id pa_budgetary_controls.parent_member_id%type := null;
250 g_fclc_resource_list_member_id pa_budgetary_controls.resource_list_member_id%type := null;
251 g_p_funds_control_level_code varchar2(1) := null;
252 g_tt_funds_control_level_code varchar2(1) := null;
253 g_t_funds_control_level_code varchar2(1) := null;
254 g_rg_funds_control_level_code varchar2(1) := null;
255 g_r_funds_control_level_code varchar2(1) := null;
256
257 /**---------------------------------------------------------------------------------
258 -- declare plsql tables to hold values during the funds check process
259 --------------------------------------------------------------------- **/
260 type rowidtabtyp is table of urowid index by binary_integer;
261 g_tab_rowid rowidtabtyp;
262 g_tab_bc_packet_id pa_plsql_datatypes.IdTabTyp;
263 g_tab_p_bc_packet_id pa_plsql_datatypes.IdTabTyp;
264 g_tab_budget_version_id pa_plsql_datatypes.IdTabTyp;
265 g_tab_project_id pa_plsql_datatypes.IdTabTyp;
266 g_tab_task_id pa_plsql_datatypes.IdTabTyp;
267 g_tab_doc_type pa_plsql_datatypes.Char50TabTyp;
268 g_tab_doc_header_id pa_plsql_datatypes.IdTabTyp;
269 g_tab_doc_distribution_id pa_plsql_datatypes.IdTabTyp;
270 g_tab_exp_item_date pa_plsql_datatypes.DateTabTyp;
271 g_tab_exp_org_id pa_plsql_datatypes.IdTabTyp;
272 g_tab_OU pa_plsql_datatypes.IdTabTyp;
273 g_tab_actual_flag pa_plsql_datatypes.char50TabTyp;
274 g_tab_period_name pa_plsql_datatypes.char50TabTyp;
275 g_tab_time_phase_type_code pa_plsql_datatypes.char50TabTyp;
276 g_tab_amount_type pa_plsql_datatypes.char50TabTyp;
277 g_tab_boundary_code pa_plsql_datatypes.char50TabTyp;
278 g_tab_entry_level_code pa_plsql_datatypes.char50TabTyp;
279 g_tab_category_code pa_plsql_datatypes.char50TabTyp;
280 g_tab_rlmi pa_plsql_datatypes.IdTabTyp;
281 g_tab_p_resource_id pa_plsql_datatypes.IdTabTyp;
282 g_tab_r_list_id pa_plsql_datatypes.IdTabTyp;
283 g_tab_p_member_id pa_plsql_datatypes.IdTabTyp;
284 g_tab_bud_task_id pa_plsql_datatypes.IdTabTyp;
285 g_tab_bud_rlmi pa_plsql_datatypes.IdTabTyp;
286 g_tab_tt_task_id pa_plsql_datatypes.IdTabTyp;
287 g_tab_r_fclevel_code pa_plsql_datatypes.char50TabTyp;
288 g_tab_rg_fclevel_code pa_plsql_datatypes.char50TabTyp;
289 g_tab_t_fclevel_code pa_plsql_datatypes.char50TabTyp;
290 g_tab_tt_fclevel_code pa_plsql_datatypes.char50TabTyp;
291 g_tab_p_fclevel_code pa_plsql_datatypes.char50TabTyp;
292 g_tab_p_acct_fclevel_code pa_plsql_datatypes.char50TabTyp;
293 g_tab_burd_cost_flag pa_plsql_datatypes.char50TabTyp;
294 g_tab_pkt_trx_amt pa_plsql_datatypes.NumTabTyp;
295 g_tab_accounted_dr pa_plsql_datatypes.NumTabTyp;
296 g_tab_accounted_cr pa_plsql_datatypes.NumTabTyp;
297 g_tab_PA_amt pa_plsql_datatypes.NumTabTyp;
298 g_tab_PE_amt pa_plsql_datatypes.NumTabTyp;
299 g_tab_status_code pa_plsql_datatypes.char50TabTyp;
300 g_tab_effect_on_funds_code pa_plsql_datatypes.char50TabTyp;
301 g_tab_result_code pa_plsql_datatypes.char50TabTyp;
302 g_tab_r_result_code pa_plsql_datatypes.char50TabTyp;
303 g_tab_rg_result_code pa_plsql_datatypes.char50TabTyp;
304 g_tab_t_result_code pa_plsql_datatypes.char50TabTyp;
305 g_tab_tt_result_code pa_plsql_datatypes.char50TabTyp;
306 g_tab_p_result_code pa_plsql_datatypes.char50TabTyp;
307 g_tab_p_acct_result_code pa_plsql_datatypes.char50TabTyp;
308 g_tab_r_budget_posted pa_plsql_datatypes.NumTabTyp;
309 g_tab_rg_budget_posted pa_plsql_datatypes.NumTabTyp;
310 g_tab_t_budget_posted pa_plsql_datatypes.NumTabTyp;
311 g_tab_tt_budget_posted pa_plsql_datatypes.NumTabTyp;
312 g_tab_p_budget_posted pa_plsql_datatypes.NumTabTyp;
313 g_tab_r_actual_posted pa_plsql_datatypes.NumTabTyp;
314 g_tab_rg_actual_posted pa_plsql_datatypes.NumTabTyp;
315 g_tab_t_actual_posted pa_plsql_datatypes.NumTabTyp;
316 g_tab_tt_actual_posted pa_plsql_datatypes.NumTabTyp;
317 g_tab_p_actual_posted pa_plsql_datatypes.NumTabTyp;
318 g_tab_r_enc_posted pa_plsql_datatypes.NumTabTyp;
319 g_tab_rg_enc_posted pa_plsql_datatypes.NumTabTyp;
320 g_tab_t_enc_posted pa_plsql_datatypes.NumTabTyp;
321 g_tab_tt_enc_posted pa_plsql_datatypes.NumTabTyp;
322 g_tab_p_enc_posted pa_plsql_datatypes.NumTabTyp;
323 g_tab_r_budget_bal pa_plsql_datatypes.NumTabTyp;
324 g_tab_rg_budget_bal pa_plsql_datatypes.NumTabTyp;
325 g_tab_t_budget_bal pa_plsql_datatypes.NumTabTyp;
326 g_tab_tt_budget_bal pa_plsql_datatypes.NumTabTyp;
327 g_tab_p_budget_bal pa_plsql_datatypes.NumTabTyp;
328 g_tab_r_actual_approved pa_plsql_datatypes.NumTabTyp;
329 g_tab_rg_actual_approved pa_plsql_datatypes.NumTabTyp;
330 g_tab_t_actual_approved pa_plsql_datatypes.NumTabTyp;
331 g_tab_tt_actual_approved pa_plsql_datatypes.NumTabTyp;
332 g_tab_p_actual_approved pa_plsql_datatypes.NumTabTyp;
333 g_tab_r_enc_approved pa_plsql_datatypes.NumTabTyp;
334 g_tab_rg_enc_approved pa_plsql_datatypes.NumTabTyp;
335 g_tab_t_enc_approved pa_plsql_datatypes.NumTabTyp;
336 g_tab_tt_enc_approved pa_plsql_datatypes.NumTabTyp;
337 g_tab_p_enc_approved pa_plsql_datatypes.NumTabTyp;
338 g_tab_trxn_ccid pa_plsql_datatypes.Idtabtyp;
339 g_tab_budget_ccid pa_plsql_datatypes.Idtabtyp;
340 g_tab_old_budget_ccid pa_plsql_datatypes.Idtabtyp;
341 g_tab_effect_fclevel pa_plsql_datatypes.char50TabTyp;
342 g_tab_exp_category pa_plsql_datatypes.char50TabTyp;
343 g_tab_rev_category pa_plsql_datatypes.char50TabTyp;
344 g_tab_sys_link_func pa_plsql_datatypes.char50TabTyp;
345 g_tab_exp_type pa_plsql_datatypes.char50TabTyp;
346 g_tab_gl_date pa_plsql_datatypes.Datetabtyp;
347 g_tab_pa_date pa_plsql_datatypes.Datetabtyp;
348 g_tab_start_date pa_plsql_datatypes.Datetabtyp;
349 g_tab_end_date pa_plsql_datatypes.Datetabtyp;
350 g_tab_encum_type_id pa_plsql_datatypes.Idtabtyp;
351 g_tab_process_funds_level pa_plsql_datatypes.char50TabTyp;
352 g_tab_res_level_cache_amt pa_plsql_datatypes.NumTabTyp;
353 g_tab_res_grp_level_cache_amt pa_plsql_datatypes.NumTabTyp;
354 g_tab_task_level_cache_amt pa_plsql_datatypes.NumTabTyp;
355 g_tab_top_task_level_cache_amt pa_plsql_datatypes.NumTabTyp;
356 g_tab_proj_level_cache_amt pa_plsql_datatypes.NumTabTyp;
357 g_tab_prj_acct_level_cache_amt pa_plsql_datatypes.NumTabTyp;
358 /* Bug 9750534: Modified the below cache global variables from Char50TabTyp to Char100TabTyp */
359 g_tab_res_level_cache pa_plsql_datatypes.char100TabTyp;
360 g_tab_res_grp_level_cache pa_plsql_datatypes.char100TabTyp;
361 g_tab_task_level_cache pa_plsql_datatypes.char100TabTyp;
362 g_tab_top_task_level_cache pa_plsql_datatypes.char100TabTyp;
363 g_tab_proj_level_cache pa_plsql_datatypes.char100TabTyp;
364 g_tab_proj_acct_level_cache pa_plsql_datatypes.char100TabTyp;
365 g_tab_tieback_id pa_plsql_datatypes.char250TabTyp;
366 g_tab_group_resource_type_id pa_plsql_datatypes.NumTabTyp; /* bug fix 2658952 */
367 g_tab_person_id pa_plsql_datatypes.Idtabtyp;
368 g_tab_job_id pa_plsql_datatypes.Idtabtyp;
369 g_tab_vendor_id pa_plsql_datatypes.Idtabtyp;
370 g_tab_non_lab_res pa_plsql_datatypes.char250TabTyp;
371 g_tab_non_lab_res_org pa_plsql_datatypes.Idtabtyp;
372 g_tab_non_cat_rlmi pa_plsql_datatypes.Idtabtyp;
373 g_tab_proj_OU pa_plsql_datatypes.Idtabtyp;
374 g_tab_exp_OU pa_plsql_datatypes.Idtabtyp;
375 g_tab_doc_line_id pa_plsql_datatypes.Idtabtyp;
376 g_tab_ext_bdgt_link pa_plsql_datatypes.char50TabTyp;
377 g_tab_sob_id pa_plsql_datatypes.Idtabtyp;
378 g_tab_exp_gl_date pa_plsql_datatypes.DateTabTyp;
379 g_tab_exp_pa_date pa_plsql_datatypes.DateTabTyp; /*9487097 */
380 g_tab_exp_item_id pa_plsql_datatypes.Idtabtyp;
381
382 /* Bug 5631763 */
383 g_Tfund_control_level pa_budgetary_control_options.fund_control_level_task%type;
384 g_Pfund_control_level pa_budgetary_control_options.fund_control_level_project%type;
385 g_RGfund_control_level pa_budgetary_control_options.fund_control_level_res_grp%type;
386 g_Rfund_control_level pa_budgetary_control_options.fund_control_level_res%type;
387 /* Bug 5631763 */
388
389 -- Added for R12 ...
390 g_tab_burden_method_code pa_plsql_datatypes.char50TabTyp;
391 g_tab_budget_line_id pa_plsql_datatypes.IdTabTyp;
392 g_tab_src_dist_id_num_1 pa_plsql_datatypes.Idtabtyp;
393 g_tab_gl_bc_event_id pa_plsql_datatypes.Idtabtyp;
394 g_tab_src_dist_type pa_plsql_datatypes.char50TabTyp;
395 g_tab_allow_flag pa_plsql_datatypes.Char1TabTyp;
396 g_packet_credit_processed Varchar2(1);
397 g_packet_debit_processed Varchar2(1);
398
399
400 /**---------------------------------------------------------------------------------
401 -- declare a plsql record to hold values during the funds check process
402 ---------------------------------------------------------------------------------**/
403 TYPE PA_FC_RECORD is RECORD (
404 packet_id pa_bc_packets.packet_id%type,
405 bc_packet_id pa_bc_packets.bc_packet_id%type,
406 set_of_books_id pa_bc_packets.set_of_books_id%type,
407 budget_version_id pa_bc_packets.budget_version_id%type,
408 project_id pa_bc_packets.project_id%type,
409 task_id pa_bc_packets.task_id%type,
410 document_type pa_bc_packets.document_type%type,
411 document_header_id pa_bc_packets.document_header_id%type,
412 document_distribution_id pa_bc_packets.document_distribution_id%type,
413 expenditure_item_date pa_bc_packets.expenditure_item_date%type,
414 expenditure_organization_id pa_bc_packets.expenditure_organization_id%type,
415 exp_type pa_bc_packets.expenditure_type%type,
416 actual_flag pa_bc_packets.actual_flag%type,
417 period_name pa_bc_packets.period_name%type,
418 time_phased_type_code VARCHAR2(30),
419 amount_type VARCHAR2(15),
420 boundary_code VARCHAR2(15),
421 entry_level_code VARCHAR2(10),
422 categorization_code VARCHAR2(10),
423 resource_list_member_id pa_bc_packets.resource_list_member_id%TYPE,
424 parent_resource_id pa_bc_packets.parent_resource_id%type,
425 resource_list_id NUMBER,
426 parent_member_id NUMBER,
427 bud_task_id pa_bc_packets.bud_task_id%type,
428 bud_resource_list_member_id pa_bc_packets.bud_resource_list_member_id%type,
429 top_task_id pa_bc_packets.top_task_id%type,
430 r_funds_control_level_code pa_bc_packets.r_funds_control_level_code%type,
431 rg_funds_control_level_code pa_bc_packets.rg_funds_control_level_code%type,
432 t_funds_control_level_code pa_bc_packets.t_funds_control_level_code%type,
433 tt_funds_control_level_code pa_bc_packets.tt_funds_control_level_code%type,
434 p_funds_control_level_code pa_bc_packets.p_funds_control_level_code%type,
435 burdened_cost_flag VARCHAR2(10),
436 accounted_dr pa_bc_packets.accounted_dr%type,
437 accounted_cr pa_bc_packets.accounted_dr%type,
438 status_code pa_bc_packets.status_code%type,
439 r_budget_posted pa_bc_packets.res_budget_posted%type,
440 rg_budget_posted pa_bc_packets.res_budget_posted%type,
441 t_budget_posted pa_bc_packets.res_budget_posted%type,
442 tt_budget_posted pa_bc_packets.res_budget_posted%type,
443 p_budget_posted pa_bc_packets.res_budget_posted%type,
444 r_actual_posted pa_bc_packets.res_budget_posted%type,
445 rg_actual_posted pa_bc_packets.res_budget_posted%type,
446 t_actual_posted pa_bc_packets.res_budget_posted%type,
447 tt_actual_posted pa_bc_packets.res_budget_posted%type,
448 p_actual_posted pa_bc_packets.res_budget_posted%type,
449 r_enc_posted pa_bc_packets.res_budget_posted%type,
450 rg_enc_posted pa_bc_packets.res_budget_posted%type,
451 t_enc_posted pa_bc_packets.res_budget_posted%type,
452 tt_enc_posted pa_bc_packets.res_budget_posted%type,
453 p_enc_posted pa_bc_packets.res_budget_posted%type,
454 r_budget_bal pa_bc_packets.res_budget_posted%type,
455 rg_budget_bal pa_bc_packets.res_budget_posted%type,
456 t_budget_bal pa_bc_packets.res_budget_posted%type,
457 tt_budget_bal pa_bc_packets.res_budget_posted%type,
458 p_budget_bal pa_bc_packets.res_budget_posted%type,
459 r_actual_approved pa_bc_packets.res_budget_posted%type,
460 rg_actual_approved pa_bc_packets.res_budget_posted%type,
461 t_actual_approved pa_bc_packets.res_budget_posted%type,
462 tt_actual_approved pa_bc_packets.res_budget_posted%type,
463 p_actual_approved pa_bc_packets.res_budget_posted%type,
464 r_enc_approved pa_bc_packets.res_budget_posted%type,
465 rg_enc_approved pa_bc_packets.res_budget_posted%type,
466 t_enc_approved pa_bc_packets.res_budget_posted%type,
467 tt_enc_approved pa_bc_packets.res_budget_posted%type,
468 p_enc_approved pa_bc_packets.res_budget_posted%type,
469 result_code pa_bc_packets.result_code%type,
470 r_result_code pa_bc_packets.res_result_code%type,
471 rg_result_code pa_bc_packets.res_grp_result_code%type,
472 t_result_code pa_bc_packets.task_result_code%type,
473 tt_result_code pa_bc_packets.top_task_result_code%type,
474 p_result_code pa_bc_packets.project_result_code%type,
475 p_acct_result_code pa_bc_packets.project_result_code%type,
476 trxn_ccid pa_bc_packets.txn_ccid%type,
477 budget_ccid pa_bc_packets.budget_ccid%type,
478 effect_on_funds_code pa_bc_packets.effect_on_funds_code%type,
479 gl_date pa_bc_packets.expenditure_item_date%type,
480 pa_date pa_bc_packets.expenditure_item_date%type,
481 parent_bc_packet_id pa_bc_packets.bc_packet_id%type,
482 group_resource_type_id Number
483 );
484
485 -- -------------------------- R12 Changes Start -------------------------------------+
486
487 Type TypeNum is table of number index by binary_integer;
488 Type TypeVarChar is table of varchar2(50) index by binary_integer;
489 Type TypeDate is table of date index by binary_integer;
490 l_limit NUMBER(4);
491 l_program_name VARCHAR2(30);
492 g_event_id TypeNum;
493 g_doc_dist_id TypeNum;
494 g_document_type TypeVarChar;
495 g_ap_matched_case Varchar2(1);
496
497 -- This procedure will execute the budget account validation, account level FC
498 -- and update budget lines with the new derived accounts, call PROCEDURE
499 -- Build_account_summary to build pa_budget_acct_lines
500
501 PROCEDURE DO_BUDGET_BASELINE_TIEBACK(p_packet_id IN NUMBER,
502 p_return_status OUT NOCOPY VARCHAR2);
503
504 -- This procedure will build pa_budget_acct_lines
505 -- Called from DO_BUDGET_BASELINE_TIEBACK
506
507 PROCEDURE Build_account_summary(P_budget_version_id IN NUMBER,
508 P_balance_type IN VARCHAR2,
509 P_budget_amount_code IN VARCHAR2,
510 P_prev_budget_version_id IN NUMBER);
511
512 -- This procedure is an autonomus procedure that calls Build_account_summary
513 -- Called from DO_BUDGET_BASELINE_TIEBACK
514
515 PROCEDURE Build_account_summary_auto(X_budget_version_id IN NUMBER,
516 X_balance_type IN VARCHAR2,
517 X_budget_amount_code IN VARCHAR2,
518 X_prev_budget_version_id IN NUMBER,
519 X_mode IN VARCHAR2);
520
521 -- This procedure will update pa_bc_packets records with a failure status.
522 -- This procedure is an AUTONOMOUS procedure
523 -- This procedure will be called from do_budget_baseline_tieback
524
525 PROCEDURE Fail_bc_pkt_during_baseline(P_budget_version_id IN NUMBER,
526 P_period_name IN g_tab_period_name%TYPE,
527 P_budget_ccid IN g_tab_budget_ccid%TYPE,
528 P_allow_flag IN g_tab_allow_flag%TYPE,
529 P_result_code IN VARCHAR2);
530
531 -- This procedure will update pa_budget_acct_lines with a failure status.
532 -- This procedure is an AUTONOMOUS procedure
533 -- This procedure will be called from do_budget_baseline_tieback
534
535 PROCEDURE Update_failure_in_acct_summary(P_budget_version_id IN NUMBER,
536 P_period_name IN g_tab_period_name%TYPE,
537 P_budget_ccid IN g_tab_budget_ccid%TYPE,
538 P_allow_flag IN g_tab_allow_flag%TYPE,
539 P_result_code IN VARCHAR2);
540
541 -- Procedure Update_budget_ccid updated budget_ccid on the pa_bc_packet records
542 -- for this baseline, its an AUTONOMOUS procedure ..
543
544 PROCEDURE Update_budget_ccid(P_budget_version_id IN NUMBER,
545 P_budget_ccid IN g_tab_budget_ccid%TYPE,
546 P_budget_line_id IN g_tab_budget_line_id%TYPE,
547 P_budget_entry_level_code IN VARCHAR2,
548 P_period_name IN g_tab_period_name%TYPE,
549 P_rlmi IN g_tab_rlmi%TYPE,
550 P_task_id IN g_tab_task_id%TYPE,
551 P_derived_ccid IN g_tab_budget_ccid%TYPE,
552 P_allowed_flag IN g_tab_allow_flag%TYPE,
553 P_result_code IN OUT NOCOPY VARCHAR2);
554
555 -- --------------------------------------------------------------------------------+
556 -- This procedure will mark gl_bc_packets records to a status such that GL does
557 -- not execute funds available validation. Previously we used to create liquidation
558 -- entries. Instead of that, we're executing the following procedure.
559 -- This is for NO/SEPARATE LINE BURDENING only.
560 -- This procedure is called from function pa_funds_check
561 -- --------------------------------------------------------------------------------+
562 -- PROCEDURE Mark_gl_bc_packets_for_no_fc (p_packet_id IN Number);
563
564 -- --------------------------------------------------------------------------------+
565 -- This procedure will determine whether funds check/ funds check tieback
566 -- has been called for non-project related/project related txn. or budget
567 -- funds check.
568 -- p_return_code: 'NO_FC', For non-project related FC
569 -- p_return_code: 'TXN_FC',For project related txn. (including 'RESERVE_BASELINE')
570 -- p_return_code: 'BUD_FC',For SLA-BC budget baseline integration (GL FC)
571 -- --------------------------------------------------------------------------------+
572 PROCEDURE Check_txn_or_budget_fc(p_packet_id in number,
573 p_return_code out NOCOPY varchar2);
574
575 -- --------------------------------------------------------------------------------+
576 -- This procedure will update the following columns in pa_bc_packets: serial_id,
577 -- session_id,actual_flag,packet_id and status. Status will be upated from I to P.
578 -- Called from pa_funds_check
579 -- This procedure will also check if the extracts were successful, meaning that:
580 -- A. pa_bc_packet records have been extracted into gl_bc_packets
581 -- B. core records have been extracted into gl_bc_packets
582 -- C. project relieveing entries are created in gl_bc_packets
583 -- --------------------------------------------------------------------------------+
584 PROCEDURE Synch_pa_gl_packets(x_packet_id IN Number,
585 x_partial_flag IN VARCHAR2,
586 x_mode IN VARCHAR2,
587 x_result_code OUT NOCOPY Varchar2);
588
589 -- --------------------------------------------------------------------------------+
590 -- Following procedure resets funds_check_status_code and result code on
591 -- pa_budget_acct_lines for the draft version ..
592 -- --------------------------------------------------------------------------------+
593 PROCEDURE Reset_status_code_on_summary(p_budget_version_id IN Number);
594
595 -- --------------------------------------------------------------------------------+
596 -- This procedure is called from Synch_pa_gl_packets to AUTONOMOUSLY update
597 -- pa_bc_packets with failure....in case of extract failing ..
598 -- -------------------------------------------------------------------------------+
599 PROCEDURE Missing_records_failure(p_pa_packet_id IN NUMBER,
600 p_gl_packet_id IN NUMBER,
601 p_partial_flag IN VARCHAR2,
602 p_mode IN VARCHAR2);
603
604 -- --------------------------------------------------------------------------------+
605 -- This procedure is called from Synch_pa_gl_packets to update: serial_id,
606 -- session_id, actual_flag,packet_id and status ..
607 -- --------------------------------------------------------------------------------+
608 PROCEDURE Synch_data(p_pa_packet_id IN NUMBER,
609 p_gl_packet_id IN NUMBER);
610
611 -- --------------------------------------------------------------------------------+
612 -- This procedure will be called from do_budget_baseline to update pa_bc_packet
613 -- project_acct_result_code and result_code to 'P101' after account level funds
614 -- check is successful. Procedure is AUTONOMOUS
615 -- --------------------------------------------------------------------------------+
616 PROCEDURE Upd_bc_pkt_acct_result_code(P_budget_version_id IN NUMBER);
617
618 -- --------------------------------------------------------------------------------+
619 -- This procedure will check if there exists any txn. against the project
620 -- It will return 'Y' if any txn exists
621 -- --------------------------------------------------------------------------------+
622 Procedure Any_txns_against_project(p_project_id IN NUMBER,
623 p_txn_exists_in_bc_pkt OUT NOCOPY VARCHAR2,
624 p_txn_exists_in_bc_cmt OUT NOCOPY VARCHAR2);
625
626 -- --------------------------------------------------------------------------------+
627 -- This procedure has been created to handle FULL MODE failure during check funds
628 -- action of an invoice that is matched to PO .. bug 5253309
629 -- p_case added to handle future scenarios..
630 -- This is reqd. especially for scenarios where AP has multiple distributions and
631 -- some are matched to PO, in such cases the doc. is in 'PARTIAL MODE' but matched
632 -- dist. is treated in FULL MODE.
633 -- --------------------------------------------------------------------------------+
634 Procedure Full_mode_failure(p_packet_id IN NUMBER,
635 p_case IN VARCHAR2);
636
637 -- --------------------------------------------------------------------------------+
638 -- This autonomous procedure is called to update the newly derived account info.
639 -- back onto the draft budget lines during baseline/yearend ..
640 -- --------------------------------------------------------------------------------+
641 PROCEDURE Upd_new_acct_on_draft_budget(p_budget_line_rowid IN g_tab_rowid%TYPE,
642 p_budget_ccid IN g_tab_budget_ccid%TYPE,
643 p_new_ccid IN g_tab_budget_ccid%TYPE,
644 p_change_allowed IN g_tab_allow_flag%TYPE,
645 p_record_updated OUT NOCOPY Varchar2);
646
647 -- --------------------------------------------------------------------------------+
648 -- This procedure will fail data in the other packet .. i.e. the credit packet ..
649 -- --------------------------------------------------------------------------------+
650 PROCEDURE Fail_credit_packet(p_input_packet IN Varchar2,
651 p_return_status_code OUT NOCOPY varchar2);
652
653 -- -------------------------- R12 Changes End -------------------------------------+
654
655 /**-------------------------------------------------------------------------------
656 -- Procedure to Initialize the global variables
657 -------------------------------------------------------------------------------**/
658 PROCEDURE Initialize_globals IS
659
660 BEGIN
661
662
663 g_error_stage := null;
664 g_error_msg := null;
665 g_project_id := null;
666 g_task_id := null;
667 g_top_task_id := null;
668 g_bdgt_version_id := null;
669 g_bud_task_id := null;
670 g_rlmi := null;
671 g_bud_rlmi := null;
672 g_prlmi := null;
673 g_entry_level_code := null;
674 g_start_date := null;
675 g_end_date := null;
676 g_time_phase_code := null;
677 g_pre_project_id := null;
678 g_pre_task_id := null;
679 g_pre_top_task_id := null;
680 g_pre_bdgt_version_id := null;
681 g_pre_bud_task_id := null;
682 g_pre_rlmi := null;
683 g_pre_bud_rlmi := null;
684 g_pre_prlmi := null;
685 g_pre_entry_level_code := null;
686 g_pre_start_date := null;
687 g_pre_end_date := null;
688 g_pre_time_phase_code := null;
689 g_r_budget_posted := null;
690 g_r_actual_posted := null;
691 g_r_enc_posted := null;
692 g_r_enc_approved := null;
693 g_r_enc_pending := null;
694 g_r_actual_approved := null;
695 g_r_budget_posted := null;
696 g_r_actual_posted := null;
697 g_r_enc_posted := null;
698 g_r_enc_approved := null;
699 g_r_enc_pending := null;
700 g_r_actual_approved := null;
701 g_r_actual_pending := null;
702 g_rg_budget_posted := null;
703 g_rg_actual_posted := null;
704 g_rg_enc_posted := null;
705 g_rg_enc_approved := null;
706 g_rg_enc_pending := null;
707 g_rg_actual_approved := null;
708 g_rg_actual_pending := null;
709 g_t_budget_posted := null;
710 g_t_actual_posted := null;
711 g_t_enc_posted := null;
712 g_t_enc_approved := null;
713 g_t_enc_pending := null;
714 g_t_actual_approved := null;
715 g_t_actual_pending := null;
716 g_tt_budget_posted := null;
717 g_tt_actual_posted := null;
718 g_tt_enc_posted := null;
719 g_tt_enc_approved := null;
720 g_tt_enc_pending := null;
721 g_tt_actual_approved := null;
722 g_tt_actual_pending := null;
723 g_p_budget_posted := null;
724 g_p_actual_posted := null;
725 g_p_enc_posted := null;
726 g_p_enc_approved := null;
727 g_p_enc_pending := null;
728 g_p_actual_approved := null;
729 g_p_actual_pending := null;
730 g_r_pkt_amt := null;
731 g_rg_pkt_amt := null;
732 g_t_pkt_amt := null;
733 g_tt_pkt_amt := null;
734 g_p_pkt_amt := null;
735 g_p_acct_pkt_amt := null;
736 g_r_base_amt := null;
737 g_rg_base_amt := null;
738 g_t_base_amt := null;
739 g_tt_base_amt := null;
740 g_p_base_amt := null;
741 g_p_acct_base_amt := null;
742 g_bdgt_ccid := null;
743 g_pre_bdgt_ccid := null;
744 g_p_acct_enc_approved := null;
745 g_p_acct_actual_approved := null;
746 g_exp_burden_method := null;
747 g_exp_project_id := null;
748
749 -----for performance testing these variables added
750 g_bal_r_project_id := null;
751 g_bal_r_task_id := null;
752 g_bal_r_top_task_id := null;
753 g_bal_r_bdgt_version_id := null;
754 g_bal_r_bud_task_id := null;
755 g_bal_r_rlmi := null;
756 g_bal_r_bud_rlmi := null;
757 g_bal_r_prlmi := null;
758 g_bal_r_entry_level_code := null;
759 g_bal_r_start_date := null;
760 g_bal_r_end_date := null;
761 g_bal_r_time_phase_code := null;
762
763 g_pkt_r_project_id := null;
764 g_pkt_r_task_id := null;
765 g_pkt_r_top_task_id := null;
766 g_pkt_r_bdgt_version_id := null;
767 g_pkt_r_bud_task_id := null;
768 g_pkt_r_rlmi := null;
769 g_pkt_r_bud_rlmi := null;
770 g_pkt_r_prlmi := null;
771 g_pkt_r_entry_level_code := null;
772 g_pkt_r_start_date := null;
773 g_pkt_r_end_date := null;
774 g_pkt_r_time_phase_code := null;
775
776 g_bal_rg_project_id := null;
777 g_bal_rg_task_id := null;
778 g_bal_rg_top_task_id := null;
779 g_bal_rg_bdgt_version_id := null;
780 g_bal_rg_bud_task_id := null;
781 g_bal_rg_rlmi := null;
782 g_bal_rg_bud_rlmi := null;
783 g_bal_rg_prlmi := null;
784 g_bal_rg_entry_level_code := null;
785 g_bal_rg_start_date := null;
786 g_bal_rg_end_date := null;
787 g_bal_rg_time_phase_code := null;
788
789 g_pkt_rg_project_id := null;
790 g_pkt_rg_task_id := null;
791 g_pkt_rg_top_task_id := null;
792 g_pkt_rg_bdgt_version_id := null;
793 g_pkt_rg_bud_task_id := null;
794 g_pkt_rg_rlmi := null;
795 g_pkt_rg_bud_rlmi := null;
796 g_pkt_rg_prlmi := null;
797 g_pkt_rg_entry_level_code := null;
798 g_pkt_rg_start_date := null;
799 g_pkt_rg_end_date := null;
800 g_pkt_rg_time_phase_code := null;
801
802 g_bal_t_project_id := null;
803 g_bal_t_task_id := null;
804 g_bal_t_top_task_id := null;
805 g_bal_t_bdgt_version_id := null;
806 g_bal_t_bud_task_id := null;
807 g_bal_t_rlmi := null;
808 g_bal_t_bud_rlmi := null;
809 g_bal_t_prlmi := null;
810 g_bal_t_entry_level_code := null;
811 g_bal_t_start_date := null;
812 g_bal_t_end_date := null;
813 g_bal_t_time_phase_code := null;
814
815 g_pkt_t_project_id := null;
816 g_pkt_t_task_id := null;
817 g_pkt_t_top_task_id := null;
818 g_pkt_t_bdgt_version_id := null;
819 g_pkt_t_bud_task_id := null;
820 g_pkt_t_rlmi := null;
821 g_pkt_t_bud_rlmi := null;
822 g_pkt_t_prlmi := null;
823 g_pkt_t_entry_level_code := null;
824 g_pkt_t_start_date := null;
825 g_pkt_t_end_date := null;
826 g_pkt_t_time_phase_code := null;
827
828 g_bal_tt_project_id := null;
829 g_bal_tt_task_id := null;
830 g_bal_tt_top_task_id := null;
831 g_bal_tt_bdgt_version_id := null;
832 g_bal_tt_bud_task_id := null;
833 g_bal_tt_rlmi := null;
834 g_bal_tt_bud_rlmi := null;
835 g_bal_tt_prlmi := null;
836 g_bal_tt_entry_level_code := null;
837 g_bal_tt_start_date := null;
838 g_bal_tt_end_date := null;
839 g_bal_tt_time_phase_code := null;
840
841 g_pkt_tt_project_id := null;
842 g_pkt_tt_task_id := null;
843 g_pkt_tt_top_task_id := null;
844 g_pkt_tt_bdgt_version_id := null;
845 g_pkt_tt_bud_task_id := null;
846 g_pkt_tt_rlmi := null;
847 g_pkt_tt_bud_rlmi := null;
848 g_pkt_tt_prlmi := null;
849 g_pkt_tt_entry_level_code := null;
850 g_pkt_tt_start_date := null;
851 g_pkt_tt_end_date := null;
852 g_pkt_tt_time_phase_code := null;
853
854 g_bal_p_project_id := null;
855 g_bal_p_task_id := null;
856 g_bal_p_top_task_id := null;
857 g_bal_p_bdgt_version_id := null;
858 g_bal_p_bud_task_id := null;
859 g_bal_p_rlmi := null;
860 g_bal_p_bud_rlmi := null;
861 g_bal_p_prlmi := null;
862 g_bal_p_entry_level_code := null;
863 g_bal_p_start_date := null;
864 g_bal_p_end_date := null;
865 g_bal_p_time_phase_code := null;
866
867 g_pkt_p_project_id := null;
868 g_pkt_p_task_id := null;
869 g_pkt_p_top_task_id := null;
870 g_pkt_p_bdgt_version_id := null;
871 g_pkt_p_bud_task_id := null;
872 g_pkt_p_rlmi := null;
873 g_pkt_p_bud_rlmi := null;
874 g_pkt_p_prlmi := null;
875 g_pkt_p_entry_level_code := null;
876 g_pkt_p_start_date := null;
877 g_pkt_p_end_date := null;
878 g_pkt_p_time_phase_code := null;
879
880
881 g_pkt_p_acct_project_id := null;
882 g_pkt_p_acct_task_id := null;
883 g_pkt_p_acct_bdgt_ccid := null;
884 g_pkt_p_acct_bdgt_version_id := null;
885 --g_pkt_p_acct_bud_task_id := null;
886 g_pkt_p_acct_rlmi := null;
887 g_pkt_p_acct_bud_rlmi := null;
888 g_pkt_p_acct_prlmi := null;
889 g_pkt_p_acct_entry_level_code := null;
890 g_pkt_p_acct_start_date := null;
891 g_pkt_p_acct_end_date := null;
892 g_pkt_p_acct_time_phase_code := null;
893 --- end of cache variables for resource level bal and pkt
894
895
896 -- clear plsql tabs
897 g_tab_res_level_cache_amt.delete;
898 g_tab_res_grp_level_cache_amt.delete;
899 g_tab_task_level_cache_amt.delete;
900 g_tab_top_task_level_cache_amt.delete;
901 g_tab_proj_level_cache_amt.delete;
902 g_tab_prj_acct_level_cache_amt.delete;
903 g_tab_res_level_cache.delete;
904 g_tab_res_grp_level_cache.delete;
905 g_tab_task_level_cache.delete;
906 g_tab_top_task_level_cache.delete;
907 g_tab_proj_level_cache.delete;
908 g_tab_proj_acct_level_cache.delete;
909
910 END Initialize_globals;
911 /**-----------------------------------------------------------------------------
912 --Procedure to initialize the value of the record to zero after every loop.
913 ------------------------------------------------------------------------------**/
914 PROCEDURE initialize_record (
915 pa_bc_rec_ini IN OUT NOCOPY pa_fc_record ) IS
916 x_err_code NUMBER;
917 x_err_buff VARCHAR2 ( 2000 );
918 BEGIN
919 pa_bc_rec_ini.packet_id := 0;
920 pa_bc_rec_ini.bc_packet_id := 0;
921 pa_bc_rec_ini.set_of_books_id := 0;
922 pa_bc_rec_ini.budget_version_id := 0;
923 pa_bc_rec_ini.project_id := 0;
924 pa_bc_rec_ini.task_id := 0;
925 pa_bc_rec_ini.document_type := null;
926 pa_bc_rec_ini.document_header_id := 0;
927 pa_bc_rec_ini.document_distribution_id := 0;
928 pa_bc_rec_ini.expenditure_item_date := NULL;
929 pa_bc_rec_ini.expenditure_organization_id := 0;
930 pa_bc_rec_ini.exp_type := null;
931 pa_bc_rec_ini.actual_flag := NULL;
932 pa_bc_rec_ini.period_name := NULL;
933 pa_bc_rec_ini.time_phased_type_code := NULL;
934 pa_bc_rec_ini.amount_type := NULL;
935 pa_bc_rec_ini.boundary_code := NULL;
936 pa_bc_rec_ini.entry_level_code := NULL;
937 pa_bc_rec_ini.categorization_code := NULL;
938 pa_bc_rec_ini.resource_list_member_id := 0;
939 pa_bc_rec_ini.parent_resource_id := 0;
940 pa_bc_rec_ini.resource_list_id := 0;
941 pa_bc_rec_ini.parent_member_id := 0;
942 pa_bc_rec_ini.bud_task_id := 0;
943 pa_bc_rec_ini.bud_resource_list_member_id := 0;
944 pa_bc_rec_ini.top_task_id := 0;
945 pa_bc_rec_ini.r_funds_control_level_code := NULL;
946 pa_bc_rec_ini.rg_funds_control_level_code := NULL;
947 pa_bc_rec_ini.t_funds_control_level_code := NULL;
948 pa_bc_rec_ini.tt_funds_control_level_code := NULL;
949 pa_bc_rec_ini.p_funds_control_level_code := NULL;
950 pa_bc_rec_ini.burdened_cost_flag := NULL;
951 pa_bc_rec_ini.accounted_dr := 0;
952 pa_bc_rec_ini.accounted_cr := 0;
953 pa_bc_rec_ini.status_code := 0;
954 pa_bc_rec_ini.r_budget_posted := 0;
955 pa_bc_rec_ini.rg_budget_posted := 0;
956 pa_bc_rec_ini.t_budget_posted := 0;
957 pa_bc_rec_ini.tt_budget_posted := 0;
958 pa_bc_rec_ini.p_budget_posted := 0;
959 pa_bc_rec_ini.r_actual_posted := 0;
960 pa_bc_rec_ini.rg_actual_posted := 0;
961 pa_bc_rec_ini.t_actual_posted := 0;
962 pa_bc_rec_ini.tt_actual_posted := 0;
963 pa_bc_rec_ini.p_actual_posted := 0;
964 pa_bc_rec_ini.r_enc_posted := 0;
965 pa_bc_rec_ini.rg_enc_posted := 0;
966 pa_bc_rec_ini.t_enc_posted := 0;
967 pa_bc_rec_ini.tt_enc_posted := 0;
968 pa_bc_rec_ini.p_enc_posted := 0;
969 pa_bc_rec_ini.r_budget_bal := 0;
970 pa_bc_rec_ini.rg_budget_bal := 0;
971 pa_bc_rec_ini.t_budget_bal := 0;
972 pa_bc_rec_ini.tt_budget_bal := 0;
973 pa_bc_rec_ini.p_budget_bal := 0;
974 pa_bc_rec_ini.r_actual_approved := 0;
975 pa_bc_rec_ini.rg_actual_approved := 0;
976 pa_bc_rec_ini.t_actual_approved := 0;
977 pa_bc_rec_ini.tt_actual_approved := 0;
978 pa_bc_rec_ini.p_actual_approved := 0;
979 pa_bc_rec_ini.r_enc_approved := 0;
980 pa_bc_rec_ini.rg_enc_approved := 0;
981 pa_bc_rec_ini.t_enc_approved := 0;
982 pa_bc_rec_ini.tt_enc_approved := 0;
983 pa_bc_rec_ini.p_enc_approved := 0;
984 pa_bc_rec_ini.result_code := NULL;
985 pa_bc_rec_ini.r_result_code := NULL;
986 pa_bc_rec_ini.rg_result_code := NULL;
987 pa_bc_rec_ini.t_result_code := NULL;
988 pa_bc_rec_ini.tt_result_code := NULL;
989 pa_bc_rec_ini.p_result_code := NULL;
990 pa_bc_rec_ini.p_acct_result_code := NULL;
991 pa_bc_rec_ini.trxn_ccid := NULL;
992 pa_bc_rec_ini.budget_ccid := NULL;
993 pa_bc_rec_ini.effect_on_funds_code := NULL;
994 pa_bc_rec_ini.gl_date := NULL;
995 pa_bc_rec_ini.pa_date := NULL;
996 pa_bc_rec_ini.parent_bc_packet_id := 0;
997 pa_bc_rec_ini.group_resource_type_id := null;
998
999
1000 EXCEPTION
1001 WHEN OTHERS THEN
1002 Commit;
1003 RAISE;
1004 END initialize_record;
1005
1006
1007 /**--------------------------------------------------------------------------
1008 -- This api initializes the pl/sql tables
1009 -------------------------------------------------------------------------- **/
1010 PROCEDURE init_plsql_tabs IS
1011
1012 BEGIN
1013 g_tab_rowid.delete;
1014 g_tab_bc_packet_id.delete;
1015 g_tab_p_bc_packet_id.delete;
1016 g_tab_budget_version_id.delete;
1017 g_tab_project_id.delete;
1018 g_tab_task_id.delete;
1019 g_tab_doc_type.delete;
1020 g_tab_doc_header_id.delete;
1021 g_tab_doc_distribution_id.delete;
1022 g_tab_exp_item_date.delete;
1023 g_tab_exp_org_id.delete;
1024 g_tab_OU.delete;
1025 g_tab_actual_flag.delete;
1026 g_tab_period_name.delete;
1027 g_tab_time_phase_type_code.delete;
1028 g_tab_amount_type.delete;
1029 g_tab_boundary_code.delete;
1030 g_tab_entry_level_code.delete;
1031 g_tab_category_code.delete;
1032 g_tab_rlmi.delete;
1033 g_tab_p_resource_id.delete;
1034 g_tab_r_list_id.delete;
1035 g_tab_p_member_id.delete;
1036 g_tab_bud_task_id.delete;
1037 g_tab_bud_rlmi.delete;
1038 g_tab_tt_task_id.delete;
1039 g_tab_r_fclevel_code.delete;
1040 g_tab_rg_fclevel_code.delete;
1041 g_tab_t_fclevel_code.delete;
1042 g_tab_tt_fclevel_code.delete;
1043 g_tab_p_fclevel_code.delete;
1044 g_tab_p_acct_fclevel_code.delete;
1045 g_tab_burd_cost_flag.delete;
1046 g_tab_pkt_trx_amt.delete;
1047 g_tab_accounted_dr.delete;
1048 g_tab_accounted_cr.delete;
1049 g_tab_PA_amt.delete;
1050 g_tab_PE_amt.delete;
1051 g_tab_status_code.delete;
1052 g_tab_effect_on_funds_code.delete;
1053 g_tab_result_code.delete;
1054 g_tab_r_result_code.delete;
1055 g_tab_rg_result_code.delete;
1056 g_tab_t_result_code.delete;
1057 g_tab_tt_result_code.delete;
1058 g_tab_p_result_code.delete;
1059 g_tab_r_budget_posted.delete;
1060 g_tab_rg_budget_posted.delete;
1061 g_tab_t_budget_posted.delete;
1062 g_tab_tt_budget_posted.delete;
1063 g_tab_p_budget_posted.delete;
1064 g_tab_r_actual_posted.delete;
1065 g_tab_rg_actual_posted.delete;
1066 g_tab_t_actual_posted.delete;
1067 g_tab_tt_actual_posted.delete;
1068 g_tab_p_actual_posted.delete;
1069 g_tab_r_enc_posted.delete;
1070 g_tab_rg_enc_posted.delete;
1071 g_tab_t_enc_posted.delete;
1072 g_tab_tt_enc_posted.delete;
1073 g_tab_p_enc_posted.delete;
1074 g_tab_r_budget_bal.delete;
1075 g_tab_rg_budget_bal.delete;
1076 g_tab_t_budget_bal.delete;
1077 g_tab_tt_budget_bal.delete;
1078 g_tab_p_budget_bal.delete;
1079 g_tab_r_actual_approved.delete;
1080 g_tab_rg_actual_approved.delete;
1081 g_tab_t_actual_approved.delete;
1082 g_tab_tt_actual_approved.delete;
1083 g_tab_p_actual_approved.delete;
1084 g_tab_r_enc_approved.delete;
1085 g_tab_rg_enc_approved.delete;
1086 g_tab_t_enc_approved.delete;
1087 g_tab_tt_enc_approved.delete;
1088 g_tab_p_enc_approved.delete;
1089 g_tab_effect_fclevel.delete;
1090 g_tab_trxn_ccid.delete;
1091 g_tab_budget_ccid.delete;
1092 g_tab_p_acct_result_code.delete;
1093 g_tab_exp_category.delete;
1094 g_tab_rev_category.delete;
1095 g_tab_sys_link_func.delete;
1096 g_tab_exp_type.delete;
1097 g_tab_gl_date.delete;
1098 g_tab_pa_date.delete;
1099 g_tab_start_date.delete;
1100 g_tab_end_date.delete;
1101 g_tab_encum_type_id.delete;
1102 g_tab_process_funds_level.delete;
1103 g_tab_old_budget_ccid.delete;
1104 g_tab_group_resource_type_id.delete;
1105 g_tab_person_id.delete;
1106 g_tab_job_id.delete;
1107 g_tab_vendor_id.delete;
1108 g_tab_non_lab_res.delete;
1109 g_tab_non_lab_res_org.delete;
1110 g_tab_non_cat_rlmi.delete;
1111 g_tab_proj_OU.delete;
1112 g_tab_exp_OU.delete;
1113 g_tab_doc_line_id.delete;
1114 g_tab_ext_bdgt_link.delete;
1115 g_tab_sob_id.delete;
1116 g_tab_exp_gl_date.delete;
1117 g_tab_exp_pa_date.delete; /*9487097*/
1118 g_tab_exp_item_id.delete;
1119 g_tab_burden_method_code.delete; -- for r12
1120 g_tab_budget_line_id.delete; -- for r12
1121
1122 EXCEPTION
1123
1124 WHEN OTHERS THEN
1125 --commit;
1126 RAISE;
1127
1128
1129 END init_plsql_tabs;
1130
1131 -------->6599207 ------As part of CC Enhancements
1132 --Forward declarations
1133 PROCEDURE Post_Bdn_Lines_To_GL_CBC (
1134 p_Packet_ID IN Number,
1135 p_calling_module IN VARCHAR2,
1136 p_packet_status IN VARCHAR2,
1137 p_reference1 IN VARCHAR2,
1138 p_reference2 IN VARCHAR2,
1139 x_return_status OUT NOCOPY VARCHAR2
1140 );
1141 -------->6599207 ------END
1142
1143 ---Forward declarations
1144 PROCEDURE update_EIS (p_packet_id IN NUMBER,
1145 p_calling_module IN VARCHAR2,
1146 p_mode IN VARCHAR2,
1147 x_return_status OUT NOCOPY VARCHAR2);
1148
1149 ---Forward declarations
1150 PROCEDURE update_GL_CBC_result_code(
1151 p_packet_id IN number,
1152 p_calling_module IN varchar2,
1153 p_mode IN varchar2,
1154 p_partial_flag IN varchar2,
1155 p_reference1 IN varchar2 default null,
1156 p_reference2 IN varchar2 default null,
1157 p_packet_status IN varchar2,
1158 x_return_status OUT NOCOPY varchar2);
1159 -- Forward declarations
1160 FUNCTION pa_fck_process
1161 (p_sob IN NUMBER
1162 ,p_packet_id IN pa_bc_packets.packet_id%type
1163 ,p_mode IN varchar2
1164 ,p_partial_flag IN varchar2
1165 ,p_arrival_seq IN NUMBER
1166 ,p_reference1 IN varchar2
1167 ,p_reference2 IN varchar2
1168 --,p_reference3 IN varchar2
1169 ,p_calling_module IN varchar2
1170 ) return BOOLEAN;
1171
1172 /** This API derives the return code for GL / CBC
1173 * based on partial reserve flag, If the funds check is called
1174 * in partial mode GL /CBC expects the return status as P if
1175 * the records are partially passed
1176 */
1177 FUNCTION get_gl_cbc_return_status(
1178 p_packet_id NUMBER) return varchar2 IS
1179
1180 CURSOR pkt_status is
1181 SELECT decode(count(*),count(decode(substr(nvl(pbc.result_code,'P'),1,1),'P',1)),'S','P')
1182 FROM pa_bc_packets pbc
1183 WHERE pbc.packet_id = p_packet_id;
1184
1185 l_pkt_status varchar2(10);
1186 BEGIN
1187 OPEN pkt_status;
1188 FETCH pkt_status INTO l_pkt_status;
1189 CLOSE pkt_status;
1190
1191 return nvl(l_pkt_status,'P');
1192
1193 EXCEPTION
1194 WHEN OTHERS THEN
1195 IF pkt_status%isopen then
1196 close pkt_status;
1197 END IF;
1198 return nvl(l_pkt_status,'P');
1199
1200 END get_gl_cbc_return_status;
1201
1202 /**----------------------------------------------------------------------------
1203 -- This api checks whether the project is of burden on same or different
1204 -- expenditure items
1205 -- returns 'S' (SAME) 'D'(SEPARATE) 'N' (NO BURDEN)
1206 --------------------------------------------------------------------------- **/
1207 FUNCTION check_bdn_on_sep_item(p_project_id In number) return varchar2 IS
1208 l_burden_method VARCHAR2(20);
1209 BEGIN
1210
1211 If g_exp_project_id is null or g_exp_project_id <> p_project_id then
1212 SELECT decode(NVL(ppt.burden_cost_flag, 'N'),'Y',
1213 NVL(ppt.burden_amt_display_method,'S'),'N')
1214 -- decode(NVL(ppt.burden_amt_display_method,'S'), 'S','SAME','D','DIFFERENT'),'NONE')
1215 INTO l_burden_method
1216 FROM pa_project_types ppt,
1217 pa_projects_all pp
1218 WHERE
1219 ppt.project_type = pp.project_type
1220 AND pp.project_id = p_project_id;
1221
1222 g_exp_burden_method := l_burden_method;
1223 g_exp_project_id := p_project_id;
1224
1225 RETURN l_burden_method;
1226
1227 Else -- retrive from cache
1228
1229 RETURN g_exp_burden_method;
1230 End if;
1231
1232 EXCEPTION
1233 WHEN NO_DATA_FOUND THEN
1234 g_exp_burden_method := 'N';
1235 -- g_exp_burden_method := 'NONE';
1236 RETURN g_exp_burden_method;
1237 WHEN OTHERS THEN
1238 RAISE;
1239
1240 END check_bdn_on_sep_item;
1241 /**------------------------------------------------------------------
1242 -- This api updates the result and status code in pa bc packets
1243 -- whenever there is error while processing
1244 ----------------------------------------------------------------- **/
1245 PROCEDURE result_status_code_update
1246 ( p_status_code IN VARCHAR2 default null
1247 ,p_result_code IN VARCHAR2 default null
1248 ,p_res_result_code IN VARCHAR2 default null
1249 ,p_res_grp_result_code IN VARCHAR2 default null
1250 ,p_task_result_code IN VARCHAR2 default null
1251 ,p_top_task_result_code IN VARCHAR2 default null
1252 ,p_project_result_code IN VARCHAR2 default null
1253 ,p_proj_acct_result_code IN VARCHAR2 default null
1254 ,p_bc_packet_id IN NUMBER default null
1255 ,p_packet_id IN NUMBER ) IS
1256
1257 /* Commented as part of 13009945 cursor cur_pkts is
1258 SELECT packet_id,
1259 bc_packet_id
1260 FROM pa_bc_packets
1261 WHERE packet_id = p_packet_id;
1262
1263 l_tab_packet_id pa_plsql_datatypes.idtabtyp;
1264 l_tab_bc_packet_id pa_plsql_datatypes.idtabtyp; */
1265
1266 PRAGMA AUTONOMOUS_TRANSACTION;
1267
1268 BEGIN
1269 pa_debug.init_err_stack('PA_FUNDS_CONTROL_PKG.result_status_code_update');
1270 /******
1271 -- Added if else condition to avoid full table scan on pa_bc_packets
1272 --EXPLAIN PLAN IS:
1273 --1:UPDATE STATEMENT :(cost=2,rows=1)
1274 --2:UPDATE PA_BC_PACKETS :(cost=,rows=)
1275 --3:TABLE ACCESS BY INDEX ROWID PA_BC_PACKETS :(cost=2,rows=1)
1276 --4:INDEX UNIQUE SCAN PA_BC_PACKETS_U1 :(cost=1,rows=1)
1277 *******/
1278
1279 If p_status_code = 'T' then
1280
1281 /* Commented as part of 13009945
1282 OPEN cur_pkts;
1283 LOOP
1284 l_tab_packet_id.delete;
1285 l_tab_bc_packet_id.delete;
1286 FETCH cur_pkts BULK COLLECT INTO
1287 l_tab_packet_id
1288 ,l_tab_bc_packet_id LIMIT 500;
1289 IF NOT l_tab_packet_id.EXISTS(1) then
1290 EXIT;
1291 END if;
1292 FORALL i IN l_tab_packet_id.first .. l_tab_packet_id.last
1293 */
1294 UPDATE pa_bc_packets
1295 SET status_code = 'T',
1296 result_code = decode(substr(nvl(result_code,'P'),1,1)
1297 ,'P', decode(substr(nvl(p_result_code,'P'),1,1)
1298 ,'F', p_result_code,'F142')
1299 ,result_code),
1300 res_result_code = nvl(res_result_code,p_res_result_code),
1301 res_grp_result_code = nvl(res_grp_result_code,p_res_grp_result_code),
1302 task_result_code = nvl(task_result_code,p_task_result_code),
1303 top_task_result_code = nvl(top_task_result_code,p_top_task_result_code),
1304 project_result_code = nvl(project_result_code,p_project_result_code),
1305 project_acct_result_code =nvl(project_acct_result_code,p_proj_acct_result_code)
1306 WHERE packet_id = p_packet_id;
1307
1308 -- Exit when cur_pkts%NOTFOUND;
1309 commit;
1310 /* Commented as part of 13009945 END LOOP;
1311 CLOSE cur_pkts; */
1312
1313
1314 ELSIf p_bc_packet_id is NOT NULL and p_status_code <> 'T' then
1315
1316 /* Commented as part of 13009945 OPEN cur_pkts;
1317 LOOP
1318 l_tab_packet_id.delete;
1319 l_tab_bc_packet_id.delete;
1320 FETCH cur_pkts BULK COLLECT INTO
1321 l_tab_packet_id,
1322 l_tab_bc_packet_id LIMIT 500;
1323 IF NOT l_tab_packet_id.EXISTS(1) then
1324 EXIT;
1325 END if;
1326 FORALL i IN l_tab_packet_id.first .. l_tab_packet_id.last */
1327
1328 UPDATE pa_bc_packets
1329 SET status_code = nvl(p_status_code,status_code),
1330 result_code = nvl(p_result_code ,result_code),
1331 res_result_code = nvl(p_res_result_code,res_result_code),
1332 res_grp_result_code = nvl(p_res_grp_result_code,res_grp_result_code),
1333 task_result_code = nvl(p_task_result_code,task_result_code),
1334 top_task_result_code = nvl(p_top_task_result_code,top_task_result_code),
1335 project_result_code = nvl(p_project_result_code,project_result_code),
1336 project_acct_result_code =nvl(p_proj_acct_result_code,project_acct_result_code)
1337 WHERE packet_id = p_packet_id
1338 AND bc_packet_id = p_bc_packet_id
1339 AND substr(nvl(result_code,'P'),1,1) <> 'F';
1340
1341 -- Exit when cur_pkts%NOTFOUND;
1342 commit;
1343 /* Commented as part of 13009945 END LOOP;
1344 CLOSE cur_pkts; */
1345 Else
1346 /* Commented as part of 13009945
1347 OPEN cur_pkts;
1348 LOOP
1349 l_tab_packet_id.delete;
1350 l_tab_bc_packet_id.delete;
1351 FETCH cur_pkts BULK COLLECT INTO
1352 l_tab_packet_id,
1353 l_tab_bc_packet_id LIMIT 500;
1354 IF NOT l_tab_packet_id.EXISTS(1) then
1355 EXIT;
1356 END if;
1357 FORALL i IN l_tab_packet_id.first .. l_tab_packet_id.last */
1358 UPDATE pa_bc_packets
1359 SET status_code = nvl(p_status_code,status_code),
1360 result_code = nvl(p_result_code ,result_code),
1361 res_result_code = nvl(p_res_result_code,res_result_code),
1362 res_grp_result_code = nvl(p_res_grp_result_code,res_grp_result_code),
1363 task_result_code = nvl(p_task_result_code,task_result_code),
1364 top_task_result_code = nvl(p_top_task_result_code,top_task_result_code),
1365 project_result_code = nvl(p_project_result_code,project_result_code),
1366 project_acct_result_code =nvl(p_proj_acct_result_code,project_acct_result_code)
1367 WHERE packet_id = p_packet_id
1368 AND substr(nvl(result_code,'P'),1,1) <> 'F';
1369 -- Exit when cur_pkts%NOTFOUND;
1370 commit;
1371 /* Commented as part of 13009945 END LOOP;
1372 CLOSE cur_pkts; */
1373 End if;
1374 /* Commented as part of 13009945 IF cur_pkts%isopen then
1375 close cur_pkts;
1376 END IF; */
1377 commit; -- to end an active autonmous transaction
1378 PA_DEBUG.reset_err_stack;
1379 return;
1380 EXCEPTION
1381 WHEN OTHERS THEN
1382 /* Commented as part of 13009945
1383 IF cur_pkts%isopen then
1384 close cur_pkts;
1385 END IF; */
1386 RAISE;
1387
1388 END result_status_code_update;
1389
1390
1391 procedure log_message_imp(p_msg_token1 in varchar2 default null) is
1392 begin
1393
1394 --r_debug.r_msg(p_msg =>'LOG : '||p_msg_token1,p_packet_id => g_packet_id);
1395 --pa_fck_util.debug_msg_imp('LOG : '||p_msg_token1);
1396 return;
1397 End;
1398
1399 ----------------------------------------------------------------
1400 -- This api writes message to log file / buffer / dummy table
1401 -- and initalizes the final out NOCOPY params with values
1402 ----------------------------------------------------------------
1403 PROCEDURE log_message(
1404 p_stage IN VARCHAR2 default null,
1405 p_error_msg IN VARCHAR2 default null,
1406 p_return_status IN varchar2 default null,
1407 p_msg_token1 IN VARCHAR2 default null,
1408 p_msg_token2 IN VARCHAR2 default null ) IS
1409
1410 BEGIN
1411
1412 IF p_error_msg is NOT NULL then
1413 g_error_msg := p_error_msg;
1414 END IF;
1415 IF p_return_status is NOT null then
1416 g_return_status := p_return_status;
1417 End if;
1418
1419 /* write the debug log only if debug is enabled */
1420 IF g_debug_mode = 'Y' THEN
1421
1422 IF p_stage is NOT null then
1423 pa_debug.g_err_stage := 'Stage :'|| substr(p_stage,1,250);
1424 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1425 pa_debug.write('pa.plsql.PA_FUNDS_CONTROL_PKG','LOG: '||pa_debug.g_err_stage,3);
1426 g_error_stage := substr(p_stage,1,10);
1427 END IF;
1428
1429 IF p_error_msg is NOT NULL then
1430 pa_debug.g_err_stage := 'Error Msg :'||substr(p_error_msg,1,250);
1431 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1432 PA_DEBUG.write
1433 (x_Module => 'pa.plsql.PA_FUNDS_CONTROL_PKG'
1434 ,x_Msg => substr('LOG:'||p_error_msg,1,240)
1435 ,x_Log_Level => 3);
1436 g_error_msg := p_error_msg;
1437 END IF;
1438
1439 IF p_msg_token1 is NOT NULL or p_msg_token2 is NOT NULL then
1440 IF p_msg_token2 is not null then
1441 pa_debug.g_err_stage := substr(p_msg_token2,1,250);
1442 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1443 pa_debug.write('pa.plsql.PA_FUNDS_CONTROL_PKG','LOG: '||pa_debug.g_err_stage,3);
1444 END IF;
1445 IF p_msg_token1 is NOT NULL then
1446 pa_debug.g_err_stage := substr(p_msg_token1,1,250);
1447 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1448 PA_DEBUG.write
1449 (x_Module => 'pa.plsql.PA_FUNDS_CONTROL_PKG'
1450 ,x_Msg => substr('LOG:'||p_msg_token1,1,240)
1451 ,x_Log_Level => 3);
1452
1453 END IF ;
1454 END IF;
1455
1456 END IF; -- end of g_debug_mode
1457 return;
1458
1459 END log_message;
1460
1461 /** Bug fix:2302945 check whether the project is installed in this OU
1462 ** This api checks the records in pa_implementaions for the given OU if
1463 ** no records exits , it assumes that project is not installed in this OU
1464 **/
1465 FUNCTION IS_PA_INSTALL_IN_OU RETURN VARCHAR2 is
1466
1467 l_return_var varchar2(10) := 'Y';
1468
1469 BEGIN
1470 IF g_debug_mode = 'Y' THEN
1471 log_message(p_msg_token1 => 'Inside IS_PA_INSTALL_IN_OU api');
1472 End If;
1473 SELECT 'Y'
1474 INTO l_return_var
1475 FROM pa_implementations;
1476 IF g_debug_mode = 'Y' THEN
1477 log_message(p_msg_token1 => 'End of IS_PA_INSTALL_IN_OU api return var:'||l_return_var);
1478 End If;
1479 Return l_return_var ;
1480
1481 EXCEPTION
1482 when NO_data_found then
1483 IF g_debug_mode = 'Y' THEN
1484 log_message(p_msg_token1 => 'End of IS_PA_INSTALL_IN_OU api return var:N');
1485 End If;
1486 return 'N';
1487 when Too_many_rows then
1488 return 'Y';
1489 When others then
1490 IF g_debug_mode = 'Y' THEN
1491 log_message(p_msg_token1 => 'Failed in IS_PA_INSTALL_IN_OU'||SQLERRM);
1492 End If;
1493 Raise;
1494
1495 END IS_PA_INSTALL_IN_OU;
1496
1497 -------------------------------------------------------------------------
1498 -- This api checks whether the Invoice is coming after the
1499 -- interface from projects if the invoice is already interfaced
1500 -- from projects then donot derive burden components
1501 -- if the invoice system_linkage function is 'VI' then
1502 -- derive budget ccid, encum type id, etc and DONOT do funds check
1503 -- mark the invoice as approved and donot create encum liqd
1504 -- if the invoice system linkage func is 'ER' then
1505 -- derive budget ccid, encum type id, etc and DONOT funds check
1506 -- mark the invoice as approved and create encum liqd for raw only
1507 -- NOTE : IF THE PROJECT IS BURDEN ON SAME EI THEN DO NOTHING
1508 -- ELSE DERIVE budget,encum type id,create encum liqd AND mark the
1509 -- invoice as approved
1510 -- R12 Note: This procedure is not longer used ... as the check for
1511 -- expense report is carried out upfront and also from r12 on
1512 -- VI txn. will no longer be interfaced back to AP ...
1513 -- Not removing procedure as it can be used (if reqd..)
1514 -------------------------------------------------------------------------
1515 PROCEDURE is_ap_from_project
1516 (p_packet_id IN NUMBER,
1517 p_calling_module IN VARCHAR2,
1518 x_return_status OUT NOCOPY VARCHAR2) IS
1519
1520 PRAGMA AUTONOMOUS_TRANSACTION;
1521
1522 --EXPLAIN PLAN IS:
1523 --1:SELECT STATEMENT :(cost=269,rows=2)
1524 --2:SORT UNIQUE :(cost=269,rows=2)
1525 --3:UNION-ALL :(cost=,rows=)
1526 --4:NESTED LOOPS :(cost=137,rows=1)
1527 --5:NESTED LOOPS :(cost=122,rows=1)
1528 --6:TABLE ACCESS BY INDEX ROWID PA_BC_PACKETS :(cost=120,rows=1)
1529 --7:INDEX RANGE SCAN PA_BC_PACKETS_U1 :(cost=5,rows=1)
1530 --6:TABLE ACCESS BY INDEX ROWID PA_EXPENDITURE_ITEMS_ALL :(cost=2,rows=2345)
1531 --7:INDEX RANGE SCAN PA_EXPENDITURE_ITEMS_N9 :(cost=1,rows=2345)
1532 --5:TABLE ACCESS BY INDEX ROWID PA_COST_DISTRIBUTION_LINES_ALL :(cost=15,rows=47647)
1533 --6:INDEX RANGE SCAN PA_COST_DISTRIBUTION_LINES_U1 :(cost=1,rows=47647)
1534 --4:NESTED LOOPS :(cost=128,rows=1)
1535 --5:NESTED LOOPS :(cost=121,rows=1)
1536 --6:TABLE ACCESS BY INDEX ROWID PA_BC_PACKETS :(cost=120,rows=1)
1537 --7:INDEX RANGE SCAN PA_BC_PACKETS_U1 :(cost=5,rows=1)
1538 --6:TABLE ACCESS BY INDEX ROWID AP_EXPENSE_REPORT_HEADERS_ALL :(cost=1,rows=290)
1539 --7:INDEX RANGE SCAN AP_EXPENSE_REPORT_HEADERS_N1 :(cost=,rows=290)
1540 --5:TABLE ACCESS FULL AP_EXPENSE_REPORT_LINES_ALL :(cost=7,rows=1260)
1541
1542 CURSOR invoice_cdls is
1543 SELECT pbc.bc_packet_id,
1544 pbc.project_id,
1545 nvl(exp.system_linkage_function,'VI') system_linkage_function,
1546 pbc.burden_method_code
1547 FROM pa_bc_packets pbc
1548 ,pa_cost_distribution_lines_all cdl
1549 ,pa_expenditure_items_all exp
1550 WHERE pbc.packet_id = p_packet_id
1551 AND pbc.document_header_id = cdl.system_reference2
1552 AND pbc.document_distribution_id = cdl.system_reference3
1553 AND pbc.document_type = 'AP'
1554 AND cdl.line_type = 'R'
1555 AND cdl.expenditure_item_id = exp.expenditure_item_id
1556 AND pbc.task_id = exp.task_id -- added to use index N9
1557 AND pbc.expenditure_item_date = exp.expenditure_item_date --added to use index N9
1558 AND exp.system_linkage_function in ('VI','ER')
1559 UNION
1560 SELECT pbc.bc_packet_id,
1561 pbc.project_id,
1562 'ER' system_linkage_function,
1563 pbc.burden_method_code
1564 FROM pa_bc_packets pbc
1565 ,ap_expense_report_headers_all exphead
1566 ,ap_expense_report_lines_all expline
1567 WHERE pbc.packet_id = p_packet_id
1568 AND pbc.document_header_id = exphead.vouchno
1569 AND pbc.set_of_books_id = exphead.set_of_books_id
1570 AND exphead.report_header_id = expline.report_header_id /* added for bug#2634995 */
1571 AND pbc.document_distribution_id = expline.distribution_line_number
1572 AND pbc.document_type = 'AP'
1573 AND pbc.project_id = expline.project_id
1574 AND pbc.task_id = expline.task_id
1575 AND pbc.expenditure_type = expline.expenditure_type
1576 AND pbc.set_of_books_id = expline.set_of_books_id;
1577
1578 l_num_rows NUMBER := 100;
1579 l_pre_project_id NUMBER := NULL;
1580 l_burden_method VARCHAR2(50);
1581 l_pre_burden_method varchar2(50);
1582
1583 BEGIN
1584 IF g_debug_mode = 'Y' THEN
1585 log_message(p_msg_token1 => 'Inside the is_ap_from project api');
1586 End If;
1587
1588 --Initialize the error stack
1589 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.is_ap_from_project');
1590
1591 x_return_status := 'S';
1592
1593 IF p_calling_module = 'GL' then
1594 OPEN invoice_cdls;
1595 LOOP
1596 --Initialize the plsql tables
1597 Init_plsql_tabs;
1598
1599 FETCH invoice_cdls BULK COLLECT INTO
1600 g_tab_bc_packet_id,
1601 g_tab_project_id,
1602 g_tab_sys_link_func,
1603 g_tab_burden_method_code LIMIT l_num_rows;
1604
1605 If NOT g_tab_bc_packet_id.EXISTS(1) then
1606 IF g_debug_mode = 'Y' THEN
1607 log_message(p_msg_token1 => 'this Invoice is Not interfaced from Project');
1608 End If;
1609 EXIT;
1610 else
1611 IF g_debug_mode = 'Y' THEN
1612 log_message(p_msg_token1 => 'this Invoice is interfaced from projects');
1613 End If;
1614 null;
1615 End if;
1616 FOR i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST LOOP
1617
1618 IF g_tab_bc_packet_id(i) is NOT NULL then
1619
1620 If g_tab_burden_method_code(i) is NULL then
1621
1622 IF g_tab_project_id(i) <> l_pre_project_id
1623 or l_pre_project_id is NULL then
1624
1625 l_burden_method :=check_bdn_on_sep_item (g_tab_project_id(i));
1626 l_pre_burden_method := l_burden_method;
1627 Else
1628 l_burden_method := l_pre_burden_method;
1629 End if;
1630
1631 Else
1632 l_burden_method := g_tab_burden_method_code(i);
1633 l_pre_burden_method := l_burden_method;
1634
1635 End If; -- If g_tab_burden_method_code(i) is NULL then
1636
1637 IF g_debug_mode = 'Y' THEN
1638 log_message(p_msg_token1 => 'burden method ['||l_burden_method||
1639 ']g_tab_sys_link_func['||g_tab_sys_link_func(i)||']' );
1640 End If;
1641
1642
1643 IF g_tab_sys_link_func(i) = 'VI' then
1644 --If l_burden_method = 'SAME' then
1645 If l_burden_method = 'S' then
1646 g_tab_status_code(i) := 'V';
1647 Else
1648 g_tab_status_code(i) := 'L';
1649 End if;
1650 g_tab_result_code(i) := 'P114';
1651 g_tab_r_result_code(i) := 'P114';
1652 g_tab_rg_result_code(i) := 'P114';
1653 g_tab_t_result_code(i) := 'P114';
1654 g_tab_tt_result_code(i) := 'P114';
1655 g_tab_p_result_code(i) := 'P114';
1656 g_tab_p_acct_result_code(i) := 'P114';
1657 Elsif g_tab_sys_link_func(i) = 'ER' then
1658 --If l_burden_method = 'SAME' then
1659 If l_burden_method = 'S' then
1660 g_tab_status_code(i) := 'V';
1661 Else
1662 g_tab_status_code(i) := 'L';
1663 End if;
1664 g_tab_result_code(i) := 'P115';
1665 g_tab_r_result_code(i) := 'P115';
1666 g_tab_rg_result_code(i) := 'P115';
1667 g_tab_t_result_code(i) := 'P115';
1668 g_tab_tt_result_code(i) := 'P115';
1669 g_tab_p_result_code(i) := 'P115';
1670 g_tab_p_acct_result_code(i) := 'P115';
1671 End if;
1672 l_pre_project_id := g_tab_project_id(i);
1673 End if;
1674 END LOOP;
1675
1676 --update the result and status code in pa bc packets
1677 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
1678 UPDATE pa_bc_packets
1679 SET status_code = g_tab_status_code(i),
1680 result_code = g_tab_result_code(i),
1681 res_result_code = g_tab_r_result_code(i),
1682 res_grp_result_code = g_tab_rg_result_code(i),
1683 task_result_code = g_tab_t_result_code(i),
1684 top_task_result_code = g_tab_tt_result_code(i),
1685 project_result_code = g_tab_p_result_code(i),
1686 project_acct_result_code = g_tab_p_acct_result_code(i)
1687 WHERE bc_packet_id = g_tab_bc_packet_id(i)
1688 AND packet_id = p_packet_id;
1689 EXIT WHEN invoice_cdls%NOTFOUND;
1690 END LOOP;
1691 CLOSE invoice_cdls;
1692
1693 End IF;
1694 IF g_debug_mode = 'Y' THEN
1695 log_message(p_msg_token1 => 'End of is_ap_from_project api');
1696 End If;
1697 PA_DEBUG.reset_err_stack;
1698 commit; -- to end an active autonmous transaction
1699 return;
1700
1701 EXCEPTION
1702 when others then
1703 x_return_status := 'T';
1704 IF g_debug_mode = 'Y' THEN
1705 log_message(p_msg_token1 => 'failed in is_ap_from_project api SQLERR ['||sqlcode||sqlerrm||']');
1706 End If;
1707 --commit;
1708
1709 --Raise;
1710 END is_ap_from_project;
1711
1712
1713 --------------------------------------------------------------------------------------------------------
1714 --Procedure to be called inside check_funds_available to generate result code and status for each record.
1715 -------------------------------------------------------------------------------------------------------
1716 PROCEDURE generate_result_code(
1717 p_fclevel_code IN VARCHAR2 DEFAULT 'B',
1718 p_available_amt IN NUMBER DEFAULT 0,
1719 p_stage IN VARCHAR2 DEFAULT 0,
1720 p_budget_posted_amt IN NUMBER DEFAULT 0,
1721 x_result_code IN OUT NOCOPY VARCHAR2,
1722 x_r_result_code IN OUT NOCOPY VARCHAR2,
1723 x_rg_result_code IN OUT NOCOPY VARCHAR2,
1724 x_t_result_code IN OUT NOCOPY VARCHAR2,
1725 x_tt_result_code IN OUT NOCOPY VARCHAR2,
1726 x_p_result_code IN OUT NOCOPY VARCHAR2,
1727 x_p_acct_result_code IN OUT NOCOPY VARCHAR2,
1728 x_return_status IN OUT NOCOPY VARCHAR2
1729 ) IS
1730 BEGIN
1731 IF g_debug_mode = 'Y' THEN
1732 log_message(p_msg_token1 => 'p_fclevel_code ['||p_fclevel_code||']p_available_amt['||p_available_amt||
1733 ']p_stage ['||p_stage||']p_budget_posted_amt ['||p_budget_posted_amt||']' );
1734 End If;
1735
1736 -- p_stage
1737 -- 100 Resource Level
1738 -- 200 Resource Group Level
1739 -- 300 Task Level
1740 -- 400 Top Task Level
1741 -- 500 Project Level
1742 -- 600 Project Account Level
1743 /*** Bug Fix :1892535 if the budget amount is zero and
1744 * available amount(transaction amount) is zero then transaction should pass
1745 * funds check
1746 * Example budget for project p1 = 500 task t1 = 500 resource r1 = 0 for period jan-01
1747 * Transactions project task resource period acct_dr acct_cr
1748 * 1 p1 t1 r1 jan-01 - 1000
1749 * 2 p1 t1 r1 jan-01 1000 -
1750 * ideally the net effect of the both transactions are zero so they must pass
1751 * funds check
1752
1753 IF NVL ( p_budget_posted_amt, 0 ) = 0
1754 AND NVL ( p_available_amt, 0 ) = 0
1755 AND p_fclevel_code = 'B' THEN
1756
1757 IF p_stage = 100 THEN
1758 -- msg : F101 = No budget at resource level
1759 x_result_code := 'F101';
1760 x_r_result_code := 'F101';
1761 x_rg_result_code := 'F101';
1762 x_t_result_code := 'F101';
1763 x_tt_result_code := 'F101';
1764 x_p_result_code := 'F101';
1765 x_p_acct_result_code := 'F101';
1766 ELSIF p_stage = 200 THEN
1767 -- msg : F102 = No budget at resource Group level
1768 x_result_code := 'F102';
1769 x_rg_result_code := 'F102';
1770 x_t_result_code := 'F102';
1771 x_tt_result_code := 'F102';
1772 x_p_result_code := 'F102';
1773 x_p_acct_result_code := 'F102';
1774 ELSIF p_stage = 300 THEN
1775 -- msg : F103 = No budget at task level
1776 x_result_code := 'F103';
1777 x_t_result_code := 'F103';
1778 x_tt_result_code := 'F103';
1779 x_p_result_code := 'F103';
1780 x_p_acct_result_code := 'F103';
1781 ELSIF p_stage = 400 THEN
1782 -- msg : F104 = No budget at top task level
1783 x_result_code := 'F104';
1784 x_tt_result_code := 'F104';
1785 x_p_result_code := 'F104';
1786 x_p_acct_result_code := 'F104';
1787 ELSIF p_stage = 500 THEN
1788 -- msg : F105 = No budget at Project level
1789 x_result_code := 'F105';
1790 x_p_result_code := 'F105';
1791 x_p_acct_result_code := 'F105';
1792 ELSIF p_stage = 600 THEN
1793 -- msg : F106 = No budget at project acct level
1794 x_result_code := 'F106';
1795 x_p_acct_result_code := 'F106';
1796
1797 END IF;
1798 x_return_status := 'F';
1799 RETURN;
1800 END IF;
1801
1802 ********end of bug fix:1892535 ***/
1803
1804 -- check if the funds control level code is none then
1805 -- pass the transaction
1806 IF p_fclevel_code = 'N' THEN
1807
1808 IF p_stage = 100 THEN
1809 x_result_code := 'P111';
1810 x_r_result_code := 'P111';
1811 ELSIF p_stage = 200 THEN
1812 x_result_code := 'P109';
1813 x_rg_result_code := 'P109';
1814 ELSIF p_stage = 300 THEN
1815 x_result_code := 'P107';
1816 x_t_result_code := 'P107';
1817 ELSIF p_stage = 400 THEN
1818 x_result_code := 'P105';
1819 x_tt_result_code := 'P105';
1820 ELSIF p_stage = 500 THEN
1821 x_result_code := 'P103';
1822 x_p_result_code := 'P103';
1823 ELSIF p_stage = 600 THEN
1824 x_result_code := 'P101';
1825 x_p_acct_result_code := 'P101';
1826 END IF;
1827
1828 x_return_status := 'P';
1829 END IF;
1830
1831 -- check if teh funds control level code is Absolute or Advisory
1832 -- if absolute then check whether the funds avaiabl with in the limit
1833 -- if so pass the transaction otherwise fail the transaction
1834 -- if the control level code is advisory then pass the transaction with
1835 -- warning if exceeds the available amount
1836 /** Bug fix : 1975786 p_fclevel_code D - advisory is changed to A
1837 * since the lookup code is changed from D - A
1838 * initial lookup codes B - Absolute, D - Advisory N - None
1839 * changed lookup codes B - Absolute, A - Advisory N - None
1840 **/
1841 IF p_fclevel_code IN ( 'B', 'A' ) and p_available_amt >= 0 then
1842 IF p_stage = 100 THEN
1843 x_result_code := 'P111';
1844 x_r_result_code := 'P111';
1845 ELSIF p_stage = 200 THEN
1846 x_result_code := 'P109';
1847 x_rg_result_code := 'P109';
1848 ELSIF p_stage = 300 THEN
1849 x_result_code := 'P107';
1850 x_t_result_code := 'P107';
1851 ELSIF p_stage = 400 THEN
1852 x_result_code := 'P105';
1853 x_tt_result_code := 'P105';
1854 ELSIF p_stage = 500 THEN
1855 x_result_code := 'P103';
1856 x_p_result_code := 'P103';
1857 ELSIF p_stage = 600 THEN
1858 x_result_code := 'P101';
1859 x_p_acct_result_code := 'P101';
1860 END IF;
1861
1862 x_return_status := 'P';
1863
1864 ELSIF p_fclevel_code = 'A' and p_available_amt < 0 then
1865 IF p_stage = 100 THEN
1866 x_result_code := 'P112';
1867 x_r_result_code := 'P112';
1868 ELSIF p_stage = 200 THEN
1869 x_result_code := 'P110';
1870 x_rg_result_code := 'P110';
1871 ELSIF p_stage = 300 THEN
1872 x_result_code := 'P108';
1873 x_t_result_code := 'P108';
1874 ELSIF p_stage = 400 THEN
1875 x_result_code := 'P106';
1876 x_tt_result_code := 'P106';
1877 ELSIF p_stage = 500 THEN
1878 x_result_code := 'P104';
1879 x_p_result_code := 'P104';
1880 ELSIF p_stage = 600 THEN
1881 x_result_code := 'P102';
1882 x_p_acct_result_code := 'P102';
1883 END IF;
1884
1885 x_return_status := 'A'; -- Modified for bug 9156359
1886
1887 ELSIF p_fclevel_code = 'B' AND p_available_amt < 0 then
1888 /** Bug :1969608 fix added If conditions, if the budget amount is zero
1889 * to display the proper error message
1890 **/
1891 IF p_stage = 100 THEN
1892
1893 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1894 -- msg : F101 = No budget at resource level
1895 x_result_code := 'F101';
1896 x_r_result_code := 'F101';
1897 x_rg_result_code := 'F101';
1898 x_t_result_code := 'F101';
1899 x_tt_result_code := 'F101';
1900 x_p_result_code := 'F101';
1901 x_p_acct_result_code := 'F101';
1902
1903 Else
1904 -- msg : F108 Failed at resource level
1905 x_result_code := 'F108';
1906 x_r_result_code := 'F108';
1907 x_rg_result_code := 'F108';
1908 x_t_result_code := 'F108';
1909 x_tt_result_code := 'F108';
1910 x_p_result_code := 'F108';
1911 x_p_acct_result_code := 'F108';
1912 End if;
1913 ELSIF p_stage = 200 THEN
1914
1915 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1916 -- msg : F102 = No budget at resource Group level
1917 x_result_code := 'F102';
1918 x_rg_result_code := 'F102';
1919 x_t_result_code := 'F102';
1920 x_tt_result_code := 'F102';
1921 x_p_result_code := 'F102';
1922 x_p_acct_result_code := 'F102';
1923
1924 Else
1925 -- msg : F109 Failed at resource group level
1926 x_result_code := 'F109';
1927 x_rg_result_code := 'F109';
1928 x_t_result_code := 'F109';
1929 x_tt_result_code := 'F109';
1930 x_p_result_code := 'F109';
1931 x_p_acct_result_code := 'F109';
1932 End if;
1933 ELSIF p_stage = 300 THEN
1934
1935 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1936 -- msg : F103 = No budget at task level
1937 x_result_code := 'F103';
1938 x_t_result_code := 'F103';
1939 x_tt_result_code := 'F103';
1940 x_p_result_code := 'F103';
1941 x_p_acct_result_code := 'F103';
1942
1943 Else
1944 -- msg : F110 failed at task level
1945 x_result_code := 'F110';
1946 x_t_result_code := 'F110';
1947 x_tt_result_code := 'F110';
1948 x_p_result_code := 'F110';
1949 x_p_acct_result_code := 'F110';
1950 End if;
1951 ELSIF p_stage = 400 THEN
1952
1953 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1954
1955 -- msg : F104 = No budget at top task level
1956 x_result_code := 'F104';
1957 x_tt_result_code := 'F104';
1958 x_p_result_code := 'F104';
1959 x_p_acct_result_code := 'F104';
1960
1961 Else
1962 -- msg : F111 Failed at top task level
1963 x_result_code := 'F111';
1964 x_tt_result_code := 'F111';
1965 x_p_result_code := 'F111';
1966 x_p_acct_result_code := 'F111';
1967 End if;
1968 ELSIF p_stage = 500 THEN
1969
1970 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1971 -- msg : F105 = No budget at Project level
1972 x_result_code := 'F105';
1973 x_p_result_code := 'F105';
1974 x_p_acct_result_code := 'F105';
1975
1976 Else
1977 -- msg : F112 Failed at the project level
1978 x_result_code := 'F112';
1979 x_p_result_code := 'F112';
1980 x_p_acct_result_code := 'F112';
1981 End if;
1982 ELSIF p_stage = 600 THEN
1983
1984 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1985 -- msg : F106 = No budget at project acct level
1986 x_result_code := 'F106';
1987 x_p_acct_result_code := 'F106';
1988
1989 Else
1990 -- msg : F113 failed at the project acct level
1991 x_result_code := 'F113';
1992 x_p_acct_result_code := 'F113';
1993 End if;
1994 END IF;
1995
1996 x_return_status := 'F';
1997 END IF;
1998 IF g_debug_mode = 'Y' THEN
1999 log_message(p_msg_token1 => 'x_result_code ='||x_result_code||']x_r_result_code['||x_r_result_code||
2000 ']x_rg_result_code ['||x_rg_result_code||']x_t_result_code ['||x_t_result_code||
2001 ']x_tt_result_code ['||x_tt_result_code||']x_p_result_code ['||x_p_result_code||
2002 ']x_p_acct_rresult_code ['||x_p_acct_result_code||']' );
2003 End If;
2004
2005
2006 EXCEPTION
2007 WHEN OTHERS THEN
2008 IF g_debug_mode = 'Y' THEN
2009 log_message(p_msg_token1 => 'failed in generate result code api SQLERR :'||sqlcode||sqlerrm);
2010 End If;
2011 --commit;
2012 RAISE;
2013 END generate_result_code;
2014 ----------------------------------------------------------------------------------------
2015 -- This Api caches the pa bc packets amounts based on the
2016 -- same resource resource grp , project , task etc,
2017 -----------------------------------------------------------------------------------------
2018 PROCEDURE CACHE_PKT_AMOUNTS(
2019 p_project_id in pa_bc_packets.project_id%type
2020 ,p_bdgt_version in pa_bc_packets.budget_version_id%type
2021 ,p_top_task_id in pa_bc_packets.top_task_id%type
2022 ,p_task_id in pa_bc_packets.task_id%type
2023 ,p_bud_task_id in pa_bc_packets.bud_task_id%type
2024 ,p_start_date in DATE
2025 ,p_end_date in DATE
2026 ,p_rlmi in pa_bc_packets.resource_list_member_id%type
2027 ,p_bud_rlmi in pa_bc_packets.bud_resource_list_member_id%type
2028 ,p_prlmi in pa_bc_packets.parent_resource_id%type
2029 ,p_bdgt_ccid in pa_bc_packets.budget_ccid%type
2030 ,p_accounted_dr in number
2031 ,p_accounted_cr in number
2032 ,p_calling_module in varchar2
2033 ,p_partial_flag in varchar2
2034 ,p_function in varchar2 -- add or deduct amts from cache
2035 ,p_bc_packet_id in number
2036 ,p_doc_type in varchar2
2037 ,p_doc_header_id in number
2038 ,p_doc_distribution_id in number
2039 ,x_cached_status out NOCOPY varchar2
2040 ,x_result_code in out NOCOPY varchar2
2041 ,p_counter in number
2042 ) IS
2043 l_res_level_cache VARCHAR2(100);
2044 l_res_grp_level_cache VARCHAR2(100);
2045 l_task_level_cache VARCHAR2(100);
2046 l_top_task_level_cache VARCHAR2(100);
2047 l_proj_level_cache VARCHAR2(100);
2048 l_proj_acct_level_cache VARCHAR2(100);
2049 l_res_level_count NUMBER;
2050 l_res_grp_level_count NUMBER;
2051 l_task_level_count NUMBER;
2052 l_top_task_level_count NUMBER;
2053 l_proj_level_count NUMBER;
2054 l_proj_acct_level_count NUMBER;
2055 l_new_resource VARCHAR2(1);
2056 l_new_resource_group VARCHAR2(1);
2057 l_new_task VARCHAR2(1);
2058 l_new_top_task VARCHAR2(1);
2059 l_new_proj VARCHAR2(1);
2060 l_new_proj_acct VARCHAR2(1);
2061 l_cache_amt_minus number;
2062 l_result_code VARCHAR2(100);
2063 l_res_level_cache_minus VARCHAR2(100);
2064 l_rg_level_cache_minus VARCHAR2(100);
2065 l_task_level_cache_minus VARCHAR2(100);
2066 l_tt_level_cache_minus VARCHAR2(100);
2067 l_proj_level_cache_minus VARCHAR2(100);
2068 l_p_acct_level_cache_minus VARCHAR2(100);
2069 l_number number;
2070 BEGIN
2071
2072 IF p_partial_flag = 'Y' then
2073 IF g_debug_mode = 'Y' THEN
2074 log_message(p_msg_token1 => 'assiging the amts to cache');
2075 End If;
2076
2077 -- Resource level cache
2078 l_res_level_cache := p_project_id||p_bdgt_version||p_bud_task_id||p_prlmi||
2079 p_rlmi||trunc(p_start_date)||trunc(p_end_date);
2080 l_res_level_count := nvl(g_tab_res_level_cache.count,0);
2081
2082 -- Resource Group level cache
2083 l_res_grp_level_cache := p_project_id||p_bdgt_version||p_bud_task_id||p_prlmi||
2084 trunc(p_start_date)||trunc(p_end_date);
2085 l_res_grp_level_count := nvl(g_tab_res_grp_level_cache.count,0);
2086
2087 -- Task level cache
2088 l_task_level_cache := p_project_id||p_bdgt_version||p_top_task_id||p_task_id||
2089 trunc(p_start_date)||trunc(p_end_date);
2090 l_task_level_count := nvl(g_tab_task_level_cache.count,0);
2091
2092 -- Top level cache
2093 l_top_task_level_cache := p_project_id||p_bdgt_version||p_top_task_id||
2094 trunc(p_start_date)||trunc(p_end_date);
2095 l_top_task_level_count := nvl(g_tab_top_task_level_cache.count,0);
2096
2097 -- Project level cache
2098 l_proj_level_cache := p_project_id||p_bdgt_version||trunc(p_start_date)||trunc(p_end_date);
2099 l_proj_level_count := nvl(g_tab_proj_level_cache.count,0);
2100
2101 --project account level cache
2102 l_proj_acct_level_cache := p_project_id||p_bdgt_version||p_bdgt_ccid||
2103 trunc(p_start_date)||trunc(p_end_date);
2104 l_proj_acct_level_count := nvl(g_tab_proj_acct_level_cache.count,0);
2105 IF g_debug_mode = 'Y' THEN
2106 log_message(p_msg_token1 => 'end of assiging the amts to cache');
2107 End If;
2108
2109 End if;
2110
2111 -- check if the same header_id is already failed then donot cache and donot
2112 -- funds check just update the status and result code to failed
2113 IF p_function = 'ADD' then
2114 IF g_debug_mode = 'Y' THEN
2115 log_message(p_msg_token1 => 'inside ADD function');
2116 End If;
2117 x_result_code := null;
2118 x_cached_status := 'Y';
2119 --IF g_tab_doc_header_id.count > 0 then
2120 IF nvl(p_counter,0) > 1 then
2121 --FOR i in 1 .. g_tab_doc_header_id.count LOOP
2122 FOR i in 1 .. p_counter -1 LOOP
2123 /* FOR DISTERADJ and CBC process check at document header level
2124 * even if single transaction found error then
2125 * mark the current transaction as failed
2126 * FOR GL,BASELINE process check at the document distribution
2127 * level
2128 */
2129 IF (p_doc_header_id = g_tab_doc_header_id(i) and
2130 p_doc_type = g_tab_doc_type(i) and
2131 p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
2132 ,'TRXIMPORT','RESERVE_BASELINE') and
2133 p_bc_packet_id <> g_tab_bc_packet_id(i) )
2134 OR
2135 (p_doc_header_id = g_tab_doc_header_id(i) and
2136 p_doc_type = g_tab_doc_type(i) and
2137 p_doc_distribution_id = g_tab_doc_distribution_id(i) and
2138 p_calling_module IN ('GL') and
2139 p_bc_packet_id <> g_tab_bc_packet_id(i) ) Then
2140
2141 If substr(g_tab_result_code(i),1,1) = 'F' then
2142 x_result_code := g_tab_result_code(i);
2143 IF g_debug_mode = 'Y' THEN
2144 log_message(p_msg_token1 => 'failed documnet header found');
2145 End If;
2146 End If;
2147 End if;
2148 END LOOP;
2149 End if;
2150 IF g_debug_mode = 'Y' THEN
2151 log_message(p_msg_token1 => 'end of ADD function');
2152 End If;
2153 If substr(x_result_code,1,1) = 'F' then
2154 x_cached_status := 'N';
2155 return;
2156 End if;
2157 End if;
2158
2159
2160 IF p_function = 'MINUS' then
2161 IF g_debug_mode = 'Y' THEN
2162 log_message(p_msg_token1 => 'Inside MINUS if condition');
2163 End If;
2164
2165 IF g_debug_mode = 'Y' THEN
2166 log_message(p_msg_token1 =>'p_partial_flag = '||p_partial_flag);
2167 end if;
2168
2169 IF p_partial_flag <> 'Y' then
2170 g_r_pkt_amt := NVL(g_r_pkt_amt,0)
2171 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2172 g_rg_pkt_amt := NVL(g_rg_pkt_amt,0)
2173 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2174 g_t_pkt_amt := NVL(g_t_pkt_amt,0)
2175 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2176 g_tt_pkt_amt := NVL(g_tt_pkt_amt,0)
2177 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2178 g_p_pkt_amt := NVL(g_p_pkt_amt,0)
2179 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2180 g_p_acct_pkt_amt := NVL(g_p_acct_pkt_amt,0)
2181 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2182
2183 END IF;
2184
2185 IF p_partial_flag = 'Y' then
2186 -- check if the same header id is already passed but this raw / burden line fails
2187 -- then deduct that amount from the passed line and synchonize the status and result
2188 -- codes for minus
2189 l_result_code := x_result_code;
2190 l_cache_amt_minus := 0;
2191 IF g_debug_mode = 'Y' THEN
2192 log_message(p_msg_token1 => 'check g_tab_doc_header_id.count ');
2193 End If;
2194 --IF g_tab_doc_header_id.count > 0 then
2195 IF nvl(p_counter,0) > 1 then
2196 IF g_debug_mode = 'Y' THEN
2197 log_message(p_msg_token1 => 'opening cursor num = '||g_tab_doc_header_id.count );
2198 End If;
2199 FOR i in 1 .. p_counter - 1 LOOP
2200 If (p_doc_header_id = g_tab_doc_header_id(i) and
2201 p_doc_type = g_tab_doc_type(i) and
2202 p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
2203 ,'TRXIMPORT','RESERVE_BASELINE') and
2204 p_bc_packet_id <> g_tab_bc_packet_id(i) )
2205 OR
2206 (p_doc_header_id = g_tab_doc_header_id(i) and
2207 p_doc_type = g_tab_doc_type(i) and
2208 p_doc_distribution_id = g_tab_doc_distribution_id(i) and
2209 p_calling_module IN ('GL') and
2210 p_bc_packet_id <> g_tab_bc_packet_id(i) ) then
2211
2212 If substr(g_tab_result_code(i),1,2) = 'P1'
2213 and g_tab_start_date.EXISTS(i) and g_tab_end_date.EXISTS(i) then
2214
2215 l_cache_amt_minus := nvl(g_tab_accounted_dr(i),0)
2216 - nvl(g_tab_accounted_cr(i),0);
2217 IF g_debug_mode = 'Y' THEN
2218 log_message(p_msg_token1 => 'l_res_level_cache_minus, bc_packet_id ['
2219 ||p_bc_packet_id||']g_tab_proj count['||
2220 g_tab_project_id(i)||']');
2221 End IF;
2222
2223 l_res_level_cache_minus :=
2224 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_bud_task_id(i)
2225 ||g_tab_p_resource_id(i)||g_tab_rlmi(i)||trunc(g_tab_start_date(i))||
2226 trunc(g_tab_end_date(i));
2227 IF g_debug_mode = 'Y' THEN
2228 log_message(p_msg_token1 => 'l_rg_level_cache_minus');
2229 End If;
2230
2231 l_rg_level_cache_minus :=
2232 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_bud_task_id(i)
2233 ||g_tab_p_resource_id(i)||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2234 IF g_debug_mode = 'Y' THEN
2235 log_message(p_msg_token1 => 'l_task_level_cache_minus');
2236 End If;
2237 l_task_level_cache_minus :=
2238 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_tt_task_id(i)
2239 ||g_tab_task_id(i)||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2240
2241 IF g_debug_mode = 'Y' THEN
2242 log_message(p_msg_token1 =>'l_tt_level_cache_minus');
2243 End If;
2244 l_tt_level_cache_minus :=
2245 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_tt_task_id(i)
2246 ||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2247 IF g_debug_mode = 'Y' THEN
2248 log_message(p_msg_token1 =>'l_proj_level_cache_minus');
2249 End If;
2250
2251 l_proj_level_cache_minus :=
2252 g_tab_project_id(i)||g_tab_budget_version_id(i)
2253 ||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2254 IF g_debug_mode = 'Y' THEN
2255 log_message(p_msg_token1 =>'l_p_acct_level_cache_minus');
2256 End if;
2257
2258 l_p_acct_level_cache_minus :=
2259 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_budget_ccid(i)
2260 ||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2261
2262 -- Resource level
2263 IF g_debug_mode = 'Y' THEN
2264 log_message(p_msg_token1 =>'check l_res_level_count > 0');
2265 End If;
2266 IF l_res_level_count > 0 then
2267 IF g_debug_mode = 'Y' THEN
2268 log_message(p_msg_token1 =>'count = '||l_res_level_count);
2269 End if;
2270 FOR j IN 1 .. l_res_level_count LOOP
2271 IF g_debug_mode = 'Y' THEN
2272 log_message(p_msg_token1 => 'Iside for loop Resource level ');
2273 End IF;
2274 If g_tab_res_level_cache(j) = l_res_level_cache_minus then
2275 IF g_debug_mode = 'Y' THEN
2276 log_message(p_msg_token1 =>'minus cache found');
2277 End If;
2278 g_tab_res_level_cache_amt(j) :=
2279 NVL(g_tab_res_level_cache_amt(j),0) -
2280 nvl(l_cache_amt_minus,0);
2281 EXIT;
2282 END IF;
2283 END LOOP;
2284 End if;
2285
2286 -- Resource Group level
2287 IF l_res_grp_level_count > 0 then
2288 FOR j IN 1 .. l_res_grp_level_count LOOP
2289 IF g_debug_mode = 'Y' THEN
2290 log_message(p_msg_token1 => 'Inside for loop Resource Group level');
2291 End If;
2292 If g_tab_res_grp_level_cache(j) = l_rg_level_cache_minus then
2293 IF g_debug_mode = 'Y' THEN
2294 log_message(p_msg_token1 =>'minus cahce found at res grp');
2295 End If;
2296 g_tab_res_grp_level_cache_amt(j) :=
2297 NVL(g_tab_res_grp_level_cache_amt(j),0) -
2298 nvl(l_cache_amt_minus,0);
2299 EXIT;
2300 END IF;
2301 END LOOP;
2302 End if;
2303 -- Task level
2304 IF l_task_level_count > 0 then
2305 FOR j IN 1 .. l_task_level_count LOOP
2306 IF g_debug_mode = 'Y' THEN
2307 log_message(p_msg_token1 => 'Inside for loop minus Task level');
2308 End IF;
2309 If g_tab_task_level_cache(j) = l_task_level_cache_minus then
2310 IF g_debug_mode = 'Y' THEN
2311 log_message(p_msg_token1 =>'minus cahce found at task level');
2312 End If;
2313 g_tab_task_level_cache_amt(j) :=
2314 NVL(g_tab_task_level_cache_amt(j),0) -
2315 nvl(l_cache_amt_minus,0);
2316 EXIT;
2317 END IF;
2318 END LOOP;
2319 End if;
2320
2321 -- Top task level
2322 IF l_top_task_level_count > 0 then
2323 FOR j IN 1 .. l_top_task_level_count LOOP
2324 IF g_debug_mode = 'Y' THEN
2325 log_message(p_msg_token1 => 'Inside for loop minus Top task level');
2326 End If;
2327 If g_tab_top_task_level_cache(j) = l_tt_level_cache_minus then
2328 IF g_debug_mode = 'Y' THEN
2329 log_message(p_msg_token1 =>'minus cahce found at tt');
2330 End If;
2331 g_tab_top_task_level_cache_amt(j) :=
2332 NVL(g_tab_top_task_level_cache_amt(j),0) -
2333 nvl(l_cache_amt_minus,0);
2334 EXIT;
2335 END IF;
2336 END LOOP;
2337 End if;
2338 -- Project level
2339 IF l_proj_level_count > 0 then
2340 FOR j IN 1 .. l_proj_level_count LOOP
2341 IF g_debug_mode = 'Y' THEN
2342 log_message(p_msg_token1 => 'Inside for loop at Project level');
2343 End If;
2344 If g_tab_proj_level_cache(j) = l_proj_level_cache_minus then
2345 IF g_debug_mode = 'Y' THEN
2346 log_message(p_msg_token1 =>'minus cahce found at proj');
2347 End If;
2348 g_tab_proj_level_cache_amt(j) :=
2349 NVL(g_tab_proj_level_cache_amt(j),0) -
2350 nvl(l_cache_amt_minus,0);
2351 EXIT;
2352 END IF;
2353 END LOOP;
2354 End if;
2355 -- Project account level
2356 IF l_proj_acct_level_count > 0 then
2357 FOR j IN 1 .. l_proj_acct_level_count LOOP
2358 IF g_debug_mode = 'Y' THEN
2359 log_message(p_msg_token1 => 'inside for loop minus Project account level');
2360 End If;
2361 If g_tab_proj_acct_level_cache(j) = l_p_acct_level_cache_minus then
2362 IF g_debug_mode = 'Y' THEN
2363 log_message(p_msg_token1 =>'minus cahce found at p acct');
2364 End if;
2365 g_tab_prj_acct_level_cache_amt(j) :=
2366 NVL(g_tab_prj_acct_level_cache_amt(j),0) -
2367 nvl(l_cache_amt_minus,0);
2368 EXIT;
2369 END IF;
2370 END LOOP;
2371 End if;
2372 IF g_debug_mode = 'Y' THEN
2373 log_message(p_msg_token1 => 'passed documnet header found['||l_result_code||']' );
2374 End IF;
2375 g_tab_result_code(i) := l_result_code ;
2376 End If;
2377 End if;
2378 END LOOP;
2379 End if;
2380
2381 ---Deduct the amount from present failed document
2382 -- Resource level
2383 IF l_res_level_count > 0 then
2384 FOR I IN 1 .. l_res_level_count LOOP
2385 IF g_debug_mode = 'Y' THEN
2386 log_message(p_msg_token1 => 'Iside for loop Resource level');
2387 End If;
2388 If g_tab_res_level_cache(I) = l_res_level_cache then
2389 IF g_debug_mode = 'Y' THEN
2390 log_message(p_msg_token1 =>'same cahce found');
2391 End If;
2392 g_tab_res_level_cache_amt(I) :=
2393 NVL(g_tab_res_level_cache_amt(I),0) -
2394 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2395
2396 g_r_pkt_amt := g_tab_res_level_cache_amt(I);
2397 EXIT;
2398 END IF;
2399 END LOOP;
2400 End if;
2401 -- Resource Group level
2402 If l_res_grp_level_count > 0 then
2403 FOR I IN 1 .. l_res_grp_level_count LOOP
2404 IF g_debug_mode = 'Y' THEN
2405 log_message(p_msg_token1 => 'Iside for loop Resource Group level');
2406 End if;
2407 If g_tab_res_grp_level_cache(I) = l_res_grp_level_cache then
2408 IF g_debug_mode = 'Y' THEN
2409 log_message(p_msg_token1 =>'same cahce found');
2410 End if;
2411 g_tab_res_grp_level_cache_amt(I) :=
2412 NVL(g_tab_res_grp_level_cache_amt(I),0) -
2413 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2414
2415 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(I);
2416 EXIT;
2417 END IF;
2418 END LOOP;
2419 End if ;
2420 -- Task level
2421 If l_task_level_count > 0 then
2422 FOR I IN 1 .. l_task_level_count LOOP
2423 IF g_debug_mode = 'Y' THEN
2424 log_message(p_msg_token1 => 'Iside for loop Task level');
2425 End IF;
2426 If g_tab_task_level_cache(I) = l_task_level_cache then
2427 IF g_debug_mode = 'Y' THEN
2428 log_message(p_msg_token1 =>'same cahce found');
2429 End IF;
2430 g_tab_task_level_cache_amt(I) :=
2431 NVL(g_tab_task_level_cache_amt(I),0) -
2432 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2433 g_t_pkt_amt := g_tab_task_level_cache_amt(I);
2434 EXIT;
2435 END IF;
2436 END LOOP;
2437 End if;
2438 -- Top task level
2439 IF l_top_task_level_count > 0 then
2440 FOR I IN 1 .. l_top_task_level_count LOOP
2441 IF g_debug_mode = 'Y' THEN
2442 log_message(p_msg_token1 => 'Iside for loop Top task level');
2443 End IF;
2444 If g_tab_top_task_level_cache(I) = l_top_task_level_cache then
2445 IF g_debug_mode = 'Y' THEN
2446 log_message(p_msg_token1 =>'same cahce found');
2447 End IF;
2448 g_tab_top_task_level_cache_amt(I) :=
2449 NVL(g_tab_top_task_level_cache_amt(I),0) -
2450 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2451 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(I);
2452 EXIT;
2453 END IF;
2454 END LOOP;
2455 End if;
2456 -- Project level
2457 IF l_proj_level_count > 0 then
2458 FOR I IN 1 .. l_proj_level_count LOOP
2459 IF g_debug_mode = 'Y' THEN
2460 log_message(p_msg_token1 => 'Iside for loop Project level ');
2461 End if;
2462 If g_tab_proj_level_cache(I) = l_proj_level_cache then
2463 IF g_debug_mode = 'Y' THEN
2464 log_message(p_msg_token1 =>'same cahce found');
2465 End IF;
2466 g_tab_proj_level_cache_amt(I) :=
2467 NVL(g_tab_proj_level_cache_amt(I),0) -
2468 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2469 g_p_pkt_amt := g_tab_proj_level_cache_amt(I);
2470 EXIT;
2471 END IF;
2472 END LOOP;
2473 End if;
2474 -- Project account level
2475 IF l_proj_acct_level_count > 0 then
2476 FOR I IN 1 .. l_proj_acct_level_count LOOP
2477 IF g_debug_mode = 'Y' THEN
2478 log_message(p_msg_token1 => 'Iside for loop Project account level');
2479 End If;
2480 If g_tab_proj_acct_level_cache(I) = l_proj_acct_level_cache then
2481 IF g_debug_mode = 'Y' THEN
2482 log_message(p_msg_token1 =>'same cahce found');
2483 End IF;
2484 g_tab_prj_acct_level_cache_amt(I) :=
2485 NVL(g_tab_prj_acct_level_cache_amt(I),0) -
2486 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2487 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(I);
2488 EXIT;
2489 END IF;
2490 END LOOP;
2491 End if;
2492
2493 END IF; -- end if for partial flag
2494 IF g_debug_mode = 'Y' THEN
2495 log_message(p_msg_token1 =>'g_r_pkt_amt ['||g_r_pkt_amt||']g_rg_pkt_amt['||
2496 g_rg_pkt_amt||']g_t_pkt_amt ['||g_t_pkt_amt||']g_tt_pkt_amt ['||
2497 g_tt_pkt_amt||']g_p_pkt_amt ['||g_p_pkt_amt||']g_p_acct_pkt_amt ['||
2498 g_p_acct_pkt_amt||']' );
2499 End IF;
2500 RETURN;
2501
2502 END IF; -- end if for minus function
2503
2504 --------------------------------------------------------------------------------------
2505 IF g_debug_mode = 'Y' THEN
2506 log_message(p_msg_token1 => 'Inside the CACHE_PKT_AMOUNT api');
2507 End IF;
2508 -- Resource level Balances
2509 IF (p_project_id = g_pre_project_id) AND
2510 (p_bdgt_version = g_pre_bdgt_version_id) AND
2511 (p_bud_task_id = g_pre_bud_task_id) AND
2512 (p_prlmi = g_pre_prlmi) AND
2513 (p_rlmi = g_pre_rlmi) AND
2514 (trunc(p_start_date) = trunc(g_pre_start_date) ) /*AND
2515 (trunc(p_end_date) = trunc(g_pre_end_date) ) */ THEN /* bug 8635962*/
2516 IF g_debug_mode = 'Y' THEN
2517 log_message(p_msg_token1 => ' same resource ');
2518 End IF;
2519
2520 IF p_partial_flag <> 'Y' then
2521
2522 g_r_pkt_amt := NVL(g_r_pkt_amt,0)
2523 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2524 ELse
2525 IF g_debug_mode = 'Y' THEN
2526 log_message(p_msg_token1 =>'res level count ='||l_res_level_count);
2527 End IF;
2528 IF l_res_level_count > 0 then
2529 IF g_debug_mode = 'Y' THEN
2530 log_message(p_msg_token1 => 'l_res_level_count > 0');
2531 End IF;
2532 FOR I IN 1 .. l_res_level_count LOOP
2533 IF g_debug_mode = 'Y' THEN
2534 log_message(p_msg_token1 => 'Iside for loop');
2535 End IF;
2536 If g_tab_res_level_cache(I) = l_res_level_cache then
2537 IF g_debug_mode = 'Y' THEN
2538 log_message(p_msg_token1 =>'same cahce found');
2539 End IF;
2540 g_tab_res_level_cache_amt(I) :=
2541 NVL(g_tab_res_level_cache_amt(I),0)+
2542 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2543
2544 g_r_pkt_amt := g_tab_res_level_cache_amt(I);
2545 EXIT;
2546 END IF;
2547 END LOOP;
2548 END IF ;
2549 END IF;
2550
2551 ELSE
2552 IF g_debug_mode = 'Y' THEN
2553 log_message(p_msg_token1 => ' new resource');
2554 End if;
2555 IF p_partial_flag <> 'Y' then
2556 g_r_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2557 Else
2558 l_new_resource := 'N';
2559 IF g_debug_mode = 'Y' THEN
2560 log_message(p_msg_token1 =>'res level count ='||l_res_level_count);
2561 End IF;
2562 IF l_res_level_count > 0 then
2563 IF g_debug_mode = 'Y' THEN
2564 log_message(p_msg_token1 => 'l_res_level_count > 0');
2565 End IF;
2566 FOR I IN 1 .. l_res_level_count LOOP
2567 IF g_debug_mode = 'Y' THEN
2568 log_message(p_msg_token1 => 'Iside for loop');
2569 End If;
2570 If g_tab_res_level_cache(I) = l_res_level_cache then
2571 IF g_debug_mode = 'Y' THEN
2572 log_message(p_msg_token1 =>'same cahce found');
2573 End IF;
2574 g_tab_res_level_cache_amt(I) :=
2575 NVL(g_tab_res_level_cache_amt(I),0)+
2576 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2577 g_r_pkt_amt := g_tab_res_level_cache_amt(I);
2578 l_new_resource := 'N';
2579 EXIT;
2580 END IF;
2581 l_new_resource := 'Y';
2582 END LOOP;
2583 END IF;
2584 IF g_debug_mode = 'Y' THEN
2585 log_message(p_msg_token1 =>' l_new_resource = '||l_new_resource);
2586 End IF;
2587 IF l_new_resource = 'Y' or l_res_level_count <= 0 then
2588 IF g_debug_mode = 'Y' THEN
2589 log_message(p_msg_token1 => 'adding to cache');
2590 End IF;
2591 g_tab_res_level_cache(l_res_level_count+1) := l_res_level_cache;
2592 g_tab_res_level_cache_amt(l_res_level_count+1) :=
2593 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2594
2595 g_r_pkt_amt := g_tab_res_level_cache_amt(l_res_level_count+1);
2596 END IF;
2597
2598 END IF;
2599 END IF;
2600 IF g_debug_mode = 'Y' THEN
2601 log_message(p_msg_token1 => 'res amount ='||g_r_pkt_amt);
2602 End If;
2603 -------------------------------------------------------------------------------------------
2604 -- Resource Group level Balances
2605
2606 IF (p_project_id = g_pre_project_id) AND
2607 (p_bdgt_version = g_pre_bdgt_version_id) AND
2608 (p_bud_task_id = g_pre_bud_task_id) AND
2609 (p_prlmi = g_pre_prlmi) AND
2610 (p_prlmi <> 0 or p_rlmi = g_pre_rlmi) and --added p_prlmi <> 0 for bug 11852123
2611 --(p_rlmi = g_pre_rlmi) AND
2612 (trunc(p_start_date) = trunc(g_pre_start_date) ) /* AND
2613 (trunc(p_end_date) = trunc(g_pre_end_date) ) */ THEN /* bug 8635962*/
2614 IF g_debug_mode = 'Y' THEN
2615 log_message(p_msg_token1 => ' same res grp ');
2616 End If;
2617
2618 IF p_partial_flag <> 'Y' then
2619 g_rg_pkt_amt := NVL(g_rg_pkt_amt,0)
2620 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2621 Else
2622 IF g_debug_mode = 'Y' THEN
2623 log_message(p_msg_token1 =>'res grp level count ='||l_res_grp_level_count);
2624 End IF;
2625 IF l_res_grp_level_count > 0 then
2626 IF g_debug_mode = 'Y' THEN
2627 log_message(p_msg_token1 => 'l_res_grp_level_count > 0');
2628 End If;
2629 FOR I IN 1 .. l_res_grp_level_count LOOP
2630 IF g_debug_mode = 'Y' THEN
2631 log_message(p_msg_token1 => 'Iside for loop');
2632 End If;
2633 If g_tab_res_grp_level_cache(I) = l_res_grp_level_cache then
2634 IF g_debug_mode = 'Y' THEN
2635 log_message(p_msg_token1 =>'same cahce found');
2636 End IF;
2637 g_tab_res_grp_level_cache_amt(I) :=
2638 NVL(g_tab_res_grp_level_cache_amt(I),0)+
2639 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2640
2641 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(I);
2642 EXIT;
2643 END IF;
2644 END LOOP;
2645 END IF ;
2646 END IF;
2647
2648 ELSE
2649 IF g_debug_mode = 'Y' THEN
2650 log_message(p_msg_token1 => ' new res grp');
2651 End IF;
2652
2653 IF p_partial_flag <> 'Y' then
2654 g_rg_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2655 Else
2656
2657 l_new_resource_group := 'N';
2658 IF g_debug_mode = 'Y' THEN
2659 log_message(p_msg_token1 =>'res grp level count ='||l_res_grp_level_count);
2660 End IF;
2661 IF l_res_grp_level_count > 0 then
2662 IF g_debug_mode = 'Y' THEN
2663 log_message(p_msg_token1 => 'l_res_grp_level_count > 0');
2664 End IF;
2665 FOR I IN 1 .. l_res_grp_level_count LOOP
2666 IF g_debug_mode = 'Y' THEN
2667 log_message(p_msg_token1 => 'Iside for loop');
2668 End IF;
2669 If g_tab_res_grp_level_cache(I) = l_res_grp_level_cache then
2670 IF g_debug_mode = 'Y' THEN
2671 log_message(p_msg_token1 =>'same cahce found');
2672 End If;
2673 g_tab_res_grp_level_cache_amt(I) :=
2674 NVL(g_tab_res_grp_level_cache_amt(I),0)+
2675 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2676 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(I);
2677 l_new_resource_group := 'N';
2678 EXIT;
2679 END IF;
2680 l_new_resource_group := 'Y';
2681 END LOOP;
2682 END IF;
2683 IF g_debug_mode = 'Y' THEN
2684 log_message(p_msg_token1 =>' l_new_resource_group = '||l_new_resource_group);
2685 End If;
2686 IF l_new_resource_group = 'Y' or l_res_grp_level_count <= 0 then
2687 IF g_debug_mode = 'Y' THEN
2688 log_message(p_msg_token1 => 'adding to cache');
2689 End IF;
2690 g_tab_res_grp_level_cache(l_res_grp_level_count+1) := l_res_grp_level_cache;
2691 g_tab_res_grp_level_cache_amt(l_res_grp_level_count+1) :=
2692 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2693
2694 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(l_res_grp_level_count+1);
2695 END IF;
2696 END IF;
2697 END IF;
2698 IF g_debug_mode = 'Y' THEN
2699 log_message(p_msg_token1 => ' res grp bal ='||g_rg_pkt_amt);
2700 End IF;
2701 -------------------------------------------------------------------------------------
2702 -- Task level balances
2703
2704 IF (p_project_id = g_pre_project_id) AND
2705 (p_bdgt_version = g_pre_bdgt_version_id) AND
2706 (p_task_id = g_pre_task_id) AND
2707 (p_top_task_id = g_pre_top_task_id) AND
2708 --(p_prlmi = g_pre_prlmi) AND
2709 --(p_rlmi = g_pre_rlmi) AND
2710 (trunc(p_start_date) = trunc(g_pre_start_date) ) /* AND
2711 (trunc(p_end_date) = trunc(g_pre_end_date) ) */ THEN /* bug 8635962*/
2712 IF g_debug_mode = 'Y' THEN
2713 log_message(p_msg_token1 => ' same task level ');
2714 End IF;
2715
2716 IF p_partial_flag <> 'Y' then
2717 g_t_pkt_amt := NVL(g_t_pkt_amt,0)
2718 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2719
2720 Else
2721 IF g_debug_mode = 'Y' THEN
2722 log_message(p_msg_token1 =>'task level count ='||l_task_level_count);
2723 end IF;
2724 IF l_task_level_count > 0 then
2725 IF g_debug_mode = 'Y' THEN
2726 log_message(p_msg_token1 => 'l_task_level_count > 0');
2727 end if;
2728 FOR I IN 1 .. l_task_level_count LOOP
2729 IF g_debug_mode = 'Y' THEN
2730 log_message(p_msg_token1 => 'Iside for loop');
2731 End if;
2732 If g_tab_task_level_cache(I) = l_task_level_cache then
2733 IF g_debug_mode = 'Y' THEN
2734 log_message(p_msg_token1 =>'same cahce found');
2735 End if;
2736 g_tab_task_level_cache_amt(I) :=
2737 NVL(g_tab_task_level_cache_amt(I),0)+
2738 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2739 g_t_pkt_amt := g_tab_task_level_cache_amt(I);
2740 EXIT;
2741 END IF;
2742 END LOOP;
2743 END IF ;
2744 END IF;
2745
2746 ELSE
2747 IF g_debug_mode = 'Y' THEN
2748 log_message(p_msg_token1 => ' new task level ');
2749 End If;
2750 IF p_partial_flag <> 'Y' then
2751 g_t_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2752
2753 Else
2754 l_new_task := 'N';
2755 IF g_debug_mode = 'Y' THEN
2756 log_message(p_msg_token1 =>'task level count ='||l_task_level_count);
2757 end IF;
2758 IF l_task_level_count > 0 then
2759 IF g_debug_mode = 'Y' THEN
2760 log_message(p_msg_token1 => 'l_task_level_count > 0');
2761 end if;
2762 FOR I IN 1 .. l_task_level_count LOOP
2763 IF g_debug_mode = 'Y' THEN
2764 log_message(p_msg_token1 => 'Iside for loop');
2765 End If;
2766 If g_tab_task_level_cache(I) = l_task_level_cache then
2767 IF g_debug_mode = 'Y' THEN
2768 log_message(p_msg_token1 =>'same cahce found');
2769 end If;
2770 g_tab_task_level_cache_amt(I) :=
2771 NVL(g_tab_task_level_cache_amt(I),0)+
2772 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2773 g_t_pkt_amt := g_tab_task_level_cache_amt(I);
2774 l_new_task := 'N';
2775 EXIT;
2776 END IF;
2777 l_new_task := 'Y';
2778 END LOOP;
2779 END IF;
2780 IF g_debug_mode = 'Y' THEN
2781 log_message(p_msg_token1 =>' l_new_task= '||l_new_task);
2782 end if;
2783 IF l_new_task = 'Y' or l_task_level_count <= 0 then
2784 IF g_debug_mode = 'Y' THEN
2785 log_message(p_msg_token1 => 'adding to cache');
2786 End IF;
2787 g_tab_task_level_cache(l_task_level_count+1) := l_task_level_cache;
2788 g_tab_task_level_cache_amt(l_task_level_count+1) :=
2789 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2790 g_t_pkt_amt := g_tab_task_level_cache_amt(l_task_level_count+1);
2791 END IF;
2792 END IF;
2793 END IF;
2794 IF g_debug_mode = 'Y' THEN
2795 log_message(p_msg_token1 => ' task level bal ='||g_t_pkt_amt);
2796 End IF;
2797 ----------------------------------------------------------------------------------------------
2798 --Top Task level Balances
2799
2800 IF (p_project_id = g_pre_project_id) AND
2801 (p_bdgt_version = g_pre_bdgt_version_id) AND
2802 --(p_task_id = g_pre_task_id) AND
2803 (p_top_task_id = g_pre_top_task_id) AND
2804 --(p_prlmi = g_pre_prlmi) AND
2805 --(p_rlmi = g_pre_rlmi) AND
2806 (trunc(p_start_date) = trunc(g_pre_start_date) ) /* AND
2807 (trunc(p_end_date) = trunc(g_pre_end_date) ) */ THEN /* bug 8635962*/
2808 IF g_debug_mode = 'Y' THEN
2809 log_message(p_msg_token1 => ' same top task ');
2810 end If;
2811
2812 IF p_partial_flag <> 'Y' then
2813
2814 g_tt_pkt_amt := NVL(g_tt_pkt_amt,0)
2815 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2816
2817 Else
2818 IF g_debug_mode = 'Y' THEN
2819 log_message(p_msg_token1 =>'top task level count ='||l_top_task_level_count);
2820 End if;
2821 IF l_top_task_level_count > 0 then
2822 IF g_debug_mode = 'Y' THEN
2823 log_message(p_msg_token1 => 'l_top_task_level_count > 0');
2824 End If;
2825 FOR I IN 1 .. l_top_task_level_count LOOP
2826 IF g_debug_mode = 'Y' THEN
2827 log_message(p_msg_token1 => 'Iside for loop');
2828 end if;
2829 If g_tab_top_task_level_cache(I) = l_top_task_level_cache then
2830 IF g_debug_mode = 'Y' THEN
2831 log_message(p_msg_token1 =>'same cahce found');
2832 end if;
2833 g_tab_top_task_level_cache_amt(I) :=
2834 NVL(g_tab_top_task_level_cache_amt(I),0)+
2835 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2836 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(I);
2837 EXIT;
2838 END IF;
2839 END LOOP;
2840 END IF ;
2841 END IF;
2842
2843 ELSE
2844 IF g_debug_mode = 'Y' THEN
2845 log_message(p_msg_token1 => ' new top task level');
2846 End IF;
2847 IF p_partial_flag <> 'Y' then
2848 g_tt_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2849
2850 Else
2851 l_new_top_task := 'N';
2852 IF g_debug_mode = 'Y' THEN
2853 log_message(p_msg_token1 =>' top task level count ='||l_top_task_level_count);
2854 end if;
2855 IF l_top_task_level_count > 0 then
2856 IF g_debug_mode = 'Y' THEN
2857 log_message(p_msg_token1 => 'l_top_task_level_count > 0');
2858 end if;
2859 FOR I IN 1 .. l_top_task_level_count LOOP
2860 IF g_debug_mode = 'Y' THEN
2861 log_message(p_msg_token1 => 'Iside for loop');
2862 end if;
2863 If g_tab_top_task_level_cache(I) = l_top_task_level_cache then
2864 IF g_debug_mode = 'Y' THEN
2865 log_message(p_msg_token1 =>'same cahce found');
2866 end if;
2867 g_tab_top_task_level_cache_amt(I) :=
2868 NVL(g_tab_top_task_level_cache_amt(I),0)+
2869 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2870 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(I);
2871 l_new_top_task := 'N';
2872 EXIT;
2873 END IF;
2874 l_new_top_task := 'Y';
2875 END LOOP;
2876 END IF;
2877 IF g_debug_mode = 'Y' THEN
2878 log_message(p_msg_token1 =>' l_new_top_task= '||l_new_top_task);
2879 end if;
2880 IF l_new_top_task = 'Y' or l_top_task_level_count <= 0 then
2881 IF g_debug_mode = 'Y' THEN
2882 log_message(p_msg_token1 => 'adding to cache');
2883 end if;
2884 g_tab_top_task_level_cache(l_top_task_level_count+1) := l_top_task_level_cache;
2885 g_tab_top_task_level_cache_amt(l_top_task_level_count+1) :=
2886 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2887 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(l_top_task_level_count+1);
2888 END IF;
2889 END IF;
2890 END IF;
2891 IF g_debug_mode = 'Y' THEN
2892 log_message(p_msg_token1 => 'top task level bal ='||g_tt_pkt_amt);
2893 end if;
2894
2895 --------------------------------------------------------------------------------------------------------
2896 -- Project level Balances
2897
2898 IF (p_project_id = g_pre_project_id) AND
2899 (p_bdgt_version = g_pre_bdgt_version_id) AND
2900 --(p_task_id = g_pre_task_id) AND
2901 --(p_top_task_id = g_pre_top_task_id) AND
2902 --(p_prlmi = g_pre_prlmi) AND
2903 --(p_rlmi = g_pre_rlmi) AND
2904 (trunc(p_start_date) = trunc(g_pre_start_date) ) /* AND
2905 (trunc(p_end_date) = trunc(g_pre_end_date) )*/ THEN /* bug 8635962*/
2906 IF g_debug_mode = 'Y' THEN
2907 log_message(p_msg_token1 => ' same project ');
2908 end if;
2909
2910 IF p_partial_flag <> 'Y' then
2911 g_p_pkt_amt := NVL(g_p_pkt_amt,0)
2912 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2913
2914 Else
2915 IF g_debug_mode = 'Y' THEN
2916 log_message(p_msg_token1 =>'project level count ='||l_proj_level_count);
2917 end if;
2918 IF l_proj_level_count > 0 then
2919 IF g_debug_mode = 'Y' THEN
2920 log_message(p_msg_token1 => 'l_proj_level_count > 0');
2921 end if;
2922 FOR I IN 1 .. l_proj_level_count LOOP
2923 IF g_debug_mode = 'Y' THEN
2924 log_message(p_msg_token1 => 'Iside for loop');
2925 end if;
2926 If g_tab_proj_level_cache(I) = l_proj_level_cache then
2927 IF g_debug_mode = 'Y' THEN
2928 log_message(p_msg_token1 =>'same cahce found');
2929 end if;
2930 g_tab_proj_level_cache_amt(I) :=
2931 NVL(g_tab_proj_level_cache_amt(I),0)+
2932 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2933 g_p_pkt_amt := g_tab_proj_level_cache_amt(I);
2934 EXIT;
2935 END IF;
2936 END LOOP;
2937 END IF ;
2938
2939 END IF;
2940
2941 ELSE
2942 IF g_debug_mode = 'Y' THEN
2943 log_message(p_msg_token1 => ' new project');
2944 end if;
2945
2946 IF p_partial_flag <> 'Y' then
2947 g_p_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2948
2949 Else
2950 l_new_proj := 'N';
2951 IF g_debug_mode = 'Y' THEN
2952 log_message(p_msg_token1 =>' proj level count ='||l_proj_level_count);
2953 end if;
2954 IF l_proj_level_count > 0 then
2955 IF g_debug_mode = 'Y' THEN
2956 log_message(p_msg_token1 => 'l_proj_level_count > 0');
2957 end if;
2958 FOR I IN 1 .. l_proj_level_count LOOP
2959 IF g_debug_mode = 'Y' THEN
2960 log_message(p_msg_token1 => 'Iside for loop');
2961 end if;
2962 If g_tab_proj_level_cache(I) = l_proj_level_cache then
2963 IF g_debug_mode = 'Y' THEN
2964 log_message(p_msg_token1 =>'same cahce found');
2965 end if;
2966 g_tab_proj_level_cache_amt(I) :=
2967 NVL(g_tab_proj_level_cache_amt(I),0)+
2968 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2969 g_p_pkt_amt := g_tab_proj_level_cache_amt(I);
2970 l_new_proj := 'N';
2971 EXIT;
2972 END IF;
2973 l_new_proj := 'Y';
2974 END LOOP;
2975 END IF;
2976 IF g_debug_mode = 'Y' THEN
2977 log_message(p_msg_token1 =>' l_new_proj= '||l_new_proj);
2978 end if;
2979 IF l_new_proj = 'Y' or l_proj_level_count <= 0 then
2980 IF g_debug_mode = 'Y' THEN
2981 log_message(p_msg_token1 => 'adding to cache');
2982 end if;
2983 g_tab_proj_level_cache(l_proj_level_count+1) := l_proj_level_cache;
2984 g_tab_proj_level_cache_amt(l_proj_level_count+1) :=
2985 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2986 g_p_pkt_amt := g_tab_proj_level_cache_amt(l_proj_level_count+1);
2987 END IF;
2988 END IF;
2989 END IF;
2990 IF g_debug_mode = 'Y' THEN
2991 log_message(p_msg_token1 => 'project bal ='||g_p_pkt_amt);
2992 end if;
2993 ------------------------------------------------------------------------------------------------
2994 -- project account level Balances
2995
2996 IF (p_project_id = g_pre_project_id) AND
2997 (p_bdgt_version = g_pre_bdgt_version_id) AND
2998 (p_bdgt_ccid = g_pre_bdgt_ccid ) AND
2999 --(p_task_id = g_pre_task_id) AND
3000 --(p_top_task_id = g_pre_top_task_id) AND
3001 --(p_prlmi = g_pre_prlmi) AND
3002 --(p_rlmi = g_pre_rlmi) AND
3003 (trunc(p_start_date) = trunc(g_pre_start_date) ) /* AND
3004 (trunc(p_end_date) = trunc(g_pre_end_date) ) */ THEN /* bug 8635962*/
3005 IF g_debug_mode = 'Y' THEN
3006 log_message(p_msg_token1 => ' same project account');
3007 end if;
3008
3009 IF p_partial_flag <> 'Y' then
3010 g_p_acct_pkt_amt := NVL(g_p_acct_pkt_amt,0)
3011 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3012
3013 Else
3014 IF g_debug_mode = 'Y' THEN
3015 log_message(p_msg_token1 =>'project acct level count ='||l_proj_acct_level_count);
3016 end if;
3017 IF l_proj_acct_level_count > 0 then
3018 IF g_debug_mode = 'Y' THEN
3019 log_message(p_msg_token1 => 'l_proj_acct_level_count > 0');
3020 end if;
3021 FOR I IN 1 .. l_proj_acct_level_count LOOP
3022 IF g_debug_mode = 'Y' THEN
3023 log_message(p_msg_token1 => 'Iside for loop');
3024 end if;
3025 If g_tab_proj_acct_level_cache(I) = l_proj_acct_level_cache then
3026 IF g_debug_mode = 'Y' THEN
3027 log_message(p_msg_token1 =>'same cahce found');
3028 end if;
3029 g_tab_prj_acct_level_cache_amt(I) :=
3030 NVL(g_tab_prj_acct_level_cache_amt(I),0)+
3031 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3032 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(I);
3033 EXIT;
3034 END IF;
3035 END LOOP;
3036 END IF ;
3037 END IF;
3038
3039 ELSE
3040 IF g_debug_mode = 'Y' THEN
3041 log_message(p_msg_token1 => ' new project account');
3042 end if;
3043
3044 IF p_partial_flag <> 'Y' then
3045 g_p_acct_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3046
3047 Else
3048 l_new_proj_acct := 'N';
3049 IF g_debug_mode = 'Y' THEN
3050 log_message(p_msg_token1 =>' proj acct level count ='||l_proj_acct_level_count);
3051 end if;
3052 IF l_proj_acct_level_count > 0 then
3053 IF g_debug_mode = 'Y' THEN
3054 log_message(p_msg_token1 => 'l_proj_acct_level_count > 0');
3055 end if;
3056 FOR I IN 1 .. l_proj_acct_level_count LOOP
3057 IF g_debug_mode = 'Y' THEN
3058 log_message(p_msg_token1 => 'Iside for loop');
3059 end if;
3060 If g_tab_proj_acct_level_cache(I) = l_proj_acct_level_cache then
3061 IF g_debug_mode = 'Y' THEN
3062 log_message(p_msg_token1 =>'same cahce found');
3063 end if;
3064 g_tab_prj_acct_level_cache_amt(I) :=
3065 NVL(g_tab_prj_acct_level_cache_amt(I),0)+
3066 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3067 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(I);
3068 l_new_proj_acct := 'N';
3069 EXIT;
3070 END IF;
3071 l_new_proj_acct := 'Y';
3072 END LOOP;
3073 END IF;
3074 IF g_debug_mode = 'Y' THEN
3075 log_message(p_msg_token1 =>' l_new_proj acct = '||l_new_proj_acct);
3076 end if;
3077 IF l_new_proj_acct = 'Y' or l_proj_acct_level_count <= 0 then
3078 IF g_debug_mode = 'Y' THEN
3079 log_message(p_msg_token1 => 'adding to cache');
3080 end if;
3081 g_tab_proj_acct_level_cache(l_proj_acct_level_count+1) := l_proj_acct_level_cache;
3082 g_tab_prj_acct_level_cache_amt(l_proj_acct_level_count+1) :=
3083 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3084 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(l_proj_acct_level_count+1);
3085 END IF;
3086
3087 END IF;
3088 END IF;
3089 IF g_debug_mode = 'Y' THEN
3090 log_message(p_msg_token1 => 'project acct bal ='||g_p_acct_pkt_amt);
3091 end if;
3092
3093 REturn;
3094
3095 EXCEPTION
3096 WHEN OTHERS THEN
3097 IF g_debug_mode = 'Y' THEN
3098 log_message_imp(p_msg_token1 => 'failed in cache amt pkts apiSQLERR'|| sqlerrm||sqlcode);
3099 end if;
3100 raise;
3101 END CACHE_PKT_AMOUNTS;
3102
3103 -----------------------------------------------------------------------------------------------------------
3104 --- This Api checks the funds available for the record in pa bc packets. The following logic is used.
3105 --- funds check will be carried out NOCOPY at five levels, RESOURCE, RESOURCE GROUP, TOP TASK, TASK AND
3106 --- PROJECT level. depending on upon the budget entry method AND budgetory controls used
3107 --- if the budgetory control setup is N - None then funds check will not be done
3108 --- if the budgetory control setup is B - Absolute , D - Advisory then funds check will be done
3109 --- funds check will be done based on roll up process.
3110 ---
3111 --- BUDGET LEVEL BUDGETORY CONTROL
3112 --- -------------- -------------------
3113 ---
3114 --- RESOURCE ABSOLUTE /ADVISORY/ NONE
3115 ---
3116 --- RESOURCE GROUP ABSOLUTE /ADVISORY/ NONE
3117 ---
3118 --- TASK ABSOLUTE /ADVISORY/ NONE
3119 ---
3120 --- TOP TASK ABSOLUTE /ADVISORY/ NONE
3121 ---
3122 --- PROJECT ABSOLUTE /ADVISORY/ NONE
3123 -------------------------------------------------------------------------------------------------------------
3124
3125 PROCEDURE check_funds_available (
3126 p_sob IN pa_bc_packets.set_of_books_id%type,
3127 p_mode IN VARCHAR2,
3128 p_packet_id IN NUMBER,
3129 p_record IN OUT NOCOPY pa_fc_record,
3130 p_arrival_seq IN NUMBER,
3131 p_status_code IN VARCHAR2,
3132 p_ext_bdgt_link IN VARCHAR2,
3133 p_ext_bdgt_type IN VARCHAR2,
3134 p_start_date IN DATE,
3135 p_end_date IN DATE,
3136 p_calling_module IN VARCHAR2,
3137 p_partial_flag IN VARCHAR2,
3138 p_counter IN number
3139 ) IS
3140
3141 p_start_date_1 DATE; -- 7531681
3142 p_end_date_1 DATE; -- 7531681
3143
3144
3145
3146 -----------------------------------------------------------------------------------------------------
3147 -- This CURSOR selects AND sums up all the balances for a particular resource FROM pa_bc_balances table
3148 -- between the start date AND end date RESOURCE CURSOR
3149 -----------------------------------------------------------------------------------------------------
3150 CURSOR res_level_bal (l_rlmi number) is
3151 /* SELECT nvl(sum(BUDGET_PERIOD_TO_DATE * decode(balance_type,'BGT',1,0)) ,0),
3152 nvl(sum(ACTUAL_PERIOD_TO_DATE * decode(balance_type,'EXP',1,0)) ,0),
3153 nvl(sum(ENCUMB_PERIOD_TO_DATE * decode(balance_type,'REQ',1,
3154 'PO',1,
3155 'AP',1,
3156 'ENC',1,
3157 'CC_C_PAY',1,
3158 'CC_C_CO',1,
3159 'CC_P_PAY',1,
3160 'CC_P_CO',1,
3161 0)),0) 7531681 */
3162 SELECT NVL(SUM(BUDGET_PERIOD_TO_DATE ),0),
3163 NVL(SUM(ACTUAL_PERIOD_TO_DATE ),0),
3164 NVL(SUM(ENCUMB_PERIOD_TO_DATE ),0)
3165 FROM pa_bc_balances pb
3166 WHERE pb.project_id = p_record.project_id
3167 /* Bug fix: 3450756 Start */
3168 ---AND pb.task_id = p_record.bud_task_id
3169 AND ( (pb.task_id = p_record.bud_task_id and pb.balance_type in ('BGT'))
3170 OR
3171 (pb.balance_type NOT IN ('BGT','REV')
3172 AND
3173 ((p_record.entry_level_code = 'L' and p_record.bud_task_id = pb.task_id)
3174 OR
3175 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3176 OR
3177 (p_record.entry_level_code = 'T'
3178 and p_record.bud_task_id = pb.top_task_id /* (select t.top_task_id
3179 From pa_tasks t
3180 Where t.task_id = pb.task_id) 7531681 */
3181 )
3182 OR
3183 (p_record.entry_level_code = 'M'
3184 and ( p_record.bud_task_id = pb.task_id
3185 OR
3186 p_record.bud_task_id = pb.top_task_id /* (select t.top_task_id
3187 From pa_tasks t
3188 Where t.task_id = pb.task_id) 7531681 */
3189 )
3190 )))
3191 )
3192 /* Bug fix: 3450756 End */
3193 AND ((pb.resource_list_member_id = l_rlmi AND pb.balance_type not in ('BGT','REV'))
3194 OR (pb.resource_list_member_id = l_rlmi AND pb.balance_type ='BGT')
3195 )
3196 AND pb.budget_version_id = p_record.budget_version_id
3197 AND pb.start_date between
3198 decode(p_record.time_phased_type_code,'N', pb.start_date, p_start_date_1 ) AND -- 7531681
3199 decode(p_record.time_phased_type_code,'N', pb.start_date, p_end_date_1) -- 7531681
3200 AND pb.end_date between
3201 decode(p_record.time_phased_type_code,'N', pb.end_date, p_start_date_1 ) AND -- 7531681
3202 decode(p_record.time_phased_type_code,'N', pb.end_date, p_end_date_1) -- 7531681
3203 ;
3204 -----------------------------------------------------------------------------------------------------
3205 -- This CURSOR selects AND sums all the entedr - entecr columns FROM pa_bc_packets table
3206 -- for one resource between the start date AND end date
3207 -----------------------------------------------------------------------------------------------------
3208 CURSOR res_tot_bc_pkt(l_rlmi number,l_parent_res_id number) IS
3209 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3210 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3211 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3212 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3213 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3214 FROM pa_bc_packets pbc
3215 -- pa_bc_packet_arrival_order ao --7531681
3216 WHERE pbc.project_id = p_record.project_id
3217 AND (
3218 (nvl(pbc.top_task_id,0) = p_record.bud_task_id)
3219 or (nvl(pbc.task_id,0) = p_record.bud_task_id)
3220 or p_record.entry_level_code = 'P'
3221 )
3222 AND pbc.resource_list_member_id = l_rlmi
3223 AND NVL(pbc.parent_resource_id,0) = nvl(l_parent_res_id,0) /* Added nvl for bug fix 2658952 */
3224 AND pbc.budget_version_id = p_record.budget_version_id
3225 AND pbc.set_of_books_id = p_sob
3226 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3227 between p_start_date_1 and p_end_date_1) OR -- 7531681
3228 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3229 between p_start_date_1 and p_end_date_1) OR -- 7531681
3230 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3231 between p_start_date_1 and p_end_date_1) -- 7531681
3232 )
3233 -- AND pbc.packet_id = ao.packet_id /* 7531681 */
3234 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3235 AND pbc.balance_posted_flag = 'N'
3236 AND exists
3237 ( select 1 from pa_bc_packet_arrival_order ao
3238 where ao.packet_id = pbc.packet_id
3239 AND (
3240 -- This condition is added to avoid the concurrency issues like when two packets arrive for funds check
3241 -- one is funds check completed but not updated the status to Aprroved as the final status is updated
3242 -- after getting the status from gl tie back.mean time antother packet which arrives has to consider
3243 -- the amount which already consumeed in previous packet.
3244 -- the status code takes care of the following
3245 -- A -- Approved but not yet posted to balances / not yet swept
3246 -- P -- Pending packet which is funds checked not yet approved / when two packets arrives in queue
3247 -- has to consider the amounts in previous packet
3248 -- C -- packets arrives during baseline process will be updated with intermedidate status after FC
3249 -- B -- the approved the transaction will be updated to B during CHECK_BASELINE mode these transaction
3250 -- must be considered during RESERVE_BASELINE mode
3251 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3252 ( ao.arrival_seq < p_arrival_seq
3253 --AND ao.affect_funds_flag = 'Y'
3254 AND ao.set_of_books_id = p_sob
3255 AND pbc.status_code in ( 'A','P')
3256 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3257 -- AND pbc.balance_posted_flag = 'N' -- 7531681
3258 )
3259 OR(pbc.packet_id = p_packet_id
3260 and pbc.status_code = 'Z'
3261 and pbc.effect_on_funds_code = 'I'
3262 and p_partial_flag <> 'Y'
3263 -- and pbc.balance_posted_flag = 'N' -- 7531681
3264 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3265 )
3266 ) );
3267
3268
3269 --------------------------------------------------------------------------------------
3270 -- This CURSOR select the sum of amount from pa bc balances for the given parent
3271 -- resource id between the start and end date - RESOURCE GROUP CURSOR
3272 --------------------------------------------------------------------------------------
3273 CURSOR res_grp_level_bal (l_parent_member_id number,l_bud_rlmi number) is
3274 /* SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3275 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3276 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3277 'PO',1,
3278 'AP',1,
3279 'ENC',1,
3280 'CC_C_PAY',1,
3281 'CC_C_CO',1,
3282 'CC_P_PAY',1,
3283 'CC_P_CO',1,
3284 0)),0) 7531681*/
3285
3286 SELECT NVL(SUM(BUDGET_PERIOD_TO_DATE ),0),
3287 NVL(SUM(ACTUAL_PERIOD_TO_DATE ),0),
3288 NVL(SUM(ENCUMB_PERIOD_TO_DATE ),0)
3289 FROM pa_bc_balances pb
3290 WHERE pb.project_id = p_record.project_id
3291 /* Bug fix: 3450756 Start */
3292 ---AND pb.task_id = p_record.bud_task_id
3293 AND ( (pb.task_id = p_record.bud_task_id and pb.balance_type in ('BGT'))
3294 OR
3295 (pb.balance_type NOT IN ('BGT','REV')
3296 AND
3297 ((p_record.entry_level_code = 'L' and p_record.bud_task_id = pb.task_id)
3298 OR
3299 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3300 OR
3301 (p_record.entry_level_code = 'T'
3302 and p_record.bud_task_id = pb.top_task_id /*(select t.top_task_id
3303 From pa_tasks t
3304 Where t.task_id = pb.task_id) 7531681 */
3305 )
3306 OR
3307 (p_record.entry_level_code = 'M'
3308 and (p_record.bud_task_id = pb.task_id
3309 OR
3310 p_record.bud_task_id = pb.top_task_id /* (select t.top_task_id
3311 From pa_tasks t
3312 Where t.task_id = pb.task_id) 7531681 */
3313 )
3314 )))
3315 )
3316 /* Bug fix: 3450756 End */
3317 AND (( NVL(pb.parent_member_id,0) = NVL(l_parent_member_id,0) /* Added NVL for bug fix 2658952 */
3318 and pb.balance_type not in ('BGT','REV')
3319 and pb.parent_member_id is NOT NULL)
3320 OR (pb.resource_list_member_id = l_bud_rlmi AND
3321 pb.balance_type not in ('BGT','REV') AND
3322 pb.parent_member_id is NULL )
3323 OR (pb.resource_list_member_id = l_bud_rlmi AND pb.balance_type ='BGT'
3324 AND pb.parent_member_id is null)
3325 )
3326 AND pb.budget_version_id = p_record.budget_version_id
3327 AND pb.start_date between
3328 decode(p_record.time_phased_type_code,'N', pb.start_date, p_start_date_1) AND -- 7531681
3329 decode(p_record.time_phased_type_code,'N', pb.start_date, p_end_date_1) -- 7531681
3330 AND pb.end_date between
3331 decode(p_record.time_phased_type_code,'N', pb.end_date, p_start_date_1) AND -- 7531681
3332 decode(p_record.time_phased_type_code,'N', pb.end_date, p_end_date_1); -- 7531681
3333
3334 -----------------------------------------------------------------------------------------
3335 -- this cursor selects the sum of amounts and rolls up the resource group level
3336 -- RESOURCE ROLLUP
3337 ----------------------------------------------------------------------------------------
3338 CURSOR res_rollup_bal (l_parent_member_id number) is
3339 /* SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3340 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3341 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3342 'PO',1,
3343 'AP',1,
3344 'ENC',1,
3345 'CC_C_PAY',1,
3346 'CC_C_CO',1,
3347 'CC_P_PAY',1,
3348 'CC_P_CO',1,
3349 0)),0) 7531681 */
3350 SELECT NVL(SUM(BUDGET_PERIOD_TO_DATE ),0),
3351 NVL(SUM(ACTUAL_PERIOD_TO_DATE ),0),
3352 NVL(SUM(ENCUMB_PERIOD_TO_DATE ),0)
3353 FROM pa_bc_balances pb
3354 WHERE pb.project_id = p_record.project_id
3355 /* Bug fix: 3450756 Start */
3356 ---AND pb.task_id = p_record.bud_task_id
3357 AND ( (pb.task_id = p_record.bud_task_id and pb.balance_type in ('BGT'))
3358 OR
3359 (pb.balance_type NOT IN ('BGT','REV')
3360 AND
3361 ((p_record.entry_level_code = 'L' and p_record.bud_task_id = pb.task_id)
3362 OR
3363 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3364 OR
3365 (p_record.entry_level_code = 'T'
3366 and p_record.bud_task_id = pb.top_task_id /* (select t.top_task_id
3367 From pa_tasks t
3368 Where t.task_id = pb.task_id) 7531681 */
3369 )
3370 OR
3371 (p_record.entry_level_code = 'M'
3372 and ( p_record.bud_task_id = pb.task_id
3373 OR
3374 p_record.bud_task_id = pb.top_task_id /* (select t.top_task_id
3375 From pa_tasks t
3376 Where t.task_id = pb.task_id) 7531681 */
3377 )
3378 )))
3379 )
3380 /* Bug fix: 3450756 End */
3381 AND ((NVL(pb.parent_member_id,0) = nvl(l_parent_member_id,0) /*Added NVL for bug fix 2658952 */
3382 and pb.balance_type not in ('BGT','REV')
3383 and pb.parent_member_id is NOT NULL )
3384 OR (NVL(pb.parent_member_id,0) = nvl(l_parent_member_id,0) /*Added NVL for bug fix 2658952 */
3385 AND pb.balance_type ='BGT'
3386 AND pb.parent_member_id is NOT NULL)
3387 )
3388 AND pb.budget_version_id = p_record.budget_version_id
3389 AND pb.start_date between
3390 decode(p_record.time_phased_type_code,'N', pb.start_date, p_start_date_1) AND -- 7531681
3391 decode(p_record.time_phased_type_code,'N', pb.start_date, p_end_date_1) -- 7531681
3392 AND pb.end_date between
3393 decode(p_record.time_phased_type_code,'N', pb.end_date, p_start_date_1) AND -- 7531681
3394 decode(p_record.time_phased_type_code,'N', pb.end_date, p_end_date_1); -- 7531681
3395
3396
3397 -----------------------------------------------------------------------------------------------------
3398 -- This CURSOR selects AND sums all the entedr - entecr columns FROM pa_bc_packets table
3399 -- for one resource group between the start date AND end date
3400 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3401 -----------------------------------------------------------------------------------------------------
3402 CURSOR res_grp_tot_bc_pkt(l_parent_res_id number,l_rlmi number) IS
3403 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3404 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3405 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3406 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3407 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3408 FROM pa_bc_packets pbc
3409 -- pa_bc_packet_arrival_order ao --7531681
3410 WHERE pbc.project_id = p_record.project_id
3411 AND (
3412 (nvl(pbc.top_task_id,0) = p_record.bud_task_id)
3413 or (nvl(pbc.task_id,0) = p_record.bud_task_id)
3414 or p_record.entry_level_code = 'P'
3415 )
3416 AND ( (NVL(pbc.parent_resource_id,0) = NVl(l_parent_res_id,0) /*Added NVL for bug fix 2658952 */
3417 and NVl(l_parent_res_id,0) <> 0 )
3418 OR ( pbc.resource_list_member_id = l_rlmi
3419 and NVl(l_parent_res_id,0) = 0)
3420 )
3421 AND pbc.budget_version_id = p_record.budget_version_id
3422 AND pbc.set_of_books_id = p_sob
3423 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3424 between p_start_date_1 and p_end_date_1) OR -- 7531681
3425 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3426 between p_start_date_1 and p_end_date_1) OR -- 7531681
3427 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3428 between p_start_date_1 and p_end_date_1) -- 7531681
3429 )
3430 -- AND pbc.packet_id = ao.packet_id -- 7531681
3431 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3432 AND pbc.balance_posted_flag = 'N'
3433 AND exists
3434 ( select 1 from pa_bc_packet_arrival_order ao /* 7531681 */
3435 where pbc.packet_id = ao.packet_id
3436 AND (
3437 ( ao.arrival_seq < p_arrival_seq
3438 --AND ao.affect_funds_flag = 'Y'
3439 AND ao.set_of_books_id = p_sob
3440 AND pbc.status_code in ( 'A','P')
3441 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3442 -- AND pbc.balance_posted_flag = 'N' -- 7531681
3443 )
3444 OR(pbc.packet_id = p_packet_id
3445 and pbc.status_code = 'Z'
3446 and pbc.effect_on_funds_code = 'I'
3447 and p_partial_flag <> 'Y'
3448 -- and pbc.balance_posted_flag = 'N' -- 7531681
3449 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3450 )
3451 ));
3452
3453 -----------------------------------------------------------------------------------------------------
3454 -- This CURSOR selects AND sums up all the balances for a particular task FROM pa_bc_balances table
3455 -- between the start date AND end date and this CURSOR is opened when funds checking rolls up to
3456 -- task level FROM resource level
3457 -----------------------------------------------------------------------------------------------------
3458 CURSOR task_level_bal (l_task_id number)is
3459 /* SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3460 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3461 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3462 'PO',1,
3463 'AP',1,
3464 'ENC',1,
3465 'CC_C_PAY',1,
3466 'CC_C_CO',1,
3467 'CC_P_PAY',1,
3468 'CC_P_CO',1,
3469 0)),0) 7531681 */
3470 SELECT NVL(SUM(BUDGET_PERIOD_TO_DATE ),0),
3471 NVL(SUM(ACTUAL_PERIOD_TO_DATE ),0),
3472 NVL(SUM(ENCUMB_PERIOD_TO_DATE ),0)
3473 FROM pa_bc_balances pb
3474 WHERE pb.project_id = p_record.project_id
3475 AND pb.budget_version_id = p_record.budget_version_id
3476 /* Bug fix: 3450756 Start */
3477 --- AND ( ( pb.task_id = l_task_id AND pb.balance_type='BGT')
3478 --- OR (pb.task_id = l_task_id AND pb.balance_type not in ('REV','BGT'))
3479 --- )
3480 AND ( (pb.task_id = l_task_id and pb.balance_type in ('BGT'))
3481 OR
3482 (pb.balance_type NOT IN ('BGT','REV')
3483 AND
3484 ((p_record.entry_level_code = 'L' and pb.task_id = l_task_id )
3485 OR
3486 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3487 OR
3488 (p_record.entry_level_code = 'T'
3489 and l_task_id = pb.top_task_id /* (select t.top_task_id
3490 From pa_tasks t
3491 Where t.task_id = pb.task_id) 7531681 */
3492 )
3493 OR
3494 (p_record.entry_level_code = 'M'
3495 and ( pb.task_id = l_task_id
3496 OR
3497 l_task_id = pb.top_task_id /* (select t.top_task_id
3498 From pa_tasks t
3499 Where t.task_id = pb.task_id) 7531681 */
3500 )
3501 )))
3502 )
3503 /* Bug fix: 3450756 End */
3504 AND pb.start_date between
3505 decode(p_record.time_phased_type_code,'N', pb.start_date, p_start_date_1) AND -- 7531681
3506 decode(p_record.time_phased_type_code,'N', pb.start_date, p_end_date_1) -- 7531681
3507 AND pb.end_date between
3508 decode(p_record.time_phased_type_code,'N', pb.end_date, p_start_date_1) AND -- 7531681
3509 decode(p_record.time_phased_type_code,'N', pb.end_date, p_end_date_1); -- 7531681
3510
3511 -----------------------------------------------------------------------------------------------------
3512 --This CURSOR selects AND sums all the entedr columns FROM pa_bc_packets table for all the resources
3513 --falling under one lowest task between the start date AND end date
3514 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3515 -----------------------------------------------------------------------------------------------------
3516 CURSOR task_tot_bc_pkt (l_task_id number,l_top_task_id number) is
3517 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3518 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3519 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3520 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3521 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3522 FROM pa_bc_packets pbc
3523 -- pa_bc_packet_arrival_order ao -- 7531681
3524 WHERE pbc.project_id = p_record.project_id
3525 AND pbc.top_task_id = l_top_task_id
3526 AND pbc.task_id = l_task_id
3527 AND pbc.budget_version_id = p_record.budget_version_id
3528 AND pbc.set_of_books_id = p_sob
3529 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3530 between p_start_date_1 and p_end_date_1) OR -- 7531681
3531 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3532 between p_start_date_1 and p_end_date_1) OR -- 7531681
3533 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3534 between p_start_date_1 and p_end_date_1) -- 7531681
3535 )
3536 -- AND pbc.packet_id = ao.packet_id -- 7531681
3537 and substr(nvl(pbc.result_code,'P'),1,1)= 'P' /* 7531681 */
3538 AND pbc.balance_posted_flag = 'N'
3539 and exists
3540 (select 1 from pa_bc_packet_arrival_order ao
3541 where ao.packet_id = pbc.packet_id
3542 AND (
3543 ( ao.arrival_seq < p_arrival_seq
3544 --AND ao.affect_funds_flag = 'Y'
3545 AND ao.set_of_books_id = p_sob
3546 AND pbc.status_code in ( 'A','P')
3547 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3548 -- AND pbc.balance_posted_flag = 'N' -- 7531681
3549 )
3550 OR(pbc.packet_id = p_packet_id
3551 and pbc.status_code = 'Z'
3552 and pbc.effect_on_funds_code = 'I'
3553 and p_partial_flag <> 'Y'
3554 -- and pbc.balance_posted_flag = 'N' -- 7531681
3555 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3556 )
3557 ) );
3558
3559
3560 -----------------------------------------------------------------------------------------------------
3561 -- This CURSOR selects AND sums up all the balances for a particular top task FROM pa_bc_balances table
3562 -- between the start date AND end date
3563 -----------------------------------------------------------------------------------------------------
3564 CURSOR top_task_level_bal (l_bud_task_id number,l_top_task_id number) is
3565 /*SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3566 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3567 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3568 'PO',1,
3569 'AP',1,
3570 'ENC',1,
3571 'CC_C_PAY',1,
3572 'CC_C_CO',1,
3573 'CC_P_PAY',1,
3574 'CC_P_CO',1,
3575 0)),0) 7531681 */
3576 SELECT NVL(SUM(BUDGET_PERIOD_TO_DATE ),0),
3577 NVL(SUM(ACTUAL_PERIOD_TO_DATE),0),
3578 NVL(SUM(ENCUMB_PERIOD_TO_DATE),0)
3579 FROM pa_bc_balances pb
3580 WHERE pb.project_id = p_record.project_id
3581 AND ((pb.task_id = l_bud_task_id AND pb.balance_type='BGT' AND pb.task_id = l_top_task_id)
3582 OR (pb.top_task_id = l_top_task_id AND pb.balance_type not in ('REV','BGT'))
3583 )
3584 AND pb.budget_version_id = p_record.budget_version_id
3585 AND pb.start_date between
3586 decode(p_record.time_phased_type_code,'N', pb.start_date, p_start_date_1) AND -- 7531681
3587 decode(p_record.time_phased_type_code,'N', pb.start_date, p_end_date_1) -- 7531681
3588 AND pb.end_date between
3589 decode(p_record.time_phased_type_code,'N', pb.end_date, p_start_date_1) AND -- 7531681
3590 decode(p_record.time_phased_type_code,'N', pb.end_date, p_end_date_1); -- 7531681
3591
3592
3593 -----------------------------------------------------------------------------------------------------
3594 -- This CURSOR selects AND sums up all the balances for a particular task FROM pa_bc_balances table
3595 -- between the start date AND end date and rollup TASKROLLUP CURSOR
3596 -----------------------------------------------------------------------------------------------------
3597 CURSOR task_rollup_bal (l_top_task_id number) is
3598 /* SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3599 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3600 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3601 'PO',1,
3602 'AP',1,
3603 'ENC',1,
3604 'CC_C_PAY',1,
3605 'CC_C_CO',1,
3606 'CC_P_PAY',1,
3607 'CC_P_CO',1,
3608 0)),0) 7531681 */
3609 SELECT NVL(SUM(BUDGET_PERIOD_TO_DATE ),0),
3610 NVL(SUM(ACTUAL_PERIOD_TO_DATE),0),
3611 NVL(SUM(ENCUMB_PERIOD_TO_DATE ),0)
3612 FROM pa_bc_balances pb
3613 WHERE pb.project_id = p_record.project_id
3614 AND ((pb.top_task_id = l_top_task_id and pb.balance_type not in ('REV','BGT'))
3615 OR (pb.top_task_id = l_top_task_id AND pb.balance_type='BGT'))
3616 AND pb.budget_version_id = p_record.budget_version_id
3617 AND pb.start_date between
3618 decode(p_record.time_phased_type_code,'N', pb.start_date, p_start_date_1)AND -- 7531681
3619 decode(p_record.time_phased_type_code,'N', pb.start_date, p_end_date_1) -- 7531681
3620 AND pb.end_date between
3621 decode(p_record.time_phased_type_code,'N', pb.end_date, p_start_date_1) AND -- 7531681
3622 decode(p_record.time_phased_type_code,'N', pb.end_date, p_end_date_1); -- 7531681
3623
3624 -----------------------------------------------------------------------------------------------------
3625 --This CURSOR selects AND sums all the entedr columns FROM pa_bc_packets table for all the resources
3626 --falling under one top task between the start date AND end date
3627 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3628 -----------------------------------------------------------------------------------------------------
3629 CURSOR top_task_tot_bc_pkt (l_top_task_id number) is
3630 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3631 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3632 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3633 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3634 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3635 FROM pa_bc_packets pbc
3636 -- pa_bc_packet_arrival_order ao -- 7531681
3637 WHERE pbc.project_id = p_record.project_id
3638 AND pbc.top_task_id = l_top_task_id
3639 AND pbc.budget_version_id = p_record.budget_version_id
3640 AND pbc.set_of_books_id = p_sob
3641 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3642 between p_start_date_1 and p_end_date_1) OR -- 7531681
3643 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3644 between p_start_date_1 and p_end_date_1) OR -- 7531681
3645 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3646 between p_start_date_1 and p_end_date_1) -- 7531681
3647 )
3648 -- AND pbc.packet_id = ao.packet_id
3649 and pbc.balance_posted_flag = 'N' /* 7531681 */
3650 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3651 AND exists
3652 ( select 1 from pa_bc_packet_arrival_order ao
3653 where ao.packet_id = pbc.packet_id
3654 AND (
3655 ( ao.arrival_seq < p_arrival_seq
3656 --AND ao.affect_funds_flag = 'Y'
3657 AND ao.set_of_books_id = p_sob
3658 AND pbc.status_code in ( 'A','P')
3659 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3660 -- AND pbc.balance_posted_flag = 'N' -- 7531681
3661 )
3662 OR(pbc.packet_id = p_packet_id
3663 and pbc.status_code = 'Z'
3664 and pbc.effect_on_funds_code = 'I'
3665 and p_partial_flag <> 'Y'
3666 -- and pbc.balance_posted_flag = 'N' -- 7531681
3667 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3668 )
3669 ) );
3670 -----------------------------------------------------------------------------------------------------
3671 --This CURSOR selects AND sums up all the balances for a particular project FROM pa_bc_balances table
3672 --between the start date AND end date and this CURSOR is opened when funds checking rolles up to
3673 --the project level FROM task level
3674 -----------------------------------------------------------------------------------------------------
3675 CURSOR project_level_bal is
3676 /* SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3677 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3678 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3679 'PO',1,
3680 'AP',1,
3681 'ENC',1,
3682 'CC_C_PAY',1,
3683 'CC_C_CO',1,
3684 'CC_P_PAY',1,
3685 'CC_P_CO',1,
3686 0)),0) 7531681 */
3687 SELECT NVL(SUM(BUDGET_PERIOD_TO_DATE),0),
3688 NVL(SUM(ACTUAL_PERIOD_TO_DATE ),0),
3689 NVL(SUM(ENCUMB_PERIOD_TO_DATE),0)
3690 FROM pa_bc_balances pb
3691 WHERE pb.project_id = p_record.project_id
3692 AND pb.budget_version_id = p_record.budget_version_id
3693 AND pb.start_date between
3694 decode(p_record.time_phased_type_code,'N', pb.start_date, p_start_date_1) AND -- 7531681
3695 decode(p_record.time_phased_type_code,'N', pb.start_date, p_end_date_1) -- 7531681
3696 AND pb.end_date between
3697 decode(p_record.time_phased_type_code,'N', pb.end_date, p_start_date_1) AND -- 7531681
3698 decode(p_record.time_phased_type_code,'N', pb.end_date, p_end_date_1); -- 7531681
3699 -----------------------------------------------------------------------------------------------------
3700 --This CURSOR selects AND sums all the entedr columns FROM pa_bc_packets table for all the resources
3701 --falling under one project between the start date AND end date
3702 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3703 -----------------------------------------------------------------------------------------------------
3704 CURSOR project_tot_bc_pkt is
3705 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3706 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3707 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3708 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3709 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3710 FROM pa_bc_packets pbc
3711 -- pa_bc_packet_arrival_order ao -- 7531681
3712 WHERE pbc.project_id = p_record.project_id
3713 AND pbc.budget_version_id = p_record.budget_version_id
3714 AND pbc.set_of_books_id = p_sob
3715 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3716 between p_start_date_1 and p_end_date_1) OR -- 7531681
3717 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3718 between p_start_date_1 and p_end_date_1) OR -- 7531681
3719 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3720 between p_start_date_1 and p_end_date_1) -- 7531681
3721 )
3722 -- AND pbc.packet_id = ao.packet_id -- 7531681
3723 and pbc.balance_posted_flag = 'N'
3724 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3725 AND exists
3726 ( select 1 from pa_bc_packet_arrival_order ao
3727 where pbc.packet_id = ao.packet_id
3728 AND (
3729 ( ao.arrival_seq < p_arrival_seq
3730 --AND ao.affect_funds_flag = 'Y'
3731 AND ao.set_of_books_id = p_sob
3732 AND pbc.status_code in ( 'A','P')
3733 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3734 -- AND pbc.balance_posted_flag = 'N' -- 7531681
3735 )
3736 OR(pbc.packet_id = p_packet_id
3737 and pbc.status_code = 'Z'
3738 and pbc.effect_on_funds_code = 'I'
3739 and p_partial_flag <> 'Y'
3740 -- and pbc.balance_posted_flag = 'N' -- 7531681
3741 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3742 )
3743 ) );
3744
3745 --------------------------------------------------------------------------------------------------
3746 -- This CURSOR select and sums all the entered dr and entered cr columns from pa_bc_packets table
3747 -- for the given budget code combination id falling under the start and end date
3748 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3749 -------------------------------------------------------------------------------------------------
3750 CURSOR project_acct_tot_bc_pkt(l_bdgt_ccid NUMBER) is
3751 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3752 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3753 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3754 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3755 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3756 FROM pa_bc_packets pbc
3757 -- pa_bc_packet_arrival_order ao -- 7531681
3758 WHERE pbc.project_id = p_record.project_id
3759 AND pbc.budget_version_id = p_record.budget_version_id
3760 AND pbc.set_of_books_id = p_sob
3761 ANd pbc.budget_ccid = l_bdgt_ccid
3762 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3763 between p_start_date_1 and p_end_date_1) OR -- 7531681
3764 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3765 between p_start_date_1 and p_end_date_1) OR -- 7531681
3766 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3767 between p_start_date_1 and p_end_date_1) -- 7531681
3768 )
3769 -- AND pbc.packet_id = ao.packet_id -- 7531681
3770 and pbc.balance_posted_flag = 'N'
3771 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3772 AND exists
3773 (select 1 from pa_bc_packet_arrival_order ao
3774 where pbc.packet_id = ao.packet_id
3775 AND (
3776 ( ao.arrival_seq < p_arrival_seq
3777 --AND ao.affect_funds_flag = 'Y'
3778 AND ao.set_of_books_id = p_sob
3779 AND pbc.status_code in ( 'A','P')
3780 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3781 -- AND pbc.balance_posted_flag = 'N' -- 7531681
3782 )
3783 OR(pbc.packet_id = p_packet_id
3784 and pbc.status_code = 'Z'
3785 and pbc.effect_on_funds_code = 'I'
3786 and p_partial_flag <> 'Y'
3787 -- and pbc.balance_posted_flag = 'N' -- 7531681
3788 -- and substr(nvl(pbc.result_code,'P'),1,1)= 'P' -- 7531681
3789 )
3790 ));
3791
3792
3793
3794 -----------------------------------------------------------------------------------------------------
3795 -- declare required local variables
3796 l_stage VARCHAR2(10);
3797 l_r_budget_posted pa_bc_packets.res_budget_posted%type;
3798 l_rg_budget_posted pa_bc_packets.res_budget_posted%type;
3799 l_t_budget_posted pa_bc_packets.res_budget_posted%type;
3800 l_tt_budget_posted pa_bc_packets.res_budget_posted%type;
3801 l_p_budget_posted pa_bc_packets.res_budget_posted%type;
3802 l_r_actual_posted pa_bc_packets.res_budget_posted%type;
3803 l_rg_actual_posted pa_bc_packets.res_budget_posted%type;
3804 l_t_actual_posted pa_bc_packets.res_budget_posted%type;
3805 l_tt_actual_posted pa_bc_packets.res_budget_posted%type;
3806 l_p_actual_posted pa_bc_packets.res_budget_posted%type;
3807 l_r_enc_posted pa_bc_packets.res_budget_posted%type;
3808 l_rg_enc_posted pa_bc_packets.res_budget_posted%type;
3809 l_t_enc_posted pa_bc_packets.res_budget_posted%type;
3810 l_tt_enc_posted pa_bc_packets.res_budget_posted%type;
3811 l_p_enc_posted pa_bc_packets.res_budget_posted%type;
3812 l_r_budget_bal pa_bc_packets.res_budget_posted%type;
3813 l_rg_budget_bal pa_bc_packets.res_budget_posted%type;
3814 l_t_budget_bal pa_bc_packets.res_budget_posted%type;
3815 l_tt_budget_bal pa_bc_packets.res_budget_posted%type;
3816 l_p_budget_bal pa_bc_packets.res_budget_posted%type;
3817 l_r_actual_approved pa_bc_packets.res_budget_posted%type;
3818 l_rg_actual_approved pa_bc_packets.res_budget_posted%type;
3819 l_t_actual_approved pa_bc_packets.res_budget_posted%type;
3820 l_tt_actual_approved pa_bc_packets.res_budget_posted%type;
3821 l_p_actual_approved pa_bc_packets.res_budget_posted%type;
3822 l_r_enc_approved pa_bc_packets.res_budget_posted%type;
3823 l_rg_enc_approved pa_bc_packets.res_budget_posted%type;
3824 l_t_enc_approved pa_bc_packets.res_budget_posted%type;
3825 l_tt_enc_approved pa_bc_packets.res_budget_posted%type;
3826 l_p_enc_approved pa_bc_packets.res_budget_posted%type;
3827 l_result_code pa_bc_packets.result_code%type;
3828 l_r_result_code pa_bc_packets.res_result_code%type;
3829 l_rg_result_code pa_bc_packets.res_grp_result_code%type;
3830 l_t_result_code pa_bc_packets.task_result_code%type;
3831 l_tt_result_code pa_bc_packets.top_task_result_code%type;
3832 l_p_result_code pa_bc_packets.project_result_code%type;
3833 l_p_acct_result_code pa_bc_packets.project_result_code%type;
3834 l_status_code pa_bc_packets.status_code%type;
3835 l_available_amt pa_bc_packets.accounted_dr%type;
3836 l_return_status VARCHAR2(200);
3837 l_r_enc_pending NUMBER;
3838 l_rg_enc_pending NUMBER;
3839 l_t_enc_pending NUMBER;
3840 l_tt_enc_pending NUMBER;
3841 l_p_enc_pending NUMBER;
3842 l_r_actual_pending NUMBER;
3843 l_rg_actual_pending NUMBER;
3844 l_t_actual_pending NUMBER;
3845 l_tt_actual_pending NUMBER;
3846 l_p_actual_pending NUMBER;
3847 l_pkt_amt NUMBER;
3848 l_acct_level_bal NUMBER;
3849 l_p_acct_pkt_amt NUMBER;
3850 l_p_acct_enc_approved NUMBER;
3851 l_p_acct_actual_approved NUMBER;
3852 l_cached_satus varchar2(100);
3853
3854
3855 BEGIN
3856 -- use one level cache for storing the balances
3857 p_start_date_1 := TRUNC(p_start_date); -- 7531681
3858 p_end_date_1 := TRUNC(p_end_date);
3859
3860 IF g_debug_mode = 'Y' THEN
3861 log_message(p_msg_token1 =>'Inside the procedure check_funds_available');
3862 log_message(p_msg_token1 =>'Before Calling CACHE_PKT_AMOUNTS');
3863 end if;
3864
3865 CACHE_PKT_AMOUNTS(
3866 p_project_id => p_record.project_id
3867 ,p_bdgt_version => p_record.budget_version_id
3868 ,p_top_task_id => p_record.top_task_id
3869 ,p_task_id => p_record.task_id
3870 ,p_bud_task_id => p_record.bud_task_id
3871 ,p_start_date => p_start_date
3872 ,p_end_date => p_end_date
3873 ,p_rlmi => p_record.resource_list_member_id
3874 ,p_bud_rlmi => p_record.bud_resource_list_member_id
3875 ,p_prlmi => p_record.parent_resource_id
3876 ,p_bdgt_ccid => p_record.budget_ccid
3877 ,p_accounted_dr => p_record.accounted_dr
3878 ,p_accounted_cr => p_record.accounted_cr
3879 ,p_calling_module => p_calling_module
3880 ,p_partial_flag => p_partial_flag
3881 ,p_function => 'ADD'
3882 ,p_bc_packet_id => p_record.bc_packet_id
3883 ,p_doc_type => p_record.document_type
3884 ,p_doc_header_id => p_record.document_header_id
3885 ,p_doc_distribution_id =>p_record.document_distribution_id
3886 ,x_result_code => l_result_code
3887 ,x_cached_status => l_cached_satus
3888 ,p_counter => p_counter
3889 );
3890
3891 IF g_debug_mode = 'Y' THEN
3892 log_message(p_msg_token1 =>'After Calling CACHE_PKT_AMOUNTS');
3893 end if;
3894
3895 IF substr(l_result_code ,1,1) = 'F' then
3896 IF g_debug_mode = 'Y' THEN
3897 log_message(p_msg_token1 =>'l_result_code from cache ='||l_result_code);
3898 end if;
3899 -- msg : Raw line is failed so donot funds check for burden
3900 l_r_result_code := l_result_code;
3901 l_rg_result_code :=l_result_code;
3902 l_t_result_code := l_result_code;
3903 l_tt_result_code :=l_result_code;
3904 l_p_result_code := l_result_code;
3905 l_p_acct_result_code := l_result_code;
3906 GOTO END_PROCESS;
3907
3908 End if;
3909
3910
3911 -- check whether the effect on funds is Increase then it doesnot require
3912 -- funds check so pass the transaction
3913 If p_record.effect_on_funds_code = 'I' then
3914 IF g_debug_mode = 'Y' THEN
3915 log_message(p_msg_token1 =>'Effect on funds code ='||p_record.effect_on_funds_code);
3916 end if;
3917 -- msg : P113 = Increase in funds doest not require FC
3918 l_r_result_code := 'P113';
3919 l_rg_result_code := 'P113';
3920 l_t_result_code := 'P113';
3921 l_tt_result_code := 'P113';
3922 l_p_result_code := 'P113';
3923 l_p_acct_result_code := 'P113';
3924 l_result_code := 'P113';
3925 GOTO END_PROCESS;
3926 End if;
3927
3928 -- check if teh budget version id or rlmi is null in pa bc packets then
3929 -- mark it as invalid parameters for the funds check process
3930 If p_record.budget_version_id is NULL or p_record.resource_list_member_id is NULL
3931 or p_record.expenditure_item_date is NULL or p_record.pa_date is null or
3932 p_record.gl_date is null then
3933 IF g_debug_mode = 'Y' THEN
3934 log_message(p_msg_token1 =>'invalid params in check avaiable ');
3935 end if;
3936 l_status_code := 'F';
3937 l_r_result_code := 'F118';
3938 l_rg_result_code := 'F118';
3939 l_t_result_code := 'F118';
3940 l_tt_result_code := 'F118';
3941 l_p_result_code := 'F118';
3942 l_p_acct_result_code := 'F118';
3943 l_result_code := 'F118';
3944 GOTO END_PROCESS;
3945 End if;
3946
3947 --check whether the burdened cost flag is Y or N if the burden_cost_flag = 'N'
3948 -- mark the transaction with failure status for Invalid budget entry methods
3949 -- funds check will be done only for burdened cost
3950 If nvl(p_record.burdened_cost_flag,'N') <> 'Y' then
3951 IF g_debug_mode = 'Y' THEN
3952 log_message(p_msg_token1 =>'burden cost flag ='||p_record.burdened_cost_flag);
3953 End if;
3954 l_status_code := 'F';
3955 l_r_result_code := 'F131';
3956 l_rg_result_code := 'F131';
3957 l_t_result_code := 'F131';
3958 l_tt_result_code := 'F131';
3959 l_p_result_code := 'F131';
3960 l_p_acct_result_code := 'F131';
3961 l_result_code := 'F131';
3962 GOTO END_PROCESS;
3963 End if;
3964
3965 /*****************************************************************************/
3966 -- START OF FUNDS CHECK AT RESOURCE LEVEL -------
3967 /****************************************************************************/
3968 IF g_debug_mode = 'Y' THEN
3969 log_message(p_msg_token1 => 'category code ['||p_record.categorization_code||
3970 ']start date ['||p_start_date||'] end date['|| p_end_date||
3971 ']rlmi ['||p_record.resource_list_member_id||']bud_rlmi['||p_record.bud_resource_list_member_id||
3972 ']prlmi ['||p_record.parent_resource_id||']bud task id['||p_record.bud_task_id||
3973 ']time phase code ['||p_record.time_phased_type_code||
3974 ']budget verson id ['||p_record.budget_version_id||
3975 ']project id ['||p_record.project_id||']top task id ['||p_record.top_task_id||
3976 ']arrival seq [ '||p_arrival_seq||']resource_group_type_id['||p_record.group_resource_type_id||']');
3977 End if;
3978
3979 -- check funds at resource level if the budget is categorized by resource
3980 -- otherwise go the task level and check funds
3981 IF nvl(p_record.categorization_code,'N') = 'R' then
3982 IF g_debug_mode = 'Y' THEN
3983 log_message(p_msg_token1 => 'Categorization code ='||p_record.categorization_code);
3984 End if;
3985 l_stage := 100;
3986
3987 IF (p_record.project_id <> g_bal_r_project_id OR g_bal_r_project_id is NULL ) OR
3988 (p_record.budget_version_id <> g_bal_r_bdgt_version_id or g_bal_r_bdgt_version_id is NULL ) OR
3989 (p_record.time_phased_type_code <> g_bal_r_time_phase_code or g_bal_r_time_phase_code is NULL ) OR
3990 (p_start_date_1 <> trunc(g_bal_r_start_date) or g_bal_r_start_date is NULL ) OR -- 7531681
3991 (p_end_date_1 <> trunc(g_bal_r_end_date ) or g_bal_r_end_date is NULL) OR -- 7531681
3992 (p_record.bud_task_id <> g_bal_r_bud_task_id OR g_bal_r_bud_task_id is NULL ) OR
3993 (p_record.resource_list_member_id <> g_bal_r_rlmi or g_bal_r_rlmi is NULL ) Then
3994
3995
3996 OPEN res_level_bal (p_record.resource_list_member_id);
3997 IF g_debug_mode = 'Y' THEN
3998 log_message(p_msg_token1 => 'opened the cursor res_level_bal');
3999 end if;
4000 FETCH res_level_bal INTO l_r_budget_posted,
4001 l_r_actual_posted,
4002 l_r_enc_posted;
4003 -- store the values in global variables
4004 g_r_budget_posted := l_r_budget_posted;
4005 g_r_actual_posted := l_r_actual_posted;
4006 g_r_enc_posted := l_r_enc_posted;
4007
4008 --- added for performance testing to use as onelevel cache
4009 g_bal_r_project_id := p_record.project_id;
4010 g_bal_r_bdgt_version_id := p_record.budget_version_id;
4011 g_bal_r_bud_task_id := p_record.bud_task_id;
4012 g_bal_r_rlmi := p_record.resource_list_member_id;
4013 g_bal_r_start_date := p_start_date_1; -- 7531681
4014 g_bal_r_end_date := p_end_date_1; -- 7531681
4015 g_bal_r_time_phase_code := p_record.time_phased_type_code;
4016
4017 CLOSE res_level_bal;
4018 ELSE
4019 IF g_debug_mode = 'Y' THEN
4020 log_message(p_msg_token1 => 'Same combination for res level bal cur ');
4021 end if;
4022 l_r_budget_posted := g_r_budget_posted;
4023 l_r_actual_posted := g_r_actual_posted;
4024 l_r_enc_posted := g_r_enc_posted;
4025
4026 END IF; -- end of onelevel cache
4027 IF g_debug_mode = 'Y' THEN
4028 log_message(p_msg_token1 => 'r_bud_posted ['||l_r_budget_posted||
4029 ']r_actual_posted ['||l_r_actual_posted||']r_enc posted ['||l_r_enc_posted|| ']' );
4030 End if;
4031
4032 -- open the cursor for packet amounts at resource level
4033 IF (p_record.project_id <> g_pkt_r_project_id OR g_pkt_r_project_id is NULL ) OR
4034 (p_record.budget_version_id <> g_pkt_r_bdgt_version_id or g_pkt_r_bdgt_version_id is NULL ) OR
4035 --(p_record.time_phased_type_code <> g_pkt_r_time_phase_code or g_pkt_r_time_phase_code is NULL ) OR
4036 (p_record.entry_level_code <> g_pkt_r_entry_level_code or g_pkt_r_entry_level_code is NULL ) OR
4037 (p_start_date_1 <> trunc(g_pkt_r_start_date) or g_pkt_r_start_date is NULL ) OR -- 7531681
4038 (p_end_date_1 <> trunc(g_pkt_r_end_date ) or g_pkt_r_end_date is NULL) OR -- 7531681
4039 (p_record.bud_task_id <> g_pkt_r_bud_task_id OR g_pkt_r_bud_task_id is NULL ) OR
4040 (p_record.Parent_resource_id <> g_pkt_r_prlmi or g_pkt_r_prlmi is NULL ) OR
4041 (p_record.resource_list_member_id <> g_pkt_r_rlmi or g_pkt_r_rlmi is NULL ) Then
4042
4043 OPEN res_tot_bc_pkt(p_record.resource_list_member_id,p_record.Parent_resource_id);
4044 IF g_debug_mode = 'Y' THEN
4045 log_message(p_msg_token1 =>'opened the cursor res_tot_bc_pkt');
4046 End if;
4047 FETCH res_tot_bc_pkt INTO l_pkt_amt
4048 ,l_r_enc_approved
4049 ,l_r_actual_approved ;
4050 -- assign the values to global variables to use as onelevel cache
4051 g_r_base_amt := l_pkt_amt;
4052 g_r_enc_approved := l_r_enc_approved;
4053 g_r_enc_pending := l_r_enc_pending;
4054 g_r_actual_approved := l_r_actual_approved;
4055 g_r_actual_pending := l_r_actual_pending;
4056 IF g_debug_mode = 'Y' THEN
4057 log_message(p_msg_token1 =>'fetch cursor res_tot_bc_pkt');
4058 End if;
4059 CLOSE res_tot_bc_pkt;
4060
4061 --added for performance test to use as one level cache
4062 g_pkt_r_project_id := p_record.project_id;
4063 g_pkt_r_bdgt_version_id := p_record.budget_version_id;
4064 g_pkt_r_bud_task_id := p_record.bud_task_id;
4065 g_pkt_r_rlmi := p_record.resource_list_member_id;
4066 g_pkt_r_prlmi := p_record.Parent_resource_id;
4067 g_pkt_r_entry_level_code := p_record.entry_level_code;
4068 g_pkt_r_start_date := p_start_date_1; -- 7531681
4069 g_pkt_r_end_date := p_end_date_1; -- 7531681
4070 g_pkt_r_time_phase_code := p_record.time_phased_type_code;
4071 ---------------------end of performance test --------------
4072
4073 ELSE
4074
4075 l_pkt_amt := g_r_base_amt;
4076 l_r_enc_approved := g_r_enc_approved;
4077 l_r_enc_pending := g_r_enc_pending;
4078 l_r_actual_approved := g_r_actual_approved;
4079 l_r_actual_pending := g_r_actual_pending;
4080 END IF; -- end of onelevel cache
4081 IF g_debug_mode = 'Y' THEN
4082 log_message(p_msg_token1 => 'l_pkt_amount ['||l_pkt_amt||
4083 ']l_r_enc_approved ['||l_r_enc_approved||']l_r_enc_pending ['||l_r_enc_pending||
4084 ']l_r_actual_approved ['||l_r_actual_approved||']l_r_actual_pending ['||l_r_actual_pending||']');
4085 End if;
4086
4087 l_available_amt := nvl(l_r_budget_posted,0) -
4088 (nvl(l_r_actual_posted,0) +
4089 nvl(l_r_enc_posted,0) +
4090 nvl(l_pkt_amt,0) +
4091 nvl(l_r_actual_approved,0) +
4092 nvl(l_r_enc_approved,0) +
4093 NVL(g_r_pkt_amt,0)
4094 );
4095 IF g_debug_mode = 'Y' THEN
4096 log_message(p_msg_token1 =>'avaialbe amt ='||l_available_amt);
4097 End if;
4098 IF p_record.status_code||p_record.actual_flag = 'AE' then
4099 l_r_enc_approved := nvl(l_r_enc_approved,0) +
4100 p_record.accounted_dr
4101 - p_record.accounted_cr;
4102 IF g_debug_mode = 'Y' THEN
4103 log_message(p_msg_token1 =>'r_enc_approv ='||l_r_enc_approved);
4104 End if;
4105 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4106 l_r_enc_pending := nvl(l_r_enc_pending,0) +
4107 p_record.accounted_dr
4108 - p_record.accounted_cr;
4109 IF g_debug_mode = 'Y' THEN
4110 log_message(p_msg_token1 =>'r enc pend ='||l_r_enc_pending);
4111 end if;
4112
4113 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4114 l_r_actual_approved := nvl(l_r_actual_approved,0) +
4115 p_record.accounted_dr
4116 - p_record.accounted_cr;
4117 IF g_debug_mode = 'Y' THEN
4118 log_message(p_msg_token1 =>'r actual approv ='||l_r_actual_approved);
4119 end if;
4120
4121 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4122 l_r_actual_pending := nvl(l_r_actual_pending,0) +
4123 p_record.accounted_dr
4124 - p_record.accounted_cr;
4125 IF g_debug_mode = 'Y' THEN
4126 log_message(p_msg_token1 =>'r_actual pending ='||l_r_actual_pending);
4127 end if;
4128
4129 END IF;
4130 l_r_budget_bal := l_available_amt;
4131 IF g_debug_mode = 'Y' THEN
4132 log_message(p_msg_token1 =>'calling generate result code api ');
4133 end if;
4134 generate_result_code(
4135 p_fclevel_code => p_record.r_funds_control_level_code,
4136 p_available_amt => l_available_amt,
4137 p_stage => l_stage,
4138 p_budget_posted_amt => l_r_budget_posted,
4139 x_result_code => l_result_code,
4140 x_r_result_code => l_r_result_code,
4141 x_rg_result_code => l_rg_result_code,
4142 x_t_result_code => l_t_result_code,
4143 x_tt_result_code => l_tt_result_code,
4144 x_p_result_code => l_p_result_code,
4145 x_p_acct_result_code => l_p_acct_result_code,
4146 x_return_status => l_return_status
4147 ) ;
4148 IF g_debug_mode = 'Y' THEN
4149 log_message(p_msg_token1 =>'end of generate result code api '
4150 ||'l_r_result_code ['||l_r_result_code||']l_result_code['||l_result_code||']' );
4151 End if;
4152
4153 IF l_return_status = 'F' THEN
4154 g_adv_result_code := NULL; -- Added for bug 9156359
4155 GOTO END_PROCESS;
4156 ELSIF l_return_status = 'A' THEN
4157 g_adv_result_code := 'A'; -- Added for bug 9156359
4158 ELSE
4159 -- PROCEED TO NEXT STAGE ie RESOURCE GROUP LEVEL
4160 NULL;
4161 END IF;
4162
4163
4164 --********************************************************************
4165 -- RESOURCE GROUP LEVEL ------
4166 --*******************************************************************
4167 l_stage := 200;
4168 IF g_debug_mode = 'Y' THEN
4169 log_message(p_msg_token1 => 'Stage 200');
4170 end if;
4171
4172 /* Bug fix 2658952 : If the Budget is by resource only with no resource group then
4173 * donot check the balances at the resource group level
4174 * group_resoruce_type_id = 0 indicates resource group by is NONE in resource list */
4175
4176 IF NVL(p_record.group_resource_type_id,0) <> 0 Then
4177
4178 -- open the cursor for packet amounts at resource group level
4179 IF (p_record.project_id <> g_bal_rg_project_id OR g_bal_rg_project_id is NULL ) OR
4180 (p_record.budget_version_id <> g_bal_rg_bdgt_version_id or g_bal_rg_bdgt_version_id is NULL ) OR
4181 (p_record.time_phased_type_code <> g_bal_rg_time_phase_code or g_bal_rg_time_phase_code is NULL ) OR
4182 --(p_record.entry_level_code <> g_bal_rg_entry_level_code or g_bal_rg_entry_level_code is NULL ) OR
4183 (p_start_date_1 <> trunc(g_bal_rg_start_date) or g_bal_rg_start_date is NULL ) OR -- 7531681
4184 (p_end_date_1 <> trunc(g_bal_rg_end_date ) or g_bal_rg_end_date is NULL) OR -- 7531681
4185 (p_record.bud_task_id <> g_bal_rg_bud_task_id OR g_bal_rg_bud_task_id is NULL ) OR
4186 (p_record.Parent_resource_id <> g_bal_rg_prlmi or g_bal_rg_prlmi is NULL ) OR
4187 (p_record.bud_resource_list_member_id <> g_bal_rg_bud_rlmi or g_bal_rg_bud_rlmi is NULL ) Then
4188
4189 OPEN res_grp_level_bal (p_record.parent_resource_id,p_record.bud_resource_list_member_id);
4190 IF g_debug_mode = 'Y' THEN
4191 log_message(p_msg_token1 =>'opened res_grp_level_bal cursor ');
4192 End if;
4193 FETCH res_grp_level_bal INTO l_rg_budget_posted,
4194 l_rg_actual_posted,
4195 l_rg_enc_posted;
4196 CLOSE res_grp_level_bal;
4197 -- check whether the resource level budget balance is zero and control level
4198 -- is Absolute then check the budget by rolling up the balances from resource
4199 IF l_rg_budget_posted = 0 then
4200 OPEN res_rollup_bal (p_record.parent_resource_id);
4201 IF g_debug_mode = 'Y' THEN
4202 log_message(p_msg_token1 =>'rg budget posted is zero so open rollup cursor ');
4203 end if;
4204 FETCH res_rollup_bal INTO l_rg_budget_posted,
4205 l_rg_actual_posted,
4206 l_rg_enc_posted;
4207 CLOSE res_rollup_bal;
4208 END IF;
4209 g_rg_budget_posted := l_rg_budget_posted;
4210 g_rg_actual_posted := l_rg_actual_posted;
4211 g_rg_enc_posted := l_rg_enc_posted;
4212
4213 --- added for performance testing
4214 g_bal_rg_project_id := p_record.project_id;
4215 g_bal_rg_bdgt_version_id := p_record.budget_version_id;
4216 g_bal_rg_bud_task_id := p_record.bud_task_id;
4217 g_bal_rg_bud_rlmi := p_record.bud_resource_list_member_id;
4218 g_bal_rg_prlmi := p_record.parent_resource_id;
4219 g_bal_rg_entry_level_code := p_record.entry_level_code;
4220 g_bal_rg_start_date := p_start_date_1; -- 7531681
4221 g_bal_rg_end_date := p_end_date_1; -- 7531681
4222 g_bal_rg_time_phase_code := p_record.time_phased_type_code;
4223 ------------------ end of perfromance test ----
4224
4225 ELSE
4226 IF g_debug_mode = 'Y' THEN
4227 log_message(p_msg_token1 => 'same comination for res_grp bal cur');
4228 end if;
4229 l_rg_budget_posted := g_rg_budget_posted;
4230 l_rg_actual_posted := g_rg_actual_posted;
4231 l_rg_enc_posted := g_rg_enc_posted;
4232 END IF; -- end for one level cache
4233 IF g_debug_mode = 'Y' THEN
4234 log_message(p_msg_token1 =>'rg budget posted ['||l_rg_budget_posted||
4235 ']rg actual_posted [ '||l_rg_actual_posted||']rg enc_posted ['||l_rg_enc_posted ||']');
4236 end if;
4237
4238 -- open the cursor for packet amounts at resource group level
4239 IF (p_record.project_id <> g_pkt_rg_project_id OR g_pkt_rg_project_id is NULL ) OR
4240 (p_record.budget_version_id <> g_pkt_rg_bdgt_version_id or g_pkt_rg_bdgt_version_id is NULL ) OR
4241 --(p_record.time_phased_type_code <> g_pkt_rg_time_phase_code or g_pkt_rg_time_phase_code is NULL ) OR
4242 (p_record.entry_level_code <> g_pkt_rg_entry_level_code or g_pkt_rg_entry_level_code is NULL ) OR
4243 (p_start_date_1 <> trunc(g_pkt_rg_start_date) or g_pkt_rg_start_date is NULL ) OR -- 7531681
4244 (p_end_date_1 <> trunc(g_pkt_rg_end_date ) or g_pkt_rg_end_date is NULL) OR -- 7531681
4245 (p_record.bud_task_id <> g_pkt_rg_bud_task_id OR g_pkt_rg_bud_task_id is NULL ) OR
4246 (p_record.Parent_resource_id <> g_pkt_rg_prlmi or g_pkt_rg_prlmi is NULL) OR
4247 /* added for bug fix: 2658952 */
4248 (((p_record.Parent_resource_id = 0 and g_pkt_rg_rlmi <> p_record.resource_list_member_id)
4249 or (g_pkt_rg_rlmi is NULL and p_record.Parent_resource_id = 0 )) /* endof bug fix 2658952 */
4250 ) Then
4251
4252 OPEN res_grp_tot_bc_pkt(p_record.Parent_resource_id,p_record.resource_list_member_id);
4253 IF g_debug_mode = 'Y' THEN
4254 log_message(p_msg_token1 => 'opened the res_grp_tot_bc_pkt cursor ');
4255 end if;
4256 FETCH res_grp_tot_bc_pkt INTO l_pkt_amt
4257 ,l_rg_enc_approved
4258 ,l_rg_actual_approved ;
4259
4260 --store the values in global to use as one level cache
4261 g_rg_base_amt := l_pkt_amt;
4262 g_rg_enc_approved := l_rg_enc_approved;
4263 g_rg_enc_pending := l_rg_enc_pending;
4264 g_rg_actual_approved := l_rg_actual_approved;
4265 g_rg_actual_pending := l_rg_actual_pending;
4266 CLOSE res_grp_tot_bc_pkt;
4267
4268 --added for performance test to use as one level cache
4269 g_pkt_rg_project_id := p_record.project_id;
4270 g_pkt_rg_bdgt_version_id := p_record.budget_version_id;
4271 g_pkt_rg_bud_task_id := p_record.bud_task_id;
4272 g_pkt_rg_rlmi := p_record.resource_list_member_id;
4273 --g_pkt_rg_bud_rlmi := null;
4274 g_pkt_rg_prlmi := p_record.Parent_resource_id;
4275 g_pkt_rg_entry_level_code := p_record.entry_level_code;
4276 g_pkt_rg_start_date := p_start_date_1; -- 7531681
4277 g_pkt_rg_end_date := p_end_date_1; -- 7531681
4278 g_pkt_rg_time_phase_code := p_record.time_phased_type_code;
4279 ------------end of performance test --------------
4280
4281 ELSE
4282 IF g_debug_mode = 'Y' THEN
4283 log_message(p_msg_token1 => 'Same combination found at resgrppkt cursor');
4284 end if;
4285 l_pkt_amt := g_rg_base_amt ;
4286 l_rg_enc_approved := g_rg_enc_approved;
4287 l_rg_enc_pending := g_rg_enc_pending;
4288 l_rg_actual_approved := g_rg_actual_approved;
4289 l_rg_actual_pending := g_rg_actual_pending;
4290
4291 END IF ; -- end of one level cache
4292 IF g_debug_mode = 'Y' THEN
4293 log_message(p_msg_token1 => 'rg_l_pkt_amt ['||l_pkt_amt||
4294 ']rg_enc_approved ['||l_rg_enc_approved||']rg_rg_enc_pending ['||l_rg_enc_pending||
4295 ']rg_actual_approved [ '||l_rg_actual_approved||']rg_actual_pending ['||l_rg_actual_pending||']');
4296 End if;
4297
4298 l_available_amt := nvl(l_rg_budget_posted,0) -
4299 (nvl(l_rg_actual_posted,0) +
4300 nvl(l_rg_enc_posted,0) +
4301 nvl(l_pkt_amt,0) +
4302 nvl(l_rg_actual_approved,0) +
4303 nvl(l_rg_enc_approved,0) +
4304 nvl(g_rg_pkt_amt ,0)
4305 );
4306 IF g_debug_mode = 'Y' THEN
4307 log_message(p_msg_token1 => 'available_amt = '|| l_available_amt);
4308 End if;
4309 IF p_record.status_code||p_record.actual_flag = 'AE' then
4310 l_rg_enc_approved := nvl(l_rg_enc_approved,0) +
4311 p_record.accounted_dr
4312 - p_record.accounted_cr;
4313 IF g_debug_mode = 'Y' THEN
4314 log_message(p_msg_token1 =>'rg_enc_approved ='||l_rg_enc_approved);
4315 end if;
4316 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4317 l_rg_enc_pending := nvl(l_rg_enc_pending,0) +
4318 p_record.accounted_dr
4319 - p_record.accounted_cr;
4320 IF g_debug_mode = 'Y' THEN
4321 log_message(p_msg_token1 => 'rg_rg_enc_pending ='||l_rg_enc_pending);
4322 end if;
4323
4324 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4325 l_rg_actual_approved := nvl(l_rg_actual_approved,0) +
4326 p_record.accounted_dr
4327 - p_record.accounted_cr;
4328 IF g_debug_mode = 'Y' THEN
4329 log_message(p_msg_token1 => 'rg_actual_approved = '||l_rg_actual_approved);
4330 end if;
4331
4332 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4333 l_rg_actual_pending := nvl(l_rg_actual_pending,0) +
4334 p_record.accounted_dr
4335 - p_record.accounted_cr;
4336 IF g_debug_mode = 'Y' THEN
4337 log_message(p_msg_token1 => 'rg_actual_pending ='||l_rg_actual_pending);
4338 end if;
4339
4340 END IF;
4341 l_rg_budget_bal := l_available_amt;
4342 IF g_debug_mode = 'Y' THEN
4343 log_message(p_msg_token1 => 'calling generate_result_code at res rgp ');
4344 end if;
4345 generate_result_code(
4346 p_fclevel_code => p_record.rg_funds_control_level_code,
4347 p_available_amt => l_available_amt,
4348 p_stage => l_stage,
4349 p_budget_posted_amt => l_rg_budget_posted,
4350 x_result_code => l_result_code,
4351 x_r_result_code => l_r_result_code,
4352 x_rg_result_code => l_rg_result_code,
4353 x_t_result_code => l_t_result_code,
4354 x_tt_result_code => l_tt_result_code,
4355 x_p_result_code => l_p_result_code,
4356 x_p_acct_result_code => l_p_acct_result_code,
4357 x_return_status => l_return_status
4358 ) ;
4359 IF g_debug_mode = 'Y' THEN
4360 log_message(p_msg_token1 => 'end of generate_result_code api'||
4361 'l_rg_result_code [ '||l_rg_result_code||'l_result_code ['||l_result_code||']' );
4362 end if;
4363
4364 IF l_return_status = 'F' THEN
4365 g_adv_result_code := NULL; -- Added for bug 9156359
4366 GOTO END_PROCESS;
4367 ELSIF l_return_status = 'A' THEN
4368 g_adv_result_code := 'A'; -- Added for bug 9156359
4369 ELSE
4370 -- PROCEED TO NEXT STAGE ie TASK LEVEL
4371 NULL;
4372 END IF;
4373
4374 ELSE
4375 -- Pass the transaction at resource group level if the resoource is not grouped
4376 -- by resource group
4377 l_rg_result_code := 'P109';
4378
4379 END IF ; -- end of group_resource_type_id /* bug fix 2658952 */
4380
4381 END IF; -- end if for budget categorization of resource
4382
4383 --******************************************************************************
4384 -- TASK LEVEL BALANCE ------
4385 --******************************************************************************
4386
4387 -- check whether the budget is by task if so then check the funds available at task level
4388 IF p_record.bud_task_id <> 0 then
4389 IF g_debug_mode = 'Y' THEN
4390 log_message(p_msg_token1 =>'Stage = 300');
4391 End if;
4392 l_stage := 300;
4393 -- open the cursor for packet amounts at task level
4394 IF (p_record.project_id <> g_bal_t_project_id OR g_bal_t_project_id is NULL ) OR
4395 (p_record.budget_version_id <> g_bal_t_bdgt_version_id or g_bal_t_bdgt_version_id is NULL ) OR
4396 (p_record.time_phased_type_code <> g_bal_t_time_phase_code or g_bal_t_time_phase_code is NULL ) OR
4397 --(p_record.entry_level_code <> g_bal_t_entry_level_code or g_bal_t_entry_level_code is NULL ) OR
4398 (p_start_date_1 <> trunc(g_bal_t_start_date) or g_bal_t_start_date is NULL ) OR -- 7531681
4399 (p_end_date_1 <> trunc(g_bal_t_end_date ) or g_bal_t_end_date is NULL) OR -- 7531681
4400 (p_record.task_id <> g_bal_t_task_id OR g_bal_t_task_id is NULL ) THEN
4401
4402
4403 OPEN task_level_bal (p_record.bud_task_id);
4404 IF g_debug_mode = 'Y' THEN
4405 log_message(p_msg_token1 =>'opened the cursor task_level_bal');
4406 end if;
4407 FETCH task_level_bal INTO l_t_budget_posted,
4408 l_t_actual_posted,
4409 l_t_enc_posted;
4410
4411 -- assign the fetched values to globals and use it as cache
4412 g_t_budget_posted := l_t_budget_posted;
4413 g_t_actual_posted := l_t_actual_posted;
4414 g_t_enc_posted := l_t_enc_posted;
4415
4416 CLOSE task_level_bal;
4417
4418 --- added for performance testing
4419 g_bal_t_project_id := p_record.project_id;
4420 g_bal_t_task_id := p_record.task_id;
4421 g_bal_t_bdgt_version_id := p_record.budget_version_id;
4422 g_bal_t_bud_task_id := p_record.bud_task_id;
4423 g_bal_t_bud_rlmi := p_record.bud_resource_list_member_id;
4424 g_bal_t_prlmi := p_record.parent_resource_id;
4425 g_bal_t_entry_level_code := p_record.entry_level_code;
4426 g_bal_t_start_date := p_start_date_1; -- 7531681
4427 g_bal_t_end_date := p_end_date_1; -- 7531681
4428 g_bal_t_time_phase_code := p_record.time_phased_type_code;
4429 -------------------- end of perfromance test ----
4430 ELSE
4431 IF g_debug_mode = 'Y' THEN
4432 log_message(p_msg_token1 => 'same combination found for task level bal');
4433 end if;
4434 l_t_budget_posted := g_t_budget_posted;
4435 l_t_actual_posted := g_t_actual_posted;
4436 l_t_enc_posted := g_t_enc_posted;
4437 END IF;
4438 IF g_debug_mode = 'Y' THEN
4439 log_message(p_msg_token1 =>'t_budget_posted ['||l_t_budget_posted||
4440 ']t_actual_posted ['||l_t_actual_posted||']tenc_posted ['||l_t_enc_posted||']');
4441 end if;
4442
4443 IF (p_record.project_id <> g_pkt_t_project_id OR g_pkt_t_project_id is NULL ) OR
4444 (p_record.budget_version_id <> g_pkt_t_bdgt_version_id or g_pkt_t_bdgt_version_id is NULL ) OR
4445 --(p_record.time_phased_type_code <> g_pkt_t_time_phase_code or g_pkt_t_time_phase_code is NULL ) OR
4446 (p_record.entry_level_code <> g_pkt_t_entry_level_code or g_pkt_t_entry_level_code is NULL ) OR
4447 (p_start_date_1 <> trunc(g_pkt_t_start_date) or g_pkt_t_start_date is NULL ) OR -- 7531681
4448 (p_end_date_1 <> trunc(g_pkt_t_end_date ) or g_pkt_t_end_date is NULL) OR -- 7531681
4449 (p_record.top_task_id <> g_pkt_t_top_task_id OR g_pkt_t_top_task_id is NULL ) OR
4450 (p_record.task_id <> g_pkt_t_task_id OR g_pkt_t_task_id is NULL ) THEN
4451
4452 OPEN task_tot_bc_pkt (p_record.task_id ,p_record.top_task_id );
4453 IF g_debug_mode = 'Y' THEN
4454 log_message(p_msg_token1 =>'opened task_tot_bc_pkt cursor ');
4455 end if;
4456 FETCH task_tot_bc_pkt INTO l_pkt_amt
4457 ,l_t_enc_approved
4458 ,l_t_actual_approved ;
4459 g_t_base_amt := l_pkt_amt;
4460 g_t_enc_approved := l_t_enc_approved;
4461 g_t_enc_pending := l_t_enc_pending;
4462 g_t_actual_approved := l_t_actual_approved;
4463 g_t_actual_pending := l_t_actual_pending;
4464
4465 CLOSE task_tot_bc_pkt;
4466
4467
4468 -- added for performance test
4469 g_pkt_t_project_id := p_record.project_id;
4470 g_pkt_t_task_id := p_record.task_id;
4471 g_pkt_t_top_task_id := p_record.top_task_id;
4472 g_pkt_t_bdgt_version_id := p_record.budget_version_id;
4473 g_pkt_t_prlmi := p_record.Parent_resource_id;
4474 g_pkt_t_entry_level_code := p_record.entry_level_code;
4475 g_pkt_t_start_date := p_start_date_1; -- 7531681
4476 g_pkt_t_end_date := p_end_date_1; -- 7531681
4477 g_pkt_t_time_phase_code := p_record.time_phased_type_code;
4478 ----------end of performance test --------------
4479
4480 ELSE
4481 --assign the values to global variables to use one level cache
4482 l_pkt_amt := g_t_base_amt;
4483 l_t_enc_approved := g_t_enc_approved;
4484 l_t_enc_pending := g_t_enc_pending;
4485 l_t_actual_approved := g_t_actual_approved;
4486 l_t_actual_pending := g_t_actual_pending;
4487 END IF;
4488 IF g_debug_mode = 'Y' THEN
4489 log_message(p_msg_token1 =>'pkt_amt ['||l_pkt_amt||
4490 ']t_enc_approved ['||l_t_enc_approved||']t_enc_pending [ '||l_t_enc_pending||
4491 ']t_actual_approved ['||l_t_actual_approved||']t_actual_pending ['||l_t_actual_pending||']');
4492 End if;
4493
4494 l_available_amt := nvl(l_t_budget_posted,0) -
4495 (nvl(l_t_actual_posted,0) +
4496 nvl(l_t_enc_posted,0) +
4497 nvl(l_pkt_amt,0) +
4498 nvl(l_t_actual_approved,0) +
4499 nvl(l_t_enc_approved,0) +
4500 nvl(g_t_pkt_amt,0)
4501 );
4502 IF g_debug_mode = 'Y' THEN
4503 log_message(p_msg_token1 =>'available_amt ='||l_available_amt);
4504 end if;
4505 IF p_record.status_code||p_record.actual_flag = 'AE' then
4506 l_t_enc_approved := nvl(l_t_enc_approved,0) +
4507 p_record.accounted_dr
4508 - p_record.accounted_cr;
4509 IF g_debug_mode = 'Y' THEN
4510 log_message(p_msg_token1 =>'t_enc_approved ='||l_t_enc_approved);
4511 end if;
4512 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4513 l_t_enc_pending := nvl(l_t_enc_pending,0) +
4514 p_record.accounted_dr
4515 - p_record.accounted_cr;
4516 IF g_debug_mode = 'Y' THEN
4517 log_message(p_msg_token1 =>'t_enc_pending = '||l_t_enc_pending);
4518 end if;
4519
4520 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4521 l_t_actual_approved := nvl(l_t_actual_approved,0) +
4522 p_record.accounted_dr
4523 - p_record.accounted_cr;
4524 IF g_debug_mode = 'Y' THEN
4525 log_message(p_msg_token1 =>'t_actual_approved ='||l_t_actual_approved);
4526 end if;
4527
4528 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4529 l_t_actual_pending := nvl(l_t_actual_pending,0) +
4530 p_record.accounted_dr
4531 - p_record.accounted_cr;
4532 IF g_debug_mode = 'Y' THEN
4533 log_message(p_msg_token1 =>'t_actual_pending ='||l_t_actual_pending);
4534 end if;
4535
4536 END IF;
4537 l_t_budget_bal := l_available_amt;
4538 IF g_debug_mode = 'Y' THEN
4539 log_message(p_msg_token1 =>'calling generate_result_code api ');
4540 end if;
4541 generate_result_code(
4542 p_fclevel_code => p_record.t_funds_control_level_code,
4543 p_available_amt => l_available_amt,
4544 p_stage => l_stage,
4545 p_budget_posted_amt => l_t_budget_posted,
4546 x_result_code => l_result_code,
4547 x_r_result_code => l_r_result_code,
4548 x_rg_result_code => l_rg_result_code,
4549 x_t_result_code => l_t_result_code,
4550 x_tt_result_code => l_tt_result_code,
4551 x_p_result_code => l_p_result_code,
4552 x_p_acct_result_code => l_p_acct_result_code,
4553 x_return_status => l_return_status
4554 ) ;
4555 IF g_debug_mode = 'Y' THEN
4556 log_message(p_msg_token1 =>'end of generate result code api '
4557 ||'l_t_result_code ['||l_t_result_code||']l_result_code['||l_result_code||']' );
4558 end if;
4559 IF l_return_status = 'F' THEN
4560 g_adv_result_code := NULL; -- Added for bug 9156359
4561 GOTO END_PROCESS;
4562 ELSIF l_return_status = 'A' THEN
4563 g_adv_result_code := 'A'; -- Added for bug 9156359
4564 ELSE
4565 -- PROCEED TO NEXT STAGE ie TOP TASK LEVEL
4566 NULL;
4567 END IF;
4568
4569 END IF;
4570 --*****************************************************************************
4571 --- TOP TASK LEVEL ------
4572 --******************************************************************************
4573 -- check whether the budget is by top task if so then check the funds available
4574 -- at top task level
4575 IF p_record.bud_task_id <> 0 then
4576
4577 l_stage := 400;
4578 -- open the cursor for packet amounts at top task level
4579 IF (p_record.project_id <> g_bal_tt_project_id OR g_bal_tt_project_id is NULL ) OR
4580 (p_record.budget_version_id <> g_bal_tt_bdgt_version_id or g_bal_tt_bdgt_version_id is NULL ) OR
4581 (p_record.time_phased_type_code <> g_bal_tt_time_phase_code or g_bal_tt_time_phase_code is NULL ) OR
4582 --(p_record.entry_level_code <> g_bal_tt_entry_level_code or g_bal_tt_entry_level_code is NULL ) OR
4583 (trunc(p_start_date) <> trunc(g_bal_tt_start_date) or g_bal_tt_start_date is NULL ) OR
4584 (trunc(p_end_date) <> trunc(g_bal_tt_end_date ) or g_bal_tt_end_date is NULL) OR
4585 (p_record.top_task_id <> g_bal_tt_top_task_id OR g_bal_tt_top_task_id is NULL ) OR
4586 (p_record.bud_task_id <> g_bal_tt_bud_task_id OR g_bal_tt_bud_task_id is NULL ) THEN
4587
4588 OPEN top_task_level_bal (p_record.bud_task_id ,p_record.top_task_id );
4589 IF g_debug_mode = 'Y' THEN
4590 log_message(p_msg_token1 =>'opened top_task_level_bal cursor ');
4591 end if;
4592 FETCH top_task_level_bal INTO l_tt_budget_posted,
4593 l_tt_actual_posted,
4594 l_tt_enc_posted;
4595 CLOSE top_task_level_bal;
4596
4597 If l_tt_budget_posted = 0 then
4598 IF g_debug_mode = 'Y' THEN
4599 log_message(p_msg_token1 =>'l_tt_budget_posted = 0 and opend roll up cursor');
4600 end if;
4601 -- rollup the task balance and check the funds avialable
4602 OPEN task_rollup_bal (p_record.top_task_id );
4603 FETCH task_rollup_bal INTO l_tt_budget_posted,
4604 l_tt_actual_posted,
4605 l_tt_enc_posted;
4606 CLOSE task_rollup_bal;
4607 End if;
4608 -- assign the values to globals to use as cache
4609 g_tt_budget_posted := l_tt_budget_posted;
4610 g_tt_actual_posted := l_tt_actual_posted;
4611 g_tt_enc_posted := l_tt_enc_posted;
4612
4613 --- added for performance testing to use as one level cache
4614 g_bal_tt_project_id := p_record.project_id;
4615 g_bal_tt_task_id := p_record.task_id;
4616 g_bal_tt_top_task_id := p_record.top_task_id;
4617 g_bal_tt_bdgt_version_id := p_record.budget_version_id;
4618 g_bal_tt_bud_task_id := p_record.bud_task_id;
4619 g_bal_tt_bud_rlmi := p_record.bud_resource_list_member_id;
4620 g_bal_tt_prlmi := p_record.parent_resource_id;
4621 g_bal_tt_entry_level_code := p_record.entry_level_code;
4622 g_bal_tt_start_date := trunc(p_start_date);
4623 g_bal_tt_end_date := trunc(p_end_date);
4624 g_bal_tt_time_phase_code := p_record.time_phased_type_code;
4625 -------------- end of perfromance test ----
4626
4627 ELSE
4628 IF g_debug_mode = 'Y' THEN
4629 log_message(p_msg_token1 => 'Same combination found at top task cursor');
4630 end if;
4631
4632 l_tt_budget_posted := g_tt_budget_posted;
4633 l_tt_actual_posted := g_tt_actual_posted;
4634 l_tt_enc_posted := g_tt_enc_posted;
4635 END IF;
4636 IF g_debug_mode = 'Y' THEN
4637 log_message(p_msg_token1 =>'tt_budget_posted ['||l_tt_budget_posted||
4638 ']tt_actual_posted ['||l_tt_actual_posted||']_tt_enc_posted ['||l_tt_enc_posted||']');
4639 end if;
4640
4641 IF (p_record.project_id <> g_pkt_tt_project_id OR g_pkt_tt_project_id is NULL ) OR
4642 (p_record.budget_version_id <> g_pkt_tt_bdgt_version_id or g_pkt_tt_bdgt_version_id is NULL ) OR
4643 --(p_record.time_phased_type_code <> g_pkt_tt_time_phase_code or g_pkt_tt_time_phase_code is NULL ) OR
4644 (p_record.entry_level_code <> g_pkt_tt_entry_level_code or g_pkt_tt_entry_level_code is NULL ) OR
4645 (trunc(p_start_date) <> trunc(g_pkt_tt_start_date) or g_pkt_tt_start_date is NULL ) OR
4646 (trunc(p_end_date) <> trunc(g_pkt_tt_end_date ) or g_pkt_tt_end_date is NULL) OR
4647 (p_record.top_task_id <> g_pkt_tt_top_task_id OR g_pkt_tt_top_task_id is NULL ) THEN
4648
4649
4650 OPEN top_task_tot_bc_pkt (p_record.top_task_id );
4651 IF g_debug_mode = 'Y' THEN
4652 log_message(p_msg_token1 =>'opend top_task_tot_bc_pkt cursor');
4653 end if;
4654 FETCH top_task_tot_bc_pkt INTO l_pkt_amt
4655 ,l_tt_enc_approved
4656 ,l_tt_actual_approved;
4657 g_tt_base_amt := l_pkt_amt;
4658 g_tt_enc_approved := l_tt_enc_approved;
4659 g_tt_enc_pending := l_tt_enc_pending;
4660 g_tt_actual_approved := l_tt_actual_approved;
4661 g_tt_actual_pending := l_tt_actual_pending;
4662 CLOSE top_task_tot_bc_pkt;
4663
4664 -- added for performance test
4665 g_pkt_tt_project_id := p_record.project_id;
4666 g_pkt_tt_task_id := p_record.task_id;
4667 g_pkt_tt_top_task_id := p_record.top_task_id;
4668 g_pkt_tt_bdgt_version_id := p_record.budget_version_id;
4669 --g_pkt_tt_bud_task_id := p_record.bud_task_id;
4670 --g_pkt_tt_rlmi := p_record.resource_list_member_id;
4671 --g_pkt_tt_bud_rlmi := null;
4672 g_pkt_tt_prlmi := p_record.Parent_resource_id;
4673 g_pkt_tt_entry_level_code := p_record.entry_level_code;
4674 g_pkt_tt_start_date := trunc(p_start_date);
4675 g_pkt_tt_end_date := trunc(p_end_date);
4676 g_pkt_tt_time_phase_code := p_record.time_phased_type_code;
4677 ---------end of performance test --------------
4678
4679 ELSE
4680 IF g_debug_mode = 'Y' THEN
4681 log_message(p_msg_token1 => 'same combination for top task pkt cursor');
4682 end if;
4683 l_pkt_amt := g_tt_base_amt;
4684 l_tt_enc_approved := g_tt_enc_approved;
4685 l_tt_enc_pending := g_tt_enc_pending;
4686 l_tt_actual_approved := g_tt_actual_approved;
4687 l_tt_actual_pending := g_tt_actual_pending;
4688 END IF; -- end of one level cache
4689 IF g_debug_mode = 'Y' THEN
4690 log_message(p_msg_token1 =>'pkt_amt ['||l_pkt_amt||
4691 ']tt_enc_approved ['||l_tt_enc_approved||']tt_enc_pending [ '||l_tt_enc_pending||
4692 ']tt_actual_approved ['||l_tt_actual_approved||']tt_actual_pending ['||l_tt_actual_pending|| ']' );
4693 end if;
4694
4695 l_available_amt := nvl(l_tt_budget_posted,0) -
4696 (nvl(l_tt_actual_posted,0) +
4697 nvl(l_tt_enc_posted,0) +
4698 nvl(l_pkt_amt,0) +
4699 nvl(l_tt_actual_approved,0) +
4700 nvl(l_tt_enc_approved,0) +
4701 nvl(g_tt_pkt_amt ,0)
4702 );
4703 IF g_debug_mode = 'Y' THEN
4704 log_message(p_msg_token1 =>'available_amt ='||l_available_amt);
4705 end if;
4706 IF p_record.status_code||p_record.actual_flag = 'AE' then
4707 l_tt_enc_approved := nvl(l_tt_enc_approved,0) +
4708 p_record.accounted_dr
4709 - p_record.accounted_cr;
4710 IF g_debug_mode = 'Y' THEN
4711 log_message(p_msg_token1 =>'tt_enc_approved ='||l_tt_enc_approved);
4712 end if;
4713 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4714 l_tt_enc_pending := nvl(l_tt_enc_pending,0) +
4715 p_record.accounted_dr
4716 - p_record.accounted_cr;
4717 IF g_debug_mode = 'Y' THEN
4718 log_message(p_msg_token1 =>'tt_enc_pending = '||l_tt_enc_pending);
4719 end if;
4720
4721 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4722 l_tt_actual_approved := nvl(l_tt_actual_approved,0) +
4723 p_record.accounted_dr
4724 - p_record.accounted_cr;
4725 IF g_debug_mode = 'Y' THEN
4726 log_message(p_msg_token1 =>'tt_actual_approved ='||l_tt_actual_approved);
4727 end if;
4728
4729 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4730 l_tt_actual_pending := nvl(l_tt_actual_pending,0) +
4731 p_record.accounted_dr
4732 - p_record.accounted_cr;
4733 IF g_debug_mode = 'Y' THEN
4734 log_message(p_msg_token1 =>'tt_actual_pending ='||l_tt_actual_pending);
4735 end if;
4736
4737 END IF;
4738 l_tt_budget_bal := l_available_amt;
4739 IF g_debug_mode = 'Y' THEN
4740 log_message(p_msg_token1 =>'calling generate_result_code at tt level ');
4741 end if;
4742 generate_result_code(
4743 p_fclevel_code => p_record.tt_funds_control_level_code,
4744 p_available_amt => l_available_amt,
4745 p_stage => l_stage,
4746 p_budget_posted_amt => l_tt_budget_posted,
4747 x_result_code => l_result_code,
4748 x_r_result_code => l_r_result_code,
4749 x_rg_result_code => l_rg_result_code,
4750 x_t_result_code => l_t_result_code,
4751 x_tt_result_code => l_tt_result_code,
4752 x_p_result_code => l_p_result_code,
4753 x_p_acct_result_code => l_p_acct_result_code,
4754 x_return_status => l_return_status
4755 ) ;
4756 IF g_debug_mode = 'Y' THEN
4757 log_message(p_msg_token1 =>'end of generate result code api '
4758 ||'l_tt_result_code ['||l_tt_result_code||']l_result_code['||l_result_code||']' );
4759 end if;
4760
4761 IF l_return_status = 'F' THEN
4762 g_adv_result_code := NULL; -- Added for bug 9156359
4763 GOTO END_PROCESS;
4764 ELSIF l_return_status = 'A' THEN
4765 g_adv_result_code := 'A'; -- Added for bug 9156359
4766 ELSE
4767 -- PROCEED TO NEXT STAGE ie PROJECT LEVEL
4768 NULL;
4769 END IF;
4770 END IF ; -- end if for top task level
4771 --*******************************************************************************
4772 -- FUNDS CHECK AT PROJECT LEVEL --------
4773 --******************************************************************************
4774 l_stage := 500;
4775 IF g_debug_mode = 'Y' THEN
4776 log_message(p_msg_token1 =>'stage = 500');
4777 end if;
4778
4779 IF (p_record.project_id <> g_bal_p_project_id OR g_bal_p_project_id is NULL ) OR
4780 (p_record.budget_version_id <> g_bal_p_bdgt_version_id or g_bal_p_bdgt_version_id is NULL ) OR
4781 (p_record.time_phased_type_code <> g_bal_p_time_phase_code or g_bal_p_time_phase_code is NULL ) OR
4782 --(p_record.entry_level_code <> g_bal_p_entry_level_code or g_bal_p_entry_level_code is NULL ) OR
4783 (trunc(p_start_date) <> trunc(g_bal_p_start_date) or g_bal_p_start_date is NULL ) OR
4784 (trunc(p_end_date) <> trunc(g_bal_p_end_date ) or g_bal_p_end_date is NULL) THEN
4785
4786 OPEN project_level_bal;
4787 IF g_debug_mode = 'Y' THEN
4788 log_message(p_msg_token1 =>'opened project level bal cursor ');
4789 end if;
4790 FETCH project_level_bal INTO l_p_budget_posted,
4791 l_p_actual_posted,
4792 l_p_enc_posted;
4793
4794 g_p_budget_posted := l_p_budget_posted;
4795 g_p_actual_posted := l_p_actual_posted;
4796 g_p_enc_posted := l_p_enc_posted;
4797 IF g_debug_mode = 'Y' THEN
4798 log_message(p_msg_token1 =>'p_budget_posted ['||l_p_budget_posted||
4799 ']p_actual_posted ['||l_p_actual_posted||']p_enc_posted ['||l_p_enc_posted||']' );
4800 end if;
4801
4802 CLOSE project_level_bal;
4803
4804 --- added for performance testing
4805 g_bal_p_project_id := p_record.project_id;
4806 g_bal_p_task_id := p_record.task_id;
4807 g_bal_p_top_task_id := p_record.top_task_id;
4808 g_bal_p_bdgt_version_id := p_record.budget_version_id;
4809 g_bal_p_bud_task_id := p_record.bud_task_id;
4810 g_bal_p_bud_rlmi := p_record.bud_resource_list_member_id;
4811 g_bal_p_prlmi := p_record.parent_resource_id;
4812 g_bal_p_entry_level_code := p_record.entry_level_code;
4813 g_bal_p_start_date := trunc(p_start_date);
4814 g_bal_p_end_date := trunc(p_end_date);
4815 g_bal_p_time_phase_code := p_record.time_phased_type_code;
4816 -------------- end of perfromance test ----
4817
4818 ELSE
4819 IF g_debug_mode = 'Y' THEN
4820 log_message(p_msg_token1 => 'Same combination for project cur ');
4821 end if;
4822 l_p_budget_posted := g_p_budget_posted;
4823 l_p_actual_posted := g_p_actual_posted;
4824 l_p_enc_posted := g_p_enc_posted;
4825 END IF;
4826 IF g_debug_mode = 'Y' THEN
4827 log_message(p_msg_token1 =>'p_budget_posted ['||l_p_budget_posted||
4828 ']p_actual_posted ['||l_p_actual_posted||']p_enc_posted ['||l_p_enc_posted||']' );
4829 end if;
4830
4831 IF (p_record.project_id <> g_pkt_p_project_id OR g_pkt_p_project_id is NULL ) OR
4832 (p_record.budget_version_id <> g_pkt_p_bdgt_version_id or g_pkt_p_bdgt_version_id is NULL ) OR
4833 --(p_record.time_phased_type_code <> g_pkt_p_time_phase_code or g_pkt_p_time_phase_code is NULL ) OR
4834 (p_record.entry_level_code <> g_pkt_p_entry_level_code or g_pkt_p_entry_level_code is NULL ) OR
4835 (trunc(p_start_date) <> trunc(g_pkt_p_start_date) or g_pkt_p_start_date is NULL ) OR
4836 (trunc(p_end_date) <> trunc(g_pkt_p_end_date ) or g_pkt_p_end_date is NULL) THEN
4837
4838 OPEN project_tot_bc_pkt ;
4839 IF g_debug_mode = 'Y' THEN
4840 log_message(p_msg_token1 =>'opened project_tot_bc_pkt cursor ');
4841 end if;
4842 FETCH project_tot_bc_pkt INTO l_pkt_amt
4843 ,l_p_enc_approved
4844 ,l_p_actual_approved ;
4845 g_p_base_amt := l_pkt_amt;
4846 g_p_enc_approved := l_p_enc_approved;
4847 g_p_enc_pending := l_p_enc_pending;
4848 g_p_actual_approved:= l_p_actual_approved;
4849 g_p_actual_pending := l_p_actual_pending;
4850
4851 CLOSE project_tot_bc_pkt;
4852
4853 -- added for performance test
4854 g_pkt_p_project_id := p_record.project_id;
4855 g_pkt_p_bdgt_version_id := p_record.budget_version_id;
4856 g_pkt_p_entry_level_code := p_record.entry_level_code;
4857 g_pkt_p_start_date := trunc(p_start_date);
4858 g_pkt_p_end_date := trunc(p_end_date);
4859 g_pkt_p_time_phase_code := p_record.time_phased_type_code;
4860 -------end of performance test --------------
4861
4862 ELSE
4863 IF g_debug_mode = 'Y' THEN
4864 log_message(p_msg_token1 => 'Same combination for project acct cursor');
4865 end if;
4866 l_pkt_amt := g_p_base_amt;
4867 l_p_enc_approved := g_p_enc_approved;
4868 l_p_enc_pending := g_p_enc_pending;
4869 l_p_actual_approved:= g_p_actual_approved;
4870 l_p_actual_pending := g_p_actual_pending;
4871
4872 END IF;
4873 IF g_debug_mode = 'Y' THEN
4874 log_message(p_msg_token1 =>'pkt_amt ['||l_pkt_amt||']p_enc_approved ='||l_p_enc_approved||
4875 ']p_enc_pending = '||l_p_enc_pending||']p_actual_approved ='||l_p_actual_approved||
4876 ']p_actual_pending ='||l_p_actual_pending||']' );
4877 end if;
4878
4879 l_available_amt := nvl(l_p_budget_posted,0) -
4880 (nvl(l_p_actual_posted,0) +
4881 nvl(l_p_enc_posted ,0)+
4882 nvl(l_pkt_amt,0) +
4883 nvl(l_p_actual_approved,0) +
4884 nvl(l_p_enc_approved,0) +
4885 nvl(g_p_pkt_amt ,0)
4886 );
4887 IF g_debug_mode = 'Y' THEN
4888 log_message(p_msg_token1 =>'available_amt ='||l_available_amt);
4889 end if;
4890 IF p_record.status_code||p_record.actual_flag = 'AE' then
4891 l_p_enc_approved := nvl(l_p_enc_approved,0) +
4892 p_record.accounted_dr
4893 - p_record.accounted_cr;
4894 IF g_debug_mode = 'Y' THEN
4895 log_message(p_msg_token1 =>'p_enc_approved ='||l_p_enc_approved);
4896 end if;
4897 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4898 l_p_enc_pending := nvl(l_p_enc_pending,0) +
4899 p_record.accounted_dr
4900 - p_record.accounted_cr;
4901 IF g_debug_mode = 'Y' THEN
4902 log_message(p_msg_token1 =>'p_enc_pending = '||l_p_enc_pending);
4903 end if;
4904
4905 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4906 l_p_actual_approved := nvl(l_p_actual_approved,0) +
4907 p_record.accounted_dr
4908 - p_record.accounted_cr;
4909 IF g_debug_mode = 'Y' THEN
4910 log_message(p_msg_token1 =>'p_actual_approved ='||l_p_actual_approved);
4911 end if;
4912
4913 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4914 l_p_actual_pending := nvl(l_p_actual_pending,0) +
4915 p_record.accounted_dr
4916 - p_record.accounted_cr;
4917 IF g_debug_mode = 'Y' THEN
4918 log_message(p_msg_token1 =>'p_actual_pending ='||l_p_actual_pending);
4919 end if;
4920
4921 END IF;
4922 l_p_budget_bal := l_available_amt;
4923 IF g_debug_mode = 'Y' THEN
4924 log_message(p_msg_token1 =>'calling generate_result_code at p level ');
4925 end if;
4926 generate_result_code(
4927 p_fclevel_code => p_record.p_funds_control_level_code,
4928 p_available_amt => l_available_amt,
4929 p_stage => l_stage,
4930 p_budget_posted_amt => l_p_budget_posted,
4931 x_result_code => l_result_code,
4932 x_r_result_code => l_r_result_code,
4933 x_rg_result_code => l_rg_result_code,
4934 x_t_result_code => l_t_result_code,
4935 x_tt_result_code => l_tt_result_code,
4936 x_p_result_code => l_p_result_code,
4937 x_p_acct_result_code => l_p_acct_result_code,
4938 x_return_status => l_return_status
4939 ) ;
4940 IF g_debug_mode = 'Y' THEN
4941 log_message(p_msg_token1 =>'end of generate result code api ');
4942 log_message(p_msg_token1 =>'l_p_result_code = '||l_p_result_code||
4943 'l_result_code ='||l_result_code);
4944 log_message(p_msg_token1 =>'end of generate_result_code api ');
4945 end if;
4946
4947 IF l_return_status = 'F' THEN
4948 g_adv_result_code := NULL; -- Added for bug 9156359
4949 GOTO END_PROCESS;
4950 ELSIF l_return_status = 'A' THEN
4951 g_adv_result_code := 'A'; -- Added for bug 9156359
4952 ELSE
4953 -- PROCEED TO NEXT STAGE ie PROJECT ACCOUNT LEVEL BAL
4954 NULL;
4955 END IF;
4956 --***************************************************************************
4957 -- FUNDS CHECK AT PROJECT ACCOUNT LEVEL BALANCE--
4958 --*************************************************************************
4959
4960 -- R12 change: Account level funds check should not be carried out here for re-baseline
4961 IF P_MODE NOT IN ('S','B') THEN
4962
4963 -- if the budget linked with Standard GL / External Budget then
4964 -- check the funds avaiable at account level for each transaction
4965 IF g_debug_mode = 'Y' THEN
4966 log_message(p_msg_token1 => 'funds check at project account level');
4967 End if;
4968 IF p_ext_bdgt_link = 'Y' then
4969 l_stage := 600;
4970 IF g_debug_mode = 'Y' THEN
4971 log_message(p_msg_token1 => 'Stage 600 calling Get_Acct_Line_Balance api'||
4972 'in parameters are budget_version_id ['||p_record.budget_version_id||
4973 ']p_start_date ['||p_start_date||']p_end_date ['||p_end_date||
4974 ']budget_ccid [ '||p_record.budget_ccid||']' );
4975 End if;
4976
4977 l_acct_level_bal := pa_funds_control_utils.Get_Acct_Line_Balance(
4978 p_budget_version_id => p_record.budget_version_id,
4979 p_start_date => p_start_date,
4980 p_end_date => p_end_date,
4981 p_budget_ccid => p_record.budget_ccid);
4982 IF g_debug_mode = 'Y' THEN
4983 log_message(p_msg_token1 =>'acct_level_bal ='||l_acct_level_bal);
4984 end if;
4985
4986 IF (p_record.project_id <> g_pkt_p_acct_project_id OR g_pkt_p_acct_project_id is NULL ) OR
4987 (p_record.budget_version_id <> g_pkt_p_acct_bdgt_version_id or g_pkt_p_acct_bdgt_version_id is NULL ) OR
4988 (p_record.budget_ccid <> g_pkt_p_acct_bdgt_ccid or g_pkt_p_acct_bdgt_ccid is NULL ) OR
4989 (trunc(p_start_date) <> trunc(g_pkt_p_acct_start_date) or g_pkt_p_acct_start_date is NULL ) OR
4990 (trunc(p_end_date) <> trunc(g_pkt_p_acct_end_date ) or g_pkt_p_acct_end_date is NULL) THEN
4991
4992 --r_msg('NEW PROJECT ACCT FOR PKT');
4993 OPEN project_acct_tot_bc_pkt(p_record.budget_ccid);
4994 IF g_debug_mode = 'Y' THEN
4995 log_message(p_msg_token1 => 'opened project_acct_tot_bc_pkt cursor ');
4996 end if;
4997 FETCH project_acct_tot_bc_pkt INTO l_pkt_amt,
4998 l_p_acct_enc_approved,
4999 l_p_acct_actual_approved;
5000
5001 g_p_acct_base_amt := l_pkt_amt;
5002 g_p_acct_enc_approved := l_p_acct_enc_approved;
5003 g_p_acct_actual_approved := l_p_acct_actual_approved;
5004 CLOSE project_acct_tot_bc_pkt;
5005
5006 -- added for performance test
5007 g_pkt_p_acct_project_id := p_record.project_id;
5008 g_pkt_p_acct_bdgt_version_id := p_record.budget_version_id;
5009 g_pkt_p_acct_bdgt_ccid := p_record.budget_ccid;
5010 g_pkt_p_acct_start_date := trunc(p_start_date);
5011 g_pkt_p_acct_end_date := trunc(p_end_date);
5012 g_pkt_p_acct_time_phase_code := p_record.time_phased_type_code;
5013 -----end of performance test --------------
5014
5015 ELSE
5016 l_pkt_amt := g_p_acct_base_amt;
5017 l_p_acct_enc_approved := g_p_acct_enc_approved;
5018 l_p_acct_actual_approved:= g_p_acct_actual_approved;
5019
5020 END IF;
5021 IF g_debug_mode = 'Y' THEN
5022 log_message(p_msg_token1 =>'l_p_acct_enc_approved ['||l_p_acct_enc_approved||
5023 ']l_p_acct_actual_approved ['||l_p_acct_actual_approved||
5024 ']l_p_acct_pkt_amt ['||l_pkt_amt||']g_p_acct_pkt_amt ['||g_p_acct_pkt_amt||']' );
5025 End if;
5026
5027 l_available_amt := nvl(l_acct_level_bal,0) -
5028 ( --nvl(l_p_acct_enc_approved,0) +
5029 -- nvl(l_p_acct_actual_approved,0) +
5030 nvl(l_pkt_amt,0) +
5031 nvl(g_p_acct_pkt_amt,0)
5032 );
5033 IF g_debug_mode = 'Y' THEN
5034 log_message(p_msg_token1 => 'available_amt ['||l_available_amt||']' );
5035 end if;
5036 generate_result_code(
5037 p_fclevel_code => p_record.p_funds_control_level_code,
5038 p_available_amt => l_available_amt,
5039 p_stage => l_stage,
5040 p_budget_posted_amt => l_acct_level_bal,
5041 x_result_code => l_result_code,
5042 x_r_result_code => l_r_result_code,
5043 x_rg_result_code => l_rg_result_code,
5044 x_t_result_code => l_t_result_code,
5045 x_tt_result_code => l_tt_result_code,
5046 x_p_result_code => l_p_result_code,
5047 x_p_acct_result_code => l_p_acct_result_code,
5048 x_return_status => l_return_status
5049 ) ;
5050 IF g_debug_mode = 'Y' THEN
5051 log_message(p_msg_token1 =>'End of generate result l_p_acct_result_code = '||
5052 l_p_acct_result_code||']l_result_code ['||l_result_code||']');
5053 End if;
5054
5055 END IF; -- external link check
5056
5057 END IF; --IF P_MODE NOT IN ('S','B') THEN
5058
5059 --Store the local values in global variables to use as one level cache
5060 g_project_id := p_record.project_id;
5061 g_top_task_id := p_record.top_task_id;
5062 g_task_id := p_record.task_id;
5063 g_bdgt_version_id := p_record.budget_version_id;
5064 g_bud_task_id := p_record.bud_task_id;
5065 g_rlmi := p_record.resource_list_member_id;
5066 g_bud_rlmi := p_record.bud_resource_list_member_id;
5067 g_prlmi := p_record.parent_resource_id;
5068 g_entry_level_code := p_record.entry_level_code;
5069 g_start_date := p_start_date;
5070 g_end_date := p_end_date;
5071 g_time_phase_code := p_record.time_phased_type_code;
5072 g_bdgt_ccid := p_record.budget_ccid;
5073
5074
5075
5076 <<END_PROCESS>>
5077 IF g_debug_mode = 'Y' THEN
5078 log_message(p_msg_token1 => 'End of process assiging out NOCOPY parameters with funds checked results');
5079 end if;
5080 -- Assign all out NOCOPY parameters with funds checked results
5081 p_record.r_budget_posted := l_r_budget_posted ;
5082 p_record.rg_budget_posted := l_rg_budget_posted;
5083 p_record.t_budget_posted := l_t_budget_posted;
5084 p_record.tt_budget_posted := l_tt_budget_posted ;
5085 p_record.p_budget_posted := l_p_budget_posted;
5086 p_record.r_actual_posted := l_r_actual_posted;
5087 p_record.rg_actual_posted := l_rg_actual_posted;
5088 p_record.t_actual_posted := l_t_actual_posted;
5089 p_record.tt_actual_posted := l_tt_actual_posted;
5090 p_record.p_actual_posted := l_p_actual_posted;
5091 p_record.r_enc_posted := l_r_enc_posted;
5092 p_record.rg_enc_posted := l_rg_enc_posted ;
5093 p_record.t_enc_posted := l_t_enc_posted ;
5094 p_record.tt_enc_posted := l_tt_enc_posted ;
5095 p_record.p_enc_posted := l_p_enc_posted;
5096 p_record.r_budget_bal := l_r_budget_bal;
5097 p_record.rg_budget_bal := l_rg_budget_bal ;
5098 p_record.t_budget_bal := l_t_budget_bal;
5099 p_record.tt_budget_bal := l_tt_budget_bal;
5100 p_record.p_budget_bal := l_p_budget_bal;
5101 p_record.r_actual_approved := l_r_actual_approved;
5102 p_record.rg_actual_approved := l_rg_actual_approved;
5103 p_record.t_actual_approved := l_t_actual_approved ;
5104 p_record.tt_actual_approved := l_tt_actual_approved;
5105 p_record.p_actual_approved := l_p_actual_approved ;
5106 p_record.r_enc_approved := l_r_enc_approved;
5107 p_record.rg_enc_approved := l_rg_enc_approved;
5108 p_record.t_enc_approved := l_t_enc_approved ;
5109 p_record.tt_enc_approved := l_tt_enc_approved;
5110 p_record.p_enc_approved := l_p_enc_approved;
5111 p_record.result_code := l_result_code;
5112 p_record.r_result_code := l_r_result_code;
5113 p_record.rg_result_code := l_rg_result_code;
5114 p_record.t_result_code := l_t_result_code;
5115 p_record.tt_result_code := l_tt_result_code;
5116 p_record.p_result_code := l_p_result_code;
5117 p_record.p_acct_result_code := l_p_acct_result_code;
5118
5119 g_pre_project_id := p_record.project_id;
5120 g_pre_top_task_id := p_record.top_task_id;
5121 g_pre_task_id := p_record.task_id;
5122 g_pre_bdgt_version_id := p_record.budget_version_id;
5123 g_pre_bud_task_id := p_record.bud_task_id;
5124 g_pre_rlmi := p_record.resource_list_member_id;
5125 g_pre_bud_rlmi := p_record.bud_resource_list_member_id;
5126 g_pre_prlmi := p_record.parent_resource_id;
5127 g_pre_entry_level_code := p_record.entry_level_code;
5128 g_pre_start_date := p_start_date;
5129 g_pre_end_date := p_end_date;
5130 g_pre_time_phase_code := p_record.time_phased_type_code;
5131 g_pre_bdgt_ccid := p_record.budget_ccid;
5132 IF g_debug_mode = 'Y' THEN
5133 log_message(p_msg_token1 => 'end of assignments sub string l_result_code ['||l_result_code||']' );
5134 end if;
5135
5136 IF substr(l_result_code,1,1) = 'F' and l_cached_satus = 'Y' then
5137 IF g_debug_mode = 'Y' THEN
5138 log_message(p_msg_token1 => 'calling cache pkt amounts to minus');
5139 end if;
5140 -- deduct this amount from the cache
5141 CACHE_PKT_AMOUNTS(
5142 p_project_id => p_record.project_id
5143 ,p_bdgt_version => p_record.budget_version_id
5144 ,p_top_task_id => p_record.top_task_id
5145 ,p_task_id => p_record.task_id
5146 ,p_bud_task_id => p_record.bud_task_id
5147 ,p_start_date => p_start_date
5148 ,p_end_date => p_end_date
5149 ,p_rlmi => p_record.resource_list_member_id
5150 ,p_bud_rlmi => p_record.bud_resource_list_member_id
5151 ,p_prlmi => p_record.parent_resource_id
5152 ,p_bdgt_ccid => p_record.budget_ccid
5153 ,p_accounted_dr => p_record.accounted_dr
5154 ,p_accounted_cr => p_record.accounted_cr
5155 ,p_calling_module => p_calling_module
5156 ,p_partial_flag => p_partial_flag
5157 ,p_function => 'MINUS'
5158 ,p_bc_packet_id => p_record.bc_packet_id
5159 ,p_doc_type => p_record.document_type
5160 ,p_doc_header_id => p_record.document_header_id
5161 ,p_doc_distribution_id =>p_record.document_distribution_id
5162 ,x_result_code => l_result_code
5163 ,x_cached_status => l_cached_satus
5164 ,p_counter => p_counter
5165 );
5166
5167 IF g_debug_mode = 'Y' THEN
5168 log_message(p_msg_token1 => 'After calling CACHE_PKT_AMOUNTS to minus');
5169 end if;
5170 END IF;
5171
5172
5173 IF res_level_bal%ISOPEN then
5174 CLOSE res_level_bal;
5175 END IF;
5176
5177 IF res_tot_bc_pkt%ISOPEN then
5178 CLOSE res_tot_bc_pkt;
5179 END IF;
5180
5181 IF res_grp_level_bal%ISOPEN THEN
5182 CLOSE res_grp_level_bal;
5183 END IF;
5184
5185 IF res_rollup_bal%ISOPEN THEN
5186 CLOSE res_rollup_bal;
5187 END IF;
5188 IF res_grp_tot_bc_pkt%ISOPEN THEN
5189 CLOSE res_grp_tot_bc_pkt;
5190 END IF;
5191 IF task_level_bal%ISOPEN THEN
5192 CLOSE task_level_bal;
5193 END IF;
5194 IF task_tot_bc_pkt%ISOPEN THEN
5195 CLOSE task_tot_bc_pkt;
5196 END IF;
5197 IF top_task_level_bal%ISOPEN THEN
5198 CLOSE top_task_level_bal;
5199 END IF;
5200 IF task_rollup_bal%ISOPEN THEN
5201 CLOSE task_rollup_bal;
5202 END IF;
5203 IF top_task_tot_bc_pkt%ISOPEN THEN
5204 CLOSE top_task_tot_bc_pkt;
5205 END IF;
5206 IF project_level_bal%ISOPEN THEN
5207 CLOSE project_level_bal;
5208 END IF;
5209 IF project_tot_bc_pkt%ISOPEN THEN
5210 CLOSE project_tot_bc_pkt;
5211 END IF;
5212 IF project_acct_tot_bc_pkt%ISOPEN THEN
5213 CLOSE project_acct_tot_bc_pkt;
5214 END IF;
5215 RETURN;
5216
5217 EXCEPTION
5218 WHEN OTHERS THEN
5219 IF g_debug_mode = 'Y' THEN
5220 log_message(p_msg_token1 => 'funds check failed due to unexpected error');
5221 end if;
5222 IF res_level_bal%ISOPEN then
5223 CLOSE res_level_bal;
5224 END IF;
5225
5226 IF res_tot_bc_pkt%ISOPEN then
5227 CLOSE res_tot_bc_pkt;
5228 END IF;
5229
5230 IF res_grp_level_bal%ISOPEN THEN
5231 CLOSE res_grp_level_bal;
5232 END IF;
5233
5234 IF res_rollup_bal%ISOPEN THEN
5235 CLOSE res_rollup_bal;
5236 END IF;
5237 IF res_grp_tot_bc_pkt%ISOPEN THEN
5238 CLOSE res_grp_tot_bc_pkt;
5239 END IF;
5240 IF task_level_bal%ISOPEN THEN
5241 CLOSE task_level_bal;
5242 END IF;
5243 IF task_tot_bc_pkt%ISOPEN THEN
5244 CLOSE task_tot_bc_pkt;
5245 END IF;
5246 IF top_task_level_bal%ISOPEN THEN
5247 CLOSE top_task_level_bal;
5248 END IF;
5249 IF task_rollup_bal%ISOPEN THEN
5250 CLOSE task_rollup_bal;
5251 END IF;
5252 IF top_task_tot_bc_pkt%ISOPEN THEN
5253 CLOSE top_task_tot_bc_pkt;
5254 END IF;
5255 IF project_level_bal%ISOPEN THEN
5256 CLOSE project_level_bal;
5257 END IF;
5258 IF project_tot_bc_pkt%ISOPEN THEN
5259 CLOSE project_tot_bc_pkt;
5260 END IF;
5261 IF project_acct_tot_bc_pkt%ISOPEN THEN
5262 CLOSE project_acct_tot_bc_pkt;
5263 END IF;
5264 IF g_debug_mode = 'Y' THEN
5265 log_message(p_msg_token1 => 'Exception in check_eunds_available SQLERR :'||sqlcode||sqlerrm);
5266 end if;
5267 --commit;
5268 Raise;
5269 END check_funds_available ;
5270 ---------------------------------------------------------------------------------
5271 -- This Api updates the pa_bc_packets with fundscheck amounts and result code
5272 -- after doing the fundscheck this api is in autonomous transaction
5273 ---------------------------------------------------------------------------------
5274 PROCEDURE update_pkt_amts(p_packet_id IN number) IS
5275 PRAGMA AUTONOMOUS_TRANSACTION;
5276 BEGIN
5277 IF g_debug_mode = 'Y' THEN
5278 log_message(p_msg_token1 => 'before update of pa bc packets ');
5279 End if;
5280 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
5281 UPDATE pa_bc_packets
5282 SET result_code = nvl(g_tab_result_code(i),result_code),
5283 res_result_code =nvl( g_tab_r_result_code(i),res_result_code),
5284 res_grp_result_code = nvl(g_tab_rg_result_code(i),res_grp_result_code),
5285 task_result_code = nvl(g_tab_t_result_code(i),task_result_code),
5286 top_task_result_code = nvl(g_tab_tt_result_code(i),top_task_result_code),
5287 project_result_code = nvl(g_tab_p_result_code(i),project_result_code),
5288 project_acct_result_code = nvl(g_tab_p_acct_result_code(i),project_acct_result_code),
5289 status_code = decode(nvl(g_tab_status_code(i),status_code),'Z','P',
5290 nvl(g_tab_status_code(i),status_code)),
5291 res_budget_posted =nvl( g_tab_r_budget_posted(i),res_budget_posted),
5292 res_grp_budget_posted = nvl(g_tab_rg_budget_posted(i),res_grp_budget_posted),
5293 task_budget_posted = nvl(g_tab_t_budget_posted(i),task_budget_posted),
5294 top_task_budget_posted = nvl(g_tab_tt_budget_posted(i),top_task_budget_posted),
5295 project_budget_posted = nvl(g_tab_p_budget_posted(i),project_budget_posted),
5296 res_actual_posted = nvl(g_tab_r_actual_posted(i),res_actual_posted ),
5297 res_grp_actual_posted = nvl(g_tab_rg_actual_posted(i),res_grp_actual_posted),
5298 task_actual_posted = nvl(g_tab_t_actual_posted(i),task_actual_posted),
5299 top_task_actual_posted = nvl(g_tab_tt_actual_posted(i),top_task_actual_posted),
5300 project_actual_posted = nvl(g_tab_p_actual_posted(i),project_actual_posted),
5301 res_enc_posted = nvl(g_tab_r_enc_posted(i),res_enc_posted),
5302 res_grp_enc_posted = nvl(g_tab_rg_enc_posted(i),res_grp_enc_posted),
5303 task_enc_posted = nvl(g_tab_t_enc_posted(i),task_enc_posted ),
5304 top_task_enc_posted = nvl(g_tab_tt_enc_posted(i),top_task_enc_posted),
5305 project_enc_posted = nvl(g_tab_p_enc_posted(i),project_enc_posted),
5306 res_budget_bal = nvl(g_tab_r_budget_bal(i),res_budget_bal),
5307 res_grp_budget_bal = nvl(g_tab_rg_budget_bal(i),res_grp_budget_bal),
5308 task_budget_bal = nvl(g_tab_t_budget_bal(i),task_budget_bal),
5309 top_task_budget_bal = nvl(g_tab_tt_budget_bal(i),top_task_budget_bal),
5310 project_budget_bal = nvl(g_tab_p_budget_bal(i),project_budget_bal),
5311 res_actual_approved = nvl(g_tab_r_actual_approved(i),res_actual_approved),
5312 res_grp_actual_approved = nvl(g_tab_rg_actual_approved(i),res_grp_actual_approved),
5313 task_actual_approved =nvl( g_tab_t_actual_approved(i),task_actual_approved),
5314 top_task_actual_approved = nvl(g_tab_tt_actual_approved(i),top_task_actual_approved),
5315 project_actual_approved = nvl(g_tab_p_actual_approved(i),project_actual_approved),
5316 res_enc_approved = nvl(g_tab_r_enc_approved(i),res_enc_approved),
5317 res_grp_enc_approved = nvl(g_tab_rg_enc_approved(i),res_grp_enc_approved),
5318 task_enc_approved = nvl(g_tab_t_enc_approved(i),task_enc_approved),
5319 top_task_enc_approved = nvl(g_tab_tt_enc_approved(i),top_task_enc_approved),
5320 project_enc_approved = nvl(g_tab_p_enc_approved(i),project_enc_approved)
5321 WHERE packet_id = p_packet_id
5322 AND rowid = g_tab_rowid(i);
5323 IF g_debug_mode = 'Y' THEN
5324 log_message(p_msg_token1 => 'End of FORALL update statement');
5325 End If;
5326
5327 commit;
5328 return;
5329
5330 EXCEPTION
5331 when others then
5332 raise;
5333 END update_pkt_amts;
5334 /** This api updates the Encumbrance approved bal for the packets
5335 * which contains transaction PO,AP,CC_P_PAY,CC_C_PAY
5336 * This API is primarily intended to update the encumbrance_approved_bal
5337 * to display in the funds check view form refer to Bug:2021199
5338 **/
5339 PROCEDURE update_enc_approvl_bal(p_packet_id IN pa_bc_packets.packet_id%type
5340 ,p_mode IN varchar2
5341 ,p_calling_module IN varchar2
5342 ) IS
5343 PRAGMA AUTONOMOUS_TRANSACTION;
5344
5345 /* Bug fix: 2658952 Transaction funds chekc screen not showing proper balances
5346 * If the inner sub query in update statement returns no rows then all the
5347 * enc approved columns are updated to zero
5348 * So moving the subquery into cursor and updating the bc_packets enc_approved
5349 * columns in a loop
5350 */
5351
5352 /** Bug fix : if Invoice has Tax lines then api fails with sql error
5353 ** ORA-01427: single-row subquery returns more than one row to avoid this
5354 ** sum() function has been used. For proper fix we need to add few columns to
5355 ** pa_bc_packets and pa_bc_commitments to distiguish the lines as ITEM / TAX
5356 ** the fix required here to add one more condition a.line_type = b.line_type
5357 **/
5358
5359 CURSOR updEnc(p_bc_pkt_id Number
5360 ,p_res_enc_approved Number
5361 ,p_res_grp_enc_approved Number
5362 ,p_task_enc_approved Number
5363 ,p_top_task_enc_approved Number
5364 ,p_project_enc_approved Number
5365 ) IS
5366 select decode(nvl(p_res_enc_approved,0),0,0,p_res_enc_approved -
5367 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5368 decode(nvl(p_res_grp_enc_approved,0),0,0,p_res_grp_enc_approved -
5369 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5370 decode(nvl(p_task_enc_approved,0),0,0,p_task_enc_approved -
5371 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5372 decode(nvl(p_top_task_enc_approved,0),0,0,p_top_task_enc_approved -
5373 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5374 decode(nvl(p_project_enc_approved,0),0,0,p_project_enc_approved -
5375 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0)))
5376 from pa_bc_packets a
5377 ,pa_bc_packets b
5378 where
5379 a.packet_id = p_packet_id
5380 and a.bc_packet_id = p_bc_pkt_id
5381 and a.packet_id = b.packet_id
5382 and b.result_code like 'P%'
5383 and abs((nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0))) -
5384 abs((nvl(b.accounted_dr,0)-nvl(b.accounted_cr,0))) < .1
5385 and ( (a.parent_bc_packet_id is null and b.parent_bc_packet_id is null)
5386 or (a.parent_bc_packet_id is not null and b.parent_bc_packet_id is not null)
5387 )
5388 and ((( a.document_type = 'PO' and b.document_type = 'REQ')
5389 and exists ( select 'Y'
5390 from po_distributions_all po
5391 ,po_req_distributions_all req
5392 where req.distribution_id = b.document_distribution_id
5393 and po.po_distribution_id = a.document_distribution_id
5394 and po.req_distribution_id = req.distribution_id
5395 and a.packet_id = b.packet_id
5396 and a.bc_packet_id = p_bc_pkt_id
5397 and b.packet_id = p_packet_id
5398 )
5399 )
5400 OR (( a.document_type = 'AP' and b.document_type = 'PO' )
5401 and exists ( select 'Y'
5402 from po_distributions_all po
5403 ,ap_invoice_distributions_all ap
5404 where po.po_distribution_id = b.document_distribution_id
5405 and ap.invoice_id = a.document_header_id
5406 and ap.distribution_line_number = a.document_distribution_id
5407 and ap.po_distribution_id = po.po_distribution_id
5408 and a.packet_id = b.packet_id
5409 and a.bc_packet_id = p_bc_pkt_id
5410 and b.packet_id = p_packet_id
5411 union /*Bug 13602288: Self Assessed Tax Changes*/
5412 select 'Y'
5413 from po_distributions_all po
5414 ,ap_self_assessed_tax_dist_all ap
5415 where po.po_distribution_id = b.document_distribution_id
5416 and ap.invoice_id = a.document_header_id
5417 and ap.distribution_line_number = a.document_distribution_id
5418 and ap.po_distribution_id = po.po_distribution_id
5419 and a.packet_id = b.packet_id
5420 and a.bc_packet_id = p_bc_pkt_id
5421 and b.packet_id = p_packet_id
5422 )
5423 )
5424 OR (( a.document_type = 'AP' and b.document_type in ( 'CC_P_PAY','CC_C_PAY' ))
5425 and exists ( select 'Y'
5426 from po_distributions_all po
5427 ,ap_invoice_distributions_all ap
5428 where po.po_distribution_id = ap.po_distribution_id
5429 and ap.invoice_id = a.document_header_id
5430 and ap.distribution_line_number = a.document_distribution_id
5431 and po.req_header_reference_num = b.document_header_id
5432 and po.req_line_reference_num = b.document_distribution_id
5433 and a.packet_id = b.packet_id
5434 and a.bc_packet_id = p_bc_pkt_id
5435 and b.packet_id = p_packet_id
5436 union /*Bug 13602288: Self Assessed Tax Changes*/
5437 select 'Y'
5438 from po_distributions_all po
5439 ,ap_self_assessed_tax_dist_all ap
5440 where po.po_distribution_id = ap.po_distribution_id
5441 and ap.invoice_id = a.document_header_id
5442 and ap.distribution_line_number = a.document_distribution_id
5443 and po.req_header_reference_num = b.document_header_id
5444 and po.req_line_reference_num = b.document_distribution_id
5445 and a.packet_id = b.packet_id
5446 and a.bc_packet_id = p_bc_pkt_id
5447 and b.packet_id = p_packet_id
5448 )
5449 )
5450 OR (( a.document_type = 'EXP' and b.document_type = 'AP' )
5451 and (abs(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0)) =
5452 abs(nvl(b.accounted_dr,0) - nvl(b.accounted_cr,0)))
5453 and exists (select 'Y'
5454 from ap_invoice_distributions_all ap
5455 ,pa_bc_packets pbc
5456 where ap.invoice_id = b.document_header_id
5457 and ap.distribution_line_number = b.document_distribution_id
5458 /** and pbc.packet_id = 4003 commented out NOCOPY the hardcoded **/
5459 and pbc.packet_id = p_packet_id
5460 and pbc.document_distribution_id = a.document_distribution_id
5461 and pbc.document_header_id = a.document_header_id
5462 and pbc.document_type = 'EXP'
5463 and pbc.result_code like 'P%'
5464 and a.packet_id = b.packet_id
5465 and a.bc_packet_id = p_bc_pkt_id
5466 and b.packet_id = p_packet_id
5467 union /*Bug 13602288: Self Assessed Tax Changes*/
5468 select 'Y'
5469 from ap_self_assessed_tax_dist_all ap
5470 ,pa_bc_packets pbc
5471 where ap.invoice_id = b.document_header_id
5472 and ap.distribution_line_number = b.document_distribution_id
5473 and pbc.packet_id = p_packet_id
5474 and pbc.document_distribution_id = a.document_distribution_id
5475 and pbc.document_header_id = a.document_header_id
5476 and pbc.document_type = 'EXP'
5477 and pbc.result_code like 'P%'
5478 and a.packet_id = b.packet_id
5479 and a.bc_packet_id = p_bc_pkt_id
5480 and b.packet_id = p_packet_id
5481 )
5482 )
5483 );
5484
5485
5486 CURSOR selEncDetails IS
5487 SELECT pkts.bc_packet_id,
5488 pkts.res_enc_approved,
5489 pkts.res_grp_enc_approved,
5490 pkts.task_enc_approved,
5491 pkts.top_task_enc_approved,
5492 pkts.project_enc_approved
5493 FROM pa_bc_packets pkts
5494 WHERE pkts.packet_id = p_packet_id
5495 AND nvl(pkts.accounted_dr,0) - nvl(pkts.accounted_cr,0) > 0
5496 AND substr(pkts.result_code ,1,1) = 'P';
5497
5498 l_num_rows Number := 200;
5499 l_r_enc_approved Number := Null;
5500 l_rg_enc_approved Number := Null;
5501 l_t_enc_approved Number := Null;
5502 l_tt_enc_approved Number := Null;
5503 l_p_enc_approved Number := Null;
5504
5505
5506 BEGIN
5507
5508 IF p_calling_module in ('GL','CBC') and p_mode in ('R','U','C') then
5509 IF g_debug_mode = 'Y' THEN
5510 log_message(p_msg_token1 => 'Inside update_enc_apprvoled_bal api');
5511 End If;
5512
5513 OPEN selEncDetails;
5514 IF g_debug_mode = 'Y' THEN
5515 log_message(p_msg_token1 => 'opened the selEncDetails cursor');
5516 End If;
5517 LOOP
5518
5519 init_plsql_tabs;
5520
5521 FETCH selEncDetails BULK COLLECT INTO
5522 g_tab_bc_packet_id,
5523 g_tab_r_enc_approved,
5524 g_tab_rg_enc_approved,
5525 g_tab_t_enc_approved,
5526 g_tab_tt_enc_approved,
5527 g_tab_p_enc_approved LIMIT l_num_rows;
5528
5529 IF NOT g_tab_bc_packet_id.EXISTS(1) then
5530 IF g_debug_mode = 'Y' THEN
5531 log_message(p_msg_token1 => 'Fetch rows is zero ');
5532 End if;
5533 EXIT;
5534 END IF;
5535
5536 FOR i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST LOOP
5537
5538 l_r_enc_approved := Null;
5539 l_rg_enc_approved := Null;
5540 l_t_enc_approved := Null;
5541 l_tt_enc_approved := Null;
5542 l_p_enc_approved := Null;
5543
5544 IF ( nvl(g_tab_r_enc_approved(i),0) <> 0 OR
5545 nvl(g_tab_rg_enc_approved(i),0) <> 0 OR
5546 nvl(g_tab_t_enc_approved(i),0) <> 0 OR
5547 nvl(g_tab_tt_enc_approved(i),0) <> 0 OR
5548 nvl(g_tab_p_enc_approved(i),0) <> 0 ) THEN
5549
5550 OPEN updEnc(g_tab_bc_packet_id(i)
5551 ,g_tab_r_enc_approved(i)
5552 ,g_tab_rg_enc_approved(i)
5553 ,g_tab_t_enc_approved(i)
5554 ,g_tab_tt_enc_approved(i)
5555 ,g_tab_p_enc_approved(i));
5556
5557 FETCH updEnc INTO l_r_enc_approved
5558 ,l_rg_enc_approved
5559 ,l_t_enc_approved
5560 ,l_tt_enc_approved
5561 ,l_p_enc_approved ;
5562
5563 CLOSE updEnc;
5564
5565 If nvl(l_r_enc_approved,0) <> 0 Then
5566 g_tab_r_enc_approved(i) := l_r_enc_approved;
5567 End If;
5568 If nvl(l_rg_enc_approved,0) <> 0 Then
5569 g_tab_rg_enc_approved(i) := l_rg_enc_approved;
5570 End If;
5571 If nvl(l_t_enc_approved,0) <> 0 Then
5572 g_tab_t_enc_approved(i) := l_t_enc_approved;
5573 End If;
5574 If nvl(l_tt_enc_approved,0) <> 0 Then
5575 g_tab_tt_enc_approved(i) := l_tt_enc_approved ;
5576 End If;
5577 If nvl(l_p_enc_approved,0) <> 0 Then
5578 g_tab_p_enc_approved(i) := l_p_enc_approved;
5579 End If;
5580
5581 END If;
5582
5583 END LOOP;
5584
5585 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
5586 UPDATE pa_bc_packets
5587 SET
5588 res_enc_approved = nvl(g_tab_r_enc_approved(i),res_enc_approved),
5589 res_grp_enc_approved = nvl(g_tab_rg_enc_approved(i),res_grp_enc_approved),
5590 task_enc_approved = nvl(g_tab_t_enc_approved(i),task_enc_approved),
5591 top_task_enc_approved = nvl(g_tab_tt_enc_approved(i),top_task_enc_approved),
5592 project_enc_approved = nvl(g_tab_p_enc_approved(i),project_enc_approved)
5593 WHERE packet_id = p_packet_id
5594 AND bc_packet_id = g_tab_bc_packet_id(i);
5595
5596 EXIT WHEN selEncDetails%NOTFOUND;
5597
5598 END LOOP;
5599 CLOSE selEncDetails;
5600
5601 END If;
5602 IF g_debug_mode = 'Y' THEN
5603 log_message(p_msg_token1 =>'End of update_enc_approved_bal api');
5604 End if;
5605
5606 COMMIT; -- to end an active autonomous transaction
5607
5608 EXCEPTION
5609
5610 when others then
5611 IF g_debug_mode = 'Y' THEN
5612 log_message(p_msg_token1 => 'Failed in update_enc_approval_bal api SQLERR:'||SQLCODE||SQLERRM);
5613 End if;
5614 Raise;
5615
5616 END update_enc_approvl_bal;
5617
5618 --------------------------------------------------------------------------------------------------------
5619 -- This api is called in partial mode, when funds check is called in partial mode
5620 -- funds check will be done on the basis of document_type and document_header_id for
5621 -- batch of 100 EI at a time this api is created to fix the bug :
5622 --------------------------------------------------------------------------------------------------------
5623 FUNCTION pa_fcp_process
5624 (p_sob IN NUMBER
5625 ,p_packet_id IN pa_bc_packets.packet_id%type
5626 ,p_mode IN varchar2
5627 ,p_partial_flag IN varchar2
5628 ,p_arrival_seq IN NUMBER
5629 ,p_reference1 IN varchar2
5630 ,p_reference2 IN varchar2
5631 ,p_calling_module IN varchar2
5632 ) return boolean IS
5633
5634 -- funds check will be done based on document_type and
5635 -- document_header_id. hence a batch of 100 EIS will be processed
5636 -- once.( if burden on diff item leades to 300 eis approximatly).
5637 l_tab_doc_type pa_plsql_datatypes.char50tabtyp;
5638 l_tab_effect_fc_level pa_plsql_datatypes.char50tabtyp;
5639 l_tab_doc_header_id pa_plsql_datatypes.idtabtyp;
5640 l_tab_bc_packet_id pa_plsql_datatypes.idtabtyp;
5641 l_num_rows NUMBER := 200;
5642 cursor cur_docs is
5643 SELECT document_type,
5644 document_header_id
5645 FROM pa_bc_packets
5646 WHERE packet_id = p_packet_id
5647 AND status_code = 'P'
5648 AND NVL(substr(result_code,1,1),'P') <> 'F'
5649 ORDER BY document_type,
5650 document_header_id;
5651
5652 -- this cursor picks all the transactions which are marked to
5653 -- intermediate status
5654 cursor cur_reset_doc_sts is
5655 SELECT bc_packet_id
5656 FROM pa_bc_packets
5657 WHERE packet_id = p_packet_id
5658 AND status_code = 'Z';
5659
5660 -- cursor to pick all the transaction which doesnot require funds check
5661 -- ie fc results in increase
5662 cursor cur_get_fc_incr_trxn is
5663 SELECT bc_packet_id,
5664 effect_on_funds_code
5665 FROM pa_bc_packets
5666 WHERE packet_id = p_packet_id
5667 AND status_code = 'P'
5668 AND nvl(substr(result_code,1,1),'P') <> 'F'
5669 AND effect_on_funds_code = 'I';
5670
5671 PROCEDURE update_docs_status
5672 (p_packet_id in number
5673 ,p_status_code in varchar2 ) IS
5674 PRAGMA AUTONOMOUS_TRANSACTION;
5675 BEGIN
5676
5677
5678 IF g_debug_mode = 'Y' THEN
5679 log_message(p_msg_token1 => 'Inside update_docs_status');
5680 log_message(p_msg_token1 => 'p_status_code= '||p_status_code);
5681 End if;
5682 IF p_status_code = 'Z' then
5683
5684 FORALL i IN l_tab_doc_header_id.FIRST .. l_tab_doc_header_id.LAST
5685 /* 4141729 - Added INDEX hint */
5686 UPDATE /*+ INDEX (pbp PA_BC_PACKETS_U1) */ pa_bc_packets
5687 SET status_code = p_status_code
5688 WHERE packet_id = p_packet_id
5689 AND document_type = l_tab_doc_type(i)
5690 AND document_header_id = l_tab_doc_header_id(i)
5691 AND status_code = 'P'
5692 AND nvl(substr(result_code,1,1),'P') <> 'F';
5693
5694 Elsif p_status_code = 'P' then
5695
5696 -- Reset the status code after processing
5697 FORALL i IN l_tab_bc_packet_id.FIRST .. l_tab_bc_packet_id.LAST
5698 UPDATE pa_bc_packets
5699 SET status_code = p_status_code
5700 WHERE packet_id = p_packet_id
5701 AND bc_packet_id = l_tab_bc_packet_id(i);
5702 Elsif p_status_code = 'I' then
5703 -- update the result codes to pass as the funds check result in
5704 -- increase in amounts
5705 FORALL i IN l_tab_bc_packet_id.FIRST .. l_tab_bc_packet_id.LAST
5706 UPDATE pa_bc_packets
5707 SET status_code = 'Z',
5708 result_code = 'P113',
5709 res_result_code = 'P113',
5710 res_grp_result_code = 'P113',
5711 task_result_code = 'P113',
5712 top_task_result_code = 'P113',
5713 project_result_code = 'P113',
5714 Project_acct_result_code = 'P113'
5715 WHERE packet_id = p_packet_id
5716 AND bc_packet_id = l_tab_bc_packet_id(i);
5717
5718 END IF;
5719
5720 commit;
5721 return;
5722 EXCEPTION
5723 when others then
5724 raise;
5725 END update_docs_status;
5726
5727
5728 BEGIN
5729 IF g_debug_mode = 'Y' THEN
5730 log_message(p_msg_token1 => 'Inside pa_fcp_process');
5731 log_message(p_msg_token1 => 'partial flag = '||p_partial_flag);
5732 End if;
5733
5734 Initialize_globals;
5735 init_plsql_tabs;
5736 IF p_partial_flag = 'Y' then
5737 OPEN cur_docs;
5738 LOOP
5739 l_tab_doc_type.delete;
5740 l_tab_doc_header_id.delete;
5741 FETCH cur_docs BULK COLLECT INTO
5742 l_tab_doc_type,
5743 l_tab_doc_header_id LIMIT 100;
5744 IF NOT l_tab_doc_header_id.EXISTS(1) then
5745 IF g_debug_mode = 'Y' THEN
5746 log_message(p_msg_token1 => 'no recs found');
5747 End if;
5748 EXIT;
5749 END IF;
5750 IF g_debug_mode = 'Y' THEN
5751 log_message(p_msg_token1 => 'calling update_docs_status api');
5752 End if;
5753 -- update the status_code to intermediate state
5754 update_docs_status(p_packet_id, 'Z');
5755 IF g_debug_mode = 'Y' THEN
5756 log_message(p_msg_token1 => 'count of tab header id ='||l_tab_doc_header_id.count);
5757 End if;
5758
5759 /* Moved this here for bug 6378539*/
5760 exit when cur_docs%notfound;
5761 END LOOP;
5762 CLOSE cur_docs;
5763 /* End Bug 6378539 */
5764
5765 -- Call funds check pa_fck_process for batch of 100 eis
5766 IF g_debug_mode = 'Y' THEN
5767 log_message(p_msg_token1 => 'pa fck process in partial flag modepartial flag['||p_partial_flag);
5768 End if;
5769 IF NOT pa_fck_process
5770 (p_sob => p_sob
5771 ,p_packet_id => p_packet_id
5772 ,p_mode => p_mode
5773 ,p_partial_flag => p_partial_flag
5774 ,p_arrival_seq => p_arrival_seq
5775 ,p_reference1 => p_reference1
5776 ,p_reference2 => p_reference2
5777 --,p_reference3 => p_reference3
5778 ,p_calling_module => p_calling_module
5779 ) then
5780 IF g_debug_mode = 'Y' THEN
5781 log_message(p_msg_token1 =>
5782 'funds check failed during pa_fck_process api');
5783 End if;
5784 g_return_status := 'T';
5785 --log_message(p_return_status => 'T');
5786 END IF;
5787
5788 /* Commented this code for the bug 6378539
5789 exit when cur_docs%notfound;
5790
5791 END LOOP;
5792 CLOSE cur_docs;
5793 */
5794 Elsif p_partial_flag <> 'Y' then -- full mode
5795
5796 -- update the result codes of the all the transactions which
5797 -- donot require funds check
5798 OPEN cur_get_fc_incr_trxn;
5799 LOOP
5800 l_tab_bc_packet_id.delete;
5801 l_tab_effect_fc_level.delete;
5802 FETCH cur_get_fc_incr_trxn BULK COLLECT INTO
5803 l_tab_bc_packet_id,
5804 l_tab_effect_fc_level LIMIT l_num_rows;
5805
5806 IF not l_tab_bc_packet_id.EXISTS(1) then
5807 EXIT;
5808 END IF;
5809 -- update the result codes to pass
5810 IF g_debug_mode = 'Y' THEN
5811 log_message(p_msg_token1 => 'calling update_docs_status for Increase funds trxn');
5812 End if;
5813 update_docs_status(p_packet_id, 'I');
5814
5815 exit when cur_get_fc_incr_trxn%notfound;
5816
5817 END LOOP;
5818 CLOSE cur_get_fc_incr_trxn;
5819
5820 IF g_debug_mode = 'Y' THEN
5821 log_message(p_msg_token1 => 'calling pa fck process in full modepartial flag['||p_partial_flag);
5822 End if;
5823 -- Call funds check pa_fck_process for batch of 100 eis
5824 IF NOT pa_fck_process
5825 (p_sob => p_sob
5826 ,p_packet_id => p_packet_id
5827 ,p_mode => p_mode
5828 ,p_partial_flag => p_partial_flag
5829 ,p_arrival_seq => p_arrival_seq
5830 ,p_reference1 => p_reference1
5831 ,p_reference2 => p_reference2
5832 --,p_reference3 => p_reference3
5833 ,p_calling_module => p_calling_module
5834 ) then
5835 g_return_status := 'T';
5836 --log_message(p_return_status => 'T');
5837 END IF;
5838
5839 END IF;
5840 -- reset the status code back to earlier stage
5841 OPEN cur_reset_doc_sts;
5842 LOOP
5843 FETCH cur_reset_doc_sts BULK COLLECT INTO
5844 l_tab_bc_packet_id LIMIT 200;
5845
5846 IF not l_tab_bc_packet_id.EXISTS(1) then
5847 EXIT;
5848 END IF;
5849 IF g_debug_mode = 'Y' THEN
5850 log_message(p_msg_token1 => 'calling update_docs_status api to reset the status ');
5851 End if;
5852 -- update the status_code to intermediate state
5853 update_docs_status(p_packet_id, 'P');
5854
5855 EXIT when cur_reset_doc_sts%notfound;
5856 END LOOP;
5857 IF g_debug_mode = 'Y' THEN
5858 log_message(p_msg_token1 => 'end of cur_reset_doc_sts cursor');
5859 End if;
5860 CLOSE cur_reset_doc_sts;
5861
5862 IF cur_docs%isopen then
5863 close cur_docs;
5864 End if;
5865 IF cur_reset_doc_sts%isopen then
5866 close cur_reset_doc_sts;
5867 End if;
5868
5869 IF cur_get_fc_incr_trxn%isopen then
5870 close cur_get_fc_incr_trxn;
5871 End if;
5872
5873 /** Bug fix : 2021199 Transaction funds check form is not showing the
5874 * correct available balance when requision becomes Purchase order
5875 */
5876 /* bug fix : 2658952 moved this logic to form to derive encumbrance pending amount
5877 update_enc_approvl_bal(p_packet_id => p_packet_id
5878 ,p_calling_module => p_calling_module
5879 ,p_mode => p_mode);
5880 **/
5881 Return true;
5882
5883 EXCEPTION
5884
5885 when OTHERS then
5886 -- if there is any error then update the transaction
5887 -- back to earlier status from intermediate status
5888 -- reset the status code back to earlier stage
5889 OPEN cur_reset_doc_sts;
5890 LOOP
5891 FETCH cur_reset_doc_sts BULK COLLECT INTO
5892 l_tab_bc_packet_id LIMIT 200;
5893
5894 IF not l_tab_bc_packet_id.EXISTS(1) then
5895 EXIT;
5896 END IF;
5897 IF g_debug_mode = 'Y' THEN
5898 log_message(p_msg_token1 => 'calling update_docs_status api to reset the status ');
5899 End if;
5900 -- update the status_code to intermediate state
5901 update_docs_status(p_packet_id, 'P');
5902
5903 EXIT when cur_reset_doc_sts%notfound;
5904 END LOOP;
5905 IF g_debug_mode = 'Y' THEN
5906 log_message(p_msg_token1 => 'end of cur_reset_doc_sts cursor');
5907 End if;
5908 CLOSE cur_reset_doc_sts;
5909
5910 if cur_docs%isopen then
5911 close cur_docs;
5912 ENd if;
5913 IF cur_reset_doc_sts%isopen then
5914 close cur_reset_doc_sts;
5915 End if;
5916 IF cur_get_fc_incr_trxn%isopen then
5917 close cur_get_fc_incr_trxn;
5918 End if;
5919 IF g_debug_mode = 'Y' THEN
5920 log_message(p_msg_token1 => 'Failed in pa_fcp_process');
5921 End if;
5922 Raise;
5923 END pa_fcp_process;
5924 --------------------------------------------------------------------------------------------------------------
5925 -- This is an wrapper api for main funds check process where it make calls to CHECK_FUNDS_AVAILABLE api
5926 -- in a loop and updates the pa bc packets in batch of 200 records
5927 -------------------------------------------------------------------------------------------------------------
5928 FUNCTION pa_fck_process
5929 (p_sob IN NUMBER
5930 ,p_packet_id IN pa_bc_packets.packet_id%type
5931 ,p_mode IN varchar2
5932 ,p_partial_flag IN varchar2
5933 ,p_arrival_seq IN NUMBER
5934 ,p_reference1 IN varchar2
5935 ,p_reference2 IN varchar2
5936 --,p_reference3 IN varchar2
5937 ,p_calling_module IN varchar2
5938 ) return BOOLEAN is
5939
5940 -- this cursor picks all the details for a particular transaction whcih requires
5941 -- funds check
5942 CURSOR trxn_details IS
5943 SELECT pbc.rowid,
5944 pbc.bc_packet_id,
5945 pbv.budget_version_id ,
5946 pbc.project_id ,
5947 pbc.task_id ,
5948 pbc.document_type,
5949 pbc.document_header_id ,
5950 pbc.document_distribution_id,
5951 pbc.expenditure_item_date ,
5952 pbc.expenditure_organization_id ,
5953 pbc.actual_flag ,
5954 pbc.period_name ,
5955 pm.time_phased_type_code,
5956 pb.amount_type ,
5957 pb.boundary_code ,
5958 pm.entry_level_code,
5959 pm.categorization_code ,
5960 pbc.resource_list_member_id ,
5961 NVL(pbc.parent_resource_id,0) , /* Added for Bug fix: 2658952 */
5962 pbv.resource_list_id ,
5963 NVL(rlm.parent_member_id,0) , /* Added for Bug fix: 2658952 */
5964 pbc.bud_task_id ,
5965 pbc.bud_resource_list_member_id ,
5966 pbc.top_task_id ,
5967 pbc.r_funds_control_level_code ,
5968 pbc.rg_funds_control_level_code ,
5969 pbc.t_funds_control_level_code ,
5970 pbc.tt_funds_control_level_code ,
5971 pbc.p_funds_control_level_code ,
5972 pm.burdened_cost_flag ,
5973 nvl(pbc.accounted_dr,0) accounted_dr,
5974 nvl(pbc.accounted_cr,0) accounted_cr,
5975 nvl(pbc.accounted_dr ,0) - nvl(pbc.accounted_cr,0) pkt_trx_amt,
5976 decode(pbc.status_code||actual_flag,'PE',
5977 nvl(pbc.accounted_dr ,0)-nvl(pbc.accounted_cr,0)*1,0) PE_amt,
5978 decode(pbc.status_code||actual_flag,'PA',
5979 nvl(pbc.accounted_dr ,0)-nvl(pbc.accounted_cr,0)*1,0) PA_amt,
5980 pbc.status_code,
5981 pbc.effect_on_funds_code,
5982 pbc.result_code ,
5983 pbc.res_result_code ,
5984 pbc.res_grp_result_code ,
5985 pbc.task_result_code ,
5986 pbc.top_task_result_code ,
5987 pbc.project_result_code ,
5988 pbc.res_budget_posted,
5989 pbc.res_grp_budget_posted,
5990 pbc.task_budget_posted,
5991 pbc.top_task_budget_posted,
5992 pbc.project_budget_posted,
5993 pbc.res_actual_posted,
5994 pbc.res_grp_actual_posted,
5995 pbc.task_actual_posted,
5996 pbc.top_task_actual_posted,
5997 pbc.project_actual_posted,
5998 pbc.res_enc_posted,
5999 pbc.res_grp_enc_posted,
6000 pbc.task_enc_posted,
6001 pbc.top_task_enc_posted,
6002 pbc.project_enc_posted,
6003 pbc.res_budget_bal,
6004 pbc.res_grp_budget_bal,
6005 pbc.task_budget_bal,
6006 pbc.top_task_budget_bal,
6007 pbc.project_budget_bal,
6008 pbc.res_actual_approved,
6009 pbc.res_grp_actual_approved,
6010 pbc.task_actual_approved,
6011 pbc.top_task_actual_approved,
6012 pbc.project_actual_approved,
6013 pbc.res_enc_approved,
6014 pbc.res_grp_enc_approved,
6015 pbc.task_enc_approved,
6016 pbc.top_task_enc_approved,
6017 pbc.project_enc_approved ,
6018 pbc.effect_on_funds_code,
6019 pbc.txn_ccid,
6020 pbc.budget_ccid,
6021 pbc.gl_date,
6022 pbc.pa_date,
6023 pbc.parent_bc_packet_id,
6024 /** added for bug fix : 1992734 **/
6025 pbc.fc_start_date, /* PAM changes */
6026 pbc.fc_end_date,
6027 nvl(list.GROUP_RESOURCE_TYPE_ID,0) GROUP_RESOURCE_TYPE_ID, /* added for bug fix2658952 */
6028 pbc.ext_bdgt_flag
6029 FROM
6030 pa_bc_packets pbc,
6031 pa_budget_versions pbv,
6032 pa_budget_entry_methods pm,
6033 pa_budgetary_control_options pb,
6034 pa_projects_all pp,
6035 pa_resource_list_members rlm,
6036 PA_RESOURCE_LISTS_ALL_BG list
6037 WHERE pbc.packet_id = p_packet_id
6038 AND pbc.budget_version_id = pbv.budget_version_id
6039 AND pbv.budget_entry_method_code = pm.budget_entry_method_code
6040 AND pbc.resource_list_member_id = rlm.resource_list_member_id
6041 AND pp.project_id = pbc.project_id
6042 AND pbc.project_id = pb.project_id
6043 AND nvl(substr(pbc.result_code,1,1),'P') NOT IN ( 'F','R')
6044 AND ( (pbc.status_code = 'P'
6045 and p_partial_flag <> 'Y'
6046 )
6047 OR
6048 (pbc.status_code = 'Z'
6049 and (pbc.funds_process_mode = 'B' or p_partial_flag = 'Y')) /* 15894144 Changed the condition pbc.effect_on_funds_code to
6050 funds_process_mode */
6051 /*Bug 13707987: During budget base line p_partial_flag will N and all the records having effect_on_funds_code = I
6052 will be marked Z hence to pick these records added or condition for pbc.effect_on_funds_code*/
6053 )
6054 AND pb.BDGT_CNTRL_FLAG = 'Y'
6055 AND pb.BUDGET_TYPE_CODE = pbv.budget_type_code
6056 AND ((pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
6057 and pb.EXTERNAL_BUDGET_CODE = 'GL')
6058 OR
6059 (pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
6060 and pb.EXTERNAL_BUDGET_CODE is NULL)
6061 OR
6062 (pbc.document_type in ('CC_P_CO','CC_C_CO')
6063 and pb.EXTERNAL_BUDGET_CODE = 'CC' )
6064 )
6065 /* added for bug fix 2658952 */
6066 AND list.RESOURCE_LIST_ID = rlm.RESOURCE_LIST_ID
6067 ORDER BY
6068 pbc.project_id,
6069 pbc.budget_version_id,
6070 pbc.fc_start_date , /** added for bug fix : 1992734 **/
6071 pbc.fc_end_date , /* bug 8635962 */
6072 --decode(p_partial_flag,'Y',pbc.effect_on_funds_code,0) desc, commented for 13707987
6073 decode(p_calling_module,'DISTERADJ',pbc.document_header_id,0),
6074 pbc.task_id,
6075 pbc.bud_task_id,
6076 NVL(pbc.parent_resource_id,0) , /* Added for Bug fix: 2658952 */
6077 pbc.resource_list_member_id,
6078 pbc.effect_on_funds_code desc, --added for Bug 13707987
6079 pbc.bud_resource_list_member_id,
6080 nvl(pbc.accounted_dr,0) - nvl(pbc.accounted_cr,0)
6081 ;
6082 l_previous_bdgt_version_id NUMBER;
6083 l_num_rows NUMBER := 200;
6084 l_status_code VARCHAR2(1) := 'P';
6085 l_return_status VARCHAR2(1) := 'S';
6086 l_prv_project_id NUMBER := null;
6087 l_ext_bdgt_type VARCHAR2(10);
6088 l_ext_bdgt_link VARCHAR2(1);
6089 l_prv_ext_bdgt_type VARCHAR2(10) := null;
6090 l_fc_record pa_fc_record;
6091 l_start_date DATE;
6092 l_end_date DATE;
6093 l_result_code VARCHAR2(20);
6094 l_error_stage VARCHAR2(20);
6095 l_error_msg VARCHAR2(2000);
6096 l_error_code number;
6097 l_date_for_calc Date;
6098
6099 l_prv_time_phase VARCHAR2(20):= null;
6100 l_prv_exp_item_date DATE := null;
6101 l_prv_amount_type VARCHAR2(20):= null;
6102 l_prv_boundary_code VARCHAR2(20):= null;
6103 l_prv_sob NUMBER := null;
6104 l_prv_bdgt_version_id NUMBER := null;
6105 l_prv_gl_date DATE := null;
6106 l_prv_pa_date DATE := null;
6107
6108 l_counter number := 0;
6109
6110 BEGIN
6111
6112 IF p_partial_flag = 'Y' then
6113 l_num_rows := 100000;
6114 Else
6115 l_num_rows := 200;
6116 ENd IF;
6117 IF g_debug_mode = 'Y' THEN
6118 log_message(p_msg_token1 => 'Inside the pa_fck_process');
6119 End if;
6120 OPEN trxn_details;
6121 IF g_debug_mode = 'Y' THEN
6122 log_message(p_msg_token1 => 'opened the trxn details cursor');
6123 End if;
6124 LOOP -- start of the batch process
6125 -- initialize the pl/sql tables fecth the values into tables
6126 init_plsql_tabs;
6127 FETCH trxn_details BULK COLLECT INTO
6128 g_tab_rowid,
6129 g_tab_bc_packet_id,
6130 g_tab_budget_version_id ,
6131 g_tab_project_id ,
6132 g_tab_task_id ,
6133 g_tab_doc_type,
6134 g_tab_doc_header_id ,
6135 g_tab_doc_distribution_id,
6136 g_tab_exp_item_date ,
6137 g_tab_exp_org_id ,
6138 g_tab_actual_flag ,
6139 g_tab_period_name ,
6140 g_tab_time_phase_type_code,
6141 g_tab_amount_type ,
6142 g_tab_boundary_code ,
6143 g_tab_entry_level_code,
6144 g_tab_category_code ,
6145 g_tab_rlmi ,
6146 g_tab_p_resource_id ,
6147 g_tab_r_list_id ,
6148 g_tab_p_member_id ,
6149 g_tab_bud_task_id ,
6150 g_tab_bud_rlmi ,
6151 g_tab_tt_task_id ,
6152 g_tab_r_fclevel_code ,
6153 g_tab_rg_fclevel_code ,
6154 g_tab_t_fclevel_code ,
6155 g_tab_tt_fclevel_code ,
6156 g_tab_p_fclevel_code ,
6157 g_tab_burd_cost_flag ,
6158 g_tab_accounted_dr,
6159 g_tab_accounted_cr,
6160 g_tab_pkt_trx_amt,
6161 g_tab_PE_amt,
6162 g_tab_PA_amt,
6163 g_tab_status_code,
6164 g_tab_effect_on_funds_code,
6165 g_tab_result_code ,
6166 g_tab_r_result_code ,
6167 g_tab_rg_result_code ,
6168 g_tab_t_result_code ,
6169 g_tab_tt_result_code ,
6170 g_tab_p_result_code ,
6171 g_tab_r_budget_posted,
6172 g_tab_rg_budget_posted,
6173 g_tab_t_budget_posted,
6174 g_tab_tt_budget_posted,
6175 g_tab_p_budget_posted,
6176 g_tab_r_actual_posted,
6177 g_tab_rg_actual_posted,
6178 g_tab_t_actual_posted,
6179 g_tab_tt_actual_posted,
6180 g_tab_p_actual_posted,
6181 g_tab_r_enc_posted,
6182 g_tab_rg_enc_posted,
6183 g_tab_t_enc_posted,
6184 g_tab_tt_enc_posted,
6185 g_tab_p_enc_posted,
6186 g_tab_r_budget_bal,
6187 g_tab_rg_budget_bal,
6188 g_tab_t_budget_bal,
6189 g_tab_tt_budget_bal,
6190 g_tab_p_budget_bal,
6191 g_tab_r_actual_approved,
6192 g_tab_rg_actual_approved,
6193 g_tab_t_actual_approved,
6194 g_tab_tt_actual_approved,
6195 g_tab_p_actual_approved,
6196 g_tab_r_enc_approved,
6197 g_tab_rg_enc_approved,
6198 g_tab_t_enc_approved,
6199 g_tab_tt_enc_approved,
6200 g_tab_p_enc_approved,
6201 g_tab_effect_fclevel,
6202 g_tab_trxn_ccid,
6203 g_tab_budget_ccid,
6204 g_tab_gl_date,
6205 g_tab_pa_date,
6206 g_tab_p_bc_packet_id,
6207 g_tab_start_date,
6208 g_tab_end_date,
6209 g_tab_group_resource_type_id,
6210 g_tab_ext_bdgt_link LIMIT l_num_rows;
6211 IF g_debug_mode = 'Y' THEN
6212 log_message(p_msg_token1 => 'after fectch num rows'||g_tab_doc_header_id.count);
6213 End if;
6214
6215 IF NOT g_tab_rowid.EXISTS(1) then
6216 IF g_debug_mode = 'Y' THEN
6217 log_message(p_msg_token1 => 'Fetch rows is zero ');
6218 END IF;
6219 EXIT;
6220 END IF;
6221
6222
6223
6224 -- For each record in table loop through derive start and end dates
6225 -- check the availability of funds
6226 l_counter := 0;
6227 FOR i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST LOOP
6228 l_counter := l_counter + 1;
6229 IF g_debug_mode = 'Y' THEN
6230 log_message(p_msg_token1 => 'Initizaling the record with in FOR loop');
6231 End if;
6232 -- Initialize the funds check record
6233 initialize_record(l_fc_record);
6234
6235 l_fc_record.packet_id := p_packet_id;
6236 l_fc_record.bc_packet_id := g_tab_bc_packet_id(i);
6237 l_fc_record.set_of_books_id := p_sob;
6238 l_fc_record.budget_version_id := g_tab_budget_version_id(i);
6239 l_fc_record.project_id := g_tab_project_id(i);
6240 l_fc_record.task_id := g_tab_task_id(i);
6241 l_fc_record.document_type := g_tab_doc_type(i);
6242 l_fc_record.document_header_id := g_tab_doc_header_id(i);
6243 l_fc_record.document_distribution_id := g_tab_doc_distribution_id(i);
6244 l_fc_record.expenditure_item_date := g_tab_exp_item_date(i);
6245 l_fc_record.expenditure_organization_id := g_tab_exp_org_id(i);
6246 l_fc_record.actual_flag := g_tab_actual_flag(i);
6247 l_fc_record.period_name := g_tab_period_name(i);
6248 l_fc_record.time_phased_type_code := g_tab_time_phase_type_code(i);
6249 l_fc_record.amount_type := g_tab_amount_type(i);
6250 l_fc_record.boundary_code := g_tab_boundary_code(i);
6251 l_fc_record.entry_level_code := g_tab_entry_level_code(i);
6252 l_fc_record.categorization_code := g_tab_category_code(i);
6253 l_fc_record.resource_list_member_id := g_tab_rlmi(i);
6254 l_fc_record.parent_resource_id := g_tab_p_resource_id(i);
6255 l_fc_record.resource_list_id := g_tab_r_list_id(i);
6256 l_fc_record.parent_member_id := g_tab_p_member_id(i);
6257 l_fc_record.bud_task_id := g_tab_bud_task_id(i);
6258 l_fc_record.bud_resource_list_member_id := g_tab_bud_rlmi(i);
6259 l_fc_record.top_task_id := g_tab_tt_task_id(i);
6260 l_fc_record.r_funds_control_level_code := g_tab_r_fclevel_code(i);
6261 l_fc_record.rg_funds_control_level_code := g_tab_rg_fclevel_code(i);
6262 l_fc_record.t_funds_control_level_code := g_tab_t_fclevel_code(i);
6263 l_fc_record.tt_funds_control_level_code := g_tab_tt_fclevel_code(i);
6264 l_fc_record.p_funds_control_level_code := g_tab_p_fclevel_code(i);
6265 l_fc_record.burdened_cost_flag := g_tab_burd_cost_flag(i);
6266 l_fc_record.accounted_dr := g_tab_accounted_dr(i);
6267 l_fc_record.accounted_cr := g_tab_accounted_cr(i);
6268 l_fc_record.status_code := l_status_code;
6269 l_fc_record.r_budget_posted := g_tab_r_budget_posted(i);
6270 l_fc_record.rg_budget_posted := g_tab_rg_budget_posted(i);
6271 l_fc_record.t_budget_posted := g_tab_t_budget_posted(i);
6272 l_fc_record.tt_budget_posted := g_tab_tt_budget_posted(i);
6273 l_fc_record.p_budget_posted := g_tab_p_budget_posted(i);
6274 l_fc_record.r_actual_posted := g_tab_r_actual_posted(i);
6275 l_fc_record.rg_actual_posted := g_tab_rg_actual_posted(i);
6276 l_fc_record.t_actual_posted := g_tab_t_actual_posted(i);
6277 l_fc_record.tt_actual_posted := g_tab_tt_actual_posted(i);
6278 l_fc_record.p_actual_posted := g_tab_p_actual_posted(i);
6279 l_fc_record.r_enc_posted := g_tab_r_enc_posted(i);
6280 l_fc_record.rg_enc_posted := g_tab_rg_enc_posted(i);
6281 l_fc_record.t_enc_posted := g_tab_t_enc_posted(i);
6282 l_fc_record.tt_enc_posted := g_tab_tt_enc_posted(i);
6283 l_fc_record.p_enc_posted := g_tab_p_enc_posted(i);
6284 l_fc_record.r_budget_bal := g_tab_r_budget_bal(i);
6285 l_fc_record.rg_budget_bal := g_tab_rg_budget_bal(i);
6286 l_fc_record.t_budget_bal := g_tab_t_budget_bal(i);
6287 l_fc_record.tt_budget_bal := g_tab_tt_budget_bal(i);
6288 l_fc_record.p_budget_bal := g_tab_p_budget_bal(i);
6289 l_fc_record.r_actual_approved := g_tab_r_actual_approved(i);
6290 l_fc_record.rg_actual_approved := g_tab_rg_actual_approved(i);
6291 l_fc_record.t_actual_approved := g_tab_t_actual_approved(i);
6292 l_fc_record.tt_actual_approved := g_tab_tt_actual_approved(i);
6293 l_fc_record.p_actual_approved := g_tab_p_actual_approved(i);
6294 l_fc_record.r_enc_approved := g_tab_r_enc_approved(i);
6295 l_fc_record.rg_enc_approved := g_tab_rg_enc_approved(i);
6296 l_fc_record.t_enc_approved := g_tab_t_enc_approved(i);
6297 l_fc_record.tt_enc_approved := g_tab_tt_enc_approved(i);
6298 l_fc_record.p_enc_approved := g_tab_p_enc_approved(i);
6299 l_fc_record.result_code := g_tab_result_code(i);
6300 l_fc_record.r_result_code := g_tab_r_result_code(i);
6301 l_fc_record.rg_result_code := g_tab_rg_result_code(i);
6302 l_fc_record.t_result_code := g_tab_t_result_code(i);
6303 l_fc_record.tt_result_code := g_tab_tt_result_code(i);
6304 l_fc_record.p_result_code := g_tab_p_result_code(i);
6305 l_fc_record.effect_on_funds_code := g_tab_effect_fclevel(i);
6306 l_fc_record.trxn_ccid := g_tab_trxn_ccid(i);
6307 l_fc_record.budget_ccid := g_tab_budget_ccid(i);
6308 l_fc_record.gl_date := g_tab_gl_date(i);
6309 l_fc_record.pa_date := g_tab_pa_date(i);
6310 l_fc_record.parent_bc_packet_id := g_tab_p_bc_packet_id(i);
6311 l_fc_record.group_resource_type_id := g_tab_group_resource_type_id(i);
6312 -- check whether the budget type is STD or CBC and budget is Linked with GL
6313 If l_fc_record.document_type in ('AP','PO','REQ','EXP','CC_C_PAY','CC_P_PAY' ) THEN
6314 l_ext_bdgt_type := 'STD';
6315 Else
6316 l_ext_bdgt_type := 'CBC';
6317 End if;
6318
6319 IF g_debug_mode = 'Y' THEN
6320 log_message(p_msg_token1 =>'start date['||g_tab_start_date(i)||']end date['||g_tab_end_date(i)||']');
6321 End if;
6322 l_start_date := g_tab_start_date(i);
6323 l_end_date := g_tab_end_date(i);
6324 l_ext_bdgt_link := g_tab_ext_bdgt_link(i);
6325
6326 If g_tab_start_date(i) is not null and g_tab_end_date(i) is not null then
6327
6328
6329 IF g_debug_mode = 'Y' THEN
6330 log_message(p_msg_token1 => 'Before calling check_funds_available');
6331 End if;
6332 check_funds_available (
6333 p_sob => p_sob,
6334 p_mode => p_mode,
6335 p_packet_id => p_packet_id,
6336 p_record => l_fc_record, -- IN OUT NOCOPY param
6337 p_arrival_seq => p_arrival_seq,
6338 p_status_code => l_status_code,
6339 p_ext_bdgt_link => l_ext_bdgt_link,
6340 p_ext_bdgt_type => l_ext_bdgt_type,
6341 p_start_date => l_start_date,
6342 p_end_date => l_end_date,
6343 p_calling_module => p_calling_module,
6344 p_partial_flag => p_partial_flag,
6345 p_counter => l_counter
6346 );
6347 If g_debug_mode = 'Y' Then
6348 log_message(p_msg_token1 => 'After check_funds_available api call');
6349 End if;
6350 Else -- assign the result code derived during the start date and end date
6351 -- proceed to next record for funds check
6352 /** commented for bug fix : 1992734 **/
6353 --l_fc_record.result_code := l_result_code;
6354 l_fc_record.result_code := 'F136';
6355
6356 End if;
6357
6358
6359
6360 --- Assign the OUT NOCOPY parameter values to pl / sql tables
6361 IF g_debug_mode = 'Y' THEN
6362 log_message(p_msg_token1 => 'Assiginig out NOCOPY params to global variables');
6363 End if;
6364 g_tab_r_budget_posted(i) := l_fc_record.r_budget_posted;
6365 g_tab_rg_budget_posted(i) := l_fc_record.rg_budget_posted;
6366 g_tab_t_budget_posted(i) := l_fc_record.t_budget_posted;
6367 g_tab_tt_budget_posted(i) := l_fc_record.tt_budget_posted;
6368 g_tab_p_budget_posted(i) := l_fc_record.p_budget_posted;
6369 g_tab_r_actual_posted(i) := l_fc_record.r_actual_posted;
6370 g_tab_rg_actual_posted(i) := l_fc_record.rg_actual_posted;
6371 g_tab_t_actual_posted(i) := l_fc_record.t_actual_posted;
6372 g_tab_tt_actual_posted(i) := l_fc_record.tt_actual_posted;
6373 g_tab_p_actual_posted(i) := l_fc_record.p_actual_posted;
6374 g_tab_r_enc_posted(i) := l_fc_record.r_enc_posted;
6375 g_tab_rg_enc_posted(i) := l_fc_record.rg_enc_posted;
6376 g_tab_t_enc_posted(i) := l_fc_record.t_enc_posted;
6377 g_tab_tt_enc_posted(i) := l_fc_record.tt_enc_posted;
6378 g_tab_p_enc_posted(i) := l_fc_record.p_enc_posted;
6379 g_tab_r_budget_bal(i) := l_fc_record.r_budget_bal;
6380 g_tab_rg_budget_bal(i):= l_fc_record.rg_budget_bal;
6381 g_tab_t_budget_bal(i) := l_fc_record.t_budget_bal;
6382 g_tab_tt_budget_bal(i) := l_fc_record.tt_budget_bal;
6383 g_tab_p_budget_bal(i) := l_fc_record.p_budget_bal;
6384 g_tab_r_actual_approved(i):= l_fc_record.r_actual_approved;
6385 g_tab_rg_actual_approved(i) := l_fc_record.rg_actual_approved;
6386 g_tab_t_actual_approved(i) := l_fc_record.t_actual_approved;
6387 g_tab_tt_actual_approved(i) := l_fc_record.tt_actual_approved;
6388 g_tab_p_actual_approved(i) := l_fc_record.p_actual_approved;
6389 g_tab_r_enc_approved(i) := l_fc_record.r_enc_approved;
6390 g_tab_rg_enc_approved(i) := l_fc_record.rg_enc_approved;
6391 g_tab_t_enc_approved(i) := l_fc_record.t_enc_approved;
6392 g_tab_tt_enc_approved(i) := l_fc_record.tt_enc_approved ;
6393 g_tab_p_enc_approved(i) := l_fc_record.p_enc_approved;
6394 g_tab_result_code(i) := l_fc_record.result_code;
6395 g_tab_r_result_code(i) := l_fc_record.r_result_code;
6396 g_tab_rg_result_code(i) := l_fc_record.rg_result_code;
6397 g_tab_t_result_code(i) := l_fc_record.t_result_code;
6398 g_tab_tt_result_code(i) := l_fc_record.tt_result_code;
6399 g_tab_p_result_code(i) := l_fc_record.p_result_code;
6400 g_tab_p_acct_result_code(i) := l_fc_record.p_acct_result_code;
6401 IF g_debug_mode = 'Y' THEN
6402 log_message(p_msg_token1 => 'end of assignments');
6403 End if;
6404
6405
6406 END LOOP;
6407
6408 -- update the bc_packets with result and status codes in batch
6409 IF g_debug_mode = 'Y' THEN
6410 log_message(p_msg_token1 => 'Calling update pkt amts autonomous transaction statement');
6411 End if;
6412 update_pkt_amts(p_packet_id);
6413 IF g_debug_mode = 'Y' THEN
6414 log_message(p_msg_token1 => 'after the autonomous call');
6415 End if;
6416 EXIT WHEN trxn_details%NOTFOUND;
6417 END LOOP; -- end of the batch process
6418 CLOSE trxn_details;
6419 IF g_debug_mode = 'Y' THEN
6420 log_message(p_msg_token1 => 'end of trxn_details cursor ');
6421 End if;
6422 RETURN true;
6423
6424 EXCEPTION
6425
6426 when others then
6427 IF g_debug_mode = 'Y' THEN
6428 log_message(p_msg_token1 => 'failed due to un expected error during funds check');
6429 End if;
6430 If trxn_details%ISOPEN then
6431 close trxn_details;
6432 End if;
6433 IF g_debug_mode = 'Y' THEN
6434 log_message(p_msg_token1 => 'failed in pa_fc_process api SQLERR :'||sqlcode||sqlerrm);
6435 End if;
6436 Raise;
6437
6438
6439 END pa_fck_process;
6440
6441 ---------------------------------------------------------------------------------------------------------------
6442 --This API inserts the packet id into the gl_bc_arrival_packet_order , derives the arrival sequence
6443 --and ensures the data consistency for funds check process
6444 ---------------------------------------------------------------------------------------------------------------
6445
6446 FUNCTION get_arrival_seq
6447 (p_calling_module IN VARCHAR2
6448 ,p_packet_id IN NUMBER
6449 ,p_sobid IN NUMBER
6450 ,p_mode IN VARCHAR2
6451 ) RETURN NUMBER IS
6452
6453 PRAGMA AUTONOMOUS_TRANSACTION;
6454
6455 v_arrival_seq NUMBER;
6456 l_number NUMBER;
6457
6458 BEGIN
6459 IF g_debug_mode = 'Y' THEN
6460 log_message(p_msg_token1 => 'Inside the get arrival seq api');
6461 End if;
6462
6463 ------- Acquire a lock before processing ----------------
6464 PA_DEBUG.Set_User_Lock_Mode
6465 ( x_Lock_Mode => 6
6466 ,x_Commit_Mode => FALSE
6467 ,x_TimeOut => 30);
6468
6469 l_number := pa_debug.acquire_user_lock('PAFUNDSCHECKLOCKER');
6470 IF g_debug_mode = 'Y' THEN
6471 log_message(p_msg_token1 => 'the value of lock handler = '||l_number);
6472 End if;
6473 If l_number = 0 then
6474
6475 IF g_debug_mode = 'Y' THEN
6476 log_message(p_msg_token1 => 'Acquired the lock for funds check');
6477 End if;
6478 INSERT INTO pa_bc_packet_arrival_order
6479 ( packet_id
6480 , set_of_books_id
6481 , arrival_seq
6482 , affect_funds_flag
6483 , last_update_date
6484 , last_updated_by
6485 )
6486 VALUES (
6487 p_packet_id
6488 ,p_sobid
6489 ,pa_bc_packet_arrival_order_s.nextval
6490 ,DECODE ( p_mode, 'B', 'N', 'Y' )
6491 --For budget submit and baselining(S and B) it does not affect the funds.
6492 --For Encumbrances (E) it afffects funds.
6493 ,SYSDATE
6494 ,fnd_global.user_id
6495 );
6496 IF g_debug_mode = 'Y' THEN
6497 log_message(p_msg_token1 => 'No of records inserted into pa_bc_packet_arrival_order ='||sql%rowcount);
6498 End if;
6499
6500 BEGIN
6501 SELECT arrival_seq
6502 INTO v_arrival_seq
6503 FROM pa_bc_packet_arrival_order ao
6504 WHERE ao.packet_id = p_packet_id;
6505
6506 EXCEPTION
6507 WHEN OTHERS THEN
6508 result_status_code_update(p_packet_id => p_packet_id,
6509 p_status_code => 'R',
6510 p_result_code => 'F141',
6511 p_res_result_code => 'F141',
6512 p_res_grp_result_code => 'F141',
6513 p_task_result_code => 'F141',
6514 p_project_result_code => 'F141',
6515 p_proj_acct_result_code => 'F141');
6516 v_arrival_seq := 0;
6517 IF g_debug_mode = 'Y' THEN
6518 log_message(p_msg_token1=>'Failed to acquire lock - Exception portion');
6519 End if;
6520 log_message(p_error_msg =>sqlcode||sqlerrm);
6521 END;
6522 ------------- Release the Lock --------------
6523 If (pa_debug.release_user_lock('PAFUNDSCHECKLOCKER') = 0) then
6524 IF g_debug_mode = 'Y' THEN
6525 log_message(p_msg_token1 => 'Released the Lock');
6526 End if;
6527 END If;
6528
6529 ELSE
6530 IF g_debug_mode = 'Y' THEN
6531 log_message(p_msg_token1 => 'Failed to Acquire lock ');
6532 End if;
6533 -- Error msg : 'F141 = Funds check failed to acquire lock';
6534 result_status_code_update(p_packet_id => p_packet_id,
6535 p_status_code => 'R',
6536 p_result_code => 'F141',
6537 p_res_result_code => 'F141',
6538 p_res_grp_result_code => 'F141',
6539 p_task_result_code => 'F141',
6540 p_project_result_code => 'F141',
6541 p_proj_acct_result_code => 'F141');
6542 commit;
6543 null;
6544 END IF;
6545
6546 commit;
6547 RETURN nvl(v_arrival_seq,0);
6548
6549 EXCEPTION
6550 when others then
6551 If (pa_debug.release_user_lock('PAFUNDSCHECKLOCKER') = 0) then
6552 IF g_debug_mode = 'Y' THEN
6553 log_message(p_msg_token1 => 'Released the Lock');
6554 End if;
6555 null;
6556 END If;
6557 result_status_code_update(p_packet_id => p_packet_id,
6558 p_status_code => 'T',
6559 p_result_code => 'F141',
6560 p_res_result_code => 'F141',
6561 p_res_grp_result_code => 'F141',
6562 p_task_result_code => 'F141',
6563 p_project_result_code => 'F141',
6564 p_proj_acct_result_code => 'F141');
6565 IF g_debug_mode = 'Y' THEN
6566 log_message(p_msg_token1 => 'failed in get arrival seq apiSQLERR :'||sqlcode||sqlerrm);
6567 End if;
6568 --commit;
6569 return 0;
6570 Raise;
6571 END get_arrival_seq;
6572
6573 ---------------------------------------------------------------------------------------
6574 -- api to calulate budgeted resource list id in packet for a budget version,
6575 -- entry level code and budget entry method and update pa_bc_packets for the
6576 -- set of records having the same combinations.The bud_res_list_id is required
6577 -- to get the resource group level balances from the pa_bc_balances
6578 ---------------------------------------------------------------------------------------
6579 FUNCTION bud_res_list_id_update
6580 ( p_project_id IN NUMBER,
6581 p_budget_version_id IN NUMBER,
6582 p_resource_list_member_id IN NUMBER,
6583 p_categorization_code IN VARCHAR2,
6584 x_bud_resource_list_member_id OUT NOCOPY NUMBER,
6585 x_parent_resource_id OUT NOCOPY NUMBER
6586 ) return BOOLEAN IS
6587
6588 ----------------------------------------------------------------------------
6589 -- find the correct resource list id for funds checking.
6590 -- if no budget at the resource level then check the budget at the parent
6591 ---level and get the resource list id from pa_bc_balances
6592 ---------------------------------------------------------------------------
6593 CURSOR cur_bud_res_list_id IS
6594 SELECT pr.resource_list_id,
6595 pr.parent_member_id
6596 FROM pa_resource_list_members pr
6597 WHERE pr.resource_list_member_id = p_resource_list_member_id;
6598
6599 --This cursor picks up the resource list member id at the resource level
6600 -- if the budget is defined at the resource level
6601 CURSOR cur_res_member(v_project_id NUMBER,
6602 v_bdgt_version_id NUMBER,
6603 v_res_list_mem_id NUMBER) IS
6604 SELECT resource_list_member_id
6605 FROM pa_bc_balances
6606 WHERE budget_version_id = v_bdgt_version_id
6607 AND project_id = v_project_id
6608 AND resource_list_member_id = v_res_list_mem_id
6609 AND balance_type = 'BGT';
6610
6611 --This cursor picks up the resource list member id at the parent resource level
6612 -- if the budget at the resource level is not defined and defined at the resource
6613 -- group level
6614 CURSOR cur_parent_res_member(v_project_id NUMBER,
6615 v_bdgt_version_id NUMBER,
6616 v_parent_res_list_mem_id NUMBER) IS
6617 SELECT resource_list_member_id
6618 FROM pa_bc_balances
6619 WHERE budget_version_id = v_bdgt_version_id
6620 ANd project_id = v_project_id
6621 AND resource_list_member_id = v_parent_res_list_mem_id
6622 AND balance_type = 'BGT';
6623
6624
6625 l_budget_version_id pa_bc_packets.budget_version_id%TYPE;
6626 l_project_id pa_bc_packets.project_id%TYPE;
6627 l_task_id pa_bc_packets.bud_task_id%TYPE;
6628 l_resource_list_member_id pa_bc_packets.resource_list_member_id%TYPE;
6629 l_resource_list_id pa_resource_list_members.resource_list_id%TYPE;
6630 l_parent_member_id pa_resource_list_members.parent_member_id%TYPE;
6631 l_level pa_resource_list_members.member_level%TYPE;
6632 l_categorization_code pa_budget_entry_methods.categorization_code%TYPE;
6633 l_bud_res_list_member_id pa_bc_packets.bud_resource_list_member_id%TYPE;
6634 l_parent_resource_id pa_resource_list_members.parent_member_id%TYPE;
6635 BEGIN
6636
6637 IF g_debug_mode = 'Y' THEN
6638 log_message(p_msg_token1 => 'Inside bud_res_list_id_update api');
6639 End if;
6640
6641 OPEN cur_bud_res_list_id;
6642 LOOP
6643 FETCH cur_bud_res_list_id
6644 INTO l_resource_list_id,
6645 l_parent_member_id;
6646 EXIT WHEN cur_bud_res_list_id%NOTFOUND;
6647
6648 IF g_debug_mode = 'Y' THEN
6649 log_message(p_msg_token1 => 'p_categorization_code= '||p_categorization_code);
6650 End if;
6651
6652 IF p_categorization_code = 'R' THEN
6653 -- find the correct resource list id for funds checking.
6654 OPEN cur_res_member(p_project_id,
6655 p_budget_version_id,
6656 p_resource_list_member_id);
6657 FETCH cur_res_member INTO l_bud_res_list_member_id;
6658 -- if the resource is not found then check at the parent level
6659 IF cur_res_member%notfound THEN
6660 OPEN cur_parent_res_member
6661 (p_project_id,
6662 p_budget_version_id,
6663 l_parent_member_id);
6664 FETCH cur_parent_res_member INTO l_bud_res_list_member_id;
6665 IF cur_parent_res_member%notfound THEN
6666 l_bud_res_list_member_id := l_resource_list_member_id;
6667 END IF;
6668 CLOSE cur_parent_res_member;
6669 END IF;
6670 CLOSE cur_res_member;
6671
6672 ELSE -- Not categorized by resource
6673
6674 BEGIN
6675
6676 SELECT pb.resource_list_member_id
6677 INTO l_bud_res_list_member_id
6678 FROM pa_bc_balances pb
6679 WHERE pb.budget_version_id = p_budget_version_id
6680 AND pb.project_id = p_project_id
6681 AND balance_type = 'BGT'
6682 AND ROWNUM = 1;
6683
6684 EXCEPTION
6685 when no_data_found then
6686 null;
6687 END;
6688 END IF;
6689
6690 x_bud_resource_list_member_id := l_bud_res_list_member_id;
6691 x_parent_resource_id := l_parent_member_id;
6692 IF g_debug_mode = 'Y' THEN
6693 log_message(p_msg_token1 => 'x_bud_resource_list_member_id= '||x_bud_resource_list_member_id);
6694 log_message(p_msg_token1 => 'x_parent_resource_id= '||x_parent_resource_id);
6695 End if;
6696 END LOOP;
6697 CLOSE cur_bud_res_list_id;
6698
6699 RETURN true;
6700
6701 EXCEPTION
6702 WHEN OTHERS THEN
6703
6704 if cur_bud_res_list_id%ISOPEN then
6705 close cur_bud_res_list_id;
6706 end if;
6707
6708 If cur_parent_res_member%ISOPEN then
6709 close cur_parent_res_member;
6710 End if;
6711
6712 If cur_res_member%ISOPEN then
6713 close cur_res_member;
6714 End if;
6715 IF g_debug_mode = 'Y' THEN
6716 log_message(p_msg_token1 => 'failed in bud res list id api SQLERR :'||sqlcode||sqlerrm);
6717 End if;
6718 RAISE;
6719
6720 END bud_res_list_id_update;
6721 --------------------------------------------------------------------------------------------
6722 ---Procedure to calulate budgeted task id in packet for a budget version, entry level code
6723 --- and budget entry method and update pa_bc_packets for the same set of records having
6724 --- the same combinations. Update the pa bc pakcets based on the budget entry methods
6725 --- L -- Enter budget at low task
6726 --- M -- Enter budget at Top task or Low task
6727 --- P -- Enter budget at Project level
6728 --- T -- Enter budget at Top task level
6729 -----------------------------------------------------------------------------------------------------
6730 FUNCTION budget_task_id_update
6731 ( p_project_id IN NUMBER,
6732 p_task_id IN NUMBER,
6733 p_budget_version_id IN NUMBER,
6734 p_entry_level_code IN VARCHAR2,
6735 x_bud_task_id OUT NOCOPY NUMBER,
6736 x_top_task_id OUT NOCOPY NUMBER
6737 ) RETURN BOOLEAN IS
6738
6739 -- This cursor picks the LOW_TASK_ID from pa_balances
6740 CURSOR cur_low_task_id( l_project_id NUMBER,
6741 l_task_id NUMBER,
6742 l_bdgt_version_id NUMBER) IS
6743 SELECT task_id
6744 FROM pa_bc_balances
6745 WHERE budget_version_id = l_bdgt_version_id
6746 AND project_id = l_project_id
6747 AND task_id = l_task_id
6748 AND balance_type = 'BGT';
6749
6750 --This cursor picks the TOP_TASK_ID from pa_balances
6751 CURSOR cur_top_task_id( l_project_id NUMBER,
6752 l_task_id NUMBER,
6753 l_bdgt_version_id NUMBER) IS
6754 SELECT task_id
6755 FROM pa_bc_balances
6756 WHERE budget_version_id = l_bdgt_version_id
6757 AND project_id = l_project_id
6758 AND balance_type = 'BGT'
6759 AND task_id = (SELECT top_task_id
6760 FROM pa_tasks
6761 WHERE task_id = l_task_id
6762 );
6763
6764
6765 l_bud_task_id pa_bc_packets.bud_task_id%TYPE;
6766 l_top_task_id pa_bc_packets.bud_task_id%TYPE;
6767
6768
6769 BEGIN
6770
6771 ------------------------------------------------------------------------------------
6772 -- if the budget entry level in 'L','T','P' -- update directly.
6773 -------------------------------------------------------------------------------------------
6774 IF g_debug_mode = 'Y' THEN
6775 log_message(p_msg_token1 => 'Inside budget_task_id_update api');
6776 log_message(p_msg_token1 => 'p_entry_level_code= '||p_entry_level_code);
6777 End if;
6778 SELECT top_task_id
6779 INTO l_top_task_id
6780 FROM pa_tasks
6781 WHERE task_id = p_task_id;
6782
6783 If p_entry_level_code in ('P', 'L', 'T' ) then
6784 If p_entry_level_code = 'P' then
6785 x_bud_task_id := 0;
6786 x_top_task_id := 0;
6787 Elsif p_entry_level_code = 'L' then
6788 x_bud_task_id := p_task_id ;
6789 x_top_task_id := l_top_task_id;
6790 Elsif p_entry_level_code = 'T' then
6791 x_bud_task_id := l_top_task_id;
6792 x_top_task_id := l_top_task_id;
6793 End if;
6794
6795 Elsif p_entry_level_code = 'M' then
6796
6797 ---------------------------------------------------------------------------------
6798 -- if the budget entry level = 'M' update by record.first select the budget task id
6799 -- (LOW TASK)based on the project,task,budget version from pa_bc_balances if not found then
6800 -- select the budget task id(TOP TASK) based on the project,task,budget version from
6801 -- pa_bc_balacnes for the toptask in pa_tasks
6802 -------------------------------------------------------------------------------------
6803 OPEN cur_low_task_id( p_project_id,
6804 p_task_id,
6805 p_budget_version_id);
6806
6807 FETCH cur_low_task_id INTO x_bud_task_id;
6808 IF cur_low_task_id%NOTFOUND THEN
6809
6810 OPEN cur_top_task_id( p_project_id,
6811 p_task_id,
6812 p_budget_version_id);
6813 FETCH cur_top_task_id INTO x_bud_task_id;
6814 IF cur_top_task_id%NOTFOUND THEN
6815 x_bud_task_id := p_task_id;
6816 END IF;
6817 CLOSE cur_top_task_id;
6818
6819
6820 END IF;
6821 CLOSE cur_low_task_id;
6822 x_top_task_id := l_top_task_id;
6823
6824 End IF;
6825
6826
6827 RETURN TRUE;
6828 EXCEPTION
6829 WHEN OTHERS THEN
6830 IF g_debug_mode = 'Y' THEN
6831 log_message(p_msg_token1 => 'failed in budget task id update api SQLERR :'||sqlcode||sqlerrm);
6832 End if;
6833 RAISE;
6834
6835 END budget_task_id_update;
6836
6837 -- This api derives the effect on funds control level code based on
6838 -- amount the valid return values are I - Increase D - Decrease
6839 FUNCTION get_fclevel_code(p_accounted_dr IN NUMBER,
6840 p_accounted_cr IN NUMBER,
6841 x_effect_on_funds_code OUT NOCOPY VARCHAR2)
6842 return boolean IS
6843 BEGIN
6844 -- Update the pa_bc_packets set the effect on funds level code I - Increase , D - Decrease
6845 -- based on the amount entered_dr and entered_cr
6846 IF SIGN (NVL(p_accounted_dr,0)-NVL(p_accounted_cr,0)) = 1 then
6847 x_effect_on_funds_code := 'D';
6848 Else
6849 x_effect_on_funds_code := 'I';
6850 End if;
6851
6852 RETURN TRUE;
6853 EXCEPTION
6854 WHEN OTHERS THEN
6855 IF g_debug_mode = 'Y' THEN
6856 log_message(p_msg_token1 => 'failed in get fclevel code apiSQLERR :'||sqlcode||sqlerrm);
6857 End if;
6858 RAISE;
6859
6860 END get_fclevel_code;
6861
6862 -----------------------------------------------------------------------------------------------
6863 --Procedure to update the funds control level code in a packet for a project, budget version,
6864 --budget entry method.update pa_bc_packets for the set of records having the same combinations.
6865 ------------------------------------------------------------------------------------------------
6866 FUNCTION funds_ctrl_level_code (
6867 p_project_id IN NUMBER,
6868 p_task_id IN NUMBER,
6869 p_top_task_id IN NUMBER,
6870 p_parent_member_id IN NUMBER,
6871 p_resource_list_member_id IN NUMBER,
6872 p_budget_version_id IN NUMBER,
6873 p_bud_task_id IN NUMBER,
6874 p_categorization_code IN VARCHAR2,
6875 x_r_funds_control_level_code OUT NOCOPY VARCHAR2,
6876 x_rg_funds_control_level_code OUT NOCOPY VARCHAR2,
6877 x_t_funds_control_level_code OUT NOCOPY VARCHAR2,
6878 x_tt_funds_control_level_code OUT NOCOPY VARCHAR2,
6879 x_p_funds_control_level_code OUT NOCOPY VARCHAR2
6880 )
6881 return BOOLEAN is
6882
6883 l_r_funds_control_level_code VARCHAR2 ( 1 );
6884 l_rg_funds_control_level_code VARCHAR2 ( 1 );
6885 l_t_funds_control_level_code VARCHAR2 ( 1 );
6886 l_tt_funds_control_level_code VARCHAR2 ( 1 );
6887 l_p_funds_control_level_code VARCHAR2 ( 1 );
6888
6889 CURSOR res_fcl IS
6890 SELECT funds_control_level_code
6891 FROM pa_budgetary_controls pbc
6892 ,pa_budget_versions bv
6893 WHERE bv.budget_version_id = p_budget_version_id
6894 AND bv.project_id = pbc.project_id
6895 AND bv.budget_type_code = pbc.budget_type_code
6896 AND pbc.project_id = p_project_id
6897 AND ( pbc.task_id = 0
6898 OR pbc.task_id = p_task_id )
6899 AND ((pbc.resource_list_member_id = p_resource_list_member_id
6900 AND pbc.parent_member_id = p_parent_member_id) OR
6901 (pbc.resource_list_member_id = p_resource_list_member_id
6902 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1 )
6903 ) ;
6904 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 )) ; */
6905
6906
6907 CURSOR res_grp_fcl IS
6908 SELECT funds_control_level_code
6909 FROM pa_budgetary_controls pbc
6910 ,pa_budget_versions bv
6911 WHERE bv.budget_version_id = p_budget_version_id
6912 AND bv.project_id = pbc.project_id
6913 AND bv.budget_type_code = pbc.budget_type_code
6914 AND pbc.project_id = p_project_id
6915 AND ( pbc.task_id = 0
6916 OR pbc.task_id = p_task_id )
6917 AND pbc.resource_list_member_id = p_parent_member_id
6918 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1;
6919 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0; */
6920
6921 CURSOR task_fcl IS
6922 SELECT funds_control_level_code
6923 FROM pa_budgetary_controls pbc
6924 ,pa_budget_versions bv
6925 WHERE bv.budget_version_id = p_budget_version_id
6926 AND bv.project_id = pbc.project_id
6927 AND bv.budget_type_code = pbc.budget_type_code
6928 AND pbc.project_id = p_project_id
6929 AND pbc.task_id = p_task_id
6930 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 */
6931 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1
6932 AND NVL(pbc.resource_list_member_id,0) = 0;
6933
6934 CURSOR top_task_fcl IS
6935 SELECT funds_control_level_code
6936 FROM pa_budgetary_controls pbc
6937 ,pa_budget_versions bv
6938 WHERE bv.budget_version_id = p_budget_version_id
6939 AND bv.project_id = pbc.project_id
6940 AND bv.budget_type_code = pbc.budget_type_code
6941 AND pbc.project_id = p_project_id
6942 AND pbc.task_id = p_top_task_id
6943 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 */
6944 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1
6945 AND NVL(pbc.resource_list_member_id,0) = 0;
6946
6947 CURSOR project_fcl IS
6948 SELECT funds_control_level_code
6949 FROM pa_budgetary_controls pbc
6950 ,pa_budget_versions bv
6951 WHERE bv.budget_version_id = p_budget_version_id
6952 AND bv.project_id = pbc.project_id
6953 AND bv.budget_type_code = pbc.budget_type_code
6954 AND pbc.project_id = p_project_id
6955 AND NVL(pbc.task_id,0) = 0
6956 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 */
6957 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1
6958 AND NVL(pbc.resource_list_member_id,0) = 0;
6959
6960 /* Bug 5631763 : If there exists no BC records for the resource group/resource then the funds control levels
6961 are defaulted from those defined in pa_budgetary_control_options. If the funds control defined
6962 in pa_budgetary_control_options for the resource group/resource is "Default from Resource List"
6963 then the funds control levels are derived appropriately from the resource list. */
6964 CURSOR c_res_resgrp_no_bc (c_resource_list_member_id NUMBER) IS
6965 select nvl(rlm.funds_control_level_code,'N')
6966 from PA_RESOURCE_LIST_MEMBERS rlm
6967 where rlm.resource_list_member_id = c_resource_list_member_id
6968 and rlm.ENABLED_FLAG = 'Y'
6969 and DECODE(rlm.RESOURCE_TYPE_CODE, 'UNCLASSIFIED', 'Y', DISPLAY_FLAG) = 'Y'
6970 and nvl(rlm.migration_code, 'M') = 'M';
6971
6972
6973 BEGIN
6974 IF g_debug_mode = 'Y' THEN
6975 log_message(p_msg_token1 => 'funds_ctrl_level_code - in params are'||
6976 'Budget version ['||p_budget_version_id||
6977 ']p_resource_list_member_id ['||p_resource_list_member_id||
6978 ']project_id['||p_project_id||']p_task_id ['||p_task_id||
6979 ']p_top_task_id['||p_top_task_id||']p_bud_task_id['||p_bud_task_id||
6980 ']p_categorization_code['||p_categorization_code||']' );
6981 End if;
6982
6983 --Bug 5964934
6984 if p_budget_version_id = g_fclc_budget_version_id and
6985 p_project_id = g_fclc_project_id and
6986 g_p_funds_control_level_code is not null then
6987 l_p_funds_control_level_code := g_p_funds_control_level_code;
6988 else
6989 -- check the project funds control level code
6990 OPEN project_fcl;
6991 FETCH project_fcl INTO l_p_funds_control_level_code;
6992 IF project_fcl%NOTFOUND then
6993 l_p_funds_control_level_code := g_Pfund_control_level; -- Bug 5631763
6994 END IF;
6995 CLOSE project_fcl;
6996
6997 --Bug 5964934
6998 g_fclc_budget_version_id := p_budget_version_id;
6999 g_fclc_project_id := p_project_id;
7000 g_p_funds_control_level_code := nvl(l_p_funds_control_level_code,'N');
7001 end if;
7002
7003 -- task level funds control level codes
7004 IF NVL(p_bud_task_id,0) <> 0 THEN
7005 --Bug 5964934
7006 if p_budget_version_id = g_fclc_budget_version_id and
7007 p_project_id = g_fclc_project_id and
7008 p_top_task_id = g_fclc_top_task_id and
7009 g_tt_funds_control_level_code is not null then
7010 l_tt_funds_control_level_code := g_tt_funds_control_level_code;
7011 else
7012
7013 OPEN top_task_fcl;
7014 FETCH top_task_fcl INTO l_tt_funds_control_level_code;
7015 IF top_task_fcl%NOTFOUND then
7016 l_tt_funds_control_level_code := g_Tfund_control_level; -- Bug 5631763
7017 END IF;
7018
7019 CLOSE top_task_fcl;
7020
7021 --Bug 5964934
7022 g_fclc_budget_version_id := p_budget_version_id;
7023 g_fclc_project_id := p_project_id;
7024 g_fclc_top_task_id := p_top_task_id;
7025 g_tt_funds_control_level_code := nvl(l_tt_funds_control_level_code,'N');
7026 end if;
7027
7028 --Bug 5964934
7029 if p_budget_version_id = g_fclc_budget_version_id and
7030 p_project_id = g_fclc_project_id and
7031 p_task_id = g_fclc_task_id and
7032 g_t_funds_control_level_code is not null then
7033 l_t_funds_control_level_code := g_t_funds_control_level_code;
7034 else
7035 OPEN task_fcl;
7036 FETCH task_fcl INTO l_t_funds_control_level_code;
7037 IF task_fcl%NOTFOUND then
7038 l_t_funds_control_level_code := g_Tfund_control_level; -- Bug 5631763
7039 END IF;
7040
7041 CLOSE task_fcl;
7042 --Bug 5964934
7043 g_fclc_budget_version_id := p_budget_version_id;
7044 g_fclc_project_id := p_project_id;
7045 g_fclc_task_id := p_task_id;
7046 g_t_funds_control_level_code := nvl(l_t_funds_control_level_code,'N');
7047 end if;
7048
7049 END IF;
7050
7051 -- Resource level and resource group level funds control level codes
7052 IF p_categorization_code = 'R' THEN
7053
7054 --Bug 5964934
7055 if p_budget_version_id = g_fclc_budget_version_id and
7056 p_project_id = g_fclc_project_id and
7057 p_task_id = g_fclc_task_id and
7058 p_parent_member_id = g_fclc_parent_member_id and
7059 p_resource_list_member_id = g_fclc_resource_list_member_id and
7060 g_r_funds_control_level_code is not null then
7061 l_r_funds_control_level_code := g_r_funds_control_level_code;
7062 else
7063 OPEN res_fcl;
7064 FETCH res_fcl INTO l_r_funds_control_level_code;
7065 IF res_fcl%NOTFOUND then
7066 /* Bug 5631763 */
7067 If g_Rfund_control_level = 'D' then
7068 OPEN c_res_resgrp_no_bc (p_resource_list_member_id) ;
7069 FETCH c_res_resgrp_no_bc INTO l_r_funds_control_level_code;
7070 CLOSE c_res_resgrp_no_bc;
7071 else
7072 l_r_funds_control_level_code := g_Rfund_control_level;
7073 end if;
7074 /* Bug 5631763 */
7075 END IF;
7076
7077 CLOSE res_fcl;
7078 --Bug 5964934
7079 g_fclc_budget_version_id := p_budget_version_id;
7080 g_fclc_project_id := p_project_id;
7081 g_fclc_task_id := p_task_id;
7082 g_fclc_parent_member_id := p_parent_member_id;
7083 g_fclc_resource_list_member_id := p_resource_list_member_id;
7084 g_r_funds_control_level_code := nvl(l_r_funds_control_level_code,'N');
7085 end if;
7086 --Bug 5964934
7087 if p_budget_version_id = g_fclc_budget_version_id and
7088 p_project_id = g_fclc_project_id and
7089 p_task_id = g_fclc_task_id and
7090 p_parent_member_id = g_fclc_parent_member_id and
7091 g_rg_funds_control_level_code is not null then
7092 l_rg_funds_control_level_code := g_rg_funds_control_level_code;
7093 else
7094
7095 OPEN res_grp_fcl;
7096 FETCH res_grp_fcl INTO l_rg_funds_control_level_code;
7097 IF res_grp_fcl%NOTFOUND then
7098 /* Bug 5631763 */
7099 If g_RGfund_control_level = 'D' then
7100 If p_parent_member_id IS NOT NULL then
7101 OPEN c_res_resgrp_no_bc (p_parent_member_id);
7102 FETCH c_res_resgrp_no_bc INTO l_rg_funds_control_level_code;
7103 CLOSE c_res_resgrp_no_bc;
7104 else
7105 l_rg_funds_control_level_code := l_r_funds_control_level_code;
7106 end if;
7107 else
7108 l_rg_funds_control_level_code := g_RGfund_control_level;
7109 end if;
7110 /* Bug 5631763 */
7111 END IF;
7112 CLOSE res_grp_fcl;
7113
7114 --Bug 5964934
7115 g_fclc_budget_version_id := p_budget_version_id;
7116 g_fclc_project_id := p_project_id;
7117 g_fclc_task_id := p_task_id;
7118 g_fclc_parent_member_id := p_parent_member_id;
7119 g_rg_funds_control_level_code := nvl(l_rg_funds_control_level_code,'N');
7120 end if;
7121
7122 END IF;
7123
7124 x_r_funds_control_level_code := nvl(l_r_funds_control_level_code,'N');
7125 x_rg_funds_control_level_code := nvl(l_rg_funds_control_level_code,'N');
7126 x_t_funds_control_level_code := nvl(l_t_funds_control_level_code,'N');
7127 x_tt_funds_control_level_code := nvl(l_tt_funds_control_level_code,'N');
7128 x_p_funds_control_level_code := nvl(l_p_funds_control_level_code,'N');
7129
7130 IF g_debug_mode = 'Y' THEN
7131 log_message(p_msg_token1 => 'x_r_funds_control_level_code= '||x_r_funds_control_level_code);
7132 log_message(p_msg_token1 => 'x_rg_funds_control_level_code= '||x_rg_funds_control_level_code);
7133 log_message(p_msg_token1 => 'x_t_funds_control_level_code= '||x_t_funds_control_level_code);
7134 log_message(p_msg_token1 => 'x_tt_funds_control_level_code= '||x_tt_funds_control_level_code);
7135 log_message(p_msg_token1 => 'x_p_funds_control_level_code= '||x_p_funds_control_level_code);
7136 End if;
7137
7138 Return True;
7139
7140 EXCEPTION
7141 WHEN OTHERS THEN
7142 if project_fcl%ISOPEN then
7143 close project_fcl;
7144 end if;
7145 if top_task_fcl%ISOPEN then
7146 close top_task_fcl;
7147 end if;
7148 if task_fcl%ISOPEN then
7149 close task_fcl;
7150 end if;
7151 if res_grp_fcl%ISOPEN then
7152 close res_grp_fcl;
7153 end if;
7154 if res_fcl%ISOPEN then
7155 close res_fcl;
7156 end if;
7157 IF g_debug_mode = 'Y' THEN
7158 log_message(p_msg_token1 => 'failed in funds ctrl level codeapi SQLERR :'||sqlcode||sqlerrm);
7159 End if;
7160 raise;
7161 END funds_ctrl_level_code;
7162
7163 ----------------------------------------------------------------------------------------------
7164 -- This api Updates pa_bc_packets with , all the details required for creating
7165 -- encumbrance liquidation entries and to update budget account balances .
7166 -- get the following parameters budget_cc_id, encum_type_id, gl_date, gl_period etc.
7167 -----------------------------------------------------------------------------------------------
7168 FUNCTION encum_detail_update
7169 (p_mode IN VARCHAR2,
7170 p_project_id IN NUMBER,
7171 p_Task_id IN NUMBER,
7172 p_Budget_version_id IN NUMBER,
7173 p_Resource_list_member_id IN NUMBER,
7174 p_sob_id IN NUMBER,
7175 p_Period_name IN varchar2,
7176 p_Expenditure_item_date IN date,
7177 p_document_type IN VARCHAR2,
7178 p_ext_bdgt_type IN VARCHAR2,
7179 p_ext_bdgt_link IN VARCHAR2,
7180 p_bdgt_entry_level IN VARCHAR2,
7181 p_top_task_id IN NUMBER,
7182 p_OU IN NUMBER,
7183 p_calling_module IN VARCHAR2,
7184 x_budget_ccid IN OUT NOCOPY NUMBER,
7185 x_budget_line_id IN OUT NOCOPY NUMBER,
7186 x_gl_date OUT NOCOPY date,
7187 x_pa_date OUT NOCOPY date,
7188 x_result_code OUT NOCOPY varchar2,
7189 x_r_result_code OUT NOCOPY varchar2,
7190 x_rg_result_code OUT NOCOPY varchar2,
7191 x_t_result_code OUT NOCOPY varchar2,
7192 x_tt_result_code OUT NOCOPY varchar2,
7193 x_p_result_code OUT NOCOPY varchar2,
7194 x_p_acct_result_code OUT NOCOPY varchar2
7195 ) return BOOLEAN IS
7196
7197
7198 l_pa_date pa_bc_packets.pa_date%type := null;
7199 l_gl_date pa_bc_packets.gl_date%type := null;
7200 l_budget_ccid pa_bc_packets.budget_ccid%type := null;
7201 l_budget_line_id pa_bc_packets.budget_line_id%type := null;
7202 l_error_message_code varchar2(200) := null;
7203 l_return_status varchar2(10) := 'S';
7204 l_gl_start_date date;
7205
7206
7207 BEGIN
7208 IF g_debug_mode = 'Y' THEN
7209 log_message(p_msg_token1 =>'Inside encum_detail_update api');
7210 End if;
7211 -- Initialize the out NOCOPY params with null values
7212 --x_budget_ccid := null;
7213 x_gl_date := null;
7214 x_pa_date := null;
7215 x_result_code := null;
7216 x_r_result_code := null;
7217 x_rg_result_code := null;
7218 x_t_result_code := null;
7219 x_tt_result_code := null;
7220 x_p_result_code := null;
7221 x_p_acct_result_code := null;
7222 --- document type in AP, PO, REQ, Contract Commitments and Contract Payements
7223 --- GL_DATE is derived from gl_period_statuses for the given period_name and period_year
7224 --- get end_date from gl_period_statuses based on period_name and period_num and period_year
7225 --- for document type in Expenditures
7226 --- when there is budget linked derive GL_DATE based on the Expenditure Item Date
7227 --- When there is No link then derive gl date based on the pa_periods
7228 IF g_debug_mode = 'Y' THEN
7229 log_message(p_msg_token1 =>'ext bdgt link ['||p_ext_bdgt_link||']document type['||p_document_type||']');
7230 log_message(p_msg_token1 =>'p_mode='||p_mode);
7231 End if;
7232 If p_mode NOT in ('B','S') then -- and p_ext_bdgt_link = 'Y' then
7233 BEGIN
7234
7235 If p_document_type <> 'EXP' THEN
7236 IF g_debug_mode = 'Y' THEN
7237 log_message(p_msg_token1 =>'selecting gl date');
7238 End if;
7239
7240 if pa_budget_fund_pkg.Is_bdgt_intg_enabled(p_project_id => p_project_id, p_mode => p_mode) then
7241
7242 SELECT gl.end_date,
7243 gl.start_date
7244 INTO l_gl_date,l_gl_start_date
7245 FROM gl_period_statuses gl
7246 WHERE gl.application_id = 101
7247 AND gl.set_of_books_id = p_sob_id
7248 AND gl.period_name = p_period_name
7249 AND gl.closing_status in ('O','F');
7250
7251 Else
7252
7253 SELECT gl.end_date,
7254 gl.start_date
7255 INTO l_gl_date,l_gl_start_date
7256 FROM gl_period_statuses gl
7257 WHERE gl.application_id = 101
7258 AND gl.set_of_books_id = p_sob_id
7259 AND gl.period_name = p_period_name;
7260
7261 End if;
7262
7263
7264 IF g_debug_mode = 'Y' THEN
7265 log_message(p_msg_token1 =>'gl_end date = '||l_gl_date||' gl start date ='||l_gl_start_date);
7266 End if;
7267 /** pagl date derivation logic for the Funds check process
7268 * get the pa date for the expenditure item date. expenditure item date is treated
7269 * as transaction date even though we have accounting date entered in invoice.
7270 * so that the transaction date as close as to the accounting date
7271 * If ei_date is between gl.start and gl.end dates then
7272 * gl_date := ei_date
7273 * elsif ei_date > gl.end_date then
7274 * gl_date := gl.end_date
7275 * elsif ei_date < gl.start_date then
7276 * gl_date := gl.start_date
7277 * end if;
7278 **/
7279 If trunc(p_Expenditure_item_date) >= trunc(l_gl_start_date) and
7280 trunc(p_Expenditure_item_date) <= trunc(l_gl_date) then
7281 /** if the profile option is set then transaction date is gl date otherwise
7282 * gl end date is the gl date
7283 **/
7284 IF nvl(fnd_profile.value_specific('PA_EN_NEW_GLDATE_DERIVATION'),'N') = 'Y' THEN
7285 l_gl_date := p_Expenditure_item_date;
7286 ELSE
7287 l_gl_date := l_gl_date;
7288 END IF;
7289 Elsif trunc(p_Expenditure_item_date) > trunc(l_gl_date) then
7290 l_gl_date := l_gl_date;
7291 Elsif trunc(p_Expenditure_item_date) < trunc(l_gl_start_date) then
7292 l_gl_date := l_gl_start_date;
7293 End if;
7294 IF g_debug_mode = 'Y' THEN
7295 log_message(p_msg_token1 =>'after pagl derivation gl_end date = '
7296 ||l_gl_date||' gl start date ='||l_gl_start_date);
7297 End if;
7298
7299 --for document type EXP gl date and pa date are derived while
7300 -- inserting records into pa_bc_packets
7301 -- get the gl start date from gl_period_status for getting the budget ccid
7302
7303 Elsif p_document_type = 'EXP' THEN
7304 SELECT gl.start_date
7305 INTO l_gl_start_date
7306 FROM gl_period_statuses gl
7307 WHERE gl.application_id = 101
7308 AND gl.set_of_books_id = p_sob_id
7309 AND gl.period_name = p_period_name;
7310 IF g_debug_mode = 'Y' THEN
7311 log_message(p_msg_token1 =>'gl start date['||l_gl_start_date||']gl_date['||l_gl_date||']' );
7312 End if;
7313
7314 End if;
7315 x_gl_date := l_gl_date;
7316 EXCEPTION
7317 WHEN NO_DATA_FOUND THEN
7318 IF g_debug_mode = 'Y' THEN
7319 log_message(p_msg_token1 =>'GL date not found ');
7320 End if;
7321 -- Error msg : 'F134 = Start or End date is null for GL period
7322 x_result_code := 'F134';
7323 x_r_result_code := 'F134';
7324 x_rg_result_code := 'F134';
7325 x_t_result_code := 'F134';
7326 x_tt_result_code := 'F134';
7327 x_p_result_code := 'F134';
7328 x_p_acct_result_code := 'F134';
7329 RETURN false;
7330 WHEN OTHERS THEN
7331 IF g_debug_mode = 'Y' THEN
7332 log_message(p_msg_token1 =>'exeption in GL date finding'||sqlcode||sqlerrm);
7333 End if;
7334 --raise;
7335 END ;
7336
7337 Elsif p_mode in ('B', 'S') and p_ext_bdgt_link = 'Y' then
7338 /** get the gl_start_date to get the budget_ccid**/
7339 BEGIN
7340 SELECT gl.end_date,
7341 gl.start_date
7342 INTO l_gl_date,l_gl_start_date
7343 FROM gl_period_statuses gl
7344 WHERE gl.application_id = 101
7345 AND gl.set_of_books_id = p_sob_id
7346 AND gl.period_name = p_period_name;
7347 x_gl_date := l_gl_start_date;
7348 IF g_debug_mode = 'Y' THEN
7349 log_message(p_msg_token1 =>'l_gl_date= '||l_gl_date||'l_gl_start_date= '||l_gl_start_date);
7350 End if;
7351 EXCEPTION
7352 WHEN NO_DATA_FOUND THEN
7353 IF g_debug_mode = 'Y' THEN
7354 log_message(p_msg_token1 =>'GL date not found ');
7355 End if;
7356 -- Error msg : 'F134 = Start or End date is null for GL period
7357 x_result_code := 'F134';
7358 x_r_result_code := 'F134';
7359 x_rg_result_code := 'F134';
7360 x_t_result_code := 'F134';
7361 x_tt_result_code := 'F134';
7362 x_p_result_code := 'F134';
7363 x_p_acct_result_code := 'F134';
7364 RETURN false;
7365 WHEN OTHERS THEN
7366 raise;
7367 END;
7368
7369 End if;
7370
7371 -- If the budget is not linked and document type is exp then
7372 -- derive the pa_date based on the gl date
7373 If p_mode not IN ('B','S') then --and p_ext_bdgt_link <> 'Y' and
7374 --p_document_type in ( 'EXP','AP','REQ','PO','CC_C_PAY','CC_P_PAY') then
7375 IF g_debug_mode = 'Y' THEN
7376 log_message(p_msg_token1 =>'Selecting pa date');
7377 End if;
7378
7379 IF p_document_type <> 'EXP' then
7380
7381 BEGIN
7382 /** pa_gl_date derivation logic
7383 * for deriving the pa date call the
7384 * centralized api pa_utils.get_pa_date by passing
7385 * expenditure_item_date as the transaction date
7386 * the below lines are commented out NOCOPY
7387 SELECT end_date
7388 INTO l_pa_date
7389 FROM pa_periods
7390 WHERE --(gl_period_name = p_period_name
7391 --OR
7392 trunc(l_gl_date) between start_date and end_date
7393 --)
7394 AND status in ('O','F') ;
7395 **/
7396
7397 l_pa_date := pa_utils2.get_pa_date
7398 (p_Expenditure_item_date,NULL,p_OU);
7399
7400 If l_pa_date is null then
7401 x_result_code := 'F130';
7402 End if;
7403 IF g_debug_mode = 'Y' THEN
7404 log_message(p_msg_token1 =>'pa_date = '||l_pa_date);
7405 End if;
7406 x_pa_date := l_pa_date;
7407 EXCEPTION
7408 WHEN NO_DATA_FOUND THEN
7409 IF g_debug_mode = 'Y' THEN
7410 log_message(p_msg_token1 =>'pa date not found ');
7411 End if;
7412 --Error msg : 'F130 = Start or End Date is null for PA periods';
7413 x_result_code := 'F130';
7414 x_r_result_code := 'F130';
7415 x_rg_result_code := 'F130';
7416 x_t_result_code := 'F130';
7417 x_tt_result_code := 'F130';
7418 x_p_result_code := 'F130';
7419 x_p_acct_result_code := 'F130';
7420 RETURN false;
7421
7422 WHEN OTHERS THEN
7423 IF g_debug_mode = 'Y' THEN
7424 log_message(p_msg_token1 =>'exception in pa date finding');
7425 End if;
7426 Raise;
7427
7428 END;
7429 Elsif p_document_type = 'EXP' then /* Changes Start for Bug 6042137 */
7430 BEGIN
7431 l_pa_date := pa_utils2.get_pa_date
7432 (p_Expenditure_item_date,NULL,p_OU);
7433 If l_pa_date is null then
7434 x_result_code := 'F130';
7435 End if;
7436 IF g_debug_mode = 'Y' THEN
7437 log_message(p_msg_token1 =>'pa_dater = '||l_pa_date);
7438 End if;
7439 x_pa_date := l_pa_date;
7440 EXCEPTION
7441 WHEN NO_DATA_FOUND THEN
7442 IF g_debug_mode = 'Y' THEN
7443 log_message(p_msg_token1 =>'pa date not found ');
7444 End if;
7445 --Error msg : 'F130 = Start or End Date is null for PA periods';
7446 x_result_code := 'F130';
7447 x_r_result_code := 'F130';
7448 x_rg_result_code := 'F130';
7449 x_t_result_code := 'F130';
7450 x_tt_result_code := 'F130';
7451 x_p_result_code := 'F130';
7452 x_p_acct_result_code := 'F130';
7453 RETURN false;
7454 WHEN OTHERS THEN
7455 IF g_debug_mode = 'Y' THEN
7456 log_message(p_msg_token1 =>'exception in pa date finding');
7457 End if;
7458 Raise;
7459 END; /* Changes End for Bug 6042137 */
7460 End if;
7461
7462 End if;
7463
7464 -- Derive budget ccid in all other modes except budget baseline and commitment fund check
7465 -- During budget baseline: account level FC is executed during FC tieback ..
7466 -- Budget_ccid for txn. will be derived in tieback as budget lines are not visible here ...
7467 -- During commitment fund scheck, budget ccid and line id is derived upfront ..
7468
7469 --If p_mode <> 'B' then
7470 If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ' ,'TRXIMPORT') then
7471
7472 -- get budget_code_combination_id from pa_budget_lines
7473 -- for the given budget_version_id,project_id,task_id and resource list member id
7474 -- get the resource assignment_id from pa_resource_assignments
7475 -- get the budget_code_combination_id from pa_budget_lines for the
7476 -- given resource assignment id and start date of the gl period
7477 IF p_ext_bdgt_link = 'Y' then
7478 IF g_debug_mode = 'Y' THEN
7479 log_message(p_msg_token1 =>'Calling Budget ccid api In parameters are'||
7480 ']p_project_id ['||p_project_id||']p_task_id ['||p_task_id||'p_start date['||l_gl_start_date||
7481 ']p_top_task_id ['||p_top_task_id||'budgt by ['||p_bdgt_entry_level||
7482 ']rlmi ['||p_resource_list_member_id||']p_budget_version_id ['||p_budget_version_id ||']' );
7483 End if;
7484
7485 PA_FUNDS_CONTROL_UTILS.Get_Budget_CCID (
7486 p_project_id => p_project_id,
7487 p_task_id => p_task_id,
7488 p_res_list_mem_id => p_resource_list_member_id,
7489 --p_period_name => p_period_name,
7490 p_start_date => l_gl_start_date,
7491 p_budget_version_id => p_budget_version_id,
7492 p_top_task_id => p_top_task_id,
7493 p_entry_level_code => p_bdgt_entry_level,
7494 x_budget_ccid => l_budget_ccid,
7495 x_budget_line_id => l_budget_line_id,
7496 x_return_status => l_return_status,
7497 x_error_message_code => l_error_message_code);
7498 IF g_debug_mode = 'Y' THEN
7499 log_message(p_msg_token1 =>'After Budget ccid apiBudget ccid ['||l_budget_ccid||']' );
7500 End if;
7501
7502 If l_budget_ccid is NULL then
7503 --Error msg : 'F132 = Transaction Failed at Budget CCID setup';
7504 IF g_debug_mode = 'Y' THEN
7505 log_message(p_msg_token1 =>'Assigning F132 for the result code');
7506 End if;
7507 x_result_code := 'F132';
7508 x_r_result_code := 'F132';
7509 x_rg_result_code := 'F132';
7510 x_t_result_code := 'F132';
7511 x_tt_result_code := 'F132';
7512 x_p_result_code := 'F132';
7513 x_p_acct_result_code := 'F132';
7514 return false;
7515 End if;
7516
7517 x_budget_ccid := l_budget_ccid;
7518 x_budget_line_id := l_budget_line_id;
7519
7520 End if; -- IF p_ext_bdgt_link = 'Y' then
7521 End If; -- If p_mode <> 'B' then
7522
7523
7524 RETURN TRUE;
7525 EXCEPTION
7526 WHEN OTHERS THEN
7527 --x_status_code := 'T';
7528 --Return False;
7529 Raise;
7530
7531 END encum_detail_update;
7532
7533 -----------------------------------------------------------------------------
7534 -- This Api updates the pa_bc_packets with funds check setup parameters
7535 -- like resource list member id, top task id,and encumbrance details
7536 ----------------------------------------------------------------------------
7537 PROCEDURE update_pkts(p_packet_id number) IS
7538
7539 PRAGMA AUTONOMOUS_TRANSACTION;
7540
7541 BEGIN
7542 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
7543 UPDATE pa_bc_packets
7544 SET parent_resource_id = nvl(g_tab_p_resource_id(i),parent_resource_id),
7545 bud_task_id = nvl(g_tab_bud_task_id(i) ,bud_task_id) ,
7546 bud_resource_list_member_id = nvl(g_tab_bud_rlmi(i) ,bud_resource_list_member_id),
7547 top_task_id = nvl(g_tab_tt_task_id(i) ,top_task_id),
7548 r_funds_control_level_code = nvl(g_tab_r_fclevel_code(i),r_funds_control_level_code),
7549 rg_funds_control_level_code =nvl( g_tab_rg_fclevel_code(i),rg_funds_control_level_code),
7550 t_funds_control_level_code = nvl(g_tab_t_fclevel_code(i), t_funds_control_level_code),
7551 tt_funds_control_level_code = nvl(g_tab_tt_fclevel_code(i),tt_funds_control_level_code),
7552 p_funds_control_level_code = nvl(g_tab_p_fclevel_code(i),p_funds_control_level_code),
7553 result_code = nvl(g_tab_result_code(i) ,result_code),
7554 res_result_code = nvl(g_tab_r_result_code(i) ,res_result_code),
7555 res_grp_result_code = nvl(g_tab_rg_result_code(i),res_grp_result_code) ,
7556 task_result_code = nvl(g_tab_t_result_code(i),task_result_code),
7557 top_task_result_code = nvl(g_tab_tt_result_code(i), top_task_result_code),
7558 project_result_code = nvl(g_tab_p_result_code(i),project_result_code),
7559 project_acct_result_code = nvl(g_tab_p_acct_result_code(i),project_acct_result_code),
7560 budget_ccid = nvl(budget_ccid,g_tab_budget_ccid(i)),
7561 budget_line_id = nvl(budget_line_id,g_tab_budget_line_id(i)),
7562 burden_method_code = nvl(burden_method_code,g_tab_burden_method_code(i)),
7563 txn_ccid = nvl(g_tab_trxn_ccid(i),txn_ccid),
7564 effect_on_funds_code = nvl(g_tab_effect_fclevel(i), effect_on_funds_code),
7565 proj_encumbrance_type_id = nvl(g_tab_encum_type_id(i) ,proj_encumbrance_type_id),
7566 gl_date = nvl(g_tab_gl_date(i),gl_date),
7567 pa_date =nvl( g_tab_pa_date(i),pa_date),
7568 ext_bdgt_flag = nvl(g_tab_ext_bdgt_link(i),ext_bdgt_flag),
7569 fc_start_date = nvl(g_tab_start_date(i),fc_start_date),
7570 fc_end_date = nvl(g_tab_end_date(i),fc_end_date)
7571 WHERE packet_id = p_packet_id
7572 AND rowid = g_tab_rowid(i);
7573
7574 commit; -- to end an autonomous transaction
7575 return;
7576
7577 EXCEPTION
7578 WHEN OTHERS THEN
7579 g_return_status := 'T';
7580 IF g_debug_mode = 'Y' THEN
7581 log_message(p_msg_token1 => 'Failed in update_pkts api SQLERR'||sqlerrm||sqlcode);
7582 End if;
7583 RAISE;
7584 END update_pkts;
7585 ------------------------------------------------------------------------------------
7586 /* PAM Changes: calling new resource mapping api for performance improvement*/
7587 ------------------------------------------------------------------------------------
7588 PROCEDURE DERIVE_RLMI
7589 ( p_packet_id IN pa_bc_packets.packet_id%type,
7590 p_mode IN varchar2,
7591 p_sob IN NUMBER,
7592 p_reference1 IN varchar2 default null,
7593 p_reference2 IN varchar2 default null,
7594 p_calling_module IN varchar2 default 'GL'
7595 ) IS
7596
7597 PRAGMA AUTONOMOUS_TRANSACTION;
7598
7599 Cursor cur_rlmi_details IS
7600 SELECT pbc.rowid,
7601 pbc.budget_version_id,
7602 pbc.project_id,
7603 pbc.task_id,
7604 pbc.document_type,
7605 pbc.document_header_id,
7606 pbc.expenditure_organization_id,
7607 pbc.expenditure_type,
7608 TYPE.expenditure_category,
7609 TYPE.revenue_category_code,
7610 /* bug fix: 3700261 NVL ( ei.system_linkage_function, 'VI' ) */
7611 decode(pbc.document_type,'EXP',NVL ( ei.system_linkage_function, 'VI' ),'VI')
7612 system_linkage_function,
7613 pm.categorization_code resource_category_code,
7614 pbc.parent_bc_packet_id,
7615 pm.entry_level_code ,
7616 pbc.period_name,
7617 pbc.expenditure_item_date,
7618 pbc.bc_packet_id,
7619 pbc.org_id exp_org_id,
7620 pp.org_id proj_org_id,
7621 pbc.document_line_id,
7622 bv.resource_list_id,
7623 pbc.vendor_id
7624 FROM pa_bc_packets pbc,
7625 pa_projects_all pp,
7626 pa_budget_versions bv,
7627 pa_budget_entry_methods pm,
7628 pa_expenditure_types type,
7629 pa_expenditure_items_all ei
7630 WHERE pbc.packet_id = p_packet_id
7631 AND pp.project_id = pbc.project_id
7632 AND bv.project_id = pp.project_id
7633 AND pbc.budget_version_id = bv.budget_version_id
7634 AND bv.budget_entry_method_code = pm.budget_entry_method_code
7635 AND pbc.expenditure_type = TYPE.expenditure_type(+)
7636 AND pbc.document_header_id = ei.expenditure_item_id(+)
7637 AND pbc.status_code in ('P','L','I')
7638 AND substr(nvl(pbc.result_code,'P'),1,1) not in ('R','F')
7639 ORDER BY /** Bug fix :2004139 order by clause is changed to column names **/
7640 pbc.project_id,
7641 pbc.budget_version_id,
7642 pm.entry_level_code ,
7643 pm.categorization_code,
7644 pbc.task_id,
7645 pbc.expenditure_type,
7646 pbc.document_type,
7647 pbc.document_header_id,
7648 ei.system_linkage_function ;
7649 --1,2,3,4,5,10,6,8,7;
7650
7651 -- Declare local variables to hold values and use one level cache
7652 l_counter NUMBER := 0;
7653 l_return_status VARCHAR2(10);
7654 l_status_code VARCHAR2(10);
7655 l_result_code VARCHAR2(10);
7656 l_cache_project_id NUMBER;
7657 l_cache_task_id NUMBER;
7658 l_cache_bdgt_version_id NUMBER;
7659 l_res_list_id NUMBER;
7660 l_cache_res_list_id NUMBER;
7661 l_cache_exp_org_id NUMBER;
7662 l_job_id NUMBER;
7663 l_cache_job_id NUMBER;
7664 l_vendor_id NUMBER;
7665 l_cache_vendor_id NUMBER;
7666 l_cache_exp_type VARCHAR2 ( 30 );
7667 l_non_labor_resource VARCHAR2 ( 80 );
7668 l_non_labor_resource_org_id NUMBER;
7669 l_cache_non_lab_res_org NUMBER;
7670 l_cache_non_lab_res VARCHAR2 ( 80 );
7671 l_cache_sys_link_func VARCHAR2 ( 30 );
7672 l_cache_doc_type VARCHAR2 ( 10 );
7673 l_cache_doc_header_id NUMBER;
7674 l_non_cat_rlmi NUMBER;
7675 l_cache_non_cat_rlmi NUMBER;
7676 l_person_id NUMBER;
7677 l_cache_person_id NUMBER;
7678 l_error_stage VARCHAR2 ( 2000 ):= NULL;
7679 l_error_code NUMBER;
7680 l_cache_category_code VARCHAR2(30);
7681 l_cache_entry_level_code VARCHAR2(10);
7682 l_error_msg VARCHAR2(2000);
7683 l_cache_res_list_result_code VARCHAR2(10);
7684 l_cache_non_cat_bdgt_ver_id Number;
7685 l_cache_non_cat_result_code VARCHAR2(30);
7686 l_fc_utils2_cwk_rlmi NUMBER;
7687
7688 l_tab_resmap_list_id PA_PLSQL_DATATYPES.IDTABTYP;
7689 l_tab_resmap_project_id PA_PLSQL_DATATYPES.IDTABTYP;
7690 l_tab_resmap_pkt_line_type PA_PLSQL_DATATYPES.CHAR50TABTYP;
7691 ----------------------------------------------------------------------------------------
7692 -- If resource list is setup without resource groups and the
7693 -- resources are setup as expenditure categories, Funds check
7694 -- fail due to a resource mapping error.
7695 -------------------------------------------------------------------------------------
7696 CURSOR get_non_cat_rlmi(v_bdgt_ver_id NUMBER) IS
7697 SELECT resource_list_member_id
7698 FROM pa_bc_balances gb
7699 WHERE gb.budget_version_id = v_bdgt_ver_id
7700 AND balance_type = 'BGT'
7701 AND ROWNUM = 1;
7702
7703 CURSOR get_req_vend(v_doc_header_id NUMBER) IS
7704 SELECT line.vendor_id
7705 FROM po_requisition_lines line,
7706 po_requisition_headers req
7707 WHERE line.requisition_header_id = req.requisition_header_id
7708 AND req.requisition_header_id = v_doc_header_id ;
7709
7710
7711 CURSOR get_po_vend(v_doc_header_id NUMBER) IS
7712 SELECT head.vendor_id
7713 FROM po_headers_all head
7714 WHERE head.po_header_id = v_doc_header_id;
7715
7716
7717 CURSOR get_ap_vend(v_doc_header_id NUMBER) IS
7718 SELECT head.vendor_id
7719 FROM ap_invoices_all head
7720 WHERE head.invoice_id = v_doc_header_id;
7721
7722 CURSOR get_igc_vend(v_doc_header_id NUMBER) IS
7723 SELECT head.vendor_id
7724 FROM igc_cc_headers_all head
7725 WHERE head.cc_header_id = v_doc_header_id;
7726
7727 CURSOR get_exp_details(v_doc_header_id NUMBER) IS
7728 SELECT EXP.incurred_by_person_id,
7729 item.job_id
7730 FROM pa_expenditures_all exp,
7731 pa_expenditure_items_all item
7732 WHERE item.expenditure_item_id = v_doc_header_id
7733 AND item.expenditure_id = EXP.expenditure_id;
7734
7735 CURSOR get_non_usg_exp_details(v_doc_exp_type VARCHAR2) IS
7736 SELECT tp.attribute2,
7737 tp.attribute3
7738 FROM pa_expenditure_types tp
7739 WHERE tp.expenditure_type = v_doc_exp_type;
7740
7741 CURSOR get_usg_exp_details(v_doc_header_id NUMBER) IS
7742 SELECT EXP.incurred_by_person_id,
7743 item.job_id,
7744 item.non_labor_resource,
7745 item.organization_id
7746 FROM pa_expenditures_all exp,
7747 pa_expenditure_items_all item
7748 WHERE item.expenditure_item_id = v_doc_header_id
7749 AND item.expenditure_id = EXP.expenditure_id;
7750
7751 CURSOR cur_resList IS
7752 SELECT distinct bv.resource_list_id
7753 ,bv.budget_version_id
7754 ,bv.project_id
7755 ,NVL(pm.categorization_code,'N') resource_category_code
7756 FROM pa_budget_versions bv
7757 ,pa_budget_entry_methods pm
7758 ,pa_bc_packets pkt
7759 WHERE pkt.packet_id = p_packet_id
7760 AND bv.budget_version_id = pkt.budget_version_id
7761 AND substr(nvl(pkt.result_code,'P'),1,1) <> ('F')
7762 AND pkt.status_code in ('P','L','I')
7763 AND bv.budget_entry_method_code = pm.budget_entry_method_code
7764 ;
7765
7766 CURSOR cur_cwkRlmi IS
7767 SELECT pkt.bc_packet_id
7768 ,pkt.project_id
7769 ,pkt.task_id
7770 ,pkt.budget_version_id
7771 ,pkt.document_type
7772 ,pkt.document_header_id
7773 ,pkt.document_distribution_id
7774 ,pkt.document_line_id
7775 ,pkt.expenditure_type
7776 ,pkt.resource_list_member_id
7777 ,decode(NVL(pt.burden_amt_display_method,'N'),'D'
7778 ,decode(parent_bc_packet_id,NULL,'RAW','BURDEN'),'RAW') pkt_line_type
7779 FROM pa_bc_packets pkt
7780 ,pa_project_types_all pt
7781 ,pa_projects_all pp
7782 WHERE pkt.packet_id = p_packet_id
7783 AND pkt.document_line_id is not null
7784 AND pkt.document_type in ('PO','EXP')
7785 ANd NVL(pkt.summary_record_flag,'N') <> 'Y'
7786 AND substr(nvl(pkt.result_code,'P'),1,1) <> 'F'
7787 ANd pkt.status_code in ('P','L','I')
7788 AND pp.project_id = pkt.project_id
7789 AND pp.project_type = pt.project_type
7790 and pt.org_id = pp.org_id ;
7791
7792
7793 BEGIN
7794
7795 -- Initialize the error stack
7796 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.Derive_rlmi');
7797 IF g_debug_mode = 'Y' THEN
7798 log_message(p_msg_token1 => 'inside the fundscheck derive rlmi');
7799 End if;
7800 -- initialize the pl/sql talbes
7801 Init_plsql_tabs;
7802
7803 l_counter := 0;
7804
7805 FOR i IN cur_rlmi_details LOOP
7806 l_counter := l_counter + 1;
7807
7808 <<START_OF_RLMI>>
7809 IF g_debug_mode = 'Y' THEN
7810 log_message(p_msg_token1 => 'category['||i.resource_category_code ||
7811 ']bc packet id['||i.bc_packet_id||']resList['||i.resource_list_id||']' );
7812 End if;
7813 IF i.resource_category_code = 'R' THEN
7814 -- use one level cache to derive the values and then store in plsql tabls
7815 -- derive all other input params required for rlmi api.
7816 IF i.resource_list_id is NOT NULL Then
7817
7818 ---USE one level cache for storing the values and if values are same the
7819 -- skip the process continue to process the next set of records
7820 If (l_cache_sys_link_func is NULL OR
7821 i.system_linkage_function <> l_cache_sys_link_func)OR
7822 (l_cache_doc_header_id is NULL OR
7823 i.document_header_id <> l_cache_doc_header_id) OR
7824 (l_cache_doc_type is NULL OR
7825 i.document_type <> l_cache_doc_type)OR
7826 (l_cache_exp_type is NULL OR
7827 i.expenditure_type <> l_cache_exp_type)OR
7828 (l_cache_task_id is NULL OR
7829 i.task_id <> l_cache_task_id) OR
7830 (l_cache_exp_org_id is NULL OR
7831 i.expenditure_organization_id <> l_cache_exp_org_id) THEN
7832
7833 l_job_id := NULL;
7834 l_non_labor_resource := NULL;
7835 l_non_labor_resource_org_id := NULL;
7836 l_person_id := NULL;
7837 l_vendor_id := i.vendor_id;
7838
7839 IF g_debug_mode = 'Y' THEN
7840 log_message(p_msg_token1 => 'deriving INPUT PARAMETERS FOR RESOURCE MAPPING');
7841 End if;
7842
7843 -- -----------------VENDOR ID--------------------------+
7844 IF l_vendor_id is null THEN -- it will not be null for AP/PO/REQ FC
7845
7846 IF ( i.system_linkage_function = 'VI' AND i.document_type = 'REQ' ) THEN
7847
7848 OPEN get_req_vend(i.document_header_id);
7849 FETCH get_req_vend INTO l_vendor_id;
7850 CLOSE get_req_vend;
7851
7852 ELSIF ( i.system_linkage_function = 'VI' AND i.document_type = 'PO' ) THEN
7853
7854 OPEN get_po_vend(i.document_header_id);
7855 FETCH get_po_vend INTO l_vendor_id;
7856 CLOSE get_po_vend;
7857
7858 ELSIF ( i.system_linkage_function = 'VI' AND i.document_type = 'AP' ) THEN
7859
7860 OPEN get_ap_vend(i.document_header_id);
7861 FETCH get_ap_vend INTO l_vendor_id;
7862 CLOSE get_ap_vend;
7863
7864 ELSIF ( i.system_linkage_function = 'VI' AND i.document_type IN
7865 ( 'CC_C_PAY','CC_P_PAY','CC_C_CO','CC_P_CO','CC','CP')) THEN
7866
7867 OPEN get_igc_vend(i.document_header_id);
7868 FETCH get_igc_vend INTO l_vendor_id;
7869 CLOSE get_igc_vend;
7870 END IF;
7871
7872 END IF; ---IF l_vendor_id is null THEN
7873 -- -----------------VENDOR ID--------------------------+
7874
7875 IF ( i.system_linkage_function IN ('ER','ST','OT') AND
7876 i.document_type = 'EXP' )THEN
7877 OPEN get_exp_details(i.document_header_id);
7878 FETCH get_exp_details INTO
7879 l_person_id
7880 ,l_job_id;
7881 CLOSE get_exp_details;
7882 ELSIF ( i.system_linkage_function = 'USG' ) THEN
7883 IF i.document_type <> 'EXP' Then
7884 OPEN get_non_usg_exp_details(i.expenditure_type);
7885 FETCH get_non_usg_exp_details INTO
7886 l_non_labor_resource,
7887 l_non_labor_resource_org_id;
7888 CLOSE get_non_usg_exp_details;
7889
7890 ELSIF i.document_type = 'EXP' THEN
7891 OPEN get_usg_exp_details(i.document_header_id);
7892 FETCH get_usg_exp_details INTO
7893 l_person_id,
7894 l_job_id,
7895 l_non_labor_resource,
7896 l_non_labor_resource_org_id;
7897 CLOSE get_usg_exp_details;
7898
7899 END IF;
7900 END IF; -- end of INPUT PARAMETERS
7901
7902 l_cache_sys_link_func := i.system_linkage_function;
7903 l_cache_doc_header_id := i.document_header_id;
7904 l_cache_doc_type := i.document_type;
7905 l_cache_exp_type := i.expenditure_type;
7906 l_cache_task_id := i.task_id;
7907 l_cache_exp_org_id := i.expenditure_organization_id;
7908 l_cache_person_id := l_person_id;
7909 l_cache_job_id := l_job_id;
7910 l_cache_non_lab_res :=l_non_labor_resource;
7911 l_cache_non_lab_res_org := l_non_labor_resource_org_id;
7912 l_cache_vendor_id := l_vendor_id;
7913 ELSE
7914 --retrive from cache
7915 l_person_id := l_cache_person_id;
7916 l_job_id := l_cache_job_id;
7917 l_non_labor_resource := l_cache_non_lab_res;
7918 l_non_labor_resource_org_id := l_cache_non_lab_res_org;
7919 l_vendor_id := l_cache_vendor_id;
7920
7921
7922 END IF;
7923 END IF ; -- end of resouce list is not null
7924
7925 ELSE -- budget is not categorized by resource
7926 IF g_debug_mode = 'Y' THEN
7927 log_message(p_msg_token1 => 'Not Categorized by resouce ');
7928 End if;
7929 l_result_code := NULL;
7930 IF (l_cache_non_cat_bdgt_ver_id is null or i.budget_version_id <> l_cache_non_cat_bdgt_ver_id ) then
7931 OPEN get_non_cat_rlmi(i.budget_version_id);
7932 FETCH get_non_cat_rlmi INTO l_non_cat_rlmi;
7933 IF get_non_cat_rlmi%NOTFOUND OR l_non_cat_rlmi IS NULL THEN
7934 l_result_code := 'F128';
7935 END IF;
7936 CLOSE get_non_cat_rlmi;
7937 l_cache_non_cat_bdgt_ver_id := i.budget_version_id;
7938 l_cache_non_cat_rlmi := l_non_cat_rlmi ;
7939 l_cache_non_cat_result_code := l_result_code;
7940 ELSE -- retriev from cache
7941 l_non_cat_rlmi := l_cache_non_cat_rlmi;
7942 l_result_code := l_cache_non_cat_result_code;
7943 END IF;
7944
7945 END IF; -- end if for category
7946
7947 -- Assign all the local values to plsql tables
7948 g_tab_budget_version_id(l_counter) := i.budget_version_id;
7949 g_tab_project_id(l_counter) := i.project_id;
7950 g_tab_task_id(l_counter) := i.task_id;
7951 g_tab_doc_type(l_counter) := i.document_type;
7952 g_tab_doc_header_id(l_counter) := i.document_header_id;
7953 g_tab_doc_line_id(l_counter) := i.document_line_id;
7954 g_tab_exp_org_id(l_counter) := i.expenditure_organization_id;
7955 g_tab_exp_type(l_counter) := i.expenditure_type;
7956 g_tab_exp_category(l_counter) := i.expenditure_category;
7957 g_tab_rev_category(l_counter) := i.revenue_category_code;
7958 g_tab_sys_link_func(l_counter) := i.system_linkage_function;
7959 g_tab_category_code(l_counter) := i.resource_category_code;
7960 g_tab_p_bc_packet_id(l_counter) :=i.parent_bc_packet_id;
7961 g_tab_entry_level_code(l_counter):= i.entry_level_code;
7962 g_tab_period_name(l_counter) := i.period_name;
7963 g_tab_exp_item_date(l_counter) := i.expenditure_item_date;
7964 g_tab_bc_packet_id(l_counter) := i.bc_packet_id;
7965 g_tab_exp_OU(l_counter) := i.exp_org_id;
7966 g_tab_proj_OU(l_counter) := i.proj_org_id;
7967 g_tab_rlmi(l_counter) := NULL;
7968 g_tab_non_cat_rlmi(l_counter) := l_non_cat_rlmi;
7969 g_tab_r_list_id(l_counter) := i.resource_list_id;
7970 g_tab_result_code(l_counter) := l_result_code;
7971 g_tab_result_code(l_counter) := l_result_code;
7972 g_tab_r_result_code(l_counter) := l_result_code;
7973 g_tab_rg_result_code(l_counter) := l_result_code;
7974 g_tab_t_result_code(l_counter) := l_result_code;
7975 g_tab_tt_result_code(l_counter) := l_result_code;
7976 g_tab_p_result_code(l_counter) := l_result_code;
7977 g_tab_person_id(l_counter) := l_person_id;
7978 g_tab_job_id(l_counter) := l_job_id;
7979 g_tab_vendor_id(l_counter) := l_vendor_id;
7980 g_tab_non_lab_res(l_counter) := l_non_labor_resource;
7981 g_tab_non_lab_res_org(l_counter) := l_non_labor_resource_org_id;
7982
7983 END LOOP;
7984
7985 --insert the records into tmp table
7986 IF g_tab_bc_packet_id.EXISTS(1) THEN
7987
7988 BEGIN
7989
7990
7991 FOR resList in cur_resList LOOP
7992
7993 IF resList.resource_category_code = 'R' Then
7994 -- call resource mapping api if the budget is categorized by resource
7995 -- Insert the plsql values into a temp tables
7996 FORALL i IN g_tab_bc_packet_id.First ..g_tab_bc_packet_id.Last
7997 Insert into PA_MAPPABLE_TXNS_TMP
7998 (txn_id
7999 ,person_id
8000 ,job_id
8001 ,organization_id
8002 ,vendor_id
8003 ,expenditure_type
8004 ,event_type
8005 ,non_labor_resource
8006 ,expenditure_category
8007 ,revenue_category
8008 ,non_labor_resource_org_id
8009 ,event_type_classification
8010 ,system_linkage_function
8011 ,project_role_id
8012 ,resource_list_id
8013 ,system_reference1
8014 ,system_reference2
8015 ,system_reference3
8016 )
8017 SELECT
8018 pa_mappable_txns_tmp_s.NEXTVAL
8019 ,g_tab_person_id(i)
8020 ,g_tab_job_id(i)
8021 ,g_tab_exp_org_id(i)
8022 ,g_tab_vendor_id(i)
8023 ,g_tab_exp_type(i)
8024 ,null
8025 ,g_tab_non_lab_res(i)
8026 ,g_tab_exp_category(i)
8027 ,g_tab_rev_category(i)
8028 ,g_tab_non_lab_res_org(i)
8029 ,null
8030 ,g_tab_sys_link_func(i)
8031 ,null
8032 ,g_tab_r_list_id(i)
8033 ,p_packet_id
8034 ,g_tab_bc_packet_id(i)
8035 ,g_tab_project_id(i)
8036 FROM DUAL
8037 WHERE substr(nvl(g_tab_result_code(i),'P'),1,1) not in ('R','F')
8038 AND g_tab_r_list_id(i) = resList.resource_list_id
8039 AND g_tab_budget_version_id(i) = resList.budget_version_id
8040 AND g_tab_category_code(i) = 'R' ;
8041
8042 IF sql%ROWCOUNT > 0 Then
8043 COMMIT; -- so that the transactions are available in other sessions for res map
8044 log_message(p_msg_token1 => 'Calling Resource mapping API for ResList['
8045 ||resList.resource_list_id||']');
8046 -- Call the resource map api.
8047 PA_RES_ACCUMS.new_map_txns
8048 (x_resource_list_id => resList.resource_list_id
8049 ,x_error_stage => l_error_stage
8050 ,x_error_code => l_error_msg ) ;
8051
8052 IF g_debug_mode = 'Y' THEN
8053 log_message(p_msg_token1 => 'After PA_RES_ACCUMS.new_map_txns call');
8054 End if;
8055
8056 /* 7531681 Update PA_BC_PACKETS pkt
8057 SET (pkt.resource_list_member_id
8058 ,pkt.result_code
8059 ,pkt.res_result_code
8060 ,pkt.res_grp_result_code
8061 ,pkt.task_result_code
8062 ,pkt.top_task_result_code
8063 ,pkt.project_result_code
8064 ,pkt.project_acct_result_code) =
8065 (select tmp.resource_list_member_id
8066 ,decode(tmp.resource_list_member_id,NULL
8067 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8068 ,pkt.result_code)
8069 ,decode(tmp.resource_list_member_id,NULL
8070 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8071 ,pkt.result_code)
8072 ,decode(tmp.resource_list_member_id,NULL
8073 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8074 ,pkt.result_code)
8075 ,decode(tmp.resource_list_member_id,NULL
8076 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8077 ,pkt.result_code)
8078 ,decode(tmp.resource_list_member_id,NULL
8079 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8080 ,pkt.result_code)
8081 ,decode(tmp.resource_list_member_id,NULL
8082 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8083 ,pkt.result_code)
8084 ,decode(tmp.resource_list_member_id,NULL
8085 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8086 ,pkt.result_code)
8087 from PA_MAPPABLE_TXNS_TMP tmp
8088 where tmp.system_reference1 = pkt.packet_id
8089 and tmp.system_reference2 = pkt.bc_packet_id)
8090 WHERE pkt.packet_id = p_packet_id
8091 AND EXISTS ( SELECT 'Y'
8092 FROM PA_MAPPABLE_TXNS_TMP tmp
8093 WHERE tmp.system_reference1 = pkt.packet_id
8094 AND tmp.system_reference2 = pkt.bc_packet_id);
8095 7531681 */
8096 /* 7531681 start **/
8097 FORALL i in g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
8098 UPDATE PA_BC_PACKETS PKT SET (PKT.RESOURCE_LIST_MEMBER_ID) =
8099 (select TMP.RESOURCE_LIST_MEMBER_ID
8100 FROM
8101 PA_MAPPABLE_TXNS_TMP TMP
8102 WHERE
8103 TMP.SYSTEM_REFERENCE1 = p_packet_id AND
8104 TMP.SYSTEM_REFERENCE2 = g_tab_bc_packet_id(i))
8105 WHERE
8106 PKT.PACKET_ID = p_packet_id and
8107 pkt.bc_packet_id = g_tab_bc_packet_id(i)
8108 AND pkt.budget_version_id = resList.budget_version_id
8109 AND pkt.budget_version_id = g_tab_budget_version_id(i)
8110 AND g_tab_r_list_id(i) = resList.resource_list_id ;
8111
8112 /* 7531681 end */
8113
8114
8115 END IF;
8116
8117
8118 END IF;
8119
8120 log_message(p_msg_token1 =>'Finally one Update for Non Categoriztion Resource as wells as Failed transactions');
8121 FORALL i in g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
8122 UPDATE pa_bc_packets pkt
8123 SET pkt.resource_list_member_id = decode(g_tab_category_code(i),'R',pkt.resource_list_member_id
8124 ,g_tab_non_cat_rlmi(i))
8125 ,pkt.result_code = decode(g_tab_category_code(i),'R'
8126 ,decode(pkt.resource_list_member_id,NULL
8127 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8128 ,pkt.result_code)
8129 ,decode(g_tab_non_cat_rlmi(i),NULL
8130 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8131 ,pkt.result_code)
8132 )
8133 ,pkt.res_result_code = decode(g_tab_category_code(i),'R'
8134 ,decode(pkt.resource_list_member_id,NULL
8135 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8136 ,pkt.result_code)
8137 ,decode(g_tab_non_cat_rlmi(i),NULL
8138 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8139 ,pkt.result_code)
8140 )
8141 ,pkt.res_grp_result_code = decode(g_tab_category_code(i),'R'
8142 ,decode(pkt.resource_list_member_id,NULL
8143 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8144 ,pkt.result_code)
8145 ,decode(g_tab_non_cat_rlmi(i),NULL
8146 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8147 ,pkt.result_code)
8148 )
8149 ,pkt.task_result_code = decode(g_tab_category_code(i),'R'
8150 ,decode(pkt.resource_list_member_id,NULL
8151 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8152 ,pkt.result_code)
8153 ,decode(g_tab_non_cat_rlmi(i),NULL
8154 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8155 ,pkt.result_code)
8156 )
8157 ,pkt.top_task_result_code = decode(g_tab_category_code(i),'R'
8158 ,decode(pkt.resource_list_member_id,NULL
8159 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8160 ,pkt.result_code)
8161 ,decode(g_tab_non_cat_rlmi(i),NULL
8162 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8163 ,pkt.result_code)
8164 )
8165 ,pkt.project_result_code = decode(g_tab_category_code(i),'R'
8166 ,decode(pkt.resource_list_member_id,NULL
8167 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8168 ,pkt.result_code)
8169 ,decode(g_tab_non_cat_rlmi(i),NULL
8170 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8171 ,pkt.result_code)
8172 )
8173 ,pkt.project_acct_result_code = decode(g_tab_category_code(i),'R'
8174 ,decode(pkt.resource_list_member_id,NULL
8175 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8176 ,pkt.result_code)
8177 ,decode(g_tab_non_cat_rlmi(i),NULL
8178 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
8179 ,pkt.result_code)
8180 )
8181 WHERE pkt.packet_id = p_packet_id
8182 AND pkt.bc_packet_id = g_tab_bc_packet_id(i)
8183 AND pkt.budget_version_id = resList.budget_version_id
8184 AND pkt.budget_version_id = g_tab_budget_version_id(i)
8185 AND g_tab_r_list_id(i) = resList.resource_list_id
8186 ;
8187 END LOOP;
8188
8189 /* delete the records from tmp table */
8190 DELETE FROM PA_MAPPABLE_TXNS_TMP tmp
8191 WHERE tmp.system_reference1 = p_packet_id;
8192
8193 /* CWK labor changes update the pkts with reosurce list member ids of the summary records
8194 * information on the transactions */
8195 IF p_calling_module NOT IN ('CBC') Then
8196
8197 log_message(p_msg_token1 => 'Updating rlmi with summary record rlmi for Contigent Wkr transactions');
8198 OPEN cur_cwkRlmi ;
8199 LOOP
8200 -- Initialize the plsql tables
8201 g_tab_bc_packet_id.delete;
8202 g_tab_project_id.delete;
8203 g_tab_task_id.delete;
8204 g_tab_budget_version_id.delete;
8205 g_tab_doc_type.delete;
8206 g_tab_doc_header_id.delete;
8207 g_tab_doc_distribution_id.delete;
8208 g_tab_doc_line_id.delete;
8209 g_tab_exp_type.delete;
8210 g_tab_rlmi.delete;
8211 l_tab_resmap_pkt_line_type.delete;
8212 FETCH cur_cwkRlmi BULK COLLECT INTO
8213 g_tab_bc_packet_id
8214 ,g_tab_project_id
8215 ,g_tab_task_id
8216 ,g_tab_budget_version_id
8217 ,g_tab_doc_type
8218 ,g_tab_doc_header_id
8219 ,g_tab_doc_distribution_id
8220 ,g_tab_doc_line_id
8221 ,g_tab_exp_type
8222 ,g_tab_rlmi
8223 ,l_tab_resmap_pkt_line_type LIMIT 500;
8224 pa_funds_control_pkg.log_message(p_msg_token1=>'NumOfCwkRecs['||g_tab_bc_packet_id.count||']');
8225 IF NOT g_tab_bc_packet_id.EXISTS(1) THEN
8226 EXIT;
8227 END IF;
8228
8229 FOR i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST LOOP
8230 l_fc_utils2_cwk_rlmi := NULL;
8231 l_fc_utils2_cwk_rlmi := pa_funds_control_utils2.get_CWK_RLMI
8232 (g_tab_project_id(i)
8233 ,g_tab_task_id(i)
8234 ,g_tab_budget_version_id(i)
8235 ,g_tab_doc_header_id(i)
8236 ,g_tab_doc_distribution_id(i)
8237 ,g_tab_doc_line_id(i)
8238 ,g_tab_doc_type(i)
8239 ,g_tab_exp_type(i)
8240 ,l_tab_resmap_pkt_line_type(i)
8241 ,'FUNDS_CHECK');
8242
8243 pa_funds_control_pkg.log_message(p_msg_token1=>'bcPktId['||g_tab_bc_packet_id(i)||
8244 ']pktrlmi['||g_tab_rlmi(i)||']cwkRlmi['||l_fc_utils2_cwk_rlmi||
8245 ']pktLineType['||l_tab_resmap_pkt_line_type(i)||']');
8246 g_tab_rlmi(i) := NVL(l_fc_utils2_cwk_rlmi,g_tab_rlmi(i));
8247 END LOOP;
8248 -- Bulk update the cwkRlmi
8249 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
8250 UPDATE pa_bc_packets pkt
8251 SET pkt.resource_list_member_id = NVL(g_tab_rlmi(i),pkt.resource_list_member_id)
8252 WHERE pkt.packet_id = p_packet_id
8253 AND pkt.bc_packet_id = g_tab_bc_packet_id(i)
8254 AND pkt.document_type in ('PO','EXP')
8255 ANd NVL(pkt.summary_record_flag,'N') <> 'Y'
8256 AND substr(nvl(pkt.result_code,'P'),1,1) <> 'F' ;
8257 log_message(p_msg_token1 => 'No of rows updated['||sql%rowcount||']');
8258 IF cur_cwkRlmi%NOTFOUND THEN
8259 EXIT;
8260 END IF;
8261 END LOOP;
8262 CLOSE cur_cwkRlmi;
8263
8264 END IF;
8265
8266 EXCEPTION
8267 WHEN NO_DATA_FOUND Then
8268 Null;
8269 WHEN OTHERS THEN
8270 RAISE;
8271 END ;
8272
8273 END IF;
8274
8275 COMMIT;
8276 PA_DEBUG.reset_err_stack;
8277
8278 EXCEPTION
8279 WHEN OTHERS THEN
8280 RAISE;
8281
8282 END DERIVE_RLMI;
8283
8284
8285
8286
8287 ---------------------------------------------------------------------------------------------------
8288 --- This api set up the resource list member id ,parent_resource_id,parent_member_id,top task id
8289 -- bud_task_id ,funds control level codes and pa date gl date budget ccid and encumbrance type id
8290 -- for for each record in the packet.
8291 -----------------------------------------------------------------------------------------------------
8292 FUNCTION funds_check_setup
8293 ( p_packet_id IN pa_bc_packets.packet_id%type,
8294 p_mode IN varchar2,
8295 p_sob IN NUMBER,
8296 p_reference1 IN varchar2 default null,
8297 p_reference2 IN varchar2 default null,
8298 p_calling_module IN varchar2
8299
8300 ) return boolean IS
8301
8302 -- This cursor picks all the details required for resource list member id mapping
8303 -- one level cache logic is used to update the pa_bc_packet table
8304 CURSOR setup_details IS
8305 SELECT pbc.rowid,
8306 pbc.budget_version_id,
8307 pbc.project_id,
8308 pbc.task_id,
8309 pbc.document_type,
8310 pbc.document_header_id,
8311 pbc.expenditure_organization_id,
8312 pbc.expenditure_type,
8313 pm.categorization_code,
8314 pbc.parent_bc_packet_id,
8315 pm.entry_level_code ,
8316 pbc.accounted_dr,
8317 pbc.accounted_cr,
8318 pbc.period_name,
8319 pbc.expenditure_item_date,
8320 pbc.bc_packet_id,
8321 pbc.txn_ccid,
8322 pbc.old_budget_ccid,
8323 pbc.org_id,
8324 pbc.resource_list_member_id,
8325 bv.resource_list_id,
8326 pm.time_phased_type_code,
8327 pb.amount_type,
8328 pb.boundary_code,
8329 pbc.set_of_books_id,
8330 pbc.gl_date,
8331 pbc.pa_date, /*9487097 */
8332 pbc.burden_method_code,
8333 --decode(pbc.burden_method_code,'S','SAME',
8334 -- 'D','DIFFERENT',
8335 -- 'N','NONE',
8336 -- pbc.burden_method_code) burden_method_code,
8337 pbc.budget_line_id,
8338 pbc.budget_ccid
8339 FROM pa_bc_packets pbc,
8340 pa_budget_versions bv,
8341 pa_budget_entry_methods pm,
8342 pa_budgetary_control_options pb
8343 WHERE pbc.packet_id = p_packet_id
8344 AND pbc.budget_version_id = bv.budget_version_id
8345 AND bv.budget_entry_method_code = pm.budget_entry_method_code
8346 AND pbc.status_code in ('P','L')
8347 AND substr(nvl(pbc.result_code,'P'),1,1) not in ('R','F')
8348 AND pb.project_id = pbc.project_id
8349 AND pb.BDGT_CNTRL_FLAG = 'Y'
8350 AND pb.BUDGET_TYPE_CODE = bv.budget_type_code
8351 AND ((pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
8352 and pb.EXTERNAL_BUDGET_CODE = 'GL')
8353 OR
8354 (pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
8355 and pb.EXTERNAL_BUDGET_CODE is NULL)
8356 OR
8357 (pbc.document_type in ('CC_P_CO','CC_C_CO')
8358 and pb.EXTERNAL_BUDGET_CODE = 'CC' )
8359 )
8360 ORDER BY /** Bug fix :2004139 order by clause is changed to column names **/
8361 pbc.project_id,
8362 pbc.budget_version_id,
8363 pm.entry_level_code ,
8364 pm.categorization_code,
8365 pbc.task_id,
8366 pbc.expenditure_type,
8367 pbc.document_type,
8368 pbc.document_header_id
8369 ;
8370
8371 /* Bug 5631763 */
8372 cursor c_funds_control_level(bud_version_id NUMBER) is
8373 select fund_control_level_project,
8374 fund_control_level_task ,
8375 fund_control_level_res_grp,
8376 fund_control_level_res
8377 from pa_budgetary_control_options pb,
8378 pa_budget_versions pv
8379 where pv.project_id = pb.project_id
8380 AND pb.BDGT_CNTRL_FLAG = 'Y'
8381 AND pb.BUDGET_TYPE_CODE = pv.budget_type_code
8382 AND pv.budget_version_id = bud_version_id;
8383 /* Bug 5631763 */
8384
8385 -- Declare local variables to hold values and use one level cache
8386 l_return_status VARCHAR2(10);
8387 l_status_code VARCHAR2(10);
8388 l_result_code VARCHAR2(10);
8389 l_r_result_code VARCHAR2(10);
8390 l_rg_result_code VARCHAR2(10);
8391 l_t_result_code VARCHAR2(10);
8392 l_tt_result_code VARCHAR2(10);
8393 l_p_result_code VARCHAR2(10);
8394 l_p_acct_result_code VARCHAR2(10);
8395 l_pre_rlmi NUMBER;
8396 l_project_id NUMBER;
8397 l_pre_project_id NUMBER;
8398 l_task_id NUMBER;
8399 l_pre_task_id NUMBER;
8400 l_budget_version_id NUMBER;
8401 l_pre_budget_version_id NUMBER;
8402 l_pre_res_list_id NUMBER;
8403 l_exp_org_id NUMBER;
8404 l_pre_exp_org_id NUMBER;
8405 l_exp_type VARCHAR2 ( 30 );
8406 l_pre_exp_type VARCHAR2 ( 30 );
8407 l_expenditure_type VARCHAR2 ( 30 );
8408 l_doc_type VARCHAR2 ( 10 );
8409 l_pre_doc_type VARCHAR2 ( 10 );
8410 l_doc_header_id NUMBER;
8411 l_pre_doc_header_id NUMBER;
8412 l_parent_id NUMBER;
8413 l_error_stage VARCHAR2 ( 2000 ):= NULL;
8414 l_error_code NUMBER;
8415 l_group_by_none VARCHAR2 ( 60 );
8416 l_num_rows NUMBER := 200;
8417 l_parent_member_id NUMBER;
8418 l_parent_resource_id NUMBER;
8419 l_bud_rlmi NUMBER;
8420 l_bud_task_id NUMBER;
8421 l_top_task_id NUMBER;
8422 l_trxn_ccid NUMBER;
8423 l_budget_ccid NUMBER;
8424 l_budget_line_id pa_budget_lines.budget_line_id%type;
8425 l_r_fclevel_code VARCHAR2(10);
8426 l_rg_fclevel_code VARCHAR2(10);
8427 l_t_fclevel_code VARCHAR2(10);
8428 l_tt_fclevel_code VARCHAR2(10);
8429 l_p_fclevel_code VARCHAR2(10);
8430 l_p_acct_fclevel_code VARCHAR2(10);
8431 l_effect_on_funds_code VARCHAR2(10);
8432 l_pre_category_code VARCHAR2(30);
8433 l_category_code VARCHAR2(30);
8434 l_entry_level_code VARCHAR2(10);
8435 l_pre_entry_level_code VARCHAR2(10);
8436 l_ext_bdgt_type VARCHAR2(10);
8437 l_ext_bdgt_link VARCHAR2(10);
8438 l_encum_type_id NUMBER;
8439 l_gl_date DATE;
8440 l_pa_date DATE;
8441 l_error_msg VARCHAR2(2000);
8442 l_prv_burden_method VARCHAR2(20);
8443 l_burden_method VARCHAR2(20);
8444 l_pre_ext_bdgt_link VARCHAR2(20);
8445 l_pre_time_phase_code varchar2(80);
8446 l_pre_amount_type varchar2(80);
8447 l_pre_boundary_code varchar2(80);
8448 l_pre_fc_sdate Date := Null;
8449 l_pre_fc_edate Date := Null;
8450 l_pre_ei_date Date := Null; /*Bug 8562406 */
8451 l_trx_item_date Date := Null;
8452 l_fc_start_date Date := Null;
8453 l_fc_end_date Date := Null;
8454 l_err_buff VARCHAR2(2000);
8455
8456 l_imp_count Number := 0;
8457
8458 BEGIN
8459 -- Initialize the error stack
8460 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.setup');
8461
8462 If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
8463 ,'TRXIMPORT','RESERVE_BASELINE') then
8464
8465 -- Note: For commitment Funds check, derive_rlmi is called in pa_funds_control_pkg1
8466 -- R12: BC-SLA Integration ..
8467
8468 IF g_debug_mode = 'Y' THEN
8469 log_message(p_msg_token1 => 'inside the fundscheck setup api Calling Derive_rlmi ');
8470 End if;
8471
8472 DERIVE_RLMI
8473 ( p_packet_id => p_packet_id
8474 ,p_mode => p_mode
8475 ,p_sob => p_sob
8476 ,p_reference1 => p_reference1
8477 ,p_reference2 => p_reference2
8478 ,p_calling_module => p_calling_module
8479 );
8480
8481 IF g_debug_mode = 'Y' THEN
8482 log_message(p_msg_token1 => 'After DERIVE_RLMI api call');
8483 End if;
8484
8485 End If;
8486
8487 -- open cursor and fetch 200 rows at a time
8488 OPEN setup_details;
8489 IF g_debug_mode = 'Y' THEN
8490 log_message(p_msg_token1 => 'opened the cursor for setup details');
8491 End if;
8492 LOOP
8493 -- initialize the pl/sql talbes
8494 Init_plsql_tabs;
8495
8496 FETCH setup_details BULK COLLECT INTO
8497 g_tab_rowid,
8498 g_tab_budget_version_id,
8499 g_tab_project_id,
8500 g_tab_task_id,
8501 g_tab_doc_type,
8502 g_tab_doc_header_id,
8503 g_tab_exp_org_id,
8504 g_tab_exp_type,
8505 g_tab_category_code,
8506 g_tab_p_bc_packet_id,
8507 g_tab_entry_level_code ,
8508 g_tab_accounted_dr,
8509 g_tab_accounted_cr,
8510 g_tab_period_name,
8511 g_tab_exp_item_date,
8512 g_tab_bc_packet_id,
8513 g_tab_trxn_ccid,
8514 g_tab_old_budget_ccid,
8515 g_tab_OU,
8516 g_tab_rlmi,
8517 g_tab_r_list_id,
8518 g_tab_time_phase_type_code,
8519 g_tab_amount_type,
8520 g_tab_boundary_code,
8521 g_tab_sob_id,
8522 g_tab_exp_gl_date,
8523 g_tab_exp_pa_date, /*9487097 */
8524 g_tab_burden_method_code,
8525 g_tab_budget_line_id,
8526 g_tab_budget_ccid
8527 LIMIT l_num_rows;
8528 IF g_debug_mode = 'Y' THEN
8529 log_message(p_msg_token1 =>'Afeter fetch statements');
8530 End if;
8531
8532 If NOT g_tab_rowid.EXISTS(1) then
8533 IF g_debug_mode = 'Y' THEN
8534 log_message(p_msg_token1 => 'Fetched the NO ROWS ');
8535 End if;
8536 exit;
8537 Else
8538 IF g_debug_mode = 'Y' THEN
8539 log_message(p_msg_token1 => 'Fetched the rows into plsql tables');
8540 End if;
8541 null;
8542 End if;
8543
8544 -- for each record in derive the resource list member id, parent resource id ,
8545 -- bud task id , top taskid funds control level codes, budget ccid, gl date ,
8546 -- pa date, encumbrance type id etc.
8547 --
8548 FOR i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST LOOP
8549
8550 g_tab_p_resource_id(i) := null;
8551 g_tab_p_member_id(i) := null;
8552 g_tab_bud_task_id(i) := null;
8553 g_tab_bud_rlmi(i) := null;
8554 g_tab_tt_task_id(i) := null;
8555 g_tab_r_fclevel_code(i) := null;
8556 g_tab_rg_fclevel_code(i) := null;
8557 g_tab_t_fclevel_code(i) := null;
8558 g_tab_tt_fclevel_code(i) := null;
8559 g_tab_p_fclevel_code(i) := null;
8560 g_tab_p_acct_fclevel_code(i) := null;
8561 g_tab_status_code(i) := null;
8562 g_tab_result_code(i) := null;
8563 g_tab_r_result_code(i) := null;
8564 g_tab_rg_result_code(i) := null;
8565 g_tab_t_result_code(i) := null;
8566 g_tab_tt_result_code(i) := null;
8567 g_tab_p_result_code(i) := null;
8568 g_tab_p_acct_result_code(i) := null;
8569 --g_tab_budget_ccid(i) := null;
8570 g_tab_effect_fclevel(i) := null;
8571 g_tab_encum_type_id(i) := null;
8572 g_tab_gl_date(i) := null;
8573 g_tab_pa_date(i) := null;
8574 g_tab_start_date(i) := null;
8575 g_tab_end_date(i) := null;
8576 g_tab_ext_bdgt_link(i) := null;
8577
8578 /* Bug 5631763 */
8579
8580 g_Tfund_control_level := NULL;
8581 g_Pfund_control_level := NULL;
8582 g_RGfund_control_level := NULL;
8583 g_Rfund_control_level := NULL;
8584
8585
8586 OPEN c_funds_control_level(g_tab_budget_version_id(i));
8587 FETCH c_funds_control_level INTO
8588 g_Pfund_control_level ,
8589 g_Tfund_control_level ,
8590 g_RGfund_control_level,
8591 g_Rfund_control_level;
8592 CLOSE c_funds_control_level;
8593
8594 /* Bug 5631763 */
8595
8596 <<START_OF_RLMI>>
8597 IF g_debug_mode = 'Y' THEN
8598 log_message(p_msg_token1 => 'category['||g_tab_category_code(i)||
8599 ']bc packet id['||g_tab_bc_packet_id(i)||']' );
8600 End if;
8601
8602 -- derive the budget resouce list member id , parent resource
8603 -- id based the resource list member id and use one level cache
8604
8605 IF (l_pre_rlmi is NULL or g_tab_rlmi(i) <> l_pre_rlmi )OR
8606 (l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i))OR
8607 (l_pre_budget_version_id is NULL or l_pre_budget_version_id <>
8608 g_tab_budget_version_id(i) )OR
8609 (l_pre_category_code is NULL or l_pre_category_code <> g_tab_category_code(i))
8610 Then
8611 IF g_debug_mode = 'Y' THEN
8612 log_message(p_msg_token1 => 'Calling bud_res_list_id_update api ');
8613 End if;
8614 IF NOT bud_res_list_id_update
8615 ( p_project_id => g_tab_project_id(i),
8616 p_budget_version_id => g_tab_budget_version_id(i),
8617 p_resource_list_member_id => g_tab_rlmi(i),
8618 p_categorization_code => g_tab_category_code(i),
8619 x_bud_resource_list_member_id => l_bud_rlmi,
8620 x_parent_resource_id => l_parent_resource_id
8621 ) Then
8622 IF g_debug_mode = 'Y' THEN
8623 log_message(p_msg_token1 =>
8624 'Failed to derive bud_rlmi and parent resource id');
8625 End if;
8626 l_error_msg := 'Failed to derive bud_rlmi and parent resource id';
8627 END IF;
8628 IF g_debug_mode = 'Y' THEN
8629 log_message(p_msg_token1 => 'bud rlmi ['||l_bud_rlmi||']parent res ['||
8630 l_parent_resource_id||']');
8631 End if;
8632
8633 END IF;
8634
8635
8636 -- derive the budgeted task and top task id
8637 IF (l_pre_task_id is NULL or l_pre_task_id <> g_tab_task_id(i) )OR
8638 (l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i))OR
8639 (l_pre_budget_version_id is NULL or l_pre_budget_version_id <>
8640 g_tab_budget_version_id(i) )OR
8641 (l_pre_entry_level_code is NULL or l_pre_entry_level_code
8642 <> g_tab_entry_level_code(i) ) Then
8643 IF g_debug_mode = 'Y' THEN
8644 log_message(p_msg_token1 => 'Calling bud task id update api ');
8645 End if;
8646 IF NOT budget_task_id_update
8647 ( p_project_id => g_tab_project_id(i),
8648 p_task_id => g_tab_task_id(i),
8649 p_budget_version_id => g_tab_budget_version_id(i),
8650 p_entry_level_code => g_tab_entry_level_code(i),
8651 x_bud_task_id => l_bud_task_id,
8652 x_top_task_id => l_top_task_id
8653 ) then
8654 IF g_debug_mode = 'Y' THEN
8655 log_message(p_msg_token1 => 'Failed to derive top task and bud task ids');
8656 End if;
8657 l_error_msg := 'Failed to derive top task and bud task ids';
8658 END IF;
8659 END IF;
8660
8661
8662 -- Derive the effect on funds control based on the accounted dr
8663 -- and accounted cr
8664 IF g_debug_mode = 'Y' THEN
8665 log_message(p_msg_token1 => 'Calling get_fclevel_code api ');
8666 End if;
8667 IF NOT get_fclevel_code
8668 (p_accounted_dr => g_tab_accounted_dr(i),
8669 p_accounted_cr => g_tab_accounted_cr(i),
8670 x_effect_on_funds_code => l_effect_on_funds_code) Then
8671 IF g_debug_mode = 'Y' THEN
8672 log_message(p_msg_token1 => 'Failed to derive Effect on Funds control level code');
8673 End if;
8674 l_error_msg := 'Failed to derive Effect on Funds control level code';
8675 END IF;
8676
8677 -- Derive the funds control level codes for each level ie resource
8678 -- resource group, task, top task and project level
8679 IF g_debug_mode = 'Y' THEN
8680 log_message(p_msg_token1 => 'Calling funds_ctrl_level_code api ');
8681 End if;
8682 IF NOT funds_ctrl_level_code (
8683 p_project_id => g_tab_project_id(i),
8684 p_task_id => g_tab_task_id(i),
8685 p_top_task_id => l_top_task_id,
8686 p_parent_member_id => l_parent_resource_id,
8687 p_resource_list_member_id => g_tab_rlmi(i),
8688 p_budget_version_id => g_tab_budget_version_id(i),
8689 p_bud_task_id => l_bud_task_id,
8690 p_categorization_code => g_tab_category_code(i),
8691 x_r_funds_control_level_code => l_r_fclevel_code,
8692 x_rg_funds_control_level_code => l_rg_fclevel_code,
8693 x_t_funds_control_level_code => l_t_fclevel_code,
8694 x_tt_funds_control_level_code => l_tt_fclevel_code,
8695 x_p_funds_control_level_code => l_p_fclevel_code
8696 ) then
8697 IF g_debug_mode = 'Y' THEN
8698 log_message(p_msg_token1 => 'Failed to derive Funds control level codes');
8699 End if;
8700 l_error_msg := 'Failed to derive Funds control level codes';
8701 END IF;
8702
8703 -- check whether the budget type is STD or CBC
8704 IF g_tab_doc_type(i) in ('PO','REQ','AP','EXP','CC_P_PAY','CC_C_PAY') then
8705 l_ext_bdgt_type := 'STD';
8706 ELSIF g_tab_doc_type(i) in ('CC_C_CO','CC_P_CO') then
8707 l_ext_bdgt_type := 'CBC';
8708 End IF;
8709
8710
8711 --check whether the project is linked or not if linked with std
8712 -- budget then derive all the encumbrance details
8713 l_ext_bdgt_link := 'N';
8714 IF l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i) then
8715 l_ext_bdgt_link := pa_funds_control_utils.get_bdgt_link
8716 ( p_project_id =>g_tab_project_id(i),
8717 p_calling_mode => l_ext_bdgt_type);
8718 l_pre_ext_bdgt_link := l_ext_bdgt_link;
8719 Else
8720 l_ext_bdgt_link := l_pre_ext_bdgt_link;
8721 End IF;
8722 IF g_debug_mode = 'Y' THEN
8723 log_message(p_msg_token1 => 'l_ext_bdgt_link ['||l_ext_bdgt_link||']');
8724 End if;
8725
8726 -- Dervie the encumbrance details such as gl date / pa date,
8727 -- budget ccid etc,
8728 IF g_debug_mode = 'Y' THEN
8729 log_message(p_msg_token1 =>'Period name ['||g_tab_period_name(i)||
8730 ']exp item date ['||g_tab_exp_item_date(i)||']doc type ['|| g_tab_doc_type(i)||']');
8731 End if;
8732
8733
8734 l_budget_ccid := null;
8735 l_budget_line_id := null;
8736 l_gl_date := null;
8737 l_pa_date := null;
8738
8739 IF NOT encum_detail_update
8740 (p_mode => p_mode,
8741 p_project_id => g_tab_project_id(i),
8742 p_Task_id => g_tab_task_id(i),
8743 p_Budget_version_id => g_tab_budget_version_id(i),
8744 p_Resource_list_member_id => g_tab_rlmi(i),
8745 p_sob_id => p_sob,
8746 p_Period_name => g_tab_period_name(i),
8747 p_Expenditure_item_date => g_tab_exp_item_date(i),
8748 p_document_type => g_tab_doc_type(i),
8749 p_ext_bdgt_type => l_ext_bdgt_type,
8750 p_ext_bdgt_link => l_ext_bdgt_link,
8751 p_bdgt_entry_level => g_tab_entry_level_code(i),
8752 p_top_task_id => l_top_task_id,
8753 p_OU => g_tab_OU(i),
8754 p_calling_module => p_calling_module,
8755 x_budget_ccid => l_budget_ccid,
8756 x_budget_line_id => l_budget_line_id,
8757 x_gl_date => l_gl_date,
8758 x_pa_date => l_pa_date,
8759 x_result_code => l_result_code,
8760 x_r_result_code => l_r_result_code,
8761 x_rg_result_code => l_rg_result_code,
8762 x_t_result_code => l_t_result_code,
8763 x_tt_result_code => l_tt_result_code,
8764 x_p_result_code => l_p_result_code,
8765 x_p_acct_result_code => l_p_acct_result_code
8766 ) then
8767 IF g_debug_mode = 'Y' THEN
8768 log_message(p_msg_token1 => 'Failed to derive Encumbrance Details ');
8769 End if;
8770 l_error_msg := 'Failed to derive Encumbrance Details ';
8771 IF g_debug_mode = 'Y' THEN
8772 log_message(p_msg_token1 => 'l_budget_ccid ['||l_budget_ccid||']l_gl_date['
8773 ||l_gl_date||']l_pa_date['||l_pa_date||']');
8774 End if;
8775 GOTO END_OF_FC_SETUP_PROCESS;
8776
8777 END IF;
8778
8779 IF g_debug_mode = 'Y' THEN
8780 log_message(p_msg_token1 => 'After Encumbrance Details api');
8781 End if;
8782
8783 If p_calling_module not in
8784 ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ' ,'TRXIMPORT','RESERVE_BASELINE') then
8785
8786 l_budget_ccid := g_tab_budget_ccid(i);
8787 l_budget_line_id := g_tab_budget_line_id(i);
8788
8789 End If;
8790
8791 -- check if the project type is burden on different seperate ei
8792 -- then update the burden line tranaction ccid with budget ccid
8793 log_message(p_msg_token1 => 'Update the trxn ccid for bdn lines ');
8794
8795 l_trxn_ccid := g_tab_trxn_ccid(i);
8796
8797 l_burden_method := g_tab_burden_method_code(i);
8798
8799 If l_burden_method is NULL then
8800
8801 IF l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i) then
8802
8803 l_burden_method := check_bdn_on_sep_item (g_tab_project_id(i));
8804 l_prv_burden_method := l_burden_method;
8805 Else
8806 l_burden_method := l_prv_burden_method;
8807 End if;
8808
8809 Else
8810
8811 l_prv_burden_method := l_burden_method;
8812
8813 End If;
8814
8815 IF g_debug_mode = 'Y' THEN
8816 log_message(p_msg_token1 => 'l_burden_method ='||l_burden_method);
8817 End if;
8818 If g_tab_p_bc_packet_id(i) is NOT NULL and l_ext_bdgt_link = 'Y' then
8819 --IF l_burden_method in ( 'DIFFERENT','SAME') then
8820 IF l_burden_method in ( 'D','S') then
8821 IF g_debug_mode = 'Y' THEN
8822 log_message(p_msg_token1 =>'g_tab_trxn_ccid(i) ='||l_budget_ccid);
8823 End if;
8824 l_trxn_ccid := l_budget_ccid;
8825 End if;
8826 End if;
8827
8828 -- check if the budget is linked to external budget GL then
8829 -- transaction ccid must equal to budget ccid otherwise error out NOCOPY
8830 -- differenct cases: Burden on same ei - donot check for raw line
8831 -- Burden on sep ei - check trxn ccid = bdgt_ccid
8832 -- NO burden for ei - check trxn ccid = bdgt_ccid for raw line
8833 IF g_debug_mode = 'Y' THEN
8834 log_message(p_msg_token1 =>'ext budget link ['||l_ext_bdgt_link||
8835 ']txn ccid ['||l_trxn_ccid ||']budget ccid ['||l_budget_ccid || ']' );
8836 End if;
8837
8838 ---- If the calling mode NOT IN Base line then derive encum type id
8839 --- get the encum_type_id from api get_budget_control_options for
8840 --- the given project_id
8841 IF l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i) then
8842 If P_mode NOT IN ('B','S') then
8843 l_encum_type_id := pa_funds_control_utils.Get_encum_type_id
8844 ( p_project_id => g_tab_project_id(i),
8845 p_calling_mode => l_ext_bdgt_type);
8846 if l_encum_type_id is null and l_ext_bdgt_link = 'Y' then
8847 --Error msg : 'F135 = Transaction failed due to Encumbrance type is null';
8848 --l_status_code := 'R';
8849 l_result_code := 'F135';
8850 l_r_result_code := 'F135';
8851 l_rg_result_code := 'F135';
8852 l_t_result_code := 'F135';
8853 l_tt_result_code := 'F135';
8854 l_p_result_code := 'F135';
8855 l_p_acct_result_code := 'F135';
8856 End if;
8857 End if;
8858 End if;
8859
8860 IF substr(nvl(l_result_code,'P'),1,1) <> 'F' Then -- result_code check
8861
8862 If g_tab_time_phase_type_code(i) = 'G' Then
8863 -- for document type exp pass the gl date derived by the cdls for all others
8864 -- derive gl date as the end of the period name
8865 If g_tab_doc_type(i) = 'EXP' Then
8866 l_trx_item_date := g_tab_exp_gl_date(i);
8867 Else
8868 l_trx_item_date := nvl(l_gl_date,g_tab_exp_gl_date(i)); --Bug 5495666
8869 End If;
8870 Elsif g_tab_time_phase_type_code(i) = 'P' Then
8871
8872 if g_tab_doc_type(i) = 'EXP' Then /*9487097*/
8873 l_trx_item_date := g_tab_exp_pa_date(i);
8874 else
8875 l_trx_item_date := nvl(l_pa_date,g_tab_exp_pa_date(i)); --Bug5472629
8876 end if;
8877
8878 Else
8879 l_trx_item_date := g_tab_exp_item_date(i);
8880 End if;
8881
8882 /* ========================================================================================+
8883 Following code is incorrect ..not required.
8884 -- If p_mode is 'B' and 'S', use the period_name stamped on the txn. being funds checked
8885 -- to get the start and end date
8886 -- In normal FC mode, call pa_funds_control_pkg1.setup_start_end_date to derive dates
8887 log_message(p_msg_token1 =>'Mode ['||p_mode||'] Period name['||g_tab_period_name(i)||']');
8888
8889 If p_mode in ('B','S') then -- Mode check
8890 Begin
8891 SELECT gl.start_date,gl.end_date
8892 INTO l_fc_start_date,l_fc_end_date
8893 FROM gl_period_statuses gl
8894 WHERE gl.application_id = 101
8895 AND gl.set_of_books_id = p_sob
8896 AND gl.period_name = g_tab_period_name(i);
8897 Exception
8898 When no_data_found then
8899 l_result_code := 'F136';
8900 IF g_debug_mode = 'Y' THEN
8901 log_message(p_msg_token1 =>'Mode ['||p_mode||'] Exception: No Data Found - F136');
8902 END IF;
8903 When too_many_rows then
8904 l_result_code := 'F136';
8905 IF g_debug_mode = 'Y' THEN
8906 log_message(p_msg_token1 =>'Mode ['||p_mode||'] Exception: Too Many Rows - F136');
8907 END IF;
8908 End;
8909
8910 Else -- Mode check
8911 ===============================================================================================+ */
8912
8913 If (l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i)) OR
8914 (l_pre_budget_version_id is NULL or l_pre_budget_version_id <> g_tab_budget_version_id(i) ) OR
8915 (l_pre_time_phase_code is NULL or l_pre_time_phase_code <> g_tab_time_phase_type_code(i)) OR
8916 (l_pre_amount_type is NULL or l_pre_amount_type <> g_tab_amount_type(i)) OR
8917 (l_pre_boundary_code is NULL or l_pre_boundary_code <> g_tab_boundary_code(i)) OR
8918 (l_pre_fc_sdate is NULL or l_pre_fc_edate is NULL OR
8919 trunc(l_trx_item_date) NOT BETWEEN l_pre_fc_sdate AND l_pre_fc_edate) OR
8920 (to_char(nvl(l_pre_ei_date,g_tab_exp_item_date(i)),'YYYY')<>to_char(g_tab_exp_item_date(i),'YYYY') AND g_tab_exp_item_date(i) is not NULL ) /*Bug 8562406 */
8921 THEN -- call date API
8922 If g_debug_mode = 'Y' THEN
8923 log_message(p_msg_token1 => 'Calling pa_funds_control_pkg1.setup_start_end_date API');
8924 End if;
8925
8926 /*PAM changes derive start and end dates */
8927 pa_funds_control_pkg1.setup_start_end_date (
8928 p_packet_id => p_packet_id
8929 ,p_bc_packet_id => g_tab_bc_packet_id(i)
8930 ,p_project_id => g_tab_project_id(i)
8931 ,p_budget_version_id => g_tab_budget_version_id(i)
8932 ,p_time_phase_type_code => g_tab_time_phase_type_code(i)
8933 ,p_expenditure_item_date => l_trx_item_date
8934 ,p_amount_type => g_tab_amount_type(i)
8935 ,p_boundary_code => g_tab_boundary_code(i)
8936 ,p_set_of_books_id => g_tab_sob_id(i)
8937 ,x_start_date => l_fc_start_date
8938 ,x_end_date => l_fc_end_date
8939 ,x_error_code => l_error_code
8940 ,x_err_buff => l_err_buff
8941 ,x_return_status => l_return_status
8942 ,x_result_code => l_result_code
8943 );
8944 If g_debug_mode = 'Y' THEN
8945 log_message(p_msg_token1 => 'End of setup_start_end_date Resultcode['||l_result_code||']');
8946 End if;
8947
8948 Else --retrieve fro cache
8949 l_fc_start_date := l_pre_fc_sdate;
8950 l_fc_end_date := l_pre_fc_edate ;
8951 End If; -- call date API
8952
8953 --End If; -- Mode check
8954
8955
8956 END If; -- result_code check
8957
8958 IF g_debug_mode = 'Y' THEN
8959 log_message(p_msg_token1 =>'l_fc_start_date ['||l_fc_start_date||'] l_fc_end_date ['||l_fc_end_date||']');
8960 log_message(p_msg_token1 => 'storing values in local variables');
8961 End if;
8962
8963 ---------------------------------------------------------------
8964 -- store the values in local variables
8965 l_pre_doc_header_id := g_tab_doc_header_id(i) ;
8966 l_pre_doc_type := g_tab_doc_type(i) ;
8967 l_pre_exp_type := g_tab_exp_type(i) ;
8968 l_pre_project_id := g_tab_project_id(i) ;
8969 l_pre_budget_version_id := g_tab_budget_version_id(i) ;
8970 l_pre_task_id := g_tab_task_id(i) ;
8971 l_pre_exp_org_id := g_tab_exp_org_id(i) ;
8972 l_pre_res_list_id := g_tab_r_list_id(i);
8973 l_pre_rlmi := g_tab_rlmi(i);
8974 l_pre_entry_level_code := g_tab_entry_level_code(i);
8975 l_pre_category_code := g_tab_category_code(i);
8976 l_pre_time_phase_code := g_tab_time_phase_type_code(i);
8977 l_pre_amount_type := g_tab_amount_type(i);
8978 l_pre_boundary_code := g_tab_boundary_code(i);
8979 l_pre_fc_sdate := l_fc_start_date;
8980 l_pre_fc_edate := l_fc_end_date;
8981 l_pre_ei_date := g_tab_exp_item_date(i) ; /*Bug 8562406 */
8982 IF g_debug_mode = 'Y' THEN
8983 log_message(p_msg_token1 =>'end of storing values in local variables');
8984 End if;
8985
8986 << END_OF_FC_SETUP_PROCESS>>
8987 ----------------------------------------------------------------
8988 -- Assign the out NOCOPY parameters to pl/sql tables
8989 ----------------------------------------------------------------
8990 IF g_debug_mode = 'Y' THEN
8991 log_message(p_msg_token1 => 'assiging out NOCOPY param values to plsql tables');
8992 End if;
8993 --if the funds check is called in Forcepass mode, then after deriving
8994 -- all the setup parameters if there is no error then update the result code
8995 -- to success and donot call pa_fcp_process
8996 If p_mode in ('F') and substr(nvl(l_result_code,'P'),1,1) = 'P' then
8997 l_result_code := 'P116'; -- Transaction passed funds check in forcepass mode
8998 l_r_result_code := 'P116';
8999 l_rg_result_code := 'P116';
9000 l_t_result_code := 'P116';
9001 l_tt_result_code := 'P116';
9002 l_p_result_code := 'P116';
9003 l_p_acct_result_code := 'P116';
9004 End if;
9005
9006 g_tab_p_resource_id(i) := l_parent_resource_id;
9007 g_tab_p_member_id(i) := l_parent_member_id;
9008 g_tab_bud_task_id(i) := l_bud_task_id;
9009 g_tab_bud_rlmi(i) := l_bud_rlmi;
9010 g_tab_tt_task_id(i) := l_top_task_id;
9011 g_tab_r_fclevel_code(i) := l_r_fclevel_code;
9012 g_tab_rg_fclevel_code(i) := l_rg_fclevel_code;
9013 g_tab_t_fclevel_code(i) := l_t_fclevel_code;
9014 g_tab_tt_fclevel_code(i) := l_tt_fclevel_code;
9015 g_tab_p_fclevel_code(i) := l_p_fclevel_code;
9016 g_tab_p_acct_fclevel_code(i) := l_p_acct_fclevel_code;
9017 g_tab_result_code(i) := l_result_code;
9018 g_tab_r_result_code(i) := l_r_result_code;
9019 g_tab_rg_result_code(i) := l_rg_result_code;
9020 g_tab_t_result_code(i) := l_t_result_code;
9021 g_tab_tt_result_code(i) := l_tt_result_code;
9022 g_tab_p_result_code(i) := l_p_result_code;
9023 g_tab_p_acct_result_code(i) := l_p_acct_result_code;
9024 g_tab_trxn_ccid(i) := l_trxn_ccid;
9025 g_tab_budget_ccid(i) := l_budget_ccid;
9026 g_tab_burden_method_code(i) := l_burden_method;
9027 g_tab_budget_line_id(i) := l_budget_line_id;
9028 g_tab_effect_fclevel(i) := l_effect_on_funds_code;
9029 g_tab_encum_type_id(i) := l_encum_type_id;
9030 g_tab_gl_date(i) := l_gl_date;
9031 g_tab_pa_date(i) := l_pa_date;
9032 g_tab_ext_bdgt_link(i) := l_ext_bdgt_link;
9033 g_tab_start_date(i) := l_fc_start_date;
9034 g_tab_end_date(i) := l_fc_end_date;
9035
9036 IF g_debug_mode = 'Y' THEN
9037 log_message(p_msg_token1 => 'End of Assignments');
9038 End if;
9039
9040
9041 END LOOP; -- end of forloop
9042 IF g_debug_mode = 'Y' THEN
9043 log_message(p_msg_token1 => 'After loop calling FORALL update statement');
9044 End if;
9045
9046 -- update the pa bc pakcets in a batch of 200 records after dering the setup
9047 -- param values
9048 /*****
9049 log_message(p_msg_token1 => 'update bc packets for batch of 200 record ');
9050 for i in g_tab_rowid.FIRST .. g_tab_rowid.LAST loop
9051 log_message(p_msg_token1 => 'g_tab_bc_packet_id ='||g_tab_bc_packet_id(i));
9052 log_message(p_msg_token1 => 'g_tab_p_resource_id(i) ='||g_tab_p_resource_id(i));
9053 log_message(p_msg_token1 => 'g_tab_bud_task_id(i) ='||g_tab_bud_task_id(i));
9054 log_message(p_msg_token1 => 'g_tab_bud_rlmi(i) ='||g_tab_bud_rlmi(i));
9055 log_message(p_msg_token1 => 'g_tab_r_fclevel_code(i) ='||g_tab_r_fclevel_code(i));
9056 log_message(p_msg_token1 => 'g_tab_rg_fclevel_code(i) ='||g_tab_rg_fclevel_code(i));
9057 log_message(p_msg_token1 => 'g_tab_t_fclevel_code(i) ='||g_tab_t_fclevel_code(i));
9058 log_message(p_msg_token1 =>'g_tab_tt_fclevel_code(i) ='||g_tab_tt_fclevel_code(i));
9059 log_message(p_msg_token1 =>' g_tab_p_fclevel_code(i) ='||g_tab_p_fclevel_code(i));
9060 log_message(p_msg_token1 =>'g_tab_result_code(i) ='||g_tab_result_code(i) );
9061 log_message(p_msg_token1 =>'g_tab_r_result_code(i)='||g_tab_r_result_code(i));
9062 log_message(p_msg_token1 =>'g_tab_rg_result_code(i)='||g_tab_rg_result_code(i));
9063 log_message(p_msg_token1 =>'g_tab_p_result_code(i) ='||g_tab_p_result_code(i));
9064 log_message(p_msg_token1 =>'g_tab_p_acct_result_code(i) ='||g_tab_p_acct_result_code(i));
9065 log_message(p_msg_token1 =>'g_tab_effect_fclevel(i) ='||g_tab_effect_fclevel(i));
9066 log_message(p_msg_token1 =>'g_tab_budget_ccid(i) ='||g_tab_budget_ccid(i));
9067 log_message(p_msg_token1 =>'g_tab_encum_type_id(i) ='||g_tab_encum_type_id(i));
9068 log_message(p_msg_token1 =>'g_tab_gl_date(i)='||g_tab_gl_date(i));
9069 log_message(p_msg_token1 =>'g_tab_pa_date(i) ='||g_tab_pa_date(i));
9070 log_message(p_msg_token1 =>'g_tab_ext_bdgt_link(i)='||g_tab_ext_bdgt_link(i));
9071 log_message(p_msg_token1 =>'g_tab_start_date(i) = '||g_tab_start_date(i));
9072 log_message(p_msg_token1 =>'g_tab_end_date(i) = '||g_tab_end_date(i));
9073 end loop;
9074 *****/
9075
9076 IF g_debug_mode = 'Y' THEN
9077 log_message(p_msg_token1 => 'calling update pkt autonomous transaction api');
9078 End if;
9079 update_pkts(p_packet_id => p_packet_id);
9080 IF g_debug_mode = 'Y' THEN
9081 log_message(p_msg_token1 => 'after the pkt autonomous transaction api');
9082 End if;
9083
9084
9085 EXIT when setup_details%NOTFOUND;
9086
9087 END LOOP; -- end of setup details cursor;
9088 IF g_debug_mode = 'Y' THEN
9089 log_message(p_msg_token1 =>'End of setup_details cursor');
9090 End if;
9091 CLOSE setup_details;
9092 IF g_debug_mode = 'Y' THEN
9093 log_message(p_msg_token1 => 'End of fundscheck setup api');
9094 End if;
9095 If setup_details%ISOPEN THEN
9096 close setup_details;
9097 End if;
9098
9099 return true;
9100
9101 EXCEPTION
9102
9103 WHEN OTHERS THEN
9104 If setup_details%ISOPEN THEN
9105 close setup_details;
9106 End if;
9107 IF g_debug_mode = 'Y' THEN
9108 log_message(p_msg_token1 => 'Unexpected Error during Funds check setup Params SQLERROR '||sqlcode||sqlerrm);
9109 End if;
9110 -- Error Msg : 'F120 = Funds check failed during Setup and Summerization';
9111 result_status_code_update(
9112 p_status_code => 'T',
9113 p_result_code => 'F120',
9114 p_res_result_code => 'F120',
9115 p_res_grp_result_code => 'F120',
9116 p_task_result_code => 'F120',
9117 p_top_task_result_code => 'F120',
9118 p_project_result_code => 'F120',
9119 p_proj_acct_result_code => 'F120',
9120 p_packet_id => p_packet_id);
9121 log_message(p_error_msg => sqlcode||sqlerrm);
9122 --commit;
9123 Raise;
9124
9125 END funds_check_setup;
9126 ---------------------------------------------------------------------------------------
9127 -- This api syncronizes the burden lines with raw line
9128 -- if the burden line pass but raw line fails then burden transaction
9129 -- will be marked as failed
9130 -------------------------------------------------------------------------------------
9131 PROCEDURE result_code_update_burden
9132 (p_packet_id IN NUMBER,
9133 x_return_status OUT NOCOPY VARCHAR2 )IS
9134 PRAGMA AUTONOMOUS_TRANSACTION;
9135
9136 CURSOR update_burden_rows IS
9137 SELECT bc_packet_id,
9138 result_code,
9139 res_result_code,
9140 res_grp_result_code,
9141 task_result_code,
9142 top_task_result_code,
9143 project_result_code,
9144 project_acct_result_code
9145 FROM pa_bc_packets
9146 WHERE packet_id = p_packet_id
9147 AND parent_bc_packet_id IS NULL
9148 AND nvl(SUBSTR ( result_code,1,1),'P') IN ('F','R');
9149
9150 l_num_rows NUMBER:= 200;
9151
9152
9153 BEGIN
9154
9155 IF g_debug_mode = 'Y' THEN
9156 log_message(p_msg_token1 => 'Indide result_code_update_burden api ');
9157 End if;
9158
9159
9160 OPEN update_burden_rows; LOOP
9161 IF g_debug_mode = 'Y' THEN
9162 log_message(p_msg_token1 => 'opened the update_burden_rows cursor ');
9163 End if;
9164 g_tab_bc_packet_id.delete;
9165 g_tab_r_result_code.delete;
9166 g_tab_rg_result_code.delete;
9167 g_tab_t_result_code.delete;
9168 g_tab_tt_result_code.delete;
9169 g_tab_p_result_code.delete;
9170 g_tab_p_acct_result_code.delete;
9171 FETCH update_burden_rows BULK COLLECT INTO
9172 g_tab_bc_packet_id,
9173 g_tab_result_code,
9174 g_tab_r_result_code,
9175 g_tab_rg_result_code,
9176 g_tab_t_result_code,
9177 g_tab_tt_result_code,
9178 g_tab_p_result_code,
9179 g_tab_p_acct_result_code
9180 LIMIT l_num_rows;
9181 IF NOT g_tab_bc_packet_id.EXISTS(1) then
9182 IF g_debug_mode = 'Y' THEN
9183 log_message(p_msg_token1 => 'no rows found ');
9184 End if;
9185 EXIT;
9186 END IF;
9187 IF g_debug_mode = 'Y' THEN
9188 log_message(p_msg_token1 => 'calling FORALL stagtment');
9189 End if;
9190 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
9191 -- error msg : 'F116 = Transaction failed funds check because of Raw';
9192 UPDATE pa_bc_packets
9193 --SET result_code = 'F116' the line is commented out NOCOPY as the user need not be shown
9194 -- difference between raw and burden
9195 SET result_code = g_tab_result_code(i),
9196 res_result_code = g_tab_r_result_code(i),
9197 res_grp_result_code = g_tab_rg_result_code(i),
9198 task_result_code = g_tab_t_result_code(i),
9199 top_task_result_code = g_tab_tt_result_code(i),
9200 project_result_code = g_tab_p_result_code(i),
9201 project_acct_result_code = g_tab_p_acct_result_code(i)
9202 WHERE packet_id = p_packet_id
9203 AND parent_bc_packet_id = g_tab_bc_packet_id(i)
9204 AND nvl(substr(result_code,1,1),'P') in ('P','A');
9205 -- end of for all
9206 COMMIT;
9207
9208 EXIT when update_burden_rows%NOTFOUND ;
9209
9210 END LOOP;
9211 CLOSE update_burden_rows;
9212 IF g_debug_mode = 'Y' THEN
9213 log_message(p_msg_token1 => 'end of update_burden_rows cursor');
9214 End if;
9215 commit;
9216
9217 EXCEPTION
9218
9219 WHEN OTHERS THEN
9220 if update_burden_rows%ISOPEN THEN
9221 close update_burden_rows ;
9222 End if;
9223 IF g_debug_mode = 'Y' THEN
9224 log_message(p_msg_token1 => 'Exception portion in result_code_update_burden api');
9225 End if;
9226 x_return_status := 'T';
9227 RETURN;
9228
9229 END result_code_update_burden;
9230
9231 -- This api synchronizes the raw lines with burden lines
9232 -- if the raw transaction passes but the burden transaction fails
9233 -- the update the bc_packet set the staus of raw transaction as failed
9234
9235 PROCEDURE result_code_update_raw
9236 (p_packet_id IN NUMBER,
9237 x_return_status OUT NOCOPY VARCHAR2 )IS
9238 PRAGMA AUTONOMOUS_TRANSACTION;
9239 CURSOR update_raw_rows IS
9240 SELECT a.parent_bc_packet_id,
9241 a.result_code,
9242 a.res_result_code,
9243 a.res_grp_result_code,
9244 a.task_result_code,
9245 a.top_task_result_code,
9246 a.project_result_code,
9247 a.project_acct_result_code
9248 FROM pa_bc_packets a,
9249 pa_bc_packets b
9250 WHERE a.packet_id = p_packet_id
9251 AND nvl(SUBSTR ( a.result_code,1,1),'P') in ('R','F')
9252 AND a.parent_bc_packet_id IS NOT NULL
9253 ANd a.packet_id = b.packet_id
9254 AND b.bc_packet_id = a.parent_bc_packet_id
9255 AND nvl(substr(b.result_code,1,1),'P') in ('A','P');
9256 l_num_rows NUMBER:=200;
9257
9258
9259 BEGIN
9260
9261 IF g_debug_mode = 'Y' THEN
9262 log_message(p_msg_token1 => 'Indide result_code_update_raw api ');
9263 End if;
9264
9265 OPEN update_raw_rows; LOOP
9266 IF g_debug_mode = 'Y' THEN
9267 log_message(p_msg_token1 => 'opened the cursor update_raw_rows cursor');
9268 End if;
9269 g_tab_p_bc_packet_id.delete;
9270 g_tab_r_result_code.delete;
9271 g_tab_rg_result_code.delete;
9272 g_tab_t_result_code.delete;
9273 g_tab_tt_result_code.delete;
9274 g_tab_p_result_code.delete;
9275 g_tab_p_acct_result_code.delete;
9276 FETCH update_raw_rows BULK COLLECT INTO
9277 g_tab_p_bc_packet_id,
9278 g_tab_result_code,
9279 g_tab_r_result_code,
9280 g_tab_rg_result_code,
9281 g_tab_t_result_code,
9282 g_tab_tt_result_code,
9283 g_tab_p_result_code,
9284 g_tab_p_acct_result_code
9285 LIMIT l_num_rows;
9286 IF NOT g_tab_p_bc_packet_id.EXISTS(1) then
9287 IF g_debug_mode = 'Y' THEN
9288 log_message(p_msg_token1 => 'no rows found ');
9289 End if;
9290 EXIT;
9291 END IF;
9292 IF g_debug_mode = 'Y' THEN
9293 log_message(p_msg_token1 => 'calling FORALL statment');
9294 End if;
9295 FORALL i IN g_tab_p_bc_packet_id.FIRST .. g_tab_p_bc_packet_id.LAST
9296 -- Error msg : 'F115 = Transaction failed funds check because of Burden';
9297 UPDATE pa_bc_packets
9298 --SET result_code = 'F115'
9299 SET result_code = g_tab_result_code(i),
9300 res_result_code = g_tab_r_result_code(i),
9301 res_grp_result_code = g_tab_rg_result_code(i),
9302 task_result_code = g_tab_t_result_code(i),
9303 top_task_result_code = g_tab_tt_result_code(i),
9304 project_result_code = g_tab_p_result_code(i),
9305 project_acct_result_code = g_tab_p_acct_result_code(i)
9306 WHERE packet_id = p_packet_id
9307 AND bc_packet_id = g_tab_p_bc_packet_id(i)
9308 AND nvl(substr(result_code,1,1),'P') in ('A','P');
9309 -- end of forall loop
9310 COMMIT;
9311
9312 EXIT WHEN update_raw_rows%NOTFOUND;
9313 END LOOP;
9314 CLOSE update_raw_rows;
9315 IF g_debug_mode = 'Y' THEN
9316 log_message(p_msg_token1 => 'end of update_raw_rows api ');
9317 End if;
9318
9319 commit;
9320 EXCEPTION
9321
9322 WHEN OTHERS THEN
9323 if update_raw_rows%ISOPEN THEN
9324 close update_raw_rows ;
9325 End if;
9326 IF g_debug_mode = 'Y' THEN
9327 log_message(p_msg_token1 => 'exception in result_code_update_raw api ');
9328 End if;
9329 x_return_status := 'T';
9330 RETURN;
9331
9332
9333 END result_code_update_raw;
9334
9335 -- This api ensures that all the transactions are passed at documnet header
9336 -- level whether it is full mode or partial mode
9337 PROCEDURE update_trxn_doc_levl
9338 (p_packet_id IN NUMBER,
9339 p_mode IN VARCHAR2,
9340 p_calling_module IN VARCHAR2,
9341 x_return_status OUT NOCOPY VARCHAR2) IS
9342 PRAGMA AUTONOMOUS_TRANSACTION;
9343
9344 CURSOR update_headers IS
9345 SELECT document_header_id,
9346 document_line_id,
9347 exp_item_id,
9348 result_code
9349 FROM pa_bc_packets
9350 WHERE packet_id = p_packet_id
9351 AND nvl(substr(result_code,1,1),'P') in ('F','R');
9352
9353 l_num_rows NUMBER := 200;
9354 BEGIN
9355 -- Initialize the error stack
9356 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.update_trxn_doc_levl');
9357
9358 --reset the return status
9359 x_return_status := 'S';
9360 IF g_debug_mode = 'Y' THEN
9361 log_message(p_msg_token1 => 'inside the update_trxn_doc_levl api');
9362 End if;
9363 IF p_calling_module in ('DISTBTC','CBC','TRXNIMPORT','DISTVIADJ','DISTERADJ','EXPENDITURE','TRXIMPORT','DISTCWKST') then
9364
9365 OPEN update_headers; LOOP
9366 IF g_debug_mode = 'Y' THEN
9367 log_message(p_msg_token1 => 'opened the update_headers cursor ');
9368 End if;
9369 g_tab_doc_header_id.delete;
9370 g_tab_doc_line_id.delete;
9371 g_tab_exp_item_id.delete;
9372 g_tab_result_code.delete;
9373 FETCH update_headers BULK COLLECT INTO
9374 g_tab_doc_header_id,
9375 g_tab_doc_line_id,
9376 g_tab_exp_item_id,
9377 g_tab_result_code LIMIT l_num_rows;
9378 IF NOT g_tab_doc_header_id.EXISTS(1) then
9379 IF g_debug_mode = 'Y' THEN
9380 log_message(p_msg_token1 => 'no rows found ');
9381 End if;
9382 EXIT;
9383 END IF;
9384 IF g_debug_mode = 'Y' THEN
9385 log_message(p_msg_token1 => 'calling FORALL statement count['||g_tab_doc_header_id.count||']');
9386 End if;
9387 FORALL i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST
9388 -- Error msg : F117 = Transaction failed due to adjusted cdls
9389 UPDATE pa_bc_packets
9390 SET result_code = decode(substr(nvl(result_code,'P'),1,1),'P',
9391 decode(p_calling_module,'CBC',g_tab_result_code(i),'F117'),result_code)
9392 WHERE packet_id = p_packet_id
9393 AND ( (document_header_id = g_tab_doc_header_id(i)
9394 and document_type in ('EXP','AP','CC_P_PAY','CC_C_PAY','CC_C_CO','CC_P_CO')
9395 and p_calling_module in ('DISTBTC','CBC','DISTVIADJ','TRXIMPORT','DISTERADJ')
9396 )
9397 OR
9398 (p_calling_module = 'DISTCWKST'
9399 and document_line_id = g_tab_doc_line_id(i)
9400 and exp_item_id = g_tab_exp_item_id(i)
9401 and document_type in ('PO','EXP')
9402 )
9403 )
9404 AND nvl(substr(result_code,1,1),'P') in ('P','A');
9405
9406 IF g_debug_mode = 'Y' THEN
9407 log_message(p_msg_token1 => 'Num of Rows updated['||sql%rowcount||']');
9408 End if;
9409 EXIT WHEN update_headers%NOTFOUND ;
9410 END LOOP;
9411 CLOSE update_headers;
9412 IF g_debug_mode = 'Y' THEN
9413 log_message(p_msg_token1 => 'end of update_headers cursor');
9414 End if;
9415 COMMIT;
9416 END IF;
9417 COMMIT;
9418 EXCEPTION
9419 when others then
9420 IF update_headers%ISOPEN THEN
9421 close update_headers;
9422 End IF;
9423 IF g_debug_mode = 'Y' THEN
9424 log_message(p_msg_token1 => 'exception in update_trxn_doc_levl api ');
9425 End if;
9426 log_message(p_error_msg => sqlcode||sqlerrm);
9427 x_return_status := 'T';
9428 RETURN;
9429
9430 END update_trxn_doc_levl;
9431 -- This api syncronizes the raw and burden lines
9432 -- if the burden line pass but raw line fails then burden transaction
9433 -- will be marked as failed
9434 PROCEDURE sync_raw_burden
9435 (p_packet_id IN NUMBER,
9436 p_mode IN VARCHAR2,
9437 p_calling_module IN VARCHAR2,
9438 x_return_status OUT NOCOPY VARCHAR2) IS
9439
9440 BEGIN
9441 -- call for update the burden transaction with failure status
9442 IF g_debug_mode = 'Y' THEN
9443 log_message(p_msg_token1 => 'Calling result_code_update_burden api ');
9444 End if;
9445 result_code_update_burden
9446 (p_packet_id => p_packet_id,
9447 x_return_status => x_return_status);
9448 -- call for update of the raw transaction with the failure status
9449 IF g_debug_mode = 'Y' THEN
9450 log_message(p_msg_token1 => 'Calling result_code_update_raw api ');
9451 End if;
9452 result_code_update_raw
9453 (p_packet_id => p_packet_id,
9454 x_return_status => x_return_status);
9455 IF g_debug_mode = 'Y' THEN
9456 log_message(p_msg_token1 => 'After result_code_update_raw api call');
9457 End if;
9458
9459 --call for update at the ei level if ei is a adjusted cdls
9460 IF g_debug_mode = 'Y' THEN
9461 log_message(p_msg_token1 => 'Calling update_trxn_doc_levl api ');
9462 End if;
9463
9464 update_trxn_doc_levl
9465 (p_packet_id => p_packet_id,
9466 p_mode => p_mode,
9467 p_calling_module => p_calling_module,
9468 x_return_status => x_return_status);
9469 IF g_debug_mode = 'Y' THEN
9470 log_message(p_msg_token1 => 'After update_trxn_doc_levl api call');
9471 End if;
9472
9473 EXCEPTION
9474 when others then
9475 IF g_debug_mode = 'Y' THEN
9476 log_message(p_msg_token1 => 'failed in sync raw burden api SQLERROR:'||sqlcode||sqlerrm);
9477 End if;
9478 --commit;
9479 RAISE;
9480
9481 END sync_raw_burden;
9482 --------------------------------------------------------------------
9483 -- This api check whether the base line is progress for the given
9484 -- project
9485 --------------------------------------------------------------------
9486 FUNCTION is_baseline_progress(p_project_id number)
9487 return varchar2 IS
9488
9489 l_status_flag varchar2(1) := 'N';
9490 l_wf_status varchar2(25) := null;
9491
9492 cursor check_bdgt_baseline is
9493 SELECT wf_status_code
9494 FROM pa_budget_versions
9495 WHERE project_id = p_project_id
9496 AND wf_status_code is NOT NULL;
9497
9498
9499
9500 BEGIN
9501 IF g_debug_mode = 'Y' THEN
9502 log_message(p_msg_token1 =>' Inside the is_baselinei_progress api');
9503 End if;
9504 OPEN check_bdgt_baseline;
9505 LOOP
9506 FETCH check_bdgt_baseline INTO l_wf_status;
9507 EXIT WHEN check_bdgt_baseline%NOTFOUND;
9508 IF g_debug_mode = 'Y' THEN
9509 log_message(p_msg_token1 => 'WF_STATUS_CODE ='||l_wf_status);
9510 End if;
9511 IF l_wf_status = 'IN_ROUTE' then
9512 -- ie the budget is under baselineing for this project
9513 l_status_flag := 'Y';
9514 EXIT;
9515 END IF;
9516 END LOOP;
9517 CLOSE check_bdgt_baseline;
9518
9519 If check_bdgt_baseline%ISOPEN then
9520 close check_bdgt_baseline;
9521 End if;
9522
9523
9524 RETURN l_status_flag;
9525 EXCEPTION
9526 WHEN OTHERS THEN
9527 If check_bdgt_baseline%ISOPEN then
9528 close check_bdgt_baseline;
9529 End if;
9530 RAISE;
9531
9532 END is_baseline_progress;
9533
9534 -----------------------------------------------------------------------------------------------+
9535 -- This procedure is the autonomous version of status_code_udpate. Basically, this procedure
9536 -- will call status_code_update
9537 -- main procedure status_code_update is being made non-autonomous
9538 -----------------------------------------------------------------------------------------------+
9539 PROCEDURE status_code_update_autonomous (
9540 p_calling_module IN VARCHAR2,
9541 p_packet_id IN NUMBER,
9542 p_mode IN VARCHAR2,
9543 p_partial IN VARCHAR2 DEFAULT 'N',
9544 p_packet_status IN VARCHAR2 DEFAULT 'S',
9545 x_return_status OUT NOCOPY varchar2 )
9546 IS
9547 PRAGMA AUTONOMOUS_TRANSACTION;
9548 BEGIN
9549
9550 status_code_update (
9551 p_calling_module => p_calling_module,
9552 p_packet_id => p_packet_id,
9553 p_mode => p_mode,
9554 p_partial => p_partial,
9555 p_packet_status => p_packet_status,
9556 x_return_status => x_return_status);
9557 COMMIT;
9558
9559 End status_code_update_autonomous;
9560
9561 --------------------------------------------------------------------------------------------
9562 -- This api updates the status of bc packets based on the result code
9563 -- and calling mode and partial flag
9564 -- The valid status code values are
9565 -- A - Approved
9566 -- B - Base lined -- Intermediate status (r12 on - not used)
9567 -- R - Rejected
9568 -- C - Checked -- Intermediate status (r12 on - not used)
9569 -- F - Failed Check
9570 -- S - Passed Check
9571 -- E - Error
9572 -- T - Fatal
9573 -- V - Vendor Invoice - Intermediate status to avoid sweeper to pick
9574 -- L - Intermediate status for Expense report to liquidate but avoid sweeper to pick
9575 -- I - Intermedidate status in which commitment records will be created, this will be synched
9576 -- as the first step in pa_funds_check (Added in R12)
9577 -- if the calling module is BASELINE then use BULK FETCH AND BULK
9578 -- update logic since the volume of records is more.
9579 -----------------------------------------------------------------------------------------------
9580 PROCEDURE status_code_update (
9581 p_calling_module IN VARCHAR2,
9582 p_packet_id IN NUMBER,
9583 p_mode IN VARCHAR2,
9584 p_partial IN VARCHAR2 DEFAULT 'N',
9585 p_packet_status IN VARCHAR2 DEFAULT 'S',
9586 x_return_status OUT NOCOPY varchar2 ) IS
9587
9588 -- PRAGMA AUTONOMOUS_TRANSACTION;
9589
9590 CURSOR baseline_error_status IS
9591 SELECT rowid,
9592 bc_packet_id
9593 FROM pa_bc_packets
9594 WHERE packet_id = p_packet_id
9595 AND EXISTS(
9596 SELECT 'x'
9597 FROM pa_bc_packets
9598 WHERE packet_id = p_packet_id
9599 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9600 );
9601
9602 CURSOR baseline_success_status IS
9603 SELECT rowid,
9604 bc_packet_id
9605 FROM pa_bc_packets
9606 WHERE packet_id = p_packet_id
9607 AND status_code = 'P'
9608 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P';
9609
9610 CURSOR cur_projects IS
9611 SELECT distinct project_id
9612 FROM pa_bc_packets
9613 WHERE packet_id = p_packet_id;
9614
9615 CURSOR cur_fatal_error IS
9616 SELECT bc_packet_id
9617 FROM pa_bc_packets
9618 WHERE packet_id = p_packet_id;
9619
9620 l_project_id NUMBER;
9621 l_base_line_project NUMBER;
9622 l_base_line_flag VARCHAR2(10):= 'N';
9623 l_num_rows NUMBER := 200;
9624 l_rowcount NUMBER ;
9625
9626
9627 BEGIN
9628 -- initialize the return status to success
9629 x_return_status := 'S';
9630
9631 --Initialize the err stack
9632 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.status_code_update');
9633
9634 IF g_debug_mode = 'Y' THEN
9635 log_message(p_msg_token1 =>'Inside the status code update api p_calling_module['
9636 ||p_calling_module||']packet_id['||p_packet_id||']mode['
9637 ||p_mode||']partial flag['||p_partial||']packet_status['
9638 ||p_packet_status||']');
9639 End if;
9640
9641 /** Incase of fatal error from distribute expenses report or transaction import programs
9642 * update the status code of the packets to fatal so that it will not pickup
9643 * for updating the balances
9644 */
9645 IF p_packet_status = 'T' then
9646
9647 OPEN cur_fatal_error;
9648 LOOP
9649 g_tab_bc_packet_id.delete;
9650 FETCH cur_fatal_error BULK COLLECT
9651 INTO g_tab_bc_packet_id LIMIT 300;
9652 IF NOT g_tab_bc_packet_id.EXISTS(1) then
9653 exit;
9654 END IF;
9655
9656 FORALL i IN g_tab_bc_packet_id.first .. g_tab_bc_packet_id.last
9657 UPDATE pa_bc_packets
9658 SET status_code = 'T'
9659 WHERE packet_id = p_packet_id
9660 AND bc_packet_id = g_tab_bc_packet_id(i);
9661
9662 Exit when cur_fatal_error%NOTFOUND;
9663
9664 END LOOP;
9665
9666 CLOSE cur_fatal_error;
9667 --commit; -- to end an active autonomous transaction
9668 pa_debug.reset_err_stack;
9669 RETURN;
9670
9671 END IF;
9672
9673
9674 IF p_calling_module in ('RESERVE_BASELINE') and p_mode = 'S' THEN
9675 IF g_debug_mode = 'Y' THEN
9676 log_message(p_msg_token1 =>'stage : STATUS_CODE:SUBMIT');
9677 End if;
9678 -- if the calling mode is submit and if there is any failed transaction
9679 -- the whole package is marked as E - Error other wise it is Passed check
9680 g_error_stage := 'STATUS_CODE:SUBMIT';
9681 OPEN baseline_error_status;
9682 IF g_debug_mode = 'Y' THEN
9683 log_message(p_msg_token1 => 'opened cursor baseline_error_status ');
9684 End if;
9685 LOOP
9686 g_tab_bc_packet_id.delete;
9687 FETCH baseline_error_status BULK COLLECT INTO
9688 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9689 If NOT g_tab_rowid.EXISTS(1) then
9690 IF g_debug_mode = 'Y' THEN
9691 log_message(p_msg_token1 => 'no records fetched exiting');
9692 End if;
9693 EXIT;
9694 End if;
9695 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9696 UPDATE pa_bc_packets
9697 SET status_code = 'E'
9698 WHERE packet_id = p_packet_id
9699 AND bc_packet_id = g_tab_bc_packet_id(i);
9700 --COMMIT;
9701 EXIT when baseline_error_status%NOTFOUND;
9702 END LOOP;
9703 CLOSE baseline_error_status;
9704
9705 OPEN baseline_success_status;
9706 IF g_debug_mode = 'Y' THEN
9707 log_message(p_msg_token1 => 'opened baseline_success_status cursor ');
9708 End if;
9709 LOOP
9710 g_tab_bc_packet_id.delete;
9711 FETCH baseline_success_status BULK COLLECT INTO
9712 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9713 IF NOT g_tab_rowid.EXISTS(1) then
9714 IF g_debug_mode = 'Y' THEN
9715 log_message(p_msg_token1 => 'no records fetched exiting');
9716 End if;
9717 EXIT;
9718 END IF;
9719 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9720 UPDATE pa_bc_packets
9721 SET status_code = 'S'
9722 WHERE packet_id = p_packet_id
9723 AND bc_packet_id = g_tab_bc_packet_id(i);
9724 --COMMIT;
9725 EXIT when baseline_success_status%NOTFOUND;
9726 END LOOP;
9727 CLOSE baseline_success_status;
9728
9729 ELSIF p_calling_module in ('RESERVE_BASELINE') and p_mode = 'B' THEN
9730 -- if the calling mode is Base line and if there is any failed transaction
9731 -- the whole package is marked as R - Rejected other wise it is Approved
9732 -- update the status to intermediate status of B - baseline finally the
9733 -- the base line process will udate the status to A and sweeper programm
9734 -- picks all the records
9735 g_error_stage := 'STATUS_CODE: BASELINE';
9736 IF g_debug_mode = 'Y' THEN
9737 log_message(p_msg_token1 => 'stage : STATUS_CODE: BASELINE');
9738 End if;
9739 OPEN baseline_error_status;
9740 IF g_debug_mode = 'Y' THEN
9741 log_message(p_msg_token1 => 'opened baseline_error_status cursor ');
9742 End if;
9743 LOOP
9744 g_tab_bc_packet_id.delete;
9745 FETCH baseline_error_status BULK COLLECT INTO
9746 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9747 IF NOT g_tab_rowid.EXISTS(1) then
9748 IF g_debug_mode = 'Y' THEN
9749 log_message(p_msg_token1 => 'no recrods found');
9750 End if;
9751 EXIT;
9752 END IF;
9753 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9754 UPDATE pa_bc_packets
9755 SET status_code = 'R' -- rejected
9756 WHERE packet_id = p_packet_id
9757 AND bc_packet_id = g_tab_bc_packet_id(i);
9758
9759 log_message(p_msg_token1 => 're-baseline fails [ '||sql%rowcount||' ] records updated to R');
9760 --COMMIT;
9761 EXIT when baseline_error_status%NOTFOUND;
9762 END LOOP;
9763 CLOSE baseline_error_status;
9764
9765 /* =====================================================================+
9766 || Pass code will be handled in PABBFNDB.pls
9767 || ---------------------------------------------------------------------+
9768 OPEN baseline_success_status;
9769 IF g_debug_mode = 'Y' THEN
9770 log_message(p_msg_token1 => 'opened baseline_success_status cursor ');
9771 End if;
9772 LOOP
9773 g_tab_bc_packet_id.delete;
9774 FETCH baseline_success_status BULK COLLECT INTO
9775 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9776 IF NOT g_tab_rowid.EXISTS(1) then
9777 IF g_debug_mode = 'Y' THEN
9778 log_message(p_msg_token1 => 'no recrods found');
9779 End if;
9780 EXIT;
9781 END IF;
9782 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9783 UPDATE pa_bc_packets
9784 SET status_code = 'A'
9785 WHERE packet_id = p_packet_id
9786 AND bc_packet_id = g_tab_bc_packet_id(i);
9787
9788 log_message(p_msg_token1 => 're-baseline passed [ '||sql%rowcount||' ] records updated to R');
9789 --COMMIT;
9790 EXIT when baseline_success_status%NOTFOUND;
9791 END LOOP;
9792 CLOSE baseline_success_status;
9793 IF g_debug_mode = 'Y' THEN
9794 log_message(p_msg_token1 => 'end of baseline update staus');
9795 End if;
9796 ==========================================================================+ */
9797
9798 ELSIF p_mode = 'C' THEN
9799 -- if the calling mode is Check Funds and if there is any failed transaction
9800 -- the whole package is marked as F - Failed Check other wise it is Checked - C
9801 g_error_stage := 'STATUS_CODE: CHECK FUNDS';
9802 IF g_debug_mode = 'Y' THEN
9803 log_message(p_msg_token1 => 'stage : STATUS_CODE: CHECK FUNDS');
9804 End if;
9805 IF p_partial = 'Y' THEN
9806 IF g_debug_mode = 'Y' THEN
9807 log_message(p_msg_token1 => 'p_partial = Y');
9808 End if;
9809 -- If the calling mode is Reserve and Partial flag is 'Y' then
9810 -- if there is any failed transaction then update the bc packet with
9811 -- each record as Rejected.
9812 g_error_stage := 'STATUS_CODE:RESERVE - Partial';
9813 IF g_debug_mode = 'Y' THEN
9814 log_message(p_msg_token1 => 'STATUS_CODE:RESERVE - Partial');
9815 End if;
9816 UPDATE pa_bc_packets
9817 SET status_code = DECODE ( SUBSTR (
9818 nvl(result_code,'P'), 1, 1 )
9819 , 'P', decode(status_code,'P','S',status_code)
9820 , 'F' )
9821 WHERE packet_id = p_packet_id
9822 AND status_code in ('P','L','S');
9823 l_rowcount := sql%rowcount;
9824 Elsif p_partial <> 'Y' then
9825
9826 UPDATE pa_bc_packets
9827 SET status_code = 'F'
9828 WHERE packet_id = p_packet_id
9829 AND EXISTS (SELECT 'x'
9830 FROM pa_bc_packets
9831 WHERE packet_id = p_packet_id
9832 AND ( SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9833 OR p_packet_status in ('F','R','T')
9834 ));
9835 l_rowcount := sql%rowcount;
9836
9837 If l_rowcount <= 0 then
9838 UPDATE pa_bc_packets
9839 SET status_code = 'S'
9840 WHERE packet_id = p_packet_id
9841 AND status_code in ('P','L','S')
9842 AND SUBSTR ( nvl(result_code,'P'),1,1 ) = 'P';
9843
9844 End if;
9845 End if;
9846
9847 ELSIF p_mode = 'U' THEN
9848 -- if the calling mode is Un Reserve and if there is any failed transaction
9849 -- the whole package is marked as R - Rejected other wise it is Approved
9850 -- *** The transaction which comes during baseline process to maintain data
9851 -- concurrancy the following logic is used
9852 -- check if the budget is being baseline for the project then mark the
9853 -- status of the transaction belong the particular project which is being baselined
9854 -- to intermediate status so that the baseline process picks all theses records
9855 -- and calls agian funds check process . and finally the base line process
9856 -- marks the status to approved
9857 g_error_stage := 'STATUS_CODE: UNRESERVE';
9858 IF g_debug_mode = 'Y' THEN
9859 log_message(p_msg_token1 => 'Stage : STATUS_CODE: UNRESERVE');
9860 End if;
9861
9862 UPDATE pa_bc_packets
9863 SET status_code = 'R'
9864 WHERE packet_id = p_packet_id
9865 AND EXISTS (SELECT 'x'
9866 FROM pa_bc_packets
9867 WHERE packet_id = p_packet_id
9868 AND ( SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9869 OR p_packet_status in ('F','R','T')
9870 ));
9871 l_rowcount := sql%rowcount;
9872 IF g_debug_mode = 'Y' THEN
9873 log_message(p_msg_token1 => 'no rows updated = '||l_rowcount);
9874 End if;
9875
9876 IF l_rowcount <= 0 THEN
9877 --- check the transaction is arrived during the base line process
9878 --- if so the mark the status to intermediate status
9879 OPEN cur_projects;
9880 IF g_debug_mode = 'Y' THEN
9881 log_message(p_msg_token1 => 'opened cur_project cursor');
9882 End if;
9883 LOOP
9884 FETCH cur_projects INTO l_project_id;
9885 IF g_debug_mode = 'Y' THEN
9886 log_message(p_msg_token1 => 'project id ='||l_project_id);
9887 End if;
9888 EXIT WHEN cur_projects%NOTFOUND;
9889
9890 UPDATE pa_bc_packets
9891 SET status_code = 'A'
9892 WHERE packet_id = p_packet_id
9893 AND project_id = l_project_id
9894 AND status_code in ('P')
9895 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P';
9896 END LOOP;
9897 CLOSE cur_projects;
9898 IF g_debug_mode = 'Y' THEN
9899 log_message(p_msg_token1 => 'end of cur_projects cursor ');
9900 End if;
9901
9902 END IF;
9903
9904 ELSIF p_mode in ('F','R') THEN
9905 IF g_debug_mode = 'Y' THEN
9906 log_message(p_msg_token1 => 'Stage : STATUSCODE : RESERVE');
9907 End if;
9908
9909 OPEN cur_projects;
9910 LOOP
9911 FETCH cur_projects INTO l_project_id;
9912 EXIT WHEN cur_projects%NOTFOUND;
9913
9914 IF g_debug_mode = 'Y' THEN
9915 log_message(p_msg_token1 => 'base_line_flag ='||l_base_line_flag);
9916 End if;
9917
9918 IF p_partial = 'Y' THEN
9919 -- If the calling mode is Reserve and Partial flag is 'Y' then
9920 -- if there is any failed transaction then update the bc packet with
9921 -- each record as Rejected.
9922 g_error_stage := 'STATUS_CODE:RESERVE - Partial';
9923 IF g_debug_mode = 'Y' THEN
9924 log_message(p_msg_token1 => 'STATUS_CODE:RESERVE - Partial');
9925 End if;
9926
9927 UPDATE pa_bc_packets
9928 SET status_code = DECODE ( SUBSTR (
9929 nvl(result_code,'P'), 1, 1 )
9930 , 'P', decode(status_code,'P','A',status_code)
9931 , 'R' )
9932 WHERE packet_id = p_packet_id
9933 AND project_id = l_project_id
9934 AND status_code in ('P','L');
9935 IF g_debug_mode = 'Y' THEN
9936 log_message(p_msg_token1 => 'no of rows updated ='||sql%rowcount);
9937 end if;
9938
9939 IF SQL%NOTFOUND THEN
9940 log_message (p_msg_token1 =>'Updated the status code for Partial Mode');
9941 END IF;
9942
9943 ELSE -- p_partial <> 'Y' then
9944 -- If the calling mode is Reserve and Partial flag is 'N'ie full mode then
9945 -- if there is any failed transaction then update the whole packet with Rejected
9946 g_error_stage := 'STATUS_CODE:RESERVE - Full';
9947 IF g_debug_mode = 'Y' THEN
9948 log_message(p_msg_token1 =>'STATUS_CODE:RESERVE - Full');
9949 End if;
9950
9951 UPDATE pa_bc_packets
9952 SET status_code = 'R'
9953 WHERE packet_id = p_packet_id
9954 AND project_id = l_project_id
9955 AND EXISTS (SELECT 'x'
9956 FROM pa_bc_packets
9957 WHERE packet_id = p_packet_id
9958 AND ( SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9959 OR p_packet_status in ('F','R','T')
9960 ));
9961 l_rowcount := sql%rowcount;
9962 IF g_debug_mode = 'Y' THEN
9963 log_message(p_msg_token1 =>'no of rows rejected ='||l_rowcount);
9964 End if;
9965
9966 IF l_rowcount <= 0 THEN
9967 --- check the transaction is arrived during the base line process
9968 --- if so the mark the status to intermediate status
9969
9970 UPDATE pa_bc_packets
9971 SET status_code = 'A'
9972 WHERE packet_id = p_packet_id
9973 AND project_id = l_project_id
9974 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P'
9975 AND status_code in ('P');
9976
9977 IF g_debug_mode = 'Y' THEN
9978 log_message(p_msg_token1 =>'no of rows approved ='||sql%rowcount);
9979 End if;
9980 END IF;
9981
9982 END IF; -- end if for partial flag
9983 END LOOP;
9984 CLOSE cur_projects;
9985 IF g_debug_mode = 'Y' THEN
9986 log_message(p_msg_token1 =>'end of cur project cursor ');
9987 End if;
9988 END IF; -- end if for calling mode
9989
9990
9991 --reset the error stack
9992 pa_debug.reset_err_stack;
9993 --commit; -- to end an active autonmous transaction
9994 IF cur_projects%isopen then
9995 close cur_projects;
9996 End if;
9997 IF baseline_success_status%isopen then
9998 close baseline_success_status;
9999 End if;
10000 IF baseline_error_status%isopen then
10001 close baseline_error_status;
10002 End if;
10003 return;
10004
10005 EXCEPTION
10006 WHEN OTHERS THEN
10007 IF cur_projects%isopen then
10008 close cur_projects;
10009 End if;
10010 IF baseline_success_status%isopen then
10011 close baseline_success_status;
10012 End if;
10013 IF baseline_error_status%isopen then
10014 close baseline_error_status;
10015 End if;
10016 IF cur_fatal_error%isopen then
10017 close cur_fatal_error;
10018 End if;
10019 x_return_status := 'T';
10020 IF g_debug_mode = 'Y' THEN
10021 log_message(p_msg_token1 => 'failed in status code update api SQLERR :'||sqlcode||sqlerrm);
10022 End if;
10023 RAISE;
10024 END status_code_update;
10025
10026 --------------------------------------------------------------------------------------
10027 -- this api updates the Expenditure items with status code
10028 -- if the transaction passes the funds check the gl date
10029 -- will be stampled on cdl otherwise the ei is updated with
10030 -- rejection code
10031 --------------------------------------------------------------------------
10032 PROCEDURE update_EIS (p_packet_id IN NUMBER,
10033 p_calling_module IN VARCHAR2,
10034 p_mode IN VARCHAR2,
10035 x_return_status OUT NOCOPY VARCHAR2) IS
10036 CURSOR ei_details is
10037 SELECT project_id,
10038 document_type,
10039 document_header_id,
10040 document_distribution_id,
10041 GL_DATE ,
10042 budget_ccid,
10043 proj_encumbrance_type_id,
10044 status_code,
10045 result_code,
10046 bc_packet_id,
10047 parent_bc_packet_id,
10048 res_result_code,
10049 res_grp_result_code,
10050 task_result_code,
10051 top_task_result_code,
10052 project_result_code,
10053 project_acct_result_code,
10054 accounted_dr,
10055 accounted_cr,
10056 budget_version_id,
10057 budget_line_id
10058 FROM pa_bc_packets
10059 WHERE packet_id = p_packet_id
10060 ORDER BY document_header_id,document_distribution_id,bc_packet_id;
10061
10062 l_pre_exp_item_id NUMBER := null;
10063 l_num_rows NUMBER := 200;
10064 l_tab_dist_warn_code pa_plsql_datatypes.char25tabtyp;
10065 l_warn_code varchar2(30);
10066 l_tab_warning_code pa_plsql_datatypes.char25tabtyp;
10067 l_tab_ext_bdgt_flag pa_plsql_datatypes.char25tabtyp;
10068 j NUMBER;
10069 l_doc_header_id pa_bc_packets.document_header_id%type;
10070 l_pre_project_id pa_bc_packets.project_id%type := null;
10071 l_count NUMBER;
10072 l_ext_bdgt_type VARCHAR2(25) := null;
10073 l_ext_bdgt_link VARCHAR2(25) := null;
10074 L_PRE_EXT_BDGT_TYPE VARCHAR2(25) := null;
10075
10076 BEGIN
10077
10078 --Initialize the error stack
10079 pa_debug.init_err_stack('PA_FUNDS_CONTROL_PKG.update_EIS');
10080
10081 -- initialize the return status
10082 x_return_status := 'S';
10083 IF g_debug_mode = 'Y' THEN
10084 log_message(p_msg_token1 => 'Inside the Update EIS api');
10085 log_message(p_msg_token1 => 'p_calling_module='||p_calling_module);
10086 log_message(p_msg_token1 => 'p_mode='||p_mode);
10087 End if;
10088 -- update the ei with rejection code if the transaction fails during funds check
10089 -- else stamp GL_DATE on the cdl for all funds check passed transaction
10090 IF p_calling_module in ('DISTBTC','EXPENDITURE','DISTVIADJ','DISTERADJ','INTERFACVI','INTERFACER','DISTCWKST') then
10091 IF g_debug_mode = 'Y' THEN
10092 log_message(p_msg_token1 => 'Inside the Update EIS api');
10093 End if;
10094 IF p_mode in ('R','U','C') then
10095 OPEN ei_details;
10096 LOOP
10097 g_tab_project_id.delete;
10098 g_tab_doc_type.delete;
10099 g_tab_doc_header_id.delete;
10100 g_tab_doc_distribution_id.delete;
10101 g_tab_gl_date.delete;
10102 g_tab_budget_ccid.delete;
10103 g_tab_encum_type_id.delete;
10104 g_tab_status_code.delete;
10105 g_tab_result_code.delete;
10106 g_tab_bc_packet_id.delete;
10107 g_tab_p_bc_packet_id.delete;
10108 g_tab_r_result_code.delete;
10109 g_tab_rg_result_code.delete;
10110 g_tab_t_result_code.delete;
10111 g_tab_tt_result_code.delete;
10112 g_tab_p_result_code.delete;
10113 g_tab_p_acct_result_code.delete;
10114 l_tab_dist_warn_code.delete;
10115 l_tab_warning_code.delete;
10116 g_tab_accounted_dr.delete;
10117 g_tab_accounted_cr.delete;
10118 l_tab_ext_bdgt_flag.delete;
10119 g_tab_budget_version_id.delete;
10120 g_tab_budget_line_id.delete;
10121 FETCH ei_details BULK COLLECT INTO
10122 g_tab_project_id,
10123 g_tab_doc_type,
10124 g_tab_doc_header_id,
10125 g_tab_doc_distribution_id,
10126 g_tab_gl_date,
10127 g_tab_budget_ccid,
10128 g_tab_encum_type_id,
10129 g_tab_status_code,
10130 g_tab_result_code,
10131 g_tab_bc_packet_id,
10132 g_tab_p_bc_packet_id,
10133 g_tab_r_result_code,
10134 g_tab_rg_result_code,
10135 g_tab_t_result_code,
10136 g_tab_tt_result_code,
10137 g_tab_p_result_code,
10138 g_tab_p_acct_result_code,
10139 g_tab_accounted_dr,
10140 g_tab_accounted_cr,
10141 g_tab_budget_version_id,
10142 g_tab_budget_line_id LIMIT l_num_rows;
10143 IF NOT g_tab_doc_header_id.EXISTS(1) then
10144 EXIT;
10145 END IF;
10146
10147 FOR i IN g_tab_doc_type.FIRST .. g_tab_doc_type.LAST LOOP
10148
10149 If g_tab_doc_type(i) in ('CC_C_PAY','CC_P_PAY','AP'
10150 ,'PO','REQ','EXP') THEN
10151 l_ext_bdgt_type := 'STD';
10152 Elsif g_tab_doc_type(i) in ('CC_C_CO','CC_P_CO') then
10153 l_ext_bdgt_type := 'CBC';
10154 End if;
10155
10156 If (l_pre_project_id is NULL or l_pre_project_id
10157 <> g_tab_project_id(i)) OR
10158 (l_pre_ext_bdgt_type is NULL or l_pre_ext_bdgt_type <>
10159 l_ext_bdgt_type ) then
10160
10161 l_ext_bdgt_link := PA_FUNDS_CONTROL_UTILS.get_bdgt_link(
10162 p_project_id => g_tab_project_id(i),
10163 p_calling_mode => l_ext_bdgt_type );
10164
10165
10166 END IF;
10167
10168 l_tab_ext_bdgt_flag(i) := l_ext_bdgt_link;
10169
10170 l_pre_project_id := g_tab_project_id(i);
10171 l_pre_ext_bdgt_type := l_ext_bdgt_type;
10172
10173 END LOOP;
10174 IF g_debug_mode = 'Y' THEN
10175 log_message(p_msg_token1 => 'Check for the Advisory Warnings ');
10176 End if;
10177
10178 FOR i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST LOOP
10179 l_tab_dist_warn_code(i) := 'P';
10180
10181 If substr(g_tab_result_code(i),1,1) = 'P' then
10182 IF g_tab_r_result_code(i) = 'P112' then
10183 l_tab_dist_warn_code(i) := 'P112';
10184 Elsif g_tab_rg_result_code(i) = 'P110' and
10185 l_tab_dist_warn_code(i) <> 'P112' then
10186 l_tab_dist_warn_code(i) := 'P110';
10187 Elsif g_tab_t_result_code(i) = 'P108' and
10188 l_tab_dist_warn_code(i) NOT IN ('P112','P110') then
10189 l_tab_dist_warn_code(i) := 'P108';
10190 Elsif g_tab_tt_result_code(i) = 'P106' and
10191 l_tab_dist_warn_code(i) NOT IN ('P112','P110','P108') then
10192 l_tab_dist_warn_code(i) := 'P106';
10193 Elsif g_tab_p_result_code(i) = 'P104' and
10194 l_tab_dist_warn_code(i) NOT IN ('P112','P110','P108','P106') then
10195 l_tab_dist_warn_code(i) := 'P104';
10196 End if;
10197 Else
10198 l_tab_dist_warn_code(i) := null;
10199 End if;
10200 If l_tab_dist_warn_code(i) NOT IN
10201 ('P112','P110','P108','P106','P104') then
10202 l_tab_dist_warn_code(i) := null;
10203 End if;
10204
10205 END LOOP;
10206
10207
10208 l_count := 0;
10209
10210 FOR i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST LOOP
10211 l_count := l_count + 1;
10212 If substr(g_tab_result_code(i),1,1) = 'P' then
10213 If g_tab_doc_header_id(i) <> l_doc_header_id OR
10214 l_doc_header_id is NULL then
10215 j := l_count;
10216 l_warn_code := 'P';
10217 LOOP -- through all cdls lines
10218 If NOT g_tab_doc_header_id.exists(j) then
10219 Exit;
10220 End if;
10221 If g_tab_doc_header_id(i) = g_tab_doc_header_id(j) then
10222 If substr(g_tab_result_code(i),1,1) = 'P' then
10223 IF l_tab_dist_warn_code(j) = 'P112' then
10224 l_warn_code := 'P112';
10225 Exit;
10226 Elsif l_tab_dist_warn_code(j) = 'P110' and
10227 l_warn_code <> 'P112' then
10228 l_warn_code := 'P110';
10229 Elsif l_tab_dist_warn_code(j) = 'P108' and
10230 l_warn_code NOT IN ('P112','P110') then
10231 l_warn_code := 'P108';
10232 Elsif l_tab_dist_warn_code(j) = 'P106' and
10233 l_warn_code NOT IN
10234 ('P112','P110','P108') then
10235 l_warn_code := 'P106';
10236 Elsif l_tab_dist_warn_code(j) = 'P104' and
10237 l_warn_code NOT IN
10238 ('P112','P110','P108','P106') then
10239 l_warn_code := 'P104';
10240 End if;
10241 End if;
10242 Else
10243 exit;
10244 End if;
10245 j := j + 1;
10246
10247 END LOOP;
10248 l_tab_warning_code(i) := l_warn_code;
10249 If l_tab_warning_code(i) NOT IN
10250 ('P112','P110','P108','P106','P104') then
10251 l_tab_warning_code(i) := null;
10252 End if;
10253 l_doc_header_id := g_tab_doc_header_id(i);
10254
10255 Else
10256 l_tab_warning_code(i) := l_warn_code;
10257 If l_tab_warning_code(i) NOT IN
10258 ('P112','P110','P108','P106','P104') then
10259 l_tab_warning_code(i) := null;
10260 End if;
10261 End If;
10262 Else -- for result code fail
10263 l_tab_warning_code(i) := null;
10264 End if;
10265
10266 END LOOP;
10267 -- update ei with cost dist rejection code if there is failed funds check
10268 -- and update ei with cost dist warning code for transaction with
10269 -- advisory warnings.
10270 IF g_debug_mode = 'Y' THEN
10271 log_message(p_msg_token1 => 'Calling FORALL update for EI');
10272 End if;
10273 /*=========================================================+
10274 | Bug 3565708: Added g_tab_p_bc_packet_id(i) = -7777 ; so |
10275 | rejection would include BTC txns also. |
10276 +=========================================================*/
10277 FORALL i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST
10278 UPDATE pa_expenditure_items_all
10279 SET cost_dist_rejection_code =
10280 decode(substr(g_tab_result_code(i),1,1),'F',
10281 g_tab_result_code(i),null)
10282 ,cost_dist_warning_code = l_tab_warning_code(i)
10283 WHERE expenditure_item_id = g_tab_doc_header_id(i)
10284 AND (g_tab_p_bc_packet_id(i) is NULL OR g_tab_p_bc_packet_id(i) = -7777 );
10285 IF g_debug_mode = 'Y' THEN
10286 log_message(p_msg_token1 => 'Calling FORALL update for CDL');
10287 End if;
10288 -- If the transaction passes the fundscheck then update the
10289 -- cdls with gl_date,encumbrance type id, budget ccid and
10290 -- encumbrance amount for the R line .updating C and D lines
10291 -- will be done in Distribute Burden transaction process
10292 FORALL i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST
10293 UPDATE pa_cost_distribution_lines_all
10294 SET --gl_date = g_tab_gl_date(i)
10295 budget_ccid = g_tab_budget_ccid(i)
10296 ,budget_version_id = g_tab_budget_version_id(i)
10297 ,budget_line_id = g_tab_budget_line_id(i)
10298 ,liquidate_encum_flag = 'Y'
10299 ,encumbrance_type_id = g_tab_encum_type_id(i)
10300 ,encumbrance_amount = nvl(g_tab_accounted_dr(i),0) -
10301 nvl(g_tab_accounted_cr(i),0)
10302 WHERE expenditure_item_id = g_tab_doc_header_id(i)
10303 AND line_num = g_tab_doc_distribution_id(i)
10304 AND line_type = 'R'
10305 AND g_tab_p_bc_packet_id(i) is null
10306 AND l_tab_ext_bdgt_flag(i) = 'Y'
10307 AND substr(nvl(g_tab_result_code(i),'P'),1,1) = 'P';
10308
10309 EXIT WHEN ei_details%NOTFOUND;
10310 IF g_debug_mode = 'Y' THEN
10311 log_message(p_msg_token1 => 'end of FORALL update for CDL');
10312 End if;
10313 END LOOP;
10314 END IF;
10315
10316 END IF;
10317 pa_debug.reset_err_stack;
10318
10319 Return;
10320 EXCEPTION
10321 WHEN OTHERS THEN
10322 x_return_status := 'T';
10323 IF g_debug_mode = 'Y' THEN
10324 log_message(p_msg_token1 => 'SQLERR :'||sqlcode||sqlerrm|| 'failed in update_EIS api');
10325 End if;
10326 log_message(p_error_msg => sqlcode||sqlerrm);
10327 Raise;
10328 END update_EIS;
10329 ------------------------------------------------------------
10330 -- This api posts the encumbrance liqudation entries and
10331 -- updates the budget account balances when there is
10332 -- link with the std budget
10333 -----------------------------------------------------------
10334 PROCEDURE upd_bdgt_encum_bal(
10335 p_packet_id IN NUMBER,
10336 p_calling_module IN VARCHAR2,
10337 p_mode IN VARCHAR2,
10338 p_packet_status IN VARCHAR2,
10339 x_return_status OUT NOCOPY VARCHAR2) IS
10340
10341 CURSOR bdgt_encum_details is
10342 SELECT project_id,
10343 budget_version_id,
10344 budget_ccid,
10345 period_name,
10346 sum(nvl(accounted_dr,0)),
10347 sum(nvl(accounted_cr,0))
10348 FROM pa_bc_packets
10349 WHERE packet_id = p_packet_id
10350 AND substr(nvl(result_code,'P'),1,1) = 'P'
10351 AND status_code = 'A'
10352 AND NVL(ext_bdgt_flag,'N') = 'Y' /*PAM changes */
10353 GROUP BY project_id,
10354 budget_version_id,
10355 budget_ccid,
10356 period_name
10357 ORDER BY project_id,
10358 budget_version_id,
10359 budget_ccid,
10360 period_name;
10361
10362 l_num_rows NUMBER := 200;
10363 l_error_msg_code VARCHAR2(1000);
10364 l_return_status VARCHAR2(100);
10365 l_msg_count NUMBER;
10366 l_debug_stage varchar2(10000);
10367 l_bdgt_acct_amt Number;
10368
10369 BEGIN
10370 g_debug_mode := 'Y';
10371 --Initialize the error stack
10372 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.upd_bdgt_encum_bal');
10373 IF g_debug_mode = 'Y' THEN
10374 log_message(p_msg_token1 => 'inside the update budget acct api'||
10375 'calling module ['||p_calling_module||']p_mode ['||p_mode||
10376 ']p_packet_status ['||p_packet_status ||']' );
10377 End if;
10378
10379 x_return_status := 'S';
10380
10381 IF p_packet_status = 'S' and p_mode in ('R','U','F') then
10382
10383 OPEN bdgt_encum_details;
10384 LOOP
10385 g_tab_project_id.delete;
10386 g_tab_budget_version_id.delete;
10387 g_tab_budget_ccid.delete;
10388 g_tab_period_name.delete;
10389 g_tab_accounted_dr.delete;
10390 g_tab_accounted_cr.delete;
10391 g_tab_encum_type_id.delete;
10392 g_tab_gl_date.delete;
10393 g_tab_doc_type.delete;
10394
10395 FETCH bdgt_encum_details BULK COLLECT INTO
10396 g_tab_project_id,
10397 g_tab_budget_version_id,
10398 g_tab_budget_ccid,
10399 g_tab_period_name,
10400 g_tab_accounted_dr,
10401 g_tab_accounted_cr LIMIT l_num_rows;
10402 IF g_debug_mode = 'Y' THEN
10403 log_message(p_msg_token1 => 'fetched rows['||g_tab_project_id.count||']into plsql tables ');
10404 End if;
10405 IF NOT g_tab_project_id.EXISTS(1) then
10406 IF g_debug_mode = 'Y' THEN
10407 log_message(p_msg_token1 => 'No rows found exit ');
10408 End if;
10409 EXIT;
10410 END IF;
10411 log_message(p_msg_token1 => 'Calling UPD_BDGT_ACCT_BAL api in Loop');
10412 FOR i IN g_tab_budget_ccid.FIRST .. g_tab_budget_ccid.LAST LOOP
10413 l_bdgt_acct_amt := (nvl(g_tab_accounted_dr(i),0) - nvl(g_tab_accounted_cr(i),0));
10414 IF g_debug_mode = 'Y' THEN
10415 log_message(p_msg_token1 => 'calling pa_budget_fund_pkg.UPD_BDGT_ACCT_BAL api ');
10416 l_debug_stage := 'p_gl_period_name ['||g_tab_period_name(i)||']p_budget_version_id [';
10417 l_debug_stage := l_debug_stage||g_tab_budget_version_id(i)||']p_ccid [';
10418 l_debug_stage := l_debug_stage||g_tab_budget_ccid(i)||']p_amount [';
10419 l_debug_stage := l_debug_stage||l_bdgt_acct_amt||']' ;
10420 log_message(p_msg_token1 => l_debug_stage);
10421 End if;
10422 If NVL(l_bdgt_acct_amt,0) <> 0 Then
10423 pa_budget_fund_pkg.UPD_BDGT_ACCT_BAL
10424 (p_gl_period_name => g_tab_period_name(i),
10425 p_budget_version_id => g_tab_budget_version_id(i),
10426 p_ccid => g_tab_budget_ccid(i),
10427 p_amount => l_bdgt_acct_amt,
10428 x_msg_data => l_error_msg_code,
10429 x_msg_count => l_msg_count,
10430 x_return_status => l_return_status
10431 );
10432 End if;
10433 IF g_debug_mode = 'Y' THEN
10434 log_message(p_msg_token1 => 'end of UPD_BDGT_ACCT_BAL apirestun status ='||l_return_status);
10435 End if;
10436
10437 END LOOP;
10438 --COMMIT;
10439 EXIT WHEN bdgt_encum_details%NOTFOUND;
10440 END LOOP;
10441 CLOSE bdgt_encum_details;
10442
10443 END IF; -- end if for packet status
10444
10445 pa_debug.reset_err_stack;
10446
10447 RETURN;
10448
10449 EXCEPTION
10450 when others then
10451 IF bdgt_encum_details%isopen then
10452 close bdgt_encum_details;
10453 END IF;
10454 x_return_status := 'T';
10455 result_status_code_update
10456 (p_packet_id => p_packet_id,
10457 p_result_code => 'F162',
10458 p_res_result_code => 'F162',
10459 p_res_grp_result_code => 'F162',
10460 p_task_result_code => 'F162',
10461 p_top_task_result_code => 'F162',
10462 p_project_result_code => 'F162',
10463 p_proj_acct_result_code => 'F162',
10464 p_status_code => 'T');
10465 If g_debug_mode = 'Y' Then
10466 log_message(p_msg_token1 => 'failed in upd bdgt encum bal api SQLERR :'||sqlcode||sqlerrm);
10467 End if;
10468 Raise;
10469 END upd_bdgt_encum_bal;
10470
10471 -------->6599207 ------As part of CC Enhancements
10472 PROCEDURE create_liqd_entry
10473 (p_packet_id IN NUMBER,
10474 p_calling_module IN varchar2,
10475 p_reference2 IN varchar2,
10476 p_reference1 IN varchar2,
10477 p_mode IN varchar2,
10478 p_packet_status IN varchar2,
10479 x_return_status OUT NOCOPY varchar2) IS
10480
10481 l_max_batch_line_id number(10);
10482
10483 BEGIN
10484 --Initialize the error stack
10485 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.create_liqd_entry');
10486
10487 x_return_status := 'S';
10488 If g_debug_mode = 'Y' Then
10489 log_message(p_msg_token1 => 'Inside the create_liqd_entry api ');
10490 End if;
10491 /** Bug fix : 1900229 During Check mode also insert liquidation and burden transaction
10492 * to gl_bc_packets and igc_cc_interface tables
10493 */
10494 IF g_debug_mode = 'Y' THEN
10495 log_message(p_msg_token1 => 'p_calling_module'||p_calling_module||' p_mode= '||p_mode);
10496 End if;
10497
10498 IF p_calling_module = 'CBC' and p_mode in ('R','U','C','F') then
10499
10500 SELECT nvl(MAX(batch_line_num),0)
10501 INTO l_max_batch_line_id
10502 FROM igc_cc_interface
10503 WHERE document_type = 'CC'
10504 AND cc_header_id = p_reference2;
10505
10506
10507 INSERT INTO igc_cc_interface(
10508 CC_HEADER_ID,
10509 CC_VERSION_NUM,
10510 CC_ACCT_LINE_ID,
10511 CC_DET_PF_LINE_ID ,
10512 CODE_COMBINATION_ID,
10513 BATCH_LINE_NUM ,
10514 CC_TRANSACTION_DATE ,
10515 CC_FUNC_DR_AMT ,
10516 CC_FUNC_CR_AMT ,
10517 JE_SOURCE_NAME ,
10518 JE_CATEGORY_NAME,
10519 PERIOD_SET_NAME ,
10520 PERIOD_NAME ,
10521 ACTUAL_FLAG ,
10522 BUDGET_DEST_FLAG ,
10523 SET_OF_BOOKS_ID ,
10524 ENCUMBRANCE_TYPE_ID ,
10525 CBC_RESULT_CODE ,
10526 STATUS_CODE ,
10527 BUDGET_VERSION_ID ,
10528 BUDGET_AMT ,
10529 COMMITMENT_ENCMBRNC_AMT ,
10530 OBLIGATION_ENCMBRNC_AMT ,
10531 CC_ENCMBRNC_DATE ,
10532 FUNDS_AVAILABLE_AMT ,
10533 CURRENCY_CODE ,
10534 TRANSACTION_DESCRIPTION ,
10535 REFERENCE_1 ,
10536 REFERENCE_2 ,
10537 REFERENCE_3 ,
10538 REFERENCE_4 ,
10539 REFERENCE_5 ,
10540 REFERENCE_6 ,
10541 REFERENCE_7 ,
10542 REFERENCE_8 ,
10543 REFERENCE_9 ,
10544 REFERENCE_10,
10545 LAST_UPDATE_DATE ,
10546 LAST_UPDATED_BY ,
10547 LAST_UPDATE_LOGIN ,
10548 CREATION_DATE ,
10549 CREATED_BY ,
10550 DOCUMENT_TYPE,
10551 Project_line
10552 --BATCH_ID ,
10553 --PA_FLAG ,
10554 --RESULT_CODE_LEVEL ,
10555 --RESULT_CODE_SOURCE
10556 )
10557 SELECT
10558 igc.CC_HEADER_ID,
10559 igc.CC_VERSION_NUM,
10560 igc.CC_ACCT_LINE_ID,
10561 igc.CC_DET_PF_LINE_ID ,
10562 pbc.txn_ccid,
10563 l_max_batch_line_id + to_number(rownum), --igc.BATCH_LINE_NUM ,
10564 igc.CC_TRANSACTION_DATE ,
10565 decode(nvl(pbc.accounted_cr,0),0,NULL,pbc.accounted_cr),
10566 decode(nvl(pbc.accounted_dr,0),0,NULL,pbc.accounted_dr),
10567 igc.JE_SOURCE_NAME ,
10568 igc.JE_CATEGORY_NAME,
10569 igc.PERIOD_SET_NAME ,
10570 igc.PERIOD_NAME ,
10571 'E',
10572 igc.BUDGET_DEST_FLAG ,
10573 igc.SET_OF_BOOKS_ID ,
10574 pbc.proj_encumbrance_type_id,
10575 igc.CBC_RESULT_CODE ,
10576 igc.STATUS_CODE ,
10577 igc.BUDGET_VERSION_ID ,
10578 igc.BUDGET_AMT ,
10579 igc.COMMITMENT_ENCMBRNC_AMT ,
10580 igc.OBLIGATION_ENCMBRNC_AMT ,
10581 igc.CC_ENCMBRNC_DATE ,
10582 igc.FUNDS_AVAILABLE_AMT ,
10583 igc.CURRENCY_CODE ,
10584 igc.TRANSACTION_DESCRIPTION ,
10585 igc.REFERENCE_1 ,
10586 igc.REFERENCE_2 ,
10587 igc.REFERENCE_3 ,
10588 igc.REFERENCE_4 ,
10589 igc.REFERENCE_5 ,
10590 igc.REFERENCE_6 ,
10591 igc.REFERENCE_7 ,
10592 'PKT_ID:'||pbc.packet_id, --igc.REFERENCE_8 ,
10593 'BC_PKT_ID:'||pbc.bc_packet_id, --igc.REFERENCE_9 ,
10594 igc.REFERENCE_10,
10595 --igc.REFERENCE_10,
10596 igc.LAST_UPDATE_DATE ,
10597 igc.LAST_UPDATED_BY ,
10598 igc.LAST_UPDATE_LOGIN ,
10599 igc.CREATION_DATE ,
10600 igc.CREATED_BY ,
10601 igc.DOCUMENT_TYPE ,
10602 'Y'
10603 --igc.BATCH_ID ,
10604 --igc.PA_FLAG ,
10605 --igc.RESULT_CODE_LEVEL ,
10606 --igc.RESULT_CODE_SOURCE
10607 FROM igc_cc_interface igc,
10608 pa_bc_packets pbc
10609 WHERE pbc.packet_id = p_packet_id
10610 AND pbc.document_header_id = igc.cc_header_id
10611 AND pbc.document_distribution_id = igc.cc_acct_line_id
10612 AND pbc.document_type in ('CC_C_CO','CC_P_CO')
10613 AND pa_funds_control_utils.get_bdgt_link(
10614 pbc.project_id,decode(pbc.document_type,'CC_C_CO','CBC',
10615 'CC_P_CO','CBC',
10616 'STD')) = 'Y'
10617 AND pbc.status_code NOT IN ('Z','T','V','B')
10618 AND substr(nvl(pbc.result_code,'P'),1,1) = 'P'
10619 AND ( pbc.gl_row_number = igc.rowid
10620 OR
10621 (to_char(pbc.bc_packet_id) = substr(igc.reference_9,
10622 length('BC_PKT_ID:')+1)
10623 )
10624 );
10625 If g_debug_mode = 'Y' Then
10626 log_message(p_msg_token1 => 'No of rows inserted into CBC = '||sql%rowcount);
10627 End if;
10628
10629 END IF;
10630
10631 pa_debug.reset_err_stack;
10632 return;
10633 EXCEPTION
10634 when others then
10635 result_status_code_update
10636 (p_packet_id => p_packet_id,
10637 p_result_code => 'F161',
10638 p_res_result_code => 'F161',
10639 p_res_grp_result_code => 'F161',
10640 p_task_result_code => 'F161',
10641 p_top_task_result_code => 'F161',
10642 p_project_result_code => 'F161',
10643 p_proj_acct_result_code => 'F161',
10644 p_status_code => 'T');
10645 x_return_status := 'T';
10646 If g_debug_mode = 'Y' Then
10647 log_message(p_msg_token1 => 'failed in create liqd entry apiSQLERR :'||sqlcode||sqlerrm);
10648 End if;
10649 Raise;
10650
10651 END create_liqd_entry;
10652 -------->6599207 ------END
10653
10654
10655 --------------------------------------------------------------
10656 -- Determine the return code sent to GL / CBC /BASELINE etc
10657 -- based on the full mode or partial mode the return status
10658 -- declared as success or failure. In partial mode even if there
10659 -- are failed transaction exist in packet, the return status
10660 -- is success since the packet is partially cleared
10661 -- for the full mode even if there exist single failed transaction
10662 -- the whole packet is marked as rejected / failed
10663 --------------------------------------------------------------
10664 PROCEDURE gen_return_code(p_packet_id IN NUMBER,
10665 p_partial_flag IN VARCHAR2,
10666 p_calling_mode IN VARCHAR2,
10667 x_return_status OUT NOCOPY VARCHAR2) IS
10668
10669 l_err_code NUMBER := 0;
10670 l_return_code varchar2(1):= 'S';
10671 CURSOR cur_fatal_error IS
10672 SELECT 1
10673 FROM DUAL
10674 WHERE EXISTS (SELECT null
10675 FROM pa_bc_packets
10676 WHERE packet_id = p_packet_id
10677 AND status_code = 'T'
10678 );
10679
10680 CURSOR cur_normal_error IS
10681 SELECT 1
10682 FROM DUAL
10683 WHERE EXISTS (SELECT null
10684 FROM pa_bc_packets
10685 WHERE packet_id = p_packet_id
10686 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
10687 );
10688
10689 /* To check at least one transaction is passed in partial mode */
10690 CURSOR cur_success_recs IS
10691 SELECT 1
10692 FROM DUAL
10693 WHERE EXISTS (SELECT null
10694 FROM pa_bc_packets
10695 WHERE packet_id = p_packet_id
10696 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P'
10697 );
10698
10699 BEGIN
10700 If g_debug_mode = 'Y' Then
10701 log_message(p_msg_token1 => 'Inside gen_return_code api');
10702 End if;
10703 -- Initialize the error stack
10704 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.gen_return_code');
10705
10706 -- Initialize the return status to success
10707 x_return_status := l_return_code;
10708
10709 -- check for fatal error in the packet
10710 OPEN cur_fatal_error;
10711 FETCH cur_fatal_error INTO l_err_code;
10712 IF cur_fatal_error%notfound then
10713 -- check for normal error
10714 OPEN cur_normal_error;
10715 FETCH cur_normal_error INTO l_err_code;
10716 IF cur_normal_error%notfound then
10717 l_err_code := 0;
10718 l_return_code := 'S';
10719 ELSE
10720 IF p_partial_flag <> 'Y' then -- full mode
10721 l_err_code := 1;
10722 l_return_code := 'F';
10723 ELSE -- partial mode
10724 -- check for any of the transaction passes the funds check
10725 OPEN cur_success_recs;
10726 FETCH cur_success_recs INTO l_err_code;
10727 IF cur_success_recs%notfound then
10728 l_err_code := 1;
10729 l_return_code := 'F';
10730 Else
10731 l_err_code := 0;
10732 l_return_code := 'S';
10733 End If;
10734 CLOSE cur_success_recs;
10735 END IF;
10736 END IF;
10737 CLOSE cur_normal_error;
10738 ELSE
10739 l_return_code := 'T';
10740 l_err_code := 1;
10741
10742 END IF;
10743 CLOSE cur_fatal_error;
10744
10745 IF l_err_code <> 0 and l_return_code <> 'S' then
10746 x_return_status := l_return_code;
10747 END IF;
10748
10749 -- reset the error stack
10750 PA_DEBUG.reset_err_stack;
10751
10752 return;
10753
10754 EXCEPTION
10755 when others then
10756 If cur_normal_error%ISOPEN THEN
10757 CLOSE cur_normal_error;
10758 END IF;
10759 IF cur_fatal_error%ISOPEN THEN
10760 CLOSE cur_fatal_error;
10761 END IF;
10762 IF cur_success_recs%ISOPEN THEN
10763 CLOSE cur_success_recs;
10764 END IF;
10765 result_status_code_update(p_packet_id => p_packet_id,
10766 p_result_code => 'F160',
10767 p_status_code => 'T',
10768 p_res_result_code => 'F160',
10769 p_res_grp_result_code => 'F160',
10770 p_task_result_code => 'F160',
10771 p_top_task_result_code => 'F160',
10772 p_project_result_code => 'F160',
10773 p_proj_acct_result_code => 'F160');
10774 If g_debug_mode = 'Y' Then
10775 log_message(p_msg_token1 => 'Failed in gen_return_code api unexpected Error '|| sqlcode||sqlerrm);
10776 End if;
10777 log_message(p_error_msg => sqlcode||sqlerrm);
10778
10779 x_return_status := 'T';
10780 return;
10781 END gen_return_code;
10782
10783 -------->6599207 ------As part of CC Enhancements
10784 PROCEDURE Post_Bdn_Lines_To_GL_CBC (
10785 p_Packet_ID IN Number,
10786 p_calling_module IN VARCHAR2,
10787 p_packet_status IN VARCHAR2,
10788 p_reference1 IN VARCHAR2,
10789 p_reference2 IN VARCHAR2,
10790 x_return_status OUT NOCOPY VARCHAR2
10791 ) IS
10792
10793 l_BCPacketID Number(15);
10794 l_GLRowNumber GL_BC_Packets.Originating_RowID%Type;
10795 l_cbcrownumber urowid;
10796 l_max_batch_line_id number(15);
10797
10798 --This cursor is defined to pick up all the burden cost lines
10799 --from the PA_BC_Packets table among other transactions.
10800
10801 CURSOR c_Burden_Costs IS
10802 SELECT BC_Packet_ID
10803 FROM PA_BC_Packets
10804 WHERE Packet_ID=p_Packet_ID AND
10805 Parent_BC_Packet_ID IS NOT NULL;
10806
10807 -- This cursor is defined to pick up the Row Number in the GL_BC_Packets
10808 -- table that corresponds to the BCPacket ID stored in PA_BC_Packets table.
10809
10810 CURSOR c_Row_Number(
10811 l_BCPacketID IN Number) IS
10812 SELECT RowID
10813 FROM GL_BC_Packets
10814 WHERE Template_ID=l_BCPacketID;
10815
10816 l_rowcount NUMBER := 0;
10817
10818 BEGIN
10819
10820 x_return_status := FND_API.G_RET_STS_SUCCESS;
10821
10822 pa_debug.init_err_stack ('PA_Funds_Control_Pkg.Post_Burden_Lines_To_GL');
10823
10824 If g_debug_mode = 'Y' Then
10825 log_message(p_msg_token1 => 'Inside the Post_Burden_Lines_To_GL api');
10826 log_message(p_msg_token1 => 'p_calling_module='||p_calling_module);
10827 End if;
10828
10829 IF p_calling_module = 'CBC' then
10830 SELECT nvl(MAX(batch_line_num),0)
10831 INTO l_max_batch_line_id
10832 FROM igc_cc_interface
10833 WHERE document_type = 'CC'
10834 AND cc_header_id = p_reference2;
10835
10836 INSERT INTO igc_cc_interface(
10837 CC_HEADER_ID,
10838 CC_VERSION_NUM,
10839 CC_ACCT_LINE_ID,
10840 CC_DET_PF_LINE_ID ,
10841 CODE_COMBINATION_ID,
10842 BATCH_LINE_NUM ,
10843 CC_TRANSACTION_DATE ,
10844 CC_FUNC_DR_AMT ,
10845 CC_FUNC_CR_AMT ,
10846 JE_SOURCE_NAME ,
10847 JE_CATEGORY_NAME,
10848 PERIOD_SET_NAME ,
10849 PERIOD_NAME ,
10850 ACTUAL_FLAG ,
10851 BUDGET_DEST_FLAG ,
10852 SET_OF_BOOKS_ID ,
10853 ENCUMBRANCE_TYPE_ID ,
10854 CBC_RESULT_CODE ,
10855 STATUS_CODE ,
10856 BUDGET_VERSION_ID ,
10857 BUDGET_AMT ,
10858 COMMITMENT_ENCMBRNC_AMT ,
10859 OBLIGATION_ENCMBRNC_AMT ,
10860 CC_ENCMBRNC_DATE ,
10861 FUNDS_AVAILABLE_AMT ,
10862 CURRENCY_CODE ,
10863 TRANSACTION_DESCRIPTION ,
10864 REFERENCE_1 ,
10865 REFERENCE_2 ,
10866 REFERENCE_3 ,
10867 REFERENCE_4 ,
10868 REFERENCE_5 ,
10869 REFERENCE_6 ,
10870 REFERENCE_7 ,
10871 REFERENCE_8 ,
10872 REFERENCE_9 ,
10873 REFERENCE_10,
10874 LAST_UPDATE_DATE ,
10875 LAST_UPDATED_BY ,
10876 LAST_UPDATE_LOGIN ,
10877 CREATION_DATE ,
10878 CREATED_BY ,
10879 DOCUMENT_TYPE ,
10880 Project_Line
10881 --BATCH_ID ,
10882 --PA_FLAG ,
10883 --RESULT_CODE_LEVEL ,
10884 --RESULT_CODE_SOURCE
10885 )
10886 SELECT
10887 igc.CC_HEADER_ID,
10888 igc.CC_VERSION_NUM,
10889 igc.CC_ACCT_LINE_ID,
10890 igc.CC_DET_PF_LINE_ID ,
10891 pbc.txn_ccid,
10892 l_max_batch_line_id + to_number(rownum), -- igc.BATCH_LINE_NUM ,
10893 igc.CC_TRANSACTION_DATE ,
10894 decode(nvl(pbc.accounted_dr,0),0,NULL,pbc.accounted_dr),
10895 decode(nvl(pbc.accounted_cr,0),0,NULL,pbc.accounted_cr),
10896 igc.JE_SOURCE_NAME ,
10897 igc.JE_CATEGORY_NAME,
10898 igc.PERIOD_SET_NAME ,
10899 igc.PERIOD_NAME ,
10900 igc.actual_flag,
10901 igc.BUDGET_DEST_FLAG ,
10902 igc.SET_OF_BOOKS_ID ,
10903 pbc.encumbrance_type_id,
10904 igc.CBC_RESULT_CODE ,
10905 igc.STATUS_CODE ,
10906 igc.BUDGET_VERSION_ID ,
10907 igc.BUDGET_AMT ,
10908 igc.COMMITMENT_ENCMBRNC_AMT ,
10909 igc.OBLIGATION_ENCMBRNC_AMT ,
10910 igc.CC_ENCMBRNC_DATE ,
10911 igc.FUNDS_AVAILABLE_AMT ,
10912 igc.CURRENCY_CODE ,
10913 igc.TRANSACTION_DESCRIPTION ,
10914 igc.REFERENCE_1 ,
10915 igc.REFERENCE_2 ,
10916 igc.REFERENCE_3 ,
10917 igc.REFERENCE_4 ,
10918 igc.REFERENCE_5 ,
10919 igc.REFERENCE_6 ,
10920 igc.REFERENCE_7 ,
10921 'PKT_ID:'||pbc.packet_id, --igc.REFERENCE_8 , /** checked with Arkadi cbc team **/
10922 'BC_PKT_ID:'||pbc.bc_packet_id, --igc.REFERENCE_9 , /** to use these two columns **/
10923 igc.REFERENCE_10,
10924 igc.LAST_UPDATE_DATE ,
10925 igc.LAST_UPDATED_BY ,
10926 igc.LAST_UPDATE_LOGIN ,
10927 igc.CREATION_DATE ,
10928 igc.CREATED_BY ,
10929 igc.DOCUMENT_TYPE ,
10930 'Y'
10931 --igc.BATCH_ID ,
10932 --igc.PA_FLAG ,
10933 --igc.RESULT_CODE_LEVEL ,
10934 --igc.RESULT_CODE_SOURCE
10935 FROM igc_cc_interface igc,
10936 pa_bc_packets pbc
10937 WHERE pbc.packet_id = p_packet_id
10938 AND pbc.document_type in ('CC_C_CO','CC_P_CO')
10939 /*** bug fix : 1883119
10940 AND ( pbc.status_code = 'P'
10941 OR (pbc.status_code in ('P','S') and g_mode = 'C')
10942 )
10943 **/
10944 AND pbc.status_code NOT IN ('Z','T','V','B','L')
10945 AND substr(nvl(pbc.result_code,'P'),1,1) = 'P'
10946 AND pbc.document_header_id = igc.cc_header_id
10947 AND pbc.document_distribution_id = igc.cc_acct_line_id
10948 AND ( ( pbc.parent_bc_packet_id is NOT NULL)
10949 or (pbc.parent_bc_packet_id is NULL
10950 and check_bdn_on_sep_item (pbc.project_id) = 'S')
10951 )
10952 ANd igc.document_type = 'CC';
10953 l_rowcount := sql%rowcount;
10954 If g_debug_mode = 'Y' Then
10955 log_message(p_msg_token1 => 'No of rows inseted to IGC = '||l_rowcount);
10956 End if;
10957
10958 END IF;
10959 pa_debug.reset_err_stack ;
10960
10961 EXCEPTION
10962
10963 WHEN OTHERS THEN
10964
10965 x_return_status := 'T';
10966 If p_calling_module = 'GL' then
10967 result_status_code_update(p_packet_id => p_packet_id,
10968 p_result_code => 'F163',
10969 p_status_code => 'T',
10970 p_res_result_code => 'F163',
10971 p_res_grp_result_code => 'F163',
10972 p_task_result_code => 'F163',
10973 p_top_task_result_code => 'F163',
10974 p_project_result_code => 'F163',
10975 p_proj_acct_result_code => 'F163');
10976 Elsif p_calling_module = 'CBC' then
10977 result_status_code_update(p_packet_id => p_packet_id,
10978 p_result_code => 'F164',
10979 p_status_code => 'T',
10980 p_res_result_code => 'F164',
10981 p_res_grp_result_code => 'F164',
10982 p_task_result_code => 'F164',
10983 p_top_task_result_code => 'F164',
10984 p_project_result_code => 'F164',
10985 p_proj_acct_result_code => 'F164');
10986 End if;
10987 If g_debug_mode = 'Y' Then
10988 log_message(p_msg_token1 => 'failed in post_bdn_lines_gl_cbc apiSQLERR :'||sqlcode||sqlerrm);
10989 End if;
10990 --commit;
10991 Raise;
10992 END Post_Bdn_Lines_To_GL_CBC;
10993 -------->6599207 ------END
10994
10995 ----------------------------------------------------------------
10996 --This procedure updates the result and status code in GL /CBc
10997 -- packets when the project funds check process fails
10998 ----------------------------------------------------------------
10999 PROCEDURE update_GL_CBC_result_code(
11000 p_packet_id IN number,
11001 p_calling_module IN varchar2,
11002 p_mode IN varchar2,
11003 p_partial_flag IN varchar2,
11004 p_reference1 IN varchar2 default null,
11005 p_reference2 IN varchar2 default null,
11006 p_packet_status IN varchar2,
11007 x_return_status OUT NOCOPY varchar2) IS
11008
11009 l_igc_status varchar2(100);
11010 l_pkt_fatal_error_flag varchar2(100):= 'N';
11011
11012 CURSOR pkt_status IS
11013 SELECT 'Y'
11014 FROM pa_bc_packets
11015 WHERE status_code = 'T'
11016 AND packet_id = p_packet_id
11017 AND rownum = 1;
11018
11019 CURSOR igc_status(l_cc_header_id number
11020 ,l_cc_type varchar2) is
11021 SELECT decode(count(*), count(decode(substr(nvl
11022 (igc.cbc_result_code,'P'),1,1),'P',1)),'P','F')
11023 FROM igc_cc_interface igc
11024 WHERE igc.cc_header_id = l_cc_header_id;
11025
11026
11027 CURSOR gl_status is
11028 SELECT decode(count(*), count(decode(substr(nvl
11029 (gl.result_code,'P'),1,1),'P',1)),'P','F')
11030 FROM gl_bc_packets gl
11031 WHERE gl.packet_id = p_packet_id;
11032 BEGIN
11033
11034 --Initialize the err stack
11035 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.update_GL_CBC_result_code');
11036
11037 -- initialize the return status to success
11038 x_return_status := 'S';
11039 l_pkt_fatal_error_flag := 'N';
11040 If g_debug_mode = 'Y' Then
11041 log_message(p_msg_token1 => 'Inside the update_GL_CBC_result_code api');
11042 log_message(p_msg_token1 => 'p_packet_status='||p_packet_status);
11043 log_message(p_msg_token1 => 'g_partial_flag='||g_partial_flag);
11044 log_message(p_msg_token1 => 'p_calling_module='||p_calling_module);
11045 End if;
11046
11047
11048 IF p_packet_status in ( 'S','F','T') or g_partial_flag = 'Y' then
11049
11050 OPEN pkt_status;
11051 FETCH pkt_status INTO l_pkt_fatal_error_flag;
11052 CLOSE pkt_status;
11053
11054 IF p_calling_module in ('GL','GL_TIEBACK') and p_mode in ('R','U','C','F') then
11055 If g_debug_mode = 'Y' Then
11056 log_message(p_msg_token1 =>' update gl bc packet with result code ');
11057 End if;
11058 UPDATE gl_bc_packets gl
11059 SET gl.result_code =
11060 (select MAX(
11061 decode(substr(nvl(gl.result_code,'P'),1,1),'P',
11062 decode( pbc.result_code,'F100','X00',
11063 'F101','X59',
11064 'F102','X60',
11065 'F103','X61',
11066 'F104','X62',
11067 'F105','X63',
11068 'F106','X64',
11069 'F107','X29',
11070 'F108','X30',
11071 'F109','X31',
11072 'F110','X32',
11073 'F111','X33',
11074 'F112','X34',
11075 'F113','X35',
11076 'F114','X36',
11077 'F115','X36',
11078 'F116','X36',
11079 'F117','X36',
11080 'F118','X38',
11081 'F119','X37',
11082 'F120','X36',
11083 'F121','X40',
11084 'F122','X41',
11085 'F123','X42',
11086 'F124','X43',
11087 'F125','X44',
11088 'F127','X45',
11089 'F128','X46',
11090 'F129','X47',
11091 'F130','X48',
11092 'F131','X49',
11093 'F132','X50',
11094 'F134','X51',
11095 'F135','X52',
11096 'F136','X36',
11097 'F137','X54',
11098 'F138','X55',
11099 'F140','X36',
11100 'F141','X56',
11101 'F142','X36',
11102 'F143','X53',
11103 'F144','X36',
11104 'F145','X36',
11105 'F146','X36',
11106 'F160','X36',
11107 'F161','X36',
11108 'F162','X36',
11109 'F163','X36',
11110 'F164','X36',
11111 'F165','X39',
11112 'F166','X38', -- added during CC import testing 2891273
11113 'F168','X36', -- added fo r12 ..
11114 /** added decodes for stamping advisory warnings bug :1975786 **/
11115 'P101',decode(pbc.res_result_code,'P112','P35',
11116 decode(pbc.res_grp_result_code,'P110','P36',
11117 decode(pbc.task_result_code,'P108','P37',
11118 decode(pbc.top_task_result_code,'P106','P38',
11119 decode(pbc.project_result_code,'P104','P31',
11120 decode(pbc.project_acct_result_code,'P102','P29',
11121 'P28')))))),
11122 'P102',decode(pbc.res_result_code,'P112','P35',
11123 decode(pbc.res_grp_result_code,'P110','P36',
11124 decode(pbc.task_result_code,'P108','P37',
11125 decode(pbc.top_task_result_code,'P106','P38',
11126 decode(pbc.project_result_code,'P104','P31',
11127 decode(pbc.project_acct_result_code,'P102','P29',
11128 'P29')))))),
11129 'P103',decode(pbc.res_result_code,'P112','P35',
11130 decode(pbc.res_grp_result_code,'P110','P36',
11131 decode(pbc.task_result_code,'P108','P37',
11132 decode(pbc.top_task_result_code,'P106','P38',
11133 decode(pbc.project_result_code,'P104','P31',
11134 decode(pbc.project_acct_result_code,'P102','P29',
11135 'P30')))))),
11136 'P104',decode(pbc.res_result_code,'P112','P35',
11137 decode(pbc.res_grp_result_code,'P110','P36',
11138 decode(pbc.task_result_code,'P108','P37',
11139 decode(pbc.top_task_result_code,'P106','P38',
11140 decode(pbc.project_result_code,'P104','P31',
11141 decode(pbc.project_acct_result_code,'P102','P29',
11142 'P31')))))),
11143 'P105',decode(pbc.res_result_code,'P112','P35',
11144 decode(pbc.res_grp_result_code,'P110','P36',
11145 decode(pbc.task_result_code,'P108','P37',
11146 decode(pbc.top_task_result_code,'P106','P38',
11147 decode(pbc.project_result_code,'P104','P31',
11148 decode(pbc.project_acct_result_code,'P102','P29',
11149 'P30')))))),
11150 'P106',decode(pbc.res_result_code,'P112','P35',
11151 decode(pbc.res_grp_result_code,'P110','P36',
11152 decode(pbc.task_result_code,'P108','P37',
11153 decode(pbc.top_task_result_code,'P106','P38',
11154 decode(pbc.project_result_code,'P104','P31',
11155 decode(pbc.project_acct_result_code,'P102','P29',
11156 'P38')))))),
11157 'P107',decode(pbc.res_result_code,'P112','P35',
11158 decode(pbc.res_grp_result_code,'P110','P36',
11159 decode(pbc.task_result_code,'P108','P37',
11160 decode(pbc.top_task_result_code,'P106','P38',
11161 decode(pbc.project_result_code,'P104','P31',
11162 decode(pbc.project_acct_result_code,'P102','P29',
11163 'P30')))))),
11164 'P108',decode(pbc.res_result_code,'P112','P35',
11165 decode(pbc.res_grp_result_code,'P110','P36',
11166 decode(pbc.task_result_code,'P108','P37',
11167 decode(pbc.top_task_result_code,'P106','P38',
11168 decode(pbc.project_result_code,'P104','P31',
11169 decode(pbc.project_acct_result_code,'P102','P29',
11170 'P37')))))),
11171 'P109',decode(pbc.res_result_code,'P112','P35',
11172 decode(pbc.res_grp_result_code,'P110','P36',
11173 decode(pbc.task_result_code,'P108','P37',
11174 decode(pbc.top_task_result_code,'P106','P38',
11175 decode(pbc.project_result_code,'P104','P31',
11176 decode(pbc.project_acct_result_code,'P102','P29',
11177 'P30')))))),
11178 'P110',decode(pbc.res_result_code,'P112','P35',
11179 decode(pbc.res_grp_result_code,'P110','P36',
11180 decode(pbc.task_result_code,'P108','P37',
11181 decode(pbc.top_task_result_code,'P106','P38',
11182 decode(pbc.project_result_code,'P104','P31',
11183 decode(pbc.project_acct_result_code,'P102','P29',
11184 'P36')))))),
11185 'P111',decode(pbc.res_result_code,'P112','P35',
11186 decode(pbc.res_grp_result_code,'P110','P36',
11187 decode(pbc.task_result_code,'P108','P37',
11188 decode(pbc.top_task_result_code,'P106','P38',
11189 decode(pbc.project_result_code,'P104','P31',
11190 decode(pbc.project_acct_result_code,'P102','P29',
11191 'P30')))))),
11192 'P112',decode(pbc.res_result_code,'P112','P35',
11193 decode(pbc.res_grp_result_code,'P110','P36',
11194 decode(pbc.task_result_code,'P108','P37',
11195 decode(pbc.top_task_result_code,'P106','P38',
11196 decode(pbc.project_result_code,'P104','P31',
11197 decode(pbc.project_acct_result_code,'P102','P29',
11198 'P35')))))),
11199 'P113','P32',
11200 'P114','P33',
11201 'P115','P34',
11202 'P116','P05',
11203 'F150','F58',
11204 'F151','F58',
11205 'F155','F58',
11206 'F156','F58',
11207 'F152','F57',
11208 'F153','F57',
11209 'F157','F57',
11210 'F158','F57',
11211 'F169','F35',
11212 'F170','F36',
11213 'F171','F36',
11214 'F172','F36',
11215 'F173','F36',
11216 gl.result_code )
11217 , gl.result_code ))
11218 from pa_bc_packets pbc
11219 where pbc.packet_id = p_packet_id
11220 and pbc.document_distribution_id = gl.source_distribution_id_num_1
11221 and ((pbc.source_event_id = gl.event_id
11222 and (pbc.document_type = decode(gl.source_distribution_type,'AP_INV_DIST','AP','AP_PREPAY','AP','X')
11223 OR
11224 pbc.document_type = decode(gl.source_distribution_type,'PO_DISTRIBUTIONS_ALL','PO','X')
11225 OR
11226 pbc.document_type = decode(gl.source_distribution_type,'PO_REQ_DISTRIBUTIONS_ALL','REQ','X')
11227 OR
11228 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_C_PAY')
11229 OR
11230 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_P_PAY')
11231 )
11232 )
11233 OR
11234 (pbc.bc_event_id = gl.event_id
11235 and (pbc.document_type = decode(gl.source_distribution_type,'PA_AP_BURDEN','AP','X')
11236 OR
11237 pbc.document_type = decode(gl.source_distribution_type,'PA_PO_BURDEN','PO','X')
11238 OR
11239 pbc.document_type = decode(gl.source_distribution_type,'PA_REQ_BURDEN','REQ','X')
11240 OR
11241 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_C_PAY')
11242 OR
11243 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_P_PAY')
11244 )
11245 )
11246 )
11247 )
11248 WHERE gl.packet_id = p_packet_id
11249 -- Bug 5352185 : Added the nvl to the following AND condition.
11250 AND nvl(substr(gl.result_code,1,1),'P') not in ('X') -- In AP matched case if PO fails, the PO rec. already failed
11251 AND (gl.event_id, gl.source_distribution_id_num_1
11252 --,source_distribution_type
11253 ) in
11254 (Select pb.bc_event_id,
11255 pb.document_distribution_id
11256 --,decode(pb.document_type,
11257 -- 'AP','AP_INV_DIST',
11258 -- 'AP','PA_AP_BURDEN',
11259 -- 'PO','PO_DISTRIBUTIONS_ALL',
11260 -- 'PO','PA_PO_BURDEN',
11261 -- 'REQ','PA_REQ_BURDEN',
11262 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
11263 from pa_bc_packets pb
11264 where pb.packet_id = p_packet_id
11265 UNION ALL
11266 Select pb.source_event_id,
11267 pb.document_distribution_id
11268 --,decode(pb.document_type,
11269 -- 'AP','AP_INV_DIST',
11270 -- 'AP','PA_AP_BURDEN',
11271 -- 'PO','PO_DISTRIBUTIONS_ALL',
11272 -- 'PO','PA_PO_BURDEN',
11273 -- 'REQ','PA_REQ_BURDEN',
11274 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
11275 from pa_bc_packets pb
11276 where pb.packet_id = p_packet_id);
11277
11278 If g_debug_mode = 'Y' Then
11279 log_message(p_msg_token1 =>'no of rows result code updated after= '||sql%rowcount);
11280 End if;
11281
11282 -- Following code is being added as in case of AP-PO matched case, in gl_bc_packets
11283 -- source_distribution_id_num_1 points to AP
11284 -- this is only reqd. in case of non-integrated budgets as for non-integrated budgets we do
11285 -- not create "PA_PO_BURDEN" records so no records in gl_bc_packets gets updated ..
11286
11287 If nvl(g_ap_matched_case,'N') = 'Y' then
11288 If g_debug_mode = 'Y' Then
11289 log_message(p_msg_token1 =>' update gl bc packet with result code for PO for AP matched');
11290 End if;
11291
11292 UPDATE gl_bc_packets gl
11293 SET gl.result_code =
11294 (select MAX(
11295 decode(substr(nvl(gl.result_code,'P'),1,1),'P',
11296 decode( pbc.result_code,'F100','X00',
11297 'F101','X59',
11298 'F102','X60',
11299 'F103','X61',
11300 'F104','X62',
11301 'F105','X63',
11302 'F106','X64',
11303 'F107','X29',
11304 'F108','X30',
11305 'F109','X31',
11306 'F110','X32',
11307 'F111','X33',
11308 'F112','X34',
11309 'F113','X35',
11310 'F114','X36',
11311 'F115','X36',
11312 'F116','X36',
11313 'F117','X36',
11314 'F118','X38',
11315 'F119','X37',
11316 'F120','X36',
11317 'F121','X40',
11318 'F122','X41',
11319 'F123','X42',
11320 'F124','X43',
11321 'F125','X44',
11322 'F127','X45',
11323 'F128','X46',
11324 'F129','X47',
11325 'F130','X48',
11326 'F131','X49',
11327 'F132','X50',
11328 'F134','X51',
11329 'F135','X52',
11330 'F136','X36',
11331 'F137','X54',
11332 'F138','X55',
11333 'F140','X36',
11334 'F141','X56',
11335 'F142','X36',
11336 'F143','X53',
11337 'F144','X36',
11338 'F145','X36',
11339 'F146','X36',
11340 'F160','X36',
11341 'F161','X36',
11342 'F162','X36',
11343 'F163','X36',
11344 'F164','X36',
11345 'F165','X39',
11346 'F166','X38', -- added during CC import testing 2891273
11347 'F168','X36', -- added fo r12 ..
11348 /** added decodes for stamping advisory warnings bug :1975786 **/
11349 'P101',decode(pbc.res_result_code,'P112','P35',
11350 decode(pbc.res_grp_result_code,'P110','P36',
11351 decode(pbc.task_result_code,'P108','P37',
11352 decode(pbc.top_task_result_code,'P106','P38',
11353 decode(pbc.project_result_code,'P104','P31',
11354 decode(pbc.project_acct_result_code,'P102','P29',
11355 'P28')))))),
11356 'P102',decode(pbc.res_result_code,'P112','P35',
11357 decode(pbc.res_grp_result_code,'P110','P36',
11358 decode(pbc.task_result_code,'P108','P37',
11359 decode(pbc.top_task_result_code,'P106','P38',
11360 decode(pbc.project_result_code,'P104','P31',
11361 decode(pbc.project_acct_result_code,'P102','P29',
11362 'P29')))))),
11363 'P103',decode(pbc.res_result_code,'P112','P35',
11364 decode(pbc.res_grp_result_code,'P110','P36',
11365 decode(pbc.task_result_code,'P108','P37',
11366 decode(pbc.top_task_result_code,'P106','P38',
11367 decode(pbc.project_result_code,'P104','P31',
11368 decode(pbc.project_acct_result_code,'P102','P29',
11369 'P30')))))),
11370 'P104',decode(pbc.res_result_code,'P112','P35',
11371 decode(pbc.res_grp_result_code,'P110','P36',
11372 decode(pbc.task_result_code,'P108','P37',
11373 decode(pbc.top_task_result_code,'P106','P38',
11374 decode(pbc.project_result_code,'P104','P31',
11375 decode(pbc.project_acct_result_code,'P102','P29',
11376 'P31')))))),
11377 'P105',decode(pbc.res_result_code,'P112','P35',
11378 decode(pbc.res_grp_result_code,'P110','P36',
11379 decode(pbc.task_result_code,'P108','P37',
11380 decode(pbc.top_task_result_code,'P106','P38',
11381 decode(pbc.project_result_code,'P104','P31',
11382 decode(pbc.project_acct_result_code,'P102','P29',
11383 'P30')))))),
11384 'P106',decode(pbc.res_result_code,'P112','P35',
11385 decode(pbc.res_grp_result_code,'P110','P36',
11386 decode(pbc.task_result_code,'P108','P37',
11387 decode(pbc.top_task_result_code,'P106','P38',
11388 decode(pbc.project_result_code,'P104','P31',
11389 decode(pbc.project_acct_result_code,'P102','P29',
11390 'P38')))))),
11391 'P107',decode(pbc.res_result_code,'P112','P35',
11392 decode(pbc.res_grp_result_code,'P110','P36',
11393 decode(pbc.task_result_code,'P108','P37',
11394 decode(pbc.top_task_result_code,'P106','P38',
11395 decode(pbc.project_result_code,'P104','P31',
11396 decode(pbc.project_acct_result_code,'P102','P29',
11397 'P30')))))),
11398 'P108',decode(pbc.res_result_code,'P112','P35',
11399 decode(pbc.res_grp_result_code,'P110','P36',
11400 decode(pbc.task_result_code,'P108','P37',
11401 decode(pbc.top_task_result_code,'P106','P38',
11402 decode(pbc.project_result_code,'P104','P31',
11403 decode(pbc.project_acct_result_code,'P102','P29',
11404 'P37')))))),
11405 'P109',decode(pbc.res_result_code,'P112','P35',
11406 decode(pbc.res_grp_result_code,'P110','P36',
11407 decode(pbc.task_result_code,'P108','P37',
11408 decode(pbc.top_task_result_code,'P106','P38',
11409 decode(pbc.project_result_code,'P104','P31',
11410 decode(pbc.project_acct_result_code,'P102','P29',
11411 'P30')))))),
11412 'P110',decode(pbc.res_result_code,'P112','P35',
11413 decode(pbc.res_grp_result_code,'P110','P36',
11414 decode(pbc.task_result_code,'P108','P37',
11415 decode(pbc.top_task_result_code,'P106','P38',
11416 decode(pbc.project_result_code,'P104','P31',
11417 decode(pbc.project_acct_result_code,'P102','P29',
11418 'P36')))))),
11419 'P111',decode(pbc.res_result_code,'P112','P35',
11420 decode(pbc.res_grp_result_code,'P110','P36',
11421 decode(pbc.task_result_code,'P108','P37',
11422 decode(pbc.top_task_result_code,'P106','P38',
11423 decode(pbc.project_result_code,'P104','P31',
11424 decode(pbc.project_acct_result_code,'P102','P29',
11425 'P30')))))),
11426 'P112',decode(pbc.res_result_code,'P112','P35',
11427 decode(pbc.res_grp_result_code,'P110','P36',
11428 decode(pbc.task_result_code,'P108','P37',
11429 decode(pbc.top_task_result_code,'P106','P38',
11430 decode(pbc.project_result_code,'P104','P31',
11431 decode(pbc.project_acct_result_code,'P102','P29',
11432 'P35')))))),
11433 'P113','P32',
11434 'P114','P33',
11435 'P115','P34',
11436 'P116','P05',
11437 'F150','F58',
11438 'F151','F58',
11439 'F155','F58',
11440 'F156','F58',
11441 'F152','F57',
11442 'F153','F57',
11443 'F157','F57',
11444 'F158','F57',
11445 'F169','F35',
11446 'F170','F36',
11447 'F171','F36',
11448 'F172','F36',
11449 'F173','F36',
11450 gl.result_code )
11451 , gl.result_code ))
11452 from pa_bc_packets pbc
11453 where pbc.packet_id = p_packet_id
11454 and pbc.document_type = 'PO'
11455 and pbc.bc_event_id is null
11456 and pbc.reference3 = gl.source_distribution_id_num_1
11457 and (nvl(pbc.accounted_dr,0) - nvl(pbc.accounted_cr,0)) =
11458 -1* (nvl(gl.accounted_dr,0) - nvl(gl.accounted_cr,0))
11459 )
11460 WHERE gl.packet_id = p_packet_id
11461 AND gl.source_distribution_type = 'AP_INV_DIST'
11462 AND substr(gl.result_code,1,1) not in ('X','F')
11463 AND exists
11464 ( select 1
11465 from pa_bc_packets pbc1
11466 where pbc1.packet_id = p_packet_id
11467 and pbc1.document_type = 'PO'
11468 and pbc1.bc_event_id is null
11469 and pbc1.reference3 = gl.source_distribution_id_num_1
11470 and (nvl(pbc1.accounted_dr,0) - nvl(pbc1.accounted_cr,0)) =
11471 -1* (nvl(gl.accounted_dr,0) - nvl(gl.accounted_cr,0))
11472 );
11473
11474 If g_debug_mode = 'Y' Then
11475 log_message(p_msg_token1 =>'(AP match,non int) no of rows,result code updated= '||sql%rowcount);
11476 End if;
11477
11478 End If;
11479
11480
11481 IF p_calling_module in ('GL_TIEBACK') then
11482
11483 open gl_status;
11484 fetch gl_status into l_igc_status;
11485 close gl_status;
11486
11487 If g_debug_mode = 'Y' Then
11488 log_message(p_msg_token1 =>'p_calling_module ['||p_calling_module||']l_gl_status ['||l_igc_status||']');
11489 End if;
11490
11491 UPDATE gl_bc_packets gl
11492 SET gl.result_code = decode(substr(gl.result_code,1,1),'P',
11493 decode(sign(nvl(gl.accounted_dr,0) - nvl(gl.accounted_cr,0)),
11494 -1, 'P32',
11495 gl.result_code),gl.result_code),
11496 gl.status_code = decode(nvl(l_pkt_fatal_error_flag,'N'),'Y','T',
11497 decode(p_partial_flag
11498 ,'Y', decode(substr(nvl(gl.result_code,'P'),1,1) ,
11499 'P',gl.status_code,
11500 'F',decode(p_mode,'C','F','R'),
11501 'X',decode(p_mode,'C','F','R'),
11502 gl.status_code)
11503 ,'N',decode(p_packet_status,
11504 'S',decode(l_igc_status,'P', decode(p_mode,'C','S','A'),
11505 'F', decode(p_mode,'C','F','R')),
11506 'F',decode(p_mode,'C','F','R'),
11507 'T',decode(p_mode,'C','F','R'),'R')))
11508 WHERE gl.packet_id = p_packet_id
11509 AND (gl.event_id, gl.source_distribution_id_num_1
11510 --,source_distribution_type
11511 ) in
11512 (Select pb.bc_event_id,
11513 pb.document_distribution_id
11514 --,decode(pb.document_type,
11515 -- 'AP','AP_INV_DIST',
11516 -- 'AP','PA_AP_BURDEN',
11517 -- 'PO','PO_DISTRIBUTIONS_ALL',
11518 -- 'PO','PA_PO_BURDEN',
11519 -- 'REQ','PA_REQ_BURDEN',
11520 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
11521 from pa_bc_packets pb
11522 where pb.packet_id = p_packet_id
11523 UNION ALL
11524 Select pb.source_event_id,
11525 pb.document_distribution_id
11526 --,decode(pb.document_type,
11527 -- 'AP','AP_INV_DIST',
11528 -- 'AP','PA_AP_BURDEN',
11529 -- 'PO','PO_DISTRIBUTIONS_ALL',
11530 -- 'PO','PA_PO_BURDEN',
11531 -- 'REQ','PA_REQ_BURDEN',
11532 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
11533 from pa_bc_packets pb
11534 where pb.packet_id = p_packet_id);
11535
11536
11537 If g_debug_mode = 'Y' Then
11538 log_message(p_msg_token1 =>'no of rows status code updated after= '||sql%rowcount);
11539 End if;
11540 END IF;
11541
11542 ELSIF p_calling_module in('CBC','CBC_TIEBACK') and p_mode in ('R','U','C','F') then
11543 If g_debug_mode = 'Y' Then
11544 log_message(p_msg_token1 =>' update CBC packet with result code ');
11545 End if;
11546
11547 UPDATE igc_cc_interface igc
11548 SET igc.cbc_result_code =
11549 (select MAX(
11550 decode(substr(nvl(igc.cbc_result_code,'P'),1,1),'P',
11551 decode( pbc.result_code,'F100','F00',
11552 'F101','F59',
11553 'F102','F60',
11554 'F103','F61',
11555 'F104','F62',
11556 'F105','F63',
11557 'F106','F64',
11558 'F107','F29',
11559 'F108','F30',
11560 'F109','F31',
11561 'F110','F32',
11562 'F111','F33',
11563 'F112','F34',
11564 'F113','F35',
11565 'F114','F36',
11566 'F115','F36',
11567 'F116','F36',
11568 'F117','F36',
11569 'F118','F38',
11570 'F119','F37',
11571 'F120','F36',
11572 'F121','F40',
11573 'F122','F41',
11574 'F123','F42',
11575 'F124','F43',
11576 'F125','F44',
11577 'F127','F45',
11578 'F128','F46',
11579 'F129','F47',
11580 'F130','F48',
11581 'F131','F49',
11582 'F132','F50',
11583 'F134','F51',
11584 'F135','F52',
11585 'F136','F36',
11586 'F137','F54',
11587 'F138','F55',
11588 'F140','F36',
11589 'F141','F56',
11590 'F142','F36',
11591 'F143','F53',
11592 'F144','F36',
11593 'F145','F36',
11594 'F146','F36',
11595 'F160','F36',
11596 'F161','F36',
11597 'F162','F36',
11598 'F163','F36',
11599 'F164','F36',
11600 'F165','F39',
11601 'F166','F38', -- added during CC import testing 2891273
11602 -- added decodes for stamping advisory warnings bug :1975786
11603 'P101',decode(pbc.res_result_code,'P112','P35',
11604 decode(pbc.res_grp_result_code,'P110','P36',
11605 decode(pbc.task_result_code,'P108','P37',
11606 decode(pbc.top_task_result_code,'P106','P38',
11607 decode(pbc.project_result_code,'P104','P31',
11608 decode(pbc.project_acct_result_code,'P102','P29',
11609 'P28')))))),
11610 'P102',decode(pbc.res_result_code,'P112','P35',
11611 decode(pbc.res_grp_result_code,'P110','P36',
11612 decode(pbc.task_result_code,'P108','P37',
11613 decode(pbc.top_task_result_code,'P106','P38',
11614 decode(pbc.project_result_code,'P104','P31',
11615 decode(pbc.project_acct_result_code,'P102','P29',
11616 'P29')))))),
11617 'P103',decode(pbc.res_result_code,'P112','P35',
11618 decode(pbc.res_grp_result_code,'P110','P36',
11619 decode(pbc.task_result_code,'P108','P37',
11620 decode(pbc.top_task_result_code,'P106','P38',
11621 decode(pbc.project_result_code,'P104','P31',
11622 decode(pbc.project_acct_result_code,'P102','P29',
11623 'P30')))))),
11624 'P104',decode(pbc.res_result_code,'P112','P35',
11625 decode(pbc.res_grp_result_code,'P110','P36',
11626 decode(pbc.task_result_code,'P108','P37',
11627 decode(pbc.top_task_result_code,'P106','P38',
11628 decode(pbc.project_result_code,'P104','P31',
11629 decode(pbc.project_acct_result_code,'P102','P29',
11630 'P31')))))),
11631 'P105',decode(pbc.res_result_code,'P112','P35',
11632 decode(pbc.res_grp_result_code,'P110','P36',
11633 decode(pbc.task_result_code,'P108','P37',
11634 decode(pbc.top_task_result_code,'P106','P38',
11635 decode(pbc.project_result_code,'P104','P31',
11636 decode(pbc.project_acct_result_code,'P102','P29',
11637 'P30')))))),
11638 'P106',decode(pbc.res_result_code,'P112','P35',
11639 decode(pbc.res_grp_result_code,'P110','P36',
11640 decode(pbc.task_result_code,'P108','P37',
11641 decode(pbc.top_task_result_code,'P106','P38',
11642 decode(pbc.project_result_code,'P104','P31',
11643 decode(pbc.project_acct_result_code,'P102','P29',
11644 'P38')))))),
11645 'P107',decode(pbc.res_result_code,'P112','P35',
11646 decode(pbc.res_grp_result_code,'P110','P36',
11647 decode(pbc.task_result_code,'P108','P37',
11648 decode(pbc.top_task_result_code,'P106','P38',
11649 decode(pbc.project_result_code,'P104','P31',
11650 decode(pbc.project_acct_result_code,'P102','P29',
11651 'P30')))))),
11652 'P108',decode(pbc.res_result_code,'P112','P35',
11653 decode(pbc.res_grp_result_code,'P110','P36',
11654 decode(pbc.task_result_code,'P108','P37',
11655 decode(pbc.top_task_result_code,'P106','P38',
11656 decode(pbc.project_result_code,'P104','P31',
11657 decode(pbc.project_acct_result_code,'P102','P29',
11658 'P37')))))),
11659 'P109',decode(pbc.res_result_code,'P112','P35',
11660 decode(pbc.res_grp_result_code,'P110','P36',
11661 decode(pbc.task_result_code,'P108','P37',
11662 decode(pbc.top_task_result_code,'P106','P38',
11663 decode(pbc.project_result_code,'P104','P31',
11664 decode(pbc.project_acct_result_code,'P102','P29',
11665 'P30')))))),
11666 'P110',decode(pbc.res_result_code,'P112','P35',
11667 decode(pbc.res_grp_result_code,'P110','P36',
11668 decode(pbc.task_result_code,'P108','P37',
11669 decode(pbc.top_task_result_code,'P106','P38',
11670 decode(pbc.project_result_code,'P104','P31',
11671 decode(pbc.project_acct_result_code,'P102','P29',
11672 'P36')))))),
11673 'P111',decode(pbc.res_result_code,'P112','P35',
11674 decode(pbc.res_grp_result_code,'P110','P36',
11675 decode(pbc.task_result_code,'P108','P37',
11676 decode(pbc.top_task_result_code,'P106','P38',
11677 decode(pbc.project_result_code,'P104','P31',
11678 decode(pbc.project_acct_result_code,'P102','P29',
11679 'P30')))))),
11680 'P112',decode(pbc.res_result_code,'P112','P35',
11681 decode(pbc.res_grp_result_code,'P110','P36',
11682 decode(pbc.task_result_code,'P108','P37',
11683 decode(pbc.top_task_result_code,'P106','P38',
11684 decode(pbc.project_result_code,'P104','P31',
11685 decode(pbc.project_acct_result_code,'P102','P29',
11686 'P35')))))),
11687 'P113','P32',
11688 'P114','P33',
11689 'P115','P34',
11690 'P116','P05',
11691 'F150','F58',
11692 'F151','F58',
11693 'F155','F58',
11694 'F156','F58',
11695 'F152','F57',
11696 'F153','F57',
11697 'F157','F57',
11698 'F158','F57', igc.cbc_result_code )
11699 , igc.cbc_result_code))
11700 from pa_bc_packets pbc
11701 where pbc.packet_id = p_packet_id
11702 and (pbc.gl_row_number = igc.rowid
11703 or
11704 ( substr(igc.reference_9,length('BC_PKT_ID:')+1) in
11705 ( pbc.bc_packet_id)
11706 )
11707 )
11708 )
11709 WHERE igc.rowid in (SELECT pkt.gl_row_number
11710 FROM pa_bc_packets pkt
11711 WHERE pkt.packet_id = p_packet_id
11712 AND pkt.gl_row_number = igc.rowid
11713 )
11714 OR
11715 ( substr(igc.reference_9,length('BC_PKT_ID:')+1) in
11716 ( SELECT pbc.bc_packet_id
11717 FROM pa_bc_packets pbc
11718 WHERE pbc.packet_id = substr(reference_8,length('PKT_ID:')+1)
11719 AND pbc.bc_packet_id = substr(reference_9,length('BC_PKT_ID:')+1)
11720 )
11721 );
11722
11723
11724 IF p_calling_module in('CBC','CBC_TIEBACK') then
11725
11726 /** the calling module CBC_TIEBACK is used to update the
11727 * status code in igc_cc_interface table if pa pass and
11728 * cbc fc fails, if pa fails then cbc doesnot call tie back
11729 * since payment forcast lines are not funds checked we
11730 * should not update the status code of payment forcast line
11731 */
11732
11733 open igc_status(p_reference2,p_reference1);
11734 fetch igc_status into l_igc_status;
11735 close igc_status;
11736
11737 UPDATE igc_cc_interface igc
11738 SET igc.cbc_result_code = decode(substr(cbc_result_code,1,1),'P',
11739 decode(sign(nvl(igc.cc_func_dr_amt,0)
11740 - nvl(igc.cc_func_cr_amt,0)),
11741 -1, 'P32',
11742 -- --1,'P28', commented for bug :1975786
11743 cbc_result_code),cbc_result_code),
11744 igc.status_code = decode(nvl(l_pkt_fatal_error_flag,'N'),'Y','T',
11745 decode(p_partial_flag
11746 ,'Y', decode(substr(nvl(igc.cbc_result_code,'P'),1,1) ,
11747 'P',igc.status_code,
11748 'F',decode(p_mode,'C','F','R'),
11749 'X',decode(p_mode,'C','F','R'),
11750 igc.status_code)
11751 ,'N',decode(p_packet_status,
11752 'S',decode(l_igc_status,'P', decode(p_mode,'C','S','A'),
11753 'F', decode(p_mode,'C','F','R')),
11754 'F',decode(p_mode,'C','F','R'),
11755 'T',decode(p_mode,'C','F','R'),'R')))
11756 WHERE ((p_calling_module = 'CBC_TIEBACK'
11757 and igc.cc_header_id = p_reference2)
11758 OR
11759 ( p_calling_module = 'CBC' and
11760 (igc.cc_header_id,igc.cc_acct_line_id) in
11761 (SELECT pkt.document_header_id,pkt.document_distribution_id
11762 FROM pa_bc_packets pkt
11763 WHERE pkt.packet_id = p_packet_id
11764 AND pkt.document_header_id = igc.cc_header_id
11765 AND pkt.document_distribution_id = igc.cc_acct_line_id
11766 AND pkt.document_type in ('CC_C_CO','CC_P_CO')
11767 )));
11768
11769
11770 END IF;
11771 If g_debug_mode = 'Y' Then
11772 log_message(p_msg_token1 =>'no of rows updated = '||sql%rowcount);
11773 End if;
11774
11775 END IF;
11776
11777 END IF;
11778 If gl_status%isopen then
11779 close gl_status;
11780 End if;
11781 If igc_status%isopen then
11782 close igc_status;
11783 End if;
11784 If pkt_status%isopen then
11785 close pkt_status;
11786 End if;
11787
11788 -- reset the error stack
11789 PA_DEBUG.reset_err_stack;
11790
11791 Return;
11792
11793 EXCEPTION
11794 WHEN OTHERS THEN
11795 If gl_status%isopen then
11796 close gl_status;
11797 End if;
11798 If igc_status%isopen then
11799 close igc_status;
11800 End if;
11801 If pkt_status%isopen then
11802 close pkt_status;
11803 End if;
11804 --log_message(p_return_status => 'T');
11805 g_return_status := 'T';
11806 x_return_status := 'T';
11807 If g_debug_mode = 'Y' Then
11808 log_message(p_msg_token1 => 'failed in update gl cbc result code apiSQLERR :'||sqlcode||sqlerrm);
11809 End if;
11810 Raise;
11811 END update_GL_CBC_result_code;
11812 ---------------------------------------------------------------------
11813 -- This APi checks whether the project is under base line process
11814 -- if so updates the bc packets with rejection status and returns
11815 ---------------------------------------------------------------------
11816 FUNCTION is_project_baseline
11817 (p_calling_module IN varchar2,
11818 p_packet_id IN number) RETURN BOOLEAN is
11819 PRAGMA AUTONOMOUS_TRANSACTION;
11820 l_status_flag BOOLEAN := true;
11821 l_num_rows NUMBER := 100;
11822 l_lck_number NUMBER;
11823 l_bdgt_type varchar2(30);
11824 l_yr_end_rollover_flag varchar2(10);
11825 l_pre_project_id pa_bc_packets.project_id%type := NULL;
11826 CURSOR cur_projects IS
11827 SELECT project_id
11828 FROM pa_bc_packets
11829 WHERE packet_id = p_packet_id;
11830
11831 BEGIN
11832 If g_debug_mode = 'Y' Then
11833 log_message(p_msg_token1 => 'Inside is_project_baseline api');
11834 log_message(p_msg_token1 => 'p_calling_module='||p_calling_module);
11835 End if;
11836 /* Intialize the default values for flag variables */
11837 l_yr_end_rollover_flag := 'N';
11838 l_status_flag := true;
11839
11840 IF p_calling_module not in ( 'RESERVE_BASELINE') then
11841
11842 OPEN cur_projects;
11843 LOOP
11844 g_tab_project_id.delete;
11845 If NOT l_status_flag then
11846 EXIT;
11847 END IF;
11848 FETCH cur_projects BULK COLLECT INTO
11849 g_tab_project_id LIMIT l_num_rows;
11850 If NOT g_tab_project_id.EXISTS(1) then
11851 EXIT;
11852 End if;
11853 FOR i IN g_tab_project_id.FIRST .. g_tab_project_id.LAST LOOP
11854 IF l_pre_project_id is NULL or
11855 l_pre_project_id <> g_tab_project_id(i) then
11856
11857 /** Added the Phase II changes Yr end rollover **/
11858 If p_calling_module = 'CBC' then
11859 l_bdgt_type := 'CBC';
11860 Else
11861 l_bdgt_type := 'STD';
11862 End if;
11863 l_yr_end_rollover_flag := PA_FUNDS_CONTROL_UTILS.
11864 get_fnd_reqd_flag(g_tab_project_id(i),
11865 l_bdgt_type);
11866 IF l_yr_end_rollover_flag = 'R' then
11867 /** Year End Rollover process is in progress
11868 * so mark the transaction as failes
11869 */
11870 l_status_flag := FALSE;
11871 If g_debug_mode = 'Y' Then
11872 log_message(p_msg_token1 => 'Yr End Rollover is in progress');
11873 End if;
11874 EXIT;
11875 END IF;
11876
11877 IF (pa_debug.acquire_user_lock('BSLNFCHKLOCK:'||
11878 g_tab_project_id(i))) = 0 then
11879 -- if the lock is acquired for project
11880 -- indicates the budget is not under baseline
11881 -- for this project so release the lock
11882 IF (pa_debug.release_user_lock('BSLNFCHKLOCK:'||
11883 g_tab_project_id(i))) = 0 then
11884 null;
11885 END IF;
11886
11887 ELSE -- this project is under baseline lock
11888 l_status_flag := FALSE;
11889 If g_debug_mode = 'Y' Then
11890 log_message(p_msg_token1 => 'Budget Baseline is under progress');
11891 End if;
11892 EXIT;
11893 END IF;
11894 END IF;
11895 l_pre_project_id := g_tab_project_id(i);
11896
11897 END LOOP;
11898
11899 EXIT when cur_projects%NOTFOUND;
11900
11901 END LOOP;
11902 CLOSE cur_projects;
11903
11904 IF l_status_flag = FALSE and l_yr_end_rollover_flag = 'N' then
11905 -- Error F143 = 'Funds check failed as Budget Baseline is under progress'
11906 result_status_code_update(
11907 p_status_code => 'R',
11908 p_result_code => 'F143',
11909 p_res_result_code => 'F143',
11910 p_res_grp_result_code => 'F143',
11911 p_task_result_code => 'F143',
11912 p_top_task_result_code => 'F143',
11913 p_project_result_code => 'F143',
11914 p_proj_acct_result_code => 'F143',
11915 p_packet_id => p_packet_id);
11916
11917 Elsif l_status_flag = FALSE and l_yr_end_rollover_flag = 'R' then
11918 -- Error F119 = 'Failed due to Year end rollover process is in progress'
11919 result_status_code_update(
11920 p_status_code => 'R',
11921 p_result_code => 'F119',
11922 p_res_result_code => 'F119',
11923 p_res_grp_result_code => 'F119',
11924 p_task_result_code => 'F119',
11925 p_top_task_result_code => 'F119',
11926 p_project_result_code => 'F119',
11927 p_proj_acct_result_code => 'F119',
11928 p_packet_id => p_packet_id);
11929 End IF;
11930 END IF;
11931 If cur_projects%isopen then
11932 close cur_projects;
11933 End if;
11934 COMMIT ; -- to end an active autonomous transaction
11935 REturn l_status_flag;
11936
11937 EXCEPTION
11938 WHEN OTHERS THEN
11939 If cur_projects%isopen then
11940 close cur_projects;
11941 End if;
11942 l_lck_number := pa_debug.release_user_lock('BSLNFCHKLOCK:'|| l_pre_project_id);
11943 result_status_code_update
11944 (p_status_code => 'T',
11945 p_packet_id => p_packet_id);
11946 If g_debug_mode = 'Y' Then
11947 log_message(p_msg_token1 => 'failed in is_project_baseline apSQLERR :'||sqlcode||sqlerrm);
11948 End if;
11949 --commit;
11950 Raise;
11951
11952
11953 END is_project_baseline;
11954 /*****************************************************************************************************
11955 *This is the Main funds check function which calls all the other functions and procedures.
11956 *This API is called from the following places
11957 * GL - Funds check process
11958 * CBC - Funds check process
11959 * Costing - During Expenditure Cost Distribution process
11960 * Transaction Import Process
11961 * Baseline of Budget
11962 *
11963 * Parameters :
11964 * p_set_of_books_id : Set of Books ID in GL accounts for the packet to funds checked.
11965 * p_calling_module : Identifier of the module from which the funds checker will be invoked
11966 * The valid values are
11967 * GL - General ledger
11968 * CBC - Contract Conmmitment
11969 *- CHECK_BASELINE - Budget Baselining (from r12 .. no such mode)
11970 *- RESERVE_BASELINE - for delta protion ( conccurance issue)
11971 * TRXIMPORT - Transaction Import
11972 * DISTVIADJ - Invoice Adjustments
11973 * DISTERADJ - Expense Report Adjustments
11974 * INTERFACVI - Interface VI to payables
11975 * INTERFACER - Interface ER to payables
11976 * EXPENDITURE - For actuals entering through Projects
11977 * DISTCWKST -- for Distribute labor process for cwk transactions only
11978 * DISTBTC -- create and distribute burden process (burden recompile process)
11979 *
11980 * P_packet_id : Packet ID of the packet to be funds checked.
11981 * P_mode : Funds Checker Operation Mode.
11982 * C - Check funds
11983 * R - Reserve funds.
11984 * U - Un-reserve (only for REQ,PO and AP)
11985 * B - Called from budget baseline process (Processed like check funds)
11986 * S - Called from Budget submission (Processed like check funds)
11987 * (From r12 on - not used)
11988 * A - Adjustment same as Reserve funds (called from PO,REQ)
11989 * F - Force Pass mode (called from Contract Commitments)
11990 * P_partial_flag : Indicates the packet can be fundschecked/reserverd partially or not
11991 * Y - Partial
11992 * N - Full mode, default is N
11993 * P_reference1 If the p_mode is 'R',U,C,F' and p_calling_module = 'CBC'or 'EXP' then
11994 * this parameter holds the document type info Document Type
11995 * EXP - Expenditures originating from project
11996 * CC - Contract Commitments
11997 * Elsif p_mode is B, S and p_calling_module = 'BASELINE' then
11998 * this parameter holds the ext_bdgt_link_flag
11999 * End if;
12000 * * This param is not null for EXP , CC document type and Base line mode
12001 * P_reference2 If the p_mode is 'R',U,C,F' and p_calling_module = 'CBC' then
12002 * this parameter holds the document header info for Contract Commitment
12003 * document Header Id from Contract Commitments
12004 * IGC_CC_INTERFACE.CC_HEADER_ID
12005 * Elsif p_mode is B, S and p_calling_module = 'BASELINE' then
12006 * this parameter holds the project_id
12007 * End if;
12008 * * This param is not null for CC document type and Base line mode
12009 * P_reference3 If p_mode is B, S and p_calling_module = 'BASELINE' then
12010 * this parameter holds the budget_version_id
12011 * End if;
12012 * * This param is not null for Base line mode and Contract commitments
12013 *
12014 * p_conc_flag : identifies when funds check is invoked from concurrent program.
12015 * The valid values are
12016 * 'N' default
12017 * 'Y' - concurrent programm
12018 *
12019 * x_return_status : Fudscheck return status
12020 * Valid Status are
12021 * S - Success
12022 * F - Failure
12023 * T - Fatal
12024 * x_error_stage :Identifies the place where funds check process failed
12025 *
12026 * x_error_messagee :defines the type of error : SQLerror||sqlcode
12027 *
12028 *
12029 *NOTE : p_packet_id will be null for Contract commitments so the packet id to be generated
12030 * if the p_calling_module is 'CBC'.
12031 * if the p_calling_module is TRXIMPORT then set_of_books_id to be generated
12032 ****************************************************************************************************************/
12033 FUNCTION pa_funds_check
12034 (p_calling_module IN VARCHAR2
12035 ,p_conc_flag IN VARCHAR2 DEFAULT 'N'
12036 ,p_set_of_book_id IN NUMBER
12037 ,p_packet_id IN NUMBER
12038 ,p_mode IN VARCHAR2 DEFAULT 'C'
12039 ,p_partial_flag IN VARCHAR2 DEFAULT 'N'
12040 ,p_reference1 IN VARCHAR2 DEFAULT NULL
12041 ,p_reference2 IN VARCHAR2 DEFAULT NULL
12042 ,p_reference3 IN VARCHAR2 DEFAULT NULL
12043 ,x_return_status OUT NOCOPY VARCHAR2
12044 ,x_error_msg OUT NOCOPY VARCHAR2
12045 ,x_error_stage OUT NOCOPY VARCHAR2
12046 ) RETURN BOOLEAN IS
12047
12048
12049 x_e_code VARCHAR2(10);
12050 x_e_stage VARCHAR2(2000);
12051
12052 CURSOR cur_packets IS
12053 SELECT gl_bc_packets_s.nextval
12054 FROM dual;
12055
12056 CURSOR cur_sob(v_packet_id number) IS
12057 SELECT set_of_books_id
12058 FROM pa_bc_packets
12059 WHERE packet_id = v_packet_id;
12060
12061 l_arrival_seq NUMBER;
12062 l_packet_id pa_bc_packets.packet_id%type;
12063 l_set_of_books_id pa_bc_packets.set_of_books_id%type;
12064 l_err_code NUMBER := 0;
12065 l_err_buff VARCHAR2 ( 2000 ) := NULL;
12066 l_return_code VARCHAR2 ( 1 );
12067 l_result_code VARCHAR2 ( 1 ) := 'P';
12068 l_status VARCHAR2 ( 1 );
12069 l_doc_type VARCHAR2(30);
12070 l_return_status VARCHAR2(30);
12071 l_packet_status VARCHAR2(30);
12072 l_error_stage VARCHAR2(20);
12073 l_err_msg_code VARCHAR2(30);
12074 l_E_CODE NUMBER;
12075 l_num_rows number;
12076 l_mode varchar2(10);
12077 l_debug_mode varchar2(10);
12078 l_calling_code varchar2(10);
12079
12080 l_fc_final_exit_flag VARCHAR2(100) := 'NORMAL_EXIT';
12081
12082 x_resource_list_member_id number;
12083 x_resource_id number;
12084 -------------------------------------------------------------------------------------------------------
12085 -- This is local procedure used as lock mechanism After inserting Commit to release the lock
12086 -- When a lock on pa_concurrency_control is not available if Funds Checker is invoked from a
12087 -- Concurrent Process, it waits if Funds Checker is invoked from an Online Process,
12088 -- it exits with an error
12089 --------------------------------------------------------------------------------------------------------------
12090 BEGIN
12091
12092 --- Initialize the error statck
12093 PA_DEBUG.init_err_stack ('PA_FUNDS_CONTROL_PKG.pa_funds_check');
12094
12095 fnd_profile.get('PA_DEBUG_MODE',g_debug_mode);
12096 g_debug_mode := NVL(g_debug_mode, 'N');
12097
12098 PA_DEBUG.SET_PROCESS( x_process => 'PLSQL'
12099 ,x_write_file => 'LOG'
12100 ,x_debug_mode => g_debug_mode
12101 );
12102 If g_debug_mode = 'Y' then
12103 log_message(p_msg_token1 => 'Start Of project Funds check Calling module['
12104 || p_calling_module||']calling mode['||p_mode||']reference1['
12105 ||p_reference1||']reference2['||p_reference2||']partial flag['
12106 ||p_partial_flag||']conc flag['||p_conc_flag||']packet_id['
12107 ||p_packet_id||']' );
12108 End if;
12109
12110 /** Bug fix :2302945 If PA is NOT installed in OU then we should return as success
12111 ** without proceeding further . This api checks whether the In given operating unit
12112 ** project is installed or not, if not installed return with success
12113 **/
12114 IF IS_PA_INSTALL_IN_OU = 'N' then
12115 x_return_status := 'S';
12116 g_return_status := 'S';
12117 If g_debug_mode = 'Y' then
12118 log_message(p_msg_token1=>'PA NOT INSTALLED IN THIS OU.return status='||
12119 x_return_status);
12120 End if;
12121 PA_DEBUG.Reset_err_stack;
12122 Return True;
12123 END IF;
12124 /** End of Bug fix **/
12125
12126 -------->6599207 ------As part of CC Enhancements
12127 /* COMMENTING THIS CODE FOR CC ENHANCEMENTS
12128 ------------------------------------------------------------------------------------------+
12129 ----For CBC following procedure creates pa_bc_packet from ICG_CC_INTERFACE for Fundscheck.
12130 ----If the calling mode is Reserve, unreserve , Force pass and check then copy
12131 ----all the ICG_CC_INTERFACE to pa_bc_packets
12132 ------------------------------------------------------------------------------------------+
12133
12134 --IF l_mode IN ( 'R','C','F' ) AND p_calling_module = 'CBC' THEN
12135 IF p_calling_module = 'CBC' THEN
12136
12137 -- ------------------------------------------------------------------------------------------+
12138 -- :( AS CBC IS NOT SUPPORTED, IF CBC CALLS PA, RETURN 'T' BACK TO CALLING PGM ..
12139 -- ------------------------------------------------------------------------------------------+
12140
12141 If g_debug_mode = 'Y' then
12142 log_message(p_stage => 10,p_msg_token1 => 'For CBC calling copy_gl_pkt_to_pa_pkt in mode ='||l_mode);
12143 end if;
12144
12145 -- PA_FUNDS_CONTROL_PKG1.copy_gl_pkt_to_pa_pkt
12146 -- (p_packet_id => l_packet_id
12147 -- ,p_calling_module => p_calling_module
12148 -- ,p_return_code => l_return_status
12149 -- ,p_reference1 => p_reference1
12150 -- ,p_reference2 => p_reference2);
12151
12152 --IF l_return_status <> 'S' then
12153 If g_debug_mode = 'Y' then
12154 log_message (p_msg_token1 => 'Error while create records in pa_bc_packets');
12155 end if;
12156 g_return_status := 'T';
12157 x_return_status := g_return_status;
12158 l_fc_final_exit_flag := 'NORMAL_ERROR';
12159 GOTO END_PROCESS;
12160 --END IF;
12161 --If g_debug_mode = 'Y' then
12162 -- log_message(p_msg_token1 => 'Populating records in pa_bc_packets is successful');
12163 --end if;
12164 END IF;
12165 */
12166 -------->6599207 ------END
12167
12168 -- -----------------------------------------------------------------------------------+
12169 -- This procedure will synch packet_id, serial_id, session_id, actual_flag,status_code
12170 -- from gl_bc_packets to pa_bc_packets ..
12171 -- Synch up only required for Commitment Funds check ..
12172 -- -----------------------------------------------------------------------------------+
12173
12174 If p_calling_module not in
12175 ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ','TRXIMPORT','RESERVE_BASELINE','CDL') then
12176
12177 SYNCH_PA_GL_PACKETS(x_packet_id => p_packet_id,
12178 x_partial_flag => p_partial_flag,
12179 x_mode => p_mode,
12180 x_result_code => x_return_status);
12181
12182 If nvl(x_return_status,'S') = 'F' then -- Bug 5557520
12183
12184 If g_debug_mode = 'Y' then
12185 log_message(p_msg_token1 => 'Synch_pa_gl_packets failed .. extracts failed .. full mode');
12186 End If;
12187
12188 l_fc_final_exit_flag := 'NORMAL_ERROR';
12189 g_return_status := 'F';
12190 GOTO END_PROCESS;
12191
12192 End If;
12193
12194 End If;
12195
12196 -------->6599207 ------As part of CC Enhancements
12197 If p_calling_module <> 'CBC' Then
12198
12199 -- -----------------------------------------------------------------------------------+
12200 -- Check if PA FC called for project related txn. or budget or its called for non-FC
12201 -- NO_FC: non-project related FC, exit with 'S' status
12202 -- BUD_FC: BC FC called projects (SLA-BC Integration for budget baseline) - exit with
12203 -- 'S' status
12204 -- TXN_FC: PA FC called for txn. or budget baseline 'RESERVE_BASELINE' mode - existing
12205 -- -----------------------------------------------------------------------------------+
12206 If g_debug_mode = 'Y' then
12207 log_message(p_msg_token1 => 'Before calling CHECK_TXN_OR_BUDGET_FC');
12208 End If;
12209 CHECK_TXN_OR_BUDGET_FC (p_packet_id,l_calling_code);
12210
12211 If g_debug_mode = 'Y' then
12212 log_message(p_msg_token1=>'FC called mode:'||l_calling_code);
12213 End If;
12214
12215
12216 If l_calling_code in ('NO_FC','BUD_FC') THEN -- II
12217
12218 x_return_status := 'S';
12219 g_return_status := 'S';
12220
12221 If g_debug_mode = 'Y' then
12222 If l_calling_code = 'NO_FC' then
12223 log_message(p_msg_token1=>'PA FC called for non-project transactions');
12224 Else
12225 log_message(p_msg_token1=>'PA FC called by BC FC API during budget funds check by GL');
12226 End If;
12227
12228 End If;
12229
12230 PA_DEBUG.Reset_err_stack;
12231 Return TRUE;
12232
12233 End If; -- II
12234
12235 -- -----------------------------------------------------------------------------------+
12236 End If;
12237 -------->6599207 ------END
12238
12239
12240 l_fc_final_exit_flag := 'NORMAL_EXIT';
12241 -- Assign the In params to Global varialbes
12242 g_mode := p_mode;
12243 g_calling_module := p_calling_module;
12244 g_partial_flag := p_partial_flag;
12245 g_packet_id := p_packet_id;
12246 l_mode := p_mode;
12247
12248 If l_mode = 'A' then -- Adjustments same as Reserve funds
12249 l_mode := 'R';
12250 End if;
12251 g_mode := l_mode;
12252
12253 If g_debug_mode = 'Y' then
12254 log_message(p_msg_token1 => 'initialize l_fc_final_exit_flag = '||l_fc_final_exit_flag);
12255 End if;
12256
12257 -- Initialize the Out variable with success
12258 x_return_status := 'S';
12259 g_return_status := 'S';
12260
12261
12262 If g_debug_mode = 'Y' then
12263 log_message(p_msg_token1 => 'Before PA_FUNDS_CONTROL_UTILS.init_util_variables call' );
12264 End if;
12265 --Initialize the funds control util package global variables
12266 PA_FUNDS_CONTROL_UTILS.init_util_variables;
12267
12268 If g_debug_mode = 'Y' then
12269 log_message(p_msg_token1 => 'After PA_FUNDS_CONTROL_UTILS.init_util_variables call' );
12270 log_message(p_msg_token1 => 'Before Initialize_globals call' );
12271 End if;
12272 --Inialize the the local global variables
12273 Initialize_globals;
12274
12275
12276 If g_debug_mode = 'Y' then
12277 log_message(p_msg_token1 => 'After Initialize_globals call' );
12278 log_message(p_msg_token1 => 'l_mode='||l_mode );
12279 End if;
12280
12281 -- generete packet id if the calling module is contract commitments
12282 -- and store it in the global variable, use the glboal variable in
12283 -- tie back api for status confirmation for CBC.
12284 If p_calling_module = 'CBC' and l_mode not in('U') then
12285 OPEN cur_packets;
12286 FETCH cur_packets INTO l_packet_id;
12287 CLOSE cur_packets;
12288 g_cbc_packet_id := l_packet_id;
12289 g_packet_id := l_packet_id;
12290 Else
12291 If g_debug_mode = 'Y' then
12292 log_message(p_msg_token1 => ' assiging the packet id to global variable p_packet_id = '
12293 ||p_packet_id);
12294 End if;
12295 l_packet_id := p_packet_id;
12296 g_packet_id := l_packet_id;
12297 End If;
12298
12299 -- get the set of books id from the pa bc packets for the given packet id
12300 If p_calling_module in ('TRXIMPORT', 'TRXNIMPORT') then
12301 OPEN cur_sob(l_packet_id);
12302 FETCH cur_sob INTO l_set_of_books_id;
12303 CLOSE cur_sob;
12304
12305 Else
12306 l_set_of_books_id := p_set_of_book_id;
12307 END IF;
12308 If g_debug_mode = 'Y' then
12309 log_message(p_msg_token1 => ' the value of l_packet_id ='||l_packet_id||' - g packet_id ='||g_packet_id);
12310 End if;
12311
12312 -- if the calling mode is unreserved then copy all the rows into
12313 -- unreserved packet update the status and return, in tie back process
12314 -- update the budget_acct_balances
12315 If l_mode in ('U') and p_calling_module in ('GL','CBC') then
12316 If g_debug_mode = 'Y' then
12317 log_message(p_msg_token1 => ' calling create_unrsvd_lines api');
12318 end if;
12319 If NOT PA_FUNDS_CONTROL_PKG1.create_unrsvd_lines
12320 ( x_packet_id => l_packet_id
12321 ,p_mode => l_mode
12322 ,p_calling_module => p_calling_module
12323 ,p_reference1 => p_reference1
12324 ,p_reference2 => p_reference2
12325 ) then
12326 If g_debug_mode = 'Y' then
12327 log_message(p_msg_token1 => 'Failed to create unreserved packet lines');
12328 end if;
12329 g_return_status := 'F';
12330 --log_message(p_return_status => 'F');
12331 x_return_status := g_return_status;
12332 l_fc_final_exit_flag := 'NORMAL_ERROR';
12333 If g_debug_mode = 'Y' then
12334 log_message(p_msg_token1 => 'Return status :'||x_return_status);
12335 end if;
12336 pa_debug.reset_err_stack;
12337 return FALSE;
12338
12339 End if;
12340 g_packet_id := l_packet_id;
12341
12342 --generate return code for the packet and return
12343 If g_debug_mode = 'Y' then
12344 log_message(p_msg_token1 => 'Calling gen_return_code API');
12345 end if;
12346 gen_return_code(p_packet_id => l_packet_id
12347 ,p_partial_flag => p_partial_flag
12348 ,p_calling_mode => p_calling_module
12349 ,x_return_status => l_packet_status);
12350 If g_debug_mode = 'Y' then
12351 log_message(p_msg_token1 => 'After gen_return_code API call');
12352 end if;
12353 -- if the pa_funds check fails then in tie back process
12354 -- just return with out proceeding further else check
12355 -- the return status of gl and cbc update the status code
12356 -- of packets
12357 If p_calling_module = 'GL' then
12358 g_pa_gl_return_status := l_packet_status;
12359 Elsif p_calling_module = 'CBC' then
12360 g_pa_cbc_return_status := l_packet_status;
12361 End if;
12362 g_return_status := l_packet_status;
12363 If g_debug_mode = 'Y' then
12364 log_message(p_msg_token1 => 'The return code of the FC process :'||l_packet_status);
12365 end if;
12366 --log_message(p_return_status => l_packet_status);
12367
12368 x_return_status := l_packet_status;
12369 If g_debug_mode = 'Y' then
12370 log_message(p_msg_token1 => 'Return status :'||x_return_status);
12371 end if;
12372 pa_debug.reset_err_stack;
12373 return true;
12374
12375 End IF; -- end of Unreserve mode
12376
12377 -------->6599207 ------As part of CC Enhancements
12378 IF l_mode IN ( 'R','C','F' ) THEN
12379 If g_debug_mode = 'Y' then
12380 log_message(p_stage => 10,p_msg_token1 => 'inside the if condition mode ='||l_mode);
12381 end if;
12382
12383
12384 IF p_calling_module ='CBC' then
12385 If g_debug_mode = 'Y' then
12386 log_message(p_msg_token1 => 'calling populate plsql tabs api');
12387 end if;
12388
12389 PA_FUNDS_CONTROL_PKG1.populate_plsql_tabs_CBC
12390 (p_packet_id => l_packet_id
12391 ,p_calling_module => p_calling_module
12392 ,p_reference1 => p_reference1
12393 ,p_reference2 => p_reference2
12394 ,p_mode => l_mode);
12395
12396 End if;
12397 If g_debug_mode = 'Y' then
12398 log_message(p_msg_token1 => 'After populate plsql tabs api call');
12399 log_message(p_msg_token1 => 'End of create_bc_pkt_lines api');
12400 end if;
12401 END IF;
12402 -------->6599207 ------END
12403
12404
12405 ------------------------------------------------------------------------
12406 -- check whether the budget baseline is going on if so return and
12407 -- update the result code in pa bc packets with error code
12408 ------------------------------------------------------------------------
12409 If g_debug_mode = 'Y' then
12410 log_message( p_stage => 30, p_msg_token1 => 'Check whether the project is under Baseline process');
12411 end if;
12412 IF NOT is_project_baseline
12413 (p_calling_module => p_calling_module,
12414 p_packet_id => l_packet_id ) then
12415 If g_debug_mode = 'Y' then
12416 log_message( p_msg_token1 => 'BASELINE / YEAR END ROLLOVER is Under progress');
12417 end if;
12418 --log_message(p_return_status => 'F');
12419 g_return_status := 'F';
12420 x_return_status := g_return_status;
12421 l_fc_final_exit_flag := 'NORMAL_ERROR';
12422 GOTO END_PROCESS;
12423 END IF;
12424 -------------------------------------------------------------------------------------------------------
12425 --- Check if the mode is in B,S,R,U,C,F then Insert Arrival Sequence for the Packet.
12426 -- The Row Share Lock ensures that packets are assigned sequences strictly in order of arrival
12427 ------------------------------------------------------------------------------------------------------
12428 IF l_mode IN ( 'B', 'S','R','C','F' ) THEN
12429 If g_debug_mode = 'Y' then
12430 log_message(p_stage => 40,p_msg_token1 => 'Calling get_arrival_seq API');
12431 end if;
12432
12433
12434 l_arrival_seq := get_arrival_seq
12435 (p_calling_module => p_calling_module
12436 ,p_packet_id => l_packet_id
12437 ,p_sobid => l_set_of_books_id
12438 ,p_mode => l_mode
12439 );
12440
12441
12442 If g_debug_mode = 'Y' then
12443 log_message( p_msg_token1 => 'After get_arrival_seq call');
12444 log_message( p_msg_token1 => 'l_arrival_seq='||l_arrival_seq);
12445 end if;
12446
12447 IF l_arrival_seq = 0 then
12448 log_message(p_error_msg => 'F141');
12449 If g_debug_mode = 'Y' then
12450 log_message(p_msg_token1 => 'Failed to acquire lock');
12451 end if;
12452 l_fc_final_exit_flag := 'NORMAL_ERROR';
12453 GOTO END_PROCESS;
12454 End IF;
12455 If g_debug_mode = 'Y' then
12456 log_message(p_msg_token1 => 'End of get_arrival_seq API');
12457 end if;
12458
12459 END IF;
12460
12461 If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ','TRXIMPORT') then
12462
12463 -- Note: For commitment Funds check, populate_burden_cost is called in pa_funds_control_pkg1
12464 -- R12: BC-SLA Integration ..
12465
12466 -----------------------------------------------------------------------------------------------------
12467 -- Populate the Burden cost for each record in packet if project type is of burden on same EI
12468 -- otherwise create separate bc packet lines if the project type is of burden as separate EI
12469 --Lock the arrival order sequence table
12470 ------------------------------------------------------------------------------------------------------
12471 --IF l_mode IN ( 'R', 'C','F' ) and p_calling_module not in ( 'RESERVE_BASELINE') THEN
12472 If g_debug_mode = 'Y' then
12473 log_message(p_stage => 50,p_msg_token1 => p_calling_module||':Calling Populate_burden_cost API');
12474 end if;
12475
12476 PA_FUNDS_CONTROL_PKG1.Populate_burden_cost
12477 (p_packet_id => l_packet_id
12478 ,p_calling_module => p_calling_module
12479 ,x_return_status => l_return_status
12480 ,x_err_msg_code => l_err_msg_code);
12481
12482 If g_debug_mode = 'Y' then
12483 log_message(p_msg_token1 => 'After calling PA_FUNDS_CONTROL_PKG1.Populate_burden_cost api');
12484 end if;
12485
12486 IF l_return_status <> 'S' then
12487 If g_debug_mode = 'Y' then
12488 log_message (p_msg_token1 => 'Error while populating Burden Cost for');
12489 end if;
12490 --log_message(p_return_status => 'T');
12491 g_return_status := 'T';
12492 x_return_status := g_return_status;
12493 l_fc_final_exit_flag := 'NORMAL_ERROR';
12494 GOTO END_PROCESS;
12495 END IF;
12496 If g_debug_mode = 'Y' then
12497 log_message(p_msg_token1 => 'Populating burden cost is successful');
12498 end if;
12499 --END IF;
12500
12501 End if; -- If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
12502
12503 -------------------------------------------------------------------------------------------
12504 -- This Api setup the required funds check parameters such as resource list member id,
12505 -- funds control level code, budget resource list id, budget task id etc.
12506 -------------------------------------------------------------------------------------------
12507 If g_debug_mode = 'Y' then
12508 log_message(p_stage => 60,p_msg_token1 => 'Calling funds_check_setup API');
12509 end if;
12510 If l_mode not in ('U') then
12511 IF NOT funds_check_setup
12512 (p_packet_id => l_packet_id
12513 ,p_mode => l_mode
12514 ,p_sob => l_set_of_books_id
12515 ,p_reference1 => p_reference1
12516 ,p_reference2 => p_reference2
12517 ,p_calling_module => p_calling_module
12518
12519 ) THEN
12520 If g_debug_mode = 'Y' then
12521 log_message(p_msg_token1 =>'funds check failed at setup and summerization');
12522 end if;
12523 --log_message(p_return_status => 'T');
12524 g_return_status := 'T';
12525 x_return_status := g_return_status;
12526 l_fc_final_exit_flag := 'NORMAL_ERROR';
12527 GOTO END_PROCESS;
12528 END IF;
12529 End if;
12530 If g_debug_mode = 'Y' then
12531 log_message(p_msg_token1 => 'End of funds_check_setup API');
12532 end if;
12533
12534 -----------------------------------------------------------------------------------------------------------
12535 -- Main Funds Check Processor Calling pa_fck_process . In this process it derives start date and end date
12536 -- based on amount type and boundary code and checks funds available against the budget from the bottom up
12537 -- ie, checks at the Resource level resource group level task level top task level project level .
12538 -- If all the level funds check passes then it sets the status as S for each bc_packet_record
12539 --------------------------------------------------------------------------------------------------------
12540 If g_debug_mode = 'Y' then
12541 log_message(p_stage => 70,p_msg_token1 => 'Calling pa_fck_process API');
12542 end if;
12543 IF l_mode NOT in ('F','U') then
12544 IF NOT pa_fcp_process
12545 (p_sob => l_set_of_books_id
12546 ,p_packet_id => l_packet_id
12547 ,p_mode => l_mode
12548 ,p_partial_flag => p_partial_flag
12549 ,p_arrival_seq => l_arrival_seq
12550 ,p_reference1 => p_reference1
12551 ,p_reference2 => p_reference2
12552 --,p_reference3 => p_reference3
12553 ,p_calling_module => p_calling_module
12554
12555 ) then
12556 If g_debug_mode = 'Y' then
12557 log_message(p_msg_token1 => 'funds check failed during pa_fck_process api');
12558 end if;
12559 --log_message(p_return_status => 'T');
12560 g_return_status := 'T';
12561 x_return_status := g_return_status;
12562 l_fc_final_exit_flag := 'NORMAL_ERROR';
12563 GOTO END_PROCESS;
12564 END IF;
12565 END IF;
12566 If g_debug_mode = 'Y' then
12567 log_message(p_msg_token1 => 'end of pa_fck_process complete');
12568 end if;
12569
12570 -----------------------------------------------------------------------
12571 -- synchronize the raw and burden lines if there is a failure
12572 ------------------------------------------------------------------------
12573 If g_debug_mode = 'Y' then
12574 log_message(p_stage => 80,p_msg_token1 => 'Calling sync_raw_burden API');
12575 end if;
12576 If l_mode not in ('U') then
12577 sync_raw_burden
12578 (p_packet_id => l_packet_id
12579 ,p_mode => l_mode
12580 ,p_calling_module => p_calling_module
12581 ,x_return_status => l_return_status
12582 );
12583 IF l_return_status <> 'S' then
12584 log_message(p_msg_token1 => 'Failed to synchronize the raw and burden lines');
12585 End if;
12586 log_message(p_msg_token1 => 'End of sync_raw_burden API');
12587 End if;
12588 -------------------------------------------------------------------------
12589 -- Update ei and cdls with gl date, encum type id, budget ccid etc if the
12590 -- funds check pass else update ei with cost dist reject code
12591 --------------------------------------------------------------------------
12592 If g_debug_mode = 'Y' then
12593 log_message(p_stage => 90 ,p_msg_token1 => 'Calling update_EIS API');
12594 end if;
12595 If l_mode not in ('U') and p_calling_module in ('DISTBTC','DISTERADJ','EXPENDITURE','DISTVIADJ','DISTCWKST'
12596 ,'INTERFACER','INTERFACVI') then
12597 update_EIS (p_packet_id => l_packet_id
12598 ,p_calling_module => p_calling_module
12599 ,p_mode => l_mode
12600 ,x_return_status => l_return_status);
12601 IF l_return_status <> 'S' then
12602 If g_debug_mode = 'Y' then
12603 log_message(p_msg_token1 => 'Failed to update EI and CDLs with status');
12604 end if;
12605 --log_message(p_return_status => l_return_status);
12606 g_return_status := l_return_status;
12607 End if;
12608 If g_debug_mode = 'Y' then
12609 log_message(p_msg_token1 => 'End of update_EIS API');
12610 end if;
12611 End if;
12612
12613 ---------------------------------------------------------------------------
12614 -- Determine the return code sent to GL /CBC
12615 -- the out NOCOPY parameter l_return_status is the status of the
12616 -- packet which is funds checked
12617 ----------------------------------------------------------------------------
12618 If g_debug_mode = 'Y' then
12619 log_message(p_stage => 100, p_msg_token1 => 'Calling gen_return_code API');
12620 end if;
12621 gen_return_code(p_packet_id => l_packet_id
12622 ,p_partial_flag => p_partial_flag
12623 ,p_calling_mode => p_calling_module
12624 ,x_return_status => l_packet_status);
12625
12626 If g_debug_mode = 'Y' then
12627 log_message(p_msg_token1 => 'After gen_return_code api call');
12628 end if;
12629 -- if the pa_funds check fails then in tie back process
12630 -- just return with out proceeding further else check
12631 -- the return status of gl and cbc update the status code
12632 -- of packets
12633 If p_calling_module = 'GL' then
12634 g_pa_gl_return_status := l_packet_status;
12635 Elsif p_calling_module = 'CBC' then
12636 g_pa_cbc_return_status := l_packet_status;
12637 End if;
12638 If g_debug_mode = 'Y' then
12639 log_message(p_msg_token1 => 'The return code of the FC process :'||l_packet_status);
12640 end if;
12641
12642 -- --------------------------------------------------------------------------+
12643 -- Update gl_bc_packets status such that GL FC will not execute funds
12644 -- avaialble validation ... This is for no/separate line burdening
12645 -- --------------------------------------------------------------------------+
12646 --IF p_calling_module in ('GL','CBC') and l_mode IN ('R','C','F') then
12647
12648 -- MARK_GL_BC_PACKETS_FOR_NO_FC(p_packet_id => l_packet_id);
12649
12650 --End if;
12651
12652 -------->6599207 ------As part of CC Enhancements
12653 IF p_calling_module in ('CBC') and l_mode IN ('R','C','F') then
12654 -- funds check resutl is success
12655 If g_debug_mode = 'Y' then
12656 log_message(p_stage => 110, p_msg_token1 => 'Calling Post_Bdn_Lines_To_GL_CBC API');
12657 end if;
12658 Post_Bdn_Lines_To_GL_CBC (
12659 p_Packet_ID => l_packet_id
12660 ,p_calling_module => p_calling_module
12661 ,p_packet_status => l_packet_status
12662 ,p_reference1 => p_reference1
12663 ,p_reference2 => p_reference2
12664 ,x_return_status => l_return_status
12665 );
12666
12667 If g_debug_mode = 'Y' then
12668 log_message(p_msg_token1 => 'After Post_Bdn_Lines_To_GL_CBC api call');
12669 end if;
12670
12671 IF l_return_status <> 'S' then
12672 If g_debug_mode = 'Y' then
12673 log_message(p_msg_token1 => 'Failed to post burden lines to GL / CBC');
12674 end if;
12675 --log_message(p_return_status => l_return_status);
12676 g_return_status := l_return_status;
12677 End if;
12678 If g_debug_mode = 'Y' then
12679 log_message(p_msg_token1 =>'End of Post_Bdn_Lines_To_GL_CBC API');
12680 end if;
12681
12682 ----------------------------------------------------------------------------------
12683 -- if the project funds check is success full then call encumbrance liquidation
12684 -- entries in gl bc packets and igc cc interface tables
12685 ----------------------------------------------------------------------------------
12686 If g_debug_mode = 'Y' then
12687 log_message(p_stage => 120, p_msg_token1 => 'Calling create_liqd_entry API');
12688 end if;
12689 create_liqd_entry(
12690 p_Packet_ID => l_packet_id
12691 ,p_calling_module => p_calling_module
12692 ,P_mode => l_mode
12693 ,p_reference1 => p_reference1
12694 ,p_reference2 => p_reference2
12695 ,p_packet_status => l_packet_status
12696 ,x_return_status => l_return_status
12697 );
12698
12699 If g_debug_mode = 'Y' then
12700 log_message(p_msg_token1 => 'After create_liqd_entry api call');
12701 end if;
12702
12703 IF l_return_status <> 'S' then
12704 If g_debug_mode = 'Y' then
12705 log_message(p_msg_token1 => 'Failed to create liquidation entries in GL / CBC');
12706 end if;
12707 --log_message(p_return_status => l_return_status);
12708 g_return_status := l_return_status;
12709 End if;
12710 If g_debug_mode = 'Y' then
12711 log_message(p_msg_token1 => 'End of create_liqd_entry API');
12712 end if;
12713
12714 End if;
12715 -------->6599207 ------END
12716
12717
12718 -----------------------------------------------------------------------------------
12719 -- if the packet status is failed then update the status code of the pa bc packets
12720 -- for gl, cbc, trxn imports as failed otherwise the status code is updated in
12721 -- the tie back process
12722 -----------------------------------------------------------------------------------
12723 If ( (p_calling_module IN ( 'DISTBTC','GL','CBC','DISTERADJ','TRXIMPORT','DISTVIADJ','DISTCWKST')
12724 and l_mode not in ('U') and l_packet_status <> 'S' )
12725 OR ( p_calling_module IN ('RESERVE_BASELINE'))
12726 -- OR l_mode = 'C' , 'C' should behave like 'R' mode ..
12727 ) then
12728 If g_debug_mode = 'Y' then
12729 log_message(p_stage => 130, p_msg_token1 => 'calling update status code for failed packet');
12730 end if;
12731 status_code_update (
12732 p_calling_module => p_calling_module
12733 ,p_packet_id => l_packet_id
12734 ,p_mode => l_mode
12735 ,p_partial =>p_partial_flag
12736 ,p_packet_status => l_packet_status
12737 ,x_return_status => l_return_status
12738 );
12739 If g_debug_mode = 'Y' then
12740 log_message(p_msg_token1 => 'end of status code for failed packet');
12741 end if;
12742 IF l_return_status <> 'S' then
12743 If g_debug_mode = 'Y' then
12744 log_message(p_msg_token1 => 'Failed to update status codes');
12745 end if;
12746 --log_message(p_return_status => l_return_status);
12747 g_return_status := l_return_status;
12748 End if;
12749 End if;
12750
12751 If p_calling_module IN ( 'GL','CBC') AND l_mode not in ('U') and
12752 (l_packet_status <> 'S' OR p_partial_flag = 'Y') then
12753 If g_debug_mode = 'Y' then
12754 log_message(p_stage => 140, p_msg_token1 =>'Calling update_GL_CBC_result_code API');
12755 end if;
12756
12757 update_GL_CBC_result_code(
12758 p_packet_id => l_packet_id
12759 ,p_calling_module => p_calling_module
12760 ,p_mode => l_mode
12761 ,p_partial_flag => p_partial_flag
12762 ,p_reference1 => p_reference1
12763 ,p_reference2 => p_reference2
12764 ,p_packet_status => l_packet_status
12765 ,x_return_status => l_return_status
12766 );
12767 If g_debug_mode = 'Y' then
12768 log_message(p_msg_token1 => 'After update_GL_CBC_result_code api call');
12769 end if;
12770
12771 IF l_return_status <> 'S' then
12772 If g_debug_mode = 'Y' then
12773 log_message(p_msg_token1 => 'Failed to update result_code in GL /CBC ');
12774 end if;
12775 --log_message(p_return_status => l_return_status);
12776 g_return_status := l_return_status;
12777 End if;
12778 If g_debug_mode = 'Y' then
12779 log_message(p_msg_token1 =>'End of update_GL_CBC_result_code APIl_packet_status['||l_packet_status);
12780 end if;
12781 End IF;
12782 x_return_status := l_packet_status;
12783 If x_return_status = 'S' then
12784 /** added if condition if the funds check is called from GL /CBC
12785 * and partial_flag = 'Y' then GL /CBC funds check expects return
12786 * as 'P' instead of 'S' so set the return code for GL /CBC for
12787 * partial mode as P
12788 */
12789 If p_partial_flag = 'Y' and p_calling_module in ('GL','CBC') then
12790 If g_debug_mode = 'Y' then
12791 log_message(p_stage => 150, p_msg_token1 => 'Calling get_gl_cbc_return_status api');
12792 end if;
12793 x_return_status := get_gl_cbc_return_status
12794 (p_packet_id => l_packet_id);
12795
12796 End if;
12797 x_error_stage := 0;
12798 x_error_msg := null;
12799 Else -- was causing plsql value error
12800 x_error_stage := substr(g_error_stage,1,100); -- CBC funds check defined length as 100
12801 x_error_msg := substr(g_error_msg,1,100); -- so substr func added to reduce the length
12802 End if;
12803
12804 <<END_PROCESS>>
12805 If g_debug_mode = 'Y' then
12806 log_message(p_msg_token1 => 'End of Funds check Process l_fc_final_exit_flag['||
12807 l_fc_final_exit_flag);
12808 end if;
12809
12810 IF l_fc_final_exit_flag = 'NORMAL_ERROR' then
12811 x_return_status := 'F';
12812 -- update the gl / cbc result code with failure status
12813 If p_calling_module in ('GL','CBC') then
12814
12815 If g_debug_mode = 'Y' then
12816 log_message(p_stage => 140, p_msg_token1 =>'Calling update_GL_CBC_result_code API');
12817 end if;
12818 update_GL_CBC_result_code(
12819 p_packet_id => l_packet_id
12820 ,p_calling_module => p_calling_module
12821 ,p_mode => l_mode
12822 ,p_partial_flag => p_partial_flag
12823 ,p_reference1 => p_reference1
12824 ,p_reference2 => p_reference2
12825 ,p_packet_status => 'F' -- failure
12826 ,x_return_status => l_return_status);
12827
12828
12829 If g_debug_mode = 'Y' then
12830 log_message(p_msg_token1 => 'After update_GL_CBC_result_code api call');
12831 end if;
12832
12833 Elsif p_calling_module in ('DISTBTC','DISTERADJ','DISTVIADJ','INTERFACER','INTERFACVI','DISTCWKST') THEN
12834 update_EIS (p_packet_id => l_packet_id
12835 ,p_calling_module => p_calling_module
12836 ,p_mode => l_mode
12837 ,x_return_status => l_return_status);
12838 End if;
12839 If p_calling_module = 'GL' then
12840 g_pa_gl_return_status := 'F';
12841 Elsif p_calling_module = 'CBC' then
12842 g_pa_cbc_return_status := 'F';
12843 End if;
12844
12845 END IF;
12846 -- Reset the error stack
12847 PA_DEBUG.reset_err_stack;
12848 If g_debug_mode = 'Y' then
12849 log_message(p_msg_token1 => 'Return status :'||x_return_status);
12850 end if;
12851 RETURN ( TRUE );
12852 EXCEPTION
12853 WHEN OTHERS THEN
12854 x_error_stage := g_error_stage;
12855 x_error_msg := SQLCODE||SQLERRM;
12856 x_return_status := 'T';
12857 --log_message(p_return_status => x_return_status );
12858 g_return_status := 'T' ;
12859 result_status_code_update
12860 ( p_packet_id => l_packet_id,
12861 p_status_code => 'T',
12862 p_result_code => 'F142',
12863 p_res_result_code => 'F142',
12864 p_res_grp_result_code => 'F142',
12865 p_task_result_code => 'F142',
12866 p_top_task_result_code => 'F142',
12867 p_proj_acct_result_code => 'F142');
12868
12869 IF p_calling_module in ('DISTBTC','DISTVIADJ','DISTERADJ','EXPENDITURE','INTERFACER','INTERFACVI','DISTCWKST') then
12870 update_EIS(p_packet_id => l_packet_id
12871 ,p_calling_module => p_calling_module
12872 ,p_mode => l_mode
12873 ,x_return_status => l_return_status);
12874 If g_debug_mode = 'Y' then
12875 log_message(p_msg_token1 =>
12876 'Updateing EIS with rejection_code');
12877 end if;
12878 ELSIF p_calling_module in ('GL','CBC') then
12879 update_GL_CBC_result_code(
12880 p_packet_id =>l_packet_id
12881 ,p_calling_module =>p_calling_module
12882 ,p_partial_flag => p_partial_flag
12883 ,p_reference1 => p_reference1
12884 ,p_reference2 => p_reference2
12885 ,p_mode =>l_mode
12886 ,p_packet_status => 'T'
12887 ,x_return_status => l_return_status);
12888 END IF;
12889 If p_calling_module = 'GL' then
12890 g_pa_gl_return_status := 'T';
12891 Elsif p_calling_module = 'CBC' then
12892 g_pa_cbc_return_status := 'T';
12893 End if;
12894
12895 If cur_sob%ISOPEN then
12896 close cur_sob;
12897 End if;
12898
12899 If cur_packets%ISOPEN then
12900 close cur_packets;
12901 End if;
12902 If g_debug_mode = 'Y' then
12903 log_message(p_msg_token1 => 'failed in pa_funds_check apiSQLERR :'||sqlcode||sqlerrm);
12904 end if;
12905 -- Reset the error stack
12906 PA_DEBUG.reset_err_stack;
12907 RETURN ( false );
12908
12909 END pa_funds_check;
12910
12911 -----------------------------------------------------------
12912 -- This API returns the GL return code based on the full or
12913 -- partial modes in the case of RESERVE,CHECK FUNDS
12914 ----------------------------------------------------------
12915 FUNCTION get_gl_return_code(p_packet_id in number,
12916 p_partial_flag in varchar2 default 'N')
12917 return varchar2 IS
12918
12919 -- check for fatal error for the transactions in full mode
12920 cursor gl_status_fatal_error is
12921 SELECT 1
12922 FROM gl_bc_packets a
12923 WHERE a.packet_id = p_packet_id
12924 AND EXISTS (
12925 SELECT 'Y'
12926 FROM gl_bc_packets b
12927 WHERE b.status_code = 'T'
12928 AND b.packet_id = a.packet_id
12929 );
12930
12931 -- check for normal error for the transaction in full mode
12932 cursor gl_status_normal_error is
12933 SELECT 1
12934 FROM gl_bc_packets a
12935 WHERE a.packet_id = p_packet_id
12936 AND EXISTS (
12937 SELECT 'Y'
12938 FROM gl_bc_packets b
12939 WHERE b.packet_id = a.packet_id
12940 AND ((b.status_code in ('R','F','T')
12941 AND substr(b.result_code,1,1) = ('F')
12942 ) OR
12943 ( b.status_code = 'T' )
12944 )
12945 );
12946
12947 -- Check for at least on passed transaction in gl in partial mode
12948 -- if not found then all transactions are rejected
12949 cursor gl_status_partial is
12950 SELECT 1
12951 FROM gl_bc_packets a
12952 WHERE a.packet_id = p_packet_id
12953 AND EXISTS
12954 (SELECT 'Y'
12955 FROM gl_bc_packets b
12956 WHERE b.status_code in ('S','A','P')
12957 AND substr(b.result_code,1,1) IN ('P','A')
12958 AND b.packet_id = a.packet_id
12959 );
12960
12961
12962
12963 l_return_code varchar2(10) := 'S';
12964 l_status_code number := 0;
12965 BEGIN
12966
12967 If g_debug_mode = 'Y' Then
12968 log_message(p_msg_token1 => 'Inside get_gl_return_code api');
12969 End if;
12970 l_return_code := 'S';
12971 l_status_code := 0;
12972 IF p_partial_flag <> 'Y' then -- full mode
12973 If g_debug_mode = 'Y' Then
12974 log_message(p_msg_token1 => 'opening cur to check fatal error');
12975 End if;
12976 OPEN gl_status_fatal_error;
12977 FETCH gl_status_fatal_error INTO l_status_code;
12978 IF gl_status_fatal_error%NOTFOUND THEN
12979 OPEN gl_status_normal_error;
12980 If g_debug_mode = 'Y' Then
12981 log_message(p_msg_token1 => 'opening cur to check normal error');
12982 End if;
12983 FETCH gl_status_normal_error INTO l_status_code;
12984 IF gl_status_normal_error%NOTFOUND THEN
12985 If g_debug_mode = 'Y' Then
12986 log_message(p_msg_token1 => 'cur not found');
12987 End if;
12988 l_return_code := 'S';
12989 END IF;
12990 CLOSE gl_status_normal_error;
12991 END IF;
12992 CLOSE gl_status_fatal_error;
12993
12994 IF gl_status_fatal_error%isopen then
12995 close gl_status_fatal_error;
12996 End if;
12997 IF gl_status_normal_error%isopen then
12998 close gl_status_normal_error;
12999 End if;
13000
13001 IF nvl(l_status_code,0) > 0 then
13002 l_return_code := 'F';
13003 Else
13004 l_return_code := 'S';
13005 End if;
13006 If g_debug_mode = 'Y' Then
13007 log_message(p_msg_token1 => 'gl return code ='||l_return_code);
13008 End if;
13009 return l_return_code;
13010
13011 ELSE -- partial mode
13012
13013 OPEN gl_status_partial;
13014 If g_debug_mode = 'Y' Then
13015 log_message(p_msg_token1 => 'opening cur to check gl return code ');
13016 End if;
13017 FETCH gl_status_partial INTO l_status_code;
13018 IF gl_status_partial%NOTFOUND then
13019 If g_debug_mode = 'Y' Then
13020 log_message(p_msg_token1 => 'cur not found');
13021 End if;
13022 l_return_code := 'F';
13023 Else
13024 l_return_code := 'S';
13025 End if;
13026 CLOSE gl_status_partial;
13027
13028 IF gl_status_partial%isopen then
13029 close gl_status_partial;
13030 End if;
13031 If g_debug_mode = 'Y' Then
13032 log_message(p_msg_token1 => 'gl return code ='||l_return_code);
13033 End if;
13034 return l_return_code;
13035 END IF;
13036
13037 EXCEPTION
13038 when others then
13039 If g_debug_mode = 'Y' Then
13040 log_message(p_msg_token1 => 'Failed in get_gl_return_code api');
13041 End if;
13042 raise;
13043 END get_gl_return_code;
13044
13045 /** If the calling module is partial then
13046 * status and return code should be updated in
13047 * pa_bc_packets using autonmous transaction other wise
13048 * it causes a deadlock while calling sync_raw_burden from tie back api
13049 **/
13050 PROCEDURE tie_back_status(p_calling_module in varchar2,
13051 p_packet_id in number,
13052 p_partial_flag in varchar2,
13053 p_mode in varchar2,
13054 p_glcbc_return_code in varchar2) IS
13055
13056 PRAGMA AUTONOMOUS_TRANSACTION;
13057
13058 BEGIN
13059
13060 If g_debug_mode = 'Y' Then
13061 log_message(p_msg_token1 => 'In tie_back_status,p_calling_module,p_packet_id,p_partial_flag:'
13062 ||p_calling_module||','||p_packet_id||','||p_partial_flag);
13063 log_message(p_msg_token1 => 'In tie_back_status,p_mode,p_glcbc_return_code:'
13064 ||p_mode||','||p_glcbc_return_code);
13065 End if;
13066
13067 If p_calling_module in('GL','CBC') and p_mode in ('C','R','A','F') then
13068 FORALL i IN g_tab_src_dist_id_num_1.FIRST .. g_tab_src_dist_id_num_1.LAST
13069 UPDATE pa_bc_packets
13070 SET result_code =
13071 decode(p_calling_module,
13072 'GL',
13073 decode(p_partial_flag,
13074 'Y',decode(p_mode,'C','F150','F156'),
13075 'N',decode(p_mode,'C',decode(p_glcbc_return_code,'F','F150',
13076 'R','F151',
13077 'T','F151')
13078 ,'R',decode(p_glcbc_return_code,'F','F155',
13079 'R','F155',
13080 'T','F155')
13081 ,'A',decode(p_glcbc_return_code,'F','F155',
13082 'R','F155',
13083 'T','F155')
13084 ,'F',decode(p_glcbc_return_code,'F','F155',
13085 'R','F155',
13086 'T','F155'))),
13087 'CBC',
13088 decode(p_partial_flag,
13089 'Y',decode(p_mode,'C','F152','F158'),
13090 'N',decode(p_mode,'C',decode(p_glcbc_return_code,'F','F152',
13091 'R','F153',
13092 'T','F153')
13093 ,'R',decode(p_glcbc_return_code,'F','F157',
13094 'R','F157',
13095 'T','F157')
13096 ,'A',decode(p_glcbc_return_code,'F','F157',
13097 'R','F157',
13098 'T','F157')
13099 ,'F',decode(p_glcbc_return_code,'F','F157',
13100 'R','F157',
13101 'T','F157'))))
13102 WHERE packet_id = p_packet_id
13103 AND substr(nvl(result_code,'P'),1,1) = 'P'
13104 AND document_distribution_id = g_tab_src_dist_id_num_1(i)
13105 AND (source_event_id = g_tab_gl_bc_event_id(i)
13106 OR
13107 bc_event_id = g_tab_gl_bc_event_id(i))
13108 AND document_type = g_tab_src_dist_type(i);
13109
13110 If g_debug_mode = 'Y' Then
13111 log_message(p_msg_token1 => 'In tie_back_status, pa_bc_pkt records updated:'||SQL%ROWCOUNT);
13112 End if;
13113
13114 Elsif (p_calling_module in('DISTBTC','DISTVIADJ','DISTCWKST')and p_glcbc_return_code = 'T') Then
13115 /* mark the transaction result code as rejected if the return code of the distribute
13116 * vendor invoice adjustment process raises unexpected error
13117 */
13118 UPDATE pa_bc_packets
13119 SET result_code = decode(substr(nvl(result_code,'P'),1,1),'P','F151',result_code)
13120 WHERE packet_id = p_packet_id;
13121
13122 End if;
13123 commit; -- to end an active autonomous transaction
13124
13125 If g_debug_mode = 'Y' Then
13126 log_message(p_msg_token1 => 'In tie_back_status: End');
13127 End if;
13128
13129 return;
13130
13131 EXCEPTION
13132 WHEN OTHERS THEN
13133 If g_debug_mode = 'Y' Then
13134 pa_funds_control_pkg.log_message(p_msg_token1 => 'Failed in tie_back_status apiSQLERR:'||
13135 sqlcode||sqlerrm);
13136 End if;
13137 RAISE;
13138
13139 END tie_back_status;
13140
13141 /********************************************************************************************************
13142 * This is the Tie back api which updates the status of pa_bc_packets table after
13143 * confirming the funds checking status of GL / Contract Commitments
13144 *Parameters:
13145 * P_packet_id : Packet Identifier of the funds check process
13146 * P_mode :Funds Checker Operation Mode
13147 * R - Reserve Default
13148 * B - Base line
13149 * C - Check
13150 * P_calling_module :This holds the info of budget type
13151 * GL --- Standard Default
13152 * CBC --- Contract Commitments
13153 * P_reference1 :This Param is not null in case of Contract Commitment
13154 * If P_ext_bdgt_type = CBC
13155 * This param holds the information of document type
13156 * P_reference2 = Igc_cc_interface.document_type
13157 * elsif p_mode = B then
13158 * P_reference1 = project_id
13159 * Else
13160 * P_reference1 = NULL;
13161 * End if;
13162 * P_reference2 :This Param is not null in case of Contract Commitment
13163 * If P_ext_bdgt_type = CBC
13164 * This param holds the information of document Header Id
13165 * P_reference2 = Igc_cc_interface.CC_HEADER_ID
13166 * elsif p_mode = B then
13167 * P_reference2 = budget_version_id
13168 * Else
13169 * P_reference2 = NULL;
13170 * End if;
13171 * p_partial_flag :Partial reservation flag
13172 * Y - partial mode
13173 * N - full Mode default
13174 * P_gl_cbc_return_code :The return status of the GL /CBC funds check process
13175 *************************************************************************************************************/
13176
13177 PROCEDURE PA_GL_CBC_CONFIRMATION
13178 (p_calling_module IN VARCHAR2
13179 ,p_packet_id IN NUMBER
13180 ,p_mode IN VARCHAR2 DEFAULT 'C'
13181 ,p_partial_flag IN VARCHAR2 DEFAULT 'N'
13182 ,p_reference1 IN VARCHAR2 DEFAULT NULL ----- doc type 'CC'
13183 ,p_reference2 IN VARCHAR2 DEFAULT NULL ---- CC_HEADER_ID
13184 ,p_gl_cbc_return_code IN OUT NOCOPY VARCHAR2
13185 ,x_return_status OUT NOCOPY VARCHAR2
13186 ) IS
13187
13188 l_packet_id NUMBER;
13189
13190 CURSOR gl_cur(v_packet_id NUMBER) is
13191 SELECT DISTINCT gl.source_distribution_id_num_1 distribution_id,
13192 gl.event_id,
13193 decode(gl.source_distribution_type,
13194 'AP_INV_DIST','AP',
13195 'AP_PREPAY','AP',
13196 'PA_AP_BURDEN','AP',
13197 'PO_DISTRIBUTIONS_ALL','PO',
13198 'PA_PO_BURDEN','PO',
13199 'PA_REQ_BURDEN','REQ',
13200 'PO_REQ_DISTRIBUTIONS_ALL','REQ') source_distribution_type
13201 FROM gl_bc_packets gl
13202 WHERE gl.packet_id = v_packet_id
13203 AND ( (nvl(substr(gl.result_code,1,1),'P') = 'F'
13204 AND gl.status_code in ('F','R'))
13205 OR (gl.status_code = 'T')
13206 );
13207
13208 -- Cursor to check the number of failed/passed records in gl and accordingly pass return status back to PSA.
13209 -- Note : No need to have partial flag logic here as procedure update_GL_CBC_result_code has already stamped
13210 -- gl bc packets status code based on partial flag.
13211 -- Output values :
13212 -- return 'F' if all have failed --fail
13213 -- return 'P' if some of the records have failed --partial
13214 -- return 'S' if all have success --success
13215
13216 CURSOR gl_return_code IS
13217 SELECT decode(count(*)
13218 ,count(decode(substr(nvl(gl.result_code,'P'),1,1),'P',1)),'S'
13219 ,count(decode(substr(nvl(gl.result_code,'P'),1,1),'F',1,'X',1)),'F'
13220 ,decode(p_partial_flag,'N','F','P')) -- Bug 5522810 : p_partial_flag is also checked before returning partial mode
13221 FROM gl_bc_packets gl
13222 WHERE gl.packet_id = p_packet_id;
13223
13224 -------->6599207 ------As part of CC Enhancements
13225 CURSOR cbc_cur IS
13226 SELECT igc.rowid,igc.reference_9
13227 FROM igc_cc_interface igc
13228 WHERE igc.document_type = p_reference1
13229 AND igc.cc_header_id = p_reference2
13230 AND ((nvl(substr(igc.cbc_result_code,1,1),'P') = 'F'
13231 AND igc.status_code in ('F','R'))
13232 OR (igc.status_code = 'T')
13233 );
13234 -------->6599207 ------END
13235
13236
13237 l_num_rows NUMBER := 100;
13238 l_return_status VARCHAR2(1);
13239 l_gl_cbc_return_code VARCHAR2(10);
13240 l_pa_return_code VARCHAR2(10);
13241 l_mode VARCHAR2(10);
13242 l_debug_mode VARCHAR2(10);
13243 l_calling_module VARCHAR2(30);
13244 l_calling_code VARCHAR2(10);
13245 l_event_result_status VARCHAR2(15);
13246
13247 BEGIN
13248 --Initialize the error stack
13249 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.PA_GL_CBC_CONFIRMATION');
13250
13251 fnd_profile.get('PA_DEBUG_MODE',g_debug_mode );
13252 g_debug_mode := NVL(g_debug_mode, 'N');
13253
13254 If g_debug_mode = 'Y' then
13255 log_message(p_msg_token1=>'Inside PA_GL_CBC_CONFIRMATION api');
13256 end if;
13257
13258 PA_DEBUG.SET_PROCESS( x_process => 'PLSQL'
13259 ,x_write_file => 'LOG'
13260 ,x_debug_mode => g_debug_mode
13261 );
13262
13263 /** Bug fix :2302945 If PA is NOT installed in OU then we should return as success
13264 ** without proceeding further . This api checks whether the In given operating unit
13265 ** project is installed or not, if not installed return with success
13266 **/
13267 IF IS_PA_INSTALL_IN_OU = 'N' then
13268 x_return_status := 'S';
13269 g_return_status := 'S';
13270
13271 If g_debug_mode = 'Y' then
13272 log_message(p_msg_token1=>'PA NOT INSTALLED IN THIS OU.return status='
13273 ||x_return_status);
13274 end if;
13275 PA_DEBUG.Reset_err_stack;
13276 Return;
13277 END IF;
13278 /** End of Bug fix **/
13279
13280 l_mode := p_mode;
13281 If l_mode = 'A' then -- A Adjustment called from PO and REQ only
13282 l_mode := 'R';
13283 End if;
13284
13285 If g_debug_mode = 'Y' Then
13286 log_message(p_msg_token1 =>'INSIDE PA_GL_CBC_CONFIRMATION'||
13287 'calling module ['||p_calling_module|| ']mode ['||l_mode||
13288 ']p_reference1['|| p_reference1||']p_reference2[ '||p_reference2||
13289 ']p_packet_id ['||p_packet_id||']p_partial_flag[ '||p_partial_flag||
13290 ']p_gl_cbc_return_code [ '||p_gl_cbc_return_code||']g_ap_matched_case['||g_ap_matched_case||']');
13291 End if;
13292
13293 -------->6599207 ------As part of CC Enhancements
13294 /* COMMENTED THIS CODE
13295 -- ------------------------------------------------------------------------------------------+
13296 -- :( AS CBC IS NOT SUPPORTED, IF CBC CALLS PA, RETURN 'T' BACK TO CALLING PGM ..
13297 -- ------------------------------------------------------------------------------------------+
13298 --IF l_mode IN ( 'R','C','F' ) AND p_calling_module = 'CBC' THEN
13299 IF p_calling_module = 'CBC' THEN
13300 If g_debug_mode = 'Y' then
13301 log_message(p_msg_token1 => 'PA FC Called for CBC .. FAIL Process');
13302 End if;
13303
13304 p_gl_cbc_return_code := 'T';
13305 x_return_status := 'T';
13306 g_return_status := 'T';
13307
13308 PA_DEBUG.Reset_err_stack;
13309
13310 RETURN;
13311 END IF;
13312 -- ------------------------------------------------------------------------------------------+
13313 -- CBC Check Ends here ....
13314 -- ------------------------------------------------------------------------------------------+
13315 */
13316 -------->6599207 ------END
13317
13318 -------->6599207 ------As part of CC Enhancements -- Added IF condition alone
13319 IF p_calling_module <> 'CBC' THEN
13320
13321 -- -----------------------------------------------------------------------------------+
13322 -- Check if PA FC called for project related txn. or budget or its called for non-FC
13323 -- NO_FC: non-projcet related FC, exit with 'S' status
13324 -- BUD_FC: BC FC called projects (SLA-BC Integration for budget baseline) - new
13325 -- TXN_FC: PA FC called for txn. mode - existing
13326 -- -----------------------------------------------------------------------------------+
13327 CHECK_TXN_OR_BUDGET_FC (p_packet_id,l_calling_code);
13328
13329 If g_debug_mode = 'Y' then
13330 log_message(p_msg_token1=>'FC called mode:'||l_calling_code);
13331 End If;
13332
13333
13334 -- -----------------------------------------------------------------------------------+
13335 -- If NOT PA FC, exit program ..
13336 -- -----------------------------------------------------------------------------------+
13337 If l_calling_code = 'NO_FC' then
13338
13339 x_return_status := 'S';
13340 g_return_status := 'S';
13341 -- Bug 5140510 : p_gl_cbc_return_code should not be overwritten.
13342 -- p_gl_cbc_return_code := 'S';
13343
13344 If g_debug_mode = 'Y' then
13345 log_message(p_msg_token1=>'PA FC called for non-project transactions: EXIT FC program');
13346 End If;
13347
13348 PA_DEBUG.Reset_err_stack;
13349 RETURN;
13350
13351 End If;
13352
13353
13354 -- -------------------------------------------------------------------------------------+
13355 -- SLA-BC Integration: GL FC for budget calls PA tieback, here we execute account level
13356 -- funds check for the baseline mode .. and also build account summary ...
13357 -- -------------------------------------------------------------------------------------+
13358
13359 If l_calling_code = 'BUD_FC' then
13360
13361 If g_debug_mode = 'Y' then
13362 log_message(p_msg_token1=>'Before calling DO_BUDGET_BASELINE_TIEBACK');
13363 End If;
13364
13365 DO_BUDGET_BASELINE_TIEBACK(p_packet_id,x_return_status);
13366
13367 If g_debug_mode = 'Y' then
13368 log_message(p_msg_token1=>'After calling DO_BUDGET_BASELINE_TIEBACK, return status:'||x_return_status);
13369 End If;
13370
13371 If x_return_status <> 'S' then
13372
13373 p_gl_cbc_return_code := 'F';
13374
13375 Else
13376
13377 p_gl_cbc_return_code := 'S';
13378
13379 End If;
13380
13381 RETURN;
13382
13383 End if;
13384 -- -----------------------------------------------------------------------------------+
13385
13386 END IF;
13387 -------->6599207 ------END
13388
13389
13390 -- Intitalize the out NOCOPY parameter
13391 x_return_status := 'S';
13392 If g_debug_mode = 'Y' Then
13393 log_message(p_msg_token1 =>' g_pa_gl_return_status ['||g_pa_gl_return_status||
13394 ']g_pa_cbc_return_status ['||g_pa_cbc_return_status||']');
13395 End if;
13396
13397 -- Assign the status codes of GL / CBC to local varialbes
13398 -- if gl return code is null then derive return code
13399 IF p_gl_cbc_return_code is null and p_calling_module = 'GL' then
13400 l_gl_cbc_return_code := get_gl_return_code
13401 (p_packet_id => p_packet_id
13402 ,p_partial_flag => p_partial_flag);
13403 Elsif p_gl_cbc_return_code in ('P','S','A') then
13404
13405 l_gl_cbc_return_code := 'S';
13406 Else
13407 l_gl_cbc_return_code := nvl(p_gl_cbc_return_code,'S') ;
13408 End if;
13409 If g_debug_mode = 'Y' Then
13410 log_message(p_msg_token1 =>'l_gl_cbc_return_code = '||l_gl_cbc_return_code);
13411 End if;
13412
13413 If p_calling_module = 'CBC' and p_packet_id is NULL then
13414 l_packet_id := g_cbc_packet_id;
13415 Elsif p_calling_module = 'GL' and l_mode not in ('U') then
13416 l_packet_id := p_packet_id;
13417 Elsif l_mode in ('U') then
13418 l_packet_id := g_packet_id;
13419 End if;
13420 If g_debug_mode = 'Y' Then
13421 log_message(p_msg_token1 => 'packet_id ['||l_packet_id||']g_packet_id = '||g_packet_id||
13422 ']g_cbc_packet_id ['||g_cbc_packet_id||']');
13423
13424 log_message(p_stage => 10 ,p_msg_token1 => 'Start Of PA_GL_CBC_CONFIRMATION ');
13425 End if;
13426
13427 IF p_calling_module = 'GL' and l_mode in ('C','R','F') and g_pa_gl_return_status = 'S' then
13428
13429 OPEN gl_cur(l_packet_id);
13430 LOOP
13431 g_tab_src_dist_id_num_1.delete;
13432 g_tab_gl_bc_event_id.delete;
13433 g_tab_src_dist_type.delete;
13434
13435 FETCH gl_cur BULK COLLECT INTO
13436 g_tab_src_dist_id_num_1,g_tab_gl_bc_event_id,g_tab_src_dist_type LIMIT l_num_rows;
13437
13438 If g_debug_mode = 'Y' Then
13439 log_message(p_msg_token1 => ' GL Failed distinct (event/distr/dist type) record count:'
13440 ||g_tab_src_dist_id_num_1.COUNT);
13441 End if;
13442
13443 IF NOT g_tab_src_dist_id_num_1.EXISTS(1) then
13444 EXIT;
13445 END IF;
13446
13447 tie_back_status
13448 (p_calling_module => p_calling_module
13449 ,p_packet_id => l_packet_id
13450 ,p_partial_flag => p_partial_flag
13451 ,p_mode => l_mode
13452 ,p_glcbc_return_code => l_gl_cbc_return_code);
13453
13454 EXIT WHEN gl_cur%notfound;
13455
13456 END LOOP;
13457 CLOSE gl_cur;
13458
13459 -------->6599207 ------As part of CC Enhancements
13460 ---- Uncommented this ELSIF condition
13461 ELSIF p_calling_module = 'CBC' and l_mode in ('C','R','F') and g_pa_cbc_return_status = 'S' then
13462
13463 OPEN cbc_cur;
13464 LOOP
13465 g_tab_rowid.delete;
13466 g_tab_tieback_id.delete;
13467 FETCH cbc_cur BULK COLLECT INTO
13468 g_tab_rowid,g_tab_tieback_id LIMIT l_num_rows;
13469 IF NOT g_tab_rowid.EXISTS(1) then
13470 EXIT;
13471 END IF;
13472
13473 tie_back_status
13474 (p_calling_module => p_calling_module
13475 ,p_packet_id => l_packet_id
13476 ,p_partial_flag => p_partial_flag
13477 ,p_mode => l_mode
13478 ,p_glcbc_return_code => l_gl_cbc_return_code);
13479
13480 EXIT WHEN cbc_cur%notfound;
13481
13482 END LOOP;
13483 CLOSE cbc_cur;
13484
13485 END IF;
13486 -------->6599207 ------END
13487
13488 -- After update of packet status based on GL return code if there are
13489 -- any transactions failed in GL for raw line if not integrated
13490 -- then we have to tie up raw and burden lines in partial mode
13491 If p_calling_module in ('GL','CBC') and
13492 ( g_pa_gl_return_status = 'S' OR g_pa_cbc_return_status = 'S' )then
13493 If g_debug_mode = 'Y' Then
13494 log_message(p_msg_token1 => 'calling sync_raw_burden api in tie back');
13495 End if;
13496 sync_raw_burden
13497 (p_packet_id =>l_packet_id,
13498 p_mode =>l_mode,
13499 p_calling_module =>p_calling_module,
13500 x_return_status =>l_return_status);
13501 If g_debug_mode = 'Y' Then
13502 log_message(p_msg_token1 => 'calling status_code_update api in tie back');
13503 End if;
13504
13505 If g_debug_mode = 'Y' Then
13506 log_message(p_msg_token1 => 'Calling procedure full_mode_failure ..');
13507 End if;
13508
13509 FULL_MODE_FAILURE(p_packet_id => l_packet_id, p_case => 'AP_FULL_MODE_FAILURE');
13510
13511 If g_debug_mode = 'Y' Then
13512 log_message(p_msg_token1 => 'After Calling procedure full_mode_failure ..');
13513 End if;
13514
13515
13516 status_code_update (
13517 p_calling_module => p_calling_module
13518 ,p_packet_id => l_packet_id
13519 ,p_mode => l_mode
13520 ,p_partial => p_partial_flag
13521 ,p_packet_status => l_gl_cbc_return_code
13522 ,x_return_status => l_return_status
13523 );
13524 If g_debug_mode = 'Y' Then
13525 log_message(p_msg_token1 => 'return status = '||l_return_status);
13526 End if;
13527 IF l_return_status <> 'S' then
13528 log_message(p_msg_token1 => 'Failed to update status codes');
13529 End if;
13530 End if;
13531
13532
13533 -- if the return status from gl/ cbc is success then update the budget
13534 -- account balances
13535 IF l_gl_cbc_return_code = 'S' and p_calling_module in ('GL','CBC')
13536 and (g_pa_gl_return_status = 'S' OR g_pa_cbc_return_status = 'S' )
13537 and l_mode in ('R','U','F') then
13538 If g_debug_mode = 'Y' Then
13539 log_message(p_msg_token1 => 'calling upd_bdgt_encum_bal api from tieback');
13540 End if;
13541 upd_bdgt_encum_bal(
13542 p_packet_id => l_packet_id
13543 ,p_calling_module => p_calling_module
13544 ,p_mode => l_mode
13545 ,p_packet_status => l_gl_cbc_return_code
13546 ,x_return_status => l_return_status
13547 );
13548 If g_debug_mode = 'Y' Then
13549 log_message(p_msg_token1 => 'after upd_bdgt_encum_bal api return status ='||l_return_status);
13550 End if;
13551 IF l_return_status <> 'S' then
13552 If g_debug_mode = 'Y' Then
13553 log_message(p_msg_token1 => 'Calling upd_cwk_attributes API');
13554 End if;
13555 End if;
13556
13557 /* PAM changes */
13558 If p_calling_module = 'GL' Then
13559 -- update the cwk attributes for the passed transactions
13560 pa_funds_control_pkg1.upd_cwk_attributes
13561 (p_calling_module => p_calling_module
13562 ,p_packet_id => l_packet_id
13563 ,p_mode => l_mode
13564 ,p_reference => 'UPD_AMTS'
13565 ,x_return_status => l_return_status
13566 );
13567
13568 -- update the cwk compiled_multiplier
13569 pa_funds_control_pkg1.upd_cwk_attributes(
13570 p_calling_module => p_calling_module
13571 ,p_packet_id => l_packet_id
13572 ,p_mode => l_mode
13573 ,p_reference => 'UPD_MULTIPLIER'
13574 ,x_return_status => l_return_status
13575 );
13576
13577 If g_debug_mode = 'Y' Then
13578 log_message(p_msg_token1 => 'End of upd_cwk_attributes API return status ['||l_return_status||']');
13579 End if;
13580
13581 End If;
13582
13583 END IF;
13584
13585 IF p_calling_module in ('GL','CBC') then
13586
13587 If p_calling_module = 'GL' then
13588 l_calling_module := 'GL_TIEBACK';
13589 Elsif p_calling_module = 'CBC' then
13590 l_calling_module := 'CBC_TIEBACK';
13591 Else
13592 l_calling_module := p_calling_module;
13593 End if;
13594 update_GL_CBC_result_code(
13595 p_packet_id => l_packet_id,
13596 p_calling_module => l_calling_module,
13597 p_partial_flag => p_partial_flag,
13598 p_reference1 => p_reference1,
13599 p_reference2 => p_reference2,
13600 p_mode => l_mode,
13601 p_packet_status => l_gl_cbc_return_code,
13602 x_return_status => l_return_status
13603 );
13604
13605 /** commit is used here since in check mode GL does not commit or it may be calling in auto
13606 * nomous mode when called from PO, REQ. so
13607 * even though pa funds check updates the result code and status codes in gl
13608 * it is being setting to null after funds check call
13609 */
13610 --If p_calling_module = 'GL' and p_partial_flag = 'Y' and l_mode = 'C' then
13611 -- commit;
13612 --End if;
13613 -- This COMMIT has been removed as tieback is in the main sesion and by issuing
13614 -- commit, global tables can get wiped out .. R12 change
13615
13616 -- Logic to check the number of failed/passed records in gl and accordingly pass return status back to PSA.
13617 -- return 'F' if all have failed --fail
13618 -- return 'P' if some of the records have failed --partial
13619 -- return 'S' if all have success --success
13620
13621 OPEN gl_return_code ;
13622 FETCH gl_return_code INTO p_gl_cbc_return_code;
13623 CLOSE gl_return_code;
13624
13625 If g_debug_mode = 'Y' Then
13626 log_message(p_msg_token1 => 'Final return value for PSA p_gl_cbc_return_code '||p_gl_cbc_return_code);
13627 End if;
13628
13629 End if;
13630
13631 select decode(p_gl_cbc_return_code,'S',decode(nvl(g_adv_result_code,'X'),'A','A',p_gl_cbc_return_code),p_gl_cbc_return_code)
13632 into p_gl_cbc_return_code -- Added for bug 9156359
13633 from dual;
13634
13635 -- Reset the error stack
13636 PA_DEBUG.reset_err_stack;
13637
13638 RETURN;
13639 EXCEPTION
13640 WHEN OTHERS THEN
13641 IF gl_cur%ISOPEN then
13642 close gl_cur;
13643 END IF;
13644 --IF cbc_cur%ISOPEN then
13645 -- close cbc_cur;
13646 --END IF;
13647
13648 result_status_code_update(p_status_code => 'T',
13649 p_packet_id => l_packet_id);
13650
13651 p_gl_cbc_return_code := 'T';
13652 x_return_status := 'T';
13653
13654 If g_debug_mode = 'Y' Then
13655 log_message(p_msg_token1 => 'Un handled Exception Error in PA_GL_CBC_CONFIRMATION');
13656 End if;
13657 log_message(p_error_msg => sqlcode||sqlerrm);
13658 -- Reset the error stack
13659 PA_DEBUG.reset_err_stack;
13660
13661 END PA_GL_CBC_CONFIRMATION;
13662
13663 /* The following API is added to tie back the status code of the
13664 * bc packets during the distribute vendor invoice adjustments
13665 * This API will be called from PABCCSTB.pls package
13666 */
13667 /*
13668 * Moved the API from main fc process to tieback process to update the bdgt acct balance and status code
13669 * Added for bug : 2961161 to update the status of packet if
13670 * called in DISTVIADJ mode and packet status is success
13671 */
13672 PROCEDURE tieback_pkt_status
13673 (p_calling_module in varchar2
13674 ,p_packet_id in number
13675 ,p_partial_flag in varchar2 default 'N'
13676 ,p_mode in varchar2 default 'R'
13677 ,p_tieback_status in varchar2 default 'T' --'S' for Success, 'T' -- fatal Error
13678 ,p_request_id in number
13679 ,x_return_status OUT NOCOPY varchar2) IS
13680
13681 cursor curViPkts IS
13682 SELECT distinct packet_id
13683 FROM pa_bc_packets
13684 WHERE request_id = p_request_id;
13685
13686 l_tieback_status varchar2(100);
13687 l_packet_id Number;
13688 l_mode Varchar2(100);
13689 l_partial_flag Varchar2(100);
13690
13691 BEGIN
13692 -- Initialize the Variables
13693 x_return_status := 'S';
13694 l_tieback_status := NVl(p_tieback_status,'T');
13695 l_packet_id := p_packet_id;
13696 l_mode := p_mode;
13697 l_partial_flag := NVl(p_partial_flag,'N');
13698
13699 --Initialize the error stack
13700 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.tieback_pkt_status');
13701
13702 fnd_profile.get('PA_DEBUG_MODE',g_debug_mode );
13703 g_debug_mode := NVL(g_debug_mode, 'N');
13704
13705 If g_debug_mode = 'Y' then
13706 log_message(p_msg_token1=>'Inside tieback_pkt_status api');
13707 end if;
13708
13709 PA_DEBUG.SET_PROCESS( x_process => 'PLSQL'
13710 ,x_write_file => 'LOG'
13711 ,x_debug_mode => g_debug_mode
13712 );
13713
13714 IF g_debug_mode = 'Y' Then
13715 log_message(p_msg_token1=>'Inside tieback_pkt_status l_packet_id['||l_packet_id||']l_mode['||
13716 l_mode||']l_partial_flag['||l_partial_flag||']p_calling_module['||
13717 p_calling_module||']p_tieback_status['||p_tieback_status||']p_request_id['||
13718 p_request_id||']' );
13719
13720 End If;
13721
13722 IF IS_PA_INSTALL_IN_OU = 'N' then
13723 x_return_status := 'S';
13724 g_return_status := 'S';
13725
13726 If g_debug_mode = 'Y' then
13727 log_message(p_msg_token1=>'PA NOT INSTALLED IN THIS OU.return status='||x_return_status);
13728 end if;
13729 PA_DEBUG.Reset_err_stack;
13730 Return;
13731 END IF;
13732
13733 IF p_calling_module in ('DISTBTC','DISTVIADJ','DISTCWKST' ) Then
13734 log_message(p_msg_token1 =>'Looping through each packet for the requestId to update the status');
13735
13736 FOR i IN curViPkts LOOP
13737
13738 l_packet_id := i.packet_id;
13739
13740 If l_tieback_status = 'T' Then
13741 If g_debug_mode = 'Y' Then
13742 log_message(p_msg_token1 =>'Calling ResultCode Tieback['||l_packet_id||']');
13743 End If;
13744 tie_back_status
13745 (p_calling_module => p_calling_module
13746 ,p_packet_id => l_packet_id
13747 ,p_partial_flag => l_partial_flag
13748 ,p_mode => l_mode
13749 ,p_glcbc_return_code => l_tieback_status
13750 );
13751 If g_debug_mode = 'Y' then
13752 log_message(p_msg_token1=>'After tie_back_status api call');
13753 end if;
13754 ELSE
13755
13756 If g_debug_mode = 'Y' Then
13757 log_message(p_msg_token1 => 'calling status_code_update in tie back['||l_packet_id||']');
13758 End if;
13759
13760 status_code_update (
13761 p_calling_module => p_calling_module
13762 ,p_packet_id => l_packet_id
13763 ,p_mode => l_mode
13764 ,p_partial => l_partial_flag
13765 ,p_packet_status => l_tieback_status
13766 ,x_return_status => x_return_status
13767 );
13768 If g_debug_mode = 'Y' Then
13769 log_message(p_msg_token1 => 'After StatuscodeUpdate return status['||x_return_status);
13770 End if;
13771
13772 IF ( x_return_status = 'S' AND l_tieback_status = 'S' AND l_mode in ('R','U','F') ) Then
13773
13774 If g_debug_mode = 'Y' then
13775 log_message(p_msg_token1=>'Before upd_bdgt_encum_bal api call');
13776 end if;
13777 upd_bdgt_encum_bal(
13778 p_packet_id => l_packet_id
13779 ,p_calling_module => p_calling_module
13780 ,p_mode => l_mode
13781 ,p_packet_status => l_tieback_status
13782 ,x_return_status => x_return_status
13783 );
13784
13785 If g_debug_mode = 'Y' then
13786 log_message(p_msg_token1=>'After upd_bdgt_encum_bal api call');
13787 end if;
13788 /* PAM changes */
13789 If p_calling_module in ('DISTCWKST') Then
13790 log_message(p_msg_token1 => 'Calling upd_cwk_attributes API');
13791 -- update the cwk attributes for the passed transactions
13792 pa_funds_control_pkg1.upd_cwk_attributes
13793 (p_calling_module => p_calling_module
13794 ,p_packet_id => l_packet_id
13795 ,p_mode => l_mode
13796 ,p_reference => 'UPD_AMTS'
13797 ,x_return_status => x_return_status
13798 );
13799 End If;
13800
13801 End If;
13802 End If; -- l_pkt_status <> 'T'
13803
13804 END LOOP;
13805
13806 END IF;
13807
13808 IF g_debug_mode = 'Y' Then
13809 log_message(p_msg_token1=>'End of tieback_pkt_status API');
13810 End If;
13811
13812 -- Reset the error stack
13813 PA_DEBUG.reset_err_stack;
13814
13815 RETURN;
13816 EXCEPTION
13817 WHEN OTHERS THEN
13818 x_return_status := 'U';
13819 PA_DEBUG.reset_err_stack;
13820 Raise;
13821
13822 END tieback_pkt_status;
13823
13824 -------------------------------------------------------------------------------------
13825 -- This is an overloaded procedure inturn make calls to main funds check function
13826 -- this api is called from GL_funds checker from PO / REQ approval process
13827 -------------------------------------------------------------------------------------
13828 PROCEDURE pa_funds_check
13829 (p_calling_module IN VARCHAR2
13830 ,p_set_of_book_id IN NUMBER
13831 ,p_packet_id IN NUMBER
13832 ,p_mode IN VARCHAR2 DEFAULT 'C'
13833 ,p_partial_flag IN VARCHAR2 DEFAULT 'N'
13834 ,p_reference1 IN VARCHAR2 DEFAULT NULL
13835 ,p_reference2 IN VARCHAR2 DEFAULT NULL
13836 ,x_return_status OUT NOCOPY VARCHAR2
13837 ,x_error_msg OUT NOCOPY VARCHAR2
13838 ,x_error_stage OUT NOCOPY VARCHAR2
13839 ) IS
13840
13841 l_return_status varchar2(100);
13842 l_error_msg varchar2(100);
13843 l_error_stage varchar2(100);
13844
13845 BEGIN
13846
13847
13848
13849 IF NOT pa_funds_check
13850 (p_calling_module => p_calling_module
13851 ,p_conc_flag => 'N'
13852 ,p_set_of_book_id =>p_set_of_book_id
13853 ,p_packet_id => p_packet_id
13854 ,p_mode =>p_mode
13855 ,p_partial_flag =>p_partial_flag
13856 ,p_reference1 =>p_reference1
13857 ,p_reference2 => p_reference2
13858 ,p_reference3 => null
13859 ,x_return_status => x_return_status
13860 ,x_error_msg => x_error_msg
13861 ,x_error_stage => x_error_stage
13862 ) then
13863 If g_debug_mode = 'Y' Then
13864 log_message(p_msg_token1 => 'Error during funds check process');
13865 End if;
13866
13867 End if;
13868 END;
13869
13870 -- ------------------------------------ R12 Start ------------------------------------------------+
13871 -- R12 Changes: New procedure/functions that were added
13872
13873 -- --------------------------------------------------------------------------------+
13874 -- This procedure has been created to handle FULL MODE failure during check funds
13875 -- action of an invoice that is matched to PO .. bug 5253309
13876 -- p_case added to handle future scenarios..
13877 -- This is reqd. especially for scenarios where AP has multiple distributions and
13878 -- some are matched to PO, in such cases the doc. is in 'PARTIAL MODE' but matched
13879 -- dist. is treated in FULL MODE.
13880 -- This procedure will also handle the scenario where var. record failed but original
13881 -- record passed and vice versa ..basically related events failure ..
13882 -- --------------------------------------------------------------------------------+
13883 PROCEDURE Full_mode_failure(p_packet_id IN NUMBER,
13884 p_case IN VARCHAR2)
13885 is
13886 TYPE t_reference1 is table of pa_bc_packets.reference1%type;
13887 TYPE t_reference3 is table of pa_bc_packets.reference3%type;
13888 tt_reference1 t_reference1;
13889 tt_reference3 t_reference3;
13890 Begin
13891 If nvl(p_case,'NO_AP') = 'AP_FULL_MODE_FAILURE' then
13892
13893 -- --------------------------------------------------------------------------------------+
13894 -- Scenario:
13895 -- Document_type doc_dist_id reference1 reference3 doc_dist_type
13896 -- AP 101 PO 2 ITEM
13897 -- AP 102 PO 2 IPV
13898 -- PO 2 AP 101 STANDARD
13899 --
13900 -- First update takes care of the scenario where 101 failed then fail 102
13901 -- 2nd update will take care of the scenario where either 101 or 102 failed, fail PO or
13902 -- PO failed, fail AP.
13903 -- K.Biju June6th,2006
13904 -- --------------------------------------------------------------------------------------+
13905
13906
13907 If g_debug_mode = 'Y' Then
13908 log_message(p_msg_token1 => 'Full_mode_failure: Check AP matched failure case exists');
13909 End if;
13910
13911 /* Bug 5589452 : Update to fail all AP/PO records in packet which are associated with related invoice distributions */
13912 Update pa_bc_packets pbc
13913 set pbc.result_code = 'F170'
13914 where pbc.packet_id = p_packet_id
13915 and substr(pbc.result_code,1,1) = 'P'
13916 and pbc.document_type in ('PO','AP')
13917 and ( decode (pbc.document_type , 'PO' , to_number(pbc.reference2) , 'AP' , pbc.document_header_id),
13918 decode (pbc.document_type , 'PO' , to_number(pbc.reference3) , 'AP' , pbc.document_distribution_id)) IN
13919 /** Select to fetch all related invoice distributions associated with a failed record in packet.
13920 This sql fetches all invoice distributions linked to each other with charge_applicable_to_dist_id and related id**/
13921 ( select distinct b.invoice_id,b.invoice_distribution_id
13922 from ap_invoice_distributions_all a
13923 ,ap_invoice_distributions_all b
13924 where (a.invoice_id,a.invoice_distribution_id) in
13925 /**select to fetch Invoice id and Inv distribution id associated with failed AP/PO records in a packet**/
13926 (select DECODE(pbc1.document_type,'PO',to_number(pbc1.reference2),pbc1.document_header_id),
13927 DECODE(pbc1.document_type,'PO',to_number(pbc1.reference3),pbc1.document_distribution_id)
13928 from pa_bc_packets pbc1
13929 where pbc1.packet_id = p_packet_id
13930 and substr(pbc1.result_code,1,1) = 'F'
13931 and pbc1.document_type in ('AP','PO')
13932 and pbc1.parent_bc_packet_id is null)
13933 and b.invoice_id = a.invoice_id
13934 and COALESCE(b.charge_applicable_to_dist_id,b.related_id,b.invoice_distribution_id) =
13935 COALESCE(a.charge_applicable_to_dist_id,a.related_id,a.invoice_distribution_id)
13936 UNION /*Bug 13602288: Self Assessed Tax Changes - If one transaction is failed funds check, we need to fail all other transactions which are associated to that packet */
13937 select distinct b.invoice_id,b.invoice_distribution_id
13938 from ap_self_assessed_tax_dist_all a
13939 ,ap_self_assessed_tax_dist_all b
13940 where (a.invoice_id,a.invoice_distribution_id) in
13941 /**select to fetch Invoice id and Inv distribution id associated with failed AP/PO records in a packet**/
13942 (select DECODE(pbc1.document_type,'PO',to_number(pbc1.reference2),pbc1.document_header_id),
13943 DECODE(pbc1.document_type,'PO',to_number(pbc1.reference3),pbc1.document_distribution_id)
13944 from pa_bc_packets pbc1
13945 where pbc1.packet_id = p_packet_id
13946 and substr(pbc1.result_code,1,1) = 'F'
13947 and pbc1.document_type in ('AP','PO')
13948 and pbc1.parent_bc_packet_id is null)
13949 and b.invoice_id = a.invoice_id
13950 and COALESCE(b.charge_applicable_to_dist_id,b.related_id,b.invoice_distribution_id) =
13951 COALESCE(a.charge_applicable_to_dist_id,a.related_id,a.invoice_distribution_id)
13952 );
13953
13954
13955 select pbc.reference1,pbc.reference3
13956 BULK COLLECT into tt_reference1,tt_reference3
13957 from pa_bc_packets pbc
13958 where pbc.packet_id = p_packet_id
13959 and pbc.parent_bc_packet_id is null -- this is ok. as this proc. is fired after raw/burden synch
13960 and ((pbc.document_type = 'PO' and
13961 pbc.reference1 = 'AP' and
13962 substr(pbc.result_code,1,1) = 'F')
13963 OR
13964 (pbc.document_type = 'AP' and
13965 pbc.reference1 = 'PO' and
13966 substr(pbc.result_code,1,1) = 'F')
13967 );
13968
13969 If tt_reference1.exists(1) then
13970
13971 If g_debug_mode = 'Y' Then
13972 log_message(p_msg_token1 => 'Full_mode_failure: Yes!! AP matched failure case exists');
13973 log_message(p_msg_token1 => 'Full_mode_failure: Fail related AP distributions,viceversa');
13974 End if;
13975
13976 -- Fail other related AP distributions
13977 -- e.g.: If variance failed then failed original distribution and vice versa
13978 forall x in tt_reference1.FIRST..tt_reference1.LAST
13979 Update pa_bc_packets pbc
13980 set pbc.result_code = 'F170'
13981 where pbc.packet_id = p_packet_id
13982 and pbc.reference3 = tt_reference3(x) -- All rel matched AP dist. has same PO as ref3
13983 and pbc.document_type = 'AP'
13984 and substr(pbc.result_code,1,1) = 'P'
13985 and tt_reference1(x) = 'PO'; -- AP record has PO as reference1
13986
13987 If g_debug_mode = 'Y' Then
13988 log_message(p_msg_token1 => 'Full_mode_failure: Rel. dist. fail, records updated:'||SQL%ROWCOUNT);
13989 log_message(p_msg_token1 => 'Full_mode_failure: Fail PO if AP failed,viceversa');
13990 End if;
13991
13992 -- Fail other records with F170 (full mode failure)
13993 -- basically fail those records with result_code P%%%
13994 forall x in tt_reference1.FIRST..tt_reference1.LAST
13995 Update pa_bc_packets pbc
13996 set pbc.result_code = 'F170'
13997 where pbc.packet_id = p_packet_id
13998 and pbc.document_distribution_id = tt_reference3(x)
13999 and pbc.document_type = tt_reference1(x)
14000 and substr(pbc.result_code,1,1) = 'P';
14001
14002 If g_debug_mode = 'Y' Then
14003 log_message(p_msg_token1 => 'Full_mode_failure: PO-AP full mode, records updated:'||SQL%ROWCOUNT);
14004 End if;
14005
14006 tt_reference1.delete;
14007 tt_reference3.delete;
14008
14009 End if;
14010
14011 End If; --If nvl(p_case,'NO_FAILURE') = 'AP_FULL_MODE_FAILURE' then
14012
14013 End Full_mode_failure;
14014
14015 -- --------------------------------------------------------------------------------+
14016 -- This procedure is called from Synch_pa_gl_packets to AUTONOMOUSLY update
14017 -- pa_bc_packets with failure....in case of extract failing ..
14018 -- -------------------------------------------------------------------------------+
14019 PROCEDURE Missing_records_failure(p_pa_packet_id IN NUMBER,
14020 p_gl_packet_id IN NUMBER,
14021 p_partial_flag IN VARCHAR2,
14022 p_mode IN VARCHAR2) IS
14023 PRAGMA AUTONOMOUS_TRANSACTION;
14024 BEGIN
14025 l_program_name := 'Missing_records_failure:';
14026 If g_debug_mode = 'Y' then
14027 log_message(p_msg_token1=>l_program_name||':Start:p_partial_flag:'|| p_partial_flag );
14028 End If;
14029
14030 forall i in g_event_id.FIRST..g_event_id.LAST
14031 Update pa_bc_packets pbc
14032 set pbc.result_code = 'F173',
14033 pbc.status_code = decode(p_mode,'C','F','R'),
14034 pbc.packet_id = p_gl_packet_id
14035 where pbc.packet_id = p_pa_packet_id
14036 and pbc.bc_event_id = g_event_id(i)
14037 and pbc.document_distribution_id = g_doc_dist_id(i)
14038 and pbc.document_type = g_document_type(i);
14039
14040 -- Bug 5557520 : if F173 is encountered, we should be failing the complete packet
14041 -- without cheking for p_partial_flag as it will result into data corruption.
14042 --If p_partial_flag = 'N' then
14043 -- Full mode failure ...
14044 Update pa_bc_packets pbc
14045 set pbc.result_code = 'F170',
14046 pbc.status_code = decode(p_mode,'C','F','R'),
14047 pbc.packet_id = p_gl_packet_id
14048 where pbc.packet_id = p_pa_packet_id
14049 and substr(nvl(pbc.result_code,'P'),1,1) = 'P';
14050
14051 --End If;
14052
14053 IF g_debug_mode = 'Y' THEN
14054 log_message(p_msg_token1 =>'no of rows Updated in missing records failure ='||sql%rowcount);
14055 End if;
14056
14057 COMMIT;
14058
14059 If g_debug_mode = 'Y' then
14060 log_message(p_msg_token1=>l_program_name||':End');
14061 End If;
14062
14063 End Missing_records_failure;
14064
14065 -- --------------------------------------------------------------------------------+
14066 -- This procedure is called from Synch_pa_gl_packets to update: serial_id,
14067 -- session_id, actual_flag,packet_id and status ..
14068 -- --------------------------------------------------------------------------------+
14069 PROCEDURE Synch_data(p_pa_packet_id IN NUMBER,
14070 p_gl_packet_id IN NUMBER) IS
14071
14072 CURSOR cur_get_gl_data IS
14073 SELECT session_id,
14074 serial_id ,event_id , source_distribution_type
14075 FROM gl_bc_packets
14076 WHERE packet_id = p_gl_packet_id
14077 AND ROWNUM =1 ;
14078
14079 -- Note: bc_event_id is null being used as for integrated case, the balancing
14080 -- entries by PA (PA_PO_BURDEN) are present and that will synch the records
14081 -- so, the issue is only for non-integrated budgets ..
14082 Cursor cur_ap_matched_case is
14083 SELECT 'Y'
14084 FROM dual
14085 WHERE EXISTS(
14086 select 1
14087 from pa_bc_packets pbc1
14088 where pbc1.packet_id = p_pa_packet_id
14089 and pbc1.bc_event_id is null
14090 and pbc1.document_type = 'PO'
14091 and exists (select 1
14092 from pa_bc_packets pbc2
14093 where pbc2.packet_id = p_gl_packet_id
14094 and pbc2.bc_event_id is null
14095 and pbc2.document_type = 'AP'));
14096
14097 l_session_id pa_bc_packets.session_id%TYPE;
14098 l_serial_id pa_bc_packets.serial_id%TYPE;
14099 l_event_id pa_bc_packets.source_event_id%TYPE;
14100 l_source_distribution_type gl_bc_packets.source_distribution_type%TYPE;
14101
14102 PRAGMA AUTONOMOUS_TRANSACTION;
14103 BEGIN
14104 l_program_name := 'Synch_data:';
14105 If g_debug_mode = 'Y' then
14106 log_message(p_msg_token1=>l_program_name||'Start');
14107 End If;
14108
14109 OPEN cur_get_gl_data;
14110 FETCH cur_get_gl_data INTO l_session_id,l_serial_id ,l_event_id,l_source_distribution_type;
14111 CLOSE cur_get_gl_data;
14112
14113 -- ------------------------------------------------------+
14114 -- Need to change this code .. all we need is one update
14115 -- and set g_ap_matched_case flag...
14116 -- ------------------------------------------------------+
14117
14118
14119 If g_debug_mode = 'Y' then
14120 log_message(p_msg_token1 =>'Session Id '||l_session_id||' Serial ID '||l_serial_id||' Event_id '||l_event_id);
14121 log_message(p_msg_token1 =>'p_gl_packet_id '||p_gl_packet_id||' p_pa_packet_id '||p_pa_packet_id);
14122 log_message(p_msg_token1 =>'l_source_distribution_type is '||l_source_distribution_type);
14123
14124 End If;
14125
14126
14127 Update pa_bc_packets pb
14128 set pb.packet_id = p_gl_packet_id,
14129 pb.status_code = decode(pb.status_code,'I','P',pb.status_code),
14130 pb.session_id = DECODE(pb.session_id,NULL,l_session_id,pb.session_id),
14131 pb.serial_id = DECODE(pb.serial_id,NULL,l_serial_id,pb.serial_id)
14132 where pb.packet_id = p_pa_packet_id --Bug 14408086 Added the condition to check event_id and document type
14133 and ( pb.source_event_id in (select distinct event_id
14134 from gl_bc_packets where packet_id = p_gl_packet_id)
14135 or pb.bc_event_id in (select distinct event_id
14136 from gl_bc_packets where packet_id = p_gl_packet_id)
14137 );
14138
14139 /*( pb.source_event_id = l_event_id or pb.bc_event_id = l_event_id
14140 ); */ -- Modified for bug 14665683
14141 /* Removed for bug #14635279 (pb.source_event_id = l_event_id
14142 and (pb.document_type = decode(l_source_distribution_type,'AP_INV_DIST','AP','AP_PREPAY','AP','X')
14143 OR pb.document_type = decode(l_source_distribution_type,'PO_DISTRIBUTIONS_ALL','PO','X')
14144 OR pb.document_type = decode(l_source_distribution_type,'PO_REQ_DISTRIBUTIONS_ALL','REQ','X')
14145 OR pb.document_type = decode(l_source_distribution_type,'CC','CC_C_PAY')
14146 OR pb.document_type = decode(l_source_distribution_type,'CC','CC_P_PAY')
14147 )
14148 )
14149 OR
14150 ( pb.bc_event_id = l_event_id
14151 and (pb.document_type = decode(l_source_distribution_type,'PA_AP_BURDEN','AP','X')
14152 OR pb.document_type = decode(l_source_distribution_type,'PA_PO_BURDEN','PO','X')
14153 OR pb.document_type = decode(l_source_distribution_type,'PA_REQ_BURDEN','REQ','X')
14154 OR pb.document_type = decode(l_source_distribution_type,'CC','CC_C_PAY')
14155 OR pb.document_type = decode(l_source_distribution_type,'CC','CC_P_PAY')
14156 )
14157 )
14158 */
14159
14160
14161 IF g_debug_mode = 'Y' THEN
14162 log_message(p_msg_token1 =>'no of rows Updated ='||sql%rowcount);
14163 log_message('Session Id '||l_session_id||' Serial ID '||l_serial_id||' Event_id '||l_event_id);
14164 End If;
14165
14166
14167 -- ------------------------------------------------------------------------------ +
14168 -- In case of non-integrated records, we do not have the budget relieving entries
14169 -- meaning that there are no PO records, so the above update fails to update info.
14170 -- on the PO records, thats why we have the following code ...
14171 -- Why did we go with this "work around" code
14172 -- For Auto-create case, REQ record.document_distribution_id_num_1 pointed to REQ
14173 -- but for matched case, po's dist. num is pointing to AP.
14174 -- For more info. check bug 5206285 ..
14175 -- ------------------------------------------------------------------------------ +
14176 g_ap_matched_case := 'N';
14177
14178 Open cur_ap_matched_case;
14179 fetch cur_ap_matched_case into g_ap_matched_case;
14180 close cur_ap_matched_case;
14181
14182 COMMIT;
14183
14184 If g_debug_mode = 'Y' then
14185 log_message(p_msg_token1=>l_program_name||'End');
14186 End If;
14187
14188 END Synch_data;
14189
14190
14191
14192 -- --------------------------------------------------------------------------------+
14193 -- This procedure will update the following columns in pa_bc_packets: serial_id,
14194 -- session_id,actual_flag,packet_id and status. Status will be upated from I to P.
14195 -- Called from pa_funds_check
14196 -- This procedure will also check if the extracts were successful, meaning that:
14197 -- A. pa_bc_packet records have been extracted into gl_bc_packets
14198 -- B. core records have been extracted into gl_bc_packets
14199 -- C. project relieveing entries are created in gl_bc_packets
14200 -- --------------------------------------------------------------------------------+
14201 PROCEDURE Synch_pa_gl_packets(x_packet_id IN Number,
14202 x_partial_flag IN VARCHAR2,
14203 x_mode IN VARCHAR2,
14204 x_result_code OUT NOCOPY Varchar2)
14205 IS
14206 l_pa_packet_id pa_bc_packets.packet_id%type;
14207
14208 Cursor c_old_packet is
14209 Select pb.packet_id
14210 from pa_bc_packets pb
14211 where pb.bc_event_id in
14212 (select glbc.event_id
14213 from gl_bc_packets glbc
14214 where glbc.packet_id = x_packet_id)
14215 union all
14216 Select pb.packet_id
14217 from pa_bc_packets pb
14218 where pb.source_event_id in
14219 (select glbc.event_id
14220 from gl_bc_packets glbc
14221 where glbc.packet_id = x_packet_id);
14222
14223 -- 1st select reqd. in the case where core distribution not in gl_bc_packets
14224 -- 2nd select reqd. in the case where PA distribution not in gl_bc_packets
14225
14226 BEGIN
14227
14228 l_program_name := 'Synch_pa_gl_packets:';
14229 If g_debug_mode = 'Y' then
14230 log_message(p_msg_token1=>l_program_name||'Start:x_packet_id,x_partial_flag:'||
14231 x_packet_id||','||x_partial_flag );
14232 End If;
14233
14234 -- Get the packet_id that was established earlier ..
14235 Open c_old_packet;
14236 fetch c_old_packet into l_pa_packet_id;
14237 Close c_old_packet;
14238
14239 If g_debug_mode = 'Y' then
14240 log_message(p_msg_token1=>l_program_name||' Previously establised packet is:'||l_pa_packet_id);
14241 End If;
14242
14243 If l_pa_packet_id is not null then
14244
14245 -- ---------------------------------------------------------------------------------------------- +
14246 -- A. Check if there is any extract failure ... for PA records
14247 If g_debug_mode = 'Y' then
14248 log_message(p_msg_token1=>l_program_name||' Previously establised packet is:'||l_pa_packet_id);
14249 End If;
14250 -- ---------------------------------------------------------------------------------------------- +
14251
14252 -------->6599207 ------As part of CC Enhancements
14253 -- modified doctype checking. Added CC_C_PAY also.
14254
14255 Select pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
14256 BULK COLLECT into g_event_id,g_doc_dist_id,g_document_type
14257 from pa_bc_packets pbc
14258 where packet_id = l_pa_packet_id
14259 and pbc.bc_event_id is not null -- to filter out non-integrated budgets ...
14260 group by pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
14261 having count(pbc.bc_event_id) > (select count(glbc.event_id)
14262 from gl_bc_packets glbc--,
14263 --xla_distribution_links xlad
14264 where glbc.packet_id = x_packet_id
14265 and glbc.event_id = pbc.bc_event_id
14266 and glbc.source_distribution_id_num_1 = pbc.document_distribution_id
14267 and decode(glbc.source_distribution_type,
14268 'PA_AP_BURDEN','AP',
14269 'PA_PO_BURDEN','PO',
14270 'PA_REQ_BURDEN','REQ','CC','CC_')||
14271 decode(glbc.source_distribution_type,'CC',substr(pbc.document_type,4),'')
14272 = pbc.document_type);
14273 --and xlad.event_id = glbc.event_id
14274 --and xlad.ae_header_id = glbc.ae_header_id
14275 --and xlad.ae_line_num = glbc.ae_line_num
14276 --and xlad.applied_to_entity_code <> 'BUDGETS');
14277 -- cannot use xla_distribution_links as FC is AUTONOMOUS
14278 -------->6599207 ------END
14279
14280 If g_debug_mode = 'Y' then
14281 log_message(p_msg_token1=>l_program_name||':'||g_event_id.COUNT||' PA event(s) did not have corr. gl_bc_packet records');
14282 End If;
14283
14284 If g_event_id.COUNT > 0 then -- COUNT
14285
14286 If g_debug_mode = 'Y' then
14287 log_message(p_msg_token1=>l_program_name||' Calling missing_records_failure');
14288 End If;
14289
14290 MISSING_RECORDS_FAILURE(p_pa_packet_id => l_pa_packet_id,
14291 p_gl_packet_id => x_packet_id,
14292 p_partial_flag => x_partial_flag,
14293 p_mode => x_mode);
14294 If g_debug_mode = 'Y' then
14295 log_message(p_msg_token1=>l_program_name||' After Calling missing_records_failure api');
14296 End If;
14297
14298 g_event_id.DELETE;
14299 g_doc_dist_id.DELETE;
14300 g_document_type.DELETE;
14301
14302
14303 -- Bug 5557520 : If F173 failure then return fatal error irrespective of partial flag
14304 -- If all records have failed, set result code to 'F' so that
14305 -- FC will not proceed further .. (meaning after synch, it exists) ..
14306 Begin
14307
14308 select null -- null is ok ..
14309 into x_result_code
14310 from dual
14311 where exists
14312 (Select 1
14313 from pa_bc_packets
14314 where packet_id = l_pa_packet_id
14315 and status_code = 'I');
14316 Exception
14317 when no_data_found then
14318 x_result_code := 'F';
14319 End;
14320
14321
14322 End If; -- COUNT
14323
14324 -- ---------------------------------------------------------------------------------------------------------+
14325 If g_debug_mode = 'Y' then
14326 log_message(p_msg_token1=>l_program_name||':result code:'||x_result_code);
14327 log_message(p_msg_token1=>l_program_name||':If resultcode <> F then check if core records are missing');
14328 End If;
14329 -- ---------------------------------------------------------------------------------------------------------+
14330
14331 /* ===============================================================================================================+
14332 THIS IS NO LONGER REQUIRED .. SA PSA ENSURES THAT ALL RECORDS ARE COPIED OVER .....
14333
14334 If nvl(x_result_code,'P') <> 'F' then
14335
14336 Select pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
14337 BULK COLLECT into g_event_id,g_doc_dist_id,g_document_type
14338 from pa_bc_packets pbc
14339 where pbc.packet_id = l_pa_packet_id
14340 and pbc.status_code = 'I'
14341 and pbc.source_event_id is not null
14342 and not exists (select 1
14343 from gl_bc_packets glbc
14344 where glbc.packet_id = x_packet_id
14345 and glbc.event_id = pbc.source_event_id
14346 and glbc.source_distribution_id_num_1 = pbc.document_distribution_id);
14347
14348 If g_debug_mode = 'Y' then
14349 log_message(p_msg_token1=>l_program_name||':'||g_event_id.COUNT||
14350 ' BC events did not have corr. gl_bc_packet records');
14351 End If;
14352
14353 If g_event_id.COUNT > 0 then -- COUNT
14354
14355 If g_debug_mode = 'Y' then
14356 log_message(p_msg_token1=>l_program_name||' Calling missing_records_failure');
14357 End If;
14358
14359 MISSING_RECORDS_FAILURE(p_pa_packet_id => l_pa_packet_id,
14360 p_gl_packet_id => x_packet_id,
14361 p_partial_flag => x_partial_flag,
14362 p_mode => x_mode);
14363
14364 g_event_id.DELETE;
14365 g_doc_dist_id.DELETE;
14366 g_document_type.DELETE;
14367
14368
14369 If x_partial_flag = 'N' then -- PARTIAL FLAG CHECK
14370
14371 -- Full mode failure ...
14372 x_result_code := 'F';
14373
14374 Elsif x_partial_flag = 'Y' then
14375
14376 -- Partial mode failure ..
14377 -- If all records have failed, set result code to 'F' so that
14378 -- FC will not proceed further .. (meaning after synch, it exists) ..
14379 Begin
14380
14381 select null -- null is ok ..
14382 into x_result_code
14383 from dual
14384 where exists
14385 (Select 1
14386 from pa_bc_packets
14387 where packet_id = l_pa_packet_id
14388 and status_code = 'I');
14389 Exception
14390 when no_data_found then
14391 x_result_code := 'F';
14392 End;
14393
14394 End If; -- PARTIAL FLAG CHECK
14395
14396 End if; --If g_event_id.COUNT > 0 then -- COUNT
14397
14398 End If; -- If nvl(x_result_code,'P') = 'F' then
14399
14400 -- ---------------------------------------------------------------------------------------------------------+
14401 If g_debug_mode = 'Y' then
14402 log_message(p_msg_token1=>l_program_name||':result code:'||x_result_code);
14403 log_message(p_msg_token1=>l_program_name||':If resultcode <> F then check if PA relieving created');
14404 End If;
14405 -- ---------------------------------------------------------------------------------------------------------+
14406 =============================================================================================================== */
14407
14408 If nvl(x_result_code,'P') <> 'F' then
14409
14410 Select DISTINCT pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
14411 BULK COLLECT into g_event_id,g_doc_dist_id,g_document_type
14412 from pa_bc_packets pbc
14413 where pbc.packet_id = l_pa_packet_id
14414 and pbc.status_code = 'I'
14415 and pbc.bc_event_id is not null
14416 and (document_type not like 'CC%' or parent_bc_packet_id is not null) -- added for bug 10429325
14417 and not exists (select glbc.source_distribution_id_num_1
14418 from gl_bc_packets glbc
14419 where glbc.packet_id = x_packet_id
14420 and (glbc.event_id = pbc.bc_event_id
14421 OR
14422 glbc.event_id = pbc.source_event_id)
14423 -- 2nd clause to take care of sep. line burdening
14424 and glbc.source_distribution_id_num_1 = pbc.document_distribution_id
14425 and (nvl(glbc.accounted_dr,0) - nvl(glbc.accounted_cr,0)) = -1 * (pbc.accounted_dr - pbc.accounted_cr)
14426 );
14427
14428 If g_debug_mode = 'Y' then
14429 log_message(p_msg_token1=>l_program_name||':'||g_event_id.COUNT||
14430 ' Distribution(s) missing PA relieving records');
14431 End If;
14432
14433 If g_event_id.COUNT > 0 then -- COUNT
14434
14435 If g_debug_mode = 'Y' then
14436 log_message(p_msg_token1=>l_program_name||' Calling missing_records_failure');
14437 End If;
14438
14439 MISSING_RECORDS_FAILURE(p_pa_packet_id => l_pa_packet_id,
14440 p_gl_packet_id => x_packet_id,
14441 p_partial_flag => x_partial_flag,
14442 p_mode => x_mode);
14443
14444 g_event_id.DELETE;
14445 g_doc_dist_id.DELETE;
14446 g_document_type.DELETE;
14447
14448 If x_partial_flag = 'N' then -- PARTIAL FLAG CHECK
14449
14450 -- Full mode failure ...
14451 x_result_code := 'F';
14452
14453 Elsif x_partial_flag = 'Y' then
14454
14455 -- Partial mode failure ..
14456 -- If all records have failed, set result code to 'F' so that
14457 -- FC will not proceed further .. (meaning after synch, it exists) ..
14458 Begin
14459
14460 select null -- null is ok ..
14461 into x_result_code
14462 from dual
14463 where exists
14464 (Select 1
14465 from pa_bc_packets
14466 where packet_id = l_pa_packet_id
14467 and status_code = 'I');
14468 Exception
14469 when no_data_found then
14470 x_result_code := 'F';
14471 End;
14472
14473 End If; -- PARTIAL FLAG CHECK
14474
14475 End if; --If g_event_id.COUNT > 0 then -- COUNT
14476
14477 End If; -- If nvl(x_result_code,'P') = 'F' then
14478 -- ---------------------------------------------------------------------------------------------------------+
14479
14480 -- B. Update pa_bc_packet data
14481
14482 SYNCH_DATA(p_pa_packet_id => l_pa_packet_id,
14483 p_gl_packet_id => x_packet_id);
14484
14485 End If;
14486
14487 If g_debug_mode = 'Y' then
14488 log_message(p_msg_token1=>l_program_name||'End:x_result_code:'||x_result_code);
14489 End If;
14490
14491 End Synch_pa_gl_packets;
14492
14493 -- --------------------------------------------------------------------------------+
14494 -- This procedure will mark gl_bc_packets records to a status such that GL does
14495 -- not execute funds available validation. Previously we used to create liquidation
14496 -- entries. Instead of that, we're executing the following procedure.
14497 -- This is for NO/SEPARATE LINE BURDENING only.
14498 -- This procedure is called from function pa_funds_check
14499 -- --------------------------------------------------------------------------------+
14500 /*
14501 PROCEDURE Mark_gl_bc_packets_for_no_fc (p_packet_id IN Number)
14502 IS
14503 -- At this point we should not check for result code ...
14504 Cursor c_bc_packet_id is
14505 select distinct pabc.project_id
14506 from pa_bc_packets pabc
14507 where pabc.packet_id = p_packet_id;
14508
14509 l_project_burden_method VARCHAR2(15);
14510
14511 Begin
14512 If g_debug_mode = 'Y' Then
14513 log_message(p_msg_token1 =>'In Mark_gl_bc_packets_for_no_fc - Start');
14514 End if;
14515
14516 for x in c_bc_packet_id loop
14517
14518 l_project_burden_method := pa_funds_control_pkg.check_bdn_on_sep_item(x.project_id);
14519
14520 If (l_project_burden_method <> 'DIFFERENT') then
14521
14522 Update gl_bc_packets glbc
14523 set status_code = 'P' -- Open Issue no 4 in DLD: Check if this is final ?????
14524 where glbc.rowid in
14525 (select pabc.gl_row_number
14526 from pa_bc_packets pabc
14527 where pabc.packet_id = p_packet_id
14528 and pabc.project_id = x.project_id
14529 and pabc.parent_bc_packet_id is null
14530 );
14531 End If;
14532 end loop;
14533
14534 If g_debug_mode = 'Y' Then
14535 log_message(p_msg_token1 =>'In Mark_gl_bc_packets_for_no_fc - End');
14536 End if;
14537
14538 End Mark_gl_bc_packets_for_no_fc;
14539 */
14540 -- --------------------------------------------------------------------------------+
14541 -- This procedure will determine whether funds check/ funds check tieback
14542 -- has been called for non-project related/project related txn. or budget
14543 -- funds check.
14544 -- p_return_code: 'NO_FC', For non-project related FC
14545 -- p_return_code: 'TXN_FC',For project related txn. (including 'RESERVE_BASELINE')
14546 -- p_return_code: 'BUD_FC',For SLA-BC budget baseline integration (GL FC)
14547 -- --------------------------------------------------------------------------------+
14548 PROCEDURE Check_txn_or_budget_fc(p_packet_id in number,
14549 p_return_code out NOCOPY varchar2)
14550 IS
14551 BEGIN
14552
14553 If g_debug_mode = 'Y' Then
14554 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc - Start');
14555 End if;
14556
14557 -- Code should first check txns. and then the global variables
14558 -- Reason: As during budget abseline, PA FC will be called 2 times,
14559 -- 1st time for txn. FC and the 2nd time for Account FC (by PSA)
14560 -- so, the 1st time , output should be 'TXN_FC' and the 2nd time 'BUD/REV_FC'
14561
14562 -- Check if its a "projects transaction" related FC
14563
14564 Select 'TXN_FC'
14565 into p_return_code
14566 from dual
14567 where exists
14568 (select 1 from pa_bc_packets
14569 where packet_id = p_packet_id);
14570
14571 If g_debug_mode = 'Y' Then
14572 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc:p_return_code'||p_return_code);
14573 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc - End');
14574 End If;
14575
14576 EXCEPTION
14577
14578 When no_data_found then
14579
14580 -- Is it a budget baseline /year-end/budget check funds related FC call ..
14581
14582 If nvl(pa_budget_fund_pkg.g_processing_mode,'FC') in ('YEAR_END','BASELINE','CHECK_FUNDS') then
14583
14584 p_return_code := 'BUD_FC';
14585
14586 Else
14587 -- This PA FC call is for "non-project" related txn.
14588 p_return_code := 'NO_FC';
14589
14590 End If;
14591
14592 If g_debug_mode = 'Y' Then
14593 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc:p_return_code'||p_return_code);
14594 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc - End');
14595 End if;
14596
14597 END Check_txn_or_budget_fc;
14598
14599 -- --------------------------------------------------------------------------------+
14600 -- This procedure will be called from do_budget_baseline to fail pa_bc_packet
14601 -- records (by account and period) that fails account level validation or
14602 -- account level funds check. Procedure is AUTONOMOUS.
14603 -- --------------------------------------------------------------------------------+
14604 PROCEDURE Fail_bc_pkt_during_baseline(P_budget_version_id IN NUMBER,
14605 P_period_name IN g_tab_period_name%TYPE,
14606 P_budget_ccid IN g_tab_budget_ccid%TYPE,
14607 P_allow_flag IN g_tab_allow_flag%TYPE,
14608 P_result_code IN VARCHAR2)
14609 IS
14610 PRAGMA AUTONOMOUS_TRANSACTION;
14611 Begin
14612
14613 If g_debug_mode = 'Y' Then
14614 log_message(p_msg_token1 =>'Inside Fail_bc_pkt_during_baseline');
14615 log_message(p_msg_token1 =>'P_result_code='||P_result_code);
14616 End if;
14617
14618 If P_result_code <> 'F170' then
14619
14620 Forall i in P_budget_ccid.FIRST..P_budget_ccid.LAST
14621 Update pa_bc_packets
14622 set status_code = 'R',
14623 result_code = P_result_code
14624 where budget_version_id = P_budget_version_id
14625 and budget_ccid = P_budget_ccid(i)
14626 and period_name = P_period_name(i)
14627 and P_allow_flag(i) = 'N';
14628
14629 Elsif P_result_code = 'F170' then
14630
14631 Update pa_bc_packets
14632 set status_code = 'R',
14633 result_code = 'F170'
14634 where budget_version_id = P_budget_version_id
14635 and status_code in ('P','A');
14636
14637 End If;
14638
14639 COMMIT;
14640
14641 End Fail_bc_pkt_during_baseline;
14642
14643 -- --------------------------------------------------------------------------------+
14644 -- This procedure will be called from do_budget_baseline to fail pa_budget_acct_lines
14645 -- pa_budget_acct_lines (by account and period) that fails account level validation
14646 -- or account level funds check. Procedure is AUTONOMOUS.
14647 -- --------------------------------------------------------------------------------+
14648 PROCEDURE Update_failure_in_acct_summary(P_budget_version_id IN NUMBER,
14649 P_period_name IN g_tab_period_name%TYPE,
14650 P_budget_ccid IN g_tab_budget_ccid%TYPE,
14651 P_allow_flag IN g_tab_allow_flag%TYPE,
14652 P_result_code IN VARCHAR2)
14653 IS
14654 PRAGMA AUTONOMOUS_TRANSACTION;
14655 Begin
14656
14657 If g_debug_mode = 'Y' then
14658 log_message(p_msg_token1=>'Update_failure_in_acct_summary:P_budget_version_id['||P_budget_version_id
14659 ||'], P_result_code['||P_result_code||']' );
14660 log_message(p_msg_token1=>'Update_failure_in_acct_summary: No of records to fail:'||P_budget_ccid.COUNT);
14661 End If;
14662
14663 Forall i in P_budget_ccid.FIRST..P_budget_ccid.LAST
14664 Update pa_budget_acct_lines
14665 set funds_check_status_code = 'R',
14666 funds_check_result_code = P_result_code
14667 where budget_version_id = P_budget_version_id
14668 and code_combination_id = P_budget_ccid(i)
14669 and gl_period_name = P_period_name(i)
14670 and P_allow_flag(i) = 'N'
14671 and P_budget_ccid(i) is not null;
14672 -- last condition is reqd. as zero$ lines will not be existing in draft ..
14673
14674 If g_debug_mode = 'Y' then
14675 log_message(p_msg_token1=>'Update_failure_in_acct_summary: Records Updated:'||SQL%ROWCOUNT);
14676 log_message(p_msg_token1=>'Update_failure_in_acct_summary: Fail other records with F170');
14677 End If;
14678
14679 Update pa_budget_acct_lines
14680 set funds_check_status_code = 'R',
14681 funds_check_result_code = 'F170'
14682 where budget_version_id = P_budget_version_id
14683 and nvl(funds_check_status_code,'P') <> 'R';
14684
14685 If g_debug_mode = 'Y' then
14686 log_message(p_msg_token1=>'Update_failure_in_acct_summary: Records Updated:'||SQL%ROWCOUNT);
14687 End If;
14688
14689 COMMIT;
14690
14691 End Update_failure_in_acct_summary;
14692
14693 -- --------------------------------------------------------------------------------+
14694 -- This procedure will be called from do_budget_baseline to update pa_bc_packet
14695 -- project_acct_result_code and result_code to 'P101' after account level funds
14696 -- check is successful. Procedure is AUTONOMOUS
14697 -- --------------------------------------------------------------------------------+
14698 PROCEDURE Upd_bc_pkt_acct_result_code(P_budget_version_id IN NUMBER)
14699 IS
14700 PRAGMA AUTONOMOUS_TRANSACTION;
14701 Begin
14702 Update pa_bc_packets
14703 set project_acct_result_code = 'P101',
14704 result_code = 'P101'
14705 where budget_version_id = P_budget_version_id;
14706
14707 If g_debug_mode = 'Y' then
14708 log_message(p_msg_token1=>l_program_name||'Upd_bc_pkt_acct_result_code records updated:'||SQL%ROWCOUNT);
14709 End If;
14710
14711 COMMIT;
14712 End Upd_bc_pkt_acct_result_code;
14713
14714 -- --------------------------------------------------------------------------------+
14715 -- Procedure Update_budget_ccid updates budget_ccid on the pa_bc_packet records
14716 -- for this baseline, its an AUTONOMOUS procedure ..
14717 -- --------------------------------------------------------------------------------+
14718 PROCEDURE Update_budget_ccid(P_budget_version_id IN NUMBER,
14719 P_budget_ccid IN g_tab_budget_ccid%TYPE,
14720 P_budget_line_id IN g_tab_budget_line_id%TYPE,
14721 P_budget_entry_level_code IN VARCHAR2,
14722 P_period_name IN g_tab_period_name%TYPE,
14723 P_rlmi IN g_tab_rlmi%TYPE,
14724 P_task_id IN g_tab_task_id%TYPE,
14725 P_derived_ccid IN g_tab_budget_ccid%TYPE,
14726 P_allowed_flag IN g_tab_allow_flag%TYPE,
14727 P_result_code IN OUT NOCOPY VARCHAR2)
14728
14729 IS
14730 PRAGMA AUTONOMOUS_TRANSACTION;
14731 Begin
14732
14733 -- ------------------------------------------------------------------------------------+
14734 If g_debug_mode = 'Y' then
14735 log_message(p_msg_token1=>'Update_budget_ccid: p_budget_entry_level_code['
14736 ||p_budget_entry_level_code||'] Null->Update new CCID else Synch' );
14737 End If;
14738 -- ------------------------------------------------------------------------------------+
14739
14740 p_result_code := 'F';
14741
14742 If p_budget_entry_level_code is NULL then
14743
14744
14745 Forall x in p_derived_ccid.FIRST..p_derived_ccid.LAST
14746 Update pa_bc_packets pbc
14747 set pbc.budget_ccid = p_derived_ccid(x)
14748 where pbc.budget_ccid = p_budget_ccid(x)
14749 and pbc.period_name = p_period_name(x)
14750 and p_allowed_flag(x) = 'Y';
14751
14752 Else
14753
14754 If p_budget_entry_level_code = 'P' then
14755
14756 Forall i in p_budget_ccid.FIRST..p_budget_ccid.LAST
14757 Update pa_bc_packets pbc
14758 set pbc.budget_ccid = p_budget_ccid(i),
14759 pbc.budget_line_id = p_budget_line_id(i)
14760 where pbc.budget_version_id = p_budget_version_id
14761 and pbc.bud_resource_list_member_id = p_rlmi(i)
14762 and pbc.period_name = p_period_name(i);
14763
14764 ElsIf p_budget_entry_level_code in ('L','T','M') then
14765
14766 Forall i in p_budget_ccid.FIRST..p_budget_ccid.LAST
14767 Update pa_bc_packets pbc
14768 set pbc.budget_ccid = p_budget_ccid(i),
14769 pbc.budget_line_id = p_budget_line_id(i)
14770 where pbc.budget_version_id = p_budget_version_id
14771 and pbc.bud_task_id = p_task_id(i)
14772 and pbc.bud_resource_list_member_id = p_rlmi(i)
14773 and pbc.period_name = p_period_name(i);
14774 End If;
14775
14776 End If;
14777
14778 -- ------------------------------------------------------------------------------------+
14779 If g_debug_mode = 'Y' then
14780 log_message(p_msg_token1=>'Update_budget_ccid on pa_bc_packets:Budget_ccid updated on:'
14781 || SQL%ROWCOUNT||' records');
14782 End If;
14783 -- ------------------------------------------------------------------------------------+
14784
14785 Update pa_bc_packets pbc
14786 set pbc.result_code = 'F132',
14787 pbc.status_code = 'R'
14788 where pbc.budget_version_id = p_budget_version_id
14789 and pbc.budget_ccid is null;
14790
14791 -- ------------------------------------------------------------------------------------+
14792 If g_debug_mode = 'Y' then
14793 log_message(p_msg_token1=>'Update_budget_ccid on pa_bc_packets:'
14794 ||' Records with null ccid'||SQL%ROWCOUNT||' If >0 then F132');
14795 End If;
14796 -- ------------------------------------------------------------------------------------+
14797
14798 If SQL%ROWCOUNT > 0 then
14799 p_result_code := 'F';
14800 End if;
14801
14802 COMMIT;
14803 p_result_code := 'S';
14804
14805 Exception
14806
14807 When others then
14808 COMMIT;
14809 p_result_code := 'F';
14810 End Update_budget_ccid;
14811
14812 -- --------------------------------------------------------------------------------+
14813 -- This procedure will check if there exists any txn. against the project
14814 -- It will return 'Y' if any txn exists
14815 -- --------------------------------------------------------------------------------+
14816 Procedure Any_txns_against_project(p_project_id IN NUMBER,
14817 p_txn_exists_in_bc_pkt OUT NOCOPY VARCHAR2,
14818 p_txn_exists_in_bc_cmt OUT NOCOPY VARCHAR2)
14819 IS
14820 Begin
14821 If g_debug_mode = 'Y' then
14822 log_message(p_msg_token1=>'Any_txns_against_project:p_project_id:'||p_project_id);
14823 End If;
14824
14825 If (pa_budget_fund_pkg.g_processing_mode in ('BASELINE','CHECK_FUNDS') and pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y') then
14826
14827 If g_debug_mode = 'Y' then
14828 log_message(p_msg_token1=>'Any_txns_against_project:Baseline/CF Mode-Check if txns. exists in pa_bc_packets');
14829 End If;
14830
14831 Begin
14832 Select 'Y' into p_txn_exists_in_bc_pkt from dual where exists
14833 (select 1 from pa_bc_packets where project_id = p_project_id and status_code in ('A','P','I'));
14834 Exception
14835 When no_data_found then
14836 p_txn_exists_in_bc_pkt := 'N';
14837 End;
14838
14839 If g_debug_mode = 'Y' then
14840 log_message(p_msg_token1=>'Any_txns_against_project:Baseline/CF Mode-Check if txns. exists in pa_bc_commitments');
14841 End If;
14842
14843 Begin
14844 Select 'Y' into p_txn_exists_in_bc_cmt from dual where exists
14845 (select 1 from pa_bc_commitments where project_id = p_project_id);
14846 Exception
14847 When no_data_found then
14848 p_txn_exists_in_bc_cmt := 'N';
14849 End;
14850
14851 Else
14852 p_txn_exists_in_bc_pkt := 'N';
14853 p_txn_exists_in_bc_cmt := 'N';
14854 End if;
14855
14856 End Any_txns_against_project;
14857
14858 -- --------------------------------------------------------------------------------+
14859 -- This procedure will execute the budget account validation, account level FC
14860 -- and update budget lines with the new derived accounts, call PROCEDURE
14861 -- Build_account_summary to build pa_budget_acct_lines
14862 -- Parameters:
14863 -- p_packet_id : packet being funds checked
14864 -- p_return_status : 'S' for success and 'F' for failure
14865 -- --------------------------------------------------------------------------------+
14866 PROCEDURE Do_budget_baseline_tieback(p_packet_id IN NUMBER,
14867 p_return_status OUT NOCOPY VARCHAR2)
14868 IS
14869 t_ccid pa_plsql_datatypes.Idtabtyp;
14870 t_bud_ccid pa_plsql_datatypes.Idtabtyp;
14871 t_budget_line_id pa_plsql_datatypes.Idtabtyp;
14872 t_rlmi pa_plsql_datatypes.Idtabtyp;
14873 t_parent_rlmi pa_plsql_datatypes.Idtabtyp;
14874 t_project_id pa_plsql_datatypes.Idtabtyp;
14875 t_task_id pa_plsql_datatypes.Idtabtyp;
14876 t_top_task_id pa_plsql_datatypes.Idtabtyp;
14877 t_prev_ver_ccid pa_plsql_datatypes.Idtabtyp;
14878 t_start_date pa_plsql_datatypes.Datetabtyp;
14879 t_txn_currency_code pa_plsql_datatypes.char50TabTyp;
14880 t_draft_needs_update pa_plsql_datatypes.char50TabTyp;
14881 t_draft_budget_rowid rowidtabtyp;
14882 t_draft_ccid pa_plsql_datatypes.Idtabtyp;
14883 t_raid TypeNum;
14884 t_gl_rowid rowidtabtyp;
14885 t_budget_rowid rowidtabtyp;
14886 t_budget_start_date TypeDate;
14887 l_bvid_for_acct_changed_API pa_budget_versions.budget_Version_id%type;
14888
14889 l_count NUMBER(4);
14890 l_validation_failed VARCHAR2(1);
14891 l_set_of_books_id pa_implementations_all.set_of_books_id%type;
14892 l_budget_entry_level_code pa_budget_entry_methods.entry_level_code%TYPE;
14893 l_current_budget_version_id pa_budget_versions.budget_version_id%TYPE;
14894 l_draft_budget_version_id pa_budget_versions.budget_version_id%TYPE;
14895 l_result_code pa_bc_packets.result_code%TYPE;
14896 l_acct_changed VARCHAR2(1);
14897 l_draft_acct_changed_flag VARCHAR2(1);
14898 l_record_updated_flag VARCHAR2(1);
14899 l_project_id pa_budget_versions.project_id%type;
14900 l_txn_exists_bc_pkt_flag VARCHAR2(1);
14901 l_txn_exists_bc_cmt_flag VARCHAR2(1);
14902 l_gl_failure_flag VARCHAR2(1);
14903 l_derive_draft_values VARCHAR2(1);
14904
14905 -- Step 2.0: Synch budget lines and pa_bc_packets ....
14906 Cursor c_acct_sync_bud_line_pa_bc_pkt(p_budget_version_id in NUMBER,
14907 p_set_of_books_id IN NUMBER,
14908 p_project_id IN NUMBER) is
14909 select pbl.code_combination_id,
14910 pbl.budget_line_id,
14911 pra.resource_list_member_id,
14912 pra.task_id,
14913 pbl.period_name --glps.period_name
14914 from pa_budget_lines pbl,
14915 pa_resource_assignments pra--,
14916 --gl_period_statuses glps
14917 where pra.budget_version_id = p_budget_version_id
14918 and pra.project_id = p_project_id -- added to improve performance ..
14919 and pra.budget_version_id = pbl.budget_version_id
14920 and pra.resource_assignment_id = pbl.resource_assignment_id;
14921 --and glps.application_id = 101
14922 --and glps.set_of_books_id = p_set_of_books_id
14923 --and trunc(pbl.start_date) = trunc(glps.start_date)
14924 --and exists (select 1
14925 -- from pa_bc_packets pbc
14926 -- where pbc.budget_version_id = pbl.budget_version_id
14927 -- and pbc.resource_list_member_id = pra.resource_list_member_id
14928 -- and (pra.task_id = pbc.task_id OR
14929 -- pra.task_id = pbc.top_task_id OR
14930 -- pra.task_id = 0)
14931 -- and glps.period_name = pbc.period_name
14932 -- );
14933
14934 -- Step 3.0: Identify records that have failed in gl_bc_packets ..
14935 Cursor c_gl_failure(p_budget_version_id in number) is
14936 select pbl.code_combination_id budget_ccid,
14937 pbl.period_name period_name,
14938 'N' allow_flag ,
14939 pra.project_id,
14940 pra.task_id,
14941 pra.resource_list_member_id rlmi,
14942 pbl.start_date,
14943 pbl.txn_currency_code
14944 from gl_bc_packets glbc,
14945 pa_budget_lines pbl,
14946 pa_resource_assignments pra
14947 where glbc.packet_id = p_packet_id
14948 and pbl.budget_version_id = p_budget_version_id
14949 and pbl.budget_line_id = glbc.source_distribution_id_num_1
14950 and substr(nvl(glbc.result_code,'P'),1,1) = 'F'
14951 and pra.resource_assignment_id = pbl.resource_assignment_id
14952 and pra.budget_version_id = pbl.budget_version_id;
14953 --and nvl(glbc.result_code,'P) <> 'F35';
14954
14955 -- Step 4.0: This cursor is used to synch account data between gl_bc_packets and the budget ..
14956 Cursor c_budget_lines_synch(p_budget_version_id in number) is
14957 select glbc.code_combination_id sla_ccid,
14958 glbc.rowid gl_rowid,
14959 pbl.code_combination_id budget_ccid,
14960 pbl.resource_assignment_id budget_raid,
14961 pbl.rowid budget_rowid,
14962 pbl.start_date start_date,
14963 pbl.period_name period_name,
14964 'Y' allow_flag,
14965 pbl.budget_line_id budget_line_id,
14966 pbl.txn_currency_code txn_currency_code,
14967 'N' draft_needs_update,
14968 pra.project_id,
14969 pra.task_id,
14970 pra.resource_list_member_id,
14971 nvl(prlm.parent_member_id,-99) parent_rlmi
14972 from gl_bc_packets glbc,
14973 pa_budget_lines pbl,
14974 pa_resource_assignments pra,
14975 pa_resource_list_members prlm
14976 where glbc.packet_id = p_packet_id
14977 and pbl.budget_version_id = p_budget_version_id
14978 and pbl.budget_line_id = glbc.source_distribution_id_num_1
14979 and pra.resource_assignment_id = pbl.resource_assignment_id
14980 and pra.budget_version_id = pbl.budget_version_id
14981 and prlm.resource_list_member_id = pra.resource_list_member_id;
14982 --and nvl(pbl.code_combination_id,-1) <> glbc.code_combination_id;
14983
14984 -- Above commented as user could have changed draft account and then modified
14985 -- SLA setup to derive the same account ..meaning..we need to compare ccids across version ..
14986
14987 -- Step 7.0: Cursor used for account level funds check
14988 -- Logic:
14989 -- Get the distinct ccid/start/end date combo from pa_bc_packets and for that check if there
14990 -- are any combo having sum(available amount) < 0
14991
14992 Cursor c_acct_lines(p_current_bvid IN NUMBER) is
14993 select pbl.gl_period_name, pbl.code_combination_id ,'N' allow_flag
14994 from pa_budget_acct_lines pbl
14995 where (pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date) in
14996 (select pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date
14997 from pa_budget_acct_lines pbl
14998 where (pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date) in
14999 (select distinct a.budget_version_id,a.budget_ccid,a.fc_start_date,a.fc_end_date
15000 from pa_bc_packets a
15001 where a.budget_version_id = p_current_bvid)
15002 group by pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date
15003 having sum(nvl(pbl.Curr_Ver_Available_Amount,0)) < 0
15004 )
15005 UNION
15006 -- Bug 5206341 : Cursor to validate account level balances for Open and Closed periods
15007 select pbl.gl_period_name, pbl.code_combination_id ,'N' allow_flag
15008 from pa_budget_acct_lines pbl
15009 where (pbl.budget_version_id,pbl.code_combination_id) in
15010 (select pbl.budget_version_id,pbl.code_combination_id
15011 from pa_budget_acct_lines pbl
15012 where pbl.budget_version_id = p_current_bvid
15013 group by pbl.budget_version_id,pbl.code_combination_id
15014 having sum(nvl(pbl.Curr_Ver_Available_Amount,0)) < 0
15015 )
15016 AND PA_FUNDS_CONTROL_UTILS.CLOSED_PERIODS_EXISTS_IN_BUDG(p_current_bvid) ='Y' ;
15017
15018 --and pbl.Curr_Ver_Available_Amount < 0;
15019 -- Draft has Jan and txn for Dec.. YTD/Y, in that case, Jan should have failure too
15020
15021 -- 10.0: Cursor used to select records to fail all records ....
15022 -- As data split between packet, records were not being failed in the credit packet ..
15023 Cursor c_gl_records is
15024 select glbc.rowid,glbc.ae_header_id,glbc.ledger_id
15025 from gl_bc_packets glbc
15026 where glbc.event_id in
15027 (select event_id from psa_bc_xla_events_gt);
15028
15029 l_dummy_value number(1);
15030
15031 Begin
15032
15033 l_program_name := 'Do_Budget_baseline_tieback:';
15034 If g_debug_mode = 'Y' then
15035 log_message(p_msg_token1=>l_program_name||'Start');
15036 End If;
15037
15038 /* If CC Logic needs to be added then we will need to have some sort of outer
15039 loop which will exeute for Cost and CC budget
15040 */
15041 -- ---------------------------------------------------------------------------+
15042 -- 0.0: Is the call for the current version?? if not exit
15043 -- Reason: BC calls PAFC 2 times as the packets are created per entity_id
15044 -- So: During a CF after baseline or re-baseline, 2 packets will be
15045 -- created, for the reversing packet, we should not do any processing
15046 -- Account check etc. is not reqd. for the reversing as we use
15047 -- 'LINE REVERSALS'
15048 -- ---------------------------------------------------------------------------+
15049 log_message(p_msg_token1=>l_program_name||'Check if PAFC called for current version');
15050
15051 l_dummy_value := 0;
15052
15053 Begin
15054
15055 Select 1 into l_dummy_value from dual
15056 where exists (Select 1
15057 from gl_bc_packets glbc,
15058 pa_budget_lines pbl
15059 where glbc.packet_id = p_packet_id
15060 and pbl.budget_version_id = pa_budget_fund_pkg.g_cost_current_bvid
15061 and pbl.budget_line_id = glbc.source_distribution_id_num_1);
15062
15063 Exception
15064 When no_data_found then
15065 null;
15066 End;
15067
15068 If l_dummy_value = 0 then
15069 If g_debug_mode = 'Y' then
15070 log_message(p_msg_token1=>l_program_name||'PA FC called for prev. baselined version');
15071 End If;
15072
15073 g_packet_credit_processed := 'Y';
15074
15075 If g_packet_debit_processed = 'Y' then
15076 log_message(p_msg_token1=>l_program_name||': As debit already processed Calling Fail_credit_packet');
15077 FAIL_CREDIT_PACKET(p_input_packet => 'CREDIT',
15078 p_return_status_code => p_return_status);
15079 End if;
15080
15081 RETURN;
15082 End If;
15083
15084 If g_debug_mode = 'Y' then
15085 l_program_name := 'Do_budget_baseline_tieback';
15086 log_message(p_msg_token1=>l_program_name||'PA FC called for latest version - Draft/Baselined');
15087 End If;
15088
15089 -- ---------------------------------------------------------------------------+
15090 -- 1.0: Initalize variables ..
15091 -- ---------------------------------------------------------------------------+
15092 -- 1.1: Return Status: If all steps pass, send 'S', else send 'F'
15093 p_return_status := 'S';
15094
15095 -- 1.2: initalize limit var. used for bulk ..
15096 l_limit := 500;
15097
15098 -- 1.3: Get latest budget version being baselined
15099 l_current_budget_version_id := pa_budget_fund_pkg.g_cost_current_bvid;
15100
15101 -- 1.4: Get draft version ...
15102 -- This is required to udpate the account summary table (we will be updating acct.
15103 -- summary table for the draft version, except for 'Year end' where we will be updating
15104 -- the working budget created ..
15105
15106 If g_debug_mode = 'Y' then
15107 log_message(p_msg_token1=>l_program_name||'Get Draft Budget');
15108 End If;
15109
15110 --If (pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y') then
15111 If pa_budget_fund_pkg.g_processing_mode in ('YEAR_END','BASELINE') then
15112
15113 -- Get the draft or working budget ..
15114
15115 Select pbv.budget_version_id
15116 into l_draft_budget_version_id
15117 from pa_budget_versions pbv
15118 where (pbv.project_id,pbv.budget_type_code) in
15119 (select project_id,budget_type_code
15120 from pa_budget_versions
15121 where budget_version_id = l_current_budget_version_id)
15122 and pbv.budget_status_code = decode(pa_budget_fund_pkg.g_processing_mode,
15123 'YEAR_END','W','S');
15124
15125 If g_debug_mode = 'Y' then
15126 log_message(p_msg_token1=>l_program_name||'Yr End/Base Draft Budget:'||l_draft_budget_version_id);
15127 End If;
15128
15129 End If;
15130
15131 -- End If;
15132
15133
15134 If pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS' then
15135
15136 l_draft_budget_version_id := l_current_budget_version_id;
15137
15138 If g_debug_mode = 'Y' then
15139 log_message(p_msg_token1=>l_program_name||'CF Draft Budget:'||l_draft_budget_version_id);
15140 End If;
15141
15142 End If;
15143
15144 -- 1.5: Derive budget entry level code
15145 If (pa_budget_fund_pkg.g_balance_type = 'E' /*Top Down*/ and
15146 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' ) then
15147
15148 If g_debug_mode = 'Y' then
15149 log_message(p_msg_token1=>l_program_name||'Get Budget Entry Method');
15150 End If;
15151
15152 select pbem.entry_level_code
15153 into l_budget_entry_level_code
15154 from pa_budget_entry_methods pbem,
15155 pa_budget_versions pbv
15156 where pbv.budget_version_id = l_current_budget_version_id
15157 and pbem.budget_entry_method_code = pbv.budget_entry_method_code;
15158
15159 End If;
15160
15161 If g_debug_mode = 'Y' then
15162 log_message(p_msg_token1=>l_program_name||':g_processing_mode:'||pa_budget_fund_pkg.g_processing_mode||
15163 ':Balance type:'||pa_budget_fund_pkg.g_balance_type||
15164 ':Budget Amount Code:'||pa_budget_fund_pkg.g_budget_amount_code||
15165 ':Rebaseline Flag:'||pa_budget_fund_pkg.g_cost_rebaseline_flag);
15166
15167 log_message(p_msg_token1=>l_program_name||':Current budget version:'||l_current_budget_version_id||
15168 ':Draft version:'||l_draft_budget_version_id||':budget entry level code:' || l_budget_entry_level_code);
15169 End If;
15170
15171 -- 1.6: Reset funds_check_status_code and funds_check_result_code for the draft version
15172 -- in check funds mode.
15173 -- Reason: if the last check funds had failed then the failure codes should be nullified
15174 -- 1/14/06: this is reqd. for baseline too..so that it can override the
15175 -- existing status ... if there is any failure ..
15176 -- 8/22/06: This step should be carried out for CF/baseline/rebaseline for E/B balance_type
15177 -- Failures can happen for first time baseline and also for bottom up budgets too
15178
15179 --If ((pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') or
15180 --(pa_budget_fund_pkg.g_balance_type = 'E' and -- Top Down
15181 -- pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and -- Re-costing
15182 -- pa_budget_fund_pkg.g_processing_mode = 'BASELINE')
15183 --then
15184
15185 If (pa_budget_fund_pkg.g_processing_mode in ('CHECK_FUNDS','BASELINE')) then
15186
15187 If g_debug_mode = 'Y' then
15188 --log_message(p_msg_token1=>l_program_name||'Nullify failure status from draft version - Check funds');
15189 log_message(p_msg_token1=>l_program_name||' Rebuild Draft summary');
15190 log_message(p_msg_token1=>l_program_name||'Before BUILD_ACCOUNT_SUMMARY_AUTO call');
15191 -- this is reqd. for the scenario where the user has modified the draft version budget line and after that we
15192 -- the user had created txn. for the baseline version which has a diff acct.
15193 -- In this case, draft. budget line can have acct. A2 and summary will have A1 ..
15194 End If;
15195
15196 --RESET_STATUS_CODE_ON_SUMMARY(l_draft_budget_version_id);
15197 BUILD_ACCOUNT_SUMMARY_AUTO(x_budget_version_id => l_draft_budget_version_id,
15198 x_balance_type =>pa_budget_fund_pkg.g_balance_type,
15199 x_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
15200 x_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid,
15201 x_mode=>'PASS');
15202 If g_debug_mode = 'Y' then
15203 log_message(p_msg_token1=>l_program_name||'After BUILD_ACCOUNT_SUMMARY_AUTO call');
15204 End If;
15205 -- Autonomous used as we're updating pa_budget_acct_lines in AUTONOMOUS
15206 -- mode for failures later ..
15207 End If;
15208
15209 -- 1.7: Initalize l_acct_changed
15210 l_acct_changed := 'N';
15211 l_draft_acct_changed_flag := 'N';
15212 l_record_updated_flag := 'N';
15213
15214 -- 1.8: Get project_id
15215 If g_debug_mode = 'Y' then
15216 l_program_name := 'Do_budget_baseline_tieback';
15217 log_message(p_msg_token1=>l_program_name||'Get Project Id');
15218 End If;
15219
15220 select project_id into l_project_id from pa_budget_versions
15221 where budget_version_id = l_current_budget_version_id;
15222
15223 -- 1.9: If processing mode is BASELINE (and its a rebaseline, check if there are
15224 -- txns. against the project, if yes, set flag to 'Y' else 'N')
15225 -- This flag will be used further in the code to minimize code being
15226 -- executed ..this will improve performance ..
15227 -- Note: project_id being used as there is an index on project_id alone ..
15228
15229 l_txn_exists_bc_pkt_flag := 'N';
15230 l_txn_exists_bc_cmt_flag := 'N';
15231
15232 -- 8/22: This should fire for re-baseline/top-down only ..
15233 If (pa_budget_fund_pkg.g_balance_type = 'E' and -- Top Down
15234 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y') --and -- Re-costing
15235 --pa_budget_fund_pkg.g_processing_mode = 'BASELINE')
15236 then
15237
15238 If g_debug_mode = 'Y' then
15239 log_message(p_msg_token1=>l_program_name||'Before ANY_TXNS_AGAINST_PROJECT call');
15240 End If;
15241
15242 ANY_TXNS_AGAINST_PROJECT(p_project_id => l_project_id,
15243 p_txn_exists_in_bc_pkt => l_txn_exists_bc_pkt_flag,
15244 p_txn_exists_in_bc_cmt => l_txn_exists_bc_cmt_flag);
15245
15246 End If;
15247 If g_debug_mode = 'Y' then
15248 log_message(p_msg_token1=>l_program_name||'After ANY_TXNS_AGAINST_PROJECT call');
15249 End If;
15250 If g_debug_mode = 'Y' then
15251 l_program_name := 'Do_budget_baseline_tieback';
15252 log_message(p_msg_token1=>l_program_name||'l_txn_exists_bc_pkt_flag ['||l_txn_exists_bc_pkt_flag||
15253 '] l_txn_exists_bc_cmt_flag ['||l_txn_exists_bc_cmt_flag||']');
15254 End If;
15255
15256 -- ------------------------- END STEP 1 --------------------------------------+
15257
15258 -- ---------------------------------------------------------------------------+
15259 -- 2.0 : Update budget_ccid and budget_line_id on pa_bc_packets . Ccid being
15260 -- calculated here as during the regular flow the zero $ lines created
15261 -- during baseline are not visible ...
15262 -- Call procedure update_budget_ccid, this has to be autonomous ...
15263 -- ---------------------------------------------------------------------------+
15264 If (pa_budget_fund_pkg.g_balance_type = 'E' and -- Top Down
15265 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and -- Re-costing
15266 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and -- Baseline
15267 l_txn_exists_bc_pkt_flag = 'Y') -- Txn. exists against the project
15268 then -- (2.0 Main If)
15269
15270 -- Get set of books
15271 If g_debug_mode = 'Y' then
15272 log_message(p_msg_token1=>l_program_name||'Get Set of Books');
15273 End If;
15274
15275 select set_of_books_id into l_set_of_books_id from pa_implementations;
15276
15277 -- Update budget lines on pa_bc_packets ..
15278 If g_debug_mode = 'Y' then
15279 log_message(p_msg_token1=>l_program_name||'Update budget info. on pa_bc_packets');
15280 End If;
15281
15282 open c_acct_sync_bud_line_pa_bc_pkt(l_current_budget_version_id, l_set_of_books_id,l_project_id);
15283 loop
15284 fetch c_acct_sync_bud_line_pa_bc_pkt BULK COLLECT into g_tab_budget_ccid,
15285 g_tab_budget_line_id,
15286 g_tab_rlmi,
15287 g_tab_task_id,
15288 g_tab_period_name
15289 LIMIT l_limit;
15290
15291 If g_tab_budget_ccid.exists(1) then
15292
15293 -- Update Budget ccid and budget line id on pa_bc_packets .. AUTONOMOUS
15294
15295 Update_budget_ccid(P_budget_version_id => l_current_budget_version_id,
15296 P_budget_ccid => g_tab_budget_ccid,
15297 P_budget_line_id => g_tab_budget_line_id,
15298 P_budget_entry_level_code => l_budget_entry_level_code,
15299 P_period_name => g_tab_period_name,
15300 P_rlmi => g_tab_rlmi,
15301 P_task_id => g_tab_task_id,
15302 P_derived_ccid => t_ccid,
15303 P_allowed_flag => g_tab_allow_flag,
15304 P_result_code => P_return_status);
15305
15306 -- Note: Above t_ccid and g_tab_allow_flag are null pl/sql tables ..
15307
15308 -- Initalize variables ..
15309 g_tab_budget_ccid.DELETE;
15310 g_tab_budget_line_id.DELETE;
15311 g_tab_rlmi.DELETE;
15312 g_tab_task_id.DELETE;
15313 g_tab_period_name.DELETE;
15314
15315 Else
15316 EXIT; -- Exit Loop
15317 End If;
15318
15319 End Loop; -- c_acct_sync_bud_line_pa_bc_pkt
15320
15321 Close c_acct_sync_bud_line_pa_bc_pkt;
15322
15323 If g_debug_mode = 'Y' then
15324 l_program_name := 'Do_budget_baseline_tieback';
15325 log_message(p_msg_token1=>l_program_name||'Update_budget_ccid complete, status is:'||p_return_status);
15326 End If;
15327
15328 End If; -- (2.0 Main If)
15329 -- ------------------------- END STEP 2 --------------------------------------+
15330
15331 -- -------------------------- STEP 3 -----------------------------------------+
15332 -- If GL failed, fail pa_bc_packets and Summary acct (draft version)
15333 -- pa_bc_packets failed for Top-Down/Re-Baseline ..
15334 -- Acct. summary failed for all ...
15335 -- ----------------------------------------------------------------------------+
15336 If g_debug_mode = 'Y' then
15337 log_message(p_msg_token1=>l_program_name||':Check if any GL records failed');
15338 End If;
15339
15340 Begin
15341
15342 Select 'Y' into l_gl_failure_flag from dual where exists
15343 (select 1 from gl_bc_packets
15344 where packet_id = p_packet_id
15345 and substr(nvl(result_code,'P'),1,1) = 'F');
15346 Exception
15347 When no_data_found then
15348 l_gl_failure_flag := 'N';
15349 End;
15350
15351 If g_debug_mode = 'Y' then
15352 log_message(p_msg_token1=>l_program_name||':l_gl_failure_flag:'||l_gl_failure_flag);
15353 End If;
15354
15355 If (P_return_status = 'S' and l_gl_failure_flag = 'Y') then
15356
15357 If g_debug_mode = 'Y' then
15358 log_message(p_msg_token1=>l_program_name||':Inside GL failure if condition');
15359 End If;
15360
15361 -- ## Get the budget lines where account has changed
15362 Open c_gl_failure(l_current_budget_version_id);
15363 loop
15364 fetch c_gl_failure BULK COLLECT into t_bud_ccid,
15365 g_tab_period_name,
15366 g_tab_allow_flag,
15367 t_project_id,
15368 t_task_id,
15369 t_rlmi,
15370 t_start_date,
15371 t_txn_currency_code
15372 LIMIT l_limit;
15373
15374
15375 If t_bud_ccid.exists(1) then
15376
15377 -- ----------------------------------------------------------------------------------+
15378 -- ## There are records to process ..
15379 If g_debug_mode = 'Y' then
15380 log_message(p_msg_token1=>l_program_name||': GL failed case exists');
15381 End If;
15382 -- ----------------------------------------------------------------------------------+
15383
15384 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15385 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
15386 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15387 l_txn_exists_bc_pkt_flag = 'Y') then
15388 -- ----------------------------------------------------------------------------------+
15389 -- ## Fail pa_bc_packets:
15390 If g_debug_mode = 'Y' then
15391 log_message(p_msg_token1=>l_program_name||': GL failed - Fail pa_bc_packets');
15392 End If;
15393 -- ----------------------------------------------------------------------------------+
15394
15395 -- Autonomous procedure called for update ...these are the records that
15396 -- has already passed PA FC but now needs to be failed ...
15397
15398 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15399 P_period_name => g_tab_period_name,
15400 P_budget_ccid => t_bud_ccid,
15401 P_allow_flag => g_tab_allow_flag,
15402 P_result_code => 'F155');
15403 End If;
15404
15405 -- ----------------------------------------------------------------------------------+
15406 -- ## Fail draft account summary ..
15407 If g_debug_mode = 'Y' then
15408 l_program_name := 'Do_budget_baseline_tieback';
15409 log_message(p_msg_token1=>l_program_name||': GL failed - Fail account summary');
15410 End If;
15411 -- ----------------------------------------------------------------------------------+
15412 -- Update Draft version (account summary table) to failure ..
15413 -- Note: in case of 'Year End' the working budget will be updated ..
15414
15415 If pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS' then
15416 l_result_code := 'F150';
15417 Else
15418 l_result_code := 'F155';
15419 End If;
15420
15421 -- If the mode is not CF then the account derived may be different than that on CF
15422 -- so, we need to derive the account that exists on the draft version ..
15423 -- else issue was that baseline had acct A2 and draft had A1 and then the call
15424 -- to UPDATE_FAILURE_IN_ACCT_SUMMARY would not udpate any records ...
15425
15426 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
15427
15428 If g_debug_mode = 'Y' then
15429 log_message(p_msg_token1=>l_program_name||': Derive draft ccid');
15430 End If;
15431
15432 for x in t_project_id.FIRST..t_project_id.LAST loop
15433 Begin
15434 select code_combination_id draft_ccid
15435 into t_draft_ccid(x)
15436 from pa_budget_lines bl,
15437 pa_resource_assignments pra
15438 where pra.budget_version_id = l_draft_budget_version_id
15439 and pra.project_id = t_project_id(x)
15440 and pra.task_id = t_task_id(x)
15441 and pra.resource_list_member_id = t_rlmi(x)
15442 and bl.resource_assignment_id = pra.resource_assignment_id
15443 and bl.start_date = t_start_date(x)
15444 and bl.txn_currency_code = t_txn_currency_code(x);
15445
15446
15447 Exception
15448 When no_data_found then
15449 t_draft_ccid(x) := null;
15450 End;
15451 end loop;
15452
15453 End If;
15454
15455 If g_debug_mode = 'Y' then
15456 log_message(p_msg_token1=>l_program_name||': Update failure in draft acct. summary');
15457 End If;
15458
15459 -- ----------------------------------------------------------------------------------+
15460 -- Following if condition is required as t_draft_ccid is calcualted for non-CF mode only ...
15461 -- as for CF mode, t_bud_ccid is the draft ccid ...
15462 -- ----------------------------------------------------------------------------------+
15463 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
15464
15465 If g_debug_mode = 'Y' then
15466 log_message(p_msg_token1=>l_program_name||': <> CF, Calling Update_failure_in_acct_summary');
15467 End If;
15468
15469 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15470 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15471 P_period_name => g_tab_period_name,
15472 P_budget_ccid => t_draft_ccid,
15473 P_allow_flag => g_tab_allow_flag,
15474 P_result_code => l_result_code);
15475 Else
15476
15477 If g_debug_mode = 'Y' then
15478 log_message(p_msg_token1=>l_program_name||': = CF, Calling Update_failure_in_acct_summary');
15479 End If;
15480
15481 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15482 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15483 P_period_name => g_tab_period_name,
15484 P_budget_ccid => t_bud_ccid,
15485 P_allow_flag => g_tab_allow_flag,
15486 P_result_code => l_result_code);
15487 End If;
15488
15489
15490
15491 -- ----------------------------------------------------------------------------------+
15492 -- ## Set failure status ..
15493 -- ----------------------------------------------------------------------------------+
15494 p_return_status := 'F';
15495
15496 Else
15497 EXIT; -- Exit Loop
15498 End If; -- If t_bud_ccid(1).exists
15499
15500 -- ## Initialize ..
15501 t_bud_ccid.DELETE;
15502 g_tab_period_name.DELETE;
15503 g_tab_allow_flag.DELETE;
15504 t_project_id.DELETE;
15505 t_task_id.DELETE;
15506 t_rlmi.DELETE;
15507 t_start_date.DELETE;
15508 t_txn_currency_code.DELETE;
15509
15510 if t_draft_ccid.exists(1) then t_draft_ccid.DELETE; end if;
15511
15512 End Loop;
15513
15514 close c_gl_failure;
15515 -- -------------------------------------------------------------------------------------------------------+
15516 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15517 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
15518 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15519 p_return_status = 'F' and
15520 l_txn_exists_bc_pkt_flag = 'Y') then
15521
15522 If g_debug_mode = 'Y' then
15523 log_message(p_msg_token1=>l_program_name||':Fail pa_bc_packets as GL Failed - F170 update');
15524 End If;
15525
15526 -- Autonomous procedure called for update ...these are the records that
15527 -- has already passed PA FC but now needs to be failed ... as some records have failed with F169 above
15528
15529 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15530 P_period_name => g_tab_period_name,
15531 P_budget_ccid => g_tab_budget_ccid,
15532 P_allow_flag => g_tab_allow_flag,
15533 P_result_code => 'F170');
15534
15535 -- Note: All the pl/sql tables being passed are nulls
15536
15537 End If;
15538
15539 If g_debug_mode = 'Y' then
15540 log_message(p_msg_token1=>l_program_name||':Executing gl failure check end .., status:'||p_return_status);
15541 End If;
15542
15543 End If; --If P_return_status = 'S' then
15544 -- -------------------------- END STEP 3 -------------------------------------+
15545
15546 -- -------------------------- STEP 4 -----------------------------------------+
15547 -- If (Top-Down and re-baseline and "reserve"/"check funds"/"year end")
15548 -- execute "budget account validation" (for the latest budget
15549 -- version only). i.e. account change not allowed on a budget line
15550 -- that has txn.s against it. If any found, fail gl_bc_packets with F35
15551 --
15552 -- IF ACCOUNT CHANGE ALLOWED, then update the account information on
15553 -- pa_budget_lines
15554 -- Note: We however have to synch data for all modes and all budget types ..
15555 -- ---------------------------------------------------------------------------+
15556
15557
15558 If (--pa_budget_fund_pkg.g_balance_type = 'E' /*Top Down*/ and
15559 --pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15560 p_return_status = 'S' ) then -- I
15561
15562 If g_debug_mode = 'Y' then
15563 log_message(p_msg_token1=>l_program_name||':Executing account validation');
15564 End If;
15565
15566 -- ## Get the budget lines where account has changed
15567 Open c_budget_lines_synch(l_current_budget_version_id);
15568 loop
15569 fetch c_budget_lines_synch BULK COLLECT into t_ccid,
15570 t_gl_rowid,
15571 t_bud_ccid,
15572 t_raid,
15573 t_budget_rowid,
15574 t_budget_start_date,
15575 g_tab_period_name,
15576 g_tab_allow_flag,
15577 g_tab_budget_line_id,
15578 t_txn_currency_code,
15579 t_draft_needs_update,
15580 t_project_id,
15581 t_task_id,
15582 t_rlmi,
15583 t_parent_rlmi
15584 LIMIT l_limit;
15585
15586 If t_ccid.exists(1) then -- II
15587
15588 l_count := 0;
15589 l_count := t_ccid.COUNT;
15590 l_validation_failed := 'N';
15591 l_derive_draft_values := 'N';
15592
15593 -- ----------------------------------------------------------------------------------+
15594 -- ## A. Check if SLA has derived an account diff. than that on the budget line ...
15595 If g_debug_mode = 'Y' then
15596 log_message(p_msg_token1=>l_program_name||':Check if SLA derived diff. account');
15597 End If;
15598 -- ----------------------------------------------------------------------------------+
15599 for x in t_ccid.FIRST..t_ccid.LAST loop
15600
15601 If t_ccid(x) <> t_bud_ccid(x) then
15602 t_draft_needs_update(x) := 'Y';
15603 l_derive_draft_values := 'Y';
15604 l_acct_changed := 'Y';
15605 End If;
15606
15607 end loop;
15608 If g_debug_mode = 'Y' then
15609 log_message(p_msg_token1=>l_program_name||':l_derive_draft_values['||l_derive_draft_values||']');
15610 End If;
15611
15612 -- ----------------------------------------------------------------------------------+
15613 -- ## B. Get prev. version budget ccid
15614 -- ----------------------------------------------------------------------------------+
15615 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15616 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15617 (l_txn_exists_bc_pkt_flag ='Y' OR l_txn_exists_bc_cmt_flag = 'Y'))
15618 then -- B
15619
15620 If g_debug_mode = 'Y' then
15621 log_message(p_msg_token1=>l_program_name||':Derive Top task id');
15622 End If;
15623
15624 If l_budget_entry_level_code = 'P' then
15625 for x in t_Task_id.FIRST..t_task_id.LAST loop
15626 t_top_task_id(x) := 0;
15627 end loop;
15628 Else
15629 for x in t_Task_id.FIRST..t_task_id.LAST loop
15630 select top_task_id into t_top_task_id(x)
15631 from pa_tasks
15632 where task_id = t_task_id(x);
15633 end loop;
15634 End If;
15635
15636 If g_debug_mode = 'Y' then
15637 log_message(p_msg_token1=>l_program_name||':Derive prev. ver ccid');
15638 End If;
15639
15640 for x in t_ccid.FIRST..t_ccid.LAST loop
15641
15642 Begin
15643 select pbl.code_combination_id into
15644 t_prev_ver_ccid(x)
15645 from pa_budget_lines pbl,
15646 pa_resource_assignments pra
15647 where pbl.start_date = t_budget_start_date(x)
15648 and pbl.txn_currency_code = t_txn_currency_code(x)
15649 and pbl.budget_version_id = pa_budget_fund_pkg.g_cost_prev_bvid
15650 and pbl.budget_version_id = pra.budget_version_id
15651 and pbl.resource_assignment_id = pra.resource_assignment_id
15652 and pra.project_id = t_project_id(x)
15653 and (pra.task_id = t_task_id(x) OR
15654 pra.task_id = t_top_task_id(x))
15655 and (pra.resource_list_member_id= t_rlmi(x) OR
15656 pra.resource_list_member_id= t_parent_rlmi(x));
15657 Exception
15658 when no_data_found then
15659 t_prev_ver_ccid(x) := -1;
15660 End;
15661
15662 -- note: if ct. changes budget from lowest to top task or
15663 -- moves resource group to group then there can be an issue ..
15664 -- product management said that should not happen .. so not handling that for
15665 -- the time being ..
15666 -- Issue: lets say task11 had A1 and task 12 had A2 but now ct. moves budget to task1 (top level)
15667 -- then which budget account to consider ..it gets kinds complicated then ..
15668 end loop;
15669
15670 End If; --B
15671
15672 If g_debug_mode = 'Y' then
15673 log_message(p_msg_token1=>l_program_name||':After derive prev. ver ccid');
15674 End If;
15675
15676 -- ----------------------------------------------------------------------------------+
15677 -- ## C. Call API for validation (if account change allowed)
15678 -- ----------------------------------------------------------------------------------+
15679 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15680 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15681 (l_txn_exists_bc_pkt_flag ='Y' OR l_txn_exists_bc_cmt_flag = 'Y')
15682 )
15683 then -- API If
15684 -- ----------------------------------------------------------------------------------------------------+
15685 If g_debug_mode = 'Y' then
15686 log_message(p_msg_token1=>l_program_name||': Account change allowed-Inside main if condition');
15687 for x in t_project_id.FIRST..t_project_id.LAST loop
15688 log_message(p_msg_token1=>l_program_name||':t_top_task_id['||t_task_id(x)
15689 ||'] t_task_id['||t_task_id(x)
15690 ||'] t_parent_rlmi['||t_parent_rlmi(x)
15691 ||'] t_rlmi['||t_rlmi(x)
15692 ||'] t_budget_start_date['||t_budget_start_date(x)
15693 ||'] g_tab_period_name['||g_tab_period_name(x)
15694 ||'] t_prev_ver_ccid['||t_prev_ver_ccid(x)
15695 ||'] t_ccid['||t_ccid(x)||']');
15696 end loop;
15697 End If;
15698 -- ----------------------------------------------------------------------------------------------------+
15699
15700 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
15701 l_bvid_for_acct_changed_API := l_current_budget_version_id;
15702 Else
15703 l_bvid_for_acct_changed_API := pa_budget_fund_pkg.g_cost_prev_bvid;
15704 End if;
15705
15706 If g_debug_mode = 'Y' then
15707 log_message(p_msg_token1=>l_program_name||': For acct. change API, bvid being used:'
15708 ||l_bvid_for_acct_changed_API);
15709 End If;
15710
15711 for x in t_project_id.FIRST..t_project_id.LAST loop
15712
15713 If (t_prev_ver_ccid(x) <> t_ccid(x))
15714 then
15715 If g_debug_mode = 'Y' then
15716 log_message(p_msg_token1=>l_program_name||': Calling pa_funds_control_utils.is_Account_change_allowed2');
15717 End If;
15718
15719 IF pa_funds_control_utils.is_Account_change_allowed2
15720 (p_budget_version_id => l_bvid_for_acct_changed_API,
15721 p_project_id => t_project_id(x),
15722 p_top_task_id => t_top_task_id(x),
15723 p_task_id => t_task_id(x),
15724 p_parent_resource_id => t_parent_rlmi(x),
15725 p_resource_list_member_id => t_rlmi(x),
15726 p_start_date => t_budget_start_date(x),
15727 p_period_name => g_tab_period_name(x),
15728 p_entry_level_code => l_budget_entry_level_code,
15729 p_mode => 'FORM') = 'N'
15730 THEN -- III
15731
15732 g_tab_allow_flag(x) := 'N'; -- Account Change not allowed ...
15733 l_validation_failed := 'Y';
15734 l_derive_draft_values := 'Y';
15735
15736 If g_debug_mode = 'Y' then
15737 log_message(p_msg_token1=>l_program_name||':Acct change failed for raid['||t_raid(x)||']period['||
15738 g_tab_period_name(x)||']');
15739 End If;
15740
15741 END IF; -- III
15742
15743 End If; -- Current to prev. budget ccid check ..
15744
15745 end loop;
15746
15747 End If; --API If
15748
15749 -- ----------------------------------------------------------------------------------+
15750 If g_debug_mode = 'Y' then
15751
15752 log_message(p_msg_token1=>l_program_name||':l_validation_failed ['||l_validation_failed||']');
15753
15754 For x in t_bud_ccid.FIRST..t_bud_ccid.LAST loop
15755 log_message(p_msg_token1=>l_program_name||':source_distribution_id_num_1/g_tab_budget_line_id ['
15756 ||g_tab_budget_line_id(x)||']g_tab_allow_flag['||g_tab_allow_flag(x)
15757 ||']g_tab_period_name['||g_tab_period_name(x)||']t_raid'||t_raid(x)||']');
15758 end loop;
15759 End If;
15760 -- ----------------------------------------------------------------------------------+
15761
15762 -- ----------------------------------------------------------------------------------+
15763 -- C2. Get the draft information for update ...
15764 -- ----------------------------------------------------------------------------------+
15765 If g_debug_mode = 'Y' then
15766 log_message(p_msg_token1=>l_program_name||': l_derive_draft_values['||l_derive_draft_values||']');
15767 End If;
15768
15769 If l_derive_draft_values = 'Y' then
15770
15771 If g_debug_mode = 'Y' then
15772 log_message(p_msg_token1=>l_program_name||': Derive draft rowid and draft ccid');
15773 End If;
15774
15775 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then -- CF
15776 for x in t_project_id.FIRST..t_project_id.LAST
15777 loop
15778
15779 -- If draft needs update then we need to get the draft rowid for updating
15780 -- the account change and draft ccid for the below API ..
15781 -- And the below begin..end block is reqd. as the baseline budget can have zero $ lines ..
15782
15783 Begin
15784 select pbl.rowid,pbl.code_combination_id into
15785 t_draft_budget_rowid(x),t_draft_ccid(x)
15786 from pa_budget_lines pbl,
15787 pa_resource_assignments pra
15788 where pbl.start_date = t_budget_start_date(x)
15789 and pbl.txn_currency_code = t_txn_currency_code(x)
15790 and pbl.budget_version_id = pra.budget_version_id
15791 and pbl.resource_assignment_id = pra.resource_assignment_id
15792 and pra.budget_version_id = l_draft_budget_version_id
15793 and pra.project_id = t_project_id(x)
15794 and pra.task_id = t_task_id(x)
15795 and pra.resource_list_member_id= t_rlmi(x);
15796 Exception
15797 when no_data_found then
15798 If g_debug_mode = 'Y' then
15799 log_message(p_msg_token1=>l_program_name||'Derive drafr budget ccid:No Data Found');
15800 log_message(p_msg_token1=>l_program_name||': t_budget_start_date(x):'||t_budget_start_date(x)
15801 ||' t_txn_currency_code(x):'||t_txn_currency_code(x)
15802 ||' t_project_id(x):'||t_project_id(x)
15803 ||' t_task_id(x):'||t_task_id(x)
15804 ||' t_rlmi(x): '||t_rlmi(x));
15805 End if;
15806
15807 t_draft_budget_rowid(x) := null;
15808 t_draft_ccid(x) := -1;
15809 End;
15810
15811 If t_draft_needs_update(x) = 'N' then
15812 t_draft_budget_rowid(x) := null;
15813 End If; --If t_draft_needs_update(x) = 'Y' then
15814
15815 -- Above is reqd. as only those rowid with <> 'NO DATA FOUND' is used for updating account change ..
15816
15817 end loop;
15818 End If; -- CF ..
15819 End if; --If l_derive_draft_values = 'Y' then
15820
15821 If g_debug_mode = 'Y' then
15822 log_message(p_msg_token1=>l_program_name||': After derive draft rowid and draft ccid');
15823 End If;
15824
15825
15826 -- ----------------------------------------------------------------------------------+
15827 -- ## D. If any budget acccount failed validation then ..
15828 -- ----------------------------------------------------------------------------------+
15829
15830 If l_validation_failed = 'Y' then
15831
15832 -- ----------------------------------------------------------------------------------+
15833 -- ## Fail gl_bc_packets ..
15834 If g_debug_mode = 'Y' then
15835 log_message(p_msg_token1=>l_program_name||': Acct. val. failed - Fail gl_bc_packets');
15836 End If;
15837 -- ----------------------------------------------------------------------------------+
15838
15839 Forall x in t_bud_ccid.FIRST..t_bud_ccid.LAST
15840 Update gl_bc_packets glbc
15841 set glbc.result_code = 'F35'
15842 where glbc.packet_id = p_packet_id
15843 and glbc.source_distribution_id_num_1 = g_tab_budget_line_id(x)
15844 and g_tab_allow_flag(x) = 'N';
15845
15846 If g_debug_mode = 'Y' then
15847 log_message(p_msg_token1=>l_program_name||SQL%ROWCOUNT||' GL line updated');
15848 End If;
15849
15850 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15851 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
15852 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15853 l_txn_exists_bc_pkt_flag = 'Y') then
15854
15855 -- ----------------------------------------------------------------------------------+
15856 -- ## Fail pa_bc_packets:
15857 If g_debug_mode = 'Y' then
15858 log_message(p_msg_token1=>l_program_name||': Acct. val. failed [F169] - Fail pa_bc_packets');
15859 End If;
15860 -- ----------------------------------------------------------------------------------+
15861
15862 -- Autonomous procedure called for update ...these are the records that
15863 -- has already passed PA FC but now needs to be failed ...
15864
15865 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15866 P_period_name => g_tab_period_name,
15867 P_budget_ccid => t_bud_ccid,
15868 P_allow_flag => g_tab_allow_flag,
15869 P_result_code => 'F169');
15870
15871 End If;
15872
15873 -- ----------------------------------------------------------------------------------+
15874 -- ## Fail draft account summary ..
15875 If g_debug_mode = 'Y' then
15876 log_message(p_msg_token1=>l_program_name||': Acct. change. val. failed(F169) - Update draft account summary');
15877 End If;
15878 -- Update Draft version (account summary table) to failure ..
15879 -- Note: in case of 'Year End' the working budget will be updated ..
15880 -- ----------------------------------------------------------------------------------+
15881 -- Following if condition being used as for = 'CF' ..t_draft_ccid is not calculated ..
15882
15883 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
15884
15885 -- -------------------------------------------------------------------------------------------------+
15886 If g_debug_mode = 'Y' then
15887 log_message(p_msg_token1=>l_program_name||': Upd acct. summ - <> CF:l_draft_budget_version_id['
15888 ||l_draft_budget_version_id||']');
15889 for x in g_tab_period_name.FIRST..g_tab_period_name.LAST loop
15890 log_message(p_msg_token1=>l_program_name||': g_tab_period_name['||g_tab_period_name(x)
15891 ||'] t_draft_ccid ['||t_draft_ccid(x)
15892 ||']');
15893 end loop;
15894 End If;
15895 -- -------------------------------------------------------------------------------------------------+
15896
15897 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15898 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15899 P_period_name => g_tab_period_name,
15900 P_budget_ccid => t_draft_ccid,
15901 P_allow_flag => g_tab_allow_flag,
15902 P_result_code => 'F169');
15903
15904 Else
15905
15906 -- -------------------------------------------------------------------------------------------------+
15907 If g_debug_mode = 'Y' then
15908 log_message(p_msg_token1=>l_program_name||': Upd acct. summ,mode = CF:l_draft_budget_version_id['
15909 ||l_draft_budget_version_id||']');
15910 for x in g_tab_period_name.FIRST..g_tab_period_name.LAST loop
15911 log_message(p_msg_token1=>l_program_name||': g_tab_period_name['||g_tab_period_name(x)
15912 ||'] t_bud_ccid ['||t_bud_ccid(x)
15913 ||']');
15914 end loop;
15915
15916 End If;
15917 -- -------------------------------------------------------------------------------------------------+
15918
15919 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15920 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15921 P_period_name => g_tab_period_name,
15922 P_budget_ccid => t_bud_ccid,
15923 P_allow_flag => g_tab_allow_flag,
15924 P_result_code => 'F169');
15925
15926 End If;
15927 -- ----------------------------------------------------------------------------------+
15928 -- ## Set failure status ..
15929 -- ----------------------------------------------------------------------------------+
15930 p_return_status := 'F';
15931
15932
15933 End If; -- If l_validation_failed = 'Y' then (Acct. validation failed)
15934
15935
15936 -- --------------------------------------------------------------------------------+
15937 -- ## E. Update those budget lines where account info. can change ....
15938 If g_debug_mode = 'Y' then
15939 log_message(p_msg_token1=>l_program_name||': Update changed account info on budget lines'
15940 ||'l_acct_changed['||l_acct_changed||'] l_validation_failed['
15941 ||l_validation_failed||']' );
15942 End If;
15943 -- --------------------------------------------------------------------------------+
15944 If l_acct_changed = 'Y' then
15945
15946 If (l_validation_failed = 'N' or pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') then
15947 -- update budget lines only if there is no failure
15948 -- reason: because if there is any failure, baseline/yearend/checkfunds fails ..
15949 -- and a rollback is issued for the 1st 2 ..
15950 -- However for CF, we will update the account change for the records
15951 -- that did not fail FC .. till the point the loop exits ..
15952
15953 If g_debug_mode = 'Y' then
15954 log_message(p_msg_token1=>l_program_name||': Updating budget line on current version' );
15955 End If;
15956
15957 forall x in t_ccid.FIRST..t_ccid.LAST
15958 Update pa_budget_lines pbl
15959 set pbl.code_combination_id = t_ccid(x)
15960 where pbl.rowid = t_budget_rowid(x)
15961 and t_bud_ccid(x) <> t_ccid(x)
15962 and g_tab_allow_flag(x) = 'Y';
15963
15964 If (sql%rowcount > 0 and pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') then
15965 l_draft_acct_changed_flag := 'Y';
15966 End If;
15967
15968 If g_debug_mode = 'Y' then
15969 log_message(p_msg_token1=>l_program_name||':'||sql%rowcount
15970 ||' budget lines updated for current version' );
15971 End If;
15972
15973 End If; -- If l_validation_failed = 'N' then
15974
15975 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS') then
15976
15977 -- We also need to update the draft version account information ..atleast for the ones
15978 -- where account change is allowed .. AUTONOMOUS Update ..
15979
15980 If g_debug_mode = 'Y' then
15981 log_message(p_msg_token1=>l_program_name||': Update new account on draft summary'
15982 ||': l_record_updated_flag:'||l_record_updated_flag);
15983
15984 for x in t_draft_budget_rowid.FIRST..t_draft_budget_rowid.LAST loop
15985 log_message(p_msg_token1=>l_program_name||':t_bud_ccid:'||t_bud_ccid(x)
15986 ||':t_ccid:'||t_ccid(x)
15987 ||':g_tab_allow_flag:'||g_tab_allow_flag(x)
15988 ||':t_draft_budget_rowid:'||t_draft_budget_rowid(x));
15989 end loop;
15990 End If;
15991
15992 UPD_NEW_ACCT_ON_DRAFT_BUDGET(p_budget_line_rowid => t_draft_budget_rowid,
15993 p_budget_ccid => t_bud_ccid,
15994 p_new_ccid => t_ccid,
15995 p_change_allowed => g_tab_allow_flag,
15996 p_record_updated => l_record_updated_flag);
15997
15998 If l_record_updated_flag = 'Y' then
15999 l_draft_acct_changed_flag := 'Y';
16000 End if;
16001
16002 End If;
16003
16004 -- Initialized variable to 'N' for the next run ..
16005 l_acct_changed := 'N';
16006
16007 End If; -- If l_acct_changed = 'Y' then
16008
16009 -- ---------------------------------------------------------------------------------------+
16010 If g_debug_mode = 'Y' then
16011 log_message(p_msg_token1=>l_program_name||SQL%ROWCOUNT||' budget line records updated');
16012 End If;
16013 -- ---------------------------------------------------------------------------------------+
16014
16015 Else
16016 EXIT; -- Exit Loop
16017 End If; -- If t_ccid(1).exists -- II
16018
16019 -- ----------------------------------------------------------------------------------+
16020 -- ## F. Initalize variables
16021 If g_debug_mode = 'Y' then
16022 log_message(p_msg_token1=>l_program_name||': initalize variables');
16023 End If;
16024 -- ----------------------------------------------------------------------------------+
16025 t_ccid.DELETE;
16026 t_bud_ccid.DELETE;
16027 t_gl_rowid.DELETE;
16028 t_budget_rowid.DELETE;
16029 t_raid.DELETE;
16030 t_budget_start_date.DELETE;
16031 g_tab_period_name.DELETE;
16032 g_tab_allow_flag.DELETE;
16033 g_tab_budget_line_id.DELETE;
16034 t_txn_currency_code.DELETE;
16035 t_project_id.DELETE;
16036 t_task_id.DELETE;
16037 t_rlmi.DELETE;
16038 t_parent_rlmi.DELETE;
16039
16040 -- Following tables are conditioanlly build ..
16041 if t_top_task_id.exists(1) then t_top_task_id.DELETE; end if;
16042 if t_prev_ver_ccid.exists(1) then t_prev_ver_ccid.DELETE; end if;
16043 if t_draft_needs_update.exists(1) then t_draft_needs_update.DELETE; end if;
16044 if t_draft_ccid.exists(1) then t_draft_ccid.DELETE; end if;
16045 if t_draft_budget_rowid.exists(1) then t_draft_budget_rowid.DELETE; end if;
16046 End Loop;
16047
16048 close c_budget_lines_synch;
16049
16050 If g_debug_mode = 'Y' then
16051 log_message(p_msg_token1=>l_program_name||':After account validation, return status:'||p_return_status);
16052 End If;
16053
16054 End If; -- I , Top-Down Check, re-baseline
16055
16056 -- --------------------------------------------------------------------------+
16057 If (pa_budget_fund_pkg.g_balance_type = 'E' and
16058 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
16059 p_return_status = 'F' and
16060 l_txn_exists_bc_pkt_flag = 'Y') then
16061
16062 If g_debug_mode = 'Y' then
16063 log_message(p_msg_token1=>l_program_name||':Fail pa_bc_packets as account info. changed - F170 update');
16064 End If;
16065
16066 -- Autonomous procedure called for update ...these are the records that
16067 -- has already passed PA FC but now needs to be failed ... as some records have failed with F169 above
16068
16069 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
16070 P_period_name => g_tab_period_name,
16071 P_budget_ccid => g_tab_budget_ccid,
16072 P_allow_flag => g_tab_allow_flag,
16073 P_result_code => 'F170');
16074
16075 -- Note: All the pl/sql tables being passed are nulls
16076
16077 End If;
16078
16079 -- ---------------------------------------------------------------------------+
16080 -- If the status is 'Failed' but there was an account changed that was updated
16081 -- on budget lines, then we will need to rebuild the draft version summary and
16082 -- that too in AUTONOMUS mode ...
16083 -- What we're talking here is the draft budget data that gets updated above
16084 -- during baseline/yearend and CF ..
16085 -- ---------------------------------------------------------------------------+
16086
16087 If (l_draft_acct_changed_flag = 'Y' and
16088 p_return_status = 'F' )
16089 then
16090 If g_debug_mode = 'Y' then
16091 log_message(p_msg_token1=>l_program_name||': Failure case - Rebuild draft acct. sumamry');
16092 End If;
16093
16094 BUILD_ACCOUNT_SUMMARY_AUTO(x_budget_version_id => l_draft_budget_version_id,
16095 x_balance_type =>pa_budget_fund_pkg.g_balance_type,
16096 x_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
16097 x_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid,
16098 x_mode=>'FAIL');
16099 End If;
16100 -- ------------------------- END STEP 4 --------------------------------------+
16101
16102 If p_return_status = 'S' then -- II
16103 -- ------------------------------------------------------------------------+
16104 -- 5.0: Build account summary for the current version ..
16105 -- ------------------------------------------------------------------------+
16106 If g_debug_mode = 'Y' then
16107 log_message(p_msg_token1=>l_program_name||':Processing Mode:'||pa_budget_fund_pkg.g_processing_mode);
16108 log_message(p_msg_token1=>l_program_name||':Build account summary for the current version');
16109 End If;
16110
16111 -- ACCOUNT SUMMARY SHOULD ALWAYS BE GENERATED .. CASE WHERE USER MANUALLY UPDATED
16112 -- ACCOUNT, IN THIS CASE, ACCT. SUMMARY IS DIFF. THAN ACTUAL SUMMARY
16113
16114 BUILD_ACCOUNT_SUMMARY(p_budget_version_id => l_current_budget_version_id,
16115 p_balance_type =>pa_budget_fund_pkg.g_balance_type,
16116 p_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
16117 p_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid);
16118
16119 If g_debug_mode = 'Y' then
16120 log_message(p_msg_token1=>l_program_name||': Done building account summary for the current version');
16121 End If;
16122 -- ------------------------- END STEP 5 -----------------------------------+
16123 -- 6.0: Build account summary for the draf version .. <> CF mode ..
16124 -- 'Cause in CF mode, we build for the draft version :)
16125 -- ------------------------------------------------------------------------+
16126 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and l_draft_acct_changed_flag = 'Y')
16127 then
16128
16129 If g_debug_mode = 'Y' then
16130 log_message(p_msg_token1=>l_program_name||':Build account summary for the draft version');
16131 End If;
16132
16133 BUILD_ACCOUNT_SUMMARY_AUTO(x_budget_version_id => l_draft_budget_version_id,
16134 x_balance_type =>pa_budget_fund_pkg.g_balance_type,
16135 x_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
16136 x_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid,
16137 x_mode=>'PASS');
16138
16139 If g_debug_mode = 'Y' then
16140 log_message(p_msg_token1=>l_program_name||': Done building account summary for the draft version');
16141 End If;
16142
16143 End If; -- Step 6.0 main If ..
16144
16145 -- ------------------------- END STEP 6 -----------------------------------+
16146 -- 7.0: Top Down (but not "Year-End") and re-baseline, carry out
16147 -- "Account level" FC
16148 -- ------------------------------------------------------------------------+
16149
16150 If (pa_budget_fund_pkg.g_balance_type = 'E' and
16151 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
16152 pa_budget_fund_pkg.g_processing_mode = 'BASELINE') then
16153 --l_txn_exists_bc_pkt_flag = 'Y') then
16154
16155 -- Account level FC .. ONLY for BASELINE mode
16156
16157 If g_debug_mode = 'Y' then
16158 l_program_name := 'Do_Budget_baseline_tieback';
16159 log_message(p_msg_token1=>l_program_name||':Account Level Funds Check');
16160 End If;
16161
16162
16163 Open c_acct_lines(l_current_budget_version_id);
16164 loop
16165 fetch c_acct_lines BULK COLLECT into g_tab_period_name,
16166 g_tab_budget_ccid,
16167 g_tab_allow_flag
16168 LIMIT l_limit;
16169 l_count := 0;
16170 l_count := g_tab_budget_ccid.COUNT;
16171
16172
16173 If l_count > 0 then
16174
16175 -- ----------------------------------------------------------------------------------+
16176 If g_debug_mode = 'Y' then
16177 log_message(p_msg_token1=>l_program_name||':Account Level Funds Check failed - Fail gl_bc_packets');
16178
16179 For x in g_tab_budget_ccid.FIRST..g_tab_budget_ccid.LAST loop
16180 log_message(p_msg_token1=>l_program_name||':g_tab_budget_ccid'||g_tab_budget_ccid(x)
16181 ||'g_tab_period_name'|| g_tab_period_name(x));
16182 end loop;
16183 End If;
16184 -- ----------------------------------------------------------------------------------+
16185
16186 -- A. Fail gl_bc_packets:
16187 Forall x in g_tab_budget_ccid.FIRST..g_tab_budget_ccid.LAST
16188 Update gl_bc_packets glbc
16189 set glbc.result_code = 'F35'
16190 where glbc.packet_id = p_packet_id
16191 and glbc.code_combination_id = g_tab_budget_ccid(x)
16192 and glbc.period_name = g_tab_period_name(x);
16193
16194 If g_debug_mode = 'Y' then
16195 log_message(p_msg_token1=>l_program_name||SQL%ROWCOUNT||' GL line updated');
16196 End If;
16197
16198 -- B. Fail pa_bc_packets:
16199
16200 -- Autonomous procedure called for update ...these are the records that
16201 -- has already passed PA FC but now needs to be failed ...
16202
16203 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
16204 P_period_name => g_tab_period_name,
16205 P_budget_ccid => g_tab_budget_ccid,
16206 P_allow_flag => g_tab_allow_flag,
16207 P_result_code => 'F113');
16208
16209 If g_debug_mode = 'Y' then
16210 log_message(p_msg_token1=>l_program_name||':Account Level Funds Check failed - Fail draft account summary');
16211 End If;
16212
16213 -- C. Update Draft version (account summary table) to failure ..
16214
16215 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
16216
16217 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
16218 P_period_name => g_tab_period_name,
16219 P_budget_ccid => g_tab_budget_ccid,
16220 P_allow_flag => g_tab_allow_flag,
16221 P_result_code => 'F113');
16222
16223 -- D. Set Failure status
16224
16225 p_return_status := 'F';
16226
16227
16228 -- E. Initalize variables..
16229
16230 g_tab_budget_ccid.DELETE;
16231 g_tab_period_name.DELETE;
16232 g_tab_allow_flag.DELETE;
16233
16234 End If; --If l_count > 0 then
16235
16236
16237 If l_count < l_limit then
16238 exit;
16239 End If;
16240
16241 end loop; -- Main cursor c_acct_lines;
16242
16243 Close c_acct_lines;
16244
16245
16246 If (p_return_status = 'F') then
16247
16248 If g_debug_mode = 'Y' then
16249 log_message(p_msg_token1=>l_program_name||':Account level failure ...');
16250 End If;
16251
16252 -- Autonomous procedure called for update ...these are the records that
16253 -- has already passed PA FC but now needs to be failed ... as some records have failed with F113 above
16254
16255 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
16256 P_period_name => g_tab_period_name,
16257 P_budget_ccid => g_tab_budget_ccid,
16258 P_allow_flag => g_tab_allow_flag,
16259 P_result_code => 'F170');
16260
16261 -- Note: All the pl/sql tables being passed are nulls
16262
16263 End If;
16264
16265 End If; -- account level FC complete ...
16266
16267 -- ------------------------- END STEP 7 -----------------------------------+
16268
16269 End If; -- II If p_return_status = 'S' then (step 5..7)
16270
16271 -- ------------------------- STEP 8 -----------------------------------+
16272 -- Step 8.0: Update Pass status/result code on pa_budget_acct_lines
16273 -- Step 8.1: Update Pass status/result code on current version (CF/Baseline/Yearend)
16274 /* ==============================================================================================+
16275 -- STEP NOT REQUIRED AS acct. summary initialized/build with 'P101' and 'A' ...
16276
16277 If ((pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') OR
16278 (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and p_return_status = 'S')
16279 ) then
16280
16281 If g_debug_mode = 'Y' then
16282 log_message(p_msg_token1=>'End:'||l_program_name||'Update Pass status/result code on pa_budget_acct_lines - Current');
16283 End If;
16284
16285 Update pa_budget_acct_lines
16286 set funds_check_status_code = 'A',
16287 funds_check_result_code = 'P101'
16288 where budget_version_id = l_current_budget_version_id
16289 and nvl(funds_check_status_code,'A') <> 'R';
16290
16291 If g_debug_mode = 'Y' then
16292 log_message(p_msg_token1=>l_program_name||'Current Acct Summary-P101 update:'||SQL%ROWCOUNT);
16293 End If;
16294
16295 End If;
16296
16297 -- Step 8.2: Update Pass status/result code on draft version for Baseline/year End mode
16298
16299 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and p_return_status = 'S')
16300 then
16301
16302 If g_debug_mode = 'Y' then
16303 log_message(p_msg_token1=>'End:'||l_program_name||'Update Pass status/result code on pa_budget_acct_lines - Draft');
16304 End If;
16305
16306 Update pa_budget_acct_lines
16307 set funds_check_status_code = 'A',
16308 funds_check_result_code = 'P101'
16309 where budget_version_id = l_draft_budget_version_id;
16310
16311 If g_debug_mode = 'Y' then
16312 log_message(p_msg_token1=>l_program_name||'Draft Acct Summary-P101 update:'||SQL%ROWCOUNT);
16313 End If;
16314
16315 End If;
16316 ============================================================================================== */
16317
16318 -- ------------------------- END STEP 8 -----------------------------------+
16319
16320 -- ------------------------- STEP 9 -----------------------------------+
16321 -- Step 9.0: Update project_acct_result_code/result_code on pa_bc_packets
16322
16323 If (pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
16324 p_return_status = 'S' and
16325 l_txn_exists_bc_pkt_flag = 'Y') then
16326
16327 If g_debug_mode = 'Y' then
16328 log_message(p_msg_token1=>l_program_name||'Update acct level result code on pa_bc_packets');
16329 End If;
16330
16331 UPD_BC_PKT_ACCT_RESULT_CODE(P_budget_version_id => l_current_budget_version_id);
16332
16333 End if;
16334 -- ------------------------- END STEP 9 -----------------------------------+
16335
16336 -- -------------------------- STEP 10 --------------------------------------+
16337 -- Step 10.0: We need to fail all records in case of Check funds/reserve ..
16338
16339 If (p_return_status = 'F' and pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') then
16340 -- Filtering reserve_baseline as during baseline if there is a failure everything rolls back ..
16341
16342 g_packet_debit_processed := 'Y';
16343
16344 If g_packet_credit_processed = 'Y' then
16345 log_message(p_msg_token1=>l_program_name||': As credit already processed Calling Fail_credit_packet');
16346 FAIL_CREDIT_PACKET(p_input_packet => 'DEBIT',
16347 p_return_status_code => p_return_status);
16348 End if;
16349
16350 End If;
16351 -- ------------------------- END STEP 10 -----------------------------------+
16352
16353
16354 If g_debug_mode = 'Y' then
16355 l_program_name := 'Do_budget_baseline_tieback';
16356 log_message(p_msg_token1=>'End:'||l_program_name||'return status:'||p_return_status);
16357 End If;
16358
16359 EXCEPTION
16360 When others then
16361 If g_debug_mode = 'Y' then
16362 l_program_name := 'Do_budget_baseline_tieback';
16363 log_message(p_msg_token1=>l_program_name||':When Others:'||SQLERRM);
16364 End If;
16365
16366 p_return_status := 'F';
16367
16368 END DO_BUDGET_BASELINE_TIEBACK;
16369
16370 -- --------------------------------------------------------------------------------+
16371 -- This procedure will build pa_budget_acct_lines
16372 -- Called from DO_BUDGET_BASELINE_TIEBACK and PA_GL_CBC_CONFIRMATION (for revenue)
16373 -- Parameters:
16374 -- p_budget_version_id : Current budget version being funds checked
16375 -- p_balance_type : E (For Top Down) and B (Bottom Up)
16376 -- p_budget_amount_code : 'C' for cost and 'R' for revenue
16377 -- p_prev_budget_version_id: Budget version being reversed (for re-baseline
16378 -- and year-end case)
16379 -- --------------------------------------------------------------------------------+
16380 PROCEDURE Build_account_summary(P_budget_version_id IN NUMBER,
16381 P_balance_type IN VARCHAR2,
16382 P_budget_amount_code IN VARCHAR2,
16383 P_prev_budget_version_id IN NUMBER)
16384 IS
16385
16386 t_period_name TypeVarChar;
16387 t_start_date TypeDate;
16388 t_end_date TypeDate;
16389 t_ccid TypeNum;
16390 t_amt TypeNum;
16391
16392 l_date Date;
16393 l_login Number;
16394 l_request Number;
16395 l_count Number;
16396
16397 Cursor c_acct_lines is
16398 select pbl.period_name,
16399 pbl.start_date,
16400 pbl.end_date,
16401 pbl.code_combination_id,
16402 sum(decode(nvl(p_balance_type,'X'),
16403 'E', decode(NVL(pbl.Burdened_Cost,0),
16404 0,nvl(pbl.raw_cost,0),
16405 pbl.burdened_cost ) ,
16406 'B',decode(p_budget_amount_code,
16407 'R',nvl(pbl.revenue,0) ,
16408 'C', decode(NVL(pbl.Burdened_Cost,0),
16409 0,nvl(pbl.raw_cost,0),
16410 pbl.burdened_cost ),
16411 0 ),
16412 0 )) total_amount
16413 from pa_budget_lines pbl
16414 where budget_version_id = p_budget_version_id
16415 group by pbl.period_name,
16416 pbl.start_date,
16417 pbl.end_date,
16418 pbl.code_combination_id;
16419
16420 BEGIN
16421 l_program_name := 'Build_account_summary:';
16422 If g_debug_mode = 'Y' then
16423 log_message(p_msg_token1=>l_program_name||'Start');
16424 End If;
16425
16426 l_date := sysdate;
16427 l_login := fnd_global.login_id;
16428 l_request := fnd_global.conc_request_id;
16429 l_limit := 500;
16430 -- ------------------------------------------------------------------------+
16431 -- 1.0: Creating PA_Budget_Acct_Lines record for the current budget version
16432 -- ------------------------------------------------------------------------+
16433
16434 -- To make sure that there is no budget acct. line .. acct. gen. seems to be creating summary ..
16435 Delete from PA_Budget_Acct_Lines
16436 where budget_version_id = P_budget_version_id;
16437
16438 If g_debug_mode = 'Y' then
16439 log_message(p_msg_token1=>l_program_name||'Deleted '||SQL%ROWCOUNT||' PA_Budget_Acct_Lines records');
16440 End If;
16441
16442 If g_debug_mode = 'Y' then
16443 log_message(p_msg_token1=>l_program_name||':Creating records');
16444 End If;
16445
16446 Open c_acct_lines;
16447 loop
16448 fetch c_acct_lines
16449 BULK COLLECT into t_period_name,
16450 t_start_date,
16451 t_end_date,
16452 t_ccid,
16453 t_amt
16454 LIMIT l_limit;
16455 l_count := t_ccid.COUNT;
16456
16457 If g_debug_mode = 'Y' then
16458 log_message(p_msg_token1=>l_program_name||'Fetched '||l_count||' budget records');
16459 End If;
16460
16461 If l_count > 0 then
16462
16463 If g_debug_mode = 'Y' then
16464 for i in 1..l_count loop
16465 log_message(p_msg_token1=>l_program_name||'P_budget_version_id,start_date,t_ccid'
16466 ||P_budget_version_id||';'||t_start_date(i)||';'||t_ccid(i));
16467 end loop;
16468 End If;
16469
16470 forall i in 1..l_count
16471 INSERT INTO PA_Budget_Acct_Lines (
16472 Budget_Acct_Line_ID,
16473 Budget_version_ID,
16474 GL_Period_Name,
16475 Start_Date,
16476 End_Date,
16477 Code_Combination_ID,
16478 Prev_Ver_Budget_Amount,
16479 Prev_Ver_Available_Amount,
16480 Curr_Ver_Budget_Amount,
16481 Curr_Ver_Available_Amount,
16482 Accounted_Amount,
16483 Last_Update_Date,
16484 Last_Updated_By,
16485 Creation_Date,
16486 Created_By,
16487 Last_Update_Login,
16488 Request_ID,
16489 funds_check_status_code,
16490 funds_check_result_code)
16491 VALUES(PA_Budget_Acct_Lines_S.NEXTVAL, -- Budget acct line id
16492 P_budget_version_id, -- Budget version id
16493 t_period_name(i), -- Period name
16494 t_start_date(i), -- Start date
16495 t_end_date(i), -- End date
16496 t_ccid(i), -- CCID
16497 0, -- Prev. version bud. amt
16498 0, -- Prev. version avail.amt
16499 t_amt(i), -- Curr. version bud. amt
16500 0, -- Curr. version avail.amt
16501 0, -- Accounted amount
16502 l_date, -- Last update date
16503 l_login, -- Last update by
16504 l_date, -- Created date
16505 l_login, -- Created by
16506 l_login, -- Last update login
16507 l_request, -- Request
16508 'A', -- funds_check_status_code
16509 'P101'); -- funds_check_result_code
16510
16511
16512 t_period_name.DELETE;
16513 t_start_date.DELETE;
16514 t_end_date.DELETE;
16515 t_ccid.DELETE;
16516 t_amt.DELETE;
16517
16518 End If;
16519
16520 If l_count < l_limit then
16521 exit;
16522 end if;
16523
16524 end loop;
16525 close c_acct_lines;
16526
16527 If g_debug_mode = 'Y' then
16528 log_message(p_msg_token1=>l_program_name||' After PA_Budget_Acct_Lines Insert DML');
16529 End If;
16530 -- -------------------------------------------------------------------+
16531 -- 2.0: Update previous amounts (budget and available)
16532 -- -------------------------------------------------------------------+
16533 If p_prev_budget_version_id is not null then -- re-baseline -- I
16534 If g_debug_mode = 'Y' then
16535 log_message(p_msg_token1=>l_program_name||':Updating previous amounts');
16536 End If;
16537
16538 Update PA_Budget_Acct_Lines pbl
16539 set (pbl.Prev_Ver_Budget_Amount,pbl.Prev_Ver_Available_Amount) =
16540 (select pbl1.Curr_Ver_Budget_Amount,
16541 pbl1.Curr_Ver_Available_Amount
16542 from PA_Budget_Acct_Lines pbl1
16543 where pbl1.budget_version_id = P_prev_budget_version_id
16544 and pbl1.code_combination_id = pbl.code_combination_id
16545 and pbl1.start_date = pbl.start_date)
16546 where pbl.budget_version_id = p_budget_version_id
16547 and exists
16548 (select 1
16549 from PA_Budget_Acct_Lines pbl2
16550 where pbl2.budget_version_id = P_prev_budget_version_id
16551 and pbl2.code_combination_id = pbl.code_combination_id
16552 and pbl2.start_date = pbl.start_date);
16553 -- Bottom "exists clause" reqd, else if there is no record then the
16554 -- previous budget amounts may get updated to null and its a not null field
16555 End If; -- I
16556
16557 -- -------------------------------------------------------------------+
16558 -- 3.0: Update available and accounted amounts for the current version
16559 -- -------------------------------------------------------------------+
16560 If g_debug_mode = 'Y' then
16561 log_message(p_msg_token1=>l_program_name||':Updating avail. bal and accounted amt.');
16562 End If;
16563
16564 -- e.g. Prev.Budget = 100, Current Budget = 50, Prev. available = 90
16565 -- That means there were txn. for 10 against prev. budget (100-90)
16566 -- Current available = 50 - (100-90) = 40
16567 -- Accounted = 100-50 = 50
16568
16569 Update PA_Budget_Acct_Lines
16570 set Curr_Ver_Available_Amount = Curr_Ver_Budget_Amount -
16571 (Prev_Ver_Budget_Amount - Prev_Ver_Available_Amount),
16572 Accounted_Amount = Curr_Ver_Budget_Amount - Prev_Ver_Budget_Amount
16573 -- Accounted_Amount = Prev_Ver_Budget_Amount - Curr_Ver_Budget_Amount
16574 where budget_version_id = p_budget_version_id;
16575
16576
16577 -- -------------------------------------------------------------------+
16578 -- 4.0: Build account lines that are missing with respect to previous
16579 -- version. e.g.: Budget line deleted, acct/period changed on
16580 -- the old budget
16581 -- -------------------------------------------------------------------+
16582 If p_prev_budget_version_id is not null then -- re-baseline -- II
16583 If g_debug_mode = 'Y' then
16584 log_message(p_msg_token1=>l_program_name||':Creating missing records');
16585 End If;
16586
16587 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and
16588 P_budget_version_id = pa_budget_fund_pkg.g_cost_current_bvid )then
16589
16590 -- This IF..END IF ..is reqd. as this procedure is called for the draft version
16591 -- during <> 'CF' mode ..to rebuild the acct. sumamry for the draft version
16592 -- In this case, the else part should fire ..
16593
16594 INSERT INTO PA_BUDGET_ACCT_LINES (
16595 Budget_Acct_Line_ID,
16596 Budget_Version_ID,
16597 GL_Period_Name,
16598 Start_Date,
16599 End_Date,
16600 Code_Combination_ID,
16601 Prev_Ver_Budget_Amount,
16602 Prev_Ver_Available_Amount,
16603 Curr_Ver_Budget_Amount,
16604 Curr_Ver_Available_Amount,
16605 accounted_amount,
16606 LAST_UPDATE_DATE,
16607 LAST_UPDATED_BY,
16608 LAST_UPDATE_LOGIN,
16609 CREATION_DATE,
16610 CREATED_BY,
16611 REQUEST_ID,
16612 funds_check_status_code,
16613 funds_check_result_code
16614 )
16615 SELECT
16616 PA_BUDGET_ACCT_LINES_S.nextval,
16617 P_Budget_Version_ID, -- current version
16618 BL1.GL_Period_Name,
16619 BL1.Start_Date,
16620 BL1.End_Date,
16621 BL1.Code_Combination_ID,
16622 BL1.Curr_Ver_Budget_Amount,
16623 BL1.Curr_Ver_Available_Amount,
16624 0,
16625 0,
16626 0 - BL1.Curr_Ver_Budget_Amount,
16627 l_date,
16628 l_login,
16629 l_login,
16630 l_date,
16631 l_login,
16632 l_request,
16633 'A',
16634 'P101'
16635 FROM PA_BUDGET_ACCT_LINES BL1
16636 WHERE BL1.Budget_Version_ID = P_prev_budget_version_id
16637 AND NOT EXISTS
16638 ( SELECT 'x'
16639 FROM PA_BUDGET_ACCT_LINES BL2
16640 WHERE BL2.Budget_Version_ID = P_budget_version_id
16641 AND BL2.Code_Combination_ID = BL1.Code_Combination_ID
16642 AND BL2.Start_Date = BL1.Start_Date ) ;
16643
16644 -- In the above select, cannot use code combination filter
16645 -- scenario: CCID for JAN-05 was 101 but now it changed to 102 ..
16646 -- in this case, we can create record for 101 (as FC can have issue)
16647 -- If reqd. we can create 101 for the draft version by using a decode
16648
16649 -- 8/22: Code combination filter is fine .. as accounts cannot change on budget lines with txn.
16650 -- And also, the missing lines are created with current amount = 0
16651
16652 Else
16653
16654 INSERT INTO PA_BUDGET_ACCT_LINES (
16655 Budget_Acct_Line_ID,
16656 Budget_Version_ID,
16657 GL_Period_Name,
16658 Start_Date,
16659 End_Date,
16660 Code_Combination_ID,
16661 Prev_Ver_Budget_Amount,
16662 Prev_Ver_Available_Amount,
16663 Curr_Ver_Budget_Amount,
16664 Curr_Ver_Available_Amount,
16665 accounted_amount,
16666 LAST_UPDATE_DATE,
16667 LAST_UPDATED_BY,
16668 LAST_UPDATE_LOGIN,
16669 CREATION_DATE,
16670 CREATED_BY,
16671 REQUEST_ID,
16672 funds_check_status_code,
16673 funds_check_result_code
16674 )
16675 SELECT
16676 PA_BUDGET_ACCT_LINES_S.nextval,
16677 P_Budget_Version_ID, -- current version
16678 BL1.GL_Period_Name,
16679 BL1.Start_Date,
16680 BL1.End_Date,
16681 BL1.Code_Combination_ID,
16682 BL1.Curr_Ver_Budget_Amount,
16683 BL1.Curr_Ver_Available_Amount,
16684 0,
16685 0,
16686 0 - BL1.Curr_Ver_Budget_Amount,
16687 l_date,
16688 l_login,
16689 l_login,
16690 l_date,
16691 l_login,
16692 l_request,
16693 'A',
16694 'P101'
16695 FROM PA_BUDGET_ACCT_LINES BL1
16696 WHERE BL1.Budget_Version_ID = P_prev_budget_version_id
16697 AND (BL1.Curr_Ver_Budget_Amount <> 0 OR
16698 BL1.Prev_Ver_Budget_Amount <> 0)
16699 -- this is to filter the zero $ lines ...
16700 AND NOT EXISTS
16701 ( SELECT 'x'
16702 FROM PA_BUDGET_ACCT_LINES BL2
16703 WHERE BL2.Budget_Version_ID = P_budget_version_id
16704 AND BL2.Code_Combination_ID = BL1.Code_Combination_ID
16705 AND BL2.Start_Date = BL1.Start_Date ) ;
16706 End If;
16707
16708
16709 End If; -- re-baseline check -- II
16710
16711 If g_debug_mode = 'Y' then
16712 log_message(p_msg_token1=>'End:'||l_program_name);
16713 End If;
16714
16715 Exception
16716 When Others then
16717 If g_debug_mode = 'Y' then
16718 log_message(p_msg_token1=>'End:'||l_program_name||SQLERRM);
16719 End If;
16720 RAISE;
16721
16722 END Build_account_summary;
16723
16724 -- --------------------------------------------------------------------------------+
16725 -- This program is called to build the draft summary from Step 4 in do_budget_baseline
16726 -- It calls build_account_summary ..
16727 -- --------------------------------------------------------------------------------+
16728 PROCEDURE Build_account_summary_auto(X_budget_version_id IN NUMBER,
16729 X_balance_type IN VARCHAR2,
16730 X_budget_amount_code IN VARCHAR2,
16731 X_prev_budget_version_id IN NUMBER,
16732 X_mode IN VARCHAR2)
16733 IS
16734 tt_gl_period_name pa_plsql_datatypes.char50TabTyp;
16735 tt_code_combination_id pa_plsql_datatypes.IdTabTyp;
16736 tt_result_code pa_plsql_datatypes.char50TabTyp;
16737 PRAGMA AUTONOMOUS_TRANSACTION;
16738 Begin
16739 If g_debug_mode = 'Y' then
16740 log_message(p_msg_token1=>'Build_account_summary_auto:Start:X_mode:'||X_mode);
16741 End If;
16742
16743 If X_mode = 'FAIL' then
16744 Begin
16745 Select gl_period_name,
16746 code_combination_id,
16747 funds_check_result_code
16748 BULK COLLECT
16749 into tt_gl_period_name,
16750 tt_code_combination_id,
16751 tt_result_code
16752 from pa_budget_acct_lines
16753 where budget_version_id = X_budget_version_id
16754 and funds_check_result_code like 'F%';
16755 Exception
16756 When no_data_found then
16757 null;
16758 End;
16759 End If; --If X_mode = 'FAIL' then
16760
16761
16762 BUILD_ACCOUNT_SUMMARY(p_budget_version_id => X_budget_version_id,
16763 p_balance_type => X_balance_type,
16764 p_budget_amount_code => X_budget_amount_code,
16765 p_prev_budget_version_id => X_prev_budget_version_id);
16766
16767
16768 If X_mode = 'FAIL' then
16769 If tt_code_combination_id.exists(1) then
16770 forall x in tt_result_code.FIRST..tt_result_code.LAST
16771 update pa_budget_acct_lines
16772 set funds_check_result_code = tt_result_code(x)
16773 where budget_version_id = X_budget_version_id
16774 and code_combination_id = tt_code_combination_id(x)
16775 and gl_period_name = tt_gl_period_name(x);
16776
16777
16778 tt_gl_period_name.DELETE;
16779 tt_code_combination_id.DELETE;
16780 tt_result_code.DELETE;
16781
16782 End If;
16783 End If; --If X_mode = 'FAIL' then
16784
16785 COMMIT;
16786
16787 If g_debug_mode = 'Y' then
16788 log_message(p_msg_token1=>'Build_account_summary_auto:End');
16789 End If;
16790
16791 End Build_account_summary_auto;
16792
16793 -- --------------------------------------------------------------------------------+
16794 -- Following procedure resets funds_check_status_code and result code on
16795 -- pa_budget_acct_lines for the draft version ..
16796 -- 8/22: Initalizing to pass status ..
16797 -- --------------------------------------------------------------------------------+
16798 PROCEDURE Reset_status_code_on_summary(p_budget_version_id IN Number)
16799 IS
16800 PRAGMA AUTONOMOUS_TRANSACTION;
16801 Begin
16802
16803 Update pa_budget_acct_lines
16804 set funds_check_status_code = 'A', --null,
16805 funds_check_result_code = 'P101' --null
16806 where budget_version_id = p_budget_version_id;
16807 --and (funds_check_status_code is not null or funds_check_result_code is not null);
16808
16809 If g_debug_mode = 'Y' then
16810 log_message(p_msg_token1=>'Reset_status_code_on_summary:Status nullified on:'||SQL%ROWCOUNT || ' records');
16811 End If;
16812
16813 COMMIT;
16814
16815 End Reset_status_code_on_summary;
16816
16817 -- --------------------------------------------------------------------------------+
16818 -- This autonomous procedure is called to update the newly derived account info.
16819 -- back onto the draft budget lines during baseline/yearend ..
16820 -- --------------------------------------------------------------------------------+
16821 PROCEDURE Upd_new_acct_on_draft_budget(p_budget_line_rowid IN g_tab_rowid%TYPE,
16822 p_budget_ccid IN g_tab_budget_ccid%TYPE,
16823 p_new_ccid IN g_tab_budget_ccid%TYPE,
16824 p_change_allowed IN g_tab_allow_flag%TYPE,
16825 p_record_updated OUT NOCOPY Varchar2)
16826
16827 IS
16828 l_count number;
16829 PRAGMA AUTONOMOUS_TRANSACTION;
16830 Begin
16831 forall x in p_new_ccid.FIRST..p_new_ccid.LAST
16832 Update pa_budget_lines pbl
16833 set pbl.code_combination_id = p_new_ccid(x)
16834 where pbl.rowid = p_budget_line_rowid(x)
16835 and p_budget_ccid(x) <> p_new_ccid(x)
16836 and p_change_allowed(x) = 'Y'
16837 and p_budget_line_rowid(x) is not null;
16838
16839 -- p_change_allowed is used to restrict the budget lines where acct. valdiation failed, F169 issue
16840 -- p_budget_line_rowid is not null, is used to restrict update, this is for the zero $ budget
16841 -- lines that will not be existant in the draft budget
16842
16843 l_count := SQL%ROWCOUNT;
16844
16845 If g_debug_mode = 'Y' then
16846 log_message(p_msg_token1=>'Upd_new_acct_on_draft_budget:Acct. updated on:'||l_count || ' records');
16847 End If;
16848
16849 If l_count > 0 then
16850 p_record_updated := 'Y';
16851 Else
16852 p_record_updated := 'N';
16853 End if;
16854
16855 COMMIT;
16856
16857 End Upd_new_acct_on_draft_budget;
16858
16859 -- --------------------------------------------------------------------------------+
16860 -- This procedure will fail data in the other packet .. i.e. the credit packet ..
16861 -- --------------------------------------------------------------------------------+
16862 PROCEDURE Fail_credit_packet(p_input_packet IN Varchar2,
16863 p_return_status_code OUT NOCOPY varchar2)
16864 IS
16865 -- Cursor used to select records to fail all records ....
16866 -- As data split between packet, records were not being failed in the credit packet ..
16867 Cursor c_gl_records is
16868 select glbc.rowid,glbc.ae_header_id,glbc.ledger_id
16869 from gl_bc_packets glbc
16870 where glbc.event_id in
16871 (select event_id from psa_bc_xla_events_gt);
16872
16873 l_baseline_failed Varchar2(1);
16874 t_ae_header_id TypeNum;
16875 t_ledger_id TypeNum;
16876 t_glrowid TypeVarChar;
16877
16878 BEGIN
16879 l_program_name := 'Fail_credit_packet';
16880
16881 If g_debug_mode = 'Y' then
16882 log_message(p_msg_token1=>l_program_name||'Inside Fail_credit_packet api');
16883 End If;
16884
16885 If p_input_packet = 'DEBIT' then
16886
16887 l_baseline_failed := 'Y';
16888
16889 Elsif p_input_packet = 'CREDIT' then
16890
16891 Begin
16892 select 'Y'
16893 into l_baseline_failed
16894 from dual
16895 where exists
16896 (select packet_id
16897 from gl_bc_packets glbc
16898 where glbc.event_id in
16899 (select event_id from psa_bc_xla_events_gt)
16900 and glbc.result_code like 'F%');
16901 Exception
16902 when no_data_found then
16903 l_baseline_failed := 'N';
16904 End;
16905
16906 End If;
16907
16908 If l_baseline_failed = 'N' then
16909 p_return_status_code := 'S';
16910 RETURN;
16911 Else
16912 p_return_status_code := 'F';
16913 End If;
16914
16915 If g_debug_mode = 'Y' then
16916 log_message(p_msg_token1=>l_program_name||'Fail all records for the session');
16917 End If;
16918
16919 Open c_gl_records;
16920 loop
16921 Fetch c_gl_records BULK COLLECT into t_glrowid,
16922 t_ae_header_id,
16923 t_ledger_id
16924 LIMIT l_limit;
16925
16926
16927 If g_debug_mode = 'Y' then
16928 log_message(p_msg_token1=>l_program_name||'No. of records in pl/sql table['||t_glrowid.count||']');
16929 End If;
16930
16931 If t_glrowid.exists(1) then
16932
16933 -- -------------------------------------------------------------------------- +
16934 -- Fail gl_bc_packet records ...
16935 -- -------------------------------------------------------------------------- +
16936 forall i in t_glrowid.FIRST..t_glrowid.LAST
16937 Update gl_bc_packets glbc
16938 set glbc.result_code = decode(substr(glbc.result_code,1,1),'F',glbc.result_code,'F35'),
16939 glbc.status_code = decode(pa_budget_fund_pkg.g_processing_mode,
16940 'CHECK_FUNDS','F','R')
16941 where rowid = t_glrowid(i);
16942
16943 If g_debug_mode = 'Y' then
16944 log_message(p_msg_token1=>l_program_name||'GL packets, records updated['||sql%rowcount||']');
16945 End If;
16946
16947 -- -------------------------------------------------------------------------- +
16948 -- Fail xla_ae_headers_gt records ...
16949 -- -------------------------------------------------------------------------- +
16950 forall i in t_ae_header_id.FIRST..t_ae_header_id.LAST
16951 UPDATE xla_ae_headers_gt
16952 SET funds_status_code = decode(pa_budget_fund_pkg.g_processing_mode,
16953 'CHECK_FUNDS','F','R')
16954 WHERE ae_header_id = t_ae_header_id(i)
16955 AND ledger_id = t_ledger_id(i);
16956
16957 If g_debug_mode = 'Y' then
16958 log_message(p_msg_token1=>l_program_name||'xla_ae_headers_gt, records updated['||sql%rowcount||']');
16959 End If;
16960 -- -------------------------------------------------------------------------- +
16961 -- Fail gl_bc_packet records ...
16962 -- -------------------------------------------------------------------------- +
16963 forall i in t_ae_header_id.FIRST..t_ae_header_id.LAST
16964 UPDATE xla_validation_lines_gt
16965 SET funds_status_code = 'F77'
16966 WHERE ae_header_id = t_ae_header_id(i);
16967
16968 If g_debug_mode = 'Y' then
16969 log_message(p_msg_token1=>l_program_name||'xla_validation_lines_gt, records updated['||sql%rowcount||']');
16970 End If;
16971
16972 -- -------------------------------------------------------------------------- +
16973 -- Initalize records ...
16974 -- -------------------------------------------------------------------------- +
16975
16976 t_glrowid.delete;
16977 t_ae_header_id.delete;
16978 t_ledger_id.delete;
16979
16980 If t_glrowid.COUNT < l_limit then
16981 exit;
16982 End if;
16983
16984 Else -- if t_gl_rowid.exists(1)
16985 exit;
16986 End if;
16987
16988 end loop;
16989
16990
16991 End Fail_credit_packet;
16992
16993
16994 -- ------------------------------------ R12 End ------------------------------------------------+
16995
16996 END PA_FUNDS_CONTROL_PKG;