[Home] [Help]
PACKAGE BODY: APPS.PA_TRX_IMPORT
Source
1 PACKAGE BODY PA_TRX_IMPORT AS
2 /* $Header: PAXTTRXB.pls 120.130.12020000.7 2013/04/05 07:06:35 rboyalap ship $ */
3
4 last_empno VARCHAR2(30) DEFAULT NULL;
5 last_proj VARCHAR2(25) DEFAULT NULL;
6 last_task VARCHAR2(25) DEFAULT NULL;
7 last_etype VARCHAR2(30) DEFAULT NULL;
8 current_expend VARCHAR2(2000) DEFAULT NULL;
9 current_expend2 VARCHAR2(2000) DEFAULT NULL;
10 current_period DATE DEFAULT NULL;
11
12
13 current_system_linkage VARCHAR2(30) DEFAULT NULL;
14
15 G_trx_source VARCHAR2(30) DEFAULT NULL;
16 G_eclass VARCHAR2(30) DEFAULT NULL;
17 G_trx_link VARCHAR2(30) DEFAULT NULL;
18 G_trx_costed VARCHAR2(1) DEFAULT NULL;
19 G_trx_start DATE DEFAULT NULL;
20 G_trx_end DATE DEFAULT NULL;
21 G_emp_org_oride VARCHAR2(1) DEFAULT NULL;
22
23 G_trx_predef_flag VARCHAR2(1) DEFAULT NULL;
24 G_allow_adj_flag VARCHAR2(1) DEFAULT NULL;
25 G_gl_accted_flag VARCHAR2(1) DEFAULT NULL;
26 G_allow_dup_flag VARCHAR2(1) DEFAULT NULL;
27 /* G_skip_tc_flag VARCHAR2(1) DEFAULT NULL;
28 Removed for bug 1299909 as this has been moved to sepcs of this package. */
29 G_burdened_flag VARCHAR2(1) DEFAULT NULL;
30
31 G_etype_link VARCHAR2(30) DEFAULT NULL;
32 G_etype_start DATE DEFAULT NULL;
33 G_etype_end DATE DEFAULT NULL;
34 G_etype_cr NUMBER(22,5) DEFAULT 1;
35 G_etype_cost_rate_flag VARCHAR2(1) DEFAULT NULL;
36
37 G_etype_active BOOLEAN DEFAULT FALSE ;
38 G_etec_start DATE DEFAULT NULL ;
39 G_etec_end DATE DEFAULT NULL ;
40 G_etype_labor_flag VARCHAR2(1) DEFAULT NULL;
41
42 G_person_id NUMBER(15) DEFAULT NULL;
43 G_org_id NUMBER(15) DEFAULT NULL;
44 G_job_id NUMBER(15) DEFAULT NULL;
45 G_task_id NUMBER(15) DEFAULT NULL;
46 G_project_id NUMBER(15) DEFAULT NULL;
47 G_adj_item_id NUMBER(15) DEFAULT NULL;
48 G_user NUMBER(15) DEFAULT NULL;
49
50 G_Proj_bcost_flag VARCHAR2(1) DEFAULT NULL ;
51
52 G_nlro_id NUMBER(15) DEFAULT NULL;
53 G_nlr_etype VARCHAR2(30) DEFAULT NULL;
54 G_nlr_start DATE DEFAULT NULL;
55 G_nlr_end DATE DEFAULT NULL;
56 G_nlro_start DATE DEFAULT NULL;
57 G_nlro_end DATE DEFAULT NULL;
58
59 G_lcm VARCHAR2(20) DEFAULT NULL;
60 G_burden_compile_set_id NUMBER DEFAULT NULL;
61 G_compiled_multiplier NUMBER := 0;
62
63 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
64 --
65 g_paapimp_validate_dt varchar2(1) := 'Y' ;
66
67 -- MC Changes
68 G_accounting_currency_code VARCHAR2(15) DEFAULT NULL;
69 G_allow_acct_user_rate VARCHAR2(1) DEFAULT NULL;
70 G_allow_foreign_curr_txn VARCHAR2(1) DEFAULT NULL;
71 G_allow_proj_user_rate VARCHAR2(1) DEFAULT NULL;
72 G_allow_copy_acct_cost_flag VARCHAR2(1) DEFAULT NULL;
73 G_project_currency_code VARCHAR2(15) DEFAULT NULL;
74 G_default_rate_type VARCHAR2(30) DEFAULT NULL;
75 G_proj_rate_date DATE DEFAULT NULL;
76 G_project_rate_type gl_daily_conversion_types.conversion_type%TYPE
77 DEFAULT NULL;
78 G_acct_rate_type gl_daily_conversion_types.conversion_type%TYPE DEFAULT NULL;
79 G_raw_cost NUMBER DEFAULT NULL;
80
81 /* Trx_Import Enhancement */
82 G_override_to_org_id NUMBER DEFAULT NULL;
83 /*G_orig_exp_txn_reference1 VARCHAR2(30) DEFAULT NULL;
84 G_orig_user_exp_txn_reference VARCHAR2(30) DEFAULT NULL; */
85 /* Size of the two variables commented above have been modified to varchar2(60) as fix for bug 1504289*/
86 G_orig_exp_txn_reference1 VARCHAR2(60) DEFAULT NULL;
87 G_orig_user_exp_txn_reference VARCHAR2(60) DEFAULT NULL;
88 G_vendor_id NUMBER DEFAULT NULL;
89 G_Vendor_Site_id NUMBER DEFAULT NULL;
90 G_previous_vendor_number VARCHAR2(30) DEFAULT NULL;
91 G_orig_exp_txn_reference2 VARCHAR2(60) DEFAULT NULL;
92 G_orig_exp_txn_reference3 VARCHAR2(60) DEFAULT NULL;
93 /* End of Enhancment */
94
95 X_ei_id NUMBER(15) DEFAULT NULL;
96
97 G_CDL_SYSTEM_REFERENCE2 NUMBER;
98 G_CDL_SYSTEM_REFERENCE3 NUMBER;
99 G_CDL_SYSTEM_REFERENCE4 pa_transaction_interface_all.cdl_system_reference4%TYPE; --2339216-apdisc; Commented for bug 4281765
100 /* REL12-AP Lines uptake
101 ** Support for cdl_system_reference5
102 ** cdl_system_reference5 to store invoice distribution ID
103 */
104 G_CDL_SYSTEM_REFERENCE5 NUMBER;
105 G_MOAC_ORG_ID NUMBER ;
106
107
108 -- SST changes: New global variables
109 G_pre_processing_extn pa_transaction_sources.pre_processing_extension%TYPE
110 DEFAULT NULL;
111 G_post_processing_extn pa_transaction_sources.post_processing_extension%TYPE
112 DEFAULT NULL;
113
114 G_reversed_orig_txn_reference PA_TRANSACTION_INTERFACE_ALL.reversed_orig_txn_reference%TYPE;
115
116 /* Bug 4107560 */
117 G_prev_ORIG_TRAN_REF PA_TRANSACTION_INTERFACE_ALL.ORIG_TRANSACTION_REFERENCE%TYPE;
118 G_WIP_RESOURCE_ID PA_TRANSACTION_INTERFACE_ALL.WIP_RESOURCE_ID%TYPE;
119
120
121 G_project_type_class PA_PROJECT_TYPES_ALL.PROJECT_TYPE_CLASS_CODE%TYPE;
122 /* added for the bug# 1428216, starts here */
123 G_burden_amt_display_method PA_PROJECT_TYPES_ALL.BURDEN_AMT_DISPLAY_METHOD%TYPE;
124 /* added for the bug# 1428216, ends here */
125 -- End SST Changes
126
127 -- IC Changes
128 G_CrossChargeType pa_expenditure_items_all.cc_cross_charge_type%TYPE;
129 G_CrossChargeCode pa_expenditure_items_all.cc_cross_charge_code%TYPE;
130 G_PrvdrOrganizationId hr_organization_units.organization_id%TYPE;
131 G_RecvrOrganizationId hr_organization_units.organization_id%TYPE;
132 G_RecvrOrgId hr_organization_units.organization_id%TYPE;
133 G_BrowLentDistCode pa_expenditure_items_all.cc_bl_distributed_code%TYPE;
134 G_IcProcessed_Code pa_expenditure_items_all.cc_ic_processed_code%TYPE;
135 -- END IC Changes
136 current_etype_classcode VARCHAR2(100) DEFAULT NULL;
137
138 -- Oct 2001 Enhanced Period Processing
139 -- Start EPP Changes
140 G_PaDate pa_cost_distribution_lines_all.pa_date%TYPE;
141 G_PaPeriodName pa_cost_distribution_lines_all.pa_period_name%TYPE;
142 G_RecvrPaDate pa_cost_distribution_lines_all.recvr_pa_date%TYPE;
143 G_RecvrPaPeriodName pa_cost_distribution_lines_all.recvr_pa_period_name%TYPE;
144 G_GlPeriodName pa_cost_distribution_lines_all.gl_period_name%TYPE;
145 G_RecvrGlDate pa_cost_distribution_lines_all.recvr_gl_date%TYPE;
146 G_RecvrGlPeriodName pa_cost_distribution_lines_all.recvr_gl_period_name%TYPE;
147 G_SobId pa_implementations_all.set_of_books_id%TYPE;
148 G_RecvrSobId pa_implementations_all.set_of_books_id%TYPE;
149 -- G_FSIO_ENABLED varchar2(1); --FSIO Changes
150
151 Prev_SobId NUMBER;
152 Prev_OrgID NUMBER;
153 Prev_RecvrSobId NUMBER;
154 Prev_RecvrOrgID NUMBER;
155 -- End EPP Changes
156
157 --Start PA-I Changes
158 G_projfunc_cost_rate_type gl_daily_conversion_types.conversion_type%TYPE DEFAULT NULL;
159 G_Assignment_Id NUMBER;
160 G_Work_Type_Id NUMBER;
161 G_Tp_Amt_Type_Code VARCHAR2(30);
162 --End PA-I Changes
163
164 --Start PA-J Period-End Accrual Changes
165 G_GlDate DATE;
166 G_AccDate DATE;
167 G_RecvrAccDate DATE;
168 G_RevAccDate DATE;
169 G_RevRecvrAccDate DATE;
170 G_RevPaDate pa_cost_distribution_lines_all.pa_date%TYPE;
171 G_RevPaPeriodName pa_cost_distribution_lines_all.pa_period_name%TYPE;
172 G_RevGlDate pa_cost_distribution_lines_all.gl_date%TYPE;
173 G_RevGlPeriodName pa_cost_distribution_lines_all.gl_period_name%TYPE;
174 G_RevRecvrPaDate pa_cost_distribution_lines_all.recvr_pa_date%TYPE;
175 G_RevRecvrPaPdName pa_cost_distribution_lines_all.recvr_pa_period_name%TYPE;
176 G_RevRecvrGlDate pa_cost_distribution_lines_all.recvr_gl_date%TYPE;
177 G_RevRecvrGlPdName pa_cost_distribution_lines_all.recvr_gl_period_name%TYPE;
178 --End PA-J Period-End Accrual Changes
179
180 --Start PA-K Changes
181 G_Process_Funds_Flag VARCHAR2(1);
182 l_Expend1 VARCHAR2(2000) DEFAULT NULL;
183 l_Expend2 VARCHAR2(2000) DEFAULT NULL;
184 G_Group_Name VARCHAR2(240); /* Bug#2373198 Increased size from 80 to 240 */
185
186 G_MOrg VARCHAR2(1);
187 G_PrjInfoPrjId NUMBER;
188 G_PrjInfoBCostFlag VARCHAR2(1);
189 G_PrjInfoTypeClass PA_PROJECT_TYPES_ALL.PROJECT_TYPE_CLASS_CODE%TYPE;
190 G_PrjInfoBdDisplay PA_PROJECT_TYPES_ALL.BURDEN_AMT_DISPLAY_METHOD%TYPE;
191 G_PrjInfoTotBdFlag PA_PROJECT_TYPES_ALL.TOTAL_BURDEN_FLAG%TYPE;
192 G_NewTxnPrjId NUMBER;
193 --G_NewTxnsAllowed VARCHAR2(1);
194 G_EClassInfoEtype VARCHAR2(30);
195 /* bug #3134359 changed the size of G_EClassInfoSysLink to 30 from 3
196 as this is the size allowed in the base table pa_system_linkages.function,
197 size 30 is allowed in the front end also,ideally this should work with 3
198 if the values are from lookup */
199 --G_EClassInfoSysLink VARCHAR2(3);
200 G_EClassInfoSysLink VARCHAR2(30);
201 G_ETypeInfoEtype VARCHAR2(30);
202 G_ETypeInfoDate DATE;
203 G_NlrInfoNlr VARCHAR2(20);
204 G_NlrInfoNlroId NUMBER;
205 G_CurrInfoPrjCurrCode VARCHAR2(15);
206 G_CurrInfoPrjRtType VARCHAR2(30);
207 G_CurrInfoPrjFCurrCode VARCHAR2(15);
208 G_CurrInfoPrjFRtType VARCHAR2(30);
209 G_CurrInfoTaskId NUMBER;
210 G_OrgNameEmpNum VARCHAR2(30);
211 G_OrgNameDate DATE;
212 G_OrgNameOrgName hr_all_organization_units.name%TYPE;
213 G_OrgNameBGName hr_all_organization_units.name%TYPE;
214 G_OrgNameBGId NUMBER;
215 G_PrevCCID NUMBER;
216 G_PrevRetVal NUMBER;
217 G_Total_Burden_Flag VARCHAR2(1);
218
219 G_Debug_Mode VARCHAR2(1) ;
220
221 --added variable for cost blue-print project
222 G_gl_posted_flag VARCHAR2(1) DEFAULT NULL;
223
224 -- 10253400: Payroll integration enhancement for 12.2..start
225 G_Location_Id Number DEFAULT NULL;
226 G_Pay_Element_Type_Id NUMBER default NULL;
227
228 ---- Added for payroll billable_flag changes for 12.2 start bug#12344689
229 g_costing_method pa_compensation_rule_sets.costing_method%type;
230 g_rate_source_code pa_compensation_rule_sets.rate_source_code%type;
231 g_enable_accrual_code pa_compensation_rule_sets.enable_accrual_code%type;
232 g_payroll_accrual_flag VARCHAR2(1) default NULL; ---- Added for payroll billable_flag changes for 12.2 end bug#12344689
233
234 -- 10253400: Payroll integration enhancement for 12.2..end
235
236 PG_DEBUG varchar2(1) := NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
237
238 P_BTC_SRC_RESRC varchar2(1) := NVL(FND_PROFILE.value('PA_RPT_BTC_SRC_RESRC'), 'N'); -- 4057874
239 G_Cbs_Element_Id NUMBER DEFAULT NULL; -- Added for CBS Enhancement Bug 16220146
240 -- R12 funds management uptake : Below global variables stores adjusting expenditures data
241 -- which will be accessed by fundscheck autonomous API's
242
243 g_xface_project_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
244 g_xface_task_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
245 g_xface_exp_type_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
246 g_xface_ei_date_tbl PA_PLSQL_DATATYPES.DateTabTyp;
247 g_xface_exp_org_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
248 g_xface_bud_ver_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
249 g_xface_Entered_Cr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
250 g_xface_Entered_Dr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
251 g_xface_acct_Cr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
252 g_xface_acct_Dr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
253 g_xface_Txn_Ccid_tbl PA_PLSQL_DATATYPES.IdTabTyp;
254 g_xface_org_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
255 g_xface_Txn_interface_tbl PA_PLSQL_DATATYPES.IdTabTyp;
256 g_xface_vendor_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
257 g_vendor_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
258
259 g_sob_Id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
260 g_Period_Year_tbl PA_PLSQL_DATATYPES.NumTabTyp;
261 g_project_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
262 g_task_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
263 g_exp_type_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
264 g_ei_date_tbl PA_PLSQL_DATATYPES.DateTabTyp;
265 g_exp_org_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
266 g_bud_ver_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
267 g_budget_line_id_tbl PA_PLSQL_DATATYPES.IdTabTyp; -- R12 Funds Management uptake
268 g_Document_Type_tbl PA_PLSQL_DATATYPES.Char10TabTyp;
269 g_Doc_Header_Id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
270 g_Doc_dist_Id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
271 g_Entered_Cr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
272 g_Entered_Dr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
273 g_acct_Cr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
274 g_acct_Dr_tbl PA_PLSQL_DATATYPES.NumTabTyp;
275 g_Actual_Flag_tbl PA_PLSQL_DATATYPES.Char1TabTyp;
276 g_Txn_Ccid_tbl PA_PLSQL_DATATYPES.IdTabTyp;
277 g_Je_Catg_Name_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
278 g_Je_sorce_Name_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
279 g_org_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
280 g_Pa_Date_tbl PA_PLSQL_DATATYPES.DateTabTyp;
281 g_packet_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
282 g_bc_packet_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
283 g_bc_parent_pkt_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
284 g_enc_type_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
285 g_doc_hdr_id_2_tbl PA_PLSQL_DATATYPES.IdTabTyp;
286 g_doc_dist_type_tbl PA_PLSQL_DATATYPES.Char30TabTyp;
287 g_bc_comt_id_tbl PA_PLSQL_DATATYPES.IdTabTyp;
288
289
290
291
292
293 -- R12 funds management uptake : End
294
295 PROCEDURE log_message(p_message in VARCHAR2, p_mode in NUMBER DEFAULT 0);
296
297 --End PA-K Changes
298
299 --Bug 2905892
300 G_FC_Gl_Date DATE;
301 G_FC_Period_Name pa_bc_packets.period_name%Type;
302 G_FC_Period_Year pa_bc_packets.period_year%type; --REL12
303 G_PrevFCGLDate DATE;
304 G_PrevFCPdName pa_bc_packets.period_name%Type;
305
306 PROCEDURE tr_import_funds_check (p_pa_date IN DATE,
307 p_txn_source IN VARCHAR2,
308 p_acct_raw_cost IN NUMBER,
309 p_adj_exp_item_id IN NUMBER,
310 p_txn_interface_id IN NUMBER,
311 p_fc_document_type IN VARCHAR2,
312 x_packet_id OUT NOCOPY NUMBER ,
313 x_error_message_code OUT NOCOPY VARCHAR2 ,
314 x_error_stage OUT NOCOPY VARCHAR2 ,
315 x_return_status OUT NOCOPY VARCHAR2);
316
317 PROCEDURE tieback_fc_records ( x_return_status OUT NOCOPY VARCHAR2,
318 p_calling_mode IN VARCHAR2) ;
319
320 --PA-J Receipt Accrual Changes
321 --Added the below new procedures for funds check
322 PROCEDURE ap_funds_check (
323 p_txn_source IN VARCHAR2,
324 p_acct_raw_cost IN NUMBER,
325 p_packet_id IN NUMBER,
326 p_sys_ref2 IN NUMBER,
327 p_sys_ref3 IN NUMBER,
328 p_sys_ref5 IN NUMBER, --REL12
329 p_adj_exp_item_id IN NUMBER, --REL12
330 p_txn_interface_id IN NUMBER, --REL12
331 p_fc_document_type IN VARCHAR2, --REL12
332 x_error_message_code OUT NOCOPY VARCHAR2,
333 x_error_stage OUT NOCOPY VARCHAR2,
334 x_return_status OUT NOCOPY VARCHAR2) ;
335
336 PROCEDURE ap_po_funds_check (
337 p_txn_source IN VARCHAR2,
338 p_acct_raw_cost IN NUMBER,
339 p_packet_id IN NUMBER,
340 p_po_hdr_id IN NUMBER,
341 p_po_dist_id IN NUMBER,
342 p_inv_id IN NUMBER,
343 p_inv_dist_id IN NUMBER, --REL12
344 p_dist_line IN NUMBER,
345 p_adj_exp_item_id IN NUMBER, --REL12
346 p_txn_interface_id IN NUMBER, --REL12
347 p_fc_document_type IN VARCHAR2, --REL12
348 p_base_qty_var_amt IN NUMBER,
349 p_base_amt_var_amt IN NUMBER,
350 x_error_message_code OUT NOCOPY VARCHAR2,
351 x_error_stage OUT NOCOPY VARCHAR2,
352 x_return_status OUT NOCOPY VARCHAR2);
353
354 PROCEDURE po_funds_check (
355 p_txn_source IN VARCHAR2,
356 p_acct_raw_cost IN NUMBER,
357 p_packet_id IN NUMBER,
358 p_sys_ref2 IN NUMBER,
359 p_sys_ref3 IN NUMBER,
360 p_sys_ref4 IN NUMBER, -- Bug 5530897 : Added the parameter p_sys_ref4.
361 p_adj_exp_item_id IN NUMBER, --REL12
362 p_txn_interface_id IN NUMBER, --REL12
363 p_fc_document_type IN VARCHAR2, --REL12
364 x_error_message_code OUT NOCOPY VARCHAR2,
365 x_error_stage OUT NOCOPY VARCHAR2,
366 x_return_status OUT NOCOPY VARCHAR2);
367
368 --2339216-apdisc
369 PROCEDURE ap_disc_funds_check (
370 p_txn_source IN VARCHAR2,
371 p_acct_raw_cost IN NUMBER,
372 p_packet_id IN NUMBER,
373 p_sys_ref2 IN NUMBER,
374 p_sys_ref3 IN NUMBER,
375 p_sys_ref4 IN VARCHAR2, --REL12
376 p_sys_ref5 IN NUMBER, --REL12
377 p_adj_exp_item_id IN NUMBER, --REL12
378 p_txn_interface_id IN NUMBER, --REL12
379 p_fc_document_type IN VARCHAR2, --REL12
380 x_error_message_code OUT NOCOPY VARCHAR2,
381 x_error_stage OUT NOCOPY VARCHAR2,
382 x_return_status OUT NOCOPY VARCHAR2) ;
383 PROCEDURE ap_cash_based_funds_check (
384 p_txn_source IN VARCHAR2,
385 p_acct_raw_cost IN NUMBER,
386 p_packet_id IN NUMBER,
387 p_sys_ref2 IN NUMBER, --REL12
388 p_sys_ref4 IN VARCHAR2, --REL12
389 p_sys_ref5 IN NUMBER, --REL12
390 p_adj_exp_item_id IN NUMBER, --REL12
391 p_txn_interface_id IN NUMBER, --REL12
392 p_fc_document_type IN VARCHAR2, --REL12
393 x_error_message_code OUT NOCOPY VARCHAR2,
394 x_error_stage OUT NOCOPY VARCHAR2,
395 x_return_status OUT NOCOPY VARCHAR2);
396
397 PROCEDURE insert_ap_bc_packets(p_packet_id IN NUMBER,
398 p_sys_ref2 IN NUMBER,
399 p_sys_ref4 IN VARCHAR2,
400 p_sys_ref5 IN NUMBER,
401 p_acct_raw_cost IN NUMBER,
402 p_acct_bur_cost IN NUMBER,
403 p_fc_document_type IN VARCHAR2,
404 p_txn_source IN VARCHAR2,
405 p_adj_exp_item_id IN NUMBER,
406 p_txn_interface_id IN NUMBER);
407
408 PROCEDURE insert_ap_bc_pkt_autonomous
409 (p_packet_id IN NUMBER,
410 p_sys_ref2 IN NUMBER,
411 p_sys_ref4 IN VARCHAR2,
412 p_sys_ref5 IN NUMBER,
413 p_acct_raw_cost IN NUMBER,
414 p_acct_bur_cost IN NUMBER,
415 p_fc_document_type IN VARCHAR2,
416 p_txn_source IN VARCHAR2,
417 p_adj_exp_item_id IN NUMBER,
418 p_txn_interface_id IN NUMBER,
419 p_comm_fc_req IN VARCHAR2,
420 p_act_fc_req IN VARCHAR2,
421 p_adj_act_fc_req IN VARCHAR2);
422
423 PROCEDURE insert_cash_ap_bc_packets(p_packet_id IN NUMBER,
424 p_sys_ref2 IN NUMBER,
425 p_sys_ref5 IN NUMBER,
426 p_acct_raw_cost IN NUMBER,
427 p_fc_document_type IN VARCHAR2,
428 p_txn_source IN VARCHAR2,
429 p_adj_exp_item_id IN NUMBER,
430 p_txn_interface_id IN NUMBER,
431 p_cash_pay_to_relieve IN NUMBER DEFAULT 0);
432
433 PROCEDURE insert_cash_ap_bc_pkt_auto
434 (p_packet_id IN NUMBER,
435 p_sys_ref2 IN NUMBER,
436 p_sys_ref5 IN NUMBER,
437 p_acct_raw_cost IN NUMBER,
438 p_fc_document_type IN VARCHAR2,
439 p_txn_source IN VARCHAR2,
440 p_adj_exp_item_id IN NUMBER,
441 p_txn_interface_id IN NUMBER,
442 p_cash_pay_to_relieve IN NUMBER DEFAULT 0,
443 p_comm_fc_req IN VARCHAR2,
444 p_act_fc_req IN VARCHAR2,
445 p_adj_act_fc_req IN VARCHAR2);
446
447 PROCEDURE insert_po_bc_packets(p_packet_id IN NUMBER,
448 p_sys_ref2 IN NUMBER,
449 p_sys_ref4 IN NUMBER,
450 p_sys_ref3 IN NUMBER,
451 p_acct_raw_cost IN NUMBER,
452 p_cmt_raw_cost IN NUMBER,
453 p_fc_document_type IN VARCHAR2,
454 p_txn_source IN VARCHAR2,
455 p_adj_exp_item_id IN NUMBER,
456 p_txn_interface_id IN NUMBER);
457
458 /* Bug 5396719 : Modified the parameters p_comm_fc_req,p_act_fc_req and p_adj_act_fc_req
459 of the PROCEDURE insert_po_bc_packets_auto to be of VARCHAR2 datatype. */
460
461 PROCEDURE insert_po_bc_packets_auto
462 (p_packet_id IN NUMBER,
463 p_sys_ref2 IN NUMBER,
464 p_sys_ref4 IN NUMBER,
465 p_sys_ref3 IN NUMBER,
466 p_acct_raw_cost IN NUMBER,
467 p_cmt_raw_cost IN NUMBER,
468 p_fc_document_type IN VARCHAR2,
469 p_txn_source IN VARCHAR2,
470 p_adj_exp_item_id IN NUMBER,
471 p_txn_interface_id IN NUMBER,
472 p_comm_fc_req IN VARCHAR2,
473 p_act_fc_req IN VARCHAR2,
474 p_adj_act_fc_req IN VARCHAR2);
475
476
477 -- Log messages changes
478 --l_debug_mode VARCHAR2(20) := 'N';
479
480 RESOURCE_BUSY EXCEPTION;
481 PRAGMA EXCEPTION_INIT( RESOURCE_BUSY, -0054 );
482
483 i BINARY_INTEGER DEFAULT 0;
484
485 PROCEDURE init_xface_plsql_tables IS
486 BEGIN
487 g_xface_project_id_tbl.delete;
488 g_xface_task_id_tbl.delete;
489 g_xface_exp_type_tbl.delete;
490 g_xface_ei_date_tbl.delete;
491 g_xface_exp_org_id_tbl.delete;
492 g_xface_bud_ver_id_tbl.delete;
493 g_xface_Entered_Cr_tbl.delete;
494 g_xface_Entered_Dr_tbl.delete;
495 g_xface_acct_Cr_tbl.delete;
496 g_xface_acct_Dr_tbl.delete;
497 g_xface_Txn_Ccid_tbl.delete;
498 g_xface_org_id_tbl.delete;
499 g_xface_Txn_interface_tbl.delete;
500 END init_xface_plsql_tables;
501
502 /* Deleting plsql tables */
503
504 PROCEDURE clear_plsql_tables IS
505 BEGIN
506
507 g_sob_Id_tbl.delete;
508 g_Period_Year_tbl.delete;
509 g_project_id_tbl.delete;
510 g_task_id_tbl.delete;
511 g_exp_type_tbl.delete;
512 g_ei_date_tbl.delete;
513 g_exp_org_id_tbl.delete;
514 g_bud_ver_id_tbl.delete;
515 g_budget_line_id_tbl.delete; -- R12 Funds Management uptake
516 g_Document_Type_tbl.delete;
517 g_Doc_Header_Id_tbl.delete;
518 g_Doc_dist_Id_tbl.delete;
519 g_Entered_Cr_tbl.delete;
520 g_Entered_Dr_tbl.delete;
521 g_acct_Cr_tbl.delete;
522 g_acct_Dr_tbl.delete;
523 g_Actual_Flag_tbl.delete;
524 g_Txn_Ccid_tbl.delete;
525 g_Je_Catg_Name_tbl.delete;
526 g_Je_sorce_Name_tbl.delete;
527 g_org_id_tbl.delete;
528 g_Pa_Date_tbl.delete;
529 g_bc_packet_id_tbl.delete;
530 g_packet_id_tbl.delete;
531 g_bc_parent_pkt_id_tbl.delete;
532 g_enc_type_id_tbl.delete;
533 g_doc_hdr_id_2_tbl.delete;
534 g_doc_dist_type_tbl.delete;
535 g_bc_comt_id_tbl.delete;
536
537 END clear_plsql_tables;
538
539 PROCEDURE GetTrxSrcInfo ( X_trx_src IN VARCHAR2 )
540 IS
541 BEGIN
542
543 pa_cc_utils.set_curr_function('GetTrxSrcInfo');
544
545 -- Modifying this query to check for transaction_source rather than
546 -- user transaction source
547 -- 697638 Bug fix
548 --
549 -- Removed cost_burdened_flag, this flag is obsolete for 11.5, the
550 -- functionality is replaced by allow_burden_flag
551
552 SELECT ts.transaction_source
553 , ts.system_linkage_function
554 , DECODE( ts.system_linkage_function,
555 'ST', 'PT',
556 'ER', 'PE',
557 'VI','VI','PU' )/* Added for bug 2041741*/
558 , ts.costed_flag
559 , ts.start_date_active
560 , ts.end_date_active
561 , predefined_flag
562 , allow_adjustments_flag
563 , gl_accounted_flag
564 , nvl(posted_flag, 'N') -- get posted_flag
565 , allow_duplicate_reference_flag
566 , skip_tc_validation_flag
567 , allow_emp_org_override_flag
568 , allow_burden_flag
569 , pre_processing_extension -- SST change
570 , post_processing_extension -- SST change
571 , nvl(batch_size,0)
572 , nvl(process_funds_check,'N')
573 INTO
574 G_trx_source
575 , G_trx_link
576 , G_eclass
577 , G_trx_costed
578 , G_trx_start
579 , G_trx_end
580 , G_trx_predef_flag
581 , G_allow_adj_flag
582 , G_gl_accted_flag
583 , G_gl_posted_flag
584 , G_allow_dup_flag
585 , G_skip_tc_flag
586 , G_emp_org_oride
587 , G_burdened_flag
588 , G_pre_processing_extn
589 , G_post_processing_extn
590 , G_Batch_Size
591 , G_Process_Funds_Flag
592 FROM
593 pa_transaction_sources ts
594 WHERE
595 ts.transaction_source = X_trx_src;
596
597 pa_cc_utils.reset_curr_function;
598 EXCEPTION
599 WHEN NO_DATA_FOUND THEN
600 G_trx_link := NULL;
601 pa_cc_utils.reset_curr_function;
602 END GetTrxSrcInfo;
603
604 -- Get implementation currency information
605 --
606 PROCEDURE GetImpCurrInfo
607 IS
608 BEGIN
609 pa_cc_utils.set_curr_function('GetImpCurrInfo');
610 IF PG_DEBUG = 'Y' THEN
611 pa_debug.G_err_Stage := 'call to pa_multi_currency.init';
612 log_message('log_message: ' || pa_debug.G_err_Stage);
613 END IF;
614
615 pa_multi_currency.init;
616
617 IF PG_DEBUG = 'Y' THEN
618 pa_debug.G_err_stage := 'Assigning currency code and rate type to local variables';
619 log_message('log_message: ' || pa_debug.G_err_Stage);
620 END IF;
621 G_accounting_currency_code := pa_multi_currency.G_accounting_currency_code;
622 G_default_rate_type := pa_multi_currency.G_rate_type;
623
624 IF PG_DEBUG = 'Y' THEN
625 pa_debug.G_err_Stage := 'Before calling pa_cc_utils.reset_curr_function';
626 log_message('log_message: ' || pa_debug.G_err_Stage);
627 END IF;
628
629 pa_cc_utils.reset_curr_function;
630
631 IF PG_DEBUG = 'Y' THEN
632 pa_debug.G_err_Stage := 'After calling pa_cc_utils.reset_curr_function';
633 log_message('log_message: ' || pa_debug.G_err_Stage);
634 END IF;
635
636 EXCEPTION
637 WHEN NO_DATA_FOUND THEN
638 IF PG_DEBUG = 'Y' THEN
639 pa_debug.G_err_Stage := 'Inside When NO_DATA_FOUND Exception of GetImpCurrInfo';
640 log_message('log_message: ' || pa_debug.G_err_Stage);
641 END IF;
642 G_default_rate_type := NULL;
643 G_accounting_currency_code := NULL;
644 pa_cc_utils.reset_curr_function;
645 END GetImpCurrInfo;
646
647 --
648 -- Get project/task currency information
649 --
650 PROCEDURE GetProjCurrInfo( X_task_id IN NUMBER,
651 X_project_currency_code IN OUT NOCOPY VARCHAR2,
652 X_project_rate_type IN OUT NOCOPY VARCHAR2,
653 -- PA-I Changes : Added proj func attr
654 X_projfunc_currency_code IN OUT NOCOPY VARCHAR2,
655 X_projfunc_cost_rate_type IN OUT NOCOPY VARCHAR2)
656 IS
657 BEGIN
658
659 pa_cc_utils.set_curr_function('GetProjCurrInfo');
660 IF PG_DEBUG = 'Y' THEN
661 log_message('log_message: In GetProjCurrInfo api');
662 pa_debug.G_err_stage := 'Calling get_project_rate_type';
663 log_message('log_message: ' || pa_debug.G_err_Stage);
664 END IF;
665
666 If (G_CurrInfoTaskId = X_task_id) Then
667
668 IF PG_DEBUG = 'Y' THEN
669 pa_debug.G_err_stage := 'Using Cached Values';
670 log_message('log_message: ' || pa_debug.G_err_Stage);
671 END IF;
672
673 X_project_currency_code := G_CurrInfoPrjCurrCode;
674 X_project_rate_type := G_CurrInfoPrjRtType;
675 X_projfunc_currency_code := G_CurrInfoPrjFCurrCode;
676 X_projfunc_cost_rate_type := G_CurrInfoPrjFRtType;
677
678 G_CurrInfoTaskId := X_task_id;
679
680 Else
681
682 IF PG_DEBUG = 'Y' THEN
683 pa_debug.G_err_stage := 'Selecting Values';
684 log_message('log_message: ' || pa_debug.G_err_Stage);
685 log_message('log_message: Calling pa_multi_currency_txn.get_proj_rate_type');
686 END IF;
687
688 -- PA-I Changes : The API get_project_rate_type has been renamed to get_proj_rate_type
689 pa_multi_currency_txn.get_proj_rate_type(P_task_id => X_task_id,
690 P_project_currency_code => X_project_currency_code,
691 P_project_rate_type => X_project_rate_type);
692
693 IF PG_DEBUG = 'Y' THEN
694 log_message('log_message: After Calling pa_multi_currency_txn.get_proj_rate_type');
695 pa_debug.G_err_stage := 'Calling pa_multi_currency_txn.get_projfunc_cost_rate_type';
696 log_message('log_message: ' || pa_debug.G_err_Stage);
697 END IF;
698
699 -- PA-I Changes : Calling API to get Proj Functional Currency Code only
700 pa_multi_currency_txn.get_projfunc_cost_rate_type(P_task_id => X_task_id,
701 P_projfunc_currency_code => X_projfunc_currency_code,
702 P_projfunc_cost_rate_type => X_projfunc_cost_rate_type);
703 IF PG_DEBUG = 'Y' THEN
704 pa_debug.G_err_stage := 'After Calling get_projfunc_rate_type';
705 log_message('log_message: ' || pa_debug.G_err_Stage);
706 END IF;
707
708 G_CurrInfoPrjCurrCode := X_project_currency_code;
709 G_CurrInfoPrjRtType := X_project_rate_type;
710 G_CurrInfoPrjFCurrCode := X_projfunc_currency_code;
711 G_CurrInfoPrjFRtType := X_projfunc_cost_rate_type;
712
713 G_CurrInfoTaskId := X_task_id;
714
715 IF PG_DEBUG = 'Y' THEN
716 log_message('log_message: Value of X_project_currency_code= ' || X_project_currency_code);
717 log_message('log_message: Value of X_project_rate_type= ' || X_project_rate_type);
718 log_message('log_message: Value of X_projfunc_currency_code= ' || X_projfunc_currency_code);
719 log_message('log_message: Value of X_projfunc_cost_rate_type= ' || X_projfunc_cost_rate_type);
720 END IF;
721
722 End If;
723
724 pa_cc_utils.reset_curr_function;
725
726 END GetProjCurrInfo;
727
728 --
729 -- default functional and project currency conversion attributes
730 --
731 PROCEDURE DefaultCurrAttributes(X_acct_currency_code IN VARCHAR2,
732 X_project_currency_code IN VARCHAR2,
733 X_acct_rate_date IN OUT NOCOPY DATE,
734 X_acct_rate_type IN OUT NOCOPY VARCHAR2,
735 X_acct_exchange_rate IN OUT NOCOPY NUMBER,
736 X_project_rate_date IN OUT NOCOPY DATE,
737 X_project_rate_type IN OUT NOCOPY VARCHAR2,
738 X_project_exchange_rate IN OUT NOCOPY NUMBER )
739 IS
740
741 BEGIN
742
743 pa_cc_utils.set_curr_function('DefaultCurrAttributes');
744
745 IF ( X_acct_currency_code = X_project_currency_code) THEN
746
747 X_acct_rate_type := nvl(X_project_rate_type,X_acct_rate_type);
748 X_acct_rate_date := nvl(X_project_rate_date,X_acct_rate_date);
749 X_acct_exchange_rate := nvl(X_project_exchange_rate, X_acct_exchange_rate);
750
751 X_project_rate_type := nvl(X_project_rate_type,X_acct_rate_type);
752 X_project_rate_date := nvl(X_project_rate_date,X_acct_rate_date);
753 X_project_exchange_rate := nvl(X_project_exchange_rate, X_acct_exchange_rate) ;
754
755
756 END IF;
757 pa_cc_utils.reset_curr_function;
758
759 END DefaultCurrAttributes;
760
761 /* PA-I Changes
762 For un-accounted transactions we need not call DefaultCurrAttributes.
763 This is because the checks that are being performed here will be anyway
764 performed during costing in pa_multi_currency_txn. To avoid redundant code
765 we are not performing these checks in PA_TRX_IMPORT.
766 Please see prior versions for the changed DefaultCurrAttributes if needed.
767 */
768
769 PROCEDURE GetVendorId(P_vendor_number IN VARCHAR2)
770 IS
771 BEGIN
772
773 pa_cc_utils.set_curr_function('GetVendorId');
774
775 IF PG_DEBUG = 'Y' THEN
776 pa_debug.G_err_stage := 'In GetVendorId api with Vendor Number as an input';
777 log_message('log_message: ' || pa_debug.G_err_Stage);
778 END IF;
779
780 SELECT vendor_ID INTO G_vendor_id
781 FROM po_vendors
782 WHERE segment1 = p_vendor_number;
783
784
785 IF PG_DEBUG = 'Y' THEN
786 pa_debug.G_err_stage := 'G_vendor_id='||G_vendor_id;
787 log_message('log_message: ' || pa_debug.G_err_Stage);
788 END IF;
789
790 pa_cc_utils.reset_curr_function;
791
792 EXCEPTION WHEN others THEN
793 G_vendor_id := NULL;
794 pa_cc_utils.reset_curr_function;
795 END GetVendorId;
796
797 --
798 --BUG : 4696351 PJ.R12:DI4:APLINES: VENDOR INFORMATION NOT IMPORTED DURING TRANSACTION IMPORT
799 --
800 PROCEDURE GetVendorID ( p_person_id IN NUMBER )
801 IS
802 BEGIN
803
804 pa_cc_utils.set_curr_function('GetVendorId for an employee (person_id):'||p_person_id);
805
806 IF PG_DEBUG = 'Y' THEN
807 pa_debug.G_err_stage := 'In GetVendorId api with person id as an input';
808 log_message('log_message: ' || pa_debug.G_err_Stage);
809 END IF;
810
811 select vendor_id
812 into g_vendor_id
813 from po_vendors
814 where employee_id = p_person_id
815 and vendor_type_lookup_code = 'EMPLOYEE' ;
816
817 IF PG_DEBUG = 'Y' THEN
818 pa_debug.G_err_stage := 'G_vendor_id='||g_vendor_id;
819 log_message('log_message: ' || pa_debug.G_err_Stage);
820 END IF;
821
822 pa_cc_utils.reset_curr_function;
823
824 EXCEPTION WHEN others THEN
825 G_vendor_id := NULL;
826 pa_cc_utils.reset_curr_function;
827 END GetVendorId ;
828
829 PROCEDURE GetEtypeInfo( X_etype IN VARCHAR2
830 , X_date IN DATE )
831 IS
832 BEGIN
833
834 pa_cc_utils.set_curr_function('GetEtypeInfo');
835
836 IF PG_DEBUG = 'Y' THEN
837 pa_debug.G_err_stage := 'In GetEtypeInfo api';
838 log_message('log_message: ' || pa_debug.G_err_Stage);
839 END IF;
840
841 If (G_ETypeInfoEtype = X_etype AND trunc(G_ETypeInfoDate) = trunc(X_date)) Then
842
843 IF PG_DEBUG = 'Y' THEN
844 pa_debug.G_err_Stage := 'Cached Values';
845 log_message('log_message: ' || pa_debug.G_err_Stage);
846 END IF;
847
848 G_ETypeInfoEtype := X_etype;
849 G_ETypeInfoDate := X_date;
850
851 Else
852 IF PG_DEBUG = 'Y' THEN
853 pa_debug.G_err_Stage := 'Selecting Values';
854 log_message('log_message: ' || pa_debug.G_err_Stage);
855 END IF;
856
857 SELECT
858 /* et.system_linkage_function */ /* Commented for Bug#2726242 */
859 et.start_date_active
860 , et.end_date_active
861 , NVL(ecr.cost_rate, 1)
862 , et.cost_rate_flag
863 INTO
864 /* G_etype_link */ /* Commented for Bug#2726242 */
865 G_etype_start
866 , G_etype_end
867 , G_etype_cr
868 , G_etype_cost_rate_flag
869 FROM
870 pa_expenditure_cost_rates ecr
871 , pa_expenditure_types et
872 WHERE
873 et.expenditure_type = ecr.expenditure_type (+)
874 AND X_date BETWEEN ecr.start_date_active (+)
875 AND nvl(ecr.end_date_active (+), X_date)
876 AND et.expenditure_type = X_etype;
877
878 G_etype_active := TRUE ;
879
880 G_ETypeInfoEtype := X_etype;
881 G_ETypeInfoDate := X_date;
882
883 End If;
884
885 pa_cc_utils.reset_curr_function;
886
887 EXCEPTION
888 WHEN NO_DATA_FOUND THEN
889 /* G_etype_link := NULL; */ /* Commented for Bug#2726242 */
890 G_etype_start := NULL;
891 G_etype_end := NULL;
892 G_etype_cr := NULL;
893 G_etype_active := FALSE ;
894
895 G_ETypeInfoEtype := X_etype;
896 G_ETypeInfoDate := X_date;
897
898 pa_cc_utils.reset_curr_function;
899
900 END GetEtypeInfo;
901
902 PROCEDURE GetEtypeEclassInfo( X_etype IN VARCHAR2
903 , X_system_linkage IN VARCHAR2 )
904 IS
905 BEGIN
906
907 pa_cc_utils.set_curr_function('GetEtypeEclassInfo');
908
909 If (G_EClassInfoEtype = X_etype AND G_EClassInfoSysLink = X_system_linkage) then
910
911 IF PG_DEBUG = 'Y' THEN
912 pa_debug.G_err_Stage := 'Cached Values';
913 log_message('log_message: ' || pa_debug.G_err_Stage);
914 END IF;
915
916 G_EClassInfoEtype := X_etype;
917 G_EClassInfoSysLink := X_system_linkage;
918
919 Else
920
921 IF PG_DEBUG = 'Y' THEN
922 pa_debug.G_err_Stage := 'Selecting Values';
923 log_message('log_message: ' || pa_debug.G_err_Stage);
924 END IF;
925
926 SELECT
927 ets.system_linkage_function
928 ,st.labor_non_labor_flag
929 ,ets.start_date_active
930 ,ets.end_date_active
931 INTO
932 G_etype_link
933 , G_etype_labor_flag
934 , G_etec_start
935 , G_etec_end
936 FROM pa_system_linkages st,
937 pa_expend_typ_sys_links ets
938 WHERE st.function = ets.system_linkage_function
939 AND ets.system_linkage_function = X_system_linkage
940 AND ets.expenditure_type = X_etype ;
941
942 G_etype_active := TRUE ;
943
944 G_EClassInfoEtype := X_etype;
945 G_EClassInfoSysLink := X_system_linkage;
946
947 End If;
948
949 pa_cc_utils.reset_curr_function;
950
951 EXCEPTION
952 WHEN NO_DATA_FOUND THEN
953 G_etype_link := NULL;
954 G_etec_start := NULL;
955 G_etec_end := NULL;
956 G_etype_active := FALSE ;
957 G_EClassInfoEtype := X_etype;
958 G_EClassInfoSysLink := X_system_linkage;
959
960 pa_cc_utils.reset_curr_function;
961
962 END GetEtypeEclassInfo;
963
964 PROCEDURE GetNlrInfo( X_nlr IN VARCHAR2
965 , X_nlro_id IN NUMBER )
966 IS
967 BEGIN
968
969 pa_cc_utils.set_curr_function('GetNlrInfo');
970 IF PG_DEBUG = 'Y' THEN
971 pa_debug.G_err_Stage := 'select from pa_non_labor_resources';
972 log_message('log_message: ' || pa_debug.G_err_Stage);
973 END IF;
974
975 If (G_NlrInfoNlr = X_nlr) Then
976
977 IF PG_DEBUG = 'Y' THEN
978 pa_debug.G_err_Stage := 'Cached Values';
979 log_message('log_message: ' || pa_debug.G_err_Stage);
980 END IF;
981
982 G_NlrInfoNlr := X_nlr;
983
984 Else
985
986 IF PG_DEBUG = 'Y' THEN
987 pa_debug.G_err_Stage := 'Selecting Values';
988 log_message('log_message: ' || pa_debug.G_err_Stage);
989 END IF;
990
991 SELECT
992 nlr.expenditure_type
993 , nlr.start_date_active
994 , nlr.end_date_active
995 INTO
996 G_nlr_etype
997 , G_nlr_start
998 , G_nlr_end
999 FROM
1000 pa_non_labor_resources nlr
1001 WHERE
1002 nlr.non_labor_resource = X_nlr;
1003
1004 G_NlrInfoNlr := X_nlr;
1005
1006 End If;
1007
1008 BEGIN
1009 IF PG_DEBUG = 'Y' THEN
1010 pa_debug.G_err_stage := 'select from pa_non_labor_resource_orgs';
1011 log_message('log_message: ' || pa_debug.G_err_Stage);
1012 END IF;
1013
1014 If (G_NlrInfoNlr = X_nlr and G_NlrInfoNlroId = X_nlro_id) Then
1015
1016 G_NlrInfoNlroId := X_nlro_id;
1017
1018 Else
1019
1020 SELECT
1021 nlro.start_date_active
1022 , nlro.end_date_active
1023 INTO
1024 G_nlro_start
1025 , G_nlro_end
1026 FROM
1027 pa_non_labor_resource_orgs nlro
1028 WHERE
1029 nlro.organization_id = X_nlro_id
1030 AND nlro.non_labor_resource = X_nlr;
1031
1032 G_NlrInfoNlroId := X_nlro_id;
1033
1034 End If;
1035
1036 EXCEPTION
1037 WHEN NO_DATA_FOUND THEN
1038 G_nlro_start := NULL;
1039 G_nlro_end := NULL;
1040 G_NlrInfoNlroId := X_nlro_id;
1041 G_NlrInfoNlr := X_nlr;
1042 END;
1043
1044 pa_cc_utils.reset_curr_function;
1045 EXCEPTION
1046 WHEN NO_DATA_FOUND THEN
1047 G_nlr_start := NULL;
1048 G_nlr_end := NULL;
1049 G_nlr_etype := NULL;
1050 G_nlro_start := NULL;
1051 G_nlro_end := NULL;
1052 pa_cc_utils.reset_curr_function;
1053
1054 END GetNlrInfo;
1055
1056 PROCEDURE CheckDupItem( X_trx_source IN VARCHAR2
1057 , X_trx_ref IN VARCHAR2
1058 , X_status OUT NOCOPY VARCHAR2 )
1059 IS
1060 dummy NUMBER;
1061 BEGIN
1062
1063 pa_cc_utils.set_curr_function('CheckDupItem');
1064
1065 IF PG_DEBUG = 'Y' THEN
1066 pa_debug.G_err_stage := 'In CheckDupItem api';
1067 log_message('log_message: ' || pa_debug.G_err_Stage);
1068 END IF;
1069
1070 BEGIN
1071 SELECT
1072 1
1073 INTO
1074 dummy
1075 FROM
1076 sys.dual
1077 WHERE EXISTS
1078 ( SELECT 1
1079 FROM pa_expenditure_items ei
1080 WHERE ei.orig_transaction_reference = X_trx_ref
1081 AND ei.transaction_source = X_trx_source );
1082
1083 EXCEPTION
1084 WHEN NO_DATA_FOUND THEN
1085 NULL;
1086 END;
1087
1088 IF ( dummy = 1 ) THEN
1089 X_status := 'DUPLICATE_ITEM';
1090 pa_cc_utils.reset_curr_function;
1091 RETURN;
1092
1093 ELSIF ( i > 0 ) THEN
1094
1095 FOR j IN 1..i LOOP
1096 IF ( pa_transactions.TrxRefTab(j) = X_trx_ref ) THEN
1097 X_status := 'DUPLICATE_ITEM';
1098 pa_cc_utils.reset_curr_function;
1099 RETURN;
1100 END IF;
1101 END LOOP;
1102
1103 ELSE
1104 X_status := NULL;
1105
1106 END IF;
1107 pa_cc_utils.reset_curr_function;
1108
1109 END CheckDupItem;
1110
1111 PROCEDURE CheckDupAdjItem( X_adj_item_id IN NUMBER
1112 , X_status OUT NOCOPY VARCHAR2 )
1113 IS
1114 BEGIN
1115
1116 pa_cc_utils.set_curr_function('CheckDupAdjItem');
1117
1118 IF PG_DEBUG = 'Y' THEN
1119 pa_debug.G_err_stage := 'In CheckDupAdjItem api';
1120 log_message('log_message: ' || pa_debug.G_err_Stage);
1121 END IF;
1122
1123 IF ( i > 0 ) THEN
1124
1125 FOR j IN 1..i LOOP
1126 IF ( pa_transactions.AdjEiTab(j) = X_adj_item_id) THEN
1127 X_status := 'DUPLICATE_ADJUST_ITEM';
1128 pa_cc_utils.reset_curr_function;
1129 RETURN;
1130 END IF;
1131 END LOOP;
1132
1133 ELSE
1134 X_status := NULL;
1135
1136 END IF;
1137 pa_cc_utils.reset_curr_function;
1138 END CheckDupAdjItem;
1139
1140 -- SST Change: changed procedure from getprojbcostflag
1141 -- to getprojtypeinfo because we're not only retrieving
1142 -- burden cost flag, we're also retrieving project type
1143 -- class code
1144 -- PA-K Changes: Selecting burden_amt_display_method
1145 -- Bug 2634812 : Selecting total_burden_flag
1146 PROCEDURE GetProjTypeInfo( X_Project_id IN NUMBER,
1147 X_Proj_bcost_flag OUT NOCOPY VARCHAR2,
1148 X_proj_type_class OUT NOCOPY VARCHAR2,
1149 X_burden_amt_display_method OUT NOCOPY VARCHAR2,
1150 X_Total_Burden_Flag OUT NOCOPY VARCHAR2)
1151
1152 IS
1153 BEGIN
1154 pa_cc_utils.set_curr_function('GetProjTypeInfo');
1155
1156 If (X_Project_id = G_PrjInfoPrjId) Then
1157
1158 IF PG_DEBUG = 'Y' THEN
1159 pa_debug.G_err_stage := 'Inside GetProjTypeInfo, using cached values';
1160 log_message('log_message: ' || pa_debug.G_err_stage);
1161 END IF;
1162
1163 X_Proj_bcost_flag := G_PrjInfoBCostFlag;
1164 X_proj_type_class := G_PrjInfoTypeClass;
1165 X_burden_amt_display_method := G_PrjInfoBdDisplay;
1166 X_Total_Burden_Flag := G_PrjInfoTotBdFlag;
1167
1168 Else
1169
1170 IF PG_DEBUG = 'Y' THEN
1171 pa_debug.G_err_stage := 'Inside GetProjTypeInfo, selecting values';
1172 log_message('log_message: ' || pa_debug.G_err_stage);
1173 END IF;
1174
1175 -- SST changes, added project_type_class to select statement
1176 SELECT burden_cost_flag, project_type_class_code, burden_amt_display_method,
1177 total_burden_flag
1178 INTO X_proj_bcost_flag, X_proj_type_class, X_burden_amt_display_method,
1179 X_Total_Burden_Flag
1180 FROM pa_projects_all proj,
1181 pa_project_types_all ptype
1182 WHERE proj.project_type = ptype.project_type
1183 -- MOAC Changes
1184 AND proj.org_id = ptype.org_id
1185 AND project_id = X_Project_id ;
1186
1187 G_PrjInfoPrjId := X_Project_id;
1188 G_PrjInfoBCostFlag := X_proj_bcost_flag;
1189 G_PrjInfoTypeClass := X_proj_type_class;
1190 G_PrjInfoBdDisplay := X_burden_amt_display_method;
1191 G_PrjInfoTotBdFlag := X_Total_Burden_Flag;
1192
1193 End If;
1194
1195 pa_cc_utils.reset_curr_function;
1196
1197 EXCEPTION
1198 WHEN NO_DATA_FOUND THEN
1199 X_Proj_bcost_flag := NULL ;
1200 X_proj_type_class := NULL;
1201 X_burden_amt_display_method := NULL;
1202 X_Total_Burden_Flag := NULL;
1203 G_PrjInfoPrjId := X_Project_id;
1204 G_PrjInfoBCostFlag := X_proj_bcost_flag;
1205 G_PrjInfoTypeClass := X_proj_type_class;
1206 G_PrjInfoBdDisplay := X_burden_amt_display_method;
1207 G_PrjInfoTotBdFlag := X_Total_Burden_Flag;
1208
1209 pa_cc_utils.reset_curr_function;
1210 END GetProjTypeInfo ;
1211
1212 FUNCTION CheckCCID ( ccid number ) RETURN NUMBER
1213 IS
1214 X_ccid number(15) ;
1215 BEGIN
1216 -- pa_cc_utils.set_curr_function('CheckCCID');
1217 -- not setting error stack because this procedure
1218 -- will be violating its associated pragma.
1219 IF PG_DEBUG = 'Y' THEN
1220 pa_debug.G_err_stage := 'Inside CheckCCID api';
1221 log_message('log_message: ' || pa_debug.G_err_stage);
1222 END IF;
1223
1224 If ccid is null Then
1225 G_PrevCCID := ccid;
1226 G_PrevRetVal := NULL;
1227 return(NULL);
1228 End If;
1229
1230 If G_PrevCCID = ccid Then
1231
1232 X_ccid := G_PrevRetVal;
1233
1234 Else
1235
1236 select code_combination_id
1237 into X_ccid
1238 from gl_code_combinations
1239 where code_combination_id = ccid
1240 and enabled_flag='Y'
1241 and chart_of_accounts_id in (select sob.chart_of_accounts_id
1242 from pa_implementations imp
1243 ,gl_sets_of_books sob
1244 where imp.set_of_books_id=sob.set_of_books_id) ; /*10138679*/
1245
1246 G_PrevCCID := ccid;
1247 G_PrevRetVal := 1;
1248
1249 End If;
1250
1251 --pa_cc_utils.reset_curr_function;
1252 return(X_ccid) ;
1253 EXCEPTION
1254 WHEN NO_DATA_FOUND THEN
1255 G_PrevRetVal := NULL;
1256 G_PrevCCID := ccid;
1257 --pa_cc_utils.reset_curr_function;
1258 RETURN (NULL) ;
1259 END CheckCCID ;
1260
1261 -- =============================================================
1262 -- Bugs: 1063562 and 1069585
1263 -- New Procedure Validate_VI to do the following validations for Vendor Invoices:
1264 -- 1. Transaction Source needs to be GL accounted.
1265 -- 2. Vendor Number needs to be provided
1266
1267 PROCEDURE Validate_VI (
1268 X_vendor_number IN VARCHAR2,
1269 X_employee_number IN VARCHAR2,
1270 X_result OUT NOCOPY NUMBER,
1271 X_status OUT NOCOPY VARCHAR2) AS
1272
1273 BEGIN
1274 IF G_gl_accted_flag <> 'Y' THEN
1275 X_status := 'PA_VI_TRX_SRC_NOT_GL_ACCTED';
1276 X_result := 1;
1277 RETURN;
1278 ELSIF X_vendor_number IS NULL THEN
1279 X_status := 'PA_VI_VEND_NUM_IS_NULL';
1280 X_result := 1;
1281 RETURN;
1282 END IF;
1283 END;
1284 --
1285 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
1286 --
1287 PROCEDURE validate_exp_date ( p_project_id IN NUMBER,
1288 p_task_id In NUMBER,
1289 p_award_id in NUMBER,
1290 p_incurred_by_org_id in number,
1291 p_vendor_id in NUMBER,
1292 p_person_id in number,
1293 p_exp_item_date in date,
1294 p_exp_type in varchar2,
1295 p_system_linkage in varchar2,
1296 p_txn_source in varchar2,
1297 p_calling_modle in varchar2,
1298 x_err_msg_cd in out nocopy varchar2,
1299 x_status out nocopy varchar2 )is
1300 Cursor c_dates is
1301 select nvl(p.start_date, p_exp_item_date) proj_start_date,
1302 nvl(p.completion_date, p_exp_item_date) proj_end_date,
1303 nvl(t.start_date, p_exp_item_date) task_start_date,
1304 nvl(t.completion_date, p_exp_item_date) task_completion_date,
1305 nvl(et.start_date_active, p_exp_item_date) et_start_date,
1306 nvl(et.end_date_active, p_exp_item_date) et_end_date,
1307 nvl(sl.start_date_active, p_exp_item_date) sl_start_date,
1308 nvl(sl.end_date_active, p_exp_item_date) sl_end_date
1309 from pa_projects_all p,
1310 pa_tasks t,
1311 pa_expenditure_types et,
1312 pa_expend_typ_sys_links sl
1313 where p.project_id = p_project_id
1314 and t.project_id = p_project_id
1315 and t.task_id = p_task_id
1316 and et.expenditure_type = p_exp_type
1317 and sl.system_linkage_function = p_system_linkage
1318 and sl.expenditure_type = p_exp_type ;
1319
1320 CURSOR GET_VALID_AWARDS IS
1321 Select Allowable_Schedule_Id,
1322 nvl(Preaward_Date,START_DATE_ACTIVE) preaward_date,
1323 End_Date_Active end_date,
1324 Close_Date close_date,
1325 Status
1326 from GMS_AWARDS
1327 where award_id = P_award_id;
1328
1329 c_dates_rec c_dates%rowtype ;
1330 c_award_rec GET_VALID_AWARDS%Rowtype ;
1331
1332 FUNCTION check_active_employee (p_vendor_id Number ,p_person_id Number ,p_Ei_Date Date ) Return varchar2 IS
1333
1334 l_return_string varchar2(10) := 'Y';
1335 l_return_number Number := NULL;
1336 l_emp_number Number := Null;
1337
1338 CURSOR cur_emp IS
1339 SELECT vend.employee_id
1340 FROM po_vendors vend
1341 WHERE vend.vendor_id = p_vendor_id
1342 /* AND p_ei_date BETWEEN nvl(vend.start_date_active,p_ei_date) AND
1343 nvl( vend.end_date_active, trunc(sysdate) ) ; */
1344 -- Bug 11063869 --Added trunc for the dates in the below condition.
1345 AND trunc(p_ei_date) BETWEEN nvl(trunc(vend.start_date_active),trunc(p_ei_date)) AND
1346 nvl( trunc(vend.end_date_active), trunc(sysdate) ) ;
1347
1348 BEGIN
1349 If nvl(p_person_id,0) = 0 then
1350 OPEN cur_emp;
1351 FETCH cur_emp INTO l_emp_number;
1352 CLOSE cur_emp;
1353 Else
1354 l_emp_number := p_person_id;
1355 End If;
1356
1357 If l_emp_number is NOT NULL then
1358
1359 l_return_number := pa_utils.GetEmpOrgId( l_emp_number, p_ei_date );
1360 If l_return_number is NULL then
1361 l_return_string := 'N';
1362 End If;
1363 End If;
1364 Return l_return_string;
1365
1366 END check_active_employee;
1367
1368 BEGIN
1369
1370 pa_cc_utils.set_curr_function('validate_exp_date');
1371
1372 IF x_err_msg_cd is not NULL THEN
1373 x_status := FND_API.G_RET_STS_ERROR ;
1374 RETURN ;
1375 END IF ;
1376
1377 x_status := FND_API.G_RET_STS_SUCCESS;
1378
1379 IF PG_DEBUG = 'Y' THEN
1380 log_message('log_message: fetching project dates ' );
1381 END IF;
1382
1383 open c_dates ;
1384 fetch c_dates into c_dates_rec ;
1385 close c_dates ;
1386
1387 IF PG_DEBUG = 'Y' THEN
1388 log_message('log_message: Validating exp dates now' );
1389 END IF;
1390
1391
1392 IF p_award_id is not null then
1393 IF PG_DEBUG = 'Y' THEN
1394 log_message('log_message: award passed is :'||p_award_id ) ;
1395 END IF;
1396
1397 open get_valid_awards ;
1398 fetch get_valid_awards into c_award_rec ;
1399 close get_valid_awards ;
1400
1401 IF p_exp_item_date < TRUNC(c_award_rec.preaward_date) THEN
1402 x_err_msg_cd := 'GMS_EXP_ITEM_DT_BEFORE_AWD_ST' ;
1403 x_status := FND_API.G_RET_STS_ERROR ;
1404 RETURN ;
1405 END IF ;
1406
1407 IF p_exp_item_date > TRUNC(c_award_rec.end_date) THEN
1408 x_err_msg_cd := 'GMS_EXP_ITEM_DT_AFTER_AWD_END' ;
1409 x_status := FND_API.G_RET_STS_ERROR ;
1410 RETURN ;
1411 END IF ;
1412
1413 IF c_award_rec.close_date < TRUNC(SYSDATE) THEN
1414 x_err_msg_cd := 'GMS_AWARD_IS_CLOSED' ;
1415 x_status := FND_API.G_RET_STS_ERROR ;
1416 RETURN ;
1417 END IF ;
1418 END IF ;
1419
1420 IF PG_DEBUG = 'Y' THEN
1421 log_message('log_message: Validating exp dates -> exp types' );
1422 END IF;
1423 /* IF p_exp_item_date not between c_dates_rec.et_start_date and c_dates_rec.et_end_date then */
1424 -- Bug 11063869 --Added trunc for the dates in the below if condition.
1425 IF trunc(p_exp_item_date) not between trunc(c_dates_rec.et_start_date) and trunc(c_dates_rec.et_end_date) then
1426 x_err_msg_cd := 'EXP_TYPE_INACTIVE' ;
1427 x_status := FND_API.G_RET_STS_ERROR ;
1428 RETURN ;
1429 END IF ;
1430
1431 IF PG_DEBUG = 'Y' THEN
1432 log_message('log_message: Validating exp dates -> System Linkage Function' );
1433 END IF;
1434 /* IF p_exp_item_date not between c_dates_rec.sl_start_date and c_dates_rec.sl_end_date THEN */
1435 -- Bug 11063869--Added trunc for the dates in the below if condition.
1436 IF trunc(p_exp_item_date) not between trunc(c_dates_rec.sl_start_date) and trunc(c_dates_rec.sl_end_date) THEN
1437 x_err_msg_cd := 'ETYPE_SLINK_INACTIVE' ;
1438 x_status := FND_API.G_RET_STS_ERROR ;
1439 RETURN ;
1440 END IF ;
1441
1442 IF PG_DEBUG = 'Y' THEN
1443 log_message('log_message: Validating exp dates -> Project Level' );
1444 END IF;
1445 /* IF p_exp_item_date NOT between c_dates_rec.proj_start_date and c_dates_rec.proj_end_date THEN */
1446 -- Bug 11063869--Added trunc for the dates in the below if condition.
1447 IF trunc(p_exp_item_date) NOT between trunc(c_dates_rec.proj_start_date) and trunc(c_dates_rec.proj_end_date) THEN
1448 x_err_msg_cd := 'PA_EX_PROJECT_DATE' ;
1449 x_status := FND_API.G_RET_STS_ERROR ;
1450 RETURN ;
1451 END IF ;
1452
1453 IF PG_DEBUG = 'Y' THEN
1454 log_message('log_message: Validating exp dates -> Task Level' );
1455 END IF;
1456 IF trunc( p_exp_item_date) NOT between trunc( c_dates_rec.task_start_date) and trunc (c_dates_rec.task_completion_date) THEN
1457 x_err_msg_cd := 'PA_EXP_TASK_EFF' ;
1458 x_status := FND_API.G_RET_STS_ERROR ;
1459 RETURN ;
1460 END IF ;
1461
1462 IF PG_DEBUG = 'Y' THEN
1463 log_message('log_message: Validating exp dates -> Exp Org Level' );
1464 END IF;
1465 IF pa_utils2.CheckExporg(p_incurred_by_org_id,p_exp_item_date) = 'N' then
1466 x_err_msg_cd := 'PA_EXP_ORG_NOT_ACTIVE' ;
1467 x_status := FND_API.G_RET_STS_ERROR ;
1468 RETURN ;
1469 END IF;
1470
1471 IF PG_DEBUG = 'Y' THEN
1472 log_message('log_message: Validating exp dates -> Employee Level' );
1473 END IF;
1474 /*Start chnages for bug#15857341 */
1475 /*IF nvl(check_active_employee (p_vendor_id => p_vendor_id ,p_person_id => p_person_id ,p_ei_date => p_exp_item_date),'N') = 'N' then
1476 x_err_msg_cd := 'NO_ASSIGNMENT' ;
1477 x_status := FND_API.G_RET_STS_ERROR ;
1478 RETURN ;
1479 End if;*/
1480
1481 pa_cc_utils.reset_curr_function;
1482
1483
1484 END VALIDATE_EXP_DATE ;
1485
1486
1487
1488 PROCEDURE ValidateItem(
1489 X_trx_src IN VARCHAR2
1490 , X_enum IN VARCHAR2
1491 , X_oname IN VARCHAR2
1492 , X_end_date IN DATE
1493 , X_ei_date IN DATE
1494 , X_etype IN VARCHAR2
1495 , X_pnum IN VARCHAR2
1496 , X_tnum IN VARCHAR2
1497 , X_nlr IN VARCHAR2
1498 , X_nlro_name IN VARCHAR2
1499 , X_qty IN NUMBER
1500 , X_denom_raw_cost IN OUT NOCOPY NUMBER /*10357604 */
1501 , X_module IN VARCHAR2
1502 , X_trx_ref IN VARCHAR2
1503 , X_match_flag IN VARCHAR2
1504 , X_entered_by IN NUMBER
1505 , X_att_cat IN VARCHAR2
1506 , X_att1 IN OUT NOCOPY VARCHAR2 --DFF Upgrade:
1507 , X_att2 IN OUT NOCOPY VARCHAR2 --Change from IN to
1508 , X_att3 IN OUT NOCOPY VARCHAR2 --IN OUT
1509 , X_att4 IN OUT NOCOPY VARCHAR2
1510 , X_att5 IN OUT NOCOPY VARCHAR2
1511 , X_att6 IN OUT NOCOPY VARCHAR2
1512 , X_att7 IN OUT NOCOPY VARCHAR2
1513 , X_att8 IN OUT NOCOPY VARCHAR2
1514 , X_att9 IN OUT NOCOPY VARCHAR2
1515 , X_att10 IN OUT NOCOPY VARCHAR2
1516 , X_drccid IN NUMBER
1517 , X_crccid IN NUMBER
1518 , X_gl_date IN OUT NOCOPY DATE -- Change from IN to IN OUT, bug 3357936
1519 , X_denom_burdened_cost IN OUT NOCOPY NUMBER
1520 , X_system_linkage IN VARCHAR2
1521 , X_status OUT NOCOPY VARCHAR2
1522 , X_bill_flag OUT NOCOPY VARCHAR2
1523 , X_receipt_currency_amount IN NUMBER
1524 , X_receipt_currency_code IN VARCHAR2
1525 , X_receipt_exchange_rate IN OUT NOCOPY NUMBER
1526 , X_denom_currency_code IN OUT NOCOPY VARCHAR2
1527 , X_acct_rate_date IN OUT NOCOPY DATE
1528 , X_acct_rate_type IN OUT NOCOPY VARCHAR2
1529 , X_acct_exchange_rate IN OUT NOCOPY NUMBER
1530 , X_acct_raw_cost IN NUMBER
1531 , X_acct_burdened_cost IN OUT NOCOPY NUMBER
1532 , X_acct_exchange_rounding_limit IN NUMBER
1533 , X_project_currency_code IN OUT NOCOPY VARCHAR2
1534 , X_project_rate_date IN OUT NOCOPY DATE
1535 , X_project_rate_type IN OUT NOCOPY VARCHAR2
1536 , X_project_exchange_rate IN OUT NOCOPY NUMBER
1537 , X_project_raw_cost IN OUT NOCOPY NUMBER
1538 , X_project_burdened_cost IN OUT NOCOPY NUMBER
1539 -- Trx_import enhancement: New parameter
1540 , X_override_to_oname IN VARCHAR2
1541 , X_vendor_number IN VARCHAR2
1542 , X_org_id IN NUMBER
1543 , X_Business_Group_Name IN VARCHAR2
1544 -- PA-I Changes : Added Proj Func Currency Attr
1545 , X_Projfunc_currency_code IN OUT NOCOPY VARCHAR2
1546 , X_Projfunc_cost_rate_date IN OUT NOCOPY DATE
1547 , X_Projfunc_cost_rate_type IN OUT NOCOPY VARCHAR2
1548 , X_Projfunc_cost_exchange_rate IN OUT NOCOPY NUMBER
1549 , X_actual_project_raw_cost IN OUT NOCOPY NUMBER
1550 , X_actual_project_burdened_cost IN OUT NOCOPY NUMBER
1551 -- PA-I Changes : Added Assignment and Work Type Name
1552 , X_Assignment_Name IN OUT NOCOPY VARCHAR2
1553 , X_Work_Type_Name IN OUT NOCOPY VARCHAR2
1554 -- PA-J Period-End Accrual Changes : Added accrual_flag
1555 , X_accrual_flag IN VARCHAR2
1556 --PA-K Changes
1557 , P_project_id IN NUMBER
1558 , P_task_id IN NUMBER
1559 , P_person_id IN NUMBER
1560 , P_organization_id IN NUMBER
1561 , P_NLR_Org_Id IN NUMBER
1562 , P_Vendor_Id IN NUMBER
1563 , P_Override_Organization_Id IN NUMBER
1564 , P_Person_business_Group_Id IN NUMBER
1565 , P_assignment_id IN NUMBER
1566 , P_work_type_id IN NUMBER
1567 , P_Emp_Org_Id IN NUMBER
1568 , P_Emp_Job_Id IN NUMBER
1569 /* Added parameter X_txn_interface_id for bug 2563364 */
1570 , X_txn_interface_id IN NUMBER
1571 , P_po_number IN VARCHAR2 /* cwk */
1572 , P_po_header_id IN OUT NOCOPY NUMBER
1573 , P_po_line_num IN NUMBER
1574 , P_po_line_id IN OUT NOCOPY NUMBER
1575 , P_person_type IN VARCHAR2
1576 , P_po_price_type IN VARCHAR2
1577 /* REL12-AP Lines uptake */
1578 , p_adj_exp_item_id IN NUMBER default NULL
1579 , p_fc_document_type IN varchar2 default NULL
1580 -- , p_agreement_id IN OUT NOCOPY NUMBER --FSIO Changes
1581 -- , p_agreement_number IN OUT NOCOPY varchar2)
1582 -- 10253400: Payroll integration enhancement for 12.2..start
1583 ,P_JOB_ID PA_TRANSACTION_INTERFACE_ALL.JOB_ID%TYPE DEFAULT NULL
1584 ,P_JOB_NAME PA_TRANSACTION_INTERFACE_ALL.JOB_NAME%TYPE DEFAULT NULL
1585 ,P_LOCATION_ID PA_TRANSACTION_INTERFACE_ALL.LOCATION_ID%TYPE DEFAULT NULL
1586 ,P_LOCATION_CODE PA_TRANSACTION_INTERFACE_ALL.LOCATION_CODE%TYPE DEFAULT NULL
1587 ,P_PAY_ELEMENT_TYPE_ID PA_TRANSACTION_INTERFACE_ALL.PAY_ELEMENT_type_ID%TYPE DEFAULT NULL
1588 -- 10253400: Payroll integration enhancement for 12.2..end
1589 -- Start: Added for bug 16220146
1590 ,P_CBS_ELEMENT_ID PA_TRANSACTION_INTERFACE_ALL.CBS_ELEMENT_ID%TYPE DEFAULT NULL
1591 ,P_CBS_ELEMENT_NAME PA_TRANSACTION_INTERFACE_ALL.CBS_ELEMENT_NAME%TYPE DEFAULT NULL
1592 -- End: Added for bug 16220146
1593 )
1594 IS
1595 temp_status VARCHAR2(30) DEFAULT NULL;
1596 temp_bill_flag VARCHAR2(1) DEFAULT NULL;
1597 temp_msg_application VARCHAR2(50) := 'PA';
1598 temp_msg_type VARCHAR2(1) := 'E';
1599 temp_msg_token1 VARCHAR2(2000) := '';
1600 temp_msg_token2 VARCHAR2(2000) :='';
1601 temp_msg_token3 VARCHAR2(2000) :='';
1602 temp_msg_count NUMBER :=1;
1603 temp_dff_msg VARCHAR(2000) :='';
1604
1605 dummy NUMBER DEFAULT NULL;
1606 l_dummy Varchar2(1) DEFAULT NULL;
1607
1608 l_converted_amount NUMBER DEFAULT NULL;
1609 l_denominator NUMBER DEFAULT NULL;
1610 l_numerator NUMBER DEFAULT NULL;
1611 l_rate NUMBER DEFAULT NULL;
1612 l_status VARCHAR2(80) DEFAULT NULL;
1613 l_api_status varchar2(1) ;
1614 l_status_num NUMBER DEFAULT NULL;
1615 l_stage NUMBER DEFAULT NULL;
1616 l_validate_user_rate_type VARCHAR2(1) DEFAULT 'Y';
1617 l_handel_exception_flag VARCHAR2(1) DEFAULT 'Y';
1618 l_denom_cost_ratio NUMBER := 1;
1619 l_project_rate_type VARCHAR2(30) := NULL;
1620 l_acct_rate_date DATE;
1621 l_acct_rate_type VARCHAR2(30);
1622 l_acct_exchange_rate NUMBER;
1623 l_acct_raw_cost NUMBER;
1624
1625 l_Raw_Bc_Packet_Id NUMBER;
1626 l_Packet_Id NUMBER;
1627 l_fc_return_status VARCHAR2(30);
1628 l_fc_error_stage VARCHAR2(30);
1629 l_fc_error_msg VARCHAR2(30);
1630
1631 -- Start PA-I Changes
1632 l_projfunc_cost_rate_type VARCHAR2(30) := NULL;
1633 l_asgn_work_ret_sts VARCHAR2(1);
1634 l_asgn_work_err_msg VARCHAR2(1000);
1635 -- End PA-I Changes
1636
1637 -- PA-J Period-End Accrual Changes
1638 l_period_end_txn VARCHAR2(1) := 'N';
1639 l_ret_sts VARCHAR2(1);
1640 x_err_stage VARCHAR2(100);
1641
1642 --Bug 3010848
1643 L_Org_RetSts Varchar2(50);
1644
1645 l_SobId pa_implementations_all.set_of_books_id%TYPE; -- bug 3357936
1646 l_appl_id NUMBER(15) := PA_PERIOD_PROCESS_PKG.Application_Id; -- bug 3357936
1647
1648 -- Start of Changes for Bug 5743708
1649 x_cp_structure VARCHAR2(30);
1650 x_cost_base VARCHAR2(30);
1651 -- End of Changes for Bug 5743708
1652
1653 /* cwk */
1654 l_po_rate NUMBER := 0;
1655 l_Calc_Amt NUMBER := 0;
1656 l_processed_cost NUMBER := 0;
1657 l_costed NUMBER := 0;
1658 l_uncosted NUMBER := 0;
1659 l_retrn_val NUMBER := -1;
1660 l_cwk_amt_updated VARCHAR2(1) := 'N';
1661 l_all_neg_acc VARCHAR2(1); -- BUG 16451280
1662
1663 Cursor c_check_fail(c_packet_id NUMBER) is
1664 Select 'X'
1665 from Dual
1666 Where exists (select 'Y' from pa_bc_packets
1667 Where packet_id = c_packet_id
1668 and substr(nvl(result_code, 'P'),1,1) = 'F');
1669
1670
1671 pa_date DATE DEFAULT NULL ;
1672 recvr_pa_date DATE DEFAULT NULL ; /* Bug # 1653831 */
1673 v_result NUMBER := 0;
1674
1675 x_return_status NUMBER;
1676 x_error_code VARCHAR2(100);
1677 x_error_stage NUMBER;
1678
1679 --l_NewTxnsAllowed VARCHAR2(1);
1680
1681 /***** CWK CHANGES - This function will check existance of record of a
1682 combination of po_line_id and task_id in PLSQL table *****/
1683
1684 Function Is_Po_Line_Task_Processed (
1685 P_Po_Line_Id IN NUMBER,
1686 P_Task_Id IN NUMBER
1687 ) Return Boolean
1688 Is
1689 l_Line_Task_str VARCHAR2(150) := NULL;
1690 Begin
1691
1692 l_Line_Task_str := P_Po_Line_Id ||'.'||P_Task_Id;
1693
1694 IF PoLineTaskTab.COUNT > 0 THEN
1695 FOR i IN PoLineTaskTab.FIRST..PoLineTaskTab.LAST
1696 LOOP
1697 IF (l_Line_Task_str = PoLineTaskTab(i)) THEN
1698 Return True;
1699 End If;
1700 END LOOP;
1701 End If;
1702
1703 Return False;
1704
1705 End Is_Po_Line_Task_Processed;
1706
1707 /***** CWK CHANGES - This Procedure will update PL/SQL Tables to reflect *****/
1708 /***** Processed Amount for the given Po_Line_ID. That will be used to *****/
1709 /***** do the Po Funds check and validate the transaction record. *****/
1710
1711 PROCEDURE po_processed_amt_chk(P_Po_Line_Id IN NUMBER
1712 ,P_Task_Id IN NUMBER
1713 ,P_Calc_Amt IN NUMBER
1714 ,X_Processed_Amt OUT NOCOPY NUMBER
1715 ,X_status OUT NOCOPY VARCHAR2
1716 ) IS
1717 PRAGMA AUTONOMOUS_TRANSACTION;
1718 l_counter BINARY_INTEGER := 0 ;
1719 l_Line_Task_str VARCHAR2(150) := NULL;
1720 l_lock_status NUMBER := -1;
1721 l_costed_amt NUMBER := 0;
1722 l_uncosted_amt NUMBER := 0;
1723
1724
1725 BEGIN
1726
1727 l_Line_Task_str := P_Po_Line_Id ||'.'||P_Task_Id;
1728
1729 IF PoLineTaskTab.COUNT > 0 THEN
1730
1731 BEGIN
1732
1733 FOR i IN PoLineTaskTab.FIRST..PoLineTaskTab.LAST
1734 LOOP
1735
1736 IF (l_Line_Task_str = PoLineTaskTab(i)) THEN
1737
1738 PoAmtTab(i) := PoAmtTab(i) + P_Calc_Amt;
1739 X_Processed_Amt := PoAmtTab(i);
1740
1741 x_status := null;
1742 RETURN;
1743
1744 END IF;
1745
1746 END LOOP;
1747
1748 EXCEPTION
1749 WHEN OTHERS THEN
1750
1751 IF PG_DEBUG = 'Y' THEN
1752 pa_debug.G_err_stage := 'PO_PROCESSED_AMT_CHK : Search of Records : ' ||SQLERRM;
1753 log_message('log_message: ' || pa_debug.G_err_stage,1);
1754 END IF;
1755
1756 END ;
1757
1758 END IF ;
1759
1760 -- Now Acquire the lock for Po Line Id and Task Id combination String.
1761
1762 l_lock_status := Pa_Debug.Acquire_User_Lock(l_Line_Task_str);
1763
1764 IF (l_lock_status = 0) THEN
1765
1766 l_counter := PoLineTaskTab.COUNT;
1767 l_counter := l_counter + 1;
1768
1769 PoLineTaskTab(l_counter) := l_Line_Task_str;
1770 PoAmtTab (l_counter) := P_Calc_Amt ;
1771 X_Processed_Amt := P_Calc_Amt ;
1772 x_status := null;
1773 return;
1774
1775 ELSE
1776
1777 IF PG_DEBUG = 'Y' THEN
1778 pa_debug.G_err_stage := 'PO_PROCESSED_AMT_CHK : Failed To Aquire Lock for : '||l_Line_Task_str;
1779 log_message('log_message: ' || pa_debug.G_err_stage,1);
1780 END IF;
1781
1782 x_status := 'PO_LINE_TASK_LOCKED';
1783 RETURN;
1784
1785 END IF;
1786
1787 EXCEPTION
1788 WHEN OTHERS THEN
1789
1790 IF PG_DEBUG = 'Y' THEN
1791 pa_debug.G_err_stage := 'PO_PROCESSED_AMT_CHK : Insertion of Records : ' ||SQLERRM;
1792 log_message('log_message: ' || pa_debug.G_err_stage,1);
1793 END IF;
1794
1795 END po_processed_amt_chk;
1796
1797 PROCEDURE undo_processed_amt_chk(P_Po_Line_Id NUMBER
1798 ,P_Task_Id NUMBER
1799 ,P_Calc_Amt NUMBER
1800 ) IS
1801
1802 l_Line_Task_str VARCHAR2(150) := NULL;
1803
1804 BEGIN
1805
1806 l_Line_Task_str := P_Po_Line_Id ||'.'||P_Task_Id;
1807
1808 FOR i IN PoLineTaskTab.FIRST..PoLineTaskTab.LAST
1809 LOOP
1810
1811 IF (l_Line_Task_str = PoLineTaskTab(i)) THEN
1812
1813 PoAmtTab(i) := PoAmtTab(i) - P_Calc_Amt;
1814
1815 END IF;
1816
1817 END LOOP;
1818
1819 EXCEPTION
1820 WHEN OTHERS THEN
1821
1822 IF PG_DEBUG = 'Y' THEN
1823 pa_debug.G_err_stage := 'UNDO_PROCESSED_AMT_CHK : While Undoing Processed Amt Check : ' ||SQLERRM;
1824 log_message('log_message: ' || pa_debug.G_err_stage,1);
1825 END IF;
1826
1827 END undo_processed_amt_chk;
1828
1829 /** *
1830 *** Validate Items Main processing begins here
1831 **/
1832 BEGIN
1833 pa_cc_utils.set_curr_function('ValidateItem');
1834
1835 IF PG_DEBUG = 'Y' THEN
1836 pa_debug.G_err_stage := 'Inside ValidateItem';
1837 log_message('log_message: ' || pa_debug.G_err_stage);
1838 END IF;
1839
1840 G_adj_item_id := NULL;
1841 G_job_id := NULL;
1842
1843 X_status := NULL;
1844
1845 IF (G_accounting_currency_code IS NULL) THEN
1846 GetImpCurrInfo;
1847 END IF;
1848
1849 --PA-K Changes: For PAAPIMP we can skip the following validations and
1850 --use the ID attributes provided.
1851
1852 /*Bug 8208577 Begin*/
1853 log_message('Checking for negative accrual transaction ' );
1854
1855 /* Started Bug 16451280 */
1856 l_all_neg_acc := NULL;
1857 SELECT NVL(allow_negative_accrual, 'N')
1858 INTO l_all_neg_acc
1859 FROM pa_implementations_all
1860 WHERE org_id = X_org_id;
1861
1862 /* END Bug 16451280 */
1863
1864 IF (SIGN(x_denom_raw_cost)=-1 and X_accrual_flag='Y' AND l_all_neg_acc = 'N' ) THEN -- Bug 16451280
1865 pa_debug.G_err_Stage := 'Negative Accrual Transaction';
1866 log_message('log_message: ' || pa_debug.G_err_Stage);
1867 X_status := 'NEG_ACCRUAL_TRANS';
1868 pa_cc_utils.reset_curr_function;
1869 RETURN;
1870 END IF;
1871 /*Bug 8208577 End*/
1872
1873 IF (nvl(X_module, 'EXTERNAL') <> 'PAAPIMP') THEN ---{
1874
1875 IF PG_DEBUG = 'Y' THEN
1876 pa_debug.G_err_stage := 'Calling module not PAAPIMP';
1877 log_message('log_message: ' || pa_debug.G_err_stage);
1878 END IF;
1879
1880 --
1881 -- Changes for CBGA
1882 --
1883 -- The following change was to get the business group id if a business group
1884 -- name is provided.
1885 --
1886 --PA-K Changes: If predefined source and ID provided then use it else derive.
1887 /** Bug#3026218 If Person Business Group Id is not null then use it and
1888 do not derive **/
1889 IF P_Person_Business_Group_Id IS NOT NULL THEN
1890 G_Business_Group_Id := P_Person_Business_Group_Id;
1891 ELSE
1892
1893 IF X_Business_Group_Name IS NULL THEN
1894
1895 G_Business_Group_Id := NULL ;
1896
1897 ELSIF G_Prev_Business_Group_Name = X_Business_Group_Name THEN
1898
1899 G_Business_Group_Id := G_Prev_Business_Group_Id ;
1900 ELSE
1901 G_Business_Group_Id := pa_utils2.GetBusinessGroupId(X_Business_Group_Name);
1902
1903 IF G_Business_Group_Id is NULL THEN
1904
1905 X_status := 'PA_INVALID_BUSINESS_GROUP';
1906
1907 G_Prev_Business_Group_Name := NULL ;
1908 G_Prev_Business_Group_Id := NULL ;
1909
1910 ELSE
1911
1912 G_Prev_Business_Group_Name := X_Business_Group_Name ;
1913 G_Prev_Business_Group_Id := G_Business_Group_Id ;
1914 END IF; /* G_Business_Group_Id is NULL */
1915 END IF; /* X_Business_Group_Name IS NULL */
1916 END IF; /* P_Person_Business_Group_Id IS NOT NULL */
1917
1918 -- ===========================================================================
1919 -- Perform TRANSACTION SOURCE validation:
1920 -- * TRANSACTION SOURCE exists
1921 -- * If TRANSACTION SOURCE is defined as costed, then RAW_COST must be
1922 -- provided
1923 -- * TRANSACTION SORUCE must be active as of the transaction date
1924
1925 last_empno := NULL;
1926 last_proj := NULL;
1927 last_task := NULL;
1928 last_etype := NULL;
1929
1930 IF ( nvl( X_module, 'EXTERNAL' ) <> 'PAXTRTRX' ) THEN
1931
1932 IF PG_DEBUG = 'Y' THEN
1933 pa_debug.G_err_Stage := 'G_trx_link = ' || G_trx_link;
1934 log_message('log_message: ' || pa_debug.G_err_Stage);
1935 END IF;
1936
1937 IF (G_trx_link is null OR X_trx_src <> G_trx_source) Then --3567234
1938 IF PG_DEBUG = 'Y' THEN
1939 pa_debug.G_err_Stage := 'Calling GetTrxSrcInfo';
1940 log_message('log_message: ' || pa_debug.G_err_Stage);
1941 END IF;
1942 GetTrxSrcInfo( X_trx_src );
1943 End If;
1944
1945 IF ( G_trx_link IS NULL ) THEN
1946 IF PG_DEBUG = 'Y' THEN
1947 pa_debug.G_err_Stage := 'Invalid Trx Source';
1948 log_message('log_message: ' || pa_debug.G_err_Stage);
1949 END IF;
1950 X_status := 'INVALID_TRX_SOURCE';
1951 pa_cc_utils.reset_curr_function;
1952 RETURN;
1953 END IF;
1954
1955 END IF;
1956
1957 -- ==========================================================================
1958 -- Bugs: 1063562 and 1069585
1959 -- Calls procedure Validate_VI to do the following validations for Vendor Invoices:
1960 -- 1. Transaction Source needs to be GL accounted.
1961 -- 2. Vendor Number needs to be provided
1962 IF (X_system_linkage = 'VI') THEN
1963 Validate_VI (
1964 X_vendor_number => X_vendor_number,
1965 X_employee_number => X_enum,
1966 X_result => v_result,
1967 X_status => X_status);
1968 IF (v_result <> 0) THEN
1969 pa_cc_utils.reset_curr_function;
1970 RETURN;
1971 END IF;
1972 END IF;
1973
1974 -- Validation for non zero raw cost is moved from here to the else clause of the
1975 -- Burden Transaction validation.... Selva 03/07/97
1976 --
1977 IF ( trunc(X_ei_date) NOT BETWEEN trunc(G_trx_start)
1978 AND nvl(trunc(G_trx_end), trunc(X_ei_date))) THEN
1979 X_status := 'TRX_SOURCE_INACTIVE';
1980 pa_cc_utils.reset_curr_function;
1981 RETURN;
1982
1983 END IF;
1984
1985 -- ==========================================================================
1986 -- Added 'VI' in the following IF condition.
1987 -- A supplier invoice does not need to have
1988 -- employee number and organization name
1989 IF ( X_system_linkage NOT IN ('ST', 'OT','ER', 'VI') ) THEN
1990 if ( X_enum IS NULL AND X_ONAME is NULL ) THEN
1991 X_status := 'EMP_OR_ORG_MAND' ;
1992 pa_cc_utils.reset_curr_function;
1993 RETURN ;
1994 end if ;
1995 END IF ;
1996
1997 -- REL12 AP Lines uptake.
1998 -- Unaccounted Expense report transactions are not allowed.
1999 IF ( X_system_linkage = 'ER' and NVL(g_gl_accted_flag,'N') = 'N' ) then
2000 X_status := 'PA_ER_NOT_ACCOUNTED' ;
2001 pa_cc_utils.reset_curr_function;
2002 RETURN ;
2003 END IF ;
2004
2005 -- ===========================================================================
2006 -- Verify that the expenditure ending date is a valid expenditure week
2007 -- ending date
2008 --
2009 IF PG_DEBUG = 'Y' THEN
2010 pa_debug.G_err_stage := 'Calling pa_utils.GetWeekEnding';
2011 log_message('log_message: ' || pa_debug.G_err_Stage);
2012 END IF;
2013 IF (trunc( X_end_date) <> trunc(pa_utils.NewGetWeekEnding( X_end_date )) ) THEN
2014 X_status := 'INVALID_END_DATE';
2015 pa_cc_utils.reset_curr_function;
2016 RETURN;
2017
2018 -- ===========================================================================
2019 -- Verify that the transaction item date is on or before the week ending
2020 -- date
2021 --
2022 ELSIF ( trunc(X_ei_date) > trunc(X_end_date) ) THEN /* Bug 4284192 */
2023 X_status := 'EI_DATE_AFTER_END_DATE';
2024 pa_cc_utils.reset_curr_function;
2025 RETURN;
2026 END IF; --PA-K Changes: Added 'EndIf' separating the date checks
2027 --from the person and org checks
2028
2029 --PA-K Changes: Use the ID if provided for predefined transaction sources.
2030 /** Bug#3026218. If Person Id and Organization Id are provided, then use them **/
2031 IF P_Person_Id is not null and P_Organization_Id is not null Then
2032 G_Person_Id := P_Person_Id;
2033 G_Org_Id := P_Organization_Id;
2034
2035 /* Bug 6519602: Base Bug 6519570 - Changes start */
2036 IF PG_DEBUG = 'Y' THEN
2037 pa_debug.G_err_stage := 'Calling pa_utils.GetEmpJobId';
2038 log_message('log_message: ' || pa_debug.G_err_Stage);
2039 END IF;
2040
2041 -- 10253400: Payroll integration enhancement for 12.2..start
2042 -- Job related parameters are now sent for ST. Validate them.
2043 IF (p_job_id is not null or p_job_name is not null) and X_system_linkage = 'ST' then
2044
2045 IF PG_DEBUG = 'Y' THEN
2046 pa_debug.G_err_Stage := 'Calling pa_utils.GetJobId';
2047 log_message('log_message: ' || pa_debug.G_err_Stage);
2048 END IF;
2049
2050 /* Start changes for bug#12646514 */
2051 G_job_id := pa_utils.GetJobId(X_Business_Group_Id => G_Business_Group_Id
2052 ,X_Job_Id => p_job_id
2053 ,X_Job_Name => p_job_name
2054 ,X_Date => X_ei_Date);
2055 /* End changes for bug#12646514 */
2056
2057 ELSE
2058 IF PG_DEBUG = 'Y' THEN
2059 pa_debug.G_err_Stage := 'Calling pa_utils.GetEmpJobId..2';
2060 log_message('log_message: ' || pa_debug.G_err_Stage);
2061 END IF;
2062
2063 G_job_id := pa_utils.GetEmpJobId(
2064 X_person_id => G_person_id,
2065 X_date => X_ei_date ,
2066 X_po_number => p_po_number,
2067 X_po_line_num => p_po_line_num);
2068 END IF;
2069
2070 IF ( G_job_id IS NULL ) THEN
2071 /* Start changes for bug#12646514 */
2072 -- X_status := 'NO_ASSIGNMENT';
2073 X_status := pa_utils.G_return_status;
2074 /* End changes for bug#12646514 */
2075 pa_cc_utils.reset_curr_function;
2076 RETURN;
2077 END IF;
2078
2079 -- 10253400: Payroll integration enhancement for 12.2..end
2080
2081 IF PG_DEBUG = 'Y' THEN
2082 pa_debug.G_err_stage := ' G_Job_Id = ' || G_Job_Id;
2083 log_message('log_message: ' || pa_debug.G_err_stage);
2084 END IF;
2085 /* Bug 6519602: Base Bug 6519570 - Changes end */
2086
2087 ELSE
2088 -- Bug: 1063552
2089 -- For third party transaction sources transferring supplier invoices,
2090 -- we will not transfer the employee number
2091 -- We will transfer the organization info if the following requirements are met:
2092 -- 1. Transaction source is defined with employee organization override
2093 -- 2. User provided a valid organization name for the override.
2094 IF ((X_enum is NOT NULL) AND
2095 (G_trx_predef_flag = 'N') AND
2096 (X_system_linkage = 'VI')) THEN
2097
2098 G_person_id := NULL;
2099
2100 IF PG_DEBUG = 'Y' THEN
2101 pa_debug.G_err_Stage := 'Calling pa_utils.GetOrgnId';
2102 log_message('log_message: ' || pa_debug.G_err_Stage);
2103 END IF;
2104
2105 IF ( X_oname IS NOT NULL ) THEN
2106
2107 --Start of changes for bug 3010848
2108 --G_org_id := pa_utils.GetOrgId(X_oname);
2109 pa_utils.GetOrgnId(X_org_name => X_oname,
2110 X_bg_id => G_Business_Group_Id,
2111 X_Orgn_Id => G_org_id,
2112 X_Return_Status => L_Org_RetSts);
2113
2114 If L_Org_RetSts is Not Null Then
2115 X_status := L_Org_RetSts;
2116 RETURN;
2117 End If;
2118 --End of changes for bug 3010848
2119
2120
2121 IF (G_org_id IS NULL) THEN
2122 X_status := 'PA_EXP_ORG_INVALID';
2123 pa_cc_utils.reset_curr_function;
2124 RETURN;
2125 END IF;
2126
2127 /* PA-K Changes: Commenting the CheckExporg, moved the check to one place below*/
2128
2129 ELSE
2130 G_org_id := NULL;
2131 END IF; /* IF X_oname IS NOT NULL*/
2132
2133 -- ===========================================================================
2134 -- Get the person ID for the employee number given
2135 ELSIF ( X_enum IS NOT NULL ) THEN
2136
2137 IF PG_DEBUG = 'Y' THEN
2138 pa_debug.G_err_stage := 'Calling pa_utils.GetEmpId, G_business_Group_id = ' || G_business_Group_id;
2139 log_message('log_message: ' || pa_debug.G_err_Stage);
2140 END IF;
2141 -- Fixed Bug 1534973, 1581184
2142 -- Passing X_Ei_Date parameter to GetEmpId
2143
2144 pa_utils2.GetEmpId( G_business_Group_id,
2145 X_enum,
2146 G_person_id,
2147 P_person_type, /* cwk */
2148 X_Ei_Date );
2149
2150 IF ( pa_utils2.G_return_status IS NOT NULL ) THEN
2151 X_status := pa_utils2.G_return_status ;
2152 pa_cc_utils.reset_curr_function;
2153 RETURN;
2154 ELSE
2155 last_empno := X_enum;
2156
2157 -- ==============================================
2158 -- Enhancement for Oracle Labor Distribution
2159 -- Don't fetch the employee's org ID if the flag
2160 -- allow_emp_org_override_flag is set to 'Y'
2161
2162 IF nvl(G_emp_org_oride,'N') = 'Y' THEN
2163
2164 /*Bug 2655157, Commented this code see below for actual code
2165 IF ( X_oname IS NULL ) THEN
2166 X_status := 'PA_EXP_ORG_MANDATORY';
2167 pa_cc_utils.reset_curr_function;
2168 RETURN;
2169 END IF;
2170
2171 IF PG_DEBUG = 'Y' THEN
2172 pa_debug.G_err_Stage := 'Calling pa_utils.GetOrgId';
2173 log_message('log_message: ' || pa_debug.G_err_Stage);
2174 END IF;
2175
2176 G_org_id := pa_utils.GetOrgId(X_oname);
2177
2178 IF (G_org_id IS NULL) THEN
2179 X_status := 'PA_EXP_ORG_INVALID';
2180 pa_cc_utils.reset_curr_function;
2181 RETURN;
2182 END IF;
2183 */
2184 -- Bug 2655157 : Below code added for the error being raised in
2185 -- Review Transactions form
2186 IF ( X_oname IS NULL ) THEN
2187 IF PG_DEBUG = 'Y' THEN
2188 pa_debug.G_err_Stage := 'Calling pa_utils.GetEmpOrgId';
2189 log_message('log_message: ' || pa_debug.G_err_Stage);
2190 END IF;
2191
2192 G_org_id := pa_utils.GetEmpOrgId(G_person_id, X_Ei_Date);
2193
2194 IF ( G_org_id IS NULL ) THEN
2195 X_status := 'PA_EXP_ORG_MANDATORY';
2196 pa_cc_utils.reset_curr_function;
2197 RETURN;
2198 END IF;
2199
2200 ELSE
2201
2202 IF PG_DEBUG = 'Y' THEN
2203 pa_debug.G_err_Stage := 'Calling pa_utils.GetOrgnId';
2204 log_message('log_message: ' || pa_debug.G_err_Stage);
2205 END IF;
2206
2207 --Start of changes for Bug 3010848
2208 --G_org_id := pa_utils.GetOrgId(X_oname);
2209 pa_utils.GetOrgnId(X_org_name => X_oname,
2210 X_bg_id => G_Business_Group_Id,
2211 X_Orgn_Id => G_org_id,
2212 X_Return_Status => L_Org_RetSts);
2213
2214
2215 If L_Org_RetSts is Not Null Then
2216 X_status := L_Org_RetSts;
2217 RETURN;
2218 End If;
2219 --End of changes for Bug 3010848
2220
2221
2222 IF (G_org_id IS NULL) THEN
2223 X_status := 'PA_EXP_ORG_INVALID';
2224 pa_cc_utils.reset_curr_function;
2225 RETURN;
2226 END IF;
2227
2228 END IF;
2229 --End of fix for Bug 2655157
2230
2231 -- ============================================
2232 -- Get the job ID of the employee's job
2233 -- assignment as of the item date
2234
2235 IF PG_DEBUG = 'Y' THEN
2236 pa_debug.G_err_stage := 'Calling pa_utils.GetEmpJobId..3';
2237 log_message('log_message: ' || pa_debug.G_err_Stage);
2238 END IF;
2239
2240 -- 10253400: Payroll integration enhancement for 12.2..start
2241 -- Job related parameters are now sent for ST. Validate them.
2242 IF (p_job_id is not null or p_job_name is not null) and X_system_linkage = 'ST' then
2243 IF PG_DEBUG = 'Y' THEN
2244 pa_debug.G_err_Stage := 'Calling pa_utils.GetJobId..2';
2245 log_message('log_message: ' || pa_debug.G_err_Stage);
2246 END IF;
2247 /* Start changes for bug#12646514 */
2248
2249 G_job_id := pa_utils.GetJobId(X_Business_Group_Id => G_Business_Group_Id
2250 ,X_Job_Id => p_job_id
2251 ,X_Job_Name => p_job_name
2252 ,X_Date => X_ei_Date);
2253 /* End changes for bug#12646514 */
2254
2255 -- 10253400: Payroll integration enhancement for 12.2..end
2256 ELSE
2257 IF PG_DEBUG = 'Y' THEN
2258 pa_debug.G_err_Stage := 'Calling pa_utils.GetEmpJobId';
2259 log_message('log_message: ' || pa_debug.G_err_Stage);
2260 END IF;
2261
2262 G_job_id := pa_utils.GetEmpJobId(
2263 X_person_id => G_person_id,
2264 X_date => X_ei_date ,
2265 X_po_number => p_po_number,
2266 X_po_line_num => p_po_line_num);
2267 END IF;
2268 -- Added PO params for bug 4044057
2269 -- Need to validate the assigment for the entered PO
2270
2271 IF ( G_job_id IS NULL ) THEN
2272
2273 -- Commented for bug 4531168
2274 -- IF p_po_number is null THEN
2275 -- X_status := 'NO_ASSIGNMENT';
2276 -- ELSE
2277 -- X_status := 'NO_PO_ASSIGNMENT';
2278 -- END IF;
2279 -- pa_cc_utils.reset_curr_function;
2280 -- RETURN;
2281
2282 /*Begin for bug 4531168*/
2283 IF X_trx_src in ('OLD', 'GOLD', 'GOLDE') and p_po_number is null THEN
2284 begin
2285 select paa.job_id
2286 into G_job_id
2287 from PER_ALL_ASSIGNMENTS_F paa,
2288 psp_summary_lines psl
2289 where paa.assignment_id = psl.assignment_id
2290 and psl.effective_date between paa.effective_start_date and paa.effective_end_date
2291 and psl.SUMMARY_LINE_ID = X_trx_ref;
2292 exception
2293 when OTHERS then
2294 X_status := 'NO_ASSIGNMENT';
2295 pa_cc_utils.reset_curr_function;
2296 RETURN;
2297 end;
2298 ELSIF p_po_number is null then
2299
2300 /* Start changes for bug#12646514 */
2301 X_status := pa_utils.G_return_status;
2302 -- X_status := 'NO_ASSIGNMENT';
2303 /* End changes for bug#12646514 */
2304
2305 pa_cc_utils.reset_curr_function;
2306 RETURN;
2307 ELSE
2308 X_status := 'NO_PO_ASSIGNMENT';
2309 pa_cc_utils.reset_curr_function;
2310 RETURN;
2311 END IF;
2312 /* End for bug 4531168 */
2313
2314 END IF;
2315
2316 ELSE
2317
2318 -- =============================================
2319 -- Get the organization ID of the employee's
2320 -- organization assignment as of the item date
2321
2322 /* Pa.K Changes: For Performance, combined org and job id derivation */
2323
2324 G_org_id := P_Emp_Org_Id;
2325 G_Job_Id := P_Emp_Job_Id;
2326
2327 If G_org_id is NULL or G_Job_Id is NULL Then
2328 IF PG_DEBUG = 'Y' THEN
2329 pa_debug.G_err_stage := 'Calling pa_utils.GetEmpOrgJobId..1';
2330 log_message('log_message: ' || pa_debug.G_err_Stage);
2331 END IF;
2332
2333 -- 10253400: Payroll integration enhancement for 12.2.. start
2334 IF p_job_id is not null or p_job_name is not null then
2335
2336 IF PG_DEBUG = 'Y' THEN
2337 pa_debug.G_err_stage := 'Calling pa_utils.GetEmpOrgJobId..3';
2338 log_message('log_message: ' || pa_debug.G_err_Stage);
2339 END IF;
2340 /* Start changes for bug#12646514 */
2341 G_Job_ID := pa_utils.getjobid(X_Business_Group_Id => G_Business_Group_Id,X_Job_Id => p_Job_Id,
2342 X_Job_Name => p_Job_Name,
2343 X_Date => X_Ei_Date);
2344 /* End changes for bug#12646514 */
2345
2346 IF G_Job_Id is null THEN
2347
2348 /* Start changes for bug#12646514 */
2349 -- X_status := 'NO_ASSIGNMENT';
2350 X_status := pa_utils.G_return_status;
2351 /* End changes for bug#12646514 */
2352
2353 pa_cc_utils.reset_curr_function;
2354 RETURN;
2355 END IF;
2356 END IF;
2357
2358 IF G_Org_Id is null then
2359 G_Org_Id := pa_utils.getEmpOrgId(X_Person_Id => G_Person_Id,
2360 X_Date => X_Ei_Date);
2361 END IF;
2362
2363 If G_Job_Id IS NULL OR G_Org_Id IS NULL THEN
2364 -- 10253400: Payroll integration enhancement for 12.2.. end
2365 pa_utils.GetEmpOrgJobId( G_person_id, X_ei_date, G_Org_Id, G_Job_Id ,p_po_number, p_po_line_num);
2366 End if;
2367 -- Added PO params for bug 4044057
2368 -- Need to validate the assigment for the entered PO
2369
2370 End If;
2371
2372
2373 IF ( G_org_id IS NULL or G_Job_Id IS NULL ) THEN
2374
2375 -- Commented for bug 4531168
2376 -- IF p_po_number is null THEN
2377 -- X_status := 'NO_ASSIGNMENT';
2378 -- ELSE
2379 -- X_status := 'NO_PO_ASSIGNMENT';
2380 -- END IF;
2381 -- pa_cc_utils.reset_curr_function;
2382 -- RETURN;
2383
2384 /*Begin for bug 4531168*/
2385 IF X_trx_src in ('OLD', 'GOLD', 'GOLDE') and p_po_number is null THEN
2386 begin
2387 select paa.job_id
2388 into G_job_id
2389 from PER_ALL_ASSIGNMENTS_F paa,
2390 psp_summary_lines psl
2391 where paa.assignment_id = psl.assignment_id
2392 and psl.effective_date between paa.effective_start_date and paa.effective_end_date
2393 and psl.SUMMARY_LINE_ID = X_trx_ref;
2394 exception
2395 when OTHERS then
2396 X_status := 'NO_ASSIGNMENT';
2397 pa_cc_utils.reset_curr_function;
2398 RETURN;
2399 end;
2400 ELSIF p_po_number is null then
2401 X_status := 'NO_ASSIGNMENT';
2402 pa_cc_utils.reset_curr_function;
2403 RETURN;
2404 ELSE
2405 X_status := 'NO_PO_ASSIGNMENT';
2406 pa_cc_utils.reset_curr_function;
2407 RETURN;
2408 END IF;
2409 /* End for bug 4531168 */
2410
2411 END IF;
2412
2413 END IF; /* IF nvl(G_emp_org_oride,'N') = 'Y' */
2414
2415 /* PA-K Changes: Commenting the CheckExporg, moved the check to one place below */
2416
2417 /* PA-K Changes: For Performance, combined org and job id derivation */
2418
2419 END IF; /* IF ( G_person_id IS NULL ) */
2420
2421 -- ===========================================================================
2422 -- Get the organization ID for the incurred by organization name given
2423 ELSIF ( X_enum IS NULL AND X_oname IS NOT NULL ) THEN
2424
2425 IF PG_DEBUG = 'Y' THEN
2426 pa_debug.G_err_Stage := 'Calling pa_utils.GetOrgnId';
2427 log_message('log_message: ' || pa_debug.G_err_Stage);
2428 END IF;
2429
2430 G_person_id := NULL;
2431 --Start of changes for 3010848
2432 --G_org_id := pa_utils.GetOrgId( X_oname );
2433 pa_utils.GetOrgnId(X_org_name => X_oname,
2434 X_bg_id => G_Business_Group_Id,
2435 X_Orgn_Id => G_org_id,
2436 X_Return_Status => L_Org_RetSts);
2437
2438 If L_Org_RetSts is Not Null Then
2439 X_status := L_Org_RetSts;
2440 RETURN;
2441 End If;
2442 --End of changes for 3010848
2443
2444
2445 IF ( G_org_id IS NULL ) THEN
2446 X_status := 'INVALID_ORGANIZATION';
2447 pa_cc_utils.reset_curr_function;
2448 RETURN;
2449 END IF;
2450
2451 /* PA-K Changes: Commenting the CheckExporg, moved the check to one place below */
2452
2453 -- =============================================================================
2454 -- Trx_import enhancement:
2455 -- X_enum and X_oname are both NULL. This can happen when transferring invoices
2456 -- with supplier not being an employee
2457 ELSE
2458 G_person_id := NULL;
2459 G_org_id := NULL;
2460 END IF; /*IF ( X_end_date <> trunc(pa_utils.GetWeekEnding( X_end_date )) ) */
2461
2462 END IF; --Predefined source check for person and organization id
2463
2464 -- PA-K Changes: Moved CheckExporg to below one place
2465 IF G_org_id is not NULL THEN
2466 IF pa_trx_import.g_skip_tc_flag <> 'Y' and PA_TRX_IMPORT.Get_GVal_ProjTskEi_Date = 'Y' then /* Added for Bug # 2170237 */
2467 -- Modified the above condition for BUG6931833
2468 IF PG_DEBUG = 'Y' THEN
2469 pa_debug.G_err_stage := 'Calling pa_utils2.CheckExporg';
2470 log_message('log_message: ' || pa_debug.G_err_Stage);
2471 log_message('log_message: ' || 'G_org_id = ' || G_org_id);
2472 END IF;
2473 IF pa_utils2.CheckExporg(G_org_id,X_ei_date) = 'N' then
2474 X_status := 'PA_EXP_ORG_NOT_ACTIVE';
2475 pa_cc_utils.reset_curr_function;
2476 RETURN;
2477 END IF;
2478 END IF;
2479 END IF; /* Added for Bug # 2170237 */
2480
2481 -- =========================================================================
2482 -- 12.2 payroll intg. Validate the Location data and populate the location
2483 -- 10253400: Payroll integration enhancement for 12.2.
2484 -- =========================================================================
2485 IF P_Location_Id is null and P_Location_Code is null then
2486 G_location_id := pa_utils.GetAsgnLocationId(p_person_id => G_Person_Id,
2487 p_ei_date => X_ei_date);
2488 END IF;
2489
2490 IF P_Location_Id is not null or P_Location_Code is not null then
2491
2492 IF PG_DEBUG = 'Y' THEN
2493 pa_debug.G_err_stage := 'Calling pa_utils.GetLocationId';
2494 log_message('log_message: ' || pa_debug.G_err_Stage);
2495 log_message('log_message: ' || 'G_org_id = ' || G_org_id);
2496 END IF;
2497
2498 G_location_id := pa_utils.getlocationId(p_location_id
2499 ,p_location_code
2500 ,X_ei_Date);
2501
2502 IF PG_DEBUG = 'Y' THEN
2503 pa_debug.G_err_stage := 'Called pa_utils.GetLocationId';
2504 log_message('log_message: ' || pa_debug.G_err_Stage);
2505 log_message('log_message: ' || 'G_location_id = ' || G_location_id);
2506 END IF;
2507
2508 if G_location_id is null then
2509 -- put a message here and raise;
2510 X_status := 'PA_INVALID_LOCATION';
2511 pa_cc_utils.reset_curr_function;
2512 RETURN;
2513 end if;
2514 END IF;
2515
2516 -- =============================================================================
2517 -- Trx_import enhancement:
2518 -- Get override-to organization ID if override_to_organization_name is provided
2519 --
2520 --PA-K Changes: Use the ID if provided for predefined transaction sources.
2521 /** Bug#3026218. Use ID if provided for any transaction source **/
2522 IF P_override_organization_id IS NOT NULL THEN
2523 G_override_to_org_id := P_override_organization_id;
2524 ELSE
2525 IF (X_override_to_oname IS NOT NULL) THEN
2526
2527 IF PG_DEBUG = 'Y' THEN
2528 pa_debug.G_err_stage := 'Calling pa_utils.GetOrgnId for override org';
2529 log_message('log_message: ' || pa_debug.G_err_Stage);
2530 END IF;
2531
2532 --Start of changes for bug 3010848
2533 --G_override_to_org_id := pa_utils.GetOrgId(X_override_to_oname);
2534
2535 pa_cc_utils.log_message('X_override_to_oname = ' || X_override_to_oname
2536 || ' G_Business_Group_Id = ' || G_Business_Group_Id);
2537
2538
2539 pa_utils.GetOrgnId(X_org_name => X_override_to_oname,
2540 X_bg_id => G_Business_Group_Id,
2541 X_Orgn_Id => G_override_to_org_id,
2542 X_Return_Status => L_Org_RetSts);
2543
2544 If L_Org_RetSts is Not Null Then
2545 X_status := L_Org_RetSts;
2546 RETURN;
2547 End If;
2548 --End of changes for bug 3010848
2549
2550 IF (G_override_to_org_id IS NULL) THEN
2551 X_status := 'PA_OVERRIDE_ORG_INVALID';
2552 pa_cc_utils.reset_curr_function;
2553 RETURN;
2554 ELSIF pa_trx_import.g_skip_tc_flag <> 'Y' and PA_TRX_IMPORT.Get_GVal_ProjTskEi_Date = 'Y' THEN /* Added for Bug # 2170237 */
2555 --Modified above condition for bug6931833
2556 IF pa_utils2.CheckExporg(G_override_to_org_id, X_ei_date) = 'N' THEN
2557 X_status := 'PA_OVERRIDE_ORG_NOT_ACTIVE';
2558 pa_cc_utils.reset_curr_function;
2559 RETURN;
2560 END IF;
2561 END IF; /* Added for Bug # 2170237 */
2562 ELSE
2563 -- Bug: 927655
2564 -- Reset G_override_to_org_id to NULL, so that the next transaction within
2565 -- the same expenditure does not get the same override to org.
2566 G_override_to_org_id := NULL;
2567 -- X_override_to_oname IS NULL, check if G_org_id IS NULL.
2568 -- If G_org_id is also NULL, then return error
2569 IF (G_org_id IS NULL) THEN
2570 X_status := 'PA_EXP_ORG_NOT_SPECIFIED';
2571 pa_cc_utils.reset_curr_function;
2572 RETURN;
2573 END IF;
2574 END IF;
2575 END IF;
2576
2577 -- =============================================================================
2578 -- Trx_import enhancement:
2579 -- Check the vendor number only if the current vendor number is different from
2580 -- the previous vendor number
2581 --PA-K Changes: Use the ID if provided for predefined transaction sources.
2582 /** Bug#3026218 Use Vendor Id if provided for any tyep of transaction source **/
2583 IF P_Vendor_Id is not NULL THEN
2584 G_vendor_id := P_Vendor_Id;
2585 ELSIF
2586 ( X_vendor_number IS NOT NULL AND
2587 (G_previous_vendor_number <> X_vendor_number OR
2588 G_previous_vendor_number IS NULL ) ) THEN
2589
2590 GetVendorId(P_vendor_number => X_vendor_number);
2591
2592 IF (G_vendor_id IS NULL) THEN
2593 X_status := 'PA_SUPPLIER_NUM_INVALID';
2594 pa_cc_utils.reset_curr_function;
2595 RETURN;
2596 END IF;
2597
2598 G_previous_vendor_number := X_vendor_number;
2599 ELSIF (X_vendor_number IS NULL) THEN --added for 8205209
2600 G_vendor_id := NULL;
2601 G_previous_vendor_number := NULL; -- added for 9466254
2602
2603 END IF;
2604
2605 -- ===========================================================================
2606 -- Get the project and task IDs associated with the project and task
2607 -- numbers given
2608 --
2609 -- IF ( last_proj IS NULL OR X_pnum <> last_proj ) THEN
2610
2611 --PA-K Changes: Use the ID if provided for predefined transaction sources.
2612 /** Bug#3026218. Use Project Id, if provided for any type of transaction source **/
2613 IF P_Project_Id is not null THEN
2614 G_project_id := P_Project_Id;
2615 ELSE
2616 IF PG_DEBUG = 'Y' THEN
2617 pa_debug.G_err_stage := 'Calling pa_utils.GetProjId';
2618 log_message('log_message: ' || pa_debug.G_err_Stage);
2619 END IF;
2620
2621 G_project_id := pa_utils.GetProjId( X_pnum );
2622 END IF;
2623
2624 --PA-K Changes:
2625 --IF (G_Task_Id IS NULL) THEN
2626 --PA-K Changes: Use the ID if provided for predefined transaction sources.
2627 /** Bug#3026218 Use Task Id, if provided for any type of transaction source **/
2628 IF P_Task_Id is not NULL THEN
2629 G_task_id := P_Task_Id;
2630 ELSE
2631 IF PG_DEBUG = 'Y' THEN
2632 pa_debug.G_err_stage := 'Calling pa_utils.GetTaskId';
2633 log_message('log_message: ' || pa_debug.G_err_Stage);
2634 END IF;
2635
2636 G_task_id := pa_utils.GetTaskId( G_project_id, X_tnum );
2637 END IF;
2638
2639 -- ===========================================================================
2640 -- EXPENDITURE TYPE validation
2641 -- * Expenditure type given exists
2642 -- * Expenditure type has same system linkage as transaction source
2643 -- 07/15/97- selva: This above condition is not valid after project Manuf. changes.
2644 -- * Expenditure type is active as of the transaction item date
2645 -- IF ( last_etype IS NULL OR x_etype <> last_etype ) THEN
2646 -- Check pa_expend_typ_sys_links table for for existence and activeness of
2647 -- the given exp_type/sys_link combination
2648
2649 IF PG_DEBUG = 'Y' THEN
2650 pa_debug.G_err_stage := 'Calling GetEtypeEclassInfo';
2651 log_message('log_message: ' || pa_debug.G_err_Stage);
2652 END IF;
2653 GetEtypeEclassInfo(X_etype, X_system_linkage) ;
2654
2655 IF ( G_etype_link is NULL ) then
2656 X_status := 'INVALID_ETYPE_SYSLINK' ;
2657 pa_cc_utils.reset_curr_function;
2658 RETURN ;
2659 END IF ;
2660
2661 IF ( X_ei_date NOT BETWEEN G_etec_start
2662 AND nvl( G_etec_end, X_ei_date ) ) THEN
2663 X_status := 'ETYPE_SLINK_INACTIVE';
2664 pa_cc_utils.reset_curr_function;
2665 RETURN;
2666 END IF;
2667
2668 -- Check pa_expenditure_types table for for existence and activeness of
2669 -- the given exp_type combination
2670 IF PG_DEBUG = 'Y' THEN
2671 pa_debug.G_err_stage := 'Calling GetEtypeInfo';
2672 log_message('log_message: ' || pa_debug.G_err_Stage);
2673 END IF;
2674 GetEtypeInfo( X_etype, X_ei_date );
2675
2676 IF ( NOT G_etype_active ) THEN
2677 X_status := 'INVALID_EXP_TYPE';
2678 pa_cc_utils.reset_curr_function;
2679 RETURN;
2680 ELSE
2681 last_etype := x_etype;
2682 END IF;
2683
2684 -- Based on project journal design a transaction source can have more than one system_linkage
2685 -- So the validation of system_linkage of source with expenditure type is no more valid.
2686 -- The validation should be between the system_linkage of the record and the system_linkage of
2687 -- expenditure type of the same record. At present the system linkage is in pa_expenditure_types
2688 -- table. But once the new table for expenditure type and system_linkage is created, the given
2689 -- record's system linkage should be checked for existence in the new table.
2690 -- Selva 03/07/97
2691
2692 IF ( X_ei_date NOT BETWEEN G_etype_start
2693 AND nvl( G_etype_end, X_ei_date ) ) THEN
2694 X_status := 'EXP_TYPE_INACTIVE';
2695 pa_cc_utils.reset_curr_function;
2696 RETURN;
2697 END IF;
2698
2699 ELSE --Calling module = PAAPIMP
2700
2701 IF PG_DEBUG = 'Y' THEN
2702 pa_debug.G_err_stage := 'Calling module is PAAPIMP';
2703 log_message('log_message: ' || pa_debug.G_err_stage);
2704 END IF;
2705
2706 G_project_id := P_Project_Id;
2707 G_task_id := P_Task_Id;
2708 G_Vendor_Id := P_Vendor_Id;
2709 G_Person_Id := P_Person_Id;
2710 G_override_to_org_id := P_Override_Organization_Id ;
2711
2712 --
2713 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
2714 -- Expenditure item related date validations are not relevant for Expense Reports.
2715 --
2716 IF PG_DEBUG = 'Y' THEN
2717 log_message('log_message: validate_exp_date x_module ='||x_module) ;
2718 log_message('log_message: validate_exp_date g_paapimp_validate_dt ='||g_paapimp_validate_dt) ;
2719 log_message('log_message: validate_exp_date x_system_linkage ='||x_system_linkage) ;
2720 log_message('log_message: validate_exp_date x_status ='||x_status) ;
2721 END IF ;
2722
2723 IF (nvl(X_module, 'EXTERNAL') = 'PAAPIMP' and
2724 g_paapimp_validate_dt = 'Y' and
2725 x_system_linkage = 'VI' and
2726 x_status is NULL ) THEN
2727
2728 IF PG_DEBUG = 'Y' THEN
2729 log_message('log_message: validate_exp_date p_project_id ='||p_project_id) ;
2730 log_message('log_message: validate_exp_date p_task_id ='||p_task_id) ;
2731 log_message('log_message: validate_exp_date p_organization_id ='||p_organization_id) ;
2732 log_message('log_message: validate_exp_date p_override_organization_id ='||p_override_organization_id) ;
2733 log_message('log_message: validate_exp_date p_vendor_id ='||p_vendor_id) ;
2734 log_message('log_message: validate_exp_date p_person_id ='||p_person_id) ;
2735 log_message('log_message: validate_exp_date x_system_linkage ='||x_system_linkage) ;
2736 log_message('log_message: validate_exp_date x_trx_source ='||x_trx_src) ;
2737 END IF ;
2738
2739 -- ===================================================
2740 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
2741 -- Following are not validated....
2742 -- PA adjustments for supplier invoice transactions
2743 -- Reversals
2744 -- Funds check adjustments
2745 -- Expenditure item adjustments
2746 -- Net ZERO Transactions for reversals
2747 -- ====================================================
2748
2749 validate_exp_date( p_project_id,
2750 p_task_id,
2751 NULL,
2752 p_override_organization_id, /*Bug 6146558 */
2753 p_vendor_id,
2754 p_person_id,
2755 x_ei_date,
2756 x_etype,
2757 x_system_linkage,
2758 x_trx_src,
2759 x_module,
2760 x_status,
2761 l_api_status) ;
2762
2763 IF X_status is not null and l_api_status = fnd_api.g_ret_sts_error then
2764
2765 --
2766 -- Bug:5502147 R12.PJ:XB9:QA:APL: ISSUES IN EI DATE VALIDATION IN PROJECTS
2767 -- Following is done to support Query by project number or task number in the transaction review form.
2768 --
2769 update pa_transaction_interface_all
2770 Set project_number = ( select segment1
2771 from pa_projects_all
2772 where project_id = P_project_id ),
2773 task_number = ( select task_number from pa_tasks
2774 where task_id = P_task_id)
2775 where txn_interface_id = X_txn_interface_id ;
2776
2777 return ;
2778 END IF ;
2779 END IF ;
2780
2781
2782 --Bug 2719674: For AP EXPENSE, G_Org_Id equivalent to
2783 --pa_expenditures_all.incurred_by_organization_id and G_Job_Id should be populated
2784 --Since these values are derived while forming the grouping attributes,
2785 --just reuse the values.
2786 /* Bug 6498029: Base Bug 6339005: added OR ( X_trx_src= 'AP NRTAX' and X_system_linkage = 'ER' ) condition for populating G_Job_id if transaction source is 'Non-Recoverable Tax From Payables' */
2787 If ( X_trx_src= 'AP EXPENSE' OR ( X_trx_src= 'AP NRTAX' and X_system_linkage = 'ER' )) Then
2788 -- Modified the following line to assign P_Organization_Id to G_Org_id for
2789 -- bug#4689402 (forward port for 4614046)
2790 /* Begin bug 5400719: See reasoning in 11i bug 5381025*/
2791 -- G_Org_Id := P_Organization_Id; --P_Emp_Org_Id;
2792 G_Org_Id := NVL(P_Override_Organization_Id, P_Organization_Id); /* added for bug 5381025 */ /*Bug 7343687*/
2793 /* End bug 5400719 */
2794 G_Job_Id := P_Emp_Job_Id;
2795
2796 IF PG_DEBUG = 'Y' THEN
2797 pa_debug.G_err_stage := 'AP EXPENSE, G_Org_Id, G_Job_Id = ' || G_Org_Id || ',' || G_Job_Id;
2798 log_message('log_message: ' || pa_debug.G_err_stage);
2799 END IF;
2800
2801 If (G_Org_Id is NULL or G_Job_Id is NULL) Then
2802 X_status := 'NO_ASSIGNMENT';
2803 pa_cc_utils.reset_curr_function;
2804 RETURN;
2805 End If;
2806
2807 End If;
2808
2809 END IF; ---}
2810
2811 IF ( G_project_id IS NULL ) THEN
2812 IF PG_DEBUG = 'Y' THEN
2813 pa_debug.G_err_stage := 'Project Id is null';
2814 log_message('log_message: ' || pa_debug.G_err_stage);
2815 END IF;
2816 X_status := 'INVALID_PROJECT';
2817 pa_cc_utils.reset_curr_function;
2818 RETURN;
2819 ELSE
2820 IF PG_DEBUG = 'Y' THEN
2821 pa_debug.G_err_stage := 'Calling GetProjTypeInfo';
2822 log_message('log_message: ' || pa_debug.G_err_Stage);
2823 END IF;
2824
2825 -- Bug 2634812 : Deriving total_burden_flag
2826 GetProjTypeInfo( G_project_id,
2827 G_Proj_bcost_flag,
2828 G_project_type_class,
2829 G_burden_amt_display_method,
2830 G_Total_Burden_Flag ) ;
2831
2832 IF G_proj_bcost_flag IS NULL THEN
2833 IF PG_DEBUG = 'Y' THEN
2834 pa_debug.G_err_stage := 'Project Type is invalid';
2835 log_message('log_message: ' || pa_debug.G_err_stage);
2836 END IF;
2837
2838 X_status := 'INVALID_PROJ_TYPE' ;
2839 pa_cc_utils.reset_curr_function;
2840 RETURN ;
2841 END IF ;
2842
2843 /* PA-K Changes: Moved G_burden_amt_display_method to GetProjTypeInfo */
2844
2845 last_proj := X_pnum;
2846
2847 /* Bug 2726763: Remove reduntant call to pa_project_utils.check_project_action_allowed
2848 This check is already present in PATC.
2849
2850 -- ===========================================================================
2851 -- Check if new transactions are allowed against this project
2852
2853 IF PG_DEBUG = 'Y' THEN
2854 pa_debug.G_err_stage := 'Calling pa_project_utils.check_project_action_allowed';
2855 log_message('log_message: ' || pa_debug.G_err_Stage);
2856 END IF;
2857
2858 -- PA-K Changes: Using Caching for performance
2859
2860 If (G_NewTxnPrjId = G_project_id) Then
2861
2862 l_NewTxnsAllowed := G_NewTxnsAllowed;
2863
2864 Else
2865
2866 l_NewTxnsAllowed := pa_project_utils.check_project_action_allowed(
2867 X_project_id => G_project_id,
2868 X_action_code => 'NEW_TXNS');
2869 G_NewTxnsAllowed := l_NewTxnsAllowed;
2870 G_NewTxnPrjId := G_project_id;
2871
2872 End If;
2873
2874 IF l_NewTxnsAllowed = 'N'
2875 THEN
2876 IF PG_DEBUG = 'Y' THEN
2877 pa_debug.G_err_stage := 'Project does not allow new txns';
2878 log_message('log_message: ' || pa_debug.G_err_stage);
2879 END IF;
2880
2881 X_status := 'PA_NEW_TXNS_NOT_ALLOWED';
2882 pa_cc_utils.reset_curr_function;
2883 RETURN;
2884 END IF;
2885 */
2886
2887 -- ===========================================================================
2888 -- Check if the cross charging is allowed for this project
2889
2890 --Bug 2726763: Add skip_tc_flag check for checking if project is chargeable.
2891 If pa_trx_import.g_skip_tc_flag <> 'Y' and PA_TRX_IMPORT.Get_GVal_ProjTskEi_Date = 'Y' then
2892 --Modified above condition for BUG6931833
2893
2894 IF PG_DEBUG = 'Y' THEN
2895 pa_debug.G_err_stage := 'Calling pa_utils.IsCrossChargeable';
2896 log_message('log_message: ' || pa_debug.G_err_Stage);
2897 END IF;
2898
2899 If not pa_utils.IsCrossChargeable(G_Project_Id) then
2900 X_Status := 'PA_PROJECT_NOT_VALID' ;
2901 pa_cc_utils.reset_curr_function;
2902 return ;
2903 End If ;
2904
2905 End If ;
2906
2907 -- ELSIF ( last_task IS NULL OR X_tnum <> last_task ) THEN
2908
2909 IF ( G_task_id IS NULL ) THEN
2910 IF PG_DEBUG = 'Y' THEN
2911 pa_debug.G_err_stage := 'Task Id is null';
2912 log_message('log_message: ' || pa_debug.G_err_stage);
2913 END IF;
2914
2915 X_status := 'INVALID_TASK';
2916 pa_cc_utils.reset_curr_function;
2917 RETURN;
2918 ELSE
2919 IF PG_DEBUG = 'Y' THEN
2920 pa_debug.G_err_stage := 'Calling pa_utils2.GetLaborCostMultiplier';
2921 log_message('log_message: ' || pa_debug.G_err_Stage);
2922 END IF;
2923 G_lcm := pa_utils2.GetLaborCostMultiplier(G_Task_id);
2924 last_task := X_tnum;
2925 END IF;
2926
2927 END IF;
2928
2929 --FSIO Changes Starts
2930 --Populate Agreement_Number and ID if FSIO is enabled.
2931 /* IF G_project_type_class = 'CONTRACT' AND G_FSIO_ENABLED = 'Y' THEN
2932 declare
2933 l_agreement_number pa_agreements.agreement_num%type;
2934 l_agreement_id number(15);
2935 begin
2936 PA_agreements_clnt_extn.get_agreement (
2937 p_project_id,
2938 p_task_id,
2939 x_ei_date,
2940 x_etype,
2941 NVL(p_organization_id, p_override_organization_id),
2942 p_vendor_id,
2943 p_person_id,
2944 x_system_linkage,
2945 l_agreement_number,
2946 l_agreement_id,
2947 x_trx_src,
2948 x_status,
2949 l_api_status);
2950 IF l_agreement_number IS NOT NULL AND l_agreement_id IS NOT NULL then
2951 declare
2952 l_dummy1 varchar2(1);
2953 begin
2954 SELECT 'Y'
2955 INTO l_dummy1
2956 FROM pa_agreements
2957 WHERE agreement_id = l_agreement_id
2958 AND agreement_num = l_agreement_number;
2959 exception
2960 WHEN NO_DATA_FOUND then
2961 X_status := 'INVALID_AGREEMENT_FR_CLNT_EXTN';
2962 pa_cc_utils.reset_curr_function;
2963 RETURN;
2964 end;
2965 p_agreement_number := l_agreement_number;
2966 p_agreement_id := l_agreement_id;
2967 END if;
2968 end;
2969 IF p_agreement_id IS NOT NULL or p_agreement_number IS NOT NULL then
2970 begin
2971 IF p_agreement_id IS NOT NULL then
2972 SELECT agreement_num
2973 INTO p_agreement_number
2974 FROM pa_agreements
2975 WHERE agreement_id = p_agreement_id;
2976 ELSIF p_agreement_number IS NOT NULL then
2977 SELECT agreement_id
2978 INTO p_agreement_id
2979 FROM pa_agreements
2980 WHERE agreement_num = p_agreement_number;
2981 END if;
2982 exception
2983 WHEN NO_DATA_FOUND then
2984 X_status := 'INVALID_AGREEMENT';
2985 pa_cc_utils.reset_curr_function;
2986 RETURN;
2987 end;
2988 IF p_agreement_id IS NULL or p_agreement_number IS NULL then
2989 X_status := 'INVALID_AGREEMENT';
2990 pa_cc_utils.reset_curr_function;
2991 RETURN;
2992 END if;
2993 else
2994 --Call default agreement derivation logic
2995 pa_billing.get_agreement_id (p_project_id,
2996 p_task_id,
2997 x_ei_date,
2998 p_agreement_id,
2999 p_agreement_number);
3000 END if;
3001 ELSE --IF G_project_type_class = 'CONTRACT' AND G_FSIO_ENABLED = 'Y' THEN
3002 p_agreement_id := NULL;
3003 p_agreement_number := NULL;
3004 END IF;
3005 --FSIO Changes Ends */
3006
3007 -- Start: Changes for CBS Enhancement bug 16220146
3008 -- ===================================================================
3009 -- Validation specific to Cost codes for CBS enabled projects
3010 -- ===================================================================
3011
3012 IF PA_ALTERNATE_TASK_PVT.Is_Cbs_Enabled(G_project_id) = 'Y' THEN
3013
3014 IF P_cbs_element_id is not null THEN
3015
3016 G_Cbs_Element_Id := P_cbs_element_id;
3017
3018 IF PG_DEBUG = 'Y' THEN
3019 pa_debug.G_err_stage := 'Validating the cost code id';
3020 log_message('log_message: ' || pa_debug.G_err_Stage);
3021 END IF;
3022
3023 PA_ALTERNATE_TASK_PVT.Is_Cost_Element_Valid(G_Cbs_Element_Id,
3024 G_task_id,
3025 G_project_id,
3026 temp_msg_type,
3027 temp_status,
3028 temp_msg_count
3029 );
3030
3031 IF temp_status IS NOT NULL THEN
3032 IF PG_DEBUG = 'Y' THEN
3033 pa_debug.G_err_stage := 'PA_CBS_INVALID_COST_CODE';
3034 log_message('log_message: ' || pa_debug.G_err_Stage);
3035 END IF;
3036
3037 G_cbs_element_id := NULL;
3038
3039 X_status := 'PA_CBS_INVALID_COST_CODE';
3040 pa_cc_utils.reset_curr_function;
3041 RETURN;
3042 ELSE
3043 IF PG_DEBUG = 'Y' THEN
3044 pa_debug.G_err_stage := 'The cost code id is valid for the project/task combination';
3045 log_message('log_message: ' || pa_debug.G_err_Stage);
3046 END IF;
3047
3048 END IF;
3049
3050 ELSIF P_cbs_element_name is not null THEN
3051
3052 IF PG_DEBUG = 'Y' THEN
3053 pa_debug.G_err_stage := 'Validating the cost code name';
3054 log_message('log_message: ' || pa_debug.G_err_Stage);
3055 END IF;
3056
3057 PA_ALTERNATE_TASK_PVT.Is_Cost_Code_Valid(P_cbs_element_name,
3058 G_task_id,
3059 G_project_id,
3060 temp_msg_type,
3061 temp_status,
3062 temp_msg_count
3063 );
3064
3065 IF temp_status IS NOT NULL THEN
3066 IF PG_DEBUG = 'Y' THEN
3067 pa_debug.G_err_stage := 'PA_CBS_INVALID_COST_CODE';
3068 log_message('log_message: ' || pa_debug.G_err_Stage);
3069 END IF;
3070
3071 G_cbs_element_id := NULL;
3072
3073 X_status := 'PA_CBS_INVALID_COST_CODE';
3074 pa_cc_utils.reset_curr_function;
3075 RETURN;
3076 ELSE
3077 IF PG_DEBUG = 'Y' THEN
3078 pa_debug.G_err_stage := 'Getting the cost code element id for the corresponding cost code name';
3079 log_message('log_message: ' || pa_debug.G_err_Stage);
3080 END IF;
3081
3082 BEGIN
3083 SELECT RBS_ELEMENT_ID
3084 INTO G_cbs_element_id
3085 FROM PA_PROJECTS_ALL PAP, PA_RBS_ELEMENTS PRE
3086 WHERE PAP.PROJECT_ID = G_project_id
3087 AND PRE.RBS_VERSION_ID = PAP.CBS_VERSION_ID
3088 AND PRE.COST_CODE = P_cbs_element_name;
3089
3090 EXCEPTION
3091 WHEN OTHERS THEN
3092 G_cbs_element_id := NULL;
3093 RAISE;
3094 END;
3095
3096 END IF;
3097
3098 ELSE
3099 IF PG_DEBUG = 'Y' THEN
3100 pa_debug.G_err_stage := 'PA_CBS_NO_COST_CODE';
3101 log_message('log_message: ' || pa_debug.G_err_Stage);
3102 END IF;
3103
3104 G_cbs_element_id := NULL;
3105
3106 X_status := 'PA_CBS_NO_COST_CODE';
3107 pa_cc_utils.reset_curr_function;
3108 RETURN;
3109
3110 END IF;
3111 ELSE
3112 G_cbs_element_id := NULL;
3113
3114 IF PG_DEBUG = 'Y' THEN
3115 pa_debug.G_err_stage := 'The project id '|| G_project_id || ' is not CBS Enabled';
3116 log_message('log_message: ' || pa_debug.G_err_Stage);
3117 END IF;
3118
3119 IF p_cbs_element_id IS NOT NULL OR P_cbs_element_name IS NOT NULL THEN
3120
3121 IF PG_DEBUG = 'Y' THEN
3122 pa_debug.G_err_stage := 'PA_CBS_PROJ_NON_CBS';
3123 log_message('log_message: ' || pa_debug.G_err_Stage);
3124 END IF;
3125
3126 X_status := 'PA_CBS_PROJ_NON_CBS';
3127 pa_cc_utils.reset_curr_function;
3128 RETURN;
3129 END IF;
3130
3131 END IF;
3132
3133 -- End: Changes for CBS Enhancement bug 16220146
3134
3135 -- ===================================================================
3136 -- Validation specific to Multi Currency Transactions
3137 -- * Check if user rate type is allowed for converting to
3138 -- functional currency
3139 -- * for acct_rate_type='User' check if exchange rate is populated
3140 -- * for acct_rate_type<> 'User' check if the rate type is valid
3141 -- * Check if user rate type is allowed for converting to
3142 -- project currency
3143 -- * for project_rate_type='User' check if exchange rate is populated
3144 -- * for project_rate_type<> 'User' check if the rate type is valid
3145 -- * check if denom currency code is populated.
3146 -- * check if transaction currency code is valid.
3147
3148 -- Multi Currency validation common to uncosted,costed and accounted txns
3149 --
3150 /*-----------------------------------------------------------------------------
3151 -- Transaction currency should be always be available.
3152 -- if it is not availabe, then default it to functional currency code
3153 ------------------------------------------------------------------------------*/
3154 IF ( X_denom_currency_code IS NULL ) THEN
3155
3156 X_denom_currency_code := G_accounting_currency_code;
3157
3158 ELSE -- X_denom_currency_code IS NOT NULL
3159
3160 IF PG_DEBUG = 'Y' THEN
3161 pa_debug.G_err_stage := 'Calling pa_multi_currency.validate_currency_code';
3162 log_message('log_message: ' || pa_debug.G_err_Stage);
3163 END IF;
3164 IF (pa_multi_currency.validate_currency_code(
3165 P_currency_code =>X_denom_currency_code,
3166 P_ei_date =>X_ei_date)= 'N')
3167 THEN
3168
3169 X_status :='PA_INVALID_DENOM_CURRENCY';
3170 pa_cc_utils.reset_curr_function;
3171 RETURN;
3172
3173 END IF; -- end invalid denom currency validation
3174
3175 END IF; -- End X_denom_currency_code IS NULL
3176
3177 /*------------------------------------------------------------------------
3178 -- Get the project currency code, which is required for validation of project
3179 -- currency attributes. Get project currency information
3180 -------------------------------------------------------------------------*/
3181
3182 IF PG_DEBUG = 'Y' THEN
3183 pa_debug.G_err_stage := 'Calling GetProjCurrInfo';
3184 log_message('log_message: ' || pa_debug.G_err_Stage);
3185 END IF;
3186
3187 -- PA-I Changes: Get Proj Functional currency code
3188 GetProjCurrInfo(G_task_id,
3189 X_project_currency_code,
3190 l_project_rate_type,
3191 X_projfunc_currency_code,
3192 l_projfunc_cost_rate_type);
3193
3194 --
3195 -- if project currency is null return null
3196 --
3197 IF ( X_project_currency_code IS NULL ) THEN
3198
3199 X_status := 'PA_MISSING_PROJ_CURR';
3200 pa_cc_utils.reset_curr_function;
3201 RETURN;
3202
3203 END IF;
3204
3205 -- Start PA-I Changes
3206 -- if project functional currency is null return error
3207 --
3208 IF ( X_projfunc_currency_code IS NULL ) THEN
3209
3210 X_status := 'PA_MISSING_PRJFUNC_CURR';
3211 pa_cc_utils.reset_curr_function;
3212 RETURN;
3213
3214 END IF;
3215 -- End PA-I Changes
3216
3217 /*-----------------------------------------------------------------------
3218 -- check if the functional rate type provided is valid.
3219 ------------------------------------------------------------------------*/
3220 IF ( X_acct_rate_type IS NOT NULL ) THEN
3221
3222 --Corrected Fix for Bug 2489534
3223 If (nvl(X_module, 'EXTERNAL') = 'PAAPIMP' OR
3224 -- S.N. Bug 3570261
3225 ((P_po_number IS NOT NULL OR P_Po_Line_Num IS NOT NULL OR
3226 P_Po_Header_Id IS NOT NULL OR P_Po_Line_Id IS NOT NULL) AND
3227 x_system_linkage in ('ST','OT'))
3228 -- E.N. Bug 3570261
3229 ) Then
3230
3231 G_acct_rate_type := X_acct_rate_type;
3232
3233 Else
3234
3235 IF PG_DEBUG = 'Y' THEN
3236 pa_debug.G_err_stage := 'Calling pa_multi_currency.get_conversion_type';
3237 log_message('log_message: ' || pa_debug.G_err_Stage);
3238 END IF;
3239 G_acct_rate_type := pa_multi_currency.get_conversion_type(
3240 P_user_rate_type => X_acct_rate_type);
3241
3242 End If;
3243
3244 IF ( G_acct_rate_type IS NULL ) THEN
3245
3246 --Conversion rate type is invalid. Reject the txn
3247
3248 X_status := 'PA_INVALID_ACCT_RATE_TYPE';
3249 pa_cc_utils.reset_curr_function;
3250 RETURN;
3251 END IF; --G_acct_rate_type is null
3252
3253 ELSE -- X_acct_rate_type is null
3254
3255 G_acct_rate_type := NULL;
3256
3257 END IF; -- X_acct_rate_type is not null
3258
3259 /*-----------------------------------------------------------------------
3260 -- check if the project rate type provided is valid.
3261 ------------------------------------------------------------------------*/
3262 IF ( X_project_rate_type IS NOT NULL ) THEN
3263
3264 --Corrected Fix for Bug 2489534
3265 If (nvl(X_module, 'EXTERNAL') <> 'PAAPIMP') Then
3266 IF PG_DEBUG = 'Y' THEN
3267 pa_debug.G_err_stage := 'Calling pa_multi_currency.get_conversion_type';
3268 log_message('log_message: ' || pa_debug.G_err_Stage);
3269 END IF;
3270 G_project_rate_type := pa_multi_currency.get_conversion_type(
3271 P_user_rate_type => X_project_rate_type);
3272 Else
3273 G_project_rate_type := X_project_rate_type;
3274 End If;
3275
3276 IF ( G_project_rate_type IS NULL ) THEN
3277
3278 --Conversion rate type is invalid. Reject the txn
3279 X_status := 'PA_INVALID_PROJ_RATE_TYPE';
3280 pa_cc_utils.reset_curr_function;
3281 RETURN;
3282
3283 END IF; --G_project_rate_type is null
3284
3285 ELSE -- i.e. X_project_rate_type is null
3286
3287 G_project_rate_type := NULL;
3288 END IF; -- X_project_rate_type is not null
3289
3290 -- Start PA-I Changes
3291 /*-----------------------------------------------------------------------
3292 -- check if the project functional rate type provided is valid.
3293 ------------------------------------------------------------------------*/
3294 IF ( X_projfunc_cost_rate_type IS NOT NULL ) THEN
3295
3296 --Corrected Fix for Bug 2489534
3297 If (nvl(X_module, 'EXTERNAL') <> 'PAAPIMP') Then
3298 IF PG_DEBUG = 'Y' THEN
3299 pa_debug.G_err_stage := 'Calling pa_multi_currency.get_conversion_type';
3300 log_message('log_message: ' || pa_debug.G_err_Stage);
3301 END IF;
3302 G_projfunc_cost_rate_type := pa_multi_currency.get_conversion_type(
3303 P_user_rate_type => X_projfunc_cost_rate_type);
3304 Else
3305 G_projfunc_cost_rate_type := X_projfunc_cost_rate_type;
3306 End If;
3307
3308 IF ( G_projfunc_cost_rate_type IS NULL ) THEN
3309
3310 --Conversion rate type is invalid. Reject the txn
3311
3312 X_status := 'PA_INVALID_PRJFUNC_CST_RT_TYP';
3313 pa_cc_utils.reset_curr_function;
3314 RETURN;
3315 END IF; --G_projfunc_cost_rate_type is null
3316
3317 ELSE -- X_projfunc_cost_rate_type is null
3318
3319 G_projfunc_cost_rate_type := NULL;
3320
3321 END IF; -- X_projfunc_cost_rate_type is not null
3322 -- End PA-I Changes
3323
3324 -- Added below for Bug 16451280
3325 IF (( G_acct_rate_type = 'User' ) and (X_denom_currency_code <> G_accounting_currency_code) ) THEN
3326
3327 -- check if rate type 'User' is allowed
3328 IF PG_DEBUG = 'Y' THEN
3329 pa_debug.G_err_stage := 'Calling pa_multi_currency.is_user_rate_type_allowed';
3330 log_message('log_message: ' || pa_debug.G_err_Stage);
3331 END IF;
3332 IF ( pa_multi_currency.is_user_rate_type_allowed(
3333 P_from_currency => X_denom_currency_code,
3334 P_to_currency => G_accounting_currency_code,
3335 P_conversion_date => nvl(X_acct_rate_date,sysdate))='N')
3336 THEN
3337
3338 -- If rate type 'User' is not allowed, reject the txn.
3339 X_status := 'PA_NO_ACCT_USER_RATE_TYPE';
3340 pa_cc_utils.reset_curr_function;
3341 RETURN;
3342
3343 ELSE -- Conversion Rate type 'User' is allowed
3344
3345 -- If rate type 'User' is allowed then the exchange rate should
3346 -- be provided.
3347
3348 IF ( X_acct_exchange_rate IS NULL ) THEN
3349 X_status := 'PA_ACCT_USER_RATE_NOT_DEFINED';
3350 pa_cc_utils.reset_curr_function;
3351 RETURN;
3352 END IF;-- end X_acct_exchange_rate IS NULL
3353
3354 END IF;-- End is_user_rate_type_allowed ='N'
3355
3356 END IF; -- End X_acct_rate_tye ='User'
3357
3358 -- Perform the same validation for project conversion rate type
3359
3360 -- Added below for Bug 16451280
3361 IF (( G_project_rate_type = 'User' ) and (X_denom_currency_code <> X_project_currency_code) ) THEN
3362
3363 IF PG_DEBUG = 'Y' THEN
3364 pa_debug.G_err_stage := 'Calling pa_multi_currency.is_user_rate_type_allowed';
3365 log_message('log_message: ' || pa_debug.G_err_Stage);
3366 END IF;
3367 IF ( pa_multi_currency.is_user_rate_type_allowed(
3368 P_from_currency => X_denom_currency_code,
3369 P_to_currency => X_project_currency_code,
3370 P_conversion_date => nvl(X_project_rate_date,sysdate))='N')
3371 THEN
3372 X_status := 'PA_NO_PROJ_USER_RATE_TYPE';
3373 pa_cc_utils.reset_curr_function;
3374 RETURN;
3375
3376 ELSE --conversion rate type 'User' is allowed
3377
3378 IF ( X_project_exchange_rate IS NULL ) THEN
3379 X_status := 'PA_PROJ_USER_RATE_NOT_DEFINED';
3380 pa_cc_utils.reset_curr_function;
3381 RETURN;
3382 END IF;-- End X_project_exchange_rate IS NULL
3383
3384 END IF;--End is_user_rate_type_allowed ='N'
3385
3386 END IF;-- End G_project_rate_type = 'User'
3387
3388 -- Start PA-I Changes
3389 -- Perform the same validation for project functional conversion rate type
3390
3391 -- Added below for Bug 16451280
3392
3393 IF ( ( G_projfunc_cost_rate_type = 'User' ) and (X_denom_currency_code <> X_projfunc_currency_code) ) THEN
3394
3395 IF PG_DEBUG = 'Y' THEN
3396 pa_debug.G_err_stage := 'Calling pa_multi_currency.is_user_rate_type_allowed';
3397 log_message('log_message: ' || pa_debug.G_err_Stage);
3398 END IF;
3399 IF ( pa_multi_currency.is_user_rate_type_allowed(
3400 P_from_currency => X_denom_currency_code,
3401 P_to_currency => X_projfunc_currency_code,
3402 P_conversion_date => nvl(X_projfunc_cost_rate_date,sysdate))='N')
3403 THEN
3404 X_status := 'PA_NO_PRJFUNC_CST_USER_RT_TYP';
3405 pa_cc_utils.reset_curr_function;
3406 RETURN;
3407
3408 ELSE --conversion rate type 'User' is allowed
3409
3410 IF ( X_projfunc_cost_exchange_rate IS NULL ) THEN
3411 X_status := 'PA_PRJFUNC_CST_USER_RATE_NULL';
3412 pa_cc_utils.reset_curr_function;
3413 RETURN;
3414 END IF;-- End X_project_exchange_rate IS NULL
3415
3416 END IF;--End is_user_rate_type_allowed ='N'
3417
3418 END IF;-- End G_projfunc_cost_rate_type = 'User'
3419 -- End PA-I Changes
3420
3421 /*---------------------------------------------------------------------------
3422 -- END MULTI CURRENCY VALIDATION COMMON TO UNCOSTED,COSTED, ACCOUNTED TXNS
3423 ----------------------------------------------------------------------------*/
3424 --
3425 -- Multi currency validation for uncosted txns
3426 --
3427 -- if the txn is uncosted then
3428 -- * if expenditure types with cost rate flag = 'Y'
3429 -- and labor related system linkages, the denom_currency_code should be same
3430 -- as acct_currency_code because Oracle Projects maintains cost rates
3431 -- and employee compensations in functional currency only
3432 -- * for ER with receipt currency different
3433 -- from denom currency, the receipt amount should be populated.
3434 -- * for ER check if receipt currency code is valid
3435
3436 IF ( nvl(G_trx_costed,'N') = 'N' ) THEN
3437
3438 /* ----------------------------------------------------------------------------
3439 -- Prior to PA-K:
3440 -- Labor cost rates are entered in functional currency only hence the
3441 -- Transaction and Functional currencies should be same for labor transactions.
3442 -- Similarly transactions that require cost rate should have same transaction
3443 -- and functional currencies.
3444 -- With and Beyond PA-K:
3445 -- Labor Costing Enhancements, If Etype Labor Flag = Y, the denom and acct
3446 curreny could differ.
3447 ------------------------------------------------------------------------------*/
3448
3449 IF nvl(G_etype_cost_rate_flag,'N') = 'Y'
3450 --OR nvl(G_etype_labor_flag,'N') = 'Y' )
3451 THEN
3452
3453 IF ( X_denom_currency_code <> G_accounting_currency_code ) THEN
3454
3455 X_status := 'PA_DENOM_ACCT_CURR_DIFF';
3456 pa_cc_utils.reset_curr_function;
3457 RETURN;
3458
3459 END IF;
3460
3461 END IF;
3462
3463 /*-----------------------------------------------------------------------------
3464 -- For Expense reports Users can enter the receipt currency information. The
3465 -- following section validates if the user entered receipt currency is a valid
3466 -- currency in Oracle Applications.
3467 ------------------------------------------------------------------------------*/
3468
3469 IF ( X_system_linkage = 'ER' ) THEN
3470
3471 IF ( X_receipt_currency_code IS NOT NULL ) THEN
3472
3473 IF PG_DEBUG = 'Y' THEN
3474 pa_debug.G_err_stage := 'Calling pa_multi_currency.validate_currency_code';
3475 log_message('log_message: ' || pa_debug.G_err_Stage);
3476 END IF;
3477 IF (pa_multi_currency.validate_currency_code(
3478 P_currency_code =>X_receipt_currency_code,
3479 P_ei_date => X_ei_date)= 'N')
3480 THEN
3481
3482 X_status :='PA_INVALID_RECEIPT_CURRENCY';
3483 pa_cc_utils.reset_curr_function;
3484 RETURN;
3485
3486 END IF; -- end invalid receipt currency validation
3487
3488 /*----------------------------------------------------------------------------
3489 -- If all the receipt currency is different from transaction currency, the user
3490 -- should provide the receipt amount which will be used later to calculate the
3491 -- receipt exchange rate. If the amount is not provided, the transaction will
3492 -- be rejected
3493 -----------------------------------------------------------------------------*/
3494
3495 IF ( nvl(X_receipt_currency_code,X_denom_currency_code) <> X_denom_currency_code ) THEN
3496
3497 IF ( nvl(X_receipt_currency_amount,0) = 0 ) THEN
3498
3499 X_status := 'PA_MISSING_RECEIPT_AMOUNT';
3500 pa_cc_utils.reset_curr_function;
3501 RETURN;
3502
3503 ELSE -- receipt amount is not zero
3504
3505 -- derive the receipt exchange rate from the ratio of quantity
3506 -- to receipt amount
3507
3508 IF PG_DEBUG = 'Y' THEN
3509 pa_debug.G_err_stage := 'Calling pa_currency.round_trans_currency_amt';
3510 log_message('log_message: ' || pa_debug.G_err_Stage);
3511 END IF;
3512 X_receipt_exchange_rate := (X_qty/
3513 pa_currency.round_trans_currency_amt1(
3514 X_receipt_currency_amount,
3515 nvl(X_receipt_currency_code,X_denom_currency_code)));
3516
3517
3518 END IF; -- end receipt currency info validation
3519
3520 END IF; -- end receipt curr code <> denom curr code
3521
3522 END IF; -- end receipt curr code not null
3523
3524 END IF; --end system linkage = ER
3525
3526 END IF; -- end G_trx_costed ='N'
3527
3528 /*-----------------------------------------------------------------------------
3529 -- END MULTI CURRENCY VALIDATION FOR UNCOSTED TXNS
3530 -----------------------------------------------------------------------------*/
3531
3532 /*-----------------------------------------------------------------------------
3533 -- START MULTI CURRENCY VALIDATION FOR COSTED/UNCOSTED UNACCOUNTED TXNS
3534 -----------------------------------------------------------------------------*/
3535 /* PA-I Changes
3536 For un-accounted transactions we need not call DefaultCurrAttributes.
3537 This is because the checks that are being performed here will be anyway
3538 performed during costing in pa_multi_currency_txn. To avoid redundant code
3539 we are not performing these checks in PA_TRX_IMPORT.
3540 */
3541
3542 /*-----------------------------------------------------------------------------
3543 -- END MULTI CURRENCY VALIDATION FOR COSTED/UNCOSTED UNACCOUNTED TXNS
3544 -----------------------------------------------------------------------------*/
3545
3546 --
3547 -- Multi currency validation for accounted transactions
3548 --
3549 -- If the transaction is accounted then
3550 -- * Currency information to convert from transaction to functional currency
3551 -- should be provided if transaction and functional currencies are different
3552 -- * The acct_raw_cost should be populated
3553 -- * validate if the user provided functional raw cost is with in the
3554 -- tolerance
3555 -- * if functional and transaction currencies are same the corresponding
3556 -- raw costs should be equal.
3557 -- * calculate project raw cost
3558 --
3559
3560 -- Start of code changes for the bug 12837454
3561 IF G_gl_accted_flag='N' and ( nvl(G_trx_costed,'N') = 'Y' ) and
3562 ( nvl(X_denom_currency_code,G_accounting_currency_code) = G_accounting_currency_code) THEN
3563
3564 IF (X_denom_raw_cost is null) THEN
3565 X_denom_raw_cost := X_acct_raw_cost;
3566 END IF;
3567
3568 IF (X_denom_burdened_cost is null) THEN
3569 X_denom_burdened_cost := X_acct_burdened_cost;
3570 END IF;
3571 END IF;
3572
3573 -- End of code changes for the bug 12837454
3574
3575 IF ( nvl(G_gl_accted_flag,'N') = 'Y' ) THEN
3576
3577 -- Functional raw cost should be provided for accounted transactions
3578 /*Bug# 2168903:Replaced the check of nvl(X_acct_raw_cost,0) = 0 with
3579 x_acct_raw_cost is NULL ,in the IF condition below */
3580
3581 IF ( X_acct_raw_cost IS NULL AND X_system_linkage <>'BTC' ) THEN
3582
3583 X_status := 'PA_NO_ACCT_COST';
3584 pa_cc_utils.reset_curr_function;
3585 RETURN;
3586
3587 END IF; -- acct_raw_cost is null
3588
3589 IF ( nvl(X_denom_currency_code,G_accounting_currency_code) <> G_accounting_currency_code) THEN
3590
3591 /* --------------------------------------------------------------------
3592 -- If Transaction and Functional currencies are not same the user should
3593 -- provide conversion attributes(i.e X_acct_rate_date,X_acct_rate_type,
3594 -- X_acct_exchange_rate).
3595 ---------------------------------------------------------------------*/
3596 IF ( X_acct_rate_date IS NULL ) THEN
3597
3598 X_status := 'PA_NO_ACCT_CURR_RATE_DATE';
3599 pa_cc_utils.reset_curr_function;
3600 RETURN;
3601
3602 END IF; -- End X_acct_rate_date is NULL
3603
3604 IF (G_acct_rate_type IS NULL) THEN
3605
3606 X_status := 'PA_NO_ACCT_CURR_RATE_TYPE';
3607 pa_cc_utils.reset_curr_function;
3608 RETURN;
3609
3610 END IF; -- End G_acct_rate_type IS NULL
3611
3612 /* Starts - Commented for bug# 5890661
3613 IF ( X_acct_exchange_rate IS NULL) THEN
3614
3615 X_status := 'PA_NO_ACCT_CURR_RATE';
3616 pa_cc_utils.reset_curr_function;
3617 RETURN;
3618
3619 END IF; -- End X_acct_exchange_rate IS NULL
3620 Ends - commented for bug# 5890661 */
3621
3622 /*-------------------------------------------------------------------
3623 -- Validate if the user provided Functional raw cost is with in the
3624 -- tolerance( tolerance is identified by acct_round_limit column).
3625 -- This is done by calculating the functional raw cost from the
3626 -- conversion attributes provided by the user, the calculated
3627 -- functional raw cost is then compared with the fucntional cost
3628 -- provided by the user. If acct_round_limit is NULL then it will be
3629 -- assumed that the acct_round_limit is Zero(0).
3630 --------------------------------------------------------------------*/
3631
3632 l_acct_rate_date := X_acct_rate_date;
3633 l_acct_rate_type := G_acct_rate_type;
3634 l_acct_exchange_rate := X_acct_exchange_rate;
3635 l_acct_raw_cost := X_acct_raw_cost;
3636
3637 IF PG_DEBUG = 'Y' THEN
3638 pa_debug.G_err_stage := 'Calling pa_multi_currency.convert_amount';
3639 log_message('log_message: ' || pa_debug.G_err_Stage);
3640 END IF;
3641
3642 pa_multi_currency.convert_amount(
3643 P_from_currency => X_denom_currency_code,
3644 P_to_currency => G_accounting_currency_code,
3645 P_conversion_date => l_acct_rate_date,
3646 P_conversion_type => l_acct_rate_type,
3647 P_amount => X_denom_raw_cost,
3648 P_user_validate_flag => l_validate_user_rate_type,
3649 P_handle_exception_flag => l_handel_exception_flag,
3650 P_converted_amount => l_converted_amount,
3651 P_denominator => l_denominator,
3652 P_numerator => l_numerator,
3653 P_rate => X_acct_exchange_rate,
3654 X_status => l_status);
3655
3656 IF ( l_status IS NOT NULL ) THEN
3657
3658 X_status := l_status;
3659 pa_cc_utils.reset_curr_function;
3660 RETURN;
3661
3662 END IF; -- End l_status IS NOT NULL
3663
3664
3665 -- Check if the calculated functional raw cost is with in the
3666 -- tolerance
3667
3668 -- Bug 1603841
3669 -- If transaction_source is any of the following then
3670 -- do not check for the rounding limit.
3671
3672 IF X_trx_src not in ('AP INVOICE' ,'AP EXPENSE','AP NRTAX', 'AP DISCOUNTS', 'AP ERV',
3673 --PA-J Receipt Accrual changes
3674 'AP VARIANCE', 'PO RECEIPT', 'PO RECEIPT NRTAX',
3675 'Inventory','Inventory Misc','Work In Process', /*Bug4202839*/
3676 'CSE_INV_ISSUE','CSE_INV_ISSUE_DEPR', /*Bug4202839*/
3677 'PJM_CSTBP_INV_NO_ACCOUNTS','PJM_CSTBP_WIP_NO_ACCOUNTS', /*Bug4202839*/
3678 'PJM_CSTBP_WIP_ACCOUNTS','PJM_CSTBP_INV_ACCOUNTS',
3679 'PJM_CSTBP_ST_ACCOUNTS','PJM_NON_CSTBP_ST_ACCOUNTS','PJM_CSTBP_ST_NO_ACCOUNTS',/*Bug4202839*/
3680 'PO RECEIPT NRTAX PRICE ADJ', 'PO RECEIPT PRICE ADJ',
3681 'INTERPROJECT_AP_INVOICES','INTERCOMPANY_AP_INVOICES') THEN /* Added the 2 transaction sources for bug 3461993 */
3682 -- pricing changes
3683
3684 IF abs(l_converted_amount - X_acct_raw_cost) >
3685 abs(nvl(X_acct_exchange_rounding_limit,0)) THEN
3686
3687 X_status := 'PA_EXCEED_ROUND_LIMIT';
3688 pa_cc_utils.reset_curr_function;
3689 RETURN;
3690
3691 END IF; -- end functional amount tolerance check
3692 ELSE
3693 -- Bug 4038568
3694 -- If source is AP/PO, copy the exchange rate from the source system instead of rederiving from GL
3695
3696 X_acct_exchange_rate := nvl(l_acct_exchange_rate,X_acct_exchange_rate);
3697
3698 END IF;
3699
3700 ELSE -- denom currency_ = accounting currency
3701
3702 --
3703 -- If functional and transaction currencies are same the the
3704 -- corresponding amounts should also be equal
3705 --
3706 IF PG_DEBUG = 'Y' THEN
3707 pa_debug.G_err_stage := 'Calling pa_multi_currency.round_trans_currency_amt';
3708 log_message('log_message: ' || pa_debug.G_err_Stage);
3709 END IF;
3710
3711
3712 /* Start 10357604 */
3713 --IF (nvl(G_gl_accted_flag,'N') = 'Y') THEN --Commented out GL accounted check for bug 12687356
3714
3715 IF (X_denom_raw_cost is null) THEN
3716 X_denom_raw_cost := X_acct_raw_cost;
3717 END IF;
3718
3719 IF (X_denom_burdened_cost is null) THEN
3720 X_denom_burdened_cost := X_acct_burdened_cost;
3721 END IF;
3722
3723 --END IF; --Commented out GL accounted check for bug 12687356
3724
3725 /* End 10357604 */
3726
3727 /* Added the call to round off X_acct_raw_cost for bug 2871273 */
3728 IF ( pa_currency.round_trans_currency_amt1(X_acct_raw_cost, G_accounting_currency_code) <>
3729 pa_currency.round_trans_currency_amt1(X_denom_raw_cost,
3730 X_denom_currency_code )) THEN
3731
3732 X_status := 'PA_INVALID_ACCT_DENOM_COST';
3733 pa_cc_utils.reset_curr_function;
3734 RETURN;
3735
3736 END IF; -- end acct raw cost <> denom raw cost
3737
3738 END IF; -- denom <> acct curr
3739
3740 --
3741 -- call get_currency_amounts to derive project currency amount
3742 -- for accounted transactions. For accounted transactions
3743 -- the EI's are created with cost_distributed_flag='Y', so
3744 -- the the costing program cannot pick up these records
3745 -- to calculate the project currency costs. Here we are passing
3746 -- the G_gl_accted_flag to pa_multi_currency_txn package, the
3747 -- package will calculate the project cost if the gl_accted_flag
3748 -- is 'Y'.
3749 --
3750 -- initilize the local variables before passing them to
3751 -- get_currency_amounts
3752
3753 l_acct_rate_date := X_acct_rate_date;
3754 l_acct_rate_type := G_acct_rate_type;
3755 l_acct_exchange_rate := X_acct_exchange_rate;
3756 l_acct_raw_cost := X_acct_raw_cost;
3757
3758 BEGIN
3759
3760 IF PG_DEBUG = 'Y' THEN
3761 pa_debug.G_err_stage := 'Calling pa_multi_currency_txn.get_currency_amounts';
3762 log_message('log_message: ' || pa_debug.G_err_Stage);
3763 END IF;
3764 pa_multi_currency_txn.get_currency_amounts(
3765 P_task_id => G_task_id,
3766 P_ei_date => X_ei_date,
3767 P_denom_raw_cost => X_denom_raw_cost,
3768 P_denom_curr_code => X_denom_currency_code,
3769 P_acct_curr_code => G_accounting_currency_code,
3770 P_accounted_flag => G_gl_accted_flag,
3771 P_acct_rate_date => l_acct_rate_date,
3772 P_acct_rate_type => l_acct_rate_type,
3773 P_acct_exch_rate => l_acct_exchange_rate,
3774 P_acct_raw_cost => l_acct_raw_cost,
3775 P_project_curr_code => X_project_currency_code,
3776 P_project_rate_type => G_project_rate_type,
3777 P_project_rate_date => X_project_rate_date,
3778 P_project_exch_rate => X_project_exchange_rate,
3779 --P_project_raw_cost => X_project_raw_cost,
3780 --PA-I Changes : Proj Func raw cost is calculated in P_raw_cost
3781 --P_raw_cost => X_project_raw_cost,
3782 P_projfunc_raw_cost => X_project_raw_cost,
3783 P_status => l_status,
3784 P_stage => l_stage,
3785 --PA-I Changes : Added Proj Func Attributes and Project raw cost
3786 P_projfunc_curr_code => X_projfunc_currency_code,
3787 P_projfunc_cost_rate_type => G_projfunc_cost_rate_type,
3788 P_projfunc_cost_rate_date => X_projfunc_cost_rate_date,
3789 P_projfunc_cost_exch_rate => X_projfunc_cost_exchange_rate,
3790 P_project_raw_cost => X_actual_project_raw_cost);
3791
3792 X_actual_project_raw_cost := pa_currency.round_trans_currency_amt1(X_actual_project_raw_cost,X_project_currency_code); -- Bug 8621083 / 8595274
3793
3794 /***************PA-I changes************************
3795 Commenting the exception section as the exceptions are already handled in
3796 the pa_multi_currency_txn pkg.
3797 ****************************************************/
3798
3799 END; -- end calculate project raw cost
3800
3801
3802 IF ( l_status IS NOT NULL ) THEN
3803 X_status := l_status;
3804 pa_cc_utils.reset_curr_function;
3805 RETURN;
3806
3807 END IF; -- end l_status IS NOT NULL
3808
3809 END IF; -- end gl_accounted_flag =Y
3810
3811
3812 -- ===========================================================================
3813 -- Validation specific to STRAIGHT_TIME transactions
3814 -- * Transaction item date must be within the expenditure week ending
3815 -- on the ending date given
3816 -- * Employee must be specified
3817 --
3818 -- Bug 1000221, added OT to the in clause
3819
3820 IF ( X_system_linkage in ( 'ST', 'OT' )) THEN
3821
3822 IF PG_DEBUG = 'Y' THEN
3823 pa_debug.G_err_stage := 'Calling pa_utils.DateInExpWeek';
3824 log_message('log_message: ' || pa_debug.G_err_Stage);
3825 END IF;
3826
3827 IF ( NOT pa_utils.DateInExpWeek( X_ei_date , X_end_date ) ) THEN
3828 X_status := 'ITEM_NOT_IN_WEEK';
3829 pa_cc_utils.reset_curr_function;
3830 RETURN;
3831 ELSIF ( X_enum IS NULL ) THEN
3832 X_status := 'EMP_MAND_FOR_TIME';
3833 pa_cc_utils.reset_curr_function;
3834 RETURN;
3835 END IF;
3836
3837 -- ===========================================================================
3838 -- Validation specific to EXPENSE_REPORTS transactions
3839 -- * Employee must be specified
3840 --
3841
3842 ELSIF ( X_system_linkage = 'ER' ) THEN
3843 IF ( X_enum IS NULL and X_trx_src NOT IN ('AP EXPENSE', 'AP NRTAX','AP VARIANCE','AP ERV') ) THEN
3844 /* Bug2780387. Added 'AP NRTAX' to the NOT IN list */
3845 /* Bug 10405702 . Added 'AP VARIANCE','AP ERV' to the NOT IN list */
3846 X_status := 'EMP_MAND_FOR_ER';
3847 pa_cc_utils.reset_curr_function;
3848 RETURN;
3849 END IF;
3850
3851 -- ===========================================================================
3852 -- Validation specific to USAGES items
3853 -- * Employee OR organization must be given
3854 -- * Non-labor resource and non-labor resource owning organization must
3855 -- be given
3856 -- * Non-labor resource and non-labor resource owning organization are
3857 -- both valid
3858 -- * Non-labor resource is active as of the transaction item date
3859 -- * Non-labor resource is owned by the given non-labor resource org as of
3860 -- the transaction item date
3861 -- * Expenditure type of the non-labor resource matches that of the
3862 -- transaction
3863 --
3864
3865 ELSIF ( X_system_linkage = 'USG' ) THEN
3866 IF ( X_enum IS NULL AND X_oname IS NULL ) THEN
3867 X_status := 'EMP_OR_ORG_MAND_FOR_USAGES';
3868 pa_cc_utils.reset_curr_function;
3869 RETURN;
3870 ELSIF ( X_nlr IS NULL ) THEN
3871 X_status := 'NL_RSRC_MAND_FOR_USAGES';
3872 pa_cc_utils.reset_curr_function;
3873 RETURN;
3874 ELSIF ( X_nlro_name IS NULL ) THEN
3875 X_status := 'NL_RSRC_ORG_MAND_FOR_USAGES';
3876 pa_cc_utils.reset_curr_function;
3877 RETURN;
3878 END IF;
3879
3880 --PA-K Changes: Use the ID if provided for predefined transaction sources.
3881 /** Bug#3026218 Use ID, if provided for any type of transaction source **/
3882 IF P_NLR_Org_Id is not null Then
3883 G_nlro_id := P_NLR_Org_Id;
3884 ELSE
3885 IF PG_DEBUG = 'Y' THEN
3886 pa_debug.G_err_stage := 'Calling pa_utils.GetOrgnId';
3887 log_message('log_message: ' || pa_debug.G_err_Stage);
3888 END IF;
3889 --Start of changes for Bug 3010848
3890
3891 --G_nlro_id := pa_utils.GetOrgId( X_nlro_name );
3892 pa_utils.GetOrgnId(X_org_name => X_nlro_name,
3893 X_bg_id => G_Business_Group_Id,
3894 X_Orgn_Id => G_nlro_id,
3895 X_Return_Status => L_Org_RetSts);
3896
3897 If L_Org_RetSts is Not Null Then
3898 X_status := L_Org_RetSts;
3899 RETURN;
3900 End If;
3901 --End of changes for Bug 3010848
3902
3903 END IF;
3904
3905 IF ( G_nlro_id IS NULL ) THEN
3906 X_status := 'INVALID_NL_RSRC_ORG';
3907 pa_cc_utils.reset_curr_function;
3908 RETURN;
3909 END IF;
3910
3911 IF PG_DEBUG = 'Y' THEN
3912 pa_debug.G_err_stage := 'Calling GetNlrInfo(X_nlr,G_nlro_id) ';
3913 log_message('log_message: ' || pa_debug.G_err_Stage);
3914 END IF;
3915 GetNlrInfo( X_nlr, G_nlro_id );
3916
3917 IF ( G_nlr_etype IS NULL ) THEN
3918 X_status := 'INVALID_NL_RSRC';
3919 pa_cc_utils.reset_curr_function;
3920 RETURN;
3921 ELSIF ( X_ei_date NOT BETWEEN G_nlr_start
3922 AND nvl( G_nlr_end, X_ei_date ) ) THEN
3923 X_status := 'NL_RSRC_INACTIVE';
3924 pa_cc_utils.reset_curr_function;
3925 RETURN;
3926 ELSIF ( G_nlro_start IS NULL ) THEN
3927 X_status := 'ORG_NOT_OWNER_OF_NL_RSRC';
3928 pa_cc_utils.reset_curr_function;
3929 RETURN;
3930 ELSIF ( X_ei_date NOT BETWEEN G_nlro_start
3931 AND nvl( G_nlro_end, X_ei_date ) ) THEN
3932 X_status := 'ORG_NOT_OWNER_OF_NL_RSRC';
3933 pa_cc_utils.reset_curr_function;
3934 RETURN;
3935 ELSIF ( G_nlr_etype <> X_etype ) THEN
3936 X_status := 'NL_EXP_TYPE_DIFF';
3937 pa_cc_utils.reset_curr_function;
3938 RETURN;
3939 END IF;
3940 END IF;
3941
3942 -- ===========================================================================
3943 -- Validation specific to BURDEN TRANSACTIONS
3944 -- If transactionsource.cost_burden_flag = 'N' then don't allow burden trans.
3945 -- If ProjectType.burden_cost_flag = 'N' then don't allow burden trans.
3946 -- If both qty and raw cost are non zero then don't allow burden trans.
3947 -- If burdened cost is zero then don't allow burden trans.
3948
3949 IF X_system_linkage = 'BTC' THEN
3950
3951 /* Bug# 2063667 - If the transaction source is not Burdened but
3952 system linkage is BTC , then reject the transaction */
3953 /* Bug 2844973 Added g_trx_source <> 'ALLOCATIONS' condition */
3954
3955 IF nvl(G_burdened_flag,'N') = 'N' and g_trx_source <> 'ALLOCATIONS' THEN
3956 X_status := 'TRXSRC_NOTALLOW_BURDEN' ;
3957 pa_cc_utils.reset_curr_function;
3958 RETURN ;
3959 END IF ;
3960
3961 -- IF G_proj_bcost_flag = 'N' THEN
3962 -- X_status := 'PROJ_NOTALLOW_BURDEN' ;
3963 -- RETURN ;
3964 -- END IF ;
3965 -- Multi-Currency changes. Changed raw_cost to denom_raw_cost
3966 --
3967 IF nvl(X_qty,0) <> 0 OR nvl(X_denom_raw_cost,0) <> 0 THEN
3968 X_status := 'INVALID_BURDEN_TRANS' ;
3969 pa_cc_utils.reset_curr_function;
3970 RETURN ;
3971 END IF ;
3972
3973 --
3974 -- Multi-Currency Changes. Changes burdened_cost to denom_burdened-cost
3975 --
3976 IF X_denom_burdened_cost IS NULL THEN
3977 X_status := 'INVALID_BURDEN_AMOUNT' ;
3978 pa_cc_utils.reset_curr_function;
3979 RETURN ;
3980 END IF ;
3981
3982 ELSE -- X_system_linkage <> 'BTC'
3983
3984 IF ( G_trx_costed = 'Y' AND X_denom_raw_cost is NULL ) THEN
3985 X_status := 'NO_RAW_COST';
3986 pa_cc_utils.reset_curr_function;
3987 RETURN;
3988 END IF ;
3989
3990 -- Get compiled multiplier and compile set id for transaction sources
3991 -- that have allow_burden_flag set to N and gl_accounted_flag set to Y
3992 -- Bug: 979112: Get compiled multiplier only if the project type is
3993 -- defined with a burden schedule
3994
3995 -- All the below logic is commented for 2798971 has been
3996 -- handled while calculating the Burdened cost.
3997 -- After this change Burden Cost is calculated by calling
3998 -- pa_cost_plus1.get_indirect_cost_import procedure.
3999 -- instead of compiled multiplier since this was leading to
4000 -- a penny difference in Burden cost and Accrued revenue.
4001 /* --Commented code for Bug 2798971
4002 IF ( nvl(G_burdened_flag,'N') = 'N' ) AND
4003 ( nvl( G_gl_accted_flag,'N' ) = 'Y') AND
4004 ( nvl(G_proj_bcost_flag, 'N') = 'Y') THEN
4005
4006 IF PG_DEBUG = 'Y' THEN
4007 pa_debug.G_err_stage := 'Calling pa_cost_plus1.get_compile_set_info';
4008 log_message('log_message: ' || pa_debug.G_err_Stage);
4009 END IF;
4010 pa_cost_plus1.get_compile_set_info(
4011 task_id => G_task_id,
4012 p_txn_interface_id => X_txn_interface_id, -- added for bug 2563364
4013 effective_date => X_ei_date,
4014 expenditure_type => X_etype,
4015 organization_id => nvl(G_override_to_org_id, G_org_id),
4016 schedule_type => 'C',
4017 Compiled_multiplier => G_compiled_multiplier,
4018 compiled_set_id => G_burden_compile_set_id,
4019 status => l_status_num,
4020 stage => l_stage,
4021 x_cp_structure => x_cp_structure -- Added for Bug 5743708,
4022 x_cost_base => x_cost_base-- Added for Bug 5743708 );
4023
4024
4025 -- Bug: 925488 and 956683: get_compile_set_info calls get_cost_base. Get_cost_base
4026 -- returns status = 100 when a expenditure type is not defined with a
4027 -- cost base. We should not return error when this happens. Instead,
4028 -- we'll set compiled multiplier to 0 so when we calculate burdened cost,
4029 -- burdened_cost = raw_cost * (1 + compiled_multipler), burdened_cost
4030 -- will equal to raw_cost
4031 IF ( l_status_num <> 0 ) THEN
4032 IF (l_status_num = 100) THEN
4033 G_compiled_multiplier := 0;
4034 G_burden_compile_set_id := to_number(NULL);
4035 ELSE
4036 X_status := 'PA_ERR_IN_COST_PLUS';
4037 pa_cc_utils.reset_curr_function;
4038 RETURN;
4039 END IF;
4040 END IF;
4041
4042 -- code added for the Bug #1428216 starts here
4043 IF (NVL(G_burden_amt_display_method,'S') = 'D' ) THEN
4044 G_compiled_multiplier := 0;
4045 END IF;
4046 -- code added for the Bug #1428216 endss here
4047
4048 -- Bug: 979112: If the project type is not defined with burden schedule,
4049 -- then set compiled_multiplier equal to 0 because the
4050 -- formula is burden_cost = raw_cost * (1 + multipler)
4051 ELSE
4052 G_compiled_multiplier := 0;
4053 G_burden_compile_set_id := to_number(NULL);
4054
4055 END IF; -- End G_burdened_flag = N and G_gl_accted_flag =Y
4056
4057 --Commented code for Bug 2798971 ends */
4058
4059 -- If the transaction is burdened and does not have a burdened amount
4060 -- then reject the transaction
4061
4062 IF nvl(G_burdened_flag,'N') = 'Y' AND
4063 /* nvl( X_denom_burdened_cost ,0 ) = 0 THEN Commented for bug3144614 */
4064 X_denom_burdened_cost is NULL THEN /* Added for bug3144614 */
4065 X_status := 'INVALID_BURDEN_AMOUNT' ;
4066 pa_cc_utils.reset_curr_function;
4067 RETURN ;
4068 END IF; -- End
4069
4070 /* Bug# 2063667 - If the transaction source is not Burdened and
4071 not externally gl accounted but burden amount is not null,
4072 then reject the transaction */
4073
4074 IF (nvl(G_burdened_flag,'N') = 'N' AND
4075 nvl(G_gl_accted_flag,'N') = 'N' AND
4076 X_denom_burdened_cost is NOT NULL) THEN
4077 X_status := 'TRXSRC_NOTALLOW_BURDEN';
4078 pa_cc_utils.reset_curr_function;
4079 RETURN ;
4080 END IF ;
4081
4082 /* Bug# 2063667 - If the project type is not Burdened but burden
4083 amount is not null, then reject the transaction */
4084
4085 /*Bug# 2448543 -If the project type is not burdened (which implies
4086 the defaulted burden amount should be equal to raw amount )but the
4087 burden amount is not equal to raw amount then reject the txn.*/
4088
4089 /* Bug#2529120 - Added Check for Source Accounted Over fix done for 2448543
4090 For a Non Burdend Project, reject the transaction for the following conditions
4091 A. If Source is GL Unaccounted and denom burdened cost is not null
4092 B. If Source is GL accounted and denom burdened cost <> denom raw cost
4093 */
4094 /* Bug#2529120 -- Comment Code - Start
4095 IF (nvl(G_proj_bcost_flag,'N') = 'N' AND
4096 X_denom_burdened_cost <> X_denom_raw_cost) THEN * 2448543*
4097 * X_denom_burdened_cost is NOT NULL) THEN -Commented for Bug# 2448543*
4098 Comment Code -- End -- Bug#2529120 */
4099
4100 /* commented for Bug 3593432
4101 IF nvl(G_proj_bcost_flag,'N') = 'N' THEN
4102 IF ((nvl(G_gl_accted_flag,'N') = 'Y' AND X_denom_burdened_cost <> X_denom_raw_cost)
4103 OR (nvl(G_gl_accted_flag,'N') = 'N' AND X_denom_burdened_cost is NOT NULL)) THEN
4104 X_status := 'PROJ_NOTALLOW_BURDEN' ;
4105 pa_cc_utils.reset_curr_function;
4106 RETURN ;
4107 END IF; * Accted Flag IF *
4108 END IF ;
4109 commented for Bug 3593432 End */
4110
4111 /* Added for Bug 3593432 */
4112 IF nvl(G_proj_bcost_flag,'N') = 'N' AND X_denom_burdened_cost <> X_denom_raw_cost THEN
4113 X_status := 'PROJ_NOTALLOW_BURDEN' ;
4114 pa_cc_utils.reset_curr_function;
4115 RETURN ;
4116 END IF ;
4117 /* Added for Bug 3593432 End */
4118
4119
4120 END IF; -- End system_linkage <> BTC
4121
4122 -- ============================================================================
4123 -- --------------------------------------------------------------------------
4124 -- Multi-Currency changes. calculating burden cost for accounted
4125 -- transactions.
4126 --
4127 -- Example: denom raw cost acct_raw_cost proj_raw_cost
4128 -- ---------------- ------------------ -------------
4129 -- 100 USD 120 BPL 120 BPL(derived)
4130 -- if acct_burdened_cost is null and denom_burdened_cost is 120 USD
4131 -- the acct_burdened_cost is derived by multiplying acct_raw_cost with the
4132 -- ratio of denom_burdened_cost and denom_raw_cost( for non BTC txns )
4133 -- for BTC txns since the denom_raw_cost will be zero(0), the func and proj
4134 -- Bcost are derrived by directly converting the denom_burden_cost using the
4135 -- project and functional currency conversion attributes.
4136 --
4137 -- For non BTC txns
4138 -- i.e acct_burdened_cost = (denom_burdened_cost/denom_raw_cost) * acct_raw_cost
4139 -- proj_burdened_cost = (denom_burdened_cost/denom_raw_cost) * proj_raw_cost
4140 --
4141 -- For BTC txns ( transaction raw cost = 0 )
4142 -- acct_burdened_cost = (transaction to functional curr conversion rate) *
4143 -- transaction burdened cost
4144 -- project_burdened-cost = (transaction to project curr conversion rate)*
4145 -- transaction burdened cost
4146 --
4147 -- if acct_burdened_cost is not null then
4148 -- derive proj_burdened_cost by multiplying project_raw_cost with the ratio
4149 -- of denom_burdened_cost and denom_raw_cost.
4150 --
4151 -- If allow_burden_flag is 'N' then the burden amounts
4152 -- are calculated by orcale projects(only for non BTC txns)
4153
4154 -----------------------------------------------------------------------------
4155
4156 IF ( nvl(G_gl_accted_flag,'N') = 'Y') THEN
4157 IF ( nvl(G_burdened_flag,'N') = 'N' ) THEN
4158
4159 -- calculate the burden amount using the compiled multiplier derived
4160 -- from PA burden schedule for transactions accounted externally, txns
4161 -- that are not accounted externally, Oracle Projects costing programs
4162 -- will calculate the burdened costs.
4163 --
4164
4165 /* --Commented code for Bug 2798971
4166 IF PG_DEBUG = 'Y' THEN
4167 pa_debug.G_err_stage := 'Calling pa_currency.round_trans_currency_amt';
4168 log_message('log_message: ' || pa_debug.G_err_Stage);
4169 END IF;
4170 X_denom_burdened_cost := pa_currency.round_trans_currency_amt1(
4171 X_denom_raw_cost * (1 + G_compiled_multiplier ),X_denom_currency_code);
4172
4173 X_acct_burdened_cost := pa_currency.round_currency_amt1(
4174 X_acct_raw_cost * (1 + G_compiled_multiplier));
4175
4176 X_project_burdened_cost := pa_currency.round_trans_currency_amt1(
4177 X_project_raw_cost * (1 + g_compiled_multiplier),
4178 X_projfunc_currency_code);
4179
4180 X_actual_project_burdened_cost := pa_currency.round_trans_currency_amt1(
4181 X_actual_project_raw_cost * (1 + g_compiled_multiplier),
4182 X_project_currency_code);
4183 --Commented code for Bug 2798971 ends*/
4184
4185 /* Added code for 2798971 */
4186 IF (nvl(G_proj_bcost_flag, 'N') = 'Y') THEN
4187 IF PG_DEBUG = 'Y' THEN
4188 pa_debug.G_err_stage := 'Calling pa_cost_plus1.get_indirect_cost_import';
4189 log_message('log_message: ' || pa_debug.G_err_Stage);
4190 END IF;
4191 pa_cost_plus1.get_indirect_cost_import (
4192 task_id => G_task_id,
4193 p_txn_interface_id => X_txn_interface_id, -- added for bug 3246794
4194 effective_date => X_ei_date,
4195 expenditure_type => X_etype,
4196 organization_id => nvl(G_override_to_org_id, G_org_id),
4197 schedule_type => 'C',
4198 direct_cost => X_actual_project_raw_cost,
4199 direct_cost_denom => X_denom_raw_cost,
4200 direct_cost_acct => X_acct_raw_cost,
4201 direct_cost_project => X_project_raw_cost,
4202 indirect_cost_sum => X_actual_project_burdened_cost,
4203 indirect_cost_denom_sum => X_denom_burdened_cost,
4204 indirect_cost_acct_sum => X_acct_burdened_cost,
4205 indirect_cost_project_sum => X_project_burdened_cost,
4206 l_projfunc_currency_code => X_projfunc_currency_code,
4207 l_project_currency_code => X_project_currency_code,
4208 l_acct_currency_code => null,
4209 l_denom_currency_code => X_denom_currency_code,
4210 Compiled_set_id => G_burden_compile_set_id,
4211 status => l_status_num,
4212 stage => l_stage);
4213 -- Bug: 925488 and 956683: get_indirect_cost_import calls get_cost_base. Get_cost_base
4214 -- returns status = 100 when a expenditure type is not defined with a
4215 -- cost base. We should not return error when this happens. Instead,
4216 -- burdened_cost = raw_cost , burdened_cost will equal to raw_cost
4217
4218 /* Error checking modified and added below. The checks are based on the
4219 different values of status and stage returned by get_indirect_cost_import
4220 bug2837165 starts */
4221
4222 IF ( l_status_num <> 0 ) THEN
4223 IF (l_status_num = 100 AND l_stage = 300) THEN
4224 G_compiled_multiplier := 0;
4225 G_burden_compile_set_id := to_number(NULL);
4226 elsif (l_status_num = 100) then
4227 if( l_stage = 100)then
4228 X_status := 'NO_IND_RATE_SCH_REVISION';
4229 pa_cc_utils.reset_curr_function;
4230 RETURN;
4231 elsif (l_stage = 200) then
4232 X_status := 'NO_COST_PLUS_STRUCTURE';
4233 pa_cc_utils.reset_curr_function;
4234 RETURN;
4235 elsif (l_stage = 400) then
4236 X_status := 'NO_ACTIVE_COMPILED_SET';
4237 pa_cc_utils.reset_curr_function;
4238 RETURN;
4239 end if;
4240 ELSE
4241 X_status := 'PA_ERR_IN_COST_PLUS';
4242 pa_cc_utils.reset_curr_function;
4243 RETURN;
4244 END IF;
4245 END IF;
4246 /* bug2837165 ends */
4247 /* code added for the Bug #1428216 starts here*/
4248 /* If project is burdened on a different EI we are stamping the compile_set_id
4249 but burden cost will be equal to raw costs. */
4250 IF (NVL(G_burden_amt_display_method,'S') = 'D' ) THEN
4251 G_compiled_multiplier := 0;
4252 X_denom_burdened_cost := X_denom_raw_cost;
4253 X_acct_burdened_cost := X_acct_raw_cost;
4254 X_project_burdened_cost := X_project_raw_cost;
4255 X_actual_project_burdened_cost := X_actual_project_raw_cost;
4256 ELSE
4257 /* code added for the Bug #1428216 ends here*/
4258 /* Code modified for 2798971. Added an ELSE condition */
4259 X_denom_burdened_cost := X_denom_burdened_cost + X_denom_raw_cost;
4260 X_acct_burdened_cost := X_acct_burdened_cost + X_acct_raw_cost;
4261 X_project_burdened_cost := X_project_burdened_cost + X_project_raw_cost;
4262 X_actual_project_burdened_cost := X_actual_project_burdened_cost + X_actual_project_raw_cost;
4263 END IF; -- IF (NVL(G_burden_amt_display_method,'S') = 'D' )
4264 ELSE
4265 G_compiled_multiplier := 0;
4266 G_burden_compile_set_id := to_number(NULL);
4267 X_denom_burdened_cost := X_denom_raw_cost;
4268 X_acct_burdened_cost := X_acct_raw_cost;
4269 X_project_burdened_cost := X_project_raw_cost;
4270 X_actual_project_burdened_cost := X_actual_project_raw_cost;
4271 END IF; -- IF (nvl(G_proj_bcost_flag, 'N') = 'Y') THEN
4272 /* Added code for 2798971 ends */
4273
4274 ELSIF ( nvl(G_burdened_flag,'N') = 'Y' ) THEN
4275 IF ( nvl(X_denom_raw_cost,0) = 0) THEN
4276
4277 -- if the transaction raw cost is zero then calculate the
4278 -- functional and project BCost by using the conversion attributes.
4279
4280 IF ( nvl(X_acct_burdened_cost,0) = 0 ) THEN
4281
4282 -- initilize l_status
4283 l_status := NULL;
4284
4285 IF PG_DEBUG = 'Y' THEN
4286 pa_debug.G_err_stage := 'Calling pa_multi_currency.convert_amount for functional currency';
4287 log_message('log_message: ' || pa_debug.G_err_Stage);
4288 END IF;
4289 pa_multi_currency.convert_amount(
4290 P_from_currency => X_denom_currency_code,
4291 P_to_currency => G_accounting_currency_code,
4292 P_conversion_date => X_acct_rate_date,
4293 P_conversion_type => G_acct_rate_type,
4294 P_amount => X_denom_burdened_cost,
4295 P_user_validate_flag => l_validate_user_rate_type,
4296 P_handle_exception_flag => l_handel_exception_flag,
4297 P_converted_amount => X_acct_burdened_cost,
4298 P_denominator => l_denominator,
4299 P_numerator => l_numerator,
4300 P_rate => X_acct_exchange_rate,
4301 X_status => l_status);
4302
4303 IF ( l_status IS NOT NULL ) THEN
4304 X_status := l_status;
4305 pa_cc_utils.reset_curr_function;
4306 RETURN;
4307 END IF; -- End l_status IS NOT NULL
4308
4309 END IF;-- End X_acct_burdened_cost = 0
4310
4311 -- calculate the project Bcost using the project conversion attributes
4312 -- before calling convert_amount initilize l_status
4313
4314 l_status := NULL;
4315
4316 IF PG_DEBUG = 'Y' THEN
4317 pa_debug.G_err_stage := 'Calling pa_multi_currency.convert_amount for project currency';
4318 log_message('log_message: ' || pa_debug.G_err_Stage);
4319 END IF;
4320 pa_multi_currency.convert_amount(
4321 P_from_currency => X_denom_currency_code,
4322 P_to_currency => X_project_currency_code,
4323 P_conversion_date => X_project_rate_date,
4324 P_conversion_type => G_project_rate_type,
4325 P_amount => X_denom_burdened_cost,
4326 P_user_validate_flag => l_validate_user_rate_type,
4327 P_handle_exception_flag => l_handel_exception_flag,
4328 --P_converted_amount => X_project_burdened_cost,
4329 --PA-I Changes : Project costs are calculated in x_actual_project.._cost
4330 P_converted_amount => X_actual_project_burdened_cost,
4331 P_denominator => l_denominator,
4332 P_numerator => l_numerator,
4333 P_rate => X_project_exchange_rate,
4334 X_status => l_status);
4335
4336 IF ( l_status IS NOT NULL ) THEN
4337 X_status := l_status;
4338 pa_cc_utils.reset_curr_function;
4339 RETURN;
4340 END IF; -- End l_status IS NOT NULL
4341
4342 -- PA-I Changes : Added below for Project Functional Burdened cost calculation
4343 -- calculate the project functional Bcost using the project functional conversion attributes
4344 -- before calling convert_amount initilize l_status
4345
4346 l_status := NULL;
4347
4348 IF PG_DEBUG = 'Y' THEN
4349 pa_debug.G_err_stage := 'Calling pa_multi_currency.convert_amount for project functional currency';
4350 log_message('log_message: ' || pa_debug.G_err_Stage);
4351 END IF;
4352 pa_multi_currency.convert_amount(
4353 P_from_currency => X_denom_currency_code,
4354 P_to_currency => X_projfunc_currency_code,
4355 P_conversion_date => X_projfunc_cost_rate_date,
4356 P_conversion_type => G_projfunc_cost_rate_type,
4357 P_amount => X_denom_burdened_cost,
4358 P_user_validate_flag => l_validate_user_rate_type,
4359 P_handle_exception_flag => l_handel_exception_flag,
4360 P_converted_amount => X_project_burdened_cost,
4361 P_denominator => l_denominator,
4362 P_numerator => l_numerator,
4363 P_rate => X_projfunc_cost_exchange_rate,
4364 X_status => l_status);
4365
4366 IF ( l_status IS NOT NULL ) THEN
4367 X_status := l_status;
4368 pa_cc_utils.reset_curr_function;
4369 RETURN;
4370 END IF; -- End l_status IS NOT NULL
4371
4372 ELSE -- i.e denom_raw_cost <> 0
4373
4374 -- Multi-Currency changes.
4375 -- If the Trx Source indicates that the transaction is burdened then
4376 -- for accounted transactions, if the acct_burdened_cost is null or 0 then
4377 -- acct_burdened_cost is derived by multiplying the acct_raw_cost with
4378 -- denom_cost_ratio.
4379
4380 IF PG_DEBUG = 'Y' THEN
4381 pa_debug.G_err_stage := 'Calling pa_currency.round_trans_currency_amt';
4382 log_message('log_message: ' || pa_debug.G_err_Stage);
4383 END IF;
4384
4385 X_project_burdened_cost := pa_currency.round_trans_currency_amt1(
4386 X_project_raw_cost *
4387 (X_denom_burdened_cost/X_denom_raw_cost),
4388 X_projfunc_currency_code);
4389
4390 X_actual_project_burdened_cost := pa_currency.round_trans_currency_amt1(
4391 X_actual_project_raw_cost *
4392 (X_denom_burdened_cost/X_denom_raw_cost),
4393 X_project_currency_code);
4394
4395 IF ( nvl( X_acct_burdened_cost ,0 ) = 0 ) THEN
4396 X_acct_burdened_cost := pa_currency.round_currency_amt1(
4397 X_acct_raw_cost * (X_denom_burdened_cost/X_denom_raw_cost));
4398 END IF; -- end acct_burdened_cost = 0
4399 END IF; -- End denom_raw_cost = 0
4400 END IF; -- end G_burdened_flag = N
4401 END IF; -- end G_gl_accted_flag = Y
4402
4403 -- ===========================================================================
4404 -- If gl_accounted_flag = 'Y' then for each transaction we should have
4405 -- Valid dr_ccid, cr_ccid , gl_date.
4406 IF G_gl_accted_flag = 'Y' THEN
4407
4408 IF (nvl(X_module, 'EXTERNAL') <> 'PAAPIMP') THEN
4409 --PA-J Receipt Accrual Changes : Added AP VARIANCE and PO RECEIPT transaction sources
4410 --PA-I Changes : Added Discounts for AP Discounts project
4411
4412 IF Checkccid(X_drccid) IS NULL THEN
4413 pa_debug.G_err_stage := 'Calling Checkccid'; log_message(pa_debug.G_err_Stage);
4414 X_status := 'INVALID_DR_CCID' ;
4415 pa_cc_utils.reset_curr_function;
4416 RETURN ;
4417 END IF ;
4418 IF Checkccid(X_crccid) IS NULL THEN
4419 X_status := 'INVALID_CR_CCID' ;
4420 pa_cc_utils.reset_curr_function;
4421 RETURN ;
4422 END IF ;
4423
4424 --
4425 --BUG : 4696351 PJ.R12:DI4:APLINES: VENDOR INFORMATION NOT IMPORTED DURING TRANSACTION IMPORT
4426 --
4427 IF x_system_linkage = 'ER' and
4428 g_vendor_id is NULL THEN
4429
4430 getvendorId(g_person_id) ;
4431
4432 IF g_vendor_id is NULL then
4433 x_status := 'PA_INVALID_SUPPLIER_INFO';
4434 pa_cc_utils.reset_curr_function;
4435 RETURN;
4436 END IF ;
4437
4438 END IF ;
4439 END IF; -- Added for bug 1428539.
4440
4441 /* -- Commented for bug 3357936
4442 IF G_gl_posted_flag = 'N' AND X_gl_date IS NULL THEN
4443
4444 select set_of_books_id
4445 into l_SobId
4446 from pa_implementations_all
4447 where nvl(org_id,-99) = nvl(X_org_id,-99);
4448
4449 X_gl_date := pa_utils2.get_prvdr_gl_date( X_ei_date, l_appl_id , l_SobId) ;
4450
4451 END IF;
4452 */
4453
4454 IF X_gl_date IS NULL THEN
4455 X_status := 'INVALID_GL_DATE' ;
4456 pa_cc_utils.reset_curr_function;
4457 RETURN ;
4458 END IF ;
4459
4460 /*********EPP Changes. This code is commented, is moved after IC check*********
4461 -- Added the pa_date validation fix bug 572196. The for accounted items
4462 -- there should be a valid open/future pa_period
4463 -- Added the following function call calculate pa_date to Resolve Bug 1103257 base bug 967390
4464 *******************************************************************************/
4465
4466
4467
4468 END IF ;
4469
4470 -- ===========================================================================
4471 -- Verify that the transaction has not already been loaded into PA (no
4472 -- other expenditure items exist having the same TRANSACTION SOURCE and
4473 -- ORIG TRANSACTION REFERENCE)
4474 --
4475
4476 IF G_allow_dup_flag <> 'Y' THEN
4477
4478 IF PG_DEBUG = 'Y' THEN
4479 pa_debug.G_err_stage := 'Calling CheckDupItem';
4480 log_message('log_message: ' || pa_debug.G_err_Stage);
4481 END IF;
4482 CheckDupItem ( X_trx_src, X_trx_ref, temp_status );
4483 IF ( temp_status IS NOT NULL ) THEN
4484 X_status := temp_status;
4485 pa_cc_utils.reset_curr_function;
4486 RETURN;
4487 END IF;
4488
4489 END IF ;
4490
4491 -- ===========================================================================
4492 -- If the transaction is an adjustment (negative quantity) of a specific
4493 -- expenditure item (UNMATCHED_NEGATIVE_TXN_FLAG is 'N'), then verify that
4494 -- a matching expenditure item exists
4495 --
4496 -- Oracle Time and Labor(OTL)requires the ability to reverse an ei with a quantity = 0
4497 -- so only for OTL that option has been added.
4498 -- (X_match_flag = 'N' and nvl(X_module, 'EXTERNAL') = 'PAAPIMP' )
4499 --
4500 IF ( ( X_qty < 0 and X_match_flag = 'N' ) OR
4501 ( X_match_flag = 'N' and X_trx_src = 'ORACLE TIME AND LABOR' ) OR
4502 ( nvl(p_adj_exp_item_id,0) > 0 and nvl(X_module, 'EXTERNAL') = 'PAAPIMP') ) THEN
4503
4504 IF PG_DEBUG = 'Y' THEN
4505 pa_debug.G_err_stage := 'Calling pa_adjustments.VerifyOrigItem';
4506 log_message('log_message: ' || pa_debug.G_err_Stage);
4507 END IF;
4508
4509 /* REL12 AP Lines Uptake */
4510 IF ( p_adj_exp_item_id is not NULL and
4511 nvl(X_module, 'EXTERNAL') = 'PAAPIMP' ) THEN
4512 G_adj_item_id := p_adj_exp_item_id ;
4513 ELSE
4514
4515 G_adj_item_id := pa_adjustments.VerifyOrigItem(
4516 X_person_id => G_person_id
4517 , X_org_id => G_org_id
4518 , X_item_date => X_ei_date
4519 , X_task_id => G_task_id
4520 , X_exp_type => X_etype
4521 , X_system_linkage_function => X_system_linkage
4522 , X_nl_org_id => G_nlro_id
4523 , X_nl_resource => X_nlr
4524 , X_quantity => X_qty
4525 , X_denom_raw_cost => X_denom_raw_cost
4526 , X_trx_source => X_trx_src
4527 , X_denom_currency_code => X_denom_currency_code
4528 , X_acct_raw_cost => X_acct_raw_cost
4529 , X_reversed_orig_txn_reference => G_reversed_orig_txn_reference
4530 , X_cbs_element_id => G_cbs_element_id -- Added for CBS Enhancement Bug 16220146
4531 );
4532 END IF ;
4533
4534 IF ( G_adj_item_id IS NULL ) THEN
4535
4536 X_status := 'NO_MATCHING_ITEM';
4537 pa_cc_utils.reset_curr_function;
4538 RETURN;
4539
4540 ELSIF ( G_adj_item_id IS NOT NULL) AND
4541 ( X_module = 'PAXTRTRX' OR X_module = 'PAAPIMP') THEN
4542
4543
4544 IF PG_DEBUG = 'Y' THEN
4545 pa_debug.G_err_stage := 'Calling pa_adjustments.ExpAdjItemTab';
4546 log_message('log_message: ' || pa_debug.G_err_Stage);
4547 END IF;
4548 pa_adjustments.ExpAdjItemTab(G_adj_item_id) := G_adj_item_id;
4549
4550 -- Commenting out the following procedure because verifyorigitem
4551 -- already checks for adjusted ei's that are not yet inserted into
4552 -- database table( EI Table). Bug 752915
4553
4554 -- CheckDupAdjItem( G_adj_item_id, temp_status );
4555
4556 IF PG_DEBUG = 'Y' THEN
4557 pa_debug.G_err_stage := 'Locking adjusting item:'||to_char(G_adj_item_id);
4558 log_message('log_message: ' || pa_debug.G_err_Stage);
4559 END IF;
4560
4561 BEGIN
4562
4563 SELECT
4564 expenditure_item_id
4565 INTO
4566 dummy
4567 FROM
4568 pa_expenditure_items
4569 WHERE
4570 expenditure_item_id = G_adj_item_id
4571 FOR UPDATE NOWAIT;
4572
4573 EXCEPTION
4574 WHEN RESOURCE_BUSY THEN
4575 temp_status := 'CANNOT_LOCK_ORIG_ITEM';
4576 END;
4577 END IF;
4578
4579 IF ( temp_status IS NOT NULL ) THEN
4580 X_status := temp_status;
4581 pa_cc_utils.reset_curr_function;
4582 RETURN;
4583 END IF;
4584
4585 END IF;
4586
4587 -- ===========================================================================
4588 -- IC Changes
4589 --
4590 -- CAll Cross Charge identification API. This API determines
4591 -- Provider Organization
4592 -- Receiver Organization,
4593 -- Cross charge code: Valid values are (B, I, N, X )
4594 -- B = Borrow and Lent , I = Inter Company, N= Not Cross charged
4595 -- X = Never Cross Charged
4596 -- The value of Cross charge code will be used to derive
4597 -- CC_BL_DISTRIBUTED_CODE and CC_IC_PROCESSED_CODE.
4598 --
4599 -- Receiver operating uint,
4600 -- Cross charge type: VAlid values are ( IU, IC, IO )
4601 -- IU = Cross Charge across operating units within one legal entity
4602 -- IC = Cross Charge across operating units across legal entities
4603 -- IO = Cross charge with in one Operating unit( Borrow and lent )
4604 --
4605 -- The cross charge identification is usually done by costing progarm
4606 -- However for accounted txns are not picked up by costing programs, hence
4607 -- transaction import should identify cross charge txns.
4608
4609 -- Initilize the package body global variables before calling the
4610 -- CC Identification API.
4611
4612 G_CrossChargeType := 'NO';
4613 G_CrossChargeCode := 'P';
4614 G_PrvdrOrganizationId := NULL;
4615 G_RecvrOrganizationId := NULL;
4616 G_RecvrOrgId := NULL;
4617 G_BrowLentDistCode := 'X';
4618 G_IcProcessed_Code := 'X';
4619
4620 /* Added g_trx_costed in if condition for bug 1897348*/
4621 IF (( nvl(G_gl_accted_flag,'N') = 'Y') OR
4622 (nvl(G_trx_costed,'N') = 'Y')) THEN
4623
4624 <<Cc_Identification_Api>>
4625 BEGIN
4626
4627 IF PG_DEBUG = 'Y' THEN
4628 pa_debug.G_err_stage := 'Calling PA_CC_IDENT.PA_CC_IDENTIFY_TXN_ADJ';
4629 log_message('log_message: ' || pa_debug.G_err_Stage);
4630 END IF;
4631
4632 G_unmatched_negative_txn_flag := NVL(X_match_flag, 'N'); -- Bug 16451280
4633
4634 PA_CC_IDENT.PA_CC_IDENTIFY_TXN_ADJ(
4635 -- Changed the follwing NVL as the G_override_to_org_id should always
4636 -- take precedence over G_org_id bug #4689402 (forward port for 4614046)
4637 P_ExpOrganizationId => NVL(G_override_to_org_id, G_org_id), --For 1612483
4638 P_ExpOrgid => X_org_id , -- bug 1612483
4639 P_ProjectId => G_project_id,
4640 P_TaskId => G_task_id,
4641 P_ExpItemDate => X_ei_date,
4642 /* Passing TXN_INTERFACE_ID instead of null for 3234973
4643 and calling_module as 'TRANSACTION_IMPORT' */
4644 /* P_ExpItemId => NULL, */
4645 P_ExpItemId => X_txn_interface_id,
4646 P_ExpType => X_etype,
4647 P_PersonId => G_person_id ,
4648 P_SysLink => X_system_linkage,
4649 P_PrjOrganizationId => NULL,
4650 P_PrjOrgId => NULL,
4651 P_TransSource => X_trx_src,
4652 P_NLROrganizationId => G_nlro_id,
4653 P_PrvdrLEId => NULL,
4654 P_RecvrLEId => NULL,
4655 X_Status => X_Status,
4656 X_CrossChargeType => G_CrossChargeType,
4657 X_CrossChargeCode => G_CrossChargeCode,
4658 X_PrvdrOrganizationId => G_PrvdrOrganizationId,
4659 X_RecvrOrganizationId => G_RecvrOrganizationId,
4660 X_RecvrOrgId => G_RecvrOrgId,
4661 X_Error_Stage => temp_dff_msg,
4662 X_Error_Code => temp_status,
4663 /* Added calling module for 3234973, so that client extention can function correctly. */
4664 X_Calling_Module => 'TRANSACTION_IMPORT');
4665
4666 EXCEPTION WHEN others THEN
4667 IF PG_DEBUG = 'Y' THEN
4668 log_message('log_message: ' || pa_debug.G_err_stack,1);
4669 log_message('log_message: ' || SQLERRM,1);
4670 log_message('log_message: ' || pa_debug.G_err_stage,1);
4671 END IF;
4672 X_Status := 'PA_ERR_IN_CC_IDENT_API';
4673 pa_cc_utils.reset_curr_function;
4674 RETURN;
4675 END Cc_Identification_Api;
4676
4677 -- if an error has occured in CC identification API, the
4678 -- X_Status variable will be populated with the error code.
4679 IF ( X_Status IS NOT NULL ) THEN
4680 pa_cc_utils.reset_curr_function;
4681 RETURN;
4682 ELSE -- i.e. successful completion
4683
4684 IF ( G_CrossChargeCode = 'B' ) THEN
4685
4686 -- Brrowed and lent processing
4687 -- The EI will be marked for
4688 -- borrow and lent processing
4689
4690 G_BrowLentDistCode := 'N';
4691 G_IcProcessed_Code := 'X';
4692
4693 ELSIF ( G_CrossChargeCode = 'I' ) THEN
4694
4695 -- Inter company processing
4696 -- the Ei will be marked for IC processing
4697
4698 G_BrowLentDistCode := 'X';
4699 G_IcProcessed_Code := 'N';
4700
4701 ELSE
4702 -- No Cross Charge processing
4703
4704 G_BrowLentDistCode := 'X';
4705 G_IcProcessed_Code := 'X';
4706
4707 END IF; -- end G_CrossChargeCode = 'B'
4708 END IF; -- End X_status is not null
4709
4710 -- Added the following function call calculate recvr_pa_date to Resolve Bug # 1653831
4711
4712 /* EPP Changes: Moved recvr_pa_date derivation after this section */
4713
4714 -- End of code for Bug # 1653831
4715 /* IC Change: we need to get receiver org ID regarldess
4716 of accounted or unaccounted transaction. For accounted
4717 case, we call PA_CC_IDENT.pa_cc_identify_txn_adj to
4718 get receiver org ID along with other info. For
4719 unaccounted case, we call PA_UTILS2.GetPrjOrgId to get
4720 only the reciever org id info. */
4721 ELSE
4722 /* IC Changes: Get receiver organization ID */
4723 IF PG_DEBUG = 'Y' THEN
4724 pa_debug.G_err_stage := 'Calling PA_UTILS2.GetPrjOrgId';
4725 log_message('log_message: ' || pa_debug.G_err_Stage);
4726 END IF;
4727 G_RecvrOrgId := PA_UTILS2.GetPrjOrgId(p_project_id => G_project_id,
4728 p_task_id => NULL);
4729 END IF; -- End gl_accted_flag = Y
4730 -- ==========================================================================
4731
4732 /***********Start EPP CHANGES. Added call to get period information*************/
4733
4734 G_PaDate := NULL;
4735 G_PaPeriodName := NULL;
4736 G_RecvrPaDate := NULL;
4737 G_RecvrPaPeriodName := NULL;
4738 G_GlPeriodName := NULL;
4739 G_RecvrGlDate := NULL;
4740 G_RecvrGlPeriodName := NULL;
4741 G_SobId := NULL;
4742 G_RecvrSobId := NULL;
4743
4744 /* PA-J Period-End Accrual Changes :
4745 Need to retrieve set_of_books information for provider
4746 and receiver orgs when gl_accted_flag is Y and also
4747 for unaccounted period-end accrual transactions.
4748 A miscellaneous transaction (system_linkage = PJ) with the
4749 accrual_flag set to Y is a period-end accrual transaction.
4750 For period-end accrual transaction the period information
4751 is retrieved from a new API get_accrual_period_information.
4752 */
4753
4754 G_GlDate := NULL;
4755 G_AccDate := NULL;
4756 G_RecvrAccDate := NULL;
4757 G_RevAccDate := NULL;
4758 G_RevRecvrAccDate := NULL;
4759 G_RevPaDate := NULL;
4760 G_RevPaPeriodName := NULL;
4761 G_RevGlDate := NULL;
4762 G_RevGlPeriodName := NULL;
4763 G_RevRecvrPaDate := NULL;
4764 G_RevRecvrPaPdName:= NULL;
4765 G_RevRecvrGlDate := NULL;
4766 G_RevRecvrGlPdName:= NULL;
4767 l_period_end_txn := 'N';
4768
4769 --Identify if the transaction is a period-end accrual transaction
4770 IF (x_system_linkage = 'PJ' and x_accrual_flag = 'Y') THEN
4771
4772 IF PG_DEBUG = 'Y' THEN
4773 pa_debug.G_err_stage := 'This is a Period-End Accrual transaction';
4774 log_message('log_message: ' || pa_debug.G_err_Stage);
4775 END IF;
4776
4777 l_period_end_txn := 'Y';
4778
4779 END IF;
4780
4781 --If transaction is accounted then derive the provider and receiver set of books information.
4782 IF ( nvl(G_gl_accted_flag,'N') = 'Y' or l_period_end_txn = 'Y') THEN
4783
4784 IF PG_DEBUG = 'Y' THEN
4785 pa_debug.G_err_stage := 'Retrieve provider and receiver set_of_books';
4786 log_message('log_message: ' || pa_debug.G_err_Stage);
4787 END IF;
4788
4789 log_message('log_message: x_org_id= ' || X_org_id || ' Prev = '|| Prev_OrgId); -- For bug 3590027
4790 if (nvl(X_org_id,-101) <> nvl(Prev_OrgId,-99)) then -- Added nvl to X_org_id for bug 3590027
4791
4792 IF PG_DEBUG = 'Y' THEN
4793 pa_debug.G_err_stage := 'Diff org_id';
4794 log_message('log_message: ' || pa_debug.G_err_Stage);
4795 END IF;
4796
4797 select set_of_books_id
4798 into G_SobId
4799 from pa_implementations_all
4800 where org_id = X_org_id;
4801
4802 Prev_SobId := G_SobId;
4803 Prev_OrgID := X_Org_Id;
4804 else
4805
4806 IF PG_DEBUG = 'Y' THEN
4807 pa_debug.G_err_stage := 'Same org_id';
4808 log_message('log_message: ' || pa_debug.G_err_Stage);
4809 END IF;
4810
4811 G_SobId := Prev_SobId;
4812 end if;
4813
4814 --IF (nvl(Prev_SobId,-101) <> nvl(G_SobId,-99)) THEN
4815 -- SELECT NVL(sla_ledger_cash_basis_flag,'N')
4816 -- INTO G_cash_based_accounting
4817 -- FROM gl_sets_of_books
4818 -- WHERE set_of_books_id = G_SobId;
4819 --
4820 --END IF;
4821
4822 log_message('log_message: G_RecvrOrgId= ' || G_RecvrOrgId || ' Prev = '|| Prev_RecvrOrgId);--Bug 3590027
4823 if (nvl(G_RecvrOrgId,-101) <> nvl(Prev_RecvrOrgId,-99)) then -- Added nvl to G_RecvrOrgId for 3590027
4824
4825 IF PG_DEBUG = 'Y' THEN
4826 pa_debug.G_err_stage := 'Diff recvr_org_id';
4827 log_message('log_message: ' || pa_debug.G_err_Stage);
4828 END IF;
4829
4830 select set_of_books_id
4831 into G_RecvrSobId
4832 from pa_implementations_all
4833 where org_id = nvl(G_RecvrOrgId,-99);
4834
4835 Prev_RecvrSobId := G_RecvrSobId;
4836 Prev_RecvrOrgID := G_RecvrOrgId;
4837 else
4838
4839 IF PG_DEBUG = 'Y' THEN
4840 pa_debug.G_err_stage := 'Same recvr_org_id';
4841 log_message('log_message: ' || pa_debug.G_err_Stage);
4842 END IF;
4843
4844 G_RecvrSobId := Prev_RecvrSobId;
4845 end if;
4846
4847 IF PG_DEBUG = 'Y' THEN
4848 log_message('log_message: ' || 'Prvdr Sob ID = ' || G_SobId);
4849 log_message('log_message: ' || 'Recvr Sob ID = ' || G_RecvrSobId);
4850 END IF;
4851 END IF;
4852
4853 --If transaction is an accounted, non-period end accrual transaction then call
4854 --pa_integration.get_period_information to derive the period information.
4855 IF ( (nvl(G_gl_accted_flag,'N') = 'Y') and (l_period_end_txn = 'N')) THEN
4856
4857 IF PG_DEBUG = 'Y' THEN
4858 pa_debug.G_err_stage := 'Start PA_Date and Recvr_PA_Date Checks for non-period-end accrual txns';
4859 log_message('log_message: ' || pa_debug.G_err_Stage);
4860 END IF;
4861
4862 IF PG_DEBUG = 'Y' THEN
4863 pa_debug.G_err_stage := 'Calling pa_integration.get_period_information';
4864 log_message('log_message: ' || pa_debug.G_err_Stage);
4865 END IF;
4866
4867 pa_integration.get_period_information(
4868 p_expenditure_item_date => X_ei_date
4869 ,p_prvdr_gl_date => X_gl_date
4870 ,x_recvr_gl_date => G_RecvrGlDate
4871 ,p_line_type => 'R'
4872 ,p_prvdr_org_id => X_org_id
4873 ,p_recvr_org_id => G_RecvrOrgId
4874 ,p_prvdr_sob_id => G_SobId
4875 ,p_recvr_sob_id => G_RecvrSobId
4876 ,x_prvdr_pa_date => G_PaDate
4877 ,x_prvdr_pa_period_name => G_PaPeriodName
4878 ,x_prvdr_gl_period_name => G_GlPeriodName
4879 ,x_recvr_pa_date => G_RecvrPaDate
4880 ,x_recvr_pa_period_name => G_RecvrPaPeriodName
4881 ,x_recvr_gl_period_name => G_RecvrGlPeriodName
4882 ,x_return_status => x_return_status
4883 ,x_error_code => x_error_code
4884 ,x_error_stage => x_error_stage);
4885
4886 IF PG_DEBUG = 'Y' THEN
4887 log_message('log_message: ' || 'G_OrgID = '|| X_org_id || ' G_RecvrOrgId = '|| G_RecvrOrgId || ' X_ei_date = '|| X_ei_date);
4888 log_message('log_message: ' || 'G_PaDate = '|| G_PaDate || ' G_PaPeriodName = '|| G_PaPeriodName);
4889 log_message('log_message: ' || 'G_GlDate = '|| X_gl_date || ' G_GlPeriodName = '|| G_GlPeriodName);
4890 log_message('log_message: ' || 'G_RecvrPaDate = '|| G_RecvrPaDate || ' G_RecvrPeriodName = '|| G_RecvrPaPeriodName);
4891 log_message('log_message: ' || 'G_RecvrGlDate = '|| G_RecvrGlDate || ' G_RecvrGlPeriodName = '|| G_RecvrGlPeriodName);
4892 END IF;
4893
4894 IF PG_DEBUG = 'Y' THEN
4895 pa_debug.G_err_stage := 'After pa_integration.get_period_information';
4896 log_message('log_message: ' || pa_debug.G_err_Stage);
4897 END IF;
4898
4899 --Pa_date check being done here
4900 IF G_PaDate is NULL then
4901
4902 IF PG_DEBUG = 'Y' THEN
4903 pa_debug.G_err_stage := 'PA_Date is null';
4904 log_message('log_message: ' || pa_debug.G_err_Stage);
4905 END IF;
4906
4907 X_status := 'INVALID_PA_DATE' ;
4908 pa_cc_utils.reset_curr_function;
4909 RETURN ;
4910
4911 END IF ;
4912
4913 IF nvl(X_org_id,-999) <> nvl(G_RecvrOrgId,-999) THEN ----------------------{
4914
4915 IF PG_DEBUG = 'Y' THEN
4916 pa_debug.G_err_stage := 'Before Check for the Receiver Date';
4917 log_message('log_message: ' || pa_debug.G_err_Stage);
4918 END IF;
4919
4920 IF G_RecvrPaDate is NULL then
4921
4922 IF PG_DEBUG = 'Y' THEN
4923 pa_debug.G_err_stage := 'Recvr_PA_Date is null';
4924 log_message('log_message: ' || pa_debug.G_err_Stage);
4925 END IF;
4926
4927 X_status := 'INVALID_RECVR_PA_DATE' ;
4928 pa_cc_utils.reset_curr_function;
4929 RETURN ;
4930
4931 END IF ;
4932
4933 IF G_RecvrGlDate is NULL then
4934
4935 IF PG_DEBUG = 'Y' THEN
4936 pa_debug.G_err_stage := 'Recvr_GL_Date is null';
4937 log_message('log_message: ' || pa_debug.G_err_Stage);
4938 END IF;
4939
4940 X_status := 'INVALID_RECVR_GL_DATE' ;
4941 pa_cc_utils.reset_curr_function;
4942 RETURN ;
4943
4944 END IF ;
4945
4946 IF PG_DEBUG = 'Y' THEN
4947 pa_debug.G_err_stage := 'After Check for the Receiver Date';
4948 log_message('log_message: ' || pa_debug.G_err_Stage);
4949 END IF;
4950
4951 END IF ; ----------------------------------}
4952
4953 END IF; --Accted = Y and Period_End = N
4954
4955 --If transaction is accounted or unaccounted, period end accrual transaction then call
4956 --pa_utils2.get_period_information to derive the accrual period information for the original
4957 --and reversing line.
4958 IF ( l_period_end_txn = 'Y' ) THEN
4959
4960 IF PG_DEBUG = 'Y' THEN
4961 pa_debug.G_err_stage := 'Start PA_Date and Recvr_PA_Date Checks for period-end accrual txns';
4962 log_message('log_message: ' || pa_debug.G_err_Stage);
4963 END IF;
4964
4965 IF PG_DEBUG = 'Y' THEN
4966 pa_debug.G_err_stage := 'Calling pa_utils2.get_accrual_period_information';
4967 log_message('log_message: ' || pa_debug.G_err_Stage);
4968 END IF;
4969
4970 G_GlDate := X_gl_date;
4971
4972 --Call get_accrual_period_information API for the original line
4973 pa_utils2.get_accrual_period_information (
4974 p_expenditure_item_date => X_ei_date --in
4975 ,x_prvdr_accrual_date => G_AccDate --in/out. For original item this is passed OUT
4976 ,x_recvr_accrual_date => G_RecvrAccDate --in/out. For original item this is passed OUT
4977 ,p_prvdr_org_id => X_org_id --in
4978 ,p_recvr_org_id => G_RecvrOrgId --in
4979 ,p_prvdr_sob_id => G_SobId --in
4980 ,p_recvr_sob_id => G_RecvrSobId --in
4981 ,p_calling_module => 'TRXIMPORT' --in
4982 ,x_prvdr_pa_date => G_PaDate --out
4983 ,x_prvdr_pa_period_name => G_PaPeriodName --out
4984 ,x_prvdr_gl_date => G_GlDate --in/out. This is passed IN if accounted. Unaccounted, it will be null
4985 ,x_prvdr_gl_period_name => G_GlPeriodName --out
4986 ,x_recvr_pa_date => G_RecvrPaDate --out
4987 ,x_recvr_pa_period_name => G_RecvrPaPeriodName --out
4988 ,x_recvr_gl_date => G_RecvrGlDate --out
4989 ,x_recvr_gl_period_name => G_RecvrGlPeriodName --out
4990 ,p_adj_ei_id => null --in
4991 ,p_acct_flag => nvl(G_gl_accted_flag,'N') --in
4992 ,x_return_status => l_ret_sts --out
4993 ,x_error_code => x_error_code --out
4994 ,x_error_stage => x_err_stage --out
4995 );
4996
4997 IF PG_DEBUG = 'Y' THEN
4998 log_message('log_message: ' || 'Prvdr Acc Date = ' || G_AccDate || ' Recvr Acc Date = ' || G_RecvrAccDate);
4999 END IF;
5000
5001 if (nvl(G_gl_accted_flag,'N') = 'Y') then
5002 IF PG_DEBUG = 'Y' THEN
5003 log_message('log_message: ' || 'Prvdr Gl Date = ' || G_GlDate || ' Prvdr Gl Pd Name = ' || G_GlPeriodName);
5004 log_message('log_message: ' || 'Recvr Gl Date = ' || G_RecvrGlDate || ' Recvr Gl Pd Name = ' || G_RecvrGlPeriodName);
5005 log_message('log_message: ' || 'Prvdr PA Date = ' || G_PaDate || ' Prvdr PA Pd Name = ' || G_PaPeriodName);
5006 log_message('log_message: ' || 'Recvr PA Date = ' || G_RecvrPaDate || ' Recvr PA Pd Name = ' || G_RecvrPaPeriodName);
5007 END IF;
5008 end if;
5009
5010 if (l_ret_sts <> FND_API.G_RET_STS_SUCCESS) then
5011 x_status := x_error_code;
5012 IF PG_DEBUG = 'Y' THEN
5013 pa_debug.G_err_stage := 'Error returned for accrual date derivation = '||x_status;
5014 log_message('log_message: ' || pa_debug.G_err_Stage);
5015 END IF;
5016 pa_cc_utils.reset_curr_function;
5017 RETURN;
5018 end if;
5019
5020 --We copy the original item's accrual date for provider and
5021 --receiver to the reversing item variables.
5022 --For reversing item the original item's accrual date is passed
5023 --in and the reversing item's accrual date is passed out.
5024 G_RevAccDate := G_AccDate;
5025 G_RevRecvrAccDate := G_RecvrAccDate;
5026
5027 IF PG_DEBUG = 'Y' THEN
5028 pa_debug.G_err_stage := 'Calling pa_utils2.get_accrual_period_information for the reversing line';
5029 log_message('log_message: ' || pa_debug.G_err_Stage);
5030 END IF;
5031
5032
5033 --Call get_accrual_period_information API for the reversing line
5034 pa_utils2.get_accrual_period_information (
5035 p_expenditure_item_date => X_ei_date
5036 ,x_prvdr_accrual_date => G_RevAccDate --in/out (both)
5037 ,x_recvr_accrual_date => G_RevRecvrAccDate --in/out (both)
5038 ,p_prvdr_org_id => X_org_id
5039 ,p_recvr_org_id => G_RecvrOrgId
5040 ,p_prvdr_sob_id => G_SobId
5041 ,p_recvr_sob_id => G_RecvrSobId
5042 ,p_calling_module => 'TRXIMPORT'
5043 ,x_prvdr_pa_date => G_RevPaDate
5044 ,x_prvdr_pa_period_name => G_RevPaPeriodName
5045 ,x_prvdr_gl_date => G_RevGlDate --in/out (passed OUT for reversing item)
5046 ,x_prvdr_gl_period_name => G_RevGlPeriodName
5047 ,x_recvr_pa_date => G_RevRecvrPaDate
5048 ,x_recvr_pa_period_name => G_RevRecvrPaPdName
5049 ,x_recvr_gl_date => G_RevRecvrGlDate
5050 ,x_recvr_gl_period_name => G_RevRecvrGLPdName
5051 ,p_adj_ei_id => 99 --dummy value to be passed
5052 ,p_acct_flag => nvl(G_gl_accted_flag,'N')
5053 ,x_return_status => l_ret_sts
5054 ,x_error_code => x_error_code
5055 ,x_error_stage => x_err_stage
5056 );
5057
5058 IF PG_DEBUG = 'Y' THEN
5059 log_message('log_message: ' || 'Prvdr Acc Date = ' || G_RevAccDate || ' Recvr Acc Date = ' || G_RevRecvrAccDate);
5060 END IF;
5061
5062 if (nvl(G_gl_accted_flag,'N') = 'Y') then
5063 IF PG_DEBUG = 'Y' THEN
5064 log_message('log_message: ' || 'Prvdr Gl Date = ' || G_RevGlDate || ' Prvdr Gl Pd Name = ' || G_RevGlPeriodName);
5065 log_message('log_message: ' || 'Recvr Gl Date = ' || G_RevRecvrGlDate || ' Recvr Gl Pd Name = ' || G_RevRecvrGlPdName);
5066 log_message('log_message: ' || 'Prvdr PA Date = ' || G_RevPaDate || ' Prvdr PA Pd Name = ' || G_RevPaPeriodName);
5067 log_message('log_message: ' || 'Recvr PA Date = ' || G_RevRecvrPaDate || ' Recvr PA Pd Name = ' || G_RevRecvrPaPdName);
5068 END IF;
5069 end if;
5070
5071 IF (l_ret_sts <> FND_API.G_RET_STS_SUCCESS) THEN
5072 x_status := x_error_code;
5073 IF PG_DEBUG = 'Y' THEN
5074 pa_debug.G_err_stage := 'Error returned for reversal line accrual date derivation = '||x_status;
5075 log_message('log_message: ' || pa_debug.G_err_Stage);
5076 END IF;
5077 pa_cc_utils.reset_curr_function;
5078 RETURN;
5079 END IF;
5080
5081 END IF; -- Period_End = Y accrual txn period derivation
5082
5083 /***********End EPP CHANGES. Added call to get period information*************/
5084
5085 /*=========Start Assignment_Id, Work_Type_Id Checks========================*/
5086
5087 -- PA-I Changes
5088 -- Assignment_Id and Work_Type_Id derivation/validation checks
5089
5090 -- PA-J Txn Ctrl Changes
5091 -- Assignment Id will now be derived for Expense Reports (system_linkage of ER)
5092 -- The derivation of assignment id for ER is done in pa_utils4.
5093
5094 -- PA-K Changes: For pre-defined sources the values in assignment_name and
5095 -- work_type_name will be ignored. If ids are given they will used else it will be derived.
5096 -- For user defined sources ids will be ignored and the names if given will be validated
5097
5098 If (G_trx_predef_flag = 'Y') Then
5099
5100 IF PG_DEBUG = 'Y' THEN
5101 pa_debug.G_err_stage := 'Get Assignment and work type for predefined';
5102 log_message('log_message: ' || pa_debug.G_err_Stage);
5103 END IF;
5104
5105 If (x_system_linkage in ('ST', 'OT', 'ER')) Then
5106
5107 IF PG_DEBUG = 'Y' THEN
5108 pa_debug.G_err_stage := 'Sys Link is ST OT ER';
5109 log_message('log_message: ' || pa_debug.G_err_Stage);
5110 END IF;
5111
5112 If (P_Assignment_Id is not null) Then
5113
5114 IF PG_DEBUG = 'Y' THEN
5115 pa_debug.G_err_stage := 'P_Assignment_id is not null';
5116 log_message('log_message: ' || pa_debug.G_err_Stage);
5117 END IF;
5118
5119 G_Assignment_Id := P_Assignment_Id;
5120
5121 IF PG_DEBUG = 'Y' THEN
5122 pa_debug.G_err_stage := 'G_Assignment_Id = ' || G_Assignment_Id;
5123 log_message('log_message: ' || pa_debug.G_err_Stage);
5124 END IF;
5125
5126 Else
5127
5128 IF PG_DEBUG = 'Y' THEN
5129 pa_debug.G_err_stage := 'P_Assignment_id is null';
5130 log_message('log_message: ' || pa_debug.G_err_Stage);
5131 END IF;
5132
5133 G_Assignment_Id := pa_utils4.get_assignment_id(
5134 p_person_id => G_Person_Id
5135 ,p_project_id => G_Project_Id
5136 ,p_task_id => G_Task_Id
5137 ,p_ei_date => X_Ei_Date);
5138
5139 IF PG_DEBUG = 'Y' THEN
5140 pa_debug.G_err_stage := 'G_Assignment_Id = ' || G_Assignment_Id;
5141 log_message('log_message: ' || pa_debug.G_err_Stage);
5142 END IF;
5143
5144 End If;
5145
5146 Else
5147
5148 IF PG_DEBUG = 'Y' THEN
5149 pa_debug.G_err_stage := 'Sys Link is not ST OT ER';
5150 log_message('log_message: ' || pa_debug.G_err_Stage);
5151 END IF;
5152
5153 G_Assignment_Id := NULL;
5154
5155 End If;
5156
5157 /*Bug# 2737538:Added check of profile option value for deriving work type */
5158 /* If (nvl(pa_utils4.is_exp_work_type_enabled,'N') = 'Y') Then ** moved condition below bug 3104004 */
5159
5160 log_message('log_message: p work type id: ' || p_work_type_id);
5161
5162 If (P_Work_Type_Id is not null) Then
5163
5164 IF PG_DEBUG = 'Y' THEN
5165 pa_debug.G_err_stage := 'P_Work_Type_Id is not null';
5166 log_message('log_message: ' || pa_debug.G_err_Stage);
5167 END IF;
5168
5169 G_Work_Type_Id := P_Work_Type_Id;
5170
5171 IF PG_DEBUG = 'Y' THEN
5172 pa_debug.G_err_stage := 'G_Work_Type_Id = ' || G_Work_Type_Id;
5173 log_message('log_message: ' || pa_debug.G_err_Stage);
5174 END IF;
5175
5176 Else
5177
5178 IF PG_DEBUG = 'Y' THEN
5179 pa_debug.G_err_stage := 'P_Work_Type_Id is null';
5180 log_message('log_message: ' || pa_debug.G_err_Stage);
5181 END IF;
5182
5183 G_Work_Type_Id := pa_utils4.get_work_type_id(
5184 p_project_id => G_Project_Id
5185 ,p_task_id => G_Task_Id
5186 ,p_assignment_id => nvl(G_Assignment_Id,0));
5187
5188 IF PG_DEBUG = 'Y' THEN
5189 pa_debug.G_err_stage := 'G_Work_Type_Id = ' || G_Work_Type_Id;
5190 log_message('log_message: ' || pa_debug.G_err_Stage);
5191 END IF;
5192
5193 If (G_Work_Type_Id is NULL and nvl(pa_utils4.is_exp_work_type_enabled,'N') = 'Y') Then
5194 /*** added and condition bug 3104004 */
5195 X_Status := 'INVALID_WORK_TYPE';
5196 pa_cc_utils.reset_curr_function;
5197 Return;
5198 End If;
5199
5200 End If;
5201
5202 IF PG_DEBUG = 'Y' THEN
5203 pa_debug.G_err_stage := 'Get Tp Amt Type';
5204 log_message('log_message: ' || pa_debug.G_err_Stage);
5205 END IF;
5206
5207 G_Tp_Amt_Type_Code := pa_utils4.get_tp_amt_type_code(
5208 p_work_type_id => G_Work_Type_Id);
5209
5210 IF PG_DEBUG = 'Y' THEN
5211 pa_debug.G_err_stage := 'G_Tp_Amt_Type_Code = ' || G_Tp_Amt_Type_Code;
5212 log_message('log_message: ' || pa_debug.G_err_Stage);
5213 END IF;
5214
5215 /**End If;** commented bug 3104004 */ /*Bug# 2737538 wrapped tp_amt_type_code and work_type related calls if work type profile is enabled*/
5216
5217 Else
5218
5219 IF PG_DEBUG = 'Y' THEN
5220 pa_debug.G_err_stage := 'Calling API to derive/validate assignment and work type info';
5221 log_message('log_message: ' || pa_debug.G_err_Stage);
5222 log_message('log_message: ' || 'Assignment Name = ' || X_Assignment_Name || ' Work Type Name = ' || X_Work_Type_Name);
5223 END IF;
5224
5225 pa_utils4.get_work_assignment(
5226 p_person_id => G_Person_Id
5227 , p_project_id => G_Project_Id
5228 , p_task_id => G_Task_Id
5229 , p_ei_date => X_Ei_Date
5230 , p_system_linkage => x_system_linkage
5231 , x_assignment_id => G_Assignment_Id
5232 , x_assignment_name => X_Assignment_Name
5233 , x_work_type_id => G_Work_Type_Id
5234 , x_work_type_name => X_Work_Type_Name
5235 , x_tp_amt_type_code => G_Tp_Amt_Type_Code
5236 , x_return_status => l_asgn_work_ret_sts
5237 , x_error_message_code => l_asgn_work_err_msg);
5238
5239 --PA-J Txn Ctrl changes: Added ER to the below check.
5240 if (x_system_linkage not in ('ST', 'OT', 'ER')) then
5241 G_Assignment_Id := null;
5242 end if;
5243
5244 IF PG_DEBUG = 'Y' THEN
5245 log_message('log_message: ' || 'Assignment Id = ' || G_Assignment_Id || ' Work Type Id = ' || G_Work_Type_Id ||
5246 ' Tp Amt Type = ' || G_Tp_Amt_Type_Code);
5247 END IF;
5248
5249 IF (l_asgn_work_ret_sts <> FND_API.G_RET_STS_SUCCESS) THEN
5250
5251 IF PG_DEBUG = 'Y' THEN
5252 pa_debug.G_err_stage := 'Get Work Type and Assignment API failed';
5253 log_message('log_message: ' || pa_debug.G_err_Stage);
5254 log_message('log_message: ' || 'Ret Sts = ' || l_asgn_work_ret_sts || ' Error = ' || l_asgn_work_err_msg);
5255 END IF;
5256
5257 X_Status := l_asgn_work_err_msg;
5258 pa_cc_utils.reset_curr_function;
5259 RETURN;
5260
5261 END IF;
5262
5263 End If;
5264
5265 /*=========End Assignment_Id, Work_Type_Id Checks==========================*/
5266
5267 --PA-K Changes + bug 2634812
5268 --Bug 2688926: Reverted 2634812, removed the check on total_burden_flag project type option
5269 --For transactions that are externally burdened or externally accounted
5270 --If project is burdened then set the compiled_set_id to -1 if it is null
5271 --Also see PAXTRANB.pls 115.41, where cost_burden_distributed_flag is
5272 --based on the value of compiled_set_id
5273 If (nvl(G_burdened_flag,'N') = 'Y') OR (nvl(G_gl_accted_flag,'N') = 'Y') Then
5274
5275 If nvl(G_Proj_bcost_flag,'N') = 'Y' Then
5276
5277 If G_burden_compile_set_id is NULL Then
5278
5279 G_burden_compile_set_id := -1;
5280
5281 End If;
5282
5283 End If;
5284
5285 End If;
5286
5287 -- ==========================================================================
5288 -- The following section of the code performs valdiations specific to contingent worker timecards
5289 -- with purchase order integration for cwk. This is being placed before validate_transaction call since
5290 -- we need to pass po_header_id and po_line_id to validate_transaction and if not provided, these
5291 -- will be derived by the PO api validate_temp_labor_po
5292
5293 IF nvl(P_Person_Type,'EMP') IN ('EMP','CWK' ,'EX_EMP' ) THEN /*Bug 16451280 : Added EX_EMP*/
5294 null;
5295 ELSE
5296 X_status := 'INVALID_PERSON_TYPE';
5297 pa_cc_utils.reset_curr_function;
5298 RETURN;
5299 END IF;
5300
5301 IF ((P_po_number is not null OR P_Po_Line_Num is not null OR
5302 P_Po_Header_Id is not null OR P_Po_Line_Id is not null) AND
5303 x_system_linkage in ('ST','OT'))
5304 THEN
5305
5306
5307 IF PG_DEBUG = 'Y' THEN
5308 pa_debug.G_err_stage := 'If any of the PO attributes are not null';
5309 log_message('log_message: ' || pa_debug.G_err_Stage);
5310 END IF;
5311
5312 IF Pa_Pjc_CWk_Utils.Is_CWK_TC_Xface_Allowed(G_Project_Id) <> 'Y' THEN
5313 X_Status := 'PA_CWK_TC_NOT_ALLOWED';
5314 pa_cc_utils.reset_curr_function;
5315 RETURN;
5316 ELSIF (( nvl(G_gl_accted_flag,'N') = 'Y') OR (nvl(G_trx_costed,'N') = 'Y')) THEN
5317 X_status := 'PA_CWK_PO_COSTED_NOTSUP';
5318 pa_cc_utils.reset_curr_function;
5319 RETURN;
5320 ELSIF nvl(p_person_type,'EMP') = 'EMP' THEN
5321 X_status := 'PA_EMP_PO_NOTSUP';
5322 pa_cc_utils.reset_curr_function;
5323 RETURN;
5324 END IF;
5325
5326 IF PG_DEBUG = 'Y' THEN
5327 pa_debug.G_err_stage := 'Calling PO Validation api';
5328 log_message('log_message: ' || pa_debug.G_err_Stage);
5329 END IF;
5330
5331 PO_PA_INTEGRATION_GRP.validate_temp_labor_po (
5332 P_Api_Version => 1.0,
5333 P_Project_Id => G_project_id,
5334 P_Task_Id => G_task_id,
5335 P_Po_Number => P_po_number,
5336 P_Po_Line_Num => P_Po_Line_Num,
5337 P_Price_Type => P_po_price_type,
5338 P_Org_Id => X_org_id,
5339 P_Person_Id => G_person_id,
5340 P_effective_date => X_EI_date, -- added for bug 4155220
5341 P_Po_Header_Id => P_Po_Header_Id,
5342 P_Po_Line_Id => P_Po_Line_Id,
5343 X_Po_Line_Amt => G_Po_Line_Amt,
5344 X_Po_Rate => l_po_rate,
5345 X_Currency_Code => X_denom_currency_code,
5346 X_Curr_Rate_Type => X_acct_rate_type,
5347 X_Curr_Rate_Date => X_acct_rate_date,
5348 X_Currency_Rate => X_acct_exchange_rate,
5349 X_Vendor_Id => G_vendor_id,
5350 X_Return_StatuS => temp_msg_type,
5351 X_Message_Code => temp_status);
5352
5353 G_acct_rate_type := X_acct_rate_type; -- Bug: 3570261
5354
5355
5356 IF PG_DEBUG = 'Y' THEN
5357 pa_debug.G_err_stage := 'After PO_PA_INTEGRATION_GRP.validate_temp_labor_po ';
5358 log_message('log_message: ' || pa_debug.G_err_Stage);
5359 END IF;
5360
5361 IF temp_status IS NOT NULL THEN
5362 IF PG_DEBUG = 'Y' THEN
5363 pa_debug.G_err_stage := 'validate_temp_labor_po has failed';
5364 log_message('log_message: ' || pa_debug.G_err_Stage);
5365 END IF;
5366
5367 X_status := temp_status;
5368 pa_cc_utils.reset_curr_function;
5369 RETURN;
5370 END IF;
5371
5372 /* po amount check */
5373
5374 IF nvl(l_po_rate,0) = 0 THEN
5375 X_status := 'INVALID_PO_RATE';
5376 pa_cc_utils.reset_curr_function;
5377 RETURN;
5378 END IF;
5379
5380 l_Calc_Amt := X_qty * l_po_rate;
5381
5382
5383
5384
5385 /* Bug 4098920
5386 select sum(denom_raw_cost)
5387 into l_costed
5388 from pa_expenditure_items ei, pa_expenditures exp
5389 where ei.cost_distributed_flag = 'Y'
5390 and ei.project_id = G_project_id
5391 and ei.task_id = G_task_id
5392 and ei.po_line_id = P_Po_Line_Id
5393 and ei.system_linkage_function in ('ST','OT')
5394 and ei.expenditure_id = exp.expenditure_id
5395 and exp.person_type = 'CWK';
5396 */
5397
5398
5399 /*
5400 select sum(quantity)*l_po_rate
5401 into l_uncosted
5402 from pa_expenditure_items ei, pa_expenditures exp
5403 where ei.cost_distributed_flag = 'N'
5404 and ei.project_id = G_project_id
5405 and ei.task_id = G_task_id
5406 and ei.po_line_id = P_Po_Line_Id
5407 and ei.system_linkage_function in ('ST','OT')
5408 and ei.expenditure_id = exp.expenditure_id
5409 and exp.person_type = 'CWK';
5410 */
5411
5412 /* Bug 4098920
5413 Select Sum ( Quantity * PA_TRX_IMPORT.GET_PO_PRICE_TYPE_RATE (Project_id , Task_Id , P_Po_Line_Id , po_price_type ) )
5414 into l_uncosted
5415 From
5416 (
5417 select ei.project_id , ei.task_id , ei.po_price_type , sum(quantity) Quantity
5418 from pa_expenditure_items ei, pa_expenditures exp
5419 where ei.cost_distributed_flag = 'N'
5420 and ei.project_id = G_project_id
5421 and ei.task_id = G_task_id
5422 and ei.po_line_id = P_Po_Line_Id
5423 and ei.system_linkage_function in ('ST','OT')
5424 and ei.expenditure_id = exp.expenditure_id
5425 and exp.person_type = 'CWK'
5426 Group By ei.project_id , ei.task_id , ei.po_price_type
5427 );
5428 */
5429
5430
5431 /* Bug 4098920 : Combined the SQLs for Costed and Uncosted EI */
5432 If Is_Po_Line_Task_Processed ( P_Po_Line_Id, G_task_id ) = False Then
5433 Select Sum (
5434 Decode ( cost_distributed_flag,
5435 'N', Quantity * PA_TRX_IMPORT.GET_PO_PRICE_TYPE_RATE (G_project_id , G_task_id , P_Po_Line_Id , po_price_type ), 0
5436
5437 )
5438 ) ,
5439 Sum (
5440 Decode ( cost_distributed_flag,
5441 'Y', denom_raw_cost, 0
5442 )
5443 )
5444 Into l_uncosted, l_costed
5445 From
5446 (
5447 select ei.po_price_type , ei.cost_distributed_flag,
5448 Sum(Decode(ei.cost_distributed_flag, 'N', ei.quantity,0)) Quantity,
5449 Sum(Decode(ei.cost_distributed_flag, 'Y', ei.denom_raw_cost,0)) denom_raw_cost
5450 from pa_expenditure_items ei, pa_expenditures exp
5451 where ei.project_id = G_project_id
5452 and ei.task_id = G_task_id
5453 and ei.po_line_id = P_Po_Line_Id
5454 and ei.system_linkage_function in ('ST','OT')
5455 and ei.expenditure_id = exp.expenditure_id
5456 and exp.person_type = 'CWK'
5457 Group By ei.po_price_type , ei.cost_distributed_flag
5458 );
5459
5460 Else
5461 l_uncosted := 0;
5462 l_costed := 0;
5463 End If;
5464
5465 IF PG_DEBUG = 'Y' THEN
5466 pa_debug.G_err_stage := 'Get the Processed Amount for Line ID : '||P_Po_Line_Id || ' and Task ID '||G_task_id;
5467 log_message('log_message: ' || pa_debug.G_err_stage,1);
5468 END IF;
5469
5470 po_processed_amt_chk(P_Po_Line_Id => P_Po_Line_Id
5471 ,P_Task_Id => G_task_id
5472 ,P_Calc_Amt => l_Calc_Amt + nvl(l_uncosted,0) + nvl(l_costed,0)
5473 ,X_processed_amt => l_processed_cost
5474 ,X_status => temp_status);
5475
5476 IF temp_status IS NOT NULL THEN
5477 IF PG_DEBUG = 'Y' THEN
5478 pa_debug.G_err_stage := 'po_processed_amt_chk unable to get a lock';
5479 log_message('log_message: ' || pa_debug.G_err_Stage);
5480 END IF;
5481 X_status := temp_status;
5482 pa_cc_utils.reset_curr_function;
5483 RETURN;
5484 END IF;
5485
5486 IF 0 <= (nvl(G_Po_Line_Amt,0) - nvl(l_processed_cost,0)) then /* Bug 4098920 */
5487 l_cwk_amt_updated := 'Y' ;
5488 else
5489 x_status := 'INSUFFICIENT_PO_AMOUNT';
5490
5491 /* Undo changes that are done by po_processed_amt_chk ***/
5492 undo_processed_amt_chk(P_Po_Line_Id
5493 ,G_Task_Id /* Bug # 3609926 : Changed to G_TASK_ID from P_TASK_ID */
5494 ,l_Calc_Amt ) ;
5495 pa_cc_utils.reset_curr_function;
5496 RETURN;
5497 END IF;
5498
5499 /* po amount check */
5500
5501 END IF; /* po attributes are not null */
5502
5503 /* Bug # 3639470 : Vendor ID is not populated in case of UnAccounted/Uncosted ERs */
5504
5505 If x_system_linkage = 'ER' And NVL(P_Person_Type,'EMP') = 'CWK' AND
5506 ( NVL(G_trx_costed,'N') <> 'Y' OR NVL(G_gl_accted_flag,'N') <> 'Y' ) Then
5507
5508 hr_po_info.get_vendor_for_primary_asg (
5509 p_person_id => G_person_id ,
5510 p_effective_date => Trunc(X_ei_date) , --Bug 3891559
5511 p_vendor_id => G_Vendor_id,
5512 p_vendor_site_id => G_Vendor_Site_id
5513 );
5514
5515 If (G_Vendor_id Is Null or G_Vendor_Site_id Is Null ) Then
5516 x_status := 'PA_INVALID_SUPPLIER_INFO';
5517 pa_cc_utils.reset_curr_function;
5518 Return;
5519 End If;
5520
5521 End If;
5522
5523
5524
5525
5526
5527
5528
5529 -- ==========================================================================
5530 -- Verify that transaction does not violate any transaction controls,
5531 -- including transaction control extensions
5532 --
5533 -- DFF Upgrade:
5534 -- Calls pa_transactions_pub.validate_dff
5535 IF PG_DEBUG = 'Y' THEN
5536 pa_debug.G_err_stage := 'Calling pa_transactions_pub.validate_dff';
5537 log_message('log_message: ' || pa_debug.G_err_Stage);
5538 END IF;
5539
5540 pa_transactions_pub.validate_dff(
5541 p_dff_name => 'PA_EXPENDITURE_ITEMS_DESC_FLEX',
5542 p_attribute_category => X_att_cat,
5543 p_attribute1 => X_att1,
5544 p_attribute2 => X_att2,
5545 p_attribute3 => X_att3,
5546 p_attribute4 => X_att4,
5547 p_attribute5 => X_att5,
5548 p_attribute6 => X_att6,
5549 p_attribute7 => X_att7,
5550 p_attribute8 => X_att8,
5551 p_attribute9 => X_att9,
5552 p_attribute10 => x_att10,
5553 x_status_code => temp_status,
5554 x_error_message => temp_dff_msg);
5555
5556 IF (temp_status IS NOT NULL) THEN
5557 IF PG_DEBUG = 'Y' THEN
5558 log_message('log_message: ' || temp_dff_msg,1);
5559 log_message('log_message: ' || temp_status,1);
5560 END IF;
5561 X_status := 'PA_DFF_VALIDATION_FAILED';
5562
5563
5564 /*** CWK Changes : Now Undo changes that are done by po_processed_amt_chk ***/
5565 IF l_cwk_amt_updated = 'Y' THEN
5566 undo_processed_amt_chk(P_Po_Line_Id
5567 ,P_Task_Id
5568 ,l_Calc_Amt
5569 );
5570 END IF;
5571 pa_cc_utils.reset_curr_function;
5572 RETURN;
5573 END IF;
5574
5575 IF PG_DEBUG = 'Y' THEN
5576 pa_debug.G_err_stage := 'Calling pa_transactions_pub.validate_transaction';
5577 log_message('log_message: ' || pa_debug.G_err_Stage);
5578 END IF;
5579
5580 If PA_TRX_IMPORT.Get_GVal_ProjTskEi_Date = 'Y' then -- Added for BUG6931833
5581
5582 pa_transactions_pub.validate_transaction(
5583 X_project_id => G_project_id
5584 , X_task_id => G_task_id
5585 , X_ei_date => X_ei_date
5586 , X_expenditure_type => X_etype
5587 , X_non_labor_resource => X_nlr
5588 , X_person_id => G_person_id
5589 , X_quantity => X_qty
5590 , X_denom_currency_code => X_denom_currency_code
5591 , X_acct_currency_code => G_accounting_currency_code
5592 , X_denom_raw_cost => X_denom_raw_cost
5593 , X_acct_raw_cost => X_acct_raw_cost
5594 , X_acct_rate_type => G_acct_rate_type
5595 , X_acct_rate_date => X_acct_rate_date
5596 , X_acct_exchange_rate => X_acct_exchange_rate
5597 , X_transfer_ei => NULL
5598 -- Trx_import enhancement: If G_verride_to_org_id is not NULL,
5599 -- then that means we will check override to organization
5600 , X_incurred_by_org_id => nvl(G_override_to_org_id, G_org_id)
5601 , X_nl_resource_org_id => G_nlro_id
5602 , X_transaction_source => X_trx_src
5603 -- Bug 987539: Used to be hard code to 'PAXTRTRX'
5604 -- changing it to use the parameter validate_item was called
5605 , X_calling_module => X_module
5606 , X_vendor_id => NULL
5607 , X_entered_by_user_id => G_user
5608 , X_attribute_category => X_att_cat
5609 , X_attribute1 => X_att1
5610 , X_attribute2 => X_att2
5611 , X_attribute3 => X_att3
5612 , X_attribute4 => X_att4
5613 , X_attribute5 => X_att5
5614 , X_attribute6 => X_att6
5615 , X_attribute7 => X_att7
5616 , X_attribute8 => X_att8
5617 , X_attribute9 => X_att9
5618 , X_attribute10 => X_att10
5619 , X_attribute11 => NULL
5620 , X_attribute12 => NULL
5621 , X_attribute13 => NULL
5622 , X_attribute14 => NULL
5623 , X_attribute15 => NULL
5624 , X_msg_application => temp_msg_application
5625 , X_msg_type => temp_msg_type
5626 , X_msg_token1 => temp_msg_token1
5627 , X_msg_token2 => temp_msg_token2
5628 , X_msg_token3 => temp_msg_token3
5629 , X_msg_count => temp_msg_count
5630 , X_msg_data => temp_status
5631 , X_billable_flag=> temp_bill_flag
5632 -- PA-I Changes
5633 -- Added Assignment_Id and Work_Type_Id
5634 , p_projfunc_currency_code => X_Projfunc_Currency_Code
5635 , p_projfunc_cost_rate_type => G_projfunc_cost_rate_type
5636 , p_projfunc_cost_rate_date => X_Projfunc_Cost_Rate_Date
5637 , p_projfunc_cost_exchg_rate => X_projfunc_cost_exchange_rate
5638 , P_Assignment_Id => G_Assignment_Id
5639 , P_Work_Type_Id => G_Work_Type_Id
5640 -- PA-J Txn Ctrl Changes
5641 , P_SYS_LINK_FUNCTION => x_system_linkage
5642 , P_Po_Header_Id => P_Po_Header_Id /* cwk */
5643 , P_Po_Line_Id => P_Po_Line_Id
5644 , P_Person_Type => P_Person_Type
5645 , P_Po_Price_Type => P_Po_Price_Type
5646 -- 10253400: Payroll integration enhancement for 12.2.. start
5647 , p_job_id => G_job_id
5648 , p_location_id => G_Location_Id
5649 , p_pay_element_type_id => p_pay_element_type_id
5650 ,P_payroll_accrual_flag =>g_payroll_accrual_flag); ---- Added for payroll billable_flag changes for 12.2 bug#12344689
5651 -- 10253400: Payroll integration enhancement for 12.2.. end
5652
5653 END IF;
5654
5655 IF PG_DEBUG = 'Y' THEN
5656 pa_debug.G_err_stage := 'After pa_transactions_pub.validate_transaction';
5657 log_message('log_message: ' || pa_debug.G_err_Stage);
5658 END IF;
5659
5660 -- IF G_skip_tc_flag <> 'Y' THEN /* commented for Bug # 2108456 */
5661
5662 IF ( temp_msg_type = 'E' AND temp_status IS NOT NULL ) THEN
5663
5664 IF PG_DEBUG = 'Y' THEN
5665 pa_debug.G_err_stage := 'Validate_transaction has failed' ;
5666 log_message('log_message: ' || pa_debug.G_err_Stage);
5667 END IF;
5668
5669 X_status := temp_status;
5670
5671 /*** CWK Changes : Now Undo changes that are done by po_processed_amt_chk ***/
5672 IF l_cwk_amt_updated = 'Y' THEN
5673 undo_processed_amt_chk(P_Po_Line_Id
5674 ,P_Task_Id
5675 ,l_Calc_Amt );
5676 END IF;
5677
5678 pa_cc_utils.reset_curr_function;
5679 RETURN;
5680
5681 END IF;
5682
5683 -- END IF ; /* commented for Bug # 2108456 */
5684 X_bill_flag := temp_bill_flag; /*added for bug 6509828*/
5685 --
5686 -- The following section of the code has been written
5687 -- for funds check related changes
5688 --
5689 --PA-J Receipt Accrual Changes: Added AP VARIANCE and PO RECEIPT
5690 IF G_Process_Funds_Flag = 'Y' AND ---{
5691 --Pa-K Changes: Using the process_funds_check attributes of the source to perform funds checking
5692 --X_trx_src in ('AP INVOICE', 'AP VARIANCE', 'PO RECEIPT', 'AP NRTAX', 'PO RECEIPT NRTAX') AND
5693 X_acct_raw_cost <> 0 AND
5694 nvl(G_gl_accted_flag,'N') = 'Y' AND
5695 G_SobId = G_RecvrSobId AND
5696 --Pa_Funds_Control_Utils.Get_Fnd_Reqd_Flag(G_project_id, 'STD') = 'Y'
5697 -- REL12 AP Lines Uptake
5698 NVL(p_fc_document_type, 'NOT' ) <> 'NOT' THEN
5699
5700 IF PG_DEBUG = 'Y' THEN
5701 pa_debug.G_err_stage := 'Before calling tr_import_funds_check';
5702 log_message('log_message: ' || pa_debug.G_err_Stage);
5703 log_message('log_message: Value of pa_date is= ' || pa_date);
5704 log_message('log_message: Value of X_trx_src is= ' || X_trx_src);
5705 log_message('log_message: Value of X_acct_raw_cost is= ' || X_acct_raw_cost);
5706 log_message('log_message: Value of p_adj_exp_item_id is= ' || p_adj_exp_item_id);
5707 log_message('log_message: Value of x_txn_interface_id is= ' || x_txn_interface_id);
5708 log_message('log_message: Value of p_fc_document_type is= ' || p_fc_document_type);
5709 END IF;
5710
5711 --Bug 2905892
5712 --Assign txn gl_Date for insert of the reversing and EXP lines into pa_bc_packets
5713 G_FC_Gl_Date := X_Gl_Date;
5714
5715 tr_import_funds_check (p_pa_date => pa_date,
5716 p_txn_source => X_trx_src,
5717 p_acct_raw_cost => X_acct_raw_cost,
5718 p_adj_exp_item_id => p_adj_exp_item_id,
5719 p_txn_interface_id => x_txn_interface_id,
5720 p_fc_document_type => p_fc_document_type,
5721 x_packet_id => l_packet_id,
5722 x_error_message_code => l_fc_error_msg,
5723 x_error_stage => l_fc_error_stage,
5724 x_return_status => l_fc_return_status);
5725
5726 IF PG_DEBUG = 'Y' THEN
5727 log_message('log_message: After Calling tr_import_funds_check');
5728 log_message('log_message: Value of l_packet_id='||l_packet_id);
5729 log_message('log_message: Value of l_fc_error_msg='||l_fc_error_msg);
5730 log_message('log_message: Value of l_fc_error_stage='||l_fc_error_stage);
5731 log_message('log_message: Value of l_fc_return_status='||l_fc_return_status);
5732 END IF;
5733
5734 IF l_fc_return_status <> FND_API.G_RET_STS_SUCCESS then
5735
5736 IF PG_DEBUG = 'Y' THEN
5737 pa_debug.G_err_stage := 'Call to tr_import_funds_check did not succeed';
5738 log_message('log_message: ' || pa_debug.G_err_Stage);
5739 END IF;
5740
5741 x_status := l_fc_error_msg ;
5742 pa_cc_utils.reset_curr_function;
5743 return;
5744 END IF;
5745
5746 IF PG_DEBUG = 'Y' THEN
5747 pa_debug.G_err_stage := 'Call to internal funds check packet insert success';
5748 log_message('log_message: ' || pa_debug.G_err_Stage);
5749 log_message('log_message: Before Calling Pa_Funds_Control_Pkg.pa_funds_check');
5750 END IF;
5751
5752 IF Pa_Funds_Control_Pkg.pa_funds_check(p_calling_module => 'TRXIMPORT',
5753 p_conc_flag => 'Y',
5754 p_set_of_book_id => 1,
5755 p_packet_id => l_packet_id,
5756 p_mode => 'R',
5757 p_partial_flag => 'N',
5758 x_return_status => l_fc_return_status,
5759 x_error_stage => l_fc_error_stage,
5760 x_error_msg => l_fc_error_msg) THEN
5761
5762 IF PG_DEBUG = 'Y' THEN
5763 log_message('log_message: After Calling Pa_Funds_Control_Pkg.pa_funds_check');
5764 log_message('log_message: Value of l_fc_return_status='||l_fc_return_status);
5765 log_message('log_message: Value of l_fc_error_stage='||l_fc_error_stage);
5766 log_message('log_message: Value of l_fc_error_msg='||l_fc_error_msg);
5767 END IF;
5768
5769 IF l_fc_return_status <> FND_API.G_RET_STS_SUCCESS then
5770
5771 IF PG_DEBUG = 'Y' THEN
5772 pa_debug.G_err_stage := 'Call to funds check not success';
5773 log_message('log_message: ' || pa_debug.G_err_Stage);
5774 END IF;
5775
5776 --x_status := l_fc_return_status ;
5777 x_status := 'PA_FC_ERROR' ;
5778 pa_cc_utils.reset_curr_function;
5779 return;
5780 END IF;
5781
5782 IF PG_DEBUG = 'Y' THEN
5783 pa_debug.G_err_stage := 'Check if there are any failed records';
5784 END IF;
5785 log_message('log_message: ' || pa_debug.G_err_Stage);
5786
5787 Open c_check_fail(l_packet_id);
5788 Fetch c_check_fail
5789 into l_dummy ;
5790
5791 close c_check_fail ;
5792
5793 IF PG_DEBUG = 'Y' THEN
5794 pa_debug.G_err_stage := 'After select to check for funds check failed records';
5795 log_message('log_message: ' || pa_debug.G_err_Stage);
5796 END IF;
5797 IF l_dummy = 'X' Then
5798
5799 IF PG_DEBUG = 'Y' THEN
5800 pa_debug.G_err_stage := 'This transaction failed funds check';
5801 log_message('log_message: ' || pa_debug.G_err_Stage);
5802 END IF;
5803
5804 x_status := 'PA_FC_ERROR' ;
5805
5806 pa_cc_utils.reset_curr_function;
5807 return;
5808 ELSE
5809 IF PG_DEBUG = 'Y' THEN
5810 pa_debug.G_err_stage := 'This transaction passed funds check';
5811 log_message('log_message: ' || pa_debug.G_err_Stage);
5812 END IF;
5813
5814 NULL;
5815
5816 END IF;
5817 ELSE
5818
5819 IF PG_DEBUG = 'Y' THEN
5820 pa_debug.G_err_stage := 'Error during funds check';
5821 log_message('log_message: ' || pa_debug.G_err_Stage);
5822 END IF;
5823
5824 x_status := 'PA_FC_UNEXP_ERROR' ;
5825 pa_cc_utils.reset_curr_function;
5826 return;
5827 END IF;
5828 IF PG_DEBUG = 'Y' THEN
5829 pa_debug.G_err_stage := 'Done with funds check';
5830 log_message('log_message: ' || pa_debug.G_err_Stage);
5831 END IF;
5832 END IF; --- }
5833
5834 /* X_bill_flag := temp_bill_flag; commented for bug 6509828*/
5835
5836 --PA-J Txn Ctrl Changes
5837 --Assignment_Id is overwritten by the User in PATC/PATCX.
5838 --Since p_assignment_id in PATC cannot be changed to IN/OUT, we are using the
5839 --the global variable set in PATC.
5840 --Thus assign PATC.global variable to G_Assignment_Id here for sys links ER,ST,OT.
5841 if (x_system_linkage in ('ST', 'OT', 'ER')) then
5842 pa_debug.G_err_stage := 'Override Assignment Id';
5843 G_Assignment_Id := PATC.G_OVERIDE_ASSIGNMENT_ID;
5844
5845 /* Start of bug 2648550 */
5846 G_Work_Type_Id := PATC.G_OVERIDE_WORK_TYPE_ID;
5847 G_Tp_Amt_Type_Code := PATC.G_OVERIDE_TP_AMT_TYPE_CODE;
5848 X_Assignment_Name := PATC.G_OVERIDE_ASSIGNMENT_NAME ;
5849 X_Work_Type_Name := PATC.G_OVERIDE_WORK_TYPE_NAME;
5850 /* End of bug 2648550 */
5851
5852 IF PG_DEBUG = 'Y' THEN
5853 log_message('log_message: ' || 'Overriding Assignment Id = ' || G_Assignment_Id);
5854 END IF;
5855 end if;
5856
5857 IF PG_DEBUG = 'Y' THEN
5858 pa_debug.G_err_stage := 'Done with Validate Item';
5859 log_message('log_message: ' || pa_debug.G_err_Stage);
5860 END IF;
5861 pa_cc_utils.reset_curr_function; /* bug 2181553 */
5862
5863 -- S.N. CWK changes -> hkulkarn ---> If called from form, release the locks.
5864
5865 IF (X_module = 'EXTERNAL') THEN
5866 release_po_line_task_lock;
5867 init_po_amt_chk; /* Bug # 3609926 : To free the PL/SQL tables if called from the form */
5868 END IF;
5869
5870 -- E.N. CWK changes
5871
5872 EXCEPTION
5873 WHEN OTHERS THEN
5874 IF PG_DEBUG = 'Y' THEN
5875 log_message('log_message: ' || 'In OTHERS of ValidateItem');
5876 log_message('log_message: ' || pa_debug.G_err_Stack,1);
5877 log_message('log_message: ' || SQLERRM,1);
5878 log_message('log_message: ' || pa_debug.G_err_stage,1);
5879 END IF;
5880
5881 release_po_line_task_lock; -- bug 3512984
5882
5883 pa_cc_utils.reset_curr_function; /* bug 2181553 */
5884
5885 RAISE ;
5886 END ValidateItem;
5887
5888 PROCEDURE ValidateOrgId (
5889 X_org_id IN NUMBER
5890 , X_status OUT NOCOPY VARCHAR2 )
5891 IS
5892 BEGIN
5893 pa_cc_utils.set_curr_function('ValidateOrgId');
5894
5895 --PA.K Changes: For Performance moved the Multi-Org check to init procedure.
5896 --IF pa_utils.pa_morg_implemented = 'Y' THEN
5897
5898 /* Added for bug 3590027 */
5899 IF PG_DEBUG = 'Y' THEN
5900 log_message('Before call, G_Morg: ' || G_Morg);
5901 END IF;
5902
5903 If G_Morg is Null Then
5904 G_Morg := pa_utils.pa_morg_implemented;
5905 End If;
5906
5907 IF PG_DEBUG = 'Y' THEN
5908 log_message('After call, G_Morg: ' || G_Morg);
5909 END IF;
5910 /* Added for bug 3590027 End */
5911
5912 IF G_Morg = 'Y' THEN
5913 IF X_org_id IS NULL THEN
5914 X_status := 'MISSING_ORG_ID';
5915 pa_cc_utils.reset_curr_function;
5916 RETURN;
5917 END IF;
5918 END IF;
5919
5920 pa_cc_utils.reset_curr_function;
5921 EXCEPTION
5922 WHEN OTHERS THEN
5923 IF PG_DEBUG = 'Y' THEN
5924 log_message('log_message: ' || pa_debug.G_err_Stack,1);
5925 log_message('log_message: ' || pa_debug.G_err_Stage,1);
5926 log_message('log_message: ' || SQLERRM,1);
5927 END IF;
5928 RAISE ;
5929
5930 END ValidateOrgId;
5931
5932 -- Added the function below for bug number 1275169.
5933 /* For bug 1426802 change employee_number from NUMBER to VARCHAR2 */
5934
5935 FUNCTION GetOrgName(employee_number IN VARCHAR2,
5936 expenditure_item_date IN DATE,
5937 business_group_name IN VARCHAR2,
5938 person_type IN VARCHAR2) RETURN VARCHAR2 IS
5939 X_emp_id NUMBER;
5940 /* Bug No.2487147, UTF8 change, used %TYPE for X_org_name */
5941 /* X_org_name VARCHAR2(60); */
5942 X_org_name hr_organization_units.name%TYPE;
5943 BEGIN
5944
5945 --PA-K Changes: Caching the values.
5946
5947 if employee_number is null then
5948 RETURN NULL;
5949 else
5950
5951 If (G_OrgNameEmpNum = employee_number) and
5952 (trunc(G_OrgNameDate) = trunc(expenditure_item_date)) and
5953 (G_OrgNameBGName = business_group_name) and
5954 (G_person_type = nvl(person_type,'EMP'))Then
5955
5956 RETURN G_OrgNameOrgName;
5957
5958 Else
5959
5960 G_OrgNameBGId := pa_utils2.GetBusinessGroupId(business_group_name);
5961
5962 BEGIN
5963
5964 pa_utils2.GetEmpId ( P_Business_Group_Id => G_OrgNameBGId
5965 , P_Employee_Number => employee_number
5966 , X_Employee_Id => X_emp_id
5967 , P_Person_Type => person_type
5968 , P_EiDate => expenditure_item_date);
5969
5970 EXCEPTION
5971 WHEN NO_DATA_FOUND THEN
5972 NULL;
5973 WHEN TOO_MANY_ROWS THEN
5974 NULL;
5975 WHEN OTHERS THEN
5976 NULL;
5977 END;
5978
5979 --X_emp_id := pa_utils.GetEmpId(employee_number) ;
5980 if X_emp_id is null then
5981 RETURN NULL;
5982 else
5983
5984 X_org_name := pa_expenditures_utils.getorgtlname(pa_utils.GetEmpOrgId(X_emp_id, expenditure_item_date));
5985
5986 G_OrgNameEmpNum := employee_number;
5987 G_OrgNameDate := expenditure_item_date;
5988 G_OrgNameBGName := business_group_name;
5989 G_OrgNameOrgName := X_org_name;
5990 G_person_type := nvl(person_type,'EMP');
5991
5992 RETURN X_org_name;
5993 end if;
5994
5995 End If;
5996
5997 end if;
5998 EXCEPTION
5999 WHEN NO_DATA_FOUND THEN
6000 RETURN null;
6001 WHEN OTHERS THEN
6002 RAISE;
6003 END GetOrgName;
6004 --
6005 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
6006 --
6007 PROCEDURE set_supplier_cost_eidate( X_transaction_source IN VARCHAR2
6008 , X_batch IN VARCHAR2
6009 , X_xface_id IN NUMBER )
6010 IS
6011 V_src_txnifIDTab PA_PLSQL_DATATYPES.IdTabTyp;
6012 V_dst_txnifIDTab PA_PLSQL_DATATYPES.IdTabTyp;
6013 V_dst_ifIDTab PA_PLSQL_DATATYPES.IdTabTyp;
6014 v_src_EiDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6015 v_dst_EiDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6016 v_dst_txnstatcdTab PA_PLSQL_DATATYPES.Char1TabTyp;
6017 v_doc_headerIDTab PA_PLSQL_DATATYPES.IdTabTyp;
6018 v_week_ending_dtTab PA_PLSQL_DATATYPES.DateTabTyp;
6019
6020
6021 BEGIN
6022 pa_cc_utils.set_curr_function('Set_supplier_cost_eidate');
6023
6024 IF PG_DEBUG = 'Y' THEN
6025 log_message('log_message: Set_supplier_cost_eidate begins ' );
6026 log_message('log_message: Populate bulk variables ' );
6027 END IF;
6028 v_src_txnifIDTab.DELETE ;
6029 v_src_eidateTab.DELETE ;
6030 v_dst_ifIDTab.DELETE ;
6031 v_dst_TxnifIDTab.DELETE ;
6032 v_dst_eidateTab.DELETE ;
6033 v_dst_txnstatcdTab.DELETE ;
6034 v_doc_headerIDTab.DELETE ;
6035 v_week_ending_dtTab.DELETE ;
6036
6037 select a.txn_interface_id,
6038 a.expenditure_item_date,
6039 b.interface_id,
6040 b.txn_interface_id,
6041 b.expenditure_item_date,
6042 b.transaction_status_code
6043 BULK Collect into
6044 v_src_txnifIDTab,
6045 v_src_eidateTab,
6046 v_dst_ifIDTab,
6047 v_dst_TxnifIDTab,
6048 v_dst_eidateTab,
6049 v_dst_txnstatcdTab
6050 from pa_transaction_interface_all a,
6051 pa_transaction_interface_all b
6052 where a.interface_id = X_xface_id
6053 and a.transaction_source = X_transaction_source
6054 and a.batch_name = X_batch
6055 and a.transaction_source = b.transaction_source
6056 and b.interface_id <> X_xface_id
6057 and a.cdl_system_reference1 = b.cdl_system_reference1
6058 and a.cdl_system_reference2 = b.cdl_system_reference2
6059 and a.cdl_system_reference3 = b.cdl_system_reference3
6060 and NVL(a.cdl_system_reference4,'0') = NVL(b.cdl_system_reference4, '0')
6061 and NVL(a.cdl_system_reference5,0) = NVL(b.cdl_system_reference5,0)
6062 and b.transaction_status_code <> 'A'
6063 and NVL(a.expenditure_item_id, -1) <> 0
6064 and a.adjusted_expenditure_item_id is NULL ;
6065
6066 IF PG_DEBUG = 'Y' THEN
6067 log_message('log_message: v_src_txnifIDTab.count '|| v_src_txnifIDTab.count );
6068 END IF ;
6069
6070 IF v_src_txnifIDTab.count > 0 then
6071 IF PG_DEBUG = 'Y' THEN
6072 log_message('log_message: Updating the ei date ' );
6073 END IF ;
6074
6075 FORALL indx in 1..v_src_TxnIfIDTab.count
6076 Update pa_transaction_interface_all
6077 set expenditure_item_date = v_dst_eidateTab(indx)
6078 where txn_interface_id = v_src_TxnIfIDTab(indx) ;
6079
6080
6081 IF PG_DEBUG = 'Y' THEN
6082 log_message('log_message: Updating the ei date on adjusted transactions(reversals) ' );
6083 END IF ;
6084
6085 FORALL indx in 1..v_src_TxnIfIDTab.count
6086 Update pa_transaction_interface_all
6087 set expenditure_item_date = v_dst_eidateTab(indx)
6088 where adjusted_txn_interface_id = v_src_TxnIfIDTab(indx)
6089 and net_zero_adjustment_flag = 'Y' ;
6090
6091 IF PG_DEBUG = 'Y' THEN
6092 log_message('log_message: Determine the week ending date for the affected transactions. ' );
6093 END IF ;
6094
6095 select pa_utils.getweekending(max(a.expenditure_item_date)),
6096 a.cdl_system_reference2
6097 BULK Collect into
6098 v_week_ending_dtTab,
6099 v_doc_headerIDTab
6100 from pa_transaction_interface_all a,
6101 pa_transaction_interface_all b
6102 where a.interface_id = X_xface_id
6103 and a.transaction_source = X_transaction_source
6104 and a.batch_name = X_batch
6105 and a.transaction_source = b.transaction_source
6106 and b.interface_id <> X_xface_id
6107 and a.cdl_system_reference1 = b.cdl_system_reference1
6108 and a.cdl_system_reference2 = b.cdl_system_reference2
6109 and a.cdl_system_reference3 = b.cdl_system_reference3
6110 and NVL(a.cdl_system_reference4,'0') = NVL(b.cdl_system_reference4, '0')
6111 and nvl(a.cdl_system_reference5,0) = nvl(b.cdl_system_reference5 ,0)
6112 and b.transaction_status_code <> 'A'
6113 group by a.cdl_system_reference2 ;
6114
6115 IF v_doc_headerIDTab.count > 0 THEN
6116
6117 IF PG_DEBUG = 'Y' THEN
6118 log_message('log_message: Update the weekending date... '|| v_doc_headerIDTab.count );
6119 END IF ;
6120
6121 FORALL indx in 1..v_doc_headerIDTab.count
6122 UPDATE pa_transaction_interface_all
6123 set expenditure_ending_date = v_week_ending_dtTab(indx)
6124 where interface_id = X_xface_id
6125 and transaction_source = X_transaction_source
6126 and batch_name = X_batch
6127 and cdl_system_reference2 =v_doc_headerIDTab(indx) ;
6128
6129 END IF ;
6130 IF PG_DEBUG = 'Y' THEN
6131 log_message('log_message: Deleting the previous batch rejected transactions. ' );
6132 END IF ;
6133 FORALL indx in 1..v_dst_TxnIfIdTab.count
6134 delete from pa_transaction_interface_all
6135 where txn_interface_id = v_dst_TxnIfIdTab(indx) ;
6136
6137 END IF ;
6138 IF PG_DEBUG = 'Y' THEN
6139 log_message('log_message: End of set_supplier_cost_eidate. ' );
6140 END IF ;
6141
6142 pa_cc_utils.reset_curr_function;
6143 END set_supplier_cost_eidate ;
6144
6145 PROCEDURE import1( X_transaction_source IN VARCHAR2
6146 , X_batch IN VARCHAR2
6147 , X_xface_id IN NUMBER
6148 , X_userid IN NUMBER
6149 , X_online_exp_comment IN VARCHAR2 )
6150 IS
6151
6152 dummy NUMBER;
6153 G_expenditure_id NUMBER(15);
6154
6155 temp_status NUMBER DEFAULT NULL;
6156 X_billable_flag VARCHAR2(1);
6157 X_org_status VARCHAR2(30);
6158 X_status VARCHAR2(30);
6159
6160 -- REL12 AP Lines Uptake
6161 -- Cash based accounting support
6162 --
6163 l_status VARCHAR2(30);
6164
6165 l_return_status Varchar2(10);
6166
6167 error_msg VARCHAR2(512);
6168
6169 FIRST_RECORD BOOLEAN DEFAULT TRUE;
6170 GROUP_CREATED BOOLEAN DEFAULT TRUE;
6171 REJECT_EXP BOOLEAN DEFAULT FALSE;
6172
6173 /*Added three fields local for bug 2048868*/
6174 prev_acct_rate_type varchar2(30);
6175 prev_acct_rate_date date;
6176 prev_acct_exchange_rate Number;
6177 prev_denom_currency_code varchar2(30);
6178 prev_person_type varchar2(30);
6179
6180 -- REL12 AP Lines Uptake
6181 -- Cash based accounting support
6182 --
6183 l_rejectedSysRef5 NUMBER ;
6184 l_invoice_id NUMBER ;
6185 l_payment_status_flag varchar2(1) ;
6186
6187 CURSOR c_final_payment is
6188 SELECT payment_status_flag
6189 FROM ap_payment_schedules_all pmt
6190 WHERE pmt.invoice_id = l_invoice_id
6191 AND pmt.payment_status_flag = 'Y' ;
6192
6193
6194 --Bug 987539: New variable to identify calling module
6195 v_calling_module VARCHAR2(30);
6196
6197 CURSOR TrxBatches
6198 IS
6199 SELECT
6200 xc.transaction_source
6201 , xc.batch_name
6202 , xc.system_linkage_function
6203 , xc.batch_name ||xc.system_linkage_function|| to_char(X_xface_id) exp_group_name
6204 , xc.transaction_count
6205 , xc.processed_count
6206 FROM
6207 pa_transaction_xface_control xc
6208 WHERE
6209 xc.transaction_source = X_transaction_source
6210 AND xc.batch_name = nvl(X_batch, xc.batch_name)
6211 AND xc.status = 'PENDING'
6212 --PA-K Changes: Added intermediate_flag
6213 ORDER BY intermediate_flag desc;
6214
6215 TrxBatch TrxBatches%ROWTYPE;
6216
6217 /* Trx_import enhancment: Modify the expend field in order to change the
6218 expenditure grouping logic
6219 PA-K Changes: Added the new ID columns.
6220 Implementing 4 cursors depending on the system linkage and pre-defined flag
6221 Expend and Expend2 will be constructed from the PLSQL tables in which the
6222 values have been selected.
6223 */
6224
6225 /** Modified the following cursors to support ID columns for Non-Oracle Txns
6226 *** The current code is based on four cursors - two cursors for pre-defined sources
6227 *** (one for ST, OT and the other for other than ST and OT) - two other cursors
6228 *** for non-oracle sources of which one for ST, OT and the other for rest Sys Links
6229 *** Now these four are collapsed into two cursors - irrespective of a transaction
6230 *** source whether pre-defined on user-defined - once cursor for ST and OT and the
6231 *** other for system linkages other than ST and OT
6232 *** Cursors are removed from the code and not commented for the sake of clarity.
6233 *** Hence there will be only two cursors, defined, opened, fetched from and closed
6234 *** with these changes
6235 **/
6236
6237 /* TrxRecs1 is for ST, OT */
6238 CURSOR TrxRecs1 ( X_transaction_source VARCHAR2
6239 , current_batch VARCHAR2
6240 , curr_etype_class_code VARCHAR2 )
6241 IS
6242 SELECT
6243 system_linkage
6244 , trunc(expenditure_ending_date) expenditure_ending_date
6245 , employee_number
6246
6247 /* Moving the logic for getting organization name based on the G_emp_oride_flag to TrxRec cursor
6248 for fix 2686544 */
6249 , organization_name
6250 /* Bug fix 2655157 starts */
6251 /* , decode (G_emp_org_oride,
6252 'Y',
6253 decode (organization_name,
6254 null,
6255 GetOrgName(employee_number, expenditure_item_date, person_business_group_name),
6256 organization_name),
6257 decode (employee_number,
6258 null,
6259 organization_name,
6260 GetOrgName(employee_number, expenditure_item_date, person_business_group_name))
6261 ) organization_name */
6262 /* decode( employee_number, NULL, organization_name,
6263 decode(G_emp_org_oride,'Y',organization_name,NULL))
6264 organization_name */
6265 /* Bug fix 2655157 ends */
6266 , trunc(expenditure_item_date) expenditure_item_date
6267 , project_number
6268 , task_number
6269 , expenditure_type
6270 , non_labor_resource
6271 , non_labor_resource_org_name
6272 , quantity
6273 , raw_cost
6274 , raw_cost_rate
6275 , orig_transaction_reference
6276 , attribute_category
6277 , attribute1
6278 , attribute2
6279 , attribute3
6280 , attribute4
6281 , attribute5
6282 , attribute6
6283 , attribute7
6284 , attribute8
6285 , attribute9
6286 , attribute10
6287 , expenditure_comment
6288 , interface_id
6289 , expenditure_id
6290 , nvl(unmatched_negative_txn_flag, 'N') unmatched_negative_txn_flag
6291 , to_number( NULL ) expenditure_item_id
6292 , org_id org_id
6293 , dr_code_combination_id
6294 , cr_code_combination_id
6295 , cdl_system_reference1
6296 , cdl_system_reference2
6297 , cdl_system_reference3
6298 , cdl_system_reference4
6299 , cdl_system_reference5
6300 , trunc(gl_date) gl_date --7535550
6301 , burdened_cost
6302 , burdened_cost_rate
6303 , receipt_currency_amount
6304 , receipt_currency_code
6305 , receipt_exchange_rate
6306 , denom_currency_code
6307 , denom_raw_cost
6308 , denom_burdened_cost
6309 , trunc(acct_rate_date) acct_rate_date --7535550
6310 , acct_rate_type
6311 , acct_exchange_rate
6312 -- , pa_currency.round_currency_amt1(acct_raw_cost) acct_raw_cost -- Bug 7522080
6313 , acct_raw_cost
6314 , acct_burdened_cost
6315 , acct_exchange_rounding_limit
6316 , project_currency_code
6317 , trunc(project_rate_date) project_rate_date --7535550
6318 , project_rate_type
6319 , project_exchange_rate
6320 , orig_exp_txn_reference1
6321 , orig_user_exp_txn_reference
6322 , vendor_number
6323 , orig_exp_txn_reference2
6324 , orig_exp_txn_reference3
6325 , override_to_organization_name
6326 , reversed_orig_txn_reference
6327 , billable_flag
6328 , txn_interface_id
6329 , person_business_group_name
6330 , projfunc_currency_code
6331 , trunc(projfunc_cost_rate_date) projfunc_cost_rate_date --7535550
6332 , projfunc_cost_rate_type
6333 , projfunc_cost_exchange_rate
6334 , project_raw_cost
6335 , project_burdened_cost
6336 , assignment_name
6337 , work_type_name
6338 , nvl(accrual_flag,'N') accrual_flag
6339 , project_id
6340 , task_id
6341 , person_id
6342 , organization_id
6343 , non_labor_resource_org_id
6344 , vendor_id
6345 , override_to_organization_id
6346 , assignment_id
6347 , work_type_id
6348 , person_business_group_id
6349 , po_number /* cwk */
6350 , po_header_id
6351 , po_line_num
6352 , po_line_id
6353 , person_type
6354 , po_price_type
6355 , wip_resource_id
6356 , inventory_item_id
6357 , unit_of_measure
6358 , adjusted_expenditure_item_id
6359 , NVL(fc_document_type, 'NOT')
6360 , NULL document_type
6361 , document_distribution_type -- R12 AP lines uptake : Prepayment changes
6362 , si_assets_addition_flag
6363 , NULL -- adjusted_txn_interface_id
6364 , NULL -- net_zero_adjustment_flag
6365 , NULL -- sc_xfer_code
6366 , 0 -- final_payment_id
6367 -- , agreement_id --FSIO Changes
6368 -- , agreement_number
6369 /* 10253400: Payroll integration enhancement for 12.2..start */
6370 , job_id
6371 , job_name
6372 , location_id
6373 , location_code
6374 , pay_element_type_id
6375 /* 10253400: Payroll integration enhancement for 12.2..end */
6376 /* Start: Added for bug 16220146 */
6377 , cbs_element_name
6378 , cbs_element_id
6379 /* End: Added for bug 16220146 */
6380 FROM pa_transaction_interface
6381 WHERE transaction_source = X_transaction_source
6382 AND batch_name = current_batch
6383 AND transaction_status_code = 'P'
6384 AND system_linkage in ('ST', 'OT')
6385 ORDER BY
6386 expenditure_ending_date DESC
6387 , decode(nvl(person_id,0), 0, employee_number, person_id)
6388 , decode(nvl(organization_id,0), 0, organization_name, organization_id)
6389 , orig_exp_txn_reference1
6390 , orig_user_exp_txn_reference
6391 , decode(nvl(vendor_id,0), 0, vendor_number, vendor_id)
6392 , orig_exp_txn_reference2
6393 , orig_exp_txn_reference3
6394 , denom_currency_code
6395 , acct_rate_date
6396 , acct_rate_type
6397 , acct_exchange_rate
6398 , expenditure_item_date
6399 , decode(nvl(project_id,0), 0, project_number, project_id)
6400 , decode(nvl(task_id,0), 0, task_number, task_id)
6401 , accrual_flag ;
6402
6403
6404 /* TrxRecs2 is for other than ST, OT */
6405
6406 CURSOR TrxRecs2 ( X_transaction_source VARCHAR2
6407 , current_batch VARCHAR2
6408 , curr_etype_class_code VARCHAR2 )
6409 IS
6410 SELECT
6411 system_linkage
6412 , trunc(expenditure_ending_date) expenditure_ending_date
6413 , employee_number
6414
6415 /* Moving the logic for getting organization name based on the G_emp_oride_flag to TrxRec cursor
6416 for fix 2686544 */
6417 , organization_name
6418 /* Bug fix 2655157 starts */
6419 /* , decode (G_emp_org_oride,
6420 'Y',
6421 decode (organization_name,
6422 null,
6423 GetOrgName(employee_number, expenditure_item_date, person_business_group_name),
6424 organization_name),
6425 decode (employee_number,
6426 null,
6427 organization_name,
6428 GetOrgName(employee_number, expenditure_item_date, person_business_group_name))
6429 ) organization_name */
6430 /* decode( employee_number, NULL, organization_name,
6431 decode(G_emp_org_oride,'Y',organization_name,NULL))
6432 organization_name */
6433 /* Bug fix 2655157 ends */
6434 , trunc(expenditure_item_date) expenditure_item_date
6435 , project_number
6436 , task_number
6437 , expenditure_type
6438 , non_labor_resource
6439 , non_labor_resource_org_name
6440 , quantity
6441 , raw_cost
6442 , raw_cost_rate
6443 , orig_transaction_reference
6444 , attribute_category
6445 , attribute1
6446 , attribute2
6447 , attribute3
6448 , attribute4
6449 , attribute5
6450 , attribute6
6451 , attribute7
6452 , attribute8
6453 , attribute9
6454 , attribute10
6455 , expenditure_comment
6456 , interface_id
6457 , expenditure_id
6458 , nvl(unmatched_negative_txn_flag, 'N') unmatched_negative_txn_flag
6459 -- REL12 AP Lines uptake.
6460 -- to_number(NULL) was removed.
6461 , expenditure_item_id
6462 , org_id org_id
6463 , dr_code_combination_id
6464 , cr_code_combination_id
6465 , cdl_system_reference1
6466 , cdl_system_reference2
6467 , cdl_system_reference3
6468 , cdl_system_reference4
6469 , cdl_system_reference5
6470 , trunc(gl_date) gl_date --7535550
6471 , burdened_cost
6472 , burdened_cost_rate
6473 , receipt_currency_amount
6474 , receipt_currency_code
6475 , receipt_exchange_rate
6476 , denom_currency_code
6477 , denom_raw_cost
6478 , denom_burdened_cost
6479 , trunc(acct_rate_date) acct_rate_date --7535550
6480 , acct_rate_type
6481 , acct_exchange_rate
6482 -- , pa_currency.round_currency_amt1(acct_raw_cost) acct_raw_cost -- Bug 7522080
6483 , acct_raw_cost
6484 , acct_burdened_cost
6485 , acct_exchange_rounding_limit
6486 , project_currency_code
6487 , trunc(project_rate_date) project_rate_date --7535550
6488 , project_rate_type
6489 , project_exchange_rate
6490 , orig_exp_txn_reference1
6491 , orig_user_exp_txn_reference
6492 , vendor_number
6493 , orig_exp_txn_reference2
6494 , orig_exp_txn_reference3
6495 , override_to_organization_name
6496 , reversed_orig_txn_reference
6497 , billable_flag
6498 , txn_interface_id
6499 , person_business_group_name
6500 , projfunc_currency_code
6501 , trunc(projfunc_cost_rate_date) projfunc_cost_rate_date --7535550
6502 , projfunc_cost_rate_type
6503 , projfunc_cost_exchange_rate
6504 , project_raw_cost
6505 , project_burdened_cost
6506 , assignment_name
6507 , work_type_name
6508 , nvl(accrual_flag,'N') accrual_flag
6509 , project_id
6510 , task_id
6511 , person_id
6512 , organization_id
6513 , non_labor_resource_org_id
6514 , vendor_id
6515 , override_to_organization_id
6516 , assignment_id
6517 , work_type_id
6518 , person_business_group_id
6519 , po_number /* cwk */
6520 , po_header_id
6521 , po_line_num
6522 , po_line_id
6523 , person_type
6524 , po_price_type
6525 , wip_resource_id
6526 , inventory_item_id
6527 , unit_of_measure
6528 , adjusted_expenditure_item_id
6529 , NVL(fc_document_type, 'NOT' )
6530 , document_type
6531 , document_distribution_type
6532 , si_assets_addition_flag
6533 , adjusted_txn_interface_id
6534 , net_zero_adjustment_flag
6535 , sc_xfer_code -- supplier cost transfer status code.
6536 , 0 -- final_payment_id
6537 -- , agreement_id --FSIO Changes
6538 -- , agreement_number
6539 /* 10253400: Payroll integration enhancement for 12.2..start */
6540 , null job_id
6541 , null job_name
6542 , null location_id
6543 , null location_code
6544 , null pay_element_type_id
6545 /* 10253400: Payroll integration enhancement for 12.2..end */
6546 /* Start: Added for bug 16220146 */
6547 , cbs_element_name
6548 , cbs_element_id
6549 /* End: Added for bug 16220146 */
6550 FROM pa_transaction_interface
6551 WHERE transaction_source = X_transaction_source
6552 AND batch_name = current_batch
6553 AND transaction_status_code = 'P'
6554 AND system_linkage = curr_etype_class_code
6555 ORDER BY
6556 expenditure_ending_date DESC
6557 , decode(nvl(person_id,0), 0, employee_number, person_id)
6558 -- 5389130 added order by criteria.
6559 , decode(nvl(override_to_organization_id ,organization_id), 0, organization_name,
6560 organization_id, organization_id, override_to_organization_id)
6561 , orig_exp_txn_reference1
6562 , orig_user_exp_txn_reference
6563 , decode(nvl(vendor_id,0), 0, vendor_number, vendor_id)
6564 , orig_exp_txn_reference2
6565 , orig_exp_txn_reference3
6566 , denom_currency_code
6567 , acct_rate_date
6568 , acct_rate_type
6569 , acct_exchange_rate
6570 , expenditure_item_date
6571 -- 5389130 added order by criteria.
6572 , decode(adjusted_expenditure_item_id, null, 1, 0, 1, 0)
6573 -- , decode(curr_etype_class_code, 'VI', cdl_system_reference2, '0' ) Commented as part of the Bug 12776739
6574 -- , decode(curr_etype_class_code, 'VI', cdl_system_reference3, '0' ) Commented as part of the Bug 12776739
6575 , decode(curr_etype_class_code, 'VI', to_number(trim(cdl_system_reference2)), '0' ) -- Added as part of the Bug 12776739
6576 , decode(curr_etype_class_code, 'VI', to_number(trim(cdl_system_reference3)), '0' ) -- Added as part of the Bug 12776739
6577 , decode(curr_etype_class_code, 'VI',to_number(trim(cdl_system_reference5)),'0') -- Added for bug#13558683
6578 , TXN_INTERFACE_ID -- Added for bug 13977560
6579 , decode(curr_etype_class_code, 'VI',trim(cdl_system_reference4), '0') -- Added for bug#13558683 removed to_number from
6580 --, decode(curr_etype_class_code, 'VI', cdl_system_reference5, '0' )
6581 --commented for bug#13558683
6582 -- , decode(curr_etype_class_code, 'VI', cdl_system_reference4, '0' )
6583 --Commented for bug#13558683
6584 , decode(fc_document_type ,'ALL', 1, 'CMT', 2, 'ACT', 3 , 4 )
6585 , decode(nvl(project_id,0), 0, project_number, project_id)
6586 , decode(nvl(task_id,0), 0, task_number, task_id)
6587 , accrual_flag
6588 , NVL(adjusted_txn_interface_id,0) ;
6589
6590 --PA-K Changes: Removing the for update clause
6591 --FOR UPDATE OF transaction_status_code;
6592
6593 --TrxRec TrxRecs%ROWTYPE;
6594 X_Owner_name Dba_Tables.Owner%TYPE; /* 1869684 */
6595
6596 --PA-K Changes: Declaration of the tables used for TrxRecs Bulk Fetch
6597 --l_ExpendTab
6598 --l_Expend2Tab
6599 l_SysLinkTab PA_PLSQL_DATATYPES.Char30TabTyp;
6600 l_EmpNumTab PA_PLSQL_DATATYPES.Char30TabTyp;
6601 l_EiEndDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6602 l_OrganizationNameTab PA_PLSQL_DATATYPES.Char240TabTyp;
6603 l_EiDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6604 l_PrjNumTab PA_PLSQL_DATATYPES.Char25TabTyp;
6605 l_TaskNumTab PA_PLSQL_DATATYPES.Char25TabTyp;
6606 l_ETypeTab PA_PLSQL_DATATYPES.Char30TabTyp;
6607 l_NlrTab PA_PLSQL_DATATYPES.Char20TabTyp;
6608 l_NlrOrgNameTab PA_PLSQL_DATATYPES.Char240TabTyp;
6609 l_QtyTab PA_PLSQL_DATATYPES.QtyTabtyp;
6610 l_rawCostTab PA_PLSQL_DATATYPES.NumTabTyp; -- Bug 5959023: Changed to NumTabTyp from QtyTabtyp
6611 l_rawCostRateTab PA_PLSQL_DATATYPES.NumTabTyp; -- Bug 5959023: Changed to NumTabTyp from AmtTabTyp
6612 l_OrigTxnRefTab PA_PLSQL_DATATYPES.Char50TabTyp; --bug 12371923 : Changed the size from 30 to 50
6613 l_AttCatTab PA_PLSQL_DATATYPES.Char30TabTyp;
6614 l_Att1Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6615 l_Att2Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6616 l_Att3Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6617 l_Att4Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6618 l_Att5Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6619 l_Att6Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6620 l_Att7Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6621 l_Att8Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6622 l_Att9Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6623 l_Att10Tab PA_PLSQL_DATATYPES.Char150TabTyp;
6624 l_ExpCommentTab PA_PLSQL_DATATYPES.Char240TabTyp;
6625 l_InterfaceIdTab PA_PLSQL_DATATYPES.Num15TabTyp;
6626 l_ExpIdTab PA_PLSQL_DATATYPES.Num15TabTyp;
6627 l_UnMatchNegFlagTab PA_PLSQL_DATATYPES.Char1TabTyp;
6628 l_ExpItemIdTab PA_PLSQL_DATATYPES.Num15TabTyp;
6629 --l_JobIdTab PA_PLSQL_DATATYPES.
6630 l_OrgIdTab PA_PLSQL_DATATYPES.Num15TabTyp;
6631 l_DRCCIDTab PA_PLSQL_DATATYPES.Num15TabTyp;
6632 l_CRCCIDTab PA_PLSQL_DATATYPES.Num15TabTyp;
6633 l_SysRef1Tab PA_PLSQL_DATATYPES.Char30TabTyp;
6634 l_SysRef2Tab PA_PLSQL_DATATYPES.Char30TabTyp;
6635 l_SysRef3Tab PA_PLSQL_DATATYPES.Char30TabTyp;
6636 l_Sysref4Tab PA_PLSQL_DATATYPES.Char30TabTyp;
6637 TYPE Char30TabTyp IS TABLE OF VARCHAR2(30) index by varchar2(30) ;
6638 l_txn_rejected_sr4Tab Char30TabTyp;
6639
6640 /* REL12-AP Lines uptake START
6641 ** Support for cdl_system_reference5
6642 ** cdl_system_reference5 to store invoice distribution ID
6643 */
6644 l_Sysref5Tab PA_PLSQL_DATATYPES.IdTabTyp;
6645 l_txn_rejected_sr5tab PA_PLSQL_DATATYPES.IdTabTyp;
6646 l_AdjExpItemIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6647 l_FcDocTypeTab PA_PLSQL_DATATYPES.Char3TabTyp;
6648 l_AdjTxnInterfaceIDTab PA_PLSQL_DATATYPES.IdTabTyp;
6649 l_NZAdjFlagTab PA_PLSQL_DATATYPES.Char1TabTyp;
6650 l_AdjTxnEiIDTab PA_PLSQL_DATATYPES.IdTabTyp;
6651 l_temp_adjItemID NUMBER ;
6652 l_scXferCdTab PA_PLSQL_DATATYPES.Char1TabTyp ;
6653
6654 -- REL12 AP Lines Uptake
6655 -- Cash based accounting support
6656 --
6657 -- bug 4902112 declaration was changed from Char1TabTyp to IdTabTyp.
6658 --
6659 l_finalPaymentIdTab PA_PLSQL_DATATYPES.IdTabTyp ;
6660
6661 --REL12 Changes
6662 l_siaAddFlagTab PA_PLSQL_DATATYPES.Char1TabTyp ;
6663 l_old_SysRef1 varchar2(30) ;
6664 l_old_SysRef2 varchar2(30) ;
6665 l_old_SysRef3 varchar2(30) ;
6666 l_old_SysRef4 varchar2(30) ;
6667 l_old_SysRef5 NUMBER ;
6668 l_doc_header_id NUMBER ;
6669 l_vendor_id NUMBER ;
6670 l_doc_distribution_id NUMBER ;
6671 l_doc_payment_id NUMBER ;
6672 l_doc_line_number NUMBER ;
6673 l_gms_fundscheck varchar2(1) ;
6674 l_DocumentTypeTab PA_PLSQL_DATATYPES.Char30TabTyp;
6675 l_DocumentDistTypeTab PA_PLSQL_DATATYPES.Char30TabTyp;
6676
6677 /* REL12-AP Lines uptake END */
6678
6679
6680 l_GlDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6681 l_burdenedCostTab PA_PLSQL_DATATYPES.NumTabTyp; -- Bug 5959023: Changed to NumTabTyp from AmtTabTyp
6682 l_BdCostRateTab PA_PLSQL_DATATYPES.NumTabTyp; -- Bug 5959023: Changed to NumTabTyp from AmtTabTyp
6683 l_RcptCurrAmtTab PA_PLSQL_DATATYPES.NumTabTyp;
6684 l_RcptCurrCodeTab PA_PLSQL_DATATYPES.Char15TabTyp;
6685 l_RcptExchRateTab PA_PLSQL_DATATYPES.NumTabTyp;
6686 l_DenomCurrCodeTab PA_PLSQL_DATATYPES.Char15TabTyp;
6687 l_DenomRawCostTab PA_PLSQL_DATATYPES.NumTabTyp;
6688 l_DenomBdCostTab PA_PLSQL_DATATYPES.NumTabTyp;
6689 l_AcctRateDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6690 l_AcctRateTypeTab PA_PLSQL_DATATYPES.Char30TabTyp;
6691 l_AcctExchRateTab PA_PLSQL_DATATYPES.NumTabTyp;
6692 l_AcctRawCostTab PA_PLSQL_DATATYPES.NumTabTyp;
6693 l_AcctBdCostTab PA_PLSQL_DATATYPES.NumTabTyp;
6694 l_AcctExchRndLimitTab PA_PLSQL_DATATYPES.NumTabTyp;
6695 l_ProjCurrCodeTab PA_PLSQL_DATATYPES.Char15TabTyp;
6696 l_prjRateDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6697 l_PrjRateTypeTab PA_PLSQL_DATATYPES.Char30TabTyp;
6698 l_PrjExchRateTab PA_PLSQL_DATATYPES.NumTabTyp;
6699 l_OrigExpTxnRef1Tab PA_PLSQL_DATATYPES.Char60TabTyp;
6700 l_OrigUsrExpTxnRefTab PA_PLSQL_DATATYPES.Char60TabTyp;
6701 l_VendorNumTab PA_PLSQL_DATATYPES.Char30TabTyp;
6702 l_OrigExpTxnRef2Tab PA_PLSQL_DATATYPES.Char60TabTyp;
6703 l_OrigExpTxnRef3Tab PA_PLSQL_DATATYPES.Char60TabTyp;
6704 l_OverrideOrgNameTab PA_PLSQL_DATATYPES.Char240TabTyp;
6705 l_RevOrigTxnRefTab PA_PLSQL_DATATYPES.Char30TabTyp;
6706 l_billableFlagTab PA_PLSQL_DATATYPES.Char1TabTyp;
6707 l_TxnIfIdTab PA_PLSQL_DATATYPES.Num15TabTyp;
6708 l_PerBusGrpNameTab PA_PLSQL_DATATYPES.Char60TabTyp;
6709 l_ProjFuncCurrCodeTab PA_PLSQL_DATATYPES.Char15TabTyp;
6710 l_PrjFuncRateDateTab PA_PLSQL_DATATYPES.DateTabTyp;
6711 l_PrjFuncRateTypeTab PA_PLSQL_DATATYPES.Char30TabTyp;
6712 l_PrjFuncExchRateTab PA_PLSQL_DATATYPES.NumTabTyp;
6713 l_ProjRawCostTab PA_PLSQL_DATATYPES.NumTabTyp;
6714 l_ProjBdCostTab PA_PLSQL_DATATYPES.NumTabTyp;
6715 l_AsgnNameTab PA_PLSQL_DATATYPES.Char80TabTyp;
6716 l_WorkTypeNameTab PA_PLSQL_DATATYPES.Char80TabTyp;
6717 l_AccrualFlagTab PA_PLSQL_DATATYPES.Char1TabTyp;
6718 l_PrjIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6719 l_TaskIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6720 l_PersonIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6721 l_OrganizationIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6722 l_NLROrgIDTab PA_PLSQL_DATATYPES.IdTabTyp;
6723 l_VendorIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6724 l_OverrideOrgIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6725 l_AsgnIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6726 l_WorkTypeIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6727 l_PersonBusGrpIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6728 l_EmpOrgIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6729 l_EmpJobIdTab PA_PLSQL_DATATYPES.IdTabTyp;
6730 l_po_numberTab PA_PLSQL_DATATYPES.Char20TabTyp; /* cwk */
6731 l_po_header_idTab PA_PLSQL_DATATYPES.IdTabTyp;
6732 l_po_line_numTab PA_PLSQL_DATATYPES.NumTabTyp;
6733 l_po_line_idTab PA_PLSQL_DATATYPES.IdTabTyp;
6734 l_person_typeTab PA_PLSQL_DATATYPES.Char30TabTyp;
6735 l_po_price_typeTab PA_PLSQL_DATATYPES.Char20TabTyp;
6736 l_wip_resource_idTab PA_PLSQL_DATATYPES.IdTabTyp;
6737 l_inventory_item_idTab PA_PLSQL_DATATYPES.IdTabTyp;
6738 l_unit_of_measureTab PA_PLSQL_DATATYPES.Char30TabTyp;
6739
6740 l_Batch_Size NUMBER;
6741 l_CommitSizeRecCount NUMBER;
6742 l_BatchRecCount NUMBER;
6743 l_ActualBatchRecCnt NUMBER;
6744
6745 l_sys_link VARCHAR2(30);
6746 l_expenditure_id NUMBER;
6747 l_RevOrigTxnRef VARCHAR2(30);
6748 l_Accrual_Flag VARCHAR2(1);
6749
6750 l_gms_enabled VARCHAR2(1); --> variable for holding gms_enabled flag.
6751
6752 l_src_system_linkage_function VARCHAR2(30); -- 4057874
6753
6754 -- 10253400: Payroll integration enhancement for 12.2.. start
6755 l_job_idtab PA_PLSQL_DATATYPES.IdTabTyp;
6756 l_job_nametab PA_PLSQL_DATATYPES.Char80TabTyp;
6757 l_location_idtab PA_PLSQL_DATATYPES.IdTabTyp;
6758 l_location_codetab PA_PLSQL_DATATYPES.Char60TabTyp;
6759 l_pay_element_type_idtab PA_PLSQL_DATATYPES.IdTabTyp;
6760 l_pay_element_nametab PA_PLSQL_DATATYPES.Char80TabTyp;
6761 l_pay_element_tab PA_PLSQL_DATATYPES.Char30TabTyp;
6762 -- 10253400: Payroll integration enhancement for 12.2.. end
6763
6764 -- l_agreement_idTab PA_PLSQL_DATATYPES.IdTabTyp; --FSIO Changes
6765 -- l_agreement_numberTab PA_PLSQL_DATATYPES.Char50TabTyp;
6766
6767 -- Start: Added for bug 16220146
6768 l_cbs_element_idtab PA_PLSQL_DATATYPES.Num15TabTyp;
6769 l_cbs_element_nametab PA_PLSQL_DATATYPES.Char250TabTyp;
6770 -- End: Added for bug 16220146
6771
6772 /* Added for bug 13554435 */
6773 PROCEDURE populate_person_type ( p_person_id IN NUMBER
6774 ,p_date IN DATE
6775 ,p_person_type OUT NOCOPY VARCHAR2)
6776 IS
6777 l_Cross_BG_Profile VARCHAR2(2);
6778 l_business_group_id NUMBER;
6779 l_person_type VARCHAR2(1) ;
6780 l_assignment_status VARCHAR2(20);
6781
6782 BEGIN
6783
6784 IF PG_DEBUG = 'Y' THEN
6785 log_message('populate_person_type: Entering procedure');
6786 log_message('populate_person_type: Person ID = ' || p_person_id);
6787 log_message('populate_person_type: Date = ' || p_date);
6788 END IF;
6789
6790 l_Cross_BG_Profile:= pa_utils.IsCrossBGProfile_WNPS;
6791
6792 SELECT business_group_id
6793 INTO l_business_group_id
6794 FROM pa_implementations;
6795
6796 IF PG_DEBUG = 'Y' THEN
6797 log_message('populate_person_type: l_Cross_BG_Profile = ' || l_Cross_BG_Profile);
6798 log_message('populate_person_type: l_business_group_id = ' || l_business_group_id);
6799 END IF;
6800
6801 SELECT decode(a.assignment_type,'E','EMP','C','CWK')
6802 INTO p_person_type
6803 FROM per_assignment_status_types s
6804 ,per_all_assignments_f a
6805 WHERE a.job_id IS NOT NULL
6806 AND a.primary_flag = 'Y'
6807 AND p_date BETWEEN trunc(a.effective_start_date) AND trunc(a.effective_end_date)
6808 AND a.person_id = p_person_id
6809 AND s.per_system_status in ('ACTIVE_ASSIGN','ACTIVE_CWK','TERM_ASSIGN')
6810 AND s.assignment_status_type_id = a.assignment_status_type_id
6811 AND ((l_Cross_BG_Profile = 'N' AND l_business_group_id = a.business_group_id+0)
6812 OR l_Cross_BG_Profile = 'Y');
6813
6814 IF PG_DEBUG = 'Y' THEN
6815 log_message('populate_person_type: Person Type = ' || p_person_type);
6816 END IF;
6817
6818 EXCEPTION WHEN NO_DATA_FOUND THEN
6819 p_person_type := NULL;
6820
6821 WHEN OTHERS THEN
6822 p_person_type := NULL;
6823
6824 end populate_person_type;
6825 /* Added for bug 13554435 */
6826
6827 FUNCTION lockCntrlRec ( trx_source VARCHAR2
6828 , batch VARCHAR2
6829 , etypeclasscode VARCHAR2 ) RETURN NUMBER
6830 IS
6831 BEGIN
6832
6833 pa_cc_utils.set_curr_function('lockCntrlRec');
6834
6835 IF PG_DEBUG = 'Y' THEN
6836 log_message('log_message: ' || 'Trying to get lock for record in xface ctrl:'||
6837 ' transaction source ='||trx_source||
6838 ' batch = '||batch||
6839 ' sys link = '||etypeclasscode);
6840 END IF;
6841
6842 BEGIN
6843 IF PG_DEBUG = 'Y' THEN
6844 log_message('log_message: ' || 'Before locking record');
6845 END IF;
6846
6847 SELECT
6848 1
6849 INTO
6850 dummy
6851 FROM
6852 pa_transaction_xface_control
6853 WHERE
6854 transaction_source = trx_source
6855 AND batch_name = batch
6856 AND system_linkage_function = etypeclasscode
6857 AND status = 'PENDING'
6858 FOR UPDATE OF status NOWAIT;
6859
6860 IF PG_DEBUG = 'Y' THEN
6861 log_message('log_message: ' || 'After locking record');
6862 END IF;
6863
6864 EXCEPTION
6865 when no_data_found then
6866 IF PG_DEBUG = 'Y' THEN
6867 log_message('log_message: ' || 'Not able to Lock Record, in no data found');
6868 END IF;
6869 raise;
6870 END;
6871
6872 IF PG_DEBUG = 'Y' THEN
6873 log_message('log_message: ' || 'Got lock for record');
6874 END IF;
6875
6876 UPDATE pa_transaction_xface_control
6877 SET
6878 interface_id = X_xface_id
6879 , status = 'IN_PROGRESS'
6880 WHERE
6881 transaction_source = trx_source
6882 AND batch_name = batch
6883 AND system_linkage_function = etypeclasscode
6884 AND status = 'PENDING';
6885
6886 IF PG_DEBUG = 'Y' THEN
6887 log_message('log_message: ' || 'Updated interface id/status on pa_transaction_xface_control');
6888 END IF;
6889
6890 pa_cc_utils.reset_curr_function;
6891 RETURN 0;
6892
6893 EXCEPTION
6894 WHEN RESOURCE_BUSY THEN
6895 IF PG_DEBUG = 'Y' THEN
6896 log_message('log_message: ' || 'Cannot get lock',1);
6897 END IF;
6898 pa_cc_utils.reset_curr_function;
6899 RETURN -1;
6900 END lockCntrlRec;
6901
6902 PROCEDURE UpdControlProcessed (P_TrxSource in VARCHAR2,
6903 P_BatchName in VARCHAR2,
6904 P_XfaceId in NUMBER,
6905 P_TxnCount in NUMBER,
6906 P_ProcCount in NUMBER,
6907 P_BatchProcCount in NUMBER,
6908 p_system_linkage_function IN VARCHAR2)
6909 /* Added the parameter system_linkage_function for bug # 3291066 */
6910 IS
6911 BEGIN
6912
6913 pa_cc_utils.set_curr_function('UpdControlProcessed');
6914 IF PG_DEBUG = 'Y' THEN
6915 log_message('log_message: ' || 'Inside UpdControlProcessed,
6916 P_TrxSource = ' || P_TrxSource ||
6917 ' P_BatchName = ' || P_BatchName ||
6918 ' P_Xface_Id = ' || P_XfaceId ||
6919 ' P_TxnCount = ' || P_TxnCount ||
6920 ' P_ProcCount = ' || P_ProcCount ||
6921 ' P_BatchProcCount = '|| P_BatchProcCount);
6922 END IF;
6923
6924 /*PA-K Changes: Replaced the existing update stmt */
6925
6926 /* Bug#3451108. Added an 'AND' condition in the if clause to check if the
6927 P_BatchProcCount is not equal to Zero */
6928 If (((P_BatchProcCount + P_ProcCount) < P_TxnCount) And (P_BatchProcCount <> 0)) Then
6929
6930 IF PG_DEBUG = 'Y' THEN
6931 log_message('log_message: ' || 'Set ctrl record status to PENDING');
6932 END IF;
6933
6934 UPDATE pa_transaction_xface_control
6935 SET status = 'PENDING',
6936 intermediate_flag = 'Y',
6937 processed_count = processed_count + P_BatchProcCount
6938 WHERE transaction_source = P_TrxSource
6939 AND batch_name = P_BatchName
6940 AND interface_id = P_XfaceId
6941 AND system_linkage_function = p_system_linkage_function;
6942 /* Added the join with system_linkage_function for bug # 3291066 */
6943
6944 IF PG_DEBUG = 'Y' THEN
6945 log_message('log_message: ' || 'Updated ' || SQL%ROWCOUNT || ' records');
6946 END IF;
6947
6948 Else
6949
6950 IF PG_DEBUG = 'Y' THEN
6951 log_message('log_message: ' || 'Set ctrl record status to PROCESSED');
6952 END IF;
6953
6954 UPDATE pa_transaction_xface_control
6955 SET status = 'PROCESSED',
6956 processed_count = processed_count + P_BatchProcCount
6957 WHERE transaction_source = P_TrxSource
6958 AND batch_name = P_BatchName
6959 AND interface_id = P_XfaceId
6960 AND system_linkage_function = p_system_linkage_function;
6961 /* Added the join with system_linkage_function for bug # 3291066 */
6962
6963 IF PG_DEBUG = 'Y' THEN
6964 log_message('log_message: ' || 'Updated ' || SQL%ROWCOUNT || ' records');
6965 END IF;
6966
6967 End If;
6968
6969 pa_cc_utils.reset_curr_function;
6970
6971 END UpdControlProcessed;
6972
6973 PROCEDURE loadExpCompareVars ( expend IN VARCHAR2
6974 , expend2 IN VARCHAR2
6975 , end_date IN DATE
6976 , orig_exp_txn_reference1 IN VARCHAR2
6977 , orig_user_exp_txn_reference IN VARCHAR2
6978 , orig_exp_txn_reference2 IN VARCHAR2
6979 , orig_exp_txn_reference3 IN VARCHAR2)
6980 IS
6981 BEGIN
6982
6983 pa_cc_utils.set_curr_function('loadExpCompareVars');
6984 current_expend := expend;
6985 current_expend2 := expend2;
6986 current_period := end_date;
6987 i := 0;
6988
6989 -- Trx_import enhancement
6990 G_orig_exp_txn_reference1 := orig_exp_txn_reference1;
6991 G_orig_user_exp_txn_reference := orig_user_exp_txn_reference;
6992 G_orig_exp_txn_reference2 := orig_exp_txn_reference2;
6993 G_orig_exp_txn_reference3 := orig_exp_txn_reference3;
6994
6995 -- Current_system_linkage is added in init for creating expenditure groups
6996 -- Selva 03/10/97
6997
6998 -- Bug 1000221, OT and ST txns will be created in the same exp group
6999 -- with the system linkage = ST.
7000
7001 IF ( l_sys_link = 'OT' ) THEN
7002 current_system_linkage := 'ST';
7003 ELSE
7004 current_system_linkage := l_sys_link ;
7005 END IF;
7006
7007 -- SST change: If transaction source is 'Oracle Self Service Time',
7008 -- then we do not need to get a new expenditure ID because for
7009 -- self service time, expenditure is created at entry time, thus
7010 -- expenditure ID already exists.
7011 IF X_transaction_source = 'Oracle Self Service Time' AND
7012 l_Expenditure_Id IS NOT NULL THEN
7013
7014 G_expenditure_id := l_Expenditure_Id;
7015
7016 ELSE
7017 SELECT pa_expenditures_s.nextval
7018 INTO G_expenditure_id
7019 FROM sys.dual;
7020 END IF;
7021
7022 pa_cc_utils.reset_curr_function;
7023 END loadExpCompareVars;
7024
7025 -- Bug 2048868 : Added 5 parameters to pass currency attributes to
7026 -- pa_transactions.insertexp
7027
7028 PROCEDURE newExpend ( group_name IN VARCHAR2
7029 , ending_date IN DATE
7030 , record_count IN NUMBER
7031 , p_denom_currency_code IN VARCHAR2 DEFAULT NULL
7032 , p_acct_currency_code IN VARCHAR2 DEFAULT NULL
7033 , p_acct_rate_type IN VARCHAR2 DEFAULT NULL
7034 , p_acct_rate_date IN DATE DEFAULT NULL
7035 , p_acct_exchange_rate IN NUMBER DEFAULT NULL
7036 , p_person_type IN VARCHAR2 DEFAULT NULL /*cwk */
7037 , p_batch_name IN VARCHAR2 ) -- Bug 3613784 : Performance fix
7038 IS
7039
7040 X_status VARCHAR2(30);
7041 X_outcome NUMBER;
7042 X_route_to_person_id NUMBER;
7043 X_comment VARCHAR2(240);
7044 X_approval_status VARCHAR2(80);
7045
7046 l_acct_rate_type VARCHAR2(30);
7047 l_acct_rate_date DATE;
7048 l_acct_exchange_rate NUMBER;
7049 l_gl_accted_flag VARCHAR2(2);
7050 l_person_type VARCHAR2(10); /* Added for bug 13554435 */ /*Bug 16451280 : Changed size from 5 to 10*/
7051
7052 BEGIN
7053 pa_cc_utils.set_curr_function('newExpend');
7054
7055 IF PG_DEBUG = 'Y' THEN
7056 log_message('log_message: ' || 'record count = ' || record_count);
7057 END IF;
7058
7059 -- BUG:4748305 DFHC.D4:PRC INTERFACE SUPPLIER COST NOT INTERFACING
7060 -- VALID INVOICE DISTRIBUTIONS
7061 -- We allow good ap invoice distributions to interface in a expenditure
7062 -- and do not reject all the expenditure items in expenditure
7063 -- This is only done for VI items.
7064
7065 IF ( (NOT REJECT_EXP ) AND (v_calling_module <> 'PAAPIMP' OR record_count > 0)) OR /* Bug 8709614 */
7066 ( v_calling_module = 'PAAPIMP' and
7067 current_system_linkage = 'VI' and
7068 record_count > 0 )
7069 THEN
7070
7071 IF ( NOT GROUP_CREATED ) THEN
7072
7073 IF X_transaction_source NOT IN ('PTE TIME', 'PTE EXPENSE') THEN
7074
7075 IF PG_DEBUG = 'Y' THEN
7076 pa_debug.G_err_Stage := 'Calling pa_transactions.InsertExpGroupNew';
7077 log_message('log_message: ' || pa_debug.G_err_Stage);
7078 log_message('log_message: ' || 'Group Name = ' || group_name || ' Sys Link = ' || current_system_linkage);
7079 END IF;
7080
7081 IF (group_name <> nvl(G_group_name,'X')) THEN
7082
7083 pa_transactions.InsertExpGroupNew(
7084 group_name
7085 , 'RELEASED'
7086 , ending_date
7087 , current_system_linkage
7088 , X_userid
7089 , X_transaction_source
7090 , l_Accrual_Flag
7091 -- MOAC Changes
7092 , g_moac_org_id );
7093
7094 G_group_name := group_name;
7095
7096 GROUP_CREATED := TRUE;
7097
7098 END IF;
7099
7100 END IF;
7101
7102 END IF;
7103
7104 -- SST Change: expenditure was created when user entered
7105 -- the SST. Thus, we just need to update the expenditure_group
7106 -- for the expenditure.
7107 IF ( X_transaction_source = 'Oracle Self Service Time' ) THEN
7108
7109 IF PG_DEBUG = 'Y' THEN
7110 pa_debug.G_err_Stage := 'Updating exp for SST';
7111 log_message('log_message: ' || pa_debug.G_err_Stage);
7112 END IF;
7113
7114 UPDATE pa_expenditures
7115 SET expenditure_group = group_name
7116 WHERE expenditure_id = G_expenditure_id;
7117
7118 ELSE
7119 IF PG_DEBUG = 'Y' THEN
7120 pa_debug.G_err_Stage := 'Calling pa_transactions.InsertExp';
7121 log_message('log_message: ' || pa_debug.G_err_Stage);
7122 END IF;
7123 -- Trx_import enhancement
7124 -- Bug 2048868 : Added 5 parameters to pass currency attributes to
7125 -- pa_transactions.insertexp
7126 -- If system_linkage = ER
7127
7128
7129
7130 IF ( (current_system_linkage = 'ER') and
7131 (p_denom_currency_code <> p_acct_currency_code) ) THEN
7132
7133 if (p_acct_rate_type is null) then
7134 l_acct_rate_type := pa_multi_currency.get_rate_type;
7135 else
7136 l_acct_rate_type := p_acct_rate_type;
7137 end if;
7138
7139 if (p_acct_rate_date is null) then
7140 pa_multi_currency_txn.get_acct_rate_date(
7141 P_EI_date => ending_date,
7142 P_acct_rate_date => l_acct_rate_date);
7143 else
7144 l_acct_rate_date := p_acct_rate_date;
7145 end if;
7146
7147 /* Added for bug 13554435 */
7148 if G_person_id is not null and p_person_type is null then
7149 populate_person_type(p_person_id => G_person_id,
7150 p_date => ending_date,
7151 p_person_type => l_person_type);
7152 ELSIF p_person_type is not null then /* Modified for bug 13979727 */
7153 l_person_type := p_person_type;
7154 end if;
7155 /* Added for bug 13554435 */
7156
7157 pa_transactions.InsertExp(
7158 X_expenditure_id => G_expenditure_id,
7159 X_expend_status => 'APPROVED',
7160 X_expend_ending => ending_date,
7161 X_expend_class => G_eclass,
7162 X_inc_by_person => G_person_id,
7163 X_inc_by_org => G_org_id,
7164 X_expend_group => group_name,
7165 -- X_entered_by_id => X_userid,
7166 X_entered_by_id => FND_GLOBAL.employee_id, -- Bug 2396121
7167 X_created_by_id => X_userid,
7168 X_denom_currency_code => p_denom_currency_code,
7169 X_acct_currency_code => p_acct_currency_code,
7170 X_acct_rate_type => l_acct_rate_type,
7171 X_acct_rate_date => l_acct_rate_date,
7172 X_acct_exchange_rate => p_acct_exchange_rate,
7173 X_orig_exp_txn_reference1 => G_orig_exp_txn_reference1,
7174 X_orig_user_exp_txn_reference => G_orig_user_exp_txn_reference,
7175 X_vendor_id => G_vendor_id,
7176 X_orig_exp_txn_reference2 => G_orig_exp_txn_reference2,
7177 X_orig_exp_txn_reference3 => G_orig_exp_txn_reference3,
7178 X_person_type => l_person_type, /* Added for bug 13554435 */
7179 -- MOAC Changes
7180 p_org_id => g_moac_org_id); /*cwk */
7181
7182 ELSE
7183
7184 /*9823110 Start*/
7185
7186 If (X_transaction_source in ('AP INVOICE', 'AP NRTAX', 'AP DISCOUNTS', 'INTERCOMPANY_AP_INVOICES', 'INTERPROJECT_AP_INVOICES', 'AP VARIANCE'))
7187 and (G_person_id is NOT NULL)
7188 and (current_system_linkage <> 'ER') /*Added for the Bug 16451280*/ then
7189 G_person_id:=NULL;
7190 end if;
7191 /*9823110 End*/
7192
7193 /* Added for bug 13554435 */
7194 if G_person_id is not null and p_person_type is null then
7195 populate_person_type(p_person_id => G_person_id,
7196 p_date => ending_date,
7197 p_person_type => l_person_type);
7198 ELSIF p_person_type is not null then /* Modified for bug 13979727 */
7199 l_person_type := p_person_type;
7200 end if;
7201 /* Added for bug 13554435 */
7202
7203 pa_transactions.InsertExp(
7204 X_expenditure_id => G_expenditure_id,
7205 X_expend_status => 'APPROVED',
7206 X_expend_ending => ending_date,
7207 X_expend_class => G_eclass,
7208 X_inc_by_person => G_person_id,
7209 X_inc_by_org => G_org_id,
7210 X_expend_group => group_name,
7211 -- X_entered_by_id => X_userid,
7212 X_entered_by_id => FND_GLOBAL.employee_id, -- Bug 2396121
7213 X_created_by_id => X_userid,
7214 X_orig_exp_txn_reference1 => G_orig_exp_txn_reference1,
7215 X_orig_user_exp_txn_reference => G_orig_user_exp_txn_reference,
7216 X_vendor_id => G_vendor_id,
7217 X_acct_currency_code => p_acct_currency_code, -- Bug 6412762: Base Bug 6354066
7218 X_orig_exp_txn_reference2 => G_orig_exp_txn_reference2,
7219 X_orig_exp_txn_reference3 => G_orig_exp_txn_reference3,
7220 X_person_type => l_person_type, /* Added for bug 13554435 */
7221 -- MOAC Changes
7222 p_org_id => g_moac_org_id); /* cwk */
7223
7224 END IF;
7225
7226 END IF;
7227
7228 IF PG_DEBUG = 'Y' THEN
7229 pa_debug.G_err_Stage := 'Calling pa_transactions.InsItems';
7230 log_message('log_message: ' || pa_debug.G_err_Stage);
7231 END IF;
7232
7233 select decode(G_gl_accted_flag,'N','N',decode(G_gl_posted_flag,'Y','Y','P')) into l_gl_accted_flag from dual;
7234
7235 pa_transactions.InsItems(
7236 X_userid
7237 , 0
7238 , 'PAXTRTRX'
7239 , 'TRX_IMPORT'
7240 , record_count
7241 , temp_status
7242 , l_gl_accted_flag );
7243
7244 -- -----------------------------------------------------------------------
7245 -- OGM_0.0 - Interface for creating new ADLS for each expenditure Item
7246 -- created. This will create award distribution lines only when OGM is
7247 -- installed for the ORG in process.
7248 -- The folowing procedure returns doing nothing if status is in ERROR for
7249 -- pa_transactions.InsItems.
7250 -- ------------------------------------------------------------------------
7251 IF PG_DEBUG = 'Y' THEN
7252 log_message('log_message: ' || '1760:Call Vertical APPS interface for i>=500');
7253 END IF;
7254
7255 IF l_gms_enabled = 'Y' THEN
7256
7257 PA_GMS_API.vert_trx_interface( X_userid,
7258 0,
7259 'PAXTTRXB',
7260 'TRX_IMPORT',
7261 record_count,
7262 temp_status,
7263 G_gl_accted_flag) ;
7264
7265 IF PG_DEBUG = 'Y' THEN
7266 log_message('log_message: ' || '1760:Call Vertical APPS interface for i>=500 END.');
7267 END IF;
7268
7269 IF ( temp_status < 0 ) THEN
7270 error_msg := SQLERRM( temp_status);
7271 IF PG_DEBUG = 'Y' THEN
7272 log_message('log_message: ' || pa_debug.G_err_Stack,1);
7273 log_message('log_message: ' || error_msg,1);
7274 log_message('log_message: ' || pa_debug.G_err_Stage,1);
7275 END IF;
7276 raise_application_error( -20000, error_msg ) ;
7277 END IF;
7278 END IF; --> l_gms_enabled = 'Y'
7279
7280 IF PG_DEBUG = 'Y' THEN
7281 pa_debug.G_err_stage := 'Updating txn interface status to I';
7282 log_message('log_message: ' || pa_debug.G_err_Stage);
7283 END IF;
7284
7285 -- BUG:4748305 DFHC.D4:PRC INTERFACE SUPPLIER COST NOT INTERFACING
7286 -- VALID INVOICE DISTRIBUTIONS
7287 -- We allow good ap invoice distributions to interface in a expenditure
7288 -- and do not reject all the expenditure items in expenditure
7289 -- This is only done for VI items.
7290
7291 UPDATE pa_transaction_interface
7292 -- SST Change: If there's post import extension, then
7293 -- set status code to 'I' so the post import extension
7294 -- will pick it up, otherwise set to 'A' meaning it has
7295 -- completed the transfer process. Post-extension will
7296 -- eventually set the status code to 'A' as well if the
7297 -- the transaction went through post extension
7298 -- successfully.
7299 SET
7300 transaction_status_code = decode(G_post_processing_extn,NULL,'A',
7301 'I')
7302 WHERE
7303 expenditure_id = G_expenditure_id
7304 -- Bug 3613784 : Performance fix
7305 AND batch_name = P_batch_name
7306 AND transaction_rejection_code is NULL; -- Bug 3613784 : Performance fix
7307
7308 IF PG_DEBUG = 'Y' THEN
7309 pa_debug.G_err_stage := 'Updated ' || SQL%ROWCOUNT || ' txn interface for accepted expenditures';
7310 log_message('log_message: ' || pa_debug.G_err_Stage);
7311 END IF;
7312
7313 ELSE --IF ( NOT REJECT_EXP ) THEN
7314
7315 IF PG_DEBUG = 'Y' THEN
7316 pa_debug.G_err_stage := 'Updating txn interface for rejected expenditures';
7317 log_message('log_message: ' || pa_debug.G_err_Stage);
7318 END IF;
7319 UPDATE pa_transaction_interface
7320 SET
7321 transaction_status_code = decode(expenditure_item_id, 0, 'P', 'R') , /* Bug 8709614 */
7322 expenditure_item_id = decode(expenditure_item_id, 0, 0, NULL) /* Bug 8709614 */
7323 -- SST Change: For rejected expenditure, we need
7324 -- to reset interface table's reversed_orig_txn_reference
7325 -- field. This field is updated after calling validateitem
7326 -- for each transaction. While processing an entire
7327 -- expenditure, some transaction may pass validateitem API
7328 -- and get their reversed_orig_txn_reference field modified;
7329 -- Thus, at the end of each expenditure, we need to go back
7330 -- to reset the reversed_orig_txn_reference field to the
7331 -- original value when the expenditure is rejected.
7332 -- reversed_orig_txn_reference = l_RevOrigTxnRef --commented for bug 16451280
7333 WHERE
7334 expenditure_id = G_expenditure_id
7335 AND batch_name = P_batch_name ; -- Bug 3613784 : Performance fix
7336
7337 IF PG_DEBUG = 'Y' THEN
7338 pa_debug.G_err_stage := 'Updated ' || SQL%ROWCOUNT || ' txn interface for rejected expenditures';
7339 log_message('log_message: ' || pa_debug.G_err_Stage);
7340 END IF;
7341 END IF;
7342
7343 IF PG_DEBUG = 'Y' THEN
7344 pa_debug.G_err_stage := 'Calling pa_transactions.FlushEiTabs';
7345 log_message('log_message: ' || pa_debug.G_err_Stage);
7346 END IF;
7347 pa_transactions.FlushEiTabs;
7348
7349 -- Bug 752915, added the following to flush the adjustments ei pl/sql table
7350 --
7351 pa_adjustments.ExpAdjItemTab := pa_utils.EmptyIdTab;
7352
7353 /***** Bug 4106188 CWK Changes *****/
7354 -- release_po_line_task_lock;
7355 -- init_po_amt_chk;
7356 /***** Bug 4106188 CWK Changes *****/
7357
7358
7359 REJECT_EXP := FALSE;
7360 pa_cc_utils.reset_curr_function;
7361 END newExpend;
7362
7363 PROCEDURE InitPLSQLTab IS
7364 BEGIN
7365 --l_ExpendTab
7366 --l_Expend2Tab
7367 l_SysLinkTab.Delete;
7368 l_EmpNumTab.Delete;
7369 l_EiEndDateTab.Delete;
7370 l_OrganizationNameTab.Delete;
7371 l_EiDateTab.Delete;
7372 l_PrjNumTab.Delete;
7373 l_TaskNumTab.Delete;
7374 l_ETypeTab.Delete;
7375 l_NlrTab.Delete;
7376 l_NlrOrgNameTab.Delete;
7377 l_QtyTab.Delete;
7378 l_rawCostTab.Delete;
7379 l_rawCostRateTab.Delete;
7380 l_OrigTxnRefTab.Delete;
7381 l_AttCatTab.Delete;
7382 l_Att1Tab.Delete;
7383 l_Att2Tab.Delete;
7384 l_Att3Tab.Delete;
7385 l_Att4Tab.Delete;
7386 l_Att5Tab.Delete;
7387 l_Att6Tab.Delete;
7388 l_Att7Tab.Delete;
7389 l_Att8Tab.Delete;
7390 l_Att9Tab.Delete;
7391 l_Att10Tab.Delete;
7392 l_ExpCommentTab.Delete;
7393 l_InterfaceIdTab.Delete;
7394 l_ExpIdTab.Delete;
7395 l_UnMatchNegFlagTab.Delete;
7396 l_ExpItemIdTab.Delete;
7397 --l_JobIdTab.Delete;
7398 l_OrgIdTab.Delete;
7399 l_DRCCIDTab.Delete;
7400 l_CRCCIDTab.Delete;
7401 l_SysRef1Tab.Delete;
7402 l_SysRef2Tab.Delete;
7403 l_SysRef3Tab.Delete;
7404 l_Sysref4Tab.Delete;
7405 l_GlDateTab.Delete;
7406 l_burdenedCostTab.Delete;
7407 l_BdCostRateTab.Delete;
7408 l_RcptCurrAmtTab.Delete;
7409 l_RcptCurrCodeTab.Delete;
7410 l_RcptExchRateTab.Delete;
7411 l_DenomCurrCodeTab.Delete;
7412 l_DenomRawCostTab.Delete;
7413 l_DenomBdCostTab.Delete;
7414 l_AcctRateDateTab.Delete;
7415 l_AcctRateTypeTab.Delete;
7416 l_AcctExchRateTab.Delete;
7417 l_AcctRawCostTab.Delete;
7418 l_AcctBdCostTab.Delete;
7419 l_AcctExchRndLimitTab.Delete;
7420 l_ProjCurrCodeTab.Delete;
7421 l_prjRateDateTab.Delete;
7422 l_PrjRateTypeTab.Delete;
7423 l_PrjExchRateTab.Delete;
7424 l_OrigExpTxnRef1Tab.Delete;
7425 l_OrigUsrExpTxnRefTab.Delete;
7426 l_VendorNumTab.Delete;
7427 l_OrigExpTxnRef2Tab.Delete;
7428 l_OrigExpTxnRef3Tab.Delete;
7429 l_OverrideOrgNameTab.Delete;
7430 l_RevOrigTxnRefTab.Delete;
7431 l_billableFlagTab.Delete;
7432 l_TxnIfIdTab.Delete;
7433 l_PerBusGrpNameTab.Delete;
7434 l_ProjFuncCurrCodeTab.Delete;
7435 l_PrjFuncRateDateTab.Delete;
7436 l_PrjFuncRateTypeTab.Delete;
7437 l_PrjFuncExchRateTab.Delete;
7438 l_ProjRawCostTab.Delete;
7439 l_ProjBdCostTab.Delete;
7440 l_AsgnNameTab.Delete;
7441 l_WorkTypeNameTab.Delete;
7442 l_AccrualFlagTab.Delete;
7443 l_PrjIdTab.Delete;
7444 l_TaskIdTab.Delete;
7445 l_PersonIdTab.Delete;
7446 l_OrganizationIdTab.Delete;
7447 l_NLROrgIDTab.Delete;
7448 l_VendorIdTab.Delete;
7449 l_OverrideOrgIdTab.Delete;
7450 l_AsgnIdTab.Delete;
7451 l_WorkTypeIdTab.Delete;
7452 l_PersonBusGrpIdTab.Delete;
7453 l_EmpOrgIdTab.Delete;
7454 l_EmpJobIdTab.Delete;
7455 l_po_numberTab.Delete; /* cwk */
7456 l_po_header_idTab.Delete;
7457 l_po_line_numTab.Delete;
7458 l_po_line_idTab.Delete;
7459 l_person_typeTab.Delete;
7460 l_po_price_typeTab.Delete;
7461 l_wip_resource_idTab.Delete;
7462 l_inventory_item_idTab.Delete;
7463 l_unit_of_measureTab.Delete;
7464
7465 /* REL12-AP Lines uptake START
7466 ** Support for Related items and cdl_system_reference5
7467 ** cdl_system_reference3 to store invoice distribution ID
7468 */
7469 l_SysRef5Tab.Delete ;
7470 l_AdjExpItemIdTab.Delete ;
7471 l_FcDocTypeTab.Delete ;
7472 l_DocumentTypeTab.DELETE ;
7473 l_DocumentDistTypeTab.DELETE ;
7474 l_siaAddFlagTab.DELETE ;
7475 l_adjTxnInterfaceIDTab.delete ;
7476 l_NZAdjFlagTab.delete ;
7477 l_AdjTxnEiIDTab.delete ;
7478 l_scXferCdTab.delete ;
7479 -- REL12 AP Lines Uptake
7480 -- Cash based accounting support
7481 --
7482 l_finalPaymentIdTab.delete ;
7483 l_txn_rejected_sr5tab.DELETE ;
7484 l_txn_rejected_sr4tab.DELETE ;
7485
7486 /* REL12-AP Lines uptake END */
7487
7488 -- l_agreement_idTab.DELETE ; --FSIO Changes
7489 -- l_agreement_numberTab.DELETE ;
7490
7491 init_po_amt_chk;
7492 -- 10253400: Payroll integration enhancement for 12.2.. start
7493 l_job_idtab.delete;
7494 l_job_nametab.delete;
7495 l_location_idtab.delete;
7496 l_location_codetab.delete;
7497 l_pay_element_type_idtab.delete;
7498 -- 10253400: Payroll integration enhancement for 12.2.. end
7499 --Start: Added for bug 16220146
7500 l_cbs_element_idtab.delete;
7501 l_cbs_element_nametab.delete;
7502 -- End: Added for bug 16220146
7503 END InitPLSQLTab;
7504
7505 --
7506 -- Bug:5064930
7507 -- Reject the net zero reversals if pa adjustments have rejected
7508 -- logic description:
7509 -- supplier cost reversal transaction interface reverse the project
7510 -- adjustments corresponding to the source transactions.
7511 -- Supplier cost reversed transactions do not get interface if
7512 -- project adjustment reversal fails.
7513 -- Following function stamp the supplier cost reversal with the same rejection code as
7514 -- of the corresponding project adjustments that has rejected before in the same batch
7515 --
7516 --
7517 FUNCTION get_parent_txn_status( p_status varchar2, p_indx number ) return varchar2 is
7518 l_status varchar2(50) ;
7519 l_parent_dist_id number ;
7520 l_rejected_txn_id number ;
7521
7522 cursor c_prepay is
7523 select reversed_prepay_app_dist_id
7524 from ap_prepay_app_dists
7525 where prepay_app_dist_id = NVL(l_SysRef4Tab(p_indx),0) ;
7526
7527 cursor c_payment is
7528 select reversal_inv_pmt_id
7529 from AP_Invoice_Payments
7530 where Invoice_Payment_Id = NVL(l_SysRef4Tab(p_indx),0)
7531 and nvl(reversal_flag,'N') = 'Y' ;
7532
7533 cursor c_invdist is
7534 select parent_reversal_id
7535 into l_parent_dist_id
7536 from ap_invoice_distributions_all apd
7537 where invoice_distribution_id = NVL(l_SysRef5Tab(p_indx),0)
7538 and nvl(reversal_flag,'N') = 'Y';
7539
7540 /* Self Assessed Tax Changes*/
7541 cursor c_satdist is
7542 select parent_reversal_id
7543 into l_parent_dist_id
7544 from AP_SELF_ASSESSED_TAX_DIST_ALL apd
7545 where invoice_distribution_id = NVL(l_SysRef5Tab(p_indx),0)
7546 and nvl(reversal_flag,'N') = 'Y';
7547
7548 cursor c_rcvtxn is
7549 select parent_transaction_id
7550 from rcv_transactions
7551 where transaction_id = NVL(l_SysRef4Tab(p_indx),0) ;
7552
7553 cursor c_status_cd is
7554 select transaction_rejection_code
7555 from pa_transaction_interface_all
7556 where txn_interface_id = l_rejected_txn_id
7557 and transaction_status_code = 'R' ;
7558 BEGIN
7559 l_status := p_status ;
7560
7561 IF l_status is not null OR
7562 NVL(l_nzAdjFlagTab(p_indx), 'N') <> 'Y' OR
7563 v_calling_module <> 'PAAPIMP' THEN
7564
7565 RETURN l_status ;
7566 end if ;
7567 pa_cc_utils.set_curr_function('get_parent_txn_status');
7568
7569 IF PG_DEBUG = 'Y' THEN
7570 log_message('log_message: X_transaction_source :' || X_transaction_source);
7571 log_message('log_message: G_cash_based_accounting :' || G_cash_based_accounting);
7572 log_message('log_message: l_DocumentDistTypeTab :' || l_DocumentDistTypeTab(p_indx));
7573 log_message('log_message: l_SysRef5Tab(p_indx) :' || l_SysRef5Tab(p_indx));
7574 log_message('log_message: l_SysRef4Tab(p_indx) :' || l_SysRef4Tab(p_indx));
7575 END IF;
7576
7577 l_parent_dist_id := NULL ;
7578
7579
7580 IF X_transaction_source in ( 'AP EXPENSE', 'AP INVOICE', 'AP NRTAX' , 'AP ERV',
7581 'INTERCOMPANY_AP_INVOICES', 'INTERPROJECT_AP_INVOICES', 'AP VARIANCE' ) THEN
7582 -- {
7583 IF G_cash_based_accounting = 'Y' THEN
7584 -- {{{
7585 IF l_DocumentDistTypeTab(p_indx) = 'PREPAY' THEN
7586 open c_prepay ;
7587 fetch c_prepay into l_parent_dist_id ;
7588 close c_prepay ;
7589 ELSE
7590 open c_payment ;
7591 fetch c_payment into l_parent_dist_id ;
7592 close c_payment ;
7593 END IF ;
7594
7595 IF l_txn_rejected_sr4tab.EXISTS(l_parent_dist_id) THEN
7596 l_rejected_txn_id := l_txn_rejected_sr4tab(l_parent_dist_id) ;
7597 END IF ;
7598 -- }}}
7599 ELSE
7600 -- {{{
7601
7602 /*Self Assessed Tax Changes*/
7603 IF l_DocumentDistTypeTab(p_indx) = 'SELF_ASSESSED_TAX' then
7604 open c_satdist ;
7605 fetch c_satdist into l_parent_dist_id ;
7606 close c_satdist ;
7607 else
7608 open c_invdist ;
7609 fetch c_invdist into l_parent_dist_id ;
7610 close c_invdist ;
7611 end if;
7612
7613 IF l_txn_rejected_sr5tab.EXISTS(l_parent_dist_id) THEN
7614 l_rejected_txn_id := l_txn_rejected_sr5tab(l_parent_dist_id) ;
7615 END IF ;
7616
7617 END IF ;
7618 --}}}
7619 END IF ; -- }
7620
7621 IF X_transaction_source in ( 'PO RECEIPT', 'PO RECEIPT NRTAX',
7622 'PO RECEIPT PRICE ADJ', 'PO RECEIPT NRTAX PRICE ADJ' ) THEN
7623 --{
7624 open c_rcvtxn ;
7625 fetch c_rcvtxn into l_parent_dist_id ;
7626 close c_rcvtxn ;
7627
7628 IF l_txn_rejected_sr4tab.EXISTS(l_parent_dist_id) THEN
7629 l_rejected_txn_id := l_txn_rejected_sr4tab(l_parent_dist_id) ;
7630 END IF ;
7631 END IF ; --}
7632
7633 IF X_transaction_source in ( 'AP DISCOUNTS') THEN
7634 -- {
7635 open c_payment ;
7636 fetch c_payment into l_parent_dist_id ;
7637 close c_payment ;
7638
7639 IF l_txn_rejected_sr4tab.EXISTS(l_parent_dist_id) THEN
7640 l_rejected_txn_id := l_txn_rejected_sr4tab(l_parent_dist_id) ;
7641 END IF ;
7642
7643 END IF ; --}
7644
7645 IF PG_DEBUG = 'Y' THEN
7646 log_message('log_message: l_parent_dist_id :' || l_parent_dist_id);
7647 log_message('log_message: l_rejected_txn_id :' || l_rejected_txn_id);
7648 END IF;
7649
7650 IF l_rejected_txn_id is not null then
7651 open c_status_cd ;
7652 fetch c_status_cd into l_status ;
7653 close c_status_cd ;
7654 END IF ;
7655
7656 IF PG_DEBUG = 'Y' THEN
7657 log_message('log_message: l_status :' || l_status);
7658 END IF;
7659
7660 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
7661 --
7662 IF l_status in ( 'GMS_EXP_ITEM_DT_BEFORE_AWD_ST' ,'GMS_EXP_ITEM_DT_AFTER_AWD_END' ,
7663 'GMS_AWARD_IS_CLOSED' , 'EXP_TYPE_INACTIVE' , 'ETYPE_SLINK_INACTIVE' ,
7664 'PA_EX_PROJECT_DATE' , 'PA_EXP_TASK_EFF' , 'PA_EXP_ORG_NOT_ACTIVE' , 'NO_ASSIGNMENT' ) THEN
7665 --
7666 -- l_status := 'Unable to process this record because at least one record for the same
7667 -- distributions has been rejected.'
7668 --
7669 l_status := 'PA_REJECTED_PARENT_RECORD' ;
7670 IF PG_DEBUG = 'Y' THEN
7671 log_message('log_message: Status Override for child (Date Failure) l_status :' || l_status);
7672 END IF;
7673 END IF ;
7674
7675 pa_cc_utils.reset_curr_function;
7676
7677 return l_status ;
7678 END get_parent_txn_status ;
7679 -- =========================================
7680 BEGIN
7681
7682 -- Interface supplier invoices from AP and Web expenses
7683 -- Interface Web expenses from AP calls import1 program
7684 -- instead of Import, since the debug log messages are
7685 -- enabled only in import prog, log messages are not
7686 -- written out for the Interface programs from AP.
7687 -- The following two lines should take care of this problem.
7688
7689 If G_debug_mode is NULL Then
7690 fnd_profile.get('PA_DEBUG_MODE',G_debug_mode);
7691 G_debug_mode := NVL(G_debug_mode, 'N');
7692
7693 pa_debug.set_process(x_process => 'PLSQL',
7694 x_debug_mode => G_debug_mode);
7695 End If;
7696
7697 pa_cc_utils.log_message('Debug Mode = '||G_debug_mode,1);
7698
7699 g_request_id := fnd_global.conc_request_id;
7700 pa_cc_utils.set_curr_function('Import1');
7701 IF PG_DEBUG = 'Y' THEN
7702 log_message('log_message: ' || 'Start Transaction Import');
7703 END IF;
7704
7705 /* Bug 2451653 commented FND_STATS.Gather_Table_Stats
7706 Please see earlier versions for the code
7707 */
7708
7709 G_user := X_userid;
7710
7711 IF PG_DEBUG = 'Y' THEN
7712 log_message('log_message: ' || 'G_trx_link = '|| G_trx_link);
7713 END IF;
7714
7715 IF (G_trx_link is null) Then
7716 IF PG_DEBUG = 'Y' THEN
7717 pa_debug.G_err_Stage := 'Retriving Transaction_source';
7718 log_message('log_message: ' || pa_debug.G_err_Stage);
7719 END IF;
7720 GetTrxSrcInfo( X_transaction_source );
7721 End If;
7722
7723 l_Batch_Size := G_Batch_Size;
7724 IF PG_DEBUG = 'Y' THEN
7725 log_message('log_message: ' || 'Initial l_Batch_Size = ' || l_Batch_Size);
7726 END IF;
7727
7728 IF PG_DEBUG = 'Y' THEN
7729 pa_debug.G_err_stage := 'Retriving Currency Info from Imp options';
7730 log_message('log_message: ' || pa_debug.G_err_stage);
7731 END IF;
7732
7733 IF (G_accounting_currency_code IS NULL) THEN
7734 GetImpCurrInfo;
7735 END IF;
7736
7737 IF g_moac_org_id is NULL then
7738 g_moac_org_id := pa_moac_utils.get_current_org_id ;
7739 END IF ;
7740
7741 -- Bug 987539: Initialize v_calling_module according
7742 -- to transaction source. Basically this variable is
7743 -- used when calling validateitem API to let this API
7744 -- know who is calling it. By initializing v_calling_module
7745 -- accordingly, we can let validateitem know that the item
7746 -- we're validating comes from AP, thus validation is
7747 -- is not necessary because AP does validation at entry time.
7748 IF (X_transaction_source in ( 'AP EXPENSE', 'AP INVOICE', 'AP NRTAX', 'AP DISCOUNTS', 'INTERCOMPANY_AP_INVOICES',
7749 'INTERPROJECT_AP_INVOICES', 'AP VARIANCE', 'AP ERV', 'PO RECEIPT', 'PO RECEIPT NRTAX',
7750 'PO RECEIPT PRICE ADJ', 'PO RECEIPT NRTAX PRICE ADJ')) THEN
7751 -- pricing changes
7752 --added for 1503237
7753 v_calling_module := 'PAAPIMP';
7754 ELSE
7755 v_calling_module := 'PAXTRTRX';
7756 END IF;
7757
7758 IF PG_DEBUG = 'Y' THEN
7759 log_message('log_message: ' || 'Module:'||v_calling_module);
7760 END IF;
7761 IF PG_DEBUG = 'Y' THEN
7762 pa_debug.G_err_stage := 'Open and Fetch transaction batches';
7763 log_message('log_message: ' || pa_debug.G_err_stage);
7764 END IF;
7765
7766 /* Check if gms is enabled and keep the status in a variable */
7767
7768 l_gms_enabled := gms_pa_costing_pkg.grants_implemented;
7769
7770 /* if NVL(fnd_profile.value('PA_DEBUG_MODE'), 'N') = 'Y' then --FSIO Change
7771 G_FSIO_ENABLED := 'Y';
7772 else
7773 G_FSIO_ENABLED := 'N';
7774 end if; */
7775
7776 Open TrxBatches;
7777
7778 l_CommitSizeRecCount := 0;
7779
7780 <<batches>>
7781 Loop ---{
7782
7783 IF PG_DEBUG = 'Y' THEN
7784 pa_debug.G_err_Stage := 'Start TrxBatches loop';
7785 log_message('log_message: ' || pa_debug.G_err_stage);
7786 END IF;
7787
7788 Fetch TrxBatches INTO TrxBatch;
7789
7790 If TrxBatches%ROWCOUNT = 0 and G_Exit_Main is null Then
7791 IF PG_DEBUG = 'Y' THEN
7792 log_message('log_message: ' || pa_debug.G_err_stage,1);
7793 END IF;
7794 G_Exit_Main := TRUE;
7795 Exit batches;
7796 Elsif TrxBatches%NOTFOUND Then
7797 IF PG_DEBUG = 'Y' THEN
7798 pa_debug.G_err_Stage := 'TrxBatches notfound, exit trxbatches';
7799 log_message('log_message: ' || pa_debug.G_err_stage,1);
7800 END IF;
7801 If X_transaction_source <> 'ORACLE TIME AND LABOR' Then --bug8530681
7802 G_Exit_Main := TRUE; --Bug 7307479
7803 End If;
7804 Exit batches;
7805 End If;
7806
7807 GROUP_CREATED := FALSE;
7808 --G_group_name := TrxBatch.exp_group_name;
7809
7810 If l_Batch_Size = 0 Then
7811
7812 SELECT sum(xc.transaction_count)
7813 INTO l_Batch_Size
7814 FROM pa_transaction_xface_control xc
7815 WHERE xc.transaction_source = TrxBatch.transaction_source
7816 AND xc.status = 'PENDING';
7817
7818 IF PG_DEBUG = 'Y' THEN
7819 log_message('log_message: ' || 'l_Batch_Size is zero,set it to sum of transaction_count = '||l_Batch_Size);
7820 END IF;
7821
7822 End If;
7823
7824 IF PG_DEBUG = 'Y' THEN
7825 pa_debug.G_err_Stage := 'Locking xface ctrl record';
7826 log_message('log_message: ' || pa_debug.G_err_stage||
7827 'Transaction source = '||TrxBatch.transaction_source
7828 ||' batch= '||TrxBatch.batch_name||' sys link= '||
7829 TrxBatch.system_linkage_function);
7830 END IF;
7831
7832 dummy := lockCntrlRec( TrxBatch.transaction_source
7833 , TrxBatch.batch_name
7834 , TrxBatch.system_linkage_function );
7835
7836 IF ( dummy = 0 ) THEN ---{
7837
7838 IF PG_DEBUG = 'Y' THEN
7839 log_message('log_message: ' || 'Final l_Batch_Size = '|| l_Batch_Size);
7840 END IF;
7841
7842 IF (l_CommitSizeRecCount <> l_Batch_Size) THEN ---{
7843
7844 IF PG_DEBUG = 'Y' THEN
7845 pa_debug.G_err_Stage := 'Open cursor trxrecs';
7846 log_message('log_message: ' || pa_debug.G_err_Stage);
7847 log_message('log_message: ' || 'source = '||TrxBatch.transaction_source ||
7848 ' , batch = ' || TrxBatch.batch_name ||
7849 ' sys link = ' || TrxBatch.system_linkage_function);
7850 END IF;
7851
7852 /** Bug#3026218 There are only two cursors, as per the changes done
7853 *** and hence open them based on Sys Link Fn
7854 **/
7855
7856 If (TrxBatch.system_linkage_function = 'ST') Then
7857 OPEN TrxRecs1( TrxBatch.transaction_source
7858 , TrxBatch.batch_name
7859 , TrxBatch.system_linkage_function );
7860 Else
7861 OPEN TrxRecs2( TrxBatch.transaction_source
7862 , TrxBatch.batch_name
7863 , TrxBatch.system_linkage_function );
7864 End If;
7865
7866 FIRST_RECORD := TRUE;
7867
7868 IF PG_DEBUG = 'Y' THEN
7869 log_message('log_message: ' || 'Start Trxrec loop',1);
7870 END IF;
7871
7872 --Initialize PL/SQL tables
7873 InitPlSqlTab;
7874
7875 If l_Batch_Size = 0 Then
7876 l_BatchRecCount := TrxBatch.transaction_count;
7877 Else
7878 l_BatchRecCount := l_Batch_Size - l_CommitSizeRecCount;
7879 End If;
7880
7881 IF PG_DEBUG = 'Y' THEN
7882 log_message('log_message: ' || 'Batch = '||l_BatchRecCount);
7883 log_message('log_message: ' || 'Fetch bulk from Trxrec');
7884 END IF;
7885
7886 -- REL12 AP Lines Uptake
7887 -- Determine cash Based accounting flag
7888
7889 SELECT NVL(glb.sla_ledger_cash_basis_flag,'N')
7890 INTO G_cash_based_accounting
7891 FROM gl_sets_of_books glb, pa_implementations_all pai
7892 WHERE glb.set_of_books_id = pai.set_of_books_id
7893 AND pai.org_id = g_moac_org_id ;
7894
7895 /** Bug#3026218 There will be only two fetches - from TrxRecs1 and TRxRecs2
7896 *** Removed the code that is based on Pre-defined flag
7897 **/
7898
7899 If (TrxBatch.system_linkage_function = 'ST') Then --{
7900
7901 FETCH TrxRecs1 bulk collect into
7902 l_SysLinkTab
7903 , l_EiEndDateTab
7904 , l_EmpNumTab
7905 , l_OrganizationNameTab
7906 , l_EiDateTab
7907 , l_PrjNumTab
7908 , l_TaskNumTab
7909 , l_ETypeTab
7910 , l_NlrTab
7911 , l_NlrOrgNameTab
7912 , l_QtyTab
7913 , l_rawCostTab
7914 , l_rawCostRateTab
7915 , l_OrigTxnRefTab
7916 , l_AttCatTab
7917 , l_Att1Tab
7918 , l_Att2Tab
7919 , l_Att3Tab
7920 , l_Att4Tab
7921 , l_Att5Tab
7922 , l_Att6Tab
7923 , l_Att7Tab
7924 , l_Att8Tab
7925 , l_Att9Tab
7926 , l_Att10Tab
7927 , l_ExpCommentTab
7928 , l_InterfaceIdTab
7929 , l_ExpIdTab
7930 , l_UnMatchNegFlagTab
7931 , l_ExpItemIdTab
7932 --, l_JobIdTab
7933 , l_OrgIdTab
7934 , l_DRCCIDTab
7935 , l_CRCCIDTab
7936 , l_SysRef1Tab
7937 , l_SysRef2Tab
7938 , l_SysRef3Tab
7939 , l_Sysref4Tab
7940 , l_Sysref5Tab
7941 , l_GlDateTab
7942 , l_burdenedCostTab
7943 , l_BdCostRateTab
7944 , l_RcptCurrAmtTab
7945 , l_RcptCurrCodeTab
7946 , l_RcptExchRateTab
7947 , l_DenomCurrCodeTab
7948 , l_DenomRawCostTab
7949 , l_DenomBdCostTab
7950 , l_AcctRateDateTab
7951 , l_AcctRateTypeTab
7952 , l_AcctExchRateTab
7953 , l_AcctRawCostTab
7954 , l_AcctBdCostTab
7955 , l_AcctExchRndLimitTab
7956 , l_ProjCurrCodeTab
7957 , l_prjRateDateTab
7958 , l_PrjRateTypeTab
7959 , l_PrjExchRateTab
7960 , l_OrigExpTxnRef1Tab
7961 , l_OrigUsrExpTxnRefTab
7962 , l_VendorNumTab
7963 , l_OrigExpTxnRef2Tab
7964 , l_OrigExpTxnRef3Tab
7965 , l_OverrideOrgNameTab
7966 , l_RevOrigTxnRefTab
7967 , l_billableFlagTab
7968 , l_TxnIfIdTab
7969 , l_PerBusGrpNameTab
7970 , l_ProjFuncCurrCodeTab
7971 , l_PrjFuncRateDateTab
7972 , l_PrjFuncRateTypeTab
7973 , l_PrjFuncExchRateTab
7974 , l_ProjRawCostTab
7975 , l_ProjBdCostTab
7976 , l_AsgnNameTab
7977 , l_WorkTypeNameTab
7978 , l_AccrualFlagTab
7979 , l_PrjIdTab
7980 , l_TaskIdTab
7981 , l_PersonIdTab
7982 , l_OrganizationIdTab
7983 , l_NLROrgIDTab
7984 , l_VendorIdTab
7985 , l_OverrideOrgIdTab
7986 , l_AsgnIdTab
7987 , l_WorkTypeIdTab
7988 , l_PersonBusGrpIdTab
7989 , l_po_numberTab /* cwk */
7990 , l_po_header_idTab
7991 , l_po_line_numTab
7992 , l_po_line_idTab
7993 , l_person_typeTab
7994 , l_po_price_typeTab
7995 , l_wip_resource_idTab
7996 , l_inventory_item_idTab
7997 , l_unit_of_measureTab
7998 , l_AdjExpItemIdTab
7999 , l_FcDocTypeTab
8000 , l_DocumentTypeTab
8001 , l_DocumentDistTypeTab
8002 , l_siaAddFlagTab
8003 , l_AdjTxnInterfaceIdTab
8004 , l_nzAdjFlagTab
8005 , l_scXferCdTab
8006 , l_finalPaymentIdTab
8007 -- , l_agreement_idTab --FSIO Changes
8008 -- , l_agreement_numberTab
8009 -- 10253400: Payroll integration enhancement for 12.2..start
8010 ,l_job_idtab
8011 ,l_job_nametab
8012 ,l_location_idtab
8013 ,l_location_codetab
8014 ,l_pay_element_type_idtab
8015 -- 10253400: Payroll integration enhancement for 12.2..end
8016 -- Start: Added for bug 16220146
8017 ,l_cbs_element_nametab
8018 ,l_cbs_element_idtab -- Added for Bug 16444399
8019 -- End: Added for bug 16220146
8020 LIMIT l_BatchRecCount;
8021
8022 Else
8023
8024
8025 FETCH TrxRecs2 bulk collect into
8026 l_SysLinkTab
8027 , l_EiEndDateTab
8028 , l_EmpNumTab
8029 , l_OrganizationNameTab
8030 , l_EiDateTab
8031 , l_PrjNumTab
8032 , l_TaskNumTab
8033 , l_ETypeTab
8034 , l_NlrTab
8035 , l_NlrOrgNameTab
8036 , l_QtyTab
8037 , l_rawCostTab
8038 , l_rawCostRateTab
8039 , l_OrigTxnRefTab
8040 , l_AttCatTab
8041 , l_Att1Tab
8042 , l_Att2Tab
8043 , l_Att3Tab
8044 , l_Att4Tab
8045 , l_Att5Tab
8046 , l_Att6Tab
8047 , l_Att7Tab
8048 , l_Att8Tab
8049 , l_Att9Tab
8050 , l_Att10Tab
8051 , l_ExpCommentTab
8052 , l_InterfaceIdTab
8053 , l_ExpIdTab
8054 , l_UnMatchNegFlagTab
8055 , l_ExpItemIdTab
8056 --, l_JobIdTab
8057 , l_OrgIdTab
8058 , l_DRCCIDTab
8059 , l_CRCCIDTab
8060 , l_SysRef1Tab
8061 , l_SysRef2Tab
8062 , l_SysRef3Tab
8063 , l_Sysref4Tab
8064 , l_Sysref5Tab
8065 , l_GlDateTab
8066 , l_burdenedCostTab
8067 , l_BdCostRateTab
8068 , l_RcptCurrAmtTab
8069 , l_RcptCurrCodeTab
8070 , l_RcptExchRateTab
8071 , l_DenomCurrCodeTab
8072 , l_DenomRawCostTab
8073 , l_DenomBdCostTab
8074 , l_AcctRateDateTab
8075 , l_AcctRateTypeTab
8076 , l_AcctExchRateTab
8077 , l_AcctRawCostTab
8078 , l_AcctBdCostTab
8079 , l_AcctExchRndLimitTab
8080 , l_ProjCurrCodeTab
8081 , l_prjRateDateTab
8082 , l_PrjRateTypeTab
8083 , l_PrjExchRateTab
8084 , l_OrigExpTxnRef1Tab
8085 , l_OrigUsrExpTxnRefTab
8086 , l_VendorNumTab
8087 , l_OrigExpTxnRef2Tab
8088 , l_OrigExpTxnRef3Tab
8089 , l_OverrideOrgNameTab
8090 , l_RevOrigTxnRefTab
8091 , l_billableFlagTab
8092 , l_TxnIfIdTab
8093 , l_PerBusGrpNameTab
8094 , l_ProjFuncCurrCodeTab
8095 , l_PrjFuncRateDateTab
8096 , l_PrjFuncRateTypeTab
8097 , l_PrjFuncExchRateTab
8098 , l_ProjRawCostTab
8099 , l_ProjBdCostTab
8100 , l_AsgnNameTab
8101 , l_WorkTypeNameTab
8102 , l_AccrualFlagTab
8103 , l_PrjIdTab
8104 , l_TaskIdTab
8105 , l_PersonIdTab
8106 , l_OrganizationIdTab
8107 , l_NLROrgIDTab
8108 , l_VendorIdTab
8109 , l_OverrideOrgIdTab
8110 , l_AsgnIdTab
8111 , l_WorkTypeIdTab
8112 , l_PersonBusGrpIdTab
8113 , l_po_numberTab /* cwk */
8114 , l_po_header_idTab
8115 , l_po_line_numTab
8116 , l_po_line_idTab
8117 , l_person_typeTab
8118 , l_po_price_typeTab
8119 , l_wip_resource_idTab
8120 , l_inventory_item_idTab
8121 , l_unit_of_measureTab
8122 , l_AdjExpItemIdTab
8123 , l_FcDocTypeTab
8124 , l_DocumentTypeTab
8125 , l_DocumentDistTypeTab
8126 , l_siaAddFlagTab
8127 , l_AdjTxnInterfaceIdTab
8128 , l_nzAdjFlagTab
8129 , l_scXferCdTab
8130 , l_finalPaymentIdTab
8131 -- , l_agreement_idTab --FSIO Changes
8132 -- , l_agreement_numberTab
8133 -- 10253400: Payroll integration enhancement for 12.2..start
8134 ,l_job_idtab
8135 ,l_job_nametab
8136 ,l_location_idtab
8137 ,l_location_codetab
8138 ,l_pay_element_type_idtab
8139 -- 10253400: Payroll integration enhancement for 12.2..end
8140 -- Start: Added for bug 16220146
8141 ,l_cbs_element_nametab
8142 ,l_cbs_element_idtab -- Added for Bug 16444399
8143 -- End: Added for bug 16220146
8144 LIMIT l_BatchRecCount;
8145
8146 End If; --} /* TrxBatch.system_linkage_function = 'ST' */
8147
8148
8149 IF PG_DEBUG = 'Y' THEN
8150 pa_debug.g_err_stage := 'Log: No. of records fetched = '||l_TxnIfIDTab.count;
8151 log_message('log_message: ' || pa_debug.G_err_stage);
8152 END IF;
8153 l_ActualBatchRecCnt := l_TxnIfIDTab.count;
8154
8155
8156 /* Bug#3451108 - Added code - Start */
8157 IF l_TxnIfIDTab.count = 0 THEN
8158
8159 IF PG_DEBUG = 'Y' THEN
8160 log_message('log_message: ' || 'Fetch did not get any records, exit batches');
8161 END IF;
8162
8163 UpdControlProcessed( P_TrxSource => TrxBatch.transaction_source,
8164 P_BatchName => TrxBatch.batch_name,
8165 P_XfaceId => X_xface_id,
8166 P_TxnCount => TrxBatch.transaction_count,
8167 P_ProcCount => TrxBatch.processed_count,
8168 P_BatchProcCount => l_ActualBatchRecCnt,
8169 P_System_Linkage_Function => TrxBatch.system_linkage_function);
8170
8171 G_Exit_Main := TRUE;--anuragag Bug9349328
8172 Exit batches;
8173 END IF; /* l_TxnIfIDTab.count = 0 */
8174 /* Bug#3451108 - Added code - End */
8175
8176 FOR Z in 1..l_TxnIfIDTab.count LOOP ---{ /* cwk */
8177
8178 IF TrxBatch.system_linkage_function in ('ST','OT','VI','ER') THEN
8179 null;
8180 ELSE
8181 l_po_numberTab(z) := null;
8182 l_po_header_idTab(z) := null;
8183 l_po_line_numTab(z) := null;
8184 l_po_line_idTab(z) := null;
8185 l_po_price_typeTab(z) := null;
8186 END IF;
8187
8188 END LOOP; ---}
8189
8190 --
8191 -- Bug : 4962731
8192 -- : R12.PJ:XB1:QA:BC:INCORRECT AMOUNTS INTERFACED TO PROJECTS IN CASH BASED ACC
8193 --
8194 IF G_cash_based_accounting = 'Y' and
8195 X_transaction_source in ( 'AP EXPENSE', 'AP INVOICE', 'AP NRTAX' , 'AP ERV',
8196 'INTERCOMPANY_AP_INVOICES', 'INTERPROJECT_AP_INVOICES', 'AP VARIANCE' ) THEN
8197 G_Profile_Discount_Start_date := fnd_date.canonical_to_date(PAAPIMP_PKG.return_profile_discount_date);
8198 G_Discount_Method := PAAPIMP_PKG.return_discount_method;
8199 END IF ;
8200
8201 FOR J in 1..l_TxnIfIDTab.count LOOP ---{
8202
8203 G_cbs_element_id := l_cbs_element_idtab(j); -- Added for CBS Enhancement Bug 16220146
8204 -- REL12 : AP Lines uptake
8205 -- We only support net zero transactions for supplier invoice interface
8206 --
8207 IF v_calling_module <> 'PAAPIMP' THEN
8208 l_adjTxnInterfaceIDTab(j) := NULL ;
8209 l_NZAdjFlagTab(j) := NULL ;
8210 -- supplier cost transfer status code is used only for supplier cost
8211 -- interface process.
8212 -- The value is ignored for all other transaction source
8213 l_scXfercdTab(j) := NULL ;
8214 ELSE
8215 -- REL12 AP Lines Uptake
8216 -- Cash based accounting support
8217 --
8218 IF G_cash_based_accounting = 'Y' and
8219 X_transaction_source in ( 'AP EXPENSE', 'AP INVOICE', 'AP NRTAX' , 'AP ERV',
8220 'INTERCOMPANY_AP_INVOICES', 'INTERPROJECT_AP_INVOICES', 'AP VARIANCE' ) THEN
8221
8222 l_invoice_id := NVL(l_SysRef2Tab(j) ,0) ;
8223 l_payment_status_flag := 'N' ;
8224
8225 -- R12 AP lines uptake : Prepayment changes
8226 -- For R12 prepayments applications , final payment logic is not required.Hence introduced below If condition
8227
8228 l_finalPaymentIdTab(j) := 0 ;
8229
8230 IF l_DocumentDistTypeTab(j) <> 'PREPAY' THEN -- R12 AP lines uptake : Prepayment changes
8231
8232 open c_final_payment ;
8233 fetch c_final_payment into l_payment_status_flag ;
8234 close c_final_payment ;
8235
8236 IF NVL(l_payment_status_flag,'N') = 'Y' THEN
8237 SELECT max(Invoice_Payment_Id)
8238 into l_finalPaymentIdTab(j)
8239 from ap_payment_hist_dists Paydist
8240 where NVL(paydist.pay_dist_lookup_code, 'CASH') = 'CASH'
8241 and Paydist.invoice_distribution_id = NVL(l_SysRef5Tab(j) ,0) ;
8242 END IF ; -- l_payment_status_flag = 'Y'
8243
8244 END IF; --IF l_DocumentDistTypeTab(j) <> 'PREPAY' THEN
8245 END IF ; -- G_cash_based_accounting = 'Y'
8246
8247 IF PG_DEBUG = 'Y' THEN
8248 log_message('log_message: l_invoice_id :' || l_invoice_id);
8249 log_message('log_message: l_payment_status_flag :' || l_payment_status_flag);
8250 log_message('log_message: NVL(l_SysRef5Tab(j) ,0) :' || NVL(l_SysRef5Tab(j) ,0));
8251 log_message('log_message: l_finalPaymentIdTab(j) :' || l_finalPaymentIdTab(j));
8252 END IF;
8253 END IF ;
8254
8255 IF PG_DEBUG = 'Y' THEN
8256 log_message('log_message: ' || 'Inside TrxRec Loop ' || l_CommitSizeRecCount || 'Txn If = ' || l_TxnIfIDTab(j));
8257 END IF;
8258
8259 l_CommitSizeRecCount := l_CommitSizeRecCount + 1;
8260
8261 -- Funds check related change
8262 g_cdl_system_reference2 := to_number(TRIM(l_SysRef2Tab(j))); -- Bug 3704356
8263 g_cdl_system_reference3 := to_number(TRIM(l_SysRef3Tab(j))); -- Bug 3704356
8264 g_cdl_system_reference4 := l_SysRef4Tab(j); -- 2339216; Commented for bug 4281765
8265 -- REL12 AP Lines Uptake
8266 -- Cash based accounting support
8267 --
8268 g_finalPaymentId := l_finalPaymentIdTab(j) ;
8269
8270 /* REL12-AP Lines uptake */
8271 g_cdl_system_reference5 := to_number(TRIM(l_SysRef5Tab(j))); -- 2339216
8272 -- End Funds check related change
8273
8274 IF PG_DEBUG = 'Y' THEN
8275 log_message('log_message: g_cdl_system_reference2 :' || g_cdl_system_reference2);
8276 log_message('log_message: g_cdl_system_reference3 :' || g_cdl_system_reference3);
8277 log_message('log_message: g_cdl_system_reference4 :' || g_cdl_system_reference4);
8278 log_message('log_message: g_cdl_system_reference5 :' || g_cdl_system_reference5);
8279 log_message('log_message: g_finalPaymentId :' || g_finalPaymentId);
8280 END IF;
8281
8282 -- SST Changes
8283 -- Initilize reversed orig txn reference
8284 G_reversed_orig_txn_reference := l_RevOrigTxnRefTab(j);
8285
8286 l_sys_link := l_SysLinkTab(j);
8287 l_expenditure_id := l_ExpIdTab(j);
8288 l_RevOrigTxnRef := l_RevOrigTxnRefTab(j);
8289 l_Accrual_Flag := l_AccrualFlagTab(j);
8290
8291 /* Fix for bug 2686544: Getting organization_name based on G_emp_org_oride flag
8292 here instead of inside the TrxRec cursors */
8293 /* Bug#3026218 For user-defined sources and predefined source with no Ids use
8294 the Organization_Name */
8295 /** If ( (G_trx_predef_flag = 'N') OR
8296 *** (G_trx_predef_flag = 'Y' and l_PrjIdTab(j) is null) ) Then
8297 **/
8298 IF l_PrjIdTab(j) IS NULL THEN
8299 If (nvl(G_emp_org_oride,'N') = 'Y') Then --Bug 2719674 added nvl
8300 If (l_OrganizationNameTab(j) is null) Then
8301 l_OrganizationNameTab(j) := GetOrgName(l_EmpNumTab(j),
8302 l_EiDateTab(j),
8303 l_PerBusGrpNameTab(j),
8304 l_person_typeTab(j)); /*cwk */
8305 End If;
8306 Else
8307 If (l_EmpNumTab(j) is not null) Then
8308 l_OrganizationNameTab(j) := GetOrgName(l_EmpNumTab(j),
8309 l_EiDateTab(j),
8310 l_PerBusGrpNameTab(j),
8311 l_person_typeTab(j)); /*cwk */
8312 End If;
8313 End If;
8314 End If;
8315 /* bug 2686544 */
8316
8317 IF PG_DEBUG = 'Y' THEN
8318 log_message('log_message: ' || 'Before selecting expend grouping attributes for transaction sources');
8319 END IF;
8320
8321 If (nvl(G_emp_org_oride,'N') = 'N' and l_PersonIdTab(j) is not NULL) Then /* bug#2719674 added nvl */
8322
8323 IF PG_DEBUG = 'Y' THEN
8324 pa_debug.G_err_stage := 'Calling pa_utils.GetEmpOrgJobId';
8325 log_message('log_message: ' || pa_debug.G_err_Stage);
8326 END IF;
8327 pa_utils.GetEmpOrgJobId( l_PersonIdTab(j),
8328 l_EiDateTab(j),
8329 l_EmpOrgIdTab(j),
8330 l_EmpJobIdTab(j) );
8331
8332 /* Bug 6857130: For Reversal trxns from OTL, stamping back the organization_id that was passed and
8333 discarding the rederived value in the above call*/
8334 IF X_transaction_source = 'ORACLE TIME AND LABOR' THEN
8335 /*Start-Added below condition to defaulting the jobid for bug:12433604 */
8336 IF l_job_idtab(j) IS NULL THEN
8337 l_job_idtab(j):=l_EmpJobIdTab(j);
8338 END IF;
8339 /*End-changes for bug:12433604 */
8340 IF (l_UnMatchNegFlagTab(j) = 'N' and l_OrganizationIdTab(j) is not null and l_RevOrigTxnRefTab(j) is not null AND l_job_idtab(j) IS NOT NULL ) THEN
8341
8342 IF PG_DEBUG = 'Y' THEN
8343 log_message('log_message: ' || 'Restamping the organization_id back to the value passed from OTL');
8344 END IF;
8345 l_EmpOrgIdTab(j) := l_OrganizationIdTab(j);
8346 l_EmpJobIdTab(j) := l_job_idtab(j);
8347 END IF;
8348
8349 END IF;
8350 /* Bug 6857130 End */
8351
8352
8353 IF PG_DEBUG = 'Y' THEN
8354 pa_debug.G_err_stage := 'l_EmpOrgIdTab = ' || l_EmpOrgIdTab(j) ||
8355 ' l_EmpJobIdTab = ' || l_EmpJobIdTab(j) ;
8356 log_message('log_message: ' || pa_debug.G_err_Stage);
8357 END IF;
8358
8359 Else
8360
8361 /*Code changes for the bug 16451280 */
8362 declare
8363 begin
8364 select PPL.person_id
8365 into L_PERSONIDTAB(J)
8366 from PER_PEOPLE_F PPL,
8367 PER_ASSIGNMENTS_f ASGN ,
8368 PER_PERSON_TYPES PTYPE
8369 where
8370 ASGN.VENDOR_ID = l_VendorIdTab(j)
8371 and PPL.PERSON_ID = ASGN.PERSON_ID
8372 and PTYPE.PERSON_TYPE_ID = PPL.PERSON_TYPE_ID
8373 and PTYPE.SYSTEM_PERSON_TYPE in ('OTHER','CWK');
8374
8375
8376 PA_UTILS.GETEMPORGJOBID( L_PERSONIDTAB(J),
8377 l_EiDateTab(j),
8378 l_EmpOrgIdTab(j),
8379 L_EMPJOBIDTAB(J) );
8380 exception
8381 when OTHERS then
8382 l_EmpOrgIdTab(j) := NULL;
8383 l_EmpJobIdTab(j) := NULL;
8384
8385 end;
8386
8387 End If;
8388
8389 SELECT
8390 to_char(trunc(l_EiEndDateTab(j)), 'J')||':'||
8391 nvl(decode(nvl(l_PersonIdTab(j),0), 0, l_EmpNumTab(j), l_PersonIdTab(j)),
8392 '-DUMMY EMP-')||':'||
8393 --removing the logic for getting organization name for getting l_expend1
8394 --as it has already been done above for 2686544. So we can just use l_OrganizationNameTab(j)
8395 --nvl(decode(G_emp_org_oride,'Y',
8396 -- decode(nvl(l_OrganizationIdTab(j),0), 0, l_OrganizationNameTab(j),l_OrganizationIdTab(j)),
8397 -- decode(nvl(l_PersonIdTab(j),0),0,
8398 -- decode(l_EmpNumTab(j), null,l_OrganizationNameTab(j),
8399 -- GetOrgName(l_EmpNumTab(j),l_EiDateTab(j), l_PerBusGrpNameTab(j)))
8400 -- ,l_EmpOrgIdTab(j))),
8401 nvl(decode(nvl(l_OrganizationIdTab(j),0), 0, l_OrganizationNameTab(j), nvl(l_EmpOrgIdTab(j), l_OrganizationIdTab(j)))
8402 ,'-DUMMY ORG-')||':'||
8403 nvl(l_OrigExpTxnRef1Tab(j), '-DUMMY EXP_TXN_REF1-') || ':' ||
8404 nvl(l_OrigUsrExpTxnRefTab(j), '-DUMMY USER_EXP_TXN_REF-') || ':' ||
8405 nvl(decode(nvl(l_VendorIdTab(j),0),0,l_VendorNumTab(j),l_VendorIdTab(j)),
8406 '-DUMMY VENDOR_NUMBER-') || ':' ||
8407 nvl(l_OrigExpTxnRef2Tab(j), '-DUMMY EXP_TXN_REF2-') || ':' ||
8408 nvl(l_OrigExpTxnRef3Tab(j), '-DUMMY EXP_TXN_REF3-') || ':' ||
8409 nvl(l_AccrualFlagTab(j),'-DUMMY ACC_FLAG-')|| ':' ||
8410 nvl(l_person_typeTab(j),'EMP') /* cwk */
8411 , decode(l_SysLinkTab(j),'OT','ST',l_SysLinkTab(j)) || ':' ||
8412 decode(l_SysLinkTab(j),'ER', nvl(l_DenomCurrCodeTab(j),'-DUMMY CODE-'),
8413 'VI', nvl(l_DenomCurrCodeTab(j),'-DUMMY CODE-'),
8414 '-DUMMY CODE-')||':'||
8415 decode(l_SysLinkTab(j),'ER', nvl(to_char(l_AcctRateDateTab(j),'MMDDYYYY'),'-DUMMY DATE-'),
8416 'VI', nvl(to_char(l_AcctRateDateTab(j),'MMDDYYYY'),'-DUMMY DATE-'),
8417 '-DUMMY DATE-')||':'||
8418 decode(l_SysLinkTab(j),'ER', nvl(l_AcctRateTypeTab(j),'-DUMMY TYPE-'),
8419 'VI', nvl(l_AcctRateTypeTab(j),'-DUMMY TYPE-'),
8420 '-DUMMY TYPE-')||':'||
8421 decode(l_SysLinkTab(j),'ER', nvl(to_char(l_AcctExchRateTab(j)),'-DUMMY RATE-'),
8422 'VI', nvl(to_char(l_AcctExchRateTab(j)),'-DUMMY RATE-'),
8423 '-DUMMY RATE-')
8424 Into l_Expend1, l_Expend2
8425 From Dual;
8426
8427 IF ( FIRST_RECORD ) THEN
8428 IF PG_DEBUG = 'Y' THEN
8429 pa_debug.G_err_stage := 'Calling loadExpCompareVars';
8430 log_message('log_message: ' || 'First Record Fetched');
8431 log_message('log_message: ' || pa_debug.G_err_stage);
8432 END IF;
8433
8434 loadExpCompareVars( l_Expend1
8435 , l_Expend2
8436 , l_EiEndDateTab(j)
8437 , l_OrigExpTxnRef1Tab(j)
8438 , l_OrigUsrExpTxnRefTab(j)
8439 , l_OrigExpTxnRef2Tab(j)
8440 , l_OrigExpTxnRef3Tab(j));
8441 FIRST_RECORD := FALSE;
8442
8443 /* Bug#2374725 Commented the following ELSIF statement and added a new condition */
8444 /* ELSIF ( current_expend <> l_Expend1 OR current_expend2 <> l_Expend2) THEN */
8445 ELSIF (x_transaction_source <> 'Oracle Self Service Time' and
8446 (current_expend <> l_Expend1 OR current_expend2 <> l_Expend2)) OR
8447 (x_transaction_source = 'Oracle Self Service Time' and
8448 l_ExpIdTab(j) <> G_expenditure_id) OR
8449 (x_transaction_source = 'ORACLE TIME AND LABOR' and --Bug#4049401
8450 l_EmpOrgIdTab(j) <> G_org_id) THEN
8451
8452 IF PG_DEBUG = 'Y' THEN
8453 pa_debug.G_err_stage := 'Calling newExpend when expenditure changes';
8454 log_message('log_message: ' || pa_debug.G_err_stage);
8455 log_message('log_message: ' || 'Record Count = ' || i);
8456 END IF;
8457
8458 newExpend( TrxBatch.exp_group_name
8459 , current_period
8460 , i
8461 , prev_denom_currency_code
8462 , G_accounting_currency_code
8463 , prev_acct_rate_type
8464 , prev_acct_rate_date
8465 , prev_acct_exchange_rate
8466 , prev_person_type /* cwk */
8467 , TrxBatch.batch_name ); -- Bug 3613784 : Performance fix
8468
8469 IF PG_DEBUG = 'Y' THEN
8470 pa_debug.G_err_stage := 'CAlling loadExpCompareVars';
8471 log_message('log_message: ' || pa_debug.G_err_stage);
8472 END IF;
8473
8474 loadExpCompareVars( l_Expend1
8475 , l_Expend2
8476 , l_EiEndDateTab(j)
8477 , l_OrigExpTxnRef1Tab(j)
8478 , l_OrigUsrExpTxnRefTab(j)
8479 , l_OrigExpTxnRef2Tab(j)
8480 , l_OrigExpTxnRef3Tab(j));
8481 END IF;
8482
8483 IF PG_DEBUG = 'Y' THEN
8484 pa_debug.G_err_stage := 'CAlling ValidateOrgId';
8485 log_message('log_message: ' || pa_debug.G_err_stage);
8486 END IF;
8487
8488 ValidateOrgId(l_OrgIdTab(j),X_org_status );
8489
8490 IF ( X_org_status IS NOT NULL) THEN
8491 -- Org id is null. Update status.
8492
8493 X_status := X_org_status;
8494
8495 ELSE -- org id is not null. continue with other validations
8496
8497 -- REL12 AP Lines uptake.
8498 -- Variance record created for CWK are only for funds check purpose
8499 -- and expenditure item will not be created.
8500 -- Variance in case of accrue on receipt and amount based PO
8501 -- will not create exp items.
8502 IF l_ExpItemIdTab(j) = 0 THEN
8503 X_ei_id := NULL ;
8504 -- null value of expenditure item id would indicate that expenditure item
8505 -- will not be created.
8506 ELSE
8507 X_ei_id := pa_utils.GetNextEiId;
8508
8509 -- REL12 : AP Lines uptake
8510 -- Support net zero adjusted transactions for the supplier invoice interface.
8511 --
8512 IF NVL(l_nzAdjFlagTab(j), 'N') = 'Y' and
8513 l_adjTxnInterfaceIdTab(j) is NULL THEN
8514
8515 l_adjTxnEiIDTab(l_txnIfIdTab(j)) := X_ei_id ;
8516
8517 IF PG_DEBUG = 'Y' THEN
8518 pa_debug.G_err_stage := 'AP Net Zero adjusted expenditure item id:'||X_ei_id;
8519 log_message('log_message: ' || pa_debug.G_err_stage);
8520 pa_debug.G_err_stage := 'TXN Interface ID:'||l_txnIfIdTab(j);
8521 log_message('log_message: ' || pa_debug.G_err_stage);
8522 pa_debug.G_err_stage := 'l_adjTxnEiIDTab(l_txnIfIdTab(j)):'||l_adjTxnEiIDTab(l_txnIfIdTab(j));
8523 log_message('log_message: ' || pa_debug.G_err_stage);
8524 END IF;
8525 END IF ;
8526
8527 END IF ;
8528
8529 IF PG_DEBUG = 'Y' THEN
8530 log_message('log_message: l_ExpItemIdTab(j) :' || l_ExpItemIdTab(j));
8531 log_message('log_message: NVL(l_nzAdjFlagTab(j), N) :' || NVL(l_nzAdjFlagTab(j), 'N'));
8532 log_message('log_message: l_adjTxnInterfaceIdTab(j) :' || l_adjTxnInterfaceIdTab(j));
8533 END IF ;
8534
8535 IF PG_DEBUG = 'Y' THEN
8536 pa_debug.G_err_stage := 'CAlling ValidateItem';
8537 log_message('log_message: ' || pa_debug.G_err_stage);
8538 END IF;
8539 log_message('before calling validateitemotl: worktype: ' || l_worktypeidtab(j));
8540 x_status := NULL ;
8541
8542 If (X_transaction_source = 'ORACLE TIME AND LABOR') Then
8543
8544 ValidateItemOTL(
8545 X_trx_src => X_transaction_source
8546 , X_ei_date => l_EiDateTab(j)
8547 , X_etype => l_ETypeTab(j)
8548 , X_nlr => l_NlrTab(j)
8549 , X_qty => l_QtyTab(j)
8550 , X_denom_raw_cost => l_DenomRawCostTab(j)
8551 , X_module => v_calling_module
8552 , X_trx_ref => l_OrigTxnRefTab(j)
8553 , X_match_flag => l_UnMatchNegFlagTab(j)
8554 , X_att_cat => l_AttCatTab(j)
8555 , X_att1 => l_Att1Tab(j)
8556 , X_att2 => l_Att2Tab(j)
8557 , X_att3 => l_Att3Tab(j)
8558 , X_att4 => l_Att4Tab(j)
8559 , X_att5 => l_Att5Tab(j)
8560 , X_att6 => l_Att6Tab(j)
8561 , X_att7 => l_Att7Tab(j)
8562 , X_att8 => l_Att8Tab(j)
8563 , X_att9 => l_Att9Tab(j)
8564 , X_att10 => l_Att10Tab(j)
8565 , X_system_linkage => l_SysLinkTab(j)
8566 , X_status => X_status
8567 --, X_bill_flag => X_billable_flag
8568 , X_denom_currency_code => l_DenomCurrCodeTab(j)
8569 , X_acct_rate_date => l_AcctRateDateTab(j)
8570 , X_acct_rate_type => l_AcctRateTypeTab(j)
8571 , X_acct_exchange_rate => l_AcctRateTypeTab(j)
8572 , X_project_currency_code => l_ProjCurrCodeTab(j)
8573 , X_Projfunc_currency_code => l_ProjFuncCurrCodeTab(j)
8574 , X_Projfunc_cost_rate_date =>l_PrjFuncRateDateTab(j)
8575 , X_Projfunc_cost_rate_type => l_PrjFuncRateTypeTab(j)
8576 , X_Projfunc_cost_exchange_rate => l_PrjFuncExchRateTab(j)
8577 , X_Assignment_Name => l_AsgnNameTab(j)
8578 , X_Work_Type_Name => l_WorkTypeNameTab(j)
8579 , P_project_id => l_PrjIdTab(j)
8580 , P_task_id => l_TaskIdTab(j)
8581 , P_person_id => l_PersonIdTab(j)
8582 , P_organization_id => l_OrganizationIdTab(j)
8583 , P_assignment_id => l_AsgnIdTab(j)
8584 , P_work_type_id => l_WorkTypeIdTab(j)
8585 , P_Emp_Org_Id => l_EmpOrgIdTab(j)
8586 , P_Emp_Job_Id => l_EmpJobIdTab(j)
8587 , P_po_header_id => l_po_header_idTab(j)
8588 , P_po_line_id => l_po_line_idTab(j)
8589 , P_person_type => l_person_typeTab(j)
8590 , P_po_price_type => l_po_price_typeTab(j)
8591 , p_vendor_id => l_VendorIdTab(j) /* Bug # 3601024 */
8592 , p_location_id => l_location_Idtab(j)
8593 , p_cbs_element_id => l_cbs_element_idtab(j) -- Added for bug 16592018
8594 );
8595
8596 X_Billable_Flag := l_BillableFlagTab(j);
8597
8598 if l_worktypeidtab(j) is not null then
8599 G_Work_Type_Id := l_WorkTypeIdTab(j);
8600 end if;
8601
8602 Else
8603 l_gms_fundscheck := 'Y' ;
8604
8605 IF ( v_calling_module = 'PAAPIMP' ) THEN
8606 -- REL12 AP Lines Uptake
8607 -- Cash based accounting support
8608 --
8609 IF G_cash_based_accounting = 'Y' and
8610 X_transaction_source in ( 'AP EXPENSE', 'AP INVOICE', 'AP NRTAX' , 'AP ERV',
8611 'INTERCOMPANY_AP_INVOICES', 'INTERPROJECT_AP_INVOICES', 'AP VARIANCE' ) THEN
8612 --
8613 -- If one payment rejected then all the payments following it for the given
8614 -- invoice distribution id should be rejected.
8615 --
8616 IF l_rejectedSysRef5 = NVL(l_SysRef5Tab(j),0) THEN
8617
8618 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
8619 --
8620 IF l_status in ( 'GMS_EXP_ITEM_DT_BEFORE_AWD_ST' ,'GMS_EXP_ITEM_DT_AFTER_AWD_END' ,
8621 'GMS_AWARD_IS_CLOSED' , 'EXP_TYPE_INACTIVE' , 'ETYPE_SLINK_INACTIVE' ,
8622 'PA_EX_PROJECT_DATE' , 'PA_EXP_TASK_EFF' , 'PA_EXP_ORG_NOT_ACTIVE' , 'NO_ASSIGNMENT'
8623 ) THEN
8624 --
8625 -- x_status := 'Unable to process this record because at least one record for the same
8626 -- distributions has been rejected.'
8627 --
8628 x_status := 'PA_REJECTED_PARENT_RECORD' ;
8629 ELSE
8630 x_status := l_status ;
8631 END IF ;
8632
8633 END IF ;
8634
8635 IF PG_DEBUG = 'Y' THEN
8636 log_message('log_message: If one payment rejected then all the payments following it for the given' );
8637 log_message('log_message: invoice distribution id should be rejected.') ;
8638 log_message('log_message: x_status :'||x_status ) ;
8639 END IF ;
8640
8641
8642 ELSE
8643 l_rejectedSysRef5 := 0 ;
8644 END IF ;
8645
8646 IF ( NVL(l_old_sysRef1, '0') = NVL(l_SysRef1Tab(j), '0') AND
8647 NVL(l_old_sysRef2, '0') = NVL(l_SysRef2Tab(j), '0') AND
8648 NVL(l_old_sysRef3, '0') = NVL(l_SysRef3Tab(j), '0') AND
8649 NVL(l_old_sysRef4, '0') = NVL(l_SysRef4Tab(j), '0') AND
8650 NVL(l_old_sysRef5, 0) = NVL(l_SysRef5Tab(j), 0) ) THEN
8651 --
8652 -- Project and GMS fundschecking should be done once for a given ap
8653 -- distribution lines.
8654 -- Here because of adjustments in projects/Grants there may be multiple
8655 -- records created to back out the expenditure item.
8656 --
8657 l_gms_fundscheck := 'N' ;
8658 l_FcDocTypeTab(j):= 'NOT' ;
8659 ELSE
8660 l_gms_fundscheck := 'Y' ;
8661 l_old_sysRef1 := l_SysRef1Tab(j) ;
8662 l_old_sysRef2 := l_SysRef2Tab(j) ;
8663 l_old_sysRef3 := l_SysRef3Tab(j) ;
8664 l_old_sysRef4 := l_SysRef4Tab(j) ;
8665 l_old_sysRef5 := l_SysRef5Tab(j) ;
8666 END IF ;
8667
8668 G_adj_item_id := l_AdjExpItemIDTab(j) ;
8669
8670 IF PG_DEBUG = 'Y' THEN
8671 log_message('log_message: l_gms_fundscheck :'||l_gms_fundscheck) ;
8672 log_message('log_message: l_FcDocTypeTab(j) :'||l_FcDocTypeTab(j)) ;
8673 log_message('log_message: G_adj_item_id :'|| G_adj_item_id ) ;
8674 END IF ;
8675
8676 --
8677 -- Bug:5064930
8678 -- Reject the net zero reversals if pa adjustments have rejected
8679 --
8680 x_status := get_parent_txn_status(x_status, j) ;
8681
8682 -- R12 Check if we need date validations..
8683 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
8684 -- We do not validate expenditure item adjustments, Net Zero for reversals or
8685 -- funds check adjustments.
8686 --
8687 IF ( G_adj_item_id is NOT NULL ) OR
8688 ( l_ExpItemIdTab(j) = 0 ) OR
8689 ( l_adjTxnInterfaceIDTab(j) is not NULL )
8690 THEN
8691 g_paapimp_validate_dt := 'N' ;
8692
8693 IF G_adj_item_id = 0 THEN
8694 -- PAAPIMP create a record with G_adj_item_id value 0 to indicate date validation
8695 -- not required for the adjustment created to take care of the accounting mismatch
8696 -- for the supplier cost adjustments.
8697 --
8698 G_adj_item_id := NULL ;
8699 l_AdjExpItemIDTab(j) := NULL ;
8700 END IF ;
8701
8702 ELSE
8703 g_paapimp_validate_dt := 'Y' ;
8704 END IF ;
8705 END IF ;
8706
8707 -- REL12 AP Lines Uptake
8708 -- Cash based accounting support
8709 -- IF x_status is NULL THEN was added.
8710 --
8711 IF PG_DEBUG = 'Y' THEN
8712 pa_debug.G_err_stage := 'before calling ValidateItem API.. job name: '||l_job_nametab(j) ||', job id: ' || l_job_idtab(j);
8713 log_message('log_message: ' || pa_debug.G_err_stage);
8714 END IF;
8715
8716 IF x_status is NULL THEN
8717 --select
8718 ---- Added for payroll billable_flag changes for 12.2 start bug#12344689
8719 g_costing_method := NULL;
8720 g_rate_source_code := NULL;
8721 g_enable_accrual_code := NULL;
8722 g_payroll_accrual_flag := NULL;
8723
8724 pa_utils.get_rate_source_cost_method(l_ExpItemIdTab(j),l_EiDateTab(j),g_rate_source_code,
8725 g_costing_method,g_enable_accrual_code);
8726
8727 IF (g_enable_accrual_code = 'YES') THEN
8728 --{
8729 g_payroll_accrual_flag := 'Y';
8730 --}
8731 ELSE
8732 --{
8733 g_payroll_accrual_flag := 'N';
8734 --}
8735 END IF;
8736
8737 ---- Added for payroll billable_flag changes for 12.2 end bug#12344689
8738
8739 ValidateItem( X_transaction_source
8740 , l_EmpNumTab(j)
8741 , l_OrganizationNameTab(j)
8742 , l_EiEndDateTab(j)
8743 , l_EiDateTab(j)
8744 , l_ETypeTab(j)
8745 , l_PrjNumTab(j)
8746 , l_TaskNumTab(j)
8747 , l_NlrTab(j)
8748 , l_NlrOrgNameTab(j)
8749 , l_QtyTab(j)
8750 , l_DenomRawCostTab(j)
8751 -- Bug 987539
8752 , v_calling_module --'PAXTRTRX'
8753 , l_OrigTxnRefTab(j)
8754 , l_UnMatchNegFlagTab(j)
8755 , X_userid
8756 , l_AttCatTab(j)
8757 , l_Att1Tab(j)
8758 , l_Att2Tab(j)
8759 , l_Att3Tab(j)
8760 , l_Att4Tab(j)
8761 , l_Att5Tab(j)
8762 , l_Att6Tab(j)
8763 , l_Att7Tab(j)
8764 , l_Att8Tab(j)
8765 , l_Att9Tab(j)
8766 , l_Att10Tab(j)
8767 , l_DRCCIDTab(j)
8768 , l_CRCCIDTab(j)
8769 , l_GlDateTab(j)
8770 , l_DenomBdCostTab(j)
8771 , l_SysLinkTab(j)
8772 , X_status
8773 , X_billable_flag
8774 , l_RcptCurrAmtTab(j)
8775 , l_RcptCurrCodeTab(j)
8776 , l_RcptExchRateTab(j)
8777 , l_DenomCurrCodeTab(j)
8778 , l_AcctRateDateTab(j)
8779 , l_AcctRateTypeTab(j)
8780 , l_AcctExchRateTab(j)
8781 , l_AcctRawCostTab(j)
8782 , l_AcctBdCostTab(j)
8783 , l_AcctExchRndLimitTab(j)
8784 , l_ProjCurrCodeTab(j)
8785 , l_prjRateDateTab(j)
8786 , l_PrjRateTypeTab(j)
8787 , l_PrjExchRateTab(j)
8788 , l_rawCostTab(j)
8789 , l_burdenedCostTab(j)
8790 , l_OverrideOrgNameTab(j)
8791 , l_VendorNumTab(j)
8792 , l_OrgIdTab(j)
8793 , l_PerBusGrpNameTab(j)
8794 , l_ProjFuncCurrCodeTab(j)
8795 , l_PrjFuncRateDateTab(j)
8796 , l_PrjFuncRateTypeTab(j)
8797 , l_PrjFuncExchRateTab(j)
8798 , l_ProjRawCostTab(j)
8799 , l_ProjBdCostTab(j)
8800 , l_AsgnNameTab(j)
8801 , l_WorkTypeNameTab(j)
8802 , l_AccrualFlagTab(j)
8803 , l_PrjIdTab(j)
8804 , l_TaskIdTab(j)
8805 , l_PersonIdTab(j)
8806 , l_OrganizationIdTab(j)
8807 , l_NLROrgIDTab(j)
8808 , l_VendorIdTab(j)
8809 , l_OverrideOrgIdTab(j)
8810 , l_PersonBusGrpIdTab(j)
8811 , l_AsgnIdTab(j)
8812 , l_WorkTypeIdTab(j)
8813 , l_EmpOrgIdTab(j)
8814 , l_EmpJobIdTab(j)
8815 /* Passed the value TrxRec.txn_interface_id for bug 2563364 */
8816 , l_TxnIfIDTab(j)
8817 , l_po_numberTab(j) /* cwk */
8818 , l_po_header_idTab(j)
8819 , l_po_line_numTab(j)
8820 , l_po_line_idTab(j)
8821 , l_person_typeTab(j)
8822 , l_po_price_typeTab(j)
8823 , l_AdjExpItemIdTab(j)
8824 , l_FcDocTypeTab(j)
8825 -- , l_agreement_idTab(j) --FSIO Change
8826 -- , l_agreement_numberTab(j) );
8827 -- 10253400: Payroll integration enhancement for 12.2..start
8828 , l_job_idtab(j)
8829 , l_job_nametab(j)
8830 , l_location_Idtab(j)
8831 , l_location_Codetab(j)
8832 , l_pay_element_type_Idtab(j)
8833 -- 10253400: Payroll integration enhancement for 12.2..end
8834 -- Start: Added for CBS Enhancement Bug 16220146
8835 , l_cbs_element_idtab(j)
8836 , l_cbs_element_nametab(j)
8837 );
8838 -- End: Added for CBS Enhancement Bug 16220146
8839 END IF ;
8840
8841 IF PG_DEBUG = 'Y' THEN
8842 pa_debug.G_err_stage := 'Done calling ValidateItem API';
8843 log_message('log_message: ' || pa_debug.G_err_stage);
8844 END IF;
8845 End If;
8846
8847 if l_location_idTab(j) is null then
8848 l_location_Idtab(j) := G_Location_Id;
8849 end if;
8850
8851 -- l_BdCostRateTab(j) := l_burdenedCostTab(j)/nvl(l_QtyTab(j),1); --For Bug 4057531
8852
8853 /* Changes for bug 6719252 start here */
8854
8855 IF (l_SysLinkTab(j) = 'VI' OR l_SysLinkTab(j) = 'ER') THEN
8856 IF ( NVL(G_PrjInfoBdDisplay, 'S') = 'S') THEN
8857 IF (l_burdenedCostTab(j) = 0 or l_QtyTab(j)= 0) THEN --added condition to check for l_QtyTab(j)= 0 for the bug 7459889
8858 l_BdCostRateTab(j) := l_burdenedCostTab(j); -- which would be 0, in this case.
8859 ELSE
8860 /*IF l_QtyTab(j) = 0 then --added For bug:7436883
8861 l_QtyTab(j) :=1;
8862 END IF; Commented as part for bug 7591839*/
8863 l_BdCostRateTab(j) := l_burdenedCostTab(j)/nvl(l_QtyTab(j),1);
8864 END IF;
8865 END IF;
8866 END IF;
8867
8868 /* Changes for bug 6719252 end here */
8869
8870 -- -----------------------------------------------------------------------
8871 -- OGM_0.0 - Vertical application implementations may need to validate
8872 -- transactions based on there business needs. So the following code hook
8873 -- will call Vertical applications validations routines. It will look st
8874 -- x_status and continue validations if x_status is NULL and vertical
8875 -- application is implemented only.
8876 -- ------------------------------------------------------------------------
8877 IF PG_DEBUG = 'Y' THEN
8878 pa_debug.G_err_stage := 'Calling PA_GMS_API api';
8879 log_message('log_message: ' || pa_debug.G_err_stage);
8880 END IF;
8881
8882 IF l_gms_enabled = 'Y' and l_gms_fundscheck = 'Y' THEN
8883 PA_GMS_API.vert_app_validate(X_transaction_source,
8884 TrxBatch.batch_name,
8885 l_TxnIfIDTab(j),
8886 l_OrgIdTab(j),
8887 X_status ) ;
8888
8889 if X_status is null then
8890
8891 GMS_PA_Costing_Pkg.FundsCheck_Supplier_Cost(p_transaction_source => x_transaction_source,
8892 p_txn_interface_id => l_TxnIfIDTab(j),
8893 p_request_id => g_request_id,
8894 p_status => X_status);
8895
8896 end if;
8897
8898 END IF; --> gms_enabled.
8899
8900 IF PG_DEBUG = 'Y' THEN
8901 pa_debug.G_err_stage := 'After PA_GMS_API api';
8902 log_message('log_message: ' || pa_debug.G_err_stage);
8903 END IF;
8904
8905 -- validateitem has lot of return statements, so instead
8906 -- resetting the error stack for each return statement
8907 -- we are resetting the stack after executing
8908 -- validateitem.
8909
8910 --Bug 2749049
8911 pa_cc_utils.reset_curr_function; /* Uncommented for Bug 4309932 */
8912
8913 END IF; -- end X_org_status is not null
8914
8915 IF ( X_status IS NOT NULL ) THEN
8916
8917 IF PG_DEBUG = 'Y' THEN
8918 pa_debug.G_err_stage := 'Updating txn interface table for txn'||
8919 ' rejected by validateitem';
8920 log_message('log_message: ' || pa_debug.G_err_stage);
8921 END IF;
8922
8923 /* PA-K
8924 Performance Team Suggestion: To combine the below update (by txn_interface_id) with the
8925 update in newexpend (by expenditure_id).
8926 Results: For 20,000 records - gain of 30 sec.
8927 Implementing this combined update has been phased out until there is a dire need to do it.
8928 Placing this comment here for reference.
8929 */
8930 UPDATE pa_transaction_interface
8931 SET
8932 transaction_rejection_code = X_status
8933 , interface_id = X_xface_id
8934 , expenditure_id = G_expenditure_id
8935 , transaction_status_code = 'R'
8936 WHERE txn_interface_id = l_TxnIfIDTab(j);
8937 --PA-K Changes: Removed 'current of' clause as the 'for update'
8938 -- clause in Trxrecs has been removed.
8939 --WHERE CURRENT OF TrxRecs;
8940 IF PG_DEBUG = 'Y' THEN
8941 log_message('log_message: ' || 'Updated to reject count ' || SQL%ROWCOUNT);
8942 END IF;
8943
8944 REJECT_EXP := TRUE;
8945
8946 -- REL12 AP Lines Uptake
8947 -- Cash based accounting support
8948 -- l_rejectedSysRef5 and l_status was populated.
8949 --
8950 l_rejectedSysRef5 := NVL(l_SysRef5Tab(j), 0) ;
8951 l_status := X_status ;
8952 l_txn_rejected_sr4tab(NVL(l_SysRef4Tab(j),0) ) := l_TxnIfIDTab(j) ;
8953 l_txn_rejected_sr5tab(NVL(l_SysRef5Tab(j),0) ) := l_TxnIfIDTab(j) ;
8954
8955 IF PG_DEBUG = 'Y' THEN
8956 log_message('log_message: l_txn_rejected_sr4tab(NVL(l_SysRef4Tab(j),0) ) :'||
8957 l_txn_rejected_sr4tab(NVL(l_SysRef4Tab(j),0) )) ;
8958 log_message('log_message: l_txn_rejected_sr5tab(NVL(l_SysRef5Tab(j),0) ) :'||
8959 l_txn_rejected_sr5tab(NVL(l_SysRef5Tab(j),0) )) ;
8960
8961 log_message('log_message: NVL(l_SysRef5Tab(j), 0) :'|| NVL(l_SysRef5Tab(j), 0) ) ;
8962 log_message('log_message: NVL(l_SysRef4Tab(j), 0) :'|| NVL(l_SysRef4Tab(j), 0) ) ;
8963 END IF ;
8964
8965
8966 ELSE
8967
8968 -- BUG:4748305 DFHC.D4:PRC INTERFACE SUPPLIER COST NOT INTERFACING
8969 -- VALID INVOICE DISTRIBUTIONS
8970 -- We allow good ap invoice distributions to interface in a expenditure
8971 -- and do not reject all the expenditure items in expenditure
8972 -- This is only done for VI items.
8973 IF v_calling_module = 'PAAPIMP' and
8974 TrxBatch.system_linkage_function = 'VI' THEN
8975
8976 IF PG_DEBUG = 'Y' THEN
8977 pa_debug.G_err_stage := 'Processing the valid distributions '||
8978 ' accepted by validateitem';
8979 log_message('log_message: ' || pa_debug.G_err_stage);
8980 END IF;
8981
8982
8983 REJECT_EXP := FALSE;
8984 END IF ;
8985
8986 IF PG_DEBUG = 'Y' THEN
8987 pa_debug.G_err_stage := 'Updating txn interface table for txn'||
8988 ' accepted by validateitem';
8989 log_message('log_message: ' || pa_debug.G_err_stage);
8990 END IF;
8991
8992 UPDATE pa_transaction_interface
8993 SET
8994 transaction_rejection_code = NULL
8995 , interface_id = X_xface_id
8996 , expenditure_id = G_expenditure_id
8997 , expenditure_item_id = nvl(X_ei_id, 0) /* Bug 8709614 */
8998 -- SST Changes: If TrxRec.reversed_orig_txn_reference
8999 -- is NULL, this means we've called verifyorigitem API
9000 -- to get the reversed item's orig_txn_reference and
9001 -- store it in G_reversed_orig_txn_reference
9002 , reversed_orig_txn_reference =
9003 nvl(l_RevOrigTxnRefTab(j),G_reversed_orig_txn_reference)
9004 WHERE txn_interface_id = l_TxnIfIDTab(j);
9005
9006 l_rejectedSysRef5 := 0 ;
9007 l_status := NULL ;
9008
9009 IF PG_DEBUG = 'Y' THEN
9010 log_message('log_message: ' || 'Updated to accepted count ' || SQL%ROWCOUNT);
9011 log_message('log_message: ' || 'l_AdjTxnInterfaceIdTab(j) ' ||
9012 l_AdjTxnInterfaceIdTab(j));
9013
9014 END IF;
9015
9016 IF l_nzAdjFlagTab(j) = 'Y' and
9017 l_AdjTxnInterfaceIdTab(j) is not NULL THEN
9018 G_adj_item_id := l_AdjTxnEiIDTab(l_AdjTxnInterfaceIdTab(j) ) ;
9019 END IF ;
9020
9021 END IF;
9022
9023 IF ( NOT REJECT_EXP ) THEN ---{
9024
9025 i := i + 1;
9026
9027 IF (G_trx_costed = 'N' ) THEN
9028
9029 l_DenomRawCostTab(j) := NULL;
9030 l_rawCostRateTab(j) := NULL;
9031 l_AcctRawCostTab(j) := NULL;
9032 l_rawCostTab(j) := NULL;
9033
9034 ELSIF ( G_trx_costed = 'Y' ) THEN
9035
9036 IF PG_DEBUG = 'Y' THEN
9037 pa_debug.G_err_stage := 'rounding transaction raw cost';
9038 log_message('log_message: ' || pa_debug.G_err_stage);
9039 END IF;
9040
9041 l_DenomRawCostTab(j) := pa_currency.round_trans_currency_amt1(l_DenomRawCostTab(j),l_DenomCurrCodeTab(j));
9042
9043 /* Added the call to round off denom_burdened_cost for bug 2871273 */
9044
9045 IF PG_DEBUG = 'Y' THEN
9046 pa_debug.G_err_stage := 'rounding transaction burden cost';
9047 log_message('log_message: ' || pa_debug.G_err_stage);
9048 END IF;
9049
9050 l_DenomBdCostTab(j) := pa_currency.round_trans_currency_amt1(l_DenomBdCostTab(j),l_DenomCurrCodeTab(j));
9051
9052 END IF;
9053
9054 /* REL12-AP Lines uptake START */
9055 --
9056 --BUG : 4696351 PJ.R12:DI4:APLINES: VENDOR INFORMATION NOT IMPORTED DURING TRANSACTION IMPORT
9057 --
9058 IF v_calling_module <> 'PAAPIMP' THEN
9059 IF l_SysLinkTab(j) in ( 'ER', 'VI' ) THEN
9060 l_vendor_id := g_vendor_id ;
9061 l_SysRef1Tab(j) := g_vendor_id ;
9062 END IF ;
9063 END IF ;
9064
9065 -- R12 Bug Fixes
9066 -- 4919999
9067 -- R12.PJ:XB1:DEV:APL:EIB RELATED CHANGES FOR R12 IN TRANSACTION IMPORT
9068 --
9069 IF X_transaction_source in ('CSE_PO_RECEIPT', 'CSE_PO_RECEIPT_DEPR' ) THEN
9070 l_vendor_id := l_SysRef1Tab(j) ;
9071 l_doc_header_id := l_SysRef2Tab(j) ;
9072 l_doc_distribution_id := l_SysRef4Tab(j) ; -- RCV Transaction ID
9073 -- ===============
9074 -- Populate po distribution id in l_Doc_line_number for receipt.
9075 -- ===============
9076 l_Doc_line_number := l_SysRef3Tab(j) ;
9077
9078 ELSIF X_transaction_source in ( 'CSE_IPV_ADJUSTMENT', 'CSE_IPV_ADJUSTMENT_DEPR' ) THEN
9079 l_vendor_id := l_SysRef1Tab(j) ;
9080 l_doc_header_id := l_SysRef2Tab(j) ;
9081 l_doc_distribution_id := l_SysRef5Tab(j) ;
9082 l_Doc_line_number := l_SysRef3Tab(j) ;
9083 l_SysRef5Tab(j) := NULL ;
9084 END IF ;
9085 -- 4919999 R12.PJ:XB1:DEV:APL:EIB RELATED CHANGES FOR R12 IN TRANSACTION IMPORT
9086 -- End of R12 Bug Fixes
9087 --
9088
9089 -- 4927696 PAYABLES INTERFACE TO POPULATE SR_5 WITH PAYMENT_HIST_DIST_ID
9090 -- Cost distribution lines , System_reference5 is populated with the payment_hist_dist_id
9091 -- for discounts and payments.
9092 -- For prepay application in cash based accounting, SR5 is populated with the pre-pay
9093 -- appdist_id.
9094 IF PG_DEBUG = 'Y' THEN
9095 log_message('log_message: Cost distribution lines , System_reference5 is populated with the ') ;
9096 log_message('log_message: payment_hist_dist_id for discounts and payments. ') ;
9097 log_message('log_message: For prepay application in cash based accounting, SR5') ;
9098 log_message('log_message: is populated with the pre-pay appdist_id.') ;
9099
9100 pa_debug.G_err_stage := 'l_VendorIdTab(j) : '|| l_VendorIdTab(j) ;
9101 log_message('log_message: ' || pa_debug.G_err_stage);
9102
9103 pa_debug.G_err_stage := 'l_SysRef1Tab(j) : '|| l_SysRef1Tab(j) ;
9104 log_message('log_message: ' || pa_debug.G_err_stage);
9105 pa_debug.G_err_stage := 'l_SysRef2Tab(j) : '|| l_SysRef2Tab(j) ;
9106 log_message('log_message: ' || pa_debug.G_err_stage);
9107 pa_debug.G_err_stage := 'l_SysRef3Tab(j) : '|| l_SysRef3Tab(j) ;
9108 log_message('log_message: ' || pa_debug.G_err_stage);
9109 pa_debug.G_err_stage := 'l_SysRef4Tab(j) : '|| l_SysRef4Tab(j) ;
9110 log_message('log_message: ' || pa_debug.G_err_stage);
9111 pa_debug.G_err_stage := 'l_SysRef5Tab(j) : '|| l_SysRef5Tab(j) ;
9112 log_message('log_message: ' || pa_debug.G_err_stage);
9113 END IF;
9114
9115 IF v_calling_module = 'PAAPIMP' THEN
9116
9117 -- 4927696 PAYABLES INTERFACE TO POPULATE SR_5 WITH PAYMENT_HIST_DIST_ID
9118 l_vendor_id := NVL(l_VendorIdTab(j), l_SysRef1Tab(j)) ;
9119
9120 IF X_transaction_source in ( 'AP EXPENSE', 'AP INVOICE', 'AP NRTAX' , 'AP ERV',
9121 'INTERCOMPANY_AP_INVOICES', 'INTERPROJECT_AP_INVOICES',
9122 'AP VARIANCE' ) THEN
9123 l_doc_header_id := l_SysRef2Tab(j) ;
9124 l_doc_distribution_id := l_SysRef5Tab(j) ;
9125 l_Doc_line_number := l_SysRef3Tab(j) ;
9126
9127 -- CDL place holder for subledger id for transaction source of RECEIPTS and
9128 -- Manufacturing related records.
9129 l_SysRef5Tab(j) := NULL ;
9130 IF g_cash_based_accounting = 'Y' Then
9131
9132 -- For historical transactions l_SysRef4Tab(j) is populated with the
9133 -- 'NONREC_TAX'. Invoice distributions gets interfaced instead of
9134 -- Payments.
9135 -- BUG : 5370864
9136 -- R12.PJ:XB6:QA:APL:UPG:INTERFACE SUPP COSTS ERRORS TAX NOT INTERFACED AFTER UPG
9137 --
9138 IF l_DocumentDistTypeTab(j) <> NVL(l_SysRef4Tab(j), l_DocumentDistTypeTab(j)) THEN
9139 l_doc_payment_id := l_SysRef4Tab(j) ; -- Populated when Cash based accounting is setup.
9140 ELSE
9141 -- This is a historical transactions and payment is not interfaced. Invoice dist
9142 -- is getting interfaced instead.
9143 -- Bug : 5443263
9144 -- R12.PJ:XB7:QA:APL:UPG:ADJUSTMENT REVERSAL NOT GETTING ACCOUNTED IN CASH
9145 -- Resolution :
9146 -- We need to mark such expenditure items corresponding to invoice distributions
9147 -- as historical. The '-1' value in the l_doc_payment_id would indicate in
9148 -- PA_transactions package that this is a cash based accounting when invoice distributions
9149 -- is getting interfaced instead of payment. The value would be flipped back to null
9150 -- in the pa transactions InsItems api before creating the exp items.
9151 l_doc_payment_id := -1 ;
9152 END IF ;
9153
9154 -- l_SysRef1Tab records the payment hist dist ID when needed to go to system_reference5
9155 -- of CDLs.
9156 -- 4927696 PAYABLES INTERFACE TO POPULATE SR_5 WITH PAYMENT_HIST_DIST_ID
9157 l_SysRef5Tab(j) := l_SysRef1Tab(j) ;
9158 l_SysRef1Tab(j) := l_VendorIdTab(j) ;
9159
9160 IF l_DocumentDistTypeTab(j) = 'PREPAY' and
9161 l_doc_payment_id is not NULL and
9162 l_doc_payment_id <> -1 THEN
9163 --
9164 -- Document_payment_id is the prepay app dist id
9165 --
9166 -- 4927696 PAYABLES INTERFACE TO POPULATE SR_5 WITH PAYMENT_HIST_DIST_ID
9167 l_SysRef5Tab(j) := l_doc_payment_id ;
9168 END IF ;
9169 END IF;
9170
9171
9172 ELSIF X_transaction_source in ( 'AP DISCOUNTS' ) THEN
9173 l_doc_header_id := l_SysRef2Tab(j) ;
9174 l_doc_distribution_id := l_SysRef5Tab(j) ;
9175 l_Doc_line_number := l_SysRef3Tab(j) ;
9176 l_doc_payment_id := l_SysRef4Tab(j) ;
9177
9178 -- CDL place holder for subledger id for transaction source of RECEIPTS and
9179 -- Manufacturing related records.
9180
9181 -- l_SysRef1Tab records the payment hist dist ID when needed to go to system_reference5
9182 -- of CDLs.
9183 -- 4927696 PAYABLES INTERFACE TO POPULATE SR_5 WITH PAYMENT_HIST_DIST_ID
9184
9185 /* Bug 8674676. If its cancelled payment then system_reference 5 should be parent payment_hist_dist_id.
9186 Added additional debug messages also */
9187 pa_debug.G_err_stage := '1. After l_SysRef5Tab(j) : '|| l_SysRef5Tab(j) ;
9188 log_message('log_message: ' || pa_debug.G_err_stage);
9189
9190 select decode(reversal_flag, 'Y', reversed_pay_hist_dist_id,l_SysRef1Tab(j))
9191 into l_SysRef5Tab(j)
9192 from ap_payment_hist_dists
9193 where payment_hist_dist_id = l_SysRef1Tab(j);
9194
9195 pa_debug.G_err_stage := '2. After l_SysRef5Tab(j) : '|| l_SysRef5Tab(j) ;
9196 log_message('log_message: ' || pa_debug.G_err_stage);
9197
9198 --l_SysRef5Tab(j) := l_SysRef1Tab(j) ;
9199 --Commented for bug 8674676 and added above decode logic.
9200
9201 l_SysRef1Tab(j) := l_VendorIdTab(j) ;
9202
9203 ELSIF X_transaction_source in ( 'PO RECEIPT', 'PO RECEIPT NRTAX',
9204 'PO RECEIPT PRICE ADJ', 'PO RECEIPT NRTAX PRICE ADJ' ) THEN
9205 l_doc_header_id := l_SysRef2Tab(j) ;
9206 l_doc_distribution_id := l_SysRef4Tab(j) ; -- RCV Transaction ID
9207 -- ===============
9208 -- Populate po distribution id in l_Doc_line_number for receipt.
9209 -- ===============
9210 l_Doc_line_number := l_SysRef3Tab(j) ;
9211 l_doc_payment_id := NULL ;
9212 ELSE
9213 l_doc_header_id := NULL ;
9214 l_doc_distribution_id := NULL ;
9215 l_Doc_line_number := NULL ;
9216 l_doc_payment_id := NULL ;
9217 END IF ;
9218 END IF ; -- IF v_calling_module = 'PAAPIMP'
9219
9220 IF PG_DEBUG = 'Y' THEN
9221
9222 pa_debug.G_err_stage := ' After l_VendorIdTab(j) : '|| l_VendorIdTab(j) ;
9223 log_message('log_message: ' || pa_debug.G_err_stage);
9224
9225 pa_debug.G_err_stage := ' After l_SysRef1Tab(j) : '|| l_SysRef1Tab(j) ;
9226 log_message('log_message: ' || pa_debug.G_err_stage);
9227 pa_debug.G_err_stage := ' After l_SysRef2Tab(j) : '|| l_SysRef2Tab(j) ;
9228 log_message('log_message: ' || pa_debug.G_err_stage);
9229 pa_debug.G_err_stage := ' After l_SysRef3Tab(j) : '|| l_SysRef3Tab(j) ;
9230 log_message('log_message: ' || pa_debug.G_err_stage);
9231 pa_debug.G_err_stage := 'After l_SysRef4Tab(j) : '|| l_SysRef4Tab(j) ;
9232 log_message('log_message: ' || pa_debug.G_err_stage);
9233 pa_debug.G_err_stage := 'After l_SysRef5Tab(j) : '|| l_SysRef5Tab(j) ;
9234 log_message('log_message: ' || pa_debug.G_err_stage);
9235 END IF;
9236
9237 /* REL12-AP Lines uptake END */
9238
9239 IF ( nvl(G_gl_accted_flag,'N') = 'N' ) THEN
9240 -- If the transaction is not accounted, the costing
9241 -- program will calculate the functional and project
9242 -- costs, so Null out the functional and project costs
9243 -- for un accounted txns. Null out the exchange rates if
9244 -- the exchange rate type is not user.
9245
9246 l_AcctRawCostTab(j) := NULL;
9247 l_AcctBdCostTab(j) := NULL;
9248 l_rawCostTab(j) := NULL;
9249 l_burdenedCostTab(j) := NULL;
9250
9251 /*S.N. Bug 5170366 */
9252 IF (nvl(G_proj_bcost_flag, 'N') = 'N' AND l_DenomBdCostTab(j) = l_DenomRawCostTab(j) ) THEN
9253 l_DenomBdCostTab(j) := Null;
9254 l_BdCostRateTab(j) := Null; /*Bug#5874347*/
9255 End IF;
9256 /*E.N. Bug 5170366 */
9257
9258 IF ( nvl(G_acct_rate_type,'DUMMY') <> 'User' ) THEN
9259 l_AcctExchRateTab(j) := NULL;
9260 END IF; -- end G_acct_rate_type <> User
9261
9262 IF ( nvl(G_project_rate_type,'DUMMY') <> 'User') THEN
9263 l_PrjExchRateTab(j) := NULL;
9264 END IF; -- end G_project_rate_type <> User
9265
9266 /* Added the ELSE section to round off the acct raw and burden costs for gl costed transactions for bug 2871273 */
9267
9268 ELSE
9269
9270 l_AcctRawCostTab(j) := pa_currency.round_trans_currency_amt1(l_AcctRawCostTab(j),G_accounting_currency_code);
9271 l_AcctBdCostTab(j) := pa_currency.round_trans_currency_amt1(l_AcctBdCostTab(j),G_accounting_currency_code);
9272
9273 END IF; -- end G_gl_accted_flag = N
9274
9275 IF (l_DenomCurrCodeTab(j) = G_accounting_currency_code) THEN
9276
9277 l_AcctRateDateTab(j) := NULL;
9278 l_AcctRateTypeTab(j) := NULL;
9279 l_AcctExchRateTab(j) := NULL;
9280
9281 END IF; -- end denom currency = acct currency
9282
9283 IF ( l_DenomCurrCodeTab(j) = l_ProjCurrCodeTab(j)) THEN
9284
9285 l_prjRateDateTab(j) := NULL;
9286 l_PrjRateTypeTab(j) := NULL;
9287 l_PrjExchRateTab(j) := NULL;
9288
9289 END IF; -- End denom currency=project currency
9290
9291 -- SSt changes
9292 -- For contract and capital projects, if the billable flag
9293 -- is populated in the interface table, then override the
9294 -- billable flag derived from pa_transactions_pub.validate_transaction
9295 -- with the value in the billable flag column
9296
9297 IF PG_DEBUG = 'Y' THEN
9298 log_message('log_message: ' || 'Intial Billable Flag = ' || X_billable_flag);
9299 END IF;
9300
9301 -- Bug 8835571: Including project_type 'INDIRECT' also, as billability for Indirect Projects does not hold any meaning.
9302 -- But in Grants, the underlying award_project is always a contract project and hence all the
9303 -- trxns against the award/ project get picked up even if the project is INDIRECT project.
9304 IF ( G_project_type_class IN ('CONTRACT','CAPITAL', 'INDIRECT') AND
9305 --IF ( G_project_type_class IN ('CONTRACT','CAPITAL') AND
9306 l_billableFlagTab(j) IN ( 'Y','N')) THEN
9307
9308 IF PG_DEBUG = 'Y' THEN
9309 pa_debug.G_err_stage := 'Project_type_class in Contract, Capital';
9310 log_message('log_message: ' || pa_debug.G_err_stage);
9311 END IF;
9312
9313 X_billable_flag := l_billableFlagTab(j);
9314
9315 --PA-I Changes
9316 --If profile - PA: Require Work Type Entry for Expenditures
9317 --and profile - PA: Transaction Billability Derived from Work Type
9318 --is set to Y then we have to derive billability from work_type
9319 --else use what user has entered in TrxRec.billable_flag
9320 --Here we are calling the API get_trxn_work_billabilty to override
9321 --the billable flag.
9322 --For now we can call the API but latter if performance is a
9323 --bottleneck then we can replace this API call by just checking the
9324 --two profiles and if it is Y then use the billable_flag from
9325 --validate_transaction and if N then override with what user entered.
9326
9327 IF PG_DEBUG = 'Y' THEN
9328 pa_debug.G_err_stage := 'Calling pa_utils4.get_transaction_billability';
9329 log_message('log_message: ' || pa_debug.G_err_stage);
9330 log_message('log_message: ' || 'Billable Flag before get_trxn_work_billabilty = ' || X_billable_flag);
9331 log_message('log_message: ' || 'Work Type Id = ' || G_work_type_id);
9332 END IF;
9333
9334 X_billable_flag := pa_utils4.get_trxn_work_billabilty(
9335 p_work_type_id => G_work_type_id,
9336 p_tc_extn_bill_flag => X_billable_flag);
9337
9338 IF PG_DEBUG = 'Y' THEN
9339 log_message('log_message: ' || 'Billable Flag after get_trxn_work_billabilty = ' || X_billable_flag);
9340 END IF;
9341
9342 END IF;
9343
9344 IF PG_DEBUG = 'Y' THEN
9345 log_message('log_message: ' || 'Final Billable Flag = ' || X_billable_flag);
9346 END IF;
9347
9348 --PA-K Changes:
9349 --TrxRec.expenditure_item_id := X_ei_id;
9350
9351 --Added for bug 2048868
9352 prev_acct_rate_type := G_acct_rate_type;
9353 prev_acct_rate_date := l_AcctRateDateTab(j);
9354 prev_acct_exchange_rate := l_AcctExchRateTab(j);
9355 prev_denom_currency_code := l_DenomCurrCodeTab(j);
9356 prev_person_type := l_person_typeTab(j);
9357
9358 /* Added for 4057874 */
9359 IF (l_SysLinkTab(j) = 'BTC'
9360 AND G_trx_predef_flag = 'Y'
9361 AND X_transaction_source <> 'ALLOCATIONS'
9362 AND P_BTC_SRC_RESRC = 'Y' ) THEN
9363
9364 l_src_system_linkage_function := G_trx_link;
9365
9366 IF PG_DEBUG = 'Y' THEN
9367 log_message('log_message: ' || 'Src system linkage function = '||l_src_system_linkage_function);
9368 END IF;
9369
9370 ELSE
9371
9372 l_src_system_linkage_function := null;
9373
9374 END IF;
9375
9376 /* Bug 4107560 : Overriding the wip_resource_id for the BTC transactions to be interfaced from transaction source
9377 with wip_resource_id of parent source transaction */
9378
9379 IF l_SysLinkTab(j) = 'BTC' AND l_wip_resource_idTab(j) IS NOT NULL Then
9380
9381 If G_prev_ORIG_TRAN_REF Is Null or G_prev_ORIG_TRAN_REF <> l_OrigTxnRefTab(j) Then
9382
9383 G_prev_ORIG_TRAN_REF := l_OrigTxnRefTab(j);
9384
9385 Begin
9386 Select WIP_RESOURCE_ID
9387 INTO G_WIP_RESOURCE_ID
9388 FROM PA_TRANSACTION_INTERFACE_ALL
9389 WHERE ORIG_TRANSACTION_REFERENCE = l_OrigTxnRefTab(j)
9390 and SYSTEM_LINKAGE <> 'BTC'
9391 and rownum = 1;
9392 Exception
9393 When No_data_found Then
9394 Select resource_id
9395 into G_WIP_RESOURCE_ID
9396 from wip_transactions
9397 where transaction_id = l_OrigTxnRefTab(j);
9398 End;
9399
9400 l_wip_resource_idTab(j) := G_WIP_RESOURCE_ID;
9401 Else
9402 l_wip_resource_idTab(j) := G_WIP_RESOURCE_ID;
9403 End if;
9404
9405 IF PG_DEBUG = 'Y' THEN
9406 log_message('log_message: ' || 'BTC WIP Resource ID = ' || G_WIP_RESOURCE_ID );
9407 END IF;
9408
9409 END IF;
9410
9411 /* End of bug 4107560 */
9412
9413
9414 IF PG_DEBUG = 'Y' THEN
9415 pa_debug.G_err_stage := 'Calling Loadei';
9416 log_message('log_message: ' || pa_debug.G_err_stage);
9417 END IF;
9418
9419 -- REL12 AP Lines uptake..
9420 l_temp_adjItemID := G_adj_item_id ;
9421
9422 --
9423 -- The following code is added to calculate billable flag for the
9424 -- ap reversal distributions which is interfaced as net zero
9425 -- expenditure items
9426 --
9427 IF l_nzAdjFlagTab(j) = 'Y' Then
9428 l_temp_adjItemID := NULL ;
9429 END IF ;
9430 -- This is to avoid calling the LoadEI/newExpend etc for Quantity Variance as
9431 -- we are only interested in Funds checking the variance txn but not in interfacing to PA
9432 -- Already the txn is funds checked, so reduce the count. Bug# 8709614
9433 IF (X_ei_id is NULL AND X_transaction_source = 'AP VARIANCE') THEN
9434 i := i-1;
9435 END IF;
9436
9437
9438 IF X_ei_id is NOT NULL THEN
9439 -- Bug 4604493, 4503768 begins
9440 IF (l_SysLinkTab(j) <> 'USG') THEN
9441 G_nlro_id := Null;
9442 END IF;/*Bug 4503768*/
9443 -- Bug 4604493, 4503768 ends
9444
9445 /* Added for bug 14006460 */
9446 if G_vendor_id is NOT NULL AND l_vendor_id is null then
9447 l_vendor_id := G_vendor_id;
9448 end if;
9449 /* Added for bug 14006460 */
9450
9451
9452 /* start changes for bug#12646547 */
9453 IF X_transaction_source NOT IN ('ORACLE TIME AND LABOR') THEN
9454 --{
9455
9456 IF l_job_idtab(j) is null Then
9457 --{
9458 l_job_idtab(j) := G_job_id;
9459 --}
9460 END IF;
9461
9462 --}
9463 END IF;
9464
9465 /* End changes for bug#12646547 */
9466
9467 pa_transactions.LoadEi( X_expenditure_item_id => X_ei_id
9468 --PA-K Changes: TrxRec.expenditure_item_id
9469 ,X_expenditure_id => G_expenditure_id
9470 ,X_expenditure_item_date => l_EiDateTab(j)
9471 ,X_project_id => G_project_id
9472 ,X_task_id => G_task_id
9473 ,X_expenditure_type => l_ETypeTab(j)
9474 ,X_non_labor_resource => l_NlrTab(j)
9475 ,X_nl_resource_org_id => G_nlro_id
9476 ,X_quantity => l_QtyTab(j)
9477 ,X_raw_cost => l_rawCostTab(j)
9478 ,X_raw_cost_rate => l_rawCostRateTab(j)
9479 -- Trx_import enhancement
9480 ,X_override_to_org_id => G_override_to_org_id -- Changed from NULL
9481 /* Added for bug 3220230 for getting billability of items reversed in OIT */
9482 ,X_billable_flag => pa_utils4.GetOrig_EiBillability_SST(l_temp_adjItemID,X_billable_flag,X_transaction_source)
9483 /* Added for bug 4057474 for getting bill_hold_flag of items reversed in external txn sources like OTL. */
9484 ,X_bill_hold_flag => pa_utils4.GetOrig_EiBill_hold(l_temp_adjItemID,'N')
9485 ,X_orig_transaction_ref => l_OrigTxnRefTab(j)
9486 ,X_transferred_from_ei => NULL
9487 ,X_adj_expend_item_id => G_adj_item_id
9488 ,X_attribute_category => l_AttCatTab(j)
9489 ,X_attribute1 => l_Att1Tab(j)
9490 ,X_attribute2 => l_Att2Tab(j)
9491 ,X_attribute3 => l_Att3Tab(j)
9492 ,X_attribute4 => l_Att4Tab(j)
9493 ,X_attribute5 => l_Att5Tab(j)
9494 ,X_attribute6 => l_Att6Tab(j)
9495 ,X_attribute7 => l_Att7Tab(j)
9496 ,X_attribute8 => l_Att8Tab(j)
9497 ,X_attribute9 => l_Att9Tab(j)
9498 ,X_attribute10 => l_Att10Tab(j)
9499 ,X_ei_comment => l_ExpCommentTab(j)
9500 ,X_transaction_source => X_transaction_source
9501 ,X_source_exp_item_id => NULL
9502 ,i => i
9503 --,X_job_id => G_job_id
9504 ,X_job_id => l_job_idtab(j)
9505 ,X_org_id => l_OrgIdTab(j)
9506 ,X_labor_cost_multiplier_name => G_lcm
9507 ,X_drccid => l_DRCCIDTab(j)
9508 ,X_crccid => l_CRCCIDTab(j)
9509 ,X_cdlsr1 => l_SysRef1Tab(j)
9510 ,X_cdlsr2 => l_SysRef2Tab(j)
9511 ,X_cdlsr3 => l_SysRef3Tab(j)
9512 ,X_gldate => l_GlDateTab(j)
9513 ,X_bcost => l_burdenedCostTab(j)
9514 ,X_bcostrate => l_BdCostRateTab(j)
9515 ,X_etypeclass => l_SysLinkTab(j)
9516 ,X_burden_sum_dest_run_id => ''
9517 ,X_burden_compile_set_id => G_burden_compile_set_id
9518 ,X_receipt_currency_amount => l_RcptCurrAmtTab(j)
9519 ,X_receipt_currency_code => l_RcptCurrCodeTab(j)
9520 ,X_receipt_exchange_rate => l_RcptExchRateTab(j)
9521 ,X_denom_currency_code => l_DenomCurrCodeTab(j)
9522 ,X_denom_raw_cost => l_DenomRawCostTab(j)
9523 ,X_denom_burdened_cost => l_DenomBdCostTab(j)
9524 ,X_acct_currency_code => G_accounting_currency_code
9525 ,X_acct_rate_date => l_AcctRateDateTab(j)
9526 ,X_acct_rate_type => G_acct_rate_type
9527 ,X_acct_exchange_rate => l_AcctExchRateTab(j)
9528 ,X_acct_raw_cost => l_AcctRawCostTab(j)
9529 ,X_acct_burdened_cost => l_AcctBdCostTab(j)
9530 ,X_acct_exchange_rounding_limit => l_AcctExchRndLimitTab(j)
9531 ,X_project_currency_code => l_ProjCurrCodeTab(j)
9532 ,X_project_rate_date => l_prjRateDateTab(j)
9533 ,X_project_rate_type => G_project_rate_type
9534 ,X_project_exchange_rate => l_PrjExchRateTab(j)
9535 ,X_Cross_Charge_Type => G_CrossChargeType
9536 ,X_Cross_Charge_Code => G_CrossChargeCode
9537 ,X_Prvdr_organization_id => G_PrvdrOrganizationId
9538 ,X_Recv_organization_id => G_RecvrOrganizationId
9539 ,X_Recv_Operating_Unit => G_RecvrOrgId
9540 ,X_Borrow_Lent_Dist_Code => G_BrowLentDistCode
9541 ,X_Ic_Processed_Code => G_IcProcessed_Code
9542 ,P_PaDate => G_PaDate
9543 ,P_PaPeriodName => G_PaPeriodName
9544 ,P_RecvrPaDate => G_RecvrPaDate
9545 ,P_RecvrPaPeriodName => G_RecvrPaPeriodName
9546 ,P_GlPeriodName => G_GlPeriodName
9547 ,P_RecvrGlDate => G_RecvrGlDate
9548 ,P_RecvrGlPeriodName => G_RecvrGlPeriodName
9549 -- PA-I Changes
9550 ,p_assignment_id => G_Assignment_Id
9551 ,p_work_type_id => G_Work_Type_Id
9552 ,p_projfunc_currency_code => l_ProjFuncCurrCodeTab(j)
9553 ,p_projfunc_cost_rate_date => l_PrjFuncRateDateTab(j)
9554 ,p_projfunc_cost_rate_type => G_projfunc_cost_rate_type
9555 ,p_projfunc_cost_exchange_rate => l_PrjFuncExchRateTab(j)
9556 ,p_project_raw_cost => l_ProjRawCostTab(j)
9557 ,p_project_burdened_cost => l_ProjBdCostTab(j)
9558 ,p_tp_amt_type_code => G_Tp_Amt_Type_Code
9559 -- AP Discounts
9560 ,p_cdlsr4 => l_Sysref4Tab(j)
9561 ,p_accrual_Date => G_AccDate
9562 ,p_recvr_accrual_date => G_RecvrAccDate
9563 ,p_po_line_id => l_po_line_idTab(j) /* cwk */
9564 ,p_po_price_type => l_po_price_typeTab(j)
9565 ,p_wip_resource_id => l_wip_resource_idTab(j)
9566 ,p_inventory_item_id => l_inventory_item_idTab(j)
9567 ,p_unit_of_measure => l_unit_of_measureTab(j)
9568 ,p_src_system_linkage_function =>l_src_system_linkage_function /* 4057874 */
9569 ,p_document_header_id => l_doc_header_id
9570 ,p_document_distribution_id => l_doc_distribution_ID
9571 ,p_document_line_number => l_doc_line_number
9572 ,p_document_payment_ID => l_doc_payment_ID
9573 ,p_vendor_id => l_vendor_id
9574 ,p_document_type => l_DocumentTypeTab(j)
9575 ,p_document_distribution_type=> l_DocumentDistTypeTab(j)
9576 ,p_si_assets_addition_flag => l_siaAddFlagTab(j)
9577 ,p_sc_xfer_code => l_scxfercdTab(j)
9578 ,p_cdlsr5 => l_Sysref5Tab(j)
9579 --,p_agreement_id => l_agreement_idTab(j) --FSIO Changes
9580 ,p_location_id => l_location_idtab(j)
9581 ,p_pay_element_type_id => l_pay_element_type_idtab(j)
9582 ,p_cbs_element_id => G_cbs_element_id -- Added for CBS Enhancement Bug 16220146
9583 );
9584 END IF ;
9585
9586 -- PA-J Period-End Accrual Changes
9587 -- Call LoadEI for creating the reversing item.
9588 if (l_AccrualFlagTab(j) = 'Y' and l_SysLinkTab(j) = 'PJ' and X_ei_id is not NULL ) then
9589
9590 IF PG_DEBUG = 'Y' THEN
9591 pa_debug.G_err_stage := 'Calling Loadei for the reversing line of a Period-End Accrual transaction';
9592 log_message('log_message: ' || pa_debug.G_err_stage);
9593 END IF;
9594
9595 -- increment the counter
9596 i := i + 1;
9597
9598 pa_transactions.LoadEi(
9599 X_expenditure_item_id => pa_utils.GetNextEiId
9600 ,X_expenditure_id => G_expenditure_id
9601 ,X_expenditure_item_date => l_EiDateTab(j)
9602 ,X_project_id => G_project_id
9603 ,X_task_id => G_task_id
9604 ,X_expenditure_type => l_ETypeTab(j)
9605 ,X_non_labor_resource => l_NlrTab(j)
9606 ,X_nl_resource_org_id => G_nlro_id
9607 ,X_quantity => (0 - l_QtyTab(j))
9608 ,X_raw_cost => (0 - l_rawCostTab(j))
9609 ,X_raw_cost_rate => l_rawCostRateTab(j)
9610 ,X_override_to_org_id => G_override_to_org_id
9611 ,X_billable_flag => X_billable_flag
9612 ,X_bill_hold_flag => 'N'
9613 ,X_orig_transaction_ref => l_OrigTxnRefTab(j)
9614 ,X_transferred_from_ei => NULL
9615 ,X_adj_expend_item_id => X_ei_id --PA-K Changes: TrxRec.expenditure_item_id
9616 ,X_attribute_category => l_AttCatTab(j)
9617 ,X_attribute1 => l_Att1Tab(j)
9618 ,X_attribute2 => l_Att2Tab(j)
9619 ,X_attribute3 => l_Att3Tab(j)
9620 ,X_attribute4 => l_Att4Tab(j)
9621 ,X_attribute5 => l_Att5Tab(j)
9622 ,X_attribute6 => l_Att6Tab(j)
9623 ,X_attribute7 => l_Att7Tab(j)
9624 ,X_attribute8 => l_Att8Tab(j)
9625 ,X_attribute9 => l_Att9Tab(j)
9626 ,X_attribute10 => l_Att10Tab(j)
9627 ,X_ei_comment => l_ExpCommentTab(j)
9628 ,X_transaction_source => X_transaction_source
9629 ,X_source_exp_item_id => NULL
9630 ,i => i
9631 ,X_job_id => G_job_id
9632 ,X_org_id => l_OrgIdTab(j)
9633 ,X_labor_cost_multiplier_name => G_lcm
9634 ,X_drccid => l_DRCCIDTab(j)
9635 ,X_crccid => l_CRCCIDTab(j)
9636 ,X_cdlsr1 => l_SysRef1Tab(j)
9637 ,X_cdlsr2 => l_SysRef2Tab(j)
9638 ,X_cdlsr3 => l_SysRef3Tab(j)
9639 ,X_gldate => G_RevGlDate
9640 ,X_bcost => (0 - l_burdenedCostTab(j))
9641 ,X_bcostrate => l_BdCostRateTab(j)
9642 ,X_etypeclass => l_SysLinkTab(j)
9643 ,X_burden_sum_dest_run_id => ''
9644 ,X_burden_compile_set_id => G_burden_compile_set_id
9645 ,X_receipt_currency_amount => (0 - l_RcptCurrAmtTab(j))
9646 ,X_receipt_currency_code => l_RcptCurrCodeTab(j)
9647 ,X_receipt_exchange_rate => l_RcptExchRateTab(j)
9648 ,X_denom_currency_code => l_DenomCurrCodeTab(j)
9649 ,X_denom_raw_cost => (0 - l_DenomRawCostTab(j)) --2436444
9650 ,X_denom_burdened_cost => (0 - l_DenomBdCostTab(j))
9651 ,X_acct_currency_code => G_accounting_currency_code
9652 ,X_acct_rate_date => l_AcctRateDateTab(j)
9653 ,X_acct_rate_type => G_acct_rate_type
9654 ,X_acct_exchange_rate => l_AcctExchRateTab(j)
9655 ,X_acct_raw_cost => (0 - l_AcctRawCostTab(j))
9656 ,X_acct_burdened_cost => (0 - l_AcctBdCostTab(j))
9657 ,X_acct_exchange_rounding_limit => l_AcctExchRndLimitTab(j)
9658 ,X_project_currency_code => l_ProjCurrCodeTab(j)
9659 ,X_project_rate_date => l_prjRateDateTab(j)
9660 ,X_project_rate_type => G_project_rate_type
9661 ,X_project_exchange_rate => l_PrjExchRateTab(j)
9662 ,X_Cross_Charge_Type => G_CrossChargeType
9663 ,X_Cross_Charge_Code => G_CrossChargeCode
9664 ,X_Prvdr_organization_id => G_PrvdrOrganizationId
9665 ,X_Recv_organization_id => G_RecvrOrganizationId
9666 ,X_Recv_Operating_Unit => G_RecvrOrgId
9667 ,X_Borrow_Lent_Dist_Code => G_BrowLentDistCode
9668 ,X_Ic_Processed_Code => G_IcProcessed_Code
9669 ,P_PaDate => G_RevPaDate
9670 ,P_PaPeriodName => G_RevPaPeriodName
9671 ,P_RecvrPaDate => G_RevRecvrPaDate
9672 ,P_RecvrPaPeriodName => G_RevRecvrPaPdName
9673 ,P_GlPeriodName => G_RevGlPeriodName
9674 ,P_RecvrGlDate => G_RevRecvrGlDate
9675 ,P_RecvrGlPeriodName => G_RevRecvrGlPdName
9676 ,p_assignment_id => G_Assignment_Id
9677 ,p_work_type_id => G_Work_Type_Id
9678 ,p_projfunc_currency_code => l_ProjFuncCurrCodeTab(j)
9679 ,p_projfunc_cost_rate_date => l_PrjFuncRateDateTab(j)
9680 ,p_projfunc_cost_rate_type => G_projfunc_cost_rate_type
9681 ,p_projfunc_cost_exchange_rate => l_PrjFuncExchRateTab(j)
9682 ,p_project_raw_cost => (0 - l_ProjRawCostTab(j))
9683 ,p_project_burdened_cost => (0 - l_ProjBdCostTab(j))
9684 ,p_tp_amt_type_code => G_Tp_Amt_Type_Code
9685 ,p_cdlsr4 => l_Sysref4Tab(j)
9686 ,p_accrual_Date => G_RevAccDate
9687 ,p_recvr_accrual_date => G_RevRecvrAccDate
9688 ,p_po_line_id => l_po_line_idTab(j) /* cwk */
9689 ,p_po_price_type => l_po_price_typeTab(j)
9690 ,p_wip_resource_id => l_wip_resource_idTab(j)
9691 ,p_inventory_item_id => l_inventory_item_idTab(j)
9692 ,p_unit_of_measure => l_unit_of_measureTab(j)
9693 ,p_si_assets_addition_flag => l_siaAddFlagTab(j)
9694 -- ,p_agreement_id => l_agreement_idTab(j) --FSIO Changes
9695 --,p_location_id => l_location_idtab(j)
9696 ,p_location_id => G_Location_Id
9697 ,p_pay_element_type_id => l_pay_element_type_idtab(j)
9698 ,p_cbs_element_id => G_cbs_element_id -- Added for CBS Enhancement Bug 16220146
9699 );
9700 end if;
9701
9702 END IF; ---} -- IF ( NOT REJECT_EXP )
9703
9704 --EXIT WHEN TrxRecs%NOTFOUND;
9705 --END LOOP expenditures ;
9706
9707 l_vendor_id := NULL; /* Added for BUG # 14786288 */
9708 END LOOP; ---}
9709
9710
9711 /***** Bug 4091706 CWK Changes *****/
9712 --- release_po_line_task_lock; Commented out for bug 4106188
9713 --- init_po_amt_chk; Commented out for bug 4106188
9714 /***** Bug 4091706 CWK Changes *****/
9715
9716
9717 IF PG_DEBUG = 'Y' THEN
9718 pa_debug.G_err_stage := 'Calling newExpend after TrxRecs loop';
9719 log_message('log_message: ' || pa_debug.G_err_stage);
9720 END IF;
9721 newExpend( TrxBatch.exp_group_name
9722 , current_period
9723 , i
9724 , prev_denom_currency_code
9725 , G_accounting_currency_code
9726 , prev_acct_rate_type
9727 , prev_acct_rate_date
9728 , prev_acct_exchange_rate
9729 , prev_person_type /*cwk */
9730 , TrxBatch.batch_name ); -- Bug 3613784 : Performance fix
9731
9732 /** Bug#3026218 Close the tow cursors that are opened. Removed conditions on
9733 *** pre-defined flag
9734 **/
9735 If (TrxBatch.system_linkage_function = 'ST') Then
9736 CLOSE TrxRecs1;
9737 Else
9738 CLOSE TrxRecs2;
9739 End If;
9740
9741
9742 ELSE
9743
9744 IF PG_DEBUG = 'Y' THEN
9745 pa_debug.G_err_stage := 'Processed the commit size records, exit batches';
9746 log_message('log_message: ' || pa_debug.G_err_stage);
9747 END IF;
9748
9749 Exit batches;
9750
9751 END IF; ---}
9752
9753 ELSE
9754
9755 IF PG_DEBUG = 'Y' THEN
9756 pa_debug.G_err_stage := 'Not able to lock TrxBatch record';
9757 log_message('log_message: ' || pa_debug.G_err_stage);
9758 END IF;
9759
9760 --Bug 3239369
9761 G_Exit_Main := TRUE;
9762
9763 Exit batches;
9764
9765 /***** CWK Changes *****/
9766
9767 --- Bug 4091706 release_po_line_task_lock;
9768 --- BUg 4091706 init_po_amt_chk;
9769
9770 /***** CWK Changes *****/
9771
9772 END IF; ---}
9773
9774
9775 --PA-K Changes: UpdControlProcessed will be done for each loop of TrxBatches
9776 IF PG_DEBUG = 'Y' THEN
9777 pa_debug.G_err_stage := 'Calling UpdControlProcessed';
9778 log_message('log_message: ' || pa_debug.G_err_stage);
9779 END IF;
9780
9781 UpdControlProcessed( P_TrxSource => TrxBatch.transaction_source,
9782 P_BatchName => TrxBatch.batch_name,
9783 P_XfaceId => X_xface_id,
9784 P_TxnCount => TrxBatch.transaction_count,
9785 P_ProcCount => TrxBatch.processed_count,
9786 P_BatchProcCount => l_ActualBatchRecCnt,
9787 p_system_linkage_function => trxbatch.system_linkage_function);
9788 /* added the parameter system linkage function in the function call above for BUG # 3291066 */
9789
9790 IF PG_DEBUG = 'Y' THEN
9791 log_message('log_message: ' || 'l_CommitSizeRecCount = ' || l_CommitSizeRecCount || ' l_Batch_Size = ' || l_Batch_Size);
9792 END IF;
9793
9794 If l_CommitSizeRecCount = l_Batch_Size Then
9795 IF PG_DEBUG = 'Y' THEN
9796 log_message('log_message: ' || 'l_CommitSizeRecCount equal to l_Batch_Size, exit batches');
9797 END IF;
9798 Exit batches;
9799 End If;
9800
9801
9802 --Vijay
9803 END LOOP; ---}
9804
9805 Close TrxBatches;
9806
9807 --PA-J Receipt Accrual Changes: Added AP VARIANCE and PO RECEIPT
9808 --PA-K Changes: Using the process_funds_check attributes of the source to perform funds checking
9809 --X_transaction_source in ('AP INVOICE', 'AP VARIANCE', 'PO RECEIPT', 'AP NRTAX', 'PO RECEIPT NRTAX') THEN
9810 IF G_gl_accted_flag = 'Y' AND
9811 G_Process_Funds_Flag = 'Y' THEN
9812
9813 IF PG_DEBUG = 'Y' THEN
9814 pa_debug.G_err_stage := 'Calling tieback funds check records';
9815 log_message('log_message: ' || pa_debug.G_err_stage);
9816 END IF;
9817
9818 IF PG_DEBUG = 'Y' THEN
9819 pa_debug.G_err_stage := 'Tieback Mode = '||X_transaction_source;
9820 log_message('log_message: ' || pa_debug.G_err_stage);
9821 END IF;
9822
9823 tieback_fc_records (x_return_status => l_return_status,
9824 p_calling_mode => X_transaction_source) ;
9825
9826 END IF;
9827
9828 if l_return_status <> FND_API.G_RET_STS_SUCCESS then
9829
9830 raise_application_error(-20001,'Error during Balance Update');
9831 return ;
9832
9833 end if;
9834
9835 if l_gms_enabled = 'Y' then
9836 gms_pa_costing_pkg.Tieback_Interface(p_request_id => g_request_id,
9837 p_status => l_return_status);
9838
9839 if l_return_status <> FND_API.G_RET_STS_SUCCESS then
9840 raise_application_error(-20002,'Error during Grants Tieback process');
9841 return ;
9842 end if;
9843 --
9844 -- BUG : 5389130
9845 -- R12.PJ:XB7:DEV:BC: TO TRACK GRANTS INTERFACE ISSUES
9846 --
9847 gms_pa_costing_pkg.Net_zero_adls( X_transaction_source,
9848 X_batch ,
9849 X_xface_id,
9850 l_return_status) ;
9851
9852 if l_return_status <> FND_API.G_RET_STS_SUCCESS then
9853 raise_application_error(-20002,'Error during Grants Tieback process net_zero_adjustment_flag Zero adls');
9854 return ;
9855 end if;
9856
9857 end if;
9858
9859 /*PA-K Changes: UpdControlProcessed will be done for each loop of TrxBatches*/
9860
9861 pa_cc_utils.reset_curr_function;
9862
9863 EXCEPTION
9864
9865 WHEN OTHERS THEN
9866 IF PG_DEBUG = 'Y' THEN
9867 pa_debug.G_err_stage := 'In OTHERS exception of import1';
9868 log_message('log_message: ' || pa_debug.G_err_stage,1);
9869 log_message('Error: ' || sqlerrm,1);
9870 END IF;
9871
9872 release_po_line_task_lock; -- bug 3512984
9873
9874 --Call FC packets update API to update packets to T.
9875 Upd_PktSts_Fatal(p_request_id => G_REQUEST_ID);
9876
9877 raise;
9878
9879 END import1;
9880
9881 PROCEDURE import( X_transaction_source IN VARCHAR2
9882 , X_batch IN VARCHAR2
9883 , X_xface_id IN NUMBER
9884 , X_userid IN NUMBER
9885 , X_online_exp_comment IN VARCHAR2 )
9886 IS
9887
9888 l_cursor INTEGER;
9889 l_rows INTEGER;
9890 l_stmt VARCHAR2(2000);
9891 l_Exception_Desc VARCHAR2(2000);
9892
9893 l_run binary_integer;
9894 l_uom_status VARCHAR2(2000) := 'S';
9895
9896 BEGIN
9897
9898 --SST changes
9899 <<init_prog>>
9900 BEGIN
9901
9902 -- SST: Init calls GetTrxSrcInfo
9903 init(P_transaction_source => X_transaction_source);
9904
9905 EXCEPTION WHEN others THEN
9906 IF PG_DEBUG = 'Y' THEN
9907 log_message('log_message: ' || 'Error in Init procedure',1);
9908 log_message('log_message: ' || 'Stage='||pa_debug.G_err_stage,1);
9909 log_message('log_message: ' || SQLERRM);
9910 END IF;
9911
9912 raise_application_error(-20001,'Init:'||SQLERRM);
9913 END init_prog;
9914
9915 IF PG_DEBUG = 'Y' THEN
9916 log_message('log_message: ' || 'Run = '|| l_run);
9917 END IF;
9918
9919 -- 5235363 R12.PJ:XB4:DEV:APL:EXP ITEM DATE VALIDATIONS FOR SUPPLIER COST.
9920 --
9921 IF (X_transaction_source in ( 'AP INVOICE', 'AP NRTAX', 'AP DISCOUNTS', 'INTERCOMPANY_AP_INVOICES',
9922 'INTERPROJECT_AP_INVOICES', 'AP VARIANCE', 'AP ERV', 'PO RECEIPT', 'PO RECEIPT NRTAX',
9923 'PO RECEIPT PRICE ADJ', 'PO RECEIPT NRTAX PRICE ADJ')) THEN
9924 set_supplier_cost_eidate(X_transaction_source,X_batch,X_xface_id) ;
9925 END IF ;
9926 --
9927 -- 5235363 end of code changes.
9928 /* PA.M PJM Additional Attribute changes: Calling unit of measure insertion api for all INV/WIP/ST sources from manufacturing */
9929
9930 IF X_transaction_source in ('Inventory', 'Inventory Misc', 'PJM_CSTBP_INV_NO_ACCOUNTS',
9931 'PJM_CSTBP_INV_ACCOUNTS', 'Work In Process', 'PJM_CSTBP_ST_NO_ACCOUNTS',
9932 'PJM_CSTBP_WIP_NO_ACCOUNTS', 'PJM_CSTBP_ST_ACCOUNTS',
9933 'PJM_CSTBP_WIP_ACCOUNTS', 'PJM_NON_CSTBP_ST_ACCOUNTS') THEN
9934
9935 IF PG_DEBUG = 'Y' THEN
9936 log_message('log_message: ' || 'Calling pa_uom.get_uom for transaction source '|| X_transaction_source);
9937 END IF;
9938
9939 l_uom_status := Pa_Uom.Get_Uom (X_userid);
9940
9941 IF l_uom_status <> 'S' THEN
9942
9943 IF PG_DEBUG = 'Y' THEN
9944 log_message('log_message: ' || 'Error in Get_Uom procedure',1);
9945 log_message('log_message: ' || l_uom_status);
9946 END IF;
9947
9948 raise_application_error(-20001,'Get_Uom:'||SQLERRM);
9949
9950 END IF;
9951
9952 END IF; /* X_transaction_source */
9953
9954 <<main_loop>>
9955 LOOP
9956
9957 G_IterationNum := G_IterationNum + 1;
9958 IF PG_DEBUG = 'Y' THEN
9959 log_message('log_message: ' || 'G_IterationNum = '|| G_IterationNum);
9960 END IF;
9961
9962 <<pre_import>>
9963 BEGIN
9964 IF PG_DEBUG = 'Y' THEN
9965 pa_debug.G_err_Stage := 'Calling pre_import extension';
9966 log_message('log_message: ' || pa_debug.G_err_Stage);
9967 END IF;
9968
9969 pa_trx_import.pre_import(P_transaction_source => X_transaction_source,
9970 P_batch => X_batch,
9971 P_xface_id => X_xface_id,
9972 P_user_id => X_userid);
9973
9974 /* PA-K Changes: Remove the inter phase commits */
9975
9976 /* PA-K Changes: Commenting the call to count_status
9977 Report will directly select the counts from the interface table */
9978
9979 EXCEPTION WHEN others THEN
9980 IF PG_DEBUG = 'Y' THEN
9981 log_message('log_message: ' || 'Error in pre_import procedure',1);
9982 log_message('log_message: ' || 'Stage='||pa_debug.G_err_stage,1);
9983 log_message('log_message: ' || SQLERRM);
9984 END IF;
9985 raise_application_error(-20002,'pre_import:'||SQLERRM);
9986 END pre_import;
9987
9988 <<Import1_prog>>
9989 BEGIN
9990 pa_trx_import.import1(X_transaction_source
9991 , X_batch
9992 , X_xface_id
9993 , X_userid
9994 , X_online_exp_comment);
9995
9996 /* PA-K Changes: Remove the inter phase commits */
9997
9998 /* PA-K Changes: Commenting the call to count_status
9999 Report will directly select the counts from the interface table */
10000
10001 IF PG_DEBUG = 'Y' THEN
10002 pa_debug.G_err_stage := 'After import1';
10003 log_message('log_message: ' || pa_debug.G_err_stage);
10004 END IF;
10005
10006
10007 EXCEPTION WHEN others THEN
10008
10009 IF PG_DEBUG = 'Y' THEN
10010 log_message('log_message: ' || 'Error in import1 procedure',1);
10011 log_message('log_message: ' || 'Stage='||pa_debug.G_err_stage,1);
10012 log_message('log_message: ' || SQLERRM);
10013 END IF;
10014
10015 If X_transaction_source = 'ORACLE TIME AND LABOR' Then
10016
10017 BEGIN
10018
10019 IF PG_DEBUG = 'Y' THEN
10020 pa_debug.G_err_stage := 'Calling eception handler for OTL';
10021 log_message('log_message: ' || pa_debug.G_err_stage,1);
10022 END IF;
10023
10024
10025 -- Get cursor handle
10026 l_cursor := dbms_sql.open_cursor;
10027
10028 l_Exception_Desc := 'Error in Projects Import routine: ' || pa_debug.G_err_stage || ' : ' || SQLERRM;
10029
10030 -- Associate a sql statement with the cursor.
10031
10032 --FP M OTL API changes (bug 3600642)
10033 --replaced Hxc_Generic_Retrieval_Pkg with HXC_INTEGRATION_LAYER_V1_GRP
10034 --l_stmt := 'BEGIN Hxc_Generic_Retrieval_Pkg.Update_Transaction_Status ( ' ||
10035 l_stmt := 'BEGIN HXC_INTEGRATION_LAYER_V1_GRP.Update_Transaction_Status ( ' ||
10036 ' P_Process => :process, '||
10037 ' P_Status => :status, '||
10038 ' P_Exception_Description => :Exception_Desc );'||
10039 'END;';
10040
10041 IF PG_DEBUG = 'Y' THEN
10042 pa_debug.G_err_stage := 'After constructing the dynamic sql OTL';
10043 log_message('log_message: ' || pa_debug.G_err_stage,1);
10044 END IF;
10045
10046 -- parse the sql statement to check for any syntax or symantic errors
10047
10048 dbms_sql.parse(l_cursor,l_stmt,dbms_sql.native);
10049
10050 -- before executing the sql statement bind the variables
10051 dbms_sql.bind_variable(l_cursor,':process',
10052 'Projects Retrieval Process');
10053
10054 dbms_sql.bind_variable(l_cursor,'status',
10055 'ERRORS');
10056
10057 dbms_sql.bind_variable(l_cursor,'Exception_Desc',
10058 l_Exception_Desc);
10059
10060
10061 l_rows := dbms_sql.execute(l_cursor);
10062 IF PG_DEBUG = 'Y' THEN
10063 pa_debug.G_err_stage := 'After executing the dynamic sql OTL';
10064 log_message('log_message: ' || pa_debug.G_err_stage,1);
10065 END IF;
10066
10067 EXCEPTION
10068 When Others Then
10069 IF PG_DEBUG = 'Y' THEN
10070 pa_debug.G_err_stage := 'In excp of the dynamic sql executing OTL';
10071 log_message('log_message: ' || pa_debug.G_err_stage,1);
10072 END IF;
10073
10074 dbms_sql.close_cursor(l_cursor);
10075 RAISE;
10076
10077 END;
10078
10079 End If;
10080
10081
10082
10083
10084 raise_application_error(-20003,'import1_prog:'||SQLERRM||pa_debug.G_err_stage);
10085
10086 END import1_prog;
10087
10088
10089 /***** CWK Changes *****/
10090 release_po_line_task_lock;
10091 init_po_amt_chk;
10092 /***** CWK Changes *****/
10093
10094
10095
10096 <<post_import>>
10097 BEGIN
10098 IF PG_DEBUG = 'Y' THEN
10099 pa_debug.G_err_Stage := 'Calling post_import extension';
10100 log_message('log_message: ' || pa_debug.G_err_Stage);
10101 END IF;
10102
10103 pa_trx_import.post_import(P_transaction_source => X_transaction_source,
10104 P_batch => X_batch,
10105 P_xface_id => X_xface_id,
10106 P_user_id => X_userid);
10107
10108 /* PA-K Changes: Remove the inter phase commits */
10109
10110 /* PA-K Changes: Commenting the call to count_status
10111 Report will directly select the counts from the interface table */
10112
10113 EXCEPTION WHEN others THEN
10114 IF PG_DEBUG = 'Y' THEN
10115 log_message('log_message: ' || 'Error in post import procedure',1);
10116 log_message('log_message: ' || SQLERRM);
10117 log_message('log_message: ' || 'Stage='||pa_debug.G_err_stage,1);
10118 END IF;
10119 raise_application_error(-20004,'post_import:'||SQLERRM);
10120 END post_import;
10121
10122 /* Bug 6998382 Moved the condition to exit the import1 procedure here so that the post processing client extension
10123 is called for the last batch as well */
10124 If (G_Exit_Main) Then
10125 IF PG_DEBUG = 'Y' THEN
10126 pa_debug.G_err_stage := 'G_Exit_Main is true, exit main loop';
10127 log_message('log_message: ' || pa_debug.G_err_stage,1);
10128 END IF;
10129 Exit main_loop;
10130 End If;
10131 /* Bug 6998382 End */
10132 COMMIT;
10133
10134 END LOOP;
10135
10136 IF PG_DEBUG = 'Y' THEN
10137 log_message('log_message: ' || 'End of Procedure Import');
10138 END IF;
10139
10140 /* PA-K Changes: Commenting the call to update_status_counter
10141 Report will directly select the counts from the interface table */
10142
10143 END import;
10144
10145 -- SST changes: New APIs
10146
10147 PROCEDURE init(P_transaction_source IN VARCHAR2) IS
10148
10149 --l_debug_mode VARCHAR2(1);
10150 BEGIN
10151
10152 -- Get the debug mode, if the debug is turned on then write
10153 -- log messages to the log file.
10154
10155 fnd_profile.get('PA_DEBUG_MODE',G_debug_mode);
10156 G_debug_mode := NVL(G_debug_mode, 'N');
10157
10158 pa_debug.set_process(x_process => 'PLSQL',
10159 x_debug_mode => G_debug_mode);
10160
10161 pa_cc_utils.log_message('Debug Mode = '||G_debug_mode,1);
10162 pa_cc_utils.set_curr_function('pa_trx_import.init');
10163
10164 IF PG_DEBUG = 'Y' THEN
10165 pa_debug.G_err_Stage := 'retriving transaction source';
10166 log_message('log_message: ' || pa_debug.G_err_Stage);
10167 END IF;
10168
10169 -- Transaction import program is always run for 1 transaction source
10170 -- get the transaction source info and store in pkg body global variables
10171
10172 GetTrxSrcInfo ( X_trx_src => P_transaction_source );
10173
10174 --Pa.K Changes: For performance moved the Multi-Org check to the init procedure.
10175 G_Morg := pa_utils.pa_morg_implemented;
10176
10177 -- MOAC changes. populate the operating unit org id variable.
10178 g_moac_org_id := pa_moac_utils.get_current_org_id ;
10179
10180 IF (G_accounting_currency_code IS NULL) THEN
10181 GetImpCurrInfo;
10182 END IF;
10183
10184 pa_cc_utils.reset_curr_function;
10185
10186 END init;
10187
10188 PROCEDURE execute_import_extensions(P_program_name IN VARCHAR2,
10189 P_transaction_source IN VARCHAR2,
10190 P_batch IN VARCHAR2,
10191 P_user_id IN NUMBER,
10192 P_xface_id IN NUMBER) IS
10193
10194 l_cursor INTEGER;
10195 l_rows INTEGER;
10196 l_stmt VARCHAR2(2000);
10197
10198 BEGIN
10199
10200 -- If the transaction source has a extension associated with it then
10201 -- execute the extn, else just exit with out doing anything.
10202 -- P_program_name is the name of the extension API.
10203 -- For instance 'PA_SELF_SERVICE_PVT.Upload_SS_Timecard'
10204 IF ( P_program_name IS NOT NULL ) THEN
10205
10206 -- Get cursor handle
10207 l_cursor := dbms_sql.open_cursor;
10208
10209 -- Associate a sql statement with the cursor.
10210
10211 l_stmt := 'BEGIN '||P_program_name||
10212 '(P_transaction_source =>:transaction_source,'||
10213 ' P_batch => :batch,'||
10214 ' P_user_id => :user_id,'||
10215 ' P_xface_id => :xface_id);'||
10216 ' END;';
10217
10218 -- parse the sql statemnt to check for any syntax or symantic errors
10219
10220 dbms_sql.parse(l_cursor,l_stmt,dbms_sql.native);
10221
10222 -- before executing the sql statement bind the variables
10223
10224 dbms_sql.bind_variable(l_cursor,'transaction_source',
10225 P_transaction_source);
10226 dbms_sql.bind_variable(l_cursor,'batch',
10227 P_batch);
10228 dbms_sql.bind_variable(l_cursor,'user_id',
10229 P_user_id);
10230 dbms_sql.bind_variable(l_cursor,'xface_id',
10231 P_xface_id);
10232
10233 l_rows := dbms_sql.execute(l_cursor);
10234
10235 dbms_sql.close_cursor(l_cursor); /* added for the bug12720784 */
10236
10237 END IF;
10238
10239 EXCEPTION WHEN others THEN
10240 dbms_sql.close_cursor(l_cursor);
10241 raise;
10242 END execute_import_extensions;
10243
10244 PROCEDURE pre_import(P_transaction_source IN VARCHAR2,
10245 P_batch IN VARCHAR2,
10246 P_xface_id IN NUMBER,
10247 P_user_id IN NUMBER) IS
10248 BEGIN
10249
10250 pa_trx_import.execute_import_extensions( P_program_name => G_pre_processing_extn,
10251 P_transaction_source => P_transaction_source,
10252 P_batch => P_batch,
10253 P_xface_id => P_xface_id,
10254 P_user_id => P_user_id);
10255
10256 EXCEPTION WHEN others THEN
10257 raise;
10258 END pre_import;
10259
10260 PROCEDURE post_import(P_transaction_source IN VARCHAR2,
10261 P_batch IN VARCHAR2,
10262 P_xface_id IN NUMBER,
10263 P_user_id IN NUMBER) IS
10264 BEGIN
10265
10266 pa_trx_import.execute_import_extensions( P_program_name => G_post_processing_extn,
10267 P_transaction_source => P_transaction_source,
10268 P_batch => P_batch,
10269 P_xface_id => P_xface_id,
10270 P_user_id => P_user_id);
10271
10272
10273 EXCEPTION WHEN others THEN
10274 raise;
10275 END post_import;
10276
10277 -- Changes for New TXN Codes
10278 --- New APIs
10279 ----------------------------------------------------------------------
10280 -- This new API counts the number of transactions which passed or failed
10281 -- certain phase, depending on the parameter
10282
10283 PROCEDURE count_status(P_phase IN VARCHAR2,
10284 P_xface_id IN NUMBER,
10285 P_sucess_counter OUT NOCOPY NUMBER,
10286 P_failed_counter OUT NOCOPY NUMBER) IS
10287 v_sucess VARCHAR2(2);
10288 v_failed VARCHAR2(2);
10289
10290 BEGIN
10291 IF (P_phase = 'PREIMPORT') THEN
10292 IF (G_pre_processing_extn IS NULL) THEN
10293 P_sucess_counter := 0;
10294 P_failed_counter := 0;
10295 return;
10296 ELSE
10297 v_sucess := 'P';
10298 v_failed := 'PR';
10299 END IF;
10300 ELSIF (P_phase = 'IMPORT') THEN
10301 IF (G_post_processing_extn IS NULL) THEN
10302 v_sucess := 'A';
10303 ELSE
10304 v_sucess := 'I';
10305 END IF;
10306 v_failed := 'R';
10307 ELSIF (P_phase = 'POSTIMPORT') THEN
10308 IF (G_post_processing_extn IS NULL) THEN
10309 P_sucess_counter := 0;
10310 P_failed_counter := 0;
10311 return;
10312 ELSE
10313 v_sucess := 'A';
10314 v_failed := 'PO';
10315 END IF;
10316 END IF;
10317
10318 SELECT COUNT(DECODE(transaction_status_code, v_sucess, 1, NULL)),
10319 COUNT(DECODE(transaction_status_code, v_failed, 1, NULL))
10320 INTO P_sucess_counter, P_failed_counter
10321 FROM pa_transaction_interface
10322 WHERE interface_id = P_xface_id
10323 AND transaction_status_code IN (v_sucess, v_failed);
10324
10325 EXCEPTION
10326 WHEN OTHERS THEN
10327 RAISE;
10328 END; -- procedure count_status
10329
10330 -- This API updates the counters in pa_transaction_xface_ctrl_all table.
10331 -- It keeps one set of counters for each concurrent request. Within a
10332 -- concurrent request, it does not keep track of counts at the system
10333 -- linkage function modularity.
10334
10335 PROCEDURE update_status_counter(P_xface_id IN NUMBER) IS
10336 BEGIN
10337
10338 UPDATE pa_transaction_xface_ctrl_all
10339 SET pre_import_reject_count = G_PRE_IMPORT_REJECT_COUNT,
10340 pre_import_success_count = G_PRE_IMPORT_SUCCESS_COUNT,
10341 import_reject_count = G_IMPORT_REJECT_COUNT,
10342 import_success_count = G_IMPORT_SUCCESS_COUNT,
10343 post_import_reject_count = G_POST_IMPORT_REJECT_COUNT,
10344 post_import_success_count = G_POST_IMPORT_SUCCESS_COUNT
10345 WHERE interface_id = P_xface_id;
10346
10347 EXCEPTION
10348 WHEN OTHERS THEN
10349 RAISE;
10350 END;
10351
10352 -- Bug 5550268 : Added comments to this procedure for clarity
10353 PROCEDURE tieback_fc_records ( x_return_status OUT NOCOPY VARCHAR2,
10354 p_calling_mode IN VARCHAR2) IS
10355
10356 -- Bug 5560524 : Modified the following cursor to also fetch AP ERV records
10357 -- Cursor to fetch AP VARIANCE,PO RECEIPT and PO RECEIPT NRTAX records
10358 cursor select_bc_packets(p_calling_mode in varchar2) is
10359 select a.packet_id,
10360 a.document_header_id,
10361 a.document_distribution_id,
10362 a.budget_ccid,
10363 b.cdl_system_reference4,
10364 a.project_id,
10365 a.budget_line_id ,
10366 a.budget_version_id
10367 from pa_bc_packets a,
10368 pa_transaction_interface b
10369 where a.txn_interface_id = b.txn_interface_id
10370 and a.document_header_id = b.cdl_system_reference2
10371 and a.document_distribution_id = decode(p_calling_mode, 'AP VARIANCE',b.cdl_system_reference5
10372 , 'AP ERV',b.cdl_system_reference5
10373 , b.cdl_system_reference3)
10374 and a.document_type = decode(p_calling_mode, 'AP VARIANCE', 'AP', 'AP ERV', 'AP' , 'PO RECEIPT', 'PO', 'PO RECEIPT NRTAX', 'PO')
10375 and a.parent_bc_packet_id is null
10376 and b.transaction_status_code = 'A'
10377 and a.request_id = g_request_id
10378 and to_char(a.request_id) = b.orig_transaction_reference
10379 and a.status_code = 'P'
10380 and b.transaction_source = p_calling_mode;
10381
10382 -- Cursor to fetch expenditure records associated with AP DISCOUNTS records
10383 cursor select_disc_packets(p_calling_mode in varchar2) is
10384 select a.packet_id,
10385 b.cdl_system_reference2,
10386 b.cdl_system_reference5,
10387 a.budget_ccid,
10388 b.cdl_system_reference4,
10389 a.project_id,
10390 a.budget_line_id ,
10391 a.budget_version_id
10392 from pa_bc_packets a,
10393 pa_transaction_interface b,-- moac changes
10394 pa_expenditure_items c
10395 where a.txn_interface_id = b.txn_interface_id
10396 and a.document_header_id = b.expenditure_item_id
10397 and a.document_distribution_id = 1
10398 and a.document_type = decode(p_calling_mode, 'AP DISCOUNTS', 'EXP')
10399 and a.parent_bc_packet_id is null
10400 and b.transaction_status_code = 'A'
10401 and a.request_id = g_request_id
10402 and a.request_id = b.orig_transaction_reference
10403 and a.status_code = 'P'
10404 and b.expenditure_item_id = c.expenditure_item_id
10405 and b.transaction_source = p_calling_mode;
10406
10407 -- Cursor to fetch AP INVOICE/AP NRTAX records
10408 -- Second Union all is used to fetch PO records relieved while interfacing AP invoice distributions
10409 -- Eg : AP matched to CWK PO , AP matched to accrue on receipt
10410 cursor rcpt_acc_ap_pkts(p_calling_mode in varchar2) is
10411 select a.packet_id ,
10412 a.document_header_id ,
10413 a.document_distribution_id ,
10414 a.budget_ccid,
10415 b.cdl_system_reference4,
10416 a.project_id,
10417 a.budget_line_id ,
10418 a.budget_version_id
10419 from pa_bc_packets a,
10420 pa_transaction_interface b -- moac changes
10421 where a.txn_interface_id = b.txn_interface_id
10422 and a.document_header_id = b.cdl_system_reference2
10423 and a.document_distribution_id = b.cdl_system_reference5
10424 and a.document_type = 'AP'
10425 and a.parent_bc_packet_id is null
10426 and b.transaction_status_code = 'A'
10427 and a.request_id = g_request_id
10428 and b.transaction_source = p_calling_mode
10429 and a.status_code = 'P'
10430 union
10431 select a.packet_id ,
10432 to_number(b.cdl_system_reference2) ,
10433 to_number(b.cdl_system_reference5) ,
10434 a.budget_ccid,
10435 b.cdl_system_reference4,
10436 a.project_id,
10437 a.budget_line_id ,
10438 a.budget_version_id
10439 from pa_bc_packets a,
10440 pa_transaction_interface b, -- moac changes
10441 ap_invoice_distributions c,
10442 po_distributions d
10443 where a.txn_interface_id = b.txn_interface_id
10444 and a.document_header_id = d.po_header_id
10445 and a.document_distribution_id = d.po_distribution_id
10446 and c.invoice_id = b.cdl_system_reference2
10447 and c.invoice_distribution_id = b.cdl_system_reference5
10448 and c.po_distribution_id = d.po_distribution_id
10449 and a.document_type = 'PO'
10450 and a.parent_bc_packet_id is null
10451 and b.transaction_status_code = 'A'
10452 and a.request_id = g_request_id
10453 and b.transaction_source IN ('AP INVOICE','AP NRTAX') -- Bug 5550268
10454 and a.status_code = 'P'
10455 union /*Self Assessed Tax Changes */
10456 select a.packet_id ,
10457 to_number(b.cdl_system_reference2) ,
10458 to_number(b.cdl_system_reference5) ,
10459 a.budget_ccid,
10460 b.cdl_system_reference4,
10461 a.project_id,
10462 a.budget_line_id ,
10463 a.budget_version_id
10464 from pa_bc_packets a,
10465 pa_transaction_interface b,
10466 ap_self_assessed_tax_dist c,
10467 po_distributions d
10468 where a.txn_interface_id = b.txn_interface_id
10469 and a.document_header_id = d.po_header_id
10470 and a.document_distribution_id = d.po_distribution_id
10471 and c.invoice_id = b.cdl_system_reference2
10472 and c.invoice_distribution_id = b.cdl_system_reference5
10473 and c.po_distribution_id = d.po_distribution_id
10474 and a.document_type = 'PO'
10475 and a.parent_bc_packet_id is null
10476 and b.transaction_status_code = 'A'
10477 and a.request_id = g_request_id
10478 and b.transaction_source IN ('AP INVOICE','AP NRTAX')
10479 and a.status_code = 'P';
10480
10481 CURSOR c_exp_item_id IS
10482 SELECT txn.expenditure_item_id ,
10483 pkt.bc_packet_id
10484 FROM pa_transaction_interface txn,-- moac changes
10485 pa_bc_packets pkt
10486 WHERE pkt.txn_interface_id = txn.txn_interface_id
10487 and pkt.request_id = g_request_id
10488 and txn.transaction_status_code = 'A'
10489 and pkt.status_code = 'P'
10490 and pkt.document_type ='EXP'
10491 and txn.adjusted_expenditure_item_id IS NOT NULL
10492 and pkt.document_header_id <> txn.expenditure_item_id;
10493
10494 l_packet_id NUMBER ;
10495 l_sys_ref2 NUMBER ;
10496 l_sys_ref3 NUMBER ;
10497 l_sys_ref4 VARCHAR2(30) ;
10498 l_doc_dist_id pa_bc_packets.document_distribution_id%TYPE ;
10499 l_ExpItemId_temp_Tab PA_PLSQL_DATATYPES.Num15TabTyp;
10500 l_budget_ccid NUMBER ;
10501 l_old_pkt NUMBER := 0;
10502 l_project_id NUMBER ;
10503 l_bc_pkt_id pa_bc_packets.bc_packet_id%TYPE;
10504 l_exp_item_id pa_expenditure_items_all.expenditure_item_id%TYPE;
10505 l_budget_line_id pa_bc_packets.budget_line_id%TYPE;
10506 l_budget_version_id pa_bc_packets.budget_version_id%TYPE;
10507
10508
10509 PROCEDURE Upd_Sts_Enc_Bal(p_packet_id in number,
10510 x_return_status out NOCOPY varchar2 ) is
10511
10512 l_fc_return_status VARCHAR2(10);
10513
10514 -- Bug 5372480 : Removed the cursor c_bcpkt_projects as we already have p_packet_id.
10515
10516 l_records_updated number;
10517
10518 BEGIN
10519
10520 IF PG_DEBUG = 'Y' THEN
10521 log_message('log_message: ' || 'Inside Upd_Sts_Enc_Bal');
10522 END IF;
10523
10524 -- R12 funds management : 'C' status code has been obsoleted
10525 l_records_updated := 0;
10526
10527 -- Bug 5372480 : Records of pa_bc_packets are marked to 'A' status before calling pa_funds_control_pkg.UPD_BDGT_ENCUM_BAL
10528 -- because the CURSOR bdgt_encum_details in pa_funds_control_pkg.UPD_BDGT_ENCUM_BAL queries for 'A' status records from pa_bc_packets.
10529 -- Also there is no need to loop for distinct projects earlier being fetched by cursor c_bcpkt_projects.
10530
10531 update pa_bc_packets a
10532 set a.status_code = 'A'
10533 where a.packet_id = p_packet_id
10534 and a.request_id = g_request_id
10535 and a.status_code = 'P';
10536
10537 l_records_updated := l_records_updated + SQL%ROWCOUNT;
10538
10539
10540 IF PG_DEBUG = 'Y' THEN
10541 pa_debug.G_err_stage := 'Updated PacketId [' || p_packet_id || ']-' || l_records_updated || ' records to A/C';
10542 log_message('log_message: ' || pa_debug.G_err_Stage);
10543 END IF;
10544
10545
10546 IF PG_DEBUG = 'Y' THEN
10547 log_message('log_message: ' || 'Calling pa_funds_control_pkg.UPD_BDGT_ENCUM_BAL');
10548 END IF;
10549
10550 -- set the return status to success
10551 x_return_status := FND_API.G_RET_STS_SUCCESS;
10552
10553 pa_funds_control_pkg.UPD_BDGT_ENCUM_BAL(
10554 p_packet_id => p_packet_id,
10555 p_calling_module => 'TRXIMPORT',
10556 p_mode => 'R',
10557 p_packet_status => 'S',
10558 x_return_status => l_fc_return_status);
10559
10560 if l_fc_return_status <> FND_API.G_RET_STS_SUCCESS then
10561 x_return_status := l_fc_return_status ;
10562 return;
10563 end if;
10564
10565
10566 EXCEPTION
10567 WHEN OTHERS THEN
10568 x_return_status := fnd_api.g_ret_sts_unexp_error;
10569 RAISE;
10570
10571 END Upd_Sts_Enc_Bal;
10572
10573 BEGIN
10574
10575 pa_cc_utils.set_curr_function('tieback_fc_records');
10576
10577 IF PG_DEBUG = 'Y' THEN
10578 pa_debug.G_err_stage := 'Start of tieback_fc_records';
10579 log_message('log_message: ' || pa_debug.G_err_Stage);
10580 END IF;
10581
10582 -- set the return status to success
10583 x_return_status := FND_API.G_RET_STS_SUCCESS;
10584
10585 IF PG_DEBUG = 'Y' THEN
10586 log_message('log_message: ' || 'p_calling_mode = ' || p_calling_mode);
10587 END IF;
10588
10589 open c_exp_item_id;
10590 loop
10591 fetch c_exp_item_id
10592 into l_exp_item_id,
10593 l_bc_pkt_id;
10594
10595 if c_exp_item_id%notfound then
10596 IF PG_DEBUG = 'Y' THEN
10597 pa_debug.G_err_stage := 'No packets found for updating of exp item id , exit';
10598 log_message('log_message: ' || pa_debug.G_err_Stage);
10599 END IF;
10600 exit;
10601 end if;
10602
10603 UPDATE pa_bc_packets
10604 SET document_header_id = l_exp_item_id,
10605 reference1 = l_exp_item_id
10606 WHERE bc_packet_id = l_bc_pkt_id;
10607 END LOOP;
10608 CLOSE c_exp_item_id;
10609
10610 -- Bug 5560524 : Added 'AP ERV' to the following condition.
10611 if (p_calling_mode in ('AP VARIANCE', 'AP ERV' , 'PO RECEIPT', 'PO RECEIPT NRTAX')) Then
10612
10613 IF PG_DEBUG = 'Y' THEN
10614 pa_debug.G_err_stage := 'Before opening the cursor select_bc_packets for ' || p_calling_mode;
10615 log_message('log_message: ' || pa_debug.G_err_Stage);
10616 END IF;
10617
10618 open select_bc_packets(p_calling_mode) ;
10619
10620 loop
10621
10622 fetch select_bc_packets
10623 into l_packet_id,
10624 l_sys_ref2,
10625 l_doc_dist_id,
10626 l_budget_ccid,
10627 l_sys_ref4,
10628 l_project_id,
10629 l_budget_line_id ,
10630 l_budget_version_id;
10631
10632 if select_bc_packets%notfound then
10633 IF PG_DEBUG = 'Y' THEN
10634 pa_debug.G_err_stage := 'No packets found, exit';
10635 log_message('log_message: ' || pa_debug.G_err_Stage);
10636 END IF;
10637 exit ;
10638 end if;
10639
10640 IF PG_DEBUG = 'Y' THEN
10641 pa_debug.G_err_stage := 'Old Pkt = ' || l_old_pkt
10642 || ' Packet Id = ' || l_packet_id
10643 || ' Ref2 = ' || l_sys_ref2
10644 || ' document dist id = ' || l_doc_dist_id
10645 || ' Ref4 = ' || l_sys_ref4;
10646 log_message('log_message: ' || pa_debug.G_err_Stage);
10647 END IF;
10648
10649 IF (l_old_pkt <> l_packet_id) THEN
10650 IF PG_DEBUG = 'Y' THEN
10651 pa_debug.G_err_stage := 'Calling Upd_Sts_Enc_Bal';
10652 log_message('log_message: ' || pa_debug.G_err_Stage);
10653 END IF;
10654
10655 Upd_Sts_Enc_Bal(p_packet_id => l_packet_id,
10656 x_return_status => x_return_status);
10657
10658 IF PG_DEBUG = 'Y' THEN
10659 pa_debug.G_err_stage := 'After Calling Upd_Sts_Enc_Bal';
10660 log_message('log_message: ' || pa_debug.G_err_Stage);
10661 END IF;
10662 END IF;
10663
10664 IF (pa_funds_control_utils.get_bdgt_link(l_Project_Id, 'STD') = 'Y') THEN
10665
10666 -- BUG : 4885459 : APPSPERF:PA:PJC: PA_TRX_IMPORT : PERF. REPOSITORY EXCEPTIONS
10667
10668 l_ExpItemId_temp_Tab.DELETE ;
10669
10670 select ei.expenditure_item_id
10671 bulk collect into l_ExpItemId_temp_Tab
10672 from pa_expenditure_items_all ei
10673 where ei.document_header_id = l_sys_ref2
10674 and ei.document_distribution_id = DECODE(p_calling_mode,'AP VARIANCE',l_doc_dist_id,'AP ERV',l_doc_dist_id,l_sys_ref4); -- Bug 5560524
10675
10676 IF l_ExpItemId_temp_Tab.COUNT > 0 THEN
10677
10678 FORALL j in l_ExpItemId_temp_Tab.first..l_ExpItemId_temp_Tab.last
10679 update pa_cost_distribution_lines_all cdl
10680 set cdl.Budget_CCID = l_budget_ccid ,
10681 cdl.encumbrance_type_id = pa_funds_control_utils.get_encum_type_id(cdl.project_id,'STD'),
10682 cdl.budget_line_id = DECODE(cdl.budget_line_id,NULL,l_budget_line_id,cdl.budget_line_id),
10683 cdl.budget_version_id = DECODE(cdl.budget_version_id,NULL,l_budget_version_id,cdl.budget_version_id)
10684 Where cdl.budget_ccid is null
10685 and cdl.expenditure_item_id = l_ExpItemId_temp_Tab(j) ;
10686 END IF ;
10687
10688 IF PG_DEBUG = 'Y' THEN
10689 pa_debug.G_err_stage := 'Updated Ref2-Ref3 [' || l_sys_ref2 || ',' || l_doc_dist_id || ',' || l_sys_ref4 || ']-'
10690 || SQL%ROWCOUNT || ' Budget CCID';
10691 log_message('log_message: ' || pa_debug.G_err_Stage);
10692 END IF;
10693
10694 END IF;
10695
10696 l_old_pkt := l_packet_id;
10697
10698 end loop;
10699
10700 /* start of bug 3905744 first part */
10701 IF select_bc_packets%isopen THEN
10702 close select_bc_packets;
10703 END IF;
10704 /* end of bug 3905744 first part */
10705 --bug 3905744 closed after the second part
10706
10707 elsif (p_calling_mode in ('AP INVOICE', 'AP NRTAX') ) then
10708
10709 IF PG_DEBUG = 'Y' THEN
10710 pa_debug.G_err_stage := 'Before opening the cursor rcpt_acc_ap_pkts for ' || p_calling_mode;
10711 log_message('log_message: ' || pa_debug.G_err_Stage);
10712 END IF;
10713
10714 open rcpt_acc_ap_pkts(p_calling_mode);
10715
10716 loop
10717
10718 fetch rcpt_acc_ap_pkts
10719 into l_packet_id,
10720 l_sys_ref2,
10721 l_doc_dist_id,
10722 l_budget_ccid,
10723 l_sys_ref4,
10724 l_project_id,
10725 l_budget_line_id ,
10726 l_budget_version_id;
10727
10728 if rcpt_acc_ap_pkts%notfound then
10729 IF PG_DEBUG = 'Y' THEN
10730 pa_debug.G_err_stage := 'No packets found, exit';
10731 log_message('log_message: ' || pa_debug.G_err_Stage);
10732 END IF;
10733 exit;
10734 end if;
10735
10736 IF PG_DEBUG = 'Y' THEN
10737 pa_debug.G_err_stage := 'Old Pkt = ' || l_old_pkt
10738 || ' Packet Id = ' || l_packet_id
10739 || ' Ref2 = ' || l_sys_ref2
10740 || ' Document dist Id = ' || l_doc_dist_id
10741 || ' Ref4 = ' || l_sys_ref4;
10742 log_message('log_message: ' || pa_debug.G_err_Stage);
10743 END IF;
10744
10745 IF (l_old_pkt <> l_packet_id) THEN
10746 IF PG_DEBUG = 'Y' THEN
10747 pa_debug.G_err_stage := 'Calling Upd_Sts_Enc_Bal';
10748 log_message('log_message: ' || pa_debug.G_err_Stage);
10749 END IF;
10750
10751 Upd_Sts_Enc_Bal(p_packet_id => l_packet_id,
10752 x_return_status => x_return_status);
10753
10754 IF PG_DEBUG = 'Y' THEN
10755 pa_debug.G_err_stage := 'After Calling Upd_Sts_Enc_Bal';
10756 log_message('log_message: ' || pa_debug.G_err_Stage);
10757 END IF;
10758 END IF;
10759
10760 IF (pa_funds_control_utils.get_bdgt_link(l_Project_Id, 'STD') = 'Y') THEN
10761
10762 -- BUG : 4885459 APPSPERF:PA:PJC: PA_TRX_IMPORT : PERF. REPOSITORY EXCEPTIONS
10763 l_ExpItemId_temp_Tab.DELETE ;
10764
10765 select ei.expenditure_item_id
10766 bulk collect into l_ExpItemId_temp_Tab
10767 from pa_expenditure_items_all ei
10768 where ei.document_header_id = l_sys_ref2
10769 and ei.document_distribution_id = l_doc_dist_id; /*REL12 : AP Lines Uptake changes*/
10770
10771 IF l_ExpItemId_temp_Tab.COUNT > 0 THEN
10772
10773 FORALL j in l_ExpItemId_temp_Tab.first..l_ExpItemId_temp_Tab.last
10774 update pa_cost_distribution_lines_all cdl
10775 set cdl.Budget_CCID = l_budget_ccid ,
10776 -- R12 Funds Management Uptake : Modified and added below columns logic
10777 cdl.encumbrance_type_id = pa_funds_control_utils.get_encum_type_id(cdl.project_id,'STD'),
10778 cdl.budget_line_id = DECODE(cdl.budget_line_id,NULL,l_budget_line_id,cdl.budget_line_id),
10779 cdl.budget_version_id = DECODE(cdl.budget_version_id,NULL,l_budget_version_id,cdl.budget_version_id)
10780 Where cdl.budget_ccid is null
10781 and cdl.expenditure_item_id = l_ExpItemId_temp_Tab(j) ; /*REL12 : AP Lines Uptake changes*/
10782 END IF ;
10783
10784 IF PG_DEBUG = 'Y' THEN
10785 pa_debug.G_err_stage := 'Updated Ref2-Ref3 [' || l_sys_ref2 || ',' || l_doc_dist_id || ',' || l_sys_ref4 || ']-'
10786 || SQL%ROWCOUNT || ' Budget CCID';
10787 log_message('log_message: ' || pa_debug.G_err_Stage);
10788 END IF;
10789
10790 END IF;
10791
10792 l_old_pkt := l_packet_id;
10793
10794 end loop;
10795
10796 /* Start of bug 3905744 second part */
10797 IF rcpt_acc_ap_pkts%isopen THEN
10798 close rcpt_acc_ap_pkts;
10799 END IF;
10800 /* End of bug 3905744 second part */
10801 --bug 3905744 is ended here
10802 --closed cursor select_bc_packets after use in the first part
10803 --closed cursor rcpt_acc_ap_pkts after use in the second part
10804
10805 elsif (p_calling_mode in ('AP DISCOUNTS')) Then --Bug 2339216
10806
10807 IF PG_DEBUG = 'Y' THEN
10808 pa_debug.G_err_stage := 'Before opening the cursor select_disc_packets for ' || p_calling_mode;
10809 log_message('log_message: ' || pa_debug.G_err_Stage);
10810 END IF;
10811
10812 open select_disc_packets(p_calling_mode) ;
10813
10814 loop
10815
10816 fetch select_disc_packets
10817 into l_packet_id,
10818 l_sys_ref2,
10819 l_doc_dist_id,
10820 l_budget_ccid,
10821 l_sys_ref4,
10822 l_project_id,
10823 l_budget_line_id ,
10824 l_budget_version_id;
10825
10826 if select_disc_packets%notfound then
10827 IF PG_DEBUG = 'Y' THEN
10828 pa_debug.G_err_stage := 'No discount packets found, exit';
10829 log_message('log_message: ' || pa_debug.G_err_Stage);
10830 END IF;
10831 exit ;
10832 end if;
10833
10834 IF PG_DEBUG = 'Y' THEN
10835 pa_debug.G_err_stage := 'Old Pkt = ' || l_old_pkt
10836 || ' Packet Id = ' || l_packet_id
10837 || ' Ref2 = ' || l_sys_ref2
10838 || ' Document dist Id = ' || l_doc_dist_id
10839 || ' Ref4 = ' || l_sys_ref4;
10840 log_message('log_message: ' || pa_debug.G_err_Stage);
10841 END IF;
10842
10843 IF (l_old_pkt <> l_packet_id) THEN
10844 IF PG_DEBUG = 'Y' THEN
10845 pa_debug.G_err_stage := 'Calling Upd_Sts_Enc_Bal for discount';
10846 log_message('log_message: ' || pa_debug.G_err_Stage);
10847 END IF;
10848
10849 Upd_Sts_Enc_Bal(p_packet_id => l_packet_id,
10850 x_return_status => x_return_status);
10851
10852 IF PG_DEBUG = 'Y' THEN
10853 pa_debug.G_err_stage := 'After Calling Upd_Sts_Enc_Bal';
10854 log_message('log_message: ' || pa_debug.G_err_Stage);
10855 END IF;
10856 END IF;
10857
10858 IF (pa_funds_control_utils.get_bdgt_link(l_Project_Id, 'STD') = 'Y') THEN
10859
10860 -- BUG : 4885459 APPSPERF:PA:PJC: PA_TRX_IMPORT : PERF. REPOSITORY EXCEPTIONS
10861
10862 l_ExpItemId_temp_Tab.DELETE ;
10863
10864 select ei.expenditure_item_id
10865 bulk collect into l_ExpItemId_temp_Tab
10866 from pa_expenditure_items_all ei
10867 where ei.document_header_id = l_sys_ref2
10868 and ei.document_distribution_id = l_doc_dist_id
10869 and ei.document_payment_id = to_number(l_sys_ref4);
10870
10871 IF l_ExpItemId_temp_Tab.COUNT > 0 THEN
10872 FORALL j in l_ExpItemId_temp_Tab.first..l_ExpItemId_temp_Tab.last
10873 update pa_cost_distribution_lines_all cdl
10874 set cdl.Budget_CCID = l_budget_ccid ,
10875 cdl.encumbrance_type_id = pa_funds_control_utils.get_encum_type_id(cdl.project_id,'STD'),
10876 -- R12 Funds Management Uptake
10877 cdl.budget_line_id = DECODE(cdl.budget_line_id,NULL,l_budget_line_id,cdl.budget_line_id),
10878 cdl.budget_version_id = DECODE(cdl.budget_version_id,NULL,l_budget_version_id,cdl.budget_version_id)
10879 Where cdl.budget_ccid is null
10880 and cdl.expenditure_item_id = l_ExpItemId_temp_Tab(j) ;
10881 END IF ;
10882
10883 IF PG_DEBUG = 'Y' THEN
10884 pa_debug.G_err_stage := 'Updated Ref2-Ref3 [' || l_sys_ref2 || ',' || l_sys_ref3 || ',' || l_sys_ref4 || ']-'
10885 || SQL%ROWCOUNT || ' Budget CCID';
10886 log_message('log_message: ' || pa_debug.G_err_Stage);
10887 END IF;
10888
10889 END IF;
10890
10891 l_old_pkt := l_packet_id;
10892
10893 end loop;
10894 close select_disc_packets;
10895 end if;
10896
10897 /* Start of bug 3239837 */
10898 pa_debug.G_err_stage := 'Update rejected interface records in pa_bc_packets to T';
10899 pa_cc_utils.log_message(pa_debug.G_err_Stage);
10900
10901 update pa_bc_packets
10902 set status_code = 'T',
10903 result_code = 'F140'
10904 where request_id = g_request_id
10905 and status_code = 'P'
10906 and txn_interface_id in
10907 (select txn_interface_id /*REL12 : AP Lines Uptake changes*/
10908 from pa_transaction_interface_all
10909 where transaction_source = p_calling_mode
10910 and transaction_status_code = 'R'
10911 and orig_transaction_reference = to_char(g_request_id)
10912 );
10913
10914 pa_debug.G_err_stage := 'In stage 1 Updated count to T = '|| SQL%ROWCOUNT;
10915 pa_cc_utils.log_message(pa_debug.G_err_Stage);
10916
10917 update pa_bc_packets
10918 set status_code = 'T',
10919 result_code = 'F140'
10920 where request_id = g_request_id
10921 and status_code = 'P'
10922 and (document_header_id, document_distribution_id) in
10923 (select po_header_id, po_distribution_id
10924 from po_distributions_all
10925 where po_distribution_id in
10926 (select po_distribution_id
10927 from ap_invoice_distributions_all inv, pa_transaction_interface_all pti
10928 where inv.invoice_id = pti.cdl_system_reference2
10929 and inv.invoice_distribution_id = pti.cdl_system_reference5 /*REL12 : AP Lines Uptake changes*/
10930 and pti.transaction_source = p_calling_mode
10931 and pti.transaction_status_code = 'R'
10932 and pti.orig_transaction_reference = to_char(g_request_id))
10933 );
10934
10935 pa_debug.G_err_stage := 'In stage 2 Updated count to T = '|| SQL%ROWCOUNT;
10936 pa_cc_utils.log_message(pa_debug.G_err_Stage);
10937
10938 /* End of bug 3239837 */
10939
10940 --Bug 3592289
10941 --If pkts are still left in 'P' sts, it means the corresponding
10942 --EIs in the interface table are rejected. The above cursors select
10943 --only transaction status code = 'A'. Hence, here we update all
10944 --the remaining 'P' status for the request id to 'T'
10945 IF PG_DEBUG = 'Y' THEN
10946 log_message('log_message: Before update to T');
10947 END IF;
10948
10949 update pa_bc_packets
10950 set status_code = 'T',
10951 result_code = 'F140'
10952 where status_code = 'P'
10953 and request_id = G_REQUEST_ID;
10954
10955 IF PG_DEBUG = 'Y' THEN
10956 log_message('log_message: ' || 'Updated ' || SQL%ROWCOUNT || ' packet statuses to T');
10957 END IF;
10958
10959 --Bug 3592289 End
10960
10961
10962 IF PG_DEBUG = 'Y' THEN
10963 pa_debug.G_err_stage := 'Done with Tieback';
10964 log_message('log_message: ' || pa_debug.G_err_Stage);
10965 END IF;
10966
10967 pa_cc_utils.reset_curr_function;
10968
10969 EXCEPTION
10970 WHEN OTHERS THEN
10971 x_return_status := fnd_api.g_ret_sts_unexp_error;
10972 RAISE;
10973 END tieback_fc_records;
10974
10975 --PA-J Receipt Accrual Changes:
10976 -- 1. Renamed all existing cursors so that it can be distinguished by the source.
10977 -- Renamed c_commitment, c_bc_packets, commitment_exist cursors to
10978 -- c_ap_commitment, c_ap_bc_packets, ap_commitment_exist.
10979 -- 2. Added 2 more IN parameters to tr_import_funds_check, namely
10980 -- p_txn_source, p_acct_raw_cost
10981 -- 3. Added 3 more cursors for the PO records - c_po_commitment, c_po_bc_packets, po_commitment_exist
10982 -- 4. Converted the existing section to insert AP funds check records and added a new section for
10983 -- PO based on the p_txn_source.
10984 -- 5. For the PO reversing raw line, use -p_acct_raw_cost as the
10985 -- (accounted_dr-accounted_cr) and (entered_dr-entered_cr) columns resp.
10986 -- 6. For the PO reversing burden line, prorate the amount from the burden line of the original PO line.
10987 -- 7. For the positive EXP line, use the p_acct_raw_cost for the amount columns.
10988 PROCEDURE tr_import_funds_check ( p_pa_date IN DATE,
10989 p_txn_source IN VARCHAR2,
10990 p_acct_raw_cost IN NUMBER,
10991 p_adj_exp_item_id IN NUMBER,
10992 p_txn_interface_id IN NUMBER,
10993 p_fc_document_type IN VARCHAR2,
10994 x_packet_id OUT NOCOPY NUMBER,
10995 x_error_message_code OUT NOCOPY VARCHAR2,
10996 x_error_stage OUT NOCOPY VARCHAR2,
10997 x_return_status OUT NOCOPY VARCHAR2) IS
10998
10999 --R12 funds management uptake : modified corresponding insert api's to autonomous
11000 -- PRAGMA AUTONOMOUS_TRANSACTION;
11001
11002 -- R12 AP lines uptake : Prepayment changes :
11003 -- Deleted obsolete variables
11004
11005 l_packet_id NUMBER ;
11006 l_po_dist_id NUMBER;
11007 l_acc_flag VARCHAR2(1);
11008 l_po_hdr_id NUMBER;
11009 l_denom_po_amt NUMBER;
11010 l_acct_po_amt NUMBER;
11011 l_normal_inv VARCHAR2(1) := 'Y';
11012 l_txn_source VARCHAR2(30) := p_txn_source;
11013 --R12 Funds Management Uptake : Deleted variables defined for storing encumbrance types
11014 l_project_id NUMBER(15);
11015 l_base_qv NUMBER;
11016 l_base_av NUMBER;
11017 l_period_year pa_bc_packets.period_year%type; --REL12
11018 l_inv_type ap_invoices_all.invoice_type_lookup_code%TYPE;
11019 l_line_type_lookup_code ap_invoice_distributions_all.line_type_lookup_code%TYPE;
11020
11021 -- R12 AP lines uptake : Prepayment changes :Cursor to fetch AP related details.
11022 CURSOR C_ap_details (p_invoice_id NUMBER,
11023 p_invoice_distribution_id NUMBER) IS
11024 SELECT dist.po_distribution_id,
11025 dist.project_id,
11026 nvl(dist.base_quantity_variance,0), --PA.M QV and AV
11027 NVL(dist.base_amount_variance,0),
11028 inv.invoice_type_lookup_code,
11029 dist.line_type_lookup_code
11030 FROM ap_invoice_distributions dist,
11031 ap_invoices inv
11032 WHERE dist.invoice_id = p_invoice_id
11033 AND dist.invoice_distribution_id = p_invoice_distribution_id
11034 AND inv.invoice_id = dist.invoice_id
11035 union /*Self Assessed Tax Changes*/
11036 SELECT dist.po_distribution_id,
11037 dist.project_id,
11038 nvl(dist.base_quantity_variance,0), --PA.M QV and AV
11039 NVL(dist.base_amount_variance,0),
11040 inv.invoice_type_lookup_code,
11041 dist.line_type_lookup_code
11042 FROM ap_self_assessed_tax_dist dist,
11043 ap_invoices inv
11044 WHERE dist.invoice_id = p_invoice_id
11045 AND dist.invoice_distribution_id = p_invoice_distribution_id
11046 AND inv.invoice_id = dist.invoice_id
11047 ;
11048
11049 --Bug 2905892
11050 --Derive Period_Name for the given GL_Date from GL_Period_Statuses
11051 --for Application_Id 101.
11052 --Funds checking is done using GL periods (application id = 101)
11053 FUNCTION Get_FC_Period_Name(P_GL_Date IN DATE) RETURN VARCHAR2 IS
11054 l_Period_Name pa_bc_packets.period_name%type;
11055 BEGIN
11056
11057 IF PG_DEBUG = 'Y' THEN
11058 pa_debug.G_err_stage := 'Inside Get_FC_Period_Name function';
11059 log_message('log_message: ' || pa_debug.G_err_Stage);
11060 END IF;
11061
11062 If P_GL_Date = G_PrevFCGlDate Then
11063
11064 l_Period_Name := G_PrevFCPdName;
11065
11066 Else
11067
11068 Select Period_Name,PERIOD_YEAR
11069 Into l_Period_Name,l_period_year
11070 From Gl_Period_Statuses
11071 Where Application_Id = 101
11072 And Trunc(P_GL_Date) Between Trunc(Start_Date) And Trunc(End_Date)
11073 And Set_Of_Books_Id = G_SobId
11074 And adjustment_period_flag = 'N'; -- added for bug 3083625
11075
11076 G_PrevFCGlDate := P_GL_Date;
11077 G_PrevFCPdName := l_Period_Name;
11078 G_Fc_Period_Year := l_period_year;
11079
11080 End If;
11081
11082 IF PG_DEBUG = 'Y' THEN
11083 pa_debug.G_err_stage := 'Period_Name is='||l_Period_Name;
11084 log_message('log_message: ' || pa_debug.G_err_Stage);
11085 END IF;
11086
11087 Return l_Period_Name;
11088
11089 EXCEPTION
11090 WHEN OTHERS THEN
11091 Raise;
11092
11093 END Get_FC_Period_Name;
11094
11095 BEGIN
11096
11097 pa_cc_utils.set_curr_function('tr_import_funds_check');
11098 IF PG_DEBUG = 'Y' THEN
11099 pa_debug.G_err_stage := 'Inside Tr_Import_Funds_Check';
11100 log_message('log_message: ' || pa_debug.G_err_Stage);
11101 END IF;
11102
11103 --
11104 -- 1. Generate a packet identifier for all the records that
11105 -- needs to be inserted into Pa BC Packets
11106 --
11107 IF PG_DEBUG = 'Y' THEN
11108 pa_debug.G_err_stage := 'Generateing new packet Id';
11109 log_message('log_message: ' || pa_debug.G_err_Stage);
11110 END IF;
11111 Select Gl_Bc_Packets_s.NextVal
11112 Into l_Packet_Id
11113 From dual;
11114
11115 /* Since we have divided the funds check packet insert code into 3 sections
11116 the bc packet id will be generated in each of the individual sections
11117 rather than in the beginning
11118 */
11119
11120 --Bug 2905892
11121 --Get the GL Period Name from txn's gl_date. This will be inserted into pa_bc_packets
11122 --for both the reversing raw and burden lines and also the EXP lines.
11123 --Funds Check API will derive the GL_Date based on the Period_Name, so what
11124 --we insert for gl_date is irrelevant here.
11125 IF PG_DEBUG = 'Y' THEN
11126 pa_debug.G_err_stage := 'Calling G_FC_Period_Name';
11127 log_message('log_message: ' || pa_debug.G_err_Stage);
11128 END IF;
11129
11130 G_FC_Period_Name := Get_FC_Period_Name(P_Gl_Date => G_FC_Gl_Date);
11131
11132 IF PG_DEBUG = 'Y' THEN
11133 pa_debug.G_err_stage := 'G_FC_Period_Name = ' || G_FC_Period_Name;
11134 log_message('log_message: ' || pa_debug.G_err_Stage);
11135 log_message('log_message: Value of l_txn_source= ' || l_txn_source);
11136 END IF;
11137 --End Bug 2905892
11138
11139 -- R12 : AP Lines Uptake changes + R12 AP lines uptake : Prepayment changes
11140 -- Cash based Accounting code : When Cash based accounting is set to Yes then
11141 -- following type of transactions are allowed to be interafced to projects :
11142 -- a. Historical Data(i.e.11i) : System interfaces invoice distributions and not the payments.
11143 -- For these records g_cdl_system_reference4 will be NULL.
11144 -- Following invoices in Cash based accounting are considered as historical data :
11145 -- 1. All Invoices (including prepayments) with historical_flag ='Y'
11146 -- 2. All reversal/cancelled Invoices associated with Invoices which are interfaced
11147 -- 3. Prepayment application associated with interfaced prepayment distribution.
11148 --
11149 -- These historical invoices will be firing the same fundscheck logic as that of
11150 -- accrual based accounting invoices.
11151 -- b. R12 Data : Only payments will be interfaced.
11152 -- For these records g_cdl_system_reference4 will be NOT NULL
11153
11154 IF (l_txn_source in ('AP INVOICE', 'AP NRTAX','AP EXPENSE','INTERCOMPANY_AP_INVOICES', 'AP ERV',
11155 'INTERPROJECT_AP_INVOICES','AP VARIANCE') )
11156 AND G_cash_based_accounting = 'Y'
11157 AND NVL(g_cdl_system_reference4,0) <> 0 THEN
11158
11159 IF PG_DEBUG = 'Y' THEN
11160 log_message('log_message: Before Calling ap_cash_based_funds_check' );
11161 END IF;
11162 ap_cash_based_funds_check (
11163 p_txn_source => l_txn_source,
11164 p_acct_raw_cost => p_acct_raw_cost,
11165 p_packet_id => l_packet_id,
11166 p_sys_ref2 => to_number(g_cdl_system_reference2),
11167 p_sys_ref4 => g_cdl_system_reference4,
11168 p_sys_ref5 => to_number(g_cdl_system_reference5),
11169 p_adj_exp_item_id => p_adj_exp_item_id,
11170 p_txn_interface_id => p_txn_interface_id,
11171 p_fc_document_type => p_fc_document_type,
11172 x_error_message_code => x_error_message_code,
11173 x_error_stage => x_error_stage,
11174 x_return_status => x_return_status);
11175
11176
11177 IF PG_DEBUG = 'Y' THEN
11178 log_message('log_message: After Calling ap_cash_based_funds_check' );
11179 log_message('log_message: Value of x_error_message_code='||x_error_message_code );
11180 log_message('log_message: Value of x_error_stage='||x_error_stage );
11181 log_message('log_message: Value of x_return_status='||x_return_status );
11182 END IF;
11183
11184 ELSIF (l_txn_source in ('AP INVOICE', 'AP NRTAX') ) THEN
11185
11186 IF PG_DEBUG = 'Y' THEN
11187 pa_debug.G_err_stage := 'Selecting PO Dist Id for AP Invoice';
11188 log_message('log_message: ' || pa_debug.G_err_Stage);
11189 END IF;
11190
11191 -- REL12 : AP Lines Uptake changes
11192 -- Commented logic associated with IPV and ERV columns as these will be now interfaced
11193 -- as seperate distribution lines
11194
11195 -- R12 AP lines uptake : Prepayment changes: Shifted logic of SELECT statment to cursor .
11196 -- Also modified cursor to fetch value for invoice type
11197
11198 OPEN c_ap_details (to_number(g_cdl_system_reference2),
11199 to_number(g_cdl_system_reference5));
11200 FETCH c_ap_details INTO l_po_dist_id,
11201 l_project_id,
11202 l_base_qv,
11203 l_base_av,
11204 l_inv_type,
11205 l_line_type_lookup_code;
11206 CLOSE c_ap_details;
11207
11208 -- R12 AP lines uptake : Prepayment changes
11209 -- Deleted code added for bug 3746522 as the logic is not required
11210
11211 --PA.M QV and AV
11212 /*REL12 : AP Lines uptake changes */
11213 /*Call to AP_PA_API_PKG.Get_Inv_Amount_Var is deleted and introduced logic to fetch
11214 amt variance from ap_invoice_distributions*/
11215
11216 IF PG_DEBUG = 'Y' THEN
11217 log_message('log_message: ' || 'Po Dist = ' || l_po_dist_id);
11218 log_message('log_message: ' || ' Base QV = ' || l_base_qv );
11219 log_message('log_message: ' || ' Base AV = ' || l_base_av );
11220 log_message('log_message: ' || ' line_type_lookup_code = ' || l_line_type_lookup_code );
11221 END IF;
11222
11223 -- R12 AP lines uptake : Prepayment changes: For prepyament always fire ap_funds_check procedure
11224 -- as PREPAYMENT commitment matched to PO will never be fundschecked
11225
11226 If (l_po_dist_id is not null AND l_inv_type <> 'PREPAYMENT' ) Then
11227
11228 IF PG_DEBUG = 'Y' THEN
11229 pa_debug.G_err_stage := 'PO Dist Found, Selecting Receipt Accrual Flag';
11230 log_message('log_message: ' || pa_debug.G_err_Stage);
11231 END IF;
11232
11233 --R12 Funds management uptake changes: Obsolete logic which was based on financial system parameters.Going forward
11234 --commitments fundscheck will be performed irrespective of value stored in encumbrance types.
11235 --Hence for matched invoices amount should always be relieved against AP.
11236
11237 Select nvl(accrue_on_receipt_flag,'N'),
11238 po_header_id
11239 Into l_acc_flag,
11240 l_po_hdr_id
11241 from Po_distributions
11242 where po_distribution_id = l_po_dist_id;
11243
11244 IF PG_DEBUG = 'Y' THEN
11245 log_message('log_message: ' || 'Receipt Acc Flag = ' || l_acc_flag || ' Po Hdr = ' || l_po_hdr_id);
11246 END IF;
11247
11248 --Bug 2672772: If non-accrue on receipt and enc type same, PO commitment should be relieved
11249 -- Bug 5561690 : TIPV and TRV are interfaced with 'AP NRTAX' transaction source but
11250 -- these lines( matched to PO with accrue on receipt) are reserved as AP commitments.
11251 -- Hence should be treated as normal invoice lines.
11252 If (l_acc_flag = 'Y' AND l_line_type_lookup_code NOT IN ('TRV','TIPV'))
11253 OR --(l_acc_flag = 'N' AND l_po_enc_type_id = l_ap_enc_type_id) OR --R12 Funds Management Uptake
11254 /* when a variance exists on a tax distribution for an invoice matched to a rate based PO
11255 (for which the CWK Imp option is set to Y, meaning timecards are interfaced and only
11256 variance and tax are to be interfaced from AP/PO), the amount minus the variance should be
11257 deducted from PO commitment and the variance should be deducted from AP
11258 commitment */
11259 (l_txn_source = 'AP NRTAX' AND
11260 nvl(Pa_Pjc_Cwk_Utils.Is_rate_based_line( null, l_po_dist_id),'N') = 'Y' AND
11261 Pa_Pjc_CWk_Utils.Is_CWK_TC_Xface_Allowed(l_project_id) = 'Y')Then
11262
11263 IF PG_DEBUG = 'Y' THEN
11264 pa_debug.G_err_stage := 'PO accrues on receipt or Enc Type Same for non-accrue on receipt';
11265 log_message('log_message: ' || pa_debug.G_err_Stage);
11266 END IF;
11267
11268 --This is not a normal invoice meaning we have to reverse the
11269 --PO commitment and then check if there is any variances and
11270 --reverse them too.
11271 l_normal_inv := 'N';
11272
11273 --l_denom_po_amt := p_denom_raw_cost - (l_ipv + l_erv);
11274 --PA.M QV and AV
11275 l_acct_po_amt := p_acct_raw_cost - (/* l_base_ipv + l_erv + */ --REL12
11276 l_base_qv + nvl(l_base_av,0));
11277
11278 IF PG_DEBUG = 'Y' THEN
11279 log_message('log_message: ' || ' Acct PO Amt = ' || l_acct_po_amt);
11280 END IF;
11281
11282 IF PG_DEBUG = 'Y' THEN
11283 pa_debug.G_err_stage := 'Calling ap_po_funds_check';
11284 log_message('log_message: ' || pa_debug.G_err_Stage);
11285 END IF;
11286
11287 ap_po_funds_check (
11288 p_txn_source => l_txn_source,
11289 p_acct_raw_cost => l_acct_po_amt,
11290 p_packet_id => l_packet_id,
11291 p_po_hdr_id => l_po_hdr_id,
11292 p_po_dist_id => l_po_dist_id,
11293 p_inv_id => to_number(g_cdl_system_reference2),
11294 p_inv_dist_id => to_number(g_cdl_system_reference5), --REL12
11295 p_dist_line => to_number(g_cdl_system_reference3), --REL12
11296 p_adj_exp_item_id => p_adj_exp_item_id,
11297 p_txn_interface_id => p_txn_interface_id,
11298 p_fc_document_type => p_fc_document_type,
11299 p_base_qty_var_amt => l_base_qv,
11300 p_base_amt_var_amt => l_base_av,
11301 x_error_message_code => x_error_message_code,
11302 x_error_stage => x_error_stage,
11303 x_return_status => x_return_status);
11304
11305 IF PG_DEBUG = 'Y' THEN
11306 pa_debug.G_err_stage := 'After ap_po_funds_check';
11307 log_message('log_message: ' || pa_debug.G_err_Stage);
11308 END IF;
11309
11310 End If;
11311
11312 End If;
11313
11314 If (l_normal_inv = 'Y') Then
11315
11316 IF PG_DEBUG = 'Y' THEN
11317 pa_debug.G_err_stage := 'Start funds check packet insert for AP - non accrue on receipt diff enc type';
11318 log_message('log_message: ' || pa_debug.G_err_Stage);
11319 log_message('log_message: Calling ap_funds_check api');
11320 END IF;
11321
11322 ap_funds_check (
11323 p_txn_source => l_txn_source,
11324 p_acct_raw_cost => p_acct_raw_cost,
11325 p_packet_id => l_packet_id,
11326 p_sys_ref2 => g_cdl_system_reference2,
11327 p_sys_ref3 => g_cdl_system_reference3,
11328 p_sys_ref5 => g_cdl_system_reference5, --REL12
11329 p_adj_exp_item_id => p_adj_exp_item_id, --REL12
11330 p_txn_interface_id => p_txn_interface_id, --REL12
11331 p_fc_document_type => p_fc_document_type, --REL12
11332 x_error_message_code => x_error_message_code,
11333 x_error_stage => x_error_stage,
11334 x_return_status => x_return_status);
11335
11336 IF PG_DEBUG = 'Y' THEN
11337 pa_debug.G_err_stage := 'After ap_funds_check';
11338 log_message('log_message: ' || pa_debug.G_err_Stage);
11339 END IF;
11340
11341 /*REL12 : AP Lines Uptake changes
11342 Commented below logic as IPV / ERV/QV/AV lines will be separately interfaced
11343 and picked by the AP VARIANCE section */
11344
11345 End If;
11346
11347 --PA-J Receipt Accrual Changes:
11348 -- Added the below section for Receipt records to be funds checked.
11349 ELSIF (l_txn_source in ('PO RECEIPT', 'PO RECEIPT NRTAX')) THEN
11350
11351 IF PG_DEBUG = 'Y' THEN
11352 pa_debug.G_err_stage := 'Start funds check packet insert for PO Receipts';
11353 log_message('log_message: ' || pa_debug.G_err_Stage);
11354 log_message('log_message: Calling po_funds_check api');
11355 END IF;
11356
11357 po_funds_check (
11358 p_txn_source => l_txn_source,
11359 p_acct_raw_cost => p_acct_raw_cost,
11360 p_packet_id => l_packet_id,
11361 p_sys_ref2 => g_cdl_system_reference2,
11362 p_sys_ref3 => g_cdl_system_reference3,
11363 p_sys_ref4 => g_cdl_system_reference4, -- Bug 5530897
11364 p_adj_exp_item_id => p_adj_exp_item_id, --REL12
11365 p_txn_interface_id => p_txn_interface_id, --REL12
11366 p_fc_document_type => p_fc_document_type, --REL12
11367 x_error_message_code => x_error_message_code,
11368 x_error_stage => x_error_stage,
11369 x_return_status => x_return_status);
11370
11371 IF PG_DEBUG = 'Y' THEN
11372 pa_debug.G_err_stage := 'After po_funds_check';
11373 log_message('log_message: ' || pa_debug.G_err_Stage);
11374 END IF;
11375
11376 /* Bug 5560524 : Modified the following If condition so that ap_funds_check is also called for
11377 'AP ERV' transaction source. */
11378 ELSIF (l_txn_source in ('AP VARIANCE','AP ERV')) THEN
11379
11380 IF PG_DEBUG = 'Y' THEN
11381 pa_debug.G_err_stage := 'Start funds check packet insert for AP Variance records';
11382 log_message('log_message: ' || pa_debug.G_err_Stage);
11383 log_message('log_message: Calling ap_funds_check api');
11384 END IF;
11385
11386 ap_funds_check (
11387 p_txn_source => l_txn_source,
11388 p_acct_raw_cost => p_acct_raw_cost,
11389 p_packet_id => l_packet_id,
11390 p_sys_ref2 => g_cdl_system_reference2,
11391 p_sys_ref3 => g_cdl_system_reference3,
11392 p_sys_ref5 => g_cdl_system_reference5,
11393 p_adj_exp_item_id => p_adj_exp_item_id, --REL12
11394 p_txn_interface_id => p_txn_interface_id, --REL12
11395 p_fc_document_type => p_fc_document_type, --REL12
11396 x_error_message_code => x_error_message_code,
11397 x_error_stage => x_error_stage,
11398 x_return_status => x_return_status);
11399
11400 IF PG_DEBUG = 'Y' THEN
11401 pa_debug.G_err_stage := 'After ap_funds_check';
11402 log_message('log_message: ' || pa_debug.G_err_Stage);
11403 END IF;
11404 -- R12 AP lines uptake : Prepayment changes: This is fired for both Cash and Accrual based AP discounts.
11405 ELSIF (l_txn_source in ('AP DISCOUNTS')) THEN --2339216
11406 IF PG_DEBUG = 'Y' THEN
11407 pa_debug.G_err_stage := 'Selecting disc amount for AP Invoice';
11408 log_message('log_message: ' || pa_debug.G_err_Stage);
11409 END IF;
11410
11411 IF PG_DEBUG = 'Y' THEN
11412 pa_debug.G_err_stage := 'Discount amount='||p_acct_raw_cost;
11413 log_message('log_message: ' || pa_debug.G_err_Stage);
11414 END IF;
11415
11416 if ( p_acct_raw_cost <> 0 ) then
11417
11418 IF PG_DEBUG = 'Y' THEN
11419 pa_debug.G_err_stage := 'Aefore Calling ap_disc_funds_check';
11420 log_message('log_message: ' || pa_debug.G_err_Stage);
11421 END IF;
11422
11423 ap_disc_funds_check (
11424 p_txn_source => l_txn_source,
11425 p_acct_raw_cost => p_acct_raw_cost,
11426 p_packet_id => l_packet_id,
11427 p_sys_ref2 => g_cdl_system_reference2,
11428 p_sys_ref3 => g_cdl_system_reference3,
11429 p_sys_ref4 => g_cdl_system_reference4, --REL12
11430 p_sys_ref5 => g_cdl_system_reference5, --REL12
11431 p_adj_exp_item_id => p_adj_exp_item_id, --REL12
11432 p_txn_interface_id => p_txn_interface_id, --REL12
11433 p_fc_document_type => p_fc_document_type, --REL12
11434 x_error_message_code => x_error_message_code,
11435 x_error_stage => x_error_stage,
11436 x_return_status => x_return_status);
11437
11438 IF PG_DEBUG = 'Y' THEN
11439 pa_debug.G_err_stage := 'After Call ap_disc_funds_check';
11440 log_message('log_message: ' || pa_debug.G_err_Stage);
11441 END IF;
11442 end if; --2339216
11443 END IF; --p_txn_source check
11444
11445 x_packet_id := l_packet_id ;
11446 IF PG_DEBUG = 'Y' THEN
11447 log_message('log_message: ' || 'Returning from funds check');
11448 END IF;
11449 pa_cc_utils.reset_curr_function;
11450
11451 -- set the return status to success
11452 x_return_status := FND_API.G_RET_STS_SUCCESS;
11453
11454 EXCEPTION
11455 WHEN OTHERS THEN
11456 log_message('log_message: In others of tr import, packet_id = '|| l_packet_id); -- Bug 3592289
11457 Upd_PktSts(p_packet_id => l_packet_id);
11458
11459 IF PG_DEBUG = 'Y' THEN
11460 log_message('log_message: ' || sqlerrm||' Returning from funds check');
11461 log_message('log_message: x_return_status = ' || x_return_status); -- Bug 3592289
11462 log_message('log_message: x_error = ' || x_error_message_code); -- Bug 3592289
11463 END IF;
11464 x_return_status := fnd_api.g_ret_sts_unexp_error;
11465 pa_cc_utils.reset_curr_function;
11466 END tr_import_funds_check ;
11467
11468 --2339216: Added procedure
11469 PROCEDURE ap_disc_funds_check (
11470 p_txn_source IN VARCHAR2,
11471 p_acct_raw_cost IN NUMBER,
11472 p_packet_id IN NUMBER,
11473 p_sys_ref2 IN NUMBER,
11474 p_sys_ref3 IN NUMBER,
11475 p_sys_ref4 IN VARCHAR2, --REL12
11476 p_sys_ref5 IN NUMBER, --REL12
11477 p_adj_exp_item_id IN NUMBER, --REL12
11478 p_txn_interface_id IN NUMBER, --REL12
11479 p_fc_document_type IN VARCHAR2, --REL12
11480 x_error_message_code OUT NOCOPY VARCHAR2,
11481 x_error_stage OUT NOCOPY VARCHAR2,
11482 x_return_status OUT NOCOPY VARCHAR2) IS
11483
11484 BEGIN
11485
11486 pa_cc_utils.set_curr_function('ap_disc_funds_check');
11487
11488 IF PG_DEBUG = 'Y' THEN
11489 pa_debug.G_err_stage := 'Inside AP_Disc_Funds_Check';
11490 log_message('log_message: ' || pa_debug.G_err_Stage);
11491 log_message('log_message: Before calling insert_ap_bc_packets api');
11492 END IF;
11493
11494 insert_ap_bc_packets( p_packet_id => p_packet_id,
11495 p_sys_ref2 => p_sys_ref2,
11496 p_sys_ref4 => p_sys_ref4,
11497 p_sys_ref5 => p_sys_ref5,
11498 p_acct_raw_cost => p_acct_raw_cost,
11499 p_acct_bur_cost => 0,
11500 p_fc_document_type => p_fc_document_type ,
11501 p_txn_source => p_txn_source ,
11502 p_adj_exp_item_id => p_adj_exp_item_id ,
11503 p_txn_interface_id => p_txn_interface_id);
11504
11505 IF PG_DEBUG = 'Y' THEN
11506 log_message('log_message: After calling insert_ap_bc_packets api');
11507 END IF;
11508
11509 -- set the return status to success
11510 x_return_status := FND_API.G_RET_STS_SUCCESS;
11511
11512 pa_cc_utils.reset_curr_function;
11513
11514 EXCEPTION
11515 --Bug 2672772: Handle the NDF exception,
11516 --raise the error here but not in tr_import_funds_check
11517 WHEN NO_DATA_FOUND THEN
11518 IF PG_DEBUG = 'Y' THEN
11519 log_message('log_message: ' || sqlerrm||' In NDF: Returning from ap disc funds check');
11520 END IF;
11521 --Call FC packets update API to update packets to T.
11522 --moved to tr_import_funds_check
11523 --Upd_PktSts(p_packet_id => p_packet_id);
11524
11525 x_return_status := fnd_api.g_ret_sts_error;
11526 x_error_message_code := 'PA_FC_NDF';
11527
11528 pa_cc_utils.reset_curr_function;
11529 RAISE;
11530
11531 WHEN OTHERS THEN
11532 IF PG_DEBUG = 'Y' THEN
11533 log_message('log_message: ' || sqlerrm||' Returning from ap disc funds check');
11534 END IF;
11535 x_return_status := fnd_api.g_ret_sts_unexp_error;
11536 pa_cc_utils.reset_curr_function;
11537 RAISE;
11538 END ap_disc_funds_check;
11539
11540 PROCEDURE ap_funds_check (
11541 p_txn_source IN VARCHAR2,
11542 p_acct_raw_cost IN NUMBER,
11543 p_packet_id IN NUMBER,
11544 p_sys_ref2 IN NUMBER,
11545 p_sys_ref3 IN NUMBER,
11546 p_sys_ref5 IN NUMBER, --REL12
11547 p_adj_exp_item_id IN NUMBER, --REL12
11548 p_txn_interface_id IN NUMBER, --REL12
11549 p_fc_document_type IN VARCHAR2, --REL12
11550 x_error_message_code OUT NOCOPY VARCHAR2,
11551 x_error_stage OUT NOCOPY VARCHAR2,
11552 x_return_status OUT NOCOPY VARCHAR2) IS
11553
11554 BEGIN
11555
11556 pa_cc_utils.set_curr_function('ap_funds_check');
11557
11558 IF PG_DEBUG = 'Y' THEN
11559 pa_debug.G_err_stage := 'Inside AP_Funds_Check';
11560 log_message('log_message: ' || pa_debug.G_err_Stage);
11561 log_message('log_message: Before calling insert_ap_bc_packets api');
11562 END IF;
11563
11564 insert_ap_bc_packets( p_packet_id => p_packet_id,
11565 p_sys_ref2 => p_sys_ref2,
11566 p_sys_ref4 => NULL,
11567 p_sys_ref5 => p_sys_ref5,
11568 p_acct_raw_cost => p_acct_raw_cost,
11569 p_acct_bur_cost => 0,
11570 p_fc_document_type => p_fc_document_type ,
11571 p_txn_source => p_txn_source ,
11572 p_adj_exp_item_id => p_adj_exp_item_id ,
11573 p_txn_interface_id => p_txn_interface_id);
11574
11575 IF PG_DEBUG = 'Y' THEN
11576 log_message('log_message: ' || 'Returning from ap funds check');
11577 END IF;
11578
11579 -- set the return status to success
11580 x_return_status := FND_API.G_RET_STS_SUCCESS;
11581
11582 pa_cc_utils.reset_curr_function;
11583
11584 EXCEPTION
11585 --Bug 2672772: Handle the NDF exception,
11586 --raise the error here but not in tr_import_funds_check
11587 WHEN NO_DATA_FOUND THEN
11588 IF PG_DEBUG = 'Y' THEN
11589 log_message('log_message: ' || sqlerrm||' In NDF: Returning from ap funds check');
11590 END IF;
11591 --Call FC packets update API to update packets to T.
11592 --moved to tr_import_funds_check
11593 --Upd_PktSts(p_packet_id => p_packet_id);
11594
11595 x_return_status := fnd_api.g_ret_sts_error;
11596 x_error_message_code := 'PA_FC_NDF';
11597
11598 pa_cc_utils.reset_curr_function;
11599 RAISE;
11600
11601
11602 WHEN OTHERS THEN
11603 IF PG_DEBUG = 'Y' THEN
11604 log_message('log_message: ' || sqlerrm||' Returning from ap funds check');
11605 END IF;
11606 x_return_status := fnd_api.g_ret_sts_unexp_error;
11607 pa_cc_utils.reset_curr_function;
11608 RAISE;
11609 END ap_funds_check;
11610
11611 PROCEDURE po_funds_check (
11612 p_txn_source IN VARCHAR2,
11613 p_acct_raw_cost IN NUMBER,
11614 p_packet_id IN NUMBER,
11615 p_sys_ref2 IN NUMBER,
11616 p_sys_ref3 IN NUMBER,
11617 p_sys_ref4 IN NUMBER, -- Bug 5530897
11618 p_adj_exp_item_id IN NUMBER, --REL12
11619 p_txn_interface_id IN NUMBER, --REL12
11620 p_fc_document_type IN VARCHAR2, --REL12
11621 x_error_message_code OUT NOCOPY VARCHAR2,
11622 x_error_stage OUT NOCOPY VARCHAR2,
11623 x_return_status OUT NOCOPY VARCHAR2) IS
11624
11625 --PA.M QV and AV
11626 l_rev_acct_raw_cost Number;
11627 l_rev_acct_cost_temp Number; -- Bug 5731450
11628 l_sum_amt Number;
11629 l_cmt_rate Number; -- Bug 5731450
11630 l_act_rate Number; -- Bug 5731450
11631
11632 /* Bug 5731450 : Added the cursor to get the exchange rate for the actuals. */
11633 cursor c_acct_exchange_rate is
11634 select acct_exchange_rate
11635 from pa_transaction_interface_all
11636 where txn_interface_id = p_txn_interface_id;
11637
11638 Procedure GetCommSummAmt(p_sys_ref2 In Number,
11639 p_sys_ref3 In Number,
11640 x_sum_amt Out NOCOPY Number,
11641 x_rate Out NOCOPY Number -- Bug 5731450 : Added a new parameter x_rate.
11642 ) Is
11643 l_pkt_summ number;
11644 l_com_summ number;
11645 l_pkt_rate number; -- Bug 5731450
11646 l_com_rate number; -- Bug 5731450
11647
11648 Begin
11649
11650 /* Bug 5731450 : The following two select statements are modified to also fetch the PO exchange rate. */
11651
11652 select sum(nvl(accounted_dr,0)-nvl(accounted_cr,0)),SUM(POD.rate)/SUM(1)
11653 into l_pkt_summ,l_pkt_rate
11654 from pa_bc_packets bcc,
11655 po_distributions pod --Added for Bug#3693974
11656 where pod.po_header_id = p_sys_ref2
11657 and pod.po_distribution_id = p_sys_ref3
11658 and ((
11659 bcc.document_type = 'PO'
11660 and pod.po_distribution_id = bcc.document_distribution_id
11661 and pod.po_header_id = bcc.document_header_id
11662 )
11663 or
11664 (
11665 bcc.document_type = 'CC_C_PAY'
11666 -- 4456442, 4221848
11667 -- Bug : PQE:R12: PAAPIMP_SI: ORA-01722 IN PO_FUNDS_CHECK AND ORA-01400
11668 and pod.req_header_reference_num = to_char(bcc.document_header_id)
11669 and pod.req_line_reference_num = to_char(bcc.document_distribution_id)
11670 )
11671 )
11672 and (
11673 (bcc.Status_Code in('A','C'))
11674 or
11675 (bcc.Status_Code = 'P' and bcc.request_id = G_Request_Id)
11676 )
11677 and bcc.Parent_Bc_Packet_Id is NULL;
11678
11679 select sum(nvl(accounted_dr,0)-nvl(accounted_cr,0)),SUM(POD.rate)/SUM(1)
11680 into l_com_summ,l_com_rate
11681 from pa_bc_commitments bcc,
11682 po_distributions pod --Added for Bug#3693974
11683 where pod.po_header_id = p_sys_ref2
11684 and pod.po_distribution_id = p_sys_ref3
11685 and ((
11686 bcc.document_type = 'PO'
11687 and pod.po_distribution_id = bcc.document_distribution_id
11688 and pod.po_header_id = bcc.document_header_id
11689 )
11690 or
11691 (
11692 bcc.document_type = 'CC_C_PAY'
11693 -- 4456442, 4221848
11694 -- Bug : PQE:R12: PAAPIMP_SI: ORA-01722 IN PO_FUNDS_CHECK AND ORA-01400
11695 and pod.req_header_reference_num = to_char(bcc.document_header_id)
11696 and pod.req_line_reference_num = to_char(bcc.document_distribution_id)
11697 )
11698 )
11699 and bcc.Parent_Bc_Packet_Id is NULL;
11700
11701 x_sum_amt := nvl(l_pkt_summ,0) + nvl(l_com_summ,0) ;
11702 x_rate := COALESCE(l_pkt_rate,l_com_rate); -- Bug 5731450
11703
11704 Exception
11705 When Others Then
11706 Raise;
11707
11708 End GetCommSummAmt;
11709
11710 BEGIN
11711
11712 pa_cc_utils.set_curr_function('po_funds_check');
11713
11714 IF PG_DEBUG = 'Y' THEN
11715 pa_debug.G_err_stage := 'Inside PO_Funds_Check';
11716 log_message('log_message: ' || pa_debug.G_err_Stage);
11717 log_message('log_message: Before Calling GetCommSummAmt api');
11718 END IF;
11719
11720 -- Bug 4346519 : Receipt Returns ( i.e. -ve amt getting interfaced to projects) should reserve the cmt costs that are getting
11721 -- interfaced without any manipulations.Below logic should get fired only if commitment is being relieved
11722 -- (+ve amt getting interfaced to projects) then we should not be relieving more than the reserved amount.
11723
11724 --PA.M QV and AV
11725 GetCommSummAmt (p_sys_ref2 => p_sys_ref2,
11726 p_sys_ref3 => p_sys_ref3,
11727 x_sum_amt => l_sum_amt,
11728 x_rate => l_cmt_rate);
11729
11730 IF PG_DEBUG = 'Y' THEN
11731 log_message('log_message: After Calling GetCommSummAmt api and l_sum_amt = ' || l_sum_amt || ' p_acct_raw_cost = '|| p_acct_raw_cost);
11732 END IF;
11733
11734 --If commitment is liquidated completely then for the current record,
11735 --relieve 0 amount (l_rev_acct_raw_cost=0)
11736 /* Bug 5731450 : Derive the actual exchange rate only if the commitment exchange rate is not null. */
11737 If l_cmt_rate IS NOT NULL then
11738 open c_acct_exchange_rate;
11739 fetch c_acct_exchange_rate into l_act_rate;
11740 close c_acct_exchange_rate;
11741 end if;
11742
11743 IF PG_DEBUG = 'Y' THEN
11744 log_message('log_message: l_cmt_rate = ' || l_cmt_rate || ' l_act_rate = '|| l_act_rate);
11745 END IF;
11746
11747 /* Bug 5731450 : If the exchange rate for the PO commitment and the actuals are different then
11748 the commitment relieving is done using PO exchange rate. */
11749 If nvl(l_cmt_rate,1) <> nvl(l_act_rate,1) then
11750 l_rev_acct_cost_temp := nvl(p_acct_raw_cost,0)/nvl(l_act_rate,1)*nvl(l_cmt_rate,1);
11751 else
11752 l_rev_acct_cost_temp := nvl(p_acct_raw_cost,0);
11753 end If;
11754
11755 IF NVL(p_acct_raw_cost,0) > 0 THEN
11756
11757 if nvl(l_sum_amt,0) = 0 then
11758 if nvl(p_acct_raw_cost,0) < nvl(l_sum_amt,0) then /* added for bug:7326188 */
11759 l_rev_acct_raw_cost := nvl(p_acct_raw_cost,0);
11760 else
11761 l_rev_acct_raw_cost := 0;
11762 end if;
11763 else
11764 if l_rev_acct_cost_temp > nvl(l_sum_amt,0) then -- Bug 5731450
11765 l_rev_acct_raw_cost := nvl(l_sum_amt,0);
11766 else
11767 l_rev_acct_raw_cost := l_rev_acct_cost_temp; -- Bug 5731450
11768 end if;
11769 end if;
11770
11771 ELSE -- Bug 4346519
11772
11773 l_rev_acct_raw_cost := l_rev_acct_cost_temp; -- Bug 5731450
11774
11775 END IF;
11776
11777 IF PG_DEBUG = 'Y' THEN
11778 pa_debug.G_err_stage := 'Before Calling insert_po_bc_packets';
11779 log_message('log_message: ' || pa_debug.G_err_Stage);
11780 END IF;
11781
11782 insert_po_bc_packets (p_packet_id => p_packet_id ,
11783 p_sys_ref2 => p_sys_ref2 ,
11784 p_sys_ref4 => p_sys_ref4, -- Bug 5530897
11785 p_sys_ref3 => p_sys_ref3 ,
11786 p_acct_raw_cost => p_acct_raw_cost,
11787 p_cmt_raw_cost => l_rev_acct_raw_cost,
11788 p_fc_document_type => p_fc_document_type,
11789 p_txn_source => p_txn_source ,
11790 p_adj_exp_item_id => p_adj_exp_item_id,
11791 p_txn_interface_id => p_txn_interface_id);
11792
11793 IF PG_DEBUG = 'Y' THEN
11794 pa_debug.G_err_stage := 'After Calling insert_po_bc_packets';
11795 log_message('log_message: ' || pa_debug.G_err_Stage);
11796 END IF;
11797
11798 IF PG_DEBUG = 'Y' THEN
11799 log_message('log_message: ' || 'Returning from po funds check');
11800 END IF;
11801
11802 -- set the return status to success
11803 x_return_status := FND_API.G_RET_STS_SUCCESS;
11804
11805 pa_cc_utils.reset_curr_function;
11806
11807 EXCEPTION
11808 --Bug 2672772: Handle the NDF exception,
11809 --raise the error here but not in tr_import_funds_check
11810 WHEN NO_DATA_FOUND THEN
11811 IF PG_DEBUG = 'Y' THEN
11812 log_message('log_message: ' || sqlerrm||' In NDF: Returning from po funds check');
11813 END IF;
11814 --Call FC packets update API to update packets to T.
11815 --moved to tr_import_funds_check
11816 --Upd_PktSts(p_packet_id => p_packet_id);
11817
11818 x_return_status := fnd_api.g_ret_sts_error;
11819 x_error_message_code := 'PA_FC_NDF';
11820
11821 pa_cc_utils.reset_curr_function;
11822 RAISE;
11823
11824 WHEN OTHERS THEN
11825 IF PG_DEBUG = 'Y' THEN
11826 log_message('log_message: ' || sqlerrm||' Returning from po funds check');
11827 END IF;
11828 x_return_status := fnd_api.g_ret_sts_unexp_error;
11829 pa_cc_utils.reset_curr_function;
11830 RAISE;
11831 END po_funds_check;
11832
11833 PROCEDURE ap_po_funds_check (
11834 p_txn_source IN VARCHAR2,
11835 p_acct_raw_cost IN NUMBER,
11836 p_packet_id IN NUMBER,
11837 p_po_hdr_id IN NUMBER,
11838 p_po_dist_id IN NUMBER,
11839 p_inv_id IN NUMBER,
11840 p_inv_dist_id IN NUMBER, --REL12
11841 p_dist_line IN NUMBER, --REL12
11842 p_adj_exp_item_id IN NUMBER, --REL12
11843 p_txn_interface_id IN NUMBER, --REL12
11844 p_fc_document_type IN VARCHAR2, --REL12
11845 p_base_qty_var_amt IN NUMBER,
11846 p_base_amt_var_amt IN NUMBER,
11847 x_error_message_code OUT NOCOPY VARCHAR2,
11848 x_error_stage OUT NOCOPY VARCHAR2,
11849 x_return_status OUT NOCOPY VARCHAR2) IS
11850
11851 BEGIN
11852
11853 pa_cc_utils.set_curr_function('ap_po_funds_check');
11854
11855 IF PG_DEBUG = 'Y' THEN
11856 pa_debug.G_err_stage := 'Inside ap_po_Funds_Check';
11857 log_message('log_message: ' || pa_debug.G_err_Stage);
11858 END IF;
11859
11860 IF PG_DEBUG = 'Y' THEN
11861 pa_debug.G_err_stage := 'Start funds check packet insert for AP records that accrue on receipt';
11862 log_message('log_message: ' || pa_debug.G_err_Stage);
11863 END IF;
11864
11865 IF PG_DEBUG = 'Y' THEN
11866 pa_debug.G_err_stage := 'Call po_funds_check to reverse out the PO commitment';
11867 log_message('log_message: ' || pa_debug.G_err_Stage);
11868 END IF;
11869
11870 po_funds_check (
11871 p_txn_source => p_txn_source,
11872 p_acct_raw_cost => p_acct_raw_cost,
11873 p_packet_id => p_packet_id,
11874 p_sys_ref2 => p_po_hdr_id,
11875 p_sys_ref3 => p_po_dist_id,
11876 p_sys_ref4 => TO_NUMBER(NULL), --Bug 5550268
11877 p_adj_exp_item_id => p_adj_exp_item_id, --REL12
11878 p_txn_interface_id => p_txn_interface_id, --REL12
11879 p_fc_document_type => p_fc_document_type, --REL12
11880 x_error_message_code => x_error_message_code,
11881 x_error_stage => x_error_stage,
11882 x_return_status => x_return_status);
11883
11884 IF PG_DEBUG = 'Y' THEN
11885 pa_debug.G_err_stage := 'After calling po_funds_check api';
11886 log_message('log_message: ' || pa_debug.G_err_Stage);
11887 log_message('log_message: Value of p_base_qty_var_amt= '||p_base_qty_var_amt);
11888 log_message('log_message: Value of p_base_amt_var_amt= '||p_base_amt_var_amt);
11889 END IF;
11890
11891 /* Deleted code for IPV and ERV as these will be interfaced as seperate EXP's
11892 in REL12 */
11893
11894 /* Replaced ap_funds_check calls for QV and AV with one call to ap_funds_check
11895 .In insert_ap_bc_packets procedure logic is introduced to relieve all the varaince/invoice
11896 amounts associated with invoice distribution */
11897
11898 IF NVL(p_base_qty_var_amt,0) <> 0 THEN
11899
11900 IF PG_DEBUG = 'Y' THEN
11901 pa_debug.G_err_stage := 'Call ap_funds_check to reverse out the ap p_base_qty_var_amt = '||p_base_qty_var_amt;
11902 log_message('log_message: ' || pa_debug.G_err_Stage);
11903 END IF;
11904
11905 ap_funds_check (
11906 p_txn_source => 'AP VARIANCE',
11907 p_acct_raw_cost => p_base_qty_var_amt,
11908 p_packet_id => P_packet_id,
11909 p_sys_ref2 => g_cdl_system_reference2,
11910 p_sys_ref3 => g_cdl_system_reference3,
11911 p_sys_ref5 => g_cdl_system_reference5, --REL12
11912 p_adj_exp_item_id => p_adj_exp_item_id, --REL12
11913 p_txn_interface_id => p_txn_interface_id, --REL12
11914 p_fc_document_type => p_fc_document_type, --REL12
11915 x_error_message_code => x_error_message_code,
11916 x_error_stage => x_error_stage,
11917 x_return_status => x_return_status);
11918
11919 IF PG_DEBUG = 'Y' THEN
11920 pa_debug.G_err_stage := 'After calling ap_funds_check api';
11921 log_message('log_message: ' || pa_debug.G_err_Stage);
11922 END IF;
11923 END IF; --IF NVL(p_base_qty_var_amt,0) <> 0 THEN
11924
11925
11926 IF NVL(p_base_amt_var_amt,0) <> 0 THEN
11927
11928 IF PG_DEBUG = 'Y' THEN
11929 pa_debug.G_err_stage := 'Call ap_funds_check to reverse out the ap p_base_amt_var_amt = '||p_base_amt_var_amt;
11930 log_message('log_message: ' || pa_debug.G_err_Stage);
11931 END IF;
11932
11933 ap_funds_check (
11934 p_txn_source => 'AP VARIANCE',
11935 p_acct_raw_cost => p_base_amt_var_amt,
11936 p_packet_id => P_packet_id,
11937 p_sys_ref2 => g_cdl_system_reference2,
11938 p_sys_ref3 => g_cdl_system_reference3,
11939 p_sys_ref5 => g_cdl_system_reference5, --REL12
11940 p_adj_exp_item_id => p_adj_exp_item_id, --REL12
11941 p_txn_interface_id => p_txn_interface_id, --REL12
11942 p_fc_document_type => p_fc_document_type, --REL12
11943 x_error_message_code => x_error_message_code,
11944 x_error_stage => x_error_stage,
11945 x_return_status => x_return_status);
11946
11947 IF PG_DEBUG = 'Y' THEN
11948 pa_debug.G_err_stage := 'After calling ap_funds_check api';
11949 log_message('log_message: ' || pa_debug.G_err_Stage);
11950 END IF;
11951
11952 END IF; --IF NVL(p_base_amt_var_amt,0) <> 0 THEN
11953
11954 IF PG_DEBUG = 'Y' THEN
11955 log_message('log_message: ' || 'Returning from ap_po funds check');
11956 END IF;
11957
11958 -- set the return status to success
11959 x_return_status := FND_API.G_RET_STS_SUCCESS;
11960
11961 pa_cc_utils.reset_curr_function;
11962
11963 EXCEPTION
11964 WHEN OTHERS THEN
11965 IF PG_DEBUG = 'Y' THEN
11966 log_message('log_message: ' || sqlerrm||' Returning from ap po funds check');
11967 END IF;
11968 x_return_status := fnd_api.g_ret_sts_unexp_error;
11969 pa_cc_utils.reset_curr_function;
11970 RAISE;
11971 END ap_po_funds_check;
11972
11973 PROCEDURE Upd_PktSts_Fatal(p_request_id in number) IS
11974
11975 PRAGMA AUTONOMOUS_TRANSACTION;
11976
11977 BEGIN
11978
11979 IF PG_DEBUG = 'Y' THEN
11980 log_message('log_message: ' || 'Inside Upd_PktSts_Fatal');
11981 END IF;
11982
11983 update pa_bc_packets
11984 set status_code = 'T',
11985 result_code = 'F140'
11986 where status_code = 'P'
11987 and request_id = P_REQUEST_ID;
11988
11989 IF PG_DEBUG = 'Y' THEN
11990 log_message('log_message: ' || 'Updated ' || SQL%ROWCOUNT || ' packet statuses to T');
11991 END IF;
11992
11993 commit;
11994
11995 EXCEPTION
11996
11997 WHEN OTHERS THEN
11998 --Bug 2672772
11999 rollback;
12000 IF PG_DEBUG = 'Y' THEN -- Printed for 3592289
12001 log_message('log_message: In others of UpdPktsts_Fatal');
12002 END IF;
12003 raise;
12004
12005 END Upd_PktSts_Fatal;
12006
12007 --Bug 2672772 : Added the below procedure to update the packet status to T
12008 --if NDF error occurs in ap_funds_check and po_funds_check
12009 PROCEDURE Upd_PktSts(p_packet_id in number) IS
12010
12011 --PRAGMA AUTONOMOUS_TRANSACTION;
12012
12013 BEGIN
12014
12015 IF PG_DEBUG = 'Y' THEN
12016 log_message('log_message: ' || 'Inside Upd_PktSts,packet_id = '|| p_packet_id);
12017 END IF;
12018
12019 update pa_bc_packets
12020 set status_code = 'T',
12021 result_code = 'F140'
12022 where status_code = 'P'
12023 --Bug 3592289 changed p_packet_id to packet_id
12024 --and p_packet_id = p_packet_id;
12025 and packet_id = p_packet_id;
12026
12027 IF PG_DEBUG = 'Y' THEN
12028 log_message('log_message: ' || 'Updated ' || SQL%ROWCOUNT || ' packet statuses to T');
12029 END IF;
12030
12031 --commit;
12032
12033 EXCEPTION
12034
12035 WHEN OTHERS THEN
12036 --Bug 2672772
12037 --rollback;
12038 IF PG_DEBUG = 'Y' THEN -- Added 3 lines for 3592289
12039 log_message('log_message: In others of UpdPktsts');
12040 END IF;
12041 raise;
12042
12043 END Upd_PktSts;
12044
12045 PROCEDURE ValidateItemOTL(
12046 X_trx_src IN VARCHAR2
12047 , X_ei_date IN DATE
12048 , X_etype IN VARCHAR2
12049 , X_nlr IN VARCHAR2
12050 , X_qty IN NUMBER
12051 , X_denom_raw_cost IN NUMBER
12052 , X_module IN VARCHAR2
12053 , X_trx_ref IN VARCHAR2
12054 , X_match_flag IN VARCHAR2
12055 , X_att_cat IN VARCHAR2
12056 , X_att1 IN OUT NOCOPY VARCHAR2
12057 , X_att2 IN OUT NOCOPY VARCHAR2
12058 , X_att3 IN OUT NOCOPY VARCHAR2
12059 , X_att4 IN OUT NOCOPY VARCHAR2
12060 , X_att5 IN OUT NOCOPY VARCHAR2
12061 , X_att6 IN OUT NOCOPY VARCHAR2
12062 , X_att7 IN OUT NOCOPY VARCHAR2
12063 , X_att8 IN OUT NOCOPY VARCHAR2
12064 , X_att9 IN OUT NOCOPY VARCHAR2
12065 , X_att10 IN OUT NOCOPY VARCHAR2
12066 , X_system_linkage IN VARCHAR2
12067 , X_status OUT NOCOPY VARCHAR2
12068 --, X_bill_flag OUT NOCOPY VARCHAR2
12069 , X_denom_currency_code IN OUT NOCOPY VARCHAR2
12070 , X_acct_rate_date IN OUT NOCOPY DATE
12071 , X_acct_rate_type IN OUT NOCOPY VARCHAR2
12072 , X_acct_exchange_rate IN OUT NOCOPY NUMBER
12073 , X_acct_raw_cost IN NUMBER
12074 , X_project_currency_code IN OUT NOCOPY VARCHAR2
12075 , X_Projfunc_currency_code IN OUT NOCOPY VARCHAR2
12076 , X_Projfunc_cost_rate_date IN OUT NOCOPY DATE
12077 , X_Projfunc_cost_rate_type IN OUT NOCOPY VARCHAR2
12078 , X_Projfunc_cost_exchange_rate IN OUT NOCOPY VARCHAR2
12079 , X_Assignment_Name IN OUT NOCOPY VARCHAR2
12080 , X_Work_Type_Name IN OUT NOCOPY VARCHAR2
12081 , P_project_id IN NUMBER
12082 , P_task_id IN NUMBER
12083 , P_person_id IN NUMBER
12084 , P_organization_id IN NUMBER
12085 , P_assignment_id IN NUMBER
12086 , P_work_type_id IN NUMBER
12087 , P_Emp_Org_Id IN NUMBER
12088 , P_Emp_Job_Id IN NUMBER
12089 , P_po_header_id IN NUMBER
12090 , P_po_line_id IN NUMBER
12091 , P_person_type IN VARCHAR2
12092 , P_po_price_type IN VARCHAR2
12093 , p_vendor_id In Number /* Bug# 3601024 : Vendor ID is not passed to the PA_EXPENDITURE_ITEMS_ALL.VENDOR_ID in OTL timecards */
12094 , p_location_id IN NUMBER
12095 , p_cbs_element_id IN NUMBER DEFAULT NULL -- Added for bug 16592018
12096 )
12097 IS
12098
12099 temp_status VARCHAR2(30) DEFAULT NULL;
12100 temp_bill_flag VARCHAR2(1) DEFAULT NULL;
12101 temp_msg_application VARCHAR2(50) := 'PA';
12102 temp_msg_type VARCHAR2(1) := 'E';
12103 temp_msg_token1 VARCHAR2(2000) := '';
12104 temp_msg_token2 VARCHAR2(2000) :='';
12105 temp_msg_token3 VARCHAR2(2000) :='';
12106 temp_msg_count NUMBER :=1;
12107
12108 dummy NUMBER DEFAULT NULL;
12109
12110 l_project_rate_type VARCHAR2(30) := NULL;
12111
12112 l_projfunc_cost_rate_type VARCHAR2(30) := NULL;
12113 l_asgn_work_ret_sts VARCHAR2(1);
12114 l_asgn_work_err_msg VARCHAR2(1000);
12115 l_temp_g_assignment_id number := null; -- bug 5297060
12116
12117 BEGIN
12118 pa_cc_utils.set_curr_function('ValidateItemOTL');
12119
12120
12121 G_adj_item_id := NULL;
12122 G_job_id := NULL;
12123
12124
12125 X_status := NULL;
12126
12127 G_project_id := P_Project_Id;
12128 G_task_id := P_Task_Id;
12129 G_Person_Id := P_Person_Id;
12130
12131 G_Org_Id := P_Emp_Org_Id;
12132
12133 G_Vendor_Id := P_Vendor_ID; /* Bug# 3601024 : Vendor ID is not passed to the PA_EXPENDITURE_ITEMS_ALL.VENDOR_ID in OTL timecards */
12134
12135 /*S.N. 5297060*/
12136 IF X_match_flag = 'N' THEN
12137
12138 G_Assignment_Id := P_Assignment_Id;
12139 G_Work_Type_Id := P_Work_Type_Id;
12140
12141 G_Tp_Amt_Type_Code := pa_utils4.get_tp_amt_type_code(p_work_type_id => p_work_type_id);
12142
12143 END IF;
12144
12145 IF PG_DEBUG = 'Y' THEN
12146 log_message('log_message: G_Assignment_Id' ||G_Assignment_Id);
12147 log_message('log_message: G_Work_Type_Id' ||G_Work_Type_Id);
12148 log_message('log_message: G_Tp_Amt_Type_Code' ||G_Tp_Amt_Type_Code);
12149 END IF;
12150
12151 /*E.N. 5297060*/
12152
12153 IF ( G_Org_Id IS NULL ) THEN
12154 IF PG_DEBUG = 'Y' THEN
12155 pa_debug.G_err_Stage := 'P_Emp_Org_Id is null';
12156 log_message('log_message: ' || pa_debug.G_err_Stage);
12157 END IF;
12158 X_status := 'NO_ASSIGNMENT';
12159 pa_cc_utils.reset_curr_function;
12160 RETURN;
12161 END IF;
12162
12163 IF (G_accounting_currency_code IS NULL) THEN
12164 GetImpCurrInfo;
12165 END IF;
12166
12167 G_job_id := P_Emp_Job_Id;
12168
12169 IF ( G_job_id IS NULL ) THEN
12170 X_status := 'NO_ASSIGNMENT';
12171 pa_cc_utils.reset_curr_function;
12172 RETURN;
12173 END IF;
12174
12175 IF ( X_denom_currency_code IS NULL ) THEN
12176
12177 X_denom_currency_code := G_accounting_currency_code;
12178
12179 END IF;
12180
12181 IF PG_DEBUG = 'Y' THEN
12182 pa_debug.G_err_stage := 'Calling GetProjCurrInfo';
12183 log_message('log_message: ' || pa_debug.G_err_Stage);
12184 END IF;
12185
12186 GetProjCurrInfo(G_task_id,
12187 X_project_currency_code,
12188 l_project_rate_type,
12189 X_projfunc_currency_code,
12190 l_projfunc_cost_rate_type);
12191
12192 IF ( X_project_currency_code IS NULL ) THEN
12193
12194 X_status := 'PA_MISSING_PROJ_CURR';
12195 pa_cc_utils.reset_curr_function;
12196 RETURN;
12197
12198 END IF;
12199
12200 IF ( X_projfunc_currency_code IS NULL ) THEN
12201
12202 X_status := 'PA_MISSING_PRJFUNC_CURR';
12203 pa_cc_utils.reset_curr_function;
12204 RETURN;
12205
12206 END IF;
12207
12208 /* Added the call to GetProjTypeInfo for getting the project type class for
12209 * bug#4903329 */
12210 IF PG_DEBUG = 'Y' THEN
12211 pa_debug.G_err_stage := 'Calling GetProjTypeInfo';
12212 log_message('log_message: ' || pa_debug.G_err_Stage);
12213 END IF;
12214
12215
12216 GetProjTypeInfo( G_project_id,
12217 G_Proj_bcost_flag,
12218 G_project_type_class,
12219 G_burden_amt_display_method,
12220 G_Total_Burden_Flag ) ;
12221 /* Ends changes for bug#4903329 */
12222
12223 -- ===========================================================================
12224 -- Verify that the transaction has not already been loaded into PA (no
12225 -- other expenditure items exist having the same TRANSACTION SOURCE and
12226 -- ORIG TRANSACTION REFERENCE)
12227
12228 IF G_allow_dup_flag <> 'Y' THEN
12229
12230 IF PG_DEBUG = 'Y' THEN
12231 pa_debug.G_err_stage := 'Calling CheckDupItem';
12232 log_message('log_message: ' || pa_debug.G_err_Stage);
12233 END IF;
12234 CheckDupItem ( X_trx_src, X_trx_ref, temp_status );
12235 IF ( temp_status IS NOT NULL ) THEN
12236 X_status := temp_status;
12237 pa_cc_utils.reset_curr_function;
12238 RETURN;
12239 END IF;
12240
12241 END IF ;
12242
12243 -- ===========================================================================
12244 -- Oracle Time and Labor(OTL)requires the ability to reverse an ei with a quantity = 0
12245 -- so only for OTL that option has been added.
12246 --
12247 IF ( ( X_qty < 0 and X_match_flag = 'N' ) OR
12248 ( X_match_flag = 'N' and X_trx_src = 'ORACLE TIME AND LABOR' ) ) THEN
12249 IF PG_DEBUG = 'Y' THEN
12250 pa_debug.G_err_stage := 'Calling pa_adjustments.VerifyOrigItem';
12251 log_message('log_message: ' || pa_debug.G_err_Stage);
12252 END IF;
12253 G_adj_item_id := pa_adjustments.VerifyOrigItem(
12254 X_person_id => G_person_id
12255 , X_org_id => G_org_id
12256 , X_item_date => X_ei_date
12257 , X_task_id => G_task_id
12258 , X_exp_type => X_etype
12259 , X_system_linkage_function => X_system_linkage
12260 , X_nl_org_id => NULL
12261 , X_nl_resource => X_nlr
12262 , X_quantity => X_qty
12263 , X_denom_raw_cost => X_denom_raw_cost
12264 , X_trx_source => X_trx_src
12265 , X_denom_currency_code => X_denom_currency_code
12266 , X_acct_raw_cost => X_acct_raw_cost
12267 , X_reversed_orig_txn_reference => G_reversed_orig_txn_reference
12268 , X_cbs_element_id => p_cbs_element_id -- Added for bug 16592018
12269 );
12270
12271 IF ( G_adj_item_id IS NULL ) THEN
12272
12273 X_status := 'NO_MATCHING_ITEM';
12274 pa_cc_utils.reset_curr_function;
12275 RETURN;
12276
12277 ELSIF ( G_adj_item_id IS NOT NULL AND X_module = 'PAXTRTRX' ) THEN
12278
12279 IF PG_DEBUG = 'Y' THEN
12280 pa_debug.G_err_stage := 'Calling pa_adjustments.ExpAdjItemTab';
12281 log_message('log_message: ' || pa_debug.G_err_Stage);
12282 END IF;
12283 pa_adjustments.ExpAdjItemTab(G_adj_item_id) := G_adj_item_id;
12284
12285 IF PG_DEBUG = 'Y' THEN
12286 pa_debug.G_err_stage := 'Locking adjusting item:'||to_char(G_adj_item_id);
12287 log_message('log_message: ' || pa_debug.G_err_Stage);
12288 END IF;
12289
12290 BEGIN
12291
12292 SELECT
12293 expenditure_item_id
12294 INTO
12295 dummy
12296 FROM
12297 pa_expenditure_items
12298 WHERE
12299 expenditure_item_id = G_adj_item_id
12300 FOR UPDATE NOWAIT;
12301
12302 EXCEPTION
12303 WHEN RESOURCE_BUSY THEN
12304 temp_status := 'CANNOT_LOCK_ORIG_ITEM';
12305 END;
12306 END IF;
12307
12308 IF ( temp_status IS NOT NULL ) THEN
12309 X_status := temp_status;
12310 pa_cc_utils.reset_curr_function;
12311 RETURN;
12312 END IF;
12313
12314 END IF;
12315
12316 IF PG_DEBUG = 'Y' THEN
12317 pa_debug.G_err_stage := 'Calling PA_UTILS2.GetPrjOrgId';
12318 log_message('log_message: ' || pa_debug.G_err_Stage);
12319 END IF;
12320 G_RecvrOrgId := PA_UTILS2.GetPrjOrgId(p_project_id => G_project_id,
12321 p_task_id => NULL);
12322
12323 IF PG_DEBUG = 'Y' THEN
12324 pa_debug.G_err_stage := 'Calling API to derive/validate assignment and work type info';
12325 log_message('log_message: ' || pa_debug.G_err_Stage);
12326 log_message('log_message: ' || 'Assignment Name = ' || X_Assignment_Name || ' Work Type Name = ' || X_Work_Type_Name);
12327 END IF;
12328
12329 /*S.N. 5297060*/
12330 If ( X_match_flag <> 'N' ) THEN
12331
12332 pa_utils4.get_work_assignment(
12333 p_person_id => G_Person_Id
12334 , p_project_id => G_Project_Id
12335 , p_task_id => G_Task_Id
12336 , p_ei_date => X_Ei_Date
12337 , p_system_linkage => x_system_linkage
12338 , x_assignment_id => G_Assignment_Id
12339 , x_assignment_name => X_Assignment_Name
12340 , x_work_type_id => G_Work_Type_Id
12341 , x_work_type_name => X_Work_Type_Name
12342 , x_tp_amt_type_code => G_Tp_Amt_Type_Code
12343 , x_return_status => l_asgn_work_ret_sts
12344 , x_error_message_code => l_asgn_work_err_msg);
12345
12346 IF PG_DEBUG = 'Y' THEN
12347 log_message('log_message: ' || 'Assignment Id = ' || G_Assignment_Id ||
12348 ' Work Type Id = ' || G_Work_Type_Id ||
12349 ' Tp Amt Type = ' || G_Tp_Amt_Type_Code);
12350 END IF;
12351
12352 IF (l_asgn_work_ret_sts <> FND_API.G_RET_STS_SUCCESS) THEN
12353
12354 IF PG_DEBUG = 'Y' THEN
12355 pa_debug.G_err_stage := 'Get Work Type and Assignment API failed';
12356 log_message('log_message: ' || pa_debug.G_err_Stage);
12357 log_message('log_message: ' || 'Ret Sts = ' || l_asgn_work_ret_sts || ' Error = ' || l_asgn_work_err_msg);
12358 END IF;
12359
12360 X_Status := l_asgn_work_err_msg;
12361 pa_cc_utils.reset_curr_function;
12362 RETURN;
12363
12364 END IF;
12365
12366 END IF; -- ( X_match_flag <> 'N' )
12367 /*E.N. 5297060*/
12368
12369 G_CrossChargeCode := 'P';
12370 G_BrowLentDistCode := 'X';
12371 G_IcProcessed_Code := 'X';
12372 l_temp_g_assignment_id := G_Assignment_Id; -- bug 5297060
12373
12374 IF PG_DEBUG = 'Y' THEN
12375 pa_debug.G_err_stage := 'Calling patc client extension for override to assignment id';
12376 log_message('log_message: ' || pa_debug.G_err_Stage);
12377 END IF;
12378
12379 patcx.tc_extension( X_project_id => g_project_id
12380 , X_task_id => g_task_id
12381 , X_expenditure_item_date => X_ei_date
12382 , X_expenditure_type => X_etype
12383 , X_non_labor_resource => X_nlr
12384 , X_incurred_by_person_id => g_person_id
12385 , X_quantity => X_qty
12386 , X_denom_currency_code => X_denom_currency_code
12387 , X_acct_currency_code => G_accounting_currency_code
12388 , X_denom_raw_cost => X_denom_raw_cost
12389 , X_acct_raw_cost => X_acct_raw_cost
12390 , X_acct_rate_type => X_acct_rate_type
12391 , X_acct_rate_date => X_acct_rate_date
12392 , X_acct_exchange_rate => X_acct_exchange_rate
12393 , X_transferred_from_id => NULL
12394 , X_incurred_by_org_id => G_org_id
12395 , X_nl_resource_org_id => NULL
12396 , X_transaction_source => X_trx_src
12397 , X_calling_module => X_module
12398 , X_vendor_id => NULL
12399 , X_entered_by_user_id => G_user
12400 , X_attribute_category => X_att_cat
12401 , X_attribute1 => X_att1
12402 , X_attribute2 => X_att2
12403 , X_attribute3 => X_att3
12404 , X_attribute4 => X_att4
12405 , X_attribute5 => X_att5
12406 , X_attribute6 => X_att6
12407 , X_attribute7 => X_att7
12408 , X_attribute8 => X_att8
12409 , X_attribute9 => X_att9
12410 , X_attribute10 => X_att10
12411 , X_attribute11 => NULL
12412 , X_attribute12 => NULL
12413 , X_attribute13 => NULL
12414 , X_attribute14 => NULL
12415 , X_attribute15 => NULL
12416 , X_msg_application => temp_msg_application
12417 , X_billable_flag => temp_bill_flag
12418 , X_msg_type => temp_msg_type
12419 , X_msg_token1 => temp_msg_token1
12420 , X_msg_token2 => temp_msg_token2
12421 , X_msg_token3 => temp_msg_token3
12422 , X_msg_count => temp_msg_count
12423 , X_outcome => temp_status
12424 , p_projfunc_currency_code => x_projfunc_currency_code
12425 , p_projfunc_cost_rate_type => x_projfunc_cost_rate_type
12426 , p_projfunc_cost_rate_date => x_projfunc_cost_rate_date
12427 , p_projfunc_cost_exchg_rate => X_Projfunc_cost_exchange_rate
12428 , x_assignment_id => G_ASSIGNMENT_ID
12429 , p_work_type_id => g_work_type_id
12430 , p_sys_link_function => x_system_linkage
12431 , p_po_header_id => p_po_header_id /* cwk */
12432 , p_po_line_id => p_po_line_id
12433 , p_person_type => p_person_type
12434 , p_po_price_type => p_po_price_type );
12435
12436 -- No change to Billable Flag here, use what is inserted into the interface table
12437 X_status := temp_status; -- Added for bug#6278593
12438 /*S.N. 5297060 The patcx extension parameter x_assignment_id is IN OUT so the value can change
12439 for assignment_id. To handle this we will use a dummy assigment id to hold the value
12440 and reset the value back if the transaction is a reversal. */
12441 If X_match_flag = 'N' Then
12442 G_assignment_id := l_temp_g_assignment_id;
12443 End If;
12444 /*E.N. 5297060*/
12445
12446 /* 12.2 payroll intg .. validate location and populate default assign location if not passed */
12447 if p_location_id is null then
12448 G_location_id := pa_utils.GetAsgnLocationId(p_person_id => G_Person_Id,
12449 p_ei_date => X_ei_date);
12450 else
12451 G_Location_Id := p_location_id;
12452 end if;
12453
12454 pa_cc_utils.reset_curr_function;
12455
12456 EXCEPTION
12457 WHEN OTHERS THEN
12458 IF PG_DEBUG = 'Y' THEN
12459 log_message('log_message: ' || pa_debug.G_err_Stack,1);
12460 log_message('log_message: ' || pa_debug.G_err_stage,1);
12461 log_message('log_message: ' || SQLERRM,1);
12462 END IF;
12463 pa_cc_utils.reset_curr_function;
12464 RAISE ;
12465 END ValidateItemOTL;
12466
12467 PROCEDURE Log_Message(p_message in VARCHAR2,
12468 p_mode in NUMBER DEFAULT 0) IS
12469 BEGIN
12470 If (G_Debug_Mode = 'Y') Then
12471
12472 pa_cc_utils.log_message(p_message,p_mode);
12473
12474 End If;
12475 END Log_Message;
12476
12477 PROCEDURE init_po_amt_chk IS
12478
12479 BEGIN
12480
12481 PoLineTaskTab.DELETE;
12482 PoAmtTab.DELETE;
12483
12484 END init_po_amt_chk;
12485
12486 PROCEDURE release_po_line_task_lock IS
12487 PRAGMA AUTONOMOUS_TRANSACTION;
12488 l_lock_status NUMBER := -1;
12489 BEGIN
12490
12491 IF PoLineTaskTab.COUNT > 0 THEN
12492 FOR i IN PoLineTaskTab.FIRST..PoLineTaskTab.LAST
12493 LOOP
12494 BEGIN
12495
12496 l_lock_status := -1;
12497 l_lock_status := Pa_Debug.Release_User_Lock(PoLineTaskTab(i));
12498
12499 IF (l_lock_status = 0) THEN
12500 IF PG_DEBUG = 'Y' THEN
12501 pa_debug.G_err_stage := 'RELEASE_PO_LINE_TASK_LOCK : Released Lock for : '||PoLineTaskTab(i);
12502 log_message('log_message: ' || pa_debug.G_err_stage,1);
12503 END IF;
12504 ELSE
12505 IF PG_DEBUG = 'Y' THEN
12506 pa_debug.G_err_stage := 'RELEASE_PO_LINE_TASK_LOCK : Failed To Release Lock for : '||PoLineTaskTab(i);
12507 log_message('log_message: ' || pa_debug.G_err_stage,1);
12508 END IF;
12509 END IF;
12510
12511 EXCEPTION
12512 WHEN OTHERS THEN
12513
12514 IF PG_DEBUG = 'Y' THEN
12515 pa_debug.G_err_stage := 'RELEASE_PO_LINE_TASK_LOCK : In Process of Releasing Locks : ' ||SQLERRM;
12516 log_message('log_message: ' || pa_debug.G_err_stage,1);
12517 END IF;
12518
12519 END ;
12520
12521 END LOOP;
12522
12523 END IF ;
12524
12525 END release_po_line_task_lock;
12526
12527 /*
12528 API Decs : Retrieving rate from PO for the PO_LINE_ID And PO_PRICE_TYPE for CWK related Time Card EIs.
12529 */
12530
12531 Function GET_PO_PRICE_TYPE_RATE (p_project_id In Number, p_task_id In Number, P_Po_Line_Id In Number, P_Price_Type In Varchar2) Return Number
12532 Is
12533
12534 x_po_rate NUMBER ;
12535 x_currency_code VARCHAR (15) ;
12536 x_curr_rate_type VARCHAR (30) ;
12537 x_curr_rate_date DATE ;
12538 x_currency_rate NUMBER ;
12539 x_vendor_id NUMBER ;
12540 x_return_status VARCHAR2(100) ;
12541 x_message_code VARCHAR2(100) ;
12542
12543 Begin
12544
12545
12546 PO_PA_INTEGRATION_GRP.get_line_rate_info( p_api_version => 1.0 ,
12547 p_price_type => p_price_type ,
12548 p_po_line_id => p_po_line_id ,
12549 p_project_id => p_project_id ,
12550 p_task_id => p_task_id ,
12551 x_po_rate => x_po_rate ,
12552 x_currency_code => x_currency_code ,
12553 x_curr_rate_type => x_curr_rate_type ,
12554 x_curr_rate_date => x_curr_rate_date ,
12555 x_currency_rate => x_currency_rate ,
12556 x_vendor_id => x_vendor_id ,
12557 x_return_status => x_return_status ,
12558 x_message_code => x_message_code
12559 );
12560
12561 Return ( x_po_rate );
12562
12563 End GET_PO_PRICE_TYPE_RATE ;
12564
12565 PROCEDURE ap_cash_based_funds_check (
12566 p_txn_source IN VARCHAR2,
12567 p_acct_raw_cost IN NUMBER,
12568 p_packet_id IN NUMBER,
12569 p_sys_ref2 IN NUMBER, --REL12
12570 p_sys_ref4 IN VARCHAR2, --REL12
12571 p_sys_ref5 IN NUMBER, --REL12
12572 p_adj_exp_item_id IN NUMBER, --REL12
12573 p_txn_interface_id IN NUMBER, --REL12
12574 p_fc_document_type IN VARCHAR2, --REL12
12575 x_error_message_code OUT NOCOPY VARCHAR2,
12576 x_error_stage OUT NOCOPY VARCHAR2,
12577 x_return_status OUT NOCOPY VARCHAR2) IS
12578
12579 l_raw_amount NUMBER;
12580
12581 Procedure GetCommSummAmt( p_ap_pkt_raw_amt OUT NOCOPY NUMBER) Is
12582
12583 l_pkt_summ NUMBER;
12584 l_com_summ NUMBER;
12585 l_ap_outstanding_raw NUMBER;
12586 l_pay_inv_dist_amt NUMBER;
12587 -- R12 AP lines uptake : Prepayment changes
12588 l_cmt_pkt_found VARCHAR2(1) := 'N';
12589 l_disc_amount NUMBER ;
12590
12591 -- Below cursors calcultes Raw and Burden outstanding amount associated with AP Invoice Distribution.
12592
12593 -- Fetch BC Pkt Raw outstanding amount
12594 CURSOR C_get_raw_pkt_amt IS
12595 select sum(nvl(accounted_dr,0)-nvl(accounted_cr,0))
12596 from pa_bc_packets bcc
12597 where bcc.document_type = 'AP'
12598 and bcc.document_header_id = p_sys_ref2
12599 and bcc.document_distribution_id = p_sys_ref5
12600 and ( (bcc.Status_Code in('A','C'))
12601 or
12602 (bcc.Status_Code = 'P' and bcc.request_id = G_Request_Id))
12603 and bcc.Parent_Bc_Packet_Id is NULL;
12604
12605 CURSOR C_get_raw_bccmt_amt IS
12606 select sum(nvl(accounted_dr,0)-nvl(accounted_cr,0))
12607 from pa_bc_commitments bcc
12608 where bcc.document_type = 'AP'
12609 and bcc.document_header_id = p_sys_ref2
12610 and bcc.document_distribution_id = p_sys_ref5
12611 and bcc.Parent_Bc_Packet_Id is NULL;
12612
12613 -- ====================================================================================
12614 --
12615 -- Bug : 4962731
12616 -- : R12.PJ:XB1:QA:BC:INCORRECT AMOUNTS INTERFACED TO PROJECTS IN CASH BASED ACC
12617 -- For payments, payment amount includes discount amount. So we are interfacing
12618 -- only payments. But we need to relieve corresponding invoice amount for that
12619 -- payment.
12620 -- Invoice dist amount :100
12621 -- Payment : 80
12622 -- Disc : 20
12623 -- Actual interface : 80
12624 -- AP Relieve : 80 + 20 = 100
12625 -- Functionality :
12626 -- Discount is applicable when discount method is EXPENSE
12627 -- Discount is applicable for tax distributions when discount method is TAX
12628 -- Discount is not applicable when discount method is 'SYSTEM'
12629 -- Discount is also based on the discount profile start date
12630 -- ap payment record includes the discount amount and we do not need to interface
12631 -- discount record because we are interfacing the payments.
12632 -- But we need to relieve corresponding inv dist amount paid to relieve the ap commitment amount.
12633 -- ap amount to relieve := payment amunt + discount amount (when applicable).
12634 -- ====================================================================================
12635 CURSOR c_get_disc_amount is
12636 SELECT NVL(b.invoice_dist_base_amount , b.invoice_dist_amount) amount
12637 from ap_payment_hist_dists b,
12638 ap_invoice_distributions_all apd
12639 where b.invoice_payment_id = p_sys_ref4
12640 and b.invoice_distribution_id = p_sys_ref5
12641 and b.pay_dist_lookup_code = 'DISCOUNT'
12642 and apd.invoice_distribution_id = b.invoice_distribution_id
12643 and NVL(apd.historical_flag,'N') <> 'Y'
12644 and apd.expenditure_item_date >=G_Profile_Discount_Start_date
12645 and apd.line_type_lookup_code = decode ( G_discount_Method,
12646 'TAX', decode (apd.line_type_lookup_code,
12647 'TIPV', 'TIPV',
12648 'TERV','TERV',
12649 'TRV', 'TRV',
12650 'NONREC_TAX') ,
12651 'SYSTEM', 'NOT APPLICABLE',
12652 apd.line_type_lookup_code ) ;
12653 -- AP Invoice dist amount to be relieved for payment with ERV
12654 CURSOR C_payment_erv_amount IS
12655 SELECT NVL(paydist.invoice_dist_base_amount,paydist.invoice_dist_amount)
12656 FROM ap_payment_hist_dists Paydist
12657 WHERE paydist.pay_dist_lookup_code = 'CASH'
12658 AND Paydist.invoice_distribution_id = p_sys_ref5
12659 AND PayDIST.invoice_payment_id = p_sys_ref4
12660 AND EXISTS
12661 (SELECT 1
12662 FROM ap_invoice_payments Pay,
12663 ap_invoices_all inv
12664 WHERE pay.invoice_payment_id = p_sys_ref4
12665 AND pay.invoice_id = inv.invoice_id
12666 AND NVL(pay.exchange_rate,0) <> NVL(inv.exchange_rate,0));
12667
12668 Begin
12669 -- Intializing Variables
12670 l_pkt_summ := 0;
12671 l_com_summ := 0;
12672 p_ap_pkt_raw_amt := 0;
12673 l_pay_inv_dist_amt := 0;
12674 l_disc_amount := 0 ;
12675
12676 -- Fetching applicable discount amount absed on the discount method and profile discount start date.
12677 --
12678 -- Bug : 4962731
12679 -- : R12.PJ:XB1:QA:BC:INCORRECT AMOUNTS INTERFACED TO PROJECTS IN CASH BASED ACC
12680 --
12681 OPEN c_get_disc_amount ;
12682 fetch c_get_disc_amount into l_disc_amount ;
12683 close c_get_disc_amount ;
12684 l_disc_amount := NVL(l_disc_amount,0) ;
12685
12686 -- Fetching outstanding AP Distribution Raw amount
12687 OPEN C_get_raw_pkt_amt ;
12688 FETCH C_get_raw_pkt_amt INTO l_pkt_summ;
12689 -- R12 AP lines uptake : Prepayment changes
12690 IF C_get_raw_pkt_amt%FOUND THEN
12691 l_cmt_pkt_found := 'Y';
12692 END IF;
12693 CLOSE C_get_raw_pkt_amt;
12694
12695 OPEN C_get_raw_bccmt_amt ;
12696 FETCH C_get_raw_bccmt_amt INTO l_com_summ;
12697 -- R12 AP lines uptake : Prepayment changes
12698 IF C_get_raw_bccmt_amt%FOUND THEN
12699 l_cmt_pkt_found := 'Y';
12700 END IF;
12701 CLOSE C_get_raw_bccmt_amt;
12702
12703 -- Calculating total Outstanding raw amount on AP dist
12704 l_ap_outstanding_raw := nvl(l_pkt_summ,0) + nvl(l_com_summ,0) ;
12705
12706 -- R12 AP lines uptake : Prepayment changes
12707 -- Donot relieve commitment amount for records which have no entry in bc_commitments/bc_packets .
12708 -- These records were not Fundschecked (eg : pre-payment application , pre-payment matched to PO ..)
12709
12710 IF l_cmt_pkt_found = 'N' THEN
12711
12712 p_ap_pkt_raw_amt := 0;
12713
12714 ELSIF l_cmt_pkt_found = 'Y' THEN
12715
12716 -- Below code populates l_pay_inv_dist_amt with AP raw amount to be relieved against payments having ERV .
12717 -- If no ERV for payment then l_pay_inv_dist_amt = p_acct_raw_cost
12718
12719 OPEN C_payment_erv_amount;
12720 FETCH C_payment_erv_amount INTO l_pay_inv_dist_amt;
12721 IF C_payment_erv_amount%NOTFOUND THEN
12722 l_pay_inv_dist_amt := P_acct_raw_cost;
12723 END IF;
12724 CLOSE C_payment_erv_amount;
12725
12726
12727 --
12728 -- Bug : 4962731
12729 -- : R12.PJ:XB1:QA:BC:INCORRECT AMOUNTS INTERFACED TO PROJECTS IN CASH BASED ACC
12730 --
12731 l_pay_inv_dist_amt := l_pay_inv_dist_amt + l_disc_amount ;
12732
12733 -- If final payment relieve outstanding amount .
12734 -- Note : For refund final payment zero outstanding amount will be reserved
12735 IF NVL(G_finalPaymentID,-99) = NVL(p_sys_ref4,-99) THEN
12736 p_ap_pkt_raw_amt := -1 * l_ap_outstanding_raw;
12737
12738 -- If postive payment and not a final payment then relieve MIN(outstanding amount,payment amount)
12739 ELSIF l_pay_inv_dist_amt >0 THEN
12740 IF l_pay_inv_dist_amt >= l_ap_outstanding_raw THEN
12741 p_ap_pkt_raw_amt := -1 * l_ap_outstanding_raw;
12742 ELSE
12743 p_ap_pkt_raw_amt := -1 * l_pay_inv_dist_amt;
12744 END IF;
12745
12746 -- If negative payment and not a final payment then reserve payment amount
12747 ELSIF l_pay_inv_dist_amt < 0 THEN
12748 p_ap_pkt_raw_amt := -1 * l_pay_inv_dist_amt;
12749 END IF;
12750
12751 END IF; --IF l_cmt_pkt_found = 'N' THEN
12752
12753 Exception
12754 When Others Then
12755 Raise;
12756
12757 End GetCommSummAmt;
12758
12759 BEGIN
12760
12761 pa_cc_utils.set_curr_function('ap_funds_check');
12762
12763 IF PG_DEBUG = 'Y' THEN
12764 pa_debug.G_err_stage := 'Inside AP_Funds_Check';
12765 log_message('log_message: ' || pa_debug.G_err_Stage);
12766 END IF;
12767
12768 -- Calling GetCommSummAmt to calculate AP distribution's raw and burden amount to be relieved/reserved.
12769 GetCommSummAmt(p_ap_pkt_raw_amt => l_raw_amount);
12770
12771 IF PG_DEBUG = 'Y' THEN
12772 pa_debug.G_err_stage := 'Before calling insert_cash_ap_bc_packets';
12773 log_message('log_message: ' || pa_debug.G_err_Stage);
12774 END IF;
12775
12776 insert_cash_ap_bc_packets( p_packet_id => p_packet_id,
12777 p_sys_ref2 => p_sys_ref2,
12778 p_sys_ref5 => p_sys_ref5,
12779 p_acct_raw_cost => p_acct_raw_cost,
12780 p_fc_document_type => p_fc_document_type ,
12781 p_txn_source => p_txn_source ,
12782 p_adj_exp_item_id => p_adj_exp_item_id,
12783 p_txn_interface_id => p_txn_interface_id,
12784 p_cash_pay_to_relieve => l_raw_amount );
12785
12786
12787 IF PG_DEBUG = 'Y' THEN
12788 log_message('log_message: ' || 'After calling insert_cash_ap_bc_packets');
12789 END IF;
12790
12791 -- set the return status to success
12792 x_return_status := FND_API.G_RET_STS_SUCCESS;
12793
12794 pa_cc_utils.reset_curr_function;
12795
12796 EXCEPTION
12797 --Bug 2672772: Handle the NDF exception,
12798 --raise the error here but not in tr_import_funds_check
12799 WHEN NO_DATA_FOUND THEN
12800 IF PG_DEBUG = 'Y' THEN
12801 log_message('log_message: ' || sqlerrm||' In NDF: Returning from ap funds check');
12802 END IF;
12803
12804 WHEN OTHERS THEN
12805 IF PG_DEBUG = 'Y' THEN
12806 log_message('log_message: ' || sqlerrm||' Returning from ap funds check');
12807 END IF;
12808 x_return_status := fnd_api.g_ret_sts_unexp_error;
12809 pa_cc_utils.reset_curr_function;
12810 RAISE;
12811 END ap_cash_based_funds_check;
12812
12813 -- R12 funds management Uptake : New procedure fired in non-autonomous mode to read
12814 -- pa_transaction_interface_all table and to derive variables which drives the
12815 -- relieving/reserving of commitments and actuals flow during interface.
12816
12817 PROCEDURE insert_ap_bc_packets(p_packet_id IN NUMBER,
12818 p_sys_ref2 IN NUMBER,
12819 p_sys_ref4 IN VARCHAR2,
12820 p_sys_ref5 IN NUMBER,
12821 p_acct_raw_cost IN NUMBER,
12822 p_acct_bur_cost IN NUMBER,
12823 p_fc_document_type IN VARCHAR2,
12824 p_txn_source IN VARCHAR2,
12825 p_adj_exp_item_id IN NUMBER,
12826 p_txn_interface_id IN NUMBER) IS
12827
12828 -- Cursor to fetch data from pa_transaction_interface_table.This data is later used
12829 -- in autonomous fundscheck insert_ap_bc_pkts_autonomous procedure.
12830
12831
12832 CURSOR c_pa_txn_interface_data (p_adj_act_fc_req VARCHAR2,
12833 p_act_fc_req VARCHAR2) IS
12834 Select txn.Project_Id
12835 ,txn.Task_Id
12836 ,txn.Expenditure_Type
12837 ,txn.Expenditure_Item_Date
12838 ,nvl(txn.OVERRIDE_TO_ORGANIZATION_ID,txn.Org_Id)
12839 ,bv.Budget_Version_Id
12840 -- R12 AP lines uptake : Prepayment changes
12841 -- For Prepayment application/pre-payment matched to PO records consider p_acct_raw_cost as amount
12842 ,DECODE(txn_interface_id,p_txn_interface_id, p_acct_raw_cost,txn.acct_raw_cost)
12843 ,0
12844 ,DECODE(txn_interface_id,p_txn_interface_id, p_acct_raw_cost,txn.acct_raw_cost)
12845 ,0
12846 ,txn.cr_code_combination_id
12847 ,txn.Org_id
12848 ,txn.txn_interface_id --REL12
12849 ,txn.vendor_id /*bug 13601768*/
12850 From Pa_Budget_Versions bv,
12851 Pa_Budget_Types bt,
12852 pa_budgetary_control_options pbct,
12853 pa_transaction_interface_all txn
12854 Where bv.budget_type_code = bt.budget_type_code
12855 and bt.budget_amount_code = 'C'
12856 and bv.current_flag = 'Y'
12857 AND pbct.project_id = bv.project_id
12858 AND pbct.BDGT_CNTRL_FLAG = 'Y'
12859 AND pbct.BUDGET_TYPE_CODE = bv.budget_type_code
12860 AND (pbct.EXTERNAL_BUDGET_CODE = 'GL'
12861 OR
12862 pbct.EXTERNAL_BUDGET_CODE is NULL
12863 )
12864 AND bv.project_id = txn.project_id
12865 AND txn.txn_interface_id in ( SELECT txn1.txn_interface_id
12866 FROM pa_transaction_interface_all txn1
12867 WHERE txn1.TRANSACTION_SOURCE = p_txn_source -- Condition for using index
12868 -- new index usage needs to be verified for below columns
12869 AND txn1.cdl_system_reference2 = p_sys_ref2
12870 AND txn1.cdl_system_reference5 = p_sys_ref5
12871 AND txn1.fc_document_type in ('ACT','ALL')
12872 AND txn1.adjusted_expenditure_item_id IS NOT NULL
12873 AND p_adj_act_fc_req = 'Y'
12874 UNION ALL -- R12 AP lines uptake : Prepayment changes : Added to pick current transaction for prepayment scenarios
12875 SELECT p_txn_interface_id
12876 FROM DUAL
12877 WHERE p_act_fc_req = 'Y');
12878
12879 l_comm_fc_req VARCHAR2(1); -- Variable to identify whether commitment fundscheck is required
12880 l_act_fc_req VARCHAR2(1); -- Variable to identify whether actual fundscheck is required
12881 l_adj_act_fc_req VARCHAR2(1); -- Variable to identify whether adjusted actual fundscheck is required
12882
12883
12884 BEGIN
12885
12886 IF PG_DEBUG = 'Y' THEN
12887 log_message('log_message: ' || 'In insert_bc_packets - Start');
12888 log_message('log_message: ' || 'In insert_bc_packets - Value of p_packet_id '||p_packet_id);
12889 log_message('log_message: ' || 'In insert_bc_packets - Value of p_sys_ref2 '||p_sys_ref2 );
12890 log_message('log_message: ' || 'In insert_bc_packets - Value of p_sys_ref4 '||p_sys_ref4 );
12891 log_message('log_message: ' || 'In insert_bc_packets - Value of p_sys_ref5 '||p_sys_ref5 );
12892 log_message('log_message: ' || 'In insert_bc_packets - Value of p_acct_raw_cost '||p_acct_raw_cost);
12893 log_message('log_message: ' || 'In insert_bc_packets - Value of p_acct_bur_cost '||p_acct_bur_cost);
12894 log_message('log_message: ' || 'In insert_bc_packets - Value of p_fc_document_type '||p_fc_document_type );
12895 log_message('log_message: ' || 'In insert_bc_packets - Value of p_txn_source '||p_txn_source);
12896 log_message('log_message: ' || 'In insert_bc_packets - Value of p_adj_exp_item_id '||p_adj_exp_item_id);
12897 log_message('log_message: ' || 'In insert_bc_packets - Value of p_txn_interface_id '||p_txn_interface_id);
12898
12899 END IF;
12900
12901 -- Code to derive values for variables which will decide the flow of this procedure
12902
12903 l_comm_fc_req :='N'; -- Variable to identify whether commitment fundscheck is required
12904 l_act_fc_req :='N'; -- Variable to identify whether actual fundscheck is required
12905 l_adj_act_fc_req:='N'; -- Variable to identify whether adjusted actual fundscheck is required
12906
12907 IF p_adj_exp_item_id IS NULL THEN
12908
12909 IF p_fc_document_type ='ALL' THEN --ap normal lines import
12910 l_comm_fc_req := 'Y' ;
12911 l_act_fc_req := 'Y' ;
12912 ELSIF p_fc_document_type ='ACT' OR p_txn_source = 'AP DISCOUNTS' THEN --ap discounts lines import
12913 l_act_fc_req := 'Y' ;
12914 END IF;
12915
12916 ELSIF p_adj_exp_item_id IS NOT NULL THEN
12917
12918 IF p_fc_document_type ='ALL' THEN --ap invoice having fc enabled and adjusted ei's having fc enabled
12919 l_comm_fc_req := 'Y' ;
12920 l_adj_act_fc_req := 'Y';
12921 ELSIF p_fc_document_type ='CMT' THEN --ap invoice having fc enabled and adjusted ei's having fc disabled
12922 l_comm_fc_req := 'Y' ;
12923 ELSIF p_fc_document_type ='ACT' THEN --ap invoice having fc disabled and adjusted ei's having fc ENabled
12924 l_adj_act_fc_req := 'Y';
12925 END IF;
12926
12927 END IF;
12928
12929 IF PG_DEBUG = 'Y' THEN
12930 log_message('log_message: ' || 'In insert_bc_packets - Value of l_comm_fc_req '||l_comm_fc_req);
12931 log_message('log_message: ' || 'In insert_bc_packets - Value of l_adj_act_fc_req '||l_adj_act_fc_req );
12932 log_message('log_message: ' || 'In insert_bc_packets - Value of l_act_fc_req '||l_act_fc_req );
12933 END IF;
12934
12935 -- Cursor to fetch data from pa_transaction_interface_table.This data is later used
12936 -- in autonomous fundscheck insert_ap_bc_pkts_autonomous procedure.
12937
12938 IF ( l_adj_act_fc_req = 'Y' OR l_act_fc_req = 'Y' ) THEN
12939
12940 -- call to clean up global plsql arrays used for storing interface data.
12941 init_xface_plsql_tables;
12942
12943 OPEN c_pa_txn_interface_data(l_adj_act_fc_req ,l_act_fc_req);
12944 FETCH c_pa_txn_interface_data BULK COLLECT INTO
12945 g_xface_project_id_tbl,
12946 g_xface_task_id_tbl,
12947 g_xface_exp_type_tbl,
12948 g_xface_ei_date_tbl,
12949 g_xface_exp_org_id_tbl,
12950 g_xface_bud_ver_id_tbl,
12951 g_xface_Entered_Dr_tbl,
12952 g_xface_Entered_Cr_tbl,
12953 g_xface_acct_Dr_tbl,
12954 g_xface_acct_Cr_tbl,
12955 g_xface_Txn_Ccid_tbl,
12956 g_xface_org_id_tbl,
12957 g_xface_Txn_interface_tbl,
12958 g_xface_vendor_id_tbl; /*bug 13601768*/
12959 CLOSE c_pa_txn_interface_data;
12960
12961 IF PG_DEBUG = 'Y' THEN
12962 log_message('log_message: ' || 'In insert_bc_packets - # of recs fetched from interface table c_pa_txn_interface_data = '||g_xface_Txn_interface_tbl.count);
12963 END IF;
12964
12965 END IF; --IF ( l_adj_act_fc_req = 'Y' OR l_act_fc_req = 'Y' ) THEN
12966
12967 IF PG_DEBUG = 'Y' THEN
12968 log_message('log_message: ' || 'In insert_bc_packets - calling insert_ap_bc_pkts_autonomous');
12969 END IF;
12970
12971 insert_ap_bc_pkt_autonomous
12972 (p_packet_id => p_packet_id,
12973 p_sys_ref2 => p_sys_ref2,
12974 p_sys_ref4 => p_sys_ref4,
12975 p_sys_ref5 => p_sys_ref5,
12976 p_acct_raw_cost => p_acct_raw_cost,
12977 p_acct_bur_cost => p_acct_bur_cost,
12978 p_fc_document_type => p_fc_document_type,
12979 p_txn_source => p_txn_source,
12980 p_adj_exp_item_id => p_adj_exp_item_id ,
12981 p_txn_interface_id => p_txn_interface_id,
12982 p_comm_fc_req => l_comm_fc_req,
12983 p_act_fc_req => l_act_fc_req,
12984 p_adj_act_fc_req => l_adj_act_fc_req );
12985
12986 IF PG_DEBUG = 'Y' THEN
12987 log_message('log_message: ' || 'After calling insert_ap_bc_pkt_autonomous api');
12988 log_message('log_message: ' || 'In insert_ap_bc_packets - End');
12989 END IF;
12990
12991 EXCEPTION
12992 WHEN OTHERS THEN
12993 IF PG_DEBUG = 'Y' THEN
12994 log_message('log_message:I n insert_bc_packets exception' || sqlerrm||' Returning from insert_bc_packets');
12995 END IF;
12996 RAISE;
12997 END insert_ap_bc_packets;
12998
12999 -- This procedure inserts records into pa_bc_packets for relieving commitment raw and burden
13000 -- and also for reserving raw and burden against actual.
13001 -- 1. IF p_fc_document_type = 'CMT'/'ALL' then we need to relieve commitment amount.
13002 -- 2. If commitment exists in pa_bc_commitments (i.e. sweeper process if run) then
13003 -- insert records into pa_bc_packets to relieve the raw and burden commitment
13004 -- amounts lying in pa_bc_commitments.
13005 -- else
13006 -- insert records into pa_bc_packets to relieve the raw and burden commitment
13007 -- amounts lying in pa_bc_packets.
13008 -- end if;
13009 -- 3.p_document type = 'ALL' and p_adj_exp_item_id IS NULL implies its a regular
13010 -- Payable Invoice getting interfaced to Projects. In this case
13011 -- insert records into pa_bc_packets to reserve actual raw cost amount which is equal to
13012 -- commitment amount in pa_bc_commitments relieved in step 2.
13013 -- Note : parent_bc_packet_id is populated to -1 such that pa_funds_check process will
13014 -- generate burden against this actual based on latest compiled set id.
13015 -- 4.If p_document type = 'ACT'/'ALL' and p_adj_exp_item_id IS NOT NULL then it implies thats its a
13016 -- reversing/cancelled Payable Invoice getting interfaced to Projects and original
13017 -- interfaced exp in project has been adjusted .
13018 -- In this case insert records into pa_bc_packets to fundscheck actual raw cost which is equal to
13019 -- amount in pa_transaction_interface for each non net zero expenditures associated with this
13020 -- invoice.
13021 -- Note : In this scenraio if non net zero expenditures associated with this invoice are not costed
13022 -- then import process (PAAPIMPB.pls) will reject the transactions with PA_EI_NOT_COST_DISTRIBUTED.
13023 -- Hence the ind_compiled_set_id on original exp's will always be the latest ,so parent_bc_packet_id
13024 -- is populated to -1 such that pa_funds_check process will generate burden against this
13025 -- actual based on latest compiled set id.
13026
13027 PROCEDURE INSERT_AP_BC_PKT_AUTONOMOUS
13028 (p_packet_id IN NUMBER,
13029 p_sys_ref2 IN NUMBER,
13030 p_sys_ref4 IN VARCHAR2,
13031 p_sys_ref5 IN NUMBER,
13032 p_acct_raw_cost IN NUMBER,
13033 p_acct_bur_cost IN NUMBER,
13034 p_fc_document_type IN VARCHAR2,
13035 p_txn_source IN VARCHAR2,
13036 p_adj_exp_item_id IN NUMBER,
13037 p_txn_interface_id IN NUMBER,
13038 p_comm_fc_req IN VARCHAR2,
13039 p_act_fc_req IN VARCHAR2,
13040 p_adj_act_fc_req IN VARCHAR2) IS
13041
13042 PRAGMA AUTONOMOUS_TRANSACTION;
13043
13044 CURSOR c_gen_raw_bc_pkt IS
13045 SELECT Pa_Bc_Packets_s.NextVal
13046 FROM dual;
13047
13048 CURSOR c_get_po_dist_id IS
13049 SELECT po_distribution_id
13050 FROM ap_invoice_distributions
13051 WHERE invoice_id = p_sys_ref2
13052 AND invoice_distribution_id = p_sys_ref5
13053 union /*Self Assessed Tax Changes*/
13054 SELECT po_distribution_id
13055 FROM ap_self_assessed_tax_dist
13056 WHERE invoice_id = p_sys_ref2
13057 AND invoice_distribution_id = p_sys_ref5;
13058
13059 CURSOR c_get_po_LINE_id (p_po_dist_id NUMBER) IS
13060 SELECT po_line_id
13061 FROM po_distributions_all
13062 WHERE po_distribution_id = p_po_dist_id;
13063
13064 CURSOR c_get_vendor_id IS
13065 SELECT a.vendor_id
13066 FROM ap_invoices_all A, ap_invoice_distributions_all aid
13067 WHERE A.invoice_id = aid.invoice_id
13068 AND A.invoice_id = p_sys_ref2
13069 AND aid.invoice_distribution_id = p_sys_ref5
13070 UNION /* Added for bug 13859614 */
13071 SELECT a.vendor_id
13072 FROM ap_invoices_all A, ap_self_assessed_tax_dist_all aid
13073 WHERE A.invoice_id = aid.invoice_id
13074 AND A.invoice_id = p_sys_ref2
13075 AND aid.invoice_distribution_id = p_sys_ref5;
13076
13077 -- R12 Funds Management : This cursor can fetches both Raw and Burden Lines for commitment
13078 -- to be relieved.
13079 -- Note : This cursor can fetch more than one raw record for Quantity/amount variance scenarios.
13080 -- In this case QTY/Amount variance are stroed on same ITEM distributions , but there will be 2
13081 -- bc records one for item amout and other for quantity/amount variance
13082
13083 Cursor C_Ap_Commitment Is
13084 Select bcc.Set_Of_Books_Id
13085 ,bcc.Period_Year
13086 ,bcc.Project_Id
13087 ,bcc.Task_Id
13088 ,bcc.Expenditure_Type
13089 ,bcc.Expenditure_Item_Date
13090 ,bcc.Expenditure_Organization_Id
13091 ,bcc.Budget_Version_Id
13092 ,bcc.budget_line_id -- R12 Funds Management uptake
13093 ,bcc.Document_Type
13094 ,bcc.Document_Header_Id
13095 ,bcc.Document_Distribution_Id
13096 ,bcc.Entered_Cr
13097 ,bcc.Entered_Dr
13098 ,bcc.Accounted_Cr
13099 ,bcc.Accounted_Dr
13100 ,bcc.Actual_Flag
13101 ,bcc.Txn_Ccid
13102 ,bcc.Je_Category_Name
13103 ,bcc.Je_Source_Name
13104 ,bcc.Org_Id
13105 ,bcc.Pa_Date
13106 ,bcc.bc_packet_id
13107 ,bcc.packet_id
13108 ,bcc.parent_bc_packet_id
13109 ,bcc.encumbrance_type_id
13110 ,bcc.document_header_id_2
13111 ,bcc.document_distribution_type
13112 From Pa_Bc_Commitments_all bcc
13113 Where bcc.Document_Header_Id = p_sys_ref2
13114 and bcc.Document_Distribution_Id =p_sys_ref5
13115 --PA-J Receipt accrual changes
13116 and bcc.document_type = 'AP'
13117 and bcc.exp_item_id IS NULL -- Bug 5014138 : to pick just the encumbrance record
13118 and bcc.actual_flag = 'E' -- Bug 5014138 : to pick just the encumbrance record
13119 -- Bug 5550268 : For variance we should be picking just the variance records
13120 /* Bug 5560524 : Modified the following condition such that the burden commitment relieving record is also
13121 fetched for 'AP VARIANCE' transaction source. */
13122 and ((nvl(bcc.accounted_dr,0)-nvl(bcc.accounted_cr,0) = p_acct_raw_cost
13123 and p_txn_source = 'AP VARIANCE' and bcc.parent_bc_packet_id is null)
13124 OR
13125 p_txn_source <> 'AP VARIANCE'
13126 OR
13127 (bcc.parent_bc_packet_id is NOT null AND p_txn_source = 'AP VARIANCE')
13128 );
13129
13130
13131
13132 -- R12 Funds Management : This cursor can fetches both Raw and Burden Lines for commitment
13133 -- to be relieved.
13134 -- Note : This cursor can fetch more than one raw record for Quantity/amount variance scenarios.
13135 -- In this case QTY/Amount variance are stroed on same ITEM distributions , but there will be 2
13136 -- bc records one for item amout and other for quantity/amount variance
13137
13138 Cursor C_Ap_Bc_Packets Is
13139 Select bcc.Set_Of_Books_Id
13140 ,bcc.Period_Year
13141 ,bcc.Project_Id
13142 ,bcc.Task_Id
13143 ,bcc.Expenditure_Type
13144 ,bcc.Expenditure_Item_Date
13145 ,bcc.Expenditure_Organization_Id
13146 ,bcc.Budget_Version_Id
13147 ,bcc.budget_line_id -- R12 Funds Management uptake
13148 ,bcc.Document_Type
13149 ,bcc.Document_Header_Id
13150 ,bcc.Document_Distribution_Id
13151 ,bcc.Entered_Cr
13152 ,bcc.Entered_Dr
13153 ,bcc.Accounted_Cr
13154 ,bcc.Accounted_Dr
13155 ,bcc.Actual_Flag
13156 ,bcc.Txn_Ccid
13157 ,bcc.Je_Category_Name
13158 ,bcc.Je_Source_Name
13159 ,bcc.Org_Id
13160 ,bcc.Pa_Date
13161 ,bcc.bc_packet_id
13162 ,bcc.packet_id
13163 ,bcc.parent_bc_packet_id
13164 ,bcc.encumbrance_type_id
13165 ,bcc.document_header_id_2
13166 ,bcc.document_distribution_type
13167 From Pa_Bc_Packets bcc
13168 where bcc.Document_Header_Id = p_sys_ref2
13169 and bcc.Document_Distribution_Id =p_sys_ref5
13170 and bcc.Status_Code in ('A','C')
13171 and bcc.document_type = 'AP'
13172 and bcc.exp_item_id IS NULL -- Bug 5014138 : to pick just the encumbrance record
13173 and bcc.actual_flag = 'E' -- Bug 5014138 : to pick just the encumbrance record
13174 -- Bug 5550268 : For variance we should be picking just the variance records
13175 /* Bug 5560524 : Modified the following condition such that the burden commitment relieving record is also
13176 fetched for 'AP VARIANCE' transaction source. */
13177 and ((nvl(bcc.accounted_dr,0)-nvl(bcc.accounted_cr,0) = p_acct_raw_cost
13178 and p_txn_source = 'AP VARIANCE' and bcc.parent_bc_packet_id is null)
13179 OR
13180 p_txn_source <> 'AP VARIANCE'
13181 OR
13182 (bcc.parent_bc_packet_id is NOT null AND p_txn_source = 'AP VARIANCE')
13183 );
13184
13185 l_rec_bc_comm_exists VARCHAR2(1); -- Variable to identify whether commitment record exists in pa_bc_commitments
13186 l_rec_pkt_comm_exists VARCHAR2(1); -- Variable to identify whether commitment record exists in pa_bc_packets
13187 L_RAW_BC_PACKET_ID NUMBER;
13188 l_po_dist_id ap_invoice_distributions.po_distribution_id%TYPE;
13189 l_po_line_id po_distributions_all.po_line_id%TYPE;
13190 l_vendor_id ap_invoices_all.vendor_id%TYPE; /*bug 13601768*/
13191
13192 CURSOR c_curr_raw_pkt IS
13193 SELECT bc_packet_id
13194 FROM pa_bc_packets
13195 WHERE packet_id = p_packet_id
13196 AND Document_Header_Id = p_sys_ref2
13197 AND Document_Distribution_Id =p_sys_ref5
13198 AND parent_bc_packet_id IS NULL
13199 AND status_code ='P';
13200
13201
13202 BEGIN
13203
13204 IF PG_DEBUG = 'Y' THEN
13205 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Start');
13206 END IF;
13207
13208 OPEN c_get_vendor_id;
13209 FETCH c_get_vendor_id into l_vendor_id;
13210 CLOSE c_get_vendor_id;
13211
13212 /* cwk */
13213
13214 IF p_txn_source in ('AP NRTAX','AP VARIANCE') THEN
13215
13216 OPEN c_get_po_dist_id;
13217 FETCH c_get_po_dist_id into l_po_dist_id;
13218 CLOSE c_get_po_dist_id;
13219
13220 IF nvl(Pa_Pjc_Cwk_Utils.Is_rate_based_line( null, l_po_dist_id),'N') = 'Y' THEN
13221 OPEN c_get_po_LINE_id(l_po_dist_id);
13222 FETCH c_get_po_LINE_id into l_po_line_id;
13223 CLOSE c_get_po_LINE_id;
13224 END IF;
13225
13226 IF PG_DEBUG = 'Y' THEN
13227 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - After fetching CWK related data l_po_dist_id'||l_po_dist_id);
13228 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - After fetching CWK related data l_po_line_id'||l_po_line_id);
13229 END IF;
13230
13231 END IF;
13232
13233 -- Code to derive values for variables which will decide the flow of this procedure
13234 l_rec_bc_comm_exists:='N'; -- Variable to identify whether commitment record exists in pa_bc_commitments
13235 l_rec_pkt_comm_exists:='N'; -- Variable to identify whether commitment record exists in pa_bc_packets
13236
13237 IF p_comm_fc_req ='Y' OR p_act_fc_req = 'Y' THEN
13238
13239 IF PG_DEBUG = 'Y' THEN
13240 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Fetchign data from bc commitments');
13241 END IF;
13242
13243 clear_plsql_tables;
13244
13245 Open C_Ap_Commitment ;
13246 FETCH C_Ap_Commitment BULK COLLECT INTO
13247 g_sob_Id_tbl,
13248 g_Period_Year_tbl,
13249 g_project_id_tbl,
13250 g_task_id_tbl,
13251 g_exp_type_tbl,
13252 g_ei_date_tbl,
13253 g_exp_org_id_tbl,
13254 g_bud_ver_id_tbl,
13255 g_budget_line_id_tbl, -- R12 Funds management uptake
13256 g_Document_Type_tbl,
13257 g_Doc_Header_Id_tbl,
13258 g_Doc_dist_Id_tbl,
13259 g_Entered_Cr_tbl,
13260 g_Entered_Dr_tbl,
13261 g_acct_Cr_tbl,
13262 g_acct_Dr_tbl,
13263 g_Actual_Flag_tbl,
13264 g_Txn_Ccid_tbl,
13265 g_Je_Catg_Name_tbl,
13266 g_Je_sorce_Name_tbl,
13267 g_org_id_tbl,
13268 g_Pa_Date_tbl,
13269 g_bc_packet_id_tbl,
13270 g_packet_id_tbl,
13271 g_bc_parent_pkt_id_tbl,
13272 g_enc_type_id_tbl,
13273 g_doc_hdr_id_2_tbl,
13274 g_doc_dist_type_tbl;
13275
13276
13277 IF g_bc_packet_id_tbl.COUNT <> 0 THEN
13278 l_rec_bc_comm_exists := 'Y';
13279 END IF;
13280 CLOSE C_Ap_Commitment;
13281
13282 IF l_rec_bc_comm_exists = 'N' THEN
13283
13284 IF PG_DEBUG = 'Y' THEN
13285 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Fetchign data from bc packets');
13286 END IF;
13287
13288 OPEN C_Ap_Bc_Packets;
13289 FETCH C_Ap_Bc_Packets BULK COLLECT INTO
13290 g_sob_Id_tbl,
13291 g_Period_Year_tbl,
13292 g_project_id_tbl,
13293 g_task_id_tbl,
13294 g_exp_type_tbl,
13295 g_ei_date_tbl,
13296 g_exp_org_id_tbl,
13297 g_bud_ver_id_tbl,
13298 g_budget_line_id_tbl, -- R12 Funds management uptake
13299 g_Document_Type_tbl,
13300 g_Doc_Header_Id_tbl,
13301 g_Doc_dist_Id_tbl,
13302 g_Entered_Cr_tbl,
13303 g_Entered_Dr_tbl,
13304 g_acct_Cr_tbl,
13305 g_acct_Dr_tbl,
13306 g_Actual_Flag_tbl,
13307 g_Txn_Ccid_tbl,
13308 g_Je_Catg_Name_tbl,
13309 g_Je_sorce_Name_tbl,
13310 g_org_id_tbl,
13311 g_Pa_Date_tbl,
13312 g_bc_packet_id_tbl,
13313 g_packet_id_tbl,
13314 g_bc_parent_pkt_id_tbl,
13315 g_enc_type_id_tbl,
13316 g_doc_hdr_id_2_tbl,
13317 g_doc_dist_type_tbl;
13318
13319 IF g_bc_packet_id_tbl.COUNT <> 0 THEN
13320 l_rec_pkt_comm_exists := 'Y' ;
13321 END IF;
13322 CLOSE C_Ap_Bc_Packets;
13323
13324 END IF;
13325
13326 IF PG_DEBUG = 'Y' THEN
13327 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Number of commitment records fetched = '||g_bc_packet_id_tbl.count);
13328 END IF;
13329
13330 IF (l_rec_bc_comm_exists ='Y' OR l_rec_pkt_comm_exists = 'Y') THEN
13331
13332 -- Bug 5510447 : Insert commitment relieving raw and burden records only if p_comm_fc_req = 'Y'
13333 IF p_comm_fc_req = 'Y' THEN
13334
13335 -- Logic to insert commitment relieving raw and burden records
13336 FORALL i IN 1 .. g_bc_packet_id_tbl.count
13337 Insert Into Pa_Bc_Packets
13338 (Packet_Id
13339 ,Bc_Packet_Id
13340 ,Parent_Bc_Packet_Id
13341 ,Set_Of_Books_Id
13342 ,Gl_Date
13343 ,Period_Name
13344 ,Period_Year
13345 ,Pa_Date
13346 ,Project_Id
13347 ,Task_Id
13348 ,Expenditure_Type
13349 ,Expenditure_Item_Date
13350 ,Expenditure_Organization_Id
13351 ,Budget_Version_Id
13352 ,budget_line_id -- R12 Funds management uptake
13353 ,Document_Type
13354 ,Document_Header_Id
13355 ,Document_Distribution_Id
13356 ,Entered_Dr
13357 ,Entered_Cr
13358 ,Accounted_Dr
13359 ,Accounted_Cr
13360 ,Request_Id
13361 ,Program_Id
13362 ,Program_Application_Id
13363 ,Program_Update_Date
13364 ,Actual_Flag
13365 ,Last_Update_Date
13366 ,Last_Updated_By
13367 ,Created_By
13368 ,Creation_Date
13369 ,Last_Update_Login
13370 ,Txn_Ccid
13371 ,Burden_Cost_Flag
13372 ,Status_Code
13373 ,Je_Category_Name
13374 ,Je_Source_Name
13375 ,Org_id
13376 ,Exp_Item_Id
13377 ,Document_Line_Id
13378 ,reference1
13379 ,reference2
13380 ,reference3
13381 ,txn_interface_id --REL12
13382 ,encumbrance_type_id
13383 ,document_header_id_2
13384 ,document_distribution_type
13385 )
13386 Select p_packet_id
13387 ,g_bc_packet_id_tbl(i) -- Later updated with newly generated Id's
13388 ,g_bc_parent_pkt_id_tbl(i) -- Later updated with newly generated Id's
13389 ,g_sob_Id_tbl(i)
13390 ,G_FC_Gl_Date
13391 ,G_FC_Period_Name
13392 ,g_Period_Year_tbl(i)
13393 ,g_Pa_Date_tbl(i)
13394 ,g_project_id_tbl(i)
13395 ,g_task_id_tbl(i)
13396 ,g_exp_type_tbl(i)
13397 ,g_ei_date_tbl(i)
13398 ,g_exp_org_id_tbl(i)
13399 ,g_bud_ver_id_tbl(i)
13400 ,g_budget_line_id_tbl(i)
13401 ,g_Document_Type_tbl(i)
13402 ,g_Doc_Header_Id_tbl(i)
13403 ,g_Doc_dist_Id_tbl(i)
13404 ,g_Entered_Cr_tbl(i) -- reversing dr
13405 ,g_Entered_Dr_tbl(i) -- reversing cr
13406 ,g_acct_Cr_tbl(i)
13407 ,g_acct_Dr_tbl(i)
13408 ,g_Request_Id
13409 ,G_Program_Id
13410 ,G_PROG_APPL_ID
13411 ,sysdate
13412 ,g_Actual_Flag_tbl(i)
13413 ,sysdate
13414 ,G_CONC_LOGIN_ID
13415 ,G_CONC_LOGIN_ID
13416 ,sysdate
13417 ,G_CONC_LOGIN_ID
13418 ,g_Txn_Ccid_tbl(i)
13419 ,'R'
13420 ,'P'
13421 ,g_Je_Catg_Name_tbl(i)
13422 ,g_Je_sorce_Name_tbl(i)
13423 ,g_org_id_tbl(i)
13424 ,X_ei_id
13425 ,l_po_line_id
13426 ,'EXP'
13427 ,X_ei_id
13428 ,1
13429 ,p_txn_interface_id --REL12
13430 ,g_enc_type_id_tbl(i)
13431 ,g_doc_hdr_id_2_tbl(i)
13432 ,g_doc_dist_type_tbl(i)
13433 From dual;
13434
13435 IF PG_DEBUG = 'Y' THEN
13436 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Inserted '||SQL%ROWCOUNT||' AP reversing raw and burden line(s) into bc packets');
13437 END IF;
13438
13439 -- Logic to update bc_packet_id and parent_bc_packet_id with newly generated sequences
13440 FOR c_cur IN c_curr_raw_pkt LOOP
13441
13442 IF PG_DEBUG = 'Y' THEN
13443 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous -Logic to update correct bc pkt Id/parent BC pkt Id');
13444 END IF;
13445
13446 OPEN c_gen_raw_bc_pkt;
13447 FETCH c_gen_raw_bc_pkt INTO l_Raw_Bc_Packet_Id;
13448 CLOSE c_gen_raw_bc_pkt;
13449
13450 IF PG_DEBUG = 'Y' THEN
13451 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous -Old Bc Packet Id = ' || c_cur.bc_packet_id||'New Bc Packet Id = ' || l_Raw_Bc_Packet_Id ||'Packet Id = ' || p_packet_id);
13452 END IF;
13453
13454 -- Update raw records with new bc_packet_id
13455 UPDATE Pa_Bc_Packets
13456 SET bc_packet_id = l_Raw_Bc_Packet_Id
13457 WHERE packet_id = p_packet_id
13458 AND bc_packet_id = c_cur.bc_packet_id;
13459
13460 IF PG_DEBUG = 'Y' THEN
13461 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - NUmber of raw packets updated with new bc_packet_id '||SQL%ROWCOUNT);
13462 END IF;
13463
13464 -- Update burden records with new bc_packet_id abd parent_bc_packet_id
13465 UPDATE Pa_Bc_Packets
13466 SET bc_packet_id = Pa_Bc_Packets_s.NextVal
13467 ,parent_bc_packet_id = l_Raw_Bc_Packet_Id
13468 WHERE packet_id = p_packet_id
13469 AND parent_bc_packet_id = c_cur.bc_packet_id;
13470
13471 IF PG_DEBUG = 'Y' THEN
13472 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - NUmber of burden packets updated with new parent_bc_packet_id '||SQL%ROWCOUNT);
13473 END IF;
13474
13475 END LOOP;
13476
13477 END IF; -- Bug 5510447 : IF p_comm_fc_req = 'Y' THEN
13478
13479 --Logic to Insert the positive records for the raw line with document type 'EXP'.
13480 IF p_act_fc_req = 'Y' THEN
13481
13482 IF PG_DEBUG = 'Y' THEN
13483 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Before inserting ACTUAL raw line from bc packets');
13484 END IF;
13485
13486 FOR i IN 1 .. g_bc_packet_id_tbl.count LOOP
13487
13488
13489 Insert Into Pa_Bc_Packets
13490 (Packet_Id
13491 ,Bc_Packet_Id
13492 ,Parent_Bc_Packet_Id
13493 ,Set_Of_Books_Id
13494 ,gl_date
13495 ,Period_Name
13496 ,Period_Year
13497 ,Pa_Date
13498 ,Project_Id
13499 ,Task_Id
13500 ,Expenditure_Type
13501 ,Expenditure_Item_Date
13502 ,Expenditure_Organization_Id
13503 ,Budget_Version_Id
13504 ,budget_line_id -- R12 Funds management uptake
13505 ,Document_Type
13506 ,Document_Header_Id
13507 ,Document_Distribution_Id
13508 ,Entered_Dr
13509 ,Entered_Cr
13510 ,Accounted_Dr
13511 ,Accounted_Cr
13512 ,Request_Id
13513 ,Program_Id
13514 ,Program_Application_Id
13515 ,Program_Update_Date
13516 ,Actual_Flag
13517 ,Last_Update_Date
13518 ,Last_Updated_By
13519 ,Created_By
13520 ,Creation_Date
13521 ,Last_Update_Login
13522 ,Txn_Ccid
13523 ,Burden_Cost_Flag
13524 ,Status_Code
13525 ,Je_Category_Name
13526 ,Je_Source_Name
13527 ,Org_id
13528 ,Document_Line_Id
13529 ,reference1
13530 ,reference2
13531 ,reference3
13532 ,txn_interface_id --REL12
13533 ,vendor_id
13534 )
13535 Select p_Packet_Id
13536 ,Pa_Bc_Packets_s.NextVal
13537 ,-1
13538 ,g_sob_Id_tbl(i)
13539 ,G_FC_Gl_Date
13540 ,G_FC_Period_Name
13541 ,g_Period_Year_tbl(i)
13542 ,g_Pa_Date_tbl(i)
13543 ,g_project_id_tbl(i)
13544 ,g_task_id_tbl(i)
13545 ,g_exp_type_tbl(i)
13546 ,g_ei_date_tbl(i)
13547 ,g_exp_org_id_tbl(i)
13548 ,g_bud_ver_id_tbl(i)
13549 ,g_budget_line_id_tbl(i) -- R12 Funds management uptake
13550 ,'EXP'
13551 ,X_ei_id
13552 ,1
13553 ,DECODE(p_txn_source,'AP DISCOUNTS',p_acct_raw_cost,g_Entered_Dr_tbl(i))
13554 ,DECODE(p_txn_source,'AP DISCOUNTS',0,g_Entered_Cr_tbl(i))
13555 ,DECODE(p_txn_source,'AP DISCOUNTS',p_acct_raw_cost,g_acct_Dr_tbl(i))
13556 ,DECODE(p_txn_source,'AP DISCOUNTS',0,g_acct_Cr_tbl(i))
13557 ,g_Request_Id
13558 ,g_program_id
13559 ,g_prog_appl_id
13560 ,sysdate
13561 ,'A'
13562 ,sysdate
13563 ,g_conc_login_id
13564 ,g_conc_login_id
13565 ,sysdate
13566 ,g_conc_login_id
13567 ,g_Txn_Ccid_tbl(i)
13568 ,'N'
13569 ,'P'
13570 ,'Expenditures'
13571 ,'Project Accounting'
13572 ,g_org_id_tbl(i)
13573 ,DECODE(p_txn_source,'AP DISCOUNTS',NULL,l_po_line_id)
13574 ,DECODE(p_txn_source,'AP DISCOUNTS',NULL,'EXP')
13575 ,DECODE(p_txn_source,'AP DISCOUNTS',NULL,x_Ei_Id)
13576 ,DECODE(p_txn_source,'AP DISCOUNTS',NULL,1)
13577 ,p_txn_interface_id --REL12
13578 ,l_vendor_id
13579 From Pa_Budget_Versions bv,
13580 Pa_Budget_Types bt,
13581 pa_budgetary_control_options pbct
13582 Where bt.budget_type_Code = bv.budget_type_Code
13583 and bt.budget_amount_code = 'C'
13584 and bv.project_id = g_project_id_tbl(i)
13585 and bv.current_flag = 'Y'
13586 and pbct.project_id = bv.project_id
13587 and pbct.BDGT_CNTRL_FLAG = 'Y'
13588 and pbct.BUDGET_TYPE_CODE = bv.budget_type_code
13589 and (pbct.EXTERNAL_BUDGET_CODE = 'GL'
13590 OR
13591 pbct.EXTERNAL_BUDGET_CODE is NULL
13592 )
13593 and g_bc_parent_pkt_id_tbl(i) IS NULL; -- Need to fire only for raw records
13594
13595
13596 -- Bug 5562671 : Scenario where QTY/AMT varaince exists there will be multiple records in
13597 -- bc_commitments/bc_packets for same inv distribution, hence the global varaibles will have
13598 -- multiple distributions.But there will be only one ap discount line for both item amount +
13599 -- qty/amt varaince. Hence actuals need to reserved only once.
13600 /* Bug 5984525 : The following code is modified so that ACTUAL lines are inserted correctly
13601 into pa bc packets while interfacing discounts to Projects. */
13602 IF p_txn_source = 'AP DISCOUNTS' AND SQL%ROWCOUNT = 1 THEN
13603 IF PG_DEBUG = 'Y' THEN
13604 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Inserted 1 ACTUAL raw line(s) into bc packets');
13605 END IF;
13606 EXIT;
13607 END IF;
13608
13609 END LOOP;
13610
13611 END IF;--IF p_act_fc_req = 'Y' THEN
13612
13613 END IF; --IF l_rec_bc_comm_exists ='Y' OR l_rec_pkt_comm_exists = 'Y' THEN
13614
13615 END IF; -- p_comm_fc_req ='Y' OR p_act_fc_req = 'Y' THEN
13616
13617
13618 -- R12 AP lines uptake : Prepayment changes : Below insert will be fired for inserting 'EXP'
13619 -- records by fetching data from pa_transaction_interface_all table for below TXN records :
13620 -- a. Adjusting expenditures in txn_interface table
13621 -- b. For those commitments which were never FC'ed (eg : Prepayment application, pre-payment matched to PO ..)
13622
13623 IF ((p_adj_act_fc_req = 'Y')
13624 OR (l_rec_bc_comm_exists ='N' AND l_rec_pkt_comm_exists = 'N' AND p_act_fc_req = 'Y' )) THEN
13625
13626 IF PG_DEBUG = 'Y' THEN
13627 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Before inserting adjusted ACTUAL raw line from transaction import table');
13628 END IF;
13629
13630 FORALL i IN 1 .. g_xface_Txn_interface_tbl.count
13631 Insert Into Pa_Bc_Packets
13632 (Packet_Id
13633 ,Bc_Packet_Id
13634 ,Parent_Bc_Packet_Id
13635 ,Set_Of_Books_Id
13636 ,Gl_Date
13637 ,Period_Name
13638 ,Period_Year
13639 ,Pa_Date
13640 ,Project_Id
13641 ,Task_Id
13642 ,Expenditure_Type
13643 ,Expenditure_Item_Date
13644 ,Expenditure_Organization_Id
13645 ,Budget_Version_Id
13646 ,Document_Type
13647 ,Document_Header_Id
13648 ,Document_Distribution_Id
13649 ,Entered_Dr
13650 ,Entered_Cr
13651 ,Accounted_Dr
13652 ,Accounted_Cr
13653 ,Request_Id
13654 ,Program_Id
13655 ,Program_Application_Id
13656 ,Program_Update_Date
13657 ,Actual_Flag
13658 ,Last_Update_Date
13659 ,Last_Updated_By
13660 ,Created_By
13661 ,Creation_Date
13662 ,Last_Update_Login
13663 ,Txn_Ccid
13664 ,Burden_Cost_Flag
13665 ,Status_Code
13666 ,Je_Category_Name
13667 ,Je_Source_Name
13668 ,Org_id
13669 ,Document_Line_Id
13670 ,reference1
13671 ,reference2
13672 ,reference3
13673 ,txn_interface_id --REL12
13674 ,vendor_id
13675 )
13676 Select p_Packet_Id
13677 ,Pa_Bc_Packets_s.NextVal
13678 ,-1
13679 ,g_sobid
13680 ,G_FC_Gl_Date
13681 ,G_FC_Period_Name
13682 ,G_FC_Period_Year
13683 ,G_PaDate
13684 ,g_xface_project_id_tbl(i)
13685 ,g_xface_task_id_tbl(i)
13686 ,g_xface_exp_type_tbl(i)
13687 ,g_xface_ei_date_tbl(i)
13688 ,g_xface_exp_org_id_tbl(i)
13689 ,g_xface_bud_ver_id_tbl(i)
13690 ,'EXP'
13691 ,X_ei_id
13692 ,1
13693 -- R12 AP lines uptake : Prepayment changes
13694 -- For Prepayment application/pre-payment matched to PO records consider p_acct_raw_cost as amount
13695 ,g_xface_Entered_Dr_tbl(i)
13696 ,g_xface_acct_Cr_tbl(i)
13697 ,g_xface_acct_Dr_tbl(i)
13698 ,g_xface_acct_Cr_tbl(i)
13699 ,g_Request_Id
13700 ,g_program_id
13701 ,g_prog_appl_id
13702 ,sysdate
13703 ,'A' --Actual_Flag
13704 ,sysdate
13705 ,g_conc_login_id
13706 ,g_conc_login_id
13707 ,sysdate
13708 ,g_conc_login_id
13709 ,g_xface_Txn_Ccid_tbl(i)
13710 ,'N'
13711 ,'P'
13712 ,'Expenditures'
13713 ,'Project Accounting'
13714 ,g_xface_org_id_tbl(i)
13715 ,l_po_line_id
13716 ,'EXP'
13717 ,X_Ei_Id
13718 ,1
13719 ,g_xface_Txn_interface_tbl(i) --REL12
13720 ,g_xface_vendor_id_tbl(i)
13721 From dual;
13722
13723 IF PG_DEBUG = 'Y' THEN
13724 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - Inserted '||SQL%ROWCOUNT||' ACTUAL raw line(s) into bc packets');
13725 END IF;
13726
13727 END IF;
13728
13729 COMMIT;
13730 IF PG_DEBUG = 'Y' THEN
13731 log_message('log_message: ' || 'In insert_ap_bc_pkt_autonomous - End');
13732 END IF;
13733
13734 EXCEPTION
13735 WHEN OTHERS THEN
13736 IF PG_DEBUG = 'Y' THEN
13737 log_message('log_message: In insert_ap_bc_pkt_autonomous - ' || sqlerrm||' Returning from insert_ap_bc_pkt_autonomous');
13738 END IF;
13739 RAISE;
13740 END insert_ap_bc_pkt_autonomous;
13741
13742
13743 -- R12 funds management Uptake : New procedure fired in non-autonomous mode to read
13744 -- pa_transaction_interface_all table and to derive variables which drives the
13745 -- relieving/reserving of commitments and actuals flow during interface.
13746
13747 PROCEDURE insert_cash_ap_bc_packets(p_packet_id IN NUMBER,
13748 p_sys_ref2 IN NUMBER,
13749 p_sys_ref5 IN NUMBER,
13750 p_acct_raw_cost IN NUMBER,
13751 p_fc_document_type IN VARCHAR2,
13752 p_txn_source IN VARCHAR2,
13753 p_adj_exp_item_id IN NUMBER,
13754 p_txn_interface_id IN NUMBER,
13755 p_cash_pay_to_relieve IN NUMBER DEFAULT 0) IS
13756
13757 -- Cursor to fetch data from pa_transaction_interface_table.This data is later used
13758 -- in autonomous fundscheck insert_ap_bc_pkts_autonomous procedure.
13759
13760 CURSOR c_pa_txn_interface_data (p_adj_act_fc_req VARCHAR2,
13761 p_act_fc_req VARCHAR2) IS
13762 Select txn.Project_Id
13763 ,txn.Task_Id
13764 ,txn.Expenditure_Type
13765 ,txn.Expenditure_Item_Date
13766 ,nvl(txn.OVERRIDE_TO_ORGANIZATION_ID,txn.Org_Id)
13767 ,bv.Budget_Version_Id
13768 -- R12 AP lines uptake : Prepayment changes
13769 -- For Prepayment application/pre-payment matched to PO records consider p_acct_raw_cost as amount
13770 ,DECODE(txn_interface_id,p_txn_interface_id, p_acct_raw_cost,txn.acct_raw_cost)
13771 ,0
13772 ,DECODE(txn_interface_id,p_txn_interface_id, p_acct_raw_cost,txn.acct_raw_cost)
13773 ,0
13774 ,txn.cr_code_combination_id
13775 ,txn.Org_id
13776 ,txn.txn_interface_id --REL12
13777 ,txn.vendor_id
13778 From Pa_Budget_Versions bv,
13779 Pa_Budget_Types bt,
13780 pa_budgetary_control_options pbct,
13781 pa_transaction_interface_all txn
13782 Where bv.budget_type_code = bt.budget_type_code
13783 and bt.budget_amount_code = 'C'
13784 and bv.current_flag = 'Y'
13785 AND pbct.project_id = bv.project_id
13786 AND pbct.BDGT_CNTRL_FLAG = 'Y'
13787 AND pbct.BUDGET_TYPE_CODE = bv.budget_type_code
13788 AND (pbct.EXTERNAL_BUDGET_CODE = 'GL'
13789 OR
13790 pbct.EXTERNAL_BUDGET_CODE is NULL
13791 )
13792 AND bv.project_id = txn.project_id
13793 AND txn.txn_interface_id in ( SELECT txn1.txn_interface_id
13794 FROM pa_transaction_interface_all txn1
13795 WHERE txn1.TRANSACTION_SOURCE = p_txn_source -- Condition for using index
13796 -- new index usage needs to be verified for below columns
13797 AND txn1.cdl_system_reference2 = p_sys_ref2
13798 AND txn1.cdl_system_reference5 = p_sys_ref5
13799 AND txn1.fc_document_type in ('ACT','ALL')
13800 AND txn1.adjusted_expenditure_item_id IS NOT NULL
13801 AND p_adj_act_fc_req = 'Y'
13802 UNION ALL -- R12 AP lines uptake : Prepayment changes : Added to pick current transaction for prepayment scenarios
13803 SELECT p_txn_interface_id
13804 FROM DUAL
13805 WHERE p_act_fc_req = 'Y');
13806
13807 l_comm_fc_req VARCHAR2(1); -- Variable to identify whether commitment fundscheck is required
13808 l_act_fc_req VARCHAR2(1); -- Variable to identify whether actual fundscheck is required
13809 l_adj_act_fc_req VARCHAR2(1); -- Variable to identify whether adjusted actual fundscheck is required
13810
13811 BEGIN
13812
13813 IF PG_DEBUG = 'Y' THEN
13814 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Start');
13815 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_packet_id '||p_packet_id);
13816 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_sys_ref2 '||p_sys_ref2 );
13817 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_sys_ref5 '||p_sys_ref5 );
13818 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_acct_raw_cost '||p_acct_raw_cost);
13819 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_fc_document_type '||p_fc_document_type );
13820 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_txn_source '||p_txn_source);
13821 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_adj_exp_item_id '||p_adj_exp_item_id);
13822 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of p_txn_interface_id '||p_txn_interface_id);
13823
13824 END IF;
13825
13826 -- Code to derive values for variables which will decide the flow of this procedure
13827
13828 l_comm_fc_req :='N'; -- Variable to identify whether commitment fundscheck is required
13829 l_act_fc_req :='N'; -- Variable to identify whether actual fundscheck is required
13830 l_adj_act_fc_req:='N'; -- Variable to identify whether adjusted actual fundscheck is required
13831
13832 -- Deriving value for variable which identifies if FC required for AP commitment
13833
13834 IF ( (p_adj_exp_item_id IS NULL AND p_fc_document_type ='ALL') OR --AP normal Invoice lines
13835 (p_adj_exp_item_id IS NOT NULL AND (p_fc_document_type ='ALL' --FC enabled for AP INV and FC enabled for adjusted ei's
13836 OR p_fc_document_type ='CMT')--FC enabled for AP INV and FC Disabled for adjusted ei's
13837 )
13838 ) AND p_cash_pay_to_relieve <> 0 THEN
13839 l_comm_fc_req := 'Y' ;
13840 END IF;
13841
13842 -- Deriving value for variable which identifies if FC required for Actuals
13843 IF p_adj_exp_item_id IS NULL THEN
13844
13845 IF ( p_fc_document_type ='ALL' OR p_fc_document_type ='ACT' OR p_txn_source = 'AP DISCOUNTS') THEN
13846 l_act_fc_req := 'Y' ;
13847 END IF;
13848
13849 ELSIF p_adj_exp_item_id IS NOT NULL THEN
13850
13851 IF (p_fc_document_type ='ALL' OR p_fc_document_type ='ACT') THEN
13852 l_adj_act_fc_req := 'Y';
13853 END IF;
13854
13855 END IF;
13856
13857 IF PG_DEBUG = 'Y' THEN
13858 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of l_comm_fc_req '||l_comm_fc_req);
13859 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of l_adj_act_fc_req '||l_adj_act_fc_req );
13860 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - Value of l_act_fc_req '||l_act_fc_req );
13861 END IF;
13862
13863 -- Cursor to fetch data from pa_transaction_interface_table.This data is later used
13864 -- in autonomous fundscheck insert_ap_bc_pkts_autonomous procedure.
13865
13866 IF ( l_adj_act_fc_req = 'Y' OR l_act_fc_req = 'Y' ) THEN
13867
13868 -- call to clean up global plsql arrays used for storing interface data.
13869 init_xface_plsql_tables;
13870
13871 OPEN c_pa_txn_interface_data(l_adj_act_fc_req ,l_act_fc_req);
13872 FETCH c_pa_txn_interface_data BULK COLLECT INTO
13873 g_xface_project_id_tbl,
13874 g_xface_task_id_tbl,
13875 g_xface_exp_type_tbl,
13876 g_xface_ei_date_tbl,
13877 g_xface_exp_org_id_tbl,
13878 g_xface_bud_ver_id_tbl,
13879 g_xface_Entered_Dr_tbl,
13880 g_xface_Entered_Cr_tbl,
13881 g_xface_acct_Dr_tbl,
13882 g_xface_acct_Cr_tbl,
13883 g_xface_Txn_Ccid_tbl,
13884 g_xface_org_id_tbl,
13885 g_xface_Txn_interface_tbl,
13886 g_xface_vendor_id_tbl;
13887 CLOSE c_pa_txn_interface_data;
13888
13889 IF PG_DEBUG = 'Y' THEN
13890 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - fetched data from interface table c_pa_txn_interface_data ');
13891 END IF;
13892
13893 END IF; --IF ( l_adj_act_fc_req = 'Y' OR l_act_fc_req = 'Y' ) THEN
13894
13895 IF PG_DEBUG = 'Y' THEN
13896 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - calling insert_cash_ap_bc_pkt_auto');
13897 END IF;
13898
13899 insert_cash_ap_bc_pkt_auto
13900 (p_packet_id => p_packet_id,
13901 p_sys_ref2 => p_sys_ref2,
13902 p_sys_ref5 => p_sys_ref5,
13903 p_acct_raw_cost => p_acct_raw_cost,
13904 p_fc_document_type => p_fc_document_type,
13905 p_txn_source => p_txn_source,
13906 p_adj_exp_item_id => p_adj_exp_item_id ,
13907 p_txn_interface_id => p_txn_interface_id,
13908 p_cash_pay_to_relieve => p_cash_pay_to_relieve,
13909 p_comm_fc_req => l_comm_fc_req,
13910 p_act_fc_req => l_act_fc_req,
13911 p_adj_act_fc_req => l_adj_act_fc_req );
13912
13913 IF PG_DEBUG = 'Y' THEN
13914 log_message('log_message: ' || 'After Calling insert_cash_ap_bc_pkt_auto api');
13915 log_message('log_message: ' || 'In insert_cash_ap_bc_packets - End');
13916 END IF;
13917
13918 EXCEPTION
13919 WHEN OTHERS THEN
13920 IF PG_DEBUG = 'Y' THEN
13921 log_message('log_message:I n insert_cash_ap_bc_packets exception' || sqlerrm||' Returning from insert_cash_ap_bc_packets');
13922 END IF;
13923 RAISE;
13924 END insert_cash_ap_bc_packets;
13925
13926 -- This procedure inserts records into pa_bc_packets for relieving commitment raw and burden
13927 -- and also for reserving raw and burden against actual.
13928
13929 -- Parameter values : p_packet_id - Packet Id to be inserted
13930 -- p_sys_ref2 - Invoice Id
13931 -- p_sys_ref5 - Invoice Distribution Id
13932 -- p_acct_raw_cost - Amount to be relieved against AP and to be reserved against EXP
13933 -- p_fc_document_type - 'CMT'/'ALL'/'ACT'/'NOT'
13934 -- p_txn_source - Transaction source associated with the txn.
13935 -- p_adj_exp_item_id - Exp item id to be adjusted
13936 -- p_txn_interface_id - txn interface Id
13937 -- p_cash_pay_to_relieve - AP distribution amount to be relieved for cash based accounting.
13938 -- For cash based accounting p_acct_raw_cost amount will be reserved against EXP and
13939 -- p_cash_amt_to_relieve amount will be relived against AP.
13940
13941 PROCEDURE insert_cash_ap_bc_pkt_auto
13942 (p_packet_id IN NUMBER,
13943 p_sys_ref2 IN NUMBER,
13944 p_sys_ref5 IN NUMBER,
13945 p_acct_raw_cost IN NUMBER,
13946 p_fc_document_type IN VARCHAR2,
13947 p_txn_source IN VARCHAR2,
13948 p_adj_exp_item_id IN NUMBER,
13949 p_txn_interface_id IN NUMBER,
13950 p_cash_pay_to_relieve IN NUMBER DEFAULT 0,
13951 p_comm_fc_req IN VARCHAR2,
13952 p_act_fc_req IN VARCHAR2,
13953 p_adj_act_fc_req IN VARCHAR2) IS
13954
13955 PRAGMA AUTONOMOUS_TRANSACTION;
13956
13957 CURSOR c_gen_raw_bc_pkt IS
13958 SELECT Pa_Bc_Packets_s.NextVal
13959 FROM dual;
13960
13961 CURSOR c_get_po_dist_id IS
13962 SELECT po_distribution_id
13963 FROM ap_invoice_distributions
13964 WHERE invoice_id = p_sys_ref2
13965 AND invoice_distribution_id = p_sys_ref5
13966 union /*Self Assessed Tax Changes*/
13967 SELECT po_distribution_id
13968 FROM ap_invoice_distributions
13969 WHERE invoice_id = p_sys_ref2
13970 AND invoice_distribution_id = p_sys_ref5 ;
13971
13972 CURSOR c_get_po_LINE_id (p_po_dist_id NUMBER) IS
13973 SELECT po_line_id
13974 FROM po_distributions_all
13975 WHERE po_distribution_id = p_po_dist_id;
13976
13977 /*bug 13601768*/
13978 CURSOR c_get_vendor_id IS
13979 SELECT a.vendor_id
13980 FROM ap_invoices_all A, ap_invoice_distributions_all aid
13981 WHERE A.invoice_id = aid.invoice_id
13982 AND A.invoice_id = p_sys_ref2
13983 AND aid.invoice_distribution_id = p_sys_ref5
13984 UNION /* Added for bug 13859614 */
13985 SELECT a.vendor_id
13986 FROM ap_invoices_all A, ap_self_assessed_tax_dist_all aid
13987 WHERE A.invoice_id = aid.invoice_id
13988 AND A.invoice_id = p_sys_ref2
13989 AND aid.invoice_distribution_id = p_sys_ref5;
13990
13991 Cursor C_Ap_Commitment Is
13992 Select bcc.Set_Of_Books_Id
13993 ,bcc.Period_Year
13994 ,bcc.Project_Id
13995 ,bcc.Task_Id
13996 ,bcc.Expenditure_Type
13997 ,bcc.Expenditure_Item_Date
13998 ,bcc.Expenditure_Organization_Id
13999 ,bcc.Budget_Version_Id
14000 ,bcc.budget_line_id -- R12 Funds management uptake
14001 ,bcc.Document_Type
14002 ,bcc.Document_Header_Id
14003 ,bcc.Document_Distribution_Id
14004 ,bcc.Entered_Cr
14005 ,bcc.Entered_Dr
14006 ,bcc.Accounted_Cr
14007 ,bcc.Accounted_Dr
14008 ,bcc.Actual_Flag
14009 ,bcc.Txn_Ccid
14010 ,bcc.Je_Category_Name
14011 ,bcc.Je_Source_Name
14012 ,bcc.Org_Id
14013 ,bcc.Pa_Date
14014 ,bcc.bc_packet_id
14015 ,bcc.packet_id
14016 From Pa_Bc_Commitments_all bcc
14017 Where bcc.Document_Header_Id = p_sys_ref2
14018 and bcc.Document_Distribution_Id = p_sys_ref5
14019 and bcc.Parent_Bc_Packet_Id is NULL
14020 --PA-J Receipt accrual changes
14021 and bcc.document_type = 'AP'
14022 and bcc.exp_item_id IS NULL -- Bug 5014138 : to pick just the encumbrance record
14023 and bcc.actual_flag = 'E' -- Bug 5014138 : to pick just the encumbrance record
14024 -- R12 Ap lines Uptake : For cash based accounting which can have multiple packets associated with a distribution.
14025 and rownum = 1 ;
14026
14027
14028 Cursor C_Ap_Bc_Packets Is
14029 Select bcc.Set_Of_Books_Id
14030 ,bcc.Period_Year
14031 ,bcc.Project_Id
14032 ,bcc.Task_Id
14033 ,bcc.Expenditure_Type
14034 ,bcc.Expenditure_Item_Date
14035 ,bcc.Expenditure_Organization_Id
14036 ,bcc.Budget_Version_Id
14037 ,bcc.budget_line_id -- R12 Funds management uptake
14038 ,bcc.Document_Type
14039 ,bcc.Document_Header_Id
14040 ,bcc.Document_Distribution_Id
14041 ,bcc.Entered_Cr
14042 ,bcc.Entered_Dr
14043 ,bcc.Accounted_Cr
14044 ,bcc.Accounted_Dr
14045 ,bcc.Actual_Flag
14046 ,bcc.Txn_Ccid
14047 ,bcc.Je_Category_Name
14048 ,bcc.Je_Source_Name
14049 ,bcc.Org_Id
14050 ,bcc.Pa_Date
14051 ,bcc.bc_packet_id
14052 ,bcc.packet_id
14053 From Pa_Bc_Packets bcc
14054 where bcc.Document_Header_Id = p_sys_ref2
14055 and bcc.Document_Distribution_Id = p_sys_ref5
14056 and bcc.Status_Code in ('A','C')
14057 and bcc.Parent_Bc_Packet_Id is NULL
14058 and bcc.document_type = 'AP'
14059 and bcc.exp_item_id IS NULL -- Bug 5014138 : to pick just the encumbrance record
14060 and bcc.actual_flag = 'E' -- Bug 5014138 : to pick just the encumbrance record
14061 -- R12 Ap lines Uptake : Added for cash based accounting which can have multiple packets associated witha distribution.
14062 and rownum = 1 ;
14063
14064 l_rec_bc_comm_exists VARCHAR2(1); -- Variable to identify whether commitment record exists in pa_bc_commitments
14065 l_rec_pkt_comm_exists VARCHAR2(1); -- Variable to identify whether commitment record exists in pa_bc_packets
14066 l_Raw_Bc_Packet_Id pa_bc_packets.bc_packet_id%TYPE;
14067 l_po_dist_id ap_invoice_distributions.po_distribution_id%TYPE;
14068 l_po_line_id po_distributions_all.po_line_id%TYPE;
14069 l_vendor_id ap_invoices_all.vendor_id%TYPE; /*bug 13601768*/
14070
14071 BEGIN
14072
14073 IF PG_DEBUG = 'Y' THEN
14074 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Start');
14075 END IF;
14076
14077 OPEN c_get_vendor_id;
14078 FETCH c_get_vendor_id into l_vendor_id;
14079 CLOSE c_get_vendor_id;
14080
14081 /* cwk */
14082
14083 IF p_txn_source in ('AP NRTAX','AP VARIANCE') THEN
14084
14085 OPEN c_get_po_dist_id;
14086 FETCH c_get_po_dist_id into l_po_dist_id;
14087 CLOSE c_get_po_dist_id;
14088
14089 IF nvl(Pa_Pjc_Cwk_Utils.Is_rate_based_line( null, l_po_dist_id),'N') = 'Y' THEN
14090 OPEN c_get_po_LINE_id(l_po_dist_id);
14091 FETCH c_get_po_LINE_id into l_po_line_id;
14092 CLOSE c_get_po_LINE_id;
14093 END IF;
14094
14095 IF PG_DEBUG = 'Y' THEN
14096 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - After fetching CWK related data l_po_dist_id'||l_po_dist_id);
14097 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - After fetching CWK related data l_po_line_id'||l_po_line_id);
14098 END IF;
14099 END IF;
14100
14101 -- Code to derive values for variables which will decide the flow of this procedure
14102
14103 l_rec_bc_comm_exists:='N'; -- Variable to identify whether commitment record exists in pa_bc_commitments
14104 l_rec_pkt_comm_exists:='N'; -- Variable to identify whether commitment record exists in pa_bc_packets
14105
14106 IF p_comm_fc_req ='Y' OR p_act_fc_req = 'Y' THEN
14107
14108 IF PG_DEBUG = 'Y' THEN
14109 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Fetchign data from bc commitments');
14110 END IF;
14111
14112 Open C_Ap_Commitment ;
14113 clear_plsql_tables;
14114 FETCH C_Ap_Commitment BULK COLLECT INTO
14115 g_sob_Id_tbl,
14116 g_Period_Year_tbl,
14117 g_project_id_tbl,
14118 g_task_id_tbl,
14119 g_exp_type_tbl,
14120 g_ei_date_tbl,
14121 g_exp_org_id_tbl,
14122 g_bud_ver_id_tbl,
14123 g_budget_line_id_tbl, -- R12 funds management uptake
14124 g_Document_Type_tbl,
14125 g_Doc_Header_Id_tbl,
14126 g_Doc_dist_Id_tbl,
14127 g_Entered_Cr_tbl,
14128 g_Entered_Dr_tbl,
14129 g_acct_Cr_tbl,
14130 g_acct_Dr_tbl,
14131 g_Actual_Flag_tbl,
14132 g_Txn_Ccid_tbl,
14133 g_Je_Catg_Name_tbl,
14134 g_Je_sorce_Name_tbl,
14135 g_org_id_tbl,
14136 g_Pa_Date_tbl,
14137 g_bc_packet_id_tbl,
14138 g_packet_id_tbl;
14139
14140 IF g_bc_packet_id_tbl.COUNT <> 0 THEN
14141 l_rec_bc_comm_exists := 'Y';
14142 END IF;
14143 CLOSE C_Ap_Commitment;
14144
14145 IF l_rec_bc_comm_exists = 'N' THEN
14146
14147 IF PG_DEBUG = 'Y' THEN
14148 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Fetchign data from bc packets');
14149 END IF;
14150
14151 OPEN C_Ap_Bc_Packets;
14152 FETCH C_Ap_Bc_Packets BULK COLLECT INTO
14153 g_sob_Id_tbl,
14154 g_Period_Year_tbl,
14155 g_project_id_tbl,
14156 g_task_id_tbl,
14157 g_exp_type_tbl,
14158 g_ei_date_tbl,
14159 g_exp_org_id_tbl,
14160 g_bud_ver_id_tbl,
14161 g_budget_line_id_tbl, -- R12 funds management uptake
14162 g_Document_Type_tbl,
14163 g_Doc_Header_Id_tbl,
14164 g_Doc_dist_Id_tbl,
14165 g_Entered_Cr_tbl,
14166 g_Entered_Dr_tbl,
14167 g_acct_Cr_tbl,
14168 g_acct_Dr_tbl,
14169 g_Actual_Flag_tbl,
14170 g_Txn_Ccid_tbl,
14171 g_Je_Catg_Name_tbl,
14172 g_Je_sorce_Name_tbl,
14173 g_org_id_tbl,
14174 g_Pa_Date_tbl,
14175 g_bc_packet_id_tbl,
14176 g_packet_id_tbl;
14177
14178 IF g_bc_packet_id_tbl.COUNT <> 0 THEN
14179 l_rec_pkt_comm_exists := 'Y' ;
14180 END IF;
14181 CLOSE C_Ap_Bc_Packets;
14182
14183 END IF;
14184
14185 IF l_rec_bc_comm_exists ='Y' OR l_rec_pkt_comm_exists = 'Y' THEN
14186
14187 FOR i IN g_bc_packet_id_tbl.FIRST..g_bc_packet_id_tbl.LAST LOOP
14188
14189 -- Generate a packet identifier for RAW record that
14190 -- needs to be inserted into Pa BC Packets
14191
14192 IF PG_DEBUG = 'Y' THEN
14193 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Generating new Bc packet Id for reversing RAW act and commitment line');
14194 END IF;
14195
14196 OPEN c_gen_raw_bc_pkt;
14197 FETCH c_gen_raw_bc_pkt INTO l_Raw_Bc_Packet_Id;
14198 CLOSE c_gen_raw_bc_pkt;
14199
14200 IF PG_DEBUG = 'Y' THEN
14201 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Bc Packet Id = ' || l_Raw_Bc_Packet_Id ||'Packet Id = ' || p_packet_id);
14202 END IF;
14203
14204 IF l_rec_bc_comm_exists = 'Y' AND p_comm_fc_req ='Y' THEN
14205
14206 IF PG_DEBUG = 'Y' THEN
14207 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Before inserting AP reversing raw and burden line from bc commitments');
14208 END IF;
14209
14210 Insert Into Pa_Bc_Packets
14211 (Packet_Id
14212 ,Bc_Packet_Id
14213 ,Parent_Bc_Packet_Id
14214 ,Set_Of_Books_Id
14215 ,Gl_Date
14216 ,Period_Name
14217 ,Period_Year
14218 ,Pa_Date
14219 ,Project_Id
14220 ,Task_Id
14221 ,Expenditure_Type
14222 ,Expenditure_Item_Date
14223 ,Expenditure_Organization_Id
14224 ,Budget_Version_Id
14225 ,budget_line_id -- R12 funds management uptake
14226 ,Document_Type
14227 ,Document_Header_Id
14228 ,Document_Distribution_Id
14229 ,Entered_Dr
14230 ,Entered_Cr
14231 ,Accounted_Dr
14232 ,Accounted_Cr
14233 ,Request_Id
14234 ,Program_Id
14235 ,Program_Application_Id
14236 ,Program_Update_Date
14237 ,Actual_Flag
14238 ,Last_Update_Date
14239 ,Last_Updated_By
14240 ,Created_By
14241 ,Creation_Date
14242 ,Last_Update_Login
14243 ,Txn_Ccid
14244 ,Burden_Cost_Flag
14245 ,Status_Code
14246 ,Je_Category_Name
14247 ,Je_Source_Name
14248 ,Org_id
14249 ,Exp_Item_Id
14250 ,Document_Line_Id
14251 ,reference1
14252 ,reference2
14253 ,reference3
14254 ,txn_interface_id --REL12
14255 ,encumbrance_type_id
14256 ,document_header_id_2
14257 ,document_distribution_type
14258 )
14259 Select p_packet_id
14260 ,decode(bcc.Parent_Bc_Packet_Id,NULL,l_Raw_Bc_Packet_id,Pa_Bc_Packets_s.NextVal)
14261 ,decode(bcc.Parent_Bc_Packet_Id,NULL,NULL,l_Raw_Bc_Packet_id)
14262 ,bcc.Set_Of_Books_Id
14263 ,G_FC_Gl_Date
14264 ,G_FC_Period_Name
14265 ,bcc.Period_Year
14266 ,bcc.Pa_Date -- pa_date on raw is used for burden line
14267 ,bcc.Project_Id
14268 ,bcc.Task_Id
14269 ,bcc.Expenditure_Type
14270 ,bcc.Expenditure_Item_Date
14271 ,bcc.Expenditure_Organization_Id
14272 ,bcc.Budget_Version_Id
14273 ,bcc.budget_line_id -- R12 funds management uptake
14274 ,bcc.Document_Type
14275 ,bcc.Document_Header_Id
14276 ,bcc.Document_Distribution_Id
14277 ,DECODE(bcc.Parent_Bc_Packet_Id,NULL,p_cash_pay_to_relieve
14278 ,pa_currency.round_trans_currency_amt1((p_cash_pay_to_relieve * bcc.compiled_multiplier),G_accounting_currency_code))
14279 ,0
14280 ,DECODE(bcc.Parent_Bc_Packet_Id,NULL,p_cash_pay_to_relieve
14281 ,pa_currency.round_trans_currency_amt1((p_cash_pay_to_relieve * bcc.compiled_multiplier),G_accounting_currency_code))
14282 ,0
14283 ,g_Request_Id
14284 ,G_Program_Id
14285 ,G_PROG_APPL_ID
14286 ,sysdate
14287 ,bcc.Actual_Flag
14288 ,sysdate
14289 ,G_CONC_LOGIN_ID
14290 ,G_CONC_LOGIN_ID
14291 ,sysdate
14292 ,G_CONC_LOGIN_ID
14293 ,bcc.Txn_Ccid
14294 ,'R'
14295 ,'P'
14296 ,bcc.Je_Category_Name
14297 ,bcc.Je_Source_Name
14298 ,bcc.Org_Id
14299 ,X_ei_id
14300 ,l_po_line_id
14301 ,'EXP'
14302 ,X_ei_id
14303 ,1
14304 ,p_txn_interface_id --REL12
14305 ,bcc.encumbrance_type_id
14306 ,bcc.document_header_id_2
14307 ,bcc.document_distribution_type
14308 From Pa_Bc_Commitments_all bcc
14309 Where bcc.Document_Header_Id = p_sys_ref2 -- Added for using index
14310 and bcc.Document_Distribution_Id = p_sys_ref5
14311 and bcc.packet_id = g_packet_id_tbl(i)
14312 and bcc.document_type = 'AP' ;
14313
14314 IF PG_DEBUG = 'Y' THEN
14315 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Inserted '||SQL%ROWCOUNT||' AP reversing raw and burden line(s) into bc packets');
14316 END IF;
14317
14318 END IF; --IF l_rec_bc_comm_exists = 'Y' AND p_comm_fc_req ='Y' THEN
14319
14320
14321 IF l_rec_pkt_comm_exists='Y' AND p_comm_fc_req ='Y' THEN
14322
14323 IF PG_DEBUG = 'Y' THEN
14324 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Before inserting the AP raw and burden lines from Bc Packets');
14325 END IF;
14326
14327 Insert Into Pa_Bc_Packets
14328 (Packet_Id
14329 ,Bc_Packet_Id
14330 ,Parent_Bc_Packet_Id
14331 ,Set_Of_Books_Id
14332 ,Gl_Date
14333 ,Period_Name
14334 ,Period_Year
14335 ,Pa_Date
14336 ,Project_Id
14337 ,Task_Id
14338 ,Expenditure_Type
14339 ,Expenditure_Item_Date
14340 ,Expenditure_Organization_Id
14341 ,Budget_Version_Id
14342 ,budget_line_id -- R12 funds management uptake
14343 ,Document_Type
14344 ,Document_Header_Id
14345 ,Document_Distribution_Id
14346 ,Entered_Dr
14347 ,Entered_Cr
14348 ,Accounted_Dr
14349 ,Accounted_Cr
14350 ,Request_Id
14351 ,Program_Id
14352 ,Program_Application_Id
14353 ,Program_Update_Date
14354 ,Actual_Flag
14355 ,Last_Update_Date
14356 ,Last_Updated_By
14357 ,Created_By
14358 ,Creation_Date
14359 ,Last_Update_Login
14360 ,Txn_Ccid
14361 ,Burden_Cost_Flag
14362 ,Status_Code
14363 ,Je_Category_Name
14364 ,Je_Source_Name
14365 ,Org_id
14366 ,Exp_Item_Id
14367 ,Document_Line_Id
14368 ,reference1
14369 ,reference2
14370 ,reference3
14371 ,txn_interface_id --REL12
14372 ,encumbrance_type_id
14373 ,document_header_id_2
14374 ,document_distribution_type
14375 )
14376 Select p_packet_id
14377 ,decode(bcc.Parent_Bc_Packet_Id,NULL,l_Raw_Bc_Packet_id,Pa_Bc_Packets_s.NextVal)
14378 ,decode(bcc.Parent_Bc_Packet_Id,NULL,NULL,l_Raw_Bc_Packet_id)
14379 ,bcc.Set_Of_Books_Id
14380 ,G_FC_Gl_Date
14381 ,G_FC_Period_Name
14382 ,bcc.Period_Year
14383 ,bcc.pa_date
14384 ,bcc.Project_Id
14385 ,bcc.Task_Id
14386 ,bcc.Expenditure_Type
14387 ,bcc.Expenditure_Item_Date
14388 ,bcc.Expenditure_Organization_Id
14389 ,bcc.Budget_Version_Id
14390 ,bcc.budget_line_id -- R12 funds management uptake
14391 ,bcc.Document_Type
14392 ,bcc.Document_Header_Id
14393 ,bcc.Document_Distribution_Id
14394 ,DECODE(bcc.Parent_Bc_Packet_Id,NULL,p_cash_pay_to_relieve
14395 ,pa_currency.round_trans_currency_amt1((p_cash_pay_to_relieve * bcc.compiled_multiplier),G_accounting_currency_code))
14396 ,0
14397 ,DECODE(bcc.Parent_Bc_Packet_Id,NULL,p_cash_pay_to_relieve
14398 ,pa_currency.round_trans_currency_amt1((p_cash_pay_to_relieve * bcc.compiled_multiplier),G_accounting_currency_code))
14399 ,0
14400 ,g_Request_Id
14401 ,G_Program_Id
14402 ,G_PROG_APPL_ID
14403 ,sysdate
14404 ,bcc.Actual_Flag
14405 ,sysdate
14406 ,G_CONC_LOGIN_ID
14407 ,G_CONC_LOGIN_ID
14408 ,sysdate
14409 ,G_CONC_LOGIN_ID
14410 ,bcc.Txn_Ccid
14411 ,'R'
14412 ,'P'
14413 ,bcc.Je_Category_Name
14414 ,bcc.Je_Source_Name
14415 ,bcc.Org_id
14416 ,X_ei_id
14417 ,l_po_line_id
14418 ,'EXP'
14419 ,X_ei_id
14420 ,1
14421 ,p_txn_interface_id --REL12
14422 ,bcc.encumbrance_type_id
14423 ,bcc.document_header_id_2
14424 ,bcc.document_distribution_type
14425 From Pa_Bc_Packets bcc
14426 Where bcc.packet_id = g_packet_id_tbl(i)
14427 and bcc.document_type = 'AP'
14428 -- Bug : 4962731
14429 -- : R12.PJ:XB1:QA:BC:INCORRECT AMOUNTS INTERFACED TO PROJECTS IN CASH BASED ACC
14430 and bcc.Document_Header_Id = p_sys_ref2 -- Added for using index
14431 and bcc.Document_Distribution_Id = p_sys_ref5
14432 and bcc.Status_Code in ('A','C');
14433
14434 IF PG_DEBUG = 'Y' THEN
14435 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Before inserting the AP raw and burden lines from Bc Packets');
14436 END IF;
14437
14438 END IF; --IF l_rec_pkt_comm_exists='Y' AND p_comm_fc_req ='Y' THEN
14439
14440 IF p_act_fc_req = 'Y' THEN
14441
14442 -- Insert the positive records for the raw line with
14443 -- document type 'EXP'.
14444
14445 IF PG_DEBUG = 'Y' THEN
14446 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Before inserting ACTUAL raw line from bc packets');
14447 END IF;
14448
14449 Insert Into Pa_Bc_Packets
14450 (Packet_Id
14451 ,Bc_Packet_Id
14452 ,Parent_Bc_Packet_Id
14453 ,Set_Of_Books_Id
14454 ,gl_date
14455 ,Period_Name
14456 ,Period_Year
14457 ,Pa_Date
14458 ,Project_Id
14459 ,Task_Id
14460 ,Expenditure_Type
14461 ,Expenditure_Item_Date
14462 ,Expenditure_Organization_Id
14463 ,Budget_Version_Id
14464 ,budget_line_id -- R12 funds management uptake
14465 ,Document_Type
14466 ,Document_Header_Id
14467 ,Document_Distribution_Id
14468 ,Entered_Dr
14469 ,Entered_Cr
14470 ,Accounted_Dr
14471 ,Accounted_Cr
14472 ,Request_Id
14473 ,Program_Id
14474 ,Program_Application_Id
14475 ,Program_Update_Date
14476 ,Actual_Flag
14477 ,Last_Update_Date
14478 ,Last_Updated_By
14479 ,Created_By
14480 ,Creation_Date
14481 ,Last_Update_Login
14482 ,Txn_Ccid
14483 ,Burden_Cost_Flag
14484 ,Status_Code
14485 ,Je_Category_Name
14486 ,Je_Source_Name
14487 ,Org_id
14488 ,Document_Line_Id
14489 ,reference1
14490 ,reference2
14491 ,reference3
14492 ,txn_interface_id --REL12
14493 ,vendor_id
14494 )
14495 Select p_Packet_Id
14496 ,Pa_Bc_Packets_s.NextVal
14497 ,-1
14498 ,g_sob_Id_tbl(i)
14499 ,G_FC_Gl_Date
14500 ,G_FC_Period_Name
14501 ,g_Period_Year_tbl(i)
14502 ,g_Pa_Date_tbl(i)
14503 ,g_project_id_tbl(i)
14504 ,g_task_id_tbl(i)
14505 ,g_exp_type_tbl(i)
14506 ,g_ei_date_tbl(i)
14507 ,g_exp_org_id_tbl(i)
14508 ,g_bud_ver_id_tbl(i)
14509 ,g_budget_line_id_tbl(i) -- R12 funds management uptake
14510 ,'EXP'
14511 ,X_ei_id
14512 ,1
14513 ,p_acct_raw_cost
14514 ,0
14515 ,p_acct_raw_cost
14516 ,0
14517 ,g_Request_Id
14518 ,g_program_id
14519 ,g_prog_appl_id
14520 ,sysdate
14521 ,'A'
14522 ,sysdate
14523 ,g_conc_login_id
14524 ,g_conc_login_id
14525 ,sysdate
14526 ,g_conc_login_id
14527 ,g_Txn_Ccid_tbl(i)
14528 ,'N'
14529 ,'P'
14530 ,'Expenditures'
14531 ,'Project Accounting'
14532 ,g_org_id_tbl(i)
14533 ,l_po_line_id
14534 ,'EXP'
14535 ,x_Ei_Id
14536 ,1
14537 ,p_txn_interface_id --REL12
14538 ,l_vendor_id
14539 From Pa_Budget_Versions bv,
14540 Pa_Budget_Types bt,
14541 pa_budgetary_control_options pbct
14542 Where bt.budget_type_Code = bv.budget_type_Code
14543 and bt.budget_amount_code = 'C'
14544 and bv.project_id = g_project_id_tbl(i)
14545 and bv.current_flag = 'Y'
14546 and pbct.project_id = bv.project_id
14547 and pbct.BDGT_CNTRL_FLAG = 'Y'
14548 and pbct.BUDGET_TYPE_CODE = bv.budget_type_code
14549 and (pbct.EXTERNAL_BUDGET_CODE = 'GL'
14550 OR
14551 pbct.EXTERNAL_BUDGET_CODE is NULL
14552 );
14553
14554 IF PG_DEBUG = 'Y' THEN
14555 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Inserted '||SQL%ROWCOUNT||' ACTUAL raw line(s) into bc packets');
14556 END IF;
14557
14558 END IF;--IF p_act_fc_req = 'Y' THEN
14559 END LOOP;
14560 END IF; -- l_rec_bc_comm_exists ='Y' OR l_rec_pkt_comm_exists = 'Y' THEN
14561
14562 END IF; -- p_comm_fc_req ='Y' OR p_act_fc_req = 'Y' THEN
14563
14564
14565 -- R12 AP lines uptake : Prepayment changes : Below insert will be fired for inserting 'EXP'
14566 -- records by fetching data from pa_transaction_interface_all table for below TXN records :
14567 -- a. Adjusting expenditures in txn_interface table
14568 -- b. For those commitments which were never FC'ed (eg : Prepayment application, pre-payment matched to PO ..)
14569
14570 IF ((p_adj_act_fc_req = 'Y')
14571 OR (l_rec_bc_comm_exists ='N' AND l_rec_pkt_comm_exists = 'N' AND p_act_fc_req = 'Y' )) THEN
14572
14573 IF PG_DEBUG = 'Y' THEN
14574 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Before inserting adjusted ACTUAL raw line from transaction import table');
14575 END IF;
14576
14577 FORALL i IN 1 .. g_xface_Txn_interface_tbl.count
14578 Insert Into Pa_Bc_Packets
14579 (Packet_Id
14580 ,Bc_Packet_Id
14581 ,Parent_Bc_Packet_Id
14582 ,Set_Of_Books_Id
14583 ,Gl_Date
14584 ,Period_Name
14585 ,Period_Year
14586 ,Pa_Date
14587 ,Project_Id
14588 ,Task_Id
14589 ,Expenditure_Type
14590 ,Expenditure_Item_Date
14591 ,Expenditure_Organization_Id
14592 ,Budget_Version_Id
14593 ,Document_Type
14594 ,Document_Header_Id
14595 ,Document_Distribution_Id
14596 ,Entered_Dr
14597 ,Entered_Cr
14598 ,Accounted_Dr
14599 ,Accounted_Cr
14600 ,Request_Id
14601 ,Program_Id
14602 ,Program_Application_Id
14603 ,Program_Update_Date
14604 ,Actual_Flag
14605 ,Last_Update_Date
14606 ,Last_Updated_By
14607 ,Created_By
14608 ,Creation_Date
14609 ,Last_Update_Login
14610 ,Txn_Ccid
14611 ,Burden_Cost_Flag
14612 ,Status_Code
14613 ,Je_Category_Name
14614 ,Je_Source_Name
14615 ,Org_id
14616 ,Document_Line_Id
14617 ,reference1
14618 ,reference2
14619 ,reference3
14620 ,txn_interface_id --REL12
14621 ,vendor_id
14622 )
14623 Select p_Packet_Id
14624 ,Pa_Bc_Packets_s.NextVal
14625 ,-1
14626 ,g_sobid
14627 ,G_FC_Gl_Date
14628 ,G_FC_Period_Name
14629 ,G_FC_Period_Year
14630 ,G_PaDate
14631 ,g_xface_project_id_tbl(i)
14632 ,g_xface_task_id_tbl(i)
14633 ,g_xface_exp_type_tbl(i)
14634 ,g_xface_ei_date_tbl(i)
14635 ,g_xface_exp_org_id_tbl(i)
14636 ,g_xface_bud_ver_id_tbl(i)
14637 ,'EXP'
14638 ,X_ei_id
14639 ,1
14640 -- R12 AP lines uptake : Prepayment changes
14641 -- For Prepayment application/pre-payment matched to PO records consider p_acct_raw_cost as amount
14642 ,g_xface_Entered_Dr_tbl(i)
14643 ,g_xface_acct_Cr_tbl(i)
14644 ,g_xface_acct_Dr_tbl(i)
14645 ,g_xface_acct_Cr_tbl(i)
14646 ,g_Request_Id
14647 ,g_program_id
14648 ,g_prog_appl_id
14649 ,sysdate
14650 ,'A' --Actual_Flag
14651 ,sysdate
14652 ,g_conc_login_id
14653 ,g_conc_login_id
14654 ,sysdate
14655 ,g_conc_login_id
14656 ,g_xface_Txn_Ccid_tbl(i)
14657 ,'N'
14658 ,'P'
14659 ,'Expenditures'
14660 ,'Project Accounting'
14661 ,g_xface_org_id_tbl(i)
14662 ,l_po_line_id
14663 ,'EXP'
14664 ,X_Ei_Id
14665 ,1
14666 ,g_xface_Txn_interface_tbl(i) --REL12
14667 ,g_xface_vendor_id_tbl(i)
14668 From dual;
14669
14670 IF PG_DEBUG = 'Y' THEN
14671 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - Before inserting adjusted ACTUAL raw line from transaction import table');
14672 END IF;
14673
14674 END IF;
14675
14676 COMMIT;
14677 IF PG_DEBUG = 'Y' THEN
14678 log_message('log_message: ' || 'In insert_cash_ap_bc_pkt_auto - End');
14679 END IF;
14680
14681 EXCEPTION
14682 WHEN OTHERS THEN
14683 IF PG_DEBUG = 'Y' THEN
14684 log_message('log_message: In insert_cash_ap_bc_pkt_auto exception' || sqlerrm||' Returning from insert_cash_ap_bc_pkt_auto');
14685 END IF;
14686 RAISE;
14687 END insert_cash_ap_bc_pkt_auto;
14688
14689 -- R12 funds management Uptake : New procedure fired in non-autonomous mode to read
14690 -- pa_transaction_interface_all table and to derive variables which drives the
14691 -- relieving/reserving of commitments and actuals flow during interface.
14692
14693 PROCEDURE insert_po_bc_packets
14694 (p_packet_id IN NUMBER,
14695 p_sys_ref2 IN NUMBER,
14696 p_sys_ref4 IN NUMBER,
14697 p_sys_ref3 IN NUMBER,
14698 p_acct_raw_cost IN NUMBER,
14699 p_cmt_raw_cost IN NUMBER,
14700 p_fc_document_type IN VARCHAR2,
14701 p_txn_source IN VARCHAR2,
14702 p_adj_exp_item_id IN NUMBER,
14703 p_txn_interface_id IN NUMBER) IS
14704
14705 -- Cursor to fetch data from pa_transaction_interface_table.This data is later used
14706 -- in autonomous fundscheck insert_ap_bc_pkts_autonomous procedure.
14707
14708 CURSOR c_pa_txn_interface_data IS
14709 Select txn.Project_Id
14710 ,txn.Task_Id
14711 ,txn.Expenditure_Type
14712 ,txn.Expenditure_Item_Date
14713 ,nvl(txn.OVERRIDE_TO_ORGANIZATION_ID,txn.Org_Id)
14714 ,bv.Budget_Version_Id
14715 -- R12 AP lines uptake : Prepayment changes
14716 -- For Prepayment application/pre-payment matched to PO records consider p_acct_raw_cost as amount
14717 ,txn.acct_raw_cost
14718 ,0
14719 ,txn.acct_raw_cost
14720 ,0
14721 ,txn.cr_code_combination_id
14722 ,txn.Org_id
14723 ,txn.txn_interface_id --REL12
14724 ,txn.vendor_id
14725 From Pa_Budget_Versions bv,
14726 Pa_Budget_Types bt,
14727 pa_budgetary_control_options pbct,
14728 pa_transaction_interface_all txn
14729 Where bv.budget_type_code = bt.budget_type_code
14730 and bt.budget_amount_code = 'C'
14731 and bv.current_flag = 'Y'
14732 AND pbct.project_id = bv.project_id
14733 AND pbct.BDGT_CNTRL_FLAG = 'Y'
14734 AND pbct.BUDGET_TYPE_CODE = bv.budget_type_code
14735 AND (pbct.EXTERNAL_BUDGET_CODE = 'GL'
14736 OR
14737 pbct.EXTERNAL_BUDGET_CODE is NULL
14738 )
14739 AND bv.project_id = txn.project_id
14740 and txn.TRANSACTION_SOURCE = p_txn_source -- Condition for using index
14741 -- new index usage needs to be verified for below columns
14742 AND txn.cdl_system_reference2 = p_sys_ref2
14743 AND txn.cdl_system_reference3 = p_sys_ref3 --Bug 5550268
14744 --Bug 5550268 : Will be NULL when fired from ap_po_fundscheck_check
14745 AND (txn.cdl_system_reference4 = p_sys_ref4 OR p_sys_ref4 IS NULL)
14746 AND txn.fc_document_type in ('ACT','ALL')
14747 AND txn.adjusted_expenditure_item_id IS NOT NULL;
14748
14749 l_comm_fc_req VARCHAR2(1); -- Variable to identify whether commitment fundscheck is required
14750 l_act_fc_req VARCHAR2(1); -- Variable to identify whether actual fundscheck is required
14751 l_adj_act_fc_req VARCHAR2(1); -- Variable to identify whether adjusted actual fundscheck is required
14752
14753 BEGIN
14754
14755 IF PG_DEBUG = 'Y' THEN
14756 log_message('log_message: ' || 'In insert_po_bc_packets - Start');
14757 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_packet_id '||p_packet_id);
14758 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_sys_ref2 '||p_sys_ref2 );
14759 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_sys_ref4 '||p_sys_ref4 );
14760 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_sys_ref3 '||p_sys_ref3 );
14761 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_acct_raw_cost '||p_acct_raw_cost);
14762 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_cmt_raw_cost '||p_cmt_raw_cost); -- Bug 5731450
14763 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_fc_document_type '||p_fc_document_type );
14764 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_txn_source '||p_txn_source);
14765 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_adj_exp_item_id '||p_adj_exp_item_id);
14766 log_message('log_message: ' || 'In insert_po_bc_packets - Value of p_txn_interface_id '||p_txn_interface_id);
14767
14768 END IF;
14769
14770 -- Code to derive values for variables which will decide the flow of this procedure
14771
14772 l_comm_fc_req :='N'; -- Variable to identify whether commitment fundscheck is required
14773 l_act_fc_req :='N'; -- Variable to identify whether actual fundscheck is required
14774 l_adj_act_fc_req:='N'; -- Variable to identify whether adjusted actual fundscheck is required
14775
14776 -- Deriving value for variable which identifies if FC required for AP commitment
14777 IF p_adj_exp_item_id IS NULL THEN
14778
14779 IF p_fc_document_type ='ALL' THEN --PO normal lines import
14780 l_comm_fc_req := 'Y' ;
14781 l_act_fc_req := 'Y' ;
14782 END IF;
14783
14784 ELSIF p_adj_exp_item_id IS NOT NULL THEN
14785
14786 IF p_fc_document_type ='ALL' THEN --PO having fc enabled and adjusted ei's having fc enabled
14787 l_comm_fc_req := 'Y' ;
14788 l_adj_act_fc_req := 'Y';
14789 ELSIF p_fc_document_type ='CMT' THEN --PO having fc enabled and adjusted ei's having fc disabled
14790 l_comm_fc_req := 'Y' ;
14791 ELSIF p_fc_document_type ='ACT' THEN --PO having fc disabled and adjusted ei's having fc ENabled
14792 l_adj_act_fc_req := 'Y';
14793 END IF;
14794
14795 END IF;
14796
14797 IF PG_DEBUG = 'Y' THEN
14798 log_message('log_message: ' || 'In insert_po_bc_packets - Value of l_comm_fc_req '||l_comm_fc_req);
14799 log_message('log_message: ' || 'In insert_po_bc_packets - Value of l_adj_act_fc_req '||l_adj_act_fc_req );
14800 log_message('log_message: ' || 'In insert_po_bc_packets - Value of l_act_fc_req '||l_act_fc_req );
14801 END IF;
14802
14803 -- Cursor to fetch data from pa_transaction_interface_table.This data is later used
14804 -- in autonomous fundscheck insert_ap_bc_pkts_autonomous procedure.
14805
14806 IF ( l_adj_act_fc_req = 'Y' OR l_act_fc_req = 'Y' ) THEN
14807
14808 -- call to clean up global plsql arrays used for storing interface data.
14809 init_xface_plsql_tables;
14810
14811 OPEN c_pa_txn_interface_data;
14812 FETCH c_pa_txn_interface_data BULK COLLECT INTO
14813 g_xface_project_id_tbl,
14814 g_xface_task_id_tbl,
14815 g_xface_exp_type_tbl,
14816 g_xface_ei_date_tbl,
14817 g_xface_exp_org_id_tbl,
14818 g_xface_bud_ver_id_tbl,
14819 g_xface_Entered_Dr_tbl,
14820 g_xface_Entered_Cr_tbl,
14821 g_xface_acct_Dr_tbl,
14822 g_xface_acct_Cr_tbl,
14823 g_xface_Txn_Ccid_tbl,
14824 g_xface_org_id_tbl,
14825 g_xface_Txn_interface_tbl,
14826 g_xface_vendor_id_tbl;
14827 CLOSE c_pa_txn_interface_data;
14828
14829 IF PG_DEBUG = 'Y' THEN
14830 log_message('log_message: ' || 'In insert_po_bc_packets - fetched data from interface table c_pa_txn_interface_data ');
14831 END IF;
14832
14833 END IF; --IF ( l_adj_act_fc_req = 'Y' OR l_act_fc_req = 'Y' ) THEN
14834
14835 IF PG_DEBUG = 'Y' THEN
14836 log_message('log_message: ' || 'In insert_po_bc_packets - calling insert_po_bc_packets_auto');
14837 END IF;
14838
14839 insert_po_bc_packets_auto
14840 (p_packet_id => p_packet_id,
14841 p_sys_ref2 => p_sys_ref2,
14842 p_sys_ref4 => p_sys_ref4,
14843 p_sys_ref3 => p_sys_ref3,
14844 p_acct_raw_cost => p_acct_raw_cost,
14845 p_cmt_raw_cost => p_cmt_raw_cost,
14846 p_fc_document_type => p_fc_document_type,
14847 p_txn_source => p_txn_source,
14848 p_adj_exp_item_id => p_adj_exp_item_id ,
14849 p_txn_interface_id => p_txn_interface_id,
14850 p_comm_fc_req => l_comm_fc_req,
14851 p_act_fc_req => l_act_fc_req,
14852 p_adj_act_fc_req => l_adj_act_fc_req );
14853
14854 IF PG_DEBUG = 'Y' THEN
14855 log_message('log_message: ' || 'In insert_po_bc_packets - End');
14856 END IF;
14857
14858 EXCEPTION
14859 WHEN OTHERS THEN
14860 IF PG_DEBUG = 'Y' THEN
14861 log_message('log_message:I n insert_po_bc_packets exception' || sqlerrm||' Returning from insert_po_bc_packets');
14862 END IF;
14863 RAISE;
14864 END insert_po_bc_packets;
14865
14866 PROCEDURE insert_po_bc_packets_auto
14867 (p_packet_id IN NUMBER,
14868 p_sys_ref2 IN NUMBER,
14869 p_sys_ref4 IN NUMBER,
14870 p_sys_ref3 IN NUMBER,
14871 p_acct_raw_cost IN NUMBER,
14872 p_cmt_raw_cost IN NUMBER,
14873 p_fc_document_type IN VARCHAR2,
14874 p_txn_source IN VARCHAR2,
14875 p_adj_exp_item_id IN NUMBER,
14876 p_txn_interface_id IN NUMBER,
14877 p_comm_fc_req IN VARCHAR2,
14878 p_act_fc_req IN VARCHAR2,
14879 p_adj_act_fc_req IN VARCHAR2) IS
14880 CURSOR c_gen_raw_bc_pkt IS
14881 SELECT Pa_Bc_Packets_s.NextVal
14882 FROM dual;
14883
14884 CURSOR c_get_po_LINE_id (p_po_dist_id NUMBER) IS
14885 SELECT po_line_id
14886 FROM po_distributions_all
14887 WHERE po_distribution_id = p_po_dist_id;
14888
14889 -- Added for 13966205
14890 CURSOR C_GET_EI_DATE IS
14891 select distinct expenditure_item_date
14892 from pa_transaction_interface_all
14893 where txn_interface_id = p_txn_interface_id;
14894
14895 Cursor C_po_Commitment Is
14896 Select bcc.Set_Of_Books_Id
14897 ,bcc.Period_Year
14898 ,bcc.Project_Id
14899 ,bcc.Task_Id
14900 ,bcc.Expenditure_Type
14901 ,bcc.Expenditure_Item_Date
14902 ,bcc.Expenditure_Organization_Id
14903 ,bcc.Budget_Version_Id
14904 ,bcc.budget_line_id -- R12 funds management uptake
14905 ,bcc.Document_Type
14906 ,bcc.Document_Header_Id
14907 ,bcc.Document_Distribution_Id
14908 ,bcc.Entered_Cr
14909 ,bcc.Entered_Dr
14910 ,bcc.Accounted_Cr
14911 ,bcc.Accounted_Dr
14912 ,bcc.Actual_Flag
14913 ,bcc.Txn_Ccid
14914 ,bcc.Je_Category_Name
14915 ,bcc.Je_Source_Name
14916 ,bcc.Org_Id
14917 ,bcc.Pa_Date
14918 ,bcc.bc_packet_id
14919 ,bcc.packet_id
14920 ,bcc.bc_commitment_id
14921 ,bcc.vendor_id
14922 From Pa_Bc_Commitments_all bcc,
14923 po_distributions pod
14924 -- R12 Funds management Uptake : For fixing performance issues removing the code for CC which is obsolete for R12
14925 -- Modifying code to use Index on document_header_id and document_distribution_id of bc commitments
14926 where bcc.document_header_id = pod.po_header_id
14927 and bcc.document_distribution_id = pod.po_distribution_id
14928 and bcc.project_id = pod.project_id -- Bug# 4479105
14929 and bcc.task_id = pod.task_id --Bug# 4479105
14930 and bcc.expenditure_type = pod.expenditure_type -- Bug7620577
14931 and bcc.document_type = 'PO'
14932 and pod.po_header_id = p_sys_ref2
14933 and pod.po_distribution_id = p_sys_ref3
14934 and bcc.exp_item_id IS NULL -- Bug 5014138 : to pick just the encumbrance record
14935 and bcc.actual_flag = 'E' -- Bug 5014138 : to pick just the encumbrance record
14936 and bcc.Parent_Bc_Packet_Id is NULL
14937 Order By bcc.packet_id;
14938
14939 Cursor C_po_Bc_Packets Is
14940 Select bcc.Set_Of_Books_Id
14941 ,bcc.Period_Year
14942 ,bcc.Project_Id
14943 ,bcc.Task_Id
14944 ,bcc.Expenditure_Type
14945 ,bcc.Expenditure_Item_Date
14946 ,bcc.Expenditure_Organization_Id
14947 ,bcc.Budget_Version_Id
14948 ,bcc.budget_line_id -- R12 funds management uptake
14949 ,bcc.Document_Type
14950 ,bcc.Document_Header_Id
14951 ,bcc.Document_Distribution_Id
14952 ,bcc.Entered_Cr
14953 ,bcc.Entered_Dr
14954 ,bcc.Accounted_Cr
14955 ,bcc.Accounted_Dr
14956 ,bcc.Actual_Flag
14957 ,bcc.Txn_Ccid
14958 ,bcc.Je_Category_Name
14959 ,bcc.Je_Source_Name
14960 ,bcc.Org_Id
14961 ,bcc.Pa_Date
14962 ,bcc.bc_packet_id
14963 ,bcc.packet_id
14964 ,bcc.vendor_id
14965 -- R12 Funds management Uptake : For fixing performance issues removing the code for CC which is obsolete for R12
14966 -- Modifying code to use Index on document_header_id and document_distribution_id of bc commitments
14967 From Pa_Bc_packets bcc,
14968 po_distributions pod
14969 where bcc.document_header_id = pod.po_header_id
14970 and bcc.document_distribution_id = pod.po_distribution_id
14971 and bcc.project_id = pod.project_id -- Bug# 4479105
14972 and bcc.task_id = pod.task_id --Bug# 4479105
14973 and bcc.expenditure_type = pod.expenditure_type -- Bug7620577
14974 and bcc.document_type = 'PO'
14975 and pod.po_header_id = p_sys_ref2
14976 and pod.po_distribution_id = p_sys_ref3
14977 and bcc.exp_item_id IS NULL -- Bug 5014138 : to pick just the encumbrance record
14978 and bcc.actual_flag = 'E' -- Bug 5014138 : to pick just the encumbrance record
14979 and bcc.Status_Code in('A','C')
14980 and bcc.Parent_Bc_Packet_Id is NULL
14981 Order By bcc.packet_id;
14982
14983 l_rec_bc_comm_exists VARCHAR2(1); -- Variable to identify whether commitment record exists in pa_bc_commitments
14984 l_rec_pkt_comm_exists VARCHAR2(1); -- Variable to identify whether commitment record exists in pa_bc_packets
14985 l_Raw_Bc_Packet_Id pa_bc_packets.bc_packet_id%TYPE;
14986 l_po_line_id po_distributions_all.po_line_id%TYPE;
14987 l_expenditure_item_date pa_expenditure_items_all.expenditure_item_date%TYPE; -- Aded for 16451280
14988
14989 BEGIN
14990
14991 IF PG_DEBUG = 'Y' THEN
14992 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Start');
14993 END IF;
14994
14995 /* cwk */
14996
14997 IF p_txn_source in ('PO RECEIPT NRTAX', 'AP NRTAX') THEN
14998 IF nvl(Pa_Pjc_Cwk_Utils.Is_rate_based_line( null, p_sys_ref3),'N') = 'Y' THEN
14999 OPEN c_get_po_LINE_id(p_sys_ref3);
15000 FETCH c_get_po_LINE_id into l_po_line_id;
15001 CLOSE c_get_po_LINE_id;
15002 END IF;
15003
15004 IF PG_DEBUG = 'Y' THEN
15005 log_message('log_message: ' || 'In insert_po_bc_packets_auto - After fetching CWK related data l_po_line_id'||l_po_line_id);
15006 END IF;
15007 END IF;
15008
15009 -- Code to derive values for variables which will decide the flow of this procedure
15010
15011 l_rec_bc_comm_exists:='N'; -- Variable to identify whether commitment record exists in pa_bc_commitments
15012 l_rec_pkt_comm_exists:='N'; -- Variable to identify whether commitment record exists in pa_bc_packets
15013
15014 IF p_comm_fc_req ='Y' OR p_act_fc_req = 'Y' THEN
15015
15016 IF PG_DEBUG = 'Y' THEN
15017 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Fetchign data from bc commitments');
15018 END IF;
15019
15020 Open C_po_Commitment ;
15021
15022 clear_plsql_tables;
15023
15024 FETCH C_po_Commitment BULK COLLECT INTO
15025 g_sob_Id_tbl,
15026 g_Period_Year_tbl,
15027 g_project_id_tbl,
15028 g_task_id_tbl,
15029 g_exp_type_tbl,
15030 g_ei_date_tbl,
15031 g_exp_org_id_tbl,
15032 g_bud_ver_id_tbl,
15033 g_budget_line_id_tbl, -- R12 funds management uptake
15034 g_Document_Type_tbl,
15035 g_Doc_Header_Id_tbl,
15036 g_Doc_dist_Id_tbl,
15037 g_Entered_Cr_tbl,
15038 g_Entered_Dr_tbl,
15039 g_acct_Cr_tbl,
15040 g_acct_Dr_tbl,
15041 g_Actual_Flag_tbl,
15042 g_Txn_Ccid_tbl,
15043 g_Je_Catg_Name_tbl,
15044 g_Je_sorce_Name_tbl,
15045 g_org_id_tbl,
15046 g_Pa_Date_tbl,
15047 g_bc_packet_id_tbl,
15048 g_packet_id_tbl,
15049 g_bc_comt_id_tbl,
15050 g_vendor_id_tbl LIMIT 1; /* Intended for the bug#9234914 */
15051
15052 IF g_bc_packet_id_tbl.COUNT <> 0 THEN
15053 l_rec_bc_comm_exists := 'Y';
15054 END IF;
15055 CLOSE C_po_Commitment;
15056
15057 IF l_rec_bc_comm_exists = 'N' THEN
15058
15059 IF PG_DEBUG = 'Y' THEN
15060 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Fetchign data from bc packets');
15061 END IF;
15062
15063 OPEN C_po_Bc_Packets;
15064 FETCH C_po_Bc_Packets BULK COLLECT INTO
15065 g_sob_Id_tbl,
15066 g_Period_Year_tbl,
15067 g_project_id_tbl,
15068 g_task_id_tbl,
15069 g_exp_type_tbl,
15070 g_ei_date_tbl,
15071 g_exp_org_id_tbl,
15072 g_bud_ver_id_tbl,
15073 g_budget_line_id_tbl, -- R12 funds management uptake
15074 g_Document_Type_tbl,
15075 g_Doc_Header_Id_tbl,
15076 g_Doc_dist_Id_tbl,
15077 g_Entered_Cr_tbl,
15078 g_Entered_Dr_tbl,
15079 g_acct_Cr_tbl,
15080 g_acct_Dr_tbl,
15081 g_Actual_Flag_tbl,
15082 g_Txn_Ccid_tbl,
15083 g_Je_Catg_Name_tbl,
15084 g_Je_sorce_Name_tbl,
15085 g_org_id_tbl,
15086 g_Pa_Date_tbl,
15087 g_bc_packet_id_tbl,
15088 g_packet_id_tbl ,
15089 g_vendor_id_tbl LIMIT 1; /* Intended for the bug#9234914 */
15090
15091 IF g_bc_packet_id_tbl.COUNT <> 0 THEN
15092 l_rec_pkt_comm_exists := 'Y' ;
15093 END IF;
15094 CLOSE C_po_Bc_Packets;
15095
15096 END IF;
15097
15098 OPEN c_get_ei_date;
15099 FETCH c_get_ei_date INTO l_expenditure_item_date;
15100 CLOSE c_get_ei_date;
15101
15102 IF l_rec_bc_comm_exists ='Y' OR l_rec_pkt_comm_exists = 'Y' THEN
15103
15104 FOR i IN g_bc_packet_id_tbl.FIRST..g_bc_packet_id_tbl.LAST LOOP
15105
15106
15107 -- Generate a packet identifier for RAW record that
15108 -- needs to be inserted into Pa BC Packets
15109
15110 IF PG_DEBUG = 'Y' THEN
15111 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Generating new Bc packet Id for reversing RAW act and commitment line');
15112 END IF;
15113
15114 OPEN c_gen_raw_bc_pkt;
15115 FETCH c_gen_raw_bc_pkt INTO l_Raw_Bc_Packet_Id;
15116 CLOSE c_gen_raw_bc_pkt;
15117
15118 IF PG_DEBUG = 'Y' THEN
15119 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Bc Packet Id = ' || l_Raw_Bc_Packet_Id ||'Packet Id = ' || p_packet_id);
15120 END IF;
15121
15122 IF l_rec_bc_comm_exists = 'Y' AND p_comm_fc_req ='Y' THEN
15123
15124 IF PG_DEBUG = 'Y' THEN
15125 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Before inserting PO reversing raw and burden line from bc commitments');
15126 END IF;
15127
15128 Insert Into Pa_Bc_Packets
15129 (Packet_Id
15130 ,Bc_Packet_Id
15131 ,Parent_Bc_Packet_Id
15132 ,Set_Of_Books_Id
15133 ,Gl_Date
15134 ,Period_Name
15135 ,Period_Year
15136 ,Pa_Date
15137 ,Project_Id
15138 ,Task_Id
15139 ,Expenditure_Type
15140 ,Expenditure_Item_Date
15141 ,Expenditure_Organization_Id
15142 ,Budget_Version_Id
15143 ,Budget_line_id -- R12 funds management uptake
15144 ,Document_Type
15145 ,Document_Header_Id
15146 ,Document_Distribution_Id
15147 ,Entered_Dr
15148 ,Entered_Cr
15149 ,Accounted_Dr
15150 ,Accounted_Cr
15151 ,Request_Id
15152 ,Program_Id
15153 ,Program_Application_Id
15154 ,Program_Update_Date
15155 ,Actual_Flag
15156 ,Last_Update_Date
15157 ,Last_Updated_By
15158 ,Created_By
15159 ,Creation_Date
15160 ,Last_Update_Login
15161 ,Txn_Ccid
15162 ,Burden_Cost_Flag
15163 ,Status_Code
15164 ,Je_Category_Name
15165 ,Je_Source_Name
15166 ,Org_id
15167 ,Exp_Item_Id
15168 ,Document_Line_Id
15169 ,reference1
15170 ,reference2
15171 ,reference3
15172 ,txn_interface_id --REL12
15173 ,encumbrance_type_id
15174 ,document_header_id_2
15175 ,document_distribution_type
15176 )
15177 Select p_packet_id
15178 ,decode(bcc.Parent_Bc_Packet_Id,NULL,l_Raw_Bc_Packet_id,Pa_Bc_Packets_s.NextVal)
15179 ,decode(bcc.Parent_Bc_Packet_Id,NULL,NULL,l_Raw_Bc_Packet_id)
15180 ,bcc.Set_Of_Books_Id
15181 ,G_FC_Gl_Date
15182 ,G_FC_Period_Name
15183 ,bcc.Period_Year
15184 -- ,bcc.Pa_Date -- pa_date on raw is used for burden line /* changed to g_padate for 16451280 */
15185 , G_PADATE
15186 ,bcc.Project_Id
15187 ,bcc.Task_Id
15188 ,bcc.Expenditure_Type
15189 ,l_Expenditure_Item_Date
15190 ,bcc.Expenditure_Organization_Id
15191 ,bcc.Budget_Version_Id
15192 ,bcc.Budget_line_id -- R12 funds management uptake
15193 ,bcc.Document_Type
15194 ,bcc.Document_Header_Id
15195 ,bcc.Document_Distribution_Id
15196 ,DECODE(bcc.parent_bc_packet_id,NULL,
15197 (-1 * p_cmt_raw_cost), --rshaik
15198 (0 - (pa_currency.round_trans_currency_amt1((((nvl(bcc.Entered_dr,0)-nvl(bcc.Entered_Cr,0))/
15199 decode((nvl(g_Entered_Dr_tbl(i),0)-nvl(g_Entered_Cr_tbl(i),0)),
15200 0,1,(nvl(g_Entered_Dr_tbl(i),0)-nvl(g_Entered_Cr_tbl(i),0))))
15201 *p_cmt_raw_cost), G_accounting_currency_code))))
15202 ,0
15203 ,DECODE(bcc.parent_bc_packet_id,NULL,
15204 (-1 * p_cmt_raw_cost)
15205 ,(0 - (pa_currency.round_trans_currency_amt1((((nvl(bcc.Accounted_dr,0)-nvl(bcc.Accounted_cr,0))/
15206 decode((nvl(g_acct_Dr_tbl(i),0)-nvl(g_acct_Cr_tbl(i),0))
15207 ,0,1,(nvl(g_acct_Dr_tbl(i),0)-nvl(g_acct_Cr_tbl(i),0))))
15208 *p_cmt_raw_cost), G_accounting_currency_code))))
15209 ,0
15210 ,g_Request_Id
15211 ,G_Program_Id
15212 ,G_PROG_APPL_ID
15213 ,sysdate
15214 ,bcc.Actual_Flag
15215 ,sysdate
15216 ,G_CONC_LOGIN_ID
15217 ,G_CONC_LOGIN_ID
15218 ,sysdate
15219 ,G_CONC_LOGIN_ID
15220 ,bcc.Txn_Ccid
15221 ,'R'
15222 ,'P'
15223 ,decode(p_txn_source, 'AP NRTAX' , g_Je_Catg_Name_tbl(i)||' Tax', g_Je_Catg_Name_tbl(i))
15224 ,bcc.Je_Source_Name
15225 ,bcc.Org_Id
15226 ,X_ei_id
15227 ,l_po_line_id
15228 ,'EXP'
15229 ,X_ei_id
15230 ,1
15231 ,p_txn_interface_id --REL12
15232 ,bcc.encumbrance_type_id
15233 ,bcc.document_header_id_2
15234 ,bcc.document_distribution_type
15235 From Pa_Bc_Commitments_all bcc
15236 Where bcc.bc_commitment_id in (SELECT bcc1.bc_commitment_id
15237 FROM PA_BC_COMMITMENTS_ALL bcc1
15238 WHERE bcc1.document_header_id = p_sys_ref2
15239 AND bcc1.document_distribution_id = p_sys_ref3
15240 AND bcc1.parent_bc_packet_id = g_bc_packet_id_tbl(i)
15241 UNIOn ALL
15242 SELECT g_bc_comt_id_tbl(i)
15243 FROM DUAL);
15244
15245 IF PG_DEBUG = 'Y' THEN
15246 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Inserted '||SQL%ROWCOUNT||' PO reversing raw and burden line(s) into bc packets');
15247 END IF;
15248
15249 END IF; --IF l_rec_bc_comm_exists = 'Y' AND p_comm_fc_req ='Y' THEN
15250
15251
15252 IF l_rec_pkt_comm_exists='Y' AND p_comm_fc_req ='Y' THEN
15253
15254 IF PG_DEBUG = 'Y' THEN
15255 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Before inserting the PO raw and burden lines from Bc Packets');
15256 END IF;
15257
15258 Insert Into Pa_Bc_Packets
15259 (Packet_Id
15260 ,Bc_Packet_Id
15261 ,Parent_Bc_Packet_Id
15262 ,Set_Of_Books_Id
15263 ,Gl_Date
15264 ,Period_Name
15265 ,Period_Year
15266 ,Pa_Date
15267 ,Project_Id
15268 ,Task_Id
15269 ,Expenditure_Type
15270 ,Expenditure_Item_Date
15271 ,Expenditure_Organization_Id
15272 ,Budget_Version_Id
15273 ,Budget_line_id -- R12 funds management uptake
15274 ,Document_Type
15275 ,Document_Header_Id
15276 ,Document_Distribution_Id
15277 ,Entered_Dr
15278 ,Entered_Cr
15279 ,Accounted_Dr
15280 ,Accounted_Cr
15281 ,Request_Id
15282 ,Program_Id
15283 ,Program_Application_Id
15284 ,Program_Update_Date
15285 ,Actual_Flag
15286 ,Last_Update_Date
15287 ,Last_Updated_By
15288 ,Created_By
15289 ,Creation_Date
15290 ,Last_Update_Login
15291 ,Txn_Ccid
15292 ,Burden_Cost_Flag
15293 ,Status_Code
15294 ,Je_Category_Name
15295 ,Je_Source_Name
15296 ,Org_id
15297 ,Exp_Item_Id
15298 ,Document_Line_Id
15299 ,reference1
15300 ,reference2
15301 ,reference3
15302 ,txn_interface_id --REL12
15303 ,encumbrance_type_id
15304 ,document_header_id_2
15305 ,document_distribution_type
15306 )
15307 Select p_packet_id
15308 ,decode(bcc.Parent_Bc_Packet_Id,NULL,l_Raw_Bc_Packet_id,Pa_Bc_Packets_s.NextVal)
15309 ,decode(bcc.Parent_Bc_Packet_Id,NULL,NULL,l_Raw_Bc_Packet_id)
15310 ,bcc.Set_Of_Books_Id
15311 ,G_FC_Gl_Date
15312 ,G_FC_Period_Name
15313 ,bcc.Period_Year
15314 --,bcc.pa_date /* changed to g_padate for 16451280 */
15315 ,G_PADATE
15316 ,bcc.Project_Id
15317 ,bcc.Task_Id
15318 ,bcc.Expenditure_Type
15319 --,bcc.Expenditure_Item_Date /* changed to l_expenditure_item_date for 16451280 */
15320 ,l_expenditure_item_date
15321 ,bcc.Expenditure_Organization_Id
15322 ,bcc.Budget_Version_Id
15323 ,bcc.Budget_line_id -- R12 funds management uptake
15324 ,bcc.Document_Type
15325 ,bcc.Document_Header_Id
15326 ,bcc.Document_Distribution_Id
15327 ,DECODE(bcc.parent_bc_packet_id,NULL,
15328 -1 * p_cmt_raw_cost,
15329 (0 - (pa_currency.round_trans_currency_amt1((((nvl(bcc.Entered_dr,0)-nvl(bcc.Entered_Cr,0))/
15330 decode((nvl(g_Entered_Dr_tbl(i),0)-nvl(g_Entered_Cr_tbl(i),0)),
15331 0,1,(nvl(g_Entered_Dr_tbl(i),0)-nvl(g_Entered_Cr_tbl(i) ,0))))
15332 *p_cmt_raw_cost), G_accounting_currency_code))))
15333 ,0
15334 ,DECODE(bcc.parent_bc_packet_id,NULL,
15335 -1 * p_cmt_raw_cost
15336 ,(0 - (pa_currency.round_trans_currency_amt1((((nvl(bcc.Accounted_dr,0)-nvl(bcc.Accounted_cr,0))/
15337 decode((nvl(g_acct_Dr_tbl(i),0)-nvl(g_acct_Cr_tbl(i),0))
15338 ,0,1,(nvl(g_acct_Dr_tbl(i),0)-nvl(g_acct_Cr_tbl(i),0))))
15339 *p_cmt_raw_cost), G_accounting_currency_code))))
15340 ,0
15341 ,g_Request_Id
15342 ,G_Program_Id
15343 ,G_PROG_APPL_ID
15344 ,sysdate
15345 ,bcc.Actual_Flag
15346 ,sysdate
15347 ,G_CONC_LOGIN_ID
15348 ,G_CONC_LOGIN_ID
15349 ,sysdate
15350 ,G_CONC_LOGIN_ID
15351 ,bcc.Txn_Ccid
15352 ,'R'
15353 ,'P'
15354 ,bcc.Je_Category_Name
15355 ,bcc.Je_Source_Name
15356 ,bcc.Org_id
15357 ,X_ei_id
15358 ,l_po_line_id
15359 ,'EXP'
15360 ,X_ei_id
15361 ,1
15362 ,p_txn_interface_id --REL12
15363 ,bcc.encumbrance_type_id
15364 ,bcc.document_header_id_2
15365 ,bcc.document_distribution_type
15366 From Pa_Bc_Packets bcc
15367 Where bcc.packet_id = g_packet_id_tbl(i)
15368 and bcc.bc_packet_id in (SELECT bcc1.bc_packet_id
15369 FROM PA_BC_PACKETS bcc1
15370 WHERE bcc1.packet_id = g_packet_id_tbl(i)
15371 and bcc1.parent_bc_packet_id = g_bc_packet_id_tbl(i)
15372 and bcc1.Status_Code in ('A','C')
15373 UNIOn ALL
15374 SELECT g_bc_packet_id_tbl(i)
15375 FROM DUAL);
15376
15377 IF PG_DEBUG = 'Y' THEN
15378 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Inserted '||SQL%ROWCOUNT||' PO reversing raw and burden line(s) into bc packets');
15379 END IF;
15380
15381 END IF; --IF l_rec_pkt_comm_exists='Y' AND p_comm_fc_req ='Y' THEN
15382
15383 IF p_act_fc_req = 'Y' THEN
15384
15385 -- Insert the positive records for the raw line with
15386 -- document type 'EXP'.
15387
15388 IF PG_DEBUG = 'Y' THEN
15389 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Before inserting ACTUAL raw line from bc packets');
15390 END IF;
15391
15392 Insert Into Pa_Bc_Packets
15393 (Packet_Id
15394 ,Bc_Packet_Id
15395 ,Parent_Bc_Packet_Id
15396 ,Set_Of_Books_Id
15397 ,gl_date
15398 ,Period_Name
15399 ,Period_Year
15400 ,Pa_Date
15401 ,Project_Id
15402 ,Task_Id
15403 ,Expenditure_Type
15404 ,Expenditure_Item_Date
15405 ,Expenditure_Organization_Id
15406 ,Budget_Version_Id
15407 ,Budget_line_id -- R12 funds management uptake
15408 ,Document_Type
15409 ,Document_Header_Id
15410 ,Document_Distribution_Id
15411 ,Entered_Dr
15412 ,Entered_Cr
15413 ,Accounted_Dr
15414 ,Accounted_Cr
15415 ,Request_Id
15416 ,Program_Id
15417 ,Program_Application_Id
15418 ,Program_Update_Date
15419 ,Actual_Flag
15420 ,Last_Update_Date
15421 ,Last_Updated_By
15422 ,Created_By
15423 ,Creation_Date
15424 ,Last_Update_Login
15425 ,Txn_Ccid
15426 ,Burden_Cost_Flag
15427 ,Status_Code
15428 ,Je_Category_Name
15429 ,Je_Source_Name
15430 ,Org_id
15431 ,Document_Line_Id
15432 ,reference1
15433 ,reference2
15434 ,reference3
15435 ,txn_interface_id --REL12
15436 ,vendor_id
15437 )
15438 Select p_Packet_Id
15439 ,Pa_Bc_Packets_s.NextVal
15440 ,-1
15441 ,g_sob_Id_tbl(i)
15442 ,G_FC_Gl_Date
15443 ,G_FC_Period_Name
15444 ,g_Period_Year_tbl(i)
15445 -- ,g_Pa_Date_tbl(i) /* changed to g_padate for 16451280 */
15446 ,g_padate
15447 ,g_project_id_tbl(i)
15448 ,g_task_id_tbl(i)
15449 ,g_exp_type_tbl(i)
15450 --,g_ei_date_tbl(i) /* changed to l_expenditure_item_date for 16451280 */
15451 ,l_expenditure_item_date
15452 ,g_exp_org_id_tbl(i)
15453 ,g_bud_ver_id_tbl(i)
15454 ,g_budget_line_id_tbl(i) -- R12 funds management uptake
15455 ,'EXP'
15456 ,X_ei_id
15457 ,1
15458 ,nvl(p_acct_raw_cost,0)
15459 ,0
15460 ,nvl(p_acct_raw_cost,0)
15461 ,0
15462 ,g_Request_Id
15463 ,g_program_id
15464 ,g_prog_appl_id
15465 ,sysdate
15466 ,'A'
15467 ,sysdate
15468 ,g_conc_login_id
15469 ,g_conc_login_id
15470 ,sysdate
15471 ,g_conc_login_id
15472 ,g_Txn_Ccid_tbl(i)
15473 ,'N'
15474 ,'P'
15475 ,'Expenditures'
15476 ,'Project Accounting'
15477 ,g_org_id_tbl(i)
15478 ,l_po_line_id
15479 ,'EXP'
15480 ,x_Ei_Id
15481 ,1
15482 ,p_txn_interface_id --REL12
15483 ,g_vendor_id_tbl(i)
15484 From Pa_Budget_Versions bv,
15485 Pa_Budget_Types bt,
15486 pa_budgetary_control_options pbct
15487 Where bt.budget_type_Code = bv.budget_type_Code
15488 and bt.budget_amount_code = 'C'
15489 and bv.project_id = g_project_id_tbl(i)
15490 and bv.current_flag = 'Y'
15491 and pbct.project_id = bv.project_id
15492 and pbct.BDGT_CNTRL_FLAG = 'Y'
15493 and pbct.BUDGET_TYPE_CODE = bv.budget_type_code
15494 and (pbct.EXTERNAL_BUDGET_CODE = 'GL'
15495 OR
15496 pbct.EXTERNAL_BUDGET_CODE is NULL
15497 );
15498
15499 IF PG_DEBUG = 'Y' THEN
15500 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Inserted '||SQL%ROWCOUNT||' ACTUAL raw line(s) into bc packets');
15501 END IF;
15502
15503 END IF;--IF p_act_fc_req = 'Y' THEN
15504 END LOOP;
15505 END IF; -- l_rec_bc_comm_exists ='Y' OR l_rec_pkt_comm_exists = 'Y' THEN
15506 END IF; -- p_comm_fc_req ='Y' OR p_act_fc_req = 'Y' THEN
15507
15508 IF p_adj_act_fc_req = 'Y' THEN
15509
15510 IF PG_DEBUG = 'Y' THEN
15511 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Before inserting adjusted ACTUAL raw line from transaction import table');
15512 END IF;
15513
15514 FORALL i IN 1 .. g_xface_Txn_interface_tbl.count
15515 Insert Into Pa_Bc_Packets
15516 (Packet_Id
15517 ,Bc_Packet_Id
15518 ,Parent_Bc_Packet_Id
15519 ,Set_Of_Books_Id
15520 ,Gl_Date
15521 ,Period_Name
15522 ,Period_Year
15523 ,Pa_Date
15524 ,Project_Id
15525 ,Task_Id
15526 ,Expenditure_Type
15527 ,Expenditure_Item_Date
15528 ,Expenditure_Organization_Id
15529 ,Budget_Version_Id
15530 ,Document_Type
15531 ,Document_Header_Id
15532 ,Document_Distribution_Id
15533 ,Entered_Dr
15534 ,Entered_Cr
15535 ,Accounted_Dr
15536 ,Accounted_Cr
15537 ,Request_Id
15538 ,Program_Id
15539 ,Program_Application_Id
15540 ,Program_Update_Date
15541 ,Actual_Flag
15542 ,Last_Update_Date
15543 ,Last_Updated_By
15544 ,Created_By
15545 ,Creation_Date
15546 ,Last_Update_Login
15547 ,Txn_Ccid
15548 ,Burden_Cost_Flag
15549 ,Status_Code
15550 ,Je_Category_Name
15551 ,Je_Source_Name
15552 ,Org_id
15553 ,Document_Line_Id
15554 ,reference1
15555 ,reference2
15556 ,reference3
15557 ,txn_interface_id --REL12
15558 ,vendor_id
15559 )
15560 Select p_Packet_Id
15561 ,Pa_Bc_Packets_s.NextVal
15562 ,-1
15563 ,g_sobid
15564 ,G_FC_Gl_Date
15565 ,G_FC_Period_Name
15566 ,G_FC_Period_Year
15567 ,G_PaDate
15568 ,g_xface_project_id_tbl(i)
15569 ,g_xface_task_id_tbl(i)
15570 ,g_xface_exp_type_tbl(i)
15571 -- ,g_xface_ei_date_tbl(i) /* changed to l_expenditure_item_date for 16451280 */
15572 , l_expenditure_item_date
15573 ,g_xface_exp_org_id_tbl(i)
15574 ,g_xface_bud_ver_id_tbl(i)
15575 ,'EXP'
15576 ,X_ei_id
15577 ,1
15578 ,g_xface_Entered_Dr_tbl(i)
15579 ,g_xface_acct_Cr_tbl(i)
15580 ,g_xface_acct_Dr_tbl(i)
15581 ,g_xface_acct_Cr_tbl(i)
15582 ,g_Request_Id
15583 ,g_program_id
15584 ,g_prog_appl_id
15585 ,sysdate
15586 ,'A' --Actual_Flag
15587 ,sysdate
15588 ,g_conc_login_id
15589 ,g_conc_login_id
15590 ,sysdate
15591 ,g_conc_login_id
15592 ,g_xface_Txn_Ccid_tbl(i)
15593 ,'N'
15594 ,'P'
15595 ,'Expenditures'
15596 ,'Project Accounting'
15597 ,g_xface_org_id_tbl(i)
15598 ,l_po_line_id
15599 ,'EXP'
15600 ,X_Ei_Id
15601 ,1
15602 ,g_xface_Txn_interface_tbl(i)
15603 ,g_xface_vendor_id_tbl(i)
15604 From dual;
15605
15606 IF PG_DEBUG = 'Y' THEN
15607 log_message('log_message: ' || 'In insert_po_bc_packets_auto - Inserted '||SQL%ROWCOUNT||' ACTUAL raw line(s) into bc packets');
15608 END IF;
15609
15610 END IF;
15611
15612 COMMIT;
15613 IF PG_DEBUG = 'Y' THEN
15614 log_message('log_message: ' || 'In insert_po_bc_packets_auto - End');
15615 END IF;
15616
15617 EXCEPTION
15618 WHEN OTHERS THEN
15619 IF PG_DEBUG = 'Y' THEN
15620 log_message('log_message: insert_po_bc_packets_auto ' || sqlerrm||' Returning from insert_po_bc_packets_auto');
15621 END IF;
15622 RAISE;
15623 END insert_po_bc_packets_auto;
15624
15625 -- BUG: 4600792 PQE:R12 CHANGE AWARD END WHEN ENCUMBRANCE EXISTS, IMPORT ENC REVERSALS FOR CLOSE
15626 --
15627 /* Added the following procedure for the bug 4138033 */
15628 PROCEDURE Set_GVal_ProjTskEi_Date(L_Validate_Proj_Tsk_Ei_Date IN VARCHAR2) IS
15629 BEGIN
15630 G_Validate_Proj_Tsk_Ei_Date := L_Validate_Proj_Tsk_Ei_Date;
15631 END Set_GVal_ProjTskEi_Date;
15632
15633 /* Added the following function for the bug 4138033 */
15634 FUNCTION Get_GVal_ProjTskEi_Date RETURN VARCHAR2 IS
15635 BEGIN
15636 Return G_Validate_Proj_Tsk_Ei_Date;
15637 END;
15638
15639
15640 END PA_TRX_IMPORT;