1 package body PA_FUNDS_CONTROL_PKG as
2 -- $Header: PABCFCKB.pls 120.43 2007/11/06 10:09:15 vchilla noship $
3
4 /**-----------------------------------------------------------------------
5 --- Declare Global Variables
6 ----------------------------------------------------------------------***/
7 --g_debug_mode VARCHAR2(10); -- Moved to Spec ..
8 g_mode VARCHAR2(100);
9 g_calling_module VARCHAR2(100);
10 g_partial_flag VARCHAR2(100);
11 g_return_status VARCHAR2(1000);
12 g_pa_gl_return_status VARCHAR2(1000);
13 g_pa_cbc_return_status VARCHAR2(1000);
14 g_doc_type VARCHAR2(1000);
15 g_error_stage VARCHAR2(1000);
16 g_error_msg VARCHAR2(2000);
17 g_packet_id PA_BC_PACKETS.PACKET_ID%TYPE;
18 g_cbc_packet_id PA_BC_PACKETS.PACKET_ID%TYPE;
19 g_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
20 g_task_id PA_BC_PACKETS.TASK_ID%type := null;
21 g_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
22 g_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
23 g_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
24 g_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
25 g_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
26 g_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
27 g_entry_level_code VARCHAR2(200) := null;
28 g_start_date DATE := null;
29 g_end_date DATE := null;
30 g_time_phase_code VARCHAR2(20) := null;
31 g_pre_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
32 g_pre_task_id PA_BC_PACKETS.TASK_ID%type := null;
33 g_pre_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
34 g_pre_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
35 g_pre_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
36 g_pre_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
37 g_pre_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
38 g_pre_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
39 g_pre_entry_level_code VARCHAR2(200) := null;
40 g_pre_start_date DATE := null;
41 g_pre_end_date DATE := null;
42 g_pre_time_phase_code VARCHAR2(20) := null;
43 g_bdgt_ccid PA_BC_PACKETS.budget_ccid%type := null;
44 g_pre_bdgt_ccid PA_BC_PACKETS.budget_ccid%type := null;
45 g_r_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
46 g_r_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
47 g_r_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
48 g_r_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
49 g_r_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
50 g_r_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
51 g_r_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
52 g_rg_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
53 g_rg_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
54 g_rg_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
55 g_rg_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
56 g_rg_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
57 g_rg_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
58 g_rg_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
59 g_t_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
60 g_t_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
61 g_t_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
62 g_t_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
63 g_t_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
64 g_t_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
65 g_t_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
66 g_tt_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
67 g_tt_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
68 g_tt_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
69 g_tt_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
70 g_tt_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
71 g_tt_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
72 g_tt_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
73 g_p_budget_posted PA_BC_PACKETS.res_budget_posted%type := null;
74 g_p_actual_posted PA_BC_PACKETS.res_budget_posted%type := null;
75 g_p_enc_posted PA_BC_PACKETS.res_budget_posted%type := null;
76 g_p_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
77 g_p_enc_pending PA_BC_PACKETS.res_budget_posted%type := null;
78 g_p_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
79 g_p_actual_pending PA_BC_PACKETS.res_budget_posted%type := null;
80 g_r_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
81 g_rg_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
82 g_t_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
83 g_tt_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
84 g_p_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
85 g_p_acct_pkt_amt PA_BC_PACKETS.res_budget_posted%type := null;
86 g_r_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
87 g_rg_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
88 g_t_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
89 g_tt_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
90 g_p_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
91 g_p_acct_base_amt PA_BC_PACKETS.res_budget_posted%type := null;
92 g_p_acct_enc_approved PA_BC_PACKETS.res_budget_posted%type := null;
93 g_p_acct_actual_approved PA_BC_PACKETS.res_budget_posted%type := null;
94 g_exp_project_id pa_bc_packets.project_id%type := null;
95 g_exp_burden_method pa_bc_packets.expenditure_type%type := null;
96
97 -----These variables are added for performance testing
98 g_bal_r_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
99 g_bal_r_task_id PA_BC_PACKETS.TASK_ID%type := null;
100 g_bal_r_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
101 g_bal_r_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
102 g_bal_r_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
103 g_bal_r_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
104 g_bal_r_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
105 g_bal_r_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
106 g_bal_r_entry_level_code VARCHAR2(200) := null;
107 g_bal_r_start_date DATE := null;
108 g_bal_r_end_date DATE := null;
109 g_bal_r_time_phase_code VARCHAR2(20) := null;
110
111 g_pkt_r_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
112 g_pkt_r_task_id PA_BC_PACKETS.TASK_ID%type := null;
113 g_pkt_r_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
114 g_pkt_r_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
115 g_pkt_r_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
116 g_pkt_r_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
117 g_pkt_r_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
118 g_pkt_r_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
119 g_pkt_r_entry_level_code VARCHAR2(200) := null;
120 g_pkt_r_start_date DATE := null;
121 g_pkt_r_end_date DATE := null;
122 g_pkt_r_time_phase_code VARCHAR2(20) := null;
123
124 g_bal_rg_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
125 g_bal_rg_task_id PA_BC_PACKETS.TASK_ID%type := null;
126 g_bal_rg_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
127 g_bal_rg_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
128 g_bal_rg_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
129 g_bal_rg_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
130 g_bal_rg_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
131 g_bal_rg_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
132 g_bal_rg_entry_level_code VARCHAR2(200) := null;
133 g_bal_rg_start_date DATE := null;
134 g_bal_rg_end_date DATE := null;
135 g_bal_rg_time_phase_code VARCHAR2(20) := null;
136
137 g_pkt_rg_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
138 g_pkt_rg_task_id PA_BC_PACKETS.TASK_ID%type := null;
139 g_pkt_rg_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
140 g_pkt_rg_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
141 g_pkt_rg_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
142 g_pkt_rg_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
143 g_pkt_rg_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
144 g_pkt_rg_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
145 g_pkt_rg_entry_level_code VARCHAR2(200) := null;
146 g_pkt_rg_start_date DATE := null;
147 g_pkt_rg_end_date DATE := null;
148 g_pkt_rg_time_phase_code VARCHAR2(20) := null;
149
150 g_bal_t_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
151 g_bal_t_task_id PA_BC_PACKETS.TASK_ID%type := null;
152 g_bal_t_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
153 g_bal_t_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
154 g_bal_t_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
155 g_bal_t_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
156 g_bal_t_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
157 g_bal_t_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
158 g_bal_t_entry_level_code VARCHAR2(200) := null;
159 g_bal_t_start_date DATE := null;
160 g_bal_t_end_date DATE := null;
161 g_bal_t_time_phase_code VARCHAR2(20) := null;
162
163 g_pkt_t_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
164 g_pkt_t_task_id PA_BC_PACKETS.TASK_ID%type := null;
165 g_pkt_t_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
166 g_pkt_t_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
167 g_pkt_t_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
168 g_pkt_t_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
169 g_pkt_t_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
170 g_pkt_t_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
171 g_pkt_t_entry_level_code VARCHAR2(200) := null;
172 g_pkt_t_start_date DATE := null;
173 g_pkt_t_end_date DATE := null;
174 g_pkt_t_time_phase_code VARCHAR2(20) := null;
175
176 g_bal_tt_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
177 g_bal_tt_task_id PA_BC_PACKETS.TASK_ID%type := null;
178 g_bal_tt_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
179 g_bal_tt_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
180 g_bal_tt_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
181 g_bal_tt_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
182 g_bal_tt_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
183 g_bal_tt_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
184 g_bal_tt_entry_level_code VARCHAR2(200) := null;
185 g_bal_tt_start_date DATE := null;
186 g_bal_tt_end_date DATE := null;
187 g_bal_tt_time_phase_code VARCHAR2(20) := null;
188
189 g_pkt_tt_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
190 g_pkt_tt_task_id PA_BC_PACKETS.TASK_ID%type := null;
191 g_pkt_tt_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
192 g_pkt_tt_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
193 g_pkt_tt_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
194 g_pkt_tt_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
195 g_pkt_tt_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
196 g_pkt_tt_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
197 g_pkt_tt_entry_level_code VARCHAR2(200) := null;
198 g_pkt_tt_start_date DATE := null;
199 g_pkt_tt_end_date DATE := null;
200 g_pkt_tt_time_phase_code VARCHAR2(20) := null;
201
202 g_bal_p_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
203 g_bal_p_task_id PA_BC_PACKETS.TASK_ID%type := null;
204 g_bal_p_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
205 g_bal_p_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
206 g_bal_p_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
207 g_bal_p_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
208 g_bal_p_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
209 g_bal_p_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
210 g_bal_p_entry_level_code VARCHAR2(200) := null;
211 g_bal_p_start_date DATE := null;
212 g_bal_p_end_date DATE := null;
213 g_bal_p_time_phase_code VARCHAR2(20) := null;
214
215 g_pkt_p_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
216 g_pkt_p_task_id PA_BC_PACKETS.TASK_ID%type := null;
217 g_pkt_p_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
218 g_pkt_p_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
219 g_pkt_p_bud_task_id PA_BC_PACKETS.TASK_ID%type := null;
220 g_pkt_p_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
221 g_pkt_p_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
222 g_pkt_p_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
223 g_pkt_p_entry_level_code VARCHAR2(200) := null;
224 g_pkt_p_start_date DATE := null;
225 g_pkt_p_end_date DATE := null;
226 g_pkt_p_time_phase_code VARCHAR2(20) := null;
227
228
229 g_pkt_p_acct_project_id PA_BC_PACKETS.PROJECT_ID%TYPE := null;
230 g_pkt_p_acct_task_id PA_BC_PACKETS.TASK_ID%type := null;
231 g_pkt_p_acct_top_task_id PA_BC_PACKETS.TOP_TASK_ID%type := null;
232 g_pkt_p_acct_bdgt_version_id PA_BC_PACKETS.budget_version_id%type := null;
233 g_pkt_p_acct_bdgt_ccid PA_BC_PACKETS.budget_ccid%type := null;
234 g_pkt_p_acct_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
235 g_pkt_p_acct_bud_rlmi PA_BC_PACKETS.resource_list_member_id%type := null;
236 g_pkt_p_acct_prlmi PA_BC_PACKETS.resource_list_member_id%type := null;
237 g_pkt_p_acct_entry_level_code VARCHAR2(200) := null;
238 g_pkt_p_acct_start_date DATE := null;
239 g_pkt_p_acct_end_date DATE := null;
240 g_pkt_p_acct_time_phase_code VARCHAR2(20) := null;
241 ------- end of performance varibales declrartions
242
243 --Bug 5964934
244 g_fclc_budget_version_id pa_budget_versions.budget_version_id%type := null;
245 g_fclc_project_id pa_budgetary_controls.project_id%type := null;
246 g_fclc_top_task_id pa_budgetary_controls.top_task_id%type := null;
247 g_fclc_task_id pa_budgetary_controls.task_id%type := null;
248 g_fclc_parent_member_id pa_budgetary_controls.parent_member_id%type := null;
249 g_fclc_resource_list_member_id pa_budgetary_controls.resource_list_member_id%type := null;
250 g_p_funds_control_level_code varchar2(1) := null;
251 g_tt_funds_control_level_code varchar2(1) := null;
252 g_t_funds_control_level_code varchar2(1) := null;
253 g_rg_funds_control_level_code varchar2(1) := null;
254 g_r_funds_control_level_code varchar2(1) := null;
255
256 /**---------------------------------------------------------------------------------
257 -- declare plsql tables to hold values during the funds check process
258 --------------------------------------------------------------------- **/
259 type rowidtabtyp is table of urowid index by binary_integer;
260 g_tab_rowid rowidtabtyp;
261 g_tab_bc_packet_id pa_plsql_datatypes.IdTabTyp;
262 g_tab_p_bc_packet_id pa_plsql_datatypes.IdTabTyp;
263 g_tab_budget_version_id pa_plsql_datatypes.IdTabTyp;
264 g_tab_project_id pa_plsql_datatypes.IdTabTyp;
265 g_tab_task_id pa_plsql_datatypes.IdTabTyp;
266 g_tab_doc_type pa_plsql_datatypes.Char50TabTyp;
267 g_tab_doc_header_id pa_plsql_datatypes.IdTabTyp;
268 g_tab_doc_distribution_id pa_plsql_datatypes.IdTabTyp;
269 g_tab_exp_item_date pa_plsql_datatypes.DateTabTyp;
270 g_tab_exp_org_id pa_plsql_datatypes.IdTabTyp;
271 g_tab_OU pa_plsql_datatypes.IdTabTyp;
272 g_tab_actual_flag pa_plsql_datatypes.char50TabTyp;
273 g_tab_period_name pa_plsql_datatypes.char50TabTyp;
274 g_tab_time_phase_type_code pa_plsql_datatypes.char50TabTyp;
275 g_tab_amount_type pa_plsql_datatypes.char50TabTyp;
276 g_tab_boundary_code pa_plsql_datatypes.char50TabTyp;
277 g_tab_entry_level_code pa_plsql_datatypes.char50TabTyp;
278 g_tab_category_code pa_plsql_datatypes.char50TabTyp;
279 g_tab_rlmi pa_plsql_datatypes.IdTabTyp;
280 g_tab_p_resource_id pa_plsql_datatypes.IdTabTyp;
281 g_tab_r_list_id pa_plsql_datatypes.IdTabTyp;
282 g_tab_p_member_id pa_plsql_datatypes.IdTabTyp;
283 g_tab_bud_task_id pa_plsql_datatypes.IdTabTyp;
284 g_tab_bud_rlmi pa_plsql_datatypes.IdTabTyp;
285 g_tab_tt_task_id pa_plsql_datatypes.IdTabTyp;
286 g_tab_r_fclevel_code pa_plsql_datatypes.char50TabTyp;
287 g_tab_rg_fclevel_code pa_plsql_datatypes.char50TabTyp;
288 g_tab_t_fclevel_code pa_plsql_datatypes.char50TabTyp;
289 g_tab_tt_fclevel_code pa_plsql_datatypes.char50TabTyp;
290 g_tab_p_fclevel_code pa_plsql_datatypes.char50TabTyp;
291 g_tab_p_acct_fclevel_code pa_plsql_datatypes.char50TabTyp;
292 g_tab_burd_cost_flag pa_plsql_datatypes.char50TabTyp;
293 g_tab_pkt_trx_amt pa_plsql_datatypes.NumTabTyp;
294 g_tab_accounted_dr pa_plsql_datatypes.NumTabTyp;
295 g_tab_accounted_cr pa_plsql_datatypes.NumTabTyp;
296 g_tab_PA_amt pa_plsql_datatypes.NumTabTyp;
297 g_tab_PE_amt pa_plsql_datatypes.NumTabTyp;
298 g_tab_status_code pa_plsql_datatypes.char50TabTyp;
299 g_tab_effect_on_funds_code pa_plsql_datatypes.char50TabTyp;
300 g_tab_result_code pa_plsql_datatypes.char50TabTyp;
301 g_tab_r_result_code pa_plsql_datatypes.char50TabTyp;
302 g_tab_rg_result_code pa_plsql_datatypes.char50TabTyp;
303 g_tab_t_result_code pa_plsql_datatypes.char50TabTyp;
304 g_tab_tt_result_code pa_plsql_datatypes.char50TabTyp;
305 g_tab_p_result_code pa_plsql_datatypes.char50TabTyp;
306 g_tab_p_acct_result_code pa_plsql_datatypes.char50TabTyp;
307 g_tab_r_budget_posted pa_plsql_datatypes.NumTabTyp;
308 g_tab_rg_budget_posted pa_plsql_datatypes.NumTabTyp;
309 g_tab_t_budget_posted pa_plsql_datatypes.NumTabTyp;
310 g_tab_tt_budget_posted pa_plsql_datatypes.NumTabTyp;
311 g_tab_p_budget_posted pa_plsql_datatypes.NumTabTyp;
312 g_tab_r_actual_posted pa_plsql_datatypes.NumTabTyp;
313 g_tab_rg_actual_posted pa_plsql_datatypes.NumTabTyp;
314 g_tab_t_actual_posted pa_plsql_datatypes.NumTabTyp;
315 g_tab_tt_actual_posted pa_plsql_datatypes.NumTabTyp;
316 g_tab_p_actual_posted pa_plsql_datatypes.NumTabTyp;
317 g_tab_r_enc_posted pa_plsql_datatypes.NumTabTyp;
318 g_tab_rg_enc_posted pa_plsql_datatypes.NumTabTyp;
319 g_tab_t_enc_posted pa_plsql_datatypes.NumTabTyp;
320 g_tab_tt_enc_posted pa_plsql_datatypes.NumTabTyp;
321 g_tab_p_enc_posted pa_plsql_datatypes.NumTabTyp;
322 g_tab_r_budget_bal pa_plsql_datatypes.NumTabTyp;
323 g_tab_rg_budget_bal pa_plsql_datatypes.NumTabTyp;
324 g_tab_t_budget_bal pa_plsql_datatypes.NumTabTyp;
325 g_tab_tt_budget_bal pa_plsql_datatypes.NumTabTyp;
326 g_tab_p_budget_bal pa_plsql_datatypes.NumTabTyp;
327 g_tab_r_actual_approved pa_plsql_datatypes.NumTabTyp;
328 g_tab_rg_actual_approved pa_plsql_datatypes.NumTabTyp;
329 g_tab_t_actual_approved pa_plsql_datatypes.NumTabTyp;
330 g_tab_tt_actual_approved pa_plsql_datatypes.NumTabTyp;
331 g_tab_p_actual_approved pa_plsql_datatypes.NumTabTyp;
332 g_tab_r_enc_approved pa_plsql_datatypes.NumTabTyp;
333 g_tab_rg_enc_approved pa_plsql_datatypes.NumTabTyp;
334 g_tab_t_enc_approved pa_plsql_datatypes.NumTabTyp;
335 g_tab_tt_enc_approved pa_plsql_datatypes.NumTabTyp;
336 g_tab_p_enc_approved pa_plsql_datatypes.NumTabTyp;
337 g_tab_trxn_ccid pa_plsql_datatypes.Idtabtyp;
338 g_tab_budget_ccid pa_plsql_datatypes.Idtabtyp;
339 g_tab_old_budget_ccid pa_plsql_datatypes.Idtabtyp;
340 g_tab_effect_fclevel pa_plsql_datatypes.char50TabTyp;
341 g_tab_exp_category pa_plsql_datatypes.char50TabTyp;
342 g_tab_rev_category pa_plsql_datatypes.char50TabTyp;
343 g_tab_sys_link_func pa_plsql_datatypes.char50TabTyp;
344 g_tab_exp_type pa_plsql_datatypes.char50TabTyp;
345 g_tab_gl_date pa_plsql_datatypes.Datetabtyp;
346 g_tab_pa_date pa_plsql_datatypes.Datetabtyp;
347 g_tab_start_date pa_plsql_datatypes.Datetabtyp;
348 g_tab_end_date pa_plsql_datatypes.Datetabtyp;
349 g_tab_encum_type_id pa_plsql_datatypes.Idtabtyp;
350 g_tab_process_funds_level pa_plsql_datatypes.char50TabTyp;
351 g_tab_res_level_cache_amt pa_plsql_datatypes.NumTabTyp;
352 g_tab_res_grp_level_cache_amt pa_plsql_datatypes.NumTabTyp;
353 g_tab_task_level_cache_amt pa_plsql_datatypes.NumTabTyp;
354 g_tab_top_task_level_cache_amt pa_plsql_datatypes.NumTabTyp;
355 g_tab_proj_level_cache_amt pa_plsql_datatypes.NumTabTyp;
356 g_tab_prj_acct_level_cache_amt pa_plsql_datatypes.NumTabTyp;
357 g_tab_res_level_cache pa_plsql_datatypes.char50TabTyp;
358 g_tab_res_grp_level_cache pa_plsql_datatypes.char50TabTyp;
359 g_tab_task_level_cache pa_plsql_datatypes.char50TabTyp;
360 g_tab_top_task_level_cache pa_plsql_datatypes.char50TabTyp;
361 g_tab_proj_level_cache pa_plsql_datatypes.char50TabTyp;
362 g_tab_proj_acct_level_cache pa_plsql_datatypes.char50TabTyp;
363 g_tab_tieback_id pa_plsql_datatypes.char250TabTyp;
364 g_tab_group_resource_type_id pa_plsql_datatypes.NumTabTyp; /* bug fix 2658952 */
365 g_tab_person_id pa_plsql_datatypes.Idtabtyp;
366 g_tab_job_id pa_plsql_datatypes.Idtabtyp;
367 g_tab_vendor_id pa_plsql_datatypes.Idtabtyp;
368 g_tab_non_lab_res pa_plsql_datatypes.char250TabTyp;
369 g_tab_non_lab_res_org pa_plsql_datatypes.Idtabtyp;
370 g_tab_non_cat_rlmi pa_plsql_datatypes.Idtabtyp;
371 g_tab_proj_OU pa_plsql_datatypes.Idtabtyp;
372 g_tab_exp_OU pa_plsql_datatypes.Idtabtyp;
373 g_tab_doc_line_id pa_plsql_datatypes.Idtabtyp;
374 g_tab_ext_bdgt_link pa_plsql_datatypes.char50TabTyp;
375 g_tab_sob_id pa_plsql_datatypes.Idtabtyp;
376 g_tab_exp_gl_date pa_plsql_datatypes.DateTabTyp;
377 g_tab_exp_item_id pa_plsql_datatypes.Idtabtyp;
378
379 /* Bug 5631763 */
380 g_Tfund_control_level pa_budgetary_control_options.fund_control_level_task%type;
381 g_Pfund_control_level pa_budgetary_control_options.fund_control_level_project%type;
382 g_RGfund_control_level pa_budgetary_control_options.fund_control_level_res_grp%type;
383 g_Rfund_control_level pa_budgetary_control_options.fund_control_level_res%type;
384 /* Bug 5631763 */
385
386 -- Added for R12 ...
387 g_tab_burden_method_code pa_plsql_datatypes.char50TabTyp;
388 g_tab_budget_line_id pa_plsql_datatypes.IdTabTyp;
389 g_tab_src_dist_id_num_1 pa_plsql_datatypes.Idtabtyp;
390 g_tab_gl_bc_event_id pa_plsql_datatypes.Idtabtyp;
391 g_tab_src_dist_type pa_plsql_datatypes.char50TabTyp;
392 g_tab_allow_flag pa_plsql_datatypes.Char1TabTyp;
393 g_packet_credit_processed Varchar2(1);
394 g_packet_debit_processed Varchar2(1);
395
396
397 /**---------------------------------------------------------------------------------
398 -- declare a plsql record to hold values during the funds check process
399 ---------------------------------------------------------------------------------**/
400 TYPE PA_FC_RECORD is RECORD (
401 packet_id pa_bc_packets.packet_id%type,
402 bc_packet_id pa_bc_packets.bc_packet_id%type,
403 set_of_books_id pa_bc_packets.set_of_books_id%type,
404 budget_version_id pa_bc_packets.budget_version_id%type,
405 project_id pa_bc_packets.project_id%type,
406 task_id pa_bc_packets.task_id%type,
407 document_type pa_bc_packets.document_type%type,
408 document_header_id pa_bc_packets.document_header_id%type,
409 document_distribution_id pa_bc_packets.document_distribution_id%type,
410 expenditure_item_date pa_bc_packets.expenditure_item_date%type,
411 expenditure_organization_id pa_bc_packets.expenditure_organization_id%type,
412 exp_type pa_bc_packets.expenditure_type%type,
413 actual_flag pa_bc_packets.actual_flag%type,
414 period_name pa_bc_packets.period_name%type,
415 time_phased_type_code VARCHAR2(30),
416 amount_type VARCHAR2(15),
417 boundary_code VARCHAR2(15),
418 entry_level_code VARCHAR2(10),
419 categorization_code VARCHAR2(10),
420 resource_list_member_id pa_bc_packets.resource_list_member_id%TYPE,
421 parent_resource_id pa_bc_packets.parent_resource_id%type,
422 resource_list_id NUMBER,
423 parent_member_id NUMBER,
424 bud_task_id pa_bc_packets.bud_task_id%type,
425 bud_resource_list_member_id pa_bc_packets.bud_resource_list_member_id%type,
426 top_task_id pa_bc_packets.top_task_id%type,
427 r_funds_control_level_code pa_bc_packets.r_funds_control_level_code%type,
428 rg_funds_control_level_code pa_bc_packets.rg_funds_control_level_code%type,
429 t_funds_control_level_code pa_bc_packets.t_funds_control_level_code%type,
430 tt_funds_control_level_code pa_bc_packets.tt_funds_control_level_code%type,
431 p_funds_control_level_code pa_bc_packets.p_funds_control_level_code%type,
432 burdened_cost_flag VARCHAR2(10),
433 accounted_dr pa_bc_packets.accounted_dr%type,
434 accounted_cr pa_bc_packets.accounted_dr%type,
435 status_code pa_bc_packets.status_code%type,
436 r_budget_posted pa_bc_packets.res_budget_posted%type,
437 rg_budget_posted pa_bc_packets.res_budget_posted%type,
438 t_budget_posted pa_bc_packets.res_budget_posted%type,
439 tt_budget_posted pa_bc_packets.res_budget_posted%type,
440 p_budget_posted pa_bc_packets.res_budget_posted%type,
441 r_actual_posted pa_bc_packets.res_budget_posted%type,
442 rg_actual_posted pa_bc_packets.res_budget_posted%type,
443 t_actual_posted pa_bc_packets.res_budget_posted%type,
444 tt_actual_posted pa_bc_packets.res_budget_posted%type,
445 p_actual_posted pa_bc_packets.res_budget_posted%type,
446 r_enc_posted pa_bc_packets.res_budget_posted%type,
447 rg_enc_posted pa_bc_packets.res_budget_posted%type,
448 t_enc_posted pa_bc_packets.res_budget_posted%type,
449 tt_enc_posted pa_bc_packets.res_budget_posted%type,
450 p_enc_posted pa_bc_packets.res_budget_posted%type,
451 r_budget_bal pa_bc_packets.res_budget_posted%type,
452 rg_budget_bal pa_bc_packets.res_budget_posted%type,
453 t_budget_bal pa_bc_packets.res_budget_posted%type,
454 tt_budget_bal pa_bc_packets.res_budget_posted%type,
455 p_budget_bal pa_bc_packets.res_budget_posted%type,
456 r_actual_approved pa_bc_packets.res_budget_posted%type,
457 rg_actual_approved pa_bc_packets.res_budget_posted%type,
458 t_actual_approved pa_bc_packets.res_budget_posted%type,
459 tt_actual_approved pa_bc_packets.res_budget_posted%type,
460 p_actual_approved pa_bc_packets.res_budget_posted%type,
461 r_enc_approved pa_bc_packets.res_budget_posted%type,
462 rg_enc_approved pa_bc_packets.res_budget_posted%type,
463 t_enc_approved pa_bc_packets.res_budget_posted%type,
464 tt_enc_approved pa_bc_packets.res_budget_posted%type,
465 p_enc_approved pa_bc_packets.res_budget_posted%type,
466 result_code pa_bc_packets.result_code%type,
467 r_result_code pa_bc_packets.res_result_code%type,
468 rg_result_code pa_bc_packets.res_grp_result_code%type,
469 t_result_code pa_bc_packets.task_result_code%type,
470 tt_result_code pa_bc_packets.top_task_result_code%type,
471 p_result_code pa_bc_packets.project_result_code%type,
472 p_acct_result_code pa_bc_packets.project_result_code%type,
473 trxn_ccid pa_bc_packets.txn_ccid%type,
474 budget_ccid pa_bc_packets.budget_ccid%type,
475 effect_on_funds_code pa_bc_packets.effect_on_funds_code%type,
476 gl_date pa_bc_packets.expenditure_item_date%type,
477 pa_date pa_bc_packets.expenditure_item_date%type,
478 parent_bc_packet_id pa_bc_packets.bc_packet_id%type,
479 group_resource_type_id Number
480 );
481
482 -- -------------------------- R12 Changes Start -------------------------------------+
483
484 Type TypeNum is table of number index by binary_integer;
485 Type TypeVarChar is table of varchar2(50) index by binary_integer;
486 Type TypeDate is table of date index by binary_integer;
487 l_limit NUMBER(4);
488 l_program_name VARCHAR2(30);
489 g_event_id TypeNum;
490 g_doc_dist_id TypeNum;
491 g_document_type TypeVarChar;
492 g_ap_matched_case Varchar2(1);
493
494 -- This procedure will execute the budget account validation, account level FC
495 -- and update budget lines with the new derived accounts, call PROCEDURE
496 -- Build_account_summary to build pa_budget_acct_lines
497
498 PROCEDURE DO_BUDGET_BASELINE_TIEBACK(p_packet_id IN NUMBER,
499 p_return_status OUT NOCOPY VARCHAR2);
500
501 -- This procedure will build pa_budget_acct_lines
502 -- Called from DO_BUDGET_BASELINE_TIEBACK
503
504 PROCEDURE Build_account_summary(P_budget_version_id IN NUMBER,
505 P_balance_type IN VARCHAR2,
506 P_budget_amount_code IN VARCHAR2,
507 P_prev_budget_version_id IN NUMBER);
508
509 -- This procedure is an autonomus procedure that calls Build_account_summary
510 -- Called from DO_BUDGET_BASELINE_TIEBACK
511
512 PROCEDURE Build_account_summary_auto(X_budget_version_id IN NUMBER,
513 X_balance_type IN VARCHAR2,
514 X_budget_amount_code IN VARCHAR2,
515 X_prev_budget_version_id IN NUMBER,
516 X_mode IN VARCHAR2);
517
518 -- This procedure will update pa_bc_packets records with a failure status.
519 -- This procedure is an AUTONOMOUS procedure
520 -- This procedure will be called from do_budget_baseline_tieback
521
522 PROCEDURE Fail_bc_pkt_during_baseline(P_budget_version_id IN NUMBER,
523 P_period_name IN g_tab_period_name%TYPE,
524 P_budget_ccid IN g_tab_budget_ccid%TYPE,
525 P_allow_flag IN g_tab_allow_flag%TYPE,
526 P_result_code IN VARCHAR2);
527
528 -- This procedure will update pa_budget_acct_lines with a failure status.
529 -- This procedure is an AUTONOMOUS procedure
530 -- This procedure will be called from do_budget_baseline_tieback
531
532 PROCEDURE Update_failure_in_acct_summary(P_budget_version_id IN NUMBER,
533 P_period_name IN g_tab_period_name%TYPE,
534 P_budget_ccid IN g_tab_budget_ccid%TYPE,
535 P_allow_flag IN g_tab_allow_flag%TYPE,
536 P_result_code IN VARCHAR2);
537
538 -- Procedure Update_budget_ccid updated budget_ccid on the pa_bc_packet records
539 -- for this baseline, its an AUTONOMOUS procedure ..
540
541 PROCEDURE Update_budget_ccid(P_budget_version_id IN NUMBER,
542 P_budget_ccid IN g_tab_budget_ccid%TYPE,
543 P_budget_line_id IN g_tab_budget_line_id%TYPE,
544 P_budget_entry_level_code IN VARCHAR2,
545 P_period_name IN g_tab_period_name%TYPE,
546 P_rlmi IN g_tab_rlmi%TYPE,
547 P_task_id IN g_tab_task_id%TYPE,
548 P_derived_ccid IN g_tab_budget_ccid%TYPE,
549 P_allowed_flag IN g_tab_allow_flag%TYPE,
550 P_result_code IN OUT NOCOPY VARCHAR2);
551
552 -- --------------------------------------------------------------------------------+
553 -- This procedure will mark gl_bc_packets records to a status such that GL does
554 -- not execute funds available validation. Previously we used to create liquidation
555 -- entries. Instead of that, we're executing the following procedure.
556 -- This is for NO/SEPARATE LINE BURDENING only.
557 -- This procedure is called from function pa_funds_check
558 -- --------------------------------------------------------------------------------+
559 -- PROCEDURE Mark_gl_bc_packets_for_no_fc (p_packet_id IN Number);
560
561 -- --------------------------------------------------------------------------------+
562 -- This procedure will determine whether funds check/ funds check tieback
563 -- has been called for non-project related/project related txn. or budget
564 -- funds check.
565 -- p_return_code: 'NO_FC', For non-project related FC
566 -- p_return_code: 'TXN_FC',For project related txn. (including 'RESERVE_BASELINE')
567 -- p_return_code: 'BUD_FC',For SLA-BC budget baseline integration (GL FC)
568 -- --------------------------------------------------------------------------------+
569 PROCEDURE Check_txn_or_budget_fc(p_packet_id in number,
570 p_return_code out NOCOPY varchar2);
571
572 -- --------------------------------------------------------------------------------+
573 -- This procedure will update the following columns in pa_bc_packets: serial_id,
574 -- session_id,actual_flag,packet_id and status. Status will be upated from I to P.
575 -- Called from pa_funds_check
576 -- This procedure will also check if the extracts were successful, meaning that:
577 -- A. pa_bc_packet records have been extracted into gl_bc_packets
578 -- B. core records have been extracted into gl_bc_packets
579 -- C. project relieveing entries are created in gl_bc_packets
580 -- --------------------------------------------------------------------------------+
581 PROCEDURE Synch_pa_gl_packets(x_packet_id IN Number,
582 x_partial_flag IN VARCHAR2,
583 x_mode IN VARCHAR2,
584 x_result_code OUT NOCOPY Varchar2);
585
586 -- --------------------------------------------------------------------------------+
587 -- Following procedure resets funds_check_status_code and result code on
588 -- pa_budget_acct_lines for the draft version ..
589 -- --------------------------------------------------------------------------------+
590 PROCEDURE Reset_status_code_on_summary(p_budget_version_id IN Number);
591
592 -- --------------------------------------------------------------------------------+
593 -- This procedure is called from Synch_pa_gl_packets to AUTONOMOUSLY update
594 -- pa_bc_packets with failure....in case of extract failing ..
595 -- -------------------------------------------------------------------------------+
596 PROCEDURE Missing_records_failure(p_pa_packet_id IN NUMBER,
597 p_gl_packet_id IN NUMBER,
598 p_partial_flag IN VARCHAR2,
599 p_mode IN VARCHAR2);
600
601 -- --------------------------------------------------------------------------------+
602 -- This procedure is called from Synch_pa_gl_packets to update: serial_id,
603 -- session_id, actual_flag,packet_id and status ..
604 -- --------------------------------------------------------------------------------+
605 PROCEDURE Synch_data(p_pa_packet_id IN NUMBER,
606 p_gl_packet_id IN NUMBER);
607
608 -- --------------------------------------------------------------------------------+
609 -- This procedure will be called from do_budget_baseline to update pa_bc_packet
610 -- project_acct_result_code and result_code to 'P101' after account level funds
611 -- check is successful. Procedure is AUTONOMOUS
612 -- --------------------------------------------------------------------------------+
613 PROCEDURE Upd_bc_pkt_acct_result_code(P_budget_version_id IN NUMBER);
614
615 -- --------------------------------------------------------------------------------+
616 -- This procedure will check if there exists any txn. against the project
617 -- It will return 'Y' if any txn exists
618 -- --------------------------------------------------------------------------------+
619 Procedure Any_txns_against_project(p_project_id IN NUMBER,
620 p_txn_exists_in_bc_pkt OUT NOCOPY VARCHAR2,
621 p_txn_exists_in_bc_cmt OUT NOCOPY VARCHAR2);
622
623 -- --------------------------------------------------------------------------------+
624 -- This procedure has been created to handle FULL MODE failure during check funds
625 -- action of an invoice that is matched to PO .. bug 5253309
626 -- p_case added to handle future scenarios..
627 -- This is reqd. especially for scenarios where AP has multiple distributions and
628 -- some are matched to PO, in such cases the doc. is in 'PARTIAL MODE' but matched
629 -- dist. is treated in FULL MODE.
630 -- --------------------------------------------------------------------------------+
631 Procedure Full_mode_failure(p_packet_id IN NUMBER,
632 p_case IN VARCHAR2);
633
634 -- --------------------------------------------------------------------------------+
635 -- This autonomous procedure is called to update the newly derived account info.
636 -- back onto the draft budget lines during baseline/yearend ..
637 -- --------------------------------------------------------------------------------+
638 PROCEDURE Upd_new_acct_on_draft_budget(p_budget_line_rowid IN g_tab_rowid%TYPE,
639 p_budget_ccid IN g_tab_budget_ccid%TYPE,
640 p_new_ccid IN g_tab_budget_ccid%TYPE,
641 p_change_allowed IN g_tab_allow_flag%TYPE,
642 p_record_updated OUT NOCOPY Varchar2);
643
644 -- --------------------------------------------------------------------------------+
645 -- This procedure will fail data in the other packet .. i.e. the credit packet ..
646 -- --------------------------------------------------------------------------------+
647 PROCEDURE Fail_credit_packet(p_input_packet IN Varchar2,
648 p_return_status_code OUT NOCOPY varchar2);
649
650 -- -------------------------- R12 Changes End -------------------------------------+
651
652 /**-------------------------------------------------------------------------------
653 -- Procedure to Initialize the global variables
654 -------------------------------------------------------------------------------**/
655 PROCEDURE Initialize_globals IS
656
657 BEGIN
658
659
660 g_error_stage := null;
661 g_error_msg := null;
662 g_project_id := null;
663 g_task_id := null;
664 g_top_task_id := null;
665 g_bdgt_version_id := null;
666 g_bud_task_id := null;
667 g_rlmi := null;
668 g_bud_rlmi := null;
669 g_prlmi := null;
670 g_entry_level_code := null;
671 g_start_date := null;
672 g_end_date := null;
673 g_time_phase_code := null;
674 g_pre_project_id := null;
675 g_pre_task_id := null;
676 g_pre_top_task_id := null;
677 g_pre_bdgt_version_id := null;
678 g_pre_bud_task_id := null;
679 g_pre_rlmi := null;
680 g_pre_bud_rlmi := null;
681 g_pre_prlmi := null;
682 g_pre_entry_level_code := null;
683 g_pre_start_date := null;
684 g_pre_end_date := null;
685 g_pre_time_phase_code := null;
686 g_r_budget_posted := null;
687 g_r_actual_posted := null;
688 g_r_enc_posted := null;
689 g_r_enc_approved := null;
690 g_r_enc_pending := null;
691 g_r_actual_approved := null;
692 g_r_budget_posted := null;
693 g_r_actual_posted := null;
694 g_r_enc_posted := null;
695 g_r_enc_approved := null;
696 g_r_enc_pending := null;
697 g_r_actual_approved := null;
698 g_r_actual_pending := null;
699 g_rg_budget_posted := null;
700 g_rg_actual_posted := null;
701 g_rg_enc_posted := null;
702 g_rg_enc_approved := null;
703 g_rg_enc_pending := null;
704 g_rg_actual_approved := null;
705 g_rg_actual_pending := null;
706 g_t_budget_posted := null;
707 g_t_actual_posted := null;
708 g_t_enc_posted := null;
709 g_t_enc_approved := null;
710 g_t_enc_pending := null;
711 g_t_actual_approved := null;
712 g_t_actual_pending := null;
713 g_tt_budget_posted := null;
714 g_tt_actual_posted := null;
715 g_tt_enc_posted := null;
716 g_tt_enc_approved := null;
717 g_tt_enc_pending := null;
718 g_tt_actual_approved := null;
719 g_tt_actual_pending := null;
720 g_p_budget_posted := null;
721 g_p_actual_posted := null;
722 g_p_enc_posted := null;
723 g_p_enc_approved := null;
724 g_p_enc_pending := null;
725 g_p_actual_approved := null;
726 g_p_actual_pending := null;
727 g_r_pkt_amt := null;
728 g_rg_pkt_amt := null;
729 g_t_pkt_amt := null;
730 g_tt_pkt_amt := null;
731 g_p_pkt_amt := null;
732 g_p_acct_pkt_amt := null;
733 g_r_base_amt := null;
734 g_rg_base_amt := null;
735 g_t_base_amt := null;
736 g_tt_base_amt := null;
737 g_p_base_amt := null;
738 g_p_acct_base_amt := null;
739 g_bdgt_ccid := null;
740 g_pre_bdgt_ccid := null;
741 g_p_acct_enc_approved := null;
742 g_p_acct_actual_approved := null;
743 g_exp_burden_method := null;
744 g_exp_project_id := null;
745
746 -----for performance testing these variables added
747 g_bal_r_project_id := null;
748 g_bal_r_task_id := null;
749 g_bal_r_top_task_id := null;
750 g_bal_r_bdgt_version_id := null;
751 g_bal_r_bud_task_id := null;
752 g_bal_r_rlmi := null;
753 g_bal_r_bud_rlmi := null;
754 g_bal_r_prlmi := null;
755 g_bal_r_entry_level_code := null;
756 g_bal_r_start_date := null;
757 g_bal_r_end_date := null;
758 g_bal_r_time_phase_code := null;
759
760 g_pkt_r_project_id := null;
761 g_pkt_r_task_id := null;
762 g_pkt_r_top_task_id := null;
763 g_pkt_r_bdgt_version_id := null;
764 g_pkt_r_bud_task_id := null;
765 g_pkt_r_rlmi := null;
766 g_pkt_r_bud_rlmi := null;
767 g_pkt_r_prlmi := null;
768 g_pkt_r_entry_level_code := null;
769 g_pkt_r_start_date := null;
770 g_pkt_r_end_date := null;
771 g_pkt_r_time_phase_code := null;
772
773 g_bal_rg_project_id := null;
774 g_bal_rg_task_id := null;
775 g_bal_rg_top_task_id := null;
776 g_bal_rg_bdgt_version_id := null;
777 g_bal_rg_bud_task_id := null;
778 g_bal_rg_rlmi := null;
779 g_bal_rg_bud_rlmi := null;
780 g_bal_rg_prlmi := null;
781 g_bal_rg_entry_level_code := null;
782 g_bal_rg_start_date := null;
783 g_bal_rg_end_date := null;
784 g_bal_rg_time_phase_code := null;
785
786 g_pkt_rg_project_id := null;
787 g_pkt_rg_task_id := null;
788 g_pkt_rg_top_task_id := null;
789 g_pkt_rg_bdgt_version_id := null;
790 g_pkt_rg_bud_task_id := null;
791 g_pkt_rg_rlmi := null;
792 g_pkt_rg_bud_rlmi := null;
793 g_pkt_rg_prlmi := null;
794 g_pkt_rg_entry_level_code := null;
795 g_pkt_rg_start_date := null;
796 g_pkt_rg_end_date := null;
797 g_pkt_rg_time_phase_code := null;
798
799 g_bal_t_project_id := null;
800 g_bal_t_task_id := null;
801 g_bal_t_top_task_id := null;
802 g_bal_t_bdgt_version_id := null;
803 g_bal_t_bud_task_id := null;
804 g_bal_t_rlmi := null;
805 g_bal_t_bud_rlmi := null;
806 g_bal_t_prlmi := null;
807 g_bal_t_entry_level_code := null;
808 g_bal_t_start_date := null;
809 g_bal_t_end_date := null;
810 g_bal_t_time_phase_code := null;
811
812 g_pkt_t_project_id := null;
813 g_pkt_t_task_id := null;
814 g_pkt_t_top_task_id := null;
815 g_pkt_t_bdgt_version_id := null;
816 g_pkt_t_bud_task_id := null;
817 g_pkt_t_rlmi := null;
818 g_pkt_t_bud_rlmi := null;
819 g_pkt_t_prlmi := null;
820 g_pkt_t_entry_level_code := null;
821 g_pkt_t_start_date := null;
822 g_pkt_t_end_date := null;
823 g_pkt_t_time_phase_code := null;
824
825 g_bal_tt_project_id := null;
826 g_bal_tt_task_id := null;
827 g_bal_tt_top_task_id := null;
828 g_bal_tt_bdgt_version_id := null;
829 g_bal_tt_bud_task_id := null;
830 g_bal_tt_rlmi := null;
831 g_bal_tt_bud_rlmi := null;
832 g_bal_tt_prlmi := null;
833 g_bal_tt_entry_level_code := null;
834 g_bal_tt_start_date := null;
835 g_bal_tt_end_date := null;
836 g_bal_tt_time_phase_code := null;
837
838 g_pkt_tt_project_id := null;
839 g_pkt_tt_task_id := null;
840 g_pkt_tt_top_task_id := null;
841 g_pkt_tt_bdgt_version_id := null;
842 g_pkt_tt_bud_task_id := null;
843 g_pkt_tt_rlmi := null;
844 g_pkt_tt_bud_rlmi := null;
845 g_pkt_tt_prlmi := null;
846 g_pkt_tt_entry_level_code := null;
847 g_pkt_tt_start_date := null;
848 g_pkt_tt_end_date := null;
849 g_pkt_tt_time_phase_code := null;
850
851 g_bal_p_project_id := null;
852 g_bal_p_task_id := null;
853 g_bal_p_top_task_id := null;
854 g_bal_p_bdgt_version_id := null;
855 g_bal_p_bud_task_id := null;
856 g_bal_p_rlmi := null;
857 g_bal_p_bud_rlmi := null;
858 g_bal_p_prlmi := null;
859 g_bal_p_entry_level_code := null;
860 g_bal_p_start_date := null;
861 g_bal_p_end_date := null;
862 g_bal_p_time_phase_code := null;
863
864 g_pkt_p_project_id := null;
865 g_pkt_p_task_id := null;
866 g_pkt_p_top_task_id := null;
867 g_pkt_p_bdgt_version_id := null;
868 g_pkt_p_bud_task_id := null;
869 g_pkt_p_rlmi := null;
870 g_pkt_p_bud_rlmi := null;
871 g_pkt_p_prlmi := null;
872 g_pkt_p_entry_level_code := null;
873 g_pkt_p_start_date := null;
874 g_pkt_p_end_date := null;
875 g_pkt_p_time_phase_code := null;
876
877
878 g_pkt_p_acct_project_id := null;
879 g_pkt_p_acct_task_id := null;
880 g_pkt_p_acct_bdgt_ccid := null;
881 g_pkt_p_acct_bdgt_version_id := null;
882 --g_pkt_p_acct_bud_task_id := null;
883 g_pkt_p_acct_rlmi := null;
884 g_pkt_p_acct_bud_rlmi := null;
885 g_pkt_p_acct_prlmi := null;
886 g_pkt_p_acct_entry_level_code := null;
887 g_pkt_p_acct_start_date := null;
888 g_pkt_p_acct_end_date := null;
889 g_pkt_p_acct_time_phase_code := null;
890 --- end of cache variables for resource level bal and pkt
891
892
893 -- clear plsql tabs
894 g_tab_res_level_cache_amt.delete;
895 g_tab_res_grp_level_cache_amt.delete;
896 g_tab_task_level_cache_amt.delete;
897 g_tab_top_task_level_cache_amt.delete;
898 g_tab_proj_level_cache_amt.delete;
899 g_tab_prj_acct_level_cache_amt.delete;
900 g_tab_res_level_cache.delete;
901 g_tab_res_grp_level_cache.delete;
902 g_tab_task_level_cache.delete;
903 g_tab_top_task_level_cache.delete;
904 g_tab_proj_level_cache.delete;
905 g_tab_proj_acct_level_cache.delete;
906
907 END Initialize_globals;
908 /**-----------------------------------------------------------------------------
909 --Procedure to initialize the value of the record to zero after every loop.
910 ------------------------------------------------------------------------------**/
911 PROCEDURE initialize_record (
912 pa_bc_rec_ini IN OUT NOCOPY pa_fc_record ) IS
913 x_err_code NUMBER;
914 x_err_buff VARCHAR2 ( 2000 );
915 BEGIN
916 pa_bc_rec_ini.packet_id := 0;
917 pa_bc_rec_ini.bc_packet_id := 0;
918 pa_bc_rec_ini.set_of_books_id := 0;
919 pa_bc_rec_ini.budget_version_id := 0;
920 pa_bc_rec_ini.project_id := 0;
921 pa_bc_rec_ini.task_id := 0;
922 pa_bc_rec_ini.document_type := null;
923 pa_bc_rec_ini.document_header_id := 0;
924 pa_bc_rec_ini.document_distribution_id := 0;
925 pa_bc_rec_ini.expenditure_item_date := NULL;
926 pa_bc_rec_ini.expenditure_organization_id := 0;
927 pa_bc_rec_ini.exp_type := null;
928 pa_bc_rec_ini.actual_flag := NULL;
929 pa_bc_rec_ini.period_name := NULL;
930 pa_bc_rec_ini.time_phased_type_code := NULL;
931 pa_bc_rec_ini.amount_type := NULL;
932 pa_bc_rec_ini.boundary_code := NULL;
933 pa_bc_rec_ini.entry_level_code := NULL;
934 pa_bc_rec_ini.categorization_code := NULL;
935 pa_bc_rec_ini.resource_list_member_id := 0;
936 pa_bc_rec_ini.parent_resource_id := 0;
937 pa_bc_rec_ini.resource_list_id := 0;
938 pa_bc_rec_ini.parent_member_id := 0;
939 pa_bc_rec_ini.bud_task_id := 0;
940 pa_bc_rec_ini.bud_resource_list_member_id := 0;
941 pa_bc_rec_ini.top_task_id := 0;
942 pa_bc_rec_ini.r_funds_control_level_code := NULL;
943 pa_bc_rec_ini.rg_funds_control_level_code := NULL;
944 pa_bc_rec_ini.t_funds_control_level_code := NULL;
945 pa_bc_rec_ini.tt_funds_control_level_code := NULL;
946 pa_bc_rec_ini.p_funds_control_level_code := NULL;
947 pa_bc_rec_ini.burdened_cost_flag := NULL;
948 pa_bc_rec_ini.accounted_dr := 0;
949 pa_bc_rec_ini.accounted_cr := 0;
950 pa_bc_rec_ini.status_code := 0;
951 pa_bc_rec_ini.r_budget_posted := 0;
952 pa_bc_rec_ini.rg_budget_posted := 0;
953 pa_bc_rec_ini.t_budget_posted := 0;
954 pa_bc_rec_ini.tt_budget_posted := 0;
955 pa_bc_rec_ini.p_budget_posted := 0;
956 pa_bc_rec_ini.r_actual_posted := 0;
957 pa_bc_rec_ini.rg_actual_posted := 0;
958 pa_bc_rec_ini.t_actual_posted := 0;
959 pa_bc_rec_ini.tt_actual_posted := 0;
960 pa_bc_rec_ini.p_actual_posted := 0;
961 pa_bc_rec_ini.r_enc_posted := 0;
962 pa_bc_rec_ini.rg_enc_posted := 0;
963 pa_bc_rec_ini.t_enc_posted := 0;
964 pa_bc_rec_ini.tt_enc_posted := 0;
965 pa_bc_rec_ini.p_enc_posted := 0;
966 pa_bc_rec_ini.r_budget_bal := 0;
967 pa_bc_rec_ini.rg_budget_bal := 0;
968 pa_bc_rec_ini.t_budget_bal := 0;
969 pa_bc_rec_ini.tt_budget_bal := 0;
970 pa_bc_rec_ini.p_budget_bal := 0;
971 pa_bc_rec_ini.r_actual_approved := 0;
972 pa_bc_rec_ini.rg_actual_approved := 0;
973 pa_bc_rec_ini.t_actual_approved := 0;
974 pa_bc_rec_ini.tt_actual_approved := 0;
975 pa_bc_rec_ini.p_actual_approved := 0;
976 pa_bc_rec_ini.r_enc_approved := 0;
977 pa_bc_rec_ini.rg_enc_approved := 0;
978 pa_bc_rec_ini.t_enc_approved := 0;
979 pa_bc_rec_ini.tt_enc_approved := 0;
980 pa_bc_rec_ini.p_enc_approved := 0;
981 pa_bc_rec_ini.result_code := NULL;
982 pa_bc_rec_ini.r_result_code := NULL;
983 pa_bc_rec_ini.rg_result_code := NULL;
984 pa_bc_rec_ini.t_result_code := NULL;
985 pa_bc_rec_ini.tt_result_code := NULL;
986 pa_bc_rec_ini.p_result_code := NULL;
987 pa_bc_rec_ini.p_acct_result_code := NULL;
988 pa_bc_rec_ini.trxn_ccid := NULL;
989 pa_bc_rec_ini.budget_ccid := NULL;
990 pa_bc_rec_ini.effect_on_funds_code := NULL;
991 pa_bc_rec_ini.gl_date := NULL;
992 pa_bc_rec_ini.pa_date := NULL;
993 pa_bc_rec_ini.parent_bc_packet_id := 0;
994 pa_bc_rec_ini.group_resource_type_id := null;
995
996
997 EXCEPTION
998 WHEN OTHERS THEN
999 Commit;
1000 RAISE;
1001 END initialize_record;
1002
1003
1004 /**--------------------------------------------------------------------------
1005 -- This api initializes the pl/sql tables
1006 -------------------------------------------------------------------------- **/
1007 PROCEDURE init_plsql_tabs IS
1008
1009 BEGIN
1010 g_tab_rowid.delete;
1011 g_tab_bc_packet_id.delete;
1012 g_tab_p_bc_packet_id.delete;
1013 g_tab_budget_version_id.delete;
1014 g_tab_project_id.delete;
1015 g_tab_task_id.delete;
1016 g_tab_doc_type.delete;
1017 g_tab_doc_header_id.delete;
1018 g_tab_doc_distribution_id.delete;
1019 g_tab_exp_item_date.delete;
1020 g_tab_exp_org_id.delete;
1021 g_tab_OU.delete;
1022 g_tab_actual_flag.delete;
1023 g_tab_period_name.delete;
1024 g_tab_time_phase_type_code.delete;
1025 g_tab_amount_type.delete;
1026 g_tab_boundary_code.delete;
1027 g_tab_entry_level_code.delete;
1028 g_tab_category_code.delete;
1029 g_tab_rlmi.delete;
1030 g_tab_p_resource_id.delete;
1031 g_tab_r_list_id.delete;
1032 g_tab_p_member_id.delete;
1033 g_tab_bud_task_id.delete;
1034 g_tab_bud_rlmi.delete;
1035 g_tab_tt_task_id.delete;
1036 g_tab_r_fclevel_code.delete;
1037 g_tab_rg_fclevel_code.delete;
1038 g_tab_t_fclevel_code.delete;
1039 g_tab_tt_fclevel_code.delete;
1040 g_tab_p_fclevel_code.delete;
1041 g_tab_p_acct_fclevel_code.delete;
1042 g_tab_burd_cost_flag.delete;
1043 g_tab_pkt_trx_amt.delete;
1044 g_tab_accounted_dr.delete;
1045 g_tab_accounted_cr.delete;
1046 g_tab_PA_amt.delete;
1047 g_tab_PE_amt.delete;
1048 g_tab_status_code.delete;
1049 g_tab_effect_on_funds_code.delete;
1050 g_tab_result_code.delete;
1051 g_tab_r_result_code.delete;
1052 g_tab_rg_result_code.delete;
1053 g_tab_t_result_code.delete;
1054 g_tab_tt_result_code.delete;
1055 g_tab_p_result_code.delete;
1056 g_tab_r_budget_posted.delete;
1057 g_tab_rg_budget_posted.delete;
1058 g_tab_t_budget_posted.delete;
1059 g_tab_tt_budget_posted.delete;
1060 g_tab_p_budget_posted.delete;
1061 g_tab_r_actual_posted.delete;
1062 g_tab_rg_actual_posted.delete;
1063 g_tab_t_actual_posted.delete;
1064 g_tab_tt_actual_posted.delete;
1065 g_tab_p_actual_posted.delete;
1066 g_tab_r_enc_posted.delete;
1067 g_tab_rg_enc_posted.delete;
1068 g_tab_t_enc_posted.delete;
1069 g_tab_tt_enc_posted.delete;
1070 g_tab_p_enc_posted.delete;
1071 g_tab_r_budget_bal.delete;
1072 g_tab_rg_budget_bal.delete;
1073 g_tab_t_budget_bal.delete;
1074 g_tab_tt_budget_bal.delete;
1075 g_tab_p_budget_bal.delete;
1076 g_tab_r_actual_approved.delete;
1077 g_tab_rg_actual_approved.delete;
1078 g_tab_t_actual_approved.delete;
1079 g_tab_tt_actual_approved.delete;
1080 g_tab_p_actual_approved.delete;
1081 g_tab_r_enc_approved.delete;
1082 g_tab_rg_enc_approved.delete;
1083 g_tab_t_enc_approved.delete;
1084 g_tab_tt_enc_approved.delete;
1085 g_tab_p_enc_approved.delete;
1086 g_tab_effect_fclevel.delete;
1087 g_tab_trxn_ccid.delete;
1088 g_tab_budget_ccid.delete;
1089 g_tab_p_acct_result_code.delete;
1090 g_tab_exp_category.delete;
1091 g_tab_rev_category.delete;
1092 g_tab_sys_link_func.delete;
1093 g_tab_exp_type.delete;
1094 g_tab_gl_date.delete;
1095 g_tab_pa_date.delete;
1096 g_tab_start_date.delete;
1097 g_tab_end_date.delete;
1098 g_tab_encum_type_id.delete;
1099 g_tab_process_funds_level.delete;
1100 g_tab_old_budget_ccid.delete;
1101 g_tab_group_resource_type_id.delete;
1102 g_tab_person_id.delete;
1103 g_tab_job_id.delete;
1104 g_tab_vendor_id.delete;
1105 g_tab_non_lab_res.delete;
1106 g_tab_non_lab_res_org.delete;
1107 g_tab_non_cat_rlmi.delete;
1108 g_tab_proj_OU.delete;
1109 g_tab_exp_OU.delete;
1110 g_tab_doc_line_id.delete;
1111 g_tab_ext_bdgt_link.delete;
1112 g_tab_sob_id.delete;
1113 g_tab_exp_gl_date.delete;
1114 g_tab_exp_item_id.delete;
1115 g_tab_burden_method_code.delete; -- for r12
1116 g_tab_budget_line_id.delete; -- for r12
1117
1118 EXCEPTION
1119
1120 WHEN OTHERS THEN
1121 --commit;
1122 RAISE;
1123
1124
1125 END init_plsql_tabs;
1126
1127 -------->6599207 ------As part of CC Enhancements
1128 --Forward declarations
1129 PROCEDURE Post_Bdn_Lines_To_GL_CBC (
1130 p_Packet_ID IN Number,
1131 p_calling_module IN VARCHAR2,
1132 p_packet_status IN VARCHAR2,
1133 p_reference1 IN VARCHAR2,
1134 p_reference2 IN VARCHAR2,
1135 x_return_status OUT NOCOPY VARCHAR2
1136 );
1137 -------->6599207 ------END
1138
1139 ---Forward declarations
1140 PROCEDURE update_EIS (p_packet_id IN NUMBER,
1141 p_calling_module IN VARCHAR2,
1142 p_mode IN VARCHAR2,
1143 x_return_status OUT NOCOPY VARCHAR2);
1144
1145 ---Forward declarations
1146 PROCEDURE update_GL_CBC_result_code(
1147 p_packet_id IN number,
1148 p_calling_module IN varchar2,
1149 p_mode IN varchar2,
1150 p_partial_flag IN varchar2,
1151 p_reference1 IN varchar2 default null,
1152 p_reference2 IN varchar2 default null,
1153 p_packet_status IN varchar2,
1154 x_return_status OUT NOCOPY varchar2);
1155 -- Forward declarations
1156 FUNCTION pa_fck_process
1157 (p_sob IN NUMBER
1158 ,p_packet_id IN pa_bc_packets.packet_id%type
1159 ,p_mode IN varchar2
1160 ,p_partial_flag IN varchar2
1161 ,p_arrival_seq IN NUMBER
1162 ,p_reference1 IN varchar2
1163 ,p_reference2 IN varchar2
1164 --,p_reference3 IN varchar2
1165 ,p_calling_module IN varchar2
1166 ) return BOOLEAN;
1167
1168 /** This API derives the return code for GL / CBC
1169 * based on partial reserve flag, If the funds check is called
1170 * in partial mode GL /CBC expects the return status as P if
1171 * the records are partially passed
1172 */
1173 FUNCTION get_gl_cbc_return_status(
1174 p_packet_id NUMBER) return varchar2 IS
1175
1176 CURSOR pkt_status is
1177 SELECT decode(count(*),count(decode(substr(nvl(pbc.result_code,'P'),1,1),'P',1)),'S','P')
1178 FROM pa_bc_packets pbc
1179 WHERE pbc.packet_id = p_packet_id;
1180
1181 l_pkt_status varchar2(10);
1182 BEGIN
1183 OPEN pkt_status;
1184 FETCH pkt_status INTO l_pkt_status;
1185 CLOSE pkt_status;
1186
1187 return nvl(l_pkt_status,'P');
1188
1189 EXCEPTION
1190 WHEN OTHERS THEN
1191 IF pkt_status%isopen then
1192 close pkt_status;
1193 END IF;
1194 return nvl(l_pkt_status,'P');
1195
1196 END get_gl_cbc_return_status;
1197
1198 /**----------------------------------------------------------------------------
1199 -- This api checks whether the project is of burden on same or different
1200 -- expenditure items
1201 -- returns 'S' (SAME) 'D'(SEPARATE) 'N' (NO BURDEN)
1202 --------------------------------------------------------------------------- **/
1203 FUNCTION check_bdn_on_sep_item(p_project_id In number) return varchar2 IS
1204 l_burden_method VARCHAR2(20);
1205 BEGIN
1206
1207 If g_exp_project_id is null or g_exp_project_id <> p_project_id then
1208 SELECT decode(NVL(ppt.burden_cost_flag, 'N'),'Y',
1209 NVL(ppt.burden_amt_display_method,'S'),'N')
1210 -- decode(NVL(ppt.burden_amt_display_method,'S'), 'S','SAME','D','DIFFERENT'),'NONE')
1211 INTO l_burden_method
1212 FROM pa_project_types ppt,
1213 pa_projects_all pp
1214 WHERE
1215 ppt.project_type = pp.project_type
1216 AND pp.project_id = p_project_id;
1217
1218 g_exp_burden_method := l_burden_method;
1219 g_exp_project_id := p_project_id;
1220
1221 RETURN l_burden_method;
1222
1223 Else -- retrive from cache
1224
1225 RETURN g_exp_burden_method;
1226 End if;
1227
1228 EXCEPTION
1229 WHEN NO_DATA_FOUND THEN
1230 g_exp_burden_method := 'N';
1231 -- g_exp_burden_method := 'NONE';
1232 RETURN g_exp_burden_method;
1233 WHEN OTHERS THEN
1234 RAISE;
1235
1236 END check_bdn_on_sep_item;
1237 /**------------------------------------------------------------------
1238 -- This api updates the result and status code in pa bc packets
1239 -- whenever there is error while processing
1240 ----------------------------------------------------------------- **/
1241 PROCEDURE result_status_code_update
1242 ( p_status_code IN VARCHAR2 default null
1243 ,p_result_code IN VARCHAR2 default null
1244 ,p_res_result_code IN VARCHAR2 default null
1245 ,p_res_grp_result_code IN VARCHAR2 default null
1246 ,p_task_result_code IN VARCHAR2 default null
1247 ,p_top_task_result_code IN VARCHAR2 default null
1248 ,p_project_result_code IN VARCHAR2 default null
1249 ,p_proj_acct_result_code IN VARCHAR2 default null
1250 ,p_bc_packet_id IN NUMBER default null
1251 ,p_packet_id IN NUMBER ) IS
1252
1253 cursor cur_pkts is
1254 SELECT packet_id,
1255 bc_packet_id
1256 FROM pa_bc_packets
1257 WHERE packet_id = p_packet_id;
1258
1259 l_tab_packet_id pa_plsql_datatypes.idtabtyp;
1260 l_tab_bc_packet_id pa_plsql_datatypes.idtabtyp;
1261
1262 PRAGMA AUTONOMOUS_TRANSACTION;
1263
1264 BEGIN
1265 pa_debug.init_err_stack('PA_FUNDS_CONTROL_PKG.result_status_code_update');
1266 /******
1267 -- Added if else condition to avoid full table scan on pa_bc_packets
1268 --EXPLAIN PLAN IS:
1269 --1:UPDATE STATEMENT :(cost=2,rows=1)
1270 --2:UPDATE PA_BC_PACKETS :(cost=,rows=)
1271 --3:TABLE ACCESS BY INDEX ROWID PA_BC_PACKETS :(cost=2,rows=1)
1272 --4:INDEX UNIQUE SCAN PA_BC_PACKETS_U1 :(cost=1,rows=1)
1273 *******/
1274
1275 If p_status_code = 'T' then
1276
1277 OPEN cur_pkts;
1278 LOOP
1279 l_tab_packet_id.delete;
1280 l_tab_bc_packet_id.delete;
1281 FETCH cur_pkts BULK COLLECT INTO
1282 l_tab_packet_id
1283 ,l_tab_bc_packet_id LIMIT 500;
1284 IF NOT l_tab_packet_id.EXISTS(1) then
1285 EXIT;
1286 END if;
1287 FORALL i IN l_tab_packet_id.first .. l_tab_packet_id.last
1288 UPDATE pa_bc_packets
1289 SET status_code = 'T',
1290 result_code = decode(substr(nvl(result_code,'P'),1,1)
1291 ,'P', decode(substr(nvl(p_result_code,'P'),1,1)
1292 ,'F', p_result_code,'F142')
1293 ,result_code),
1294 res_result_code = nvl(res_result_code,p_res_result_code),
1295 res_grp_result_code = nvl(res_grp_result_code,p_res_grp_result_code),
1296 task_result_code = nvl(task_result_code,p_task_result_code),
1297 top_task_result_code = nvl(top_task_result_code,p_top_task_result_code),
1298 project_result_code = nvl(project_result_code,p_project_result_code),
1299 project_acct_result_code =nvl(project_acct_result_code,p_proj_acct_result_code)
1300 WHERE packet_id = l_tab_packet_id(i);
1301
1302 Exit when cur_pkts%NOTFOUND;
1303 commit;
1304 END LOOP;
1305 CLOSE cur_pkts;
1306
1307
1308 ELSIf p_bc_packet_id is NOT NULL and p_status_code <> 'T' then
1309
1310 OPEN cur_pkts;
1311 LOOP
1312 l_tab_packet_id.delete;
1313 l_tab_bc_packet_id.delete;
1314 FETCH cur_pkts BULK COLLECT INTO
1315 l_tab_packet_id,
1316 l_tab_bc_packet_id LIMIT 500;
1317 IF NOT l_tab_packet_id.EXISTS(1) then
1318 EXIT;
1319 END if;
1320 FORALL i IN l_tab_packet_id.first .. l_tab_packet_id.last
1321
1322 UPDATE pa_bc_packets
1323 SET status_code = nvl(p_status_code,status_code),
1324 result_code = nvl(p_result_code ,result_code),
1325 res_result_code = nvl(p_res_result_code,res_result_code),
1326 res_grp_result_code = nvl(p_res_grp_result_code,res_grp_result_code),
1327 task_result_code = nvl(p_task_result_code,task_result_code),
1328 top_task_result_code = nvl(p_top_task_result_code,top_task_result_code),
1329 project_result_code = nvl(p_project_result_code,project_result_code),
1330 project_acct_result_code =nvl(p_proj_acct_result_code,project_acct_result_code)
1331 WHERE packet_id = l_tab_packet_id(i)
1332 AND bc_packet_id = p_bc_packet_id
1333 AND substr(nvl(result_code,'P'),1,1) <> 'F';
1334
1335 Exit when cur_pkts%NOTFOUND;
1336 commit;
1337 END LOOP;
1338 CLOSE cur_pkts;
1339 Else
1340
1341 OPEN cur_pkts;
1342 LOOP
1343 l_tab_packet_id.delete;
1344 l_tab_bc_packet_id.delete;
1345 FETCH cur_pkts BULK COLLECT INTO
1346 l_tab_packet_id,
1347 l_tab_bc_packet_id LIMIT 500;
1348 IF NOT l_tab_packet_id.EXISTS(1) then
1349 EXIT;
1350 END if;
1351 FORALL i IN l_tab_packet_id.first .. l_tab_packet_id.last
1352 UPDATE pa_bc_packets
1353 SET status_code = nvl(p_status_code,status_code),
1354 result_code = nvl(p_result_code ,result_code),
1355 res_result_code = nvl(p_res_result_code,res_result_code),
1356 res_grp_result_code = nvl(p_res_grp_result_code,res_grp_result_code),
1357 task_result_code = nvl(p_task_result_code,task_result_code),
1358 top_task_result_code = nvl(p_top_task_result_code,top_task_result_code),
1359 project_result_code = nvl(p_project_result_code,project_result_code),
1360 project_acct_result_code =nvl(p_proj_acct_result_code,project_acct_result_code)
1361 WHERE packet_id = l_tab_packet_id(i)
1362 AND substr(nvl(result_code,'P'),1,1) <> 'F';
1363 Exit when cur_pkts%NOTFOUND;
1364 commit;
1365 END LOOP;
1366 CLOSE cur_pkts;
1367 End if;
1368 IF cur_pkts%isopen then
1369 close cur_pkts;
1370 END IF;
1371 commit; -- to end an active autonmous transaction
1372 PA_DEBUG.reset_err_stack;
1373 return;
1374 EXCEPTION
1375 WHEN OTHERS THEN
1376 IF cur_pkts%isopen then
1377 close cur_pkts;
1378 END IF;
1379 RAISE;
1380
1381 END result_status_code_update;
1382
1383
1384 procedure log_message_imp(p_msg_token1 in varchar2 default null) is
1385 begin
1386
1387 --r_debug.r_msg(p_msg =>'LOG : '||p_msg_token1,p_packet_id => g_packet_id);
1388 --pa_fck_util.debug_msg_imp('LOG : '||p_msg_token1);
1389 return;
1390 End;
1391
1392 ----------------------------------------------------------------
1393 -- This api writes message to log file / buffer / dummy table
1394 -- and initalizes the final out NOCOPY params with values
1395 ----------------------------------------------------------------
1396 PROCEDURE log_message(
1397 p_stage IN VARCHAR2 default null,
1398 p_error_msg IN VARCHAR2 default null,
1399 p_return_status IN varchar2 default null,
1400 p_msg_token1 IN VARCHAR2 default null,
1401 p_msg_token2 IN VARCHAR2 default null ) IS
1402
1403 BEGIN
1404
1405 IF p_error_msg is NOT NULL then
1406 g_error_msg := p_error_msg;
1407 END IF;
1408 IF p_return_status is NOT null then
1409 g_return_status := p_return_status;
1410 End if;
1411
1412 /* write the debug log only if debug is enabled */
1413 IF g_debug_mode = 'Y' THEN
1414
1415 IF p_stage is NOT null then
1416 pa_debug.g_err_stage := 'Stage :'|| substr(p_stage,1,250);
1417 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1418 pa_debug.write('pa.plsql.PA_FUNDS_CONTROL_PKG','LOG: '||pa_debug.g_err_stage,3);
1419 g_error_stage := substr(p_stage,1,10);
1420 END IF;
1421
1422 IF p_error_msg is NOT NULL then
1423 pa_debug.g_err_stage := 'Error Msg :'||substr(p_error_msg,1,250);
1424 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1425 PA_DEBUG.write
1426 (x_Module => 'pa.plsql.PA_FUNDS_CONTROL_PKG'
1427 ,x_Msg => substr('LOG:'||p_error_msg,1,240)
1428 ,x_Log_Level => 3);
1429 g_error_msg := p_error_msg;
1430 END IF;
1431
1432 IF p_msg_token1 is NOT NULL or p_msg_token2 is NOT NULL then
1433 IF p_msg_token2 is not null then
1434 pa_debug.g_err_stage := substr(p_msg_token2,1,250);
1435 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1436 pa_debug.write('pa.plsql.PA_FUNDS_CONTROL_PKG','LOG: '||pa_debug.g_err_stage,3);
1437 END IF;
1438 IF p_msg_token1 is NOT NULL then
1439 pa_debug.g_err_stage := substr(p_msg_token1,1,250);
1440 pa_debug.write_file('LOG: '||pa_debug.g_err_stage);
1441 PA_DEBUG.write
1442 (x_Module => 'pa.plsql.PA_FUNDS_CONTROL_PKG'
1443 ,x_Msg => substr('LOG:'||p_msg_token1,1,240)
1444 ,x_Log_Level => 3);
1445
1446 END IF ;
1447 END IF;
1448
1449 END IF; -- end of g_debug_mode
1450 return;
1451
1452 END log_message;
1453
1454 /** Bug fix:2302945 check whether the project is installed in this OU
1455 ** This api checks the records in pa_implementaions for the given OU if
1456 ** no records exits , it assumes that project is not installed in this OU
1457 **/
1458 FUNCTION IS_PA_INSTALL_IN_OU RETURN VARCHAR2 is
1459
1460 l_return_var varchar2(10) := 'Y';
1461
1462 BEGIN
1463 IF g_debug_mode = 'Y' THEN
1464 log_message(p_msg_token1 => 'Inside IS_PA_INSTALL_IN_OU api');
1465 End If;
1466 SELECT 'Y'
1467 INTO l_return_var
1468 FROM pa_implementations;
1469 IF g_debug_mode = 'Y' THEN
1470 log_message(p_msg_token1 => 'End of IS_PA_INSTALL_IN_OU api return var:'||l_return_var);
1471 End If;
1472 Return l_return_var ;
1473
1474 EXCEPTION
1475 when NO_data_found then
1476 IF g_debug_mode = 'Y' THEN
1477 log_message(p_msg_token1 => 'End of IS_PA_INSTALL_IN_OU api return var:N');
1478 End If;
1479 return 'N';
1480 when Too_many_rows then
1481 return 'Y';
1482 When others then
1483 IF g_debug_mode = 'Y' THEN
1484 log_message(p_msg_token1 => 'Failed in IS_PA_INSTALL_IN_OU'||SQLERRM);
1485 End If;
1486 Raise;
1487
1488 END IS_PA_INSTALL_IN_OU;
1489
1490 -------------------------------------------------------------------------
1491 -- This api checks whether the Invoice is coming after the
1492 -- interface from projects if the invoice is already interfaced
1493 -- from projects then donot derive burden components
1494 -- if the invoice system_linkage function is 'VI' then
1495 -- derive budget ccid, encum type id, etc and DONOT do funds check
1496 -- mark the invoice as approved and donot create encum liqd
1497 -- if the invoice system linkage func is 'ER' then
1498 -- derive budget ccid, encum type id, etc and DONOT funds check
1499 -- mark the invoice as approved and create encum liqd for raw only
1500 -- NOTE : IF THE PROJECT IS BURDEN ON SAME EI THEN DO NOTHING
1501 -- ELSE DERIVE budget,encum type id,create encum liqd AND mark the
1502 -- invoice as approved
1503 -- R12 Note: This procedure is not longer used ... as the check for
1504 -- expense report is carried out upfront and also from r12 on
1505 -- VI txn. will no longer be interfaced back to AP ...
1506 -- Not removing procedure as it can be used (if reqd..)
1507 -------------------------------------------------------------------------
1508 PROCEDURE is_ap_from_project
1509 (p_packet_id IN NUMBER,
1510 p_calling_module IN VARCHAR2,
1511 x_return_status OUT NOCOPY VARCHAR2) IS
1512
1513 PRAGMA AUTONOMOUS_TRANSACTION;
1514
1515 --EXPLAIN PLAN IS:
1516 --1:SELECT STATEMENT :(cost=269,rows=2)
1517 --2:SORT UNIQUE :(cost=269,rows=2)
1518 --3:UNION-ALL :(cost=,rows=)
1519 --4:NESTED LOOPS :(cost=137,rows=1)
1520 --5:NESTED LOOPS :(cost=122,rows=1)
1521 --6:TABLE ACCESS BY INDEX ROWID PA_BC_PACKETS :(cost=120,rows=1)
1522 --7:INDEX RANGE SCAN PA_BC_PACKETS_U1 :(cost=5,rows=1)
1523 --6:TABLE ACCESS BY INDEX ROWID PA_EXPENDITURE_ITEMS_ALL :(cost=2,rows=2345)
1524 --7:INDEX RANGE SCAN PA_EXPENDITURE_ITEMS_N9 :(cost=1,rows=2345)
1525 --5:TABLE ACCESS BY INDEX ROWID PA_COST_DISTRIBUTION_LINES_ALL :(cost=15,rows=47647)
1526 --6:INDEX RANGE SCAN PA_COST_DISTRIBUTION_LINES_U1 :(cost=1,rows=47647)
1527 --4:NESTED LOOPS :(cost=128,rows=1)
1528 --5:NESTED LOOPS :(cost=121,rows=1)
1529 --6:TABLE ACCESS BY INDEX ROWID PA_BC_PACKETS :(cost=120,rows=1)
1530 --7:INDEX RANGE SCAN PA_BC_PACKETS_U1 :(cost=5,rows=1)
1531 --6:TABLE ACCESS BY INDEX ROWID AP_EXPENSE_REPORT_HEADERS_ALL :(cost=1,rows=290)
1532 --7:INDEX RANGE SCAN AP_EXPENSE_REPORT_HEADERS_N1 :(cost=,rows=290)
1533 --5:TABLE ACCESS FULL AP_EXPENSE_REPORT_LINES_ALL :(cost=7,rows=1260)
1534
1535 CURSOR invoice_cdls is
1536 SELECT pbc.bc_packet_id,
1537 pbc.project_id,
1538 nvl(exp.system_linkage_function,'VI') system_linkage_function,
1539 pbc.burden_method_code
1540 FROM pa_bc_packets pbc
1541 ,pa_cost_distribution_lines_all cdl
1542 ,pa_expenditure_items_all exp
1543 WHERE pbc.packet_id = p_packet_id
1544 AND pbc.document_header_id = cdl.system_reference2
1545 AND pbc.document_distribution_id = cdl.system_reference3
1546 AND pbc.document_type = 'AP'
1547 AND cdl.line_type = 'R'
1548 AND cdl.expenditure_item_id = exp.expenditure_item_id
1549 AND pbc.task_id = exp.task_id -- added to use index N9
1550 AND pbc.expenditure_item_date = exp.expenditure_item_date --added to use index N9
1551 AND exp.system_linkage_function in ('VI','ER')
1552 UNION
1553 SELECT pbc.bc_packet_id,
1554 pbc.project_id,
1555 'ER' system_linkage_function,
1556 pbc.burden_method_code
1557 FROM pa_bc_packets pbc
1558 ,ap_expense_report_headers_all exphead
1559 ,ap_expense_report_lines_all expline
1560 WHERE pbc.packet_id = p_packet_id
1561 AND pbc.document_header_id = exphead.vouchno
1562 AND pbc.set_of_books_id = exphead.set_of_books_id
1563 AND exphead.report_header_id = expline.report_header_id /* added for bug#2634995 */
1564 AND pbc.document_distribution_id = expline.distribution_line_number
1565 AND pbc.document_type = 'AP'
1566 AND pbc.project_id = expline.project_id
1567 AND pbc.task_id = expline.task_id
1568 AND pbc.expenditure_type = expline.expenditure_type
1569 AND pbc.set_of_books_id = expline.set_of_books_id;
1570
1571 l_num_rows NUMBER := 100;
1572 l_pre_project_id NUMBER := NULL;
1573 l_burden_method VARCHAR2(50);
1574 l_pre_burden_method varchar2(50);
1575
1576 BEGIN
1577 IF g_debug_mode = 'Y' THEN
1578 log_message(p_msg_token1 => 'Inside the is_ap_from project api');
1579 End If;
1580
1581 --Initialize the error stack
1582 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.is_ap_from_project');
1583
1584 x_return_status := 'S';
1585
1586 IF p_calling_module = 'GL' then
1587 OPEN invoice_cdls;
1588 LOOP
1589 --Initialize the plsql tables
1590 Init_plsql_tabs;
1591
1592 FETCH invoice_cdls BULK COLLECT INTO
1593 g_tab_bc_packet_id,
1594 g_tab_project_id,
1595 g_tab_sys_link_func,
1596 g_tab_burden_method_code LIMIT l_num_rows;
1597
1598 If NOT g_tab_bc_packet_id.EXISTS(1) then
1599 IF g_debug_mode = 'Y' THEN
1600 log_message(p_msg_token1 => 'this Invoice is Not interfaced from Project');
1601 End If;
1602 EXIT;
1603 else
1604 IF g_debug_mode = 'Y' THEN
1605 log_message(p_msg_token1 => 'this Invoice is interfaced from projects');
1606 End If;
1607 null;
1608 End if;
1609 FOR i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST LOOP
1610
1611 IF g_tab_bc_packet_id(i) is NOT NULL then
1612
1613 If g_tab_burden_method_code(i) is NULL then
1614
1615 IF g_tab_project_id(i) <> l_pre_project_id
1616 or l_pre_project_id is NULL then
1617
1618 l_burden_method :=check_bdn_on_sep_item (g_tab_project_id(i));
1619 l_pre_burden_method := l_burden_method;
1620 Else
1621 l_burden_method := l_pre_burden_method;
1622 End if;
1623
1624 Else
1625 l_burden_method := g_tab_burden_method_code(i);
1626 l_pre_burden_method := l_burden_method;
1627
1628 End If; -- If g_tab_burden_method_code(i) is NULL then
1629
1630 IF g_debug_mode = 'Y' THEN
1631 log_message(p_msg_token1 => 'burden method ['||l_burden_method||
1632 ']g_tab_sys_link_func['||g_tab_sys_link_func(i)||']' );
1633 End If;
1634
1635
1636 IF g_tab_sys_link_func(i) = 'VI' then
1637 --If l_burden_method = 'SAME' then
1638 If l_burden_method = 'S' then
1639 g_tab_status_code(i) := 'V';
1640 Else
1641 g_tab_status_code(i) := 'L';
1642 End if;
1643 g_tab_result_code(i) := 'P114';
1644 g_tab_r_result_code(i) := 'P114';
1645 g_tab_rg_result_code(i) := 'P114';
1646 g_tab_t_result_code(i) := 'P114';
1647 g_tab_tt_result_code(i) := 'P114';
1648 g_tab_p_result_code(i) := 'P114';
1649 g_tab_p_acct_result_code(i) := 'P114';
1650 Elsif g_tab_sys_link_func(i) = 'ER' then
1651 --If l_burden_method = 'SAME' then
1652 If l_burden_method = 'S' then
1653 g_tab_status_code(i) := 'V';
1654 Else
1655 g_tab_status_code(i) := 'L';
1656 End if;
1657 g_tab_result_code(i) := 'P115';
1658 g_tab_r_result_code(i) := 'P115';
1659 g_tab_rg_result_code(i) := 'P115';
1660 g_tab_t_result_code(i) := 'P115';
1661 g_tab_tt_result_code(i) := 'P115';
1662 g_tab_p_result_code(i) := 'P115';
1663 g_tab_p_acct_result_code(i) := 'P115';
1664 End if;
1665 l_pre_project_id := g_tab_project_id(i);
1666 End if;
1667 END LOOP;
1668
1669 --update the result and status code in pa bc packets
1670 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
1671 UPDATE pa_bc_packets
1672 SET status_code = g_tab_status_code(i),
1673 result_code = g_tab_result_code(i),
1674 res_result_code = g_tab_r_result_code(i),
1675 res_grp_result_code = g_tab_rg_result_code(i),
1676 task_result_code = g_tab_t_result_code(i),
1677 top_task_result_code = g_tab_tt_result_code(i),
1678 project_result_code = g_tab_p_result_code(i),
1679 project_acct_result_code = g_tab_p_acct_result_code(i)
1680 WHERE bc_packet_id = g_tab_bc_packet_id(i)
1681 AND packet_id = p_packet_id;
1682 EXIT WHEN invoice_cdls%NOTFOUND;
1683 END LOOP;
1684 CLOSE invoice_cdls;
1685
1686 End IF;
1687 IF g_debug_mode = 'Y' THEN
1688 log_message(p_msg_token1 => 'End of is_ap_from_project api');
1689 End If;
1690 PA_DEBUG.reset_err_stack;
1691 commit; -- to end an active autonmous transaction
1692 return;
1693
1694 EXCEPTION
1695 when others then
1696 x_return_status := 'T';
1697 IF g_debug_mode = 'Y' THEN
1698 log_message(p_msg_token1 => 'failed in is_ap_from_project api SQLERR ['||sqlcode||sqlerrm||']');
1699 End If;
1700 --commit;
1701
1702 --Raise;
1703 END is_ap_from_project;
1704
1705
1706 --------------------------------------------------------------------------------------------------------
1707 --Procedure to be called inside check_funds_available to generate result code and status for each record.
1708 -------------------------------------------------------------------------------------------------------
1709 PROCEDURE generate_result_code(
1710 p_fclevel_code IN VARCHAR2 DEFAULT 'B',
1711 p_available_amt IN NUMBER DEFAULT 0,
1712 p_stage IN VARCHAR2 DEFAULT 0,
1713 p_budget_posted_amt IN NUMBER DEFAULT 0,
1714 x_result_code IN OUT NOCOPY VARCHAR2,
1715 x_r_result_code IN OUT NOCOPY VARCHAR2,
1716 x_rg_result_code IN OUT NOCOPY VARCHAR2,
1717 x_t_result_code IN OUT NOCOPY VARCHAR2,
1718 x_tt_result_code IN OUT NOCOPY VARCHAR2,
1719 x_p_result_code IN OUT NOCOPY VARCHAR2,
1720 x_p_acct_result_code IN OUT NOCOPY VARCHAR2,
1721 x_return_status IN OUT NOCOPY VARCHAR2
1722 ) IS
1723 BEGIN
1724 IF g_debug_mode = 'Y' THEN
1725 log_message(p_msg_token1 => 'p_fclevel_code ['||p_fclevel_code||']p_available_amt['||p_available_amt||
1726 ']p_stage ['||p_stage||']p_budget_posted_amt ['||p_budget_posted_amt||']' );
1727 End If;
1728
1729 -- p_stage
1730 -- 100 Resource Level
1731 -- 200 Resource Group Level
1732 -- 300 Task Level
1733 -- 400 Top Task Level
1734 -- 500 Project Level
1735 -- 600 Project Account Level
1736 /*** Bug Fix :1892535 if the budget amount is zero and
1737 * available amount(transaction amount) is zero then transaction should pass
1738 * funds check
1739 * Example budget for project p1 = 500 task t1 = 500 resource r1 = 0 for period jan-01
1740 * Transactions project task resource period acct_dr acct_cr
1741 * 1 p1 t1 r1 jan-01 - 1000
1742 * 2 p1 t1 r1 jan-01 1000 -
1743 * ideally the net effect of the both transactions are zero so they must pass
1744 * funds check
1745
1746 IF NVL ( p_budget_posted_amt, 0 ) = 0
1747 AND NVL ( p_available_amt, 0 ) = 0
1748 AND p_fclevel_code = 'B' THEN
1749
1750 IF p_stage = 100 THEN
1751 -- msg : F101 = No budget at resource level
1752 x_result_code := 'F101';
1753 x_r_result_code := 'F101';
1754 x_rg_result_code := 'F101';
1755 x_t_result_code := 'F101';
1756 x_tt_result_code := 'F101';
1757 x_p_result_code := 'F101';
1758 x_p_acct_result_code := 'F101';
1759 ELSIF p_stage = 200 THEN
1760 -- msg : F102 = No budget at resource Group level
1761 x_result_code := 'F102';
1762 x_rg_result_code := 'F102';
1763 x_t_result_code := 'F102';
1764 x_tt_result_code := 'F102';
1765 x_p_result_code := 'F102';
1766 x_p_acct_result_code := 'F102';
1767 ELSIF p_stage = 300 THEN
1768 -- msg : F103 = No budget at task level
1769 x_result_code := 'F103';
1770 x_t_result_code := 'F103';
1771 x_tt_result_code := 'F103';
1772 x_p_result_code := 'F103';
1773 x_p_acct_result_code := 'F103';
1774 ELSIF p_stage = 400 THEN
1775 -- msg : F104 = No budget at top task level
1776 x_result_code := 'F104';
1777 x_tt_result_code := 'F104';
1778 x_p_result_code := 'F104';
1779 x_p_acct_result_code := 'F104';
1780 ELSIF p_stage = 500 THEN
1781 -- msg : F105 = No budget at Project level
1782 x_result_code := 'F105';
1783 x_p_result_code := 'F105';
1784 x_p_acct_result_code := 'F105';
1785 ELSIF p_stage = 600 THEN
1786 -- msg : F106 = No budget at project acct level
1787 x_result_code := 'F106';
1788 x_p_acct_result_code := 'F106';
1789
1790 END IF;
1791 x_return_status := 'F';
1792 RETURN;
1793 END IF;
1794
1795 ********end of bug fix:1892535 ***/
1796
1797 -- check if the funds control level code is none then
1798 -- pass the transaction
1799 IF p_fclevel_code = 'N' THEN
1800
1801 IF p_stage = 100 THEN
1802 x_result_code := 'P111';
1803 x_r_result_code := 'P111';
1804 ELSIF p_stage = 200 THEN
1805 x_result_code := 'P109';
1806 x_rg_result_code := 'P109';
1807 ELSIF p_stage = 300 THEN
1808 x_result_code := 'P107';
1809 x_t_result_code := 'P107';
1810 ELSIF p_stage = 400 THEN
1811 x_result_code := 'P105';
1812 x_tt_result_code := 'P105';
1813 ELSIF p_stage = 500 THEN
1814 x_result_code := 'P103';
1815 x_p_result_code := 'P103';
1816 ELSIF p_stage = 600 THEN
1817 x_result_code := 'P101';
1818 x_p_acct_result_code := 'P101';
1819 END IF;
1820
1821 x_return_status := 'P';
1822 END IF;
1823
1824 -- check if teh funds control level code is Absolute or Advisory
1825 -- if absolute then check whether the funds avaiabl with in the limit
1826 -- if so pass the transaction otherwise fail the transaction
1827 -- if the control level code is advisory then pass the transaction with
1828 -- warning if exceeds the available amount
1829 /** Bug fix : 1975786 p_fclevel_code D - advisory is changed to A
1830 * since the lookup code is changed from D - A
1831 * initial lookup codes B - Absolute, D - Advisory N - None
1832 * changed lookup codes B - Absolute, A - Advisory N - None
1833 **/
1834 IF p_fclevel_code IN ( 'B', 'A' ) and p_available_amt >= 0 then
1835 IF p_stage = 100 THEN
1836 x_result_code := 'P111';
1837 x_r_result_code := 'P111';
1838 ELSIF p_stage = 200 THEN
1839 x_result_code := 'P109';
1840 x_rg_result_code := 'P109';
1841 ELSIF p_stage = 300 THEN
1842 x_result_code := 'P107';
1843 x_t_result_code := 'P107';
1844 ELSIF p_stage = 400 THEN
1845 x_result_code := 'P105';
1846 x_tt_result_code := 'P105';
1847 ELSIF p_stage = 500 THEN
1848 x_result_code := 'P103';
1849 x_p_result_code := 'P103';
1850 ELSIF p_stage = 600 THEN
1851 x_result_code := 'P101';
1852 x_p_acct_result_code := 'P101';
1853 END IF;
1854
1855 x_return_status := 'P';
1856
1857 ELSIF p_fclevel_code = 'A' and p_available_amt < 0 then
1858 IF p_stage = 100 THEN
1859 x_result_code := 'P112';
1860 x_r_result_code := 'P112';
1861 ELSIF p_stage = 200 THEN
1862 x_result_code := 'P110';
1863 x_rg_result_code := 'P110';
1864 ELSIF p_stage = 300 THEN
1865 x_result_code := 'P108';
1866 x_t_result_code := 'P108';
1867 ELSIF p_stage = 400 THEN
1868 x_result_code := 'P106';
1869 x_tt_result_code := 'P106';
1870 ELSIF p_stage = 500 THEN
1871 x_result_code := 'P104';
1872 x_p_result_code := 'P104';
1873 ELSIF p_stage = 600 THEN
1874 x_result_code := 'P102';
1875 x_p_acct_result_code := 'P102';
1876 END IF;
1877
1878 x_return_status := 'P';
1879
1880 ELSIF p_fclevel_code = 'B' AND p_available_amt < 0 then
1881 /** Bug :1969608 fix added If conditions, if the budget amount is zero
1882 * to display the proper error message
1883 **/
1884 IF p_stage = 100 THEN
1885
1886 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1887 -- msg : F101 = No budget at resource level
1888 x_result_code := 'F101';
1889 x_r_result_code := 'F101';
1890 x_rg_result_code := 'F101';
1891 x_t_result_code := 'F101';
1892 x_tt_result_code := 'F101';
1893 x_p_result_code := 'F101';
1894 x_p_acct_result_code := 'F101';
1895
1896 Else
1897 -- msg : F108 Failed at resource level
1898 x_result_code := 'F108';
1899 x_r_result_code := 'F108';
1900 x_rg_result_code := 'F108';
1901 x_t_result_code := 'F108';
1902 x_tt_result_code := 'F108';
1903 x_p_result_code := 'F108';
1904 x_p_acct_result_code := 'F108';
1905 End if;
1906 ELSIF p_stage = 200 THEN
1907
1908 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1909 -- msg : F102 = No budget at resource Group level
1910 x_result_code := 'F102';
1911 x_rg_result_code := 'F102';
1912 x_t_result_code := 'F102';
1913 x_tt_result_code := 'F102';
1914 x_p_result_code := 'F102';
1915 x_p_acct_result_code := 'F102';
1916
1917 Else
1918 -- msg : F109 Failed at resource group level
1919 x_result_code := 'F109';
1920 x_rg_result_code := 'F109';
1921 x_t_result_code := 'F109';
1922 x_tt_result_code := 'F109';
1923 x_p_result_code := 'F109';
1924 x_p_acct_result_code := 'F109';
1925 End if;
1926 ELSIF p_stage = 300 THEN
1927
1928 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1929 -- msg : F103 = No budget at task level
1930 x_result_code := 'F103';
1931 x_t_result_code := 'F103';
1932 x_tt_result_code := 'F103';
1933 x_p_result_code := 'F103';
1934 x_p_acct_result_code := 'F103';
1935
1936 Else
1937 -- msg : F110 failed at task level
1938 x_result_code := 'F110';
1939 x_t_result_code := 'F110';
1940 x_tt_result_code := 'F110';
1941 x_p_result_code := 'F110';
1942 x_p_acct_result_code := 'F110';
1943 End if;
1944 ELSIF p_stage = 400 THEN
1945
1946 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1947
1948 -- msg : F104 = No budget at top task level
1949 x_result_code := 'F104';
1950 x_tt_result_code := 'F104';
1951 x_p_result_code := 'F104';
1952 x_p_acct_result_code := 'F104';
1953
1954 Else
1955 -- msg : F111 Failed at top task level
1956 x_result_code := 'F111';
1957 x_tt_result_code := 'F111';
1958 x_p_result_code := 'F111';
1959 x_p_acct_result_code := 'F111';
1960 End if;
1961 ELSIF p_stage = 500 THEN
1962
1963 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1964 -- msg : F105 = No budget at Project level
1965 x_result_code := 'F105';
1966 x_p_result_code := 'F105';
1967 x_p_acct_result_code := 'F105';
1968
1969 Else
1970 -- msg : F112 Failed at the project level
1971 x_result_code := 'F112';
1972 x_p_result_code := 'F112';
1973 x_p_acct_result_code := 'F112';
1974 End if;
1975 ELSIF p_stage = 600 THEN
1976
1977 If NVL ( p_budget_posted_amt, 0 ) = 0 then
1978 -- msg : F106 = No budget at project acct level
1979 x_result_code := 'F106';
1980 x_p_acct_result_code := 'F106';
1981
1982 Else
1983 -- msg : F113 failed at the project acct level
1984 x_result_code := 'F113';
1985 x_p_acct_result_code := 'F113';
1986 End if;
1987 END IF;
1988
1989 x_return_status := 'F';
1990 END IF;
1991 IF g_debug_mode = 'Y' THEN
1992 log_message(p_msg_token1 => 'x_result_code ='||x_result_code||']x_r_result_code['||x_r_result_code||
1993 ']x_rg_result_code ['||x_rg_result_code||']x_t_result_code ['||x_t_result_code||
1994 ']x_tt_result_code ['||x_tt_result_code||']x_p_result_code ['||x_p_result_code||
1995 ']x_p_acct_rresult_code ['||x_p_acct_result_code||']' );
1996 End If;
1997
1998
1999 EXCEPTION
2000 WHEN OTHERS THEN
2001 IF g_debug_mode = 'Y' THEN
2002 log_message(p_msg_token1 => 'failed in generate result code api SQLERR :'||sqlcode||sqlerrm);
2003 End If;
2004 --commit;
2005 RAISE;
2006 END generate_result_code;
2007 ----------------------------------------------------------------------------------------
2008 -- This Api caches the pa bc packets amounts based on the
2009 -- same resource resource grp , project , task etc,
2010 -----------------------------------------------------------------------------------------
2011 PROCEDURE CACHE_PKT_AMOUNTS(
2012 p_project_id in pa_bc_packets.project_id%type
2013 ,p_bdgt_version in pa_bc_packets.budget_version_id%type
2014 ,p_top_task_id in pa_bc_packets.top_task_id%type
2015 ,p_task_id in pa_bc_packets.task_id%type
2016 ,p_bud_task_id in pa_bc_packets.bud_task_id%type
2017 ,p_start_date in DATE
2018 ,p_end_date in DATE
2019 ,p_rlmi in pa_bc_packets.resource_list_member_id%type
2020 ,p_bud_rlmi in pa_bc_packets.bud_resource_list_member_id%type
2021 ,p_prlmi in pa_bc_packets.parent_resource_id%type
2022 ,p_bdgt_ccid in pa_bc_packets.budget_ccid%type
2023 ,p_accounted_dr in number
2024 ,p_accounted_cr in number
2025 ,p_calling_module in varchar2
2026 ,p_partial_flag in varchar2
2027 ,p_function in varchar2 -- add or deduct amts from cache
2028 ,p_bc_packet_id in number
2029 ,p_doc_type in varchar2
2030 ,p_doc_header_id in number
2031 ,p_doc_distribution_id in number
2032 ,x_cached_status out NOCOPY varchar2
2033 ,x_result_code in out NOCOPY varchar2
2034 ,p_counter in number
2035 ) IS
2036 l_res_level_cache VARCHAR2(100);
2037 l_res_grp_level_cache VARCHAR2(100);
2038 l_task_level_cache VARCHAR2(100);
2039 l_top_task_level_cache VARCHAR2(100);
2040 l_proj_level_cache VARCHAR2(100);
2041 l_proj_acct_level_cache VARCHAR2(100);
2042 l_res_level_count NUMBER;
2043 l_res_grp_level_count NUMBER;
2044 l_task_level_count NUMBER;
2045 l_top_task_level_count NUMBER;
2046 l_proj_level_count NUMBER;
2047 l_proj_acct_level_count NUMBER;
2048 l_new_resource VARCHAR2(1);
2049 l_new_resource_group VARCHAR2(1);
2050 l_new_task VARCHAR2(1);
2051 l_new_top_task VARCHAR2(1);
2052 l_new_proj VARCHAR2(1);
2053 l_new_proj_acct VARCHAR2(1);
2054 l_cache_amt_minus number;
2055 l_result_code VARCHAR2(100);
2056 l_res_level_cache_minus VARCHAR2(100);
2057 l_rg_level_cache_minus VARCHAR2(100);
2058 l_task_level_cache_minus VARCHAR2(100);
2059 l_tt_level_cache_minus VARCHAR2(100);
2060 l_proj_level_cache_minus VARCHAR2(100);
2061 l_p_acct_level_cache_minus VARCHAR2(100);
2062 l_number number;
2063 BEGIN
2064
2065 IF p_partial_flag = 'Y' then
2066 IF g_debug_mode = 'Y' THEN
2067 log_message(p_msg_token1 => 'assiging the amts to cache');
2068 End If;
2069
2070 -- Resource level cache
2071 l_res_level_cache := p_project_id||p_bdgt_version||p_bud_task_id||p_prlmi||
2072 p_rlmi||trunc(p_start_date)||trunc(p_end_date);
2073 l_res_level_count := nvl(g_tab_res_level_cache.count,0);
2074
2075 -- Resource Group level cache
2076 l_res_grp_level_cache := p_project_id||p_bdgt_version||p_bud_task_id||p_prlmi||
2077 trunc(p_start_date)||trunc(p_end_date);
2078 l_res_grp_level_count := nvl(g_tab_res_grp_level_cache.count,0);
2079
2080 -- Task level cache
2081 l_task_level_cache := p_project_id||p_bdgt_version||p_top_task_id||p_task_id||
2082 trunc(p_start_date)||trunc(p_end_date);
2083 l_task_level_count := nvl(g_tab_task_level_cache.count,0);
2084
2085 -- Top level cache
2086 l_top_task_level_cache := p_project_id||p_bdgt_version||p_top_task_id||
2087 trunc(p_start_date)||trunc(p_end_date);
2088 l_top_task_level_count := nvl(g_tab_top_task_level_cache.count,0);
2089
2090 -- Project level cache
2091 l_proj_level_cache := p_project_id||p_bdgt_version||trunc(p_start_date)||trunc(p_end_date);
2092 l_proj_level_count := nvl(g_tab_proj_level_cache.count,0);
2093
2094 --project account level cache
2095 l_proj_acct_level_cache := p_project_id||p_bdgt_version||p_bdgt_ccid||
2096 trunc(p_start_date)||trunc(p_end_date);
2097 l_proj_acct_level_count := nvl(g_tab_proj_acct_level_cache.count,0);
2098 IF g_debug_mode = 'Y' THEN
2099 log_message(p_msg_token1 => 'end of assiging the amts to cache');
2100 End If;
2101
2102 End if;
2103
2104 -- check if the same header_id is already failed then donot cache and donot
2105 -- funds check just update the status and result code to failed
2106 IF p_function = 'ADD' then
2107 IF g_debug_mode = 'Y' THEN
2108 log_message(p_msg_token1 => 'inside ADD function');
2109 End If;
2110 x_result_code := null;
2111 x_cached_status := 'Y';
2112 --IF g_tab_doc_header_id.count > 0 then
2113 IF nvl(p_counter,0) > 1 then
2114 --FOR i in 1 .. g_tab_doc_header_id.count LOOP
2115 FOR i in 1 .. p_counter -1 LOOP
2116 /* FOR DISTERADJ and CBC process check at document header level
2117 * even if single transaction found error then
2118 * mark the current transaction as failed
2119 * FOR GL,BASELINE process check at the document distribution
2120 * level
2121 */
2122 IF (p_doc_header_id = g_tab_doc_header_id(i) and
2123 p_doc_type = g_tab_doc_type(i) and
2124 p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
2125 ,'TRXIMPORT','RESERVE_BASELINE') and
2126 p_bc_packet_id <> g_tab_bc_packet_id(i) )
2127 OR
2128 (p_doc_header_id = g_tab_doc_header_id(i) and
2129 p_doc_type = g_tab_doc_type(i) and
2130 p_doc_distribution_id = g_tab_doc_distribution_id(i) and
2131 p_calling_module IN ('GL') and
2132 p_bc_packet_id <> g_tab_bc_packet_id(i) ) Then
2133
2134 If substr(g_tab_result_code(i),1,1) = 'F' then
2135 x_result_code := g_tab_result_code(i);
2136 IF g_debug_mode = 'Y' THEN
2137 log_message(p_msg_token1 => 'failed documnet header found');
2138 End If;
2139 End If;
2140 End if;
2141 END LOOP;
2142 End if;
2143 IF g_debug_mode = 'Y' THEN
2144 log_message(p_msg_token1 => 'end of ADD function');
2145 End If;
2146 If substr(x_result_code,1,1) = 'F' then
2147 x_cached_status := 'N';
2148 return;
2149 End if;
2150 End if;
2151
2152
2153 IF p_function = 'MINUS' then
2154 IF g_debug_mode = 'Y' THEN
2155 log_message(p_msg_token1 => 'Inside MINUS if condition');
2156 End If;
2157
2158 IF p_partial_flag <> 'Y' then
2159 g_r_pkt_amt := NVL(g_r_pkt_amt,0)
2160 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2161 g_rg_pkt_amt := NVL(g_rg_pkt_amt,0)
2162 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2163 g_t_pkt_amt := NVL(g_t_pkt_amt,0)
2164 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2165 g_tt_pkt_amt := NVL(g_tt_pkt_amt,0)
2166 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2167 g_p_pkt_amt := NVL(g_p_pkt_amt,0)
2168 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2169 g_p_acct_pkt_amt := NVL(g_p_acct_pkt_amt,0)
2170 - (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2171
2172 END IF;
2173
2174 IF p_partial_flag = 'Y' then
2175 -- check if the same header id is already passed but this raw / burden line fails
2176 -- then deduct that amount from the passed line and synchonize the status and result
2177 -- codes for minus
2178 l_result_code := x_result_code;
2179 l_cache_amt_minus := 0;
2180 IF g_debug_mode = 'Y' THEN
2181 log_message(p_msg_token1 => 'check g_tab_doc_header_id.count ');
2182 End If;
2183 --IF g_tab_doc_header_id.count > 0 then
2184 IF nvl(p_counter,0) > 1 then
2185 IF g_debug_mode = 'Y' THEN
2186 log_message(p_msg_token1 => 'opening cursor num = '||g_tab_doc_header_id.count );
2187 End If;
2188 FOR i in 1 .. p_counter - 1 LOOP
2189 If (p_doc_header_id = g_tab_doc_header_id(i) and
2190 p_doc_type = g_tab_doc_type(i) and
2191 p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
2192 ,'TRXIMPORT','RESERVE_BASELINE') and
2193 p_bc_packet_id <> g_tab_bc_packet_id(i) )
2194 OR
2195 (p_doc_header_id = g_tab_doc_header_id(i) and
2196 p_doc_type = g_tab_doc_type(i) and
2197 p_doc_distribution_id = g_tab_doc_distribution_id(i) and
2198 p_calling_module IN ('GL') and
2199 p_bc_packet_id <> g_tab_bc_packet_id(i) ) then
2200
2201 If substr(g_tab_result_code(i),1,2) = 'P1'
2202 and g_tab_start_date.EXISTS(i) and g_tab_end_date.EXISTS(i) then
2203
2204 l_cache_amt_minus := nvl(g_tab_accounted_dr(i),0)
2205 - nvl(g_tab_accounted_cr(i),0);
2206 IF g_debug_mode = 'Y' THEN
2207 log_message(p_msg_token1 => 'l_res_level_cache_minus, bc_packet_id ['
2208 ||p_bc_packet_id||']g_tab_proj count['||
2209 g_tab_project_id(i)||']');
2210 End IF;
2211
2212 l_res_level_cache_minus :=
2213 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_bud_task_id(i)
2214 ||g_tab_p_resource_id(i)||g_tab_rlmi(i)||trunc(g_tab_start_date(i))||
2215 trunc(g_tab_end_date(i));
2216 IF g_debug_mode = 'Y' THEN
2217 log_message(p_msg_token1 => 'l_rg_level_cache_minus');
2218 End If;
2219
2220 l_rg_level_cache_minus :=
2221 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_bud_task_id(i)
2222 ||g_tab_p_resource_id(i)||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2223 IF g_debug_mode = 'Y' THEN
2224 log_message(p_msg_token1 => 'l_task_level_cache_minus');
2225 End If;
2226 l_task_level_cache_minus :=
2227 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_tt_task_id(i)
2228 ||g_tab_task_id(i)||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2229
2230 IF g_debug_mode = 'Y' THEN
2231 log_message(p_msg_token1 =>'l_tt_level_cache_minus');
2232 End If;
2233 l_tt_level_cache_minus :=
2234 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_tt_task_id(i)
2235 ||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2236 IF g_debug_mode = 'Y' THEN
2237 log_message(p_msg_token1 =>'l_proj_level_cache_minus');
2238 End If;
2239
2240 l_proj_level_cache_minus :=
2241 g_tab_project_id(i)||g_tab_budget_version_id(i)
2242 ||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2243 IF g_debug_mode = 'Y' THEN
2244 log_message(p_msg_token1 =>'l_p_acct_level_cache_minus');
2245 End if;
2246
2247 l_p_acct_level_cache_minus :=
2248 g_tab_project_id(i)||g_tab_budget_version_id(i)||g_tab_budget_ccid(i)
2249 ||trunc(g_tab_start_date(i))||trunc(g_tab_end_date(i));
2250
2251 -- Resource level
2252 IF g_debug_mode = 'Y' THEN
2253 log_message(p_msg_token1 =>'check l_res_level_count > 0');
2254 End If;
2255 IF l_res_level_count > 0 then
2256 IF g_debug_mode = 'Y' THEN
2257 log_message(p_msg_token1 =>'count = '||l_res_level_count);
2258 End if;
2259 FOR j IN 1 .. l_res_level_count LOOP
2260 IF g_debug_mode = 'Y' THEN
2261 log_message(p_msg_token1 => 'Iside for loop Resource level ');
2262 End IF;
2263 If g_tab_res_level_cache(j) = l_res_level_cache_minus then
2264 IF g_debug_mode = 'Y' THEN
2265 log_message(p_msg_token1 =>'minus cache found');
2266 End If;
2267 g_tab_res_level_cache_amt(j) :=
2268 NVL(g_tab_res_level_cache_amt(j),0) -
2269 nvl(l_cache_amt_minus,0);
2270 EXIT;
2271 END IF;
2272 END LOOP;
2273 End if;
2274
2275 -- Resource Group level
2276 IF l_res_grp_level_count > 0 then
2277 FOR j IN 1 .. l_res_grp_level_count LOOP
2278 IF g_debug_mode = 'Y' THEN
2279 log_message(p_msg_token1 => 'Inside for loop Resource Group level');
2280 End If;
2281 If g_tab_res_grp_level_cache(j) = l_rg_level_cache_minus then
2282 IF g_debug_mode = 'Y' THEN
2283 log_message(p_msg_token1 =>'minus cahce found at res grp');
2284 End If;
2285 g_tab_res_grp_level_cache_amt(j) :=
2286 NVL(g_tab_res_grp_level_cache_amt(j),0) -
2287 nvl(l_cache_amt_minus,0);
2288 EXIT;
2289 END IF;
2290 END LOOP;
2291 End if;
2292 -- Task level
2293 IF l_task_level_count > 0 then
2294 FOR j IN 1 .. l_task_level_count LOOP
2295 IF g_debug_mode = 'Y' THEN
2296 log_message(p_msg_token1 => 'Inside for loop minus Task level');
2297 End IF;
2298 If g_tab_task_level_cache(j) = l_task_level_cache_minus then
2299 IF g_debug_mode = 'Y' THEN
2300 log_message(p_msg_token1 =>'minus cahce found at task level');
2301 End If;
2302 g_tab_task_level_cache_amt(j) :=
2303 NVL(g_tab_task_level_cache_amt(j),0) -
2304 nvl(l_cache_amt_minus,0);
2305 EXIT;
2306 END IF;
2307 END LOOP;
2308 End if;
2309
2310 -- Top task level
2311 IF l_top_task_level_count > 0 then
2312 FOR j IN 1 .. l_top_task_level_count LOOP
2313 IF g_debug_mode = 'Y' THEN
2314 log_message(p_msg_token1 => 'Inside for loop minus Top task level');
2315 End If;
2316 If g_tab_top_task_level_cache(j) = l_tt_level_cache_minus then
2317 IF g_debug_mode = 'Y' THEN
2318 log_message(p_msg_token1 =>'minus cahce found at tt');
2319 End If;
2320 g_tab_top_task_level_cache_amt(j) :=
2321 NVL(g_tab_top_task_level_cache_amt(j),0) -
2322 nvl(l_cache_amt_minus,0);
2323 EXIT;
2324 END IF;
2325 END LOOP;
2326 End if;
2327 -- Project level
2328 IF l_proj_level_count > 0 then
2329 FOR j IN 1 .. l_proj_level_count LOOP
2330 IF g_debug_mode = 'Y' THEN
2331 log_message(p_msg_token1 => 'Inside for loop at Project level');
2332 End If;
2333 If g_tab_proj_level_cache(j) = l_proj_level_cache_minus then
2334 IF g_debug_mode = 'Y' THEN
2335 log_message(p_msg_token1 =>'minus cahce found at proj');
2336 End If;
2337 g_tab_proj_level_cache_amt(j) :=
2338 NVL(g_tab_proj_level_cache_amt(j),0) -
2339 nvl(l_cache_amt_minus,0);
2340 EXIT;
2341 END IF;
2342 END LOOP;
2343 End if;
2344 -- Project account level
2345 IF l_proj_acct_level_count > 0 then
2346 FOR j IN 1 .. l_proj_acct_level_count LOOP
2347 IF g_debug_mode = 'Y' THEN
2348 log_message(p_msg_token1 => 'inside for loop minus Project account level');
2349 End If;
2350 If g_tab_proj_acct_level_cache(j) = l_p_acct_level_cache_minus then
2351 IF g_debug_mode = 'Y' THEN
2352 log_message(p_msg_token1 =>'minus cahce found at p acct');
2353 End if;
2354 g_tab_prj_acct_level_cache_amt(j) :=
2355 NVL(g_tab_prj_acct_level_cache_amt(j),0) -
2356 nvl(l_cache_amt_minus,0);
2357 EXIT;
2358 END IF;
2359 END LOOP;
2360 End if;
2361 IF g_debug_mode = 'Y' THEN
2362 log_message(p_msg_token1 => 'passed documnet header found['||l_result_code||']' );
2363 End IF;
2364 g_tab_result_code(i) := l_result_code ;
2365 End If;
2366 End if;
2367 END LOOP;
2368 End if;
2369
2370 ---Deduct the amount from present failed document
2371 -- Resource level
2372 IF l_res_level_count > 0 then
2373 FOR I IN 1 .. l_res_level_count LOOP
2374 IF g_debug_mode = 'Y' THEN
2375 log_message(p_msg_token1 => 'Iside for loop Resource level');
2376 End If;
2377 If g_tab_res_level_cache(I) = l_res_level_cache then
2378 IF g_debug_mode = 'Y' THEN
2379 log_message(p_msg_token1 =>'same cahce found');
2380 End If;
2381 g_tab_res_level_cache_amt(I) :=
2382 NVL(g_tab_res_level_cache_amt(I),0) -
2383 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2384
2385 g_r_pkt_amt := g_tab_res_level_cache_amt(I);
2386 EXIT;
2387 END IF;
2388 END LOOP;
2389 End if;
2390 -- Resource Group level
2391 If l_res_grp_level_count > 0 then
2392 FOR I IN 1 .. l_res_grp_level_count LOOP
2393 IF g_debug_mode = 'Y' THEN
2394 log_message(p_msg_token1 => 'Iside for loop Resource Group level');
2395 End if;
2396 If g_tab_res_grp_level_cache(I) = l_res_grp_level_cache then
2397 IF g_debug_mode = 'Y' THEN
2398 log_message(p_msg_token1 =>'same cahce found');
2399 End if;
2400 g_tab_res_grp_level_cache_amt(I) :=
2401 NVL(g_tab_res_grp_level_cache_amt(I),0) -
2402 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2403
2404 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(I);
2405 EXIT;
2406 END IF;
2407 END LOOP;
2408 End if ;
2409 -- Task level
2410 If l_task_level_count > 0 then
2411 FOR I IN 1 .. l_task_level_count LOOP
2412 IF g_debug_mode = 'Y' THEN
2413 log_message(p_msg_token1 => 'Iside for loop Task level');
2414 End IF;
2415 If g_tab_task_level_cache(I) = l_task_level_cache then
2416 IF g_debug_mode = 'Y' THEN
2417 log_message(p_msg_token1 =>'same cahce found');
2418 End IF;
2419 g_tab_task_level_cache_amt(I) :=
2420 NVL(g_tab_task_level_cache_amt(I),0) -
2421 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2422 g_t_pkt_amt := g_tab_task_level_cache_amt(I);
2423 EXIT;
2424 END IF;
2425 END LOOP;
2426 End if;
2427 -- Top task level
2428 IF l_top_task_level_count > 0 then
2429 FOR I IN 1 .. l_top_task_level_count LOOP
2430 IF g_debug_mode = 'Y' THEN
2431 log_message(p_msg_token1 => 'Iside for loop Top task level');
2432 End IF;
2433 If g_tab_top_task_level_cache(I) = l_top_task_level_cache then
2434 IF g_debug_mode = 'Y' THEN
2435 log_message(p_msg_token1 =>'same cahce found');
2436 End IF;
2437 g_tab_top_task_level_cache_amt(I) :=
2438 NVL(g_tab_top_task_level_cache_amt(I),0) -
2439 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2440 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(I);
2441 EXIT;
2442 END IF;
2443 END LOOP;
2444 End if;
2445 -- Project level
2446 IF l_proj_level_count > 0 then
2447 FOR I IN 1 .. l_proj_level_count LOOP
2448 IF g_debug_mode = 'Y' THEN
2449 log_message(p_msg_token1 => 'Iside for loop Project level ');
2450 End if;
2451 If g_tab_proj_level_cache(I) = l_proj_level_cache then
2452 IF g_debug_mode = 'Y' THEN
2453 log_message(p_msg_token1 =>'same cahce found');
2454 End IF;
2455 g_tab_proj_level_cache_amt(I) :=
2456 NVL(g_tab_proj_level_cache_amt(I),0) -
2457 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2458 g_p_pkt_amt := g_tab_proj_level_cache_amt(I);
2459 EXIT;
2460 END IF;
2461 END LOOP;
2462 End if;
2463 -- Project account level
2464 IF l_proj_acct_level_count > 0 then
2465 FOR I IN 1 .. l_proj_acct_level_count LOOP
2466 IF g_debug_mode = 'Y' THEN
2467 log_message(p_msg_token1 => 'Iside for loop Project account level');
2468 End If;
2469 If g_tab_proj_acct_level_cache(I) = l_proj_acct_level_cache then
2470 IF g_debug_mode = 'Y' THEN
2471 log_message(p_msg_token1 =>'same cahce found');
2472 End IF;
2473 g_tab_prj_acct_level_cache_amt(I) :=
2474 NVL(g_tab_prj_acct_level_cache_amt(I),0) -
2475 (NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0));
2476 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(I);
2477 EXIT;
2478 END IF;
2479 END LOOP;
2480 End if;
2481
2482 END IF; -- end if for partial flag
2483 IF g_debug_mode = 'Y' THEN
2484 log_message(p_msg_token1 =>'g_r_pkt_amt ['||g_r_pkt_amt||']g_rg_pkt_amt['||
2485 g_rg_pkt_amt||']g_t_pkt_amt ['||g_t_pkt_amt||']g_tt_pkt_amt ['||
2486 g_tt_pkt_amt||']g_p_pkt_amt ['||g_p_pkt_amt||']g_p_acct_pkt_amt ['||
2487 g_p_acct_pkt_amt||']' );
2488 End IF;
2489 RETURN;
2490
2491 END IF; -- end if for minus function
2492
2493 --------------------------------------------------------------------------------------
2494 IF g_debug_mode = 'Y' THEN
2495 log_message(p_msg_token1 => 'Inside the CACHE_PKT_AMOUNT api');
2496 End IF;
2497 -- Resource level Balances
2498 IF (p_project_id = g_pre_project_id) AND
2499 (p_bdgt_version = g_pre_bdgt_version_id) AND
2500 (p_bud_task_id = g_pre_bud_task_id) AND
2501 (p_prlmi = g_pre_prlmi) AND
2502 (p_rlmi = g_pre_rlmi) AND
2503 (trunc(p_start_date) = trunc(g_pre_start_date) ) AND
2504 (trunc(p_end_date) = trunc(g_pre_end_date) ) THEN
2505 IF g_debug_mode = 'Y' THEN
2506 log_message(p_msg_token1 => ' same resource ');
2507 End IF;
2508
2509 IF p_partial_flag <> 'Y' then
2510
2511 g_r_pkt_amt := NVL(g_r_pkt_amt,0)
2512 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2513 ELse
2514 IF g_debug_mode = 'Y' THEN
2515 log_message(p_msg_token1 =>'res level count ='||l_res_level_count);
2516 End IF;
2517 IF l_res_level_count > 0 then
2518 IF g_debug_mode = 'Y' THEN
2519 log_message(p_msg_token1 => 'l_res_level_count > 0');
2520 End IF;
2521 FOR I IN 1 .. l_res_level_count LOOP
2522 IF g_debug_mode = 'Y' THEN
2523 log_message(p_msg_token1 => 'Iside for loop');
2524 End IF;
2525 If g_tab_res_level_cache(I) = l_res_level_cache then
2526 IF g_debug_mode = 'Y' THEN
2527 log_message(p_msg_token1 =>'same cahce found');
2528 End IF;
2529 g_tab_res_level_cache_amt(I) :=
2530 NVL(g_tab_res_level_cache_amt(I),0)+
2531 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2532
2533 g_r_pkt_amt := g_tab_res_level_cache_amt(I);
2534 EXIT;
2535 END IF;
2536 END LOOP;
2537 END IF ;
2538 END IF;
2539
2540 ELSE
2541 IF g_debug_mode = 'Y' THEN
2542 log_message(p_msg_token1 => ' new resource');
2543 End if;
2544 IF p_partial_flag <> 'Y' then
2545 g_r_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2546 Else
2547 l_new_resource := 'N';
2548 IF g_debug_mode = 'Y' THEN
2549 log_message(p_msg_token1 =>'res level count ='||l_res_level_count);
2550 End IF;
2551 IF l_res_level_count > 0 then
2552 IF g_debug_mode = 'Y' THEN
2553 log_message(p_msg_token1 => 'l_res_level_count > 0');
2554 End IF;
2555 FOR I IN 1 .. l_res_level_count LOOP
2556 IF g_debug_mode = 'Y' THEN
2557 log_message(p_msg_token1 => 'Iside for loop');
2558 End If;
2559 If g_tab_res_level_cache(I) = l_res_level_cache then
2560 IF g_debug_mode = 'Y' THEN
2561 log_message(p_msg_token1 =>'same cahce found');
2562 End IF;
2563 g_tab_res_level_cache_amt(I) :=
2564 NVL(g_tab_res_level_cache_amt(I),0)+
2565 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2566 g_r_pkt_amt := g_tab_res_level_cache_amt(I);
2567 l_new_resource := 'N';
2568 EXIT;
2569 END IF;
2570 l_new_resource := 'Y';
2571 END LOOP;
2572 END IF;
2573 IF g_debug_mode = 'Y' THEN
2574 log_message(p_msg_token1 =>' l_new_resource = '||l_new_resource);
2575 End IF;
2576 IF l_new_resource = 'Y' or l_res_level_count <= 0 then
2577 IF g_debug_mode = 'Y' THEN
2578 log_message(p_msg_token1 => 'adding to cache');
2579 End IF;
2580 g_tab_res_level_cache(l_res_level_count+1) := l_res_level_cache;
2581 g_tab_res_level_cache_amt(l_res_level_count+1) :=
2582 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2583
2584 g_r_pkt_amt := g_tab_res_level_cache_amt(l_res_level_count+1);
2585 END IF;
2586
2587 END IF;
2588 END IF;
2589 IF g_debug_mode = 'Y' THEN
2590 log_message(p_msg_token1 => 'res amount ='||g_r_pkt_amt);
2591 End If;
2592 -------------------------------------------------------------------------------------------
2593 -- Resource Group level Balances
2594
2595 IF (p_project_id = g_pre_project_id) AND
2596 (p_bdgt_version = g_pre_bdgt_version_id) AND
2597 (p_bud_task_id = g_pre_bud_task_id) AND
2598 (p_prlmi = g_pre_prlmi) AND
2599 --(p_rlmi = g_pre_rlmi) AND
2600 (trunc(p_start_date) = trunc(g_pre_start_date) ) AND
2601 (trunc(p_end_date) = trunc(g_pre_end_date) ) THEN
2602 IF g_debug_mode = 'Y' THEN
2603 log_message(p_msg_token1 => ' same res grp ');
2604 End If;
2605
2606 IF p_partial_flag <> 'Y' then
2607 g_rg_pkt_amt := NVL(g_rg_pkt_amt,0)
2608 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2609 Else
2610 IF g_debug_mode = 'Y' THEN
2611 log_message(p_msg_token1 =>'res grp level count ='||l_res_grp_level_count);
2612 End IF;
2613 IF l_res_grp_level_count > 0 then
2614 IF g_debug_mode = 'Y' THEN
2615 log_message(p_msg_token1 => 'l_res_grp_level_count > 0');
2616 End If;
2617 FOR I IN 1 .. l_res_grp_level_count LOOP
2618 IF g_debug_mode = 'Y' THEN
2619 log_message(p_msg_token1 => 'Iside for loop');
2620 End If;
2621 If g_tab_res_grp_level_cache(I) = l_res_grp_level_cache then
2622 IF g_debug_mode = 'Y' THEN
2623 log_message(p_msg_token1 =>'same cahce found');
2624 End IF;
2625 g_tab_res_grp_level_cache_amt(I) :=
2626 NVL(g_tab_res_grp_level_cache_amt(I),0)+
2627 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2628
2629 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(I);
2630 EXIT;
2631 END IF;
2632 END LOOP;
2633 END IF ;
2634 END IF;
2635
2636 ELSE
2637 IF g_debug_mode = 'Y' THEN
2638 log_message(p_msg_token1 => ' new res grp');
2639 End IF;
2640
2641 IF p_partial_flag <> 'Y' then
2642 g_rg_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2643 Else
2644
2645 l_new_resource_group := 'N';
2646 IF g_debug_mode = 'Y' THEN
2647 log_message(p_msg_token1 =>'res grp level count ='||l_res_grp_level_count);
2648 End IF;
2649 IF l_res_grp_level_count > 0 then
2650 IF g_debug_mode = 'Y' THEN
2651 log_message(p_msg_token1 => 'l_res_grp_level_count > 0');
2652 End IF;
2653 FOR I IN 1 .. l_res_grp_level_count LOOP
2654 IF g_debug_mode = 'Y' THEN
2655 log_message(p_msg_token1 => 'Iside for loop');
2656 End IF;
2657 If g_tab_res_grp_level_cache(I) = l_res_grp_level_cache then
2658 IF g_debug_mode = 'Y' THEN
2659 log_message(p_msg_token1 =>'same cahce found');
2660 End If;
2661 g_tab_res_grp_level_cache_amt(I) :=
2662 NVL(g_tab_res_grp_level_cache_amt(I),0)+
2663 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2664 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(I);
2665 l_new_resource_group := 'N';
2666 EXIT;
2667 END IF;
2668 l_new_resource_group := 'Y';
2669 END LOOP;
2670 END IF;
2671 IF g_debug_mode = 'Y' THEN
2672 log_message(p_msg_token1 =>' l_new_resource_group = '||l_new_resource_group);
2673 End If;
2674 IF l_new_resource_group = 'Y' or l_res_grp_level_count <= 0 then
2675 IF g_debug_mode = 'Y' THEN
2676 log_message(p_msg_token1 => 'adding to cache');
2677 End IF;
2678 g_tab_res_grp_level_cache(l_res_grp_level_count+1) := l_res_grp_level_cache;
2679 g_tab_res_grp_level_cache_amt(l_res_grp_level_count+1) :=
2680 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2681
2682 g_rg_pkt_amt := g_tab_res_grp_level_cache_amt(l_res_grp_level_count+1);
2683 END IF;
2684 END IF;
2685 END IF;
2686 IF g_debug_mode = 'Y' THEN
2687 log_message(p_msg_token1 => ' res grp bal ='||g_rg_pkt_amt);
2688 End IF;
2689 -------------------------------------------------------------------------------------
2690 -- Task level balances
2691
2692 IF (p_project_id = g_pre_project_id) AND
2693 (p_bdgt_version = g_pre_bdgt_version_id) AND
2694 (p_task_id = g_pre_task_id) AND
2695 (p_top_task_id = g_pre_top_task_id) AND
2696 --(p_prlmi = g_pre_prlmi) AND
2697 --(p_rlmi = g_pre_rlmi) AND
2698 (trunc(p_start_date) = trunc(g_pre_start_date) ) AND
2699 (trunc(p_end_date) = trunc(g_pre_end_date) ) THEN
2700 IF g_debug_mode = 'Y' THEN
2701 log_message(p_msg_token1 => ' same task level ');
2702 End IF;
2703
2704 IF p_partial_flag <> 'Y' then
2705 g_t_pkt_amt := NVL(g_t_pkt_amt,0)
2706 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2707
2708 Else
2709 IF g_debug_mode = 'Y' THEN
2710 log_message(p_msg_token1 =>'task level count ='||l_task_level_count);
2711 end IF;
2712 IF l_task_level_count > 0 then
2713 IF g_debug_mode = 'Y' THEN
2714 log_message(p_msg_token1 => 'l_task_level_count > 0');
2715 end if;
2716 FOR I IN 1 .. l_task_level_count LOOP
2717 IF g_debug_mode = 'Y' THEN
2718 log_message(p_msg_token1 => 'Iside for loop');
2719 End if;
2720 If g_tab_task_level_cache(I) = l_task_level_cache then
2721 IF g_debug_mode = 'Y' THEN
2722 log_message(p_msg_token1 =>'same cahce found');
2723 End if;
2724 g_tab_task_level_cache_amt(I) :=
2725 NVL(g_tab_task_level_cache_amt(I),0)+
2726 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2727 g_t_pkt_amt := g_tab_task_level_cache_amt(I);
2728 EXIT;
2729 END IF;
2730 END LOOP;
2731 END IF ;
2732 END IF;
2733
2734 ELSE
2735 IF g_debug_mode = 'Y' THEN
2736 log_message(p_msg_token1 => ' new task level ');
2737 End If;
2738 IF p_partial_flag <> 'Y' then
2739 g_t_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2740
2741 Else
2742 l_new_task := 'N';
2743 IF g_debug_mode = 'Y' THEN
2744 log_message(p_msg_token1 =>'task level count ='||l_task_level_count);
2745 end IF;
2746 IF l_task_level_count > 0 then
2747 IF g_debug_mode = 'Y' THEN
2748 log_message(p_msg_token1 => 'l_task_level_count > 0');
2749 end if;
2750 FOR I IN 1 .. l_task_level_count LOOP
2751 IF g_debug_mode = 'Y' THEN
2752 log_message(p_msg_token1 => 'Iside for loop');
2753 End If;
2754 If g_tab_task_level_cache(I) = l_task_level_cache then
2755 IF g_debug_mode = 'Y' THEN
2756 log_message(p_msg_token1 =>'same cahce found');
2757 end If;
2758 g_tab_task_level_cache_amt(I) :=
2759 NVL(g_tab_task_level_cache_amt(I),0)+
2760 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2761 g_t_pkt_amt := g_tab_task_level_cache_amt(I);
2762 l_new_task := 'N';
2763 EXIT;
2764 END IF;
2765 l_new_task := 'Y';
2766 END LOOP;
2767 END IF;
2768 IF g_debug_mode = 'Y' THEN
2769 log_message(p_msg_token1 =>' l_new_task= '||l_new_task);
2770 end if;
2771 IF l_new_task = 'Y' or l_task_level_count <= 0 then
2772 IF g_debug_mode = 'Y' THEN
2773 log_message(p_msg_token1 => 'adding to cache');
2774 End IF;
2775 g_tab_task_level_cache(l_task_level_count+1) := l_task_level_cache;
2776 g_tab_task_level_cache_amt(l_task_level_count+1) :=
2777 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2778 g_t_pkt_amt := g_tab_task_level_cache_amt(l_task_level_count+1);
2779 END IF;
2780 END IF;
2781 END IF;
2782 IF g_debug_mode = 'Y' THEN
2783 log_message(p_msg_token1 => ' task level bal ='||g_t_pkt_amt);
2784 End IF;
2785 ----------------------------------------------------------------------------------------------
2786 --Top Task level Balances
2787
2788 IF (p_project_id = g_pre_project_id) AND
2789 (p_bdgt_version = g_pre_bdgt_version_id) AND
2790 --(p_task_id = g_pre_task_id) AND
2791 (p_top_task_id = g_pre_top_task_id) AND
2792 --(p_prlmi = g_pre_prlmi) AND
2793 --(p_rlmi = g_pre_rlmi) AND
2794 (trunc(p_start_date) = trunc(g_pre_start_date) ) AND
2795 (trunc(p_end_date) = trunc(g_pre_end_date) ) THEN
2796 IF g_debug_mode = 'Y' THEN
2797 log_message(p_msg_token1 => ' same top task ');
2798 end If;
2799
2800 IF p_partial_flag <> 'Y' then
2801
2802 g_tt_pkt_amt := NVL(g_tt_pkt_amt,0)
2803 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2804
2805 Else
2806 IF g_debug_mode = 'Y' THEN
2807 log_message(p_msg_token1 =>'top task level count ='||l_top_task_level_count);
2808 End if;
2809 IF l_top_task_level_count > 0 then
2810 IF g_debug_mode = 'Y' THEN
2811 log_message(p_msg_token1 => 'l_top_task_level_count > 0');
2812 End If;
2813 FOR I IN 1 .. l_top_task_level_count LOOP
2814 IF g_debug_mode = 'Y' THEN
2815 log_message(p_msg_token1 => 'Iside for loop');
2816 end if;
2817 If g_tab_top_task_level_cache(I) = l_top_task_level_cache then
2818 IF g_debug_mode = 'Y' THEN
2819 log_message(p_msg_token1 =>'same cahce found');
2820 end if;
2821 g_tab_top_task_level_cache_amt(I) :=
2822 NVL(g_tab_top_task_level_cache_amt(I),0)+
2823 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2824 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(I);
2825 EXIT;
2826 END IF;
2827 END LOOP;
2828 END IF ;
2829 END IF;
2830
2831 ELSE
2832 IF g_debug_mode = 'Y' THEN
2833 log_message(p_msg_token1 => ' new top task level');
2834 End IF;
2835 IF p_partial_flag <> 'Y' then
2836 g_tt_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2837
2838 Else
2839 l_new_top_task := 'N';
2840 IF g_debug_mode = 'Y' THEN
2841 log_message(p_msg_token1 =>' top task level count ='||l_top_task_level_count);
2842 end if;
2843 IF l_top_task_level_count > 0 then
2844 IF g_debug_mode = 'Y' THEN
2845 log_message(p_msg_token1 => 'l_top_task_level_count > 0');
2846 end if;
2847 FOR I IN 1 .. l_top_task_level_count LOOP
2848 IF g_debug_mode = 'Y' THEN
2849 log_message(p_msg_token1 => 'Iside for loop');
2850 end if;
2851 If g_tab_top_task_level_cache(I) = l_top_task_level_cache then
2852 IF g_debug_mode = 'Y' THEN
2853 log_message(p_msg_token1 =>'same cahce found');
2854 end if;
2855 g_tab_top_task_level_cache_amt(I) :=
2856 NVL(g_tab_top_task_level_cache_amt(I),0)+
2857 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2858 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(I);
2859 l_new_top_task := 'N';
2860 EXIT;
2861 END IF;
2862 l_new_top_task := 'Y';
2863 END LOOP;
2864 END IF;
2865 IF g_debug_mode = 'Y' THEN
2866 log_message(p_msg_token1 =>' l_new_top_task= '||l_new_top_task);
2867 end if;
2868 IF l_new_top_task = 'Y' or l_top_task_level_count <= 0 then
2869 IF g_debug_mode = 'Y' THEN
2870 log_message(p_msg_token1 => 'adding to cache');
2871 end if;
2872 g_tab_top_task_level_cache(l_top_task_level_count+1) := l_top_task_level_cache;
2873 g_tab_top_task_level_cache_amt(l_top_task_level_count+1) :=
2874 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2875 g_tt_pkt_amt := g_tab_top_task_level_cache_amt(l_top_task_level_count+1);
2876 END IF;
2877 END IF;
2878 END IF;
2879 IF g_debug_mode = 'Y' THEN
2880 log_message(p_msg_token1 => 'top task level bal ='||g_tt_pkt_amt);
2881 end if;
2882
2883 --------------------------------------------------------------------------------------------------------
2884 -- Project level Balances
2885
2886 IF (p_project_id = g_pre_project_id) AND
2887 (p_bdgt_version = g_pre_bdgt_version_id) AND
2888 --(p_task_id = g_pre_task_id) AND
2889 --(p_top_task_id = g_pre_top_task_id) AND
2890 --(p_prlmi = g_pre_prlmi) AND
2891 --(p_rlmi = g_pre_rlmi) AND
2892 (trunc(p_start_date) = trunc(g_pre_start_date) ) AND
2893 (trunc(p_end_date) = trunc(g_pre_end_date) ) THEN
2894 IF g_debug_mode = 'Y' THEN
2895 log_message(p_msg_token1 => ' same project ');
2896 end if;
2897
2898 IF p_partial_flag <> 'Y' then
2899 g_p_pkt_amt := NVL(g_p_pkt_amt,0)
2900 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2901
2902 Else
2903 IF g_debug_mode = 'Y' THEN
2904 log_message(p_msg_token1 =>'project level count ='||l_proj_level_count);
2905 end if;
2906 IF l_proj_level_count > 0 then
2907 IF g_debug_mode = 'Y' THEN
2908 log_message(p_msg_token1 => 'l_proj_level_count > 0');
2909 end if;
2910 FOR I IN 1 .. l_proj_level_count LOOP
2911 IF g_debug_mode = 'Y' THEN
2912 log_message(p_msg_token1 => 'Iside for loop');
2913 end if;
2914 If g_tab_proj_level_cache(I) = l_proj_level_cache then
2915 IF g_debug_mode = 'Y' THEN
2916 log_message(p_msg_token1 =>'same cahce found');
2917 end if;
2918 g_tab_proj_level_cache_amt(I) :=
2919 NVL(g_tab_proj_level_cache_amt(I),0)+
2920 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2921 g_p_pkt_amt := g_tab_proj_level_cache_amt(I);
2922 EXIT;
2923 END IF;
2924 END LOOP;
2925 END IF ;
2926
2927 END IF;
2928
2929 ELSE
2930 IF g_debug_mode = 'Y' THEN
2931 log_message(p_msg_token1 => ' new project');
2932 end if;
2933
2934 IF p_partial_flag <> 'Y' then
2935 g_p_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2936
2937 Else
2938 l_new_proj := 'N';
2939 IF g_debug_mode = 'Y' THEN
2940 log_message(p_msg_token1 =>' proj level count ='||l_proj_level_count);
2941 end if;
2942 IF l_proj_level_count > 0 then
2943 IF g_debug_mode = 'Y' THEN
2944 log_message(p_msg_token1 => 'l_proj_level_count > 0');
2945 end if;
2946 FOR I IN 1 .. l_proj_level_count LOOP
2947 IF g_debug_mode = 'Y' THEN
2948 log_message(p_msg_token1 => 'Iside for loop');
2949 end if;
2950 If g_tab_proj_level_cache(I) = l_proj_level_cache then
2951 IF g_debug_mode = 'Y' THEN
2952 log_message(p_msg_token1 =>'same cahce found');
2953 end if;
2954 g_tab_proj_level_cache_amt(I) :=
2955 NVL(g_tab_proj_level_cache_amt(I),0)+
2956 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2957 g_p_pkt_amt := g_tab_proj_level_cache_amt(I);
2958 l_new_proj := 'N';
2959 EXIT;
2960 END IF;
2961 l_new_proj := 'Y';
2962 END LOOP;
2963 END IF;
2964 IF g_debug_mode = 'Y' THEN
2965 log_message(p_msg_token1 =>' l_new_proj= '||l_new_proj);
2966 end if;
2967 IF l_new_proj = 'Y' or l_proj_level_count <= 0 then
2968 IF g_debug_mode = 'Y' THEN
2969 log_message(p_msg_token1 => 'adding to cache');
2970 end if;
2971 g_tab_proj_level_cache(l_proj_level_count+1) := l_proj_level_cache;
2972 g_tab_proj_level_cache_amt(l_proj_level_count+1) :=
2973 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
2974 g_p_pkt_amt := g_tab_proj_level_cache_amt(l_proj_level_count+1);
2975 END IF;
2976 END IF;
2977 END IF;
2978 IF g_debug_mode = 'Y' THEN
2979 log_message(p_msg_token1 => 'project bal ='||g_p_pkt_amt);
2980 end if;
2981 ------------------------------------------------------------------------------------------------
2982 -- project account level Balances
2983
2984 IF (p_project_id = g_pre_project_id) AND
2985 (p_bdgt_version = g_pre_bdgt_version_id) AND
2986 (p_bdgt_ccid = g_pre_bdgt_ccid ) AND
2987 --(p_task_id = g_pre_task_id) AND
2988 --(p_top_task_id = g_pre_top_task_id) AND
2989 --(p_prlmi = g_pre_prlmi) AND
2990 --(p_rlmi = g_pre_rlmi) AND
2991 (trunc(p_start_date) = trunc(g_pre_start_date) ) AND
2992 (trunc(p_end_date) = trunc(g_pre_end_date) ) THEN
2993 IF g_debug_mode = 'Y' THEN
2994 log_message(p_msg_token1 => ' same project account');
2995 end if;
2996
2997 IF p_partial_flag <> 'Y' then
2998 g_p_acct_pkt_amt := NVL(g_p_acct_pkt_amt,0)
2999 + NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3000
3001 Else
3002 IF g_debug_mode = 'Y' THEN
3003 log_message(p_msg_token1 =>'project acct level count ='||l_proj_acct_level_count);
3004 end if;
3005 IF l_proj_acct_level_count > 0 then
3006 IF g_debug_mode = 'Y' THEN
3007 log_message(p_msg_token1 => 'l_proj_acct_level_count > 0');
3008 end if;
3009 FOR I IN 1 .. l_proj_acct_level_count LOOP
3010 IF g_debug_mode = 'Y' THEN
3011 log_message(p_msg_token1 => 'Iside for loop');
3012 end if;
3013 If g_tab_proj_acct_level_cache(I) = l_proj_acct_level_cache then
3014 IF g_debug_mode = 'Y' THEN
3015 log_message(p_msg_token1 =>'same cahce found');
3016 end if;
3017 g_tab_prj_acct_level_cache_amt(I) :=
3018 NVL(g_tab_prj_acct_level_cache_amt(I),0)+
3019 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3020 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(I);
3021 EXIT;
3022 END IF;
3023 END LOOP;
3024 END IF ;
3025 END IF;
3026
3027 ELSE
3028 IF g_debug_mode = 'Y' THEN
3029 log_message(p_msg_token1 => ' new project account');
3030 end if;
3031
3032 IF p_partial_flag <> 'Y' then
3033 g_p_acct_pkt_amt := NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3034
3035 Else
3036 l_new_proj_acct := 'N';
3037 IF g_debug_mode = 'Y' THEN
3038 log_message(p_msg_token1 =>' proj acct level count ='||l_proj_acct_level_count);
3039 end if;
3040 IF l_proj_acct_level_count > 0 then
3041 IF g_debug_mode = 'Y' THEN
3042 log_message(p_msg_token1 => 'l_proj_acct_level_count > 0');
3043 end if;
3044 FOR I IN 1 .. l_proj_acct_level_count LOOP
3045 IF g_debug_mode = 'Y' THEN
3046 log_message(p_msg_token1 => 'Iside for loop');
3047 end if;
3048 If g_tab_proj_acct_level_cache(I) = l_proj_acct_level_cache then
3049 IF g_debug_mode = 'Y' THEN
3050 log_message(p_msg_token1 =>'same cahce found');
3051 end if;
3052 g_tab_prj_acct_level_cache_amt(I) :=
3053 NVL(g_tab_prj_acct_level_cache_amt(I),0)+
3054 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3055 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(I);
3056 l_new_proj_acct := 'N';
3057 EXIT;
3058 END IF;
3059 l_new_proj_acct := 'Y';
3060 END LOOP;
3061 END IF;
3062 IF g_debug_mode = 'Y' THEN
3063 log_message(p_msg_token1 =>' l_new_proj acct = '||l_new_proj_acct);
3064 end if;
3065 IF l_new_proj_acct = 'Y' or l_proj_acct_level_count <= 0 then
3066 IF g_debug_mode = 'Y' THEN
3067 log_message(p_msg_token1 => 'adding to cache');
3068 end if;
3069 g_tab_proj_acct_level_cache(l_proj_acct_level_count+1) := l_proj_acct_level_cache;
3070 g_tab_prj_acct_level_cache_amt(l_proj_acct_level_count+1) :=
3071 NVL(p_accounted_dr,0) - NVL(p_accounted_cr,0);
3072 g_p_acct_pkt_amt := g_tab_prj_acct_level_cache_amt(l_proj_acct_level_count+1);
3073 END IF;
3074
3075 END IF;
3076 END IF;
3077 IF g_debug_mode = 'Y' THEN
3078 log_message(p_msg_token1 => 'project acct bal ='||g_p_acct_pkt_amt);
3079 end if;
3080
3081 REturn;
3082
3083 EXCEPTION
3084 WHEN OTHERS THEN
3085 IF g_debug_mode = 'Y' THEN
3086 log_message_imp(p_msg_token1 => 'failed in cache amt pkts apiSQLERR'|| sqlerrm||sqlcode);
3087 end if;
3088 raise;
3089 END CACHE_PKT_AMOUNTS;
3090
3091 -----------------------------------------------------------------------------------------------------------
3092 --- This Api checks the funds available for the record in pa bc packets. The following logic is used.
3093 --- funds check will be carried out NOCOPY at five levels, RESOURCE, RESOURCE GROUP, TOP TASK, TASK AND
3094 --- PROJECT level. depending on upon the budget entry method AND budgetory controls used
3095 --- if the budgetory control setup is N - None then funds check will not be done
3096 --- if the budgetory control setup is B - Absolute , D - Advisory then funds check will be done
3097 --- funds check will be done based on roll up process.
3098 ---
3099 --- BUDGET LEVEL BUDGETORY CONTROL
3100 --- -------------- -------------------
3101 ---
3102 --- RESOURCE ABSOLUTE /ADVISORY/ NONE
3103 ---
3104 --- RESOURCE GROUP ABSOLUTE /ADVISORY/ NONE
3105 ---
3106 --- TASK ABSOLUTE /ADVISORY/ NONE
3107 ---
3108 --- TOP TASK ABSOLUTE /ADVISORY/ NONE
3109 ---
3110 --- PROJECT ABSOLUTE /ADVISORY/ NONE
3111 -------------------------------------------------------------------------------------------------------------
3112
3113 PROCEDURE check_funds_available (
3114 p_sob IN pa_bc_packets.set_of_books_id%type,
3115 p_mode IN VARCHAR2,
3116 p_packet_id IN NUMBER,
3117 p_record IN OUT NOCOPY pa_fc_record,
3118 p_arrival_seq IN NUMBER,
3119 p_status_code IN VARCHAR2,
3120 p_ext_bdgt_link IN VARCHAR2,
3121 p_ext_bdgt_type IN VARCHAR2,
3122 p_start_date IN DATE,
3123 p_end_date IN DATE,
3124 p_calling_module IN VARCHAR2,
3125 p_partial_flag IN VARCHAR2,
3126 p_counter IN number
3127 ) IS
3128
3129
3130 -----------------------------------------------------------------------------------------------------
3131 -- This CURSOR selects AND sums up all the balances for a particular resource FROM pa_bc_balances table
3132 -- between the start date AND end date RESOURCE CURSOR
3133 -----------------------------------------------------------------------------------------------------
3134 CURSOR res_level_bal (l_rlmi number) is
3135 SELECT nvl(sum(BUDGET_PERIOD_TO_DATE * decode(balance_type,'BGT',1,0)) ,0),
3136 nvl(sum(ACTUAL_PERIOD_TO_DATE * decode(balance_type,'EXP',1,0)) ,0),
3137 nvl(sum(ENCUMB_PERIOD_TO_DATE * decode(balance_type,'REQ',1,
3138 'PO',1,
3139 'AP',1,
3140 'ENC',1,
3141 'CC_C_PAY',1,
3142 'CC_C_CO',1,
3143 'CC_P_PAY',1,
3144 'CC_P_CO',1,
3145 0)),0)
3146 FROM pa_bc_balances pb
3147 WHERE pb.project_id = p_record.project_id
3148 /* Bug fix: 3450756 Start */
3149 ---AND pb.task_id = p_record.bud_task_id
3150 AND ( (pb.task_id = p_record.bud_task_id and pb.balance_type in ('BGT'))
3151 OR
3152 (pb.balance_type NOT IN ('BGT','REV')
3153 AND
3154 ((p_record.entry_level_code = 'L' and p_record.bud_task_id = pb.task_id)
3155 OR
3156 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3157 OR
3158 (p_record.entry_level_code = 'T'
3159 and p_record.bud_task_id = (select t.top_task_id
3160 From pa_tasks t
3161 Where t.task_id = pb.task_id)
3162 )
3163 OR
3164 (p_record.entry_level_code = 'M'
3165 and ( p_record.bud_task_id = pb.task_id
3166 OR
3167 p_record.bud_task_id = (select t.top_task_id
3168 From pa_tasks t
3169 Where t.task_id = pb.task_id)
3170 )
3171 )))
3172 )
3173 /* Bug fix: 3450756 End */
3174 AND ((pb.resource_list_member_id = l_rlmi AND pb.balance_type not in ('BGT','REV'))
3175 OR (pb.resource_list_member_id = l_rlmi AND pb.balance_type ='BGT')
3176 )
3177 AND pb.budget_version_id = p_record.budget_version_id
3178 AND pb.start_date between
3179 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_start_date)) AND
3180 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_end_date))
3181 AND pb.end_date between
3182 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_start_date)) AND
3183 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_end_date))
3184 ;
3185 -----------------------------------------------------------------------------------------------------
3186 -- This CURSOR selects AND sums all the entedr - entecr columns FROM pa_bc_packets table
3187 -- for one resource between the start date AND end date
3188 -----------------------------------------------------------------------------------------------------
3189 CURSOR res_tot_bc_pkt(l_rlmi number,l_parent_res_id number) IS
3190 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3191 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3192 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3193 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3194 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3195 FROM pa_bc_packets pbc,
3196 pa_bc_packet_arrival_order ao
3197 WHERE pbc.project_id = p_record.project_id
3198 AND (
3199 (nvl(pbc.top_task_id,0) = p_record.bud_task_id)
3200 or (nvl(pbc.task_id,0) = p_record.bud_task_id)
3201 or p_record.entry_level_code = 'P'
3202 )
3203 AND pbc.resource_list_member_id = l_rlmi
3204 AND NVL(pbc.parent_resource_id,0) = nvl(l_parent_res_id,0) /* Added nvl for bug fix 2658952 */
3205 AND pbc.budget_version_id = p_record.budget_version_id
3206 AND pbc.set_of_books_id = p_sob
3207 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3208 between trunc(p_start_date) and trunc(p_end_date)) OR
3209 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3210 between trunc(p_start_date) and trunc(p_end_date)) OR
3211 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3212 between trunc(p_start_date) and trunc(p_end_date))
3213 )
3214 AND pbc.packet_id = ao.packet_id
3215 AND (
3216 -- This condition is added to avoid the concurrency issues like when two packets arrive for funds check
3217 -- one is funds check completed but not updated the status to Aprroved as the final status is updated
3218 -- after getting the status from gl tie back.mean time antother packet which arrives has to consider
3219 -- the amount which already consumeed in previous packet.
3220 -- the status code takes care of the following
3221 -- A -- Approved but not yet posted to balances / not yet swept
3222 -- P -- Pending packet which is funds checked not yet approved / when two packets arrives in queue
3223 -- has to consider the amounts in previous packet
3224 -- C -- packets arrives during baseline process will be updated with intermedidate status after FC
3225 -- B -- the approved the transaction will be updated to B during CHECK_BASELINE mode these transaction
3226 -- must be considered during RESERVE_BASELINE mode
3227 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3228 ( ao.arrival_seq < p_arrival_seq
3229 --AND ao.affect_funds_flag = 'Y'
3230 AND ao.set_of_books_id = p_sob
3231 AND pbc.status_code in ( 'A','P')
3232 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3233 AND pbc.balance_posted_flag = 'N'
3234 )
3235 OR(pbc.packet_id = p_packet_id
3236 and pbc.status_code = 'Z'
3237 and pbc.effect_on_funds_code = 'I'
3238 and p_partial_flag <> 'Y'
3239 and pbc.balance_posted_flag = 'N'
3240 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3241 )
3242 );
3243
3244
3245 --------------------------------------------------------------------------------------
3246 -- This CURSOR select the sum of amount from pa bc balances for the given parent
3247 -- resource id between the start and end date - RESOURCE GROUP CURSOR
3248 --------------------------------------------------------------------------------------
3249 CURSOR res_grp_level_bal (l_parent_member_id number,l_bud_rlmi number) is
3250 SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3251 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3252 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3253 'PO',1,
3254 'AP',1,
3255 'ENC',1,
3256 'CC_C_PAY',1,
3257 'CC_C_CO',1,
3258 'CC_P_PAY',1,
3259 'CC_P_CO',1,
3260 0)),0)
3261 FROM pa_bc_balances pb
3262 WHERE pb.project_id = p_record.project_id
3263 /* Bug fix: 3450756 Start */
3264 ---AND pb.task_id = p_record.bud_task_id
3265 AND ( (pb.task_id = p_record.bud_task_id and pb.balance_type in ('BGT'))
3266 OR
3267 (pb.balance_type NOT IN ('BGT','REV')
3268 AND
3269 ((p_record.entry_level_code = 'L' and p_record.bud_task_id = pb.task_id)
3270 OR
3271 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3272 OR
3273 (p_record.entry_level_code = 'T'
3274 and p_record.bud_task_id = (select t.top_task_id
3275 From pa_tasks t
3276 Where t.task_id = pb.task_id)
3277 )
3278 OR
3279 (p_record.entry_level_code = 'M'
3280 and (p_record.bud_task_id = pb.task_id
3281 OR
3282 p_record.bud_task_id = (select t.top_task_id
3283 From pa_tasks t
3284 Where t.task_id = pb.task_id)
3285 )
3286 )))
3287 )
3288 /* Bug fix: 3450756 End */
3289 AND (( NVL(pb.parent_member_id,0) = NVL(l_parent_member_id,0) /* Added NVL for bug fix 2658952 */
3290 and pb.balance_type not in ('BGT','REV')
3291 and pb.parent_member_id is NOT NULL)
3292 OR (pb.resource_list_member_id = l_bud_rlmi AND
3293 pb.balance_type not in ('BGT','REV') AND
3294 pb.parent_member_id is NULL )
3295 OR (pb.resource_list_member_id = l_bud_rlmi AND pb.balance_type ='BGT'
3296 AND pb.parent_member_id is null)
3297 )
3298 AND pb.budget_version_id = p_record.budget_version_id
3299 AND pb.start_date between
3300 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_start_date)) AND
3301 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_end_date))
3302 AND pb.end_date between
3303 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_start_date)) AND
3304 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_end_date));
3305
3306 -----------------------------------------------------------------------------------------
3307 -- this cursor selects the sum of amounts and rolls up the resource group level
3308 -- RESOURCE ROLLUP
3309 ----------------------------------------------------------------------------------------
3310 CURSOR res_rollup_bal (l_parent_member_id number) is
3311 SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3312 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3313 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3314 'PO',1,
3315 'AP',1,
3316 'ENC',1,
3317 'CC_C_PAY',1,
3318 'CC_C_CO',1,
3319 'CC_P_PAY',1,
3320 'CC_P_CO',1,
3321 0)),0)
3322 FROM pa_bc_balances pb
3323 WHERE pb.project_id = p_record.project_id
3324 /* Bug fix: 3450756 Start */
3325 ---AND pb.task_id = p_record.bud_task_id
3326 AND ( (pb.task_id = p_record.bud_task_id and pb.balance_type in ('BGT'))
3327 OR
3328 (pb.balance_type NOT IN ('BGT','REV')
3329 AND
3330 ((p_record.entry_level_code = 'L' and p_record.bud_task_id = pb.task_id)
3331 OR
3332 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3333 OR
3334 (p_record.entry_level_code = 'T'
3335 and p_record.bud_task_id = (select t.top_task_id
3336 From pa_tasks t
3337 Where t.task_id = pb.task_id)
3338 )
3339 OR
3340 (p_record.entry_level_code = 'M'
3341 and ( p_record.bud_task_id = pb.task_id
3342 OR
3343 p_record.bud_task_id = (select t.top_task_id
3344 From pa_tasks t
3345 Where t.task_id = pb.task_id)
3346 )
3347 )))
3348 )
3349 /* Bug fix: 3450756 End */
3350 AND ((NVL(pb.parent_member_id,0) = nvl(l_parent_member_id,0) /*Added NVL for bug fix 2658952 */
3351 and pb.balance_type not in ('BGT','REV')
3352 and pb.parent_member_id is NOT NULL )
3353 OR (NVL(pb.parent_member_id,0) = nvl(l_parent_member_id,0) /*Added NVL for bug fix 2658952 */
3354 AND pb.balance_type ='BGT'
3355 AND pb.parent_member_id is NOT NULL)
3356 )
3357 AND pb.budget_version_id = p_record.budget_version_id
3358 AND pb.start_date between
3359 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_start_date)) AND
3360 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_end_date))
3361 AND pb.end_date between
3362 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_start_date)) AND
3363 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_end_date));
3364
3365
3366 -----------------------------------------------------------------------------------------------------
3367 -- This CURSOR selects AND sums all the entedr - entecr columns FROM pa_bc_packets table
3368 -- for one resource group between the start date AND end date
3369 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3370 -----------------------------------------------------------------------------------------------------
3371 CURSOR res_grp_tot_bc_pkt(l_parent_res_id number,l_rlmi number) IS
3372 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3373 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3374 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3375 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3376 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3377 FROM pa_bc_packets pbc,
3378 pa_bc_packet_arrival_order ao
3379 WHERE pbc.project_id = p_record.project_id
3380 AND (
3381 (nvl(pbc.top_task_id,0) = p_record.bud_task_id)
3382 or (nvl(pbc.task_id,0) = p_record.bud_task_id)
3383 or p_record.entry_level_code = 'P'
3384 )
3385 AND ( (NVL(pbc.parent_resource_id,0) = NVl(l_parent_res_id,0) /*Added NVL for bug fix 2658952 */
3386 and NVl(l_parent_res_id,0) <> 0 )
3387 OR ( pbc.resource_list_member_id = l_rlmi
3388 and NVl(l_parent_res_id,0) = 0)
3389 )
3390 AND pbc.budget_version_id = p_record.budget_version_id
3391 AND pbc.set_of_books_id = p_sob
3392 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3393 between trunc(p_start_date) and trunc(p_end_date)) OR
3394 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3395 between trunc(p_start_date) and trunc(p_end_date)) OR
3396 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3397 between trunc(p_start_date) and trunc(p_end_date))
3398 )
3399 AND pbc.packet_id = ao.packet_id
3400 AND (
3401 ( ao.arrival_seq < p_arrival_seq
3402 --AND ao.affect_funds_flag = 'Y'
3403 AND ao.set_of_books_id = p_sob
3404 AND pbc.status_code in ( 'A','P')
3405 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3406 AND pbc.balance_posted_flag = 'N'
3407 )
3408 OR(pbc.packet_id = p_packet_id
3409 and pbc.status_code = 'Z'
3410 and pbc.effect_on_funds_code = 'I'
3411 and p_partial_flag <> 'Y'
3412 and pbc.balance_posted_flag = 'N'
3413 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3414 )
3415 );
3416
3417 -----------------------------------------------------------------------------------------------------
3418 -- This CURSOR selects AND sums up all the balances for a particular task FROM pa_bc_balances table
3419 -- between the start date AND end date and this CURSOR is opened when funds checking rolls up to
3420 -- task level FROM resource level
3421 -----------------------------------------------------------------------------------------------------
3422 CURSOR task_level_bal (l_task_id number)is
3423 SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3424 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3425 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3426 'PO',1,
3427 'AP',1,
3428 'ENC',1,
3429 'CC_C_PAY',1,
3430 'CC_C_CO',1,
3431 'CC_P_PAY',1,
3432 'CC_P_CO',1,
3433 0)),0)
3434 FROM pa_bc_balances pb
3435 WHERE pb.project_id = p_record.project_id
3436 AND pb.budget_version_id = p_record.budget_version_id
3437 /* Bug fix: 3450756 Start */
3438 --- AND ( ( pb.task_id = l_task_id AND pb.balance_type='BGT')
3439 --- OR (pb.task_id = l_task_id AND pb.balance_type not in ('REV','BGT'))
3440 --- )
3441 AND ( (pb.task_id = l_task_id and pb.balance_type in ('BGT'))
3442 OR
3443 (pb.balance_type NOT IN ('BGT','REV')
3444 AND
3445 ((p_record.entry_level_code = 'L' and pb.task_id = l_task_id )
3446 OR
3447 (p_record.entry_level_code = 'P' and p_record.bud_task_id = 0)
3448 OR
3449 (p_record.entry_level_code = 'T'
3450 and l_task_id = (select t.top_task_id
3451 From pa_tasks t
3452 Where t.task_id = pb.task_id)
3453 )
3454 OR
3455 (p_record.entry_level_code = 'M'
3456 and ( pb.task_id = l_task_id
3457 OR
3458 l_task_id = (select t.top_task_id
3459 From pa_tasks t
3460 Where t.task_id = pb.task_id)
3461 )
3462 )))
3463 )
3464 /* Bug fix: 3450756 End */
3465 AND pb.start_date between
3466 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_start_date)) AND
3467 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_end_date))
3468 AND pb.end_date between
3469 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_start_date)) AND
3470 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_end_date));
3471
3472 -----------------------------------------------------------------------------------------------------
3473 --This CURSOR selects AND sums all the entedr columns FROM pa_bc_packets table for all the resources
3474 --falling under one lowest task between the start date AND end date
3475 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3476 -----------------------------------------------------------------------------------------------------
3477 CURSOR task_tot_bc_pkt (l_task_id number,l_top_task_id number) is
3478 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3479 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3480 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3481 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3482 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3483 FROM pa_bc_packets pbc,
3484 pa_bc_packet_arrival_order ao
3485 WHERE pbc.project_id = p_record.project_id
3486 AND pbc.top_task_id = l_top_task_id
3487 AND pbc.task_id = l_task_id
3488 AND pbc.budget_version_id = p_record.budget_version_id
3489 AND pbc.set_of_books_id = p_sob
3490 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3491 between trunc(p_start_date) and trunc(p_end_date)) OR
3492 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3493 between trunc(p_start_date) and trunc(p_end_date)) OR
3494 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3495 between trunc(p_start_date) and trunc(p_end_date))
3496 )
3497 AND pbc.packet_id = ao.packet_id
3498 AND (
3499 ( ao.arrival_seq < p_arrival_seq
3500 --AND ao.affect_funds_flag = 'Y'
3501 AND ao.set_of_books_id = p_sob
3502 AND pbc.status_code in ( 'A','P')
3503 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3504 AND pbc.balance_posted_flag = 'N'
3505 )
3506 OR(pbc.packet_id = p_packet_id
3507 and pbc.status_code = 'Z'
3508 and pbc.effect_on_funds_code = 'I'
3509 and p_partial_flag <> 'Y'
3510 and pbc.balance_posted_flag = 'N'
3511 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3512 )
3513 );
3514
3515
3516 -----------------------------------------------------------------------------------------------------
3517 -- This CURSOR selects AND sums up all the balances for a particular top task FROM pa_bc_balances table
3518 -- between the start date AND end date
3519 -----------------------------------------------------------------------------------------------------
3520 CURSOR top_task_level_bal (l_bud_task_id number,l_top_task_id number) is
3521 SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3522 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3523 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3524 'PO',1,
3525 'AP',1,
3526 'ENC',1,
3527 'CC_C_PAY',1,
3528 'CC_C_CO',1,
3529 'CC_P_PAY',1,
3530 'CC_P_CO',1,
3531 0)),0)
3532 FROM pa_bc_balances pb
3533 WHERE pb.project_id = p_record.project_id
3534 AND ((pb.task_id = l_bud_task_id AND pb.balance_type='BGT' AND pb.task_id = l_top_task_id)
3535 OR (pb.top_task_id = l_top_task_id AND pb.balance_type not in ('REV','BGT'))
3536 )
3537 AND pb.budget_version_id = p_record.budget_version_id
3538 AND pb.start_date between
3539 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_start_date)) AND
3540 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_end_date))
3541 AND pb.end_date between
3542 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_start_date)) AND
3543 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_end_date));
3544
3545
3546 -----------------------------------------------------------------------------------------------------
3547 -- This CURSOR selects AND sums up all the balances for a particular task FROM pa_bc_balances table
3548 -- between the start date AND end date and rollup TASKROLLUP CURSOR
3549 -----------------------------------------------------------------------------------------------------
3550 CURSOR task_rollup_bal (l_top_task_id number) is
3551 SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3552 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3553 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3554 'PO',1,
3555 'AP',1,
3556 'ENC',1,
3557 'CC_C_PAY',1,
3558 'CC_C_CO',1,
3559 'CC_P_PAY',1,
3560 'CC_P_CO',1,
3561 0)),0)
3562 FROM pa_bc_balances pb
3563 WHERE pb.project_id = p_record.project_id
3564 AND ((pb.top_task_id = l_top_task_id and pb.balance_type not in ('REV','BGT'))
3565 OR (pb.top_task_id = l_top_task_id AND pb.balance_type='BGT'))
3566 AND pb.budget_version_id = p_record.budget_version_id
3567 AND pb.start_date between
3568 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_start_date))AND
3569 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_end_date))
3570 AND pb.end_date between
3571 decode(p_record.time_phased_type_code,'N', pb.end_date,trunc( p_start_date)) AND
3572 decode(p_record.time_phased_type_code,'N', pb.end_date,trunc( p_end_date));
3573
3574 -----------------------------------------------------------------------------------------------------
3575 --This CURSOR selects AND sums all the entedr columns FROM pa_bc_packets table for all the resources
3576 --falling under one top task between the start date AND end date
3577 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3578 -----------------------------------------------------------------------------------------------------
3579 CURSOR top_task_tot_bc_pkt (l_top_task_id number) is
3580 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3581 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3582 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3583 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3584 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3585 FROM pa_bc_packets pbc,
3586 pa_bc_packet_arrival_order ao
3587 WHERE pbc.project_id = p_record.project_id
3588 AND pbc.top_task_id = l_top_task_id
3589 AND pbc.budget_version_id = p_record.budget_version_id
3590 AND pbc.set_of_books_id = p_sob
3591 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3592 between trunc(p_start_date) and trunc(p_end_date)) OR
3593 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3594 between trunc(p_start_date) and trunc(p_end_date)) OR
3595 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3596 between trunc(p_start_date) and trunc(p_end_date))
3597 )
3598 AND pbc.packet_id = ao.packet_id
3599 AND (
3600 ( ao.arrival_seq < p_arrival_seq
3601 --AND ao.affect_funds_flag = 'Y'
3602 AND ao.set_of_books_id = p_sob
3603 AND pbc.status_code in ( 'A','P')
3604 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3605 AND pbc.balance_posted_flag = 'N'
3606 )
3607 OR(pbc.packet_id = p_packet_id
3608 and pbc.status_code = 'Z'
3609 and pbc.effect_on_funds_code = 'I'
3610 and p_partial_flag <> 'Y'
3611 and pbc.balance_posted_flag = 'N'
3612 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3613 )
3614 );
3615 -----------------------------------------------------------------------------------------------------
3616 --This CURSOR selects AND sums up all the balances for a particular project FROM pa_bc_balances table
3617 --between the start date AND end date and this CURSOR is opened when funds checking rolles up to
3618 --the project level FROM task level
3619 -----------------------------------------------------------------------------------------------------
3620 CURSOR project_level_bal is
3621 SELECT nvl(sum(BUDGET_PERIOD_TO_DATE *decode(balance_type,'BGT',1,0)) ,0),
3622 nvl(sum(ACTUAL_PERIOD_TO_DATE *decode(balance_type,'EXP',1,0)) ,0),
3623 nvl(sum(ENCUMB_PERIOD_TO_DATE *decode(balance_type,'REQ',1,
3624 'PO',1,
3625 'AP',1,
3626 'ENC',1,
3627 'CC_C_PAY',1,
3628 'CC_C_CO',1,
3629 'CC_P_PAY',1,
3630 'CC_P_CO',1,
3631 0)),0)
3632 FROM pa_bc_balances pb
3633 WHERE pb.project_id = p_record.project_id
3634 AND pb.budget_version_id = p_record.budget_version_id
3635 AND pb.start_date between
3636 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_start_date)) AND
3637 decode(p_record.time_phased_type_code,'N', pb.start_date, trunc(p_end_date))
3638 AND pb.end_date between
3639 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_start_date)) AND
3640 decode(p_record.time_phased_type_code,'N', pb.end_date, trunc(p_end_date));
3641 -----------------------------------------------------------------------------------------------------
3642 --This CURSOR selects AND sums all the entedr columns FROM pa_bc_packets table for all the resources
3643 --falling under one project between the start date AND end date
3644 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3645 -----------------------------------------------------------------------------------------------------
3646 CURSOR project_tot_bc_pkt is
3647 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3648 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3649 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3650 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3651 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3652 FROM pa_bc_packets pbc,
3653 pa_bc_packet_arrival_order ao
3654 WHERE pbc.project_id = p_record.project_id
3655 AND pbc.budget_version_id = p_record.budget_version_id
3656 AND pbc.set_of_books_id = p_sob
3657 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3658 between trunc(p_start_date) and trunc(p_end_date)) OR
3659 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3660 between trunc(p_start_date) and trunc(p_end_date)) OR
3661 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3662 between trunc(p_start_date) and trunc(p_end_date))
3663 )
3664 AND pbc.packet_id = ao.packet_id
3665 AND (
3666 ( ao.arrival_seq < p_arrival_seq
3667 --AND ao.affect_funds_flag = 'Y'
3668 AND ao.set_of_books_id = p_sob
3669 AND pbc.status_code in ( 'A','P')
3670 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3671 AND pbc.balance_posted_flag = 'N'
3672 )
3673 OR(pbc.packet_id = p_packet_id
3674 and pbc.status_code = 'Z'
3675 and pbc.effect_on_funds_code = 'I'
3676 and p_partial_flag <> 'Y'
3677 and pbc.balance_posted_flag = 'N'
3678 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3679 )
3680 );
3681
3682 --------------------------------------------------------------------------------------------------
3683 -- This CURSOR select and sums all the entered dr and entered cr columns from pa_bc_packets table
3684 -- for the given budget code combination id falling under the start and end date
3685 -- R12 note: all code related to status code 'C' and 'B' being deleted ..
3686 -------------------------------------------------------------------------------------------------
3687 CURSOR project_acct_tot_bc_pkt(l_bdgt_ccid NUMBER) is
3688 SELECT nvl(sum(decode(pbc.status_code,'P',nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0)
3689 +nvl(sum(decode(pbc.status_code||substr(pbc.result_code,1,1)||pbc.effect_on_funds_code,'ZPI',
3690 nvl(accounted_dr,0) - nvl(accounted_cr,0),0)),0),
3691 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AE',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0),
3692 nvl(sum(decode(pbc.status_code||pbc.actual_flag, 'AA',nvl(accounted_dr,0)-nvl(accounted_cr,0),0)),0)
3693 FROM pa_bc_packets pbc,
3694 pa_bc_packet_arrival_order ao
3695 WHERE pbc.project_id = p_record.project_id
3696 AND pbc.budget_version_id = p_record.budget_version_id
3697 AND pbc.set_of_books_id = p_sob
3698 ANd pbc.budget_ccid = l_bdgt_ccid
3699 AND ((p_record.time_phased_type_code = 'G' and pbc.gl_date
3700 between trunc(p_start_date) and trunc(p_end_date)) OR
3701 (p_record.time_phased_type_code = 'P' and pbc.pa_date
3702 between trunc(p_start_date) and trunc(p_end_date)) OR
3703 (p_record.time_phased_type_code = 'N' and pbc.expenditure_item_date
3704 between trunc(p_start_date) and trunc(p_end_date))
3705 )
3706 AND pbc.packet_id = ao.packet_id
3707 AND (
3708 ( ao.arrival_seq < p_arrival_seq
3709 --AND ao.affect_funds_flag = 'Y'
3710 AND ao.set_of_books_id = p_sob
3711 AND pbc.status_code in ( 'A','P')
3712 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3713 AND pbc.balance_posted_flag = 'N'
3714 )
3715 OR(pbc.packet_id = p_packet_id
3716 and pbc.status_code = 'Z'
3717 and pbc.effect_on_funds_code = 'I'
3718 and p_partial_flag <> 'Y'
3719 and pbc.balance_posted_flag = 'N'
3720 and substr(nvl(pbc.result_code,'P'),1,1)= 'P'
3721 )
3722 );
3723
3724
3725
3726 -----------------------------------------------------------------------------------------------------
3727 -- declare required local variables
3728 l_stage VARCHAR2(10);
3729 l_r_budget_posted pa_bc_packets.res_budget_posted%type;
3730 l_rg_budget_posted pa_bc_packets.res_budget_posted%type;
3731 l_t_budget_posted pa_bc_packets.res_budget_posted%type;
3732 l_tt_budget_posted pa_bc_packets.res_budget_posted%type;
3733 l_p_budget_posted pa_bc_packets.res_budget_posted%type;
3734 l_r_actual_posted pa_bc_packets.res_budget_posted%type;
3735 l_rg_actual_posted pa_bc_packets.res_budget_posted%type;
3736 l_t_actual_posted pa_bc_packets.res_budget_posted%type;
3737 l_tt_actual_posted pa_bc_packets.res_budget_posted%type;
3738 l_p_actual_posted pa_bc_packets.res_budget_posted%type;
3739 l_r_enc_posted pa_bc_packets.res_budget_posted%type;
3740 l_rg_enc_posted pa_bc_packets.res_budget_posted%type;
3741 l_t_enc_posted pa_bc_packets.res_budget_posted%type;
3742 l_tt_enc_posted pa_bc_packets.res_budget_posted%type;
3743 l_p_enc_posted pa_bc_packets.res_budget_posted%type;
3744 l_r_budget_bal pa_bc_packets.res_budget_posted%type;
3745 l_rg_budget_bal pa_bc_packets.res_budget_posted%type;
3746 l_t_budget_bal pa_bc_packets.res_budget_posted%type;
3747 l_tt_budget_bal pa_bc_packets.res_budget_posted%type;
3748 l_p_budget_bal pa_bc_packets.res_budget_posted%type;
3749 l_r_actual_approved pa_bc_packets.res_budget_posted%type;
3750 l_rg_actual_approved pa_bc_packets.res_budget_posted%type;
3751 l_t_actual_approved pa_bc_packets.res_budget_posted%type;
3752 l_tt_actual_approved pa_bc_packets.res_budget_posted%type;
3753 l_p_actual_approved pa_bc_packets.res_budget_posted%type;
3754 l_r_enc_approved pa_bc_packets.res_budget_posted%type;
3755 l_rg_enc_approved pa_bc_packets.res_budget_posted%type;
3756 l_t_enc_approved pa_bc_packets.res_budget_posted%type;
3757 l_tt_enc_approved pa_bc_packets.res_budget_posted%type;
3758 l_p_enc_approved pa_bc_packets.res_budget_posted%type;
3759 l_result_code pa_bc_packets.result_code%type;
3760 l_r_result_code pa_bc_packets.res_result_code%type;
3761 l_rg_result_code pa_bc_packets.res_grp_result_code%type;
3762 l_t_result_code pa_bc_packets.task_result_code%type;
3763 l_tt_result_code pa_bc_packets.top_task_result_code%type;
3764 l_p_result_code pa_bc_packets.project_result_code%type;
3765 l_p_acct_result_code pa_bc_packets.project_result_code%type;
3766 l_status_code pa_bc_packets.status_code%type;
3767 l_available_amt pa_bc_packets.accounted_dr%type;
3768 l_return_status VARCHAR2(200);
3769 l_r_enc_pending NUMBER;
3770 l_rg_enc_pending NUMBER;
3771 l_t_enc_pending NUMBER;
3772 l_tt_enc_pending NUMBER;
3773 l_p_enc_pending NUMBER;
3774 l_r_actual_pending NUMBER;
3775 l_rg_actual_pending NUMBER;
3776 l_t_actual_pending NUMBER;
3777 l_tt_actual_pending NUMBER;
3778 l_p_actual_pending NUMBER;
3779 l_pkt_amt NUMBER;
3780 l_acct_level_bal NUMBER;
3781 l_p_acct_pkt_amt NUMBER;
3782 l_p_acct_enc_approved NUMBER;
3783 l_p_acct_actual_approved NUMBER;
3784 l_cached_satus varchar2(100);
3785
3786
3787 BEGIN
3788 -- use one level cache for storing the balances
3789 CACHE_PKT_AMOUNTS(
3790 p_project_id => p_record.project_id
3791 ,p_bdgt_version => p_record.budget_version_id
3792 ,p_top_task_id => p_record.top_task_id
3793 ,p_task_id => p_record.task_id
3794 ,p_bud_task_id => p_record.bud_task_id
3795 ,p_start_date => p_start_date
3796 ,p_end_date => p_end_date
3797 ,p_rlmi => p_record.resource_list_member_id
3798 ,p_bud_rlmi => p_record.bud_resource_list_member_id
3799 ,p_prlmi => p_record.parent_resource_id
3800 ,p_bdgt_ccid => p_record.budget_ccid
3801 ,p_accounted_dr => p_record.accounted_dr
3802 ,p_accounted_cr => p_record.accounted_cr
3803 ,p_calling_module => p_calling_module
3804 ,p_partial_flag => p_partial_flag
3805 ,p_function => 'ADD'
3806 ,p_bc_packet_id => p_record.bc_packet_id
3807 ,p_doc_type => p_record.document_type
3808 ,p_doc_header_id => p_record.document_header_id
3809 ,p_doc_distribution_id =>p_record.document_distribution_id
3810 ,x_result_code => l_result_code
3811 ,x_cached_status => l_cached_satus
3812 ,p_counter => p_counter
3813 );
3814
3815 IF substr(l_result_code ,1,1) = 'F' then
3816 IF g_debug_mode = 'Y' THEN
3817 log_message(p_msg_token1 =>'l_result_code from cache ='||l_result_code);
3818 end if;
3819 -- msg : Raw line is failed so donot funds check for burden
3820 l_r_result_code := l_result_code;
3821 l_rg_result_code :=l_result_code;
3822 l_t_result_code := l_result_code;
3823 l_tt_result_code :=l_result_code;
3824 l_p_result_code := l_result_code;
3825 l_p_acct_result_code := l_result_code;
3826 GOTO END_PROCESS;
3827
3828 End if;
3829
3830
3831 -- check whether the effect on funds is Increase then it doesnot require
3832 -- funds check so pass the transaction
3833 If p_record.effect_on_funds_code = 'I' then
3834 IF g_debug_mode = 'Y' THEN
3835 log_message(p_msg_token1 =>'Effect on funds code ='||p_record.effect_on_funds_code);
3836 end if;
3837 -- msg : P113 = Increase in funds doest not require FC
3838 l_r_result_code := 'P113';
3839 l_rg_result_code := 'P113';
3840 l_t_result_code := 'P113';
3841 l_tt_result_code := 'P113';
3842 l_p_result_code := 'P113';
3843 l_p_acct_result_code := 'P113';
3844 l_result_code := 'P113';
3845 GOTO END_PROCESS;
3846 End if;
3847
3848 -- check if teh budget version id or rlmi is null in pa bc packets then
3849 -- mark it as invalid parameters for the funds check process
3850 If p_record.budget_version_id is NULL or p_record.resource_list_member_id is NULL
3851 or p_record.expenditure_item_date is NULL or p_record.pa_date is null or
3852 p_record.gl_date is null then
3853 IF g_debug_mode = 'Y' THEN
3854 log_message(p_msg_token1 =>'invalid params in check avaiable ');
3855 end if;
3856 l_status_code := 'F';
3857 l_r_result_code := 'F118';
3858 l_rg_result_code := 'F118';
3859 l_t_result_code := 'F118';
3860 l_tt_result_code := 'F118';
3861 l_p_result_code := 'F118';
3862 l_p_acct_result_code := 'F118';
3863 l_result_code := 'F118';
3864 GOTO END_PROCESS;
3865 End if;
3866
3867 --check whether the burdened cost flag is Y or N if the burden_cost_flag = 'N'
3868 -- mark the transaction with failure status for Invalid budget entry methods
3869 -- funds check will be done only for burdened cost
3870 If nvl(p_record.burdened_cost_flag,'N') <> 'Y' then
3871 IF g_debug_mode = 'Y' THEN
3872 log_message(p_msg_token1 =>'burden cost flag ='||p_record.burdened_cost_flag);
3873 End if;
3874 l_status_code := 'F';
3875 l_r_result_code := 'F131';
3876 l_rg_result_code := 'F131';
3877 l_t_result_code := 'F131';
3878 l_tt_result_code := 'F131';
3879 l_p_result_code := 'F131';
3880 l_p_acct_result_code := 'F131';
3881 l_result_code := 'F131';
3882 GOTO END_PROCESS;
3883 End if;
3884
3885 /*****************************************************************************/
3886 -- START OF FUNDS CHECK AT RESOURCE LEVEL -------
3887 /****************************************************************************/
3888 IF g_debug_mode = 'Y' THEN
3889 log_message(p_msg_token1 => 'category code ['||p_record.categorization_code||
3890 ']start date ['||p_start_date||'] end date['|| p_end_date||
3891 ']rlmi ['||p_record.resource_list_member_id||']bud_rlmi['||p_record.bud_resource_list_member_id||
3892 ']prlmi ['||p_record.parent_resource_id||']bud task id['||p_record.bud_task_id||
3893 ']time phase code ['||p_record.time_phased_type_code||
3894 ']budget verson id ['||p_record.budget_version_id||
3895 ']project id ['||p_record.project_id||']top task id ['||p_record.top_task_id||
3896 ']arrival seq [ '||p_arrival_seq||']resource_group_type_id['||p_record.group_resource_type_id||']');
3897 End if;
3898
3899 -- check funds at resource level if the budget is categorized by resource
3900 -- otherwise go the task level and check funds
3901 IF nvl(p_record.categorization_code,'N') = 'R' then
3902 IF g_debug_mode = 'Y' THEN
3903 log_message(p_msg_token1 => 'Categorization code ='||p_record.categorization_code);
3904 End if;
3905 l_stage := 100;
3906
3907 IF (p_record.project_id <> g_bal_r_project_id OR g_bal_r_project_id is NULL ) OR
3908 (p_record.budget_version_id <> g_bal_r_bdgt_version_id or g_bal_r_bdgt_version_id is NULL ) OR
3909 (p_record.time_phased_type_code <> g_bal_r_time_phase_code or g_bal_r_time_phase_code is NULL ) OR
3910 (trunc(p_start_date) <> trunc(g_bal_r_start_date) or g_bal_r_start_date is NULL ) OR
3911 (trunc(p_end_date) <> trunc(g_bal_r_end_date ) or g_bal_r_end_date is NULL) OR
3912 (p_record.bud_task_id <> g_bal_r_bud_task_id OR g_bal_r_bud_task_id is NULL ) OR
3913 (p_record.resource_list_member_id <> g_bal_r_rlmi or g_bal_r_rlmi is NULL ) Then
3914
3915
3916 OPEN res_level_bal (p_record.resource_list_member_id);
3917 IF g_debug_mode = 'Y' THEN
3918 log_message(p_msg_token1 => 'opened the cursor res_level_bal');
3919 end if;
3920 FETCH res_level_bal INTO l_r_budget_posted,
3921 l_r_actual_posted,
3922 l_r_enc_posted;
3923 -- store the values in global variables
3924 g_r_budget_posted := l_r_budget_posted;
3925 g_r_actual_posted := l_r_actual_posted;
3926 g_r_enc_posted := l_r_enc_posted;
3927
3928 --- added for performance testing to use as onelevel cache
3929 g_bal_r_project_id := p_record.project_id;
3930 g_bal_r_bdgt_version_id := p_record.budget_version_id;
3931 g_bal_r_bud_task_id := p_record.bud_task_id;
3932 g_bal_r_rlmi := p_record.resource_list_member_id;
3933 g_bal_r_start_date := trunc(p_start_date);
3934 g_bal_r_end_date := trunc(p_end_date);
3935 g_bal_r_time_phase_code := p_record.time_phased_type_code;
3936
3937 CLOSE res_level_bal;
3938 ELSE
3939 IF g_debug_mode = 'Y' THEN
3940 log_message(p_msg_token1 => 'Same combination for res level bal cur ');
3941 end if;
3942 l_r_budget_posted := g_r_budget_posted;
3943 l_r_actual_posted := g_r_actual_posted;
3944 l_r_enc_posted := g_r_enc_posted;
3945
3946 END IF; -- end of onelevel cache
3947 IF g_debug_mode = 'Y' THEN
3948 log_message(p_msg_token1 => 'r_bud_posted ['||l_r_budget_posted||
3949 ']r_actual_posted ['||l_r_actual_posted||']r_enc posted ['||l_r_enc_posted|| ']' );
3950 End if;
3951
3952 -- open the cursor for packet amounts at resource level
3953 IF (p_record.project_id <> g_pkt_r_project_id OR g_pkt_r_project_id is NULL ) OR
3954 (p_record.budget_version_id <> g_pkt_r_bdgt_version_id or g_pkt_r_bdgt_version_id is NULL ) OR
3955 --(p_record.time_phased_type_code <> g_pkt_r_time_phase_code or g_pkt_r_time_phase_code is NULL ) OR
3956 (p_record.entry_level_code <> g_pkt_r_entry_level_code or g_pkt_r_entry_level_code is NULL ) OR
3957 (trunc(p_start_date) <> trunc(g_pkt_r_start_date) or g_pkt_r_start_date is NULL ) OR
3958 (trunc(p_end_date) <> trunc(g_pkt_r_end_date ) or g_pkt_r_end_date is NULL) OR
3959 (p_record.bud_task_id <> g_pkt_r_bud_task_id OR g_pkt_r_bud_task_id is NULL ) OR
3960 (p_record.Parent_resource_id <> g_pkt_r_prlmi or g_pkt_r_prlmi is NULL ) OR
3961 (p_record.resource_list_member_id <> g_pkt_r_rlmi or g_pkt_r_rlmi is NULL ) Then
3962
3963 OPEN res_tot_bc_pkt(p_record.resource_list_member_id,p_record.Parent_resource_id);
3964 IF g_debug_mode = 'Y' THEN
3965 log_message(p_msg_token1 =>'opened the cursor res_tot_bc_pkt');
3966 End if;
3967 FETCH res_tot_bc_pkt INTO l_pkt_amt
3968 ,l_r_enc_approved
3969 ,l_r_actual_approved ;
3970 -- assign the values to global variables to use as onelevel cache
3971 g_r_base_amt := l_pkt_amt;
3972 g_r_enc_approved := l_r_enc_approved;
3973 g_r_enc_pending := l_r_enc_pending;
3974 g_r_actual_approved := l_r_actual_approved;
3975 g_r_actual_pending := l_r_actual_pending;
3976 IF g_debug_mode = 'Y' THEN
3977 log_message(p_msg_token1 =>'fetch cursor res_tot_bc_pkt');
3978 End if;
3979 CLOSE res_tot_bc_pkt;
3980
3981 --added for performance test to use as one level cache
3982 g_pkt_r_project_id := p_record.project_id;
3983 g_pkt_r_bdgt_version_id := p_record.budget_version_id;
3984 g_pkt_r_bud_task_id := p_record.bud_task_id;
3985 g_pkt_r_rlmi := p_record.resource_list_member_id;
3986 g_pkt_r_prlmi := p_record.Parent_resource_id;
3987 g_pkt_r_entry_level_code := p_record.entry_level_code;
3988 g_pkt_r_start_date := trunc(p_start_date);
3989 g_pkt_r_end_date := trunc(p_end_date);
3990 g_pkt_r_time_phase_code := p_record.time_phased_type_code;
3991 ---------------------end of performance test --------------
3992
3993 ELSE
3994
3995 l_pkt_amt := g_r_base_amt;
3996 l_r_enc_approved := g_r_enc_approved;
3997 l_r_enc_pending := g_r_enc_pending;
3998 l_r_actual_approved := g_r_actual_approved;
3999 l_r_actual_pending := g_r_actual_pending;
4000 END IF; -- end of onelevel cache
4001 IF g_debug_mode = 'Y' THEN
4002 log_message(p_msg_token1 => 'l_pkt_amount ['||l_pkt_amt||
4003 ']l_r_enc_approved ['||l_r_enc_approved||']l_r_enc_pending ['||l_r_enc_pending||
4004 ']l_r_actual_approved ['||l_r_actual_approved||']l_r_actual_pending ['||l_r_actual_pending||']');
4005 End if;
4006
4007 l_available_amt := nvl(l_r_budget_posted,0) -
4008 (nvl(l_r_actual_posted,0) +
4009 nvl(l_r_enc_posted,0) +
4010 nvl(l_pkt_amt,0) +
4011 nvl(l_r_actual_approved,0) +
4012 nvl(l_r_enc_approved,0) +
4013 NVL(g_r_pkt_amt,0)
4014 );
4015 IF g_debug_mode = 'Y' THEN
4016 log_message(p_msg_token1 =>'avaialbe amt ='||l_available_amt);
4017 End if;
4018 IF p_record.status_code||p_record.actual_flag = 'AE' then
4019 l_r_enc_approved := nvl(l_r_enc_approved,0) +
4020 p_record.accounted_dr
4021 - p_record.accounted_cr;
4022 IF g_debug_mode = 'Y' THEN
4023 log_message(p_msg_token1 =>'r_enc_approv ='||l_r_enc_approved);
4024 End if;
4025 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4026 l_r_enc_pending := nvl(l_r_enc_pending,0) +
4027 p_record.accounted_dr
4028 - p_record.accounted_cr;
4029 IF g_debug_mode = 'Y' THEN
4030 log_message(p_msg_token1 =>'r enc pend ='||l_r_enc_pending);
4031 end if;
4032
4033 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4034 l_r_actual_approved := nvl(l_r_actual_approved,0) +
4035 p_record.accounted_dr
4036 - p_record.accounted_cr;
4037 IF g_debug_mode = 'Y' THEN
4038 log_message(p_msg_token1 =>'r actual approv ='||l_r_actual_approved);
4039 end if;
4040
4041 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4042 l_r_actual_pending := nvl(l_r_actual_pending,0) +
4043 p_record.accounted_dr
4044 - p_record.accounted_cr;
4045 IF g_debug_mode = 'Y' THEN
4046 log_message(p_msg_token1 =>'r_actual pending ='||l_r_actual_pending);
4047 end if;
4048
4049 END IF;
4050 l_r_budget_bal := l_available_amt;
4051 IF g_debug_mode = 'Y' THEN
4052 log_message(p_msg_token1 =>'calling generate result code api ');
4053 end if;
4054 generate_result_code(
4055 p_fclevel_code => p_record.r_funds_control_level_code,
4056 p_available_amt => l_available_amt,
4057 p_stage => l_stage,
4058 p_budget_posted_amt => l_r_budget_posted,
4059 x_result_code => l_result_code,
4060 x_r_result_code => l_r_result_code,
4061 x_rg_result_code => l_rg_result_code,
4062 x_t_result_code => l_t_result_code,
4063 x_tt_result_code => l_tt_result_code,
4064 x_p_result_code => l_p_result_code,
4065 x_p_acct_result_code => l_p_acct_result_code,
4066 x_return_status => l_return_status
4067 ) ;
4068 IF g_debug_mode = 'Y' THEN
4069 log_message(p_msg_token1 =>'end of generate result code api '
4070 ||'l_r_result_code ['||l_r_result_code||']l_result_code['||l_result_code||']' );
4071 End if;
4072
4073 IF l_return_status = 'F' THEN
4074 GOTO END_PROCESS;
4075 ELSE
4076 -- PROCEED TO NEXT STAGE ie RESOURCE GROUP LEVEL
4077 NULL;
4078 END IF;
4079
4080
4081 --********************************************************************
4082 -- RESOURCE GROUP LEVEL ------
4083 --*******************************************************************
4084 l_stage := 200;
4085 IF g_debug_mode = 'Y' THEN
4086 log_message(p_msg_token1 => 'Stage 200');
4087 end if;
4088
4089 /* Bug fix 2658952 : If the Budget is by resource only with no resource group then
4090 * donot check the balances at the resource group level
4091 * group_resoruce_type_id = 0 indicates resource group by is NONE in resource list */
4092
4093 IF NVL(p_record.group_resource_type_id,0) <> 0 Then
4094
4095 -- open the cursor for packet amounts at resource group level
4096 IF (p_record.project_id <> g_bal_rg_project_id OR g_bal_rg_project_id is NULL ) OR
4097 (p_record.budget_version_id <> g_bal_rg_bdgt_version_id or g_bal_rg_bdgt_version_id is NULL ) OR
4098 (p_record.time_phased_type_code <> g_bal_rg_time_phase_code or g_bal_rg_time_phase_code is NULL ) OR
4099 --(p_record.entry_level_code <> g_bal_rg_entry_level_code or g_bal_rg_entry_level_code is NULL ) OR
4100 (trunc(p_start_date) <> trunc(g_bal_rg_start_date) or g_bal_rg_start_date is NULL ) OR
4101 (trunc(p_end_date) <> trunc(g_bal_rg_end_date ) or g_bal_rg_end_date is NULL) OR
4102 (p_record.bud_task_id <> g_bal_rg_bud_task_id OR g_bal_rg_bud_task_id is NULL ) OR
4103 (p_record.Parent_resource_id <> g_bal_rg_prlmi or g_bal_rg_prlmi is NULL ) OR
4104 (p_record.bud_resource_list_member_id <> g_bal_rg_bud_rlmi or g_bal_rg_bud_rlmi is NULL ) Then
4105
4106 OPEN res_grp_level_bal (p_record.parent_resource_id,p_record.bud_resource_list_member_id);
4107 IF g_debug_mode = 'Y' THEN
4108 log_message(p_msg_token1 =>'opened res_grp_level_bal cursor ');
4109 End if;
4110 FETCH res_grp_level_bal INTO l_rg_budget_posted,
4111 l_rg_actual_posted,
4112 l_rg_enc_posted;
4113 CLOSE res_grp_level_bal;
4114 -- check whether the resource level budget balance is zero and control level
4115 -- is Absolute then check the budget by rolling up the balances from resource
4116 IF l_rg_budget_posted = 0 then
4117 OPEN res_rollup_bal (p_record.parent_resource_id);
4118 IF g_debug_mode = 'Y' THEN
4119 log_message(p_msg_token1 =>'rg budget posted is zero so open rollup cursor ');
4120 end if;
4121 FETCH res_rollup_bal INTO l_rg_budget_posted,
4122 l_rg_actual_posted,
4123 l_rg_enc_posted;
4124 CLOSE res_rollup_bal;
4125 END IF;
4126 g_rg_budget_posted := l_rg_budget_posted;
4127 g_rg_actual_posted := l_rg_actual_posted;
4128 g_rg_enc_posted := l_rg_enc_posted;
4129
4130 --- added for performance testing
4131 g_bal_rg_project_id := p_record.project_id;
4132 g_bal_rg_bdgt_version_id := p_record.budget_version_id;
4133 g_bal_rg_bud_task_id := p_record.bud_task_id;
4134 g_bal_rg_bud_rlmi := p_record.bud_resource_list_member_id;
4135 g_bal_rg_prlmi := p_record.parent_resource_id;
4136 g_bal_rg_entry_level_code := p_record.entry_level_code;
4137 g_bal_rg_start_date := trunc(p_start_date);
4138 g_bal_rg_end_date := trunc(p_end_date);
4139 g_bal_rg_time_phase_code := p_record.time_phased_type_code;
4140 ------------------ end of perfromance test ----
4141
4142 ELSE
4143 IF g_debug_mode = 'Y' THEN
4144 log_message(p_msg_token1 => 'same comination for res_grp bal cur');
4145 end if;
4146 l_rg_budget_posted := g_rg_budget_posted;
4147 l_rg_actual_posted := g_rg_actual_posted;
4148 l_rg_enc_posted := g_rg_enc_posted;
4149 END IF; -- end for one level cache
4150 IF g_debug_mode = 'Y' THEN
4151 log_message(p_msg_token1 =>'rg budget posted ['||l_rg_budget_posted||
4152 ']rg actual_posted [ '||l_rg_actual_posted||']rg enc_posted ['||l_rg_enc_posted ||']');
4153 end if;
4154
4155 -- open the cursor for packet amounts at resource group level
4156 IF (p_record.project_id <> g_pkt_rg_project_id OR g_pkt_rg_project_id is NULL ) OR
4157 (p_record.budget_version_id <> g_pkt_rg_bdgt_version_id or g_pkt_rg_bdgt_version_id is NULL ) OR
4158 --(p_record.time_phased_type_code <> g_pkt_rg_time_phase_code or g_pkt_rg_time_phase_code is NULL ) OR
4159 (p_record.entry_level_code <> g_pkt_rg_entry_level_code or g_pkt_rg_entry_level_code is NULL ) OR
4160 (trunc(p_start_date) <> trunc(g_pkt_rg_start_date) or g_pkt_rg_start_date is NULL ) OR
4161 (trunc(p_end_date) <> trunc(g_pkt_rg_end_date ) or g_pkt_rg_end_date is NULL) OR
4162 (p_record.bud_task_id <> g_pkt_rg_bud_task_id OR g_pkt_rg_bud_task_id is NULL ) OR
4163 (p_record.Parent_resource_id <> g_pkt_rg_prlmi or g_pkt_rg_prlmi is NULL) OR
4164 /* added for bug fix: 2658952 */
4165 (((p_record.Parent_resource_id = 0 and g_pkt_rg_rlmi <> p_record.resource_list_member_id)
4166 or (g_pkt_rg_rlmi is NULL and p_record.Parent_resource_id = 0 )) /* endof bug fix 2658952 */
4167 ) Then
4168
4169 OPEN res_grp_tot_bc_pkt(p_record.Parent_resource_id,p_record.resource_list_member_id);
4170 IF g_debug_mode = 'Y' THEN
4171 log_message(p_msg_token1 => 'opened the res_grp_tot_bc_pkt cursor ');
4172 end if;
4173 FETCH res_grp_tot_bc_pkt INTO l_pkt_amt
4174 ,l_rg_enc_approved
4175 ,l_rg_actual_approved ;
4176
4177 --store the values in global to use as one level cache
4178 g_rg_base_amt := l_pkt_amt;
4179 g_rg_enc_approved := l_rg_enc_approved;
4180 g_rg_enc_pending := l_rg_enc_pending;
4181 g_rg_actual_approved := l_rg_actual_approved;
4182 g_rg_actual_pending := l_rg_actual_pending;
4183 CLOSE res_grp_tot_bc_pkt;
4184
4185 --added for performance test to use as one level cache
4186 g_pkt_rg_project_id := p_record.project_id;
4187 g_pkt_rg_bdgt_version_id := p_record.budget_version_id;
4188 g_pkt_rg_bud_task_id := p_record.bud_task_id;
4189 g_pkt_rg_rlmi := p_record.resource_list_member_id;
4190 --g_pkt_rg_bud_rlmi := null;
4191 g_pkt_rg_prlmi := p_record.Parent_resource_id;
4192 g_pkt_rg_entry_level_code := p_record.entry_level_code;
4193 g_pkt_rg_start_date := trunc(p_start_date);
4194 g_pkt_rg_end_date := trunc(p_end_date);
4195 g_pkt_rg_time_phase_code := p_record.time_phased_type_code;
4196 ------------end of performance test --------------
4197
4198 ELSE
4199 IF g_debug_mode = 'Y' THEN
4200 log_message(p_msg_token1 => 'Same combination found at resgrppkt cursor');
4201 end if;
4202 l_pkt_amt := g_rg_base_amt ;
4203 l_rg_enc_approved := g_rg_enc_approved;
4204 l_rg_enc_pending := g_rg_enc_pending;
4205 l_rg_actual_approved := g_rg_actual_approved;
4206 l_rg_actual_pending := g_rg_actual_pending;
4207
4208 END IF ; -- end of one level cache
4209 IF g_debug_mode = 'Y' THEN
4210 log_message(p_msg_token1 => 'rg_l_pkt_amt ['||l_pkt_amt||
4211 ']rg_enc_approved ['||l_rg_enc_approved||']rg_rg_enc_pending ['||l_rg_enc_pending||
4212 ']rg_actual_approved [ '||l_rg_actual_approved||']rg_actual_pending ['||l_rg_actual_pending||']');
4213 End if;
4214
4215 l_available_amt := nvl(l_rg_budget_posted,0) -
4216 (nvl(l_rg_actual_posted,0) +
4217 nvl(l_rg_enc_posted,0) +
4218 nvl(l_pkt_amt,0) +
4219 nvl(l_rg_actual_approved,0) +
4220 nvl(l_rg_enc_approved,0) +
4221 nvl(g_rg_pkt_amt ,0)
4222 );
4223 IF g_debug_mode = 'Y' THEN
4224 log_message(p_msg_token1 => 'available_amt = '|| l_available_amt);
4225 End if;
4226 IF p_record.status_code||p_record.actual_flag = 'AE' then
4227 l_rg_enc_approved := nvl(l_rg_enc_approved,0) +
4228 p_record.accounted_dr
4229 - p_record.accounted_cr;
4230 IF g_debug_mode = 'Y' THEN
4231 log_message(p_msg_token1 =>'rg_enc_approved ='||l_rg_enc_approved);
4232 end if;
4233 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4234 l_rg_enc_pending := nvl(l_rg_enc_pending,0) +
4235 p_record.accounted_dr
4236 - p_record.accounted_cr;
4237 IF g_debug_mode = 'Y' THEN
4238 log_message(p_msg_token1 => 'rg_rg_enc_pending ='||l_rg_enc_pending);
4239 end if;
4240
4241 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4242 l_rg_actual_approved := nvl(l_rg_actual_approved,0) +
4243 p_record.accounted_dr
4244 - p_record.accounted_cr;
4245 IF g_debug_mode = 'Y' THEN
4246 log_message(p_msg_token1 => 'rg_actual_approved = '||l_rg_actual_approved);
4247 end if;
4248
4249 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4250 l_rg_actual_pending := nvl(l_rg_actual_pending,0) +
4251 p_record.accounted_dr
4252 - p_record.accounted_cr;
4253 IF g_debug_mode = 'Y' THEN
4254 log_message(p_msg_token1 => 'rg_actual_pending ='||l_rg_actual_pending);
4255 end if;
4256
4257 END IF;
4258 l_rg_budget_bal := l_available_amt;
4259 IF g_debug_mode = 'Y' THEN
4260 log_message(p_msg_token1 => 'calling generate_result_code at res rgp ');
4261 end if;
4262 generate_result_code(
4263 p_fclevel_code => p_record.rg_funds_control_level_code,
4264 p_available_amt => l_available_amt,
4265 p_stage => l_stage,
4266 p_budget_posted_amt => l_rg_budget_posted,
4267 x_result_code => l_result_code,
4268 x_r_result_code => l_r_result_code,
4269 x_rg_result_code => l_rg_result_code,
4270 x_t_result_code => l_t_result_code,
4271 x_tt_result_code => l_tt_result_code,
4272 x_p_result_code => l_p_result_code,
4273 x_p_acct_result_code => l_p_acct_result_code,
4274 x_return_status => l_return_status
4275 ) ;
4276 IF g_debug_mode = 'Y' THEN
4277 log_message(p_msg_token1 => 'end of generate_result_code api'||
4278 'l_rg_result_code [ '||l_rg_result_code||'l_result_code ['||l_result_code||']' );
4279 end if;
4280
4281 IF l_return_status = 'F' THEN
4282 GOTO END_PROCESS;
4283 ELSE
4284 -- PROCEED TO NEXT STAGE ie TASK LEVEL
4285 NULL;
4286 END IF;
4287
4288 ELSE
4289 -- Pass the transaction at resource group level if the resoource is not grouped
4290 -- by resource group
4291 l_rg_result_code := 'P109';
4292
4293 END IF ; -- end of group_resource_type_id /* bug fix 2658952 */
4294
4295 END IF; -- end if for budget categorization of resource
4296
4297 --******************************************************************************
4298 -- TASK LEVEL BALANCE ------
4299 --******************************************************************************
4300
4301 -- check whether the budget is by task if so then check the funds available at task level
4302 IF p_record.bud_task_id <> 0 then
4303 IF g_debug_mode = 'Y' THEN
4304 log_message(p_msg_token1 =>'Stage = 300');
4305 End if;
4306 l_stage := 300;
4307 -- open the cursor for packet amounts at task level
4308 IF (p_record.project_id <> g_bal_t_project_id OR g_bal_t_project_id is NULL ) OR
4309 (p_record.budget_version_id <> g_bal_t_bdgt_version_id or g_bal_t_bdgt_version_id is NULL ) OR
4310 (p_record.time_phased_type_code <> g_bal_t_time_phase_code or g_bal_t_time_phase_code is NULL ) OR
4311 --(p_record.entry_level_code <> g_bal_t_entry_level_code or g_bal_t_entry_level_code is NULL ) OR
4312 (trunc(p_start_date) <> trunc(g_bal_t_start_date) or g_bal_t_start_date is NULL ) OR
4313 (trunc(p_end_date) <> trunc(g_bal_t_end_date ) or g_bal_t_end_date is NULL) OR
4314 (p_record.task_id <> g_bal_t_task_id OR g_bal_t_task_id is NULL ) THEN
4315
4316
4317 OPEN task_level_bal (p_record.bud_task_id);
4318 IF g_debug_mode = 'Y' THEN
4319 log_message(p_msg_token1 =>'opened the cursor task_level_bal');
4320 end if;
4321 FETCH task_level_bal INTO l_t_budget_posted,
4322 l_t_actual_posted,
4323 l_t_enc_posted;
4324
4325 -- assign the fetched values to globals and use it as cache
4326 g_t_budget_posted := l_t_budget_posted;
4327 g_t_actual_posted := l_t_actual_posted;
4328 g_t_enc_posted := l_t_enc_posted;
4329
4330 CLOSE task_level_bal;
4331
4332 --- added for performance testing
4333 g_bal_t_project_id := p_record.project_id;
4334 g_bal_t_task_id := p_record.task_id;
4335 g_bal_t_bdgt_version_id := p_record.budget_version_id;
4336 g_bal_t_bud_task_id := p_record.bud_task_id;
4337 g_bal_t_bud_rlmi := p_record.bud_resource_list_member_id;
4338 g_bal_t_prlmi := p_record.parent_resource_id;
4339 g_bal_t_entry_level_code := p_record.entry_level_code;
4340 g_bal_t_start_date := trunc(p_start_date);
4341 g_bal_t_end_date := trunc(p_end_date);
4342 g_bal_t_time_phase_code := p_record.time_phased_type_code;
4343 -------------------- end of perfromance test ----
4344 ELSE
4345 IF g_debug_mode = 'Y' THEN
4346 log_message(p_msg_token1 => 'same combination found for task level bal');
4347 end if;
4348 l_t_budget_posted := g_t_budget_posted;
4349 l_t_actual_posted := g_t_actual_posted;
4350 l_t_enc_posted := g_t_enc_posted;
4351 END IF;
4352 IF g_debug_mode = 'Y' THEN
4353 log_message(p_msg_token1 =>'t_budget_posted ['||l_t_budget_posted||
4354 ']t_actual_posted ['||l_t_actual_posted||']tenc_posted ['||l_t_enc_posted||']');
4355 end if;
4356
4357 IF (p_record.project_id <> g_pkt_t_project_id OR g_pkt_t_project_id is NULL ) OR
4358 (p_record.budget_version_id <> g_pkt_t_bdgt_version_id or g_pkt_t_bdgt_version_id is NULL ) OR
4359 --(p_record.time_phased_type_code <> g_pkt_t_time_phase_code or g_pkt_t_time_phase_code is NULL ) OR
4360 (p_record.entry_level_code <> g_pkt_t_entry_level_code or g_pkt_t_entry_level_code is NULL ) OR
4361 (trunc(p_start_date) <> trunc(g_pkt_t_start_date) or g_pkt_t_start_date is NULL ) OR
4362 (trunc(p_end_date) <> trunc(g_pkt_t_end_date ) or g_pkt_t_end_date is NULL) OR
4363 (p_record.top_task_id <> g_pkt_t_top_task_id OR g_pkt_t_top_task_id is NULL ) OR
4364 (p_record.task_id <> g_pkt_t_task_id OR g_pkt_t_task_id is NULL ) THEN
4365
4366 OPEN task_tot_bc_pkt (p_record.task_id ,p_record.top_task_id );
4367 IF g_debug_mode = 'Y' THEN
4368 log_message(p_msg_token1 =>'opened task_tot_bc_pkt cursor ');
4369 end if;
4370 FETCH task_tot_bc_pkt INTO l_pkt_amt
4371 ,l_t_enc_approved
4372 ,l_t_actual_approved ;
4373 g_t_base_amt := l_pkt_amt;
4374 g_t_enc_approved := l_t_enc_approved;
4375 g_t_enc_pending := l_t_enc_pending;
4376 g_t_actual_approved := l_t_actual_approved;
4377 g_t_actual_pending := l_t_actual_pending;
4378
4379 CLOSE task_tot_bc_pkt;
4380
4381
4382 -- added for performance test
4383 g_pkt_t_project_id := p_record.project_id;
4384 g_pkt_t_task_id := p_record.task_id;
4385 g_pkt_t_top_task_id := p_record.top_task_id;
4386 g_pkt_t_bdgt_version_id := p_record.budget_version_id;
4387 g_pkt_t_prlmi := p_record.Parent_resource_id;
4388 g_pkt_t_entry_level_code := p_record.entry_level_code;
4389 g_pkt_t_start_date := trunc(p_start_date);
4390 g_pkt_t_end_date := trunc(p_end_date);
4391 g_pkt_t_time_phase_code := p_record.time_phased_type_code;
4392 ----------end of performance test --------------
4393
4394 ELSE
4395 --assign the values to global variables to use one level cache
4396 l_pkt_amt := g_t_base_amt;
4397 l_t_enc_approved := g_t_enc_approved;
4398 l_t_enc_pending := g_t_enc_pending;
4399 l_t_actual_approved := g_t_actual_approved;
4400 l_t_actual_pending := g_t_actual_pending;
4401 END IF;
4402 IF g_debug_mode = 'Y' THEN
4403 log_message(p_msg_token1 =>'pkt_amt ['||l_pkt_amt||
4404 ']t_enc_approved ['||l_t_enc_approved||']t_enc_pending [ '||l_t_enc_pending||
4405 ']t_actual_approved ['||l_t_actual_approved||']t_actual_pending ['||l_t_actual_pending||']');
4406 End if;
4407
4408 l_available_amt := nvl(l_t_budget_posted,0) -
4409 (nvl(l_t_actual_posted,0) +
4410 nvl(l_t_enc_posted,0) +
4411 nvl(l_pkt_amt,0) +
4412 nvl(l_t_actual_approved,0) +
4413 nvl(l_t_enc_approved,0) +
4414 nvl(g_t_pkt_amt,0)
4415 );
4416 IF g_debug_mode = 'Y' THEN
4417 log_message(p_msg_token1 =>'available_amt ='||l_available_amt);
4418 end if;
4419 IF p_record.status_code||p_record.actual_flag = 'AE' then
4420 l_t_enc_approved := nvl(l_t_enc_approved,0) +
4421 p_record.accounted_dr
4422 - p_record.accounted_cr;
4423 IF g_debug_mode = 'Y' THEN
4424 log_message(p_msg_token1 =>'t_enc_approved ='||l_t_enc_approved);
4425 end if;
4426 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4427 l_t_enc_pending := nvl(l_t_enc_pending,0) +
4428 p_record.accounted_dr
4429 - p_record.accounted_cr;
4430 IF g_debug_mode = 'Y' THEN
4431 log_message(p_msg_token1 =>'t_enc_pending = '||l_t_enc_pending);
4432 end if;
4433
4434 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4435 l_t_actual_approved := nvl(l_t_actual_approved,0) +
4436 p_record.accounted_dr
4437 - p_record.accounted_cr;
4438 IF g_debug_mode = 'Y' THEN
4439 log_message(p_msg_token1 =>'t_actual_approved ='||l_t_actual_approved);
4440 end if;
4441
4442 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4443 l_t_actual_pending := nvl(l_t_actual_pending,0) +
4444 p_record.accounted_dr
4445 - p_record.accounted_cr;
4446 IF g_debug_mode = 'Y' THEN
4447 log_message(p_msg_token1 =>'t_actual_pending ='||l_t_actual_pending);
4448 end if;
4449
4450 END IF;
4451 l_t_budget_bal := l_available_amt;
4452 IF g_debug_mode = 'Y' THEN
4453 log_message(p_msg_token1 =>'calling generate_result_code api ');
4454 end if;
4455 generate_result_code(
4456 p_fclevel_code => p_record.t_funds_control_level_code,
4457 p_available_amt => l_available_amt,
4458 p_stage => l_stage,
4459 p_budget_posted_amt => l_t_budget_posted,
4460 x_result_code => l_result_code,
4461 x_r_result_code => l_r_result_code,
4462 x_rg_result_code => l_rg_result_code,
4463 x_t_result_code => l_t_result_code,
4464 x_tt_result_code => l_tt_result_code,
4465 x_p_result_code => l_p_result_code,
4466 x_p_acct_result_code => l_p_acct_result_code,
4467 x_return_status => l_return_status
4468 ) ;
4469 IF g_debug_mode = 'Y' THEN
4470 log_message(p_msg_token1 =>'l_t_result_code = '||l_t_result_code||
4471 'l_result_code ='||l_result_code);
4472 end if;
4473 IF l_return_status = 'F' THEN
4474 GOTO END_PROCESS;
4475 ELSE
4476 -- PROCEED TO NEXT STAGE ie TOP TASK LEVEL
4477 NULL;
4478 END IF;
4479
4480 END IF;
4481 --*****************************************************************************
4482 --- TOP TASK LEVEL ------
4483 --******************************************************************************
4484 -- check whether the budget is by top task if so then check the funds available
4485 -- at top task level
4486 IF p_record.bud_task_id <> 0 then
4487
4488 l_stage := 400;
4489 -- open the cursor for packet amounts at top task level
4490 IF (p_record.project_id <> g_bal_tt_project_id OR g_bal_tt_project_id is NULL ) OR
4491 (p_record.budget_version_id <> g_bal_tt_bdgt_version_id or g_bal_tt_bdgt_version_id is NULL ) OR
4492 (p_record.time_phased_type_code <> g_bal_tt_time_phase_code or g_bal_tt_time_phase_code is NULL ) OR
4493 --(p_record.entry_level_code <> g_bal_tt_entry_level_code or g_bal_tt_entry_level_code is NULL ) OR
4494 (trunc(p_start_date) <> trunc(g_bal_tt_start_date) or g_bal_tt_start_date is NULL ) OR
4495 (trunc(p_end_date) <> trunc(g_bal_tt_end_date ) or g_bal_tt_end_date is NULL) OR
4496 (p_record.top_task_id <> g_bal_tt_top_task_id OR g_bal_tt_top_task_id is NULL ) OR
4497 (p_record.bud_task_id <> g_bal_tt_bud_task_id OR g_bal_tt_bud_task_id is NULL ) THEN
4498
4499 OPEN top_task_level_bal (p_record.bud_task_id ,p_record.top_task_id );
4500 IF g_debug_mode = 'Y' THEN
4501 log_message(p_msg_token1 =>'opened top_task_level_bal cursor ');
4502 end if;
4503 FETCH top_task_level_bal INTO l_tt_budget_posted,
4504 l_tt_actual_posted,
4505 l_tt_enc_posted;
4506 CLOSE top_task_level_bal;
4507
4508 If l_tt_budget_posted = 0 then
4509 IF g_debug_mode = 'Y' THEN
4510 log_message(p_msg_token1 =>'l_tt_budget_posted = 0 and opend roll up cursor');
4511 end if;
4512 -- rollup the task balance and check the funds avialable
4513 OPEN task_rollup_bal (p_record.top_task_id );
4514 FETCH task_rollup_bal INTO l_tt_budget_posted,
4515 l_tt_actual_posted,
4516 l_tt_enc_posted;
4517 CLOSE task_rollup_bal;
4518 End if;
4519 -- assign the values to globals to use as cache
4520 g_tt_budget_posted := l_tt_budget_posted;
4521 g_tt_actual_posted := l_tt_actual_posted;
4522 g_tt_enc_posted := l_tt_enc_posted;
4523
4524 --- added for performance testing to use as one level cache
4525 g_bal_tt_project_id := p_record.project_id;
4526 g_bal_tt_task_id := p_record.task_id;
4527 g_bal_tt_top_task_id := p_record.top_task_id;
4528 g_bal_tt_bdgt_version_id := p_record.budget_version_id;
4529 g_bal_tt_bud_task_id := p_record.bud_task_id;
4530 g_bal_tt_bud_rlmi := p_record.bud_resource_list_member_id;
4531 g_bal_tt_prlmi := p_record.parent_resource_id;
4532 g_bal_tt_entry_level_code := p_record.entry_level_code;
4533 g_bal_tt_start_date := trunc(p_start_date);
4534 g_bal_tt_end_date := trunc(p_end_date);
4535 g_bal_tt_time_phase_code := p_record.time_phased_type_code;
4536 -------------- end of perfromance test ----
4537
4538 ELSE
4539 IF g_debug_mode = 'Y' THEN
4540 log_message(p_msg_token1 => 'Same combination found at top task cursor');
4541 end if;
4542
4543 l_tt_budget_posted := g_tt_budget_posted;
4544 l_tt_actual_posted := g_tt_actual_posted;
4545 l_tt_enc_posted := g_tt_enc_posted;
4546 END IF;
4547 IF g_debug_mode = 'Y' THEN
4548 log_message(p_msg_token1 =>'tt_budget_posted ['||l_tt_budget_posted||
4549 ']tt_actual_posted ['||l_tt_actual_posted||']_tt_enc_posted ['||l_tt_enc_posted||']');
4550 end if;
4551
4552 IF (p_record.project_id <> g_pkt_tt_project_id OR g_pkt_tt_project_id is NULL ) OR
4553 (p_record.budget_version_id <> g_pkt_tt_bdgt_version_id or g_pkt_tt_bdgt_version_id is NULL ) OR
4554 --(p_record.time_phased_type_code <> g_pkt_tt_time_phase_code or g_pkt_tt_time_phase_code is NULL ) OR
4555 (p_record.entry_level_code <> g_pkt_tt_entry_level_code or g_pkt_tt_entry_level_code is NULL ) OR
4556 (trunc(p_start_date) <> trunc(g_pkt_tt_start_date) or g_pkt_tt_start_date is NULL ) OR
4557 (trunc(p_end_date) <> trunc(g_pkt_tt_end_date ) or g_pkt_tt_end_date is NULL) OR
4558 (p_record.top_task_id <> g_pkt_tt_top_task_id OR g_pkt_tt_top_task_id is NULL ) THEN
4559
4560
4561 OPEN top_task_tot_bc_pkt (p_record.top_task_id );
4562 IF g_debug_mode = 'Y' THEN
4563 log_message(p_msg_token1 =>'opend top_task_tot_bc_pkt cursor');
4564 end if;
4565 FETCH top_task_tot_bc_pkt INTO l_pkt_amt
4566 ,l_tt_enc_approved
4567 ,l_tt_actual_approved;
4568 g_tt_base_amt := l_pkt_amt;
4569 g_tt_enc_approved := l_tt_enc_approved;
4570 g_tt_enc_pending := l_tt_enc_pending;
4571 g_tt_actual_approved := l_tt_actual_approved;
4572 g_tt_actual_pending := l_tt_actual_pending;
4573 CLOSE top_task_tot_bc_pkt;
4574
4575 -- added for performance test
4576 g_pkt_tt_project_id := p_record.project_id;
4577 g_pkt_tt_task_id := p_record.task_id;
4578 g_pkt_tt_top_task_id := p_record.top_task_id;
4579 g_pkt_tt_bdgt_version_id := p_record.budget_version_id;
4580 --g_pkt_tt_bud_task_id := p_record.bud_task_id;
4581 --g_pkt_tt_rlmi := p_record.resource_list_member_id;
4582 --g_pkt_tt_bud_rlmi := null;
4583 g_pkt_tt_prlmi := p_record.Parent_resource_id;
4584 g_pkt_tt_entry_level_code := p_record.entry_level_code;
4585 g_pkt_tt_start_date := trunc(p_start_date);
4586 g_pkt_tt_end_date := trunc(p_end_date);
4587 g_pkt_tt_time_phase_code := p_record.time_phased_type_code;
4588 ---------end of performance test --------------
4589
4590 ELSE
4591 IF g_debug_mode = 'Y' THEN
4592 log_message(p_msg_token1 => 'same combination for top task pkt cursor');
4593 end if;
4594 l_pkt_amt := g_tt_base_amt;
4595 l_tt_enc_approved := g_tt_enc_approved;
4596 l_tt_enc_pending := g_tt_enc_pending;
4597 l_tt_actual_approved := g_tt_actual_approved;
4598 l_tt_actual_pending := g_tt_actual_pending;
4599 END IF; -- end of one level cache
4600 IF g_debug_mode = 'Y' THEN
4601 log_message(p_msg_token1 =>'pkt_amt ['||l_pkt_amt||
4602 ']tt_enc_approved ['||l_tt_enc_approved||']tt_enc_pending [ '||l_tt_enc_pending||
4603 ']tt_actual_approved ['||l_tt_actual_approved||']tt_actual_pending ['||l_tt_actual_pending|| ']' );
4604 end if;
4605
4606 l_available_amt := nvl(l_tt_budget_posted,0) -
4607 (nvl(l_tt_actual_posted,0) +
4608 nvl(l_tt_enc_posted,0) +
4609 nvl(l_pkt_amt,0) +
4610 nvl(l_tt_actual_approved,0) +
4611 nvl(l_tt_enc_approved,0) +
4612 nvl(g_tt_pkt_amt ,0)
4613 );
4614 IF g_debug_mode = 'Y' THEN
4615 log_message(p_msg_token1 =>'available_amt ='||l_available_amt);
4616 end if;
4617 IF p_record.status_code||p_record.actual_flag = 'AE' then
4618 l_tt_enc_approved := nvl(l_tt_enc_approved,0) +
4619 p_record.accounted_dr
4620 - p_record.accounted_cr;
4621 IF g_debug_mode = 'Y' THEN
4622 log_message(p_msg_token1 =>'tt_enc_approved ='||l_tt_enc_approved);
4623 end if;
4624 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4625 l_tt_enc_pending := nvl(l_tt_enc_pending,0) +
4626 p_record.accounted_dr
4627 - p_record.accounted_cr;
4628 IF g_debug_mode = 'Y' THEN
4629 log_message(p_msg_token1 =>'tt_enc_pending = '||l_tt_enc_pending);
4630 end if;
4631
4632 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4633 l_tt_actual_approved := nvl(l_tt_actual_approved,0) +
4634 p_record.accounted_dr
4635 - p_record.accounted_cr;
4636 IF g_debug_mode = 'Y' THEN
4637 log_message(p_msg_token1 =>'tt_actual_approved ='||l_tt_actual_approved);
4638 end if;
4639
4640 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4641 l_tt_actual_pending := nvl(l_tt_actual_pending,0) +
4642 p_record.accounted_dr
4643 - p_record.accounted_cr;
4644 IF g_debug_mode = 'Y' THEN
4645 log_message(p_msg_token1 =>'tt_actual_pending ='||l_tt_actual_pending);
4646 end if;
4647
4648 END IF;
4649 l_tt_budget_bal := l_available_amt;
4650 IF g_debug_mode = 'Y' THEN
4651 log_message(p_msg_token1 =>'calling generate_result_code at tt level ');
4652 end if;
4653 generate_result_code(
4654 p_fclevel_code => p_record.tt_funds_control_level_code,
4655 p_available_amt => l_available_amt,
4656 p_stage => l_stage,
4657 p_budget_posted_amt => l_tt_budget_posted,
4658 x_result_code => l_result_code,
4659 x_r_result_code => l_r_result_code,
4660 x_rg_result_code => l_rg_result_code,
4661 x_t_result_code => l_t_result_code,
4662 x_tt_result_code => l_tt_result_code,
4663 x_p_result_code => l_p_result_code,
4664 x_p_acct_result_code => l_p_acct_result_code,
4665 x_return_status => l_return_status
4666 ) ;
4667 IF g_debug_mode = 'Y' THEN
4668 log_message(p_msg_token1 =>'l_tt_result_code = '||l_tt_result_code||
4669 'l_result_code ='||l_result_code);
4670 end if;
4671
4672 IF l_return_status = 'F' THEN
4673 GOTO END_PROCESS;
4674 ELSE
4675 -- PROCEED TO NEXT STAGE ie PROJECT LEVEL
4676 NULL;
4677 END IF;
4678 END IF ; -- end if for top task level
4679 --*******************************************************************************
4680 -- FUNDS CHECK AT PROJECT LEVEL --------
4681 --******************************************************************************
4682 l_stage := 500;
4683 IF g_debug_mode = 'Y' THEN
4684 log_message(p_msg_token1 =>'stage = 500');
4685 end if;
4686
4687 IF (p_record.project_id <> g_bal_p_project_id OR g_bal_p_project_id is NULL ) OR
4688 (p_record.budget_version_id <> g_bal_p_bdgt_version_id or g_bal_p_bdgt_version_id is NULL ) OR
4689 (p_record.time_phased_type_code <> g_bal_p_time_phase_code or g_bal_p_time_phase_code is NULL ) OR
4690 --(p_record.entry_level_code <> g_bal_p_entry_level_code or g_bal_p_entry_level_code is NULL ) OR
4691 (trunc(p_start_date) <> trunc(g_bal_p_start_date) or g_bal_p_start_date is NULL ) OR
4692 (trunc(p_end_date) <> trunc(g_bal_p_end_date ) or g_bal_p_end_date is NULL) THEN
4693
4694 OPEN project_level_bal;
4695 IF g_debug_mode = 'Y' THEN
4696 log_message(p_msg_token1 =>'opened project level bal cursor ');
4697 end if;
4698 FETCH project_level_bal INTO l_p_budget_posted,
4699 l_p_actual_posted,
4700 l_p_enc_posted;
4701
4702 g_p_budget_posted := l_p_budget_posted;
4703 g_p_actual_posted := l_p_actual_posted;
4704 g_p_enc_posted := l_p_enc_posted;
4705 IF g_debug_mode = 'Y' THEN
4706 log_message(p_msg_token1 =>'p_budget_posted ['||l_p_budget_posted||
4707 ']p_actual_posted ['||l_p_actual_posted||']p_enc_posted ['||l_p_enc_posted||']' );
4708 end if;
4709
4710 CLOSE project_level_bal;
4711
4712 --- added for performance testing
4713 g_bal_p_project_id := p_record.project_id;
4714 g_bal_p_task_id := p_record.task_id;
4715 g_bal_p_top_task_id := p_record.top_task_id;
4716 g_bal_p_bdgt_version_id := p_record.budget_version_id;
4717 g_bal_p_bud_task_id := p_record.bud_task_id;
4718 g_bal_p_bud_rlmi := p_record.bud_resource_list_member_id;
4719 g_bal_p_prlmi := p_record.parent_resource_id;
4720 g_bal_p_entry_level_code := p_record.entry_level_code;
4721 g_bal_p_start_date := trunc(p_start_date);
4722 g_bal_p_end_date := trunc(p_end_date);
4723 g_bal_p_time_phase_code := p_record.time_phased_type_code;
4724 -------------- end of perfromance test ----
4725
4726 ELSE
4727 IF g_debug_mode = 'Y' THEN
4728 log_message(p_msg_token1 => 'Same combination for project cur ');
4729 end if;
4730 l_p_budget_posted := g_p_budget_posted;
4731 l_p_actual_posted := g_p_actual_posted;
4732 l_p_enc_posted := g_p_enc_posted;
4733 END IF;
4734 IF g_debug_mode = 'Y' THEN
4735 log_message(p_msg_token1 =>'p_budget_posted ['||l_p_budget_posted||
4736 ']p_actual_posted ['||l_p_actual_posted||']p_enc_posted ['||l_p_enc_posted||']' );
4737 end if;
4738
4739 IF (p_record.project_id <> g_pkt_p_project_id OR g_pkt_p_project_id is NULL ) OR
4740 (p_record.budget_version_id <> g_pkt_p_bdgt_version_id or g_pkt_p_bdgt_version_id is NULL ) OR
4741 --(p_record.time_phased_type_code <> g_pkt_p_time_phase_code or g_pkt_p_time_phase_code is NULL ) OR
4742 (p_record.entry_level_code <> g_pkt_p_entry_level_code or g_pkt_p_entry_level_code is NULL ) OR
4743 (trunc(p_start_date) <> trunc(g_pkt_p_start_date) or g_pkt_p_start_date is NULL ) OR
4744 (trunc(p_end_date) <> trunc(g_pkt_p_end_date ) or g_pkt_p_end_date is NULL) THEN
4745
4746 OPEN project_tot_bc_pkt ;
4747 IF g_debug_mode = 'Y' THEN
4748 log_message(p_msg_token1 =>'opened project_tot_bc_pkt cursor ');
4749 end if;
4750 FETCH project_tot_bc_pkt INTO l_pkt_amt
4751 ,l_p_enc_approved
4752 ,l_p_actual_approved ;
4753 g_p_base_amt := l_pkt_amt;
4754 g_p_enc_approved := l_p_enc_approved;
4755 g_p_enc_pending := l_p_enc_pending;
4756 g_p_actual_approved:= l_p_actual_approved;
4757 g_p_actual_pending := l_p_actual_pending;
4758
4759 CLOSE project_tot_bc_pkt;
4760
4761 -- added for performance test
4762 g_pkt_p_project_id := p_record.project_id;
4763 g_pkt_p_bdgt_version_id := p_record.budget_version_id;
4764 g_pkt_p_entry_level_code := p_record.entry_level_code;
4765 g_pkt_p_start_date := trunc(p_start_date);
4766 g_pkt_p_end_date := trunc(p_end_date);
4767 g_pkt_p_time_phase_code := p_record.time_phased_type_code;
4768 -------end of performance test --------------
4769
4770 ELSE
4771 IF g_debug_mode = 'Y' THEN
4772 log_message(p_msg_token1 => 'Same combination for project acct cursor');
4773 end if;
4774 l_pkt_amt := g_p_base_amt;
4775 l_p_enc_approved := g_p_enc_approved;
4776 l_p_enc_pending := g_p_enc_pending;
4777 l_p_actual_approved:= g_p_actual_approved;
4778 l_p_actual_pending := g_p_actual_pending;
4779
4780 END IF;
4781 IF g_debug_mode = 'Y' THEN
4782 log_message(p_msg_token1 =>'pkt_amt ['||l_pkt_amt||']p_enc_approved ='||l_p_enc_approved||
4783 ']p_enc_pending = '||l_p_enc_pending||']p_actual_approved ='||l_p_actual_approved||
4784 ']p_actual_pending ='||l_p_actual_pending||']' );
4785 end if;
4786
4787 l_available_amt := nvl(l_p_budget_posted,0) -
4788 (nvl(l_p_actual_posted,0) +
4789 nvl(l_p_enc_posted ,0)+
4790 nvl(l_pkt_amt,0) +
4791 nvl(l_p_actual_approved,0) +
4792 nvl(l_p_enc_approved,0) +
4793 nvl(g_p_pkt_amt ,0)
4794 );
4795 IF g_debug_mode = 'Y' THEN
4796 log_message(p_msg_token1 =>'available_amt ='||l_available_amt);
4797 end if;
4798 IF p_record.status_code||p_record.actual_flag = 'AE' then
4799 l_p_enc_approved := nvl(l_p_enc_approved,0) +
4800 p_record.accounted_dr
4801 - p_record.accounted_cr;
4802 IF g_debug_mode = 'Y' THEN
4803 log_message(p_msg_token1 =>'p_enc_approved ='||l_p_enc_approved);
4804 end if;
4805 ELSIF p_record.status_code||p_record.actual_flag = 'PE' then
4806 l_p_enc_pending := nvl(l_p_enc_pending,0) +
4807 p_record.accounted_dr
4808 - p_record.accounted_cr;
4809 IF g_debug_mode = 'Y' THEN
4810 log_message(p_msg_token1 =>'p_enc_pending = '||l_p_enc_pending);
4811 end if;
4812
4813 ELSIF p_record.status_code||p_record.actual_flag = 'AA' then
4814 l_p_actual_approved := nvl(l_p_actual_approved,0) +
4815 p_record.accounted_dr
4816 - p_record.accounted_cr;
4817 IF g_debug_mode = 'Y' THEN
4818 log_message(p_msg_token1 =>'p_actual_approved ='||l_p_actual_approved);
4819 end if;
4820
4821 ELSIF p_record.status_code||p_record.actual_flag = 'PA' then
4822 l_p_actual_pending := nvl(l_p_actual_pending,0) +
4823 p_record.accounted_dr
4824 - p_record.accounted_cr;
4825 IF g_debug_mode = 'Y' THEN
4826 log_message(p_msg_token1 =>'p_actual_pending ='||l_p_actual_pending);
4827 end if;
4828
4829 END IF;
4830 l_p_budget_bal := l_available_amt;
4831 IF g_debug_mode = 'Y' THEN
4832 log_message(p_msg_token1 =>'calling generate_result_code at p level ');
4833 end if;
4834 generate_result_code(
4835 p_fclevel_code => p_record.p_funds_control_level_code,
4836 p_available_amt => l_available_amt,
4837 p_stage => l_stage,
4838 p_budget_posted_amt => l_p_budget_posted,
4839 x_result_code => l_result_code,
4840 x_r_result_code => l_r_result_code,
4841 x_rg_result_code => l_rg_result_code,
4842 x_t_result_code => l_t_result_code,
4843 x_tt_result_code => l_tt_result_code,
4844 x_p_result_code => l_p_result_code,
4845 x_p_acct_result_code => l_p_acct_result_code,
4846 x_return_status => l_return_status
4847 ) ;
4848 IF g_debug_mode = 'Y' THEN
4849 log_message(p_msg_token1 =>'l_p_result_code = '||l_p_result_code||
4850 'l_result_code ='||l_result_code);
4851 log_message(p_msg_token1 =>'end of generate_result_code api ');
4852 end if;
4853
4854 IF l_return_status = 'F' THEN
4855 GOTO END_PROCESS;
4856 ELSE
4857 -- PROCEED TO NEXT STAGE ie PROJECT ACCOUNT LEVEL BAL
4858 NULL;
4859 END IF;
4860 --***************************************************************************
4861 -- FUNDS CHECK AT PROJECT ACCOUNT LEVEL BALANCE--
4862 --*************************************************************************
4863
4864 -- R12 change: Account level funds check should not be carried out here for re-baseline
4865 IF P_MODE NOT IN ('S','B') THEN
4866
4867 -- if the budget linked with Standard GL / External Budget then
4868 -- check the funds avaiable at account level for each transaction
4869 IF g_debug_mode = 'Y' THEN
4870 log_message(p_msg_token1 => 'funds check at project account level');
4871 End if;
4872 IF p_ext_bdgt_link = 'Y' then
4873 l_stage := 600;
4874 IF g_debug_mode = 'Y' THEN
4875 log_message(p_msg_token1 => 'Stage 600 calling Get_Acct_Line_Balance api'||
4876 'in parameters are budget_version_id ['||p_record.budget_version_id||
4877 ']p_start_date ['||p_start_date||']p_end_date ['||p_end_date||
4878 ']budget_ccid [ '||p_record.budget_ccid||']' );
4879 End if;
4880
4881 l_acct_level_bal := pa_funds_control_utils.Get_Acct_Line_Balance(
4882 p_budget_version_id => p_record.budget_version_id,
4883 p_start_date => p_start_date,
4884 p_end_date => p_end_date,
4885 p_budget_ccid => p_record.budget_ccid);
4886 IF g_debug_mode = 'Y' THEN
4887 log_message(p_msg_token1 =>'acct_level_bal ='||l_acct_level_bal);
4888 end if;
4889
4890 IF (p_record.project_id <> g_pkt_p_acct_project_id OR g_pkt_p_acct_project_id is NULL ) OR
4891 (p_record.budget_version_id <> g_pkt_p_acct_bdgt_version_id or g_pkt_p_acct_bdgt_version_id is NULL ) OR
4892 (p_record.budget_ccid <> g_pkt_p_acct_bdgt_ccid or g_pkt_p_acct_bdgt_ccid is NULL ) OR
4893 (trunc(p_start_date) <> trunc(g_pkt_p_acct_start_date) or g_pkt_p_acct_start_date is NULL ) OR
4894 (trunc(p_end_date) <> trunc(g_pkt_p_acct_end_date ) or g_pkt_p_acct_end_date is NULL) THEN
4895
4896 --r_msg('NEW PROJECT ACCT FOR PKT');
4897 OPEN project_acct_tot_bc_pkt(p_record.budget_ccid);
4898 IF g_debug_mode = 'Y' THEN
4899 log_message(p_msg_token1 => 'opened project_acct_tot_bc_pkt cursor ');
4900 end if;
4901 FETCH project_acct_tot_bc_pkt INTO l_pkt_amt,
4902 l_p_acct_enc_approved,
4903 l_p_acct_actual_approved;
4904
4905 g_p_acct_base_amt := l_pkt_amt;
4906 g_p_acct_enc_approved := l_p_acct_enc_approved;
4907 g_p_acct_actual_approved := l_p_acct_actual_approved;
4908 CLOSE project_acct_tot_bc_pkt;
4909
4910 -- added for performance test
4911 g_pkt_p_acct_project_id := p_record.project_id;
4912 g_pkt_p_acct_bdgt_version_id := p_record.budget_version_id;
4913 g_pkt_p_acct_bdgt_ccid := p_record.budget_ccid;
4914 g_pkt_p_acct_start_date := trunc(p_start_date);
4915 g_pkt_p_acct_end_date := trunc(p_end_date);
4916 g_pkt_p_acct_time_phase_code := p_record.time_phased_type_code;
4917 -----end of performance test --------------
4918
4919 ELSE
4920 l_pkt_amt := g_p_acct_base_amt;
4921 l_p_acct_enc_approved := g_p_acct_enc_approved;
4922 l_p_acct_actual_approved:= g_p_acct_actual_approved;
4923
4924 END IF;
4925 IF g_debug_mode = 'Y' THEN
4926 log_message(p_msg_token1 =>'l_p_acct_enc_approved ['||l_p_acct_enc_approved||
4927 ']l_p_acct_actual_approved ['||l_p_acct_actual_approved||
4928 ']l_p_acct_pkt_amt ['||l_pkt_amt||']g_p_acct_pkt_amt ['||g_p_acct_pkt_amt||']' );
4929 End if;
4930
4931 l_available_amt := nvl(l_acct_level_bal,0) -
4932 ( --nvl(l_p_acct_enc_approved,0) +
4933 -- nvl(l_p_acct_actual_approved,0) +
4934 nvl(l_pkt_amt,0) +
4935 nvl(g_p_acct_pkt_amt,0)
4936 );
4937 IF g_debug_mode = 'Y' THEN
4938 log_message(p_msg_token1 => 'available_amt ['||l_available_amt||']' );
4939 end if;
4940 generate_result_code(
4941 p_fclevel_code => p_record.p_funds_control_level_code,
4942 p_available_amt => l_available_amt,
4943 p_stage => l_stage,
4944 p_budget_posted_amt => l_acct_level_bal,
4945 x_result_code => l_result_code,
4946 x_r_result_code => l_r_result_code,
4947 x_rg_result_code => l_rg_result_code,
4948 x_t_result_code => l_t_result_code,
4949 x_tt_result_code => l_tt_result_code,
4950 x_p_result_code => l_p_result_code,
4951 x_p_acct_result_code => l_p_acct_result_code,
4952 x_return_status => l_return_status
4953 ) ;
4954 IF g_debug_mode = 'Y' THEN
4955 log_message(p_msg_token1 =>'End of generate result l_p_acct_result_code = '||
4956 l_p_acct_result_code||']l_result_code ['||l_result_code||']');
4957 End if;
4958
4959 END IF; -- external link check
4960
4961 END IF; --IF P_MODE NOT IN ('S','B') THEN
4962
4963 --Store the local values in global variables to use as one level cache
4964 g_project_id := p_record.project_id;
4965 g_top_task_id := p_record.top_task_id;
4966 g_task_id := p_record.task_id;
4967 g_bdgt_version_id := p_record.budget_version_id;
4968 g_bud_task_id := p_record.bud_task_id;
4969 g_rlmi := p_record.resource_list_member_id;
4970 g_bud_rlmi := p_record.bud_resource_list_member_id;
4971 g_prlmi := p_record.parent_resource_id;
4972 g_entry_level_code := p_record.entry_level_code;
4973 g_start_date := p_start_date;
4974 g_end_date := p_end_date;
4975 g_time_phase_code := p_record.time_phased_type_code;
4976 g_bdgt_ccid := p_record.budget_ccid;
4977
4978
4979
4980 <<END_PROCESS>>
4981 IF g_debug_mode = 'Y' THEN
4982 log_message(p_msg_token1 => 'End of process assiging out NOCOPY parameters with funds checked results');
4983 end if;
4984 -- Assign all out NOCOPY parameters with funds checked results
4985 p_record.r_budget_posted := l_r_budget_posted ;
4986 p_record.rg_budget_posted := l_rg_budget_posted;
4987 p_record.t_budget_posted := l_t_budget_posted;
4988 p_record.tt_budget_posted := l_tt_budget_posted ;
4989 p_record.p_budget_posted := l_p_budget_posted;
4990 p_record.r_actual_posted := l_r_actual_posted;
4991 p_record.rg_actual_posted := l_rg_actual_posted;
4992 p_record.t_actual_posted := l_t_actual_posted;
4993 p_record.tt_actual_posted := l_tt_actual_posted;
4994 p_record.p_actual_posted := l_p_actual_posted;
4995 p_record.r_enc_posted := l_r_enc_posted;
4996 p_record.rg_enc_posted := l_rg_enc_posted ;
4997 p_record.t_enc_posted := l_t_enc_posted ;
4998 p_record.tt_enc_posted := l_tt_enc_posted ;
4999 p_record.p_enc_posted := l_p_enc_posted;
5000 p_record.r_budget_bal := l_r_budget_bal;
5001 p_record.rg_budget_bal := l_rg_budget_bal ;
5002 p_record.t_budget_bal := l_t_budget_bal;
5003 p_record.tt_budget_bal := l_tt_budget_bal;
5004 p_record.p_budget_bal := l_p_budget_bal;
5005 p_record.r_actual_approved := l_r_actual_approved;
5006 p_record.rg_actual_approved := l_rg_actual_approved;
5007 p_record.t_actual_approved := l_t_actual_approved ;
5008 p_record.tt_actual_approved := l_tt_actual_approved;
5009 p_record.p_actual_approved := l_p_actual_approved ;
5010 p_record.r_enc_approved := l_r_enc_approved;
5011 p_record.rg_enc_approved := l_rg_enc_approved;
5012 p_record.t_enc_approved := l_t_enc_approved ;
5013 p_record.tt_enc_approved := l_tt_enc_approved;
5014 p_record.p_enc_approved := l_p_enc_approved;
5015 p_record.result_code := l_result_code;
5016 p_record.r_result_code := l_r_result_code;
5017 p_record.rg_result_code := l_rg_result_code;
5018 p_record.t_result_code := l_t_result_code;
5019 p_record.tt_result_code := l_tt_result_code;
5020 p_record.p_result_code := l_p_result_code;
5021 p_record.p_acct_result_code := l_p_acct_result_code;
5022
5023 g_pre_project_id := p_record.project_id;
5024 g_pre_top_task_id := p_record.top_task_id;
5025 g_pre_task_id := p_record.task_id;
5026 g_pre_bdgt_version_id := p_record.budget_version_id;
5027 g_pre_bud_task_id := p_record.bud_task_id;
5028 g_pre_rlmi := p_record.resource_list_member_id;
5029 g_pre_bud_rlmi := p_record.bud_resource_list_member_id;
5030 g_pre_prlmi := p_record.parent_resource_id;
5031 g_pre_entry_level_code := p_record.entry_level_code;
5032 g_pre_start_date := p_start_date;
5033 g_pre_end_date := p_end_date;
5034 g_pre_time_phase_code := p_record.time_phased_type_code;
5035 g_pre_bdgt_ccid := p_record.budget_ccid;
5036 IF g_debug_mode = 'Y' THEN
5037 log_message(p_msg_token1 => 'end of assignments sub string l_result_code ['||l_result_code||']' );
5038 end if;
5039
5040 IF substr(l_result_code,1,1) = 'F' and l_cached_satus = 'Y' then
5041 IF g_debug_mode = 'Y' THEN
5042 log_message(p_msg_token1 => 'calling cache pkt amounts to minus');
5043 end if;
5044 -- deduct this amount from the cache
5045 CACHE_PKT_AMOUNTS(
5046 p_project_id => p_record.project_id
5047 ,p_bdgt_version => p_record.budget_version_id
5048 ,p_top_task_id => p_record.top_task_id
5049 ,p_task_id => p_record.task_id
5050 ,p_bud_task_id => p_record.bud_task_id
5051 ,p_start_date => p_start_date
5052 ,p_end_date => p_end_date
5053 ,p_rlmi => p_record.resource_list_member_id
5054 ,p_bud_rlmi => p_record.bud_resource_list_member_id
5055 ,p_prlmi => p_record.parent_resource_id
5056 ,p_bdgt_ccid => p_record.budget_ccid
5057 ,p_accounted_dr => p_record.accounted_dr
5058 ,p_accounted_cr => p_record.accounted_cr
5059 ,p_calling_module => p_calling_module
5060 ,p_partial_flag => p_partial_flag
5061 ,p_function => 'MINUS'
5062 ,p_bc_packet_id => p_record.bc_packet_id
5063 ,p_doc_type => p_record.document_type
5064 ,p_doc_header_id => p_record.document_header_id
5065 ,p_doc_distribution_id =>p_record.document_distribution_id
5066 ,x_result_code => l_result_code
5067 ,x_cached_status => l_cached_satus
5068 ,p_counter => p_counter
5069 );
5070 END IF;
5071
5072
5073 IF res_level_bal%ISOPEN then
5074 CLOSE res_level_bal;
5075 END IF;
5076
5077 IF res_tot_bc_pkt%ISOPEN then
5078 CLOSE res_tot_bc_pkt;
5079 END IF;
5080
5081 IF res_grp_level_bal%ISOPEN THEN
5082 CLOSE res_grp_level_bal;
5083 END IF;
5084
5085 IF res_rollup_bal%ISOPEN THEN
5086 CLOSE res_rollup_bal;
5087 END IF;
5088 IF res_grp_tot_bc_pkt%ISOPEN THEN
5089 CLOSE res_grp_tot_bc_pkt;
5090 END IF;
5091 IF task_level_bal%ISOPEN THEN
5092 CLOSE task_level_bal;
5093 END IF;
5094 IF task_tot_bc_pkt%ISOPEN THEN
5095 CLOSE task_tot_bc_pkt;
5096 END IF;
5097 IF top_task_level_bal%ISOPEN THEN
5098 CLOSE top_task_level_bal;
5099 END IF;
5100 IF task_rollup_bal%ISOPEN THEN
5101 CLOSE task_rollup_bal;
5102 END IF;
5103 IF top_task_tot_bc_pkt%ISOPEN THEN
5104 CLOSE top_task_tot_bc_pkt;
5105 END IF;
5106 IF project_level_bal%ISOPEN THEN
5107 CLOSE project_level_bal;
5108 END IF;
5109 IF project_tot_bc_pkt%ISOPEN THEN
5110 CLOSE project_tot_bc_pkt;
5111 END IF;
5112 IF project_acct_tot_bc_pkt%ISOPEN THEN
5113 CLOSE project_acct_tot_bc_pkt;
5114 END IF;
5115 RETURN;
5116
5117 EXCEPTION
5118 WHEN OTHERS THEN
5119 IF g_debug_mode = 'Y' THEN
5120 log_message(p_msg_token1 => 'funds check failed due to unexpected error');
5121 end if;
5122 IF res_level_bal%ISOPEN then
5123 CLOSE res_level_bal;
5124 END IF;
5125
5126 IF res_tot_bc_pkt%ISOPEN then
5127 CLOSE res_tot_bc_pkt;
5128 END IF;
5129
5130 IF res_grp_level_bal%ISOPEN THEN
5131 CLOSE res_grp_level_bal;
5132 END IF;
5133
5134 IF res_rollup_bal%ISOPEN THEN
5135 CLOSE res_rollup_bal;
5136 END IF;
5137 IF res_grp_tot_bc_pkt%ISOPEN THEN
5138 CLOSE res_grp_tot_bc_pkt;
5139 END IF;
5140 IF task_level_bal%ISOPEN THEN
5141 CLOSE task_level_bal;
5142 END IF;
5143 IF task_tot_bc_pkt%ISOPEN THEN
5144 CLOSE task_tot_bc_pkt;
5145 END IF;
5146 IF top_task_level_bal%ISOPEN THEN
5147 CLOSE top_task_level_bal;
5148 END IF;
5149 IF task_rollup_bal%ISOPEN THEN
5150 CLOSE task_rollup_bal;
5151 END IF;
5152 IF top_task_tot_bc_pkt%ISOPEN THEN
5153 CLOSE top_task_tot_bc_pkt;
5154 END IF;
5155 IF project_level_bal%ISOPEN THEN
5156 CLOSE project_level_bal;
5157 END IF;
5158 IF project_tot_bc_pkt%ISOPEN THEN
5159 CLOSE project_tot_bc_pkt;
5160 END IF;
5161 IF project_acct_tot_bc_pkt%ISOPEN THEN
5162 CLOSE project_acct_tot_bc_pkt;
5163 END IF;
5164 IF g_debug_mode = 'Y' THEN
5165 log_message(p_msg_token1 => 'Exception in check_eunds_available SQLERR :'||sqlcode||sqlerrm);
5166 end if;
5167 --commit;
5168 Raise;
5169 END check_funds_available ;
5170 ---------------------------------------------------------------------------------
5171 -- This Api updates the pa_bc_packets with fundscheck amounts and result code
5172 -- after doing the fundscheck this api is in autonomous transaction
5173 ---------------------------------------------------------------------------------
5174 PROCEDURE update_pkt_amts(p_packet_id IN number) IS
5175 PRAGMA AUTONOMOUS_TRANSACTION;
5176 BEGIN
5177 IF g_debug_mode = 'Y' THEN
5178 log_message(p_msg_token1 => 'before update of pa bc packets ');
5179 End if;
5180 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
5181 UPDATE pa_bc_packets
5182 SET result_code = nvl(g_tab_result_code(i),result_code),
5183 res_result_code =nvl( g_tab_r_result_code(i),res_result_code),
5184 res_grp_result_code = nvl(g_tab_rg_result_code(i),res_grp_result_code),
5185 task_result_code = nvl(g_tab_t_result_code(i),task_result_code),
5186 top_task_result_code = nvl(g_tab_tt_result_code(i),top_task_result_code),
5187 project_result_code = nvl(g_tab_p_result_code(i),project_result_code),
5188 project_acct_result_code = nvl(g_tab_p_acct_result_code(i),project_acct_result_code),
5189 status_code = decode(nvl(g_tab_status_code(i),status_code),'Z','P',
5190 nvl(g_tab_status_code(i),status_code)),
5191 res_budget_posted =nvl( g_tab_r_budget_posted(i),res_budget_posted),
5192 res_grp_budget_posted = nvl(g_tab_rg_budget_posted(i),res_grp_budget_posted),
5193 task_budget_posted = nvl(g_tab_t_budget_posted(i),task_budget_posted),
5194 top_task_budget_posted = nvl(g_tab_tt_budget_posted(i),top_task_budget_posted),
5195 project_budget_posted = nvl(g_tab_p_budget_posted(i),project_budget_posted),
5196 res_actual_posted = nvl(g_tab_r_actual_posted(i),res_actual_posted ),
5197 res_grp_actual_posted = nvl(g_tab_rg_actual_posted(i),res_grp_actual_posted),
5198 task_actual_posted = nvl(g_tab_t_actual_posted(i),task_actual_posted),
5199 top_task_actual_posted = nvl(g_tab_tt_actual_posted(i),top_task_actual_posted),
5200 project_actual_posted = nvl(g_tab_p_actual_posted(i),project_actual_posted),
5201 res_enc_posted = nvl(g_tab_r_enc_posted(i),res_enc_posted),
5202 res_grp_enc_posted = nvl(g_tab_rg_enc_posted(i),res_grp_enc_posted),
5203 task_enc_posted = nvl(g_tab_t_enc_posted(i),task_enc_posted ),
5204 top_task_enc_posted = nvl(g_tab_tt_enc_posted(i),top_task_enc_posted),
5205 project_enc_posted = nvl(g_tab_p_enc_posted(i),project_enc_posted),
5206 res_budget_bal = nvl(g_tab_r_budget_bal(i),res_budget_bal),
5207 res_grp_budget_bal = nvl(g_tab_rg_budget_bal(i),res_grp_budget_bal),
5208 task_budget_bal = nvl(g_tab_t_budget_bal(i),task_budget_bal),
5209 top_task_budget_bal = nvl(g_tab_tt_budget_bal(i),top_task_budget_bal),
5210 project_budget_bal = nvl(g_tab_p_budget_bal(i),project_budget_bal),
5211 res_actual_approved = nvl(g_tab_r_actual_approved(i),res_actual_approved),
5212 res_grp_actual_approved = nvl(g_tab_rg_actual_approved(i),res_grp_actual_approved),
5213 task_actual_approved =nvl( g_tab_t_actual_approved(i),task_actual_approved),
5214 top_task_actual_approved = nvl(g_tab_tt_actual_approved(i),top_task_actual_approved),
5215 project_actual_approved = nvl(g_tab_p_actual_approved(i),project_actual_approved),
5216 res_enc_approved = nvl(g_tab_r_enc_approved(i),res_enc_approved),
5217 res_grp_enc_approved = nvl(g_tab_rg_enc_approved(i),res_grp_enc_approved),
5218 task_enc_approved = nvl(g_tab_t_enc_approved(i),task_enc_approved),
5219 top_task_enc_approved = nvl(g_tab_tt_enc_approved(i),top_task_enc_approved),
5220 project_enc_approved = nvl(g_tab_p_enc_approved(i),project_enc_approved)
5221 WHERE packet_id = p_packet_id
5222 AND rowid = g_tab_rowid(i);
5223 IF g_debug_mode = 'Y' THEN
5224 log_message(p_msg_token1 => 'End of FORALL update statement');
5225 End If;
5226
5227 commit;
5228 return;
5229
5230 EXCEPTION
5231 when others then
5232 raise;
5233 END update_pkt_amts;
5234 /** This api updates the Encumbrance approved bal for the packets
5235 * which contains transaction PO,AP,CC_P_PAY,CC_C_PAY
5236 * This API is primarily intended to update the encumbrance_approved_bal
5237 * to display in the funds check view form refer to Bug:2021199
5238 **/
5239 PROCEDURE update_enc_approvl_bal(p_packet_id IN pa_bc_packets.packet_id%type
5240 ,p_mode IN varchar2
5241 ,p_calling_module IN varchar2
5242 ) IS
5243 PRAGMA AUTONOMOUS_TRANSACTION;
5244
5245 /* Bug fix: 2658952 Transaction funds chekc screen not showing proper balances
5246 * If the inner sub query in update statement returns no rows then all the
5247 * enc approved columns are updated to zero
5248 * So moving the subquery into cursor and updating the bc_packets enc_approved
5249 * columns in a loop
5250 */
5251
5252 /** Bug fix : if Invoice has Tax lines then api fails with sql error
5253 ** ORA-01427: single-row subquery returns more than one row to avoid this
5254 ** sum() function has been used. For proper fix we need to add few columns to
5255 ** pa_bc_packets and pa_bc_commitments to distiguish the lines as ITEM / TAX
5256 ** the fix required here to add one more condition a.line_type = b.line_type
5257 **/
5258
5259 CURSOR updEnc(p_bc_pkt_id Number
5260 ,p_res_enc_approved Number
5261 ,p_res_grp_enc_approved Number
5262 ,p_task_enc_approved Number
5263 ,p_top_task_enc_approved Number
5264 ,p_project_enc_approved Number
5265 ) IS
5266 select decode(nvl(p_res_enc_approved,0),0,0,p_res_enc_approved -
5267 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5268 decode(nvl(p_res_grp_enc_approved,0),0,0,p_res_grp_enc_approved -
5269 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5270 decode(nvl(p_task_enc_approved,0),0,0,p_task_enc_approved -
5271 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5272 decode(nvl(p_top_task_enc_approved,0),0,0,p_top_task_enc_approved -
5273 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0))),
5274 decode(nvl(p_project_enc_approved,0),0,0,p_project_enc_approved -
5275 sum(nvl(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0),0)))
5276 from pa_bc_packets a
5277 ,pa_bc_packets b
5278 where
5279 a.packet_id = p_packet_id
5280 and a.bc_packet_id = p_bc_pkt_id
5281 and a.packet_id = b.packet_id
5282 and b.result_code like 'P%'
5283 and abs((nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0))) -
5284 abs((nvl(b.accounted_dr,0)-nvl(b.accounted_cr,0))) < .1
5285 and ( (a.parent_bc_packet_id is null and b.parent_bc_packet_id is null)
5286 or (a.parent_bc_packet_id is not null and b.parent_bc_packet_id is not null)
5287 )
5288 and ((( a.document_type = 'PO' and b.document_type = 'REQ')
5289 and exists ( select 'Y'
5290 from po_distributions_all po
5291 ,po_req_distributions_all req
5292 where req.distribution_id = b.document_distribution_id
5293 and po.po_distribution_id = a.document_distribution_id
5294 and po.req_distribution_id = req.distribution_id
5295 and a.packet_id = b.packet_id
5296 and a.bc_packet_id = p_bc_pkt_id
5297 and b.packet_id = p_packet_id
5298 )
5299 )
5300 OR (( a.document_type = 'AP' and b.document_type = 'PO' )
5301 and exists ( select 'Y'
5302 from po_distributions_all po
5303 ,ap_invoice_distributions_all ap
5304 where po.po_distribution_id = b.document_distribution_id
5305 and ap.invoice_id = a.document_header_id
5306 and ap.distribution_line_number = a.document_distribution_id
5307 and ap.po_distribution_id = po.po_distribution_id
5308 and a.packet_id = b.packet_id
5309 and a.bc_packet_id = p_bc_pkt_id
5310 and b.packet_id = p_packet_id
5311 )
5312 )
5313 OR (( a.document_type = 'AP' and b.document_type in ( 'CC_P_PAY','CC_C_PAY' ))
5314 and exists ( select 'Y'
5315 from po_distributions_all po
5316 ,ap_invoice_distributions_all ap
5317 where po.po_distribution_id = ap.po_distribution_id
5318 and ap.invoice_id = a.document_header_id
5319 and ap.distribution_line_number = a.document_distribution_id
5320 and po.req_header_reference_num = b.document_header_id
5321 and po.req_line_reference_num = b.document_distribution_id
5322 and a.packet_id = b.packet_id
5323 and a.bc_packet_id = p_bc_pkt_id
5324 and b.packet_id = p_packet_id
5325 )
5326 )
5327 OR (( a.document_type = 'EXP' and b.document_type = 'AP' )
5328 and (abs(nvl(a.accounted_dr,0) - nvl(a.accounted_cr,0)) =
5329 abs(nvl(b.accounted_dr,0) - nvl(b.accounted_cr,0)))
5330 and exists (select 'Y'
5331 from ap_invoice_distributions_all ap
5332 ,pa_bc_packets pbc
5333 where ap.invoice_id = b.document_header_id
5334 and ap.distribution_line_number = b.document_distribution_id
5335 /** and pbc.packet_id = 4003 commented out NOCOPY the hardcoded **/
5336 and pbc.packet_id = p_packet_id
5337 and pbc.document_distribution_id = a.document_distribution_id
5338 and pbc.document_header_id = a.document_header_id
5339 and pbc.document_type = 'EXP'
5340 and pbc.result_code like 'P%'
5341 and a.packet_id = b.packet_id
5342 and a.bc_packet_id = p_bc_pkt_id
5343 and b.packet_id = p_packet_id
5344 )
5345 )
5346 );
5347
5348
5349 CURSOR selEncDetails IS
5350 SELECT pkts.bc_packet_id,
5351 pkts.res_enc_approved,
5352 pkts.res_grp_enc_approved,
5353 pkts.task_enc_approved,
5354 pkts.top_task_enc_approved,
5355 pkts.project_enc_approved
5356 FROM pa_bc_packets pkts
5357 WHERE pkts.packet_id = p_packet_id
5358 AND nvl(pkts.accounted_dr,0) - nvl(pkts.accounted_cr,0) > 0
5359 AND substr(pkts.result_code ,1,1) = 'P';
5360
5361 l_num_rows Number := 200;
5362 l_r_enc_approved Number := Null;
5363 l_rg_enc_approved Number := Null;
5364 l_t_enc_approved Number := Null;
5365 l_tt_enc_approved Number := Null;
5366 l_p_enc_approved Number := Null;
5367
5368
5369 BEGIN
5370
5371 IF p_calling_module in ('GL','CBC') and p_mode in ('R','U','C') then
5372 IF g_debug_mode = 'Y' THEN
5373 log_message(p_msg_token1 => 'Inside update_enc_apprvoled_bal api');
5374 End If;
5375
5376 OPEN selEncDetails;
5377 IF g_debug_mode = 'Y' THEN
5378 log_message(p_msg_token1 => 'opened the selEncDetails cursor');
5379 End If;
5380 LOOP
5381
5382 init_plsql_tabs;
5383
5384 FETCH selEncDetails BULK COLLECT INTO
5385 g_tab_bc_packet_id,
5386 g_tab_r_enc_approved,
5387 g_tab_rg_enc_approved,
5388 g_tab_t_enc_approved,
5389 g_tab_tt_enc_approved,
5390 g_tab_p_enc_approved LIMIT l_num_rows;
5391
5392 IF NOT g_tab_bc_packet_id.EXISTS(1) then
5393 IF g_debug_mode = 'Y' THEN
5394 log_message(p_msg_token1 => 'Fetch rows is zero ');
5395 End if;
5396 EXIT;
5397 END IF;
5398
5399 FOR i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST LOOP
5400
5401 l_r_enc_approved := Null;
5402 l_rg_enc_approved := Null;
5403 l_t_enc_approved := Null;
5404 l_tt_enc_approved := Null;
5405 l_p_enc_approved := Null;
5406
5407 IF ( nvl(g_tab_r_enc_approved(i),0) <> 0 OR
5408 nvl(g_tab_rg_enc_approved(i),0) <> 0 OR
5409 nvl(g_tab_t_enc_approved(i),0) <> 0 OR
5410 nvl(g_tab_tt_enc_approved(i),0) <> 0 OR
5411 nvl(g_tab_p_enc_approved(i),0) <> 0 ) THEN
5412
5413 OPEN updEnc(g_tab_bc_packet_id(i)
5414 ,g_tab_r_enc_approved(i)
5415 ,g_tab_rg_enc_approved(i)
5416 ,g_tab_t_enc_approved(i)
5417 ,g_tab_tt_enc_approved(i)
5418 ,g_tab_p_enc_approved(i));
5419
5420 FETCH updEnc INTO l_r_enc_approved
5421 ,l_rg_enc_approved
5422 ,l_t_enc_approved
5423 ,l_tt_enc_approved
5424 ,l_p_enc_approved ;
5425
5426 CLOSE updEnc;
5427
5428 If nvl(l_r_enc_approved,0) <> 0 Then
5429 g_tab_r_enc_approved(i) := l_r_enc_approved;
5430 End If;
5431 If nvl(l_rg_enc_approved,0) <> 0 Then
5432 g_tab_rg_enc_approved(i) := l_rg_enc_approved;
5433 End If;
5434 If nvl(l_t_enc_approved,0) <> 0 Then
5435 g_tab_t_enc_approved(i) := l_t_enc_approved;
5436 End If;
5437 If nvl(l_tt_enc_approved,0) <> 0 Then
5438 g_tab_tt_enc_approved(i) := l_tt_enc_approved ;
5439 End If;
5440 If nvl(l_p_enc_approved,0) <> 0 Then
5441 g_tab_p_enc_approved(i) := l_p_enc_approved;
5442 End If;
5443
5444 END If;
5445
5446 END LOOP;
5447
5448 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
5449 UPDATE pa_bc_packets
5450 SET
5451 res_enc_approved = nvl(g_tab_r_enc_approved(i),res_enc_approved),
5452 res_grp_enc_approved = nvl(g_tab_rg_enc_approved(i),res_grp_enc_approved),
5453 task_enc_approved = nvl(g_tab_t_enc_approved(i),task_enc_approved),
5454 top_task_enc_approved = nvl(g_tab_tt_enc_approved(i),top_task_enc_approved),
5455 project_enc_approved = nvl(g_tab_p_enc_approved(i),project_enc_approved)
5456 WHERE packet_id = p_packet_id
5457 AND bc_packet_id = g_tab_bc_packet_id(i);
5458
5459 EXIT WHEN selEncDetails%NOTFOUND;
5460
5461 END LOOP;
5462 CLOSE selEncDetails;
5463
5464 END If;
5465 IF g_debug_mode = 'Y' THEN
5466 log_message(p_msg_token1 =>'End of update_enc_approved_bal api');
5467 End if;
5468
5469 COMMIT; -- to end an active autonomous transaction
5470
5471 EXCEPTION
5472
5473 when others then
5474 IF g_debug_mode = 'Y' THEN
5475 log_message(p_msg_token1 => 'Failed in update_enc_approval_bal api SQLERR:'||SQLCODE||SQLERRM);
5476 End if;
5477 Raise;
5478
5479 END update_enc_approvl_bal;
5480
5481 --------------------------------------------------------------------------------------------------------
5482 -- This api is called in partial mode, when funds check is called in partial mode
5483 -- funds check will be done on the basis of document_type and document_header_id for
5484 -- batch of 100 EI at a time this api is created to fix the bug :
5485 --------------------------------------------------------------------------------------------------------
5486 FUNCTION pa_fcp_process
5487 (p_sob IN NUMBER
5488 ,p_packet_id IN pa_bc_packets.packet_id%type
5489 ,p_mode IN varchar2
5490 ,p_partial_flag IN varchar2
5491 ,p_arrival_seq IN NUMBER
5492 ,p_reference1 IN varchar2
5493 ,p_reference2 IN varchar2
5494 ,p_calling_module IN varchar2
5495 ) return boolean IS
5496
5497 -- funds check will be done based on document_type and
5498 -- document_header_id. hence a batch of 100 EIS will be processed
5499 -- once.( if burden on diff item leades to 300 eis approximatly).
5500 l_tab_doc_type pa_plsql_datatypes.char50tabtyp;
5501 l_tab_effect_fc_level pa_plsql_datatypes.char50tabtyp;
5502 l_tab_doc_header_id pa_plsql_datatypes.idtabtyp;
5503 l_tab_bc_packet_id pa_plsql_datatypes.idtabtyp;
5504 l_num_rows NUMBER := 200;
5505 cursor cur_docs is
5506 SELECT document_type,
5507 document_header_id
5508 FROM pa_bc_packets
5509 WHERE packet_id = p_packet_id
5510 AND status_code = 'P'
5511 AND NVL(substr(result_code,1,1),'P') <> 'F'
5512 ORDER BY document_type,
5513 document_header_id;
5514
5515 -- this cursor picks all the transactions which are marked to
5516 -- intermediate status
5517 cursor cur_reset_doc_sts is
5518 SELECT bc_packet_id
5519 FROM pa_bc_packets
5520 WHERE packet_id = p_packet_id
5521 AND status_code = 'Z';
5522
5523 -- cursor to pick all the transaction which doesnot require funds check
5524 -- ie fc results in increase
5525 cursor cur_get_fc_incr_trxn is
5526 SELECT bc_packet_id,
5527 effect_on_funds_code
5528 FROM pa_bc_packets
5529 WHERE packet_id = p_packet_id
5530 AND status_code = 'P'
5531 AND nvl(substr(result_code,1,1),'P') <> 'F'
5532 AND effect_on_funds_code = 'I';
5533
5534 PROCEDURE update_docs_status
5535 (p_packet_id in number
5536 ,p_status_code in varchar2 ) IS
5537 PRAGMA AUTONOMOUS_TRANSACTION;
5538 BEGIN
5539
5540 IF p_status_code = 'Z' then
5541
5542 FORALL i IN l_tab_doc_header_id.FIRST .. l_tab_doc_header_id.LAST
5543 /* 4141729 - Added INDEX hint */
5544 UPDATE /*+ INDEX (pbp PA_BC_PACKETS_U1) */ pa_bc_packets
5545 SET status_code = p_status_code
5546 WHERE packet_id = p_packet_id
5547 AND document_type = l_tab_doc_type(i)
5548 AND document_header_id = l_tab_doc_header_id(i)
5549 AND status_code = 'P'
5550 AND nvl(substr(result_code,1,1),'P') <> 'F';
5551
5552 Elsif p_status_code = 'P' then
5553
5554 -- Reset the status code after processing
5555 FORALL i IN l_tab_bc_packet_id.FIRST .. l_tab_bc_packet_id.LAST
5556 UPDATE pa_bc_packets
5557 SET status_code = p_status_code
5558 WHERE packet_id = p_packet_id
5559 AND bc_packet_id = l_tab_bc_packet_id(i);
5560 Elsif p_status_code = 'I' then
5561 -- update the result codes to pass as the funds check result in
5562 -- increase in amounts
5563 FORALL i IN l_tab_bc_packet_id.FIRST .. l_tab_bc_packet_id.LAST
5564 UPDATE pa_bc_packets
5565 SET status_code = 'Z',
5566 result_code = 'P113',
5567 res_result_code = 'P113',
5568 res_grp_result_code = 'P113',
5569 task_result_code = 'P113',
5570 top_task_result_code = 'P113',
5571 project_result_code = 'P113',
5572 Project_acct_result_code = 'P113'
5573 WHERE packet_id = p_packet_id
5574 AND bc_packet_id = l_tab_bc_packet_id(i);
5575
5576 END IF;
5577
5578 commit;
5579 return;
5580 EXCEPTION
5581 when others then
5582 raise;
5583 END update_docs_status;
5584
5585
5586 BEGIN
5587 IF g_debug_mode = 'Y' THEN
5588 log_message(p_msg_token1 => 'partial flag = '||p_partial_flag);
5589 End if;
5590
5591 Initialize_globals;
5592 init_plsql_tabs;
5593 IF p_partial_flag = 'Y' then
5594 OPEN cur_docs;
5595 LOOP
5596 l_tab_doc_type.delete;
5597 l_tab_doc_header_id.delete;
5598 FETCH cur_docs BULK COLLECT INTO
5599 l_tab_doc_type,
5600 l_tab_doc_header_id LIMIT 100;
5601 IF NOT l_tab_doc_header_id.EXISTS(1) then
5602 IF g_debug_mode = 'Y' THEN
5603 log_message(p_msg_token1 => 'no recs found');
5604 End if;
5605 EXIT;
5606 END IF;
5607 IF g_debug_mode = 'Y' THEN
5608 log_message(p_msg_token1 => 'calling update_docs_status api');
5609 End if;
5610 -- update the status_code to intermediate state
5611 update_docs_status(p_packet_id, 'Z');
5612 IF g_debug_mode = 'Y' THEN
5613 log_message(p_msg_token1 => 'count of tab header id ='||l_tab_doc_header_id.count);
5614 End if;
5615
5616 /* Moved this here for bug 6378539*/
5617 exit when cur_docs%notfound;
5618 END LOOP;
5619 CLOSE cur_docs;
5620 /* End Bug 6378539 */
5621
5622 -- Call funds check pa_fck_process for batch of 100 eis
5623 IF g_debug_mode = 'Y' THEN
5624 log_message(p_msg_token1 => 'pa fck process in partial flag modepartial flag['||p_partial_flag);
5625 End if;
5626 IF NOT pa_fck_process
5627 (p_sob => p_sob
5628 ,p_packet_id => p_packet_id
5629 ,p_mode => p_mode
5630 ,p_partial_flag => p_partial_flag
5631 ,p_arrival_seq => p_arrival_seq
5632 ,p_reference1 => p_reference1
5633 ,p_reference2 => p_reference2
5634 --,p_reference3 => p_reference3
5635 ,p_calling_module => p_calling_module
5636 ) then
5637 IF g_debug_mode = 'Y' THEN
5638 log_message(p_msg_token1 =>
5639 'funds check failed during pa_fck_process api');
5640 End if;
5641 g_return_status := 'T';
5642 --log_message(p_return_status => 'T');
5643 END IF;
5644
5645 /* Commented this code for the bug 6378539
5646 exit when cur_docs%notfound;
5647
5648 END LOOP;
5649 CLOSE cur_docs;
5650 */
5651 Elsif p_partial_flag <> 'Y' then -- full mode
5652
5653 -- update the result codes of the all the transactions which
5654 -- donot require funds check
5655 OPEN cur_get_fc_incr_trxn;
5656 LOOP
5657 l_tab_bc_packet_id.delete;
5658 l_tab_effect_fc_level.delete;
5659 FETCH cur_get_fc_incr_trxn BULK COLLECT INTO
5660 l_tab_bc_packet_id,
5661 l_tab_effect_fc_level LIMIT l_num_rows;
5662
5663 IF not l_tab_bc_packet_id.EXISTS(1) then
5664 EXIT;
5665 END IF;
5666 -- update the result codes to pass
5667 IF g_debug_mode = 'Y' THEN
5668 log_message(p_msg_token1 => 'calling update_docs_status for Increase funds trxn');
5669 End if;
5670 update_docs_status(p_packet_id, 'I');
5671
5672 exit when cur_get_fc_incr_trxn%notfound;
5673
5674 END LOOP;
5675 CLOSE cur_get_fc_incr_trxn;
5676
5677 IF g_debug_mode = 'Y' THEN
5678 log_message(p_msg_token1 => 'calling pa fck process in full modepartial flag['||p_partial_flag);
5679 End if;
5680 -- Call funds check pa_fck_process for batch of 100 eis
5681 IF NOT pa_fck_process
5682 (p_sob => p_sob
5683 ,p_packet_id => p_packet_id
5684 ,p_mode => p_mode
5685 ,p_partial_flag => p_partial_flag
5686 ,p_arrival_seq => p_arrival_seq
5687 ,p_reference1 => p_reference1
5688 ,p_reference2 => p_reference2
5689 --,p_reference3 => p_reference3
5690 ,p_calling_module => p_calling_module
5691 ) then
5692 g_return_status := 'T';
5693 --log_message(p_return_status => 'T');
5694 END IF;
5695
5696 END IF;
5697 -- reset the status code back to earlier stage
5698 OPEN cur_reset_doc_sts;
5699 LOOP
5700 FETCH cur_reset_doc_sts BULK COLLECT INTO
5701 l_tab_bc_packet_id LIMIT 200;
5702
5703 IF not l_tab_bc_packet_id.EXISTS(1) then
5704 EXIT;
5705 END IF;
5706 IF g_debug_mode = 'Y' THEN
5707 log_message(p_msg_token1 => 'calling update_docs_status api to reset the status ');
5708 End if;
5709 -- update the status_code to intermediate state
5710 update_docs_status(p_packet_id, 'P');
5711
5712 EXIT when cur_reset_doc_sts%notfound;
5713 END LOOP;
5714 IF g_debug_mode = 'Y' THEN
5715 log_message(p_msg_token1 => 'end of cur_reset_doc_sts cursor');
5716 End if;
5717 CLOSE cur_reset_doc_sts;
5718
5719 IF cur_docs%isopen then
5720 close cur_docs;
5721 End if;
5722 IF cur_reset_doc_sts%isopen then
5723 close cur_reset_doc_sts;
5724 End if;
5725
5726 IF cur_get_fc_incr_trxn%isopen then
5727 close cur_get_fc_incr_trxn;
5728 End if;
5729
5730 /** Bug fix : 2021199 Transaction funds check form is not showing the
5731 * correct available balance when requision becomes Purchase order
5732 */
5733 /* bug fix : 2658952 moved this logic to form to derive encumbrance pending amount
5734 update_enc_approvl_bal(p_packet_id => p_packet_id
5735 ,p_calling_module => p_calling_module
5736 ,p_mode => p_mode);
5737 **/
5738 Return true;
5739
5740 EXCEPTION
5741
5742 when OTHERS then
5743 -- if there is any error then update the transaction
5744 -- back to earlier status from intermediate status
5745 -- reset the status code back to earlier stage
5746 OPEN cur_reset_doc_sts;
5747 LOOP
5748 FETCH cur_reset_doc_sts BULK COLLECT INTO
5749 l_tab_bc_packet_id LIMIT 200;
5750
5751 IF not l_tab_bc_packet_id.EXISTS(1) then
5752 EXIT;
5753 END IF;
5754 IF g_debug_mode = 'Y' THEN
5755 log_message(p_msg_token1 => 'calling update_docs_status api to reset the status ');
5756 End if;
5757 -- update the status_code to intermediate state
5758 update_docs_status(p_packet_id, 'P');
5759
5760 EXIT when cur_reset_doc_sts%notfound;
5761 END LOOP;
5762 IF g_debug_mode = 'Y' THEN
5763 log_message(p_msg_token1 => 'end of cur_reset_doc_sts cursor');
5764 End if;
5765 CLOSE cur_reset_doc_sts;
5766
5767 if cur_docs%isopen then
5768 close cur_docs;
5769 ENd if;
5770 IF cur_reset_doc_sts%isopen then
5771 close cur_reset_doc_sts;
5772 End if;
5773 IF cur_get_fc_incr_trxn%isopen then
5774 close cur_get_fc_incr_trxn;
5775 End if;
5776 IF g_debug_mode = 'Y' THEN
5777 log_message(p_msg_token1 => 'Failed in pa_fcp_process');
5778 End if;
5779 Raise;
5780 END pa_fcp_process;
5781 --------------------------------------------------------------------------------------------------------------
5782 -- This is an wrapper api for main funds check process where it make calls to CHECK_FUNDS_AVAILABLE api
5783 -- in a loop and updates the pa bc packets in batch of 200 records
5784 -------------------------------------------------------------------------------------------------------------
5785 FUNCTION pa_fck_process
5786 (p_sob IN NUMBER
5787 ,p_packet_id IN pa_bc_packets.packet_id%type
5788 ,p_mode IN varchar2
5789 ,p_partial_flag IN varchar2
5790 ,p_arrival_seq IN NUMBER
5791 ,p_reference1 IN varchar2
5792 ,p_reference2 IN varchar2
5793 --,p_reference3 IN varchar2
5794 ,p_calling_module IN varchar2
5795 ) return BOOLEAN is
5796
5797 -- this cursor picks all the details for a particular transaction whcih requires
5798 -- funds check
5799 CURSOR trxn_details IS
5800 SELECT pbc.rowid,
5801 pbc.bc_packet_id,
5802 pbv.budget_version_id ,
5803 pbc.project_id ,
5804 pbc.task_id ,
5805 pbc.document_type,
5806 pbc.document_header_id ,
5807 pbc.document_distribution_id,
5808 pbc.expenditure_item_date ,
5809 pbc.expenditure_organization_id ,
5810 pbc.actual_flag ,
5811 pbc.period_name ,
5812 pm.time_phased_type_code,
5813 pb.amount_type ,
5814 pb.boundary_code ,
5815 pm.entry_level_code,
5816 pm.categorization_code ,
5817 pbc.resource_list_member_id ,
5818 NVL(pbc.parent_resource_id,0) , /* Added for Bug fix: 2658952 */
5819 pbv.resource_list_id ,
5820 NVL(rlm.parent_member_id,0) , /* Added for Bug fix: 2658952 */
5821 pbc.bud_task_id ,
5822 pbc.bud_resource_list_member_id ,
5823 pbc.top_task_id ,
5824 pbc.r_funds_control_level_code ,
5825 pbc.rg_funds_control_level_code ,
5826 pbc.t_funds_control_level_code ,
5827 pbc.tt_funds_control_level_code ,
5828 pbc.p_funds_control_level_code ,
5829 pm.burdened_cost_flag ,
5830 nvl(pbc.accounted_dr,0) accounted_dr,
5831 nvl(pbc.accounted_cr,0) accounted_cr,
5832 nvl(pbc.accounted_dr ,0) - nvl(pbc.accounted_cr,0) pkt_trx_amt,
5833 decode(pbc.status_code||actual_flag,'PE',
5834 nvl(pbc.accounted_dr ,0)-nvl(pbc.accounted_cr,0)*1,0) PE_amt,
5835 decode(pbc.status_code||actual_flag,'PA',
5836 nvl(pbc.accounted_dr ,0)-nvl(pbc.accounted_cr,0)*1,0) PA_amt,
5837 pbc.status_code,
5838 pbc.effect_on_funds_code,
5839 pbc.result_code ,
5840 pbc.res_result_code ,
5841 pbc.res_grp_result_code ,
5842 pbc.task_result_code ,
5843 pbc.top_task_result_code ,
5844 pbc.project_result_code ,
5845 pbc.res_budget_posted,
5846 pbc.res_grp_budget_posted,
5847 pbc.task_budget_posted,
5848 pbc.top_task_budget_posted,
5849 pbc.project_budget_posted,
5850 pbc.res_actual_posted,
5851 pbc.res_grp_actual_posted,
5852 pbc.task_actual_posted,
5853 pbc.top_task_actual_posted,
5854 pbc.project_actual_posted,
5855 pbc.res_enc_posted,
5856 pbc.res_grp_enc_posted,
5857 pbc.task_enc_posted,
5858 pbc.top_task_enc_posted,
5859 pbc.project_enc_posted,
5860 pbc.res_budget_bal,
5861 pbc.res_grp_budget_bal,
5862 pbc.task_budget_bal,
5863 pbc.top_task_budget_bal,
5864 pbc.project_budget_bal,
5865 pbc.res_actual_approved,
5866 pbc.res_grp_actual_approved,
5867 pbc.task_actual_approved,
5868 pbc.top_task_actual_approved,
5869 pbc.project_actual_approved,
5870 pbc.res_enc_approved,
5871 pbc.res_grp_enc_approved,
5872 pbc.task_enc_approved,
5873 pbc.top_task_enc_approved,
5874 pbc.project_enc_approved ,
5875 pbc.effect_on_funds_code,
5876 pbc.txn_ccid,
5877 pbc.budget_ccid,
5878 pbc.gl_date,
5879 pbc.pa_date,
5880 pbc.parent_bc_packet_id,
5881 /** added for bug fix : 1992734 **/
5882 pbc.fc_start_date, /* PAM changes */
5883 pbc.fc_end_date,
5884 nvl(list.GROUP_RESOURCE_TYPE_ID,0) GROUP_RESOURCE_TYPE_ID, /* added for bug fix2658952 */
5885 pbc.ext_bdgt_flag
5886 FROM
5887 pa_bc_packets pbc,
5888 pa_budget_versions pbv,
5889 pa_budget_entry_methods pm,
5890 pa_budgetary_control_options pb,
5891 pa_projects_all pp,
5892 pa_resource_list_members rlm,
5893 PA_RESOURCE_LISTS_ALL_BG list
5894 WHERE pbc.packet_id = p_packet_id
5895 AND pbc.budget_version_id = pbv.budget_version_id
5896 AND pbv.budget_entry_method_code = pm.budget_entry_method_code
5897 AND pbc.resource_list_member_id = rlm.resource_list_member_id
5898 AND pp.project_id = pbc.project_id
5899 AND pbc.project_id = pb.project_id
5900 AND nvl(substr(pbc.result_code,1,1),'P') NOT IN ( 'F','R')
5901 AND ( (pbc.status_code = 'P'
5902 and p_partial_flag <> 'Y'
5903 )
5904 OR
5905 (pbc.status_code = 'Z'
5906 and p_partial_flag = 'Y')
5907 )
5908 AND pb.BDGT_CNTRL_FLAG = 'Y'
5909 AND pb.BUDGET_TYPE_CODE = pbv.budget_type_code
5910 AND ((pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
5911 and pb.EXTERNAL_BUDGET_CODE = 'GL')
5912 OR
5913 (pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
5914 and pb.EXTERNAL_BUDGET_CODE is NULL)
5915 OR
5916 (pbc.document_type in ('CC_P_CO','CC_C_CO')
5917 and pb.EXTERNAL_BUDGET_CODE = 'CC' )
5918 )
5919 /* added for bug fix 2658952 */
5920 AND list.RESOURCE_LIST_ID = rlm.RESOURCE_LIST_ID
5921 ORDER BY
5922 pbc.project_id,
5923 pbc.budget_version_id,
5924 pbc.fc_start_date , /** added for bug fix : 1992734 **/
5925 decode(p_partial_flag,'Y',pbc.effect_on_funds_code,0) desc,
5926 decode(p_calling_module,'DISTERADJ',pbc.document_header_id,0),
5927 pbc.task_id,
5928 pbc.bud_task_id,
5929 NVL(pbc.parent_resource_id,0) , /* Added for Bug fix: 2658952 */
5930 pbc.resource_list_member_id,
5931 pbc.bud_resource_list_member_id,
5932 nvl(pbc.accounted_dr,0) - nvl(pbc.accounted_cr,0)
5933 ;
5934 l_previous_bdgt_version_id NUMBER;
5935 l_num_rows NUMBER := 200;
5936 l_status_code VARCHAR2(1) := 'P';
5937 l_return_status VARCHAR2(1) := 'S';
5938 l_prv_project_id NUMBER := null;
5939 l_ext_bdgt_type VARCHAR2(10);
5940 l_ext_bdgt_link VARCHAR2(1);
5941 l_prv_ext_bdgt_type VARCHAR2(10) := null;
5942 l_fc_record pa_fc_record;
5943 l_start_date DATE;
5944 l_end_date DATE;
5945 l_result_code VARCHAR2(20);
5946 l_error_stage VARCHAR2(20);
5947 l_error_msg VARCHAR2(2000);
5948 l_error_code number;
5949 l_date_for_calc Date;
5950
5951 l_prv_time_phase VARCHAR2(20):= null;
5952 l_prv_exp_item_date DATE := null;
5953 l_prv_amount_type VARCHAR2(20):= null;
5954 l_prv_boundary_code VARCHAR2(20):= null;
5955 l_prv_sob NUMBER := null;
5956 l_prv_bdgt_version_id NUMBER := null;
5957 l_prv_gl_date DATE := null;
5958 l_prv_pa_date DATE := null;
5959
5960 l_counter number := 0;
5961
5962 BEGIN
5963
5964 IF p_partial_flag = 'Y' then
5965 l_num_rows := 100000;
5966 Else
5967 l_num_rows := 200;
5968 ENd IF;
5969 IF g_debug_mode = 'Y' THEN
5970 log_message(p_msg_token1 => 'Inside the pa_fck_process');
5971 End if;
5972 OPEN trxn_details;
5973 IF g_debug_mode = 'Y' THEN
5974 log_message(p_msg_token1 => 'opened the trxn details cursor');
5975 End if;
5976 LOOP -- start of the batch process
5977 -- initialize the pl/sql tables fecth the values into tables
5978 init_plsql_tabs;
5979 FETCH trxn_details BULK COLLECT INTO
5980 g_tab_rowid,
5981 g_tab_bc_packet_id,
5982 g_tab_budget_version_id ,
5983 g_tab_project_id ,
5984 g_tab_task_id ,
5985 g_tab_doc_type,
5986 g_tab_doc_header_id ,
5987 g_tab_doc_distribution_id,
5988 g_tab_exp_item_date ,
5989 g_tab_exp_org_id ,
5990 g_tab_actual_flag ,
5991 g_tab_period_name ,
5992 g_tab_time_phase_type_code,
5993 g_tab_amount_type ,
5994 g_tab_boundary_code ,
5995 g_tab_entry_level_code,
5996 g_tab_category_code ,
5997 g_tab_rlmi ,
5998 g_tab_p_resource_id ,
5999 g_tab_r_list_id ,
6000 g_tab_p_member_id ,
6001 g_tab_bud_task_id ,
6002 g_tab_bud_rlmi ,
6003 g_tab_tt_task_id ,
6004 g_tab_r_fclevel_code ,
6005 g_tab_rg_fclevel_code ,
6006 g_tab_t_fclevel_code ,
6007 g_tab_tt_fclevel_code ,
6008 g_tab_p_fclevel_code ,
6009 g_tab_burd_cost_flag ,
6010 g_tab_accounted_dr,
6011 g_tab_accounted_cr,
6012 g_tab_pkt_trx_amt,
6013 g_tab_PE_amt,
6014 g_tab_PA_amt,
6015 g_tab_status_code,
6016 g_tab_effect_on_funds_code,
6017 g_tab_result_code ,
6018 g_tab_r_result_code ,
6019 g_tab_rg_result_code ,
6020 g_tab_t_result_code ,
6021 g_tab_tt_result_code ,
6022 g_tab_p_result_code ,
6023 g_tab_r_budget_posted,
6024 g_tab_rg_budget_posted,
6025 g_tab_t_budget_posted,
6026 g_tab_tt_budget_posted,
6027 g_tab_p_budget_posted,
6028 g_tab_r_actual_posted,
6029 g_tab_rg_actual_posted,
6030 g_tab_t_actual_posted,
6031 g_tab_tt_actual_posted,
6032 g_tab_p_actual_posted,
6033 g_tab_r_enc_posted,
6034 g_tab_rg_enc_posted,
6035 g_tab_t_enc_posted,
6036 g_tab_tt_enc_posted,
6037 g_tab_p_enc_posted,
6038 g_tab_r_budget_bal,
6039 g_tab_rg_budget_bal,
6040 g_tab_t_budget_bal,
6041 g_tab_tt_budget_bal,
6042 g_tab_p_budget_bal,
6043 g_tab_r_actual_approved,
6044 g_tab_rg_actual_approved,
6045 g_tab_t_actual_approved,
6046 g_tab_tt_actual_approved,
6047 g_tab_p_actual_approved,
6048 g_tab_r_enc_approved,
6049 g_tab_rg_enc_approved,
6050 g_tab_t_enc_approved,
6051 g_tab_tt_enc_approved,
6052 g_tab_p_enc_approved,
6053 g_tab_effect_fclevel,
6054 g_tab_trxn_ccid,
6055 g_tab_budget_ccid,
6056 g_tab_gl_date,
6057 g_tab_pa_date,
6058 g_tab_p_bc_packet_id,
6059 g_tab_start_date,
6060 g_tab_end_date,
6061 g_tab_group_resource_type_id,
6062 g_tab_ext_bdgt_link LIMIT l_num_rows;
6063 IF g_debug_mode = 'Y' THEN
6064 log_message(p_msg_token1 => 'after fectch num rows'||g_tab_doc_header_id.count);
6065 End if;
6066
6067 IF NOT g_tab_rowid.EXISTS(1) then
6068 IF g_debug_mode = 'Y' THEN
6069 log_message(p_msg_token1 => 'Fetch rows is zero ');
6070 END IF;
6071 EXIT;
6072 END IF;
6073
6074
6075
6076 -- For each record in table loop through derive start and end dates
6077 -- check the availability of funds
6078 l_counter := 0;
6079 FOR i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST LOOP
6080 l_counter := l_counter + 1;
6081 IF g_debug_mode = 'Y' THEN
6082 log_message(p_msg_token1 => 'Initizaling the record with in FOR loop');
6083 End if;
6084 -- Initialize the funds check record
6085 initialize_record(l_fc_record);
6086
6087 l_fc_record.packet_id := p_packet_id;
6088 l_fc_record.bc_packet_id := g_tab_bc_packet_id(i);
6089 l_fc_record.set_of_books_id := p_sob;
6090 l_fc_record.budget_version_id := g_tab_budget_version_id(i);
6091 l_fc_record.project_id := g_tab_project_id(i);
6092 l_fc_record.task_id := g_tab_task_id(i);
6093 l_fc_record.document_type := g_tab_doc_type(i);
6094 l_fc_record.document_header_id := g_tab_doc_header_id(i);
6095 l_fc_record.document_distribution_id := g_tab_doc_distribution_id(i);
6096 l_fc_record.expenditure_item_date := g_tab_exp_item_date(i);
6097 l_fc_record.expenditure_organization_id := g_tab_exp_org_id(i);
6098 l_fc_record.actual_flag := g_tab_actual_flag(i);
6099 l_fc_record.period_name := g_tab_period_name(i);
6100 l_fc_record.time_phased_type_code := g_tab_time_phase_type_code(i);
6101 l_fc_record.amount_type := g_tab_amount_type(i);
6102 l_fc_record.boundary_code := g_tab_boundary_code(i);
6103 l_fc_record.entry_level_code := g_tab_entry_level_code(i);
6104 l_fc_record.categorization_code := g_tab_category_code(i);
6105 l_fc_record.resource_list_member_id := g_tab_rlmi(i);
6106 l_fc_record.parent_resource_id := g_tab_p_resource_id(i);
6107 l_fc_record.resource_list_id := g_tab_r_list_id(i);
6108 l_fc_record.parent_member_id := g_tab_p_member_id(i);
6109 l_fc_record.bud_task_id := g_tab_bud_task_id(i);
6110 l_fc_record.bud_resource_list_member_id := g_tab_bud_rlmi(i);
6111 l_fc_record.top_task_id := g_tab_tt_task_id(i);
6112 l_fc_record.r_funds_control_level_code := g_tab_r_fclevel_code(i);
6113 l_fc_record.rg_funds_control_level_code := g_tab_rg_fclevel_code(i);
6114 l_fc_record.t_funds_control_level_code := g_tab_t_fclevel_code(i);
6115 l_fc_record.tt_funds_control_level_code := g_tab_tt_fclevel_code(i);
6116 l_fc_record.p_funds_control_level_code := g_tab_p_fclevel_code(i);
6117 l_fc_record.burdened_cost_flag := g_tab_burd_cost_flag(i);
6118 l_fc_record.accounted_dr := g_tab_accounted_dr(i);
6119 l_fc_record.accounted_cr := g_tab_accounted_cr(i);
6120 l_fc_record.status_code := l_status_code;
6121 l_fc_record.r_budget_posted := g_tab_r_budget_posted(i);
6122 l_fc_record.rg_budget_posted := g_tab_rg_budget_posted(i);
6123 l_fc_record.t_budget_posted := g_tab_t_budget_posted(i);
6124 l_fc_record.tt_budget_posted := g_tab_tt_budget_posted(i);
6125 l_fc_record.p_budget_posted := g_tab_p_budget_posted(i);
6126 l_fc_record.r_actual_posted := g_tab_r_actual_posted(i);
6127 l_fc_record.rg_actual_posted := g_tab_rg_actual_posted(i);
6128 l_fc_record.t_actual_posted := g_tab_t_actual_posted(i);
6129 l_fc_record.tt_actual_posted := g_tab_tt_actual_posted(i);
6130 l_fc_record.p_actual_posted := g_tab_p_actual_posted(i);
6131 l_fc_record.r_enc_posted := g_tab_r_enc_posted(i);
6132 l_fc_record.rg_enc_posted := g_tab_rg_enc_posted(i);
6133 l_fc_record.t_enc_posted := g_tab_t_enc_posted(i);
6134 l_fc_record.tt_enc_posted := g_tab_tt_enc_posted(i);
6135 l_fc_record.p_enc_posted := g_tab_p_enc_posted(i);
6136 l_fc_record.r_budget_bal := g_tab_r_budget_bal(i);
6137 l_fc_record.rg_budget_bal := g_tab_rg_budget_bal(i);
6138 l_fc_record.t_budget_bal := g_tab_t_budget_bal(i);
6139 l_fc_record.tt_budget_bal := g_tab_tt_budget_bal(i);
6140 l_fc_record.p_budget_bal := g_tab_p_budget_bal(i);
6141 l_fc_record.r_actual_approved := g_tab_r_actual_approved(i);
6142 l_fc_record.rg_actual_approved := g_tab_rg_actual_approved(i);
6143 l_fc_record.t_actual_approved := g_tab_t_actual_approved(i);
6144 l_fc_record.tt_actual_approved := g_tab_tt_actual_approved(i);
6145 l_fc_record.p_actual_approved := g_tab_p_actual_approved(i);
6146 l_fc_record.r_enc_approved := g_tab_r_enc_approved(i);
6147 l_fc_record.rg_enc_approved := g_tab_rg_enc_approved(i);
6148 l_fc_record.t_enc_approved := g_tab_t_enc_approved(i);
6149 l_fc_record.tt_enc_approved := g_tab_tt_enc_approved(i);
6150 l_fc_record.p_enc_approved := g_tab_p_enc_approved(i);
6151 l_fc_record.result_code := g_tab_result_code(i);
6152 l_fc_record.r_result_code := g_tab_r_result_code(i);
6153 l_fc_record.rg_result_code := g_tab_rg_result_code(i);
6154 l_fc_record.t_result_code := g_tab_t_result_code(i);
6155 l_fc_record.tt_result_code := g_tab_tt_result_code(i);
6156 l_fc_record.p_result_code := g_tab_p_result_code(i);
6157 l_fc_record.effect_on_funds_code := g_tab_effect_fclevel(i);
6158 l_fc_record.trxn_ccid := g_tab_trxn_ccid(i);
6159 l_fc_record.budget_ccid := g_tab_budget_ccid(i);
6160 l_fc_record.gl_date := g_tab_gl_date(i);
6161 l_fc_record.pa_date := g_tab_pa_date(i);
6162 l_fc_record.parent_bc_packet_id := g_tab_p_bc_packet_id(i);
6163 l_fc_record.group_resource_type_id := g_tab_group_resource_type_id(i);
6164 -- check whether the budget type is STD or CBC and budget is Linked with GL
6165 If l_fc_record.document_type in ('AP','PO','REQ','EXP','CC_C_PAY','CC_P_PAY' ) THEN
6166 l_ext_bdgt_type := 'STD';
6167 Else
6168 l_ext_bdgt_type := 'CBC';
6169 End if;
6170
6171 IF g_debug_mode = 'Y' THEN
6172 log_message(p_msg_token1 =>'start date['||g_tab_start_date(i)||']end date['||g_tab_end_date(i)||']');
6173 End if;
6174 l_start_date := g_tab_start_date(i);
6175 l_end_date := g_tab_end_date(i);
6176 l_ext_bdgt_link := g_tab_ext_bdgt_link(i);
6177
6178 If g_tab_start_date(i) is not null and g_tab_end_date(i) is not null then
6179
6180 check_funds_available (
6181 p_sob => p_sob,
6182 p_mode => p_mode,
6183 p_packet_id => p_packet_id,
6184 p_record => l_fc_record, -- IN OUT NOCOPY param
6185 p_arrival_seq => p_arrival_seq,
6186 p_status_code => l_status_code,
6187 p_ext_bdgt_link => l_ext_bdgt_link,
6188 p_ext_bdgt_type => l_ext_bdgt_type,
6189 p_start_date => l_start_date,
6190 p_end_date => l_end_date,
6191 p_calling_module => p_calling_module,
6192 p_partial_flag => p_partial_flag,
6193 p_counter => l_counter
6194 );
6195 If g_debug_mode = 'Y' Then
6196 log_message(p_msg_token1 => 'after the check funds available api');
6197 End if;
6198 Else -- assign the result code derived during the start date and end date
6199 -- proceed to next record for funds check
6200 /** commented for bug fix : 1992734 **/
6201 --l_fc_record.result_code := l_result_code;
6202 l_fc_record.result_code := 'F136';
6203
6204 End if;
6205
6206
6207
6208 --- Assign the OUT NOCOPY parameter values to pl / sql tables
6209 IF g_debug_mode = 'Y' THEN
6210 log_message(p_msg_token1 => 'Assiginig out NOCOPY params to global variables');
6211 End if;
6212 g_tab_r_budget_posted(i) := l_fc_record.r_budget_posted;
6213 g_tab_rg_budget_posted(i) := l_fc_record.rg_budget_posted;
6214 g_tab_t_budget_posted(i) := l_fc_record.t_budget_posted;
6215 g_tab_tt_budget_posted(i) := l_fc_record.tt_budget_posted;
6216 g_tab_p_budget_posted(i) := l_fc_record.p_budget_posted;
6217 g_tab_r_actual_posted(i) := l_fc_record.r_actual_posted;
6218 g_tab_rg_actual_posted(i) := l_fc_record.rg_actual_posted;
6219 g_tab_t_actual_posted(i) := l_fc_record.t_actual_posted;
6220 g_tab_tt_actual_posted(i) := l_fc_record.tt_actual_posted;
6221 g_tab_p_actual_posted(i) := l_fc_record.p_actual_posted;
6222 g_tab_r_enc_posted(i) := l_fc_record.r_enc_posted;
6223 g_tab_rg_enc_posted(i) := l_fc_record.rg_enc_posted;
6224 g_tab_t_enc_posted(i) := l_fc_record.t_enc_posted;
6225 g_tab_tt_enc_posted(i) := l_fc_record.tt_enc_posted;
6226 g_tab_p_enc_posted(i) := l_fc_record.p_enc_posted;
6227 g_tab_r_budget_bal(i) := l_fc_record.r_budget_bal;
6228 g_tab_rg_budget_bal(i):= l_fc_record.rg_budget_bal;
6229 g_tab_t_budget_bal(i) := l_fc_record.t_budget_bal;
6230 g_tab_tt_budget_bal(i) := l_fc_record.tt_budget_bal;
6231 g_tab_p_budget_bal(i) := l_fc_record.p_budget_bal;
6232 g_tab_r_actual_approved(i):= l_fc_record.r_actual_approved;
6233 g_tab_rg_actual_approved(i) := l_fc_record.rg_actual_approved;
6234 g_tab_t_actual_approved(i) := l_fc_record.t_actual_approved;
6235 g_tab_tt_actual_approved(i) := l_fc_record.tt_actual_approved;
6236 g_tab_p_actual_approved(i) := l_fc_record.p_actual_approved;
6237 g_tab_r_enc_approved(i) := l_fc_record.r_enc_approved;
6238 g_tab_rg_enc_approved(i) := l_fc_record.rg_enc_approved;
6239 g_tab_t_enc_approved(i) := l_fc_record.t_enc_approved;
6240 g_tab_tt_enc_approved(i) := l_fc_record.tt_enc_approved ;
6241 g_tab_p_enc_approved(i) := l_fc_record.p_enc_approved;
6242 g_tab_result_code(i) := l_fc_record.result_code;
6243 g_tab_r_result_code(i) := l_fc_record.r_result_code;
6244 g_tab_rg_result_code(i) := l_fc_record.rg_result_code;
6245 g_tab_t_result_code(i) := l_fc_record.t_result_code;
6246 g_tab_tt_result_code(i) := l_fc_record.tt_result_code;
6247 g_tab_p_result_code(i) := l_fc_record.p_result_code;
6248 g_tab_p_acct_result_code(i) := l_fc_record.p_acct_result_code;
6249 IF g_debug_mode = 'Y' THEN
6250 log_message(p_msg_token1 => 'end of assignments');
6251 End if;
6252
6253
6254 END LOOP;
6255
6256 -- update the bc_packets with result and status codes in batch
6257 IF g_debug_mode = 'Y' THEN
6258 log_message(p_msg_token1 => 'Calling update pkt amts autonomous transaction statement');
6259 End if;
6260 update_pkt_amts(p_packet_id);
6261 IF g_debug_mode = 'Y' THEN
6262 log_message(p_msg_token1 => 'after the autonomous call');
6263 End if;
6264 EXIT WHEN trxn_details%NOTFOUND;
6265 END LOOP; -- end of the batch process
6266 CLOSE trxn_details;
6267 IF g_debug_mode = 'Y' THEN
6268 log_message(p_msg_token1 => 'end of trxn_details cursor ');
6269 End if;
6270 RETURN true;
6271
6272 EXCEPTION
6273
6274 when others then
6275 IF g_debug_mode = 'Y' THEN
6276 log_message(p_msg_token1 => 'failed due to un expected error during funds check');
6277 End if;
6278 If trxn_details%ISOPEN then
6279 close trxn_details;
6280 End if;
6281 IF g_debug_mode = 'Y' THEN
6282 log_message(p_msg_token1 => 'failed in pa_fc_process api SQLERR :'||sqlcode||sqlerrm);
6283 End if;
6284 Raise;
6285
6286
6287 END pa_fck_process;
6288
6289 ---------------------------------------------------------------------------------------------------------------
6290 --This API inserts the packet id into the gl_bc_arrival_packet_order , derives the arrival sequence
6291 --and ensures the data consistency for funds check process
6292 ---------------------------------------------------------------------------------------------------------------
6293
6294 FUNCTION get_arrival_seq
6295 (p_calling_module IN VARCHAR2
6296 ,p_packet_id IN NUMBER
6297 ,p_sobid IN NUMBER
6298 ,p_mode IN VARCHAR2
6299 ) RETURN NUMBER IS
6300
6301 PRAGMA AUTONOMOUS_TRANSACTION;
6302
6303 v_arrival_seq NUMBER;
6304 l_number NUMBER;
6305
6306 BEGIN
6307 IF g_debug_mode = 'Y' THEN
6308 log_message(p_msg_token1 => 'Inside the get arrival seq api');
6309 End if;
6310
6311 ------- Acquire a lock before processing ----------------
6312 PA_DEBUG.Set_User_Lock_Mode
6313 ( x_Lock_Mode => 6
6314 ,x_Commit_Mode => FALSE
6315 ,x_TimeOut => 30);
6316
6317 l_number := pa_debug.acquire_user_lock('PAFUNDSCHECKLOCKER');
6318 IF g_debug_mode = 'Y' THEN
6319 log_message(p_msg_token1 => 'the value of lock handler = '||l_number);
6320 End if;
6321 If l_number = 0 then
6322
6323 IF g_debug_mode = 'Y' THEN
6324 log_message(p_msg_token1 => 'Acquired the lock for funds check');
6325 End if;
6326 INSERT INTO pa_bc_packet_arrival_order
6327 ( packet_id
6328 , set_of_books_id
6329 , arrival_seq
6330 , affect_funds_flag
6331 , last_update_date
6332 , last_updated_by
6333 )
6334 VALUES (
6335 p_packet_id
6336 ,p_sobid
6337 ,pa_bc_packet_arrival_order_s.nextval
6338 ,DECODE ( p_mode, 'B', 'N', 'Y' )
6339 --For budget submit and baselining(S and B) it does not affect the funds.
6340 --For Encumbrances (E) it afffects funds.
6341 ,SYSDATE
6342 ,fnd_global.user_id
6343 );
6344 IF g_debug_mode = 'Y' THEN
6345 log_message(p_msg_token1 => 'No of records inserted into pa_bc_packet_arrival_order ='||sql%rowcount);
6346 End if;
6347
6348 BEGIN
6349 SELECT arrival_seq
6350 INTO v_arrival_seq
6351 FROM pa_bc_packet_arrival_order ao
6352 WHERE ao.packet_id = p_packet_id;
6353
6354 EXCEPTION
6355 WHEN OTHERS THEN
6356 result_status_code_update(p_packet_id => p_packet_id,
6357 p_status_code => 'R',
6358 p_result_code => 'F141',
6359 p_res_result_code => 'F141',
6360 p_res_grp_result_code => 'F141',
6361 p_task_result_code => 'F141',
6362 p_project_result_code => 'F141',
6363 p_proj_acct_result_code => 'F141');
6364 v_arrival_seq := 0;
6365 IF g_debug_mode = 'Y' THEN
6366 log_message(p_msg_token1=>'Failed to acquire lock - Exception portion');
6367 End if;
6368 log_message(p_error_msg =>sqlcode||sqlerrm);
6369 END;
6370 ------------- Release the Lock --------------
6371 If (pa_debug.release_user_lock('PAFUNDSCHECKLOCKER') = 0) then
6372 IF g_debug_mode = 'Y' THEN
6373 log_message(p_msg_token1 => 'Released the Lock');
6374 End if;
6375 END If;
6376
6377 ELSE
6378 IF g_debug_mode = 'Y' THEN
6379 log_message(p_msg_token1 => 'Failed to Acquire lock ');
6380 End if;
6381 -- Error msg : 'F141 = Funds check failed to acquire lock';
6382 result_status_code_update(p_packet_id => p_packet_id,
6383 p_status_code => 'R',
6384 p_result_code => 'F141',
6385 p_res_result_code => 'F141',
6386 p_res_grp_result_code => 'F141',
6387 p_task_result_code => 'F141',
6388 p_project_result_code => 'F141',
6389 p_proj_acct_result_code => 'F141');
6390 commit;
6391 null;
6392 END IF;
6393
6394 commit;
6395 RETURN nvl(v_arrival_seq,0);
6396
6397 EXCEPTION
6398 when others then
6399 If (pa_debug.release_user_lock('PAFUNDSCHECKLOCKER') = 0) then
6400 IF g_debug_mode = 'Y' THEN
6401 log_message(p_msg_token1 => 'Released the Lock');
6402 End if;
6403 null;
6404 END If;
6405 result_status_code_update(p_packet_id => p_packet_id,
6406 p_status_code => 'T',
6407 p_result_code => 'F141',
6408 p_res_result_code => 'F141',
6409 p_res_grp_result_code => 'F141',
6410 p_task_result_code => 'F141',
6411 p_project_result_code => 'F141',
6412 p_proj_acct_result_code => 'F141');
6413 IF g_debug_mode = 'Y' THEN
6414 log_message(p_msg_token1 => 'failed in get arrival seq apiSQLERR :'||sqlcode||sqlerrm);
6415 End if;
6416 --commit;
6417 return 0;
6418 Raise;
6419 END get_arrival_seq;
6420
6421 ---------------------------------------------------------------------------------------
6422 -- api to calulate budgeted resource list id in packet for a budget version,
6423 -- entry level code and budget entry method and update pa_bc_packets for the
6424 -- set of records having the same combinations.The bud_res_list_id is required
6425 -- to get the resource group level balances from the pa_bc_balances
6426 ---------------------------------------------------------------------------------------
6427 FUNCTION bud_res_list_id_update
6428 ( p_project_id IN NUMBER,
6429 p_budget_version_id IN NUMBER,
6430 p_resource_list_member_id IN NUMBER,
6431 p_categorization_code IN VARCHAR2,
6432 x_bud_resource_list_member_id OUT NOCOPY NUMBER,
6433 x_parent_resource_id OUT NOCOPY NUMBER
6434 ) return BOOLEAN IS
6435
6436 ----------------------------------------------------------------------------
6437 -- find the correct resource list id for funds checking.
6438 -- if no budget at the resource level then check the budget at the parent
6439 ---level and get the resource list id from pa_bc_balances
6440 ---------------------------------------------------------------------------
6441 CURSOR cur_bud_res_list_id IS
6442 SELECT pr.resource_list_id,
6443 pr.parent_member_id
6444 FROM pa_resource_list_members pr
6445 WHERE pr.resource_list_member_id = p_resource_list_member_id;
6446
6447 --This cursor picks up the resource list member id at the resource level
6448 -- if the budget is defined at the resource level
6449 CURSOR cur_res_member(v_project_id NUMBER,
6450 v_bdgt_version_id NUMBER,
6451 v_res_list_mem_id NUMBER) IS
6452 SELECT resource_list_member_id
6453 FROM pa_bc_balances
6454 WHERE budget_version_id = v_bdgt_version_id
6455 AND project_id = v_project_id
6456 AND resource_list_member_id = v_res_list_mem_id
6457 AND balance_type = 'BGT';
6458
6459 --This cursor picks up the resource list member id at the parent resource level
6460 -- if the budget at the resource level is not defined and defined at the resource
6461 -- group level
6462 CURSOR cur_parent_res_member(v_project_id NUMBER,
6463 v_bdgt_version_id NUMBER,
6464 v_parent_res_list_mem_id NUMBER) IS
6465 SELECT resource_list_member_id
6466 FROM pa_bc_balances
6467 WHERE budget_version_id = v_bdgt_version_id
6468 ANd project_id = v_project_id
6469 AND resource_list_member_id = v_parent_res_list_mem_id
6470 AND balance_type = 'BGT';
6471
6472
6473 l_budget_version_id pa_bc_packets.budget_version_id%TYPE;
6474 l_project_id pa_bc_packets.project_id%TYPE;
6475 l_task_id pa_bc_packets.bud_task_id%TYPE;
6476 l_resource_list_member_id pa_bc_packets.resource_list_member_id%TYPE;
6477 l_resource_list_id pa_resource_list_members.resource_list_id%TYPE;
6478 l_parent_member_id pa_resource_list_members.parent_member_id%TYPE;
6479 l_level pa_resource_list_members.member_level%TYPE;
6480 l_categorization_code pa_budget_entry_methods.categorization_code%TYPE;
6481 l_bud_res_list_member_id pa_bc_packets.bud_resource_list_member_id%TYPE;
6482 l_parent_resource_id pa_resource_list_members.parent_member_id%TYPE;
6483 BEGIN
6484
6485 OPEN cur_bud_res_list_id;
6486 LOOP
6487 FETCH cur_bud_res_list_id
6488 INTO l_resource_list_id,
6489 l_parent_member_id;
6490 EXIT WHEN cur_bud_res_list_id%NOTFOUND;
6491
6492 IF p_categorization_code = 'R' THEN
6493 -- find the correct resource list id for funds checking.
6494 OPEN cur_res_member(p_project_id,
6495 p_budget_version_id,
6496 p_resource_list_member_id);
6497 FETCH cur_res_member INTO l_bud_res_list_member_id;
6498 -- if the resource is not found then check at the parent level
6499 IF cur_res_member%notfound THEN
6500 OPEN cur_parent_res_member
6501 (p_project_id,
6502 p_budget_version_id,
6503 l_parent_member_id);
6504 FETCH cur_parent_res_member INTO l_bud_res_list_member_id;
6505 IF cur_parent_res_member%notfound THEN
6506 l_bud_res_list_member_id := l_resource_list_member_id;
6507 END IF;
6508 CLOSE cur_parent_res_member;
6509 END IF;
6510 CLOSE cur_res_member;
6511
6512 ELSE -- Not categorized by resource
6513
6514 BEGIN
6515
6516 SELECT pb.resource_list_member_id
6517 INTO l_bud_res_list_member_id
6518 FROM pa_bc_balances pb
6519 WHERE pb.budget_version_id = p_budget_version_id
6520 AND pb.project_id = p_project_id
6521 AND balance_type = 'BGT'
6522 AND ROWNUM = 1;
6523
6524 EXCEPTION
6525 when no_data_found then
6526 null;
6527 END;
6528 END IF;
6529
6530 x_bud_resource_list_member_id := l_bud_res_list_member_id;
6531 x_parent_resource_id := l_parent_member_id;
6532
6533 END LOOP;
6534 CLOSE cur_bud_res_list_id;
6535
6536 RETURN true;
6537
6538 EXCEPTION
6539 WHEN OTHERS THEN
6540
6541 if cur_bud_res_list_id%ISOPEN then
6542 close cur_bud_res_list_id;
6543 end if;
6544
6545 If cur_parent_res_member%ISOPEN then
6546 close cur_parent_res_member;
6547 End if;
6548
6549 If cur_res_member%ISOPEN then
6550 close cur_res_member;
6551 End if;
6552 IF g_debug_mode = 'Y' THEN
6553 log_message(p_msg_token1 => 'failed in bud res list id api SQLERR :'||sqlcode||sqlerrm);
6554 End if;
6555 RAISE;
6556
6557 END bud_res_list_id_update;
6558 --------------------------------------------------------------------------------------------
6559 ---Procedure to calulate budgeted task id in packet for a budget version, entry level code
6560 --- and budget entry method and update pa_bc_packets for the same set of records having
6561 --- the same combinations. Update the pa bc pakcets based on the budget entry methods
6562 --- L -- Enter budget at low task
6563 --- M -- Enter budget at Top task or Low task
6564 --- P -- Enter budget at Project level
6565 --- T -- Enter budget at Top task level
6566 -----------------------------------------------------------------------------------------------------
6567 FUNCTION budget_task_id_update
6568 ( p_project_id IN NUMBER,
6569 p_task_id IN NUMBER,
6570 p_budget_version_id IN NUMBER,
6571 p_entry_level_code IN VARCHAR2,
6572 x_bud_task_id OUT NOCOPY NUMBER,
6573 x_top_task_id OUT NOCOPY NUMBER
6574 ) RETURN BOOLEAN IS
6575
6576 -- This cursor picks the LOW_TASK_ID from pa_balances
6577 CURSOR cur_low_task_id( l_project_id NUMBER,
6578 l_task_id NUMBER,
6579 l_bdgt_version_id NUMBER) IS
6580 SELECT task_id
6581 FROM pa_bc_balances
6582 WHERE budget_version_id = l_bdgt_version_id
6583 AND project_id = l_project_id
6584 AND task_id = l_task_id
6585 AND balance_type = 'BGT';
6586
6587 --This cursor picks the TOP_TASK_ID from pa_balances
6588 CURSOR cur_top_task_id( l_project_id NUMBER,
6589 l_task_id NUMBER,
6590 l_bdgt_version_id NUMBER) IS
6591 SELECT task_id
6592 FROM pa_bc_balances
6593 WHERE budget_version_id = l_bdgt_version_id
6594 AND project_id = l_project_id
6595 AND balance_type = 'BGT'
6596 AND task_id = (SELECT top_task_id
6597 FROM pa_tasks
6598 WHERE task_id = l_task_id
6599 );
6600
6601
6602 l_bud_task_id pa_bc_packets.bud_task_id%TYPE;
6603 l_top_task_id pa_bc_packets.bud_task_id%TYPE;
6604
6605
6606 BEGIN
6607
6608 ------------------------------------------------------------------------------------
6609 -- if the budget entry level in 'L','T','P' -- update directly.
6610 -------------------------------------------------------------------------------------------
6611 SELECT top_task_id
6612 INTO l_top_task_id
6613 FROM pa_tasks
6614 WHERE task_id = p_task_id;
6615
6616 If p_entry_level_code in ('P', 'L', 'T' ) then
6617 If p_entry_level_code = 'P' then
6618 x_bud_task_id := 0;
6619 x_top_task_id := 0;
6620 Elsif p_entry_level_code = 'L' then
6621 x_bud_task_id := p_task_id ;
6622 x_top_task_id := l_top_task_id;
6623 Elsif p_entry_level_code = 'T' then
6624 x_bud_task_id := l_top_task_id;
6625 x_top_task_id := l_top_task_id;
6626 End if;
6627
6628 Elsif p_entry_level_code = 'M' then
6629
6630 ---------------------------------------------------------------------------------
6631 -- if the budget entry level = 'M' update by record.first select the budget task id
6632 -- (LOW TASK)based on the project,task,budget version from pa_bc_balances if not found then
6633 -- select the budget task id(TOP TASK) based on the project,task,budget version from
6634 -- pa_bc_balacnes for the toptask in pa_tasks
6635 -------------------------------------------------------------------------------------
6636 OPEN cur_low_task_id( p_project_id,
6637 p_task_id,
6638 p_budget_version_id);
6639
6640 FETCH cur_low_task_id INTO x_bud_task_id;
6641 IF cur_low_task_id%NOTFOUND THEN
6642
6643 OPEN cur_top_task_id( p_project_id,
6644 p_task_id,
6645 p_budget_version_id);
6646 FETCH cur_top_task_id INTO x_bud_task_id;
6647 IF cur_top_task_id%NOTFOUND THEN
6648 x_bud_task_id := p_task_id;
6649 END IF;
6650 CLOSE cur_top_task_id;
6651
6652
6653 END IF;
6654 CLOSE cur_low_task_id;
6655 x_top_task_id := l_top_task_id;
6656
6657 End IF;
6658
6659
6660 RETURN TRUE;
6661 EXCEPTION
6662 WHEN OTHERS THEN
6663 IF g_debug_mode = 'Y' THEN
6664 log_message(p_msg_token1 => 'failed in budget task id update api SQLERR :'||sqlcode||sqlerrm);
6665 End if;
6666 RAISE;
6667
6668 END budget_task_id_update;
6669
6670 -- This api derives the effect on funds control level code based on
6671 -- amount the valid return values are I - Increase D - Decrease
6672 FUNCTION get_fclevel_code(p_accounted_dr IN NUMBER,
6673 p_accounted_cr IN NUMBER,
6674 x_effect_on_funds_code OUT NOCOPY VARCHAR2)
6675 return boolean IS
6676 BEGIN
6677 -- Update the pa_bc_packets set the effect on funds level code I - Increase , D - Decrease
6678 -- based on the amount entered_dr and entered_cr
6679 IF SIGN (NVL(p_accounted_dr,0)-NVL(p_accounted_cr,0)) = 1 then
6680 x_effect_on_funds_code := 'D';
6681 Else
6682 x_effect_on_funds_code := 'I';
6683 End if;
6684
6685 RETURN TRUE;
6686 EXCEPTION
6687 WHEN OTHERS THEN
6688 IF g_debug_mode = 'Y' THEN
6689 log_message(p_msg_token1 => 'failed in get fclevel code apiSQLERR :'||sqlcode||sqlerrm);
6690 End if;
6691 RAISE;
6692
6693 END get_fclevel_code;
6694
6695 -----------------------------------------------------------------------------------------------
6696 --Procedure to update the funds control level code in a packet for a project, budget version,
6697 --budget entry method.update pa_bc_packets for the set of records having the same combinations.
6698 ------------------------------------------------------------------------------------------------
6699 FUNCTION funds_ctrl_level_code (
6700 p_project_id IN NUMBER,
6701 p_task_id IN NUMBER,
6702 p_top_task_id IN NUMBER,
6703 p_parent_member_id IN NUMBER,
6704 p_resource_list_member_id IN NUMBER,
6705 p_budget_version_id IN NUMBER,
6706 p_bud_task_id IN NUMBER,
6707 p_categorization_code IN VARCHAR2,
6708 x_r_funds_control_level_code OUT NOCOPY VARCHAR2,
6709 x_rg_funds_control_level_code OUT NOCOPY VARCHAR2,
6710 x_t_funds_control_level_code OUT NOCOPY VARCHAR2,
6711 x_tt_funds_control_level_code OUT NOCOPY VARCHAR2,
6712 x_p_funds_control_level_code OUT NOCOPY VARCHAR2
6713 )
6714 return BOOLEAN is
6715
6716 l_r_funds_control_level_code VARCHAR2 ( 1 );
6717 l_rg_funds_control_level_code VARCHAR2 ( 1 );
6718 l_t_funds_control_level_code VARCHAR2 ( 1 );
6719 l_tt_funds_control_level_code VARCHAR2 ( 1 );
6720 l_p_funds_control_level_code VARCHAR2 ( 1 );
6721
6722 CURSOR res_fcl IS
6723 SELECT funds_control_level_code
6724 FROM pa_budgetary_controls pbc
6725 ,pa_budget_versions bv
6726 WHERE bv.budget_version_id = p_budget_version_id
6727 AND bv.project_id = pbc.project_id
6728 AND bv.budget_type_code = pbc.budget_type_code
6729 AND pbc.project_id = p_project_id
6730 AND ( pbc.task_id = 0
6731 OR pbc.task_id = p_task_id )
6732 AND ((pbc.resource_list_member_id = p_resource_list_member_id
6733 AND pbc.parent_member_id = p_parent_member_id) OR
6734 (pbc.resource_list_member_id = p_resource_list_member_id
6735 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1 )
6736 ) ;
6737 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 )) ; */
6738
6739
6740 CURSOR res_grp_fcl IS
6741 SELECT funds_control_level_code
6742 FROM pa_budgetary_controls pbc
6743 ,pa_budget_versions bv
6744 WHERE bv.budget_version_id = p_budget_version_id
6745 AND bv.project_id = pbc.project_id
6746 AND bv.budget_type_code = pbc.budget_type_code
6747 AND pbc.project_id = p_project_id
6748 AND ( pbc.task_id = 0
6749 OR pbc.task_id = p_task_id )
6750 AND pbc.resource_list_member_id = p_parent_member_id
6751 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1;
6752 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0; */
6753
6754 CURSOR task_fcl IS
6755 SELECT funds_control_level_code
6756 FROM pa_budgetary_controls pbc
6757 ,pa_budget_versions bv
6758 WHERE bv.budget_version_id = p_budget_version_id
6759 AND bv.project_id = pbc.project_id
6760 AND bv.budget_type_code = pbc.budget_type_code
6761 AND pbc.project_id = p_project_id
6762 AND pbc.task_id = p_task_id
6763 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 */
6764 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1
6765 AND NVL(pbc.resource_list_member_id,0) = 0;
6766
6767 CURSOR top_task_fcl IS
6768 SELECT funds_control_level_code
6769 FROM pa_budgetary_controls pbc
6770 ,pa_budget_versions bv
6771 WHERE bv.budget_version_id = p_budget_version_id
6772 AND bv.project_id = pbc.project_id
6773 AND bv.budget_type_code = pbc.budget_type_code
6774 AND pbc.project_id = p_project_id
6775 AND pbc.task_id = p_top_task_id
6776 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 */
6777 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1
6778 AND NVL(pbc.resource_list_member_id,0) = 0;
6779
6780 CURSOR project_fcl IS
6781 SELECT funds_control_level_code
6782 FROM pa_budgetary_controls pbc
6783 ,pa_budget_versions bv
6784 WHERE bv.budget_version_id = p_budget_version_id
6785 AND bv.project_id = pbc.project_id
6786 AND bv.budget_type_code = pbc.budget_type_code
6787 AND pbc.project_id = p_project_id
6788 AND NVL(pbc.task_id,0) = 0
6789 /* Bug fix: 2658952 AND NVL(pbc.parent_member_id,0) = 0 */
6790 AND decode(pbc.parent_member_id,0,-1,NVL(pbc.parent_member_id,-1)) = -1
6791 AND NVL(pbc.resource_list_member_id,0) = 0;
6792
6793 /* Bug 5631763 : If there exists no BC records for the resource group/resource then the funds control levels
6794 are defaulted from those defined in pa_budgetary_control_options. If the funds control defined
6795 in pa_budgetary_control_options for the resource group/resource is "Default from Resource List"
6796 then the funds control levels are derived appropriately from the resource list. */
6797 CURSOR c_res_resgrp_no_bc (c_resource_list_member_id NUMBER) IS
6798 select nvl(rlm.funds_control_level_code,'N')
6799 from PA_RESOURCE_LIST_MEMBERS rlm
6800 where rlm.resource_list_member_id = c_resource_list_member_id
6801 and rlm.ENABLED_FLAG = 'Y'
6802 and DECODE(rlm.RESOURCE_TYPE_CODE, 'UNCLASSIFIED', 'Y', DISPLAY_FLAG) = 'Y'
6803 and nvl(rlm.migration_code, 'M') = 'M';
6804
6805
6806 BEGIN
6807 IF g_debug_mode = 'Y' THEN
6808 log_message(p_msg_token1 => 'funds_ctrl_level_code - in params are'||
6809 'Budget version ['||p_budget_version_id||
6810 ']p_resource_list_member_id ['||p_resource_list_member_id||
6811 ']project_id['||p_project_id||']p_task_id ['||p_task_id||
6812 ']p_top_task_id['||p_top_task_id||']p_bud_task_id['||p_bud_task_id||
6813 ']p_categorization_code['||p_categorization_code||']' );
6814 End if;
6815
6816 --Bug 5964934
6817 if p_budget_version_id = g_fclc_budget_version_id and
6818 p_project_id = g_fclc_project_id and
6819 g_p_funds_control_level_code is not null then
6820 l_p_funds_control_level_code := g_p_funds_control_level_code;
6821 else
6822 -- check the project funds control level code
6823 OPEN project_fcl;
6824 FETCH project_fcl INTO l_p_funds_control_level_code;
6825 IF project_fcl%NOTFOUND then
6826 l_p_funds_control_level_code := g_Pfund_control_level; -- Bug 5631763
6827 END IF;
6828 CLOSE project_fcl;
6829
6830 --Bug 5964934
6831 g_fclc_budget_version_id := p_budget_version_id;
6832 g_fclc_project_id := p_project_id;
6833 g_p_funds_control_level_code := nvl(l_p_funds_control_level_code,'N');
6834 end if;
6835
6836 -- task level funds control level codes
6837 IF NVL(p_bud_task_id,0) <> 0 THEN
6838 --Bug 5964934
6839 if p_budget_version_id = g_fclc_budget_version_id and
6840 p_project_id = g_fclc_project_id and
6841 p_top_task_id = g_fclc_top_task_id and
6842 g_tt_funds_control_level_code is not null then
6843 l_tt_funds_control_level_code := g_tt_funds_control_level_code;
6844 else
6845
6846 OPEN top_task_fcl;
6847 FETCH top_task_fcl INTO l_tt_funds_control_level_code;
6848 IF top_task_fcl%NOTFOUND then
6849 l_tt_funds_control_level_code := g_Tfund_control_level; -- Bug 5631763
6850 END IF;
6851
6852 CLOSE top_task_fcl;
6853
6854 --Bug 5964934
6855 g_fclc_budget_version_id := p_budget_version_id;
6856 g_fclc_project_id := p_project_id;
6857 g_fclc_top_task_id := p_top_task_id;
6858 g_tt_funds_control_level_code := nvl(l_tt_funds_control_level_code,'N');
6859 end if;
6860
6861 --Bug 5964934
6862 if p_budget_version_id = g_fclc_budget_version_id and
6863 p_project_id = g_fclc_project_id and
6864 p_task_id = g_fclc_task_id and
6865 g_t_funds_control_level_code is not null then
6866 l_t_funds_control_level_code := g_t_funds_control_level_code;
6867 else
6868 OPEN task_fcl;
6869 FETCH task_fcl INTO l_t_funds_control_level_code;
6870 IF task_fcl%NOTFOUND then
6871 l_t_funds_control_level_code := g_Tfund_control_level; -- Bug 5631763
6872 END IF;
6873
6874 CLOSE task_fcl;
6875 --Bug 5964934
6876 g_fclc_budget_version_id := p_budget_version_id;
6877 g_fclc_project_id := p_project_id;
6878 g_fclc_task_id := p_task_id;
6879 g_t_funds_control_level_code := nvl(l_t_funds_control_level_code,'N');
6880 end if;
6881
6882 END IF;
6883
6884 -- Resource level and resource group level funds control level codes
6885 IF p_categorization_code = 'R' THEN
6886
6887 --Bug 5964934
6888 if p_budget_version_id = g_fclc_budget_version_id and
6889 p_project_id = g_fclc_project_id and
6890 p_task_id = g_fclc_task_id and
6891 p_parent_member_id = g_fclc_parent_member_id and
6892 p_resource_list_member_id = g_fclc_resource_list_member_id and
6893 g_r_funds_control_level_code is not null then
6894 l_r_funds_control_level_code := g_r_funds_control_level_code;
6895 else
6896 OPEN res_fcl;
6897 FETCH res_fcl INTO l_r_funds_control_level_code;
6898 IF res_fcl%NOTFOUND then
6899 /* Bug 5631763 */
6900 If g_Rfund_control_level = 'D' then
6901 OPEN c_res_resgrp_no_bc (p_resource_list_member_id) ;
6902 FETCH c_res_resgrp_no_bc INTO l_r_funds_control_level_code;
6903 CLOSE c_res_resgrp_no_bc;
6904 else
6905 l_r_funds_control_level_code := g_Rfund_control_level;
6906 end if;
6907 /* Bug 5631763 */
6908 END IF;
6909
6910 CLOSE res_fcl;
6911 --Bug 5964934
6912 g_fclc_budget_version_id := p_budget_version_id;
6913 g_fclc_project_id := p_project_id;
6914 g_fclc_task_id := p_task_id;
6915 g_fclc_parent_member_id := p_parent_member_id;
6916 g_fclc_resource_list_member_id := p_resource_list_member_id;
6917 g_r_funds_control_level_code := nvl(l_r_funds_control_level_code,'N');
6918 end if;
6919 --Bug 5964934
6920 if p_budget_version_id = g_fclc_budget_version_id and
6921 p_project_id = g_fclc_project_id and
6922 p_task_id = g_fclc_task_id and
6923 p_parent_member_id = g_fclc_parent_member_id and
6924 g_rg_funds_control_level_code is not null then
6925 l_rg_funds_control_level_code := g_rg_funds_control_level_code;
6926 else
6927
6928 OPEN res_grp_fcl;
6929 FETCH res_grp_fcl INTO l_rg_funds_control_level_code;
6930 IF res_grp_fcl%NOTFOUND then
6931 /* Bug 5631763 */
6932 If g_RGfund_control_level = 'D' then
6933 If p_parent_member_id IS NOT NULL then
6934 OPEN c_res_resgrp_no_bc (p_parent_member_id);
6935 FETCH c_res_resgrp_no_bc INTO l_rg_funds_control_level_code;
6936 CLOSE c_res_resgrp_no_bc;
6937 else
6938 l_rg_funds_control_level_code := l_r_funds_control_level_code;
6939 end if;
6940 else
6941 l_rg_funds_control_level_code := g_RGfund_control_level;
6942 end if;
6943 /* Bug 5631763 */
6944 END IF;
6945 CLOSE res_grp_fcl;
6946
6947 --Bug 5964934
6948 g_fclc_budget_version_id := p_budget_version_id;
6949 g_fclc_project_id := p_project_id;
6950 g_fclc_task_id := p_task_id;
6951 g_fclc_parent_member_id := p_parent_member_id;
6952 g_rg_funds_control_level_code := nvl(l_rg_funds_control_level_code,'N');
6953 end if;
6954
6955 END IF;
6956
6957 x_r_funds_control_level_code := nvl(l_r_funds_control_level_code,'N');
6958 x_rg_funds_control_level_code := nvl(l_rg_funds_control_level_code,'N');
6959 x_t_funds_control_level_code := nvl(l_t_funds_control_level_code,'N');
6960 x_tt_funds_control_level_code := nvl(l_tt_funds_control_level_code,'N');
6961 x_p_funds_control_level_code := nvl(l_p_funds_control_level_code,'N');
6962
6963 Return True;
6964
6965 EXCEPTION
6966 WHEN OTHERS THEN
6967 if project_fcl%ISOPEN then
6968 close project_fcl;
6969 end if;
6970 if top_task_fcl%ISOPEN then
6971 close top_task_fcl;
6972 end if;
6973 if task_fcl%ISOPEN then
6974 close task_fcl;
6975 end if;
6976 if res_grp_fcl%ISOPEN then
6977 close res_grp_fcl;
6978 end if;
6979 if res_fcl%ISOPEN then
6980 close res_fcl;
6981 end if;
6982 IF g_debug_mode = 'Y' THEN
6983 log_message(p_msg_token1 => 'failed in funds ctrl level codeapi SQLERR :'||sqlcode||sqlerrm);
6984 End if;
6985 raise;
6986 END funds_ctrl_level_code;
6987
6988 ----------------------------------------------------------------------------------------------
6989 -- This api Updates pa_bc_packets with , all the details required for creating
6990 -- encumbrance liquidation entries and to update budget account balances .
6991 -- get the following parameters budget_cc_id, encum_type_id, gl_date, gl_period etc.
6992 -----------------------------------------------------------------------------------------------
6993 FUNCTION encum_detail_update
6994 (p_mode IN VARCHAR2,
6995 p_project_id IN NUMBER,
6996 p_Task_id IN NUMBER,
6997 p_Budget_version_id IN NUMBER,
6998 p_Resource_list_member_id IN NUMBER,
6999 p_sob_id IN NUMBER,
7000 p_Period_name IN varchar2,
7001 p_Expenditure_item_date IN date,
7002 p_document_type IN VARCHAR2,
7003 p_ext_bdgt_type IN VARCHAR2,
7004 p_ext_bdgt_link IN VARCHAR2,
7005 p_bdgt_entry_level IN VARCHAR2,
7006 p_top_task_id IN NUMBER,
7007 p_OU IN NUMBER,
7008 p_calling_module IN VARCHAR2,
7009 x_budget_ccid IN OUT NOCOPY NUMBER,
7010 x_budget_line_id IN OUT NOCOPY NUMBER,
7011 x_gl_date OUT NOCOPY date,
7012 x_pa_date OUT NOCOPY date,
7013 x_result_code OUT NOCOPY varchar2,
7014 x_r_result_code OUT NOCOPY varchar2,
7015 x_rg_result_code OUT NOCOPY varchar2,
7016 x_t_result_code OUT NOCOPY varchar2,
7017 x_tt_result_code OUT NOCOPY varchar2,
7018 x_p_result_code OUT NOCOPY varchar2,
7019 x_p_acct_result_code OUT NOCOPY varchar2
7020 ) return BOOLEAN IS
7021
7022
7023 l_pa_date pa_bc_packets.pa_date%type := null;
7024 l_gl_date pa_bc_packets.gl_date%type := null;
7025 l_budget_ccid pa_bc_packets.budget_ccid%type := null;
7026 l_budget_line_id pa_bc_packets.budget_line_id%type := null;
7027 l_error_message_code varchar2(200) := null;
7028 l_return_status varchar2(10) := 'S';
7029 l_gl_start_date date;
7030
7031
7032 BEGIN
7033
7034 -- Initialize the out NOCOPY params with null values
7035 --x_budget_ccid := null;
7036 x_gl_date := null;
7037 x_pa_date := null;
7038 x_result_code := null;
7039 x_r_result_code := null;
7040 x_rg_result_code := null;
7041 x_t_result_code := null;
7042 x_tt_result_code := null;
7043 x_p_result_code := null;
7044 x_p_acct_result_code := null;
7045 --- document type in AP, PO, REQ, Contract Commitments and Contract Payements
7046 --- GL_DATE is derived from gl_period_statuses for the given period_name and period_year
7047 --- get end_date from gl_period_statuses based on period_name and period_num and period_year
7048 --- for document type in Expenditures
7049 --- when there is budget linked derive GL_DATE based on the Expenditure Item Date
7050 --- When there is No link then derive gl date based on the pa_periods
7051 IF g_debug_mode = 'Y' THEN
7052 log_message(p_msg_token1 =>'ext bdgt link ['||p_ext_bdgt_link||']document type['||p_document_type||']');
7053 End if;
7054 If p_mode NOT in ('B','S') then -- and p_ext_bdgt_link = 'Y' then
7055 BEGIN
7056
7057 If p_document_type <> 'EXP' THEN
7058 IF g_debug_mode = 'Y' THEN
7059 log_message(p_msg_token1 =>'selecting gl date');
7060 End if;
7061 SELECT gl.end_date,
7062 gl.start_date
7063 INTO l_gl_date,l_gl_start_date
7064 FROM gl_period_statuses gl
7065 WHERE gl.application_id = 101
7066 AND gl.set_of_books_id = p_sob_id
7067 AND gl.period_name = p_period_name
7068 AND gl.closing_status in ('O','F');
7069 IF g_debug_mode = 'Y' THEN
7070 log_message(p_msg_token1 =>'gl_end date = '||l_gl_date||' gl start date ='||l_gl_start_date);
7071 End if;
7072 /** pagl date derivation logic for the Funds check process
7073 * get the pa date for the expenditure item date. expenditure item date is treated
7074 * as transaction date even though we have accounting date entered in invoice.
7075 * so that the transaction date as close as to the accounting date
7076 * If ei_date is between gl.start and gl.end dates then
7077 * gl_date := ei_date
7078 * elsif ei_date > gl.end_date then
7079 * gl_date := gl.end_date
7080 * elsif ei_date < gl.start_date then
7081 * gl_date := gl.start_date
7082 * end if;
7083 **/
7084 If trunc(p_Expenditure_item_date) >= trunc(l_gl_start_date) and
7085 trunc(p_Expenditure_item_date) <= trunc(l_gl_date) then
7086 /** if the profile option is set then transaction date is gl date otherwise
7087 * gl end date is the gl date
7088 **/
7089 IF nvl(fnd_profile.value_specific('PA_EN_NEW_GLDATE_DERIVATION'),'N') = 'Y' THEN
7090 l_gl_date := p_Expenditure_item_date;
7091 ELSE
7092 l_gl_date := l_gl_date;
7093 END IF;
7094 Elsif trunc(p_Expenditure_item_date) > trunc(l_gl_date) then
7095 l_gl_date := l_gl_date;
7096 Elsif trunc(p_Expenditure_item_date) < trunc(l_gl_start_date) then
7097 l_gl_date := l_gl_start_date;
7098 End if;
7099 IF g_debug_mode = 'Y' THEN
7100 log_message(p_msg_token1 =>'after pagl derivation gl_end date = '
7101 ||l_gl_date||' gl start date ='||l_gl_start_date);
7102 End if;
7103
7104 --for document type EXP gl date and pa date are derived while
7105 -- inserting records into pa_bc_packets
7106 -- get the gl start date from gl_period_status for getting the budget ccid
7107
7108 Elsif p_document_type = 'EXP' THEN
7109 SELECT gl.start_date
7110 INTO l_gl_start_date
7111 FROM gl_period_statuses gl
7112 WHERE gl.application_id = 101
7113 AND gl.set_of_books_id = p_sob_id
7114 AND gl.period_name = p_period_name;
7115 IF g_debug_mode = 'Y' THEN
7116 log_message(p_msg_token1 =>'gl start date['||l_gl_start_date||']gl_date['||l_gl_date||']' );
7117 End if;
7118
7119 End if;
7120 x_gl_date := l_gl_date;
7121 EXCEPTION
7122 WHEN NO_DATA_FOUND THEN
7123 IF g_debug_mode = 'Y' THEN
7124 log_message(p_msg_token1 =>'GL date not found ');
7125 End if;
7126 -- Error msg : 'F134 = Start or End date is null for GL period
7127 x_result_code := 'F134';
7128 x_r_result_code := 'F134';
7129 x_rg_result_code := 'F134';
7130 x_t_result_code := 'F134';
7131 x_tt_result_code := 'F134';
7132 x_p_result_code := 'F134';
7133 x_p_acct_result_code := 'F134';
7134 RETURN false;
7135 WHEN OTHERS THEN
7136 IF g_debug_mode = 'Y' THEN
7137 log_message(p_msg_token1 =>'exeption in GL date finding'||sqlcode||sqlerrm);
7138 End if;
7139 --raise;
7140 END ;
7141
7142 Elsif p_mode in ('B', 'S') and p_ext_bdgt_link = 'Y' then
7143 /** get the gl_start_date to get the budget_ccid**/
7144 BEGIN
7145 SELECT gl.end_date,
7146 gl.start_date
7147 INTO l_gl_date,l_gl_start_date
7148 FROM gl_period_statuses gl
7149 WHERE gl.application_id = 101
7150 AND gl.set_of_books_id = p_sob_id
7151 AND gl.period_name = p_period_name;
7152 x_gl_date := l_gl_start_date;
7153 EXCEPTION
7154 WHEN NO_DATA_FOUND THEN
7155 IF g_debug_mode = 'Y' THEN
7156 log_message(p_msg_token1 =>'GL date not found ');
7157 End if;
7158 -- Error msg : 'F134 = Start or End date is null for GL period
7159 x_result_code := 'F134';
7160 x_r_result_code := 'F134';
7161 x_rg_result_code := 'F134';
7162 x_t_result_code := 'F134';
7163 x_tt_result_code := 'F134';
7164 x_p_result_code := 'F134';
7165 x_p_acct_result_code := 'F134';
7166 RETURN false;
7167 WHEN OTHERS THEN
7168 raise;
7169 END;
7170
7171 End if;
7172
7173 -- If the budget is not linked and document type is exp then
7174 -- derive the pa_date based on the gl date
7175 If p_mode not IN ('B','S') then --and p_ext_bdgt_link <> 'Y' and
7176 --p_document_type in ( 'EXP','AP','REQ','PO','CC_C_PAY','CC_P_PAY') then
7177 IF g_debug_mode = 'Y' THEN
7178 log_message(p_msg_token1 =>'Selecting pa date');
7179 End if;
7180
7181 IF p_document_type <> 'EXP' then
7182
7183 BEGIN
7184 /** pa_gl_date derivation logic
7185 * for deriving the pa date call the
7186 * centralized api pa_utils.get_pa_date by passing
7187 * expenditure_item_date as the transaction date
7188 * the below lines are commented out NOCOPY
7189 SELECT end_date
7190 INTO l_pa_date
7191 FROM pa_periods
7192 WHERE --(gl_period_name = p_period_name
7193 --OR
7194 trunc(l_gl_date) between start_date and end_date
7195 --)
7196 AND status in ('O','F') ;
7197 **/
7198
7199 l_pa_date := pa_utils2.get_pa_date
7200 (p_Expenditure_item_date,NULL,p_OU);
7201
7202 If l_pa_date is null then
7203 x_result_code := 'F130';
7204 End if;
7205 IF g_debug_mode = 'Y' THEN
7206 log_message(p_msg_token1 =>'pa_date = '||l_pa_date);
7207 End if;
7208 x_pa_date := l_pa_date;
7209 EXCEPTION
7210 WHEN NO_DATA_FOUND THEN
7211 IF g_debug_mode = 'Y' THEN
7212 log_message(p_msg_token1 =>'pa date not found ');
7213 End if;
7214 --Error msg : 'F130 = Start or End Date is null for PA periods';
7215 x_result_code := 'F130';
7216 x_r_result_code := 'F130';
7217 x_rg_result_code := 'F130';
7218 x_t_result_code := 'F130';
7219 x_tt_result_code := 'F130';
7220 x_p_result_code := 'F130';
7221 x_p_acct_result_code := 'F130';
7222 RETURN false;
7223
7224 WHEN OTHERS THEN
7225 IF g_debug_mode = 'Y' THEN
7226 log_message(p_msg_token1 =>'exception in pa date finding');
7227 End if;
7228 Raise;
7229
7230 END;
7231 Elsif p_document_type = 'EXP' then /* Changes Start for Bug 6042137 */
7232 BEGIN
7233 l_pa_date := pa_utils2.get_pa_date
7234 (p_Expenditure_item_date,NULL,p_OU);
7235 If l_pa_date is null then
7236 x_result_code := 'F130';
7237 End if;
7238 IF g_debug_mode = 'Y' THEN
7239 log_message(p_msg_token1 =>'pa_dater = '||l_pa_date);
7240 End if;
7241 x_pa_date := l_pa_date;
7242 EXCEPTION
7243 WHEN NO_DATA_FOUND THEN
7244 IF g_debug_mode = 'Y' THEN
7245 log_message(p_msg_token1 =>'pa date not found ');
7246 End if;
7247 --Error msg : 'F130 = Start or End Date is null for PA periods';
7248 x_result_code := 'F130';
7249 x_r_result_code := 'F130';
7250 x_rg_result_code := 'F130';
7251 x_t_result_code := 'F130';
7252 x_tt_result_code := 'F130';
7253 x_p_result_code := 'F130';
7254 x_p_acct_result_code := 'F130';
7255 RETURN false;
7256 WHEN OTHERS THEN
7257 IF g_debug_mode = 'Y' THEN
7258 log_message(p_msg_token1 =>'exception in pa date finding');
7259 End if;
7260 Raise;
7261 END; /* Changes End for Bug 6042137 */
7262 End if;
7263
7264 End if;
7265
7266 -- Derive budget ccid in all other modes except budget baseline and commitment fund check
7267 -- During budget baseline: account level FC is executed during FC tieback ..
7268 -- Budget_ccid for txn. will be derived in tieback as budget lines are not visible here ...
7269 -- During commitment fund scheck, budget ccid and line id is derived upfront ..
7270
7271 --If p_mode <> 'B' then
7272 If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ' ,'TRXIMPORT') then
7273
7274 -- get budget_code_combination_id from pa_budget_lines
7275 -- for the given budget_version_id,project_id,task_id and resource list member id
7276 -- get the resource assignment_id from pa_resource_assignments
7277 -- get the budget_code_combination_id from pa_budget_lines for the
7278 -- given resource assignment id and start date of the gl period
7279 IF p_ext_bdgt_link = 'Y' then
7280 IF g_debug_mode = 'Y' THEN
7281 log_message(p_msg_token1 =>'Calling Budget ccid api In parameters are'||
7282 ']p_project_id ['||p_project_id||']p_task_id ['||p_task_id||'p_start date['||l_gl_start_date||
7283 ']p_top_task_id ['||p_top_task_id||'budgt by ['||p_bdgt_entry_level||
7284 ']rlmi ['||p_resource_list_member_id||']p_budget_version_id ['||p_budget_version_id ||']' );
7285 End if;
7286
7287 PA_FUNDS_CONTROL_UTILS.Get_Budget_CCID (
7288 p_project_id => p_project_id,
7289 p_task_id => p_task_id,
7290 p_res_list_mem_id => p_resource_list_member_id,
7291 --p_period_name => p_period_name,
7292 p_start_date => l_gl_start_date,
7293 p_budget_version_id => p_budget_version_id,
7294 p_top_task_id => p_top_task_id,
7295 p_entry_level_code => p_bdgt_entry_level,
7296 x_budget_ccid => l_budget_ccid,
7297 x_budget_line_id => l_budget_line_id,
7298 x_return_status => l_return_status,
7299 x_error_message_code => l_error_message_code);
7300 IF g_debug_mode = 'Y' THEN
7301 log_message(p_msg_token1 =>'After Budget ccid apiBudget ccid ['||l_budget_ccid||']' );
7302 End if;
7303
7304 If l_budget_ccid is NULL then
7305 --Error msg : 'F132 = Transaction Failed at Budget CCID setup';
7306 IF g_debug_mode = 'Y' THEN
7307 log_message(p_msg_token1 =>'Assigning F132 for the result code');
7308 End if;
7309 x_result_code := 'F132';
7310 x_r_result_code := 'F132';
7311 x_rg_result_code := 'F132';
7312 x_t_result_code := 'F132';
7313 x_tt_result_code := 'F132';
7314 x_p_result_code := 'F132';
7315 x_p_acct_result_code := 'F132';
7316 return false;
7317 End if;
7318
7319 x_budget_ccid := l_budget_ccid;
7320 x_budget_line_id := l_budget_line_id;
7321
7322 End if; -- IF p_ext_bdgt_link = 'Y' then
7323 End If; -- If p_mode <> 'B' then
7324
7325
7326 RETURN TRUE;
7327 EXCEPTION
7328 WHEN OTHERS THEN
7329 --x_status_code := 'T';
7330 --Return False;
7331 Raise;
7332
7333 END encum_detail_update;
7334
7335 -----------------------------------------------------------------------------
7336 -- This Api updates the pa_bc_packets with funds check setup parameters
7337 -- like resource list member id, top task id,and encumbrance details
7338 ----------------------------------------------------------------------------
7339 PROCEDURE update_pkts(p_packet_id number) IS
7340
7341 PRAGMA AUTONOMOUS_TRANSACTION;
7342
7343 BEGIN
7344 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
7345 UPDATE pa_bc_packets
7346 SET parent_resource_id = nvl(g_tab_p_resource_id(i),parent_resource_id),
7347 bud_task_id = nvl(g_tab_bud_task_id(i) ,bud_task_id) ,
7348 bud_resource_list_member_id = nvl(g_tab_bud_rlmi(i) ,bud_resource_list_member_id),
7349 top_task_id = nvl(g_tab_tt_task_id(i) ,top_task_id),
7350 r_funds_control_level_code = nvl(g_tab_r_fclevel_code(i),r_funds_control_level_code),
7351 rg_funds_control_level_code =nvl( g_tab_rg_fclevel_code(i),rg_funds_control_level_code),
7352 t_funds_control_level_code = nvl(g_tab_t_fclevel_code(i), t_funds_control_level_code),
7353 tt_funds_control_level_code = nvl(g_tab_tt_fclevel_code(i),tt_funds_control_level_code),
7354 p_funds_control_level_code = nvl(g_tab_p_fclevel_code(i),p_funds_control_level_code),
7355 result_code = nvl(g_tab_result_code(i) ,result_code),
7356 res_result_code = nvl(g_tab_r_result_code(i) ,res_result_code),
7357 res_grp_result_code = nvl(g_tab_rg_result_code(i),res_grp_result_code) ,
7358 task_result_code = nvl(g_tab_t_result_code(i),task_result_code),
7359 top_task_result_code = nvl(g_tab_tt_result_code(i), top_task_result_code),
7360 project_result_code = nvl(g_tab_p_result_code(i),project_result_code),
7361 project_acct_result_code = nvl(g_tab_p_acct_result_code(i),project_acct_result_code),
7362 budget_ccid = nvl(budget_ccid,g_tab_budget_ccid(i)),
7363 budget_line_id = nvl(budget_line_id,g_tab_budget_line_id(i)),
7364 burden_method_code = nvl(burden_method_code,g_tab_burden_method_code(i)),
7365 txn_ccid = nvl(g_tab_trxn_ccid(i),txn_ccid),
7366 effect_on_funds_code = nvl(g_tab_effect_fclevel(i), effect_on_funds_code),
7367 proj_encumbrance_type_id = nvl(g_tab_encum_type_id(i) ,proj_encumbrance_type_id),
7368 gl_date = nvl(g_tab_gl_date(i),gl_date),
7369 pa_date =nvl( g_tab_pa_date(i),pa_date),
7370 ext_bdgt_flag = nvl(g_tab_ext_bdgt_link(i),ext_bdgt_flag),
7371 fc_start_date = nvl(g_tab_start_date(i),fc_start_date),
7372 fc_end_date = nvl(g_tab_end_date(i),fc_end_date)
7373 WHERE packet_id = p_packet_id
7374 AND rowid = g_tab_rowid(i);
7375
7376 commit; -- to end an autonomous transaction
7377 return;
7378
7379 EXCEPTION
7380 WHEN OTHERS THEN
7381 g_return_status := 'T';
7382 IF g_debug_mode = 'Y' THEN
7383 log_message(p_msg_token1 => 'Failed in update_pkts api SQLERR'||sqlerrm||sqlcode);
7384 End if;
7385 RAISE;
7386 END update_pkts;
7387 ------------------------------------------------------------------------------------
7388 /* PAM Changes: calling new resource mapping api for performance improvement*/
7389 ------------------------------------------------------------------------------------
7390 PROCEDURE DERIVE_RLMI
7391 ( p_packet_id IN pa_bc_packets.packet_id%type,
7392 p_mode IN varchar2,
7393 p_sob IN NUMBER,
7394 p_reference1 IN varchar2 default null,
7395 p_reference2 IN varchar2 default null,
7396 p_calling_module IN varchar2 default 'GL'
7397 ) IS
7398
7399 PRAGMA AUTONOMOUS_TRANSACTION;
7400
7401 Cursor cur_rlmi_details IS
7402 SELECT pbc.rowid,
7403 pbc.budget_version_id,
7404 pbc.project_id,
7405 pbc.task_id,
7406 pbc.document_type,
7407 pbc.document_header_id,
7408 pbc.expenditure_organization_id,
7409 pbc.expenditure_type,
7410 TYPE.expenditure_category,
7411 TYPE.revenue_category_code,
7412 /* bug fix: 3700261 NVL ( ei.system_linkage_function, 'VI' ) */
7413 decode(pbc.document_type,'EXP',NVL ( ei.system_linkage_function, 'VI' ),'VI')
7414 system_linkage_function,
7415 pm.categorization_code resource_category_code,
7416 pbc.parent_bc_packet_id,
7417 pm.entry_level_code ,
7418 pbc.period_name,
7419 pbc.expenditure_item_date,
7420 pbc.bc_packet_id,
7421 pbc.org_id exp_org_id,
7422 pp.org_id proj_org_id,
7423 pbc.document_line_id,
7424 bv.resource_list_id,
7425 pbc.vendor_id
7426 FROM pa_bc_packets pbc,
7427 pa_projects_all pp,
7428 pa_budget_versions bv,
7429 pa_budget_entry_methods pm,
7430 pa_expenditure_types type,
7431 pa_expenditure_items_all ei
7432 WHERE pbc.packet_id = p_packet_id
7433 AND pp.project_id = pbc.project_id
7434 AND bv.project_id = pp.project_id
7435 AND pbc.budget_version_id = bv.budget_version_id
7436 AND bv.budget_entry_method_code = pm.budget_entry_method_code
7437 AND pbc.expenditure_type = TYPE.expenditure_type(+)
7438 AND pbc.document_header_id = ei.expenditure_item_id(+)
7439 AND pbc.status_code in ('P','L','I')
7440 AND substr(nvl(pbc.result_code,'P'),1,1) not in ('R','F')
7441 ORDER BY /** Bug fix :2004139 order by clause is changed to column names **/
7442 pbc.project_id,
7443 pbc.budget_version_id,
7444 pm.entry_level_code ,
7445 pm.categorization_code,
7446 pbc.task_id,
7447 pbc.expenditure_type,
7448 pbc.document_type,
7449 pbc.document_header_id,
7450 ei.system_linkage_function ;
7451 --1,2,3,4,5,10,6,8,7;
7452
7453 -- Declare local variables to hold values and use one level cache
7454 l_counter NUMBER := 0;
7455 l_return_status VARCHAR2(10);
7456 l_status_code VARCHAR2(10);
7457 l_result_code VARCHAR2(10);
7458 l_cache_project_id NUMBER;
7459 l_cache_task_id NUMBER;
7460 l_cache_bdgt_version_id NUMBER;
7461 l_res_list_id NUMBER;
7462 l_cache_res_list_id NUMBER;
7463 l_cache_exp_org_id NUMBER;
7464 l_job_id NUMBER;
7465 l_cache_job_id NUMBER;
7466 l_vendor_id NUMBER;
7467 l_cache_vendor_id NUMBER;
7468 l_cache_exp_type VARCHAR2 ( 30 );
7469 l_non_labor_resource VARCHAR2 ( 80 );
7470 l_non_labor_resource_org_id NUMBER;
7471 l_cache_non_lab_res_org NUMBER;
7472 l_cache_non_lab_res VARCHAR2 ( 80 );
7473 l_cache_sys_link_func VARCHAR2 ( 30 );
7474 l_cache_doc_type VARCHAR2 ( 10 );
7475 l_cache_doc_header_id NUMBER;
7476 l_non_cat_rlmi NUMBER;
7477 l_cache_non_cat_rlmi NUMBER;
7478 l_person_id NUMBER;
7479 l_cache_person_id NUMBER;
7480 l_error_stage VARCHAR2 ( 2000 ):= NULL;
7481 l_error_code NUMBER;
7482 l_cache_category_code VARCHAR2(30);
7483 l_cache_entry_level_code VARCHAR2(10);
7484 l_error_msg VARCHAR2(2000);
7485 l_cache_res_list_result_code VARCHAR2(10);
7486 l_cache_non_cat_bdgt_ver_id Number;
7487 l_cache_non_cat_result_code VARCHAR2(30);
7488 l_fc_utils2_cwk_rlmi NUMBER;
7489
7490 l_tab_resmap_list_id PA_PLSQL_DATATYPES.IDTABTYP;
7491 l_tab_resmap_project_id PA_PLSQL_DATATYPES.IDTABTYP;
7492 l_tab_resmap_pkt_line_type PA_PLSQL_DATATYPES.CHAR50TABTYP;
7493 ----------------------------------------------------------------------------------------
7494 -- If resource list is setup without resource groups and the
7495 -- resources are setup as expenditure categories, Funds check
7496 -- fail due to a resource mapping error.
7497 -------------------------------------------------------------------------------------
7498 CURSOR get_non_cat_rlmi(v_bdgt_ver_id NUMBER) IS
7499 SELECT resource_list_member_id
7500 FROM pa_bc_balances gb
7501 WHERE gb.budget_version_id = v_bdgt_ver_id
7502 AND balance_type = 'BGT'
7503 AND ROWNUM = 1;
7504
7505 CURSOR get_req_vend(v_doc_header_id NUMBER) IS
7506 SELECT line.vendor_id
7507 FROM po_requisition_lines line,
7508 po_requisition_headers req
7509 WHERE line.requisition_header_id = req.requisition_header_id
7510 AND req.requisition_header_id = v_doc_header_id ;
7511
7512
7513 CURSOR get_po_vend(v_doc_header_id NUMBER) IS
7514 SELECT head.vendor_id
7515 FROM po_headers_all head
7516 WHERE head.po_header_id = v_doc_header_id;
7517
7518
7519 CURSOR get_ap_vend(v_doc_header_id NUMBER) IS
7520 SELECT head.vendor_id
7521 FROM ap_invoices_all head
7522 WHERE head.invoice_id = v_doc_header_id;
7523
7524 CURSOR get_igc_vend(v_doc_header_id NUMBER) IS
7525 SELECT head.vendor_id
7526 FROM igc_cc_headers head
7527 WHERE head.cc_header_id = v_doc_header_id;
7528
7529 CURSOR get_exp_details(v_doc_header_id NUMBER) IS
7530 SELECT EXP.incurred_by_person_id,
7531 item.job_id
7532 FROM pa_expenditures_all exp,
7533 pa_expenditure_items_all item
7534 WHERE item.expenditure_item_id = v_doc_header_id
7535 AND item.expenditure_id = EXP.expenditure_id;
7536
7537 CURSOR get_non_usg_exp_details(v_doc_exp_type VARCHAR2) IS
7538 SELECT tp.attribute2,
7539 tp.attribute3
7540 FROM pa_expenditure_types tp
7541 WHERE tp.expenditure_type = v_doc_exp_type;
7542
7543 CURSOR get_usg_exp_details(v_doc_header_id NUMBER) IS
7544 SELECT EXP.incurred_by_person_id,
7545 item.job_id,
7546 item.non_labor_resource,
7547 item.organization_id
7548 FROM pa_expenditures_all exp,
7549 pa_expenditure_items_all item
7550 WHERE item.expenditure_item_id = v_doc_header_id
7551 AND item.expenditure_id = EXP.expenditure_id;
7552
7553 CURSOR cur_resList IS
7554 SELECT distinct bv.resource_list_id
7555 ,bv.budget_version_id
7556 ,bv.project_id
7557 ,NVL(pm.categorization_code,'N') resource_category_code
7558 FROM pa_budget_versions bv
7559 ,pa_budget_entry_methods pm
7560 ,pa_bc_packets pkt
7561 WHERE pkt.packet_id = p_packet_id
7562 AND bv.budget_version_id = pkt.budget_version_id
7563 AND substr(nvl(pkt.result_code,'P'),1,1) <> ('F')
7564 AND pkt.status_code in ('P','L','I')
7565 AND bv.budget_entry_method_code = pm.budget_entry_method_code
7566 ;
7567
7568 CURSOR cur_cwkRlmi IS
7569 SELECT pkt.bc_packet_id
7570 ,pkt.project_id
7571 ,pkt.task_id
7572 ,pkt.budget_version_id
7573 ,pkt.document_type
7574 ,pkt.document_header_id
7575 ,pkt.document_distribution_id
7576 ,pkt.document_line_id
7577 ,pkt.expenditure_type
7578 ,pkt.resource_list_member_id
7579 ,decode(NVL(pt.burden_amt_display_method,'N'),'D'
7580 ,decode(parent_bc_packet_id,NULL,'RAW','BURDEN'),'RAW') pkt_line_type
7581 FROM pa_bc_packets pkt
7582 ,pa_project_types_all pt
7583 ,pa_projects_all pp
7584 WHERE pkt.packet_id = p_packet_id
7585 AND pkt.document_line_id is not null
7586 AND pkt.document_type in ('PO','EXP')
7587 ANd NVL(pkt.summary_record_flag,'N') <> 'Y'
7588 AND substr(nvl(pkt.result_code,'P'),1,1) <> 'F'
7589 ANd pkt.status_code in ('P','L','I')
7590 AND pp.project_id = pkt.project_id
7591 AND pp.project_type = pt.project_type
7592 and pt.org_id = pp.org_id ;
7593
7594
7595 BEGIN
7596
7597 -- Initialize the error stack
7598 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.Derive_rlmi');
7599 IF g_debug_mode = 'Y' THEN
7600 log_message(p_msg_token1 => 'inside the fundscheck derive rlmi');
7601 End if;
7602 -- initialize the pl/sql talbes
7603 Init_plsql_tabs;
7604
7605 l_counter := 0;
7606
7607 FOR i IN cur_rlmi_details LOOP
7608 l_counter := l_counter + 1;
7609
7610 <<START_OF_RLMI>>
7611 IF g_debug_mode = 'Y' THEN
7612 log_message(p_msg_token1 => 'category['||i.resource_category_code ||
7613 ']bc packet id['||i.bc_packet_id||']resList['||i.resource_list_id||']' );
7614 End if;
7615 IF i.resource_category_code = 'R' THEN
7616 -- use one level cache to derive the values and then store in plsql tabls
7617 -- derive all other input params required for rlmi api.
7618 IF i.resource_list_id is NOT NULL Then
7619
7620 ---USE one level cache for storing the values and if values are same the
7621 -- skip the process continue to process the next set of records
7622 If (l_cache_sys_link_func is NULL OR
7623 i.system_linkage_function <> l_cache_sys_link_func)OR
7624 (l_cache_doc_header_id is NULL OR
7625 i.document_header_id <> l_cache_doc_header_id) OR
7626 (l_cache_doc_type is NULL OR
7627 i.document_type <> l_cache_doc_type)OR
7628 (l_cache_exp_type is NULL OR
7629 i.expenditure_type <> l_cache_exp_type)OR
7630 (l_cache_task_id is NULL OR
7631 i.task_id <> l_cache_task_id) OR
7632 (l_cache_exp_org_id is NULL OR
7633 i.expenditure_organization_id <> l_cache_exp_org_id) THEN
7634
7635 l_job_id := NULL;
7636 l_non_labor_resource := NULL;
7637 l_non_labor_resource_org_id := NULL;
7638 l_person_id := NULL;
7639 l_vendor_id := i.vendor_id;
7640
7641 IF g_debug_mode = 'Y' THEN
7642 log_message(p_msg_token1 => 'deriving INPUT PARAMETERS FOR RESOURCE MAPPING');
7643 End if;
7644
7645 -- -----------------VENDOR ID--------------------------+
7646 IF l_vendor_id is null THEN -- it will not be null for AP/PO/REQ FC
7647
7648 IF ( i.system_linkage_function = 'VI' AND i.document_type = 'REQ' ) THEN
7649
7650 OPEN get_req_vend(i.document_header_id);
7651 FETCH get_req_vend INTO l_vendor_id;
7652 CLOSE get_req_vend;
7653
7654 ELSIF ( i.system_linkage_function = 'VI' AND i.document_type = 'PO' ) THEN
7655
7656 OPEN get_po_vend(i.document_header_id);
7657 FETCH get_po_vend INTO l_vendor_id;
7658 CLOSE get_po_vend;
7659
7660 ELSIF ( i.system_linkage_function = 'VI' AND i.document_type = 'AP' ) THEN
7661
7662 OPEN get_ap_vend(i.document_header_id);
7663 FETCH get_ap_vend INTO l_vendor_id;
7664 CLOSE get_ap_vend;
7665
7666 ELSIF ( i.system_linkage_function = 'VI' AND i.document_type IN
7667 ( 'CC_C_PAY','CC_P_PAY','CC_C_CO','CC_P_CO','CC','CP')) THEN
7668
7669 OPEN get_igc_vend(i.document_header_id);
7670 FETCH get_igc_vend INTO l_vendor_id;
7671 CLOSE get_igc_vend;
7672 END IF;
7673
7674 END IF; ---IF l_vendor_id is null THEN
7675 -- -----------------VENDOR ID--------------------------+
7676
7677 IF ( i.system_linkage_function IN ('ER','ST','OT') AND
7678 i.document_type = 'EXP' )THEN
7679 OPEN get_exp_details(i.document_header_id);
7680 FETCH get_exp_details INTO
7681 l_person_id
7682 ,l_job_id;
7683 CLOSE get_exp_details;
7684 ELSIF ( i.system_linkage_function = 'USG' ) THEN
7685 IF i.document_type <> 'EXP' Then
7686 OPEN get_non_usg_exp_details(i.expenditure_type);
7687 FETCH get_non_usg_exp_details INTO
7688 l_non_labor_resource,
7689 l_non_labor_resource_org_id;
7690 CLOSE get_non_usg_exp_details;
7691
7692 ELSIF i.document_type = 'EXP' THEN
7693 OPEN get_usg_exp_details(i.document_header_id);
7694 FETCH get_usg_exp_details INTO
7695 l_person_id,
7696 l_job_id,
7697 l_non_labor_resource,
7698 l_non_labor_resource_org_id;
7699 CLOSE get_usg_exp_details;
7700
7701 END IF;
7702 END IF; -- end of INPUT PARAMETERS
7703
7704 l_cache_sys_link_func := i.system_linkage_function;
7705 l_cache_doc_header_id := i.document_header_id;
7706 l_cache_doc_type := i.document_type;
7707 l_cache_exp_type := i.expenditure_type;
7708 l_cache_task_id := i.task_id;
7709 l_cache_exp_org_id := i.expenditure_organization_id;
7710 l_cache_person_id := l_person_id;
7711 l_cache_job_id := l_job_id;
7712 l_cache_non_lab_res :=l_non_labor_resource;
7713 l_cache_non_lab_res_org := l_non_labor_resource_org_id;
7714 l_cache_vendor_id := l_vendor_id;
7715 ELSE
7716 --retrive from cache
7717 l_person_id := l_cache_person_id;
7718 l_job_id := l_cache_job_id;
7719 l_non_labor_resource := l_cache_non_lab_res;
7720 l_non_labor_resource_org_id := l_cache_non_lab_res_org;
7721 l_vendor_id := l_cache_vendor_id;
7722
7723
7724 END IF;
7725 END IF ; -- end of resouce list is not null
7726
7727 ELSE -- budget is not categorized by resource
7728 IF g_debug_mode = 'Y' THEN
7729 log_message(p_msg_token1 => 'Not Categorized by resouce ');
7730 End if;
7731 l_result_code := NULL;
7732 IF (l_cache_non_cat_bdgt_ver_id is null or i.budget_version_id <> l_cache_non_cat_bdgt_ver_id ) then
7733 OPEN get_non_cat_rlmi(i.budget_version_id);
7734 FETCH get_non_cat_rlmi INTO l_non_cat_rlmi;
7735 IF get_non_cat_rlmi%NOTFOUND OR l_non_cat_rlmi IS NULL THEN
7736 l_result_code := 'F128';
7737 END IF;
7738 CLOSE get_non_cat_rlmi;
7739 l_cache_non_cat_bdgt_ver_id := i.budget_version_id;
7740 l_cache_non_cat_rlmi := l_non_cat_rlmi ;
7741 l_cache_non_cat_result_code := l_result_code;
7742 ELSE -- retriev from cache
7743 l_non_cat_rlmi := l_cache_non_cat_rlmi;
7744 l_result_code := l_cache_non_cat_result_code;
7745 END IF;
7746
7747 END IF; -- end if for category
7748
7749 -- Assign all the local values to plsql tables
7750 g_tab_budget_version_id(l_counter) := i.budget_version_id;
7751 g_tab_project_id(l_counter) := i.project_id;
7752 g_tab_task_id(l_counter) := i.task_id;
7753 g_tab_doc_type(l_counter) := i.document_type;
7754 g_tab_doc_header_id(l_counter) := i.document_header_id;
7755 g_tab_doc_line_id(l_counter) := i.document_line_id;
7756 g_tab_exp_org_id(l_counter) := i.expenditure_organization_id;
7757 g_tab_exp_type(l_counter) := i.expenditure_type;
7758 g_tab_exp_category(l_counter) := i.expenditure_category;
7759 g_tab_rev_category(l_counter) := i.revenue_category_code;
7760 g_tab_sys_link_func(l_counter) := i.system_linkage_function;
7761 g_tab_category_code(l_counter) := i.resource_category_code;
7762 g_tab_p_bc_packet_id(l_counter) :=i.parent_bc_packet_id;
7763 g_tab_entry_level_code(l_counter):= i.entry_level_code;
7764 g_tab_period_name(l_counter) := i.period_name;
7765 g_tab_exp_item_date(l_counter) := i.expenditure_item_date;
7766 g_tab_bc_packet_id(l_counter) := i.bc_packet_id;
7767 g_tab_exp_OU(l_counter) := i.exp_org_id;
7768 g_tab_proj_OU(l_counter) := i.proj_org_id;
7769 g_tab_rlmi(l_counter) := NULL;
7770 g_tab_non_cat_rlmi(l_counter) := l_non_cat_rlmi;
7771 g_tab_r_list_id(l_counter) := i.resource_list_id;
7772 g_tab_result_code(l_counter) := l_result_code;
7773 g_tab_result_code(l_counter) := l_result_code;
7774 g_tab_r_result_code(l_counter) := l_result_code;
7775 g_tab_rg_result_code(l_counter) := l_result_code;
7776 g_tab_t_result_code(l_counter) := l_result_code;
7777 g_tab_tt_result_code(l_counter) := l_result_code;
7778 g_tab_p_result_code(l_counter) := l_result_code;
7779 g_tab_person_id(l_counter) := l_person_id;
7780 g_tab_job_id(l_counter) := l_job_id;
7781 g_tab_vendor_id(l_counter) := l_vendor_id;
7782 g_tab_non_lab_res(l_counter) := l_non_labor_resource;
7783 g_tab_non_lab_res_org(l_counter) := l_non_labor_resource_org_id;
7784
7785 END LOOP;
7786
7787 --insert the records into tmp table
7788 IF g_tab_bc_packet_id.EXISTS(1) THEN
7789
7790 BEGIN
7791
7792
7793 FOR resList in cur_resList LOOP
7794
7795 IF resList.resource_category_code = 'R' Then
7796 -- call resource mapping api if the budget is categorized by resource
7797 -- Insert the plsql values into a temp tables
7798 FORALL i IN g_tab_bc_packet_id.First ..g_tab_bc_packet_id.Last
7799 Insert into PA_MAPPABLE_TXNS_TMP
7800 (txn_id
7801 ,person_id
7802 ,job_id
7803 ,organization_id
7804 ,vendor_id
7805 ,expenditure_type
7806 ,event_type
7807 ,non_labor_resource
7808 ,expenditure_category
7809 ,revenue_category
7810 ,non_labor_resource_org_id
7811 ,event_type_classification
7812 ,system_linkage_function
7813 ,project_role_id
7814 ,resource_list_id
7815 ,system_reference1
7816 ,system_reference2
7817 ,system_reference3
7818 )
7819 SELECT
7820 pa_mappable_txns_tmp_s.NEXTVAL
7821 ,g_tab_person_id(i)
7822 ,g_tab_job_id(i)
7823 ,g_tab_exp_org_id(i)
7824 ,g_tab_vendor_id(i)
7825 ,g_tab_exp_type(i)
7826 ,null
7827 ,g_tab_non_lab_res(i)
7828 ,g_tab_exp_category(i)
7829 ,g_tab_rev_category(i)
7830 ,g_tab_non_lab_res_org(i)
7831 ,null
7832 ,g_tab_sys_link_func(i)
7833 ,null
7834 ,g_tab_r_list_id(i)
7835 ,p_packet_id
7836 ,g_tab_bc_packet_id(i)
7837 ,g_tab_project_id(i)
7838 FROM DUAL
7839 WHERE substr(nvl(g_tab_result_code(i),'P'),1,1) not in ('R','F')
7840 AND g_tab_r_list_id(i) = resList.resource_list_id
7841 AND g_tab_budget_version_id(i) = resList.budget_version_id
7842 AND g_tab_category_code(i) = 'R' ;
7843
7844 IF sql%ROWCOUNT > 0 Then
7845 COMMIT; -- so that the transactions are available in other sessions for res map
7846 log_message(p_msg_token1 => 'Calling Resource mapping API for ResList['
7847 ||resList.resource_list_id||']');
7848 -- Call the resource map api.
7849 PA_RES_ACCUMS.new_map_txns
7850 (x_resource_list_id => resList.resource_list_id
7851 ,x_error_stage => l_error_stage
7852 ,x_error_code => l_error_msg ) ;
7853
7854 Update PA_BC_PACKETS pkt
7855 SET (pkt.resource_list_member_id
7856 ,pkt.result_code
7857 ,pkt.res_result_code
7858 ,pkt.res_grp_result_code
7859 ,pkt.task_result_code
7860 ,pkt.top_task_result_code
7861 ,pkt.project_result_code
7862 ,pkt.project_acct_result_code) =
7863 (select tmp.resource_list_member_id
7864 ,decode(tmp.resource_list_member_id,NULL
7865 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7866 ,pkt.result_code)
7867 ,decode(tmp.resource_list_member_id,NULL
7868 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7869 ,pkt.result_code)
7870 ,decode(tmp.resource_list_member_id,NULL
7871 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7872 ,pkt.result_code)
7873 ,decode(tmp.resource_list_member_id,NULL
7874 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7875 ,pkt.result_code)
7876 ,decode(tmp.resource_list_member_id,NULL
7877 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7878 ,pkt.result_code)
7879 ,decode(tmp.resource_list_member_id,NULL
7880 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7881 ,pkt.result_code)
7882 ,decode(tmp.resource_list_member_id,NULL
7883 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7884 ,pkt.result_code)
7885 from PA_MAPPABLE_TXNS_TMP tmp
7886 where tmp.system_reference1 = pkt.packet_id
7887 and tmp.system_reference2 = pkt.bc_packet_id)
7888 WHERE pkt.packet_id = p_packet_id
7889 AND EXISTS ( SELECT 'Y'
7890 FROM PA_MAPPABLE_TXNS_TMP tmp
7891 WHERE tmp.system_reference1 = pkt.packet_id
7892 AND tmp.system_reference2 = pkt.bc_packet_id);
7893
7894 END IF;
7895
7896
7897 END IF;
7898
7899 log_message(p_msg_token1 =>'Finally one Update for Non Categoriztion Resource as wells as Failed transactions');
7900 FORALL i in g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
7901 UPDATE pa_bc_packets pkt
7902 SET pkt.resource_list_member_id = decode(g_tab_category_code(i),'R',pkt.resource_list_member_id
7903 ,g_tab_non_cat_rlmi(i))
7904 ,pkt.result_code = decode(g_tab_category_code(i),'R'
7905 ,decode(pkt.resource_list_member_id,NULL
7906 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7907 ,pkt.result_code)
7908 ,decode(g_tab_non_cat_rlmi(i),NULL
7909 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7910 ,pkt.result_code)
7911 )
7912 ,pkt.res_result_code = decode(g_tab_category_code(i),'R'
7913 ,decode(pkt.resource_list_member_id,NULL
7914 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7915 ,pkt.result_code)
7916 ,decode(g_tab_non_cat_rlmi(i),NULL
7917 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7918 ,pkt.result_code)
7919 )
7920 ,pkt.res_grp_result_code = decode(g_tab_category_code(i),'R'
7921 ,decode(pkt.resource_list_member_id,NULL
7922 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7923 ,pkt.result_code)
7924 ,decode(g_tab_non_cat_rlmi(i),NULL
7925 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7926 ,pkt.result_code)
7927 )
7928 ,pkt.task_result_code = decode(g_tab_category_code(i),'R'
7929 ,decode(pkt.resource_list_member_id,NULL
7930 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7931 ,pkt.result_code)
7932 ,decode(g_tab_non_cat_rlmi(i),NULL
7933 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7934 ,pkt.result_code)
7935 )
7936 ,pkt.top_task_result_code = decode(g_tab_category_code(i),'R'
7937 ,decode(pkt.resource_list_member_id,NULL
7938 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7939 ,pkt.result_code)
7940 ,decode(g_tab_non_cat_rlmi(i),NULL
7941 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7942 ,pkt.result_code)
7943 )
7944 ,pkt.project_result_code = decode(g_tab_category_code(i),'R'
7945 ,decode(pkt.resource_list_member_id,NULL
7946 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7947 ,pkt.result_code)
7948 ,decode(g_tab_non_cat_rlmi(i),NULL
7949 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7950 ,pkt.result_code)
7951 )
7952 ,pkt.project_acct_result_code = decode(g_tab_category_code(i),'R'
7953 ,decode(pkt.resource_list_member_id,NULL
7954 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7955 ,pkt.result_code)
7956 ,decode(g_tab_non_cat_rlmi(i),NULL
7957 ,decode(substr(nvl(pkt.result_code,'P'),1,1),'P','F128',pkt.result_code)
7958 ,pkt.result_code)
7959 )
7960 WHERE pkt.packet_id = p_packet_id
7961 AND pkt.bc_packet_id = g_tab_bc_packet_id(i)
7962 AND pkt.budget_version_id = resList.budget_version_id
7963 AND pkt.budget_version_id = g_tab_budget_version_id(i)
7964 AND g_tab_r_list_id(i) = resList.resource_list_id
7965 ;
7966 END LOOP;
7967
7968 /* delete the records from tmp table */
7969 DELETE FROM PA_MAPPABLE_TXNS_TMP tmp
7970 WHERE tmp.system_reference1 = p_packet_id;
7971
7972 /* CWK labor changes update the pkts with reosurce list member ids of the summary records
7973 * information on the transactions */
7974 IF p_calling_module NOT IN ('CBC') Then
7975
7976 log_message(p_msg_token1 => 'Updating rlmi with summary record rlmi for Contigent Wkr transactions');
7977 OPEN cur_cwkRlmi ;
7978 LOOP
7979 -- Initialize the plsql tables
7980 g_tab_bc_packet_id.delete;
7981 g_tab_project_id.delete;
7982 g_tab_task_id.delete;
7983 g_tab_budget_version_id.delete;
7984 g_tab_doc_type.delete;
7985 g_tab_doc_header_id.delete;
7986 g_tab_doc_distribution_id.delete;
7987 g_tab_doc_line_id.delete;
7988 g_tab_exp_type.delete;
7989 g_tab_rlmi.delete;
7990 l_tab_resmap_pkt_line_type.delete;
7991 FETCH cur_cwkRlmi BULK COLLECT INTO
7992 g_tab_bc_packet_id
7993 ,g_tab_project_id
7994 ,g_tab_task_id
7995 ,g_tab_budget_version_id
7996 ,g_tab_doc_type
7997 ,g_tab_doc_header_id
7998 ,g_tab_doc_distribution_id
7999 ,g_tab_doc_line_id
8000 ,g_tab_exp_type
8001 ,g_tab_rlmi
8002 ,l_tab_resmap_pkt_line_type LIMIT 500;
8003 pa_funds_control_pkg.log_message(p_msg_token1=>'NumOfCwkRecs['||g_tab_bc_packet_id.count||']');
8004 IF NOT g_tab_bc_packet_id.EXISTS(1) THEN
8005 EXIT;
8006 END IF;
8007
8008 FOR i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST LOOP
8009 l_fc_utils2_cwk_rlmi := NULL;
8010 l_fc_utils2_cwk_rlmi := pa_funds_control_utils2.get_CWK_RLMI
8011 (g_tab_project_id(i)
8012 ,g_tab_task_id(i)
8013 ,g_tab_budget_version_id(i)
8014 ,g_tab_doc_header_id(i)
8015 ,g_tab_doc_distribution_id(i)
8016 ,g_tab_doc_line_id(i)
8017 ,g_tab_doc_type(i)
8018 ,g_tab_exp_type(i)
8019 ,l_tab_resmap_pkt_line_type(i)
8020 ,'FUNDS_CHECK');
8021
8022 pa_funds_control_pkg.log_message(p_msg_token1=>'bcPktId['||g_tab_bc_packet_id(i)||
8023 ']pktrlmi['||g_tab_rlmi(i)||']cwkRlmi['||l_fc_utils2_cwk_rlmi||
8024 ']pktLineType['||l_tab_resmap_pkt_line_type(i)||']');
8025 g_tab_rlmi(i) := NVL(l_fc_utils2_cwk_rlmi,g_tab_rlmi(i));
8026 END LOOP;
8027 -- Bulk update the cwkRlmi
8028 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
8029 UPDATE pa_bc_packets pkt
8030 SET pkt.resource_list_member_id = NVL(g_tab_rlmi(i),pkt.resource_list_member_id)
8031 WHERE pkt.packet_id = p_packet_id
8032 AND pkt.bc_packet_id = g_tab_bc_packet_id(i)
8033 AND pkt.document_type in ('PO','EXP')
8034 ANd NVL(pkt.summary_record_flag,'N') <> 'Y'
8035 AND substr(nvl(pkt.result_code,'P'),1,1) <> 'F' ;
8036 log_message(p_msg_token1 => 'No of rows updated['||sql%rowcount||']');
8037 IF cur_cwkRlmi%NOTFOUND THEN
8038 EXIT;
8039 END IF;
8040 END LOOP;
8041 CLOSE cur_cwkRlmi;
8042
8043 END IF;
8044
8045 EXCEPTION
8046 WHEN NO_DATA_FOUND Then
8047 Null;
8048 WHEN OTHERS THEN
8049 RAISE;
8050 END ;
8051
8052 END IF;
8053
8054 COMMIT;
8055 PA_DEBUG.reset_err_stack;
8056
8057 EXCEPTION
8058 WHEN OTHERS THEN
8059 RAISE;
8060
8061 END DERIVE_RLMI;
8062
8063
8064
8065
8066 ---------------------------------------------------------------------------------------------------
8067 --- This api set up the resource list member id ,parent_resource_id,parent_member_id,top task id
8068 -- bud_task_id ,funds control level codes and pa date gl date budget ccid and encumbrance type id
8069 -- for for each record in the packet.
8070 -----------------------------------------------------------------------------------------------------
8071 FUNCTION funds_check_setup
8072 ( p_packet_id IN pa_bc_packets.packet_id%type,
8073 p_mode IN varchar2,
8074 p_sob IN NUMBER,
8075 p_reference1 IN varchar2 default null,
8076 p_reference2 IN varchar2 default null,
8077 p_calling_module IN varchar2
8078
8079 ) return boolean IS
8080
8081 -- This cursor picks all the details required for resource list member id mapping
8082 -- one level cache logic is used to update the pa_bc_packet table
8083 CURSOR setup_details IS
8084 SELECT pbc.rowid,
8085 pbc.budget_version_id,
8086 pbc.project_id,
8087 pbc.task_id,
8088 pbc.document_type,
8089 pbc.document_header_id,
8090 pbc.expenditure_organization_id,
8091 pbc.expenditure_type,
8092 pm.categorization_code,
8093 pbc.parent_bc_packet_id,
8094 pm.entry_level_code ,
8095 pbc.accounted_dr,
8096 pbc.accounted_cr,
8097 pbc.period_name,
8098 pbc.expenditure_item_date,
8099 pbc.bc_packet_id,
8100 pbc.txn_ccid,
8101 pbc.old_budget_ccid,
8102 pbc.org_id,
8103 pbc.resource_list_member_id,
8104 bv.resource_list_id,
8105 pm.time_phased_type_code,
8106 pb.amount_type,
8107 pb.boundary_code,
8108 pbc.set_of_books_id,
8109 pbc.gl_date,
8110 pbc.burden_method_code,
8111 --decode(pbc.burden_method_code,'S','SAME',
8112 -- 'D','DIFFERENT',
8113 -- 'N','NONE',
8114 -- pbc.burden_method_code) burden_method_code,
8115 pbc.budget_line_id,
8116 pbc.budget_ccid
8117 FROM pa_bc_packets pbc,
8118 pa_budget_versions bv,
8119 pa_budget_entry_methods pm,
8120 pa_budgetary_control_options pb
8121 WHERE pbc.packet_id = p_packet_id
8122 AND pbc.budget_version_id = bv.budget_version_id
8123 AND bv.budget_entry_method_code = pm.budget_entry_method_code
8124 AND pbc.status_code in ('P','L')
8125 AND substr(nvl(pbc.result_code,'P'),1,1) not in ('R','F')
8126 AND pb.project_id = pbc.project_id
8127 AND pb.BDGT_CNTRL_FLAG = 'Y'
8128 AND pb.BUDGET_TYPE_CODE = bv.budget_type_code
8129 AND ((pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
8130 and pb.EXTERNAL_BUDGET_CODE = 'GL')
8131 OR
8132 (pbc.document_type in ('AP','PO','REQ','EXP','CC_P_PAY','CC_C_PAY')
8133 and pb.EXTERNAL_BUDGET_CODE is NULL)
8134 OR
8135 (pbc.document_type in ('CC_P_CO','CC_C_CO')
8136 and pb.EXTERNAL_BUDGET_CODE = 'CC' )
8137 )
8138 ORDER BY /** Bug fix :2004139 order by clause is changed to column names **/
8139 pbc.project_id,
8140 pbc.budget_version_id,
8141 pm.entry_level_code ,
8142 pm.categorization_code,
8143 pbc.task_id,
8144 pbc.expenditure_type,
8145 pbc.document_type,
8146 pbc.document_header_id
8147 ;
8148
8149 /* Bug 5631763 */
8150 cursor c_funds_control_level(bud_version_id NUMBER) is
8151 select fund_control_level_project,
8152 fund_control_level_task ,
8153 fund_control_level_res_grp,
8154 fund_control_level_res
8155 from pa_budgetary_control_options pb,
8156 pa_budget_versions pv
8157 where pv.project_id = pb.project_id
8158 AND pb.BDGT_CNTRL_FLAG = 'Y'
8159 AND pb.BUDGET_TYPE_CODE = pv.budget_type_code
8160 AND pv.budget_version_id = bud_version_id;
8161 /* Bug 5631763 */
8162
8163 -- Declare local variables to hold values and use one level cache
8164 l_return_status VARCHAR2(10);
8165 l_status_code VARCHAR2(10);
8166 l_result_code VARCHAR2(10);
8167 l_r_result_code VARCHAR2(10);
8168 l_rg_result_code VARCHAR2(10);
8169 l_t_result_code VARCHAR2(10);
8170 l_tt_result_code VARCHAR2(10);
8171 l_p_result_code VARCHAR2(10);
8172 l_p_acct_result_code VARCHAR2(10);
8173 l_pre_rlmi NUMBER;
8174 l_project_id NUMBER;
8175 l_pre_project_id NUMBER;
8176 l_task_id NUMBER;
8177 l_pre_task_id NUMBER;
8178 l_budget_version_id NUMBER;
8179 l_pre_budget_version_id NUMBER;
8180 l_pre_res_list_id NUMBER;
8181 l_exp_org_id NUMBER;
8182 l_pre_exp_org_id NUMBER;
8183 l_exp_type VARCHAR2 ( 30 );
8184 l_pre_exp_type VARCHAR2 ( 30 );
8185 l_expenditure_type VARCHAR2 ( 30 );
8186 l_doc_type VARCHAR2 ( 10 );
8187 l_pre_doc_type VARCHAR2 ( 10 );
8188 l_doc_header_id NUMBER;
8189 l_pre_doc_header_id NUMBER;
8190 l_parent_id NUMBER;
8191 l_error_stage VARCHAR2 ( 2000 ):= NULL;
8192 l_error_code NUMBER;
8193 l_group_by_none VARCHAR2 ( 60 );
8194 l_num_rows NUMBER := 200;
8195 l_parent_member_id NUMBER;
8196 l_parent_resource_id NUMBER;
8197 l_bud_rlmi NUMBER;
8198 l_bud_task_id NUMBER;
8199 l_top_task_id NUMBER;
8200 l_trxn_ccid NUMBER;
8201 l_budget_ccid NUMBER;
8202 l_budget_line_id pa_budget_lines.budget_line_id%type;
8203 l_r_fclevel_code VARCHAR2(10);
8204 l_rg_fclevel_code VARCHAR2(10);
8205 l_t_fclevel_code VARCHAR2(10);
8206 l_tt_fclevel_code VARCHAR2(10);
8207 l_p_fclevel_code VARCHAR2(10);
8208 l_p_acct_fclevel_code VARCHAR2(10);
8209 l_effect_on_funds_code VARCHAR2(10);
8210 l_pre_category_code VARCHAR2(30);
8211 l_category_code VARCHAR2(30);
8212 l_entry_level_code VARCHAR2(10);
8213 l_pre_entry_level_code VARCHAR2(10);
8214 l_ext_bdgt_type VARCHAR2(10);
8215 l_ext_bdgt_link VARCHAR2(10);
8216 l_encum_type_id NUMBER;
8217 l_gl_date DATE;
8218 l_pa_date DATE;
8219 l_error_msg VARCHAR2(2000);
8220 l_prv_burden_method VARCHAR2(20);
8221 l_burden_method VARCHAR2(20);
8222 l_pre_ext_bdgt_link VARCHAR2(20);
8223 l_pre_time_phase_code varchar2(80);
8224 l_pre_amount_type varchar2(80);
8225 l_pre_boundary_code varchar2(80);
8226 l_pre_fc_sdate Date := Null;
8227 l_pre_fc_edate Date := Null;
8228 l_trx_item_date Date := Null;
8229 l_fc_start_date Date := Null;
8230 l_fc_end_date Date := Null;
8231 l_err_buff VARCHAR2(2000);
8232
8233 l_imp_count Number := 0;
8234
8235 BEGIN
8236 -- Initialize the error stack
8237 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.setup');
8238
8239 If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
8240 ,'TRXIMPORT','RESERVE_BASELINE') then
8241
8242 -- Note: For commitment Funds check, derive_rlmi is called in pa_funds_control_pkg1
8243 -- R12: BC-SLA Integration ..
8244
8245 IF g_debug_mode = 'Y' THEN
8246 log_message(p_msg_token1 => 'inside the fundscheck setup api Calling Derive_rlmi ');
8247 End if;
8248
8249 DERIVE_RLMI
8250 ( p_packet_id => p_packet_id
8251 ,p_mode => p_mode
8252 ,p_sob => p_sob
8253 ,p_reference1 => p_reference1
8254 ,p_reference2 => p_reference2
8255 ,p_calling_module => p_calling_module
8256 );
8257
8258 End If;
8259
8260 -- open cursor and fetch 200 rows at a time
8261 OPEN setup_details;
8262 IF g_debug_mode = 'Y' THEN
8263 log_message(p_msg_token1 => 'opened the cursor for setup details');
8264 End if;
8265 LOOP
8266 -- initialize the pl/sql talbes
8267 Init_plsql_tabs;
8268
8269 FETCH setup_details BULK COLLECT INTO
8270 g_tab_rowid,
8271 g_tab_budget_version_id,
8272 g_tab_project_id,
8273 g_tab_task_id,
8274 g_tab_doc_type,
8275 g_tab_doc_header_id,
8276 g_tab_exp_org_id,
8277 g_tab_exp_type,
8278 g_tab_category_code,
8279 g_tab_p_bc_packet_id,
8280 g_tab_entry_level_code ,
8281 g_tab_accounted_dr,
8282 g_tab_accounted_cr,
8283 g_tab_period_name,
8284 g_tab_exp_item_date,
8285 g_tab_bc_packet_id,
8286 g_tab_trxn_ccid,
8287 g_tab_old_budget_ccid,
8288 g_tab_OU,
8289 g_tab_rlmi,
8290 g_tab_r_list_id,
8291 g_tab_time_phase_type_code,
8292 g_tab_amount_type,
8293 g_tab_boundary_code,
8294 g_tab_sob_id,
8295 g_tab_exp_gl_date,
8296 g_tab_burden_method_code,
8297 g_tab_budget_line_id,
8298 g_tab_budget_ccid
8299 LIMIT l_num_rows;
8300 IF g_debug_mode = 'Y' THEN
8301 log_message(p_msg_token1 =>'Afeter fetch statements');
8302 End if;
8303
8304 If NOT g_tab_rowid.EXISTS(1) then
8305 IF g_debug_mode = 'Y' THEN
8306 log_message(p_msg_token1 => 'Fetched the NO ROWS ');
8307 End if;
8308 exit;
8309 Else
8310 IF g_debug_mode = 'Y' THEN
8311 log_message(p_msg_token1 => 'Fetched the rows into plsql tables');
8312 End if;
8313 null;
8314 End if;
8315
8316 -- for each record in derive the resource list member id, parent resource id ,
8317 -- bud task id , top taskid funds control level codes, budget ccid, gl date ,
8318 -- pa date, encumbrance type id etc.
8319 --
8320 FOR i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST LOOP
8321
8322 g_tab_p_resource_id(i) := null;
8323 g_tab_p_member_id(i) := null;
8324 g_tab_bud_task_id(i) := null;
8325 g_tab_bud_rlmi(i) := null;
8326 g_tab_tt_task_id(i) := null;
8327 g_tab_r_fclevel_code(i) := null;
8328 g_tab_rg_fclevel_code(i) := null;
8329 g_tab_t_fclevel_code(i) := null;
8330 g_tab_tt_fclevel_code(i) := null;
8331 g_tab_p_fclevel_code(i) := null;
8332 g_tab_p_acct_fclevel_code(i) := null;
8333 g_tab_status_code(i) := null;
8334 g_tab_result_code(i) := null;
8335 g_tab_r_result_code(i) := null;
8336 g_tab_rg_result_code(i) := null;
8337 g_tab_t_result_code(i) := null;
8338 g_tab_tt_result_code(i) := null;
8339 g_tab_p_result_code(i) := null;
8340 g_tab_p_acct_result_code(i) := null;
8341 --g_tab_budget_ccid(i) := null;
8342 g_tab_effect_fclevel(i) := null;
8343 g_tab_encum_type_id(i) := null;
8344 g_tab_gl_date(i) := null;
8345 g_tab_pa_date(i) := null;
8346 g_tab_start_date(i) := null;
8347 g_tab_end_date(i) := null;
8348 g_tab_ext_bdgt_link(i) := null;
8349
8350 /* Bug 5631763 */
8351
8352 g_Tfund_control_level := NULL;
8353 g_Pfund_control_level := NULL;
8354 g_RGfund_control_level := NULL;
8355 g_Rfund_control_level := NULL;
8356
8357
8358 OPEN c_funds_control_level(g_tab_budget_version_id(i));
8359 FETCH c_funds_control_level INTO
8360 g_Pfund_control_level ,
8361 g_Tfund_control_level ,
8362 g_RGfund_control_level,
8363 g_Rfund_control_level;
8364 CLOSE c_funds_control_level;
8365
8366 /* Bug 5631763 */
8367
8368 <<START_OF_RLMI>>
8369 IF g_debug_mode = 'Y' THEN
8370 log_message(p_msg_token1 => 'category['||g_tab_category_code(i)||
8371 ']bc packet id['||g_tab_bc_packet_id(i)||']' );
8372 End if;
8373
8374 -- derive the budget resouce list member id , parent resource
8375 -- id based the resource list member id and use one level cache
8376
8377 IF (l_pre_rlmi is NULL or g_tab_rlmi(i) <> l_pre_rlmi )OR
8378 (l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i))OR
8379 (l_pre_budget_version_id is NULL or l_pre_budget_version_id <>
8380 g_tab_budget_version_id(i) )OR
8381 (l_pre_category_code is NULL or l_pre_category_code <> g_tab_category_code(i))
8382 Then
8383 IF g_debug_mode = 'Y' THEN
8384 log_message(p_msg_token1 => 'Calling bud_res_list_id_update api ');
8385 End if;
8386 IF NOT bud_res_list_id_update
8387 ( p_project_id => g_tab_project_id(i),
8388 p_budget_version_id => g_tab_budget_version_id(i),
8389 p_resource_list_member_id => g_tab_rlmi(i),
8390 p_categorization_code => g_tab_category_code(i),
8391 x_bud_resource_list_member_id => l_bud_rlmi,
8392 x_parent_resource_id => l_parent_resource_id
8393 ) Then
8394 IF g_debug_mode = 'Y' THEN
8395 log_message(p_msg_token1 =>
8396 'Failed to derive bud_rlmi and parent resource id');
8397 End if;
8398 l_error_msg := 'Failed to derive bud_rlmi and parent resource id';
8399 END IF;
8400 IF g_debug_mode = 'Y' THEN
8401 log_message(p_msg_token1 => 'bud rlmi ['||l_bud_rlmi||']parent res ['||
8402 l_parent_resource_id||']');
8403 End if;
8404
8405 END IF;
8406
8407
8408 -- derive the budgeted task and top task id
8409 IF (l_pre_task_id is NULL or l_pre_task_id <> g_tab_task_id(i) )OR
8410 (l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i))OR
8411 (l_pre_budget_version_id is NULL or l_pre_budget_version_id <>
8412 g_tab_budget_version_id(i) )OR
8413 (l_pre_entry_level_code is NULL or l_pre_entry_level_code
8414 <> g_tab_entry_level_code(i) ) Then
8415 IF g_debug_mode = 'Y' THEN
8416 log_message(p_msg_token1 => 'Calling bud task id update api ');
8417 End if;
8418 IF NOT budget_task_id_update
8419 ( p_project_id => g_tab_project_id(i),
8420 p_task_id => g_tab_task_id(i),
8421 p_budget_version_id => g_tab_budget_version_id(i),
8422 p_entry_level_code => g_tab_entry_level_code(i),
8423 x_bud_task_id => l_bud_task_id,
8424 x_top_task_id => l_top_task_id
8425 ) then
8426 IF g_debug_mode = 'Y' THEN
8427 log_message(p_msg_token1 => 'Failed to derive top task and bud task ids');
8428 End if;
8429 l_error_msg := 'Failed to derive top task and bud task ids';
8430 END IF;
8431 END IF;
8432
8433
8434 -- Derive the effect on funds control based on the accounted dr
8435 -- and accounted cr
8436 IF g_debug_mode = 'Y' THEN
8437 log_message(p_msg_token1 => 'Calling get_fclevel_code api ');
8438 End if;
8439 IF NOT get_fclevel_code
8440 (p_accounted_dr => g_tab_accounted_dr(i),
8441 p_accounted_cr => g_tab_accounted_cr(i),
8442 x_effect_on_funds_code => l_effect_on_funds_code) Then
8443 IF g_debug_mode = 'Y' THEN
8444 log_message(p_msg_token1 => 'Failed to derive Effect on Funds control level code');
8445 End if;
8446 l_error_msg := 'Failed to derive Effect on Funds control level code';
8447 END IF;
8448
8449 -- Derive the funds control level codes for each level ie resource
8450 -- resource group, task, top task and project level
8451 IF g_debug_mode = 'Y' THEN
8452 log_message(p_msg_token1 => 'Calling funds_ctrl_level_code api ');
8453 End if;
8454 IF NOT funds_ctrl_level_code (
8455 p_project_id => g_tab_project_id(i),
8456 p_task_id => g_tab_task_id(i),
8457 p_top_task_id => l_top_task_id,
8458 p_parent_member_id => l_parent_resource_id,
8459 p_resource_list_member_id => g_tab_rlmi(i),
8460 p_budget_version_id => g_tab_budget_version_id(i),
8461 p_bud_task_id => l_bud_task_id,
8462 p_categorization_code => g_tab_category_code(i),
8463 x_r_funds_control_level_code => l_r_fclevel_code,
8464 x_rg_funds_control_level_code => l_rg_fclevel_code,
8465 x_t_funds_control_level_code => l_t_fclevel_code,
8466 x_tt_funds_control_level_code => l_tt_fclevel_code,
8467 x_p_funds_control_level_code => l_p_fclevel_code
8468 ) then
8469 IF g_debug_mode = 'Y' THEN
8470 log_message(p_msg_token1 => 'Failed to derive Funds control level codes');
8471 End if;
8472 l_error_msg := 'Failed to derive Funds control level codes';
8473 END IF;
8474
8475 -- check whether the budget type is STD or CBC
8476 IF g_tab_doc_type(i) in ('PO','REQ','AP','EXP','CC_P_PAY','CC_C_PAY') then
8477 l_ext_bdgt_type := 'STD';
8478 ELSIF g_tab_doc_type(i) in ('CC_C_CO','CC_P_CO') then
8479 l_ext_bdgt_type := 'CBC';
8480 End IF;
8481
8482
8483 --check whether the project is linked or not if linked with std
8484 -- budget then derive all the encumbrance details
8485 l_ext_bdgt_link := 'N';
8486 IF l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i) then
8487 l_ext_bdgt_link := pa_funds_control_utils.get_bdgt_link
8488 ( p_project_id =>g_tab_project_id(i),
8489 p_calling_mode => l_ext_bdgt_type);
8490 l_pre_ext_bdgt_link := l_ext_bdgt_link;
8491 Else
8492 l_ext_bdgt_link := l_pre_ext_bdgt_link;
8493 End IF;
8494 IF g_debug_mode = 'Y' THEN
8495 log_message(p_msg_token1 => 'l_ext_bdgt_link ['||l_ext_bdgt_link||']');
8496 End if;
8497
8498 -- Dervie the encumbrance details such as gl date / pa date,
8499 -- budget ccid etc,
8500 IF g_debug_mode = 'Y' THEN
8501 log_message(p_msg_token1 =>'Period name ['||g_tab_period_name(i)||
8502 ']exp item date ['||g_tab_exp_item_date(i)||']doc type ['|| g_tab_doc_type(i)||']');
8503 End if;
8504
8505
8506 l_budget_ccid := null;
8507 l_budget_line_id := null;
8508 l_gl_date := null;
8509 l_pa_date := null;
8510
8511 IF NOT encum_detail_update
8512 (p_mode => p_mode,
8513 p_project_id => g_tab_project_id(i),
8514 p_Task_id => g_tab_task_id(i),
8515 p_Budget_version_id => g_tab_budget_version_id(i),
8516 p_Resource_list_member_id => g_tab_rlmi(i),
8517 p_sob_id => p_sob,
8518 p_Period_name => g_tab_period_name(i),
8519 p_Expenditure_item_date => g_tab_exp_item_date(i),
8520 p_document_type => g_tab_doc_type(i),
8521 p_ext_bdgt_type => l_ext_bdgt_type,
8522 p_ext_bdgt_link => l_ext_bdgt_link,
8523 p_bdgt_entry_level => g_tab_entry_level_code(i),
8524 p_top_task_id => l_top_task_id,
8525 p_OU => g_tab_OU(i),
8526 p_calling_module => p_calling_module,
8527 x_budget_ccid => l_budget_ccid,
8528 x_budget_line_id => l_budget_line_id,
8529 x_gl_date => l_gl_date,
8530 x_pa_date => l_pa_date,
8531 x_result_code => l_result_code,
8532 x_r_result_code => l_r_result_code,
8533 x_rg_result_code => l_rg_result_code,
8534 x_t_result_code => l_t_result_code,
8535 x_tt_result_code => l_tt_result_code,
8536 x_p_result_code => l_p_result_code,
8537 x_p_acct_result_code => l_p_acct_result_code
8538 ) then
8539 IF g_debug_mode = 'Y' THEN
8540 log_message(p_msg_token1 => 'Failed to derive Encumbrance Details ');
8541 End if;
8542 l_error_msg := 'Failed to derive Encumbrance Details ';
8543 IF g_debug_mode = 'Y' THEN
8544 log_message(p_msg_token1 => 'l_budget_ccid ['||l_budget_ccid||']l_gl_date['
8545 ||l_gl_date||']l_pa_date['||l_pa_date||']');
8546 End if;
8547 GOTO END_OF_FC_SETUP_PROCESS;
8548
8549 END IF;
8550
8551 IF g_debug_mode = 'Y' THEN
8552 log_message(p_msg_token1 => 'After Encumbrance Details api');
8553 End if;
8554
8555 If p_calling_module not in
8556 ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ' ,'TRXIMPORT','RESERVE_BASELINE') then
8557
8558 l_budget_ccid := g_tab_budget_ccid(i);
8559 l_budget_line_id := g_tab_budget_line_id(i);
8560
8561 End If;
8562
8563 -- check if the project type is burden on different seperate ei
8564 -- then update the burden line tranaction ccid with budget ccid
8565 log_message(p_msg_token1 => 'Update the trxn ccid for bdn lines ');
8566
8567 l_trxn_ccid := g_tab_trxn_ccid(i);
8568
8569 l_burden_method := g_tab_burden_method_code(i);
8570
8571 If l_burden_method is NULL then
8572
8573 IF l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i) then
8574
8575 l_burden_method := check_bdn_on_sep_item (g_tab_project_id(i));
8576 l_prv_burden_method := l_burden_method;
8577 Else
8578 l_burden_method := l_prv_burden_method;
8579 End if;
8580
8581 Else
8582
8583 l_prv_burden_method := l_burden_method;
8584
8585 End If;
8586
8587 IF g_debug_mode = 'Y' THEN
8588 log_message(p_msg_token1 => 'l_burden_method ='||l_burden_method);
8589 End if;
8590 If g_tab_p_bc_packet_id(i) is NOT NULL and l_ext_bdgt_link = 'Y' then
8591 --IF l_burden_method in ( 'DIFFERENT','SAME') then
8592 IF l_burden_method in ( 'D','S') then
8593 IF g_debug_mode = 'Y' THEN
8594 log_message(p_msg_token1 =>'g_tab_trxn_ccid(i) ='||l_budget_ccid);
8595 End if;
8596 l_trxn_ccid := l_budget_ccid;
8597 End if;
8598 End if;
8599
8600 -- check if the budget is linked to external budget GL then
8601 -- transaction ccid must equal to budget ccid otherwise error out NOCOPY
8602 -- differenct cases: Burden on same ei - donot check for raw line
8603 -- Burden on sep ei - check trxn ccid = bdgt_ccid
8604 -- NO burden for ei - check trxn ccid = bdgt_ccid for raw line
8605 IF g_debug_mode = 'Y' THEN
8606 log_message(p_msg_token1 =>'ext budget link ['||l_ext_bdgt_link||
8607 ']txn ccid ['||l_trxn_ccid ||']budget ccid ['||l_budget_ccid || ']' );
8608 End if;
8609
8610 ---- If the calling mode NOT IN Base line then derive encum type id
8611 --- get the encum_type_id from api get_budget_control_options for
8612 --- the given project_id
8613 IF l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i) then
8614 If P_mode NOT IN ('B','S') then
8615 l_encum_type_id := pa_funds_control_utils.Get_encum_type_id
8616 ( p_project_id => g_tab_project_id(i),
8617 p_calling_mode => l_ext_bdgt_type);
8618 if l_encum_type_id is null and l_ext_bdgt_link = 'Y' then
8619 --Error msg : 'F135 = Transaction failed due to Encumbrance type is null';
8620 --l_status_code := 'R';
8621 l_result_code := 'F135';
8622 l_r_result_code := 'F135';
8623 l_rg_result_code := 'F135';
8624 l_t_result_code := 'F135';
8625 l_tt_result_code := 'F135';
8626 l_p_result_code := 'F135';
8627 l_p_acct_result_code := 'F135';
8628 End if;
8629 End if;
8630 End if;
8631
8632 IF substr(nvl(l_result_code,'P'),1,1) <> 'F' Then -- result_code check
8633
8634 If g_tab_time_phase_type_code(i) = 'G' Then
8635 -- for document type exp pass the gl date derived by the cdls for all others
8636 -- derive gl date as the end of the period name
8637 If g_tab_doc_type(i) = 'EXP' Then
8638 l_trx_item_date := g_tab_exp_gl_date(i);
8639 Else
8640 l_trx_item_date := nvl(l_gl_date,g_tab_exp_gl_date(i)); --Bug 5495666
8641 End If;
8642 Elsif g_tab_time_phase_type_code(i) = 'P' Then
8643 l_trx_item_date := nvl(l_pa_date,g_tab_exp_item_date(i)); --Bug 5495666
8644 Else
8645 l_trx_item_date := g_tab_exp_item_date(i);
8646 End if;
8647
8648 /* ========================================================================================+
8649 Following code is incorrect ..not required.
8650 -- If p_mode is 'B' and 'S', use the period_name stamped on the txn. being funds checked
8651 -- to get the start and end date
8652 -- In normal FC mode, call pa_funds_control_pkg1.setup_start_end_date to derive dates
8653 log_message(p_msg_token1 =>'Mode ['||p_mode||'] Period name['||g_tab_period_name(i)||']');
8654
8655 If p_mode in ('B','S') then -- Mode check
8656 Begin
8657 SELECT gl.start_date,gl.end_date
8658 INTO l_fc_start_date,l_fc_end_date
8659 FROM gl_period_statuses gl
8660 WHERE gl.application_id = 101
8661 AND gl.set_of_books_id = p_sob
8662 AND gl.period_name = g_tab_period_name(i);
8663 Exception
8664 When no_data_found then
8665 l_result_code := 'F136';
8666 IF g_debug_mode = 'Y' THEN
8667 log_message(p_msg_token1 =>'Mode ['||p_mode||'] Exception: No Data Found - F136');
8668 END IF;
8669 When too_many_rows then
8670 l_result_code := 'F136';
8671 IF g_debug_mode = 'Y' THEN
8672 log_message(p_msg_token1 =>'Mode ['||p_mode||'] Exception: Too Many Rows - F136');
8673 END IF;
8674 End;
8675
8676 Else -- Mode check
8677 ===============================================================================================+ */
8678
8679 If (l_pre_project_id is NULL or l_pre_project_id <> g_tab_project_id(i)) OR
8680 (l_pre_budget_version_id is NULL or l_pre_budget_version_id <> g_tab_budget_version_id(i) ) OR
8681 (l_pre_time_phase_code is NULL or l_pre_time_phase_code <> g_tab_time_phase_type_code(i)) OR
8682 (l_pre_amount_type is NULL or l_pre_amount_type <> g_tab_amount_type(i)) OR
8683 (l_pre_boundary_code is NULL or l_pre_boundary_code <> g_tab_boundary_code(i)) OR
8684 (l_pre_fc_sdate is NULL or l_pre_fc_edate is NULL OR
8685 trunc(l_trx_item_date) NOT BETWEEN l_pre_fc_sdate AND l_pre_fc_edate) THEN -- call date API
8686 If g_debug_mode = 'Y' THEN
8687 log_message(p_msg_token1 => 'Calling pa_funds_control_pkg1.setup_start_end_date API');
8688 End if;
8689
8690 /*PAM changes derive start and end dates */
8691 pa_funds_control_pkg1.setup_start_end_date (
8692 p_packet_id => p_packet_id
8693 ,p_bc_packet_id => g_tab_bc_packet_id(i)
8694 ,p_project_id => g_tab_project_id(i)
8695 ,p_budget_version_id => g_tab_budget_version_id(i)
8696 ,p_time_phase_type_code => g_tab_time_phase_type_code(i)
8697 ,p_expenditure_item_date => l_trx_item_date
8698 ,p_amount_type => g_tab_amount_type(i)
8699 ,p_boundary_code => g_tab_boundary_code(i)
8700 ,p_set_of_books_id => g_tab_sob_id(i)
8701 ,x_start_date => l_fc_start_date
8702 ,x_end_date => l_fc_end_date
8703 ,x_error_code => l_error_code
8704 ,x_err_buff => l_err_buff
8705 ,x_return_status => l_return_status
8706 ,x_result_code => l_result_code
8707 );
8708 If g_debug_mode = 'Y' THEN
8709 log_message(p_msg_token1 => 'End of setup_start_end_date Resultcode['||l_result_code||']');
8710 End if;
8711
8712 Else --retrieve fro cache
8713 l_fc_start_date := l_pre_fc_sdate;
8714 l_fc_end_date := l_pre_fc_edate ;
8715 End If; -- call date API
8716
8717 --End If; -- Mode check
8718
8719
8720 END If; -- result_code check
8721
8722 IF g_debug_mode = 'Y' THEN
8723 log_message(p_msg_token1 =>'l_fc_start_date ['||l_fc_start_date||'] l_fc_end_date ['||l_fc_end_date||']');
8724 log_message(p_msg_token1 => 'storing values in local variables');
8725 End if;
8726
8727 ---------------------------------------------------------------
8728 -- store the values in local variables
8729 l_pre_doc_header_id := g_tab_doc_header_id(i) ;
8730 l_pre_doc_type := g_tab_doc_type(i) ;
8731 l_pre_exp_type := g_tab_exp_type(i) ;
8732 l_pre_project_id := g_tab_project_id(i) ;
8733 l_pre_budget_version_id := g_tab_budget_version_id(i) ;
8734 l_pre_task_id := g_tab_task_id(i) ;
8735 l_pre_exp_org_id := g_tab_exp_org_id(i) ;
8736 l_pre_res_list_id := g_tab_r_list_id(i);
8737 l_pre_rlmi := g_tab_rlmi(i);
8738 l_pre_entry_level_code := g_tab_entry_level_code(i);
8739 l_pre_category_code := g_tab_category_code(i);
8740 l_pre_time_phase_code := g_tab_time_phase_type_code(i);
8741 l_pre_amount_type := g_tab_amount_type(i);
8742 l_pre_boundary_code := g_tab_boundary_code(i);
8743 l_pre_fc_sdate := l_fc_start_date;
8744 l_pre_fc_edate := l_fc_end_date;
8745 IF g_debug_mode = 'Y' THEN
8746 log_message(p_msg_token1 =>'end of storing values in local variables');
8747 End if;
8748
8749 << END_OF_FC_SETUP_PROCESS>>
8750 ----------------------------------------------------------------
8751 -- Assign the out NOCOPY parameters to pl/sql tables
8752 ----------------------------------------------------------------
8753 IF g_debug_mode = 'Y' THEN
8754 log_message(p_msg_token1 => 'assiging out NOCOPY param values to plsql tables');
8755 End if;
8756 --if the funds check is called in Forcepass mode, then after deriving
8757 -- all the setup parameters if there is no error then update the result code
8758 -- to success and donot call pa_fcp_process
8759 If p_mode in ('F') and substr(nvl(l_result_code,'P'),1,1) = 'P' then
8760 l_result_code := 'P116'; -- Transaction passed funds check in forcepass mode
8761 l_r_result_code := 'P116';
8762 l_rg_result_code := 'P116';
8763 l_t_result_code := 'P116';
8764 l_tt_result_code := 'P116';
8765 l_p_result_code := 'P116';
8766 l_p_acct_result_code := 'P116';
8767 End if;
8768
8769 g_tab_p_resource_id(i) := l_parent_resource_id;
8770 g_tab_p_member_id(i) := l_parent_member_id;
8771 g_tab_bud_task_id(i) := l_bud_task_id;
8772 g_tab_bud_rlmi(i) := l_bud_rlmi;
8773 g_tab_tt_task_id(i) := l_top_task_id;
8774 g_tab_r_fclevel_code(i) := l_r_fclevel_code;
8775 g_tab_rg_fclevel_code(i) := l_rg_fclevel_code;
8776 g_tab_t_fclevel_code(i) := l_t_fclevel_code;
8777 g_tab_tt_fclevel_code(i) := l_tt_fclevel_code;
8778 g_tab_p_fclevel_code(i) := l_p_fclevel_code;
8779 g_tab_p_acct_fclevel_code(i) := l_p_acct_fclevel_code;
8780 g_tab_result_code(i) := l_result_code;
8781 g_tab_r_result_code(i) := l_r_result_code;
8782 g_tab_rg_result_code(i) := l_rg_result_code;
8783 g_tab_t_result_code(i) := l_t_result_code;
8784 g_tab_tt_result_code(i) := l_tt_result_code;
8785 g_tab_p_result_code(i) := l_p_result_code;
8786 g_tab_p_acct_result_code(i) := l_p_acct_result_code;
8787 g_tab_trxn_ccid(i) := l_trxn_ccid;
8788 g_tab_budget_ccid(i) := l_budget_ccid;
8789 g_tab_burden_method_code(i) := l_burden_method;
8790 g_tab_budget_line_id(i) := l_budget_line_id;
8791 g_tab_effect_fclevel(i) := l_effect_on_funds_code;
8792 g_tab_encum_type_id(i) := l_encum_type_id;
8793 g_tab_gl_date(i) := l_gl_date;
8794 g_tab_pa_date(i) := l_pa_date;
8795 g_tab_ext_bdgt_link(i) := l_ext_bdgt_link;
8796 g_tab_start_date(i) := l_fc_start_date;
8797 g_tab_end_date(i) := l_fc_end_date;
8798
8799 IF g_debug_mode = 'Y' THEN
8800 log_message(p_msg_token1 => 'End of Assignments');
8801 End if;
8802
8803
8804 END LOOP; -- end of forloop
8805 IF g_debug_mode = 'Y' THEN
8806 log_message(p_msg_token1 => 'After loop calling FORALL update statement');
8807 End if;
8808
8809 -- update the pa bc pakcets in a batch of 200 records after dering the setup
8810 -- param values
8811 /*****
8812 log_message(p_msg_token1 => 'update bc packets for batch of 200 record ');
8813 for i in g_tab_rowid.FIRST .. g_tab_rowid.LAST loop
8814 log_message(p_msg_token1 => 'g_tab_bc_packet_id ='||g_tab_bc_packet_id(i));
8815 log_message(p_msg_token1 => 'g_tab_p_resource_id(i) ='||g_tab_p_resource_id(i));
8816 log_message(p_msg_token1 => 'g_tab_bud_task_id(i) ='||g_tab_bud_task_id(i));
8817 log_message(p_msg_token1 => 'g_tab_bud_rlmi(i) ='||g_tab_bud_rlmi(i));
8818 log_message(p_msg_token1 => 'g_tab_r_fclevel_code(i) ='||g_tab_r_fclevel_code(i));
8819 log_message(p_msg_token1 => 'g_tab_rg_fclevel_code(i) ='||g_tab_rg_fclevel_code(i));
8820 log_message(p_msg_token1 => 'g_tab_t_fclevel_code(i) ='||g_tab_t_fclevel_code(i));
8821 log_message(p_msg_token1 =>'g_tab_tt_fclevel_code(i) ='||g_tab_tt_fclevel_code(i));
8822 log_message(p_msg_token1 =>' g_tab_p_fclevel_code(i) ='||g_tab_p_fclevel_code(i));
8823 log_message(p_msg_token1 =>'g_tab_result_code(i) ='||g_tab_result_code(i) );
8824 log_message(p_msg_token1 =>'g_tab_r_result_code(i)='||g_tab_r_result_code(i));
8825 log_message(p_msg_token1 =>'g_tab_rg_result_code(i)='||g_tab_rg_result_code(i));
8826 log_message(p_msg_token1 =>'g_tab_p_result_code(i) ='||g_tab_p_result_code(i));
8827 log_message(p_msg_token1 =>'g_tab_p_acct_result_code(i) ='||g_tab_p_acct_result_code(i));
8828 log_message(p_msg_token1 =>'g_tab_effect_fclevel(i) ='||g_tab_effect_fclevel(i));
8829 log_message(p_msg_token1 =>'g_tab_budget_ccid(i) ='||g_tab_budget_ccid(i));
8830 log_message(p_msg_token1 =>'g_tab_encum_type_id(i) ='||g_tab_encum_type_id(i));
8831 log_message(p_msg_token1 =>'g_tab_gl_date(i)='||g_tab_gl_date(i));
8832 log_message(p_msg_token1 =>'g_tab_pa_date(i) ='||g_tab_pa_date(i));
8833 log_message(p_msg_token1 =>'g_tab_ext_bdgt_link(i)='||g_tab_ext_bdgt_link(i));
8834 log_message(p_msg_token1 =>'g_tab_start_date(i) = '||g_tab_start_date(i));
8835 log_message(p_msg_token1 =>'g_tab_end_date(i) = '||g_tab_end_date(i));
8836 end loop;
8837 *****/
8838
8839 IF g_debug_mode = 'Y' THEN
8840 log_message(p_msg_token1 => 'calling update pkt autonomous transaction api');
8841 End if;
8842 update_pkts(p_packet_id => p_packet_id);
8843 IF g_debug_mode = 'Y' THEN
8844 log_message(p_msg_token1 => 'after the pkt autonomous transaction api');
8845 End if;
8846
8847
8848 EXIT when setup_details%NOTFOUND;
8849
8850 END LOOP; -- end of setup details cursor;
8851 IF g_debug_mode = 'Y' THEN
8852 log_message(p_msg_token1 =>'End of setup_details cursor');
8853 End if;
8854 CLOSE setup_details;
8855 IF g_debug_mode = 'Y' THEN
8856 log_message(p_msg_token1 => 'End of fundscheck setup api');
8857 End if;
8858 If setup_details%ISOPEN THEN
8859 close setup_details;
8860 End if;
8861
8862 return true;
8863
8864 EXCEPTION
8865
8866 WHEN OTHERS THEN
8867 If setup_details%ISOPEN THEN
8868 close setup_details;
8869 End if;
8870 IF g_debug_mode = 'Y' THEN
8871 log_message(p_msg_token1 => 'Unexpected Error during Funds check setup Params SQLERROR '||sqlcode||sqlerrm);
8872 End if;
8873 -- Error Msg : 'F120 = Funds check failed during Setup and Summerization';
8874 result_status_code_update(
8875 p_status_code => 'T',
8876 p_result_code => 'F120',
8877 p_res_result_code => 'F120',
8878 p_res_grp_result_code => 'F120',
8879 p_task_result_code => 'F120',
8880 p_top_task_result_code => 'F120',
8881 p_project_result_code => 'F120',
8882 p_proj_acct_result_code => 'F120',
8883 p_packet_id => p_packet_id);
8884 log_message(p_error_msg => sqlcode||sqlerrm);
8885 --commit;
8886 Raise;
8887
8888 END funds_check_setup;
8889 ---------------------------------------------------------------------------------------
8890 -- This api syncronizes the burden lines with raw line
8891 -- if the burden line pass but raw line fails then burden transaction
8892 -- will be marked as failed
8893 -------------------------------------------------------------------------------------
8894 PROCEDURE result_code_update_burden
8895 (p_packet_id IN NUMBER,
8896 x_return_status OUT NOCOPY VARCHAR2 )IS
8897 PRAGMA AUTONOMOUS_TRANSACTION;
8898
8899 CURSOR update_burden_rows IS
8900 SELECT bc_packet_id,
8901 result_code,
8902 res_result_code,
8903 res_grp_result_code,
8904 task_result_code,
8905 top_task_result_code,
8906 project_result_code,
8907 project_acct_result_code
8908 FROM pa_bc_packets
8909 WHERE packet_id = p_packet_id
8910 AND parent_bc_packet_id IS NULL
8911 AND nvl(SUBSTR ( result_code,1,1),'P') IN ('F','R');
8912
8913 l_num_rows NUMBER:= 200;
8914
8915
8916 BEGIN
8917 OPEN update_burden_rows; LOOP
8918 IF g_debug_mode = 'Y' THEN
8919 log_message(p_msg_token1 => 'opened the update_burden_rows cursor ');
8920 End if;
8921 g_tab_bc_packet_id.delete;
8922 g_tab_r_result_code.delete;
8923 g_tab_rg_result_code.delete;
8924 g_tab_t_result_code.delete;
8925 g_tab_tt_result_code.delete;
8926 g_tab_p_result_code.delete;
8927 g_tab_p_acct_result_code.delete;
8928 FETCH update_burden_rows BULK COLLECT INTO
8929 g_tab_bc_packet_id,
8930 g_tab_result_code,
8931 g_tab_r_result_code,
8932 g_tab_rg_result_code,
8933 g_tab_t_result_code,
8934 g_tab_tt_result_code,
8935 g_tab_p_result_code,
8936 g_tab_p_acct_result_code
8937 LIMIT l_num_rows;
8938 IF NOT g_tab_bc_packet_id.EXISTS(1) then
8939 IF g_debug_mode = 'Y' THEN
8940 log_message(p_msg_token1 => 'no rows found ');
8941 End if;
8942 EXIT;
8943 END IF;
8944 IF g_debug_mode = 'Y' THEN
8945 log_message(p_msg_token1 => 'calling FORALL stagtment');
8946 End if;
8947 FORALL i IN g_tab_bc_packet_id.FIRST .. g_tab_bc_packet_id.LAST
8948 -- error msg : 'F116 = Transaction failed funds check because of Raw';
8949 UPDATE pa_bc_packets
8950 --SET result_code = 'F116' the line is commented out NOCOPY as the user need not be shown
8951 -- difference between raw and burden
8952 SET result_code = g_tab_result_code(i),
8953 res_result_code = g_tab_r_result_code(i),
8954 res_grp_result_code = g_tab_rg_result_code(i),
8955 task_result_code = g_tab_t_result_code(i),
8956 top_task_result_code = g_tab_tt_result_code(i),
8957 project_result_code = g_tab_p_result_code(i),
8958 project_acct_result_code = g_tab_p_acct_result_code(i)
8959 WHERE packet_id = p_packet_id
8960 AND parent_bc_packet_id = g_tab_bc_packet_id(i)
8961 AND nvl(substr(result_code,1,1),'P') in ('P','A');
8962 -- end of for all
8963 COMMIT;
8964
8965 EXIT when update_burden_rows%NOTFOUND ;
8966
8967 END LOOP;
8968 CLOSE update_burden_rows;
8969 IF g_debug_mode = 'Y' THEN
8970 log_message(p_msg_token1 => 'end of update_burden_rows cursor');
8971 End if;
8972 commit;
8973
8974 EXCEPTION
8975
8976 WHEN OTHERS THEN
8977 if update_burden_rows%ISOPEN THEN
8978 close update_burden_rows ;
8979 End if;
8980 IF g_debug_mode = 'Y' THEN
8981 log_message(p_msg_token1 => 'Exception portion in result_code_update_burden api');
8982 End if;
8983 x_return_status := 'T';
8984 RETURN;
8985
8986 END result_code_update_burden;
8987
8988 -- This api synchronizes the raw lines with burden lines
8989 -- if the raw transaction passes but the burden transaction fails
8990 -- the update the bc_packet set the staus of raw transaction as failed
8991
8992 PROCEDURE result_code_update_raw
8993 (p_packet_id IN NUMBER,
8994 x_return_status OUT NOCOPY VARCHAR2 )IS
8995 PRAGMA AUTONOMOUS_TRANSACTION;
8996 CURSOR update_raw_rows IS
8997 SELECT a.parent_bc_packet_id,
8998 a.result_code,
8999 a.res_result_code,
9000 a.res_grp_result_code,
9001 a.task_result_code,
9002 a.top_task_result_code,
9003 a.project_result_code,
9004 a.project_acct_result_code
9005 FROM pa_bc_packets a,
9006 pa_bc_packets b
9007 WHERE a.packet_id = p_packet_id
9008 AND nvl(SUBSTR ( a.result_code,1,1),'P') in ('R','F')
9009 AND a.parent_bc_packet_id IS NOT NULL
9010 ANd a.packet_id = b.packet_id
9011 AND b.bc_packet_id = a.parent_bc_packet_id
9012 AND nvl(substr(b.result_code,1,1),'P') in ('A','P');
9013 l_num_rows NUMBER:=200;
9014
9015
9016 BEGIN
9017 OPEN update_raw_rows; LOOP
9018 IF g_debug_mode = 'Y' THEN
9019 log_message(p_msg_token1 => 'opened the cursor update_raw_rows cursor');
9020 End if;
9021 g_tab_p_bc_packet_id.delete;
9022 g_tab_r_result_code.delete;
9023 g_tab_rg_result_code.delete;
9024 g_tab_t_result_code.delete;
9025 g_tab_tt_result_code.delete;
9026 g_tab_p_result_code.delete;
9027 g_tab_p_acct_result_code.delete;
9028 FETCH update_raw_rows BULK COLLECT INTO
9029 g_tab_p_bc_packet_id,
9030 g_tab_result_code,
9031 g_tab_r_result_code,
9032 g_tab_rg_result_code,
9033 g_tab_t_result_code,
9034 g_tab_tt_result_code,
9035 g_tab_p_result_code,
9036 g_tab_p_acct_result_code
9037 LIMIT l_num_rows;
9038 IF NOT g_tab_p_bc_packet_id.EXISTS(1) then
9039 IF g_debug_mode = 'Y' THEN
9040 log_message(p_msg_token1 => 'no rows found ');
9041 End if;
9042 EXIT;
9043 END IF;
9044 IF g_debug_mode = 'Y' THEN
9045 log_message(p_msg_token1 => 'calling FORALL statment');
9046 End if;
9047 FORALL i IN g_tab_p_bc_packet_id.FIRST .. g_tab_p_bc_packet_id.LAST
9048 -- Error msg : 'F115 = Transaction failed funds check because of Burden';
9049 UPDATE pa_bc_packets
9050 --SET result_code = 'F115'
9051 SET result_code = g_tab_result_code(i),
9052 res_result_code = g_tab_r_result_code(i),
9053 res_grp_result_code = g_tab_rg_result_code(i),
9054 task_result_code = g_tab_t_result_code(i),
9055 top_task_result_code = g_tab_tt_result_code(i),
9056 project_result_code = g_tab_p_result_code(i),
9057 project_acct_result_code = g_tab_p_acct_result_code(i)
9058 WHERE packet_id = p_packet_id
9059 AND bc_packet_id = g_tab_p_bc_packet_id(i)
9060 AND nvl(substr(result_code,1,1),'P') in ('A','P');
9061 -- end of forall loop
9062 COMMIT;
9063
9064 EXIT WHEN update_raw_rows%NOTFOUND;
9065 END LOOP;
9066 CLOSE update_raw_rows;
9067 IF g_debug_mode = 'Y' THEN
9068 log_message(p_msg_token1 => 'end of update_raw_rows api ');
9069 End if;
9070
9071 commit;
9072 EXCEPTION
9073
9074 WHEN OTHERS THEN
9075 if update_raw_rows%ISOPEN THEN
9076 close update_raw_rows ;
9077 End if;
9078 IF g_debug_mode = 'Y' THEN
9079 log_message(p_msg_token1 => 'exception in result_code_update_raw api ');
9080 End if;
9081 x_return_status := 'T';
9082 RETURN;
9083
9084
9085 END result_code_update_raw;
9086
9087 -- This api ensures that all the transactions are passed at documnet header
9088 -- level whether it is full mode or partial mode
9089 PROCEDURE update_trxn_doc_levl
9090 (p_packet_id IN NUMBER,
9091 p_mode IN VARCHAR2,
9092 p_calling_module IN VARCHAR2,
9093 x_return_status OUT NOCOPY VARCHAR2) IS
9094 PRAGMA AUTONOMOUS_TRANSACTION;
9095
9096 CURSOR update_headers IS
9097 SELECT document_header_id,
9098 document_line_id,
9099 exp_item_id,
9100 result_code
9101 FROM pa_bc_packets
9102 WHERE packet_id = p_packet_id
9103 AND nvl(substr(result_code,1,1),'P') in ('F','R');
9104
9105 l_num_rows NUMBER := 200;
9106 BEGIN
9107 -- Initialize the error stack
9108 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.update_trxn_doc_levl');
9109
9110 --reset the return status
9111 x_return_status := 'S';
9112 IF g_debug_mode = 'Y' THEN
9113 log_message(p_msg_token1 => 'inside the update_trxn_doc_levl api');
9114 End if;
9115 IF p_calling_module in ('DISTBTC','CBC','TRXNIMPORT','DISTVIADJ','DISTERADJ','EXPENDITURE','TRXIMPORT','DISTCWKST') then
9116
9117 OPEN update_headers; LOOP
9118 IF g_debug_mode = 'Y' THEN
9119 log_message(p_msg_token1 => 'opened the update_headers cursor ');
9120 End if;
9121 g_tab_doc_header_id.delete;
9122 g_tab_doc_line_id.delete;
9123 g_tab_exp_item_id.delete;
9124 g_tab_result_code.delete;
9125 FETCH update_headers BULK COLLECT INTO
9126 g_tab_doc_header_id,
9127 g_tab_doc_line_id,
9128 g_tab_exp_item_id,
9129 g_tab_result_code LIMIT l_num_rows;
9130 IF NOT g_tab_doc_header_id.EXISTS(1) then
9131 IF g_debug_mode = 'Y' THEN
9132 log_message(p_msg_token1 => 'no rows found ');
9133 End if;
9134 EXIT;
9135 END IF;
9136 IF g_debug_mode = 'Y' THEN
9137 log_message(p_msg_token1 => 'calling FORALL statement count['||g_tab_doc_header_id.count||']');
9138 End if;
9139 FORALL i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST
9140 -- Error msg : F117 = Transaction failed due to adjusted cdls
9141 UPDATE pa_bc_packets
9142 SET result_code = decode(substr(nvl(result_code,'P'),1,1),'P',
9143 decode(p_calling_module,'CBC',g_tab_result_code(i),'F117'),result_code)
9144 WHERE packet_id = p_packet_id
9145 AND ( (document_header_id = g_tab_doc_header_id(i)
9146 and document_type in ('EXP','AP','CC_P_PAY','CC_C_PAY','CC_C_CO','CC_P_CO')
9147 and p_calling_module in ('DISTBTC','CBC','DISTVIADJ','TRXIMPORT','DISTERADJ')
9148 )
9149 OR
9150 (p_calling_module = 'DISTCWKST'
9151 and document_line_id = g_tab_doc_line_id(i)
9152 and exp_item_id = g_tab_exp_item_id(i)
9153 and document_type in ('PO','EXP')
9154 )
9155 )
9156 AND nvl(substr(result_code,1,1),'P') in ('P','A');
9157
9158 IF g_debug_mode = 'Y' THEN
9159 log_message(p_msg_token1 => 'Num of Rows updated['||sql%rowcount||']');
9160 End if;
9161 EXIT WHEN update_headers%NOTFOUND ;
9162 END LOOP;
9163 CLOSE update_headers;
9164 IF g_debug_mode = 'Y' THEN
9165 log_message(p_msg_token1 => 'end of update_headers cursor');
9166 End if;
9167 COMMIT;
9168 END IF;
9169 COMMIT;
9170 EXCEPTION
9171 when others then
9172 IF update_headers%ISOPEN THEN
9173 close update_headers;
9174 End IF;
9175 IF g_debug_mode = 'Y' THEN
9176 log_message(p_msg_token1 => 'exception in update_trxn_doc_levl api ');
9177 End if;
9178 log_message(p_error_msg => sqlcode||sqlerrm);
9179 x_return_status := 'T';
9180 RETURN;
9181
9182 END update_trxn_doc_levl;
9183 -- This api syncronizes the raw and burden lines
9184 -- if the burden line pass but raw line fails then burden transaction
9185 -- will be marked as failed
9186 PROCEDURE sync_raw_burden
9187 (p_packet_id IN NUMBER,
9188 p_mode IN VARCHAR2,
9189 p_calling_module IN VARCHAR2,
9190 x_return_status OUT NOCOPY VARCHAR2) IS
9191
9192 BEGIN
9193 -- call for update the burden transaction with failure status
9194 IF g_debug_mode = 'Y' THEN
9195 log_message(p_msg_token1 => 'Calling result_code_update_burden api ');
9196 End if;
9197 result_code_update_burden
9198 (p_packet_id => p_packet_id,
9199 x_return_status => x_return_status);
9200 -- call for update of the raw transaction with the failure status
9201 IF g_debug_mode = 'Y' THEN
9202 log_message(p_msg_token1 => 'Calling result_code_update_raw api ');
9203 End if;
9204 result_code_update_raw
9205 (p_packet_id => p_packet_id,
9206 x_return_status => x_return_status);
9207
9208
9209 --call for update at the ei level if ei is a adjusted cdls
9210 IF g_debug_mode = 'Y' THEN
9211 log_message(p_msg_token1 => 'Calling update_trxn_doc_levl api ');
9212 End if;
9213
9214 update_trxn_doc_levl
9215 (p_packet_id => p_packet_id,
9216 p_mode => p_mode,
9217 p_calling_module => p_calling_module,
9218 x_return_status => x_return_status);
9219
9220 EXCEPTION
9221 when others then
9222 IF g_debug_mode = 'Y' THEN
9223 log_message(p_msg_token1 => 'failed in sync raw burden api SQLERROR:'||sqlcode||sqlerrm);
9224 End if;
9225 --commit;
9226 RAISE;
9227
9228 END sync_raw_burden;
9229 --------------------------------------------------------------------
9230 -- This api check whether the base line is progress for the given
9231 -- project
9232 --------------------------------------------------------------------
9233 FUNCTION is_baseline_progress(p_project_id number)
9234 return varchar2 IS
9235
9236 l_status_flag varchar2(1) := 'N';
9237 l_wf_status varchar2(25) := null;
9238
9239 cursor check_bdgt_baseline is
9240 SELECT wf_status_code
9241 FROM pa_budget_versions
9242 WHERE project_id = p_project_id
9243 AND wf_status_code is NOT NULL;
9244
9245
9246
9247 BEGIN
9248 IF g_debug_mode = 'Y' THEN
9249 log_message(p_msg_token1 =>' Inside the is_baselinei_progress api');
9250 End if;
9251 OPEN check_bdgt_baseline;
9252 LOOP
9253 FETCH check_bdgt_baseline INTO l_wf_status;
9254 EXIT WHEN check_bdgt_baseline%NOTFOUND;
9255 IF g_debug_mode = 'Y' THEN
9256 log_message(p_msg_token1 => 'WF_STATUS_CODE ='||l_wf_status);
9257 End if;
9258 IF l_wf_status = 'IN_ROUTE' then
9259 -- ie the budget is under baselineing for this project
9260 l_status_flag := 'Y';
9261 EXIT;
9262 END IF;
9263 END LOOP;
9264 CLOSE check_bdgt_baseline;
9265
9266 If check_bdgt_baseline%ISOPEN then
9267 close check_bdgt_baseline;
9268 End if;
9269
9270
9271 RETURN l_status_flag;
9272 EXCEPTION
9273 WHEN OTHERS THEN
9274 If check_bdgt_baseline%ISOPEN then
9275 close check_bdgt_baseline;
9276 End if;
9277 RAISE;
9278
9279 END is_baseline_progress;
9280
9281 -----------------------------------------------------------------------------------------------+
9282 -- This procedure is the autonomous version of status_code_udpate. Basically, this procedure
9283 -- will call status_code_update
9284 -- main procedure status_code_update is being made non-autonomous
9285 -----------------------------------------------------------------------------------------------+
9286 PROCEDURE status_code_update_autonomous (
9287 p_calling_module IN VARCHAR2,
9288 p_packet_id IN NUMBER,
9289 p_mode IN VARCHAR2,
9290 p_partial IN VARCHAR2 DEFAULT 'N',
9291 p_packet_status IN VARCHAR2 DEFAULT 'S',
9292 x_return_status OUT NOCOPY varchar2 )
9293 IS
9294 PRAGMA AUTONOMOUS_TRANSACTION;
9295 BEGIN
9296
9297 status_code_update (
9298 p_calling_module => p_calling_module,
9299 p_packet_id => p_packet_id,
9300 p_mode => p_mode,
9301 p_partial => p_partial,
9302 p_packet_status => p_packet_status,
9303 x_return_status => x_return_status);
9304 COMMIT;
9305
9306 End status_code_update_autonomous;
9307
9308 --------------------------------------------------------------------------------------------
9309 -- This api updates the status of bc packets based on the result code
9310 -- and calling mode and partial flag
9311 -- The valid status code values are
9312 -- A - Approved
9313 -- B - Base lined -- Intermediate status (r12 on - not used)
9314 -- R - Rejected
9315 -- C - Checked -- Intermediate status (r12 on - not used)
9316 -- F - Failed Check
9317 -- S - Passed Check
9318 -- E - Error
9319 -- T - Fatal
9320 -- V - Vendor Invoice - Intermediate status to avoid sweeper to pick
9321 -- L - Intermediate status for Expense report to liquidate but avoid sweeper to pick
9322 -- I - Intermedidate status in which commitment records will be created, this will be synched
9323 -- as the first step in pa_funds_check (Added in R12)
9324 -- if the calling module is BASELINE then use BULK FETCH AND BULK
9325 -- update logic since the volume of records is more.
9326 -----------------------------------------------------------------------------------------------
9327 PROCEDURE status_code_update (
9328 p_calling_module IN VARCHAR2,
9329 p_packet_id IN NUMBER,
9330 p_mode IN VARCHAR2,
9331 p_partial IN VARCHAR2 DEFAULT 'N',
9332 p_packet_status IN VARCHAR2 DEFAULT 'S',
9333 x_return_status OUT NOCOPY varchar2 ) IS
9334
9335 -- PRAGMA AUTONOMOUS_TRANSACTION;
9336
9337 CURSOR baseline_error_status IS
9338 SELECT rowid,
9339 bc_packet_id
9340 FROM pa_bc_packets
9341 WHERE packet_id = p_packet_id
9342 AND EXISTS(
9343 SELECT 'x'
9344 FROM pa_bc_packets
9345 WHERE packet_id = p_packet_id
9346 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9347 );
9348
9349 CURSOR baseline_success_status IS
9350 SELECT rowid,
9351 bc_packet_id
9352 FROM pa_bc_packets
9353 WHERE packet_id = p_packet_id
9354 AND status_code = 'P'
9355 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P';
9356
9357 CURSOR cur_projects IS
9358 SELECT distinct project_id
9359 FROM pa_bc_packets
9360 WHERE packet_id = p_packet_id;
9361
9362 CURSOR cur_fatal_error IS
9363 SELECT bc_packet_id
9364 FROM pa_bc_packets
9365 WHERE packet_id = p_packet_id;
9366
9367 l_project_id NUMBER;
9368 l_base_line_project NUMBER;
9369 l_base_line_flag VARCHAR2(10):= 'N';
9370 l_num_rows NUMBER := 200;
9371 l_rowcount NUMBER ;
9372
9373
9374 BEGIN
9375 -- initialize the return status to success
9376 x_return_status := 'S';
9377
9378 --Initialize the err stack
9379 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.status_code_update');
9380
9381 IF g_debug_mode = 'Y' THEN
9382 log_message(p_msg_token1 =>'Inside the status code update api p_calling_module['
9383 ||p_calling_module||']packet_id['||p_packet_id||']mode['
9384 ||p_mode||']partial flag['||p_partial||']packet_status['
9385 ||p_packet_status||']');
9386 End if;
9387
9388 /** Incase of fatal error from distribute expenses report or transaction import programs
9389 * update the status code of the packets to fatal so that it will not pickup
9390 * for updating the balances
9391 */
9392 IF p_packet_status = 'T' then
9393
9394 OPEN cur_fatal_error;
9395 LOOP
9396 g_tab_bc_packet_id.delete;
9397 FETCH cur_fatal_error BULK COLLECT
9398 INTO g_tab_bc_packet_id LIMIT 300;
9399 IF NOT g_tab_bc_packet_id.EXISTS(1) then
9400 exit;
9401 END IF;
9402
9403 FORALL i IN g_tab_bc_packet_id.first .. g_tab_bc_packet_id.last
9404 UPDATE pa_bc_packets
9405 SET status_code = 'T'
9406 WHERE packet_id = p_packet_id
9407 AND bc_packet_id = g_tab_bc_packet_id(i);
9408
9409 Exit when cur_fatal_error%NOTFOUND;
9410
9411 END LOOP;
9412
9413 CLOSE cur_fatal_error;
9414 --commit; -- to end an active autonomous transaction
9415 pa_debug.reset_err_stack;
9416 RETURN;
9417
9418 END IF;
9419
9420
9421 IF p_calling_module in ('RESERVE_BASELINE') and p_mode = 'S' THEN
9422 IF g_debug_mode = 'Y' THEN
9423 log_message(p_msg_token1 =>'stage : STATUS_CODE:SUBMIT');
9424 End if;
9425 -- if the calling mode is submit and if there is any failed transaction
9426 -- the whole package is marked as E - Error other wise it is Passed check
9427 g_error_stage := 'STATUS_CODE:SUBMIT';
9428 OPEN baseline_error_status;
9429 IF g_debug_mode = 'Y' THEN
9430 log_message(p_msg_token1 => 'opened cursor baseline_error_status ');
9431 End if;
9432 LOOP
9433 g_tab_bc_packet_id.delete;
9434 FETCH baseline_error_status BULK COLLECT INTO
9435 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9436 If NOT g_tab_rowid.EXISTS(1) then
9437 IF g_debug_mode = 'Y' THEN
9438 log_message(p_msg_token1 => 'no records fetched exiting');
9439 End if;
9440 EXIT;
9441 End if;
9442 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9443 UPDATE pa_bc_packets
9444 SET status_code = 'E'
9445 WHERE packet_id = p_packet_id
9446 AND bc_packet_id = g_tab_bc_packet_id(i);
9447 --COMMIT;
9448 EXIT when baseline_error_status%NOTFOUND;
9449 END LOOP;
9450 CLOSE baseline_error_status;
9451
9452 OPEN baseline_success_status;
9453 IF g_debug_mode = 'Y' THEN
9454 log_message(p_msg_token1 => 'opened baseline_success_status cursor ');
9455 End if;
9456 LOOP
9457 g_tab_bc_packet_id.delete;
9458 FETCH baseline_success_status BULK COLLECT INTO
9459 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9460 IF NOT g_tab_rowid.EXISTS(1) then
9461 IF g_debug_mode = 'Y' THEN
9462 log_message(p_msg_token1 => 'no records fetched exiting');
9463 End if;
9464 EXIT;
9465 END IF;
9466 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9467 UPDATE pa_bc_packets
9468 SET status_code = 'S'
9469 WHERE packet_id = p_packet_id
9470 AND bc_packet_id = g_tab_bc_packet_id(i);
9471 --COMMIT;
9472 EXIT when baseline_success_status%NOTFOUND;
9473 END LOOP;
9474 CLOSE baseline_success_status;
9475
9476 ELSIF p_calling_module in ('RESERVE_BASELINE') and p_mode = 'B' THEN
9477 -- if the calling mode is Base line and if there is any failed transaction
9478 -- the whole package is marked as R - Rejected other wise it is Approved
9479 -- update the status to intermediate status of B - baseline finally the
9480 -- the base line process will udate the status to A and sweeper programm
9481 -- picks all the records
9482 g_error_stage := 'STATUS_CODE: BASELINE';
9483 IF g_debug_mode = 'Y' THEN
9484 log_message(p_msg_token1 => 'stage : STATUS_CODE: BASELINE');
9485 End if;
9486 OPEN baseline_error_status;
9487 IF g_debug_mode = 'Y' THEN
9488 log_message(p_msg_token1 => 'opened baseline_error_status cursor ');
9489 End if;
9490 LOOP
9491 g_tab_bc_packet_id.delete;
9492 FETCH baseline_error_status BULK COLLECT INTO
9493 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9494 IF NOT g_tab_rowid.EXISTS(1) then
9495 IF g_debug_mode = 'Y' THEN
9496 log_message(p_msg_token1 => 'no recrods found');
9497 End if;
9498 EXIT;
9499 END IF;
9500 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9501 UPDATE pa_bc_packets
9502 SET status_code = 'R' -- rejected
9503 WHERE packet_id = p_packet_id
9504 AND bc_packet_id = g_tab_bc_packet_id(i);
9505
9506 log_message(p_msg_token1 => 're-baseline fails [ '||sql%rowcount||' ] records updated to R');
9507 --COMMIT;
9508 EXIT when baseline_error_status%NOTFOUND;
9509 END LOOP;
9510 CLOSE baseline_error_status;
9511
9512 /* =====================================================================+
9513 || Pass code will be handled in PABBFNDB.pls
9514 || ---------------------------------------------------------------------+
9515 OPEN baseline_success_status;
9516 IF g_debug_mode = 'Y' THEN
9517 log_message(p_msg_token1 => 'opened baseline_success_status cursor ');
9518 End if;
9519 LOOP
9520 g_tab_bc_packet_id.delete;
9521 FETCH baseline_success_status BULK COLLECT INTO
9522 g_tab_rowid,g_tab_bc_packet_id LIMIT l_num_rows;
9523 IF NOT g_tab_rowid.EXISTS(1) then
9524 IF g_debug_mode = 'Y' THEN
9525 log_message(p_msg_token1 => 'no recrods found');
9526 End if;
9527 EXIT;
9528 END IF;
9529 FORALL i IN g_tab_rowid.FIRST .. g_tab_rowid.LAST
9530 UPDATE pa_bc_packets
9531 SET status_code = 'A'
9532 WHERE packet_id = p_packet_id
9533 AND bc_packet_id = g_tab_bc_packet_id(i);
9534
9535 log_message(p_msg_token1 => 're-baseline passed [ '||sql%rowcount||' ] records updated to R');
9536 --COMMIT;
9537 EXIT when baseline_success_status%NOTFOUND;
9538 END LOOP;
9539 CLOSE baseline_success_status;
9540 IF g_debug_mode = 'Y' THEN
9541 log_message(p_msg_token1 => 'end of baseline update staus');
9542 End if;
9543 ==========================================================================+ */
9544
9545 ELSIF p_mode = 'C' THEN
9546 -- if the calling mode is Check Funds and if there is any failed transaction
9547 -- the whole package is marked as F - Failed Check other wise it is Checked - C
9548 g_error_stage := 'STATUS_CODE: CHECK FUNDS';
9549 IF g_debug_mode = 'Y' THEN
9550 log_message(p_msg_token1 => 'stage : STATUS_CODE: CHECK FUNDS');
9551 End if;
9552 IF p_partial = 'Y' THEN
9553 IF g_debug_mode = 'Y' THEN
9554 log_message(p_msg_token1 => 'p_partial = Y');
9555 End if;
9556 -- If the calling mode is Reserve and Partial flag is 'Y' then
9557 -- if there is any failed transaction then update the bc packet with
9558 -- each record as Rejected.
9559 g_error_stage := 'STATUS_CODE:RESERVE - Partial';
9560 IF g_debug_mode = 'Y' THEN
9561 log_message(p_msg_token1 => 'STATUS_CODE:RESERVE - Partial');
9562 End if;
9563 UPDATE pa_bc_packets
9564 SET status_code = DECODE ( SUBSTR (
9565 nvl(result_code,'P'), 1, 1 )
9566 , 'P', decode(status_code,'P','S',status_code)
9567 , 'F' )
9568 WHERE packet_id = p_packet_id
9569 AND status_code in ('P','L','S');
9570 l_rowcount := sql%rowcount;
9571 Elsif p_partial <> 'Y' then
9572
9573 UPDATE pa_bc_packets
9574 SET status_code = 'F'
9575 WHERE packet_id = p_packet_id
9576 AND EXISTS (SELECT 'x'
9577 FROM pa_bc_packets
9578 WHERE packet_id = p_packet_id
9579 AND ( SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9580 OR p_packet_status in ('F','R','T')
9581 ));
9582 l_rowcount := sql%rowcount;
9583
9584 If l_rowcount <= 0 then
9585 UPDATE pa_bc_packets
9586 SET status_code = 'S'
9587 WHERE packet_id = p_packet_id
9588 AND status_code in ('P','L','S')
9589 AND SUBSTR ( nvl(result_code,'P'),1,1 ) = 'P';
9590
9591 End if;
9592 End if;
9593
9594 ELSIF p_mode = 'U' THEN
9595 -- if the calling mode is Un Reserve and if there is any failed transaction
9596 -- the whole package is marked as R - Rejected other wise it is Approved
9597 -- *** The transaction which comes during baseline process to maintain data
9598 -- concurrancy the following logic is used
9599 -- check if the budget is being baseline for the project then mark the
9600 -- status of the transaction belong the particular project which is being baselined
9601 -- to intermediate status so that the baseline process picks all theses records
9602 -- and calls agian funds check process . and finally the base line process
9603 -- marks the status to approved
9604 g_error_stage := 'STATUS_CODE: UNRESERVE';
9605 IF g_debug_mode = 'Y' THEN
9606 log_message(p_msg_token1 => 'Stage : STATUS_CODE: UNRESERVE');
9607 End if;
9608
9609 UPDATE pa_bc_packets
9610 SET status_code = 'R'
9611 WHERE packet_id = p_packet_id
9612 AND EXISTS (SELECT 'x'
9613 FROM pa_bc_packets
9614 WHERE packet_id = p_packet_id
9615 AND ( SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9616 OR p_packet_status in ('F','R','T')
9617 ));
9618 l_rowcount := sql%rowcount;
9619 IF g_debug_mode = 'Y' THEN
9620 log_message(p_msg_token1 => 'no rows updated = '||l_rowcount);
9621 End if;
9622
9623 IF l_rowcount <= 0 THEN
9624 --- check the transaction is arrived during the base line process
9625 --- if so the mark the status to intermediate status
9626 OPEN cur_projects;
9627 IF g_debug_mode = 'Y' THEN
9628 log_message(p_msg_token1 => 'opened cur_project cursor');
9629 End if;
9630 LOOP
9631 FETCH cur_projects INTO l_project_id;
9632 IF g_debug_mode = 'Y' THEN
9633 log_message(p_msg_token1 => 'project id ='||l_project_id);
9634 End if;
9635 EXIT WHEN cur_projects%NOTFOUND;
9636
9637 UPDATE pa_bc_packets
9638 SET status_code = 'A'
9639 WHERE packet_id = p_packet_id
9640 AND project_id = l_project_id
9641 AND status_code in ('P')
9642 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P';
9643 END LOOP;
9644 CLOSE cur_projects;
9645 IF g_debug_mode = 'Y' THEN
9646 log_message(p_msg_token1 => 'end of cur_projects cursor ');
9647 End if;
9648
9649 END IF;
9650
9651 ELSIF p_mode in ('F','R') THEN
9652 IF g_debug_mode = 'Y' THEN
9653 log_message(p_msg_token1 => 'Stage : STATUSCODE : RESERVE');
9654 End if;
9655
9656 OPEN cur_projects;
9657 LOOP
9658 FETCH cur_projects INTO l_project_id;
9659 EXIT WHEN cur_projects%NOTFOUND;
9660
9661 IF g_debug_mode = 'Y' THEN
9662 log_message(p_msg_token1 => 'base_line_flag ='||l_base_line_flag);
9663 End if;
9664
9665 IF p_partial = 'Y' THEN
9666 -- If the calling mode is Reserve and Partial flag is 'Y' then
9667 -- if there is any failed transaction then update the bc packet with
9668 -- each record as Rejected.
9669 g_error_stage := 'STATUS_CODE:RESERVE - Partial';
9670 IF g_debug_mode = 'Y' THEN
9671 log_message(p_msg_token1 => 'STATUS_CODE:RESERVE - Partial');
9672 End if;
9673
9674 UPDATE pa_bc_packets
9675 SET status_code = DECODE ( SUBSTR (
9676 nvl(result_code,'P'), 1, 1 )
9677 , 'P', decode(status_code,'P','A',status_code)
9678 , 'R' )
9679 WHERE packet_id = p_packet_id
9680 AND project_id = l_project_id
9681 AND status_code in ('P','L');
9682 IF g_debug_mode = 'Y' THEN
9683 log_message(p_msg_token1 => 'no of rows updated ='||sql%rowcount);
9684 end if;
9685
9686 IF SQL%NOTFOUND THEN
9687 log_message (p_msg_token1 =>'Updated the status code for Partial Mode');
9688 END IF;
9689
9690 ELSE -- p_partial <> 'Y' then
9691 -- If the calling mode is Reserve and Partial flag is 'N'ie full mode then
9692 -- if there is any failed transaction then update the whole packet with Rejected
9693 g_error_stage := 'STATUS_CODE:RESERVE - Full';
9694 IF g_debug_mode = 'Y' THEN
9695 log_message(p_msg_token1 =>'STATUS_CODE:RESERVE - Full');
9696 End if;
9697
9698 UPDATE pa_bc_packets
9699 SET status_code = 'R'
9700 WHERE packet_id = p_packet_id
9701 AND project_id = l_project_id
9702 AND EXISTS (SELECT 'x'
9703 FROM pa_bc_packets
9704 WHERE packet_id = p_packet_id
9705 AND ( SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
9706 OR p_packet_status in ('F','R','T')
9707 ));
9708 l_rowcount := sql%rowcount;
9709 IF g_debug_mode = 'Y' THEN
9710 log_message(p_msg_token1 =>'no of rows rejected ='||l_rowcount);
9711 End if;
9712
9713 IF l_rowcount <= 0 THEN
9714 --- check the transaction is arrived during the base line process
9715 --- if so the mark the status to intermediate status
9716
9717 UPDATE pa_bc_packets
9718 SET status_code = 'A'
9719 WHERE packet_id = p_packet_id
9720 AND project_id = l_project_id
9721 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P'
9722 AND status_code in ('P');
9723
9724 IF g_debug_mode = 'Y' THEN
9725 log_message(p_msg_token1 =>'no of rows approved ='||sql%rowcount);
9726 End if;
9727 END IF;
9728
9729 END IF; -- end if for partial flag
9730 END LOOP;
9731 CLOSE cur_projects;
9732 IF g_debug_mode = 'Y' THEN
9733 log_message(p_msg_token1 =>'end of cur project cursor ');
9734 End if;
9735 END IF; -- end if for calling mode
9736
9737
9738 --reset the error stack
9739 pa_debug.reset_err_stack;
9740 --commit; -- to end an active autonmous transaction
9741 IF cur_projects%isopen then
9742 close cur_projects;
9743 End if;
9744 IF baseline_success_status%isopen then
9745 close baseline_success_status;
9746 End if;
9747 IF baseline_error_status%isopen then
9748 close baseline_error_status;
9749 End if;
9750 return;
9751
9752 EXCEPTION
9753 WHEN OTHERS THEN
9754 IF cur_projects%isopen then
9755 close cur_projects;
9756 End if;
9757 IF baseline_success_status%isopen then
9758 close baseline_success_status;
9759 End if;
9760 IF baseline_error_status%isopen then
9761 close baseline_error_status;
9762 End if;
9763 IF cur_fatal_error%isopen then
9764 close cur_fatal_error;
9765 End if;
9766 x_return_status := 'T';
9767 IF g_debug_mode = 'Y' THEN
9768 log_message(p_msg_token1 => 'failed in status code update api SQLERR :'||sqlcode||sqlerrm);
9769 End if;
9770 RAISE;
9771 END status_code_update;
9772
9773 --------------------------------------------------------------------------------------
9774 -- this api updates the Expenditure items with status code
9775 -- if the transaction passes the funds check the gl date
9776 -- will be stampled on cdl otherwise the ei is updated with
9777 -- rejection code
9778 --------------------------------------------------------------------------
9779 PROCEDURE update_EIS (p_packet_id IN NUMBER,
9780 p_calling_module IN VARCHAR2,
9781 p_mode IN VARCHAR2,
9782 x_return_status OUT NOCOPY VARCHAR2) IS
9783 CURSOR ei_details is
9784 SELECT project_id,
9785 document_type,
9786 document_header_id,
9787 document_distribution_id,
9788 GL_DATE ,
9789 budget_ccid,
9790 proj_encumbrance_type_id,
9791 status_code,
9792 result_code,
9793 bc_packet_id,
9794 parent_bc_packet_id,
9795 res_result_code,
9796 res_grp_result_code,
9797 task_result_code,
9798 top_task_result_code,
9799 project_result_code,
9800 project_acct_result_code,
9801 accounted_dr,
9802 accounted_cr,
9803 budget_version_id,
9804 budget_line_id
9805 FROM pa_bc_packets
9806 WHERE packet_id = p_packet_id
9807 ORDER BY document_header_id,document_distribution_id,bc_packet_id;
9808
9809 l_pre_exp_item_id NUMBER := null;
9810 l_num_rows NUMBER := 200;
9811 l_tab_dist_warn_code pa_plsql_datatypes.char25tabtyp;
9812 l_warn_code varchar2(30);
9813 l_tab_warning_code pa_plsql_datatypes.char25tabtyp;
9814 l_tab_ext_bdgt_flag pa_plsql_datatypes.char25tabtyp;
9815 j NUMBER;
9816 l_doc_header_id pa_bc_packets.document_header_id%type;
9817 l_pre_project_id pa_bc_packets.project_id%type := null;
9818 l_count NUMBER;
9819 l_ext_bdgt_type VARCHAR2(25) := null;
9820 l_ext_bdgt_link VARCHAR2(25) := null;
9821 L_PRE_EXT_BDGT_TYPE VARCHAR2(25) := null;
9822
9823 BEGIN
9824
9825 --Initialize the error stack
9826 pa_debug.init_err_stack('PA_FUNDS_CONTROL_PKG.update_EIS');
9827
9828 -- initialize the return status
9829 x_return_status := 'S';
9830
9831 -- update the ei with rejection code if the transaction fails during funds check
9832 -- else stamp GL_DATE on the cdl for all funds check passed transaction
9833 IF p_calling_module in ('DISTBTC','EXPENDITURE','DISTVIADJ','DISTERADJ','INTERFACVI','INTERFACER','DISTCWKST') then
9834 IF g_debug_mode = 'Y' THEN
9835 log_message(p_msg_token1 => 'Inside the Update EIS api');
9836 End if;
9837 IF p_mode in ('R','U','C') then
9838 OPEN ei_details;
9839 LOOP
9840 g_tab_project_id.delete;
9841 g_tab_doc_type.delete;
9842 g_tab_doc_header_id.delete;
9843 g_tab_doc_distribution_id.delete;
9844 g_tab_gl_date.delete;
9845 g_tab_budget_ccid.delete;
9846 g_tab_encum_type_id.delete;
9847 g_tab_status_code.delete;
9848 g_tab_result_code.delete;
9849 g_tab_bc_packet_id.delete;
9850 g_tab_p_bc_packet_id.delete;
9851 g_tab_r_result_code.delete;
9852 g_tab_rg_result_code.delete;
9853 g_tab_t_result_code.delete;
9854 g_tab_tt_result_code.delete;
9855 g_tab_p_result_code.delete;
9856 g_tab_p_acct_result_code.delete;
9857 l_tab_dist_warn_code.delete;
9858 l_tab_warning_code.delete;
9859 g_tab_accounted_dr.delete;
9860 g_tab_accounted_cr.delete;
9861 l_tab_ext_bdgt_flag.delete;
9862 g_tab_budget_version_id.delete;
9863 g_tab_budget_line_id.delete;
9864 FETCH ei_details BULK COLLECT INTO
9865 g_tab_project_id,
9866 g_tab_doc_type,
9867 g_tab_doc_header_id,
9868 g_tab_doc_distribution_id,
9869 g_tab_gl_date,
9870 g_tab_budget_ccid,
9871 g_tab_encum_type_id,
9872 g_tab_status_code,
9873 g_tab_result_code,
9874 g_tab_bc_packet_id,
9875 g_tab_p_bc_packet_id,
9876 g_tab_r_result_code,
9877 g_tab_rg_result_code,
9878 g_tab_t_result_code,
9879 g_tab_tt_result_code,
9880 g_tab_p_result_code,
9881 g_tab_p_acct_result_code,
9882 g_tab_accounted_dr,
9883 g_tab_accounted_cr,
9884 g_tab_budget_version_id,
9885 g_tab_budget_line_id LIMIT l_num_rows;
9886 IF NOT g_tab_doc_header_id.EXISTS(1) then
9887 EXIT;
9888 END IF;
9889
9890 FOR i IN g_tab_doc_type.FIRST .. g_tab_doc_type.LAST LOOP
9891
9892 If g_tab_doc_type(i) in ('CC_C_PAY','CC_P_PAY','AP'
9893 ,'PO','REQ','EXP') THEN
9894 l_ext_bdgt_type := 'STD';
9895 Elsif g_tab_doc_type(i) in ('CC_C_CO','CC_P_CO') then
9896 l_ext_bdgt_type := 'CBC';
9897 End if;
9898
9899 If (l_pre_project_id is NULL or l_pre_project_id
9900 <> g_tab_project_id(i)) OR
9901 (l_pre_ext_bdgt_type is NULL or l_pre_ext_bdgt_type <>
9902 l_ext_bdgt_type ) then
9903
9904 l_ext_bdgt_link := PA_FUNDS_CONTROL_UTILS.get_bdgt_link(
9905 p_project_id => g_tab_project_id(i),
9906 p_calling_mode => l_ext_bdgt_type );
9907
9908
9909 END IF;
9910
9911 l_tab_ext_bdgt_flag(i) := l_ext_bdgt_link;
9912
9913 l_pre_project_id := g_tab_project_id(i);
9914 l_pre_ext_bdgt_type := l_ext_bdgt_type;
9915
9916 END LOOP;
9917 IF g_debug_mode = 'Y' THEN
9918 log_message(p_msg_token1 => 'Check for the Advisory Warnings ');
9919 End if;
9920
9921 FOR i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST LOOP
9922 l_tab_dist_warn_code(i) := 'P';
9923
9924 If substr(g_tab_result_code(i),1,1) = 'P' then
9925 IF g_tab_r_result_code(i) = 'P112' then
9926 l_tab_dist_warn_code(i) := 'P112';
9927 Elsif g_tab_rg_result_code(i) = 'P110' and
9928 l_tab_dist_warn_code(i) <> 'P112' then
9929 l_tab_dist_warn_code(i) := 'P110';
9930 Elsif g_tab_t_result_code(i) = 'P108' and
9931 l_tab_dist_warn_code(i) NOT IN ('P112','P110') then
9932 l_tab_dist_warn_code(i) := 'P108';
9933 Elsif g_tab_tt_result_code(i) = 'P106' and
9934 l_tab_dist_warn_code(i) NOT IN ('P112','P110','P108') then
9935 l_tab_dist_warn_code(i) := 'P106';
9936 Elsif g_tab_p_result_code(i) = 'P104' and
9937 l_tab_dist_warn_code(i) NOT IN ('P112','P110','P108','P106') then
9938 l_tab_dist_warn_code(i) := 'P104';
9939 End if;
9940 Else
9941 l_tab_dist_warn_code(i) := null;
9942 End if;
9943 If l_tab_dist_warn_code(i) NOT IN
9944 ('P112','P110','P108','P106','P104') then
9945 l_tab_dist_warn_code(i) := null;
9946 End if;
9947
9948 END LOOP;
9949
9950
9951 l_count := 0;
9952
9953 FOR i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST LOOP
9954 l_count := l_count + 1;
9955 If substr(g_tab_result_code(i),1,1) = 'P' then
9956 If g_tab_doc_header_id(i) <> l_doc_header_id OR
9957 l_doc_header_id is NULL then
9958 j := l_count;
9959 l_warn_code := 'P';
9960 LOOP -- through all cdls lines
9961 If NOT g_tab_doc_header_id.exists(j) then
9962 Exit;
9963 End if;
9964 If g_tab_doc_header_id(i) = g_tab_doc_header_id(j) then
9965 If substr(g_tab_result_code(i),1,1) = 'P' then
9966 IF l_tab_dist_warn_code(j) = 'P112' then
9967 l_warn_code := 'P112';
9968 Exit;
9969 Elsif l_tab_dist_warn_code(j) = 'P110' and
9970 l_warn_code <> 'P112' then
9971 l_warn_code := 'P110';
9972 Elsif l_tab_dist_warn_code(j) = 'P108' and
9973 l_warn_code NOT IN ('P112','P110') then
9974 l_warn_code := 'P108';
9975 Elsif l_tab_dist_warn_code(j) = 'P106' and
9976 l_warn_code NOT IN
9977 ('P112','P110','P108') then
9978 l_warn_code := 'P106';
9979 Elsif l_tab_dist_warn_code(j) = 'P104' and
9980 l_warn_code NOT IN
9981 ('P112','P110','P108','P106') then
9982 l_warn_code := 'P104';
9983 End if;
9984 End if;
9985 Else
9986 exit;
9987 End if;
9988 j := j + 1;
9989
9990 END LOOP;
9991 l_tab_warning_code(i) := l_warn_code;
9992 If l_tab_warning_code(i) NOT IN
9993 ('P112','P110','P108','P106','P104') then
9994 l_tab_warning_code(i) := null;
9995 End if;
9996 l_doc_header_id := g_tab_doc_header_id(i);
9997
9998 Else
9999 l_tab_warning_code(i) := l_warn_code;
10000 If l_tab_warning_code(i) NOT IN
10001 ('P112','P110','P108','P106','P104') then
10002 l_tab_warning_code(i) := null;
10003 End if;
10004 End If;
10005 Else -- for result code fail
10006 l_tab_warning_code(i) := null;
10007 End if;
10008
10009 END LOOP;
10010 -- update ei with cost dist rejection code if there is failed funds check
10011 -- and update ei with cost dist warning code for transaction with
10012 -- advisory warnings.
10013 IF g_debug_mode = 'Y' THEN
10014 log_message(p_msg_token1 => 'Calling FORALL update for EI');
10015 End if;
10016 /*=========================================================+
10017 | Bug 3565708: Added g_tab_p_bc_packet_id(i) = -7777 ; so |
10018 | rejection would include BTC txns also. |
10019 +=========================================================*/
10020 FORALL i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST
10021 UPDATE pa_expenditure_items_all
10022 SET cost_dist_rejection_code =
10023 decode(substr(g_tab_result_code(i),1,1),'F',
10024 g_tab_result_code(i),null)
10025 ,cost_dist_warning_code = l_tab_warning_code(i)
10026 WHERE expenditure_item_id = g_tab_doc_header_id(i)
10027 AND (g_tab_p_bc_packet_id(i) is NULL OR g_tab_p_bc_packet_id(i) = -7777 );
10028 IF g_debug_mode = 'Y' THEN
10029 log_message(p_msg_token1 => 'Calling FORALL update for CDL');
10030 End if;
10031 -- If the transaction passes the fundscheck then update the
10032 -- cdls with gl_date,encumbrance type id, budget ccid and
10033 -- encumbrance amount for the R line .updating C and D lines
10034 -- will be done in Distribute Burden transaction process
10035 FORALL i IN g_tab_doc_header_id.FIRST .. g_tab_doc_header_id.LAST
10036 UPDATE pa_cost_distribution_lines_all
10037 SET --gl_date = g_tab_gl_date(i)
10038 budget_ccid = g_tab_budget_ccid(i)
10039 ,budget_version_id = g_tab_budget_version_id(i)
10040 ,budget_line_id = g_tab_budget_line_id(i)
10041 ,liquidate_encum_flag = 'Y'
10042 ,encumbrance_type_id = g_tab_encum_type_id(i)
10043 ,encumbrance_amount = nvl(g_tab_accounted_dr(i),0) -
10044 nvl(g_tab_accounted_cr(i),0)
10045 WHERE expenditure_item_id = g_tab_doc_header_id(i)
10046 AND line_num = g_tab_doc_distribution_id(i)
10047 AND line_type = 'R'
10048 AND g_tab_p_bc_packet_id(i) is null
10049 AND l_tab_ext_bdgt_flag(i) = 'Y'
10050 AND substr(nvl(g_tab_result_code(i),'P'),1,1) = 'P';
10051
10052 EXIT WHEN ei_details%NOTFOUND;
10053 IF g_debug_mode = 'Y' THEN
10054 log_message(p_msg_token1 => 'end of FORALL update for CDL');
10055 End if;
10056 END LOOP;
10057 END IF;
10058
10059 END IF;
10060 pa_debug.reset_err_stack;
10061
10062 Return;
10063 EXCEPTION
10064 WHEN OTHERS THEN
10065 x_return_status := 'T';
10066 IF g_debug_mode = 'Y' THEN
10067 log_message(p_msg_token1 => 'SQLERR :'||sqlcode||sqlerrm|| 'failed in update_EIS api');
10068 End if;
10069 log_message(p_error_msg => sqlcode||sqlerrm);
10070 Raise;
10071 END update_EIS;
10072 ------------------------------------------------------------
10073 -- This api posts the encumbrance liqudation entries and
10074 -- updates the budget account balances when there is
10075 -- link with the std budget
10076 -----------------------------------------------------------
10077 PROCEDURE upd_bdgt_encum_bal(
10078 p_packet_id IN NUMBER,
10079 p_calling_module IN VARCHAR2,
10080 p_mode IN VARCHAR2,
10081 p_packet_status IN VARCHAR2,
10082 x_return_status OUT NOCOPY VARCHAR2) IS
10083
10084 CURSOR bdgt_encum_details is
10085 SELECT project_id,
10086 budget_version_id,
10087 budget_ccid,
10088 period_name,
10089 sum(nvl(accounted_dr,0)),
10090 sum(nvl(accounted_cr,0))
10091 FROM pa_bc_packets
10092 WHERE packet_id = p_packet_id
10093 AND substr(nvl(result_code,'P'),1,1) = 'P'
10094 AND status_code = 'A'
10095 AND NVL(ext_bdgt_flag,'N') = 'Y' /*PAM changes */
10096 GROUP BY project_id,
10097 budget_version_id,
10098 budget_ccid,
10099 period_name
10100 ORDER BY project_id,
10101 budget_version_id,
10102 budget_ccid,
10103 period_name;
10104
10105 l_num_rows NUMBER := 200;
10106 l_error_msg_code VARCHAR2(1000);
10107 l_return_status VARCHAR2(100);
10108 l_msg_count NUMBER;
10109 l_debug_stage varchar2(10000);
10110 l_bdgt_acct_amt Number;
10111
10112 BEGIN
10113 g_debug_mode := 'Y';
10114 --Initialize the error stack
10115 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.upd_bdgt_encum_bal');
10116 IF g_debug_mode = 'Y' THEN
10117 log_message(p_msg_token1 => 'inside the update budget acct api'||
10118 'calling module ['||p_calling_module||']p_mode ['||p_mode||
10119 ']p_packet_status ['||p_packet_status ||']' );
10120 End if;
10121
10122 x_return_status := 'S';
10123
10124 IF p_packet_status = 'S' and p_mode in ('R','U','F') then
10125
10126 OPEN bdgt_encum_details;
10127 LOOP
10128 g_tab_project_id.delete;
10129 g_tab_budget_version_id.delete;
10130 g_tab_budget_ccid.delete;
10131 g_tab_period_name.delete;
10132 g_tab_accounted_dr.delete;
10133 g_tab_accounted_cr.delete;
10134 g_tab_encum_type_id.delete;
10135 g_tab_gl_date.delete;
10136 g_tab_doc_type.delete;
10137
10138 FETCH bdgt_encum_details BULK COLLECT INTO
10139 g_tab_project_id,
10140 g_tab_budget_version_id,
10141 g_tab_budget_ccid,
10142 g_tab_period_name,
10143 g_tab_accounted_dr,
10144 g_tab_accounted_cr LIMIT l_num_rows;
10145 IF g_debug_mode = 'Y' THEN
10146 log_message(p_msg_token1 => 'fetched rows['||g_tab_project_id.count||']into plsql tables ');
10147 End if;
10148 IF NOT g_tab_project_id.EXISTS(1) then
10149 IF g_debug_mode = 'Y' THEN
10150 log_message(p_msg_token1 => 'No rows found exit ');
10151 End if;
10152 EXIT;
10153 END IF;
10154 log_message(p_msg_token1 => 'Calling UPD_BDGT_ACCT_BAL api in Loop');
10155 FOR i IN g_tab_budget_ccid.FIRST .. g_tab_budget_ccid.LAST LOOP
10156 l_bdgt_acct_amt := (nvl(g_tab_accounted_dr(i),0) - nvl(g_tab_accounted_cr(i),0));
10157 IF g_debug_mode = 'Y' THEN
10158 log_message(p_msg_token1 => 'calling pa_budget_fund_pkg.UPD_BDGT_ACCT_BAL api ');
10159 l_debug_stage := 'p_gl_period_name ['||g_tab_period_name(i)||']p_budget_version_id [';
10160 l_debug_stage := l_debug_stage||g_tab_budget_version_id(i)||']p_ccid [';
10161 l_debug_stage := l_debug_stage||g_tab_budget_ccid(i)||']p_amount [';
10162 l_debug_stage := l_debug_stage||l_bdgt_acct_amt||']' ;
10163 log_message(p_msg_token1 => l_debug_stage);
10164 End if;
10165 If NVL(l_bdgt_acct_amt,0) <> 0 Then
10166 pa_budget_fund_pkg.UPD_BDGT_ACCT_BAL
10167 (p_gl_period_name => g_tab_period_name(i),
10168 p_budget_version_id => g_tab_budget_version_id(i),
10169 p_ccid => g_tab_budget_ccid(i),
10170 p_amount => l_bdgt_acct_amt,
10171 x_msg_data => l_error_msg_code,
10172 x_msg_count => l_msg_count,
10173 x_return_status => l_return_status
10174 );
10175 End if;
10176 IF g_debug_mode = 'Y' THEN
10177 log_message(p_msg_token1 => 'end of UPD_BDGT_ACCT_BAL apirestun status ='||l_return_status);
10178 End if;
10179
10180 END LOOP;
10181 --COMMIT;
10182 EXIT WHEN bdgt_encum_details%NOTFOUND;
10183 END LOOP;
10184 CLOSE bdgt_encum_details;
10185
10186 END IF; -- end if for packet status
10187
10188 pa_debug.reset_err_stack;
10189
10190 RETURN;
10191
10192 EXCEPTION
10193 when others then
10194 IF bdgt_encum_details%isopen then
10195 close bdgt_encum_details;
10196 END IF;
10197 x_return_status := 'T';
10198 result_status_code_update
10199 (p_packet_id => p_packet_id,
10200 p_result_code => 'F162',
10201 p_res_result_code => 'F162',
10202 p_res_grp_result_code => 'F162',
10203 p_task_result_code => 'F162',
10204 p_top_task_result_code => 'F162',
10205 p_project_result_code => 'F162',
10206 p_proj_acct_result_code => 'F162',
10207 p_status_code => 'T');
10208 If g_debug_mode = 'Y' Then
10209 log_message(p_msg_token1 => 'failed in upd bdgt encum bal api SQLERR :'||sqlcode||sqlerrm);
10210 End if;
10211 Raise;
10212 END upd_bdgt_encum_bal;
10213
10214 -------->6599207 ------As part of CC Enhancements
10215 PROCEDURE create_liqd_entry
10216 (p_packet_id IN NUMBER,
10217 p_calling_module IN varchar2,
10218 p_reference2 IN varchar2,
10219 p_reference1 IN varchar2,
10220 p_mode IN varchar2,
10221 p_packet_status IN varchar2,
10222 x_return_status OUT NOCOPY varchar2) IS
10223
10224 l_max_batch_line_id number(10);
10225
10226 BEGIN
10227 --Initialize the error stack
10228 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.create_liqd_entry');
10229
10230 x_return_status := 'S';
10231 If g_debug_mode = 'Y' Then
10232 log_message(p_msg_token1 => 'Inside the create_liqd_entry api ');
10233 End if;
10234 /** Bug fix : 1900229 During Check mode also insert liquidation and burden transaction
10235 * to gl_bc_packets and igc_cc_interface tables
10236 */
10237
10238 IF p_calling_module = 'CBC' and p_mode in ('R','U','C','F') then
10239
10240 SELECT nvl(MAX(batch_line_num),0)
10241 INTO l_max_batch_line_id
10242 FROM igc_cc_interface
10243 WHERE document_type = 'CC'
10244 AND cc_header_id = p_reference2;
10245
10246
10247 INSERT INTO igc_cc_interface(
10248 CC_HEADER_ID,
10249 CC_VERSION_NUM,
10250 CC_ACCT_LINE_ID,
10251 CC_DET_PF_LINE_ID ,
10252 CODE_COMBINATION_ID,
10253 BATCH_LINE_NUM ,
10254 CC_TRANSACTION_DATE ,
10255 CC_FUNC_DR_AMT ,
10256 CC_FUNC_CR_AMT ,
10257 JE_SOURCE_NAME ,
10258 JE_CATEGORY_NAME,
10259 PERIOD_SET_NAME ,
10260 PERIOD_NAME ,
10261 ACTUAL_FLAG ,
10262 BUDGET_DEST_FLAG ,
10263 SET_OF_BOOKS_ID ,
10264 ENCUMBRANCE_TYPE_ID ,
10265 CBC_RESULT_CODE ,
10266 STATUS_CODE ,
10267 BUDGET_VERSION_ID ,
10268 BUDGET_AMT ,
10269 COMMITMENT_ENCMBRNC_AMT ,
10270 OBLIGATION_ENCMBRNC_AMT ,
10271 CC_ENCMBRNC_DATE ,
10272 FUNDS_AVAILABLE_AMT ,
10273 CURRENCY_CODE ,
10274 TRANSACTION_DESCRIPTION ,
10275 REFERENCE_1 ,
10276 REFERENCE_2 ,
10277 REFERENCE_3 ,
10278 REFERENCE_4 ,
10279 REFERENCE_5 ,
10280 REFERENCE_6 ,
10281 REFERENCE_7 ,
10282 REFERENCE_8 ,
10283 REFERENCE_9 ,
10284 REFERENCE_10,
10285 LAST_UPDATE_DATE ,
10286 LAST_UPDATED_BY ,
10287 LAST_UPDATE_LOGIN ,
10288 CREATION_DATE ,
10289 CREATED_BY ,
10290 DOCUMENT_TYPE,
10291 Project_line
10292 --BATCH_ID ,
10293 --PA_FLAG ,
10294 --RESULT_CODE_LEVEL ,
10295 --RESULT_CODE_SOURCE
10296 )
10297 SELECT
10298 igc.CC_HEADER_ID,
10299 igc.CC_VERSION_NUM,
10300 igc.CC_ACCT_LINE_ID,
10301 igc.CC_DET_PF_LINE_ID ,
10302 pbc.txn_ccid,
10303 l_max_batch_line_id + to_number(rownum), --igc.BATCH_LINE_NUM ,
10304 igc.CC_TRANSACTION_DATE ,
10305 decode(nvl(pbc.accounted_cr,0),0,NULL,pbc.accounted_cr),
10306 decode(nvl(pbc.accounted_dr,0),0,NULL,pbc.accounted_dr),
10307 igc.JE_SOURCE_NAME ,
10308 igc.JE_CATEGORY_NAME,
10309 igc.PERIOD_SET_NAME ,
10310 igc.PERIOD_NAME ,
10311 'E',
10312 igc.BUDGET_DEST_FLAG ,
10313 igc.SET_OF_BOOKS_ID ,
10314 pbc.proj_encumbrance_type_id,
10315 igc.CBC_RESULT_CODE ,
10316 igc.STATUS_CODE ,
10317 igc.BUDGET_VERSION_ID ,
10318 igc.BUDGET_AMT ,
10319 igc.COMMITMENT_ENCMBRNC_AMT ,
10320 igc.OBLIGATION_ENCMBRNC_AMT ,
10321 igc.CC_ENCMBRNC_DATE ,
10322 igc.FUNDS_AVAILABLE_AMT ,
10323 igc.CURRENCY_CODE ,
10324 igc.TRANSACTION_DESCRIPTION ,
10325 igc.REFERENCE_1 ,
10326 igc.REFERENCE_2 ,
10327 igc.REFERENCE_3 ,
10328 igc.REFERENCE_4 ,
10329 igc.REFERENCE_5 ,
10330 igc.REFERENCE_6 ,
10331 igc.REFERENCE_7 ,
10332 'PKT_ID:'||pbc.packet_id, --igc.REFERENCE_8 ,
10333 'BC_PKT_ID:'||pbc.bc_packet_id, --igc.REFERENCE_9 ,
10334 igc.REFERENCE_10,
10335 --igc.REFERENCE_10,
10336 igc.LAST_UPDATE_DATE ,
10337 igc.LAST_UPDATED_BY ,
10338 igc.LAST_UPDATE_LOGIN ,
10339 igc.CREATION_DATE ,
10340 igc.CREATED_BY ,
10341 igc.DOCUMENT_TYPE ,
10342 'Y'
10343 --igc.BATCH_ID ,
10344 --igc.PA_FLAG ,
10345 --igc.RESULT_CODE_LEVEL ,
10346 --igc.RESULT_CODE_SOURCE
10347 FROM igc_cc_interface igc,
10348 pa_bc_packets pbc
10349 WHERE pbc.packet_id = p_packet_id
10350 AND pbc.document_header_id = igc.cc_header_id
10351 AND pbc.document_distribution_id = igc.cc_acct_line_id
10352 AND pbc.document_type in ('CC_C_CO','CC_P_CO')
10353 AND pa_funds_control_utils.get_bdgt_link(
10354 pbc.project_id,decode(pbc.document_type,'CC_C_CO','CBC',
10355 'CC_P_CO','CBC',
10356 'STD')) = 'Y'
10357 AND pbc.status_code NOT IN ('Z','T','V','B')
10358 AND substr(nvl(pbc.result_code,'P'),1,1) = 'P'
10359 AND ( pbc.gl_row_number = igc.rowid
10360 OR
10361 (to_char(pbc.bc_packet_id) = substr(igc.reference_9,
10362 length('BC_PKT_ID:')+1)
10363 )
10364 );
10365 If g_debug_mode = 'Y' Then
10366 log_message(p_msg_token1 => 'No of rows inserted into CBC = '||sql%rowcount);
10367 End if;
10368
10369 END IF;
10370
10371 pa_debug.reset_err_stack;
10372 return;
10373 EXCEPTION
10374 when others then
10375 result_status_code_update
10376 (p_packet_id => p_packet_id,
10377 p_result_code => 'F161',
10378 p_res_result_code => 'F161',
10379 p_res_grp_result_code => 'F161',
10380 p_task_result_code => 'F161',
10381 p_top_task_result_code => 'F161',
10382 p_project_result_code => 'F161',
10383 p_proj_acct_result_code => 'F161',
10384 p_status_code => 'T');
10385 x_return_status := 'T';
10386 If g_debug_mode = 'Y' Then
10387 log_message(p_msg_token1 => 'failed in create liqd entry apiSQLERR :'||sqlcode||sqlerrm);
10388 End if;
10389 Raise;
10390
10391 END create_liqd_entry;
10392 -------->6599207 ------END
10393
10394
10395 --------------------------------------------------------------
10396 -- Determine the return code sent to GL / CBC /BASELINE etc
10397 -- based on the full mode or partial mode the return status
10398 -- declared as success or failure. In partial mode even if there
10399 -- are failed transaction exist in packet, the return status
10400 -- is success since the packet is partially cleared
10401 -- for the full mode even if there exist single failed transaction
10402 -- the whole packet is marked as rejected / failed
10403 --------------------------------------------------------------
10404 PROCEDURE gen_return_code(p_packet_id IN NUMBER,
10405 p_partial_flag IN VARCHAR2,
10406 p_calling_mode IN VARCHAR2,
10407 x_return_status OUT NOCOPY VARCHAR2) IS
10408
10409 l_err_code NUMBER := 0;
10410 l_return_code varchar2(1):= 'S';
10411 CURSOR cur_fatal_error IS
10412 SELECT 1
10413 FROM DUAL
10414 WHERE EXISTS (SELECT null
10415 FROM pa_bc_packets
10416 WHERE packet_id = p_packet_id
10417 AND status_code = 'T'
10418 );
10419
10420 CURSOR cur_normal_error IS
10421 SELECT 1
10422 FROM DUAL
10423 WHERE EXISTS (SELECT null
10424 FROM pa_bc_packets
10425 WHERE packet_id = p_packet_id
10426 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'F'
10427 );
10428
10429 /* To check at least one transaction is passed in partial mode */
10430 CURSOR cur_success_recs IS
10431 SELECT 1
10432 FROM DUAL
10433 WHERE EXISTS (SELECT null
10434 FROM pa_bc_packets
10435 WHERE packet_id = p_packet_id
10436 AND SUBSTR ( nvl(result_code,'P'), 1, 1 ) = 'P'
10437 );
10438
10439 BEGIN
10440
10441 -- Initialize the error stack
10442 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.gen_return_code');
10443
10444 -- Initialize the return status to success
10445 x_return_status := l_return_code;
10446
10447 -- check for fatal error in the packet
10448 OPEN cur_fatal_error;
10449 FETCH cur_fatal_error INTO l_err_code;
10450 IF cur_fatal_error%notfound then
10451 -- check for normal error
10452 OPEN cur_normal_error;
10453 FETCH cur_normal_error INTO l_err_code;
10454 IF cur_normal_error%notfound then
10455 l_err_code := 0;
10456 l_return_code := 'S';
10457 ELSE
10458 IF p_partial_flag <> 'Y' then -- full mode
10459 l_err_code := 1;
10460 l_return_code := 'F';
10461 ELSE -- partial mode
10462 -- check for any of the transaction passes the funds check
10463 OPEN cur_success_recs;
10464 FETCH cur_success_recs INTO l_err_code;
10465 IF cur_success_recs%notfound then
10466 l_err_code := 1;
10467 l_return_code := 'F';
10468 Else
10469 l_err_code := 0;
10470 l_return_code := 'S';
10471 End If;
10472 CLOSE cur_success_recs;
10473 END IF;
10474 END IF;
10475 CLOSE cur_normal_error;
10476 ELSE
10477 l_return_code := 'T';
10478 l_err_code := 1;
10479
10480 END IF;
10481 CLOSE cur_fatal_error;
10482
10483 IF l_err_code <> 0 and l_return_code <> 'S' then
10484 x_return_status := l_return_code;
10485 END IF;
10486
10487 -- reset the error stack
10488 PA_DEBUG.reset_err_stack;
10489
10490 return;
10491
10492 EXCEPTION
10493 when others then
10494 If cur_normal_error%ISOPEN THEN
10495 CLOSE cur_normal_error;
10496 END IF;
10497 IF cur_fatal_error%ISOPEN THEN
10498 CLOSE cur_fatal_error;
10499 END IF;
10500 IF cur_success_recs%ISOPEN THEN
10501 CLOSE cur_success_recs;
10502 END IF;
10503 result_status_code_update(p_packet_id => p_packet_id,
10504 p_result_code => 'F160',
10505 p_status_code => 'T',
10506 p_res_result_code => 'F160',
10507 p_res_grp_result_code => 'F160',
10508 p_task_result_code => 'F160',
10509 p_top_task_result_code => 'F160',
10510 p_project_result_code => 'F160',
10511 p_proj_acct_result_code => 'F160');
10512 If g_debug_mode = 'Y' Then
10513 log_message(p_msg_token1 => 'Failed in gen_return_code api unexpected Error '|| sqlcode||sqlerrm);
10514 End if;
10515 log_message(p_error_msg => sqlcode||sqlerrm);
10516
10517 x_return_status := 'T';
10518 return;
10519 END gen_return_code;
10520
10521 -------->6599207 ------As part of CC Enhancements
10522 PROCEDURE Post_Bdn_Lines_To_GL_CBC (
10523 p_Packet_ID IN Number,
10524 p_calling_module IN VARCHAR2,
10525 p_packet_status IN VARCHAR2,
10526 p_reference1 IN VARCHAR2,
10527 p_reference2 IN VARCHAR2,
10528 x_return_status OUT NOCOPY VARCHAR2
10529 ) IS
10530
10531 l_BCPacketID Number(15);
10532 l_GLRowNumber GL_BC_Packets.Originating_RowID%Type;
10533 l_cbcrownumber urowid;
10534 l_max_batch_line_id number(15);
10535
10536 --This cursor is defined to pick up all the burden cost lines
10537 --from the PA_BC_Packets table among other transactions.
10538
10539 CURSOR c_Burden_Costs IS
10540 SELECT BC_Packet_ID
10541 FROM PA_BC_Packets
10542 WHERE Packet_ID=p_Packet_ID AND
10543 Parent_BC_Packet_ID IS NOT NULL;
10544
10545 -- This cursor is defined to pick up the Row Number in the GL_BC_Packets
10546 -- table that corresponds to the BCPacket ID stored in PA_BC_Packets table.
10547
10548 CURSOR c_Row_Number(
10549 l_BCPacketID IN Number) IS
10550 SELECT RowID
10551 FROM GL_BC_Packets
10552 WHERE Template_ID=l_BCPacketID;
10553
10554 l_rowcount NUMBER := 0;
10555
10556 BEGIN
10557
10558 x_return_status := FND_API.G_RET_STS_SUCCESS;
10559
10560 pa_debug.init_err_stack ('PA_Funds_Control_Pkg.Post_Burden_Lines_To_GL');
10561
10562 If g_debug_mode = 'Y' Then
10563 log_message(p_msg_token1 => 'Inside the Post_Burden_Lines_To_GL api');
10564 End if;
10565
10566 IF p_calling_module = 'CBC' then
10567 SELECT nvl(MAX(batch_line_num),0)
10568 INTO l_max_batch_line_id
10569 FROM igc_cc_interface
10570 WHERE document_type = 'CC'
10571 AND cc_header_id = p_reference2;
10572
10573 INSERT INTO igc_cc_interface(
10574 CC_HEADER_ID,
10575 CC_VERSION_NUM,
10576 CC_ACCT_LINE_ID,
10577 CC_DET_PF_LINE_ID ,
10578 CODE_COMBINATION_ID,
10579 BATCH_LINE_NUM ,
10580 CC_TRANSACTION_DATE ,
10581 CC_FUNC_DR_AMT ,
10582 CC_FUNC_CR_AMT ,
10583 JE_SOURCE_NAME ,
10584 JE_CATEGORY_NAME,
10585 PERIOD_SET_NAME ,
10586 PERIOD_NAME ,
10587 ACTUAL_FLAG ,
10588 BUDGET_DEST_FLAG ,
10589 SET_OF_BOOKS_ID ,
10590 ENCUMBRANCE_TYPE_ID ,
10591 CBC_RESULT_CODE ,
10592 STATUS_CODE ,
10593 BUDGET_VERSION_ID ,
10594 BUDGET_AMT ,
10595 COMMITMENT_ENCMBRNC_AMT ,
10596 OBLIGATION_ENCMBRNC_AMT ,
10597 CC_ENCMBRNC_DATE ,
10598 FUNDS_AVAILABLE_AMT ,
10599 CURRENCY_CODE ,
10600 TRANSACTION_DESCRIPTION ,
10601 REFERENCE_1 ,
10602 REFERENCE_2 ,
10603 REFERENCE_3 ,
10604 REFERENCE_4 ,
10605 REFERENCE_5 ,
10606 REFERENCE_6 ,
10607 REFERENCE_7 ,
10608 REFERENCE_8 ,
10609 REFERENCE_9 ,
10610 REFERENCE_10,
10611 LAST_UPDATE_DATE ,
10612 LAST_UPDATED_BY ,
10613 LAST_UPDATE_LOGIN ,
10614 CREATION_DATE ,
10615 CREATED_BY ,
10616 DOCUMENT_TYPE ,
10617 Project_Line
10618 --BATCH_ID ,
10619 --PA_FLAG ,
10620 --RESULT_CODE_LEVEL ,
10621 --RESULT_CODE_SOURCE
10622 )
10623 SELECT
10624 igc.CC_HEADER_ID,
10625 igc.CC_VERSION_NUM,
10626 igc.CC_ACCT_LINE_ID,
10627 igc.CC_DET_PF_LINE_ID ,
10628 pbc.txn_ccid,
10629 l_max_batch_line_id + to_number(rownum), -- igc.BATCH_LINE_NUM ,
10630 igc.CC_TRANSACTION_DATE ,
10631 decode(nvl(pbc.accounted_dr,0),0,NULL,pbc.accounted_dr),
10632 decode(nvl(pbc.accounted_cr,0),0,NULL,pbc.accounted_cr),
10633 igc.JE_SOURCE_NAME ,
10634 igc.JE_CATEGORY_NAME,
10635 igc.PERIOD_SET_NAME ,
10636 igc.PERIOD_NAME ,
10637 igc.actual_flag,
10638 igc.BUDGET_DEST_FLAG ,
10639 igc.SET_OF_BOOKS_ID ,
10640 pbc.encumbrance_type_id,
10641 igc.CBC_RESULT_CODE ,
10642 igc.STATUS_CODE ,
10643 igc.BUDGET_VERSION_ID ,
10644 igc.BUDGET_AMT ,
10645 igc.COMMITMENT_ENCMBRNC_AMT ,
10646 igc.OBLIGATION_ENCMBRNC_AMT ,
10647 igc.CC_ENCMBRNC_DATE ,
10648 igc.FUNDS_AVAILABLE_AMT ,
10649 igc.CURRENCY_CODE ,
10650 igc.TRANSACTION_DESCRIPTION ,
10651 igc.REFERENCE_1 ,
10652 igc.REFERENCE_2 ,
10653 igc.REFERENCE_3 ,
10654 igc.REFERENCE_4 ,
10655 igc.REFERENCE_5 ,
10656 igc.REFERENCE_6 ,
10657 igc.REFERENCE_7 ,
10658 'PKT_ID:'||pbc.packet_id, --igc.REFERENCE_8 , /** checked with Arkadi cbc team **/
10659 'BC_PKT_ID:'||pbc.bc_packet_id, --igc.REFERENCE_9 , /** to use these two columns **/
10660 igc.REFERENCE_10,
10661 igc.LAST_UPDATE_DATE ,
10662 igc.LAST_UPDATED_BY ,
10663 igc.LAST_UPDATE_LOGIN ,
10664 igc.CREATION_DATE ,
10665 igc.CREATED_BY ,
10666 igc.DOCUMENT_TYPE ,
10667 'Y'
10668 --igc.BATCH_ID ,
10669 --igc.PA_FLAG ,
10670 --igc.RESULT_CODE_LEVEL ,
10671 --igc.RESULT_CODE_SOURCE
10672 FROM igc_cc_interface igc,
10673 pa_bc_packets pbc
10674 WHERE pbc.packet_id = p_packet_id
10675 AND pbc.document_type in ('CC_C_CO','CC_P_CO')
10676 /*** bug fix : 1883119
10677 AND ( pbc.status_code = 'P'
10678 OR (pbc.status_code in ('P','S') and g_mode = 'C')
10679 )
10680 **/
10681 AND pbc.status_code NOT IN ('Z','T','V','B','L')
10682 AND substr(nvl(pbc.result_code,'P'),1,1) = 'P'
10683 AND pbc.document_header_id = igc.cc_header_id
10684 AND pbc.document_distribution_id = igc.cc_acct_line_id
10685 AND ( ( pbc.parent_bc_packet_id is NOT NULL)
10686 or (pbc.parent_bc_packet_id is NULL
10687 and check_bdn_on_sep_item (pbc.project_id) = 'S')
10688 )
10689 ANd igc.document_type = 'CC';
10690 l_rowcount := sql%rowcount;
10691 If g_debug_mode = 'Y' Then
10692 log_message(p_msg_token1 => 'No of rows inseted to IGC = '||l_rowcount);
10693 End if;
10694
10695 END IF;
10696 pa_debug.reset_err_stack ;
10697
10698 EXCEPTION
10699
10700 WHEN OTHERS THEN
10701
10702 x_return_status := 'T';
10703 If p_calling_module = 'GL' then
10704 result_status_code_update(p_packet_id => p_packet_id,
10705 p_result_code => 'F163',
10706 p_status_code => 'T',
10707 p_res_result_code => 'F163',
10708 p_res_grp_result_code => 'F163',
10709 p_task_result_code => 'F163',
10710 p_top_task_result_code => 'F163',
10711 p_project_result_code => 'F163',
10712 p_proj_acct_result_code => 'F163');
10713 Elsif p_calling_module = 'CBC' then
10714 result_status_code_update(p_packet_id => p_packet_id,
10715 p_result_code => 'F164',
10716 p_status_code => 'T',
10717 p_res_result_code => 'F164',
10718 p_res_grp_result_code => 'F164',
10719 p_task_result_code => 'F164',
10720 p_top_task_result_code => 'F164',
10721 p_project_result_code => 'F164',
10722 p_proj_acct_result_code => 'F164');
10723 End if;
10724 If g_debug_mode = 'Y' Then
10725 log_message(p_msg_token1 => 'failed in post_bdn_lines_gl_cbc apiSQLERR :'||sqlcode||sqlerrm);
10726 End if;
10727 --commit;
10728 Raise;
10729 END Post_Bdn_Lines_To_GL_CBC;
10730 -------->6599207 ------END
10731
10732 ----------------------------------------------------------------
10733 --This procedure updates the result and status code in GL /CBc
10734 -- packets when the project funds check process fails
10735 ----------------------------------------------------------------
10736 PROCEDURE update_GL_CBC_result_code(
10737 p_packet_id IN number,
10738 p_calling_module IN varchar2,
10739 p_mode IN varchar2,
10740 p_partial_flag IN varchar2,
10741 p_reference1 IN varchar2 default null,
10742 p_reference2 IN varchar2 default null,
10743 p_packet_status IN varchar2,
10744 x_return_status OUT NOCOPY varchar2) IS
10745
10746 l_igc_status varchar2(100);
10747 l_pkt_fatal_error_flag varchar2(100):= 'N';
10748
10749 CURSOR pkt_status IS
10750 SELECT 'Y'
10751 FROM pa_bc_packets
10752 WHERE status_code = 'T'
10753 AND packet_id = p_packet_id
10754 AND rownum = 1;
10755
10756 CURSOR igc_status(l_cc_header_id number
10757 ,l_cc_type varchar2) is
10758 SELECT decode(count(*), count(decode(substr(nvl
10759 (igc.cbc_result_code,'P'),1,1),'P',1)),'P','F')
10760 FROM igc_cc_interface igc
10761 WHERE igc.cc_header_id = l_cc_header_id;
10762
10763
10764 CURSOR gl_status is
10765 SELECT decode(count(*), count(decode(substr(nvl
10766 (gl.result_code,'P'),1,1),'P',1)),'P','F')
10767 FROM gl_bc_packets gl
10768 WHERE gl.packet_id = p_packet_id;
10769 BEGIN
10770
10771 --Initialize the err stack
10772 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.update_GL_CBC_result_code');
10773
10774 -- initialize the return status to success
10775 x_return_status := 'S';
10776 l_pkt_fatal_error_flag := 'N';
10777 If g_debug_mode = 'Y' Then
10778 log_message(p_msg_token1 => 'Inside the update_GL_CBC_result_code api');
10779 End if;
10780
10781
10782 IF p_packet_status in ( 'S','F','T') or g_partial_flag = 'Y' then
10783
10784 OPEN pkt_status;
10785 FETCH pkt_status INTO l_pkt_fatal_error_flag;
10786 CLOSE pkt_status;
10787
10788 IF p_calling_module in ('GL','GL_TIEBACK') and p_mode in ('R','U','C','F') then
10789 If g_debug_mode = 'Y' Then
10790 log_message(p_msg_token1 =>' update gl bc packet with result code ');
10791 End if;
10792 UPDATE gl_bc_packets gl
10793 SET gl.result_code =
10794 (select MAX(
10795 decode(substr(nvl(gl.result_code,'P'),1,1),'P',
10796 decode( pbc.result_code,'F100','X00',
10797 'F101','X59',
10798 'F102','X60',
10799 'F103','X61',
10800 'F104','X62',
10801 'F105','X63',
10802 'F106','X64',
10803 'F107','X29',
10804 'F108','X30',
10805 'F109','X31',
10806 'F110','X32',
10807 'F111','X33',
10808 'F112','X34',
10809 'F113','X35',
10810 'F114','X36',
10811 'F115','X36',
10812 'F116','X36',
10813 'F117','X36',
10814 'F118','X38',
10815 'F119','X37',
10816 'F120','X36',
10817 'F121','X40',
10818 'F122','X41',
10819 'F123','X42',
10820 'F124','X43',
10821 'F125','X44',
10822 'F127','X45',
10823 'F128','X46',
10824 'F129','X47',
10825 'F130','X48',
10826 'F131','X49',
10827 'F132','X50',
10828 'F134','X51',
10829 'F135','X52',
10830 'F136','X36',
10831 'F137','X54',
10832 'F138','X55',
10833 'F140','X36',
10834 'F141','X56',
10835 'F142','X36',
10836 'F143','X53',
10837 'F144','X36',
10838 'F145','X36',
10839 'F146','X36',
10840 'F160','X36',
10841 'F161','X36',
10842 'F162','X36',
10843 'F163','X36',
10844 'F164','X36',
10845 'F165','X39',
10846 'F166','X38', -- added during CC import testing 2891273
10847 'F168','X36', -- added fo r12 ..
10848 /** added decodes for stamping advisory warnings bug :1975786 **/
10849 'P101',decode(pbc.res_result_code,'P112','P35',
10850 decode(pbc.res_grp_result_code,'P110','P36',
10851 decode(pbc.task_result_code,'P108','P37',
10852 decode(pbc.top_task_result_code,'P106','P38',
10853 decode(pbc.project_result_code,'P104','P31',
10854 decode(pbc.project_acct_result_code,'P102','P29',
10855 'P28')))))),
10856 'P102',decode(pbc.res_result_code,'P112','P35',
10857 decode(pbc.res_grp_result_code,'P110','P36',
10858 decode(pbc.task_result_code,'P108','P37',
10859 decode(pbc.top_task_result_code,'P106','P38',
10860 decode(pbc.project_result_code,'P104','P31',
10861 decode(pbc.project_acct_result_code,'P102','P29',
10862 'P29')))))),
10863 'P103',decode(pbc.res_result_code,'P112','P35',
10864 decode(pbc.res_grp_result_code,'P110','P36',
10865 decode(pbc.task_result_code,'P108','P37',
10866 decode(pbc.top_task_result_code,'P106','P38',
10867 decode(pbc.project_result_code,'P104','P31',
10868 decode(pbc.project_acct_result_code,'P102','P29',
10869 'P30')))))),
10870 'P104',decode(pbc.res_result_code,'P112','P35',
10871 decode(pbc.res_grp_result_code,'P110','P36',
10872 decode(pbc.task_result_code,'P108','P37',
10873 decode(pbc.top_task_result_code,'P106','P38',
10874 decode(pbc.project_result_code,'P104','P31',
10875 decode(pbc.project_acct_result_code,'P102','P29',
10876 'P31')))))),
10877 'P105',decode(pbc.res_result_code,'P112','P35',
10878 decode(pbc.res_grp_result_code,'P110','P36',
10879 decode(pbc.task_result_code,'P108','P37',
10880 decode(pbc.top_task_result_code,'P106','P38',
10881 decode(pbc.project_result_code,'P104','P31',
10882 decode(pbc.project_acct_result_code,'P102','P29',
10883 'P30')))))),
10884 'P106',decode(pbc.res_result_code,'P112','P35',
10885 decode(pbc.res_grp_result_code,'P110','P36',
10886 decode(pbc.task_result_code,'P108','P37',
10887 decode(pbc.top_task_result_code,'P106','P38',
10888 decode(pbc.project_result_code,'P104','P31',
10889 decode(pbc.project_acct_result_code,'P102','P29',
10890 'P38')))))),
10891 'P107',decode(pbc.res_result_code,'P112','P35',
10892 decode(pbc.res_grp_result_code,'P110','P36',
10893 decode(pbc.task_result_code,'P108','P37',
10894 decode(pbc.top_task_result_code,'P106','P38',
10895 decode(pbc.project_result_code,'P104','P31',
10896 decode(pbc.project_acct_result_code,'P102','P29',
10897 'P30')))))),
10898 'P108',decode(pbc.res_result_code,'P112','P35',
10899 decode(pbc.res_grp_result_code,'P110','P36',
10900 decode(pbc.task_result_code,'P108','P37',
10901 decode(pbc.top_task_result_code,'P106','P38',
10902 decode(pbc.project_result_code,'P104','P31',
10903 decode(pbc.project_acct_result_code,'P102','P29',
10904 'P37')))))),
10905 'P109',decode(pbc.res_result_code,'P112','P35',
10906 decode(pbc.res_grp_result_code,'P110','P36',
10907 decode(pbc.task_result_code,'P108','P37',
10908 decode(pbc.top_task_result_code,'P106','P38',
10909 decode(pbc.project_result_code,'P104','P31',
10910 decode(pbc.project_acct_result_code,'P102','P29',
10911 'P30')))))),
10912 'P110',decode(pbc.res_result_code,'P112','P35',
10913 decode(pbc.res_grp_result_code,'P110','P36',
10914 decode(pbc.task_result_code,'P108','P37',
10915 decode(pbc.top_task_result_code,'P106','P38',
10916 decode(pbc.project_result_code,'P104','P31',
10917 decode(pbc.project_acct_result_code,'P102','P29',
10918 'P36')))))),
10919 'P111',decode(pbc.res_result_code,'P112','P35',
10920 decode(pbc.res_grp_result_code,'P110','P36',
10921 decode(pbc.task_result_code,'P108','P37',
10922 decode(pbc.top_task_result_code,'P106','P38',
10923 decode(pbc.project_result_code,'P104','P31',
10924 decode(pbc.project_acct_result_code,'P102','P29',
10925 'P30')))))),
10926 'P112',decode(pbc.res_result_code,'P112','P35',
10927 decode(pbc.res_grp_result_code,'P110','P36',
10928 decode(pbc.task_result_code,'P108','P37',
10929 decode(pbc.top_task_result_code,'P106','P38',
10930 decode(pbc.project_result_code,'P104','P31',
10931 decode(pbc.project_acct_result_code,'P102','P29',
10932 'P35')))))),
10933 'P113','P32',
10934 'P114','P33',
10935 'P115','P34',
10936 'P116','P05',
10937 'F150','F58',
10938 'F151','F58',
10939 'F155','F58',
10940 'F156','F58',
10941 'F152','F57',
10942 'F153','F57',
10943 'F157','F57',
10944 'F158','F57',
10945 'F169','F35',
10946 'F170','F36',
10947 'F171','F36',
10948 'F172','F36',
10949 'F173','F36',
10950 gl.result_code )
10951 , gl.result_code ))
10952 from pa_bc_packets pbc
10953 where pbc.packet_id = p_packet_id
10954 and pbc.document_distribution_id = gl.source_distribution_id_num_1
10955 and ((pbc.source_event_id = gl.event_id
10956 and (pbc.document_type = decode(gl.source_distribution_type,'AP_INV_DIST','AP','AP_PREPAY','AP','X')
10957 OR
10958 pbc.document_type = decode(gl.source_distribution_type,'PO_DISTRIBUTIONS_ALL','PO','X')
10959 OR
10960 pbc.document_type = decode(gl.source_distribution_type,'PO_REQ_DISTRIBUTIONS_ALL','REQ','X')
10961 OR
10962 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_C_PAY')
10963 OR
10964 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_P_PAY')
10965 )
10966 )
10967 OR
10968 (pbc.bc_event_id = gl.event_id
10969 and (pbc.document_type = decode(gl.source_distribution_type,'PA_AP_BURDEN','AP','X')
10970 OR
10971 pbc.document_type = decode(gl.source_distribution_type,'PA_PO_BURDEN','PO','X')
10972 OR
10973 pbc.document_type = decode(gl.source_distribution_type,'PA_REQ_BURDEN','REQ','X')
10974 OR
10975 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_C_PAY')
10976 OR
10977 pbc.document_type = decode(gl.source_distribution_type,'CC','CC_P_PAY')
10978 )
10979 )
10980 )
10981 )
10982 WHERE gl.packet_id = p_packet_id
10983 -- Bug 5352185 : Added the nvl to the following AND condition.
10984 AND nvl(substr(gl.result_code,1,1),'P') not in ('X') -- In AP matched case if PO fails, the PO rec. already failed
10985 AND (gl.event_id, gl.source_distribution_id_num_1
10986 --,source_distribution_type
10987 ) in
10988 (Select pb.bc_event_id,
10989 pb.document_distribution_id
10990 --,decode(pb.document_type,
10991 -- 'AP','AP_INV_DIST',
10992 -- 'AP','PA_AP_BURDEN',
10993 -- 'PO','PO_DISTRIBUTIONS_ALL',
10994 -- 'PO','PA_PO_BURDEN',
10995 -- 'REQ','PA_REQ_BURDEN',
10996 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
10997 from pa_bc_packets pb
10998 where pb.packet_id = p_packet_id
10999 UNION ALL
11000 Select pb.source_event_id,
11001 pb.document_distribution_id
11002 --,decode(pb.document_type,
11003 -- 'AP','AP_INV_DIST',
11004 -- 'AP','PA_AP_BURDEN',
11005 -- 'PO','PO_DISTRIBUTIONS_ALL',
11006 -- 'PO','PA_PO_BURDEN',
11007 -- 'REQ','PA_REQ_BURDEN',
11008 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
11009 from pa_bc_packets pb
11010 where pb.packet_id = p_packet_id);
11011
11012 If g_debug_mode = 'Y' Then
11013 log_message(p_msg_token1 =>'no of rows result code updated after= '||sql%rowcount);
11014 End if;
11015
11016 -- Following code is being added as in case of AP-PO matched case, in gl_bc_packets
11017 -- source_distribution_id_num_1 points to AP
11018 -- this is only reqd. in case of non-integrated budgets as for non-integrated budgets we do
11019 -- not create "PA_PO_BURDEN" records so no records in gl_bc_packets gets updated ..
11020
11021 If nvl(g_ap_matched_case,'N') = 'Y' then
11022 If g_debug_mode = 'Y' Then
11023 log_message(p_msg_token1 =>' update gl bc packet with result code for PO for AP matched');
11024 End if;
11025
11026 UPDATE gl_bc_packets gl
11027 SET gl.result_code =
11028 (select MAX(
11029 decode(substr(nvl(gl.result_code,'P'),1,1),'P',
11030 decode( pbc.result_code,'F100','X00',
11031 'F101','X59',
11032 'F102','X60',
11033 'F103','X61',
11034 'F104','X62',
11035 'F105','X63',
11036 'F106','X64',
11037 'F107','X29',
11038 'F108','X30',
11039 'F109','X31',
11040 'F110','X32',
11041 'F111','X33',
11042 'F112','X34',
11043 'F113','X35',
11044 'F114','X36',
11045 'F115','X36',
11046 'F116','X36',
11047 'F117','X36',
11048 'F118','X38',
11049 'F119','X37',
11050 'F120','X36',
11051 'F121','X40',
11052 'F122','X41',
11053 'F123','X42',
11054 'F124','X43',
11055 'F125','X44',
11056 'F127','X45',
11057 'F128','X46',
11058 'F129','X47',
11059 'F130','X48',
11060 'F131','X49',
11061 'F132','X50',
11062 'F134','X51',
11063 'F135','X52',
11064 'F136','X36',
11065 'F137','X54',
11066 'F138','X55',
11067 'F140','X36',
11068 'F141','X56',
11069 'F142','X36',
11070 'F143','X53',
11071 'F144','X36',
11072 'F145','X36',
11073 'F146','X36',
11074 'F160','X36',
11075 'F161','X36',
11076 'F162','X36',
11077 'F163','X36',
11078 'F164','X36',
11079 'F165','X39',
11080 'F166','X38', -- added during CC import testing 2891273
11081 'F168','X36', -- added fo r12 ..
11082 /** added decodes for stamping advisory warnings bug :1975786 **/
11083 'P101',decode(pbc.res_result_code,'P112','P35',
11084 decode(pbc.res_grp_result_code,'P110','P36',
11085 decode(pbc.task_result_code,'P108','P37',
11086 decode(pbc.top_task_result_code,'P106','P38',
11087 decode(pbc.project_result_code,'P104','P31',
11088 decode(pbc.project_acct_result_code,'P102','P29',
11089 'P28')))))),
11090 'P102',decode(pbc.res_result_code,'P112','P35',
11091 decode(pbc.res_grp_result_code,'P110','P36',
11092 decode(pbc.task_result_code,'P108','P37',
11093 decode(pbc.top_task_result_code,'P106','P38',
11094 decode(pbc.project_result_code,'P104','P31',
11095 decode(pbc.project_acct_result_code,'P102','P29',
11096 'P29')))))),
11097 'P103',decode(pbc.res_result_code,'P112','P35',
11098 decode(pbc.res_grp_result_code,'P110','P36',
11099 decode(pbc.task_result_code,'P108','P37',
11100 decode(pbc.top_task_result_code,'P106','P38',
11101 decode(pbc.project_result_code,'P104','P31',
11102 decode(pbc.project_acct_result_code,'P102','P29',
11103 'P30')))))),
11104 'P104',decode(pbc.res_result_code,'P112','P35',
11105 decode(pbc.res_grp_result_code,'P110','P36',
11106 decode(pbc.task_result_code,'P108','P37',
11107 decode(pbc.top_task_result_code,'P106','P38',
11108 decode(pbc.project_result_code,'P104','P31',
11109 decode(pbc.project_acct_result_code,'P102','P29',
11110 'P31')))))),
11111 'P105',decode(pbc.res_result_code,'P112','P35',
11112 decode(pbc.res_grp_result_code,'P110','P36',
11113 decode(pbc.task_result_code,'P108','P37',
11114 decode(pbc.top_task_result_code,'P106','P38',
11115 decode(pbc.project_result_code,'P104','P31',
11116 decode(pbc.project_acct_result_code,'P102','P29',
11117 'P30')))))),
11118 'P106',decode(pbc.res_result_code,'P112','P35',
11119 decode(pbc.res_grp_result_code,'P110','P36',
11120 decode(pbc.task_result_code,'P108','P37',
11121 decode(pbc.top_task_result_code,'P106','P38',
11122 decode(pbc.project_result_code,'P104','P31',
11123 decode(pbc.project_acct_result_code,'P102','P29',
11124 'P38')))))),
11125 'P107',decode(pbc.res_result_code,'P112','P35',
11126 decode(pbc.res_grp_result_code,'P110','P36',
11127 decode(pbc.task_result_code,'P108','P37',
11128 decode(pbc.top_task_result_code,'P106','P38',
11129 decode(pbc.project_result_code,'P104','P31',
11130 decode(pbc.project_acct_result_code,'P102','P29',
11131 'P30')))))),
11132 'P108',decode(pbc.res_result_code,'P112','P35',
11133 decode(pbc.res_grp_result_code,'P110','P36',
11134 decode(pbc.task_result_code,'P108','P37',
11135 decode(pbc.top_task_result_code,'P106','P38',
11136 decode(pbc.project_result_code,'P104','P31',
11137 decode(pbc.project_acct_result_code,'P102','P29',
11138 'P37')))))),
11139 'P109',decode(pbc.res_result_code,'P112','P35',
11140 decode(pbc.res_grp_result_code,'P110','P36',
11141 decode(pbc.task_result_code,'P108','P37',
11142 decode(pbc.top_task_result_code,'P106','P38',
11143 decode(pbc.project_result_code,'P104','P31',
11144 decode(pbc.project_acct_result_code,'P102','P29',
11145 'P30')))))),
11146 'P110',decode(pbc.res_result_code,'P112','P35',
11147 decode(pbc.res_grp_result_code,'P110','P36',
11148 decode(pbc.task_result_code,'P108','P37',
11149 decode(pbc.top_task_result_code,'P106','P38',
11150 decode(pbc.project_result_code,'P104','P31',
11151 decode(pbc.project_acct_result_code,'P102','P29',
11152 'P36')))))),
11153 'P111',decode(pbc.res_result_code,'P112','P35',
11154 decode(pbc.res_grp_result_code,'P110','P36',
11155 decode(pbc.task_result_code,'P108','P37',
11156 decode(pbc.top_task_result_code,'P106','P38',
11157 decode(pbc.project_result_code,'P104','P31',
11158 decode(pbc.project_acct_result_code,'P102','P29',
11159 'P30')))))),
11160 'P112',decode(pbc.res_result_code,'P112','P35',
11161 decode(pbc.res_grp_result_code,'P110','P36',
11162 decode(pbc.task_result_code,'P108','P37',
11163 decode(pbc.top_task_result_code,'P106','P38',
11164 decode(pbc.project_result_code,'P104','P31',
11165 decode(pbc.project_acct_result_code,'P102','P29',
11166 'P35')))))),
11167 'P113','P32',
11168 'P114','P33',
11169 'P115','P34',
11170 'P116','P05',
11171 'F150','F58',
11172 'F151','F58',
11173 'F155','F58',
11174 'F156','F58',
11175 'F152','F57',
11176 'F153','F57',
11177 'F157','F57',
11178 'F158','F57',
11179 'F169','F35',
11180 'F170','F36',
11181 'F171','F36',
11182 'F172','F36',
11183 'F173','F36',
11184 gl.result_code )
11185 , gl.result_code ))
11186 from pa_bc_packets pbc
11187 where pbc.packet_id = p_packet_id
11188 and pbc.document_type = 'PO'
11189 and pbc.bc_event_id is null
11190 and pbc.reference3 = gl.source_distribution_id_num_1
11191 and (nvl(pbc.accounted_dr,0) - nvl(pbc.accounted_cr,0)) =
11192 -1* (nvl(gl.accounted_dr,0) - nvl(gl.accounted_cr,0))
11193 )
11194 WHERE gl.packet_id = p_packet_id
11195 AND gl.source_distribution_type = 'AP_INV_DIST'
11196 AND substr(gl.result_code,1,1) not in ('X','F')
11197 AND exists
11198 ( select 1
11199 from pa_bc_packets pbc1
11200 where pbc1.packet_id = p_packet_id
11201 and pbc1.document_type = 'PO'
11202 and pbc1.bc_event_id is null
11203 and pbc1.reference3 = gl.source_distribution_id_num_1
11204 and (nvl(pbc1.accounted_dr,0) - nvl(pbc1.accounted_cr,0)) =
11205 -1* (nvl(gl.accounted_dr,0) - nvl(gl.accounted_cr,0))
11206 );
11207
11208 If g_debug_mode = 'Y' Then
11209 log_message(p_msg_token1 =>'(AP match,non int) no of rows,result code updated= '||sql%rowcount);
11210 End if;
11211
11212 End If;
11213
11214
11215 IF p_calling_module in ('GL_TIEBACK') then
11216
11217 open gl_status;
11218 fetch gl_status into l_igc_status;
11219 close gl_status;
11220
11221 If g_debug_mode = 'Y' Then
11222 log_message(p_msg_token1 =>'p_calling_module ['||p_calling_module||']l_gl_status ['||l_igc_status||']');
11223 End if;
11224
11225 UPDATE gl_bc_packets gl
11226 SET gl.result_code = decode(substr(gl.result_code,1,1),'P',
11227 decode(sign(nvl(gl.accounted_dr,0) - nvl(gl.accounted_cr,0)),
11228 -1, 'P32',
11229 gl.result_code),gl.result_code),
11230 gl.status_code = decode(nvl(l_pkt_fatal_error_flag,'N'),'Y','T',
11231 decode(p_partial_flag
11232 ,'Y', decode(substr(nvl(gl.result_code,'P'),1,1) ,
11233 'P',gl.status_code,
11234 'F',decode(p_mode,'C','F','R'),
11235 'X',decode(p_mode,'C','F','R'),
11236 gl.status_code)
11237 ,'N',decode(p_packet_status,
11238 'S',decode(l_igc_status,'P', decode(p_mode,'C','S','A'),
11239 'F', decode(p_mode,'C','F','R')),
11240 'F',decode(p_mode,'C','F','R'),
11241 'T',decode(p_mode,'C','F','R'),'R')))
11242 WHERE gl.packet_id = p_packet_id
11243 AND (gl.event_id, gl.source_distribution_id_num_1
11244 --,source_distribution_type
11245 ) in
11246 (Select pb.bc_event_id,
11247 pb.document_distribution_id
11248 --,decode(pb.document_type,
11249 -- 'AP','AP_INV_DIST',
11250 -- 'AP','PA_AP_BURDEN',
11251 -- 'PO','PO_DISTRIBUTIONS_ALL',
11252 -- 'PO','PA_PO_BURDEN',
11253 -- 'REQ','PA_REQ_BURDEN',
11254 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
11255 from pa_bc_packets pb
11256 where pb.packet_id = p_packet_id
11257 UNION ALL
11258 Select pb.source_event_id,
11259 pb.document_distribution_id
11260 --,decode(pb.document_type,
11261 -- 'AP','AP_INV_DIST',
11262 -- 'AP','PA_AP_BURDEN',
11263 -- 'PO','PO_DISTRIBUTIONS_ALL',
11264 -- 'PO','PA_PO_BURDEN',
11265 -- 'REQ','PA_REQ_BURDEN',
11266 -- 'REQ','PO_REQ_DISTRIBUTIONS_ALL') source_distribution_type
11267 from pa_bc_packets pb
11268 where pb.packet_id = p_packet_id);
11269
11270
11271 If g_debug_mode = 'Y' Then
11272 log_message(p_msg_token1 =>'no of rows status code updated after= '||sql%rowcount);
11273 End if;
11274 END IF;
11275
11276 ELSIF p_calling_module in('CBC','CBC_TIEBACK') and p_mode in ('R','U','C','F') then
11277 If g_debug_mode = 'Y' Then
11278 log_message(p_msg_token1 =>' update CBC packet with result code ');
11279 End if;
11280
11281 UPDATE igc_cc_interface igc
11282 SET igc.cbc_result_code =
11283 (select MAX(
11284 decode(substr(nvl(igc.cbc_result_code,'P'),1,1),'P',
11285 decode( pbc.result_code,'F100','F00',
11286 'F101','F59',
11287 'F102','F60',
11288 'F103','F61',
11289 'F104','F62',
11290 'F105','F63',
11291 'F106','F64',
11292 'F107','F29',
11293 'F108','F30',
11294 'F109','F31',
11295 'F110','F32',
11296 'F111','F33',
11297 'F112','F34',
11298 'F113','F35',
11299 'F114','F36',
11300 'F115','F36',
11301 'F116','F36',
11302 'F117','F36',
11303 'F118','F38',
11304 'F119','F37',
11305 'F120','F36',
11306 'F121','F40',
11307 'F122','F41',
11308 'F123','F42',
11309 'F124','F43',
11310 'F125','F44',
11311 'F127','F45',
11312 'F128','F46',
11313 'F129','F47',
11314 'F130','F48',
11315 'F131','F49',
11316 'F132','F50',
11317 'F134','F51',
11318 'F135','F52',
11319 'F136','F36',
11320 'F137','F54',
11321 'F138','F55',
11322 'F140','F36',
11323 'F141','F56',
11324 'F142','F36',
11325 'F143','F53',
11326 'F144','F36',
11327 'F145','F36',
11328 'F146','F36',
11329 'F160','F36',
11330 'F161','F36',
11331 'F162','F36',
11332 'F163','F36',
11333 'F164','F36',
11334 'F165','F39',
11335 'F166','F38', -- added during CC import testing 2891273
11336 -- added decodes for stamping advisory warnings bug :1975786
11337 'P101',decode(pbc.res_result_code,'P112','P35',
11338 decode(pbc.res_grp_result_code,'P110','P36',
11339 decode(pbc.task_result_code,'P108','P37',
11340 decode(pbc.top_task_result_code,'P106','P38',
11341 decode(pbc.project_result_code,'P104','P31',
11342 decode(pbc.project_acct_result_code,'P102','P29',
11343 'P28')))))),
11344 'P102',decode(pbc.res_result_code,'P112','P35',
11345 decode(pbc.res_grp_result_code,'P110','P36',
11346 decode(pbc.task_result_code,'P108','P37',
11347 decode(pbc.top_task_result_code,'P106','P38',
11348 decode(pbc.project_result_code,'P104','P31',
11349 decode(pbc.project_acct_result_code,'P102','P29',
11350 'P29')))))),
11351 'P103',decode(pbc.res_result_code,'P112','P35',
11352 decode(pbc.res_grp_result_code,'P110','P36',
11353 decode(pbc.task_result_code,'P108','P37',
11354 decode(pbc.top_task_result_code,'P106','P38',
11355 decode(pbc.project_result_code,'P104','P31',
11356 decode(pbc.project_acct_result_code,'P102','P29',
11357 'P30')))))),
11358 'P104',decode(pbc.res_result_code,'P112','P35',
11359 decode(pbc.res_grp_result_code,'P110','P36',
11360 decode(pbc.task_result_code,'P108','P37',
11361 decode(pbc.top_task_result_code,'P106','P38',
11362 decode(pbc.project_result_code,'P104','P31',
11363 decode(pbc.project_acct_result_code,'P102','P29',
11364 'P31')))))),
11365 'P105',decode(pbc.res_result_code,'P112','P35',
11366 decode(pbc.res_grp_result_code,'P110','P36',
11367 decode(pbc.task_result_code,'P108','P37',
11368 decode(pbc.top_task_result_code,'P106','P38',
11369 decode(pbc.project_result_code,'P104','P31',
11370 decode(pbc.project_acct_result_code,'P102','P29',
11371 'P30')))))),
11372 'P106',decode(pbc.res_result_code,'P112','P35',
11373 decode(pbc.res_grp_result_code,'P110','P36',
11374 decode(pbc.task_result_code,'P108','P37',
11375 decode(pbc.top_task_result_code,'P106','P38',
11376 decode(pbc.project_result_code,'P104','P31',
11377 decode(pbc.project_acct_result_code,'P102','P29',
11378 'P38')))))),
11379 'P107',decode(pbc.res_result_code,'P112','P35',
11380 decode(pbc.res_grp_result_code,'P110','P36',
11381 decode(pbc.task_result_code,'P108','P37',
11382 decode(pbc.top_task_result_code,'P106','P38',
11383 decode(pbc.project_result_code,'P104','P31',
11384 decode(pbc.project_acct_result_code,'P102','P29',
11385 'P30')))))),
11386 'P108',decode(pbc.res_result_code,'P112','P35',
11387 decode(pbc.res_grp_result_code,'P110','P36',
11388 decode(pbc.task_result_code,'P108','P37',
11389 decode(pbc.top_task_result_code,'P106','P38',
11390 decode(pbc.project_result_code,'P104','P31',
11391 decode(pbc.project_acct_result_code,'P102','P29',
11392 'P37')))))),
11393 'P109',decode(pbc.res_result_code,'P112','P35',
11394 decode(pbc.res_grp_result_code,'P110','P36',
11395 decode(pbc.task_result_code,'P108','P37',
11396 decode(pbc.top_task_result_code,'P106','P38',
11397 decode(pbc.project_result_code,'P104','P31',
11398 decode(pbc.project_acct_result_code,'P102','P29',
11399 'P30')))))),
11400 'P110',decode(pbc.res_result_code,'P112','P35',
11401 decode(pbc.res_grp_result_code,'P110','P36',
11402 decode(pbc.task_result_code,'P108','P37',
11403 decode(pbc.top_task_result_code,'P106','P38',
11404 decode(pbc.project_result_code,'P104','P31',
11405 decode(pbc.project_acct_result_code,'P102','P29',
11406 'P36')))))),
11407 'P111',decode(pbc.res_result_code,'P112','P35',
11408 decode(pbc.res_grp_result_code,'P110','P36',
11409 decode(pbc.task_result_code,'P108','P37',
11410 decode(pbc.top_task_result_code,'P106','P38',
11411 decode(pbc.project_result_code,'P104','P31',
11412 decode(pbc.project_acct_result_code,'P102','P29',
11413 'P30')))))),
11414 'P112',decode(pbc.res_result_code,'P112','P35',
11415 decode(pbc.res_grp_result_code,'P110','P36',
11416 decode(pbc.task_result_code,'P108','P37',
11417 decode(pbc.top_task_result_code,'P106','P38',
11418 decode(pbc.project_result_code,'P104','P31',
11419 decode(pbc.project_acct_result_code,'P102','P29',
11420 'P35')))))),
11421 'P113','P32',
11422 'P114','P33',
11423 'P115','P34',
11424 'P116','P05',
11425 'F150','F58',
11426 'F151','F58',
11427 'F155','F58',
11428 'F156','F58',
11429 'F152','F57',
11430 'F153','F57',
11431 'F157','F57',
11432 'F158','F57', igc.cbc_result_code )
11433 , igc.cbc_result_code))
11434 from pa_bc_packets pbc
11435 where pbc.packet_id = p_packet_id
11436 and (pbc.gl_row_number = igc.rowid
11437 or
11438 ( substr(igc.reference_9,length('BC_PKT_ID:')+1) in
11439 ( pbc.bc_packet_id)
11440 )
11441 )
11442 )
11443 WHERE igc.rowid in (SELECT pkt.gl_row_number
11444 FROM pa_bc_packets pkt
11445 WHERE pkt.packet_id = p_packet_id
11446 AND pkt.gl_row_number = igc.rowid
11447 )
11448 OR
11449 ( substr(igc.reference_9,length('BC_PKT_ID:')+1) in
11450 ( SELECT pbc.bc_packet_id
11451 FROM pa_bc_packets pbc
11452 WHERE pbc.packet_id = substr(reference_8,length('PKT_ID:')+1)
11453 AND pbc.bc_packet_id = substr(reference_9,length('BC_PKT_ID:')+1)
11454 )
11455 );
11456
11457
11458 IF p_calling_module in('CBC','CBC_TIEBACK') then
11459
11460 /** the calling module CBC_TIEBACK is used to update the
11461 * status code in igc_cc_interface table if pa pass and
11462 * cbc fc fails, if pa fails then cbc doesnot call tie back
11463 * since payment forcast lines are not funds checked we
11464 * should not update the status code of payment forcast line
11465 */
11466
11467 open igc_status(p_reference2,p_reference1);
11468 fetch igc_status into l_igc_status;
11469 close igc_status;
11470
11471 UPDATE igc_cc_interface igc
11472 SET igc.cbc_result_code = decode(substr(cbc_result_code,1,1),'P',
11473 decode(sign(nvl(igc.cc_func_dr_amt,0)
11474 - nvl(igc.cc_func_cr_amt,0)),
11475 -1, 'P32',
11476 -- --1,'P28', commented for bug :1975786
11477 cbc_result_code),cbc_result_code),
11478 igc.status_code = decode(nvl(l_pkt_fatal_error_flag,'N'),'Y','T',
11479 decode(p_partial_flag
11480 ,'Y', decode(substr(nvl(igc.cbc_result_code,'P'),1,1) ,
11481 'P',igc.status_code,
11482 'F',decode(p_mode,'C','F','R'),
11483 'X',decode(p_mode,'C','F','R'),
11484 igc.status_code)
11485 ,'N',decode(p_packet_status,
11486 'S',decode(l_igc_status,'P', decode(p_mode,'C','S','A'),
11487 'F', decode(p_mode,'C','F','R')),
11488 'F',decode(p_mode,'C','F','R'),
11489 'T',decode(p_mode,'C','F','R'),'R')))
11490 WHERE ((p_calling_module = 'CBC_TIEBACK'
11491 and igc.cc_header_id = p_reference2)
11492 OR
11493 ( p_calling_module = 'CBC' and
11494 (igc.cc_header_id,igc.cc_acct_line_id) in
11495 (SELECT pkt.document_header_id,pkt.document_distribution_id
11496 FROM pa_bc_packets pkt
11497 WHERE pkt.packet_id = p_packet_id
11498 AND pkt.document_header_id = igc.cc_header_id
11499 AND pkt.document_distribution_id = igc.cc_acct_line_id
11500 AND pkt.document_type in ('CC_C_CO','CC_P_CO')
11501 )));
11502
11503
11504 END IF;
11505 If g_debug_mode = 'Y' Then
11506 log_message(p_msg_token1 =>'no of rows updated = '||sql%rowcount);
11507 End if;
11508
11509 END IF;
11510
11511 END IF;
11512 If gl_status%isopen then
11513 close gl_status;
11514 End if;
11515 If igc_status%isopen then
11516 close igc_status;
11517 End if;
11518 If pkt_status%isopen then
11519 close pkt_status;
11520 End if;
11521
11522 -- reset the error stack
11523 PA_DEBUG.reset_err_stack;
11524
11525 Return;
11526
11527 EXCEPTION
11528 WHEN OTHERS THEN
11529 If gl_status%isopen then
11530 close gl_status;
11531 End if;
11532 If igc_status%isopen then
11533 close igc_status;
11534 End if;
11535 If pkt_status%isopen then
11536 close pkt_status;
11537 End if;
11538 --log_message(p_return_status => 'T');
11539 g_return_status := 'T';
11540 x_return_status := 'T';
11541 If g_debug_mode = 'Y' Then
11542 log_message(p_msg_token1 => 'failed in update gl cbc result code apiSQLERR :'||sqlcode||sqlerrm);
11543 End if;
11544 Raise;
11545 END update_GL_CBC_result_code;
11546 ---------------------------------------------------------------------
11547 -- This APi checks whether the project is under base line process
11548 -- if so updates the bc packets with rejection status and returns
11549 ---------------------------------------------------------------------
11550 FUNCTION is_project_baseline
11551 (p_calling_module IN varchar2,
11552 p_packet_id IN number) RETURN BOOLEAN is
11553 PRAGMA AUTONOMOUS_TRANSACTION;
11554 l_status_flag BOOLEAN := true;
11555 l_num_rows NUMBER := 100;
11556 l_lck_number NUMBER;
11557 l_bdgt_type varchar2(30);
11558 l_yr_end_rollover_flag varchar2(10);
11559 l_pre_project_id pa_bc_packets.project_id%type := NULL;
11560 CURSOR cur_projects IS
11561 SELECT project_id
11562 FROM pa_bc_packets
11563 WHERE packet_id = p_packet_id;
11564
11565 BEGIN
11566 /* Intialize the default values for flag variables */
11567 l_yr_end_rollover_flag := 'N';
11568 l_status_flag := true;
11569
11570 IF p_calling_module not in ( 'RESERVE_BASELINE') then
11571
11572 OPEN cur_projects;
11573 LOOP
11574 g_tab_project_id.delete;
11575 If NOT l_status_flag then
11576 EXIT;
11577 END IF;
11578 FETCH cur_projects BULK COLLECT INTO
11579 g_tab_project_id LIMIT l_num_rows;
11580 If NOT g_tab_project_id.EXISTS(1) then
11581 EXIT;
11582 End if;
11583 FOR i IN g_tab_project_id.FIRST .. g_tab_project_id.LAST LOOP
11584 IF l_pre_project_id is NULL or
11585 l_pre_project_id <> g_tab_project_id(i) then
11586
11587 /** Added the Phase II changes Yr end rollover **/
11588 If p_calling_module = 'CBC' then
11589 l_bdgt_type := 'CBC';
11590 Else
11591 l_bdgt_type := 'STD';
11592 End if;
11593 l_yr_end_rollover_flag := PA_FUNDS_CONTROL_UTILS.
11594 get_fnd_reqd_flag(g_tab_project_id(i),
11595 l_bdgt_type);
11596 IF l_yr_end_rollover_flag = 'R' then
11597 /** Year End Rollover process is in progress
11598 * so mark the transaction as failes
11599 */
11600 l_status_flag := FALSE;
11601 If g_debug_mode = 'Y' Then
11602 log_message(p_msg_token1 => 'Yr End Rollover is in progress');
11603 End if;
11604 EXIT;
11605 END IF;
11606
11607 IF (pa_debug.acquire_user_lock('BSLNFCHKLOCK:'||
11608 g_tab_project_id(i))) = 0 then
11609 -- if the lock is acquired for project
11610 -- indicates the budget is not under baseline
11611 -- for this project so release the lock
11612 IF (pa_debug.release_user_lock('BSLNFCHKLOCK:'||
11613 g_tab_project_id(i))) = 0 then
11614 null;
11615 END IF;
11616
11617 ELSE -- this project is under baseline lock
11618 l_status_flag := FALSE;
11619 If g_debug_mode = 'Y' Then
11620 log_message(p_msg_token1 => 'Budget Baseline is under progress');
11621 End if;
11622 EXIT;
11623 END IF;
11624 END IF;
11625 l_pre_project_id := g_tab_project_id(i);
11626
11627 END LOOP;
11628
11629 EXIT when cur_projects%NOTFOUND;
11630
11631 END LOOP;
11632 CLOSE cur_projects;
11633
11634 IF l_status_flag = FALSE and l_yr_end_rollover_flag = 'N' then
11635 -- Error F143 = 'Funds check failed as Budget Baseline is under progress'
11636 result_status_code_update(
11637 p_status_code => 'R',
11638 p_result_code => 'F143',
11639 p_res_result_code => 'F143',
11640 p_res_grp_result_code => 'F143',
11641 p_task_result_code => 'F143',
11642 p_top_task_result_code => 'F143',
11643 p_project_result_code => 'F143',
11644 p_proj_acct_result_code => 'F143',
11645 p_packet_id => p_packet_id);
11646
11647 Elsif l_status_flag = FALSE and l_yr_end_rollover_flag = 'R' then
11648 -- Error F119 = 'Failed due to Year end rollover process is in progress'
11649 result_status_code_update(
11650 p_status_code => 'R',
11651 p_result_code => 'F119',
11652 p_res_result_code => 'F119',
11653 p_res_grp_result_code => 'F119',
11654 p_task_result_code => 'F119',
11655 p_top_task_result_code => 'F119',
11656 p_project_result_code => 'F119',
11657 p_proj_acct_result_code => 'F119',
11658 p_packet_id => p_packet_id);
11659 End IF;
11660 END IF;
11661 If cur_projects%isopen then
11662 close cur_projects;
11663 End if;
11664 COMMIT ; -- to end an active autonomous transaction
11665 REturn l_status_flag;
11666
11667 EXCEPTION
11668 WHEN OTHERS THEN
11669 If cur_projects%isopen then
11670 close cur_projects;
11671 End if;
11672 l_lck_number := pa_debug.release_user_lock('BSLNFCHKLOCK:'|| l_pre_project_id);
11673 result_status_code_update
11674 (p_status_code => 'T',
11675 p_packet_id => p_packet_id);
11676 If g_debug_mode = 'Y' Then
11677 log_message(p_msg_token1 => 'failed in is_project_baseline apSQLERR :'||sqlcode||sqlerrm);
11678 End if;
11679 --commit;
11680 Raise;
11681
11682
11683 END is_project_baseline;
11684 /*****************************************************************************************************
11685 *This is the Main funds check function which calls all the other functions and procedures.
11686 *This API is called from the following places
11687 * GL - Funds check process
11688 * CBC - Funds check process
11689 * Costing - During Expenditure Cost Distribution process
11690 * Transaction Import Process
11691 * Baseline of Budget
11692 *
11693 * Parameters :
11694 * p_set_of_books_id : Set of Books ID in GL accounts for the packet to funds checked.
11695 * p_calling_module : Identifier of the module from which the funds checker will be invoked
11696 * The valid values are
11697 * GL - General ledger
11698 * CBC - Contract Conmmitment
11699 *- CHECK_BASELINE - Budget Baselining (from r12 .. no such mode)
11700 *- RESERVE_BASELINE - for delta protion ( conccurance issue)
11701 * TRXIMPORT - Transaction Import
11702 * DISTVIADJ - Invoice Adjustments
11703 * DISTERADJ - Expense Report Adjustments
11704 * INTERFACVI - Interface VI to payables
11705 * INTERFACER - Interface ER to payables
11706 * EXPENDITURE - For actuals entering through Projects
11707 * DISTCWKST -- for Distribute labor process for cwk transactions only
11708 * DISTBTC -- create and distribute burden process (burden recompile process)
11709 *
11710 * P_packet_id : Packet ID of the packet to be funds checked.
11711 * P_mode : Funds Checker Operation Mode.
11712 * C - Check funds
11713 * R - Reserve funds.
11714 * U - Un-reserve (only for REQ,PO and AP)
11715 * B - Called from budget baseline process (Processed like check funds)
11716 * S - Called from Budget submission (Processed like check funds)
11717 * (From r12 on - not used)
11718 * A - Adjustment same as Reserve funds (called from PO,REQ)
11719 * F - Force Pass mode (called from Contract Commitments)
11720 * P_partial_flag : Indicates the packet can be fundschecked/reserverd partially or not
11721 * Y - Partial
11722 * N - Full mode, default is N
11723 * P_reference1 If the p_mode is 'R',U,C,F' and p_calling_module = 'CBC'or 'EXP' then
11724 * this parameter holds the document type info Document Type
11725 * EXP - Expenditures originating from project
11726 * CC - Contract Commitments
11727 * Elsif p_mode is B, S and p_calling_module = 'BASELINE' then
11728 * this parameter holds the ext_bdgt_link_flag
11729 * End if;
11730 * * This param is not null for EXP , CC document type and Base line mode
11731 * P_reference2 If the p_mode is 'R',U,C,F' and p_calling_module = 'CBC' then
11732 * this parameter holds the document header info for Contract Commitment
11733 * document Header Id from Contract Commitments
11734 * IGC_CC_INTERFACE.CC_HEADER_ID
11735 * Elsif p_mode is B, S and p_calling_module = 'BASELINE' then
11736 * this parameter holds the project_id
11737 * End if;
11738 * * This param is not null for CC document type and Base line mode
11739 * P_reference3 If p_mode is B, S and p_calling_module = 'BASELINE' then
11740 * this parameter holds the budget_version_id
11741 * End if;
11742 * * This param is not null for Base line mode and Contract commitments
11743 *
11744 * p_conc_flag : identifies when funds check is invoked from concurrent program.
11745 * The valid values are
11746 * 'N' default
11747 * 'Y' - concurrent programm
11748 *
11749 * x_return_status : Fudscheck return status
11750 * Valid Status are
11751 * S - Success
11752 * F - Failure
11753 * T - Fatal
11754 * x_error_stage :Identifies the place where funds check process failed
11755 *
11756 * x_error_messagee :defines the type of error : SQLerror||sqlcode
11757 *
11758 *
11759 *NOTE : p_packet_id will be null for Contract commitments so the packet id to be generated
11760 * if the p_calling_module is 'CBC'.
11761 * if the p_calling_module is TRXIMPORT then set_of_books_id to be generated
11762 ****************************************************************************************************************/
11763 FUNCTION pa_funds_check
11764 (p_calling_module IN VARCHAR2
11765 ,p_conc_flag IN VARCHAR2 DEFAULT 'N'
11766 ,p_set_of_book_id IN NUMBER
11767 ,p_packet_id IN NUMBER
11768 ,p_mode IN VARCHAR2 DEFAULT 'C'
11769 ,p_partial_flag IN VARCHAR2 DEFAULT 'N'
11770 ,p_reference1 IN VARCHAR2 DEFAULT NULL
11771 ,p_reference2 IN VARCHAR2 DEFAULT NULL
11772 ,p_reference3 IN VARCHAR2 DEFAULT NULL
11773 ,x_return_status OUT NOCOPY VARCHAR2
11774 ,x_error_msg OUT NOCOPY VARCHAR2
11775 ,x_error_stage OUT NOCOPY VARCHAR2
11776 ) RETURN BOOLEAN IS
11777
11778
11779 x_e_code VARCHAR2(10);
11780 x_e_stage VARCHAR2(2000);
11781
11782 CURSOR cur_packets IS
11783 SELECT gl_bc_packets_s.nextval
11784 FROM dual;
11785
11786 CURSOR cur_sob(v_packet_id number) IS
11787 SELECT set_of_books_id
11788 FROM pa_bc_packets
11789 WHERE packet_id = v_packet_id;
11790
11791 l_arrival_seq NUMBER;
11792 l_packet_id pa_bc_packets.packet_id%type;
11793 l_set_of_books_id pa_bc_packets.set_of_books_id%type;
11794 l_err_code NUMBER := 0;
11795 l_err_buff VARCHAR2 ( 2000 ) := NULL;
11796 l_return_code VARCHAR2 ( 1 );
11797 l_result_code VARCHAR2 ( 1 ) := 'P';
11798 l_status VARCHAR2 ( 1 );
11799 l_doc_type VARCHAR2(30);
11800 l_return_status VARCHAR2(30);
11801 l_packet_status VARCHAR2(30);
11802 l_error_stage VARCHAR2(20);
11803 l_err_msg_code VARCHAR2(30);
11804 l_E_CODE NUMBER;
11805 l_num_rows number;
11806 l_mode varchar2(10);
11807 l_debug_mode varchar2(10);
11808 l_calling_code varchar2(10);
11809
11810 l_fc_final_exit_flag VARCHAR2(100) := 'NORMAL_EXIT';
11811
11812 x_resource_list_member_id number;
11813 x_resource_id number;
11814 -------------------------------------------------------------------------------------------------------
11815 -- This is local procedure used as lock mechanism After inserting Commit to release the lock
11816 -- When a lock on pa_concurrency_control is not available if Funds Checker is invoked from a
11817 -- Concurrent Process, it waits if Funds Checker is invoked from an Online Process,
11818 -- it exits with an error
11819 --------------------------------------------------------------------------------------------------------------
11820 BEGIN
11821
11822 --- Initialize the error statck
11823 PA_DEBUG.init_err_stack ('PA_FUNDS_CONTROL_PKG.pa_funds_check');
11824
11825 fnd_profile.get('PA_DEBUG_MODE',g_debug_mode);
11826 g_debug_mode := NVL(g_debug_mode, 'N');
11827
11828 PA_DEBUG.SET_PROCESS( x_process => 'PLSQL'
11829 ,x_write_file => 'LOG'
11830 ,x_debug_mode => g_debug_mode
11831 );
11832 If g_debug_mode = 'Y' then
11833 log_message(p_msg_token1 => 'Start Of project Funds check Calling module['
11834 || p_calling_module||']calling mode['||p_mode||']reference1['
11835 ||p_reference1||']reference2['||p_reference2||']partial flag['
11836 ||p_partial_flag||']conc flag['||p_conc_flag||']packet_id['
11837 ||p_packet_id||']' );
11838 End if;
11839
11840 /** Bug fix :2302945 If PA is NOT installed in OU then we should return as success
11841 ** without proceeding further . This api checks whether the In given operating unit
11842 ** project is installed or not, if not installed return with success
11843 **/
11844 IF IS_PA_INSTALL_IN_OU = 'N' then
11845 x_return_status := 'S';
11846 g_return_status := 'S';
11847 If g_debug_mode = 'Y' then
11848 log_message(p_msg_token1=>'PA NOT INSTALLED IN THIS OU.return status='||
11849 x_return_status);
11850 End if;
11851 PA_DEBUG.Reset_err_stack;
11852 Return True;
11853 END IF;
11854 /** End of Bug fix **/
11855
11856 -------->6599207 ------As part of CC Enhancements
11857 /* COMMENTING THIS CODE FOR CC ENHANCEMENTS
11858 ------------------------------------------------------------------------------------------+
11859 ----For CBC following procedure creates pa_bc_packet from ICG_CC_INTERFACE for Fundscheck.
11860 ----If the calling mode is Reserve, unreserve , Force pass and check then copy
11861 ----all the ICG_CC_INTERFACE to pa_bc_packets
11862 ------------------------------------------------------------------------------------------+
11863
11864 --IF l_mode IN ( 'R','C','F' ) AND p_calling_module = 'CBC' THEN
11865 IF p_calling_module = 'CBC' THEN
11866
11867 -- ------------------------------------------------------------------------------------------+
11868 -- :( AS CBC IS NOT SUPPORTED, IF CBC CALLS PA, RETURN 'T' BACK TO CALLING PGM ..
11869 -- ------------------------------------------------------------------------------------------+
11870
11871 If g_debug_mode = 'Y' then
11872 log_message(p_stage => 10,p_msg_token1 => 'For CBC calling copy_gl_pkt_to_pa_pkt in mode ='||l_mode);
11873 end if;
11874
11875 -- PA_FUNDS_CONTROL_PKG1.copy_gl_pkt_to_pa_pkt
11876 -- (p_packet_id => l_packet_id
11877 -- ,p_calling_module => p_calling_module
11878 -- ,p_return_code => l_return_status
11879 -- ,p_reference1 => p_reference1
11880 -- ,p_reference2 => p_reference2);
11881
11882 --IF l_return_status <> 'S' then
11883 If g_debug_mode = 'Y' then
11884 log_message (p_msg_token1 => 'Error while create records in pa_bc_packets');
11885 end if;
11886 g_return_status := 'T';
11887 x_return_status := g_return_status;
11888 l_fc_final_exit_flag := 'NORMAL_ERROR';
11889 GOTO END_PROCESS;
11890 --END IF;
11891 --If g_debug_mode = 'Y' then
11892 -- log_message(p_msg_token1 => 'Populating records in pa_bc_packets is successful');
11893 --end if;
11894 END IF;
11895 */
11896 -------->6599207 ------END
11897
11898 -- -----------------------------------------------------------------------------------+
11899 -- This procedure will synch packet_id, serial_id, session_id, actual_flag,status_code
11900 -- from gl_bc_packets to pa_bc_packets ..
11901 -- Synch up only required for Commitment Funds check ..
11902 -- -----------------------------------------------------------------------------------+
11903
11904 If p_calling_module not in
11905 ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ','TRXIMPORT','RESERVE_BASELINE','CDL') then
11906
11907 SYNCH_PA_GL_PACKETS(x_packet_id => p_packet_id,
11908 x_partial_flag => p_partial_flag,
11909 x_mode => p_mode,
11910 x_result_code => x_return_status);
11911
11912 If nvl(x_return_status,'S') = 'F' then -- Bug 5557520
11913
11914 If g_debug_mode = 'Y' then
11915 log_message(p_msg_token1 => 'Synch_pa_gl_packets failed .. extracts failed .. full mode');
11916 End If;
11917
11918 l_fc_final_exit_flag := 'NORMAL_ERROR';
11919 g_return_status := 'F';
11920 GOTO END_PROCESS;
11921
11922 End If;
11923
11924 End If;
11925
11926 -------->6599207 ------As part of CC Enhancements
11927 If p_calling_module <> 'CBC' Then
11928
11929 -- -----------------------------------------------------------------------------------+
11930 -- Check if PA FC called for project related txn. or budget or its called for non-FC
11931 -- NO_FC: non-project related FC, exit with 'S' status
11932 -- BUD_FC: BC FC called projects (SLA-BC Integration for budget baseline) - exit with
11933 -- 'S' status
11934 -- TXN_FC: PA FC called for txn. or budget baseline 'RESERVE_BASELINE' mode - existing
11935 -- -----------------------------------------------------------------------------------+
11936 CHECK_TXN_OR_BUDGET_FC (p_packet_id,l_calling_code);
11937
11938 If g_debug_mode = 'Y' then
11939 log_message(p_msg_token1=>'FC called mode:'||l_calling_code);
11940 End If;
11941
11942
11943 If l_calling_code in ('NO_FC','BUD_FC') THEN -- II
11944
11945 x_return_status := 'S';
11946 g_return_status := 'S';
11947
11948 If g_debug_mode = 'Y' then
11949 If l_calling_code = 'NO_FC' then
11950 log_message(p_msg_token1=>'PA FC called for non-project transactions');
11951 Else
11952 log_message(p_msg_token1=>'PA FC called by BC FC API during budget funds check by GL');
11953 End If;
11954
11955 End If;
11956
11957 PA_DEBUG.Reset_err_stack;
11958 Return TRUE;
11959
11960 End If; -- II
11961
11962 -- -----------------------------------------------------------------------------------+
11963 End If;
11964 -------->6599207 ------END
11965
11966
11967 l_fc_final_exit_flag := 'NORMAL_EXIT';
11968 -- Assign the In params to Global varialbes
11969 g_mode := p_mode;
11970 g_calling_module := p_calling_module;
11971 g_partial_flag := p_partial_flag;
11972 g_packet_id := p_packet_id;
11973 l_mode := p_mode;
11974
11975 If l_mode = 'A' then -- Adjustments same as Reserve funds
11976 l_mode := 'R';
11977 End if;
11978 g_mode := l_mode;
11979
11980 If g_debug_mode = 'Y' then
11981 log_message(p_msg_token1 => 'initialize l_fc_final_exit_flag = '||l_fc_final_exit_flag);
11982 End if;
11983
11984 -- Initialize the Out variable with success
11985 x_return_status := 'S';
11986 g_return_status := 'S';
11987
11988
11989 --Initialize the funds control util package global variables
11990 PA_FUNDS_CONTROL_UTILS.init_util_variables;
11991
11992 --Inialize the the local global variables
11993 Initialize_globals;
11994
11995 -- generete packet id if the calling module is contract commitments
11996 -- and store it in the global variable, use the glboal variable in
11997 -- tie back api for status confirmation for CBC.
11998 If p_calling_module = 'CBC' and l_mode not in('U') then
11999 OPEN cur_packets;
12000 FETCH cur_packets INTO l_packet_id;
12001 CLOSE cur_packets;
12002 g_cbc_packet_id := l_packet_id;
12003 g_packet_id := l_packet_id;
12004 Else
12005 If g_debug_mode = 'Y' then
12006 log_message(p_msg_token1 => ' assiging the packet id to global variable p_packet_id = '
12007 ||p_packet_id);
12008 End if;
12009 l_packet_id := p_packet_id;
12010 g_packet_id := l_packet_id;
12011 End If;
12012
12013 -- get the set of books id from the pa bc packets for the given packet id
12014 If p_calling_module in ('TRXIMPORT', 'TRXNIMPORT') then
12015 OPEN cur_sob(l_packet_id);
12016 FETCH cur_sob INTO l_set_of_books_id;
12017 CLOSE cur_sob;
12018
12019 Else
12020 l_set_of_books_id := p_set_of_book_id;
12021 END IF;
12022 If g_debug_mode = 'Y' then
12023 log_message(p_msg_token1 => ' the value of l_packet_id ='||l_packet_id||' - g packet_id ='||g_packet_id);
12024 End if;
12025
12026 -- if the calling mode is unreserved then copy all the rows into
12027 -- unreserved packet update the status and return, in tie back process
12028 -- update the budget_acct_balances
12029 If l_mode in ('U') and p_calling_module in ('GL','CBC') then
12030 If g_debug_mode = 'Y' then
12031 log_message(p_msg_token1 => ' calling create_unrsvd_lines api');
12032 end if;
12033 If NOT PA_FUNDS_CONTROL_PKG1.create_unrsvd_lines
12034 ( x_packet_id => l_packet_id
12035 ,p_mode => l_mode
12036 ,p_calling_module => p_calling_module
12037 ,p_reference1 => p_reference1
12038 ,p_reference2 => p_reference2
12039 ) then
12040 If g_debug_mode = 'Y' then
12041 log_message(p_msg_token1 => 'Failed to create unreserved packet lines');
12042 end if;
12043 g_return_status := 'F';
12044 --log_message(p_return_status => 'F');
12045 x_return_status := g_return_status;
12046 l_fc_final_exit_flag := 'NORMAL_ERROR';
12047 If g_debug_mode = 'Y' then
12048 log_message(p_msg_token1 => 'Return status :'||x_return_status);
12049 end if;
12050 pa_debug.reset_err_stack;
12051 return FALSE;
12052
12053 End if;
12054 g_packet_id := l_packet_id;
12055
12056 --generate return code for the packet and return
12057 If g_debug_mode = 'Y' then
12058 log_message(p_msg_token1 => 'Calling gen_return_code API');
12059 end if;
12060 gen_return_code(p_packet_id => l_packet_id
12061 ,p_partial_flag => p_partial_flag
12062 ,p_calling_mode => p_calling_module
12063 ,x_return_status => l_packet_status);
12064
12065 -- if the pa_funds check fails then in tie back process
12066 -- just return with out proceeding further else check
12067 -- the return status of gl and cbc update the status code
12068 -- of packets
12069 If p_calling_module = 'GL' then
12070 g_pa_gl_return_status := l_packet_status;
12071 Elsif p_calling_module = 'CBC' then
12072 g_pa_cbc_return_status := l_packet_status;
12073 End if;
12074 g_return_status := l_packet_status;
12075 If g_debug_mode = 'Y' then
12076 log_message(p_msg_token1 => 'The return code of the FC process :'||l_packet_status);
12077 end if;
12078 --log_message(p_return_status => l_packet_status);
12079
12080 x_return_status := l_packet_status;
12081 If g_debug_mode = 'Y' then
12082 log_message(p_msg_token1 => 'Return status :'||x_return_status);
12083 end if;
12084 pa_debug.reset_err_stack;
12085 return true;
12086
12087 End IF; -- end of Unreserve mode
12088
12089 -------->6599207 ------As part of CC Enhancements
12090 IF l_mode IN ( 'R','C','F' ) THEN
12091 If g_debug_mode = 'Y' then
12092 log_message(p_stage => 10,p_msg_token1 => 'inside the if condition mode ='||l_mode);
12093 end if;
12094
12095
12096 IF p_calling_module ='CBC' then
12097 If g_debug_mode = 'Y' then
12098 log_message(p_msg_token1 => 'calling populate plsql tabs api');
12099 end if;
12100
12101 PA_FUNDS_CONTROL_PKG1.populate_plsql_tabs_CBC
12102 (p_packet_id => l_packet_id
12103 ,p_calling_module => p_calling_module
12104 ,p_reference1 => p_reference1
12105 ,p_reference2 => p_reference2
12106 ,p_mode => l_mode);
12107
12108 End if;
12109 If g_debug_mode = 'Y' then
12110 log_message(p_msg_token1 => 'End of create_bc_pkt_lines api');
12111 end if;
12112 END IF;
12113 -------->6599207 ------END
12114
12115
12116 ------------------------------------------------------------------------
12117 -- check whether the budget baseline is going on if so return and
12118 -- update the result code in pa bc packets with error code
12119 ------------------------------------------------------------------------
12120 If g_debug_mode = 'Y' then
12121 log_message( p_stage => 30, p_msg_token1 => 'Check whether the project is under Baseline process');
12122 end if;
12123 IF NOT is_project_baseline
12124 (p_calling_module => p_calling_module,
12125 p_packet_id => l_packet_id ) then
12126 If g_debug_mode = 'Y' then
12127 log_message( p_msg_token1 => 'BASELINE / YEAR END ROLLOVER is Under progress');
12128 end if;
12129 --log_message(p_return_status => 'F');
12130 g_return_status := 'F';
12131 x_return_status := g_return_status;
12132 l_fc_final_exit_flag := 'NORMAL_ERROR';
12133 GOTO END_PROCESS;
12134 END IF;
12135 -------------------------------------------------------------------------------------------------------
12136 --- Check if the mode is in B,S,R,U,C,F then Insert Arrival Sequence for the Packet.
12137 -- The Row Share Lock ensures that packets are assigned sequences strictly in order of arrival
12138 ------------------------------------------------------------------------------------------------------
12139 IF l_mode IN ( 'B', 'S','R','C','F' ) THEN
12140 If g_debug_mode = 'Y' then
12141 log_message(p_stage => 40,p_msg_token1 => 'Calling get_arrival_seq API');
12142 end if;
12143
12144
12145 l_arrival_seq := get_arrival_seq
12146 (p_calling_module => p_calling_module
12147 ,p_packet_id => l_packet_id
12148 ,p_sobid => l_set_of_books_id
12149 ,p_mode => l_mode
12150 );
12151
12152 IF l_arrival_seq = 0 then
12153 log_message(p_error_msg => 'F141');
12154 If g_debug_mode = 'Y' then
12155 log_message(p_msg_token1 => 'Failed to acquire lock');
12156 end if;
12157 l_fc_final_exit_flag := 'NORMAL_ERROR';
12158 GOTO END_PROCESS;
12159 End IF;
12160 If g_debug_mode = 'Y' then
12161 log_message(p_msg_token1 => 'End of get_arrival_seq API');
12162 end if;
12163
12164 END IF;
12165
12166 If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ','TRXIMPORT') then
12167
12168 -- Note: For commitment Funds check, populate_burden_cost is called in pa_funds_control_pkg1
12169 -- R12: BC-SLA Integration ..
12170
12171 -----------------------------------------------------------------------------------------------------
12172 -- Populate the Burden cost for each record in packet if project type is of burden on same EI
12173 -- otherwise create separate bc packet lines if the project type is of burden as separate EI
12174 --Lock the arrival order sequence table
12175 ------------------------------------------------------------------------------------------------------
12176 --IF l_mode IN ( 'R', 'C','F' ) and p_calling_module not in ( 'RESERVE_BASELINE') THEN
12177 If g_debug_mode = 'Y' then
12178 log_message(p_stage => 50,p_msg_token1 => p_calling_module||':Calling Populate_burden_cost API');
12179 end if;
12180
12181 PA_FUNDS_CONTROL_PKG1.Populate_burden_cost
12182 (p_packet_id => l_packet_id
12183 ,p_calling_module => p_calling_module
12184 ,x_return_status => l_return_status
12185 ,x_err_msg_code => l_err_msg_code);
12186
12187 IF l_return_status <> 'S' then
12188 If g_debug_mode = 'Y' then
12189 log_message (p_msg_token1 => 'Error while populating Burden Cost for');
12190 end if;
12191 --log_message(p_return_status => 'T');
12192 g_return_status := 'T';
12193 x_return_status := g_return_status;
12194 l_fc_final_exit_flag := 'NORMAL_ERROR';
12195 GOTO END_PROCESS;
12196 END IF;
12197 If g_debug_mode = 'Y' then
12198 log_message(p_msg_token1 => 'Populating burden cost is successful');
12199 end if;
12200 --END IF;
12201
12202 End if; -- If p_calling_module in ('DISTBTC','DISTERADJ','CBC','EXPENDITURE','DISTCWKST','DISTVIADJ'
12203
12204 -------------------------------------------------------------------------------------------
12205 -- This Api setup the required funds check parameters such as resource list member id,
12206 -- funds control level code, budget resource list id, budget task id etc.
12207 -------------------------------------------------------------------------------------------
12208 If g_debug_mode = 'Y' then
12209 log_message(p_stage => 60,p_msg_token1 => 'Calling funds_check_setup API');
12210 end if;
12211 If l_mode not in ('U') then
12212 IF NOT funds_check_setup
12213 (p_packet_id => l_packet_id
12214 ,p_mode => l_mode
12215 ,p_sob => l_set_of_books_id
12216 ,p_reference1 => p_reference1
12217 ,p_reference2 => p_reference2
12218 ,p_calling_module => p_calling_module
12219
12220 ) THEN
12221 If g_debug_mode = 'Y' then
12222 log_message(p_msg_token1 =>'funds check failed at setup and summerization');
12223 end if;
12224 --log_message(p_return_status => 'T');
12225 g_return_status := 'T';
12226 x_return_status := g_return_status;
12227 l_fc_final_exit_flag := 'NORMAL_ERROR';
12228 GOTO END_PROCESS;
12229 END IF;
12230 End if;
12231 If g_debug_mode = 'Y' then
12232 log_message(p_msg_token1 => 'End of funds_check_setup API');
12233 end if;
12234
12235 -----------------------------------------------------------------------------------------------------------
12236 -- Main Funds Check Processor Calling pa_fck_process . In this process it derives start date and end date
12237 -- based on amount type and boundary code and checks funds available against the budget from the bottom up
12238 -- ie, checks at the Resource level resource group level task level top task level project level .
12239 -- If all the level funds check passes then it sets the status as S for each bc_packet_record
12240 --------------------------------------------------------------------------------------------------------
12241 If g_debug_mode = 'Y' then
12242 log_message(p_stage => 70,p_msg_token1 => 'Calling pa_fck_process API');
12243 end if;
12244 IF l_mode NOT in ('F','U') then
12245 IF NOT pa_fcp_process
12246 (p_sob => l_set_of_books_id
12247 ,p_packet_id => l_packet_id
12248 ,p_mode => l_mode
12249 ,p_partial_flag => p_partial_flag
12250 ,p_arrival_seq => l_arrival_seq
12251 ,p_reference1 => p_reference1
12252 ,p_reference2 => p_reference2
12253 --,p_reference3 => p_reference3
12254 ,p_calling_module => p_calling_module
12255
12256 ) then
12257 If g_debug_mode = 'Y' then
12258 log_message(p_msg_token1 => 'funds check failed during pa_fck_process api');
12259 end if;
12260 --log_message(p_return_status => 'T');
12261 g_return_status := 'T';
12262 x_return_status := g_return_status;
12263 l_fc_final_exit_flag := 'NORMAL_ERROR';
12264 GOTO END_PROCESS;
12265 END IF;
12266 END IF;
12267 If g_debug_mode = 'Y' then
12268 log_message(p_msg_token1 => 'end of pa_fck_process complete');
12269 end if;
12270
12271 -----------------------------------------------------------------------
12272 -- synchronize the raw and burden lines if there is a failure
12273 ------------------------------------------------------------------------
12274 If g_debug_mode = 'Y' then
12275 log_message(p_stage => 80,p_msg_token1 => 'Calling sync_raw_burden API');
12276 end if;
12277 If l_mode not in ('U') then
12278 sync_raw_burden
12279 (p_packet_id => l_packet_id
12280 ,p_mode => l_mode
12281 ,p_calling_module => p_calling_module
12282 ,x_return_status => l_return_status
12283 );
12284 IF l_return_status <> 'S' then
12285 log_message(p_msg_token1 => 'Failed to synchronize the raw and burden lines');
12286 End if;
12287 log_message(p_msg_token1 => 'End of sync_raw_burden API');
12288 End if;
12289 -------------------------------------------------------------------------
12290 -- Update ei and cdls with gl date, encum type id, budget ccid etc if the
12291 -- funds check pass else update ei with cost dist reject code
12292 --------------------------------------------------------------------------
12293 If g_debug_mode = 'Y' then
12294 log_message(p_stage => 90 ,p_msg_token1 => 'Calling update_EIS API');
12295 end if;
12296 If l_mode not in ('U') and p_calling_module in ('DISTBTC','DISTERADJ','EXPENDITURE','DISTVIADJ','DISTCWKST'
12297 ,'INTERFACER','INTERFACVI') then
12298 update_EIS (p_packet_id => l_packet_id
12299 ,p_calling_module => p_calling_module
12300 ,p_mode => l_mode
12301 ,x_return_status => l_return_status);
12302 IF l_return_status <> 'S' then
12303 If g_debug_mode = 'Y' then
12304 log_message(p_msg_token1 => 'Failed to update EI and CDLs with status');
12305 end if;
12306 --log_message(p_return_status => l_return_status);
12307 g_return_status := l_return_status;
12308 End if;
12309 If g_debug_mode = 'Y' then
12310 log_message(p_msg_token1 => 'End of update_EIS API');
12311 end if;
12312 End if;
12313
12314 ---------------------------------------------------------------------------
12315 -- Determine the return code sent to GL /CBC
12316 -- the out NOCOPY parameter l_return_status is the status of the
12317 -- packet which is funds checked
12318 ----------------------------------------------------------------------------
12319 If g_debug_mode = 'Y' then
12320 log_message(p_stage => 100, p_msg_token1 => 'Calling gen_return_code API');
12321 end if;
12322 gen_return_code(p_packet_id => l_packet_id
12323 ,p_partial_flag => p_partial_flag
12324 ,p_calling_mode => p_calling_module
12325 ,x_return_status => l_packet_status);
12326
12327 -- if the pa_funds check fails then in tie back process
12328 -- just return with out proceeding further else check
12329 -- the return status of gl and cbc update the status code
12330 -- of packets
12331 If p_calling_module = 'GL' then
12332 g_pa_gl_return_status := l_packet_status;
12333 Elsif p_calling_module = 'CBC' then
12334 g_pa_cbc_return_status := l_packet_status;
12335 End if;
12336 If g_debug_mode = 'Y' then
12337 log_message(p_msg_token1 => 'The return code of the FC process :'||l_packet_status);
12338 end if;
12339
12340 -- --------------------------------------------------------------------------+
12341 -- Update gl_bc_packets status such that GL FC will not execute funds
12342 -- avaialble validation ... This is for no/separate line burdening
12343 -- --------------------------------------------------------------------------+
12344 --IF p_calling_module in ('GL','CBC') and l_mode IN ('R','C','F') then
12345
12346 -- MARK_GL_BC_PACKETS_FOR_NO_FC(p_packet_id => l_packet_id);
12347
12348 --End if;
12349
12350 -------->6599207 ------As part of CC Enhancements
12351 IF p_calling_module in ('CBC') and l_mode IN ('R','C','F') then
12352 -- funds check resutl is success
12353 If g_debug_mode = 'Y' then
12354 log_message(p_stage => 110, p_msg_token1 => 'Calling Post_Bdn_Lines_To_GL_CBC API');
12355 end if;
12356 Post_Bdn_Lines_To_GL_CBC (
12357 p_Packet_ID => l_packet_id
12358 ,p_calling_module => p_calling_module
12359 ,p_packet_status => l_packet_status
12360 ,p_reference1 => p_reference1
12361 ,p_reference2 => p_reference2
12362 ,x_return_status => l_return_status
12363 );
12364 IF l_return_status <> 'S' then
12365 If g_debug_mode = 'Y' then
12366 log_message(p_msg_token1 => 'Failed to post burden lines to GL / CBC');
12367 end if;
12368 --log_message(p_return_status => l_return_status);
12369 g_return_status := l_return_status;
12370 End if;
12371 If g_debug_mode = 'Y' then
12372 log_message(p_msg_token1 =>'End of Post_Bdn_Lines_To_GL_CBC API');
12373 end if;
12374
12375 ----------------------------------------------------------------------------------
12376 -- if the project funds check is success full then call encumbrance liquidation
12377 -- entries in gl bc packets and igc cc interface tables
12378 ----------------------------------------------------------------------------------
12379 If g_debug_mode = 'Y' then
12380 log_message(p_stage => 120, p_msg_token1 => 'Calling create_liqd_entry API');
12381 end if;
12382 create_liqd_entry(
12383 p_Packet_ID => l_packet_id
12384 ,p_calling_module => p_calling_module
12385 ,P_mode => l_mode
12386 ,p_reference1 => p_reference1
12387 ,p_reference2 => p_reference2
12388 ,p_packet_status => l_packet_status
12389 ,x_return_status => l_return_status
12390 );
12391 IF l_return_status <> 'S' then
12392 If g_debug_mode = 'Y' then
12393 log_message(p_msg_token1 => 'Failed to create liquidation entries in GL / CBC');
12394 end if;
12395 --log_message(p_return_status => l_return_status);
12396 g_return_status := l_return_status;
12397 End if;
12398 If g_debug_mode = 'Y' then
12399 log_message(p_msg_token1 => 'End of create_liqd_entry API');
12400 end if;
12401
12402 End if;
12403 -------->6599207 ------END
12404
12405
12406 -----------------------------------------------------------------------------------
12407 -- if the packet status is failed then update the status code of the pa bc packets
12408 -- for gl, cbc, trxn imports as failed otherwise the status code is updated in
12409 -- the tie back process
12410 -----------------------------------------------------------------------------------
12411 If ( (p_calling_module IN ( 'DISTBTC','GL','CBC','DISTERADJ','TRXIMPORT','DISTVIADJ','DISTCWKST')
12412 and l_mode not in ('U') and l_packet_status <> 'S' )
12413 OR ( p_calling_module IN ('RESERVE_BASELINE'))
12414 -- OR l_mode = 'C' , 'C' should behave like 'R' mode ..
12415 ) then
12416 If g_debug_mode = 'Y' then
12417 log_message(p_stage => 130, p_msg_token1 => 'calling update status code for failed packet');
12418 end if;
12419 status_code_update (
12420 p_calling_module => p_calling_module
12421 ,p_packet_id => l_packet_id
12422 ,p_mode => l_mode
12423 ,p_partial =>p_partial_flag
12424 ,p_packet_status => l_packet_status
12425 ,x_return_status => l_return_status
12426 );
12427 If g_debug_mode = 'Y' then
12428 log_message(p_msg_token1 => 'end of status code for failed packet');
12429 end if;
12430 IF l_return_status <> 'S' then
12431 If g_debug_mode = 'Y' then
12432 log_message(p_msg_token1 => 'Failed to update status codes');
12433 end if;
12434 --log_message(p_return_status => l_return_status);
12435 g_return_status := l_return_status;
12436 End if;
12437 End if;
12438
12439 If p_calling_module IN ( 'GL','CBC') AND l_mode not in ('U') and
12440 (l_packet_status <> 'S' OR p_partial_flag = 'Y') then
12441 If g_debug_mode = 'Y' then
12442 log_message(p_stage => 140, p_msg_token1 =>'Calling update_GL_CBC_result_code API');
12443 end if;
12444
12445 update_GL_CBC_result_code(
12446 p_packet_id => l_packet_id
12447 ,p_calling_module => p_calling_module
12448 ,p_mode => l_mode
12449 ,p_partial_flag => p_partial_flag
12450 ,p_reference1 => p_reference1
12451 ,p_reference2 => p_reference2
12452 ,p_packet_status => l_packet_status
12453 ,x_return_status => l_return_status
12454 );
12455 IF l_return_status <> 'S' then
12456 If g_debug_mode = 'Y' then
12457 log_message(p_msg_token1 => 'Failed to update result_code in GL /CBC ');
12458 end if;
12459 --log_message(p_return_status => l_return_status);
12460 g_return_status := l_return_status;
12461 End if;
12462 If g_debug_mode = 'Y' then
12463 log_message(p_msg_token1 =>'End of update_GL_CBC_result_code APIl_packet_status['||l_packet_status);
12464 end if;
12465 End IF;
12466 x_return_status := l_packet_status;
12467 If x_return_status = 'S' then
12468 /** added if condition if the funds check is called from GL /CBC
12469 * and partial_flag = 'Y' then GL /CBC funds check expects return
12470 * as 'P' instead of 'S' so set the return code for GL /CBC for
12471 * partial mode as P
12472 */
12473 If p_partial_flag = 'Y' and p_calling_module in ('GL','CBC') then
12474 If g_debug_mode = 'Y' then
12475 log_message(p_stage => 150, p_msg_token1 => 'Calling get_gl_cbc_return_status api');
12476 end if;
12477 x_return_status := get_gl_cbc_return_status
12478 (p_packet_id => l_packet_id);
12479
12480 End if;
12481 x_error_stage := 0;
12482 x_error_msg := null;
12483 Else -- was causing plsql value error
12484 x_error_stage := substr(g_error_stage,1,100); -- CBC funds check defined length as 100
12485 x_error_msg := substr(g_error_msg,1,100); -- so substr func added to reduce the length
12486 End if;
12487
12488 <<END_PROCESS>>
12489 If g_debug_mode = 'Y' then
12490 log_message(p_msg_token1 => 'End of Funds check Process l_fc_final_exit_flag['||
12491 l_fc_final_exit_flag);
12492 end if;
12493
12494 IF l_fc_final_exit_flag = 'NORMAL_ERROR' then
12495 x_return_status := 'F';
12496 -- update the gl / cbc result code with failure status
12497 If p_calling_module in ('GL','CBC') then
12498 update_GL_CBC_result_code(
12499 p_packet_id => l_packet_id
12500 ,p_calling_module => p_calling_module
12501 ,p_mode => l_mode
12502 ,p_partial_flag => p_partial_flag
12503 ,p_reference1 => p_reference1
12504 ,p_reference2 => p_reference2
12505 ,p_packet_status => 'F' -- failure
12506 ,x_return_status => l_return_status);
12507
12508 Elsif p_calling_module in ('DISTBTC','DISTERADJ','DISTVIADJ','INTERFACER','INTERFACVI','DISTCWKST') THEN
12509 update_EIS (p_packet_id => l_packet_id
12510 ,p_calling_module => p_calling_module
12511 ,p_mode => l_mode
12512 ,x_return_status => l_return_status);
12513 End if;
12514 If p_calling_module = 'GL' then
12515 g_pa_gl_return_status := 'F';
12516 Elsif p_calling_module = 'CBC' then
12517 g_pa_cbc_return_status := 'F';
12518 End if;
12519
12520 END IF;
12521 -- Reset the error stack
12522 PA_DEBUG.reset_err_stack;
12523 If g_debug_mode = 'Y' then
12524 log_message(p_msg_token1 => 'Return status :'||x_return_status);
12525 end if;
12526 RETURN ( TRUE );
12527 EXCEPTION
12528 WHEN OTHERS THEN
12529 x_error_stage := g_error_stage;
12530 x_error_msg := SQLCODE||SQLERRM;
12531 x_return_status := 'T';
12532 --log_message(p_return_status => x_return_status );
12533 g_return_status := 'T' ;
12534 result_status_code_update
12535 ( p_packet_id => l_packet_id,
12536 p_status_code => 'T',
12537 p_result_code => 'F142',
12538 p_res_result_code => 'F142',
12539 p_res_grp_result_code => 'F142',
12540 p_task_result_code => 'F142',
12541 p_top_task_result_code => 'F142',
12542 p_proj_acct_result_code => 'F142');
12543
12544 IF p_calling_module in ('DISTBTC','DISTVIADJ','DISTERADJ','EXPENDITURE','INTERFACER','INTERFACVI','DISTCWKST') then
12545 update_EIS(p_packet_id => l_packet_id
12546 ,p_calling_module => p_calling_module
12547 ,p_mode => l_mode
12548 ,x_return_status => l_return_status);
12549 If g_debug_mode = 'Y' then
12550 log_message(p_msg_token1 =>
12551 'Updateing EIS with rejection_code');
12552 end if;
12553 ELSIF p_calling_module in ('GL','CBC') then
12554 update_GL_CBC_result_code(
12555 p_packet_id =>l_packet_id
12556 ,p_calling_module =>p_calling_module
12557 ,p_partial_flag => p_partial_flag
12558 ,p_reference1 => p_reference1
12559 ,p_reference2 => p_reference2
12560 ,p_mode =>l_mode
12561 ,p_packet_status => 'T'
12562 ,x_return_status => l_return_status);
12563 END IF;
12564 If p_calling_module = 'GL' then
12565 g_pa_gl_return_status := 'T';
12566 Elsif p_calling_module = 'CBC' then
12567 g_pa_cbc_return_status := 'T';
12568 End if;
12569
12570 If cur_sob%ISOPEN then
12571 close cur_sob;
12572 End if;
12573
12574 If cur_packets%ISOPEN then
12575 close cur_packets;
12576 End if;
12577 If g_debug_mode = 'Y' then
12578 log_message(p_msg_token1 => 'failed in pa_funds_check apiSQLERR :'||sqlcode||sqlerrm);
12579 end if;
12580 -- Reset the error stack
12581 PA_DEBUG.reset_err_stack;
12582 RETURN ( false );
12583
12584 END pa_funds_check;
12585
12586 -----------------------------------------------------------
12587 -- This API returns the GL return code based on the full or
12588 -- partial modes in the case of RESERVE,CHECK FUNDS
12589 ----------------------------------------------------------
12590 FUNCTION get_gl_return_code(p_packet_id in number,
12591 p_partial_flag in varchar2 default 'N')
12592 return varchar2 IS
12593
12594 -- check for fatal error for the transactions in full mode
12595 cursor gl_status_fatal_error is
12596 SELECT 1
12597 FROM gl_bc_packets a
12598 WHERE a.packet_id = p_packet_id
12599 AND EXISTS (
12600 SELECT 'Y'
12601 FROM gl_bc_packets b
12602 WHERE b.status_code = 'T'
12603 AND b.packet_id = a.packet_id
12604 );
12605
12606 -- check for normal error for the transaction in full mode
12607 cursor gl_status_normal_error is
12608 SELECT 1
12609 FROM gl_bc_packets a
12610 WHERE a.packet_id = p_packet_id
12611 AND EXISTS (
12612 SELECT 'Y'
12613 FROM gl_bc_packets b
12614 WHERE b.packet_id = a.packet_id
12615 AND ((b.status_code in ('R','F','T')
12616 AND substr(b.result_code,1,1) = ('F')
12617 ) OR
12618 ( b.status_code = 'T' )
12619 )
12620 );
12621
12622 -- Check for at least on passed transaction in gl in partial mode
12623 -- if not found then all transactions are rejected
12624 cursor gl_status_partial is
12625 SELECT 1
12626 FROM gl_bc_packets a
12627 WHERE a.packet_id = p_packet_id
12628 AND EXISTS
12629 (SELECT 'Y'
12630 FROM gl_bc_packets b
12631 WHERE b.status_code in ('S','A','P')
12632 AND substr(b.result_code,1,1) IN ('P','A')
12633 AND b.packet_id = a.packet_id
12634 );
12635
12636
12637
12638 l_return_code varchar2(10) := 'S';
12639 l_status_code number := 0;
12640 BEGIN
12641
12642 l_return_code := 'S';
12643 l_status_code := 0;
12644 IF p_partial_flag <> 'Y' then -- full mode
12645 If g_debug_mode = 'Y' Then
12646 log_message(p_msg_token1 => 'opening cur to check fatal error');
12647 End if;
12648 OPEN gl_status_fatal_error;
12649 FETCH gl_status_fatal_error INTO l_status_code;
12650 IF gl_status_fatal_error%NOTFOUND THEN
12651 OPEN gl_status_normal_error;
12652 If g_debug_mode = 'Y' Then
12653 log_message(p_msg_token1 => 'opening cur to check normal error');
12654 End if;
12655 FETCH gl_status_normal_error INTO l_status_code;
12656 IF gl_status_normal_error%NOTFOUND THEN
12657 If g_debug_mode = 'Y' Then
12658 log_message(p_msg_token1 => 'cur not found');
12659 End if;
12660 l_return_code := 'S';
12661 END IF;
12662 CLOSE gl_status_normal_error;
12663 END IF;
12664 CLOSE gl_status_fatal_error;
12665
12666 IF gl_status_fatal_error%isopen then
12667 close gl_status_fatal_error;
12668 End if;
12669 IF gl_status_normal_error%isopen then
12670 close gl_status_normal_error;
12671 End if;
12672
12673 IF nvl(l_status_code,0) > 0 then
12674 l_return_code := 'F';
12675 Else
12676 l_return_code := 'S';
12677 End if;
12678 If g_debug_mode = 'Y' Then
12679 log_message(p_msg_token1 => 'gl return code ='||l_return_code);
12680 End if;
12681 return l_return_code;
12682
12683 ELSE -- partial mode
12684
12685 OPEN gl_status_partial;
12686 If g_debug_mode = 'Y' Then
12687 log_message(p_msg_token1 => 'opening cur to check gl return code ');
12688 End if;
12689 FETCH gl_status_partial INTO l_status_code;
12690 IF gl_status_partial%NOTFOUND then
12691 If g_debug_mode = 'Y' Then
12692 log_message(p_msg_token1 => 'cur not found');
12693 End if;
12694 l_return_code := 'F';
12695 Else
12696 l_return_code := 'S';
12697 End if;
12698 CLOSE gl_status_partial;
12699
12700 IF gl_status_partial%isopen then
12701 close gl_status_partial;
12702 End if;
12703 If g_debug_mode = 'Y' Then
12704 log_message(p_msg_token1 => 'gl return code ='||l_return_code);
12705 End if;
12706 return l_return_code;
12707 END IF;
12708
12709 EXCEPTION
12710 when others then
12711 If g_debug_mode = 'Y' Then
12712 log_message(p_msg_token1 => 'Failed in get_gl_return_code api');
12713 End if;
12714 raise;
12715 END get_gl_return_code;
12716
12717 /** If the calling module is partial then
12718 * status and return code should be updated in
12719 * pa_bc_packets using autonmous transaction other wise
12720 * it causes a deadlock while calling sync_raw_burden from tie back api
12721 **/
12722 PROCEDURE tie_back_status(p_calling_module in varchar2,
12723 p_packet_id in number,
12724 p_partial_flag in varchar2,
12725 p_mode in varchar2,
12726 p_glcbc_return_code in varchar2) IS
12727
12728 PRAGMA AUTONOMOUS_TRANSACTION;
12729
12730 BEGIN
12731
12732 If g_debug_mode = 'Y' Then
12733 log_message(p_msg_token1 => 'In tie_back_status,p_calling_module,p_packet_id,p_partial_flag:'
12734 ||p_calling_module||','||p_packet_id||','||p_partial_flag);
12735 log_message(p_msg_token1 => 'In tie_back_status,p_mode,p_glcbc_return_code:'
12736 ||p_mode||','||p_glcbc_return_code);
12737 End if;
12738
12739 If p_calling_module in('GL','CBC') and p_mode in ('C','R','A','F') then
12740 FORALL i IN g_tab_src_dist_id_num_1.FIRST .. g_tab_src_dist_id_num_1.LAST
12741 UPDATE pa_bc_packets
12742 SET result_code =
12743 decode(p_calling_module,
12744 'GL',
12745 decode(p_partial_flag,
12746 'Y',decode(p_mode,'C','F150','F156'),
12747 'N',decode(p_mode,'C',decode(p_glcbc_return_code,'F','F150',
12748 'R','F151',
12749 'T','F151')
12750 ,'R',decode(p_glcbc_return_code,'F','F155',
12751 'R','F155',
12752 'T','F155')
12753 ,'A',decode(p_glcbc_return_code,'F','F155',
12754 'R','F155',
12755 'T','F155')
12756 ,'F',decode(p_glcbc_return_code,'F','F155',
12757 'R','F155',
12758 'T','F155'))),
12759 'CBC',
12760 decode(p_partial_flag,
12761 'Y',decode(p_mode,'C','F152','F158'),
12762 'N',decode(p_mode,'C',decode(p_glcbc_return_code,'F','F152',
12763 'R','F153',
12764 'T','F153')
12765 ,'R',decode(p_glcbc_return_code,'F','F157',
12766 'R','F157',
12767 'T','F157')
12768 ,'A',decode(p_glcbc_return_code,'F','F157',
12769 'R','F157',
12770 'T','F157')
12771 ,'F',decode(p_glcbc_return_code,'F','F157',
12772 'R','F157',
12773 'T','F157'))))
12774 WHERE packet_id = p_packet_id
12775 AND substr(nvl(result_code,'P'),1,1) = 'P'
12776 AND document_distribution_id = g_tab_src_dist_id_num_1(i)
12777 AND (source_event_id = g_tab_gl_bc_event_id(i)
12778 OR
12779 bc_event_id = g_tab_gl_bc_event_id(i))
12780 AND document_type = g_tab_src_dist_type(i);
12781
12782 If g_debug_mode = 'Y' Then
12783 log_message(p_msg_token1 => 'In tie_back_status, pa_bc_pkt records updated:'||SQL%ROWCOUNT);
12784 End if;
12785
12786 Elsif (p_calling_module in('DISTBTC','DISTVIADJ','DISTCWKST')and p_glcbc_return_code = 'T') Then
12787 /* mark the transaction result code as rejected if the return code of the distribute
12788 * vendor invoice adjustment process raises unexpected error
12789 */
12790 UPDATE pa_bc_packets
12791 SET result_code = decode(substr(nvl(result_code,'P'),1,1),'P','F151',result_code)
12792 WHERE packet_id = p_packet_id;
12793
12794 End if;
12795 commit; -- to end an active autonomous transaction
12796
12797 If g_debug_mode = 'Y' Then
12798 log_message(p_msg_token1 => 'In tie_back_status: End');
12799 End if;
12800
12801 return;
12802
12803 EXCEPTION
12804 WHEN OTHERS THEN
12805 If g_debug_mode = 'Y' Then
12806 pa_funds_control_pkg.log_message(p_msg_token1 => 'Failed in tie_back_status apiSQLERR:'||
12807 sqlcode||sqlerrm);
12808 End if;
12809 RAISE;
12810
12811 END tie_back_status;
12812
12813 /********************************************************************************************************
12814 * This is the Tie back api which updates the status of pa_bc_packets table after
12815 * confirming the funds checking status of GL / Contract Commitments
12816 *Parameters:
12817 * P_packet_id : Packet Identifier of the funds check process
12818 * P_mode :Funds Checker Operation Mode
12819 * R - Reserve Default
12820 * B - Base line
12821 * C - Check
12822 * P_calling_module :This holds the info of budget type
12823 * GL --- Standard Default
12824 * CBC --- Contract Commitments
12825 * P_reference1 :This Param is not null in case of Contract Commitment
12826 * If P_ext_bdgt_type = CBC
12827 * This param holds the information of document type
12828 * P_reference2 = Igc_cc_interface.document_type
12829 * elsif p_mode = B then
12830 * P_reference1 = project_id
12831 * Else
12832 * P_reference1 = NULL;
12833 * End if;
12834 * P_reference2 :This Param is not null in case of Contract Commitment
12835 * If P_ext_bdgt_type = CBC
12836 * This param holds the information of document Header Id
12837 * P_reference2 = Igc_cc_interface.CC_HEADER_ID
12838 * elsif p_mode = B then
12839 * P_reference2 = budget_version_id
12840 * Else
12841 * P_reference2 = NULL;
12842 * End if;
12843 * p_partial_flag :Partial reservation flag
12844 * Y - partial mode
12845 * N - full Mode default
12846 * P_gl_cbc_return_code :The return status of the GL /CBC funds check process
12847 *************************************************************************************************************/
12848
12849 PROCEDURE PA_GL_CBC_CONFIRMATION
12850 (p_calling_module IN VARCHAR2
12851 ,p_packet_id IN NUMBER
12852 ,p_mode IN VARCHAR2 DEFAULT 'C'
12853 ,p_partial_flag IN VARCHAR2 DEFAULT 'N'
12854 ,p_reference1 IN VARCHAR2 DEFAULT NULL ----- doc type 'CC'
12855 ,p_reference2 IN VARCHAR2 DEFAULT NULL ---- CC_HEADER_ID
12856 ,p_gl_cbc_return_code IN OUT NOCOPY VARCHAR2
12857 ,x_return_status OUT NOCOPY VARCHAR2
12858 ) IS
12859
12860 l_packet_id NUMBER;
12861
12862 CURSOR gl_cur(v_packet_id NUMBER) is
12863 SELECT DISTINCT gl.source_distribution_id_num_1 distribution_id,
12864 gl.event_id,
12865 decode(gl.source_distribution_type,
12866 'AP_INV_DIST','AP',
12867 'AP_PREPAY','AP',
12868 'PA_AP_BURDEN','AP',
12869 'PO_DISTRIBUTIONS_ALL','PO',
12870 'PA_PO_BURDEN','PO',
12871 'PA_REQ_BURDEN','REQ',
12872 'PO_REQ_DISTRIBUTIONS_ALL','REQ') source_distribution_type
12873 FROM gl_bc_packets gl
12874 WHERE gl.packet_id = v_packet_id
12875 AND ( (nvl(substr(gl.result_code,1,1),'P') = 'F'
12876 AND gl.status_code in ('F','R'))
12877 OR (gl.status_code = 'T')
12878 );
12879
12880 -- Cursor to check the number of failed/passed records in gl and accordingly pass return status back to PSA.
12881 -- Note : No need to have partial flag logic here as procedure update_GL_CBC_result_code has already stamped
12882 -- gl bc packets status code based on partial flag.
12883 -- Output values :
12884 -- return 'F' if all have failed --fail
12885 -- return 'P' if some of the records have failed --partial
12886 -- return 'S' if all have success --success
12887
12888 CURSOR gl_return_code IS
12889 SELECT decode(count(*)
12890 ,count(decode(substr(nvl(gl.result_code,'P'),1,1),'P',1)),'S'
12891 ,count(decode(substr(nvl(gl.result_code,'P'),1,1),'F',1,'X',1)),'F'
12892 ,decode(p_partial_flag,'N','F','P')) -- Bug 5522810 : p_partial_flag is also checked before returning partial mode
12893 FROM gl_bc_packets gl
12894 WHERE gl.packet_id = p_packet_id;
12895
12896 -------->6599207 ------As part of CC Enhancements
12897 CURSOR cbc_cur IS
12898 SELECT igc.rowid,igc.reference_9
12899 FROM igc_cc_interface igc
12900 WHERE igc.document_type = p_reference1
12901 AND igc.cc_header_id = p_reference2
12902 AND ((nvl(substr(igc.cbc_result_code,1,1),'P') = 'F'
12903 AND igc.status_code in ('F','R'))
12904 OR (igc.status_code = 'T')
12905 );
12906 -------->6599207 ------END
12907
12908
12909 l_num_rows NUMBER := 100;
12910 l_return_status VARCHAR2(1);
12911 l_gl_cbc_return_code VARCHAR2(10);
12912 l_pa_return_code VARCHAR2(10);
12913 l_mode VARCHAR2(10);
12914 l_debug_mode VARCHAR2(10);
12915 l_calling_module VARCHAR2(30);
12916 l_calling_code VARCHAR2(10);
12917 l_event_result_status VARCHAR2(15);
12918
12919 BEGIN
12920 --Initialize the error stack
12921 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.PA_GL_CBC_CONFIRMATION');
12922
12923 fnd_profile.get('PA_DEBUG_MODE',g_debug_mode );
12924 g_debug_mode := NVL(g_debug_mode, 'N');
12925
12926 PA_DEBUG.SET_PROCESS( x_process => 'PLSQL'
12927 ,x_write_file => 'LOG'
12928 ,x_debug_mode => g_debug_mode
12929 );
12930
12931 /** Bug fix :2302945 If PA is NOT installed in OU then we should return as success
12932 ** without proceeding further . This api checks whether the In given operating unit
12933 ** project is installed or not, if not installed return with success
12934 **/
12935 IF IS_PA_INSTALL_IN_OU = 'N' then
12936 x_return_status := 'S';
12937 g_return_status := 'S';
12938
12939 If g_debug_mode = 'Y' then
12940 log_message(p_msg_token1=>'PA NOT INSTALLED IN THIS OU.return status='
12941 ||x_return_status);
12942 end if;
12943 PA_DEBUG.Reset_err_stack;
12944 Return;
12945 END IF;
12946 /** End of Bug fix **/
12947
12948 l_mode := p_mode;
12949 If l_mode = 'A' then -- A Adjustment called from PO and REQ only
12950 l_mode := 'R';
12951 End if;
12952
12953 If g_debug_mode = 'Y' Then
12954 log_message(p_msg_token1 =>'INSIDE PA_GL_CBC_CONFIRMATION'||
12955 'calling module ['||p_calling_module|| ']mode ['||l_mode||
12956 ']p_reference1['|| p_reference1||']p_reference2[ '||p_reference2||
12957 ']p_packet_id ['||p_packet_id||']p_partial_flag[ '||p_partial_flag||
12958 ']p_gl_cbc_return_code [ '||p_gl_cbc_return_code||']g_ap_matched_case['||g_ap_matched_case||']');
12959 End if;
12960
12961 -------->6599207 ------As part of CC Enhancements
12962 /* COMMENTED THIS CODE
12963 -- ------------------------------------------------------------------------------------------+
12964 -- :( AS CBC IS NOT SUPPORTED, IF CBC CALLS PA, RETURN 'T' BACK TO CALLING PGM ..
12965 -- ------------------------------------------------------------------------------------------+
12966 --IF l_mode IN ( 'R','C','F' ) AND p_calling_module = 'CBC' THEN
12967 IF p_calling_module = 'CBC' THEN
12968 If g_debug_mode = 'Y' then
12969 log_message(p_msg_token1 => 'PA FC Called for CBC .. FAIL Process');
12970 End if;
12971
12972 p_gl_cbc_return_code := 'T';
12973 x_return_status := 'T';
12974 g_return_status := 'T';
12975
12976 PA_DEBUG.Reset_err_stack;
12977
12978 RETURN;
12979 END IF;
12980 -- ------------------------------------------------------------------------------------------+
12981 -- CBC Check Ends here ....
12982 -- ------------------------------------------------------------------------------------------+
12983 */
12984 -------->6599207 ------END
12985
12986 -------->6599207 ------As part of CC Enhancements -- Added IF condition alone
12987 IF p_calling_module <> 'CBC' THEN
12988
12989 -- -----------------------------------------------------------------------------------+
12990 -- Check if PA FC called for project related txn. or budget or its called for non-FC
12991 -- NO_FC: non-projcet related FC, exit with 'S' status
12992 -- BUD_FC: BC FC called projects (SLA-BC Integration for budget baseline) - new
12993 -- TXN_FC: PA FC called for txn. mode - existing
12994 -- -----------------------------------------------------------------------------------+
12995 CHECK_TXN_OR_BUDGET_FC (p_packet_id,l_calling_code);
12996
12997 If g_debug_mode = 'Y' then
12998 log_message(p_msg_token1=>'FC called mode:'||l_calling_code);
12999 End If;
13000
13001
13002 -- -----------------------------------------------------------------------------------+
13003 -- If NOT PA FC, exit program ..
13004 -- -----------------------------------------------------------------------------------+
13005 If l_calling_code = 'NO_FC' then
13006
13007 x_return_status := 'S';
13008 g_return_status := 'S';
13009 -- Bug 5140510 : p_gl_cbc_return_code should not be overwritten.
13010 -- p_gl_cbc_return_code := 'S';
13011
13012 If g_debug_mode = 'Y' then
13013 log_message(p_msg_token1=>'PA FC called for non-project transactions: EXIT FC program');
13014 End If;
13015
13016 PA_DEBUG.Reset_err_stack;
13017 RETURN;
13018
13019 End If;
13020
13021
13022 -- -------------------------------------------------------------------------------------+
13023 -- SLA-BC Integration: GL FC for budget calls PA tieback, here we execute account level
13024 -- funds check for the baseline mode .. and also build account summary ...
13025 -- -------------------------------------------------------------------------------------+
13026
13027 If l_calling_code = 'BUD_FC' then
13028
13029 If g_debug_mode = 'Y' then
13030 log_message(p_msg_token1=>'Before calling DO_BUDGET_BASELINE_TIEBACK');
13031 End If;
13032
13033 DO_BUDGET_BASELINE_TIEBACK(p_packet_id,x_return_status);
13034
13035 If g_debug_mode = 'Y' then
13036 log_message(p_msg_token1=>'After calling DO_BUDGET_BASELINE_TIEBACK, return status:'||x_return_status);
13037 End If;
13038
13039 If x_return_status <> 'S' then
13040
13041 p_gl_cbc_return_code := 'F';
13042
13043 Else
13044
13045 p_gl_cbc_return_code := 'S';
13046
13047 End If;
13048
13049 RETURN;
13050
13051 End if;
13052 -- -----------------------------------------------------------------------------------+
13053
13054 END IF;
13055 -------->6599207 ------END
13056
13057
13058 -- Intitalize the out NOCOPY parameter
13059 x_return_status := 'S';
13060 If g_debug_mode = 'Y' Then
13061 log_message(p_msg_token1 =>' g_pa_gl_return_status ['||g_pa_gl_return_status||
13062 ']g_pa_cbc_return_status ['||g_pa_cbc_return_status||']');
13063 End if;
13064
13065 -- Assign the status codes of GL / CBC to local varialbes
13066 -- if gl return code is null then derive return code
13067 IF p_gl_cbc_return_code is null and p_calling_module = 'GL' then
13068 l_gl_cbc_return_code := get_gl_return_code
13069 (p_packet_id => p_packet_id
13070 ,p_partial_flag => p_partial_flag);
13071 Elsif p_gl_cbc_return_code in ('P','S','A') then
13072
13073 l_gl_cbc_return_code := 'S';
13074 Else
13075 l_gl_cbc_return_code := nvl(p_gl_cbc_return_code,'S') ;
13076 End if;
13077 If g_debug_mode = 'Y' Then
13078 log_message(p_msg_token1 =>'l_gl_cbc_return_code = '||l_gl_cbc_return_code);
13079 End if;
13080
13081 If p_calling_module = 'CBC' and p_packet_id is NULL then
13082 l_packet_id := g_cbc_packet_id;
13083 Elsif p_calling_module = 'GL' and l_mode not in ('U') then
13084 l_packet_id := p_packet_id;
13085 Elsif l_mode in ('U') then
13086 l_packet_id := g_packet_id;
13087 End if;
13088 If g_debug_mode = 'Y' Then
13089 log_message(p_msg_token1 => 'packet_id ['||l_packet_id||']g_packet_id = '||g_packet_id||
13090 ']g_cbc_packet_id ['||g_cbc_packet_id||']');
13091
13092 log_message(p_stage => 10 ,p_msg_token1 => 'Start Of PA_GL_CBC_CONFIRMATION ');
13093 End if;
13094
13095 IF p_calling_module = 'GL' and l_mode in ('C','R','F') and g_pa_gl_return_status = 'S' then
13096
13097 OPEN gl_cur(l_packet_id);
13098 LOOP
13099 g_tab_src_dist_id_num_1.delete;
13100 g_tab_gl_bc_event_id.delete;
13101 g_tab_src_dist_type.delete;
13102
13103 FETCH gl_cur BULK COLLECT INTO
13104 g_tab_src_dist_id_num_1,g_tab_gl_bc_event_id,g_tab_src_dist_type LIMIT l_num_rows;
13105
13106 If g_debug_mode = 'Y' Then
13107 log_message(p_msg_token1 => ' GL Failed distinct (event/distr/dist type) record count:'
13108 ||g_tab_src_dist_id_num_1.COUNT);
13109 End if;
13110
13111 IF NOT g_tab_src_dist_id_num_1.EXISTS(1) then
13112 EXIT;
13113 END IF;
13114
13115 tie_back_status
13116 (p_calling_module => p_calling_module
13117 ,p_packet_id => l_packet_id
13118 ,p_partial_flag => p_partial_flag
13119 ,p_mode => l_mode
13120 ,p_glcbc_return_code => l_gl_cbc_return_code);
13121
13122 EXIT WHEN gl_cur%notfound;
13123
13124 END LOOP;
13125 CLOSE gl_cur;
13126
13127 -------->6599207 ------As part of CC Enhancements
13128 ---- Uncommented this ELSIF condition
13129 ELSIF p_calling_module = 'CBC' and l_mode in ('C','R','F') and g_pa_cbc_return_status = 'S' then
13130
13131 OPEN cbc_cur;
13132 LOOP
13133 g_tab_rowid.delete;
13134 g_tab_tieback_id.delete;
13135 FETCH cbc_cur BULK COLLECT INTO
13136 g_tab_rowid,g_tab_tieback_id LIMIT l_num_rows;
13137 IF NOT g_tab_rowid.EXISTS(1) then
13138 EXIT;
13139 END IF;
13140
13141 tie_back_status
13142 (p_calling_module => p_calling_module
13143 ,p_packet_id => l_packet_id
13144 ,p_partial_flag => p_partial_flag
13145 ,p_mode => l_mode
13146 ,p_glcbc_return_code => l_gl_cbc_return_code);
13147
13148 EXIT WHEN cbc_cur%notfound;
13149
13150 END LOOP;
13151 CLOSE cbc_cur;
13152
13153 END IF;
13154 -------->6599207 ------END
13155
13156 -- After update of packet status based on GL return code if there are
13157 -- any transactions failed in GL for raw line if not integrated
13158 -- then we have to tie up raw and burden lines in partial mode
13159 If p_calling_module in ('GL','CBC') and
13160 ( g_pa_gl_return_status = 'S' OR g_pa_cbc_return_status = 'S' )then
13161 If g_debug_mode = 'Y' Then
13162 log_message(p_msg_token1 => 'calling sync_raw_burden api in tie back');
13163 End if;
13164 sync_raw_burden
13165 (p_packet_id =>l_packet_id,
13166 p_mode =>l_mode,
13167 p_calling_module =>p_calling_module,
13168 x_return_status =>l_return_status);
13169 If g_debug_mode = 'Y' Then
13170 log_message(p_msg_token1 => 'calling status_code_update api in tie back');
13171 End if;
13172
13173 If g_debug_mode = 'Y' Then
13174 log_message(p_msg_token1 => 'Calling procedure full_mode_failure ..');
13175 End if;
13176
13177 FULL_MODE_FAILURE(p_packet_id => l_packet_id, p_case => 'AP_FULL_MODE_FAILURE');
13178
13179 If g_debug_mode = 'Y' Then
13180 log_message(p_msg_token1 => 'After Calling procedure full_mode_failure ..');
13181 End if;
13182
13183
13184 status_code_update (
13185 p_calling_module => p_calling_module
13186 ,p_packet_id => l_packet_id
13187 ,p_mode => l_mode
13188 ,p_partial => p_partial_flag
13189 ,p_packet_status => l_gl_cbc_return_code
13190 ,x_return_status => l_return_status
13191 );
13192 If g_debug_mode = 'Y' Then
13193 log_message(p_msg_token1 => 'return status = '||l_return_status);
13194 End if;
13195 IF l_return_status <> 'S' then
13196 log_message(p_msg_token1 => 'Failed to update status codes');
13197 End if;
13198 End if;
13199
13200
13201 -- if the return status from gl/ cbc is success then update the budget
13202 -- account balances
13203 IF l_gl_cbc_return_code = 'S' and p_calling_module in ('GL','CBC')
13204 and (g_pa_gl_return_status = 'S' OR g_pa_cbc_return_status = 'S' )
13205 and l_mode in ('R','U','F') then
13206 If g_debug_mode = 'Y' Then
13207 log_message(p_msg_token1 => 'calling upd_bdgt_encum_bal api from tieback');
13208 End if;
13209 upd_bdgt_encum_bal(
13210 p_packet_id => l_packet_id
13211 ,p_calling_module => p_calling_module
13212 ,p_mode => l_mode
13213 ,p_packet_status => l_gl_cbc_return_code
13214 ,x_return_status => l_return_status
13215 );
13216 If g_debug_mode = 'Y' Then
13217 log_message(p_msg_token1 => 'after upd_bdgt_encum_bal api return status ='||l_return_status);
13218 End if;
13219 IF l_return_status <> 'S' then
13220 If g_debug_mode = 'Y' Then
13221 log_message(p_msg_token1 => 'Calling upd_cwk_attributes API');
13222 End if;
13223 End if;
13224
13225 /* PAM changes */
13226 If p_calling_module = 'GL' Then
13227 -- update the cwk attributes for the passed transactions
13228 pa_funds_control_pkg1.upd_cwk_attributes
13229 (p_calling_module => p_calling_module
13230 ,p_packet_id => l_packet_id
13231 ,p_mode => l_mode
13232 ,p_reference => 'UPD_AMTS'
13233 ,x_return_status => l_return_status
13234 );
13235
13236 -- update the cwk compiled_multiplier
13237 pa_funds_control_pkg1.upd_cwk_attributes(
13238 p_calling_module => p_calling_module
13239 ,p_packet_id => l_packet_id
13240 ,p_mode => l_mode
13241 ,p_reference => 'UPD_MULTIPLIER'
13242 ,x_return_status => l_return_status
13243 );
13244
13245 If g_debug_mode = 'Y' Then
13246 log_message(p_msg_token1 => 'End of upd_cwk_attributes API return status ['||l_return_status||']');
13247 End if;
13248
13249 End If;
13250
13251 END IF;
13252
13253 IF p_calling_module in ('GL','CBC') then
13254
13255 If p_calling_module = 'GL' then
13256 l_calling_module := 'GL_TIEBACK';
13257 Elsif p_calling_module = 'CBC' then
13258 l_calling_module := 'CBC_TIEBACK';
13259 Else
13260 l_calling_module := p_calling_module;
13261 End if;
13262 update_GL_CBC_result_code(
13263 p_packet_id => l_packet_id,
13264 p_calling_module => l_calling_module,
13265 p_partial_flag => p_partial_flag,
13266 p_reference1 => p_reference1,
13267 p_reference2 => p_reference2,
13268 p_mode => l_mode,
13269 p_packet_status => l_gl_cbc_return_code,
13270 x_return_status => l_return_status
13271 );
13272
13273 /** commit is used here since in check mode GL does not commit or it may be calling in auto
13274 * nomous mode when called from PO, REQ. so
13275 * even though pa funds check updates the result code and status codes in gl
13276 * it is being setting to null after funds check call
13277 */
13278 --If p_calling_module = 'GL' and p_partial_flag = 'Y' and l_mode = 'C' then
13279 -- commit;
13280 --End if;
13281 -- This COMMIT has been removed as tieback is in the main sesion and by issuing
13282 -- commit, global tables can get wiped out .. R12 change
13283
13284 -- Logic to check the number of failed/passed records in gl and accordingly pass return status back to PSA.
13285 -- return 'F' if all have failed --fail
13286 -- return 'P' if some of the records have failed --partial
13287 -- return 'S' if all have success --success
13288
13289 OPEN gl_return_code ;
13290 FETCH gl_return_code INTO p_gl_cbc_return_code;
13291 CLOSE gl_return_code;
13292
13293 If g_debug_mode = 'Y' Then
13294 log_message(p_msg_token1 => 'Final return value for PSA p_gl_cbc_return_code '||p_gl_cbc_return_code);
13295 End if;
13296
13297 End if;
13298
13299
13300 -- Reset the error stack
13301 PA_DEBUG.reset_err_stack;
13302
13303 RETURN;
13304 EXCEPTION
13305 WHEN OTHERS THEN
13306 IF gl_cur%ISOPEN then
13307 close gl_cur;
13308 END IF;
13309 --IF cbc_cur%ISOPEN then
13310 -- close cbc_cur;
13311 --END IF;
13312
13313 result_status_code_update(p_status_code => 'T',
13314 p_packet_id => l_packet_id);
13315
13316 p_gl_cbc_return_code := 'T';
13317 x_return_status := 'T';
13318
13319 If g_debug_mode = 'Y' Then
13320 log_message(p_msg_token1 => 'Un handled Exception Error in PA_GL_CBC_CONFIRMATION');
13321 End if;
13322 log_message(p_error_msg => sqlcode||sqlerrm);
13323 -- Reset the error stack
13324 PA_DEBUG.reset_err_stack;
13325
13326 END PA_GL_CBC_CONFIRMATION;
13327
13328 /* The following API is added to tie back the status code of the
13329 * bc packets during the distribute vendor invoice adjustments
13330 * This API will be called from PABCCSTB.pls package
13331 */
13332 /*
13333 * Moved the API from main fc process to tieback process to update the bdgt acct balance and status code
13334 * Added for bug : 2961161 to update the status of packet if
13335 * called in DISTVIADJ mode and packet status is success
13336 */
13337 PROCEDURE tieback_pkt_status
13338 (p_calling_module in varchar2
13339 ,p_packet_id in number
13340 ,p_partial_flag in varchar2 default 'N'
13341 ,p_mode in varchar2 default 'R'
13342 ,p_tieback_status in varchar2 default 'T' --'S' for Success, 'T' -- fatal Error
13343 ,p_request_id in number
13344 ,x_return_status OUT NOCOPY varchar2) IS
13345
13346 cursor curViPkts IS
13347 SELECT distinct packet_id
13348 FROM pa_bc_packets
13349 WHERE request_id = p_request_id;
13350
13351 l_tieback_status varchar2(100);
13352 l_packet_id Number;
13353 l_mode Varchar2(100);
13354 l_partial_flag Varchar2(100);
13355
13356 BEGIN
13357 -- Initialize the Variables
13358 x_return_status := 'S';
13359 l_tieback_status := NVl(p_tieback_status,'T');
13360 l_packet_id := p_packet_id;
13361 l_mode := p_mode;
13362 l_partial_flag := NVl(p_partial_flag,'N');
13363
13364 --Initialize the error stack
13365 PA_DEBUG.init_err_stack('PA_FUNDS_CONTROL_PKG.tieback_pkt_status');
13366
13367 fnd_profile.get('PA_DEBUG_MODE',g_debug_mode );
13368 g_debug_mode := NVL(g_debug_mode, 'N');
13369
13370 PA_DEBUG.SET_PROCESS( x_process => 'PLSQL'
13371 ,x_write_file => 'LOG'
13372 ,x_debug_mode => g_debug_mode
13373 );
13374
13375 IF g_debug_mode = 'Y' Then
13376 log_message(p_msg_token1=>'Inside tieback_pkt_status l_packet_id['||l_packet_id||']l_mode['||
13377 l_mode||']l_partial_flag['||l_partial_flag||']p_calling_module['||
13378 p_calling_module||']p_tieback_status['||p_tieback_status||']p_request_id['||
13379 p_request_id||']' );
13380
13381 End If;
13382
13383 IF IS_PA_INSTALL_IN_OU = 'N' then
13384 x_return_status := 'S';
13385 g_return_status := 'S';
13386
13387 If g_debug_mode = 'Y' then
13388 log_message(p_msg_token1=>'PA NOT INSTALLED IN THIS OU.return status='||x_return_status);
13389 end if;
13390 PA_DEBUG.Reset_err_stack;
13391 Return;
13392 END IF;
13393
13394 IF p_calling_module in ('DISTBTC','DISTVIADJ','DISTCWKST' ) Then
13395 log_message(p_msg_token1 =>'Looping through each packet for the requestId to update the status');
13396
13397 FOR i IN curViPkts LOOP
13398
13399 l_packet_id := i.packet_id;
13400
13401 If l_tieback_status = 'T' Then
13402 If g_debug_mode = 'Y' Then
13403 log_message(p_msg_token1 =>'Calling ResultCode Tieback['||l_packet_id||']');
13404 End If;
13405 tie_back_status
13406 (p_calling_module => p_calling_module
13407 ,p_packet_id => l_packet_id
13408 ,p_partial_flag => l_partial_flag
13409 ,p_mode => l_mode
13410 ,p_glcbc_return_code => l_tieback_status
13411 );
13412 ELSE
13413
13414 If g_debug_mode = 'Y' Then
13415 log_message(p_msg_token1 => 'calling status_code_update in tie back['||l_packet_id||']');
13416 End if;
13417
13418 status_code_update (
13419 p_calling_module => p_calling_module
13420 ,p_packet_id => l_packet_id
13421 ,p_mode => l_mode
13422 ,p_partial => l_partial_flag
13423 ,p_packet_status => l_tieback_status
13424 ,x_return_status => x_return_status
13425 );
13426 If g_debug_mode = 'Y' Then
13427 log_message(p_msg_token1 => 'After StatuscodeUpdate return status['||x_return_status);
13428 End if;
13429
13430 IF ( x_return_status = 'S' AND l_tieback_status = 'S' AND l_mode in ('R','U','F') ) Then
13431
13432 upd_bdgt_encum_bal(
13433 p_packet_id => l_packet_id
13434 ,p_calling_module => p_calling_module
13435 ,p_mode => l_mode
13436 ,p_packet_status => l_tieback_status
13437 ,x_return_status => x_return_status
13438 );
13439
13440 /* PAM changes */
13441 If p_calling_module in ('DISTCWKST') Then
13442 log_message(p_msg_token1 => 'Calling upd_cwk_attributes API');
13443 -- update the cwk attributes for the passed transactions
13444 pa_funds_control_pkg1.upd_cwk_attributes
13445 (p_calling_module => p_calling_module
13446 ,p_packet_id => l_packet_id
13447 ,p_mode => l_mode
13448 ,p_reference => 'UPD_AMTS'
13449 ,x_return_status => x_return_status
13450 );
13451 End If;
13452
13453 End If;
13454 End If; -- l_pkt_status <> 'T'
13455
13456 END LOOP;
13457
13458 END IF;
13459
13460 IF g_debug_mode = 'Y' Then
13461 log_message(p_msg_token1=>'End of tieback_pkt_status API');
13462 End If;
13463
13464 -- Reset the error stack
13465 PA_DEBUG.reset_err_stack;
13466
13467 RETURN;
13468 EXCEPTION
13469 WHEN OTHERS THEN
13470 x_return_status := 'U';
13471 PA_DEBUG.reset_err_stack;
13472 Raise;
13473
13474 END tieback_pkt_status;
13475
13476 -------------------------------------------------------------------------------------
13477 -- This is an overloaded procedure inturn make calls to main funds check function
13478 -- this api is called from GL_funds checker from PO / REQ approval process
13479 -------------------------------------------------------------------------------------
13480 PROCEDURE pa_funds_check
13481 (p_calling_module IN VARCHAR2
13482 ,p_set_of_book_id IN NUMBER
13483 ,p_packet_id IN NUMBER
13484 ,p_mode IN VARCHAR2 DEFAULT 'C'
13485 ,p_partial_flag IN VARCHAR2 DEFAULT 'N'
13486 ,p_reference1 IN VARCHAR2 DEFAULT NULL
13487 ,p_reference2 IN VARCHAR2 DEFAULT NULL
13488 ,x_return_status OUT NOCOPY VARCHAR2
13489 ,x_error_msg OUT NOCOPY VARCHAR2
13490 ,x_error_stage OUT NOCOPY VARCHAR2
13491 ) IS
13492
13493 l_return_status varchar2(100);
13494 l_error_msg varchar2(100);
13495 l_error_stage varchar2(100);
13496
13497 BEGIN
13498
13499
13500
13501 IF NOT pa_funds_check
13502 (p_calling_module => p_calling_module
13503 ,p_conc_flag => 'N'
13504 ,p_set_of_book_id =>p_set_of_book_id
13505 ,p_packet_id => p_packet_id
13506 ,p_mode =>p_mode
13507 ,p_partial_flag =>p_partial_flag
13508 ,p_reference1 =>p_reference1
13509 ,p_reference2 => p_reference2
13510 ,p_reference3 => null
13511 ,x_return_status => x_return_status
13512 ,x_error_msg => x_error_msg
13513 ,x_error_stage => x_error_stage
13514 ) then
13515 If g_debug_mode = 'Y' Then
13516 log_message(p_msg_token1 => 'Error during funds check process');
13517 End if;
13518
13519 End if;
13520 END;
13521
13522 -- ------------------------------------ R12 Start ------------------------------------------------+
13523 -- R12 Changes: New procedure/functions that were added
13524
13525 -- --------------------------------------------------------------------------------+
13526 -- This procedure has been created to handle FULL MODE failure during check funds
13527 -- action of an invoice that is matched to PO .. bug 5253309
13528 -- p_case added to handle future scenarios..
13529 -- This is reqd. especially for scenarios where AP has multiple distributions and
13530 -- some are matched to PO, in such cases the doc. is in 'PARTIAL MODE' but matched
13531 -- dist. is treated in FULL MODE.
13532 -- This procedure will also handle the scenario where var. record failed but original
13533 -- record passed and vice versa ..basically related events failure ..
13534 -- --------------------------------------------------------------------------------+
13535 PROCEDURE Full_mode_failure(p_packet_id IN NUMBER,
13536 p_case IN VARCHAR2)
13537 is
13538 TYPE t_reference1 is table of pa_bc_packets.reference1%type;
13539 TYPE t_reference3 is table of pa_bc_packets.reference3%type;
13540 tt_reference1 t_reference1;
13541 tt_reference3 t_reference3;
13542 Begin
13543 If nvl(p_case,'NO_AP') = 'AP_FULL_MODE_FAILURE' then
13544
13545 -- --------------------------------------------------------------------------------------+
13546 -- Scenario:
13547 -- Document_type doc_dist_id reference1 reference3 doc_dist_type
13548 -- AP 101 PO 2 ITEM
13549 -- AP 102 PO 2 IPV
13550 -- PO 2 AP 101 STANDARD
13551 --
13552 -- First update takes care of the scenario where 101 failed then fail 102
13553 -- 2nd update will take care of the scenario where either 101 or 102 failed, fail PO or
13554 -- PO failed, fail AP.
13555 -- K.Biju June6th,2006
13556 -- --------------------------------------------------------------------------------------+
13557
13558
13559 If g_debug_mode = 'Y' Then
13560 log_message(p_msg_token1 => 'Full_mode_failure: Check AP matched failure case exists');
13561 End if;
13562
13563 /* Bug 5589452 : Update to fail all AP/PO records in packet which are associated with related invoice distributions */
13564 Update pa_bc_packets pbc
13565 set pbc.result_code = 'F170'
13566 where pbc.packet_id = p_packet_id
13567 and substr(pbc.result_code,1,1) = 'P'
13568 and pbc.document_type in ('PO','AP')
13569 and ( decode (pbc.document_type , 'PO' , to_number(pbc.reference2) , 'AP' , pbc.document_header_id),
13570 decode (pbc.document_type , 'PO' , to_number(pbc.reference3) , 'AP' , pbc.document_distribution_id)) IN
13571 /** Select to fetch all related invoice distributions associated with a failed record in packet.
13572 This sql fetches all invoice distributions linked to each other with charge_applicable_to_dist_id and related id**/
13573 ( select distinct b.invoice_id,b.invoice_distribution_id
13574 from ap_invoice_distributions_all a
13575 ,ap_invoice_distributions_all b
13576 where (a.invoice_id,a.invoice_distribution_id) in
13577 /**select to fetch Invoice id and Inv distribution id associated with failed AP/PO records in a packet**/
13578 (select DECODE(pbc1.document_type,'PO',to_number(pbc1.reference2),pbc1.document_header_id),
13579 DECODE(pbc1.document_type,'PO',to_number(pbc1.reference3),pbc1.document_distribution_id)
13580 from pa_bc_packets pbc1
13581 where pbc1.packet_id = p_packet_id
13582 and substr(pbc1.result_code,1,1) = 'F'
13583 and pbc1.document_type in ('AP','PO')
13584 and pbc1.parent_bc_packet_id is null)
13585 and b.invoice_id = a.invoice_id
13586 and COALESCE(b.charge_applicable_to_dist_id,b.related_id,b.invoice_distribution_id) =
13587 COALESCE(a.charge_applicable_to_dist_id,a.related_id,a.invoice_distribution_id));
13588
13589
13590 select pbc.reference1,pbc.reference3
13591 BULK COLLECT into tt_reference1,tt_reference3
13592 from pa_bc_packets pbc
13593 where pbc.packet_id = p_packet_id
13594 and pbc.parent_bc_packet_id is null -- this is ok. as this proc. is fired after raw/burden synch
13595 and ((pbc.document_type = 'PO' and
13596 pbc.reference1 = 'AP' and
13597 substr(pbc.result_code,1,1) = 'F')
13598 OR
13599 (pbc.document_type = 'AP' and
13600 pbc.reference1 = 'PO' and
13601 substr(pbc.result_code,1,1) = 'F')
13602 );
13603
13604 If tt_reference1.exists(1) then
13605
13606 If g_debug_mode = 'Y' Then
13607 log_message(p_msg_token1 => 'Full_mode_failure: Yes!! AP matched failure case exists');
13608 log_message(p_msg_token1 => 'Full_mode_failure: Fail related AP distributions,viceversa');
13609 End if;
13610
13611 -- Fail other related AP distributions
13612 -- e.g.: If variance failed then failed original distribution and vice versa
13613 forall x in tt_reference1.FIRST..tt_reference1.LAST
13614 Update pa_bc_packets pbc
13615 set pbc.result_code = 'F170'
13616 where pbc.packet_id = p_packet_id
13617 and pbc.reference3 = tt_reference3(x) -- All rel matched AP dist. has same PO as ref3
13618 and pbc.document_type = 'AP'
13619 and substr(pbc.result_code,1,1) = 'P'
13620 and tt_reference1(x) = 'PO'; -- AP record has PO as reference1
13621
13622 If g_debug_mode = 'Y' Then
13623 log_message(p_msg_token1 => 'Full_mode_failure: Rel. dist. fail, records updated:'||SQL%ROWCOUNT);
13624 log_message(p_msg_token1 => 'Full_mode_failure: Fail PO if AP failed,viceversa');
13625 End if;
13626
13627 -- Fail other records with F170 (full mode failure)
13628 -- basically fail those records with result_code P%%%
13629 forall x in tt_reference1.FIRST..tt_reference1.LAST
13630 Update pa_bc_packets pbc
13631 set pbc.result_code = 'F170'
13632 where pbc.packet_id = p_packet_id
13633 and pbc.document_distribution_id = tt_reference3(x)
13634 and pbc.document_type = tt_reference1(x)
13635 and substr(pbc.result_code,1,1) = 'P';
13636
13637 If g_debug_mode = 'Y' Then
13638 log_message(p_msg_token1 => 'Full_mode_failure: PO-AP full mode, records updated:'||SQL%ROWCOUNT);
13639 End if;
13640
13641 tt_reference1.delete;
13642 tt_reference3.delete;
13643
13644 End if;
13645
13646 End If; --If nvl(p_case,'NO_FAILURE') = 'AP_FULL_MODE_FAILURE' then
13647
13648 End Full_mode_failure;
13649
13650 -- --------------------------------------------------------------------------------+
13651 -- This procedure is called from Synch_pa_gl_packets to AUTONOMOUSLY update
13652 -- pa_bc_packets with failure....in case of extract failing ..
13653 -- -------------------------------------------------------------------------------+
13654 PROCEDURE Missing_records_failure(p_pa_packet_id IN NUMBER,
13655 p_gl_packet_id IN NUMBER,
13656 p_partial_flag IN VARCHAR2,
13657 p_mode IN VARCHAR2) IS
13658 PRAGMA AUTONOMOUS_TRANSACTION;
13659 BEGIN
13660 l_program_name := 'Missing_records_failure:';
13661 If g_debug_mode = 'Y' then
13662 log_message(p_msg_token1=>l_program_name||':Start:p_partial_flag:'|| p_partial_flag );
13663 End If;
13664
13665 forall i in g_event_id.FIRST..g_event_id.LAST
13666 Update pa_bc_packets pbc
13667 set pbc.result_code = 'F173',
13668 pbc.status_code = decode(p_mode,'C','F','R'),
13669 pbc.packet_id = p_gl_packet_id
13670 where pbc.packet_id = p_pa_packet_id
13671 and pbc.bc_event_id = g_event_id(i)
13672 and pbc.document_distribution_id = g_doc_dist_id(i)
13673 and pbc.document_type = g_document_type(i);
13674
13675 -- Bug 5557520 : if F173 is encountered, we should be failing the complete packet
13676 -- without cheking for p_partial_flag as it will result into data corruption.
13677 --If p_partial_flag = 'N' then
13678 -- Full mode failure ...
13679 Update pa_bc_packets pbc
13680 set pbc.result_code = 'F170',
13681 pbc.status_code = decode(p_mode,'C','F','R'),
13682 pbc.packet_id = p_gl_packet_id
13683 where pbc.packet_id = p_pa_packet_id
13684 and substr(nvl(pbc.result_code,'P'),1,1) = 'P';
13685
13686 --End If;
13687
13688 COMMIT;
13689
13690 If g_debug_mode = 'Y' then
13691 log_message(p_msg_token1=>l_program_name||':End');
13692 End If;
13693
13694 End Missing_records_failure;
13695
13696 -- --------------------------------------------------------------------------------+
13697 -- This procedure is called from Synch_pa_gl_packets to update: serial_id,
13698 -- session_id, actual_flag,packet_id and status ..
13699 -- --------------------------------------------------------------------------------+
13700 PROCEDURE Synch_data(p_pa_packet_id IN NUMBER,
13701 p_gl_packet_id IN NUMBER) IS
13702
13703 CURSOR cur_get_gl_data IS
13704 SELECT session_id,
13705 serial_id
13706 FROM gl_bc_packets
13707 WHERE packet_id = p_gl_packet_id
13708 AND ROWNUM =1 ;
13709
13710 -- Note: bc_event_id is null being used as for integrated case, the balancing
13711 -- entries by PA (PA_PO_BURDEN) are present and that will synch the records
13712 -- so, the issue is only for non-integrated budgets ..
13713 Cursor cur_ap_matched_case is
13714 SELECT 'Y'
13715 FROM dual
13716 WHERE EXISTS(
13717 select 1
13718 from pa_bc_packets pbc1
13719 where pbc1.packet_id = p_pa_packet_id
13720 and pbc1.bc_event_id is null
13721 and pbc1.document_type = 'PO'
13722 and exists (select 1
13723 from pa_bc_packets pbc2
13724 where pbc2.packet_id = p_gl_packet_id
13725 and pbc2.bc_event_id is null
13726 and pbc2.document_type = 'AP'));
13727
13728 l_session_id pa_bc_packets.session_id%TYPE;
13729 l_serial_id pa_bc_packets.serial_id%TYPE;
13730
13731 PRAGMA AUTONOMOUS_TRANSACTION;
13732 BEGIN
13733 l_program_name := 'Synch_data:';
13734 If g_debug_mode = 'Y' then
13735 log_message(p_msg_token1=>l_program_name||'Start');
13736 End If;
13737
13738 OPEN cur_get_gl_data;
13739 FETCH cur_get_gl_data INTO l_session_id,l_serial_id;
13740 CLOSE cur_get_gl_data;
13741
13742 -- ------------------------------------------------------+
13743 -- Need to change this code .. all we need is one update
13744 -- and set g_ap_matched_case flag...
13745 -- ------------------------------------------------------+
13746
13747 Update pa_bc_packets pb
13748 set pb.packet_id = p_gl_packet_id,
13749 pb.status_code = decode(pb.status_code,'I','P',pb.status_code),
13750 pb.session_id = DECODE(pb.session_id,NULL,l_session_id,pb.session_id),
13751 pb.serial_id = DECODE(pb.serial_id,NULL,l_serial_id,pb.serial_id)
13752 where pb.packet_id = p_pa_packet_id ;
13753
13754 -- ------------------------------------------------------------------------------ +
13755 -- In case of non-integrated records, we do not have the budget relieving entries
13756 -- meaning that there are no PO records, so the above update fails to update info.
13757 -- on the PO records, thats why we have the following code ...
13758 -- Why did we go with this "work around" code
13759 -- For Auto-create case, REQ record.document_distribution_id_num_1 pointed to REQ
13760 -- but for matched case, po's dist. num is pointing to AP.
13761 -- For more info. check bug 5206285 ..
13762 -- ------------------------------------------------------------------------------ +
13763 g_ap_matched_case := 'N';
13764
13765 Open cur_ap_matched_case;
13766 fetch cur_ap_matched_case into g_ap_matched_case;
13767 close cur_ap_matched_case;
13768
13769 COMMIT;
13770
13771 If g_debug_mode = 'Y' then
13772 log_message(p_msg_token1=>l_program_name||'End');
13773 End If;
13774
13775 END Synch_data;
13776
13777
13778
13779 -- --------------------------------------------------------------------------------+
13780 -- This procedure will update the following columns in pa_bc_packets: serial_id,
13781 -- session_id,actual_flag,packet_id and status. Status will be upated from I to P.
13782 -- Called from pa_funds_check
13783 -- This procedure will also check if the extracts were successful, meaning that:
13784 -- A. pa_bc_packet records have been extracted into gl_bc_packets
13785 -- B. core records have been extracted into gl_bc_packets
13786 -- C. project relieveing entries are created in gl_bc_packets
13787 -- --------------------------------------------------------------------------------+
13788 PROCEDURE Synch_pa_gl_packets(x_packet_id IN Number,
13789 x_partial_flag IN VARCHAR2,
13790 x_mode IN VARCHAR2,
13791 x_result_code OUT NOCOPY Varchar2)
13792 IS
13793 l_pa_packet_id pa_bc_packets.packet_id%type;
13794
13795 Cursor c_old_packet is
13796 Select pb.packet_id
13797 from pa_bc_packets pb
13798 where pb.bc_event_id in
13799 (select glbc.event_id
13800 from gl_bc_packets glbc
13801 where glbc.packet_id = x_packet_id)
13802 union all
13803 Select pb.packet_id
13804 from pa_bc_packets pb
13805 where pb.source_event_id in
13806 (select glbc.event_id
13807 from gl_bc_packets glbc
13808 where glbc.packet_id = x_packet_id);
13809
13810 -- 1st select reqd. in the case where core distribution not in gl_bc_packets
13811 -- 2nd select reqd. in the case where PA distribution not in gl_bc_packets
13812
13813 BEGIN
13814
13815 l_program_name := 'Synch_pa_gl_packets:';
13816 If g_debug_mode = 'Y' then
13817 log_message(p_msg_token1=>l_program_name||'Start:x_packet_id,x_partial_flag:'||
13818 x_packet_id||','||x_partial_flag );
13819 End If;
13820
13821 -- Get the packet_id that was established earlier ..
13822 Open c_old_packet;
13823 fetch c_old_packet into l_pa_packet_id;
13824 Close c_old_packet;
13825
13826 If g_debug_mode = 'Y' then
13827 log_message(p_msg_token1=>l_program_name||' Previously establised packet is:'||l_pa_packet_id);
13828 End If;
13829
13830 If l_pa_packet_id is not null then
13831
13832 -- ---------------------------------------------------------------------------------------------- +
13833 -- A. Check if there is any extract failure ... for PA records
13834 If g_debug_mode = 'Y' then
13835 log_message(p_msg_token1=>l_program_name||' Previously establised packet is:'||l_pa_packet_id);
13836 End If;
13837 -- ---------------------------------------------------------------------------------------------- +
13838
13839 -------->6599207 ------As part of CC Enhancements
13840 -- modified doctype checking. Added CC_C_PAY also.
13841
13842 Select pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
13843 BULK COLLECT into g_event_id,g_doc_dist_id,g_document_type
13844 from pa_bc_packets pbc
13845 where packet_id = l_pa_packet_id
13846 and pbc.bc_event_id is not null -- to filter out non-integrated budgets ...
13847 group by pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
13848 having count(pbc.bc_event_id) > (select count(glbc.event_id)
13849 from gl_bc_packets glbc--,
13850 --xla_distribution_links xlad
13851 where glbc.packet_id = x_packet_id
13852 and glbc.event_id = pbc.bc_event_id
13853 and glbc.source_distribution_id_num_1 = pbc.document_distribution_id
13854 and decode(glbc.source_distribution_type,
13855 'PA_AP_BURDEN','AP',
13856 'PA_PO_BURDEN','PO',
13857 'PA_REQ_BURDEN','REQ','CC','CC_')||
13858 decode(glbc.source_distribution_type,'CC',substr(pbc.document_type,4),'')
13859 = pbc.document_type);
13860 --and xlad.event_id = glbc.event_id
13861 --and xlad.ae_header_id = glbc.ae_header_id
13862 --and xlad.ae_line_num = glbc.ae_line_num
13863 --and xlad.applied_to_entity_code <> 'BUDGETS');
13864 -- cannot use xla_distribution_links as FC is AUTONOMOUS
13865 -------->6599207 ------END
13866
13867 If g_debug_mode = 'Y' then
13868 log_message(p_msg_token1=>l_program_name||':'||g_event_id.COUNT||' PA event(s) did not have corr. gl_bc_packet records');
13869 End If;
13870
13871 If g_event_id.COUNT > 0 then -- COUNT
13872
13873 If g_debug_mode = 'Y' then
13874 log_message(p_msg_token1=>l_program_name||' Calling missing_records_failure');
13875 End If;
13876
13877 MISSING_RECORDS_FAILURE(p_pa_packet_id => l_pa_packet_id,
13878 p_gl_packet_id => x_packet_id,
13879 p_partial_flag => x_partial_flag,
13880 p_mode => x_mode);
13881
13882 g_event_id.DELETE;
13883 g_doc_dist_id.DELETE;
13884 g_document_type.DELETE;
13885
13886
13887 -- Bug 5557520 : If F173 failure then return fatal error irrespective of partial flag
13888 -- If all records have failed, set result code to 'F' so that
13889 -- FC will not proceed further .. (meaning after synch, it exists) ..
13890 Begin
13891
13892 select null -- null is ok ..
13893 into x_result_code
13894 from dual
13895 where exists
13896 (Select 1
13897 from pa_bc_packets
13898 where packet_id = l_pa_packet_id
13899 and status_code = 'I');
13900 Exception
13901 when no_data_found then
13902 x_result_code := 'F';
13903 End;
13904
13905
13906 End If; -- COUNT
13907
13908 -- ---------------------------------------------------------------------------------------------------------+
13909 If g_debug_mode = 'Y' then
13910 log_message(p_msg_token1=>l_program_name||':result code:'||x_result_code);
13911 log_message(p_msg_token1=>l_program_name||':If resultcode <> F then check if core records are missing');
13912 End If;
13913 -- ---------------------------------------------------------------------------------------------------------+
13914
13915 /* ===============================================================================================================+
13916 THIS IS NO LONGER REQUIRED .. SA PSA ENSURES THAT ALL RECORDS ARE COPIED OVER .....
13917
13918 If nvl(x_result_code,'P') <> 'F' then
13919
13920 Select pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
13921 BULK COLLECT into g_event_id,g_doc_dist_id,g_document_type
13922 from pa_bc_packets pbc
13923 where pbc.packet_id = l_pa_packet_id
13924 and pbc.status_code = 'I'
13925 and pbc.source_event_id is not null
13926 and not exists (select 1
13927 from gl_bc_packets glbc
13928 where glbc.packet_id = x_packet_id
13929 and glbc.event_id = pbc.source_event_id
13930 and glbc.source_distribution_id_num_1 = pbc.document_distribution_id);
13931
13932 If g_debug_mode = 'Y' then
13933 log_message(p_msg_token1=>l_program_name||':'||g_event_id.COUNT||
13934 ' BC events did not have corr. gl_bc_packet records');
13935 End If;
13936
13937 If g_event_id.COUNT > 0 then -- COUNT
13938
13939 If g_debug_mode = 'Y' then
13940 log_message(p_msg_token1=>l_program_name||' Calling missing_records_failure');
13941 End If;
13942
13943 MISSING_RECORDS_FAILURE(p_pa_packet_id => l_pa_packet_id,
13944 p_gl_packet_id => x_packet_id,
13945 p_partial_flag => x_partial_flag,
13946 p_mode => x_mode);
13947
13948 g_event_id.DELETE;
13949 g_doc_dist_id.DELETE;
13950 g_document_type.DELETE;
13951
13952
13953 If x_partial_flag = 'N' then -- PARTIAL FLAG CHECK
13954
13955 -- Full mode failure ...
13956 x_result_code := 'F';
13957
13958 Elsif x_partial_flag = 'Y' then
13959
13960 -- Partial mode failure ..
13961 -- If all records have failed, set result code to 'F' so that
13962 -- FC will not proceed further .. (meaning after synch, it exists) ..
13963 Begin
13964
13965 select null -- null is ok ..
13966 into x_result_code
13967 from dual
13968 where exists
13969 (Select 1
13970 from pa_bc_packets
13971 where packet_id = l_pa_packet_id
13972 and status_code = 'I');
13973 Exception
13974 when no_data_found then
13975 x_result_code := 'F';
13976 End;
13977
13978 End If; -- PARTIAL FLAG CHECK
13979
13980 End if; --If g_event_id.COUNT > 0 then -- COUNT
13981
13982 End If; -- If nvl(x_result_code,'P') = 'F' then
13983
13984 -- ---------------------------------------------------------------------------------------------------------+
13985 If g_debug_mode = 'Y' then
13986 log_message(p_msg_token1=>l_program_name||':result code:'||x_result_code);
13987 log_message(p_msg_token1=>l_program_name||':If resultcode <> F then check if PA relieving created');
13988 End If;
13989 -- ---------------------------------------------------------------------------------------------------------+
13990 =============================================================================================================== */
13991
13992 If nvl(x_result_code,'P') <> 'F' then
13993
13994 Select DISTINCT pbc.bc_event_id,pbc.document_distribution_id,pbc.document_type
13995 BULK COLLECT into g_event_id,g_doc_dist_id,g_document_type
13996 from pa_bc_packets pbc
13997 where pbc.packet_id = l_pa_packet_id
13998 and pbc.status_code = 'I'
13999 and pbc.bc_event_id is not null
14000 and not exists (select glbc.source_distribution_id_num_1
14001 from gl_bc_packets glbc
14002 where glbc.packet_id = x_packet_id
14003 and (glbc.event_id = pbc.bc_event_id
14004 OR
14005 glbc.event_id = pbc.source_event_id)
14006 -- 2nd clause to take care of sep. line burdening
14007 and glbc.source_distribution_id_num_1 = pbc.document_distribution_id
14008 and (nvl(glbc.accounted_dr,0) - nvl(glbc.accounted_cr,0)) = -1 * (pbc.accounted_dr - pbc.accounted_cr)
14009 );
14010
14011 If g_debug_mode = 'Y' then
14012 log_message(p_msg_token1=>l_program_name||':'||g_event_id.COUNT||
14013 ' Distribution(s) missing PA relieving records');
14014 End If;
14015
14016 If g_event_id.COUNT > 0 then -- COUNT
14017
14018 If g_debug_mode = 'Y' then
14019 log_message(p_msg_token1=>l_program_name||' Calling missing_records_failure');
14020 End If;
14021
14022 MISSING_RECORDS_FAILURE(p_pa_packet_id => l_pa_packet_id,
14023 p_gl_packet_id => x_packet_id,
14024 p_partial_flag => x_partial_flag,
14025 p_mode => x_mode);
14026
14027 g_event_id.DELETE;
14028 g_doc_dist_id.DELETE;
14029 g_document_type.DELETE;
14030
14031 If x_partial_flag = 'N' then -- PARTIAL FLAG CHECK
14032
14033 -- Full mode failure ...
14034 x_result_code := 'F';
14035
14036 Elsif x_partial_flag = 'Y' then
14037
14038 -- Partial mode failure ..
14039 -- If all records have failed, set result code to 'F' so that
14040 -- FC will not proceed further .. (meaning after synch, it exists) ..
14041 Begin
14042
14043 select null -- null is ok ..
14044 into x_result_code
14045 from dual
14046 where exists
14047 (Select 1
14048 from pa_bc_packets
14049 where packet_id = l_pa_packet_id
14050 and status_code = 'I');
14051 Exception
14052 when no_data_found then
14053 x_result_code := 'F';
14054 End;
14055
14056 End If; -- PARTIAL FLAG CHECK
14057
14058 End if; --If g_event_id.COUNT > 0 then -- COUNT
14059
14060 End If; -- If nvl(x_result_code,'P') = 'F' then
14061 -- ---------------------------------------------------------------------------------------------------------+
14062
14063 -- B. Update pa_bc_packet data
14064
14065 SYNCH_DATA(p_pa_packet_id => l_pa_packet_id,
14066 p_gl_packet_id => x_packet_id);
14067
14068 End If;
14069
14070 If g_debug_mode = 'Y' then
14071 log_message(p_msg_token1=>l_program_name||'End:x_result_code:'||x_result_code);
14072 End If;
14073
14074 End Synch_pa_gl_packets;
14075
14076 -- --------------------------------------------------------------------------------+
14077 -- This procedure will mark gl_bc_packets records to a status such that GL does
14078 -- not execute funds available validation. Previously we used to create liquidation
14079 -- entries. Instead of that, we're executing the following procedure.
14080 -- This is for NO/SEPARATE LINE BURDENING only.
14081 -- This procedure is called from function pa_funds_check
14082 -- --------------------------------------------------------------------------------+
14083 /*
14084 PROCEDURE Mark_gl_bc_packets_for_no_fc (p_packet_id IN Number)
14085 IS
14086 -- At this point we should not check for result code ...
14087 Cursor c_bc_packet_id is
14088 select distinct pabc.project_id
14089 from pa_bc_packets pabc
14090 where pabc.packet_id = p_packet_id;
14091
14092 l_project_burden_method VARCHAR2(15);
14093
14094 Begin
14095 If g_debug_mode = 'Y' Then
14096 log_message(p_msg_token1 =>'In Mark_gl_bc_packets_for_no_fc - Start');
14097 End if;
14098
14099 for x in c_bc_packet_id loop
14100
14101 l_project_burden_method := pa_funds_control_pkg.check_bdn_on_sep_item(x.project_id);
14102
14103 If (l_project_burden_method <> 'DIFFERENT') then
14104
14105 Update gl_bc_packets glbc
14106 set status_code = 'P' -- Open Issue no 4 in DLD: Check if this is final ?????
14107 where glbc.rowid in
14108 (select pabc.gl_row_number
14109 from pa_bc_packets pabc
14110 where pabc.packet_id = p_packet_id
14111 and pabc.project_id = x.project_id
14112 and pabc.parent_bc_packet_id is null
14113 );
14114 End If;
14115 end loop;
14116
14117 If g_debug_mode = 'Y' Then
14118 log_message(p_msg_token1 =>'In Mark_gl_bc_packets_for_no_fc - End');
14119 End if;
14120
14121 End Mark_gl_bc_packets_for_no_fc;
14122 */
14123 -- --------------------------------------------------------------------------------+
14124 -- This procedure will determine whether funds check/ funds check tieback
14125 -- has been called for non-project related/project related txn. or budget
14126 -- funds check.
14127 -- p_return_code: 'NO_FC', For non-project related FC
14128 -- p_return_code: 'TXN_FC',For project related txn. (including 'RESERVE_BASELINE')
14129 -- p_return_code: 'BUD_FC',For SLA-BC budget baseline integration (GL FC)
14130 -- --------------------------------------------------------------------------------+
14131 PROCEDURE Check_txn_or_budget_fc(p_packet_id in number,
14132 p_return_code out NOCOPY varchar2)
14133 IS
14134 BEGIN
14135
14136 If g_debug_mode = 'Y' Then
14137 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc - Start');
14138 End if;
14139
14140 -- Code should first check txns. and then the global variables
14141 -- Reason: As during budget abseline, PA FC will be called 2 times,
14142 -- 1st time for txn. FC and the 2nd time for Account FC (by PSA)
14143 -- so, the 1st time , output should be 'TXN_FC' and the 2nd time 'BUD/REV_FC'
14144
14145 -- Check if its a "projects transaction" related FC
14146
14147 Select 'TXN_FC'
14148 into p_return_code
14149 from dual
14150 where exists
14151 (select 1 from pa_bc_packets
14152 where packet_id = p_packet_id);
14153
14154 If g_debug_mode = 'Y' Then
14155 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc:p_return_code'||p_return_code);
14156 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc - End');
14157 End If;
14158
14159 EXCEPTION
14160
14161 When no_data_found then
14162
14163 -- Is it a budget baseline /year-end/budget check funds related FC call ..
14164
14165 If nvl(pa_budget_fund_pkg.g_processing_mode,'FC') in ('YEAR_END','BASELINE','CHECK_FUNDS') then
14166
14167 p_return_code := 'BUD_FC';
14168
14169 Else
14170 -- This PA FC call is for "non-project" related txn.
14171 p_return_code := 'NO_FC';
14172
14173 End If;
14174
14175 If g_debug_mode = 'Y' Then
14176 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc:p_return_code'||p_return_code);
14177 log_message(p_msg_token1 =>'In Check_txn_or_budget_fc - End');
14178 End if;
14179
14180 END Check_txn_or_budget_fc;
14181
14182 -- --------------------------------------------------------------------------------+
14183 -- This procedure will be called from do_budget_baseline to fail pa_bc_packet
14184 -- records (by account and period) that fails account level validation or
14185 -- account level funds check. Procedure is AUTONOMOUS.
14186 -- --------------------------------------------------------------------------------+
14187 PROCEDURE Fail_bc_pkt_during_baseline(P_budget_version_id IN NUMBER,
14188 P_period_name IN g_tab_period_name%TYPE,
14189 P_budget_ccid IN g_tab_budget_ccid%TYPE,
14190 P_allow_flag IN g_tab_allow_flag%TYPE,
14191 P_result_code IN VARCHAR2)
14192 IS
14193 PRAGMA AUTONOMOUS_TRANSACTION;
14194 Begin
14195
14196 If P_result_code <> 'F170' then
14197
14198 Forall i in P_budget_ccid.FIRST..P_budget_ccid.LAST
14199 Update pa_bc_packets
14200 set status_code = 'R',
14201 result_code = P_result_code
14202 where budget_version_id = P_budget_version_id
14203 and budget_ccid = P_budget_ccid(i)
14204 and period_name = P_period_name(i)
14205 and P_allow_flag(i) = 'N';
14206
14207 Elsif P_result_code = 'F170' then
14208
14209 Update pa_bc_packets
14210 set status_code = 'R',
14211 result_code = 'F170'
14212 where budget_version_id = P_budget_version_id
14213 and status_code in ('P','A');
14214
14215 End If;
14216
14217 COMMIT;
14218
14219 End Fail_bc_pkt_during_baseline;
14220
14221 -- --------------------------------------------------------------------------------+
14222 -- This procedure will be called from do_budget_baseline to fail pa_budget_acct_lines
14223 -- pa_budget_acct_lines (by account and period) that fails account level validation
14224 -- or account level funds check. Procedure is AUTONOMOUS.
14225 -- --------------------------------------------------------------------------------+
14226 PROCEDURE Update_failure_in_acct_summary(P_budget_version_id IN NUMBER,
14227 P_period_name IN g_tab_period_name%TYPE,
14228 P_budget_ccid IN g_tab_budget_ccid%TYPE,
14229 P_allow_flag IN g_tab_allow_flag%TYPE,
14230 P_result_code IN VARCHAR2)
14231 IS
14232 PRAGMA AUTONOMOUS_TRANSACTION;
14233 Begin
14234
14235 If g_debug_mode = 'Y' then
14236 log_message(p_msg_token1=>'Update_failure_in_acct_summary:P_budget_version_id['||P_budget_version_id
14237 ||'], P_result_code['||P_result_code||']' );
14238 log_message(p_msg_token1=>'Update_failure_in_acct_summary: No of records to fail:'||P_budget_ccid.COUNT);
14239 End If;
14240
14241 Forall i in P_budget_ccid.FIRST..P_budget_ccid.LAST
14242 Update pa_budget_acct_lines
14243 set funds_check_status_code = 'R',
14244 funds_check_result_code = P_result_code
14245 where budget_version_id = P_budget_version_id
14246 and code_combination_id = P_budget_ccid(i)
14247 and gl_period_name = P_period_name(i)
14248 and P_allow_flag(i) = 'N'
14249 and P_budget_ccid(i) is not null;
14250 -- last condition is reqd. as zero$ lines will not be existing in draft ..
14251
14252 If g_debug_mode = 'Y' then
14253 log_message(p_msg_token1=>'Update_failure_in_acct_summary: Records Updated:'||SQL%ROWCOUNT);
14254 log_message(p_msg_token1=>'Update_failure_in_acct_summary: Fail other records with F170');
14255 End If;
14256
14257 Update pa_budget_acct_lines
14258 set funds_check_status_code = 'R',
14259 funds_check_result_code = 'F170'
14260 where budget_version_id = P_budget_version_id
14261 and nvl(funds_check_status_code,'P') <> 'R';
14262
14263 If g_debug_mode = 'Y' then
14264 log_message(p_msg_token1=>'Update_failure_in_acct_summary: Records Updated:'||SQL%ROWCOUNT);
14265 End If;
14266
14267 COMMIT;
14268
14269 End Update_failure_in_acct_summary;
14270
14271 -- --------------------------------------------------------------------------------+
14272 -- This procedure will be called from do_budget_baseline to update pa_bc_packet
14273 -- project_acct_result_code and result_code to 'P101' after account level funds
14274 -- check is successful. Procedure is AUTONOMOUS
14275 -- --------------------------------------------------------------------------------+
14276 PROCEDURE Upd_bc_pkt_acct_result_code(P_budget_version_id IN NUMBER)
14277 IS
14278 PRAGMA AUTONOMOUS_TRANSACTION;
14279 Begin
14280 Update pa_bc_packets
14281 set project_acct_result_code = 'P101',
14282 result_code = 'P101'
14283 where budget_version_id = P_budget_version_id;
14284
14285 If g_debug_mode = 'Y' then
14286 log_message(p_msg_token1=>l_program_name||'Upd_bc_pkt_acct_result_code records updated:'||SQL%ROWCOUNT);
14287 End If;
14288
14289 COMMIT;
14290 End Upd_bc_pkt_acct_result_code;
14291
14292 -- --------------------------------------------------------------------------------+
14293 -- Procedure Update_budget_ccid updates budget_ccid on the pa_bc_packet records
14294 -- for this baseline, its an AUTONOMOUS procedure ..
14295 -- --------------------------------------------------------------------------------+
14296 PROCEDURE Update_budget_ccid(P_budget_version_id IN NUMBER,
14297 P_budget_ccid IN g_tab_budget_ccid%TYPE,
14298 P_budget_line_id IN g_tab_budget_line_id%TYPE,
14299 P_budget_entry_level_code IN VARCHAR2,
14300 P_period_name IN g_tab_period_name%TYPE,
14301 P_rlmi IN g_tab_rlmi%TYPE,
14302 P_task_id IN g_tab_task_id%TYPE,
14303 P_derived_ccid IN g_tab_budget_ccid%TYPE,
14304 P_allowed_flag IN g_tab_allow_flag%TYPE,
14305 P_result_code IN OUT NOCOPY VARCHAR2)
14306
14307 IS
14308 PRAGMA AUTONOMOUS_TRANSACTION;
14309 Begin
14310
14311 -- ------------------------------------------------------------------------------------+
14312 If g_debug_mode = 'Y' then
14313 log_message(p_msg_token1=>'Update_budget_ccid: p_budget_entry_level_code['
14314 ||p_budget_entry_level_code||'] Null->Update new CCID else Synch' );
14315 End If;
14316 -- ------------------------------------------------------------------------------------+
14317
14318 p_result_code := 'F';
14319
14320 If p_budget_entry_level_code is NULL then
14321
14322
14323 Forall x in p_derived_ccid.FIRST..p_derived_ccid.LAST
14324 Update pa_bc_packets pbc
14325 set pbc.budget_ccid = p_derived_ccid(x)
14326 where pbc.budget_ccid = p_budget_ccid(x)
14327 and pbc.period_name = p_period_name(x)
14328 and p_allowed_flag(x) = 'Y';
14329
14330 Else
14331
14332 If p_budget_entry_level_code = 'P' then
14333
14334 Forall i in p_budget_ccid.FIRST..p_budget_ccid.LAST
14335 Update pa_bc_packets pbc
14336 set pbc.budget_ccid = p_budget_ccid(i),
14337 pbc.budget_line_id = p_budget_line_id(i)
14338 where pbc.budget_version_id = p_budget_version_id
14339 and pbc.bud_resource_list_member_id = p_rlmi(i)
14340 and pbc.period_name = p_period_name(i);
14341
14342 ElsIf p_budget_entry_level_code in ('L','T','M') then
14343
14344 Forall i in p_budget_ccid.FIRST..p_budget_ccid.LAST
14345 Update pa_bc_packets pbc
14346 set pbc.budget_ccid = p_budget_ccid(i),
14347 pbc.budget_line_id = p_budget_line_id(i)
14348 where pbc.budget_version_id = p_budget_version_id
14349 and pbc.bud_task_id = p_task_id(i)
14350 and pbc.bud_resource_list_member_id = p_rlmi(i)
14351 and pbc.period_name = p_period_name(i);
14352 End If;
14353
14354 End If;
14355
14356 -- ------------------------------------------------------------------------------------+
14357 If g_debug_mode = 'Y' then
14358 log_message(p_msg_token1=>'Update_budget_ccid on pa_bc_packets:Budget_ccid updated on:'
14359 || SQL%ROWCOUNT||' records');
14360 End If;
14361 -- ------------------------------------------------------------------------------------+
14362
14363 Update pa_bc_packets pbc
14364 set pbc.result_code = 'F132',
14365 pbc.status_code = 'R'
14366 where pbc.budget_version_id = p_budget_version_id
14367 and pbc.budget_ccid is null;
14368
14369 -- ------------------------------------------------------------------------------------+
14370 If g_debug_mode = 'Y' then
14371 log_message(p_msg_token1=>'Update_budget_ccid on pa_bc_packets:'
14372 ||' Records with null ccid'||SQL%ROWCOUNT||' If >0 then F132');
14373 End If;
14374 -- ------------------------------------------------------------------------------------+
14375
14376 If SQL%ROWCOUNT > 0 then
14377 p_result_code := 'F';
14378 End if;
14379
14380 COMMIT;
14381 p_result_code := 'S';
14382
14383 Exception
14384
14385 When others then
14386 COMMIT;
14387 p_result_code := 'F';
14388 End Update_budget_ccid;
14389
14390 -- --------------------------------------------------------------------------------+
14391 -- This procedure will check if there exists any txn. against the project
14392 -- It will return 'Y' if any txn exists
14393 -- --------------------------------------------------------------------------------+
14394 Procedure Any_txns_against_project(p_project_id IN NUMBER,
14395 p_txn_exists_in_bc_pkt OUT NOCOPY VARCHAR2,
14396 p_txn_exists_in_bc_cmt OUT NOCOPY VARCHAR2)
14397 IS
14398 Begin
14399 If g_debug_mode = 'Y' then
14400 log_message(p_msg_token1=>'Any_txns_against_project:p_project_id:'||p_project_id);
14401 End If;
14402
14403 If (pa_budget_fund_pkg.g_processing_mode in ('BASELINE','CHECK_FUNDS') and pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y') then
14404
14405 If g_debug_mode = 'Y' then
14406 log_message(p_msg_token1=>'Any_txns_against_project:Baseline/CF Mode-Check if txns. exists in pa_bc_packets');
14407 End If;
14408
14409 Begin
14410 Select 'Y' into p_txn_exists_in_bc_pkt from dual where exists
14411 (select 1 from pa_bc_packets where project_id = p_project_id and status_code in ('A','P','I'));
14412 Exception
14413 When no_data_found then
14414 p_txn_exists_in_bc_pkt := 'N';
14415 End;
14416
14417 If g_debug_mode = 'Y' then
14418 log_message(p_msg_token1=>'Any_txns_against_project:Baseline/CF Mode-Check if txns. exists in pa_bc_commitments');
14419 End If;
14420
14421 Begin
14422 Select 'Y' into p_txn_exists_in_bc_cmt from dual where exists
14423 (select 1 from pa_bc_commitments where project_id = p_project_id);
14424 Exception
14425 When no_data_found then
14426 p_txn_exists_in_bc_cmt := 'N';
14427 End;
14428
14429 Else
14430 p_txn_exists_in_bc_pkt := 'N';
14431 p_txn_exists_in_bc_cmt := 'N';
14432 End if;
14433
14434 End Any_txns_against_project;
14435
14436 -- --------------------------------------------------------------------------------+
14437 -- This procedure will execute the budget account validation, account level FC
14438 -- and update budget lines with the new derived accounts, call PROCEDURE
14439 -- Build_account_summary to build pa_budget_acct_lines
14440 -- Parameters:
14441 -- p_packet_id : packet being funds checked
14442 -- p_return_status : 'S' for success and 'F' for failure
14443 -- --------------------------------------------------------------------------------+
14444 PROCEDURE Do_budget_baseline_tieback(p_packet_id IN NUMBER,
14445 p_return_status OUT NOCOPY VARCHAR2)
14446 IS
14447 t_ccid pa_plsql_datatypes.Idtabtyp;
14448 t_bud_ccid pa_plsql_datatypes.Idtabtyp;
14449 t_budget_line_id pa_plsql_datatypes.Idtabtyp;
14450 t_rlmi pa_plsql_datatypes.Idtabtyp;
14451 t_parent_rlmi pa_plsql_datatypes.Idtabtyp;
14452 t_project_id pa_plsql_datatypes.Idtabtyp;
14453 t_task_id pa_plsql_datatypes.Idtabtyp;
14454 t_top_task_id pa_plsql_datatypes.Idtabtyp;
14455 t_prev_ver_ccid pa_plsql_datatypes.Idtabtyp;
14456 t_start_date pa_plsql_datatypes.Datetabtyp;
14457 t_txn_currency_code pa_plsql_datatypes.char50TabTyp;
14458 t_draft_needs_update pa_plsql_datatypes.char50TabTyp;
14459 t_draft_budget_rowid rowidtabtyp;
14460 t_draft_ccid pa_plsql_datatypes.Idtabtyp;
14461 t_raid TypeNum;
14462 t_gl_rowid rowidtabtyp;
14463 t_budget_rowid rowidtabtyp;
14464 t_budget_start_date TypeDate;
14465 l_bvid_for_acct_changed_API pa_budget_versions.budget_Version_id%type;
14466
14467 l_count NUMBER(4);
14468 l_validation_failed VARCHAR2(1);
14469 l_set_of_books_id pa_implementations_all.set_of_books_id%type;
14470 l_budget_entry_level_code pa_budget_entry_methods.entry_level_code%TYPE;
14471 l_current_budget_version_id pa_budget_versions.budget_version_id%TYPE;
14472 l_draft_budget_version_id pa_budget_versions.budget_version_id%TYPE;
14473 l_result_code pa_bc_packets.result_code%TYPE;
14474 l_acct_changed VARCHAR2(1);
14475 l_draft_acct_changed_flag VARCHAR2(1);
14476 l_record_updated_flag VARCHAR2(1);
14477 l_project_id pa_budget_versions.project_id%type;
14478 l_txn_exists_bc_pkt_flag VARCHAR2(1);
14479 l_txn_exists_bc_cmt_flag VARCHAR2(1);
14480 l_gl_failure_flag VARCHAR2(1);
14481 l_derive_draft_values VARCHAR2(1);
14482
14483 -- Step 2.0: Synch budget lines and pa_bc_packets ....
14484 Cursor c_acct_sync_bud_line_pa_bc_pkt(p_budget_version_id in NUMBER,
14485 p_set_of_books_id IN NUMBER,
14486 p_project_id IN NUMBER) is
14487 select pbl.code_combination_id,
14488 pbl.budget_line_id,
14489 pra.resource_list_member_id,
14490 pra.task_id,
14491 pbl.period_name --glps.period_name
14492 from pa_budget_lines pbl,
14493 pa_resource_assignments pra--,
14494 --gl_period_statuses glps
14495 where pra.budget_version_id = p_budget_version_id
14496 and pra.project_id = p_project_id -- added to improve performance ..
14497 and pra.budget_version_id = pbl.budget_version_id
14498 and pra.resource_assignment_id = pbl.resource_assignment_id;
14499 --and glps.application_id = 101
14500 --and glps.set_of_books_id = p_set_of_books_id
14501 --and trunc(pbl.start_date) = trunc(glps.start_date)
14502 --and exists (select 1
14503 -- from pa_bc_packets pbc
14504 -- where pbc.budget_version_id = pbl.budget_version_id
14505 -- and pbc.resource_list_member_id = pra.resource_list_member_id
14506 -- and (pra.task_id = pbc.task_id OR
14507 -- pra.task_id = pbc.top_task_id OR
14508 -- pra.task_id = 0)
14509 -- and glps.period_name = pbc.period_name
14510 -- );
14511
14512 -- Step 3.0: Identify records that have failed in gl_bc_packets ..
14513 Cursor c_gl_failure(p_budget_version_id in number) is
14514 select pbl.code_combination_id budget_ccid,
14515 pbl.period_name period_name,
14516 'N' allow_flag ,
14517 pra.project_id,
14518 pra.task_id,
14519 pra.resource_list_member_id rlmi,
14520 pbl.start_date,
14521 pbl.txn_currency_code
14522 from gl_bc_packets glbc,
14523 pa_budget_lines pbl,
14524 pa_resource_assignments pra
14525 where glbc.packet_id = p_packet_id
14526 and pbl.budget_version_id = p_budget_version_id
14527 and pbl.budget_line_id = glbc.source_distribution_id_num_1
14528 and substr(nvl(glbc.result_code,'P'),1,1) = 'F'
14529 and pra.resource_assignment_id = pbl.resource_assignment_id
14530 and pra.budget_version_id = pbl.budget_version_id;
14531 --and nvl(glbc.result_code,'P) <> 'F35';
14532
14533 -- Step 4.0: This cursor is used to synch account data between gl_bc_packets and the budget ..
14534 Cursor c_budget_lines_synch(p_budget_version_id in number) is
14535 select glbc.code_combination_id sla_ccid,
14536 glbc.rowid gl_rowid,
14537 pbl.code_combination_id budget_ccid,
14538 pbl.resource_assignment_id budget_raid,
14539 pbl.rowid budget_rowid,
14540 pbl.start_date start_date,
14541 pbl.period_name period_name,
14542 'Y' allow_flag,
14543 pbl.budget_line_id budget_line_id,
14544 pbl.txn_currency_code txn_currency_code,
14545 'N' draft_needs_update,
14546 pra.project_id,
14547 pra.task_id,
14548 pra.resource_list_member_id,
14549 nvl(prlm.parent_member_id,-99) parent_rlmi
14550 from gl_bc_packets glbc,
14551 pa_budget_lines pbl,
14552 pa_resource_assignments pra,
14553 pa_resource_list_members prlm
14554 where glbc.packet_id = p_packet_id
14555 and pbl.budget_version_id = p_budget_version_id
14556 and pbl.budget_line_id = glbc.source_distribution_id_num_1
14557 and pra.resource_assignment_id = pbl.resource_assignment_id
14558 and pra.budget_version_id = pbl.budget_version_id
14559 and prlm.resource_list_member_id = pra.resource_list_member_id;
14560 --and nvl(pbl.code_combination_id,-1) <> glbc.code_combination_id;
14561
14562 -- Above commented as user could have changed draft account and then modified
14563 -- SLA setup to derive the same account ..meaning..we need to compare ccids across version ..
14564
14565 -- Step 7.0: Cursor used for account level funds check
14566 -- Logic:
14567 -- Get the distinct ccid/start/end date combo from pa_bc_packets and for that check if there
14568 -- are any combo having sum(available amount) < 0
14569
14570 Cursor c_acct_lines(p_current_bvid IN NUMBER) is
14571 select pbl.gl_period_name, pbl.code_combination_id ,'N' allow_flag
14572 from pa_budget_acct_lines pbl
14573 where (pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date) in
14574 (select pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date
14575 from pa_budget_acct_lines pbl
14576 where (pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date) in
14577 (select distinct a.budget_version_id,a.budget_ccid,a.fc_start_date,a.fc_end_date
14578 from pa_bc_packets a
14579 where a.budget_version_id = p_current_bvid)
14580 group by pbl.budget_version_id,pbl.code_combination_id,pbl.start_date,pbl.end_date
14581 having sum(nvl(pbl.Curr_Ver_Available_Amount,0)) < 0
14582 )
14583 UNION
14584 -- Bug 5206341 : Cursor to validate account level balances for Open and Closed periods
14585 select pbl.gl_period_name, pbl.code_combination_id ,'N' allow_flag
14586 from pa_budget_acct_lines pbl
14587 where (pbl.budget_version_id,pbl.code_combination_id) in
14588 (select pbl.budget_version_id,pbl.code_combination_id
14589 from pa_budget_acct_lines pbl
14590 where pbl.budget_version_id = p_current_bvid
14591 group by pbl.budget_version_id,pbl.code_combination_id
14592 having sum(nvl(pbl.Curr_Ver_Available_Amount,0)) < 0
14593 )
14594 AND PA_FUNDS_CONTROL_UTILS.CLOSED_PERIODS_EXISTS_IN_BUDG(p_current_bvid) ='Y' ;
14595
14596 --and pbl.Curr_Ver_Available_Amount < 0;
14597 -- Draft has Jan and txn for Dec.. YTD/Y, in that case, Jan should have failure too
14598
14599 -- 10.0: Cursor used to select records to fail all records ....
14600 -- As data split between packet, records were not being failed in the credit packet ..
14601 Cursor c_gl_records is
14602 select glbc.rowid,glbc.ae_header_id,glbc.ledger_id
14603 from gl_bc_packets glbc
14604 where glbc.event_id in
14605 (select event_id from psa_bc_xla_events_gt);
14606
14607 l_dummy_value number(1);
14608
14609 Begin
14610
14611 l_program_name := 'Do_Budget_baseline_tieback:';
14612 If g_debug_mode = 'Y' then
14613 log_message(p_msg_token1=>l_program_name||'Start');
14614 End If;
14615
14616 /* If CC Logic needs to be added then we will need to have some sort of outer
14617 loop which will exeute for Cost and CC budget
14618 */
14619 -- ---------------------------------------------------------------------------+
14620 -- 0.0: Is the call for the current version?? if not exit
14621 -- Reason: BC calls PAFC 2 times as the packets are created per entity_id
14622 -- So: During a CF after baseline or re-baseline, 2 packets will be
14623 -- created, for the reversing packet, we should not do any processing
14624 -- Account check etc. is not reqd. for the reversing as we use
14625 -- 'LINE REVERSALS'
14626 -- ---------------------------------------------------------------------------+
14627 log_message(p_msg_token1=>l_program_name||'Check if PAFC called for current version');
14628
14629 l_dummy_value := 0;
14630
14631 Begin
14632
14633 Select 1 into l_dummy_value from dual
14634 where exists (Select 1
14635 from gl_bc_packets glbc,
14636 pa_budget_lines pbl
14637 where glbc.packet_id = p_packet_id
14638 and pbl.budget_version_id = pa_budget_fund_pkg.g_cost_current_bvid
14639 and pbl.budget_line_id = glbc.source_distribution_id_num_1);
14640
14641 Exception
14642 When no_data_found then
14643 null;
14644 End;
14645
14646 If l_dummy_value = 0 then
14647 If g_debug_mode = 'Y' then
14648 log_message(p_msg_token1=>l_program_name||'PA FC called for prev. baselined version');
14649 End If;
14650
14651 g_packet_credit_processed := 'Y';
14652
14653 If g_packet_debit_processed = 'Y' then
14654 log_message(p_msg_token1=>l_program_name||': As debit already processed Calling Fail_credit_packet');
14655 FAIL_CREDIT_PACKET(p_input_packet => 'CREDIT',
14656 p_return_status_code => p_return_status);
14657 End if;
14658
14659 RETURN;
14660 End If;
14661
14662 If g_debug_mode = 'Y' then
14663 l_program_name := 'Do_budget_baseline_tieback';
14664 log_message(p_msg_token1=>l_program_name||'PA FC called for latest version - Draft/Baselined');
14665 End If;
14666
14667 -- ---------------------------------------------------------------------------+
14668 -- 1.0: Initalize variables ..
14669 -- ---------------------------------------------------------------------------+
14670 -- 1.1: Return Status: If all steps pass, send 'S', else send 'F'
14671 p_return_status := 'S';
14672
14673 -- 1.2: initalize limit var. used for bulk ..
14674 l_limit := 500;
14675
14676 -- 1.3: Get latest budget version being baselined
14677 l_current_budget_version_id := pa_budget_fund_pkg.g_cost_current_bvid;
14678
14679 -- 1.4: Get draft version ...
14680 -- This is required to udpate the account summary table (we will be updating acct.
14681 -- summary table for the draft version, except for 'Year end' where we will be updating
14682 -- the working budget created ..
14683
14684 If g_debug_mode = 'Y' then
14685 log_message(p_msg_token1=>l_program_name||'Get Draft Budget');
14686 End If;
14687
14688 --If (pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y') then
14689 If pa_budget_fund_pkg.g_processing_mode in ('YEAR_END','BASELINE') then
14690
14691 -- Get the draft or working budget ..
14692
14693 Select pbv.budget_version_id
14694 into l_draft_budget_version_id
14695 from pa_budget_versions pbv
14696 where (pbv.project_id,pbv.budget_type_code) in
14697 (select project_id,budget_type_code
14698 from pa_budget_versions
14699 where budget_version_id = l_current_budget_version_id)
14700 and pbv.budget_status_code = decode(pa_budget_fund_pkg.g_processing_mode,
14701 'YEAR_END','W','S');
14702
14703 If g_debug_mode = 'Y' then
14704 log_message(p_msg_token1=>l_program_name||'Yr End/Base Draft Budget:'||l_draft_budget_version_id);
14705 End If;
14706
14707 End If;
14708
14709 -- End If;
14710
14711
14712 If pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS' then
14713
14714 l_draft_budget_version_id := l_current_budget_version_id;
14715
14716 If g_debug_mode = 'Y' then
14717 log_message(p_msg_token1=>l_program_name||'CF Draft Budget:'||l_draft_budget_version_id);
14718 End If;
14719
14720 End If;
14721
14722 -- 1.5: Derive budget entry level code
14723 If (pa_budget_fund_pkg.g_balance_type = 'E' /*Top Down*/ and
14724 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' ) then
14725
14726 If g_debug_mode = 'Y' then
14727 log_message(p_msg_token1=>l_program_name||'Get Budget Entry Method');
14728 End If;
14729
14730 select pbem.entry_level_code
14731 into l_budget_entry_level_code
14732 from pa_budget_entry_methods pbem,
14733 pa_budget_versions pbv
14734 where pbv.budget_version_id = l_current_budget_version_id
14735 and pbem.budget_entry_method_code = pbv.budget_entry_method_code;
14736
14737 End If;
14738
14739 If g_debug_mode = 'Y' then
14740 log_message(p_msg_token1=>l_program_name||':g_processing_mode:'||pa_budget_fund_pkg.g_processing_mode||
14741 ':Balance type:'||pa_budget_fund_pkg.g_balance_type||
14742 ':Budget Amount Code:'||pa_budget_fund_pkg.g_budget_amount_code||
14743 ':Rebaseline Flag:'||pa_budget_fund_pkg.g_cost_rebaseline_flag);
14744
14745 log_message(p_msg_token1=>l_program_name||':Current budget version:'||l_current_budget_version_id||
14746 ':Draft version:'||l_draft_budget_version_id||':budget entry level code:' || l_budget_entry_level_code);
14747 End If;
14748
14749 -- 1.6: Reset funds_check_status_code and funds_check_result_code for the draft version
14750 -- in check funds mode.
14751 -- Reason: if the last check funds had failed then the failure codes should be nullified
14752 -- 1/14/06: this is reqd. for baseline too..so that it can override the
14753 -- existing status ... if there is any failure ..
14754 -- 8/22/06: This step should be carried out for CF/baseline/rebaseline for E/B balance_type
14755 -- Failures can happen for first time baseline and also for bottom up budgets too
14756
14757 --If ((pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') or
14758 --(pa_budget_fund_pkg.g_balance_type = 'E' and -- Top Down
14759 -- pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and -- Re-costing
14760 -- pa_budget_fund_pkg.g_processing_mode = 'BASELINE')
14761 --then
14762
14763 If (pa_budget_fund_pkg.g_processing_mode in ('CHECK_FUNDS','BASELINE')) then
14764
14765 If g_debug_mode = 'Y' then
14766 --log_message(p_msg_token1=>l_program_name||'Nullify failure status from draft version - Check funds');
14767 log_message(p_msg_token1=>l_program_name||' Rebuild Draft summary');
14768 -- this is reqd. for the scenario where the user has modified the draft version budget line and after that we
14769 -- the user had created txn. for the baseline version which has a diff acct.
14770 -- In this case, draft. budget line can have acct. A2 and summary will have A1 ..
14771 End If;
14772
14773 --RESET_STATUS_CODE_ON_SUMMARY(l_draft_budget_version_id);
14774 BUILD_ACCOUNT_SUMMARY_AUTO(x_budget_version_id => l_draft_budget_version_id,
14775 x_balance_type =>pa_budget_fund_pkg.g_balance_type,
14776 x_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
14777 x_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid,
14778 x_mode=>'PASS');
14779
14780 -- Autonomous used as we're updating pa_budget_acct_lines in AUTONOMOUS
14781 -- mode for failures later ..
14782 End If;
14783
14784 -- 1.7: Initalize l_acct_changed
14785 l_acct_changed := 'N';
14786 l_draft_acct_changed_flag := 'N';
14787 l_record_updated_flag := 'N';
14788
14789 -- 1.8: Get project_id
14790 If g_debug_mode = 'Y' then
14791 l_program_name := 'Do_budget_baseline_tieback';
14792 log_message(p_msg_token1=>l_program_name||'Get Project Id');
14793 End If;
14794
14795 select project_id into l_project_id from pa_budget_versions
14796 where budget_version_id = l_current_budget_version_id;
14797
14798 -- 1.9: If processing mode is BASELINE (and its a rebaseline, check if there are
14799 -- txns. against the project, if yes, set flag to 'Y' else 'N')
14800 -- This flag will be used further in the code to minimize code being
14801 -- executed ..this will improve performance ..
14802 -- Note: project_id being used as there is an index on project_id alone ..
14803
14804 l_txn_exists_bc_pkt_flag := 'N';
14805 l_txn_exists_bc_cmt_flag := 'N';
14806
14807 -- 8/22: This should fire for re-baseline/top-down only ..
14808 If (pa_budget_fund_pkg.g_balance_type = 'E' and -- Top Down
14809 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y') --and -- Re-costing
14810 --pa_budget_fund_pkg.g_processing_mode = 'BASELINE')
14811 then
14812
14813 ANY_TXNS_AGAINST_PROJECT(p_project_id => l_project_id,
14814 p_txn_exists_in_bc_pkt => l_txn_exists_bc_pkt_flag,
14815 p_txn_exists_in_bc_cmt => l_txn_exists_bc_cmt_flag);
14816
14817 End If;
14818
14819 If g_debug_mode = 'Y' then
14820 l_program_name := 'Do_budget_baseline_tieback';
14821 log_message(p_msg_token1=>l_program_name||'l_txn_exists_bc_pkt_flag ['||l_txn_exists_bc_pkt_flag||
14822 '] l_txn_exists_bc_cmt_flag ['||l_txn_exists_bc_cmt_flag||']');
14823 End If;
14824
14825 -- ------------------------- END STEP 1 --------------------------------------+
14826
14827 -- ---------------------------------------------------------------------------+
14828 -- 2.0 : Update budget_ccid and budget_line_id on pa_bc_packets . Ccid being
14829 -- calculated here as during the regular flow the zero $ lines created
14830 -- during baseline are not visible ...
14831 -- Call procedure update_budget_ccid, this has to be autonomous ...
14832 -- ---------------------------------------------------------------------------+
14833 If (pa_budget_fund_pkg.g_balance_type = 'E' and -- Top Down
14834 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and -- Re-costing
14835 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and -- Baseline
14836 l_txn_exists_bc_pkt_flag = 'Y') -- Txn. exists against the project
14837 then -- (2.0 Main If)
14838
14839 -- Get set of books
14840 If g_debug_mode = 'Y' then
14841 log_message(p_msg_token1=>l_program_name||'Get Set of Books');
14842 End If;
14843
14844 select set_of_books_id into l_set_of_books_id from pa_implementations;
14845
14846 -- Update budget lines on pa_bc_packets ..
14847 If g_debug_mode = 'Y' then
14848 log_message(p_msg_token1=>l_program_name||'Update budget info. on pa_bc_packets');
14849 End If;
14850
14851 open c_acct_sync_bud_line_pa_bc_pkt(l_current_budget_version_id, l_set_of_books_id,l_project_id);
14852 loop
14853 fetch c_acct_sync_bud_line_pa_bc_pkt BULK COLLECT into g_tab_budget_ccid,
14854 g_tab_budget_line_id,
14855 g_tab_rlmi,
14856 g_tab_task_id,
14857 g_tab_period_name
14858 LIMIT l_limit;
14859
14860 If g_tab_budget_ccid.exists(1) then
14861
14862 -- Update Budget ccid and budget line id on pa_bc_packets .. AUTONOMOUS
14863
14864 Update_budget_ccid(P_budget_version_id => l_current_budget_version_id,
14865 P_budget_ccid => g_tab_budget_ccid,
14866 P_budget_line_id => g_tab_budget_line_id,
14867 P_budget_entry_level_code => l_budget_entry_level_code,
14868 P_period_name => g_tab_period_name,
14869 P_rlmi => g_tab_rlmi,
14870 P_task_id => g_tab_task_id,
14871 P_derived_ccid => t_ccid,
14872 P_allowed_flag => g_tab_allow_flag,
14873 P_result_code => P_return_status);
14874
14875 -- Note: Above t_ccid and g_tab_allow_flag are null pl/sql tables ..
14876
14877 -- Initalize variables ..
14878 g_tab_budget_ccid.DELETE;
14879 g_tab_budget_line_id.DELETE;
14880 g_tab_rlmi.DELETE;
14881 g_tab_task_id.DELETE;
14882 g_tab_period_name.DELETE;
14883
14884 Else
14885 EXIT; -- Exit Loop
14886 End If;
14887
14888 End Loop; -- c_acct_sync_bud_line_pa_bc_pkt
14889
14890 Close c_acct_sync_bud_line_pa_bc_pkt;
14891
14892 If g_debug_mode = 'Y' then
14893 l_program_name := 'Do_budget_baseline_tieback';
14894 log_message(p_msg_token1=>l_program_name||'Update_budget_ccid complete, status is:'||p_return_status);
14895 End If;
14896
14897 End If; -- (2.0 Main If)
14898 -- ------------------------- END STEP 2 --------------------------------------+
14899
14900 -- -------------------------- STEP 3 -----------------------------------------+
14901 -- If GL failed, fail pa_bc_packets and Summary acct (draft version)
14902 -- pa_bc_packets failed for Top-Down/Re-Baseline ..
14903 -- Acct. summary failed for all ...
14904 -- ----------------------------------------------------------------------------+
14905 If g_debug_mode = 'Y' then
14906 log_message(p_msg_token1=>l_program_name||':Check if any GL records failed');
14907 End If;
14908
14909 Begin
14910
14911 Select 'Y' into l_gl_failure_flag from dual where exists
14912 (select 1 from gl_bc_packets
14913 where packet_id = p_packet_id
14914 and substr(nvl(result_code,'P'),1,1) = 'F');
14915 Exception
14916 When no_data_found then
14917 l_gl_failure_flag := 'N';
14918 End;
14919
14920 If g_debug_mode = 'Y' then
14921 log_message(p_msg_token1=>l_program_name||':l_gl_failure_flag:'||l_gl_failure_flag);
14922 End If;
14923
14924 If (P_return_status = 'S' and l_gl_failure_flag = 'Y') then
14925
14926 If g_debug_mode = 'Y' then
14927 log_message(p_msg_token1=>l_program_name||':Inside GL failure if condition');
14928 End If;
14929
14930 -- ## Get the budget lines where account has changed
14931 Open c_gl_failure(l_current_budget_version_id);
14932 loop
14933 fetch c_gl_failure BULK COLLECT into t_bud_ccid,
14934 g_tab_period_name,
14935 g_tab_allow_flag,
14936 t_project_id,
14937 t_task_id,
14938 t_rlmi,
14939 t_start_date,
14940 t_txn_currency_code
14941 LIMIT l_limit;
14942
14943
14944 If t_bud_ccid.exists(1) then
14945
14946 -- ----------------------------------------------------------------------------------+
14947 -- ## There are records to process ..
14948 If g_debug_mode = 'Y' then
14949 log_message(p_msg_token1=>l_program_name||': GL failed case exists');
14950 End If;
14951 -- ----------------------------------------------------------------------------------+
14952
14953 If (pa_budget_fund_pkg.g_balance_type = 'E' and
14954 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
14955 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
14956 l_txn_exists_bc_pkt_flag = 'Y') then
14957 -- ----------------------------------------------------------------------------------+
14958 -- ## Fail pa_bc_packets:
14959 If g_debug_mode = 'Y' then
14960 log_message(p_msg_token1=>l_program_name||': GL failed - Fail pa_bc_packets');
14961 End If;
14962 -- ----------------------------------------------------------------------------------+
14963
14964 -- Autonomous procedure called for update ...these are the records that
14965 -- has already passed PA FC but now needs to be failed ...
14966
14967 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
14968 P_period_name => g_tab_period_name,
14969 P_budget_ccid => t_bud_ccid,
14970 P_allow_flag => g_tab_allow_flag,
14971 P_result_code => 'F155');
14972 End If;
14973
14974 -- ----------------------------------------------------------------------------------+
14975 -- ## Fail draft account summary ..
14976 If g_debug_mode = 'Y' then
14977 l_program_name := 'Do_budget_baseline_tieback';
14978 log_message(p_msg_token1=>l_program_name||': GL failed - Fail account summary');
14979 End If;
14980 -- ----------------------------------------------------------------------------------+
14981 -- Update Draft version (account summary table) to failure ..
14982 -- Note: in case of 'Year End' the working budget will be updated ..
14983
14984 If pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS' then
14985 l_result_code := 'F150';
14986 Else
14987 l_result_code := 'F155';
14988 End If;
14989
14990 -- If the mode is not CF then the account derived may be different than that on CF
14991 -- so, we need to derive the account that exists on the draft version ..
14992 -- else issue was that baseline had acct A2 and draft had A1 and then the call
14993 -- to UPDATE_FAILURE_IN_ACCT_SUMMARY would not udpate any records ...
14994
14995 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
14996
14997 If g_debug_mode = 'Y' then
14998 log_message(p_msg_token1=>l_program_name||': Derive draft ccid');
14999 End If;
15000
15001 for x in t_project_id.FIRST..t_project_id.LAST loop
15002 Begin
15003 select code_combination_id draft_ccid
15004 into t_draft_ccid(x)
15005 from pa_budget_lines bl,
15006 pa_resource_assignments pra
15007 where pra.budget_version_id = l_draft_budget_version_id
15008 and pra.project_id = t_project_id(x)
15009 and pra.task_id = t_task_id(x)
15010 and pra.resource_list_member_id = t_rlmi(x)
15011 and bl.resource_assignment_id = pra.resource_assignment_id
15012 and bl.start_date = t_start_date(x)
15013 and bl.txn_currency_code = t_txn_currency_code(x);
15014
15015
15016 Exception
15017 When no_data_found then
15018 t_draft_ccid(x) := null;
15019 End;
15020 end loop;
15021
15022 End If;
15023
15024 If g_debug_mode = 'Y' then
15025 log_message(p_msg_token1=>l_program_name||': Update failure in draft acct. summary');
15026 End If;
15027
15028 -- ----------------------------------------------------------------------------------+
15029 -- Following if condition is required as t_draft_ccid is calcualted for non-CF mode only ...
15030 -- as for CF mode, t_bud_ccid is the draft ccid ...
15031 -- ----------------------------------------------------------------------------------+
15032 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
15033
15034 If g_debug_mode = 'Y' then
15035 log_message(p_msg_token1=>l_program_name||': <> CF, Calling Update_failure_in_acct_summary');
15036 End If;
15037
15038 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15039 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15040 P_period_name => g_tab_period_name,
15041 P_budget_ccid => t_draft_ccid,
15042 P_allow_flag => g_tab_allow_flag,
15043 P_result_code => l_result_code);
15044 Else
15045
15046 If g_debug_mode = 'Y' then
15047 log_message(p_msg_token1=>l_program_name||': = CF, Calling Update_failure_in_acct_summary');
15048 End If;
15049
15050 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15051 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15052 P_period_name => g_tab_period_name,
15053 P_budget_ccid => t_bud_ccid,
15054 P_allow_flag => g_tab_allow_flag,
15055 P_result_code => l_result_code);
15056 End If;
15057
15058
15059
15060 -- ----------------------------------------------------------------------------------+
15061 -- ## Set failure status ..
15062 -- ----------------------------------------------------------------------------------+
15063 p_return_status := 'F';
15064
15065 Else
15066 EXIT; -- Exit Loop
15067 End If; -- If t_bud_ccid(1).exists
15068
15069 -- ## Initialize ..
15070 t_bud_ccid.DELETE;
15071 g_tab_period_name.DELETE;
15072 g_tab_allow_flag.DELETE;
15073 t_project_id.DELETE;
15074 t_task_id.DELETE;
15075 t_rlmi.DELETE;
15076 t_start_date.DELETE;
15077 t_txn_currency_code.DELETE;
15078
15079 if t_draft_ccid.exists(1) then t_draft_ccid.DELETE; end if;
15080
15081 End Loop;
15082
15083 close c_gl_failure;
15084 -- -------------------------------------------------------------------------------------------------------+
15085 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15086 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
15087 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15088 p_return_status = 'F' and
15089 l_txn_exists_bc_pkt_flag = 'Y') then
15090
15091 If g_debug_mode = 'Y' then
15092 log_message(p_msg_token1=>l_program_name||':Fail pa_bc_packets as GL Failed - F170 update');
15093 End If;
15094
15095 -- Autonomous procedure called for update ...these are the records that
15096 -- has already passed PA FC but now needs to be failed ... as some records have failed with F169 above
15097
15098 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15099 P_period_name => g_tab_period_name,
15100 P_budget_ccid => g_tab_budget_ccid,
15101 P_allow_flag => g_tab_allow_flag,
15102 P_result_code => 'F170');
15103
15104 -- Note: All the pl/sql tables being passed are nulls
15105
15106 End If;
15107
15108 If g_debug_mode = 'Y' then
15109 log_message(p_msg_token1=>l_program_name||':Executing gl failure check end .., status:'||p_return_status);
15110 End If;
15111
15112 End If; --If P_return_status = 'S' then
15113 -- -------------------------- END STEP 3 -------------------------------------+
15114
15115 -- -------------------------- STEP 4 -----------------------------------------+
15116 -- If (Top-Down and re-baseline and "reserve"/"check funds"/"year end")
15117 -- execute "budget account validation" (for the latest budget
15118 -- version only). i.e. account change not allowed on a budget line
15119 -- that has txn.s against it. If any found, fail gl_bc_packets with F35
15120 --
15121 -- IF ACCOUNT CHANGE ALLOWED, then update the account information on
15122 -- pa_budget_lines
15123 -- Note: We however have to synch data for all modes and all budget types ..
15124 -- ---------------------------------------------------------------------------+
15125
15126
15127 If (--pa_budget_fund_pkg.g_balance_type = 'E' /*Top Down*/ and
15128 --pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15129 p_return_status = 'S' ) then -- I
15130
15131 If g_debug_mode = 'Y' then
15132 log_message(p_msg_token1=>l_program_name||':Executing account validation');
15133 End If;
15134
15135 -- ## Get the budget lines where account has changed
15136 Open c_budget_lines_synch(l_current_budget_version_id);
15137 loop
15138 fetch c_budget_lines_synch BULK COLLECT into t_ccid,
15139 t_gl_rowid,
15140 t_bud_ccid,
15141 t_raid,
15142 t_budget_rowid,
15143 t_budget_start_date,
15144 g_tab_period_name,
15145 g_tab_allow_flag,
15146 g_tab_budget_line_id,
15147 t_txn_currency_code,
15148 t_draft_needs_update,
15149 t_project_id,
15150 t_task_id,
15151 t_rlmi,
15152 t_parent_rlmi
15153 LIMIT l_limit;
15154
15155 If t_ccid.exists(1) then -- II
15156
15157 l_count := 0;
15158 l_count := t_ccid.COUNT;
15159 l_validation_failed := 'N';
15160 l_derive_draft_values := 'N';
15161
15162 -- ----------------------------------------------------------------------------------+
15163 -- ## A. Check if SLA has derived an account diff. than that on the budget line ...
15164 If g_debug_mode = 'Y' then
15165 log_message(p_msg_token1=>l_program_name||':Check if SLA derived diff. account');
15166 End If;
15167 -- ----------------------------------------------------------------------------------+
15168 for x in t_ccid.FIRST..t_ccid.LAST loop
15169
15170 If t_ccid(x) <> t_bud_ccid(x) then
15171 t_draft_needs_update(x) := 'Y';
15172 l_derive_draft_values := 'Y';
15173 l_acct_changed := 'Y';
15174 End If;
15175
15176 end loop;
15177 If g_debug_mode = 'Y' then
15178 log_message(p_msg_token1=>l_program_name||':l_derive_draft_values['||l_derive_draft_values||']');
15179 End If;
15180
15181 -- ----------------------------------------------------------------------------------+
15182 -- ## B. Get prev. version budget ccid
15183 -- ----------------------------------------------------------------------------------+
15184 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15185 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15186 (l_txn_exists_bc_pkt_flag ='Y' OR l_txn_exists_bc_cmt_flag = 'Y'))
15187 then -- B
15188
15189 If g_debug_mode = 'Y' then
15190 log_message(p_msg_token1=>l_program_name||':Derive Top task id');
15191 End If;
15192
15193 If l_budget_entry_level_code = 'P' then
15194 for x in t_Task_id.FIRST..t_task_id.LAST loop
15195 t_top_task_id(x) := 0;
15196 end loop;
15197 Else
15198 for x in t_Task_id.FIRST..t_task_id.LAST loop
15199 select top_task_id into t_top_task_id(x)
15200 from pa_tasks
15201 where task_id = t_task_id(x);
15202 end loop;
15203 End If;
15204
15205 If g_debug_mode = 'Y' then
15206 log_message(p_msg_token1=>l_program_name||':Derive prev. ver ccid');
15207 End If;
15208
15209 for x in t_ccid.FIRST..t_ccid.LAST loop
15210
15211 Begin
15212 select pbl.code_combination_id into
15213 t_prev_ver_ccid(x)
15214 from pa_budget_lines pbl,
15215 pa_resource_assignments pra
15216 where pbl.start_date = t_budget_start_date(x)
15217 and pbl.txn_currency_code = t_txn_currency_code(x)
15218 and pbl.budget_version_id = pa_budget_fund_pkg.g_cost_prev_bvid
15219 and pbl.budget_version_id = pra.budget_version_id
15220 and pbl.resource_assignment_id = pra.resource_assignment_id
15221 and pra.project_id = t_project_id(x)
15222 and (pra.task_id = t_task_id(x) OR
15223 pra.task_id = t_top_task_id(x))
15224 and (pra.resource_list_member_id= t_rlmi(x) OR
15225 pra.resource_list_member_id= t_parent_rlmi(x));
15226 Exception
15227 when no_data_found then
15228 t_prev_ver_ccid(x) := -1;
15229 End;
15230
15231 -- note: if ct. changes budget from lowest to top task or
15232 -- moves resource group to group then there can be an issue ..
15233 -- product management said that should not happen .. so not handling that for
15234 -- the time being ..
15235 -- Issue: lets say task11 had A1 and task 12 had A2 but now ct. moves budget to task1 (top level)
15236 -- then which budget account to consider ..it gets kinds complicated then ..
15237 end loop;
15238
15239 End If; --B
15240
15241 If g_debug_mode = 'Y' then
15242 log_message(p_msg_token1=>l_program_name||':After derive prev. ver ccid');
15243 End If;
15244
15245 -- ----------------------------------------------------------------------------------+
15246 -- ## C. Call API for validation (if account change allowed)
15247 -- ----------------------------------------------------------------------------------+
15248 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15249 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15250 (l_txn_exists_bc_pkt_flag ='Y' OR l_txn_exists_bc_cmt_flag = 'Y')
15251 )
15252 then -- API If
15253 -- ----------------------------------------------------------------------------------------------------+
15254 If g_debug_mode = 'Y' then
15255 log_message(p_msg_token1=>l_program_name||': Account change allowed-Inside main if condition');
15256 for x in t_project_id.FIRST..t_project_id.LAST loop
15257 log_message(p_msg_token1=>l_program_name||':t_top_task_id['||t_task_id(x)
15258 ||'] t_task_id['||t_task_id(x)
15259 ||'] t_parent_rlmi['||t_parent_rlmi(x)
15260 ||'] t_rlmi['||t_rlmi(x)
15261 ||'] t_budget_start_date['||t_budget_start_date(x)
15262 ||'] g_tab_period_name['||g_tab_period_name(x)
15263 ||'] t_prev_ver_ccid['||t_prev_ver_ccid(x)
15264 ||'] t_ccid['||t_ccid(x)||']');
15265 end loop;
15266 End If;
15267 -- ----------------------------------------------------------------------------------------------------+
15268
15269 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
15270 l_bvid_for_acct_changed_API := l_current_budget_version_id;
15271 Else
15272 l_bvid_for_acct_changed_API := pa_budget_fund_pkg.g_cost_prev_bvid;
15273 End if;
15274
15275 If g_debug_mode = 'Y' then
15276 log_message(p_msg_token1=>l_program_name||': For acct. change API, bvid being used:'
15277 ||l_bvid_for_acct_changed_API);
15278 End If;
15279
15280 for x in t_project_id.FIRST..t_project_id.LAST loop
15281
15282 If (t_prev_ver_ccid(x) <> t_ccid(x))
15283 then
15284 If g_debug_mode = 'Y' then
15285 log_message(p_msg_token1=>l_program_name||': Calling pa_funds_control_utils.is_Account_change_allowed2');
15286 End If;
15287
15288 IF pa_funds_control_utils.is_Account_change_allowed2
15289 (p_budget_version_id => l_bvid_for_acct_changed_API,
15290 p_project_id => t_project_id(x),
15291 p_top_task_id => t_top_task_id(x),
15292 p_task_id => t_task_id(x),
15293 p_parent_resource_id => t_parent_rlmi(x),
15294 p_resource_list_member_id => t_rlmi(x),
15295 p_start_date => t_budget_start_date(x),
15296 p_period_name => g_tab_period_name(x),
15297 p_entry_level_code => l_budget_entry_level_code,
15298 p_mode => 'FORM') = 'N'
15299 THEN -- III
15300
15301 g_tab_allow_flag(x) := 'N'; -- Account Change not allowed ...
15302 l_validation_failed := 'Y';
15303 l_derive_draft_values := 'Y';
15304
15305 If g_debug_mode = 'Y' then
15306 log_message(p_msg_token1=>l_program_name||':Acct change failed for raid['||t_raid(x)||']period['||
15307 g_tab_period_name(x)||']');
15308 End If;
15309
15310 END IF; -- III
15311
15312 End If; -- Current to prev. budget ccid check ..
15313
15314 end loop;
15315
15316 End If; --API If
15317
15318 -- ----------------------------------------------------------------------------------+
15319 If g_debug_mode = 'Y' then
15320
15321 log_message(p_msg_token1=>l_program_name||':l_validation_failed ['||l_validation_failed||']');
15322
15323 For x in t_bud_ccid.FIRST..t_bud_ccid.LAST loop
15324 log_message(p_msg_token1=>l_program_name||':source_distribution_id_num_1/g_tab_budget_line_id ['
15325 ||g_tab_budget_line_id(x)||']g_tab_allow_flag['||g_tab_allow_flag(x)
15326 ||']g_tab_period_name['||g_tab_period_name(x)||']t_raid'||t_raid(x)||']');
15327 end loop;
15328 End If;
15329 -- ----------------------------------------------------------------------------------+
15330
15331 -- ----------------------------------------------------------------------------------+
15332 -- C2. Get the draft information for update ...
15333 -- ----------------------------------------------------------------------------------+
15334 If g_debug_mode = 'Y' then
15335 log_message(p_msg_token1=>l_program_name||': l_derive_draft_values['||l_derive_draft_values||']');
15336 End If;
15337
15338 If l_derive_draft_values = 'Y' then
15339
15340 If g_debug_mode = 'Y' then
15341 log_message(p_msg_token1=>l_program_name||': Derive draft rowid and draft ccid');
15342 End If;
15343
15344 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then -- CF
15345 for x in t_project_id.FIRST..t_project_id.LAST
15346 loop
15347
15348 -- If draft needs update then we need to get the draft rowid for updating
15349 -- the account change and draft ccid for the below API ..
15350 -- And the below begin..end block is reqd. as the baseline budget can have zero $ lines ..
15351
15352 Begin
15353 select pbl.rowid,pbl.code_combination_id into
15354 t_draft_budget_rowid(x),t_draft_ccid(x)
15355 from pa_budget_lines pbl,
15356 pa_resource_assignments pra
15357 where pbl.start_date = t_budget_start_date(x)
15358 and pbl.txn_currency_code = t_txn_currency_code(x)
15359 and pbl.budget_version_id = pra.budget_version_id
15360 and pbl.resource_assignment_id = pra.resource_assignment_id
15361 and pra.budget_version_id = l_draft_budget_version_id
15362 and pra.project_id = t_project_id(x)
15363 and pra.task_id = t_task_id(x)
15364 and pra.resource_list_member_id= t_rlmi(x);
15365 Exception
15366 when no_data_found then
15367 If g_debug_mode = 'Y' then
15368 log_message(p_msg_token1=>l_program_name||'Derive drafr budget ccid:No Data Found');
15369 log_message(p_msg_token1=>l_program_name||': t_budget_start_date(x):'||t_budget_start_date(x)
15370 ||' t_txn_currency_code(x):'||t_txn_currency_code(x)
15371 ||' t_project_id(x):'||t_project_id(x)
15372 ||' t_task_id(x):'||t_task_id(x)
15373 ||' t_rlmi(x): '||t_rlmi(x));
15374 End if;
15375
15376 t_draft_budget_rowid(x) := null;
15377 t_draft_ccid(x) := -1;
15378 End;
15379
15380 If t_draft_needs_update(x) = 'N' then
15381 t_draft_budget_rowid(x) := null;
15382 End If; --If t_draft_needs_update(x) = 'Y' then
15383
15384 -- Above is reqd. as only those rowid with <> 'NO DATA FOUND' is used for updating account change ..
15385
15386 end loop;
15387 End If; -- CF ..
15388 End if; --If l_derive_draft_values = 'Y' then
15389
15390 If g_debug_mode = 'Y' then
15391 log_message(p_msg_token1=>l_program_name||': After derive draft rowid and draft ccid');
15392 End If;
15393
15394
15395 -- ----------------------------------------------------------------------------------+
15396 -- ## D. If any budget acccount failed validation then ..
15397 -- ----------------------------------------------------------------------------------+
15398
15399 If l_validation_failed = 'Y' then
15400
15401 -- ----------------------------------------------------------------------------------+
15402 -- ## Fail gl_bc_packets ..
15403 If g_debug_mode = 'Y' then
15404 log_message(p_msg_token1=>l_program_name||': Acct. val. failed - Fail gl_bc_packets');
15405 End If;
15406 -- ----------------------------------------------------------------------------------+
15407
15408 Forall x in t_bud_ccid.FIRST..t_bud_ccid.LAST
15409 Update gl_bc_packets glbc
15410 set glbc.result_code = 'F35'
15411 where glbc.packet_id = p_packet_id
15412 and glbc.source_distribution_id_num_1 = g_tab_budget_line_id(x)
15413 and g_tab_allow_flag(x) = 'N';
15414
15415 If g_debug_mode = 'Y' then
15416 log_message(p_msg_token1=>l_program_name||SQL%ROWCOUNT||' GL line updated');
15417 End If;
15418
15419 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15420 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
15421 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15422 l_txn_exists_bc_pkt_flag = 'Y') then
15423
15424 -- ----------------------------------------------------------------------------------+
15425 -- ## Fail pa_bc_packets:
15426 If g_debug_mode = 'Y' then
15427 log_message(p_msg_token1=>l_program_name||': Acct. val. failed [F169] - Fail pa_bc_packets');
15428 End If;
15429 -- ----------------------------------------------------------------------------------+
15430
15431 -- Autonomous procedure called for update ...these are the records that
15432 -- has already passed PA FC but now needs to be failed ...
15433
15434 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15435 P_period_name => g_tab_period_name,
15436 P_budget_ccid => t_bud_ccid,
15437 P_allow_flag => g_tab_allow_flag,
15438 P_result_code => 'F169');
15439
15440 End If;
15441
15442 -- ----------------------------------------------------------------------------------+
15443 -- ## Fail draft account summary ..
15444 If g_debug_mode = 'Y' then
15445 log_message(p_msg_token1=>l_program_name||': Acct. change. val. failed(F169) - Update draft account summary');
15446 End If;
15447 -- Update Draft version (account summary table) to failure ..
15448 -- Note: in case of 'Year End' the working budget will be updated ..
15449 -- ----------------------------------------------------------------------------------+
15450 -- Following if condition being used as for = 'CF' ..t_draft_ccid is not calculated ..
15451
15452 If pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' then
15453
15454 -- -------------------------------------------------------------------------------------------------+
15455 If g_debug_mode = 'Y' then
15456 log_message(p_msg_token1=>l_program_name||': Upd acct. summ - <> CF:l_draft_budget_version_id['
15457 ||l_draft_budget_version_id||']');
15458 for x in g_tab_period_name.FIRST..g_tab_period_name.LAST loop
15459 log_message(p_msg_token1=>l_program_name||': g_tab_period_name['||g_tab_period_name(x)
15460 ||'] t_draft_ccid ['||t_draft_ccid(x)
15461 ||']');
15462 end loop;
15463 End If;
15464 -- -------------------------------------------------------------------------------------------------+
15465
15466 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15467 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15468 P_period_name => g_tab_period_name,
15469 P_budget_ccid => t_draft_ccid,
15470 P_allow_flag => g_tab_allow_flag,
15471 P_result_code => 'F169');
15472
15473 Else
15474
15475 -- -------------------------------------------------------------------------------------------------+
15476 If g_debug_mode = 'Y' then
15477 log_message(p_msg_token1=>l_program_name||': Upd acct. summ,mode = CF:l_draft_budget_version_id['
15478 ||l_draft_budget_version_id||']');
15479 for x in g_tab_period_name.FIRST..g_tab_period_name.LAST loop
15480 log_message(p_msg_token1=>l_program_name||': g_tab_period_name['||g_tab_period_name(x)
15481 ||'] t_bud_ccid ['||t_bud_ccid(x)
15482 ||']');
15483 end loop;
15484
15485 End If;
15486 -- -------------------------------------------------------------------------------------------------+
15487
15488 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15489 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15490 P_period_name => g_tab_period_name,
15491 P_budget_ccid => t_bud_ccid,
15492 P_allow_flag => g_tab_allow_flag,
15493 P_result_code => 'F169');
15494
15495 End If;
15496 -- ----------------------------------------------------------------------------------+
15497 -- ## Set failure status ..
15498 -- ----------------------------------------------------------------------------------+
15499 p_return_status := 'F';
15500
15501
15502 End If; -- If l_validation_failed = 'Y' then (Acct. validation failed)
15503
15504
15505 -- --------------------------------------------------------------------------------+
15506 -- ## E. Update those budget lines where account info. can change ....
15507 If g_debug_mode = 'Y' then
15508 log_message(p_msg_token1=>l_program_name||': Update changed account info on budget lines'
15509 ||'l_acct_changed['||l_acct_changed||'] l_validation_failed['
15510 ||l_validation_failed||']' );
15511 End If;
15512 -- --------------------------------------------------------------------------------+
15513 If l_acct_changed = 'Y' then
15514
15515 If (l_validation_failed = 'N' or pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') then
15516 -- update budget lines only if there is no failure
15517 -- reason: because if there is any failure, baseline/yearend/checkfunds fails ..
15518 -- and a rollback is issued for the 1st 2 ..
15519 -- However for CF, we will update the account change for the records
15520 -- that did not fail FC .. till the point the loop exits ..
15521
15522 If g_debug_mode = 'Y' then
15523 log_message(p_msg_token1=>l_program_name||': Updating budget line on current version' );
15524 End If;
15525
15526 forall x in t_ccid.FIRST..t_ccid.LAST
15527 Update pa_budget_lines pbl
15528 set pbl.code_combination_id = t_ccid(x)
15529 where pbl.rowid = t_budget_rowid(x)
15530 and t_bud_ccid(x) <> t_ccid(x)
15531 and g_tab_allow_flag(x) = 'Y';
15532
15533 If (sql%rowcount > 0 and pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') then
15534 l_draft_acct_changed_flag := 'Y';
15535 End If;
15536
15537 If g_debug_mode = 'Y' then
15538 log_message(p_msg_token1=>l_program_name||':'||sql%rowcount
15539 ||' budget lines updated for current version' );
15540 End If;
15541
15542 End If; -- If l_validation_failed = 'N' then
15543
15544 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS') then
15545
15546 -- We also need to update the draft version account information ..atleast for the ones
15547 -- where account change is allowed .. AUTONOMOUS Update ..
15548
15549 If g_debug_mode = 'Y' then
15550 log_message(p_msg_token1=>l_program_name||': Update new account on draft summary'
15551 ||': l_record_updated_flag:'||l_record_updated_flag);
15552
15553 for x in t_draft_budget_rowid.FIRST..t_draft_budget_rowid.LAST loop
15554 log_message(p_msg_token1=>l_program_name||':t_bud_ccid:'||t_bud_ccid(x)
15555 ||':t_ccid:'||t_ccid(x)
15556 ||':g_tab_allow_flag:'||g_tab_allow_flag(x)
15557 ||':t_draft_budget_rowid:'||t_draft_budget_rowid(x));
15558 end loop;
15559 End If;
15560
15561 UPD_NEW_ACCT_ON_DRAFT_BUDGET(p_budget_line_rowid => t_draft_budget_rowid,
15562 p_budget_ccid => t_bud_ccid,
15563 p_new_ccid => t_ccid,
15564 p_change_allowed => g_tab_allow_flag,
15565 p_record_updated => l_record_updated_flag);
15566
15567 If l_record_updated_flag = 'Y' then
15568 l_draft_acct_changed_flag := 'Y';
15569 End if;
15570
15571 End If;
15572
15573 -- Initialized variable to 'N' for the next run ..
15574 l_acct_changed := 'N';
15575
15576 End If; -- If l_acct_changed = 'Y' then
15577
15578 -- ---------------------------------------------------------------------------------------+
15579 If g_debug_mode = 'Y' then
15580 log_message(p_msg_token1=>l_program_name||SQL%ROWCOUNT||' budget line records updated');
15581 End If;
15582 -- ---------------------------------------------------------------------------------------+
15583
15584 Else
15585 EXIT; -- Exit Loop
15586 End If; -- If t_ccid(1).exists -- II
15587
15588 -- ----------------------------------------------------------------------------------+
15589 -- ## F. Initalize variables
15590 If g_debug_mode = 'Y' then
15591 log_message(p_msg_token1=>l_program_name||': initalize variables');
15592 End If;
15593 -- ----------------------------------------------------------------------------------+
15594 t_ccid.DELETE;
15595 t_bud_ccid.DELETE;
15596 t_gl_rowid.DELETE;
15597 t_budget_rowid.DELETE;
15598 t_raid.DELETE;
15599 t_budget_start_date.DELETE;
15600 g_tab_period_name.DELETE;
15601 g_tab_allow_flag.DELETE;
15602 g_tab_budget_line_id.DELETE;
15603 t_txn_currency_code.DELETE;
15604 t_project_id.DELETE;
15605 t_task_id.DELETE;
15606 t_rlmi.DELETE;
15607 t_parent_rlmi.DELETE;
15608
15609 -- Following tables are conditioanlly build ..
15610 if t_top_task_id.exists(1) then t_top_task_id.DELETE; end if;
15611 if t_prev_ver_ccid.exists(1) then t_prev_ver_ccid.DELETE; end if;
15612 if t_draft_needs_update.exists(1) then t_draft_needs_update.DELETE; end if;
15613 if t_draft_ccid.exists(1) then t_draft_ccid.DELETE; end if;
15614 if t_draft_budget_rowid.exists(1) then t_draft_budget_rowid.DELETE; end if;
15615 End Loop;
15616
15617 close c_budget_lines_synch;
15618
15619 If g_debug_mode = 'Y' then
15620 log_message(p_msg_token1=>l_program_name||':After account validation, return status:'||p_return_status);
15621 End If;
15622
15623 End If; -- I , Top-Down Check, re-baseline
15624
15625 -- --------------------------------------------------------------------------+
15626 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15627 pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
15628 p_return_status = 'F' and
15629 l_txn_exists_bc_pkt_flag = 'Y') then
15630
15631 If g_debug_mode = 'Y' then
15632 log_message(p_msg_token1=>l_program_name||':Fail pa_bc_packets as account info. changed - F170 update');
15633 End If;
15634
15635 -- Autonomous procedure called for update ...these are the records that
15636 -- has already passed PA FC but now needs to be failed ... as some records have failed with F169 above
15637
15638 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15639 P_period_name => g_tab_period_name,
15640 P_budget_ccid => g_tab_budget_ccid,
15641 P_allow_flag => g_tab_allow_flag,
15642 P_result_code => 'F170');
15643
15644 -- Note: All the pl/sql tables being passed are nulls
15645
15646 End If;
15647
15648 -- ---------------------------------------------------------------------------+
15649 -- If the status is 'Failed' but there was an account changed that was updated
15650 -- on budget lines, then we will need to rebuild the draft version summary and
15651 -- that too in AUTONOMUS mode ...
15652 -- What we're talking here is the draft budget data that gets updated above
15653 -- during baseline/yearend and CF ..
15654 -- ---------------------------------------------------------------------------+
15655
15656 If (l_draft_acct_changed_flag = 'Y' and
15657 p_return_status = 'F' )
15658 then
15659 If g_debug_mode = 'Y' then
15660 log_message(p_msg_token1=>l_program_name||': Failure case - Rebuild draft acct. sumamry');
15661 End If;
15662
15663 BUILD_ACCOUNT_SUMMARY_AUTO(x_budget_version_id => l_draft_budget_version_id,
15664 x_balance_type =>pa_budget_fund_pkg.g_balance_type,
15665 x_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
15666 x_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid,
15667 x_mode=>'FAIL');
15668 End If;
15669 -- ------------------------- END STEP 4 --------------------------------------+
15670
15671 If p_return_status = 'S' then -- II
15672 -- ------------------------------------------------------------------------+
15673 -- 5.0: Build account summary for the current version ..
15674 -- ------------------------------------------------------------------------+
15675 If g_debug_mode = 'Y' then
15676 log_message(p_msg_token1=>l_program_name||':Processing Mode:'||pa_budget_fund_pkg.g_processing_mode);
15677 log_message(p_msg_token1=>l_program_name||':Build account summary for the current version');
15678 End If;
15679
15680 -- ACCOUNT SUMMARY SHOULD ALWAYS BE GENERATED .. CASE WHERE USER MANUALLY UPDATED
15681 -- ACCOUNT, IN THIS CASE, ACCT. SUMMARY IS DIFF. THAN ACTUAL SUMMARY
15682
15683 BUILD_ACCOUNT_SUMMARY(p_budget_version_id => l_current_budget_version_id,
15684 p_balance_type =>pa_budget_fund_pkg.g_balance_type,
15685 p_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
15686 p_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid);
15687
15688 If g_debug_mode = 'Y' then
15689 log_message(p_msg_token1=>l_program_name||': Done building account summary for the current version');
15690 End If;
15691 -- ------------------------- END STEP 5 -----------------------------------+
15692 -- 6.0: Build account summary for the draf version .. <> CF mode ..
15693 -- 'Cause in CF mode, we build for the draft version :)
15694 -- ------------------------------------------------------------------------+
15695 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and l_draft_acct_changed_flag = 'Y')
15696 then
15697
15698 If g_debug_mode = 'Y' then
15699 log_message(p_msg_token1=>l_program_name||':Build account summary for the draft version');
15700 End If;
15701
15702 BUILD_ACCOUNT_SUMMARY_AUTO(x_budget_version_id => l_draft_budget_version_id,
15703 x_balance_type =>pa_budget_fund_pkg.g_balance_type,
15704 x_budget_amount_code=> pa_budget_fund_pkg.g_budget_amount_code,
15705 x_prev_budget_version_id=>pa_budget_fund_pkg.g_cost_prev_bvid,
15706 x_mode=>'PASS');
15707
15708 If g_debug_mode = 'Y' then
15709 log_message(p_msg_token1=>l_program_name||': Done building account summary for the draft version');
15710 End If;
15711
15712 End If; -- Step 6.0 main If ..
15713
15714 -- ------------------------- END STEP 6 -----------------------------------+
15715 -- 7.0: Top Down (but not "Year-End") and re-baseline, carry out
15716 -- "Account level" FC
15717 -- ------------------------------------------------------------------------+
15718
15719 If (pa_budget_fund_pkg.g_balance_type = 'E' and
15720 pa_budget_fund_pkg.g_cost_rebaseline_flag = 'Y' and
15721 pa_budget_fund_pkg.g_processing_mode = 'BASELINE') then
15722 --l_txn_exists_bc_pkt_flag = 'Y') then
15723
15724 -- Account level FC .. ONLY for BASELINE mode
15725
15726 If g_debug_mode = 'Y' then
15727 l_program_name := 'Do_Budget_baseline_tieback';
15728 log_message(p_msg_token1=>l_program_name||':Account Level Funds Check');
15729 End If;
15730
15731
15732 Open c_acct_lines(l_current_budget_version_id);
15733 loop
15734 fetch c_acct_lines BULK COLLECT into g_tab_period_name,
15735 g_tab_budget_ccid,
15736 g_tab_allow_flag
15737 LIMIT l_limit;
15738 l_count := 0;
15739 l_count := g_tab_budget_ccid.COUNT;
15740
15741
15742 If l_count > 0 then
15743
15744 -- ----------------------------------------------------------------------------------+
15745 If g_debug_mode = 'Y' then
15746 log_message(p_msg_token1=>l_program_name||':Account Level Funds Check failed - Fail gl_bc_packets');
15747
15748 For x in g_tab_budget_ccid.FIRST..g_tab_budget_ccid.LAST loop
15749 log_message(p_msg_token1=>l_program_name||':g_tab_budget_ccid'||g_tab_budget_ccid(x)
15750 ||'g_tab_period_name'|| g_tab_period_name(x));
15751 end loop;
15752 End If;
15753 -- ----------------------------------------------------------------------------------+
15754
15755 -- A. Fail gl_bc_packets:
15756 Forall x in g_tab_budget_ccid.FIRST..g_tab_budget_ccid.LAST
15757 Update gl_bc_packets glbc
15758 set glbc.result_code = 'F35'
15759 where glbc.packet_id = p_packet_id
15760 and glbc.code_combination_id = g_tab_budget_ccid(x)
15761 and glbc.period_name = g_tab_period_name(x);
15762
15763 If g_debug_mode = 'Y' then
15764 log_message(p_msg_token1=>l_program_name||SQL%ROWCOUNT||' GL line updated');
15765 End If;
15766
15767 -- B. Fail pa_bc_packets:
15768
15769 -- Autonomous procedure called for update ...these are the records that
15770 -- has already passed PA FC but now needs to be failed ...
15771
15772 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15773 P_period_name => g_tab_period_name,
15774 P_budget_ccid => g_tab_budget_ccid,
15775 P_allow_flag => g_tab_allow_flag,
15776 P_result_code => 'F113');
15777
15778 If g_debug_mode = 'Y' then
15779 log_message(p_msg_token1=>l_program_name||':Account Level Funds Check failed - Fail draft account summary');
15780 End If;
15781
15782 -- C. Update Draft version (account summary table) to failure ..
15783
15784 -- Autonomous call to update pa_budget_acct_lines for the draft version ...
15785
15786 UPDATE_FAILURE_IN_ACCT_SUMMARY(P_budget_version_id => l_draft_budget_version_id,
15787 P_period_name => g_tab_period_name,
15788 P_budget_ccid => g_tab_budget_ccid,
15789 P_allow_flag => g_tab_allow_flag,
15790 P_result_code => 'F113');
15791
15792 -- D. Set Failure status
15793
15794 p_return_status := 'F';
15795
15796
15797 -- E. Initalize variables..
15798
15799 g_tab_budget_ccid.DELETE;
15800 g_tab_period_name.DELETE;
15801 g_tab_allow_flag.DELETE;
15802
15803 End If; --If l_count > 0 then
15804
15805
15806 If l_count < l_limit then
15807 exit;
15808 End If;
15809
15810 end loop; -- Main cursor c_acct_lines;
15811
15812 Close c_acct_lines;
15813
15814
15815 If (p_return_status = 'F') then
15816
15817 If g_debug_mode = 'Y' then
15818 log_message(p_msg_token1=>l_program_name||':Account level failure ...');
15819 End If;
15820
15821 -- Autonomous procedure called for update ...these are the records that
15822 -- has already passed PA FC but now needs to be failed ... as some records have failed with F113 above
15823
15824 FAIL_BC_PKT_DURING_BASELINE(P_budget_version_id => l_current_budget_version_id,
15825 P_period_name => g_tab_period_name,
15826 P_budget_ccid => g_tab_budget_ccid,
15827 P_allow_flag => g_tab_allow_flag,
15828 P_result_code => 'F170');
15829
15830 -- Note: All the pl/sql tables being passed are nulls
15831
15832 End If;
15833
15834 End If; -- account level FC complete ...
15835
15836 -- ------------------------- END STEP 7 -----------------------------------+
15837
15838 End If; -- II If p_return_status = 'S' then (step 5..7)
15839
15840 -- ------------------------- STEP 8 -----------------------------------+
15841 -- Step 8.0: Update Pass status/result code on pa_budget_acct_lines
15842 -- Step 8.1: Update Pass status/result code on current version (CF/Baseline/Yearend)
15843 /* ==============================================================================================+
15844 -- STEP NOT REQUIRED AS acct. summary initialized/build with 'P101' and 'A' ...
15845
15846 If ((pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') OR
15847 (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and p_return_status = 'S')
15848 ) then
15849
15850 If g_debug_mode = 'Y' then
15851 log_message(p_msg_token1=>'End:'||l_program_name||'Update Pass status/result code on pa_budget_acct_lines - Current');
15852 End If;
15853
15854 Update pa_budget_acct_lines
15855 set funds_check_status_code = 'A',
15856 funds_check_result_code = 'P101'
15857 where budget_version_id = l_current_budget_version_id
15858 and nvl(funds_check_status_code,'A') <> 'R';
15859
15860 If g_debug_mode = 'Y' then
15861 log_message(p_msg_token1=>l_program_name||'Current Acct Summary-P101 update:'||SQL%ROWCOUNT);
15862 End If;
15863
15864 End If;
15865
15866 -- Step 8.2: Update Pass status/result code on draft version for Baseline/year End mode
15867
15868 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and p_return_status = 'S')
15869 then
15870
15871 If g_debug_mode = 'Y' then
15872 log_message(p_msg_token1=>'End:'||l_program_name||'Update Pass status/result code on pa_budget_acct_lines - Draft');
15873 End If;
15874
15875 Update pa_budget_acct_lines
15876 set funds_check_status_code = 'A',
15877 funds_check_result_code = 'P101'
15878 where budget_version_id = l_draft_budget_version_id;
15879
15880 If g_debug_mode = 'Y' then
15881 log_message(p_msg_token1=>l_program_name||'Draft Acct Summary-P101 update:'||SQL%ROWCOUNT);
15882 End If;
15883
15884 End If;
15885 ============================================================================================== */
15886
15887 -- ------------------------- END STEP 8 -----------------------------------+
15888
15889 -- ------------------------- STEP 9 -----------------------------------+
15890 -- Step 9.0: Update project_acct_result_code/result_code on pa_bc_packets
15891
15892 If (pa_budget_fund_pkg.g_processing_mode = 'BASELINE' and
15893 p_return_status = 'S' and
15894 l_txn_exists_bc_pkt_flag = 'Y') then
15895
15896 If g_debug_mode = 'Y' then
15897 log_message(p_msg_token1=>l_program_name||'Update acct level result code on pa_bc_packets');
15898 End If;
15899
15900 UPD_BC_PKT_ACCT_RESULT_CODE(P_budget_version_id => l_current_budget_version_id);
15901
15902 End if;
15903 -- ------------------------- END STEP 9 -----------------------------------+
15904
15905 -- -------------------------- STEP 10 --------------------------------------+
15906 -- Step 10.0: We need to fail all records in case of Check funds/reserve ..
15907
15908 If (p_return_status = 'F' and pa_budget_fund_pkg.g_processing_mode = 'CHECK_FUNDS') then
15909 -- Filtering reserve_baseline as during baseline if there is a failure everything rolls back ..
15910
15911 g_packet_debit_processed := 'Y';
15912
15913 If g_packet_credit_processed = 'Y' then
15914 log_message(p_msg_token1=>l_program_name||': As credit already processed Calling Fail_credit_packet');
15915 FAIL_CREDIT_PACKET(p_input_packet => 'DEBIT',
15916 p_return_status_code => p_return_status);
15917 End if;
15918
15919 End If;
15920 -- ------------------------- END STEP 10 -----------------------------------+
15921
15922
15923 If g_debug_mode = 'Y' then
15924 l_program_name := 'Do_budget_baseline_tieback';
15925 log_message(p_msg_token1=>'End:'||l_program_name||'return status:'||p_return_status);
15926 End If;
15927
15928 EXCEPTION
15929 When others then
15930 If g_debug_mode = 'Y' then
15931 l_program_name := 'Do_budget_baseline_tieback';
15932 log_message(p_msg_token1=>l_program_name||':When Others:'||SQLERRM);
15933 End If;
15934
15935 p_return_status := 'F';
15936
15937 END DO_BUDGET_BASELINE_TIEBACK;
15938
15939 -- --------------------------------------------------------------------------------+
15940 -- This procedure will build pa_budget_acct_lines
15941 -- Called from DO_BUDGET_BASELINE_TIEBACK and PA_GL_CBC_CONFIRMATION (for revenue)
15942 -- Parameters:
15943 -- p_budget_version_id : Current budget version being funds checked
15944 -- p_balance_type : E (For Top Down) and B (Bottom Up)
15945 -- p_budget_amount_code : 'C' for cost and 'R' for revenue
15946 -- p_prev_budget_version_id: Budget version being reversed (for re-baseline
15947 -- and year-end case)
15948 -- --------------------------------------------------------------------------------+
15949 PROCEDURE Build_account_summary(P_budget_version_id IN NUMBER,
15950 P_balance_type IN VARCHAR2,
15951 P_budget_amount_code IN VARCHAR2,
15952 P_prev_budget_version_id IN NUMBER)
15953 IS
15954
15955 t_period_name TypeVarChar;
15956 t_start_date TypeDate;
15957 t_end_date TypeDate;
15958 t_ccid TypeNum;
15959 t_amt TypeNum;
15960
15961 l_date Date;
15962 l_login Number;
15963 l_request Number;
15964 l_count Number;
15965
15966 Cursor c_acct_lines is
15967 select pbl.period_name,
15968 pbl.start_date,
15969 pbl.end_date,
15970 pbl.code_combination_id,
15971 sum(decode(nvl(p_balance_type,'X'),
15972 'E', decode(NVL(pbl.Burdened_Cost,0),
15973 0,nvl(pbl.raw_cost,0),
15974 pbl.burdened_cost ) ,
15975 'B',decode(p_budget_amount_code,
15976 'R',nvl(pbl.revenue,0) ,
15977 'C', decode(NVL(pbl.Burdened_Cost,0),
15978 0,nvl(pbl.raw_cost,0),
15979 pbl.burdened_cost ),
15980 0 ),
15981 0 )) total_amount
15982 from pa_budget_lines pbl
15983 where budget_version_id = p_budget_version_id
15984 group by pbl.period_name,
15985 pbl.start_date,
15986 pbl.end_date,
15987 pbl.code_combination_id;
15988
15989 BEGIN
15990 l_program_name := 'Build_account_summary:';
15991 If g_debug_mode = 'Y' then
15992 log_message(p_msg_token1=>l_program_name||'Start');
15993 End If;
15994
15995 l_date := sysdate;
15996 l_login := fnd_global.login_id;
15997 l_request := fnd_global.conc_request_id;
15998 l_limit := 500;
15999 -- ------------------------------------------------------------------------+
16000 -- 1.0: Creating PA_Budget_Acct_Lines record for the current budget version
16001 -- ------------------------------------------------------------------------+
16002
16003 -- To make sure that there is no budget acct. line .. acct. gen. seems to be creating summary ..
16004 Delete from PA_Budget_Acct_Lines
16005 where budget_version_id = P_budget_version_id;
16006
16007 If g_debug_mode = 'Y' then
16008 log_message(p_msg_token1=>l_program_name||'Deleted '||SQL%ROWCOUNT||' PA_Budget_Acct_Lines records');
16009 End If;
16010
16011 If g_debug_mode = 'Y' then
16012 log_message(p_msg_token1=>l_program_name||':Creating records');
16013 End If;
16014
16015 Open c_acct_lines;
16016 loop
16017 fetch c_acct_lines
16018 BULK COLLECT into t_period_name,
16019 t_start_date,
16020 t_end_date,
16021 t_ccid,
16022 t_amt
16023 LIMIT l_limit;
16024 l_count := t_ccid.COUNT;
16025
16026 If g_debug_mode = 'Y' then
16027 log_message(p_msg_token1=>l_program_name||'Fetched '||l_count||' budget records');
16028 End If;
16029
16030 If l_count > 0 then
16031
16032 If g_debug_mode = 'Y' then
16033 for i in 1..l_count loop
16034 log_message(p_msg_token1=>l_program_name||'P_budget_version_id,start_date,t_ccid'
16035 ||P_budget_version_id||';'||t_start_date(i)||';'||t_ccid(i));
16036 end loop;
16037 End If;
16038
16039 forall i in 1..l_count
16040 INSERT INTO PA_Budget_Acct_Lines (
16041 Budget_Acct_Line_ID,
16042 Budget_version_ID,
16043 GL_Period_Name,
16044 Start_Date,
16045 End_Date,
16046 Code_Combination_ID,
16047 Prev_Ver_Budget_Amount,
16048 Prev_Ver_Available_Amount,
16049 Curr_Ver_Budget_Amount,
16050 Curr_Ver_Available_Amount,
16051 Accounted_Amount,
16052 Last_Update_Date,
16053 Last_Updated_By,
16054 Creation_Date,
16055 Created_By,
16056 Last_Update_Login,
16057 Request_ID,
16058 funds_check_status_code,
16059 funds_check_result_code)
16060 VALUES(PA_Budget_Acct_Lines_S.NEXTVAL, -- Budget acct line id
16061 P_budget_version_id, -- Budget version id
16062 t_period_name(i), -- Period name
16063 t_start_date(i), -- Start date
16064 t_end_date(i), -- End date
16065 t_ccid(i), -- CCID
16066 0, -- Prev. version bud. amt
16067 0, -- Prev. version avail.amt
16068 t_amt(i), -- Curr. version bud. amt
16069 0, -- Curr. version avail.amt
16070 0, -- Accounted amount
16071 l_date, -- Last update date
16072 l_login, -- Last update by
16073 l_date, -- Created date
16074 l_login, -- Created by
16075 l_login, -- Last update login
16076 l_request, -- Request
16077 'A', -- funds_check_status_code
16078 'P101'); -- funds_check_result_code
16079
16080
16081 t_period_name.DELETE;
16082 t_start_date.DELETE;
16083 t_end_date.DELETE;
16084 t_ccid.DELETE;
16085 t_amt.DELETE;
16086
16087 End If;
16088
16089 If l_count < l_limit then
16090 exit;
16091 end if;
16092
16093 end loop;
16094 close c_acct_lines;
16095
16096 If g_debug_mode = 'Y' then
16097 log_message(p_msg_token1=>l_program_name||' After PA_Budget_Acct_Lines Insert DML');
16098 End If;
16099 -- -------------------------------------------------------------------+
16100 -- 2.0: Update previous amounts (budget and available)
16101 -- -------------------------------------------------------------------+
16102 If p_prev_budget_version_id is not null then -- re-baseline -- I
16103 If g_debug_mode = 'Y' then
16104 log_message(p_msg_token1=>l_program_name||':Updating previous amounts');
16105 End If;
16106
16107 Update PA_Budget_Acct_Lines pbl
16108 set (pbl.Prev_Ver_Budget_Amount,pbl.Prev_Ver_Available_Amount) =
16109 (select pbl1.Curr_Ver_Budget_Amount,
16110 pbl1.Curr_Ver_Available_Amount
16111 from PA_Budget_Acct_Lines pbl1
16112 where pbl1.budget_version_id = P_prev_budget_version_id
16113 and pbl1.code_combination_id = pbl.code_combination_id
16114 and pbl1.start_date = pbl.start_date)
16115 where pbl.budget_version_id = p_budget_version_id
16116 and exists
16117 (select 1
16118 from PA_Budget_Acct_Lines pbl2
16119 where pbl2.budget_version_id = P_prev_budget_version_id
16120 and pbl2.code_combination_id = pbl.code_combination_id
16121 and pbl2.start_date = pbl.start_date);
16122 -- Bottom "exists clause" reqd, else if there is no record then the
16123 -- previous budget amounts may get updated to null and its a not null field
16124 End If; -- I
16125
16126 -- -------------------------------------------------------------------+
16127 -- 3.0: Update available and accounted amounts for the current version
16128 -- -------------------------------------------------------------------+
16129 If g_debug_mode = 'Y' then
16130 log_message(p_msg_token1=>l_program_name||':Updating avail. bal and accounted amt.');
16131 End If;
16132
16133 -- e.g. Prev.Budget = 100, Current Budget = 50, Prev. available = 90
16134 -- That means there were txn. for 10 against prev. budget (100-90)
16135 -- Current available = 50 - (100-90) = 40
16136 -- Accounted = 100-50 = 50
16137
16138 Update PA_Budget_Acct_Lines
16139 set Curr_Ver_Available_Amount = Curr_Ver_Budget_Amount -
16140 (Prev_Ver_Budget_Amount - Prev_Ver_Available_Amount),
16141 Accounted_Amount = Curr_Ver_Budget_Amount - Prev_Ver_Budget_Amount
16142 -- Accounted_Amount = Prev_Ver_Budget_Amount - Curr_Ver_Budget_Amount
16143 where budget_version_id = p_budget_version_id;
16144
16145
16146 -- -------------------------------------------------------------------+
16147 -- 4.0: Build account lines that are missing with respect to previous
16148 -- version. e.g.: Budget line deleted, acct/period changed on
16149 -- the old budget
16150 -- -------------------------------------------------------------------+
16151 If p_prev_budget_version_id is not null then -- re-baseline -- II
16152 If g_debug_mode = 'Y' then
16153 log_message(p_msg_token1=>l_program_name||':Creating missing records');
16154 End If;
16155
16156 If (pa_budget_fund_pkg.g_processing_mode <> 'CHECK_FUNDS' and
16157 P_budget_version_id = pa_budget_fund_pkg.g_cost_current_bvid )then
16158
16159 -- This IF..END IF ..is reqd. as this procedure is called for the draft version
16160 -- during <> 'CF' mode ..to rebuild the acct. sumamry for the draft version
16161 -- In this case, the else part should fire ..
16162
16163 INSERT INTO PA_BUDGET_ACCT_LINES (
16164 Budget_Acct_Line_ID,
16165 Budget_Version_ID,
16166 GL_Period_Name,
16167 Start_Date,
16168 End_Date,
16169 Code_Combination_ID,
16170 Prev_Ver_Budget_Amount,
16171 Prev_Ver_Available_Amount,
16172 Curr_Ver_Budget_Amount,
16173 Curr_Ver_Available_Amount,
16174 accounted_amount,
16175 LAST_UPDATE_DATE,
16176 LAST_UPDATED_BY,
16177 LAST_UPDATE_LOGIN,
16178 CREATION_DATE,
16179 CREATED_BY,
16180 REQUEST_ID,
16181 funds_check_status_code,
16182 funds_check_result_code
16183 )
16184 SELECT
16185 PA_BUDGET_ACCT_LINES_S.nextval,
16186 P_Budget_Version_ID, -- current version
16187 BL1.GL_Period_Name,
16188 BL1.Start_Date,
16189 BL1.End_Date,
16190 BL1.Code_Combination_ID,
16191 BL1.Curr_Ver_Budget_Amount,
16192 BL1.Curr_Ver_Available_Amount,
16193 0,
16194 0,
16195 0 - BL1.Curr_Ver_Budget_Amount,
16196 l_date,
16197 l_login,
16198 l_login,
16199 l_date,
16200 l_login,
16201 l_request,
16202 'A',
16203 'P101'
16204 FROM PA_BUDGET_ACCT_LINES BL1
16205 WHERE BL1.Budget_Version_ID = P_prev_budget_version_id
16206 AND NOT EXISTS
16207 ( SELECT 'x'
16208 FROM PA_BUDGET_ACCT_LINES BL2
16209 WHERE BL2.Budget_Version_ID = P_budget_version_id
16210 AND BL2.Code_Combination_ID = BL1.Code_Combination_ID
16211 AND BL2.Start_Date = BL1.Start_Date ) ;
16212
16213 -- In the above select, cannot use code combination filter
16214 -- scenario: CCID for JAN-05 was 101 but now it changed to 102 ..
16215 -- in this case, we can create record for 101 (as FC can have issue)
16216 -- If reqd. we can create 101 for the draft version by using a decode
16217
16218 -- 8/22: Code combination filter is fine .. as accounts cannot change on budget lines with txn.
16219 -- And also, the missing lines are created with current amount = 0
16220
16221 Else
16222
16223 INSERT INTO PA_BUDGET_ACCT_LINES (
16224 Budget_Acct_Line_ID,
16225 Budget_Version_ID,
16226 GL_Period_Name,
16227 Start_Date,
16228 End_Date,
16229 Code_Combination_ID,
16230 Prev_Ver_Budget_Amount,
16231 Prev_Ver_Available_Amount,
16232 Curr_Ver_Budget_Amount,
16233 Curr_Ver_Available_Amount,
16234 accounted_amount,
16235 LAST_UPDATE_DATE,
16236 LAST_UPDATED_BY,
16237 LAST_UPDATE_LOGIN,
16238 CREATION_DATE,
16239 CREATED_BY,
16240 REQUEST_ID,
16241 funds_check_status_code,
16242 funds_check_result_code
16243 )
16244 SELECT
16245 PA_BUDGET_ACCT_LINES_S.nextval,
16246 P_Budget_Version_ID, -- current version
16247 BL1.GL_Period_Name,
16248 BL1.Start_Date,
16249 BL1.End_Date,
16250 BL1.Code_Combination_ID,
16251 BL1.Curr_Ver_Budget_Amount,
16252 BL1.Curr_Ver_Available_Amount,
16253 0,
16254 0,
16255 0 - BL1.Curr_Ver_Budget_Amount,
16256 l_date,
16257 l_login,
16258 l_login,
16259 l_date,
16260 l_login,
16261 l_request,
16262 'A',
16263 'P101'
16264 FROM PA_BUDGET_ACCT_LINES BL1
16265 WHERE BL1.Budget_Version_ID = P_prev_budget_version_id
16266 AND (BL1.Curr_Ver_Budget_Amount <> 0 OR
16267 BL1.Prev_Ver_Budget_Amount <> 0)
16268 -- this is to filter the zero $ lines ...
16269 AND NOT EXISTS
16270 ( SELECT 'x'
16271 FROM PA_BUDGET_ACCT_LINES BL2
16272 WHERE BL2.Budget_Version_ID = P_budget_version_id
16273 AND BL2.Code_Combination_ID = BL1.Code_Combination_ID
16274 AND BL2.Start_Date = BL1.Start_Date ) ;
16275 End If;
16276
16277
16278 End If; -- re-baseline check -- II
16279
16280 If g_debug_mode = 'Y' then
16281 log_message(p_msg_token1=>'End:'||l_program_name);
16282 End If;
16283
16284 Exception
16285 When Others then
16286 If g_debug_mode = 'Y' then
16287 log_message(p_msg_token1=>'End:'||l_program_name||SQLERRM);
16288 End If;
16289 RAISE;
16290
16291 END Build_account_summary;
16292
16293 -- --------------------------------------------------------------------------------+
16294 -- This program is called to build the draft summary from Step 4 in do_budget_baseline
16295 -- It calls build_account_summary ..
16296 -- --------------------------------------------------------------------------------+
16297 PROCEDURE Build_account_summary_auto(X_budget_version_id IN NUMBER,
16298 X_balance_type IN VARCHAR2,
16299 X_budget_amount_code IN VARCHAR2,
16300 X_prev_budget_version_id IN NUMBER,
16301 X_mode IN VARCHAR2)
16302 IS
16303 tt_gl_period_name pa_plsql_datatypes.char50TabTyp;
16304 tt_code_combination_id pa_plsql_datatypes.IdTabTyp;
16305 tt_result_code pa_plsql_datatypes.char50TabTyp;
16306 PRAGMA AUTONOMOUS_TRANSACTION;
16307 Begin
16308 If g_debug_mode = 'Y' then
16309 log_message(p_msg_token1=>'Build_account_summary_auto:Start:X_mode:'||X_mode);
16310 End If;
16311
16312 If X_mode = 'FAIL' then
16313 Begin
16314 Select gl_period_name,
16315 code_combination_id,
16316 funds_check_result_code
16317 BULK COLLECT
16318 into tt_gl_period_name,
16319 tt_code_combination_id,
16320 tt_result_code
16321 from pa_budget_acct_lines
16322 where budget_version_id = X_budget_version_id
16323 and funds_check_result_code like 'F%';
16324 Exception
16325 When no_data_found then
16326 null;
16327 End;
16328 End If; --If X_mode = 'FAIL' then
16329
16330
16331 BUILD_ACCOUNT_SUMMARY(p_budget_version_id => X_budget_version_id,
16332 p_balance_type => X_balance_type,
16333 p_budget_amount_code => X_budget_amount_code,
16334 p_prev_budget_version_id => X_prev_budget_version_id);
16335
16336
16337 If X_mode = 'FAIL' then
16338 If tt_code_combination_id.exists(1) then
16339 forall x in tt_result_code.FIRST..tt_result_code.LAST
16340 update pa_budget_acct_lines
16341 set funds_check_result_code = tt_result_code(x)
16342 where budget_version_id = X_budget_version_id
16343 and code_combination_id = tt_code_combination_id(x)
16344 and gl_period_name = tt_gl_period_name(x);
16345
16346
16347 tt_gl_period_name.DELETE;
16348 tt_code_combination_id.DELETE;
16349 tt_result_code.DELETE;
16350
16351 End If;
16352 End If; --If X_mode = 'FAIL' then
16353
16354 COMMIT;
16355
16356 If g_debug_mode = 'Y' then
16357 log_message(p_msg_token1=>'Build_account_summary_auto:End');
16358 End If;
16359
16360 End Build_account_summary_auto;
16361
16362 -- --------------------------------------------------------------------------------+
16363 -- Following procedure resets funds_check_status_code and result code on
16364 -- pa_budget_acct_lines for the draft version ..
16365 -- 8/22: Initalizing to pass status ..
16366 -- --------------------------------------------------------------------------------+
16367 PROCEDURE Reset_status_code_on_summary(p_budget_version_id IN Number)
16368 IS
16369 PRAGMA AUTONOMOUS_TRANSACTION;
16370 Begin
16371
16372 Update pa_budget_acct_lines
16373 set funds_check_status_code = 'A', --null,
16374 funds_check_result_code = 'P101' --null
16375 where budget_version_id = p_budget_version_id;
16376 --and (funds_check_status_code is not null or funds_check_result_code is not null);
16377
16378 If g_debug_mode = 'Y' then
16379 log_message(p_msg_token1=>'Reset_status_code_on_summary:Status nullified on:'||SQL%ROWCOUNT || ' records');
16380 End If;
16381
16382 COMMIT;
16383
16384 End Reset_status_code_on_summary;
16385
16386 -- --------------------------------------------------------------------------------+
16387 -- This autonomous procedure is called to update the newly derived account info.
16388 -- back onto the draft budget lines during baseline/yearend ..
16389 -- --------------------------------------------------------------------------------+
16390 PROCEDURE Upd_new_acct_on_draft_budget(p_budget_line_rowid IN g_tab_rowid%TYPE,
16391 p_budget_ccid IN g_tab_budget_ccid%TYPE,
16392 p_new_ccid IN g_tab_budget_ccid%TYPE,
16393 p_change_allowed IN g_tab_allow_flag%TYPE,
16394 p_record_updated OUT NOCOPY Varchar2)
16395
16396 IS
16397 l_count number;
16398 PRAGMA AUTONOMOUS_TRANSACTION;
16399 Begin
16400 forall x in p_new_ccid.FIRST..p_new_ccid.LAST
16401 Update pa_budget_lines pbl
16402 set pbl.code_combination_id = p_new_ccid(x)
16403 where pbl.rowid = p_budget_line_rowid(x)
16404 and p_budget_ccid(x) <> p_new_ccid(x)
16405 and p_change_allowed(x) = 'Y'
16406 and p_budget_line_rowid(x) is not null;
16407
16408 -- p_change_allowed is used to restrict the budget lines where acct. valdiation failed, F169 issue
16409 -- p_budget_line_rowid is not null, is used to restrict update, this is for the zero $ budget
16410 -- lines that will not be existant in the draft budget
16411
16412 l_count := SQL%ROWCOUNT;
16413
16414 If g_debug_mode = 'Y' then
16415 log_message(p_msg_token1=>'Upd_new_acct_on_draft_budget:Acct. updated on:'||l_count || ' records');
16416 End If;
16417
16418 If l_count > 0 then
16419 p_record_updated := 'Y';
16420 Else
16421 p_record_updated := 'N';
16422 End if;
16423
16424 COMMIT;
16425
16426 End Upd_new_acct_on_draft_budget;
16427
16428 -- --------------------------------------------------------------------------------+
16429 -- This procedure will fail data in the other packet .. i.e. the credit packet ..
16430 -- --------------------------------------------------------------------------------+
16431 PROCEDURE Fail_credit_packet(p_input_packet IN Varchar2,
16432 p_return_status_code OUT NOCOPY varchar2)
16433 IS
16434 -- Cursor used to select records to fail all records ....
16435 -- As data split between packet, records were not being failed in the credit packet ..
16436 Cursor c_gl_records is
16437 select glbc.rowid,glbc.ae_header_id,glbc.ledger_id
16438 from gl_bc_packets glbc
16439 where glbc.event_id in
16440 (select event_id from psa_bc_xla_events_gt);
16441
16442 l_baseline_failed Varchar2(1);
16443 t_ae_header_id TypeNum;
16444 t_ledger_id TypeNum;
16445 t_glrowid TypeVarChar;
16446
16447 BEGIN
16448 l_program_name := 'Fail_credit_packet';
16449
16450 If p_input_packet = 'DEBIT' then
16451
16452 l_baseline_failed := 'Y';
16453
16454 Elsif p_input_packet = 'CREDIT' then
16455
16456 Begin
16457 select 'Y'
16458 into l_baseline_failed
16459 from dual
16460 where exists
16461 (select packet_id
16462 from gl_bc_packets glbc
16463 where glbc.event_id in
16464 (select event_id from psa_bc_xla_events_gt)
16465 and glbc.result_code like 'F%');
16466 Exception
16467 when no_data_found then
16468 l_baseline_failed := 'N';
16469 End;
16470
16471 End If;
16472
16473 If l_baseline_failed = 'N' then
16474 p_return_status_code := 'S';
16475 RETURN;
16476 Else
16477 p_return_status_code := 'F';
16478 End If;
16479
16480 If g_debug_mode = 'Y' then
16481 log_message(p_msg_token1=>l_program_name||'Fail all records for the session');
16482 End If;
16483
16484 Open c_gl_records;
16485 loop
16486 Fetch c_gl_records BULK COLLECT into t_glrowid,
16487 t_ae_header_id,
16488 t_ledger_id
16489 LIMIT l_limit;
16490
16491
16492 If g_debug_mode = 'Y' then
16493 log_message(p_msg_token1=>l_program_name||'No. of records in pl/sql table['||t_glrowid.count||']');
16494 End If;
16495
16496 If t_glrowid.exists(1) then
16497
16498 -- -------------------------------------------------------------------------- +
16499 -- Fail gl_bc_packet records ...
16500 -- -------------------------------------------------------------------------- +
16501 forall i in t_glrowid.FIRST..t_glrowid.LAST
16502 Update gl_bc_packets glbc
16503 set glbc.result_code = decode(substr(glbc.result_code,1,1),'F',glbc.result_code,'F35'),
16504 glbc.status_code = decode(pa_budget_fund_pkg.g_processing_mode,
16505 'CHECK_FUNDS','F','R')
16506 where rowid = t_glrowid(i);
16507
16508 If g_debug_mode = 'Y' then
16509 log_message(p_msg_token1=>l_program_name||'GL packets, records updated['||sql%rowcount||']');
16510 End If;
16511
16512 -- -------------------------------------------------------------------------- +
16513 -- Fail xla_ae_headers_gt records ...
16514 -- -------------------------------------------------------------------------- +
16515 forall i in t_ae_header_id.FIRST..t_ae_header_id.LAST
16516 UPDATE xla_ae_headers_gt
16517 SET funds_status_code = decode(pa_budget_fund_pkg.g_processing_mode,
16518 'CHECK_FUNDS','F','R')
16519 WHERE ae_header_id = t_ae_header_id(i)
16520 AND ledger_id = t_ledger_id(i);
16521
16522 If g_debug_mode = 'Y' then
16523 log_message(p_msg_token1=>l_program_name||'xla_ae_headers_gt, records updated['||sql%rowcount||']');
16524 End If;
16525 -- -------------------------------------------------------------------------- +
16526 -- Fail gl_bc_packet records ...
16527 -- -------------------------------------------------------------------------- +
16528 forall i in t_ae_header_id.FIRST..t_ae_header_id.LAST
16529 UPDATE xla_validation_lines_gt
16530 SET funds_status_code = 'F77'
16531 WHERE ae_header_id = t_ae_header_id(i);
16532
16533 If g_debug_mode = 'Y' then
16534 log_message(p_msg_token1=>l_program_name||'xla_validation_lines_gt, records updated['||sql%rowcount||']');
16535 End If;
16536
16537 -- -------------------------------------------------------------------------- +
16538 -- Initalize records ...
16539 -- -------------------------------------------------------------------------- +
16540
16541 t_glrowid.delete;
16542 t_ae_header_id.delete;
16543 t_ledger_id.delete;
16544
16545 If t_glrowid.COUNT < l_limit then
16546 exit;
16547 End if;
16548
16549 Else -- if t_gl_rowid.exists(1)
16550 exit;
16551 End if;
16552
16553 end loop;
16554
16555
16556 End Fail_credit_packet;
16557
16558
16559 -- ------------------------------------ R12 End ------------------------------------------------+
16560
16561 END PA_FUNDS_CONTROL_PKG;