[Home] [Help]
PACKAGE BODY: APPS.GMS_BILLING
Source
1 PACKAGE BODY GMS_BILLING AS
2 -- $Header: gmsinblb.pls 120.15.12010000.6 2008/11/27 11:13:44 rrambati ship $
3
4 -- To check on, whether to print debug messages in log file or not
5 L_DEBUG varchar2(1) := NVL(FND_PROFILE.value('GMS_ENABLE_DEBUG_MODE'), 'N');
6
7 TYPE Inst_Rec is RECORD(INSTALLMENT_ID NUMBER(15),
8 REV_BILL_AMOUNT NUMBER(22,5));
9
10 TYPE Inst_tab is TABLE OF Inst_Rec
11 INDEX BY BINARY_INTEGER;
12
13 X_Installment_tab Inst_tab; -- Used to get store installment numbers for invoice
14 X_Rev_Installment_tab Inst_tab; -- Used to get store installment numbers for revenue
15 X_ei_rollback_Inst_tab Inst_tab; -- Used to get the rollback transaction amounts /* for bug 5242484 */
16
17 TYPE Inst_Rec2 is RECORD(INSTALLMENT_ID NUMBER(15),
18 REV_BILL_AMOUNT NUMBER(22,5),
19 ACTUAL_PROJECT_ID NUMBER(15),
20 ACTUAL_TASK_ID NUMBER(15));
21
22 TYPE Inst_tab2 is TABLE OF Inst_Rec2
23 INDEX BY BINARY_INTEGER;
24
25 X_Installment_Total Inst_tab2; -- Used to collect amt's on installments for invoice
26 X_Rev_Installment_Total Inst_tab2; -- Used to collect amt's on installments for revenue
27
28 ROLLBACK_FAILURE Exception;
29
30 -- ## this exception is handled in the main procedure AWARD_BILLING only
31 -- ## but this exception is called from procedures which are called within AWARD_BILLING
32
33 NO_PROCESSING_OF_AWARD Exception;
34
35 -- ## This exception is handled in the main procedure AWARD_BILLING only
36 -- ## but this exception is called from procedures which are called within AWARD_BILLING
37
38 AWARD_DATA_LOCKED Exception;
39 -- ## This exception is handled in the main procedure AWARD_BILLING only
40
41 GMS_TAX_FAILURE Exception; --Added for bug 4506225
42 -- ## This exception is handled in the main procedure AWARD_BILLING only
43 -- ## This exception is raised when the call to GMS_TAX returns a value St_Err_Code <> 0
44
45 INVALID_INVOICE_FORMAT Exception;
46
47 -- ## This exception is handled in the main procedure AWARD_BILLING only
48 -- ## This exception is raised when the invoice format containins an element not supported by GMS
49
50 X_BURDEN_NULL_EVENT_PROCESSED BOOLEAN := FALSE;
51 X_REVRAW_NULL_EVENT_PROCESSED BOOLEAN := FALSE;
52 X_INVRAW_NULL_EVENT_PROCESSED BOOLEAN := FALSE;
53
54 -- Above package variables are set if NULL events are processed. These variables are accessed
55 -- in award_billing procedure.
56 -- X_BURDEN_NULL_EVENT_PROCESSED set in do_burden_event_processing
57 -- X_REVRAW_NULL_EVENT_PROCESSED set in do_rev_event_processing
58 -- X_INVRAW_NULL_EVENT_PROCESSED set in do_event_processing
59
60 -- X_LAST_CALL_FOR_REVENUE BOOLEAN := FALSE; -- Bug 3254097 : Commenting out the variable as the logic
61 -- which uses this variable is commented out.
62
63 -- This package variable is set when do_rev_event_processing procedure is
64 -- called for the last record.
65
66 -- Bug 3254097 : Flag to check if billing flags need to be updated for an expenditure Item.
67 X_UPD_BILLING_FLAG BOOLEAN := FALSE;
68
69 -- Bug 3235390 : Introduced the following variable to generate negative sequence
70 -- for temprary events.
71 x_temp_negative_evt_num NUMBER(15) ;
72
73 -- Bug 5413530
74 X_trans_type VARCHAR2(10);
75 G_trans_type VARCHAR2(10);
76
77 /* -----------------------------------------------------------------------------------------+ */
78 -- Function Is_Invoice_Format_Valid : This is called from :AWARDS form and gms_billing.award_billing
79 -- Function checks whether the invoice format (labor/non-labor) has any element (column) that is not
80 -- supported by Grants Accounting.
81 -- Calling context would be 'AWARDS_FORM' or 'BILLING_PROCESS'
82 -- Function returns TRUE is format is VALID else returns FALSE
83
84 Function Is_Invoice_Format_Valid(X_award_project_id IN NUMBER,
85 X_Labor_format_id IN NUMBER,
86 X_Non_Labor_format_id IN NUMBER,
87 X_calling_context IN VARCHAR2)
88 RETURN BOOLEAN IS
89 l_dummy number;
90 l_labor_format_id gms_Awards_all.labor_invoice_format_id%TYPE;
91 l_non_labor_format_id gms_Awards_all.non_labor_invoice_format_id%TYPE;
92 Begin
93
94 If X_calling_context = 'BILLING_PROCESS' then
95
96 select a.labor_invoice_format_id, a.non_labor_invoice_format_id
97 into l_labor_format_id,l_non_labor_format_id
98 from gms_awards_all a
99 where a.award_project_id = X_Award_Project_Id;
100
101 Elsif X_calling_context = 'AWARDS_FORM' then
102
103 l_Labor_format_id := X_Labor_format_id;
104 l_Non_Labor_format_id := X_Non_Labor_format_id;
105
106 End If;
107
108 --Commented columns containing 'Job' for Bug# 5003907
109 Begin
110 select 1 into l_dummy from dual where exists (
111 select 1
112 from pa_invoice_group_columns a,
113 pa_invoice_format_details b
114 where a.invoice_group_column_id = b.invoice_group_column_id
115 and b.invoice_format_id in(l_labor_format_id,X_Non_Labor_format_id)
116 and a.column_code not in ('EMPLOYEE FIRST NAME','EMPLOYEE FULL NAME',
117 'EMPLOYEE LAST NAME','EXPENDITURE CATEGORY',
118 'EXPENDITURE TYPE', --'JOB','JOB DISCIPLINE','JOB LEVEL',
119 'NON-LABOR RESOURCE','ORGANIZATION',
120 'REVENUE CATEGORY','TEXT','TOP TASK NAME',
121 'TOP TASK NUMBER','TOTAL AMOUNT','TOTAL HOURS',
122 'UNITS'));
123
124 RETURN FALSE;
125 Exception
126 When no_data_found then
127 RETURN TRUE;
128 End;
129 End Is_Invoice_Format_Valid;
130 /* -----------------------------------------------------------------------------------------+ */
131 -- Following function determines if burden is allowed ..
132 -- Used in format_specific_billing and revenue_accrual
133
134 Function allow_burden(p_transaction_source in varchar2) return BOOLEAN is
135 l_allow_burden_flag pa_transaction_sources.allow_burden_flag%type;
136 Begin
137 -- import burden amount (Txn. source UI) = allow_burden_flag (database)
138 -- Allow burden
139 -- Y - burden is imported from external transaction source and do not calculate in Projects
140 -- N - burden is calculated in projects.
141 -- we need to allow burden when allow_burden_flag is 'N'
142
143 Select DECODE( NVL(allow_burden_flag,'N'), 'N', 'Y', 'N')
144 into l_allow_burden_flag
145 from pa_transaction_sources pts
146 where pts.transaction_source = p_transaction_source;
147
148 If l_allow_burden_flag = 'Y' then
149 RETURN TRUE;
150 Else
151 RETURN FALSE;
152 End If;
153 Exception
154 When no_data_found then
155 RETURN TRUE;
156 End allow_burden;
157
158 /* ----------------------------------------------------------------------------------------- */
159 -- Following function is called from do_rev_event_processing.
160 -- this will check if there are any records with null event number ..
161
162 Function NULL_REVENUE_EVENT_EXISTS(X_award_project_id IN NUMBER,
163 X_request_id IN NUMBER,
164 X_event_type IN VARCHAR2)
165 RETURN BOOLEAN IS
166 x_dummy number(1);
167 BEGIN
168
169 Select 1
170 into x_dummy
171 from dual
172 where exists (select 1
173 from gms_event_intersect
174 where award_project_id = X_Award_Project_Id
175 and request_id = X_Request_Id
176 and event_type = X_Event_Type
177 and event_num IS NULL);
178
179 RETURN TRUE;
180
181 EXCEPTION
182
183 When Others then
184
185 RETURN FALSE;
186
187 END;
188
189 /* ----------------------------------------------------------------------------------------- */
190 -- This function will be called to determine whether we need to run billing
191 -- process (REVENUE/INVOICE) or not.
192
193 FUNCTION IS_PROCESSING_REQD(X_Calling_Process IN VARCHAR2,
194 X_Award_Id IN NUMBER)
195 RETURN BOOLEAN IS
196 l_value NUMBER :=0;
197
198 /* Added for bug 3848203 */
199
200 X_Award_Rev_Distribution_Rule VARCHAR2(30);
201 X_Award_Bill_Distribution_Rule VARCHAR2(30);
202
203 Begin
204
205 If X_Calling_Process = 'Revenue' then
206
207 Begin
208 /* Changes for bug 3848203 */
209
210 select
211 a.Revenue_Distribution_Rule
212 into
213 X_Award_Rev_Distribution_Rule
214 from
215 GMS_AWARDS a
216 where
217 a.Award_Id =X_Award_Id;
218
219 if (X_Award_Rev_Distribution_Rule = 'EVENT') then
220 RETURN FALSE;
221 else
222 Select 1
223 into l_value
224 from dual
225 where exists(
226 select /*+ INDEX(adl gms_award_distributions_n7) */ 1 /* Added hint for bug 6969435 */
227 from gms_award_distributions adl,
228 pa_tasks t3,
229 pa_tasks t5
230 where adl.award_id = X_Award_Id
231 and adl.document_type = 'EXP'
232 and adl.adl_status = 'A'
233 and adl.fc_status = 'A'
234 and adl.billable_flag ='Y' /* removed nvl for bug 6969435 */
235 and adl.revenue_distributed_flag in ('N','Z') /* removed nvl for bug 6969435 */
236 and adl.project_id = t3.project_id /* Added for bug 6969435 */
237 and t3.task_id = adl.task_id
238 and t3.top_task_id = t5.task_id
239 and t5.ready_to_distribute_flag = 'Y');
240
241 RETURN TRUE;
242 end if;
243
244 Exception
245
246 When NO_DATA_FOUND Then
247
248 RETURN FALSE;
249 End;
250
251 ElsIf X_Calling_Process = 'Invoice' then
252
253 Begin
254
255 select
256 a.Billing_Distribution_Rule
257 into
258 X_Award_Bill_Distribution_Rule
259 from
260 GMS_AWARDS a
261 where
262 a.Award_Id =X_Award_Id ;
263
264 if(X_Award_Bill_Distribution_Rule = 'EVENT') then
265 return FALSE;
266 else
267 Select 1
268 into l_value
269 from dual
270 where exists(
271 select /*+ INDEX(adl gms_award_distributions_n7) */ 1 /* Added hint for bug 6969435 */
272 from
273 gms_award_distributions adl,
274 pa_tasks t3,
275 pa_tasks t5
276 where adl.award_id = X_Award_Id
277 and adl.document_type = 'EXP'
278 and adl.adl_status = 'A'
279 and adl.fc_status = 'A'
280 and adl.billable_flag ='Y' /* removed nvl for bug 6969435 */
281 and adl.billed_flag in ('N','Z') /* removed nvl for bug 6969435 */
282 and t3.task_id = adl.task_id
283 and t3.top_task_id = t5.task_id
284 and t5.ready_to_distribute_flag = 'Y');
285
286 RETURN TRUE;
287 end if;
288
289 /* End of Changes for bug 3848203 */
290
291 Exception
292
293 When NO_DATA_FOUND Then
294
295 RETURN FALSE;
296 End;
297
298 End If;
299
300 End IS_PROCESSING_REQD;
301
302
303 -- Bug 1652198 ...
304 -- PROCEDURE LOCK_AWARD_RECORDS, new procedure to achieve concurrency between billing
305 -- processes and Awards form.
306
307 PROCEDURE LOCK_AWARD_RECORDS(X_Award_Project_id IN NUMBER,
308 X_Err_Code IN OUT NOCOPY NUMBER,
309 X_Err_Buff IN OUT NOCOPY VARCHAR2)
310 IS
311
312 X_Dummy number(1);
313 RESOURCE_BUSY EXCEPTION;
314 PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -00054);
315
316 Cursor Cur_installment_lock is
317 select a.installment_id
318 from gms_installments a,
319 gms_awards b
320 where b.award_project_id = X_Award_Project_id
321 and a.award_id = b.award_id;
322
323 Begin
324
325 X_Err_Code := 0;
326
327 Select 1
328 into x_dummy
329 from gms_awards
330 where award_project_id = X_Award_Project_id
331 FOR UPDATE NOWAIT;
332
333 IF L_DEBUG = 'Y' THEN
334 gms_error_pkg.gms_debug('After Locking Award','C');
335 END IF;
336
337 for installment_records in Cur_installment_lock
338 loop
339
340 Begin
341
342 Select 1
343 into x_dummy
344 from gms_installments
345 where installment_id = installment_records.installment_id
346 FOR UPDATE NOWAIT;
347 Exception
348 When RESOURCE_BUSY THEN
349 RAISE;
350 When OTHERS THEN
351 RAISE;
352 END;
353 end loop;
354
355 IF L_DEBUG = 'Y' THEN
356 gms_error_pkg.gms_debug('After Locking Installments','C');
357 END IF;
358
359 Exception
360
361 When RESOURCE_BUSY THEN
362
363 Raise AWARD_DATA_LOCKED;
364
365 When OTHERS THEN
366
367 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
368 'SQLCODE',
369 SQLCODE,
370 'SQLERRM',
371 SQLERRM,
372 X_Exec_Type => 'C',
373 X_Err_Code => X_Err_Code,
374 X_Err_Buff => X_Err_Buff);
375
376 --Raise NO_PROCESSING_OF_AWARD ;
377
378 End LOCK_AWARD_RECORDS;
379
380
381 -- PROCEDURE BILLING_ROLLBACK, new procedure for roll ups in case of process failure
382 -- Added x_event_num.. 8/26/02. This has been added so that event_number value can be
383 -- passed while rolling back null events ...
384
385 PROCEDURE billing_rollback (
386 x_award_project_id IN NUMBER,
387 --x_calling_process IN VARCHAR2,
388 x_event_num IN NUMBER DEFAULT NULL,
389 x_err_code IN OUT NOCOPY NUMBER,
390 x_err_buff IN OUT NOCOPY VARCHAR2
391 )
392 IS
393 F_Request_id number := 0 ;
394 F_calling_process varchar(20);
395
396 CURSOR events_to_rollback
397 IS
398 SELECT DISTINCT project_id, event_num, event_calling_process event_type
399 FROM gms_event_attribute gea
400 WHERE project_id = x_award_project_id
401 --AND event_calling_process = x_calling_process
402 and event_num > 0 /* Added for bug 4594090 */ /*Changed to >0 for bug 6969435 */
403 AND ( (x_event_num IS NULL) OR
404 (x_event_num IS NOT NULL AND event_num = x_event_num)
405 )
406 AND event_calling_process IS NOT NULL
407 -- null for manual events
408 and not exists ( /* Modified MINUS operation to Not exists clause */
409 SELECT 1 --project_id, event_num, calling_process event_type /* Modifed for 6969435 */
410 FROM pa_events
411 WHERE --project_id = x_award_project_id /* commented for 6969435 */
412 --AND calling_process = x_calling_process /* commented for 6969435 */
413 --AND ( (x_event_num IS NULL) OR /* commented for 6969435 */
414 -- (x_event_num IS NOT NULL AND event_num = x_event_num) /* commented for 6969435 */
415 -- ) /* commented for 6969435 */
416 --AND /* commented for 6969435 */
417 event_type = 'AWARD_BILLING'
418 and project_id = gea.project_id
419 and event_num = gea.event_num
420 and calling_process = gea.event_calling_process
421 );
422
423 -- x_event_num will have a value when this procedure is being called for
424 -- rolling back NULL events ...
425
426 CURSOR get_exp_raw_info (f_project_id NUMBER, f_event_num NUMBER,
427 f_event_calling_process VARCHAR2)
428 IS
429 SELECT DISTINCT gei.expenditure_item_id, gei.adl_line_num,
430 gea.actual_project_id, gea.actual_task_id,
431 gea.expenditure_org_id, gei.amount,
432 gei.revenue_accumulated, gei.creation_date,gea.request_id
433 FROM gms_event_intersect gei, gms_event_attribute gea
434 WHERE gea.project_id = f_project_id
435 AND gea.event_num = f_event_num
436 AND gea.event_calling_process = f_event_calling_process
437 AND gei.award_project_id = gea.project_id
438 AND gei.event_num = gea.event_num
439 AND gei.event_type = UPPER(f_event_calling_process);
440
441 f_raw_exp_item_id gms_award_distributions.expenditure_item_id%TYPE;
442 f_raw_adl_line_num gms_award_distributions.adl_line_num%TYPE;
443 f_raw_act_project_id gms_event_attribute.actual_project_id%TYPE;
444 f_raw_act_task_id gms_event_attribute.actual_task_id%TYPE;
445 f_raw_org_id gms_event_attribute.expenditure_org_id%TYPE;
446 f_raw_rev_accumulated gms_event_intersect.revenue_accumulated%TYPE;
447 f_raw_revenue_amount gms_event_intersect.amount%TYPE;
448 f_raw_creation_date gms_event_intersect.creation_date%TYPE;
449
450 CURSOR get_exp_burden_info (f_project_id NUMBER, f_event_num NUMBER,
451 f_event_calling_process VARCHAR2)
452 IS
453 SELECT expenditure_item_id, adl_line_num, actual_project_id,
454 actual_task_id, expenditure_org_id, burden_exp_type, burden_cost_code,
455 amount, revenue_accumulated, creation_date
456 FROM gms_burden_components
457 WHERE award_project_id = f_project_id
458 AND event_num = f_event_num
459 AND event_type = UPPER(f_event_calling_process);
460
461 f_burd_exp_item_id gms_award_distributions.expenditure_item_id%TYPE;
462 f_burd_adl_line_num gms_award_distributions.adl_line_num%TYPE;
463 f_burd_rev_accumulated gms_burden_components.revenue_accumulated%TYPE;
464 f_burd_revenue_amount gms_burden_components.amount%TYPE;
465 f_burd_act_project_id gms_burden_components.actual_project_id%TYPE;
466 f_burd_act_task_id gms_burden_components.actual_task_id%TYPE;
467 f_burd_org_id gms_burden_components.expenditure_org_id%TYPE;
468 f_burd_exp_type gms_burden_components.burden_exp_type%TYPE;
469 f_burd_cost_code gms_burden_components.burden_cost_code%TYPE;
470 f_burd_creation_date gms_burden_components.creation_date%TYPE;
471
472 -- Get_Event_Details required as Event to Installment has one - many relationship
473
474 CURSOR get_event_details (f_project_id NUMBER, f_event_num NUMBER,
475 f_event_calling_process VARCHAR2)
476 IS
477 SELECT actual_project_id, actual_task_id, installment_id,
478 revenue_amount, bill_amount
479 , rowid -- Bug 2715312
480 FROM gms_event_attribute
481 WHERE project_id = f_project_id
482 AND event_num = f_event_num
483 AND event_calling_process = f_event_calling_process;
484
485 f_act_project_id gms_event_attribute.actual_project_id%TYPE;
486 f_act_task_id gms_event_attribute.actual_task_id%TYPE;
487 f_installment_id gms_event_attribute.installment_id%TYPE;
488 f_rev_amount gms_event_attribute.revenue_amount%TYPE;
489 f_bill_amount gms_event_attribute.bill_amount%TYPE;
490 f_row_id rowid ; -- Bug 2715312
491 x_stage NUMBER (2);
492 BEGIN
493 /* --------------------------------------------------------------------------
494 || Rollback Activities Include:
495 || 10. Updating gms_award_distributions (revenue_distributed_flag/billed_flag)
496 || 20. Deleting from gms_event_intersect
497 || 30. Deleting from gms_burden_components
498 || 40. Updating gms_summary_project_fundings
499 || 50. Deleting gms_event_attribute
500 -------------------------------------------------------------------------- */
501
502 FOR evt IN events_to_rollback
503 LOOP
504 F_calling_process := UPPER(evt.event_type); /* Added for bug 4957529 */
505
506 /* -------- EXPENDITURE RELATED UPDATIONS ------------ */
507
508 -- ## RAW UPDATION
509
510 OPEN get_exp_raw_info (evt.project_id, evt.event_num,evt.event_type);
511
512 LOOP
513 FETCH get_exp_raw_info INTO f_raw_exp_item_id,
514 f_raw_adl_line_num,
515 f_raw_act_project_id,
516 f_raw_act_task_id,
517 f_raw_org_id,
518 f_raw_revenue_amount,
522 EXIT WHEN get_exp_raw_info%NOTFOUND;
519 f_raw_rev_accumulated,
520 f_raw_creation_date,
521 f_request_id; --Added for bug 4957529
523
524 BEGIN -- Expenditure Rollup Block
525 -- 10: Updating the gms_award_distributions table
526
527 x_stage := 10;
528
529 IF evt.event_type = 'Revenue'
530 THEN
531 IF f_raw_rev_accumulated = 'Y'
532 THEN
533 /* Create negative entry in gms_billing_cancellations
534 for ASI to backout revenue accumulated */
535 gms_billing_adjustments.insert_bill_cancel (evt.project_id,
536 evt.event_num,
537 f_raw_exp_item_id,
538 f_raw_adl_line_num,
539 -1 * f_raw_revenue_amount,
540 evt.event_type,
541 NULL, -- burden_exp_type
542 NULL, -- burden_cost_code
543 f_raw_creation_date,
544 f_raw_act_project_id,
545 f_raw_act_task_id,
546 f_raw_org_id,
547 SYSDATE, -- deletion_date
548 NULL, -- rlmi
549 x_err_code,
550 x_err_buff
551 );
552 END IF;
553
554 UPDATE gms_award_distributions
555 SET revenue_distributed_flag = decode(x_event_num,NULL,'N','Z'),
556 last_update_date = SYSDATE,
557 last_updated_by = fnd_global.user_id,
558 last_update_login = fnd_global.login_id
559 WHERE expenditure_item_id = f_raw_exp_item_id
560 AND adl_line_num = f_raw_adl_line_num
561 AND document_type = 'EXP'
562 AND adl_status = 'A';
563 ELSIF evt.event_type = 'Invoice'
564 THEN
565 UPDATE gms_award_distributions
566 SET billed_flag = decode(x_event_num,NULL,'N','Z'),
567 last_update_date = SYSDATE,
568 last_updated_by = fnd_global.user_id,
569 last_update_login = fnd_global.login_id
570 WHERE expenditure_item_id = f_raw_exp_item_id
571 AND adl_line_num = f_raw_adl_line_num
572 AND document_type = 'EXP'
573 AND adl_status = 'A';
574 END IF;
575
576 -- 20: Deleting records from gms_event_intersect
577
578 x_stage := 20;
579
580 DELETE
581 FROM gms_event_intersect
582 WHERE expenditure_item_id = f_raw_exp_item_id
583 AND adl_line_num = f_raw_adl_line_num
584 AND award_project_id = evt.project_id
585 AND event_num = evt.event_num
586 AND event_type = upper(evt.event_type);
587 END;
588 END LOOP; -- Get_Exp_Raw_Info
589
590 CLOSE get_exp_raw_info;
591
592 -- ## BURDEN UPDATION
593
594
595 OPEN get_exp_burden_info (evt.project_id, evt.event_num,evt.event_type);
596
597 LOOP
598 FETCH get_exp_burden_info INTO f_burd_exp_item_id,
599 f_burd_adl_line_num,
600 f_burd_act_project_id,
601 f_burd_act_task_id,
602 f_burd_org_id,
603 f_burd_exp_type,
604 f_burd_cost_code,
605 f_burd_revenue_amount,
606 f_burd_rev_accumulated,
607 f_burd_creation_date;
608 EXIT WHEN get_exp_burden_info%NOTFOUND;
609
610 BEGIN -- Expenditure Rollup Block
611 -- 30: Deleting records from gms_burden_components
612 x_stage := 30;
613
614 IF f_burd_rev_accumulated = 'Y' and evt.event_type = 'Revenue'
615 THEN
616 /* Create negative entry in gms_billing_cancellations
617 for ASI to backout revenue accumulated */
618 gms_billing_adjustments.insert_bill_cancel (evt.project_id,
619 evt.event_num,
620 f_burd_exp_item_id,
621 f_burd_adl_line_num,
622 -1 * f_burd_revenue_amount,
623 evt.event_type,
624 f_burd_exp_type, -- burden_exp_type
625 f_burd_cost_code, -- burden_cost_code
626 f_burd_creation_date,
627 f_burd_act_project_id,
628 f_burd_act_task_id,
629 f_burd_org_id,
630 SYSDATE, -- deletion_date
631 NULL, -- rlmi
632 x_err_code,
636
633 x_err_buff
634 );
635 END IF;
637 DELETE
638 FROM gms_burden_components
639 WHERE expenditure_item_id = f_burd_exp_item_id
640 AND adl_line_num = f_burd_adl_line_num
641 AND award_project_id = evt.project_id
642 AND event_num = evt.event_num
643 AND event_type = upper(evt.event_type) ;
644
645
646 END;
647 END LOOP; -- Get_Exp_Burden_Info
648
649 CLOSE get_exp_burden_info;
650 /* -------- EVENT RELATED UPDATIONS ------------ */
651
652 OPEN get_event_details (evt.project_id, evt.event_num,evt.event_type);
653
654 LOOP
655 FETCH get_event_details INTO f_act_project_id,
656 f_act_task_id,
657 f_installment_id,
658 f_rev_amount,
659 f_bill_amount,
660 f_row_id; -- Bug 2715312
661 EXIT WHEN get_event_details%NOTFOUND;
662
663 BEGIN -- Event Related
664 -- 40: Updating gms_summary_project_fundings
665
666 IF evt.event_type = 'Invoice'
667 THEN
668 UPDATE gms_summary_project_fundings
669 SET total_billed_amount =
670 total_billed_amount - f_bill_amount
671 WHERE project_id = f_act_project_id
672 AND ( task_id IS NULL
673 OR task_id = f_act_task_id
674 OR task_id = (select t.top_task_id
675 from PA_TASKS t
676 where t.task_id = f_act_task_id)
677 )
678 AND installment_id = f_installment_id;
679
680 ELSIF evt.event_type = 'Revenue'
681 THEN
682 UPDATE gms_summary_project_fundings
683 SET total_revenue_amount =
684 total_revenue_amount - f_rev_amount
685 WHERE project_id = f_act_project_id
686 AND ( task_id IS NULL
687 OR task_id = f_act_task_id
688 OR task_id = (select t.top_task_id
689 from PA_TASKS t
690 where t.task_id = f_act_task_id)
691 )
692 AND installment_id = f_installment_id;
693
694 END IF;
695
696 -- 50: Delete gms_event_attribute
697
698 DELETE
699 FROM gms_event_attribute
700 WHERE rowid= f_row_id ; -- Bug 2715312, Replaced the below conditions with rowid
701 -- WHERE project_id = evt.project_id
702 -- AND event_num = evt.event_num
703 -- AND actual_project_id = f_act_project_id
704 -- AND actual_task_id = f_act_task_id
705 -- AND installment_id = f_installment_id
706 -- AND event_calling_process = evt.event_type;
707
708 IF SQL%NOTFOUND
709 THEN
710
711 -- Following If..End If added for bug 2648168 ..
712
713 If (f_bill_amount <> 0 or
714 f_rev_amount <> 0) then
715
716 gms_error_pkg.gms_message ('GMS_BILLING_ROLLBACK_EVT',
717 'PRJ',
718 f_act_project_id,
719 'TASK',
720 f_act_task_id,
721 'INST',
722 f_installment_id,
723 'STAGE',
724 x_stage,
725 x_exec_type => 'C',
726 x_err_code => x_err_code,
727 x_err_buff => x_err_buff
728 );
729 RAISE no_processing_of_award;
730
731 End If;
732
733 END IF;
734 END; -- Event Related
735 END LOOP; -- get_event_details
736
737 CLOSE get_event_details;
738
739 END LOOP; -- Main Loop: events_to_rollback
740
741 x_err_code := 0;
742
743 If ( F_request_id <> 0 ) then
744 -- Handle net zero events .... /* Added for bug 4957529 */
745 gms_billing_adjustments.HANDLE_NET_ZERO_EVENTS (P_AWARD_PROJECT_ID => X_Award_Project_id,
746 P_REQUEST_ID => F_request_id,
747 P_CALLING_PROCESS => F_calling_process);
748 End IF ; /* Added for bug 4957529 */
749
750 END billing_rollback;
751
752 -- -----------------------------------------------------------------------------
753 -- Following procedure DELETE_NULL_EVENTS will delete the null event
754 -- records from gms_event_intersect and gms_burden_components
755 -- At the same time, it will reset the award distribution lines billing flags
756 -- For invoice records, procedure may have to update summary fundings ...
757
758 -- !!! Flags will be reset with a value of "Z" indicating net zero ...
759 /***Commented out for bug 4957529
763 X_err_code OUT NOCOPY NUMBER,
760 PROCEDURE DELETE_NULL_EVENTS (X_award_project_id IN NUMBER,
761 X_request_id IN NUMBER,
762 X_calling_process IN VARCHAR2,
764 X_err_buff OUT NOCOPY VARCHAR2)
765 IS
766 X_event_type VARCHAR2(10);
767 BEGIN
768
769 IF L_DEBUG = 'Y' THEN
770 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - START', 'C');
771 END IF;
772 X_event_type := UPPER(X_calling_process);
773
774 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
775 -- Null events for raw invoice records .. Code start
776
777 If X_INVRAW_NULL_EVENT_PROCESSED then
778
779 IF L_DEBUG = 'Y' THEN
780 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - Stage: Rollback Invoice raw events','C');
781 END IF;
782
783 billing_rollback(X_award_project_id,
784 --X_calling_process,
785 -1, -- event_num for NULL events...check do_event_processing
786 X_Err_Code,
787 X_Err_Buff);
788
789 IF L_DEBUG = 'Y' THEN
790 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - Stage: After Rollback Invoice raw events,X_Err_Code:'||X_Err_Code,'C');
791 END IF;
792
793 If X_Err_Code <> 0 then
794 gms_error_pkg.gms_message('GMS_BILLING_ROLLBACK_FAILURE',
795 'PRJ',
796 X_award_project_id,
797 X_Exec_Type => 'C',
798 X_Err_Code => X_Err_Code,
799 X_Err_Buff => X_Err_Buff);
800 Raise ROLLBACK_FAILURE;
801
802 End if;
803
804 End if;
805 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
806 -- Null events for raw revenue records .. Code start
807
808 If X_REVRAW_NULL_EVENT_PROCESSED then
809
810 IF L_DEBUG = 'Y' THEN
811 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - Stage: Revenue Raw - ADL update', 'C');
812 END IF;
813
814 Update gms_award_distributions
815 set revenue_distributed_flag = decode(revenue_distributed_flag,'Y','Z','Z','N')
816 where (expenditure_item_id,adl_line_num) in
817 (select expenditure_item_id,
818 adl_line_num
819 from gms_event_intersect
820 where award_project_id = X_award_project_id
821 and event_num = -1
822 and request_id = X_request_id
823 and event_type = X_event_type
824 )
825 and document_type = 'EXP';
826
827 IF L_DEBUG = 'Y' THEN
828 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - Stage: Revenue Raw - Delete records', 'C');
829 END IF;
830
831 Delete
832 from gms_event_intersect
833 where award_project_id = X_award_project_id
834 and event_num = -1
835 and request_id = X_request_id
836 and event_type = X_event_type;
837
838 End If;
839
840 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
841 -- Null events for burden records .. Code Start
842
843 If X_BURDEN_NULL_EVENT_PROCESSED then
844
845 If X_event_type = 'INVOICE' then
846
847 IF L_DEBUG = 'Y' THEN
848 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - Stage: Invoice Burden - ADL Update', 'C');
849 END IF;
850
851 Update gms_award_distributions
852 set billed_flag = decode(billed_flag,'Y','Z','Z','N')
853 where (expenditure_item_id,adl_line_num) in
854 (select expenditure_item_id,
855 adl_line_num
856 from gms_burden_components
857 where award_project_id = X_award_project_id
858 and event_num = -2
859 and request_id = X_request_id
860 and event_type = X_event_type
861 )
862 and document_type = 'EXP';
863
864 ElsIf X_event_type = 'REVENUE' then
865
866 IF L_DEBUG = 'Y' THEN
867 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - Stage: Revenue Burden - ADL Update', 'C');
868 END IF;
869
870 Update gms_award_distributions
871 set revenue_distributed_flag = decode(revenue_distributed_flag,'Y','Z','Z','N')
872 where (expenditure_item_id,adl_line_num) in
873 (select expenditure_item_id,
874 adl_line_num
875 from gms_burden_components
876 where award_project_id = X_award_project_id
877 and event_num = -2
878 and request_id = X_request_id
879 and event_type = X_event_type
880 )
881 and document_type = 'EXP';
882
883 End if;
884
885 IF L_DEBUG = 'Y' THEN
886 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - Stage: Burden - Delete records', 'C');
887 END IF;
888
889 Delete
890 from gms_burden_components
891 where award_project_id = X_award_project_id
892 and event_num = -2
893 and request_id = X_request_id
894 and event_type = X_event_type;
898 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
895
896 End if;
897
899 X_err_code := 0;
900 IF L_DEBUG = 'Y' THEN
901 gms_error_pkg.gms_debug('In DELETE_NULL_EVENTS - END', 'C');
902 END IF;
903 -- Not handling exceptions in this procedure .. exceptions falls to award_billing
904 End DELETE_NULL_EVENTS;
905 ***************************/
906 -- -----------------------------------------------------------------------------
907
908 -- PROCEDURE GMS_BILL_CONCURRENCY , new procedure for Concurrency Control
909
910 PROCEDURE GMS_BILL_CONCURRENCY(X_Request_Id IN NUMBER,
911 X_Award_Project_Id IN NUMBER,
912 X_Err_Code IN OUT NOCOPY NUMBER,
913 X_Err_Buff IN OUT NOCOPY VARCHAR2)
914 IS
915 X_Process_Name Varchar2(15);
916 Begin
917
918 Select 0
919 into X_Err_Code
920 from gms_concurrency_control
921 where process_key = X_Award_Project_Id
922 and process_name = 'GMS_BLNG'
923 for update NOWAIT;
924
925 Exception
926 When no_data_found then
927 -- Bug 2441525 : GSCC Errors :Added columns in insert command
928 insert into gms_concurrency_control
929 (PROCESS_NAME,
930 PROCESS_KEY ,
931 REQUEST_ID,
932 LAST_UPDATE_DATE,
933 LAST_UPDATED_BY,
934 CREATED_BY ,
935 CREATION_DATE,
936 LAST_UPDATE_LOGIN )
937 values('GMS_BLNG',
938 X_Award_Project_Id,
939 X_Request_Id,
940 sysdate,
941 fnd_global.user_id,
942 fnd_global.user_id,
943 sysdate,
944 fnd_global.login_id
945 );
946
947 commit;
948
949 -- The next begin end is required for the case when another user may
950 -- execute a select before the current user
951
952 Begin
953
954 Select 0
955 into X_Err_Code
956 from gms_concurrency_control
957 where process_key = X_Award_Project_Id
958 and process_name = 'GMS_BLNG'
959 for update NOWAIT;
960
961 Exception
962 When others then
963 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
964 'SQLCODE',
965 SQLCODE,
966 'SQLERRM',
967 SQLERRM,
968 X_Exec_Type => 'C',
969 X_Err_Code => X_Err_Code,
970 X_Err_Buff => X_Err_Buff);
971 End;
972
973 When others then
974 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
975 'SQLCODE',
976 SQLCODE,
977 'SQLERRM',
978 SQLERRM,
979 X_Exec_Type => 'C',
980 X_Err_Code => X_Err_Code,
981 X_Err_Buff => X_Err_Buff);
982
983 End GMS_BILL_CONCURRENCY;
984
985 -- PROCEDURE ONE_TIME_BILL_HOLD, updates ADL records for ONE TIME Bill Hold
986
987 PROCEDURE ONE_TIME_BILL_HOLD(X_Award_Project_Id IN NUMBER,
988 X_Award_Id IN NUMBER,
989 X_Rev_Or_Bill_Date IN DATE,
990 X_Request_Id IN NUMBER,
991 X_Err_Code IN OUT NOCOPY NUMBER,
992 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
993 /* This Cursor fetches expenditure items on ONE TIME BILL HOLD */
994 Cursor one_time_hold is
995 select /*+INDEX(pt PA_PROJECT_TYPES_U1)*/
996 ei.expenditure_item_id expenditure_item_id,
997 adl.adl_line_num adl_line_num,
998 adl.award_id award_id
999 from pa_expenditure_items_all ei,
1000 pa_expenditure_types et,
1001 pa_projects_all p,
1002 pa_project_types pt,
1003 pa_tasks t3,
1004 pa_tasks t5,
1005 gms_award_distributions adl
1006 where adl.award_id = X_Award_Id
1007 and ei.expenditure_item_id = adl.expenditure_item_id
1008 and ei.system_linkage_function <> 'BTC'
1009 and p.project_status_code <> 'CLOSED'
1010 and pt.project_type = p.project_type
1011 and pt.direct_flag = 'N'
1012 and t3.project_id = p.project_id
1013 and ei.task_id = t3.task_id
1014 and t3.top_task_id = t5.task_id
1015 and t5.ready_to_bill_flag = 'Y'
1016 and adl.cost_distributed_flag = 'Y'
1017 and ei.expenditure_item_date <= nvl(trunc(X_rev_or_bill_date),SYSDATE)
1018 and ei.expenditure_type = et.expenditure_type
1019 and adl.document_type = 'EXP'
1020 and adl.fc_status = 'A'
1021 and adl.adl_status = 'A'
1022 and ei.bill_hold_flag='O';
1023
1024 Begin
1025
1026 For Bill_Hold_Rec in one_time_hold
1027 loop
1028 /*
1029 Update gms_award_distributions
1030 set bill_hold_flag='N'
1031 where expenditure_item_id = Bill_Hold_Rec.expenditure_item_id
1032 and adl_line_num = Bill_Hold_Rec.adl_line_num
1033 and award_id = Bill_Hold_Rec.award_id
1034 and document_type='EXP'
1035 and adl_status = 'A';
1036 */
1037
1038 update pa_expenditure_items_all
1039 set bill_hold_flag='N'
1040 where expenditure_item_id = Bill_Hold_Rec.expenditure_item_id;
1041
1042 if sql%notfound then
1043
1044 gms_error_pkg.gms_message('GMS_NO_UPD_AWD_EXP_ADL',
1045 'AWD',
1046 Bill_Hold_Rec.award_id,
1047 'EXP',
1051 X_Exec_Type => 'C',
1048 Bill_Hold_Rec.expenditure_item_id,
1049 'ADL',
1050 Bill_Hold_Rec.adl_line_num,
1052 X_Err_Code => X_Err_Code,
1053 X_Err_Buff => X_Err_Buff);
1054 --RAISE_APPLICATION_ERROR(-20501,X_Err_Buff);
1055 EXIT;
1056 else
1057 X_Err_Code := 0;
1058 End if;
1059
1060 End loop;
1061
1062 -- Commit; -- Moved to Award_Billing
1063
1064 End ONE_TIME_BILL_HOLD;
1065
1066 -- PROCEDURE INSTALLMENT_AMOUNT, new procedure for storing amounts on installments
1067
1068 PROCEDURE INSTALLMENT_AMOUNT(X_Installment_id IN NUMBER,
1069 X_Rev_Bill_Amt IN NUMBER,
1070 X_Inst_amt IN OUT NOCOPY Inst_tab2,
1071 X_Actual_Project_Id IN NUMBER,
1072 X_Task_Id IN NUMBER,
1073 X_Err_Code IN OUT NOCOPY NUMBER,
1074 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1075 X_Count_Rec NUMBER;
1076 X_Counter NUMBER :=0;
1077 X_match VARCHAR2(1) := 'N';
1078 Begin
1079 X_Count_Rec := X_inst_amt.COUNT;
1080
1081 IF L_DEBUG = 'Y' THEN
1082 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - X_Count_Rec:'||X_Count_Rec,'C');
1083 END IF;
1084
1085 If nvl(X_Count_rec,0) > 0 then
1086
1087 IF L_DEBUG = 'Y' THEN
1088 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - If nvl(X_Count_rec,0) > 0','C');
1089 END IF;
1090
1091 for X_Rec_Count in 1..X_Count_Rec
1092 loop
1093
1094 IF L_DEBUG = 'Y' THEN
1095 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP','C');
1096 END IF;
1097
1098 X_Counter:= X_Counter+1;
1099
1100 if (X_inst_amt(X_Counter).installment_id = X_Installment_id
1101 and X_inst_amt(X_Counter).actual_project_id = X_Actual_Project_Id
1102 and nvl(X_inst_amt(X_Counter).actual_task_id,0) = nvl(X_Task_Id,0))
1103 then
1104 X_inst_amt(X_Counter).rev_bill_amount := X_inst_amt(X_Counter).rev_bill_amount + X_Rev_Bill_Amt;
1105 X_match := 'Y';
1106
1107 IF L_DEBUG = 'Y' THEN
1108 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN IF ','C');
1109 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN IF installment_id:'||X_inst_amt(X_Counter).installment_id,'C');
1110 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN IF actual_project_id:'||X_inst_amt(X_Counter).actual_project_id,'C');
1111 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN IF actual_task_id:'||X_inst_amt(X_Counter).actual_task_id,'C');
1112 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN IF rev_bill_amount:'||X_Rev_Bill_Amt,'C');
1113 END IF;
1114
1115 exit;
1116 end if;
1117
1118 end loop;
1119
1120 End if; -- nvl(X_Counter,0) > 0
1121
1122 if X_match ='N' then
1123
1124 X_inst_amt(nvl(X_Counter,0) + 1).installment_id := X_Installment_id;
1125 X_inst_amt(nvl(X_Counter,0) + 1).rev_bill_amount := X_Rev_Bill_Amt;
1126 X_inst_amt(nvl(X_Counter,0) + 1).actual_project_id := X_Actual_Project_Id;
1127 X_inst_amt(nvl(X_Counter,0) + 1).actual_task_id := X_Task_Id;
1128
1129 IF L_DEBUG = 'Y' THEN
1130 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN NO ','C');
1131 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN NO installment_id:'||X_Installment_id,'C');
1132 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN NO actual_project_id:'||X_Actual_Project_Id,'C');
1133 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN NO actual_task_id:'||X_Task_Id,'C');
1134 gms_error_pkg.gms_debug('INSTALLMENT_AMOUNT - IN LOOP - IN NO X_Rev_Bill_Amt:'||X_Rev_Bill_Amt,'C');
1135 END IF;
1136
1137 end if;
1138
1139 X_Err_Code := 0;
1140
1141 Exception
1142 WHEN OTHERS THEN
1143 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
1144 'SQLCODE',
1145 SQLCODE,
1146 'SQLERRM',
1147 SQLERRM,
1148 X_Exec_Type => 'C',
1149 X_Err_Code => X_Err_Code,
1150 X_Err_Buff => X_Err_Buff);
1151 --RAISE_APPLICATION_ERROR(-20502,X_Err_Buff);
1152 --RETURN;
1153
1154 End INSTALLMENT_AMOUNT;
1155
1156 ------------------------------------------------------------------------------
1157 /* New Procedure added for bug 5242484 */
1158
1159 PROCEDURE EI_ROLLBACK (
1160 x_award_id IN NUMBER,
1161 x_event_type IN VARCHAR2,
1162 x_expenditure_item_id IN NUMBER,
1163 x_adl_line_num IN NUMBER,
1164 x_actual_project_id IN NUMBER,
1165 x_task_id IN NUMBER,
1166 x_inst_cnt IN NUMBER
1167 )
1168 IS
1169
1170 x_award_project_id NUMBER := 0;
1171 i NUMBER := 0;
1172
1173
1174 BEGIN
1175
1176 /* --------------------------------------------------------------------------
1177 || Here's what we need to do :
1178 || 1. Updating gms_summary_project_fundings
1179 || 2. Deleting from gms_event_intersect
1180 || 3. Deleting from gms_burden_components
1181 || 4. Updating gms_award_distributions (revenue_distributed_flag/billed_flag)
1182 -------------------------------------------------------------------------- */
1183
1184 select award_project_id
1188
1185 into x_award_project_id
1186 from gms_awards_all where award_id = x_award_id ;
1187
1189 FOR i in 1..x_inst_cnt
1190 LOOP
1191 UPDATE gms_summary_project_fundings
1192 SET total_billed_amount = decode(x_event_type,'INVOICE',
1193 (total_billed_amount - X_ei_rollback_inst_tab(i).rev_bill_amount),total_billed_amount),
1194 total_revenue_amount = decode(x_event_type,'REVENUE',
1195 (total_revenue_amount - X_ei_rollback_inst_tab(i).rev_bill_amount),total_revenue_amount)
1196 WHERE project_id = x_actual_project_id
1197 AND ( task_id IS NULL
1198 OR task_id = x_task_id
1199 OR task_id = (select t.top_task_id
1200 from PA_TASKS t
1201 where t.task_id = x_task_id)
1202 )
1203 AND installment_id = X_ei_rollback_inst_tab(i).installment_id ;
1204
1205 END LOOP;
1206
1207 UPDATE gms_award_distributions
1208 SET revenue_distributed_flag = decode(x_event_type,'REVENUE','N',revenue_distributed_flag),
1209 billed_flag = decode(x_event_type,'INVOICE','N',billed_flag),
1210 last_update_date = SYSDATE,
1211 last_updated_by = fnd_global.user_id,
1212 last_update_login = fnd_global.login_id
1213 WHERE expenditure_item_id = x_expenditure_item_id
1214 AND document_type = 'EXP'
1215 AND adl_status = 'A'
1216 AND ( expenditure_item_id,adl_line_num ) in ( select expenditure_item_id, adl_line_num
1217 from gms_Event_intersect
1218 where expenditure_item_id = x_expenditure_item_id
1219 AND award_project_id = x_award_project_id
1220 AND event_num is NULL
1221 AND event_type = x_event_type
1222 union
1223 select expenditure_item_id, adl_line_num
1224 from gms_burden_components
1225 where expenditure_item_id = x_expenditure_item_id
1226 AND award_project_id = x_award_project_id
1227 AND event_num is NULL
1228 AND event_type = x_event_type );
1229
1230 DELETE FROM gms_event_intersect
1231 WHERE expenditure_item_id = x_expenditure_item_id
1232 AND award_project_id = x_award_project_id
1233 AND event_num is NULL
1234 AND event_type = x_event_type ;
1235
1236
1237 DELETE FROM gms_burden_components
1238 WHERE expenditure_item_id = x_expenditure_item_id
1239 AND award_project_id = x_award_project_id
1240 AND event_num IS NULL
1241 AND event_type = x_event_type ;
1242
1243 END ei_rollback;
1244
1245 /* End of new procedure for bug 5242484 */
1246
1247 -------------------------------------------------------------------------------
1248 PROCEDURE GET_SUMM_FUNDING(C_Installment_Id IN NUMBER,
1249 X_Expenditure_item_date IN DATE DEFAULT NULL,
1250 X_Award_Id IN NUMBER DEFAULT NULL,
1251 X_Task_Id IN NUMBER,
1252 X_Calling_Process IN VARCHAR2,
1253 X_Total_Funding_Amount OUT NOCOPY NUMBER,
1254 X_Total_Rev_Bill_Amount OUT NOCOPY NUMBER,
1255 X_Err_Code IN OUT NOCOPY NUMBER,
1256 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1257
1258 Begin
1259 select
1260 sum(total_funding_amount),
1261 sum(decode(X_Calling_Process,'Invoice',nvl(gmf.total_billed_amount,0),
1262 'Revenue',nvl(gmf.total_revenue_amount,0) ))
1263 into
1264 X_Total_Funding_Amount,
1265 X_Total_Rev_Bill_Amount
1266 from
1267 gms_summary_project_fundings gmf
1268 where
1269 (gmf.installment_id = nvl(C_Installment_Id,0) -- 11.5 changes, hard limit to award level
1270 OR
1271 (C_Installment_Id is NULL
1272 AND gmf.installment_id in
1273 (select installment_id
1274 from gms_installments
1275 where award_id = X_award_id
1276 and (trunc(end_date_Active) >= trunc(X_Expenditure_item_date))
1277 /* and active_flag = 'Y' Bug 6878405 */
1278 and nvl(billable_flag,'N') = 'Y'
1279 --order by end_date_active
1280 )
1281 )
1282 )
1283 and (
1284 (gmf.task_id = X_Task_Id)
1285 OR (gmf.task_id is NULL)
1286 OR (gmf.task_id = (select t.top_task_id from PA_TASKS t where t.task_id = X_Task_Id))
1287 )
1288 and gmf.project_id = (select project_id from PA_TASKS where task_id = X_Task_Id);
1289
1290
1291 --t.task_id = decode(gmf.task_id,null,t.task_id,gmf.task_id);
1292
1293 X_Err_Code := 0;
1294
1295 EXCEPTION
1296 WHEN NO_DATA_FOUND THEN
1297 X_Err_Code := 0;
1298 X_Total_Funding_Amount := -99;
1302
1299 X_Total_Rev_Bill_Amount := -99;
1300 END GET_SUMM_FUNDING;
1301 --------------------------------------------------------------------------------
1303 -- PROCEDURE: INSTALLMENT_CHECK, new procedure for Installment Check
1304
1305 PROCEDURE INSTALLMENT_CHECK(X_Installment_id IN NUMBER,
1306 X_Award_Id IN NUMBER,
1307 X_Task_Id IN NUMBER,
1308 X_Calling_Process IN VARCHAR2,
1309 X_Expenditure_item_date IN DATE,
1310 X_Money_In_Inst IN NUMBER,
1311 X_Money_In_Curr_Inst OUT NOCOPY NUMBER,
1312 X_Inst_Flag OUT NOCOPY VARCHAR2,
1313 X_Err_Code IN OUT NOCOPY NUMBER,
1314 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1315 X_temp_flag NUMBER;
1316 X_Total_Funding_Amount NUMBER(22,5);
1317 X_Total_Rev_Bill_Amount NUMBER(22,5);
1318
1319 Begin
1320
1321 GET_SUMM_FUNDING(X_Installment_id,
1322 X_Expenditure_Item_Date,
1323 X_Award_Id,
1324 X_Task_Id,
1325 X_calling_process,
1326 X_Total_Funding_Amount,
1327 X_Total_Rev_Bill_Amount,
1328 X_Err_Code,
1329 X_Err_Buff);
1330
1331 X_Money_In_Curr_Inst := X_Total_Funding_Amount - X_Total_Rev_Bill_Amount;
1332
1333 If X_Money_In_Curr_Inst >= 0 then /* Changed to 'greater than or equal to' for bug 5349106 */
1334
1335 X_Inst_Flag := 'A'; -- Money Available on current Installment
1336
1337 else
1338 If X_Money_In_Inst > 0 then
1339
1340 X_Inst_Flag := 'I'; -- Money Available on other Installment
1341
1342 elsif X_Money_In_Inst <= 0 then
1343
1344 X_Inst_Flag := 'N'; -- No other Installment exists
1345
1346 End if;
1347 End if;
1348
1349 X_Err_Code := 0;
1350
1351 EXCEPTION
1352 WHEN OTHERS THEN
1353 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
1354 'SQLCODE',
1355 SQLCODE,
1356 'SQLERRM',
1357 SQLERRM,
1358 X_Exec_Type => 'C',
1359 X_Err_Code => X_Err_Code,
1360 X_Err_Buff => X_Err_Buff);
1361 --RAISE_APPLICATION_ERROR(-20503,X_Err_Buff);
1362 --RETURN;
1363 End INSTALLMENT_CHECK;
1364
1365 --ETAX Enhancement : Replace the Output_Vat_tax_id with Output_Tax_Classification_code
1366 -- PROCEDURE: GMS_TAX, new procedure to calculate Tax Details for ADL
1367
1368 PROCEDURE GMS_TAX(X_Award_Project_Id IN NUMBER,
1369 X_Award_Id IN NUMBER,
1370 X_Rev_Or_Bill_Date IN DATE,
1371 X_Request_Id IN NUMBER,
1372 X_Err_Code IN OUT NOCOPY NUMBER,
1373 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1374
1375 X_Customer_Id pa_project_customers.customer_id%type;
1376 X_Bill_To_Site_Use_Id hz_cust_site_uses.site_use_id%type;
1377 X_Ship_To_Site_Use_Id hz_cust_site_uses.site_use_id%type;
1378
1379 /* This Cursor fetches expenditure items for which tax codes has to be calculated */
1380 Cursor get_exp_items is
1381 select --distinct
1382 adl.expenditure_item_id,
1383 adl.adl_line_num,
1384 adl.award_id
1385 from pa_expenditure_items_all ei,
1386 pa_projects_all p,
1387 pa_project_types pt,
1388 pa_tasks t3,
1389 pa_tasks t5,
1390 gms_award_distributions adl
1391 where adl.award_id = X_Award_Id
1392 and ei.expenditure_item_id = adl.expenditure_item_id
1393 and ei.system_linkage_function <> 'BTC'
1394 and p.project_status_code <> 'CLOSED'
1395 and pt.project_type = p.project_type
1396 and pt.direct_flag = 'N'
1397 and t3.project_id = p.project_id
1398 and ei.task_id = t3.task_id
1399 and t3.top_task_id = t5.task_id
1400 and t5.ready_to_bill_flag = 'Y'
1401 and adl.cost_distributed_flag = 'Y'
1402 and ei.expenditure_item_date <= nvl(trunc(X_rev_or_bill_date),SYSDATE)
1403 and adl.billed_flag = 'N' /* removed nvl for bug 6969435 */
1404 and adl.document_type='EXP'
1405 and adl.adl_status = 'A'
1406 and adl.fc_status = 'A'
1407 and adl.output_tax_exempt_flag is null;
1408
1409 -- Last clause, so that tax is calculated once for an ADL, either in Revenue or Invoice Process
1410
1411 F_Expenditure_Item_Id gms_award_distributions.expenditure_item_id%type;
1412 F_Adl_Line_Num gms_award_distributions.adl_line_num%type;
1413 F_Award_Id gms_award_distributions.award_id%type;
1414
1415 --S_Output_Vat_Tax_Id gms_award_distributions.output_vat_tax_id%type; --Changes for ETax
1416 S_Output_Tax_classify_code gms_award_distributions.output_tax_classification_code%type; --Changes for ETax
1417 S_Output_Tax_Exempt_Flag gms_award_distributions.output_tax_exempt_flag%type;
1418 S_Output_Tax_Exempt_Number gms_award_distributions.output_tax_exempt_number%type;
1419 S_Output_Exempt_Reason_Code gms_award_distributions.output_tax_exempt_reason_code%type;
1420
1421 X_Set_Of_Book_Id NUMBER(15);
1422
1423 -- Bug Fix 2994625
1424 -- Added new local variables to store bill_to_customer_id and ship_to_customer_id
1425
1426 l_Bill_to_customer_id PA_PROJECT_CUSTOMERS.BILL_TO_CUSTOMER_ID%TYPE;
1427 l_Ship_to_customer_id PA_PROJECT_CUSTOMERS.SHIP_TO_CUSTOMER_ID%TYPE;
1428
1429 -- End of Fix for Bug 2994625
1433 X_Err_Code := 0;
1430
1431 Begin
1432
1434
1435 -- STAGE 10 : GET SOB ID FROM PA_IMPLEMENTATIONS
1436 Begin
1437
1438 select set_of_books_id
1439 into X_Set_Of_Book_Id
1440 from pa_implementations;
1441
1442 Exception
1443 WHEN NO_DATA_FOUND THEN
1444 gms_error_pkg.gms_message('GMS_SOB_ID_NOT_FOUND',
1445 X_Exec_Type => 'C',
1446 X_Err_Code => X_Err_Code,
1447 X_Err_Buff => X_Err_Buff);
1448 --RAISE_APPLICATION_ERROR(-20504,X_Err_Buff);
1449 RETURN;
1450 End;
1451
1452 -- STAGE 20: RETRIEVE CUSTOMER AND SITE INFORMATION
1453
1454 -- Bug Fix 2994625
1455 -- Storing the bill_to_customer_id and ship_to_customer_id in the local variables
1456 -- End of Fix 2994625.
1457 --TCA Enhancement :Changed the reference from RA tables to HZ tables
1458 Begin
1459
1460 select distinct
1461 c.customer_id,
1462 c.bill_to_customer_id,
1463 c.ship_to_customer_id,
1464 ras.site_use_id,
1465 ras1.site_use_id
1466 into X_Customer_id,
1467 l_bill_to_customer_id,
1468 l_ship_to_customer_id,
1469 X_Bill_To_Site_Use_Id,
1470 X_Ship_To_Site_Use_Id
1471 from pa_project_customers c,
1472 hz_cust_accounts cust_acct,
1473 hz_cust_site_uses ras,
1474 hz_cust_site_uses ras1
1475 where c.project_id = X_Award_Project_Id
1476 -- and c.customer_id = rc.customer_id
1477 -- and nvl(rc.status,'A') = 'A'
1478 and c.customer_id = cust_acct.cust_account_id
1479 and nvl(cust_acct.status,'A') = 'A'
1480 and c.customer_bill_split <> 0
1481 --and ras.address_id = c.bill_to_address_id
1482 and ras.cust_acct_site_id = c.bill_to_address_id
1483 and ras.site_use_code || '' = 'BILL_TO'
1484 and ras.status || '' = 'A'
1485 -- and ras1.address_id = c.ship_to_address_id
1486 and ras1. cust_acct_site_id = c.ship_to_address_id
1487 and ras1.site_use_code || '' = 'SHIP_TO'
1488 and ras1.status || '' = 'A';
1489
1490 EXCEPTION
1491 WHEN NO_DATA_FOUND THEN
1492 gms_error_pkg.gms_message('GMS_NO_SITE_CUST',
1493 'PRJ',
1494 X_Award_Project_Id,
1495 X_Exec_Type => 'C',
1496 X_Err_Code => X_Err_Code,
1497 X_Err_Buff => X_Err_Buff);
1498 --RAISE_APPLICATION_ERROR(-20505,X_Err_Buff);
1499 RETURN;
1500
1501 WHEN TOO_MANY_ROWS THEN
1502 gms_error_pkg.gms_message('GMS_MORE_THAN_ONE_SITE_CUST',
1503 'PRJ',
1504 X_Award_Project_Id,
1505 X_Exec_Type => 'C',
1506 X_Err_Code => X_Err_Code,
1507 X_Err_Buff => X_Err_Buff);
1508 --RAISE_APPLICATION_ERROR(-20506,X_Err_Buff);
1509 RETURN;
1510
1511 WHEN OTHERS THEN
1512 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
1513 'SQLCODE',
1514 SQLCODE,
1515 'SQLERRM',
1516 SQLERRM,
1517 X_Exec_Type => 'C',
1518 X_Err_Code => X_Err_Code,
1519 X_Err_Buff => X_Err_Buff);
1520 --RAISE_APPLICATION_ERROR(-20507,X_Err_Buff);
1521 RETURN;
1522 End;
1523
1524
1525 -- STAGE 30: OPEN CURSOR TO FETCH RECORDS FROM ADL TABLE
1526
1527 Open get_exp_items;
1528 Loop
1529 Fetch get_exp_items into F_Expenditure_Item_Id, F_Adl_Line_Num, F_Award_Id;
1530 Exit When get_exp_items%NOTFOUND;
1531
1532 -- STAGE 40: CALL PA'S TAX CALCULATION PROCEDURE
1533
1534 -- Bug Fix 2994625
1535 -- passing the bill_to_customer_id and ship_to_customer_id in the call to pa_output_tax.get_default_tax_info.
1536 -- End of Fix 2994625.
1537
1538 pa_output_tax.get_default_tax_info(p_project_id => X_Award_Project_Id,
1539 P_Draft_Inv_Num => NULL, -- Invoice number
1540 P_Customer_Id => X_Customer_Id,
1541 P_Bill_to_site_use_id => X_Bill_To_Site_Use_Id,
1542 P_Ship_to_site_use_id =>X_Ship_To_Site_Use_Id,
1543 P_Sets_of_books_id => X_Set_Of_Book_Id,
1544 P_Event_id => NULL, -- Event Number
1545 P_Expenditure_item_id =>F_Expenditure_Item_Id,
1546 P_User_Id => fnd_global.user_id,
1547 P_Request_id => X_Request_id,
1548 --S_Output_Vat_Tax_Id,
1549 X_Output_tax_exempt_flag => S_Output_Tax_Exempt_Flag,
1550 X_Output_tax_exempt_number => S_Output_Tax_Exempt_number,
1551 X_Output_exempt_reason_code => S_Output_Exempt_Reason_Code,
1552 X_Output_tax_code => S_Output_Tax_classify_code,
1553 Pbill_to_customer_id => l_bill_to_customer_id,
1554 Pship_to_customer_id => l_ship_to_customer_id
1555 );
1556
1557 -- STAGE 50: UPDATE ADL LINES WITH TAX INFORMATION
1558
1559 Begin
1560
1561 Update gms_award_distributions
1562 set
1563 --output_vat_tax_id = S_Output_Vat_Tax_Id,
1564 output_tax_classification_code = S_Output_tax_classify_code,
1565 output_tax_exempt_flag = S_Output_Tax_Exempt_Flag,
1566 output_tax_exempt_number = S_Output_Tax_Exempt_Number,
1567 output_tax_exempt_reason_code = S_Output_Exempt_Reason_Code,
1568 last_update_date = sysdate,
1572 and adl_line_num = F_Adl_Line_Num
1569 last_update_login = fnd_global.login_id,
1570 last_updated_by = fnd_global.user_id
1571 where expenditure_item_id = F_Expenditure_Item_Id
1573 and award_id = X_Award_Id
1574 and document_type ='EXP'
1575 and adl_status = 'A'
1576 and output_tax_exempt_flag is null;
1577
1578
1579 If SQL%ROWCOUNT = 0 then
1580 gms_error_pkg.gms_message('GMS_NO_UPD_AWD_EXP',
1581 'AWD',
1582 X_Award_Id,
1583 'EXP',
1584 F_Expenditure_Item_Id,
1585 X_Exec_Type => 'C',
1586 X_Err_Code => X_Err_Code,
1587 X_Err_Buff => X_Err_Buff);
1588 --RAISE_APPLICATION_ERROR(-20508,X_Err_Buff);
1589 RETURN;
1590 Else
1591 X_Err_Code := 0;
1592 End If;
1593 End;
1594
1595 End Loop; -- get_exp_items
1596
1597 X_Err_Code := 0;
1598
1599 End GMS_TAX;
1600
1601 -- PROCEDURE: GET_INSTALLMENT_NUM, new procedure to get Installment Number's in case of splits
1602
1603 PROCEDURE GET_INSTALLMENT_NUM(X_Installment_id IN NUMBER,
1604 X_Award_Id IN NUMBER,
1605 X_Task_Id IN NUMBER,
1606 X_Expenditure_item_date IN DATE,
1607 X_Calling_Process IN VARCHAR2,
1608 X_Money_In_Inst IN NUMBER,
1609 X_Inst_Task_Run_Total IN NUMBER,
1610 X_Inst_Flag IN VARCHAR2,
1611 X_Inst_tab OUT NOCOPY Inst_tab,
1612 X_Inst_Count OUT NOCOPY NUMBER,
1613 X_Err_Code IN OUT NOCOPY NUMBER,
1614 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1615
1616 X_Count NUMBER(2) :=0;
1617 X_Diff_Amount NUMBER(22,5) :=0;
1618 X_Fund_Amt NUMBER(22,5) :=0;
1619 X_Total_Amt NUMBER(22,5) :=0;
1620 X_RB_Amt NUMBER(22,5) :=0;
1621 X_Installment NUMBER(15);
1622
1623 Cursor Inst_Id is
1624 select ins.installment_id installment_id,
1625 gmf.total_funding_amount total_funding_amount,
1626 decode(X_Calling_Process,'Invoice',nvl(gmf.total_billed_amount,0),'Revenue',nvl(gmf.total_revenue_amount,0)) Inv_Rev_Amount
1627 from gms_installments ins,
1628 gms_summary_project_fundings gmf
1629 where ins.award_id = X_award_id
1630 and trunc(ins.end_date_active) >= trunc(X_Expenditure_item_date)
1631 /* and ins.active_flag = 'Y' Bug 6878405 */
1632 and nvl(ins.billable_flag,'N') = 'Y'
1633 and ins.Installment_id = gmf.Installment_id
1634 and (gmf.total_funding_amount - decode(X_Calling_Process,'Invoice',nvl(gmf.total_billed_amount,0),
1635 'Revenue',nvl(gmf.total_revenue_amount,0) )) >0
1636 and ((gmf.task_id = X_Task_Id)
1637 OR (gmf.task_id is NULL)
1638 OR (gmf.task_id = (select t.top_task_id from PA_TASKS t where t.task_id = X_Task_Id))
1639 )
1640 and gmf.project_id = (select project_id from PA_TASKS where task_id = X_Task_Id)
1641 and ins.installment_id <> X_Installment_id
1642 order by ins.end_date_active;
1643
1644 Begin
1645
1646 X_Inst_tab.delete; -- initialize
1647
1648 X_Inst_Count:=0;
1649
1650 If X_Inst_Flag = 'N' then
1651
1652 X_Inst_Count :=1;
1653 X_Diff_Amount :=0;
1654
1655 Else
1656
1657 If X_Money_In_Inst >= X_Inst_Task_Run_Total then
1658
1659 X_Inst_Count :=1;
1660 X_Diff_Amount :=0;
1661 Else
1662 /* Added IF for bug 5349106 */
1663 IF X_Inst_flag = 'A' then
1664
1665 X_Inst_Count :=1;
1666
1667 X_Inst_tab(X_Inst_Count).Installment_id := X_Installment_id;
1668 X_Inst_tab(X_Inst_Count).Rev_Bill_Amount := X_Money_In_Inst;
1669
1670 X_Diff_Amount := X_Inst_Task_Run_Total - X_Money_In_Inst;
1671 End If; /* For Bug 5349106 */
1672
1673 Open Inst_Id;
1674 Loop
1675 Fetch Inst_id into X_Installment, X_Total_Amt, X_RB_Amt;
1676 exit when Inst_id%notfound;
1677
1678 X_Inst_Count := X_Inst_Count + 1;
1679
1680 X_Fund_Amt := X_Total_Amt - X_RB_Amt ;
1681
1682 If X_Fund_Amt > X_Diff_Amount then
1683
1684 X_Inst_tab(X_Inst_Count).Installment_id := X_Installment;
1685 X_Inst_tab(X_Inst_Count).Rev_Bill_Amount := X_Diff_Amount;
1686 X_Diff_Amount := 0;
1687 exit; -- exit loop
1688
1689 Else
1690
1691 X_Inst_tab(X_Inst_Count).Installment_id := X_Installment;
1692 X_Inst_tab(X_Inst_Count).Rev_Bill_Amount := X_Fund_Amt;
1693
1694 X_Diff_Amount := X_Diff_Amount - X_Fund_Amt;
1695
1696 End if;
1697 End Loop;
1698
1699 Close Inst_Id;
1700 End if; -- X_Money_In_Inst >= X_Inst_Task_Run_Total then
1701 End if; -- X_Inst_Flag = 'N' then
1702
1703 If X_Diff_Amount > 0 then
1704
1705 X_Inst_tab(X_Inst_tab.Last).Rev_Bill_Amount := X_Inst_tab(X_Inst_tab.Last).Rev_Bill_Amount + X_Diff_Amount;
1706
1707 End if;
1708
1709 X_Err_Code := 0;
1710
1711 EXCEPTION
1712 WHEN OTHERS THEN
1713 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
1714 'SQLCODE',
1715 SQLCODE,
1716 'SQLERRM',
1717 SQLERRM,
1721 --RAISE_APPLICATION_ERROR(-20509,X_Err_Buff);
1718 X_Exec_Type => 'C',
1719 X_Err_Code => X_Err_Code,
1720 X_Err_Buff => X_Err_Buff);
1722 RETURN;
1723
1724 End GET_INSTALLMENT_NUM;
1725
1726
1727 -- PROCEDURE: INSERT_EVENT, new procedure to insert records into GMS_EVENT_ATTRIBUTE table
1728
1729 PROCEDURE INSERT_EVENT(X_AWARD_PROJECT_ID IN NUMBER DEFAULT NULL,
1730 X_EVENT_NUM IN NUMBER DEFAULT NULL,
1731 X_INSTALLMENT_ID IN NUMBER DEFAULT NULL,
1732 X_ACTUAL_PROJECT_ID IN NUMBER DEFAULT NULL,
1733 X_ACTUAL_TASK_ID IN NUMBER DEFAULT NULL,
1734 X_BURDEN_COST_CODE IN VARCHAR2 DEFAULT NULL,
1735 X_EXPENDITURE_ORG_ID IN NUMBER DEFAULT NULL,
1736 X_BILL_AMOUNT IN NUMBER DEFAULT NULL,
1737 X_REVENUE_AMOUNT IN NUMBER DEFAULT NULL,
1738 X_REQUEST_ID IN NUMBER DEFAULT NULL,
1739 X_EXPENDITURE_TYPE IN VARCHAR2 DEFAULT NULL,
1740 X_Err_Code IN OUT NOCOPY NUMBER,
1741 X_Err_Buff IN OUT NOCOPY VARCHAR2,
1742 X_Calling_Process IN VARCHAR2 DEFAULT NULL) IS
1743
1744 Begin
1745 /* Insert into GMS_EVENT_ATTRIBUTE_TABLE */
1746
1747 INSERT INTO GMS_EVENT_ATTRIBUTE(
1748 PROJECT_ID,
1749 EVENT_NUM,
1750 INSTALLMENT_ID,
1751 ACTUAL_PROJECT_ID,
1752 ACTUAL_TASK_ID,
1753 BURDEN_COST_CODE,
1754 EXPENDITURE_ORG_ID,
1755 BILL_AMOUNT,
1756 REVENUE_AMOUNT,
1757 WRITE_OFF_AMOUNT,
1758 CREATED_BY,
1759 CREATED_DATE,
1760 LAST_UPDATED_BY,
1761 LAST_UPDATE_DATE,
1762 LAST_UPDATE_LOGIN,
1763 REVENUE_ACCUMULATED,
1764 RESOURCE_LIST_MEMBER_ID,
1765 REQUEST_ID,
1766 EXPENDITURE_TYPE,
1767 EVENT_CALLING_PROCESS)
1768 VALUES(X_AWARD_PROJECT_ID,
1769 X_EVENT_NUM,
1770 X_INSTALLMENT_ID,
1771 X_ACTUAL_PROJECT_ID,
1772 X_ACTUAL_TASK_ID,
1773 X_BURDEN_COST_CODE,
1774 X_EXPENDITURE_ORG_ID,
1775 NVL(X_BILL_AMOUNT,0),
1776 NVL(X_REVENUE_AMOUNT,0),
1777 0, -- Write_Off_Amount
1778 fnd_global.user_id,
1779 sysdate,
1780 fnd_global.user_id,
1781 sysdate,
1782 fnd_global.login_id,
1783 'N', -- Revenue_Accumulated
1784 NULL, -- RLMI
1785 X_REQUEST_ID,
1786 X_EXPENDITURE_TYPE,
1787 X_Calling_Process
1788 );
1789
1790 X_Err_Code := 0;
1791
1792 Exception
1793 WHEN OTHERS THEN
1794 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
1795 'SQLCODE',
1796 SQLCODE,
1797 'SQLERRM',
1798 SQLERRM,
1799 X_Exec_Type => 'C',
1800 X_Err_Code => X_Err_Code,
1801 X_Err_Buff => X_Err_Buff);
1802 --RAISE_APPLICATION_ERROR(-20510,X_Err_Buff);
1803 RETURN;
1804
1805 End INSERT_EVENT;
1806
1807
1808 -- PROCEDURE: UPDATE_EVENT, new procedure to update GMS_EVENT_ATTRIBUTE table records
1809
1810 PROCEDURE UPDATE_EVENT(X_AWARD_PROJECT_ID IN NUMBER DEFAULT NULL,
1811 X_EVENT_NUM IN NUMBER DEFAULT NULL,
1812 X_INSTALLMENT_ID IN NUMBER DEFAULT NULL,
1813 X_ACTUAL_PROJECT_ID IN NUMBER DEFAULT NULL,
1814 X_ACTUAL_TASK_ID IN NUMBER DEFAULT NULL,
1815 X_BURDEN_COST_CODE IN VARCHAR2 DEFAULT NULL,
1816 X_EXPENDITURE_ORG_ID IN NUMBER DEFAULT NULL,
1817 X_BILL_AMOUNT IN NUMBER DEFAULT NULL,
1818 X_REVENUE_AMOUNT IN NUMBER DEFAULT NULL,
1819 X_REQUEST_ID IN NUMBER DEFAULT NULL,
1820 X_EXPENDITURE_TYPE IN VARCHAR2 DEFAULT NULL,
1821 X_Err_Code IN OUT NOCOPY NUMBER,
1822 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1823
1824 Begin
1825 /* Update GMS_EVENT_ATTRIBUTE record */
1826
1827 UPDATE GMS_EVENT_ATTRIBUTE
1828 SET installment_id = X_INSTALLMENT_ID,
1829 actual_project_id = X_ACTUAL_PROJECT_ID,
1830 actual_task_id = X_ACTUAL_TASK_ID,
1831 burden_cost_code = X_BURDEN_COST_CODE,
1832 expenditure_org_id = X_EXPENDITURE_ORG_ID,
1833 bill_amount = nvl(X_BILL_AMOUNT,0),
1834 revenue_amount = nvl(X_REVENUE_AMOUNT,0),
1835 expenditure_type = X_EXPENDITURE_TYPE,
1836 last_updated_by = fnd_global.user_id,
1837 last_update_date = sysdate,
1838 last_update_login = fnd_global.login_id,
1839 request_id = X_REQUEST_ID
1840 WHERE project_id = X_AWARD_PROJECT_ID
1841 AND event_num = X_EVENT_NUM
1842 AND event_calling_process IS NULL; --Added for bug 2979125
1843
1844 If SQL%ROWCOUNT = 0 then
1845
1846 gms_error_pkg.gms_message('GMS_NO_UPD_PRJ_EVT',
1847 'PRJ',
1848 X_AWARD_PROJECT_ID,
1849 'EVT',
1850 X_EVENT_NUM,
1851 X_Exec_Type => 'C',
1852 X_Err_Code => X_Err_Code,
1853 X_Err_Buff => X_Err_Buff);
1854 --ROLLBACK;
1855 --RAISE_APPLICATION_ERROR(-20511,X_Err_Buff);
1859
1856 --Raise NO_PROCESSING_OF_AWARD ;
1857
1858 RETURN;
1860 Else
1861 X_Err_Code := 0;
1862 End If;
1863
1864 END UPDATE_EVENT;
1865
1866 -- PROCEDURE: DELETE_EVENT, new procedure to delete records from GMS_EVENT_ATTRIBUTE table
1867
1868 PROCEDURE DELETE_EVENT (X_AWARD_PROJECT_ID IN NUMBER,
1869 X_EVENT_NUM IN NUMBER,
1870 X_INSTALLMENT_ID IN NUMBER,
1871 X_Err_Code IN OUT NOCOPY NUMBER,
1872 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1873
1874 Begin
1875 /* Delete from GMS_EVENT_ATTRIBUTE_TABLE */
1876
1877 DELETE
1878 FROM gms_event_attribute
1879 WHERE project_id = X_AWARD_PROJECT_ID
1880 AND event_num = X_EVENT_NUM
1881 AND installment_id = X_INSTALLMENT_ID
1882 AND event_calling_process IS NULL; --Added for bug 2979125
1883
1884 If SQL%ROWCOUNT = 0 then
1885 gms_error_pkg.gms_message('GMS_NO_DATA_PRJ_EVT_INST',
1886 'PRJ',
1887 X_AWARD_PROJECT_ID,
1888 'EVT',
1889 X_EVENT_NUM,
1890 'INST',
1891 X_Installment_Id,
1892 X_Exec_Type => 'C',
1893 X_Err_Code => X_Err_Code,
1894 X_Err_Buff => X_Err_Buff);
1895 --ROLLBACK;
1896 --RAISE_APPLICATION_ERROR(-20512,X_Err_Buff);
1897 --Raise NO_PROCESSING_OF_AWARD ;
1898 -- RETURN;
1899 Else
1900 X_Err_Code := 0;
1901 End If;
1902
1903 END DELETE_EVENT;
1904
1905 -- FUNCTION get_total_adl_raw_cost is a new procedure to get the total billable amount from ADL
1906 -- Bug 3235390
1907
1908 FUNCTION get_total_adl_raw_cost( x_billing_type IN VARCHAR2,
1909 X_EXPENDITURE_ITEM_ID IN NUMBER ) RETURN NUMBER IS
1910 l_raw_cost NUMBER:=NULL;
1911 BEGIN
1912
1913 IF L_DEBUG = 'Y' THEN
1914 gms_error_pkg.gms_debug('IN get_total_adl_raw_cost - Start ','C');
1915 END IF;
1916
1917 SELECT NVL(SUM(raw_cost),0)
1918 INTO l_raw_cost
1919 FROM gms_award_distributions
1920 WHERE expenditure_item_id = X_Expenditure_item_id
1921 AND document_type = 'EXP' -- To pick up only actuals and not encumbrances
1922 AND adl_status = 'A'
1923 AND fc_status = 'A'
1924 AND billable_flag = 'Y';
1925
1926 RETURN l_raw_cost;
1927
1928 EXCEPTION
1929 WHEN OTHERS THEN
1930
1931 IF L_DEBUG = 'Y' THEN
1932 gms_error_pkg.gms_debug('IN get_total_adl_raw_cost - WHEN OTHERS ','C');
1933 END IF;
1934 RETURN l_raw_cost;
1935
1936 END get_total_adl_raw_cost;
1937
1938
1939 --PROCEDURE EVENT_WARPPER, new procedure to build installment num for event desc and create event_attribute record
1940
1941 PROCEDURE EVENT_WRAPPER(X_Award_Project_Id IN NUMBER,
1942 X_Actual_Project_Id IN NUMBER,
1943 X_Task_Id IN NUMBER,
1944 X_Calling_Process IN VARCHAR2,
1945 X_Evt_Amount IN NUMBER,
1946 X_Installment_Total IN OUT NOCOPY Inst_tab2,
1947 -- X_Evt_Inst_Num OUT NOCOPY VARCHAR2, -- Bug 2380344
1948 X_Burden_Cost_Code IN VARCHAR2 DEFAULT NULL,
1949 X_Exp_Org_Id IN NUMBER DEFAULT NULL,
1950 X_Request_Id IN NUMBER DEFAULT NULL,
1951 X_Err_Code IN OUT NOCOPY NUMBER,
1952 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
1953
1954 X_Row_Count NUMBER:=0;
1955 X_Diff_Amount NUMBER(22,5) :=0;
1956 X_Bill_Amount NUMBER(22,5) :=0;
1957 X_Rev_Amount NUMBER(22,5) :=0;
1958
1959 x_plsql_installment_id number(15);
1960 x_plsql_project_id number(15);
1961 x_plsql_task_id number(15);
1962 x_plsql_amount number(22,5) :=0;
1963 x_plsql_count number := 0;
1964
1965 Begin
1966
1967 IF L_DEBUG = 'Y' THEN
1968 gms_error_pkg.gms_debug('-- Start Calculation Process --','C');
1969 END IF;
1970
1971 X_Row_Count := X_Installment_Total.COUNT;
1972
1973 X_Diff_Amount := X_Evt_Amount;
1974
1975 IF L_DEBUG = 'Y' THEN
1976 gms_error_pkg.gms_debug('X_Row_Count'||X_Row_Count,'C');
1977 gms_error_pkg.gms_debug('X_Diff_Amount'||X_Diff_Amount,'C');
1978 gms_error_pkg.gms_debug('X_Actual_Project_Id :'||X_Actual_Project_Id,'C');
1979 gms_error_pkg.gms_debug('X_Task_Id :'||X_Task_Id,'C');
1980 END IF;
1981
1982 If X_Row_Count > 0 then
1983
1984 -- Stage 1: Event_Desc Creation and Event_Attribute record creation
1985
1986 for Rec_Count in 1..X_Row_Count
1987 loop
1988
1989 IF L_DEBUG = 'Y' THEN
1990 gms_error_pkg.gms_debug('PLSQL - APID:'||X_Installment_Total(Rec_Count).Actual_Project_Id,'C');
1991 gms_error_pkg.gms_debug('PLSQL - ATID:'||X_Installment_Total(Rec_Count).Actual_Task_Id,'C');
1992 gms_error_pkg.gms_debug('X_Diff_Amount:'||X_Diff_Amount,'C');
1993 gms_error_pkg.gms_debug('X_Installment_Total(Rec_Count).Rev_bill_Amount:'||X_Installment_Total(Rec_Count).Rev_bill_Amount,'C');
1994 END IF;
1995
1996 If X_Installment_Total(Rec_Count).Actual_Project_Id = X_Actual_Project_Id and
2000 x_plsql_project_id := X_Installment_Total(Rec_Count).Actual_Project_Id;
1997 nvl(X_Installment_Total(Rec_Count).Actual_Task_Id,0) = X_Task_Id then
1998
1999 x_plsql_installment_id := X_Installment_Total(Rec_Count).Installment_Id;
2001 x_plsql_task_id := X_Installment_Total(Rec_Count).Actual_Task_Id;
2002 x_plsql_count := rec_count;
2003
2004 IF L_DEBUG = 'Y' THEN
2005 gms_error_pkg.gms_debug(' ---------rec_count----------- '||rec_count,'C');
2006 gms_error_pkg.gms_debug('In If APID / ATID ','C');
2007 END IF;
2008
2009 If X_Installment_Total(Rec_Count).Rev_bill_Amount > 0 then
2010
2011 IF L_DEBUG = 'Y' THEN
2012 gms_error_pkg.gms_debug('In If PLsql amt > 0','C');
2013 END IF;
2014
2015 If X_Installment_Total(Rec_Count).Rev_bill_Amount >= X_Diff_Amount then
2016
2017 IF L_DEBUG = 'Y' THEN
2018 gms_error_pkg.gms_debug('In If Plsql amt > diff ','C');
2019 END IF;
2020
2021 X_Installment_Total(Rec_Count).Rev_bill_Amount:=X_Installment_Total(Rec_Count).Rev_bill_Amount - X_Diff_Amount;
2022
2023 /* Event Attribute Creation */
2024
2025 If X_calling_Process = 'Invoice' then
2026 X_Bill_Amount := X_Diff_Amount;
2027 X_Rev_Amount := 0;
2028 Elsif X_Calling_Process = 'Revenue' then
2029 X_Bill_Amount := 0;
2030 X_Rev_Amount := X_Diff_Amount;
2031 End if;
2032
2033 IF L_DEBUG = 'Y' THEN
2034 gms_error_pkg.gms_debug('EVENT WRAPPER - BEFORE INSERT EVENT +VE PLSQL>DIFF','C');
2035 END IF;
2036
2037 INSERT_EVENT(X_Award_Project_Id,
2038 NULL, -- event number
2039 X_Installment_Total(Rec_Count).Installment_id,
2040 X_Actual_Project_id,
2041 X_Task_Id,
2042 X_Burden_Cost_Code,
2043 X_Exp_Org_Id,
2044 X_Bill_Amount,
2045 X_Rev_Amount,
2046 X_Request_Id,
2047 NULL, -- expenditure type,
2048 X_Err_Code,
2049 X_Err_Buff,
2050 X_calling_Process);
2051
2052 If X_Err_Code <> 0 then
2053 Raise NO_PROCESSING_OF_AWARD ;
2054 End If;
2055
2056 IF L_DEBUG = 'Y' THEN
2057 gms_error_pkg.gms_debug('EVENT WRAPPER - AFTER INSERT EVENT +VE PLSQL>DIFF','C');
2058 END IF;
2059
2060 /* Event Attribute Creation */
2061
2062 X_Diff_Amount:=0;
2063
2064 exit;
2065
2066 else -- X_Installment_Total(Rec_Count).Rev_bill_Amount >= X_Diff_Amount
2067
2068 IF L_DEBUG = 'Y' THEN
2069 gms_error_pkg.gms_debug('In Diff > Plsql','C');
2070 END IF;
2071
2072 -- =============================================================================
2073 -- BUG:1714882 - GENERATE DRAFT INVOICES ON A RANGE OF AWARDS ORA-20154 CALCULATION ERROR
2074 -- BUG:1689442 - CALCULATION ERROR IN REVENUE PROCESS
2075 -- Following lines were commented out NOCOPY to resolve the fix.
2076 -- ======================================================================================
2077 --X_Diff_Amount:= X_Diff_Amount - X_Installment_Total(Rec_Count).Rev_bill_Amount;
2078 --X_Installment_Total(Rec_Count).Rev_bill_Amount:=0;
2079
2080 -- ======================================================================================
2081 -- Following lines were added to solve the fix.
2082 -- ======================================================================================
2083 If x_plsql_count = X_Row_Count then
2084 X_Installment_Total(Rec_Count).Rev_bill_Amount:= X_Installment_Total(Rec_Count).Rev_bill_Amount - X_Diff_Amount ;
2085 X_plsql_amount := X_Diff_Amount;
2086 X_Diff_Amount := 0 ;
2087
2088 Else
2089 X_Diff_Amount:= X_Diff_Amount - X_Installment_Total(Rec_Count).Rev_bill_Amount;
2090 X_plsql_amount := X_Installment_Total(Rec_Count).Rev_bill_Amount;
2091 X_Installment_Total(Rec_Count).Rev_bill_Amount:=0;
2092
2093 End If;
2094 -- ======================================================================================
2095 -- END OF THE FIX.
2096 -- ======================================================================================
2097
2098 /* Event Attribute Creation */
2099
2100 If X_calling_Process = 'Invoice' then
2101 X_Bill_Amount := X_plsql_amount;
2102 X_Rev_Amount := 0;
2103 Elsif X_Calling_Process = 'Revenue' then
2104 X_Bill_Amount := 0;
2105 X_Rev_Amount := X_plsql_amount;
2106 End if;
2107
2108 IF L_DEBUG = 'Y' THEN
2109 gms_error_pkg.gms_debug('EVENT WRAPPER - BEFORE INSERT EVENT +VE PLSQL<DIFF','C');
2110 END IF;
2111
2112 INSERT_EVENT(X_Award_Project_Id,
2113 NULL, -- event number
2114 X_Installment_Total(Rec_Count).Installment_id,
2115 X_Actual_Project_id,
2116 X_Task_Id,
2117 X_Burden_Cost_Code,
2118 X_Exp_Org_Id,
2122 NULL, -- Expenditure_Type
2119 X_Bill_Amount,
2120 X_Rev_Amount,
2121 X_Request_Id,
2123 X_Err_Code,
2124 X_Err_Buff,
2125 X_calling_Process);
2126
2127 If X_Err_Code <> 0 then
2128 --ROLLBACK;
2129 --RAISE FND_API.G_EXC_ERROR;
2130 Raise NO_PROCESSING_OF_AWARD ;
2131 End If;
2132
2133 IF L_DEBUG = 'Y' THEN
2134 gms_error_pkg.gms_debug('EVENT WRAPPER - AFTER INSERT EVENT +VE PLSQL<DIFF','C');
2135 END IF;
2136
2137 /* Event Attribute Creation */
2138
2139 End if; -- X_Installment_Total(Rec_Count).Rev_bill_Amount >= X_Diff_Amount
2140
2141 /* ----------------------------------------------------------------------------*/
2142 ELSIf ( X_Installment_Total(Rec_Count).Rev_bill_Amount < 0 ) then
2143
2144 IF L_DEBUG = 'Y' THEN
2145 gms_error_pkg.gms_debug('-ve amount','C');
2146 END IF;
2147
2148 If X_calling_Process = 'Invoice' then
2149 X_Bill_Amount := X_Diff_Amount;
2150 X_Rev_Amount := 0;
2151 Elsif X_Calling_Process = 'Revenue' then
2152 X_Bill_Amount := 0;
2153 X_Rev_Amount := X_Diff_Amount;
2154 End if;
2155
2156 IF L_DEBUG = 'Y' THEN
2157 gms_error_pkg.gms_debug('EVENT WRAPPER - BEFORE INSERT EVENT -VE','C');
2158 END IF;
2159
2160 INSERT_EVENT(X_Award_Project_Id,
2161 NULL, -- event number
2162 X_Installment_Total(Rec_Count).Installment_id,
2163 X_Actual_Project_id,
2164 X_Task_Id,
2165 X_Burden_Cost_Code,
2166 X_Exp_Org_Id,
2167 X_Bill_Amount,
2168 X_Rev_Amount,
2169 X_Request_Id,
2170 NULL, -- Expenditure_Type
2171 X_Err_Code,
2172 X_Err_Buff,
2173 X_calling_Process);
2174
2175 If X_Err_Code <> 0 then
2176 Raise NO_PROCESSING_OF_AWARD ;
2177 End If;
2178
2179 IF L_DEBUG = 'Y' THEN
2180 gms_error_pkg.gms_debug('EVENT WRAPPER - AFTER INSERT EVENT -VE','C');
2181 END IF;
2182
2183 IF X_Diff_Amount>0 THEN
2184 IF L_DEBUG = 'Y' THEN
2185 gms_error_pkg.gms_debug('X_diff > 0','C');
2186 END IF;
2187 X_Installment_Total(Rec_Count).Rev_bill_Amount:=
2188 X_Installment_Total(Rec_Count).Rev_bill_Amount - X_Diff_Amount;
2189 else
2190 IF L_DEBUG = 'Y' THEN
2191 gms_error_pkg.gms_debug('X_Diff < 0','C');
2192 END IF;
2193 X_Installment_Total(Rec_Count).Rev_bill_Amount:=
2194 X_Installment_Total(Rec_Count).Rev_bill_Amount + X_Diff_Amount;
2195
2196 END IF;
2197
2198 X_Diff_Amount := 0;
2199 /* ----------------------------------------------------------------------------*/
2200
2201 -- --------------------------------------------------------------------
2202 -- Following code has been added for null events (event num -1)
2203 -- --------------------------------------------------------------------
2204 ELSIf ( X_Installment_Total(Rec_Count).Rev_bill_Amount = 0 ) then
2205
2206 -- -----------------------------------------------------------------------------
2207 If X_INVRAW_NULL_EVENT_PROCESSED THEN
2208
2209 IF L_DEBUG = 'Y' THEN
2210 gms_error_pkg.gms_debug('EVENT WRAPPER - BEFORE ZERO $ EVENT INSERT','C');
2211 END IF;
2212
2213 INSERT_EVENT(X_Award_Project_Id,
2214 -1, -- event_num
2215 X_Installment_Total(Rec_Count).Installment_id,
2216 X_Actual_Project_id,
2217 X_Task_Id,
2218 NULL, --X_Burden_Cost_Code,
2219 NULL, --X_Exp_Org_Id,
2220 0,
2221 0,
2222 X_Request_Id,
2223 NULL, -- expenditure type,
2224 X_Err_Code,
2225 X_Err_Buff,
2226 X_calling_Process);
2227
2228 If X_Err_Code <> 0 then
2229 Raise NO_PROCESSING_OF_AWARD ;
2230 End If;
2231
2232 IF L_DEBUG = 'Y' THEN
2233 gms_error_pkg.gms_debug('EVENT WRAPPER - AFTER ZERO $ EVENT INSERT ','C');
2234 END IF;
2235
2236 End If;
2237 -- -----------------------------------------------------------------------------
2238
2239 End if; -- X_Installment_Total(Rec_Count).Rev_bill_Amount > 0
2240 End if; -- Project and task check
2241 End loop;
2242 End if; -- X_Row_Count >0
2243
2244 If X_Diff_amount <> 0 then
2245
2249 Elsif X_Calling_Process = 'Revenue' then
2246 If X_calling_Process = 'Invoice' then
2247 X_Bill_Amount := X_Diff_amount;
2248 X_Rev_Amount := 0;
2250 X_Bill_Amount := 0;
2251 X_Rev_Amount := X_Diff_amount;
2252 End if;
2253
2254 IF L_DEBUG = 'Y' THEN
2255 gms_error_pkg.gms_debug('EVENT WRAPPER - BEFORE INSERT EVENT DIFF <> 0','C');
2256 END IF;
2257
2258 INSERT_EVENT(X_Award_Project_Id,
2259 NULL, -- event number
2260 x_plsql_installment_id,
2261 x_plsql_project_id,
2262 x_plsql_task_id,
2263 X_Burden_Cost_Code,
2264 X_Exp_Org_Id,
2265 X_Bill_Amount,
2266 X_Rev_Amount,
2267 X_Request_Id,
2268 NULL, -- Expenditure_Type
2269 X_Err_Code,
2270 X_Err_Buff,
2271 X_calling_Process);
2272
2273 If X_Err_Code <> 0 then
2274 --ROLLBACK;
2275 --RAISE FND_API.G_EXC_ERROR;
2276 Raise NO_PROCESSING_OF_AWARD ;
2277 End If;
2278
2279 IF L_DEBUG = 'Y' THEN
2280 gms_error_pkg.gms_debug('EVENT WRAPPER - AFTER INSERT EVENT DIFF <> 0','C');
2281 END IF;
2282
2283 X_Installment_Total(x_plsql_count).Rev_bill_Amount := X_Installment_Total(x_plsql_count).Rev_bill_Amount - X_Diff_Amount;
2284
2285 X_Diff_Amount := 0;
2286
2287 End If;
2288
2289 -- Step 2: Error handling
2290 IF L_DEBUG = 'Y' THEN
2291 gms_error_pkg.gms_debug('X_Diff_Amount :'||to_char(X_Diff_Amount),'C');
2292 END IF;
2293
2294 If X_Diff_Amount <> 0 then
2295 gms_error_pkg.gms_message('GMS_CALC_ERROR',
2296 X_Exec_Type => 'C',
2297 X_Err_Code => X_Err_Code,
2298 X_Err_Buff => X_Err_Buff);
2299 Raise NO_PROCESSING_OF_AWARD ;
2300
2301 Else
2302 X_Err_Code := 0;
2303 End if;
2304
2305 End EVENT_WRAPPER;
2306
2307
2308 /* This Procedure GET_FORMAT_SELECT returns: */
2309 --1) The Award_ID of the Award Project
2310 --2) The Carrying Out NOCOPY Organization Id of the Award Project
2311 --3) An Array indicating which of the columns have groupby columns for Labor Format
2312 --4) An Array indicating which of the columns have groupby columns for Non_Labor Format
2313 --5) Count of Number of Columns Selected for the Labor Inv Format
2314 --6) Count of Number of Columns Selected for the Non Labor Inv Format
2315 --7) An Array indicating whether each Labor column selected is to be right justified or not
2316 --8) An Array indicating whether each Non Labor Column selected is to be left justified or not
2317 --9) An Array indicating what the Padding Length should be for each Labor Invoice Column selected
2318 --10) An Array indicating what the Padding Length should be for each NonLabor Invoice Column selected
2319 --11) An Array containing the Free Text for each Labor Format Text Column
2320 --12) An Array containing the Free Text for each Non Labor Format Text Column
2321 --13) A concatenated select for the Labor format
2322 --14) A concatenated from for the Labor format
2323 --15) A concatenated where for the Labor Format
2324 --16) A concatenated order by for the Labor Format
2325 --17) A concatenated select for the Non Labor format
2326 --18) A concatenated from for the Non Labor format
2327 --19) A concatenated where for the Non Labor Format
2328 --20) A concatenated order by for the Non Labor Format
2329 --21) If Task is used in Labor Invoice format or not
2330 --22) If Task is used in Non Labor Invoice format or not
2331 Procedure GET_FORMAT_SELECT(X_Project_Id IN NUMBER,
2332 X_Award_Id IN OUT NOCOPY NUMBER,
2333 X_Carrying_Out_Org_Id IN OUT NOCOPY NUMBER,
2334 X_Labor_Sel_Grp_Diff_Ind OUT NOCOPY Mark_Sel_Grp_Diff_Array,
2335 X_Non_Labor_Sel_Grp_Diff_Ind OUT NOCOPY Mark_Sel_Grp_Diff_Array,
2336 X_Lbr_Cnt_Of_Columns_Selected IN OUT NOCOPY NUMBER,
2337 X_Nlbr_Cnt_Of_Columns_Selected IN OUT NOCOPY NUMBER,
2338 X_Lbr_Rt_Jstfy_Flag OUT NOCOPY Mark_Sel_Grp_Diff_Array,
2339 X_Nlbr_Rt_Jstfy_Flag OUT NOCOPY Mark_Sel_Grp_Diff_Array,
2340 X_Lbr_Padding_Length OUT NOCOPY Padding_Length_Array,
2341 X_Nlbr_Padding_Length OUT NOCOPY Padding_Length_Array,
2342 X_Lbr_Text_Array OUT NOCOPY Free_Text_Array,
2343 X_Nlbr_Text_Array OUT NOCOPY Free_Text_Array,
2344 X_LABOR_CONCAT_SELECT OUT NOCOPY VARCHAR2,
2345 X_LABOR_CONCAT_FROM OUT NOCOPY VARCHAR2,
2346 X_LABOR_CONCAT_WHERE OUT NOCOPY VARCHAR2,
2347 X_LABOR_CONCAT_ORDERBY OUT NOCOPY VARCHAR2,
2348 X_LABOR_ORDERBY_IS_NULL OUT NOCOPY VARCHAR2,
2349 X_NON_LABOR_CONCAT_SELECT OUT NOCOPY VARCHAR2,
2350 X_NON_LABOR_CONCAT_FROM OUT NOCOPY VARCHAR2,
2351 X_NON_LABOR_CONCAT_WHERE OUT NOCOPY VARCHAR2 ,
2352 X_NON_LABOR_CONCAT_ORDERBY OUT NOCOPY VARCHAR2,
2353 X_NON_LABOR_ORDERBY_IS_NULL OUT NOCOPY VARCHAR2,
2354 X_LABOR_tsk_lvl_fmt OUT NOCOPY VARCHAR2, /* added for bug 3523930 */
2358 X_LABOR_SELECT VARCHAR2(2000) := NULL;
2355 X_NON_LABOR_tsk_lvl_fmt OUT NOCOPY VARCHAR2, /* added for bug 3523930 */
2356 X_Err_Num OUT NOCOPY NUMBER,
2357 X_Err_Stage OUT NOCOPY VARCHAR2) IS
2359 X_LABOR_FROM VARCHAR2(2000) := NULL;
2360 X_LABOR_WHERE VARCHAR2(2000) := NULL;
2361 X_LABOR_ORDERBY VARCHAR2(2000) := NULL;
2362 X_NON_LABOR_SELECT VARCHAR2(2000) := NULL;
2363 X_NON_LABOR_FROM VARCHAR2(2000) := NULL;
2364 X_NON_LABOR_WHERE VARCHAR2(2000) := NULL;
2365 X_NON_LABOR_ORDERBY VARCHAR2(2000) := NULL;
2366 /* Cursor to get Labor_Invoice_Format_Id and Non_Labor_Invoice_Format_Id */
2367 CURSOR GET_INVOICE_FORMAT(X_Project_Id NUMBER) IS
2368 select
2369 a.labor_invoice_format_id,
2370 a.non_labor_invoice_format_id,
2371 b.award_id, /*Award_Id*/
2372 a.carrying_out_organization_id
2373 from
2374 PA_PROJECTS_ALL a,
2375 GMS_AWARDS b
2376 where
2377 a.project_id = X_Project_Id and
2378 b.award_project_id = a.project_id ;
2379
2380 X_Labor_Invoice_Format_Id NUMBER(15);
2381 X_Non_Labor_Invoice_Format_Id NUMBER(15);
2382 X_Col_Code VARCHAR2(30);
2383 /* CURSORS FOR Creating Selects , From and Where for Labor and Non Labor Invoice Formats */
2384 /* Cursor to get the COLUMNS associated with the Invoice Format Details */
2385 CURSOR Column_Cursor(X_INV_FORMAT_ID NUMBER) IS
2386 select
2387 b.start_position START_POSITION,
2388 b.end_position END_POSITION,
2389 b.right_justify_flag RT_FLAG,
2390 b.text TEXT,
2391 a.column_code COL_CODE,
2392 a.select_text SELECT_TEXT,
2393 a.group_by_text GROUP_TEXT
2394 from
2395 pa_invoice_group_columns a,
2396 pa_invoice_format_details b
2397 where
2398 a.invoice_group_column_id = b.invoice_group_column_id and
2399 b.invoice_format_id = X_INV_FORMAT_ID
2400 order by b.start_position;
2401 /* Cursor to get the TABLES for the Group Column associated with the Invoice Format Details */
2402 CURSOR Table_Cursor(X_INV_FORMAT_ID NUMBER ) IS
2403 select /*+INDEX(a PA_INVOICE_GROUP_TABLES_N1)*/
2404 distinct a.text TABLE_TEXT
2405 from
2406 pa_invoice_group_tables a,
2407 pa_invoice_group_columns b,
2408 pa_invoice_format_details c
2409 where
2410 b.invoice_group_column_id = c.invoice_group_column_id and
2411 a.invoice_group_column_id = c.invoice_group_column_id and
2412 c.invoice_format_id = X_INV_FORMAT_ID;
2413 /* Cursor to get the WHERE for the Group Column associated with the Invoice Format Details */
2414 CURSOR Where_Cursor(X_INV_FORMAT_ID NUMBER) IS
2415 select /*+INDEX(b PA_INV_GRP_WHR_CLAUSES_U1)*/
2416 distinct b.text WHERE_TEXT
2417 from
2418 pa_inv_grp_col_whr_clauses a,
2419 pa_inv_grp_whr_clauses b,
2420 pa_invoice_group_columns c,
2421 pa_invoice_format_details d
2422 where
2423 b.invoice_group_where_clause_id = a.invoice_group_where_clause_id and
2424 a.invoice_group_column_id = c.invoice_group_column_id and
2425 c.invoice_group_column_id = d.invoice_group_column_id and
2426 d.invoice_format_id = X_INV_FORMAT_ID;
2427 /* Getting the Award Id, Labor Invoice Format Id and Non Labor Invoice Format Id for the Award Project */
2428 Begin
2429 X_LABOR_SELECT := NULL;
2430 X_LABOR_FROM := NULL;
2431 X_LABOR_WHERE := NULL;
2432 X_NON_LABOR_SELECT := NULL;
2433 X_NON_LABOR_FROM := NULL;
2434 X_NON_LABOR_WHERE := NULL;
2435 /* Two lines below are added for bug 3523930 */
2436 X_LABOR_tsk_lvl_fmt := 'N';
2437 X_NON_LABOR_tsk_lvl_fmt := 'N';
2438 OPEN GET_INVOICE_FORMAT(X_Project_Id);
2439 FETCH GET_INVOICE_FORMAT INTO
2440 X_Labor_Invoice_Format_Id ,
2441 X_Non_Labor_Invoice_Format_Id,
2442 X_Award_Id,
2443 X_Carrying_Out_Org_Id;
2444 CLOSE GET_INVOICE_FORMAT;
2445 X_Lbr_Cnt_Of_Columns_Selected := 0;
2446 X_Nlbr_Cnt_Of_Columns_Selected:= 0;
2447 Begin
2448 /*==========================================================*/
2449 /* Fetching for Labor Invoice Format SELECT, FROM, WHERE */
2450 /*==========================================================*/
2451 FOR Column_Record IN Column_Cursor(X_Labor_Invoice_Format_Id) LOOP
2452 If (Column_Record.SELECT_TEXT is NOT NULL) then
2453 X_LABOR_SELECT := X_LABOR_SELECT||Column_Record.SELECT_TEXT||',';
2454 X_Lbr_Cnt_Of_Columns_Selected := X_Lbr_Cnt_Of_Columns_Selected + 1;
2455 X_Lbr_Rt_Jstfy_Flag(X_Lbr_Cnt_Of_Columns_Selected) := Column_Record.RT_FLAG;
2456 X_Lbr_Padding_Length(X_Lbr_Cnt_Of_Columns_Selected) := (Column_Record.END_POSITION -
2457 Column_Record.START_POSITION);
2458 /* If added for bug 3523930 */
2459 IF(Column_Record.COL_CODE like '%TASK%') THEN
2460 X_LABOR_tsk_lvl_fmt :='Y';
2461 END IF;
2462 End If;
2463 If (Column_Record.GROUP_TEXT is NOT NULL) then
2464 X_LABOR_ORDERBY := X_LABOR_ORDERBY||Column_Record.GROUP_TEXT||',';
2465 X_Labor_Sel_Grp_Diff_Ind(X_Lbr_Cnt_Of_Columns_Selected) := 'Y';
2466 Else
2467 If Column_Record.COL_CODE = 'TEXT' then
2468 X_Labor_Sel_Grp_Diff_Ind(X_Lbr_Cnt_Of_Columns_Selected) := 'T';
2469 X_Lbr_Text_Array(X_Lbr_Cnt_Of_Columns_Selected) := Column_Record.TEXT;
2470 X_Lbr_Rt_Jstfy_Flag(X_Lbr_Cnt_Of_Columns_Selected) := Column_Record.RT_FLAG;
2471 X_Lbr_Padding_Length(X_Lbr_Cnt_Of_Columns_Selected) := (Column_Record.END_POSITION -
2472 Column_Record.START_POSITION) + 1;
2473 Else
2477 END LOOP;
2474 X_Labor_Sel_Grp_Diff_Ind(X_Lbr_Cnt_Of_Columns_Selected) := 'N';
2475 End If;
2476 End If;
2478 X_LABOR_CONCAT_SELECT := X_LABOR_SELECT;
2479 If X_LABOR_ORDERBY IS NOT NULL THEN
2480 X_LABOR_CONCAT_ORDERBY := (substr(X_LABOR_ORDERBY,1,length(X_LABOR_ORDERBY)-1))||' , ';
2481 X_LABOR_ORDERBY_IS_NULL := 'N';
2482 ELSE
2483 X_LABOR_ORDERBY_IS_NULL := 'Y';
2484 --X_LABOR_CONCAT_ORDERBY := ' , ';
2485 END IF;
2486 FOR Table_Record IN Table_Cursor(X_Labor_Invoice_Format_Id) LOOP
2487 X_LABOR_FROM := X_LABOR_FROM||Table_Record.TABLE_TEXT||',';
2488 END LOOP;
2489 X_LABOR_CONCAT_FROM := X_LABOR_FROM;
2490 FOR Where_Record IN Where_Cursor(X_Labor_Invoice_Format_Id) LOOP
2491 X_LABOR_WHERE := X_LABOR_WHERE||Where_Record.WHERE_TEXT||' and ';
2492 END LOOP;
2493 X_LABOR_CONCAT_WHERE := X_LABOR_WHERE;
2494 /*=======================================================*/
2495 /*==============================================================*/
2496 /* Fetching Non Labor Invoice Format Select, From, Where */
2497 /*=============================================================*/
2498 FOR Column_Record IN Column_Cursor(X_Non_Labor_Invoice_Format_Id) LOOP
2499 If (Column_Record.SELECT_TEXT is NOT NULL) then
2500 X_NON_LABOR_SELECT := X_NON_LABOR_SELECT||Column_Record.SELECT_TEXT||',';
2501 X_Nlbr_Cnt_Of_Columns_Selected := X_Nlbr_Cnt_Of_Columns_Selected + 1;
2502 X_Nlbr_Rt_Jstfy_Flag(X_Nlbr_Cnt_Of_Columns_Selected) := Column_Record.RT_FLAG;
2503 X_Nlbr_Padding_Length(X_Nlbr_Cnt_Of_Columns_Selected) := (Column_Record.END_POSITION -
2504 Column_Record.START_POSITION);
2505 /* If added for bug 3523930 */
2506 IF(Column_Record.COL_CODE like '%TASK%') THEN
2507 X_NON_LABOR_tsk_lvl_fmt :='Y';
2508 END IF;
2509 End If;
2510 If (Column_Record.GROUP_TEXT is NOT NULL) then
2511 X_NON_LABOR_ORDERBY := X_NON_LABOR_ORDERBY||Column_Record.GROUP_TEXT||',';
2512 X_Non_Labor_Sel_Grp_Diff_Ind(X_Nlbr_Cnt_Of_Columns_Selected) := 'Y';
2513 Else
2514 If Column_Record.COL_CODE = 'TEXT' then
2515 X_Non_Labor_Sel_Grp_Diff_Ind(X_Nlbr_Cnt_Of_Columns_Selected) := 'T';
2516 X_Nlbr_Text_Array(X_Nlbr_Cnt_Of_Columns_Selected) := Column_Record.TEXT;
2517 X_Nlbr_Rt_Jstfy_Flag(X_Nlbr_Cnt_Of_Columns_Selected) := Column_Record.RT_FLAG;
2518 X_Nlbr_Padding_Length(X_Nlbr_Cnt_Of_Columns_Selected) := (Column_Record.END_POSITION -
2519 Column_Record.START_POSITION) + 1;
2520 Else
2521 X_Non_Labor_Sel_Grp_Diff_Ind(X_Nlbr_Cnt_Of_Columns_Selected) := 'N';
2522 End If;
2523 End If;
2524 END LOOP;
2525 X_NON_LABOR_CONCAT_SELECT := X_NON_LABOR_SELECT;
2526 If X_NON_LABOR_ORDERBY IS NOT NULL THEN
2527 X_NON_LABOR_CONCAT_ORDERBY := (substr(X_NON_LABOR_ORDERBY,1,length(X_NON_LABOR_ORDERBY)-1))||' , ';
2528 X_NON_LABOR_ORDERBY_IS_NULL := 'N';
2529 ElSE
2530 X_NON_LABOR_ORDERBY_IS_NULL := 'Y';
2531 --X_NON_LABOR_CONCAT_ORDERBY := ' , ';
2532 END IF;
2533 FOR Table_Record IN Table_Cursor(X_Non_Labor_Invoice_Format_Id) LOOP
2534 X_NON_LABOR_FROM := X_NON_LABOR_FROM||Table_Record.TABLE_TEXT||',';
2535 END LOOP;
2536 X_NON_LABOR_CONCAT_FROM := X_NON_LABOR_FROM;
2537 FOR Where_Record IN Where_Cursor(X_Non_Labor_Invoice_Format_Id) LOOP
2538 X_NON_LABOR_WHERE := X_NON_LABOR_WHERE||Where_Record.WHERE_TEXT||' and ';
2539 END LOOP;
2540 X_NON_LABOR_CONCAT_WHERE := X_NON_LABOR_WHERE;
2541 /*=======================================================*/
2542 End;
2543 EXCEPTION
2544 WHEN OTHERS THEN
2545 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
2546 'SQLCODE',
2547 SQLCODE,
2548 'SQLERRM',
2549 SQLERRM,
2550 X_Exec_Type => 'C',
2551 X_Err_Code => X_Err_Num,
2552 X_Err_Buff => X_Err_Stage);
2553 --ROLLBACK;
2554 --RAISE_APPLICATION_ERROR(-20514,X_Err_Stage);
2555 --RETURN;
2556 Raise NO_PROCESSING_OF_AWARD ;
2557
2558 END GET_FORMAT_SELECT;
2559
2560 ---------------------------------------------------------------------------------------
2561 -- Procedure GET_AMOUNT_IN_INTERSECT: Given the Expenditure Item Id returns the cumulative
2562 -- Amount in the GMS_EVENT_INTERSECT table for all the number of times this
2563 -- expenditure item has been picked up before for billing
2564 --------------------------------------------------------------------------------------
2565 PROCEDURE GET_AMOUNT_IN_INTERSECT(X_Expenditure_Item_Id IN NUMBER,
2566 X_Adl_Line_Num IN NUMBER,
2567 X_Calling_Process IN VARCHAR2,
2568 X_Amount_In_Intersect OUT NOCOPY NUMBER) IS
2569 X_Err_Code Varchar2(1);
2570 X_Err_Buff Varchar2(2000);
2571
2572 X_Current_Amount NUMBER(22,5) := 0;
2573 Begin
2574 Begin
2575 select
2576 nvl(sum(nvl(amount,0)),0)
2577 into
2578 X_Current_Amount
2579 from
2580 GMS_EVENT_INTERSECT
2581 where
2582 expenditure_item_id = X_Expenditure_Item_Id and
2583 adl_line_num = X_Adl_Line_Num and
2584 event_type = decode(X_Calling_Process,'Invoice','INVOICE','Revenue','REVENUE');
2585 Exception
2586 When others then
2587 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
2588 'SQLCODE',
2589 SQLCODE,
2590 'SQLERRM',
2591 SQLERRM,
2592 X_Exec_Type => 'C',
2596 --RAISE_APPLICATION_ERROR(-20515,X_Err_Buff);
2593 X_Err_Code => X_Err_Code,
2594 X_Err_Buff => X_Err_Buff);
2595 --ROLLBACK;
2597 --RETURN;
2598 Raise NO_PROCESSING_OF_AWARD ;
2599
2600 End;
2601
2602 X_Amount_In_Intersect := X_Current_Amount;
2603
2604 END GET_AMOUNT_IN_INTERSECT;
2605
2606 ---------------------------------------------------------------------------------
2607 --------------------------------------------------------------------------------
2608 --Procedure GET_BURD_AMT_IN_INTERSECT: For a given expenditure item and for a given burden
2609 --cost component used to burden this expenditure item this procedure will return the burden
2610 --amount that has been billed or accrued to_date from the GMS_BURDEN_COMPONENTS table
2611 --------------------------------------------------------------------------------
2612 PROCEDURE GET_BURD_AMT_IN_INTERSECT(X_Expenditure_Item_Id IN NUMBER,
2613 X_Adl_Line_Num IN NUMBER,
2614 X_Calling_Process IN VARCHAR2,
2615 X_Burden_Cost_Code IN VARCHAR2,
2616 X_Burden_Amt_In_Table OUT NOCOPY NUMBER) IS
2617
2618 X_Err_Code Varchar2(1);
2619 X_Err_Buff Varchar2(2000);
2620 Begin
2621 Select
2622 nvl(sum(nvl(amount,0)),0)
2623 into X_Burden_Amt_In_Table
2624 from
2625 GMS_BURDEN_COMPONENTS
2626 where
2627 expenditure_item_id = X_Expenditure_Item_Id
2628 and adl_line_num = X_Adl_Line_Num
2629 and burden_cost_code = X_Burden_Cost_Code
2630 and event_type = decode(X_Calling_Process,'Invoice','INVOICE','Revenue','REVENUE');
2631 Exception
2632 When others then
2633 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
2634 'SQLCODE',
2635 SQLCODE,
2636 'SQLERRM',
2637 SQLERRM,
2638 X_Exec_Type => 'C',
2639 X_Err_Code => X_Err_Code,
2640 X_Err_Buff => X_Err_Buff);
2641 --ROLLBACK;
2642 --RAISE_APPLICATION_ERROR(-20517,X_Err_Buff);
2643 --RETURN;
2644 Raise NO_PROCESSING_OF_AWARD ;
2645
2646 End GET_BURD_AMT_IN_INTERSECT;
2647
2648 --------------------------------------------------------------------------------
2649 --------------------------------------------------------------------------------
2650 Function CHECK_FOR_NO_FUNDINGS_ROW(C_Installment_Id IN NUMBER,
2651 X_Task_Id IN NUMBER) RETURN BOOLEAN IS
2652 X_Check_Row_Exists NUMBER;
2653 Begin
2654 select
2655 1
2656 into
2657 X_Check_Row_Exists
2658 from
2659 gms_summary_project_fundings gmf
2660 where
2661 gmf.installment_id = C_Installment_Id
2662 and (
2663 (gmf.task_id = X_Task_Id)
2664 OR (gmf.task_id is NULL)
2665 OR (gmf.task_id = (select t.top_task_id from PA_TASKS t where t.task_id = X_Task_Id))
2666 )
2667 and gmf.project_id = (select project_id from PA_TASKS where task_id = X_Task_Id);
2668 RETURN FALSE;
2669 EXCEPTION
2670 WHEN NO_DATA_FOUND THEN
2671 RETURN TRUE;
2672 WHEN OTHERS THEN
2673 RETURN TRUE;
2674
2675 End CHECK_FOR_NO_FUNDINGS_ROW;
2676 -------------------------------------------------------------------------------
2677
2678 -------------------------------------------------------------------------------
2679 --Procedure GET_ACCRUE_BILL_OR_INSERT_AMT: Gets the resultant amount that needs to be accrued or
2680 --Billed for a particular Expenditure Item after taking into account the amount already existing in the
2681 --GMS_EVENT_INTERSECT table for that Expenditure Item . If the calling Process is
2682 --'Invoice' the process will look at the Billable Flag and Bill_Hold_Flag to decide how much amount
2683 --needs to be reduced from the Total Billed Amount. These two flags are not looked at for the
2684 --'Revenue' process.
2685
2686 PROCEDURE GET_ACCRUE_BILL_OR_INSERT_AMT(X_Expenditure_Item_Id IN NUMBER,
2687 X_Adl_Line_Num IN NUMBER,
2688 X_Calling_Process IN VARCHAR2,
2689 X_Raw_Cost IN NUMBER,
2690 X_Billable_Flag IN VARCHAR2,
2691 X_Bill_Hold_Flag IN VARCHAR2,
2692 X_Amount_To_Accrue_Bill_Insert OUT NOCOPY NUMBER,
2693 X_Err_Num OUT NOCOPY NUMBER,
2694 X_Err_Stage OUT NOCOPY VARCHAR2) IS
2695
2696 X_Current_Amount_In_Intersect NUMBER; -- Current Amount in Intersect table for that Exp Item
2697 Begin
2698
2699 GET_AMOUNT_IN_INTERSECT(X_Expenditure_Item_Id ,
2700 X_Adl_Line_Num,
2701 X_Calling_Process,
2702 X_Current_Amount_In_Intersect);
2703
2704 If X_Calling_Process = 'Invoice' then
2705
2706 If (X_Billable_Flag = 'N' OR nvl(X_Bill_Hold_Flag,'N') = 'Y') then
2707
2708 If X_Current_Amount_In_Intersect <> 0 then
2709 --dbms_output.put_line('In IF for BILL HOLD FLAG = Y');
2710 X_Amount_To_Accrue_Bill_Insert := (-1 * X_Current_Amount_In_Intersect);
2711 Else
2712 X_Amount_To_Accrue_Bill_Insert := 0;
2713 End If;
2714
2715 Else
2716 X_Amount_To_Accrue_Bill_Insert := (X_Raw_Cost - X_Current_Amount_In_Intersect);
2717 End If;
2718
2719 Elsif X_Calling_Process = 'Revenue' then
2720
2721 If (X_Billable_Flag = 'N' ) then
2725 Else
2722
2723 If X_Current_Amount_In_Intersect <> 0 then
2724 X_Amount_To_Accrue_Bill_Insert := (-1 * X_Current_Amount_In_Intersect);
2726 X_Amount_To_Accrue_Bill_Insert := 0;
2727 End If;
2728
2729 Else
2730 X_Amount_To_Accrue_Bill_Insert := (X_Raw_Cost - X_Current_Amount_In_Intersect);
2731 End If;
2732
2733 End If;
2734
2735 End GET_ACCRUE_BILL_OR_INSERT_AMT;
2736
2737 -----------------------------------------------------------------------------------
2738
2739 ----------------------------------------------------------------------------------
2740 --Procedure GET_BURDEN_AMT_TO_INSERT returns the burden amount to be inserted into
2741 --GMS_BURDEN_COMPONENTS table for a given expenditure item id and for a given burden
2742 --cost component
2743 ----------------------------------------------------------------------------------
2744 PROCEDURE GET_BURDEN_AMT_TO_INSERT(X_Expenditure_Item_Id IN NUMBER,
2745 X_Adl_Line_Num IN NUMBER,
2746 X_Calling_Process IN VARCHAR2,
2747 X_Burden_Cost_Code IN VARCHAR2,
2748 X_Billable_Flag IN VARCHAR2,
2749 X_Bill_Hold_Flag IN VARCHAR2,
2750 X_Burden_Amt_From_Vw IN NUMBER,
2751 X_Burden_Amt_To_Insert OUT NOCOPY NUMBER) IS
2752
2753 X_Curr_Burden_Amt_In_Table NUMBER;
2754
2755 Begin
2756
2757 GET_BURD_AMT_IN_INTERSECT(X_Expenditure_Item_Id
2758 ,X_Adl_Line_Num
2759 ,X_Calling_Process
2760 ,X_Burden_Cost_Code
2761 ,X_Curr_Burden_Amt_In_Table);
2762
2763 If X_Calling_Process = 'Invoice' then
2764 If (X_Billable_Flag = 'N' OR nvl(X_Bill_Hold_Flag,'N') = 'Y') then
2765 If X_Curr_Burden_Amt_In_Table <> 0 then
2766 X_Burden_Amt_To_Insert := (-1 * X_Curr_Burden_Amt_In_Table);
2767 Else
2768 X_Burden_Amt_To_Insert := 0;
2769 End If;
2770 Else
2771 X_Burden_Amt_To_Insert := (X_Burden_Amt_From_Vw - X_Curr_Burden_Amt_In_Table);
2772 End If;
2773 Elsif X_Calling_Process = 'Revenue' then
2774 If (X_Billable_Flag = 'N' ) then
2775 If X_Curr_Burden_Amt_In_Table <> 0 then
2776 X_Burden_Amt_To_Insert := (-1 * X_Curr_Burden_Amt_In_Table);
2777 Else
2778 X_Burden_Amt_To_Insert := 0;
2779 End If;
2780 Else
2781 X_Burden_Amt_To_Insert := (X_Burden_Amt_From_Vw - X_Curr_Burden_Amt_In_Table);
2782 End If;
2783 End If;
2784
2785 End GET_BURDEN_AMT_TO_INSERT;
2786 ------------------------------------------------------------------------------------
2787
2788 -----------------------------------------------------------------------------------
2789 --Procedure INSERT_GMS_BURDEN_COMPONENTS: Inserts rows into GMS_BURDEN_COMPONENTS table for
2790 --each component that a raw cost transaction is burdened by for an amount equal to the difference
2791 --between the current Burden Amt from the View for that Component and that expenditure item id and
2792 --the cumulative amount in GMS_BURDEN_COMPONENTS table for that component and that exp item.
2793 -----------------------------------------------------------------------------------
2794 PROCEDURE INSERT_GMS_BURDEN_COMPONENTS(X_Award_Project_Id IN NUMBER,
2795 X_Expenditure_Item_Id IN NUMBER,
2796 X_Adl_Line_Num IN NUMBER,
2797 X_Request_Id IN NUMBER,
2798 X_Calling_Process IN VARCHAR2,
2799 X_Actual_Project_Id IN NUMBER,
2800 X_Actual_Task_Id IN NUMBER,
2801 X_Burden_Expenditure_Type IN VARCHAR2,
2802 X_Burden_Cost_Code IN VARCHAR2,
2803 X_Expenditure_Org_Id IN NUMBER,
2804 X_Burd_Amt_To_Insert IN NUMBER,
2805 X_Err_Num OUT NOCOPY NUMBER,
2806 X_Err_Stage OUT NOCOPY VARCHAR2) IS
2807
2808 X_Err_Code Varchar2(1);
2809 X_Err_Buff Varchar2(2000);
2810 Begin
2811
2812 If X_Burd_Amt_To_Insert <> 0 then
2813 Begin
2814
2815 INSERT INTO GMS_BURDEN_COMPONENTS(AWARD_PROJECT_ID,
2816 EXPENDITURE_ITEM_ID,
2817 ADL_LINE_NUM,
2818 AMOUNT,
2819 REQUEST_ID,
2820 EVENT_TYPE,
2821 ACTUAL_PROJECT_ID,
2822 ACTUAL_TASK_ID,
2823 BURDEN_EXP_TYPE,
2824 EXPENDITURE_ORG_ID,
2825 BURDEN_COST_CODE,
2826 LAST_UPDATE_DATE,
2827 LAST_UPDATED_BY,
2828 CREATION_DATE,
2829 CREATED_BY,
2830 LAST_UPDATE_LOGIN,
2831 REVENUE_ACCUMULATED,
2832 RESOURCE_LIST_MEMBER_ID)
2833 VALUES(X_Award_Project_Id,
2834 X_Expenditure_Item_Id,
2835 X_Adl_Line_Num,
2836 X_Burd_Amt_To_Insert,
2837 X_request_id,
2838 decode(X_Calling_Process,'Invoice','INVOICE','Revenue','REVENUE'),
2839 X_Actual_Project_Id,
2840 X_Actual_Task_Id,
2841 X_Burden_Expenditure_Type,
2842 X_Expenditure_Org_Id,
2846 SYSDATE,
2843 X_Burden_Cost_Code,
2844 SYSDATE,
2845 fnd_global.user_id,
2847 fnd_global.user_id,
2848 fnd_global.login_id,
2849 decode(X_Calling_Process,'Invoice','X','Revenue','N'), -- Added decode for bug 5472366
2850 null);
2851
2852 X_Err_Num := 0;
2853 X_UPD_BILLING_FLAG := TRUE; -- Bug 3254097
2854
2855 IF L_DEBUG = 'Y' THEN
2856 gms_error_pkg.gms_debug('Inserted into GBC, EXP/ADL:'||X_Expenditure_Item_Id||':'||X_Adl_Line_Num,'C');
2857 END IF;
2858
2859 EXCEPTION
2860 WHEN DUP_VAL_ON_INDEX THEN
2861 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
2862 'SQLCODE',
2863 SQLCODE,
2864 'SQLERRM',
2865 SQLERRM,
2866 X_Exec_Type => 'C',
2867 X_Err_Code => X_Err_Code,
2868 X_Err_Buff => X_Err_Buff);
2869 Raise NO_PROCESSING_OF_AWARD ;
2870
2871 WHEN OTHERS THEN
2872 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
2873 'SQLCODE',
2874 SQLCODE,
2875 'SQLERRM',
2876 SQLERRM,
2877 X_Exec_Type => 'C',
2878 X_Err_Code => X_Err_Code,
2879 X_Err_Buff => X_Err_Buff);
2880 Raise NO_PROCESSING_OF_AWARD ;
2881
2882 End;
2883 End If;
2884
2885 End INSERT_GMS_BURDEN_COMPONENTS;
2886 ------------------------------------------------------------------------------------
2887 -----------------------------------------------------------------------------------------
2888 -- Procedure INSERT_GMS_EVENT_INTERSECT: Inserts a row into GMS_EVENT_INTERSECT table for an
2889 -- amount equal to the difference between the current Raw Cost on the Expenditure Item and
2890 -- the cumulative amount for the expenditure item in the table
2891 -----------------------------------------------------------------------------------------
2892 PROCEDURE INSERT_GMS_EVENT_INTERSECT(X_Award_Project_Id IN NUMBER,
2893 X_Raw_Cost IN NUMBER,
2894 X_Expenditure_Item_Id IN NUMBER,
2895 X_Adl_Line_Num IN NUMBER,
2896 X_request_id IN NUMBER,
2897 X_Amount_To_Insert IN OUT NOCOPY NUMBER,
2898 X_Calling_Process IN VARCHAR2,
2899 X_Billable_Flag IN VARCHAR2,
2900 X_Bill_Hold_Flag IN VARCHAR2,
2901 X_Err_Num OUT NOCOPY NUMBER,
2902 X_Err_Stage OUT NOCOPY VARCHAR2) IS
2903
2904 X_Err_Code Varchar2(1);
2905 X_Err_Buff Varchar2(2000);
2906 X_Current_Amount NUMBER(22,5);
2907 Begin
2908
2909 GET_ACCRUE_BILL_OR_INSERT_AMT(X_Expenditure_Item_Id,
2910 X_Adl_Line_Num,
2911 X_Calling_Process,
2912 X_Raw_Cost,
2913 X_Billable_Flag,
2914 X_Bill_Hold_Flag,
2915 X_Amount_To_Insert,
2916 X_Err_Num,
2917 X_Err_Stage);
2918
2919 X_Amount_To_Insert := pa_currency.round_currency_amt(nvl(X_Amount_To_Insert,0)); -- added for bug 5182669
2920 If X_Amount_To_Insert <> 0 then
2921 Begin
2922 INSERT INTO GMS_EVENT_INTERSECT(AWARD_PROJECT_ID,
2923 EXPENDITURE_ITEM_ID,
2924 ADL_LINE_NUM,
2925 AMOUNT,
2926 REQUEST_ID,
2927 EVENT_TYPE,
2928 LAST_UPDATE_DATE,
2929 LAST_UPDATED_BY,
2930 CREATION_DATE,
2931 CREATED_BY,
2932 LAST_UPDATE_LOGIN,
2933 REVENUE_ACCUMULATED)
2934 VALUES(X_Award_Project_Id,
2935 X_Expenditure_Item_Id,
2936 X_Adl_Line_Num,
2937 X_Amount_To_Insert,
2938 X_request_id,
2939 decode(X_Calling_Process,'Invoice','INVOICE','Revenue','REVENUE'),
2940 SYSDATE,
2941 fnd_global.user_id,
2942 SYSDATE,
2943 fnd_global.user_id,
2944 fnd_global.login_id,
2945 decode(X_Calling_Process,'Invoice','X','Revenue','N')); -- Added decode for bug 5472366
2946 X_Err_Num := 0;
2947 X_UPD_BILLING_FLAG := TRUE; -- Bug 3254097
2948
2949 IF L_DEBUG = 'Y' THEN
2950 gms_error_pkg.gms_debug('Inserted into GEI, EXP/ADL:'||X_Expenditure_Item_Id||':'||X_Adl_Line_Num,'C');
2951 END IF;
2952
2953 EXCEPTION
2954 WHEN DUP_VAL_ON_INDEX THEN
2955 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
2956 'SQLCODE',
2957 SQLCODE,
2958 'SQLERRM',
2959 SQLERRM,
2960 X_Exec_Type => 'C',
2961 X_Err_Code => X_Err_Code,
2962 X_Err_Buff => X_Err_Buff);
2963 Raise NO_PROCESSING_OF_AWARD ;
2964
2965 WHEN OTHERS THEN
2966 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
2967 'SQLCODE',
2968 SQLCODE,
2969 'SQLERRM',
2970 SQLERRM,
2971 X_Exec_Type => 'C',
2975 --RAISE_APPLICATION_ERROR(-20521,X_Err_Buff);
2972 X_Err_Code => X_Err_Code,
2973 X_Err_Buff => X_Err_Buff);
2974 --ROLLBACK;
2976 --RETURN;
2977 Raise NO_PROCESSING_OF_AWARD ;
2978
2979 End;
2980 End If;
2981
2982 End INSERT_GMS_EVENT_INTERSECT;
2983
2984 -----------------------------------------------------------------------------------------
2985 -- Procedure UPDATE_GMS_EVENT_INTERSECT: Updates GMS_EVENT_INTERSECT table with the Event Num
2986 -- of the Event created.
2987 -- Bug 3235390 : Modified the below procedure to update records based on project and task_id.
2988 -----------------------------------------------------------------------------------------
2989 PROCEDURE UPDATE_GMS_EVENT_INTERSECT(X_Event_Num IN NUMBER,
2990 X_Award_Project_Id IN NUMBER,
2991 X_request_id IN NUMBER,
2992 X_ACT_PROJECT_ID IN NUMBER,
2993 X_TASK_ID IN NUMBER) IS
2994
2995 X_Err_Code Varchar2(1);
2996 X_Err_Buff Varchar2(2000);
2997 Begin
2998 IF L_DEBUG = 'Y' THEN
2999 gms_error_pkg.gms_debug('IN EVENT INTERSECT Updation - START','C');
3000 END IF;
3001
3002 update GMS_EVENT_INTERSECT gei
3003 set
3004 gei.EVENT_NUM = X_Event_Num
3005 ,gei.last_update_date = sysdate
3006 ,gei.last_updated_by = fnd_global.user_id
3007 ,gei.last_update_login = fnd_global.login_id
3008 where gei.REQUEST_ID = X_Request_id and
3009 gei.award_project_id = X_Award_Project_Id and
3010 gei.EVENT_NUM IS NULL
3011 AND EXISTS ( -- Bug 3235390 : Added below conditions to check for project and task.
3012 SELECT gei2.expenditure_item_id
3013 FROM gms_award_distributions adl,
3014 gms_event_intersect gei2
3015 WHERE gei2.expenditure_item_id = gei.expenditure_item_id
3016 AND adl.expenditure_item_id = gei2.expenditure_item_id
3017 AND adl.adl_status = 'A'
3018 AND adl.document_type ='EXP'
3019 AND adl.project_id = x_act_project_id
3020 AND adl.task_id = x_task_id);
3021
3022
3023 If SQL%NOTFOUND THEN
3024 IF L_DEBUG = 'Y' THEN
3025 gms_error_pkg.gms_debug('IN EVENT INTERSECT Updation - ERROR','C');
3026 END IF;
3027 gms_error_pkg.gms_message('GMS_NO_UPD_PRJ_REQ',
3028 'PRJ',
3029 X_Award_Project_Id,
3030 'REQ',
3031 X_Request_id,
3032 X_Exec_Type => 'C',
3033 X_Err_Code => X_Err_Code,
3034 X_Err_Buff => X_Err_Buff);
3035 Raise NO_PROCESSING_OF_AWARD ;
3036
3037 End If;
3038 IF L_DEBUG = 'Y' THEN
3039 gms_error_pkg.gms_debug('IN EVENT INTERSECT Updation - END','C');
3040 END IF;
3041
3042 End UPDATE_GMS_EVENT_INTERSECT;
3043
3044 --------------------------------------------------------------------------------------------
3045
3046 --------------------------------------------------------------------------------------------
3047 --Procedure UPDATE_GMS_BURDEN_COMPONENTS: Updates GMS_BURDEN_COMPONENTS table with the Event Num of
3048 --the event created.
3049 --------------------------------------------------------------------------------------------
3050 PROCEDURE UPDATE_GMS_BURDEN_COMPONENTS(X_Event_Num IN NUMBER,
3051 X_Award_Project_Id IN NUMBER,
3052 X_Request_Id IN NUMBER,
3053 X_Actual_Project_Id IN NUMBER,
3054 X_Actual_Task_Id IN NUMBER,
3055 X_Burden_Cost_Code IN VARCHAR2,
3056 X_Expenditure_Org_Id IN NUMBER) IS
3057
3058 X_Err_Code Varchar2(1);
3059 X_Err_Buff Varchar2(2000);
3060 Begin
3061 IF L_DEBUG = 'Y' THEN
3062 gms_error_pkg.gms_debug('IN BURDEN COMPONENTS Updation - START','C');
3063 END IF;
3064 update /*+INDEX(GMS_BURDEN_COMPONENTS GMS_BURDEN_COMPONENTS_N3)*/ GMS_BURDEN_COMPONENTS
3065 set
3066 EVENT_NUM = X_Event_Num
3067 ,last_update_date = sysdate
3068 ,last_updated_by = fnd_global.user_id
3069 ,last_update_login = fnd_global.login_id
3070 where
3071 request_id = X_request_id and
3072 award_project_id = X_Award_Project_Id and
3073 EVENT_NUM IS NULL and
3074 actual_project_id = X_Actual_Project_Id and
3075 actual_task_id = X_Actual_Task_Id and
3076 burden_cost_code = X_Burden_Cost_Code and
3077 expenditure_org_id = X_Expenditure_Org_Id;
3078
3079 If SQL%NOTFOUND THEN
3080 IF L_DEBUG = 'Y' THEN
3081 gms_error_pkg.gms_debug('IN BURDEN COMPONENTS Updation - ERROR','C');
3082 END IF;
3083 gms_error_pkg.gms_message('GMS_NO_UPD_PRJ_REQ',
3084 'PRJ',
3085 X_Award_Project_Id,
3086 'REQ',
3087 X_Request_id,
3088 X_Exec_Type => 'C',
3089 X_Err_Code => X_Err_Code,
3090 X_Err_Buff => X_Err_Buff);
3091 Raise NO_PROCESSING_OF_AWARD ;
3092
3093 End If;
3094
3095 IF L_DEBUG = 'Y' THEN
3096 gms_error_pkg.gms_debug('IN BURDEN COMPONENTS Updation - END','C');
3097 END IF;
3098
3099 End UPDATE_GMS_BURDEN_COMPONENTS;
3100 ---------------------------------------------------------------------------------------------
3101 --PROCEDURE: EVENT_ATTRIBUTE_UPDATION, new procedure to update event number on Event_Attribute
3102
3103 PROCEDURE EVENT_ATTRIBUTE_UPDATION(X_Event_Num IN NUMBER,
3104 X_Award_Project_Id IN NUMBER,
3105 X_request_id IN NUMBER,
3106 X_Err_Code IN OUT NOCOPY NUMBER,
3107 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
3108
3109 x_count number :=0;
3110
3111 Begin
3112
3113 IF L_DEBUG = 'Y' THEN
3114 gms_error_pkg.gms_debug('IN EVENT ARRIBUTE UPDATION -- START','C');
3115 END IF;
3116
3117 update GMS_EVENT_ATTRIBUTE
3118 set
3119 EVENT_NUM = X_Event_Num
3120 ,last_update_date = sysdate
3121 ,last_updated_by = fnd_global.user_id
3122 ,last_update_login = fnd_global.login_id
3123 where
3124 request_id = X_request_id and
3125 project_id = X_Award_Project_Id and
3126 EVENT_NUM IS NULL;
3127
3128 Begin
3129
3130 Select 1
3131 into x_count
3132 from dual
3133 where exists
3134 (select 1
3135 from gms_event_attribute
3136 where request_id = X_request_id
3137 and project_id = X_Award_Project_Id
3138 and EVENT_NUM IS NULL);
3139
3140 Exception
3141
3142 When no_data_found then
3143
3144 x_count := 0;
3145 End;
3146
3147 -- If SQL%NOTFOUND THEN
3148 If x_count > 0 then
3149
3150 gms_error_pkg.gms_message('GMS_NO_UPD_PRJ_REQ',
3151 'PRJ',
3152 X_Award_Project_Id,
3153 'REQ',
3154 X_Request_id,
3155 X_Exec_Type => 'C',
3156 X_Err_Code => X_Err_Code,
3157 X_Err_Buff => X_Err_Buff);
3158 RETURN;
3159 Else
3160 X_Err_Code := 0;
3161 End If;
3162 Exception
3163
3164 When Others then
3165 IF L_DEBUG = 'Y' THEN
3166 gms_error_pkg.gms_debug('IN EVENT ARRIBUTE WHEN OTHERS ','C');
3167 END IF;
3168 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3169 'SQLCODE',
3170 SQLCODE,
3171 'SQLERRM',
3172 SQLERRM,
3173 X_Exec_Type => 'C',
3174 X_Err_Code => X_Err_Code,
3175 X_Err_Buff => X_Err_Buff);
3176 RAISE;
3177
3178 End EVENT_ATTRIBUTE_UPDATION;
3179
3180 ---------------------------------------------------------------------------------------------
3181
3182 PROCEDURE UPDATE_GMS_SUMMARY_FUNDINGS(X_Installment_Id IN NUMBER,
3183 X_Task_Id IN NUMBER,
3184 X_Calling_Process IN VARCHAR2,
3185 X_Rev_Bill_Amount IN NUMBER,
3186 X_Err_Code IN OUT NOCOPY NUMBER,
3187 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
3188
3189 X_Total_Funding_Amount NUMBER(22,5) := 0;
3190 X_Total_Rev_Bill_Amount NUMBER(22,5) := 0;
3191
3192 Begin
3193 GET_SUMM_FUNDING(X_Installment_Id,
3194 NULL,
3195 NULL,
3196 X_Task_Id,
3197 X_Calling_Process,
3198 X_Total_Funding_Amount,
3199 X_Total_Rev_Bill_Amount,
3200 X_Err_Code,
3201 X_Err_Buff);
3202
3203 If X_Err_Code <> 0 then
3204 --ROLLBACK;
3205 --RAISE FND_API.G_EXC_ERROR;
3206 Raise NO_PROCESSING_OF_AWARD ;
3207 End If;
3208 Begin
3209 If X_Calling_Process = 'Invoice' then
3210
3211 update GMS_SUMMARY_PROJECT_FUNDINGS spf
3212 set
3213 spf.TOTAL_BILLED_AMOUNT = (X_Rev_Bill_Amount + X_Total_Rev_Bill_Amount),
3214 spf.last_update_date = sysdate,
3215 spf.last_updated_by = fnd_global.user_id,
3216 spf.last_update_login = fnd_global.login_id
3217 where
3218 spf.INSTALLMENT_ID = X_Installment_Id
3219 and (
3220 (spf.TASK_ID = X_Task_Id)
3221 or (spf.TASK_ID IS NULL)
3222 or (spf.TASK_ID = (select t.top_task_id from PA_TASKS t where
3223 t.task_id = X_Task_Id))
3224 )
3225 and PROJECT_ID = (select project_id from pa_tasks where task_id = X_Task_Id);
3226
3227 --DECODE(TASK_ID,NULL,X_Task_Id,TASK_ID) = X_Task_Id
3228
3229 Elsif X_Calling_Process = 'Revenue' then
3230
3231 update GMS_SUMMARY_PROJECT_FUNDINGS spf
3232 set
3233 spf.TOTAL_REVENUE_AMOUNT = (X_Rev_Bill_Amount + X_Total_Rev_Bill_Amount),
3234 spf.last_update_date = sysdate,
3235 spf.last_updated_by = fnd_global.user_id,
3236 spf.last_update_login = fnd_global.login_id
3237 where
3238 spf.INSTALLMENT_ID = X_Installment_Id
3239 and (
3240 (spf.TASK_ID = X_Task_Id)
3241 or (spf.TASK_ID IS NULL)
3242 or (spf.TASK_ID = (select t.top_task_id from PA_TASKS t where
3243 t.task_id = X_Task_Id))
3244 )
3245 and PROJECT_ID = (select project_id from pa_tasks where task_id = X_Task_Id);
3246
3247 --DECODE(TASK_ID,NULL,X_Task_Id,TASK_ID) = X_Task_Id
3248
3249
3250 End If;
3251
3252 If SQL%ROWCOUNT = 0 then
3253 gms_error_pkg.gms_message('GMS_NO_UPD_TASK_INST',
3254 'TASK',
3255 X_Task_Id,
3256 'INST',
3257 X_Installment_Id,
3258 X_Exec_Type => 'C',
3259 X_Err_Code => X_Err_Code,
3260 X_Err_Buff => X_Err_Buff);
3261 --RAISE_APPLICATION_ERROR(-20524,X_Err_Buff);
3262 RETURN;
3263 Else
3264 X_Err_Code := 0;
3268
3265 End If;
3266
3267 End;
3269 END UPDATE_GMS_SUMMARY_FUNDINGS;
3270
3271 -- PROCEDURE: UPD_GSPF_WRAPPER, new procedure for updating gms_summary_project_fundings
3272
3273 PROCEDURE UPD_GSPF_WRAPPER(X_Installment_Id IN NUMBER,
3274 X_Task_Id IN NUMBER,
3275 X_Actual_Project_Id IN NUMBER,
3276 X_Calling_Process IN VARCHAR2,
3277 X_Rev_Bill_Amount IN NUMBER,
3278 X_Installment_Count IN NUMBER,
3279 X_Install_tab IN Inst_tab,
3280 X_Inst_total IN OUT NOCOPY Inst_tab2,
3281 X_Err_Code IN OUT NOCOPY NUMBER,
3282 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
3283 Begin
3284
3285 If X_Installment_Count = 1 then
3286
3287 UPDATE_GMS_SUMMARY_FUNDINGS(X_Installment_Id,
3288 X_Task_Id,
3289 X_Calling_Process,
3290 X_Rev_Bill_Amount,
3291 X_Err_Code,
3292 X_Err_Buff);
3293
3294 If X_Err_Code <> 0 then
3295 Raise NO_PROCESSING_OF_AWARD ;
3296 End If;
3297
3298 INSTALLMENT_AMOUNT(X_Installment_id,
3299 X_Rev_Bill_Amount,
3300 X_Inst_Total,
3301 X_Actual_Project_Id,
3302 X_Task_Id,
3303 X_Err_Code,
3304 X_Err_Buff);
3305
3306 If X_Err_Code <> 0 then
3307 Raise NO_PROCESSING_OF_AWARD ;
3308 End If;
3309 Else
3310
3311 for X_Count_Reqd in 1..X_Installment_Count
3312 loop
3313 UPDATE_GMS_SUMMARY_FUNDINGS(X_Install_tab(X_Count_Reqd).Installment_Id,
3314 X_Task_Id,
3315 X_Calling_Process,
3316 X_Install_tab(X_Count_Reqd).Rev_Bill_Amount,
3317 X_Err_Code,
3318 X_Err_Buff);
3319
3320 If X_Err_Code <> 0 then
3321 Raise NO_PROCESSING_OF_AWARD ;
3322 End If;
3323
3324 INSTALLMENT_AMOUNT(X_Install_tab(X_Count_Reqd).Installment_Id,
3325 X_Install_tab(X_Count_Reqd).Rev_Bill_Amount,
3326 X_Inst_Total,
3327 X_Actual_Project_Id,
3328 X_Task_Id,
3329 X_Err_Code,
3330 X_Err_Buff);
3331
3332 If X_Err_Code <> 0 then
3333 Raise NO_PROCESSING_OF_AWARD ;
3334 End If;
3335
3336 end loop;
3337 End if;
3338
3339 X_Err_Code := 0;
3340
3341 EXCEPTION
3342 WHEN OTHERS THEN
3343 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3344 'SQLCODE',
3345 SQLCODE,
3346 'SQLERRM',
3347 SQLERRM,
3348 X_Exec_Type => 'C',
3349 X_Err_Code => X_Err_Code,
3350 X_Err_Buff => X_Err_Buff);
3351 RETURN;
3352
3353 End UPD_GSPF_WRAPPER;
3354
3355 -----------------------------------------------------------------------------------------
3356 -- Procedure UPD_ADL_BILLING_FLAG: Updates GMS_AWARD_DISTRIBUTIONS table sets the
3357 -- Billed Flag and Revenue Distributed flag to 'Y' for the expenditure item that has been processed
3358 -----------------------------------------------------------------------------------------
3359 PROCEDURE UPD_ADL_BILLING_FLAG(X_Expenditure_Item_Id IN NUMBER,
3360 X_Adl_Line_Num IN NUMBER,
3361 X_Calling_Process IN VARCHAR2,
3362 X_Billable_Flag IN VARCHAR2,
3363 X_Bill_Hold_Flag IN VARCHAR2,
3364 X_Err_Code IN OUT NOCOPY NUMBER,
3365 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
3366
3367 Begin
3368 If X_Calling_Process = 'Invoice' then
3369 update
3370 GMS_AWARD_DISTRIBUTIONS
3371 set
3372 BILLED_FLAG = 'Y'
3373 ,last_update_date = sysdate
3374 ,last_updated_by = fnd_global.user_id
3375 ,last_update_login = fnd_global.login_id
3376 where expenditure_item_id = X_Expenditure_Item_Id
3377 and adl_line_num = X_Adl_Line_Num
3378 and document_type='EXP'
3379 and adl_status = 'A';
3380
3381 Elsif X_Calling_Process = 'Revenue' then
3382 update
3383 GMS_AWARD_DISTRIBUTIONS
3384 set
3385 revenue_distributed_flag = 'Y'
3386 ,last_update_date = sysdate
3387 ,last_updated_by = fnd_global.user_id
3388 ,last_update_login = fnd_global.login_id
3389 where expenditure_item_id = X_Expenditure_Item_Id
3390 and adl_line_num = X_Adl_Line_Num
3391 and document_type='EXP'
3392 and adl_status = 'A';
3393
3394 End If;
3395
3396 If SQL%ROWCOUNT = 0 then
3397 gms_error_pkg.gms_message('GMS_NO_UPD_EXP_ADL',
3398 'EXP',
3399 X_Expenditure_Item_Id,
3400 'ADL',
3401 X_Adl_Line_Num,
3402 X_Exec_Type => 'C',
3403 X_Err_Code => X_Err_Code,
3404 X_Err_Buff => X_Err_Buff);
3405 RETURN;
3406 Else
3407 X_Err_Code := 0;
3408 End If;
3409
3410 End UPD_ADL_BILLING_FLAG;
3411
3412 ------------------------------------------------------------------------------------------
3413 -- Procedure GET_RUN_TOTAL: This procedure get the running total for the event description
3414 ------------------------------------------------------------------------------------------
3415 Procedure GET_RUN_TOTAL(X_Req_id IN NUMBER,
3416 X_Proj_Id IN NUMBER,
3417 X_Qty OUT NOCOPY NUMBER)
3418 is
3419 Begin
3423 from pa_expenditure_items_all peia,
3420 -- Bug 3235390 : Added decode to get correct quantity
3421 Select SUM(NVL( DECODE(adl.line_num_reversed, NULL, peia.quantity,-1*peia.quantity),0))
3422 into x_qty
3424 gms_event_intersect gei,
3425 gms_award_distributions adl
3426 where peia.expenditure_item_id = gei.expenditure_item_id
3427 and adl.expenditure_item_id = gei.expenditure_item_id
3428 and adl.adl_line_num = gei.adl_line_num
3429 and adl.document_type ='EXP'
3430 and adl.adl_status ='A'
3431 and gei.request_id = X_Req_id
3432 and gei.award_project_id = X_Proj_Id
3433 and gei.event_num is null;
3434 Exception
3435 When no_data_found then
3436 x_qty:=0;
3437 End;
3438
3439 ------------------------------------------------------------------------------------------
3440 -- Bug 3235390 : Introduced the following procedure
3441 -- PROCESS_TEMP_EVENTS : This procedure is used to insert / update the temporary
3442 -- events stored in temporary global table gms_events_temp_format.
3443 ------------------------------------------------------------------------------------------
3444 PROCEDURE PROCESS_TEMP_EVENTS (p_act_project_id IN NUMBER,
3445 p_task_id IN NUMBER,
3446 p_invfmt_incl_task IN VARCHAR2, /* Bug 3523930*/
3447 p_format IN VARCHAR2,
3448 p_description IN VARCHAR2,
3449 p_calling_place IN VARCHAR2,
3450 p_units IN VARCHAR2,
3451 p_quantity IN NUMBER,
3452 p_amount IN NUMBER,
3453 p_event_num OUT NOCOPY NUMBER,
3454 p_err_code IN OUT NOCOPY NUMBER,
3455 p_err_buff IN OUT NOCOPY VARCHAR2) IS
3456
3457
3458 l_description VARCHAR2(2000);
3459
3460 /* Added below 2 cursors for 3523930*/
3461 CURSOR C_event_exists_PTF IS
3462 SELECT event_num
3463 FROM gms_events_temp_format
3464 WHERE act_project_id = p_act_project_id
3465 AND task_id = p_task_id
3466 AND NVL(format,'X') = NVL(p_format,'X');
3467
3468 CURSOR C_event_exists_F IS
3469 SELECT event_num
3470 FROM gms_events_temp_format
3471 WHERE NVL(format,'X') = NVL(p_format,'X');
3472
3473 BEGIN
3474
3475 IF L_DEBUG = 'Y' THEN
3476 gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - START ','C');
3477 gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - X_trans_type is '||X_trans_type,'C'); -- added debug for 5413530
3478 gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - G_trans_type is '||G_trans_type,'C'); -- added debug for 5413530
3479 END IF;
3480
3481 IF p_calling_place = 'Revenue' THEN
3482 l_description := p_description ||'- '|| p_quantity || ' ' || p_units;
3483 ELSE
3484 l_description := p_description;
3485 END IF;
3486
3487
3488 OPEN C_event_exists_PTF;
3489 FETCH C_event_exists_PTF INTO p_event_num ;
3490
3491 IF ( C_event_exists_PTF%FOUND AND
3492 ( ( p_format IS NULL AND X_trans_type = G_trans_type ) OR ( p_format IS NOT NULL ))) -- for bug 5413530
3493 THEN
3494 --If there exists a temporary event with exact match then we dont need to bother about the p_invfmt_incl_task = 'N'
3495 --and update the event with the amount
3496
3497 UPDATE gms_events_temp_format
3498 SET amount = amount + p_amount,
3499 quantity = quantity + p_quantity,
3500 description = decode(p_calling_place,'Revenue',p_description || '- '|| to_char(quantity + p_quantity) || ' ' ||p_units,p_description)
3501 WHERE event_num = p_Event_num
3502 AND act_project_id = p_act_project_id
3503 AND task_id = p_task_id
3504 AND nvl(format,'X') = nvl(p_format,'X'); -- for bug 5413530
3505
3506 IF L_DEBUG = 'Y' THEN
3507 gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - After updating '||p_event_num||' in gms_events_temp_format with amount '||p_amount ,'C');
3508 END IF;
3509
3510 ELSE
3511
3512 IF p_invfmt_incl_task = 'N' THEN
3513 --If there exists no temporary event with exact match and task id is not a format column then fetch
3514 --the event_num which is already creatd for this format and insert new line into gms_events_temp_format with
3515 --same event_num but with new task_id
3516
3517 OPEN C_event_exists_F;
3518 FETCH C_event_exists_F INTO p_event_num ;
3519
3520 IF ( C_event_exists_F%NOTFOUND OR
3521 ( X_trans_type <> G_trans_type AND p_format IS NULL ) ) -- for bug 5413530
3522 THEN
3523 --If there exists no temporary event with format match then generate new event_num
3524 p_Event_num := x_temp_negative_evt_num;
3525 X_temp_negative_evt_num :=x_temp_negative_evt_num-1;
3526 END If;
3527 CLOSE C_event_exists_F;
3528
3529 ELSE
3530 --If task is one of the column in format then generate new event as no match found
3531 p_Event_num := x_temp_negative_evt_num;
3532 X_temp_negative_evt_num :=x_temp_negative_evt_num-1;
3533 END If;
3534
3535 INSERT INTO gms_events_temp_format(Event_num ,
3536 ACT_PROJECT_ID,
3537 TASK_ID,
3538 QUANTITY,
3539 AMOUNT,
3540 FORMAT,
3544 p_task_id,
3541 DESCRIPTION)
3542 VALUES (p_event_num,
3543 p_act_project_id,
3545 p_quantity,
3546 p_Amount,
3547 p_format,
3548 l_description );
3549
3550 IF L_DEBUG = 'Y' THEN
3551 gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - After inserting event '||p_event_num||' into gms_events_temp_format for task '||p_task_id ||' with amount '||p_amount,'C');
3552 END IF;
3553
3554 END IF;
3555 CLOSE C_event_exists_PTF;
3556
3557 G_trans_type := X_trans_type ; /* For bug 5413530 */
3558
3559 IF L_DEBUG = 'Y' THEN
3560 gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - END ','C');
3561 END IF;
3562
3563 EXCEPTION
3564 WHEN OTHERS THEN
3565
3566 IF L_DEBUG = 'Y' THEN
3567 gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - WHEN OTHERS ','C');
3568 END IF;
3569
3570 IF C_event_exists_F%ISOPEN THEN
3571 CLOSE C_event_exists_F;
3572 END IF;
3573
3574 IF C_event_exists_PTF%ISOPEN THEN
3575 CLOSE C_event_exists_PTF;
3576 END IF;
3577
3578 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3579 'SQLCODE',
3580 SQLCODE,
3581 'SQLERRM',
3582 SQLERRM,
3583 X_Exec_Type => 'C',
3584 X_Err_Code => p_Err_Code,
3585 X_Err_Buff => p_Err_Buff);
3586 Raise NO_PROCESSING_OF_AWARD ;
3587
3588 End PROCESS_TEMP_EVENTS;
3589
3590 ---------------------------------------------------------------------------------------
3591 --Procedure CREATE_PA_EVENTS
3592 -----------------------------------------------------------------------------------------
3593 -- Bug 3235390 : This newly introduced procedure does the following :
3594 -- a. Fetches consolidated records from the plsql table
3595 -- b. Inserts consolidated events into gms_event_attribute table
3596 -- b. If amount <> 0 then inserts events into Pa_events and
3597 -- updates GEI and GEA with newly generated event_num.
3598 -- c. If amount = 0 then updates -1 on GEA and GEI and sets the
3599 -- NULL events variables.
3600 ----------------------------------------------------------------------------------------------------
3601
3602 PROCEDURE CREATE_PA_EVENTS (p_project_id In NUMBER,
3603 p_Calling_Process IN VARCHAR2,
3604 p_completion_date IN DATE,
3605 p_carrying_out_org_id IN NUMBER,
3606 p_Request_Id IN NUMBER,
3607 p_installment_total IN OUT NOCOPY inst_tab2,
3608 p_Err_Code IN OUT NOCOPY NUMBER,
3609 p_Err_Buff IN OUT NOCOPY VARCHAR2) IS
3610
3611 Evt_Num NUMBER(15) := 0;
3612 Evt_Description VARCHAR2(2000) := NULL;
3613 St_Error_Message VARCHAR2(2000);
3614 St_Status NUMBER;
3615 X_count NUMBER;
3616 X_rev_amt NUMBER(22,5);
3617 X_bill_amt NUMBER(22,5);
3618
3619 CURSOR C_get_temp_pa_events IS
3620 SELECT event_num,
3621 format,
3622 description,
3623 SUM(amount) amount
3624 FROM gms_events_temp_format
3625 GROUP BY event_num,format,description
3626 ORDER BY event_num desc;
3627
3628 CURSOR C_get_temp_gms_events (p_evt_num NUMBER,
3629 p_format VARCHAR2,
3630 p_description VARCHAR2 ) IS
3631 SELECT act_project_id,
3632 task_id,
3633 SUM(amount) amount
3634 FROM gms_events_temp_format
3635 WHERE event_num = p_evt_num
3636 AND NVL(format,'X') = NVL(p_format,'X')
3637 AND description = p_description
3638 GROUP BY act_project_id,task_id;
3639
3640 BEGIN
3641
3642 IF L_DEBUG = 'Y' THEN
3643 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - START','C');
3644 END IF;
3645
3646 FOR pa_events_rec IN C_get_temp_pa_events LOOP
3647
3648 IF nvl(pa_events_rec.amount,0) = 0 THEN
3649 Evt_num := -1;
3650
3651 IF p_Calling_Process = 'Revenue' THEN
3652 X_REVRAW_NULL_EVENT_PROCESSED := TRUE;
3653 ELSIF p_Calling_Process = 'Invoice' THEN
3654 X_INVRAW_NULL_EVENT_PROCESSED := TRUE;
3655 END IF;
3656
3657 IF L_DEBUG = 'Y' THEN
3658 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - Encountered NULL event- After setting NULL event flags','C');
3659 END IF;
3660 END IF;
3661
3662 FOR gms_events_rec IN C_get_temp_gms_events(pa_events_rec.event_num,pa_events_rec.format,pa_events_rec.description) LOOP
3663
3664 EVENT_WRAPPER(p_Project_Id,
3665 gms_events_rec.act_project_id,
3666 gms_events_rec.task_id,
3667 p_Calling_Process,
3668 gms_events_rec.amount,
3669 p_installment_total,
3670 NULL, -- Burden Cost Code
3671 NULL, -- Exp Org
3672 p_Request_Id,
3673 p_Err_Code,
3674 p_Err_Buff);
3675
3676 IF L_DEBUG = 'Y' THEN
3680 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call value of p_Err_Code '||p_Err_Code,'C');
3677 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call for event '||pa_events_rec.event_num,'C');
3678 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call for project_id '||gms_events_rec.act_project_id,'C');
3679 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call for task_id '||gms_events_rec.task_id,'C');
3681 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call value of p_Err_Buff '||p_Err_Buff,'C');
3682 END IF;
3683
3684 IF p_Err_Code <> 0 THEN
3685 Raise NO_PROCESSING_OF_AWARD ;
3686 END IF;
3687
3688 END LOOP;
3689
3690 IF pa_events_rec.amount <> 0 THEN
3691
3692 IF p_Calling_Process = 'Revenue' then
3693 X_rev_amt := pa_events_rec.amount;
3694 X_bill_amt := 0;
3695 ELSIF p_Calling_Process = 'Invoice' then
3696 X_bill_amt := pa_events_rec.amount;
3697 X_rev_amt := 0;
3698 END IF;
3699
3700 Evt_Num := pa_billing_seq.next_eventnum(p_Project_Id,NULL); -- Bug 3235390
3701
3702 pa_billing_pub.insert_event(
3703 X_rev_amt => X_rev_amt,
3704 X_bill_amt => X_bill_amt,
3705 X_project_id => p_project_id,
3706 X_event_type => 'AWARD_BILLING',
3707 X_top_task_id => NULL,
3708 X_organization_id => p_Carrying_Out_Org_Id,
3709 X_completion_date => p_completion_date,
3710 X_event_description => pa_events_rec.description,
3711 X_event_num_reversed => NULL,
3712 X_attribute_category => NULL,
3713 X_attribute1 => NULL,
3714 X_attribute2 => NULL,
3715 X_attribute3 => NULL,
3716 X_attribute4 => NULL,
3717 X_attribute5 => NULL,
3718 X_attribute6 => NULL,
3719 X_attribute7 => NULL,
3720 X_attribute8 => NULL,
3721 X_attribute9 => NULL,
3722 X_attribute10 => NULL,
3723 X_error_message => St_Error_Message,
3724 X_status => St_Status
3725 );
3726
3727 IF L_DEBUG = 'Y' THEN
3728 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After insert_event call for event number '||Evt_Num||' with amount '||pa_events_rec.amount,'C');
3729 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After insert_event call value of St_Error_Message '||St_Error_Message,'C');
3730 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After insert_event call value of St_Status '||St_Status,'C');
3731 END IF;
3732
3733 IF St_Status <> 0 THEN
3734 RAISE NO_PROCESSING_OF_AWARD;
3735 END IF;
3736
3737
3738
3739 END IF;
3740
3741 UPDATE gms_event_intersect
3742 SET Event_Num = Evt_num
3743 WHERE Event_num = pa_events_rec.event_num
3744 AND award_project_id = p_project_id; /* Added for bug 4172924*/
3745
3746 IF L_DEBUG = 'Y' THEN
3747 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After updating GEI ','C');
3748 END IF;
3749
3750 EVENT_ATTRIBUTE_UPDATION( Evt_Num,
3751 p_Project_Id,
3752 p_Request_Id,
3753 p_Err_Code,
3754 p_Err_Buff);
3755
3756 IF L_DEBUG = 'Y' THEN
3757 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_ATTRIBUTE_UPDATION value of p_Err_Code'||p_Err_Code,'C');
3758 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_ATTRIBUTE_UPDATION value of p_Err_Buff'||p_Err_Buff,'C');
3759 END IF;
3760
3761 IF p_Err_Code <> 0 THEN
3762 Raise NO_PROCESSING_OF_AWARD ;
3763 END IF;
3764
3765 END LOOP;
3766
3767 IF L_DEBUG = 'Y' THEN
3768 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - END','C');
3769 END IF;
3770
3771 EXCEPTION
3772
3773 When Others then
3774
3775 IF L_DEBUG = 'Y' THEN
3776 gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - WHEN OTHERS ','C');
3777 END IF;
3778
3779 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3780 'SQLCODE',
3781 SQLCODE,
3782 'SQLERRM',
3783 SQLERRM,
3784 X_Exec_Type => 'C',
3785 X_Err_Code => p_Err_Code,
3786 X_Err_Buff => p_Err_Buff);
3787
3788 RAISE NO_PROCESSING_OF_AWARD;
3789
3790 END CREATE_PA_EVENTS;
3791
3792 -----------------------------------------------------------------------------------------
3793 -- Procedure DO_EVENT_PROCESSING: This procedure builds the Event description and creates the
3794 -- Billing or Revenue Event
3795 -----------------------------------------------------------------------------------------
3796 -- Bug 3235390 : Modified the logic as mentioned below
3797 -- a. Code to create events in pa_events and gms_event_attribute table is
3798 -- shifted to CREATE_PA_EVENTS procedure.
3799 -- b. Events will be inserted into GBC and GEI and will be marked as billed/accrued.
3803 -- records from the plsql table and will insert events into Pa_events and
3800 -- c. Events will be assigned a negative seqeunce number which starts from -1001
3801 -- d. Distinct events and their format will be temporarly stored in plsql table
3802 -- e. Newly introduced procedure CREATE_PA_EVENTS will fetch the consolidated
3804 -- gms_event_attribute tables and updates GEI with newly generated event_num.
3805 -- Even the NULL events logic is shifted to create_pa_events procedure.
3806 ----------------------------------------------------------------------------------------------------
3807
3808
3809 PROCEDURE DO_EVENT_PROCESSING(X_Count_Of_Columns IN NUMBER DEFAULT 0,
3810 X_Sel_Grp_Diff_Ind IN Mark_Sel_Grp_Diff_Array ,
3811 X_Right_Jstfy_Flag_Array IN Mark_Sel_Grp_Diff_Array,
3812 X_Values IN Selected_Values_Rows,
3813 X_Padding_Length IN Padding_Length_Array,
3814 X_Run_Total IN Running_Total_Array ,
3815 X_Text_Array IN Free_Text_Array,
3816 X_Proj_Id IN NUMBER DEFAULT NULL,
3817 X_Task_Id IN NUMBER DEFAULT NULL,
3818 X_invfmt_incl_task IN VARCHAR2 DEFAULT 'N', /* Bug 3523930 */
3819 X_Evt_Amount IN NUMBER DEFAULT NULL,
3820 X_Carry_Out_Org_Id IN NUMBER DEFAULT NULL,
3821 X_Through_Date IN DATE DEFAULT SYSDATE,
3822 X_Call_Process IN VARCHAR2 DEFAULT NULL,
3823 X_Req_Id IN NUMBER DEFAULT NULL,
3824 C_Installment_Id IN NUMBER,
3825 X_Install_Count IN NUMBER,
3826 X_Installment_Total IN OUT NOCOPY Inst_tab2,
3827 X_Err_Code IN OUT NOCOPY NUMBER,
3828 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
3829
3830 CURSOR GET_RAW_ROWS_FROM_INTERSECT IS
3831 Select
3832 gei.award_project_id Award_Project_Id
3833 ,adl.project_id Actual_Project_Id
3834 ,adl.task_id Actual_Task_Id
3835 ,sum(gei.Amount) amount
3836 from
3837 gms_event_intersect gei,
3838 gms_award_distributions adl
3839 where
3840 gei.award_project_id = X_Proj_Id and
3841 gei.request_id = X_Req_Id and
3842 gei.event_type = 'INVOICE' and
3843 gei.event_num is NULL and
3844 adl.expenditure_item_id = gei.expenditure_item_id and
3845 adl.adl_line_num = gei.adl_line_num and
3846 adl.document_type ='EXP' and
3847 adl.adl_status ='A'
3848 group by
3849 gei.award_project_id,
3850 adl.project_id,
3851 adl.task_id;
3852
3853 Evt_Num NUMBER(15);
3854 Evt_Description VARCHAR2(2000);
3855 Evt_format VARCHAR2(2000);
3856 X_Quantity NUMBER(22,5);
3857
3858 -- 3120142
3859 x_pad1 number;
3860 x_pad2 number;
3861 x_pad3 number;
3862 -- 3120142
3863
3864 Begin
3865
3866 IF L_DEBUG = 'Y' THEN
3867 gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - START ','C');
3868 END IF;
3869
3870 /* Building the Event Description */
3871
3872 For j in 1..X_Count_Of_Columns LOOP
3873
3874 -- 3120142 Start
3875 gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3876
3877 If X_Sel_Grp_Diff_Ind(j) = 'Y' then -- I
3878
3879 --gms_error_pkg.gms_debug('****** X_Values(j) '||X_Values(j),'C');
3880 --gms_error_pkg.gms_debug('****** X_Padding_Length(j) '||X_Padding_Length(j),'C');
3881 --gms_error_pkg.gms_debug('****** length(X_Values(j)) '||length(X_Values(j)),'C');
3882
3883 -- Grouping value ................... Start
3884
3885 If (X_Padding_Length(j)- length(X_Values(j))) <= 0 then
3886 X_pad1 := X_Padding_Length(j);
3887 Else
3888 X_pad1 := X_Padding_Length(j) - (abs(X_Padding_Length(j)- length(X_Values(j))));
3889 End If;
3890 gms_error_pkg.gms_debug('****** X_pad1 '||X_pad1,'C');
3891
3892 If X_Right_Jstfy_Flag_Array(j) = 'N' then
3893 Evt_Description := Evt_Description||rpad(X_Values(j),X_Pad1)||' ';
3894 Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3895 Evt_Description := Evt_Description||lpad(X_Values(j),X_Pad1)||' ';
3896 End If;
3897
3898 -- Grouping value ................... End
3899 gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3900
3901 Elsif X_Sel_Grp_Diff_Ind(j) = 'N' then -- I
3902 -- Grouping Quantity ................... Start
3903 get_run_total(X_Req_id,X_Proj_Id,x_quantity);
3904 If (X_Padding_Length(j)- length(to_char(x_quantity))) <= 0 then
3905 X_pad2 := X_Padding_Length(j);
3906 Else
3907 X_pad2 := X_Padding_Length(j) - (abs(X_Padding_Length(j)- length(to_char(x_quantity ))));
3908 End If;
3909 gms_error_pkg.gms_debug('****** X_pad2 '||X_pad1,'C');
3910
3911 If X_Right_Jstfy_Flag_Array(j) = 'N' then
3912 Evt_Description := Evt_Description||rpad(to_char(x_quantity),x_pad2)||' ';
3913 Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3914 Evt_Description := Evt_Description||lpad(to_char(x_quantity),x_pad2)||' ';
3915 End If;
3916 -- Grouping Quantity ................... End
3917 gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3918
3922 If (X_Padding_Length(j)- length(X_Text_Array(j))) <= 0 then
3919 Elsif X_Sel_Grp_Diff_Ind(j) = 'T' then -- I
3920
3921 -- Grouping Text ................... Start
3923 X_pad3 := X_Padding_Length(j);
3924 Else
3925 X_pad3 := X_Padding_Length(j) - (abs(X_Padding_Length(j)- length(X_Text_Array(j))));
3926 End If;
3927
3928 gms_error_pkg.gms_debug('****** X_pad3 '||X_pad3,'C');
3929
3930 If X_Right_Jstfy_Flag_Array(j) = 'N' then
3931 Evt_Description := Evt_Description||rpad(X_Text_Array(j),x_pad3)||' ';
3932 Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3933 Evt_Description := Evt_Description||lpad(X_Text_Array(j),x_pad3)||' ';
3934 End If;
3935
3936 -- Grouping Text ................... End
3937 gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3938 End If; -- I
3939
3940 -- 3120142 End
3941
3942 /* ------------------------------------------------------------- 3120142 --- commented out ----------------------
3943
3944 If X_Sel_Grp_Diff_Ind(j) = 'Y' then
3945 If X_Right_Jstfy_Flag_Array(j) = 'N' then
3946 Evt_Description := Evt_Description||rpad(X_Values(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3947 length(X_Values(j) ))))||' ';
3948 Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3949 Evt_Description := Evt_Description||lpad(X_Values(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3950 length(X_Values(j) ))))||' ';
3951 End If;
3952 Elsif X_Sel_Grp_Diff_Ind(j) = 'N' then
3953
3954 get_run_total(X_Req_id,X_Proj_Id,x_quantity);
3955
3956 If X_Right_Jstfy_Flag_Array(j) = 'N' then
3957 Evt_Description := Evt_Description||rpad(to_char(x_quantity),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3958 length(to_char(x_quantity )))))||' ';
3959 Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3960 Evt_Description := Evt_Description||rpad(to_char(x_quantity),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3961 length(to_char(x_quantity )))))||' ';
3962 End If;
3963 Elsif X_Sel_Grp_Diff_Ind(j) = 'T' then
3964 If X_Right_Jstfy_Flag_Array(j) = 'N' then
3965 Evt_Description := Evt_Description||rpad(X_Text_Array(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3966 length(X_Text_Array(j) ))))||' ';
3967 Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3968 Evt_Description := Evt_Description||rpad(X_Text_Array(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3969 length(X_Text_Array(j) ))))||' ';
3970 End If;
3971 End If;
3972 ------------------------------------------------------------- 3120142 --- commented out ---------------------- */
3973 End LOOP;
3974
3975 FOR i IN 1..X_Count_Of_Columns LOOP
3976 IF X_Sel_Grp_Diff_Ind(i) = 'Y' then
3977 Evt_format := Evt_format||' - '||X_values(i);
3978 END IF;
3979
3980 END LOOP;
3981
3982 IF L_DEBUG = 'Y' THEN
3983 gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - Value of Evt_Description '||Evt_Description,'C');
3984 gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - Value of Evt_format '||Evt_format,'C');
3985 END IF;
3986
3987 /*x_temp_negative_evt_num := x_temp_negative_evt_num - 1 ; Bug 3523930 - Moved this into process tempevents*/
3988 FOR raw_events IN GET_RAW_ROWS_FROM_INTERSECT LOOP
3989
3990 PROCESS_TEMP_EVENTS (raw_events.actual_project_id,
3991 raw_events.actual_task_id,
3992 X_invfmt_incl_task, /* Added for bug 3523930 */
3993 Evt_format,
3994 Evt_Description,
3995 X_Call_Process,
3996 NULL,
3997 NULL,
3998 raw_events.amount,
3999 evt_num,
4000 x_err_code,
4001 x_err_buff) ;
4002
4003 IF L_DEBUG = 'Y' THEN
4004 gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of X_Err_Code '||X_Err_Code,'C');
4005 gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of x_err_buff '||x_err_buff,'C');
4006 END IF;
4007
4008 IF X_Err_Code <> 0 then
4009 Raise NO_PROCESSING_OF_AWARD ;
4010 END IF;
4011
4012 UPDATE_GMS_EVENT_INTERSECT(Evt_Num,
4013 X_Proj_Id,
4014 X_Req_Id,
4015 raw_events.actual_project_id,
4016 raw_events.actual_task_id );
4017
4018 IF L_DEBUG = 'Y' THEN
4019 gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - After UPDATE_GMS_EVENT_INTERSECT','C');
4020 END IF;
4021
4022 END LOOP;
4023
4024 EXCEPTION
4025 WHEN OTHERS THEN
4026
4027 IF L_DEBUG = 'Y' THEN
4028 gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - WHEN OTHERS ','C');
4029 END IF;
4030 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
4031 'SQLCODE',
4032 SQLCODE,
4033 'SQLERRM',
4034 SQLERRM,
4035 X_Exec_Type => 'C',
4036 X_Err_Code => X_Err_Code,
4037 X_Err_Buff => X_Err_Buff);
4038 END DO_EVENT_PROCESSING;
4039
4040 ---------------------------------------------------------------------------------------
4044 X_Through_Date IN DATE,
4041 --Procedure DO_BURDEN_EVENT_PROCESSING
4042 ---------------------------------------------------------------------------------------
4043 PROCEDURE DO_BURDEN_EVENT_PROCESSING(X_Project_Id IN NUMBER,
4045 X_Calling_Process IN VARCHAR2,
4046 X_Carrying_Out_Org_Id IN NUMBER,
4047 X_Request_Id IN NUMBER,
4048 X_Installment_total IN OUT NOCOPY Inst_tab2,
4049 X_Err_Code IN OUT NOCOPY NUMBER,
4050 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
4051
4052 CURSOR GET_BURD_ROWS_FROM_INTERSECT IS
4053 Select
4054 Award_Project_Id
4055 ,Actual_Project_Id
4056 ,Actual_Task_Id
4057 ,Burden_Cost_Code
4058 ,Expenditure_Org_Id
4059 ,sum(Amount)
4060 from
4061 GMS_BURDEN_COMPONENTS
4062 where
4063 award_project_id = X_Project_Id and
4064 request_id = X_Request_Id and
4065 event_type = decode(X_Calling_Process,'Revenue','REVENUE','Invoice','INVOICE') and
4066 event_num is NULL
4067 group by
4068 Award_Project_Id
4069 ,Actual_Project_Id
4070 ,Actual_Task_Id
4071 ,Burden_Cost_Code
4072 ,Expenditure_Org_Id ;
4073
4074 Ins_Award_Project_Id NUMBER := 0;
4075 Ins_Actual_Project_Id NUMBER := 0;
4076 Ins_Actual_Task_Id NUMBER := 0;
4077 Ins_Burden_Cost_Code VARCHAR2(30) := NULL;
4078 Ins_Expenditure_Org_Id NUMBER := 0;
4079 Ins_Amount NUMBER := 0;
4080
4081 Ins_Act_Proj_Num VARCHAR2(30);
4082 Ins_Act_Task_Num VARCHAR2(30);
4083 --Ins_Exp_Org_Name VARCHAR2(60);
4084 --The width of the variable is changed for UTF8 changes for HRMS schema. Refer bug 2302839.
4085 Ins_Exp_Org_Name HR_ALL_ORGANIZATION_UNITS_TL.NAME%TYPE;
4086
4087 Evt_Num NUMBER(15) := 0;
4088 Evt_Description VARCHAR2(2000) := NULL;
4089
4090 St_Error_Message VARCHAR2(2000);
4091 St_Status NUMBER;
4092
4093 Begin
4094
4095 IF L_DEBUG = 'Y' THEN
4096 gms_error_pkg.gms_debug('IN BURDEN EVENT - START','C');
4097 END IF;
4098
4099 OPEN GET_BURD_ROWS_FROM_INTERSECT;
4100 LOOP
4101 FETCH GET_BURD_ROWS_FROM_INTERSECT into
4102 Ins_Award_Project_Id
4103 ,Ins_Actual_Project_Id
4104 ,Ins_Actual_Task_Id
4105 ,Ins_Burden_Cost_Code
4106 ,Ins_Expenditure_Org_Id
4107 ,Ins_Amount;
4108 EXIT WHEN GET_BURD_ROWS_FROM_INTERSECT%NOTFOUND;
4109
4110 If Ins_Amount <> 0 then
4111 -- DO NOT INSERT ZERO AMOUNT EVENTS
4112 IF L_DEBUG = 'Y' THEN
4113 gms_error_pkg.gms_debug('DBP - If Ins_Amount <> 0 part ..','C');
4114 END IF;
4115
4116 /* Getting Actual Project Number, Task Number and Expenditure Organization Name */
4117 Begin
4118 Select
4119 a.segment1,
4120 b.task_number,
4121 c.name
4122 into
4123 Ins_Act_Proj_Num,
4124 Ins_Act_Task_Num,
4125 Ins_Exp_Org_Name
4126 from
4127 pa_projects_all a,
4128 pa_tasks b,
4129 hr_organization_units c
4130 where a.project_id = Ins_Actual_Project_Id and
4131 b.task_id = Ins_Actual_Task_Id and
4132 c.organization_id = Ins_Expenditure_Org_Id;
4133 End;
4134
4135 --------------------------------------------------------------------------
4136 /* Get the Installment Number to be concatenated with Event Description */
4137 --------------------------------------------------------------------------
4138 IF L_DEBUG = 'Y' THEN
4139 gms_error_pkg.gms_debug('DBP - CALL EVENT WRAPPER','C');
4140 END IF;
4141 EVENT_WRAPPER(X_Project_Id,
4142 Ins_Actual_Project_Id,
4143 Ins_Actual_Task_Id,
4144 X_Calling_Process,
4145 Ins_Amount,
4146 X_Installment_Total,
4147 -- Inst_Num, Bug 2380344
4148 Ins_Burden_Cost_Code,
4149 Ins_Expenditure_Org_Id,
4150 X_Request_Id,
4151 X_Err_Code,
4152 X_Err_Buff);
4153
4154 If X_Err_Code <> 0 then
4155 --ROLLBACK;
4156 --RAISE FND_API.G_EXC_ERROR;
4157 Raise NO_PROCESSING_OF_AWARD ;
4158 End If;
4159 IF L_DEBUG = 'Y' THEN
4160 gms_error_pkg.gms_debug('DBP - AFTER EVENT WRAPPER','C');
4161 END IF;
4162
4163 -------------------------------------------------------------------------------------
4164 /* Getting the Event Number */
4165 Evt_Num := pa_billing_seq.next_eventnum(Ins_Award_Project_Id,NULL);
4166
4167 IF L_DEBUG = 'Y' THEN
4168 gms_error_pkg.gms_debug('DBP - Evt_Num::'||Evt_Num,'C');
4169 END IF;
4170
4171
4172 /* Building the Event Description */
4173 Evt_Description := Ins_Act_Proj_Num||'- '||Ins_Act_Task_Num||' - '||Ins_Burden_Cost_Code||'- '||Ins_Exp_Org_Name ; -- Bug 2380344 : Removed Inst_Num
4174
4175 If X_Calling_Process = 'Revenue' then
4176 pa_billing_pub.insert_event(
4177 X_rev_amt => Ins_Amount, /* X_rev_amt */
4178 X_bill_amt => 0, /* X_bill_amt */
4179 X_project_id => Ins_Award_Project_Id, /* X_project_id */
4180 X_event_type => 'AWARD_BILLING', /* X_event_type */
4184 X_event_description => Evt_Description, /* X_event_description */
4181 X_top_task_id => NULL, /* X_top_task_id */
4182 X_organization_id => X_Carrying_Out_Org_Id, /* X_organization_id */
4183 X_completion_date => X_Through_Date, /* X_completion_date */
4185 X_event_num_reversed => NULL, /* Event Num Reversed */
4186 X_attribute_category => NULL, /* X_attribute_category */
4187 X_attribute1 => NULL, /* X_attribute1 */
4188 X_attribute2 => NULL, /* X_attribute2 */
4189 X_attribute3 => NULL, /* X_attribute3 */
4190 X_attribute4 => NULL, /* X_attribute4 */
4191 X_attribute5 => NULL, /* X_attribute5 */
4192 X_attribute6 => NULL, /* X_attribute6 */
4193 X_attribute7 => NULL, /* X_attribute7 */
4194 X_attribute8 => NULL, /* X_attribute8 */
4195 X_attribute9 => NULL, /* X_attribute9 */
4196 X_attribute10 => NULL, /* X_attribute10 */
4197 X_error_message => St_Error_Message,
4198 X_status => St_Status
4199 );
4200
4201 Elsif X_Calling_Process = 'Invoice' then
4202
4203 pa_billing_pub.insert_event(
4204 X_rev_amt => 0, /* X_rev_amt */
4205 X_bill_amt => Ins_Amount, /* X_bill_amt */
4206 X_project_id => Ins_Award_Project_Id, /* X_project_id */
4207 X_event_type => 'AWARD_BILLING', /* X_event_type */
4208 X_top_task_id => NULL, /* X_top_task_id */
4209 X_organization_id => X_Carrying_Out_Org_Id, /* X_organization_id */
4210 X_completion_date => X_Through_Date, /* X_completion_date */
4211 X_event_description => Evt_Description, /* X_event_description */
4212 X_event_num_reversed => NULL, /* Event Num Reversed */
4213 X_attribute_category => NULL, /* X_attribute_category */
4214 X_attribute1 => NULL, /* X_attribute1 */
4215 X_attribute2 => NULL, /* X_attribute2 */
4216 X_attribute3 => NULL, /* X_attribute3 */
4217 X_attribute4 => NULL, /* X_attribute4 */
4218 X_attribute5 => NULL, /* X_attribute5 */
4219 X_attribute6 => NULL, /* X_attribute6 */
4220 X_attribute7 => NULL, /* X_attribute7 */
4221 X_attribute8 => NULL, /* X_attribute8 */
4222 X_attribute9 => NULL, /* X_attribute9 */
4223 X_attribute10 => NULL, /* X_attribute10 */
4224 X_error_message => St_Error_Message,
4225 X_status => St_Status
4226 );
4227 End If;
4228
4229 IF L_DEBUG = 'Y' THEN
4230 gms_error_pkg.gms_debug('After API Event->Status Code,Message:'||St_Status||','||St_Error_Message,'C');
4231 END IF;
4232 If St_Status <> 0 then
4233
4234 IF L_DEBUG = 'Y' THEN
4235 gms_error_pkg.gms_debug('!!! IN Burden EVENT - API Call Exception !!! ','C');
4236 END IF;
4237 RAISE NO_PROCESSING_OF_AWARD;
4238
4239 End If;
4240
4241 IF L_DEBUG = 'Y' THEN
4242 gms_error_pkg.gms_debug('DBP - After Event Creation','C');
4243 END IF;
4244
4245 /* ------------------------------------------------------------------------------- */
4246 -- Updating Event Attribute
4247
4248 EVENT_ATTRIBUTE_UPDATION(Evt_Num,
4249 X_Project_Id,
4250 X_Request_Id,
4251 X_Err_Code,
4252 X_Err_Buff);
4253
4254 If X_Err_Code <> 0 then
4255 Raise NO_PROCESSING_OF_AWARD ;
4256 End If;
4257
4258 IF L_DEBUG = 'Y' THEN
4259 gms_error_pkg.gms_debug('DBP - After Event Attribute Updation','C');
4260 END IF;
4261
4262 ElsIf Ins_Amount = 0 then
4263
4264 IF L_DEBUG = 'Y' THEN
4265 gms_error_pkg.gms_debug('DBP - In Ins_Amount = 0 part ...','C');
4266 END IF;
4267
4268 -- ------------------------------------------------------------------------------------
4269 -- Event num NULL change ...
4270 -- -------------------------
4271 -- If event amount = 0 , update GBC record with event_num of -2. Set package variable
4272 -- indicating that there are burden records created with event num -2. In procedure
4273 -- award_billing, there is a check for this flag. If flag is set, then procedure
4274 -- DELETE_NULL_EVENTS will be called.
4275 -- Event Number is -2 so that billing_rollback does not rollback events..
4279 -- Set package variable to TRUE, accessed in award_billing procedure..
4276 -- ------------------------------------------------------------------------------------
4277 Evt_Num := -2;
4278
4280 X_BURDEN_NULL_EVENT_PROCESSED := TRUE;
4281
4282 End If; -- DO NOT INSERT ZERO AMOUNT EVENTS
4283
4284 /* ------------------------------------------------------------------------------- */
4285 -- Updating Burden Components
4286
4287 UPDATE_GMS_BURDEN_COMPONENTS(Evt_Num ,
4288 Ins_Award_Project_Id,
4289 X_Request_Id ,
4290 Ins_Actual_Project_Id ,
4291 Ins_Actual_Task_Id ,
4292 Ins_Burden_Cost_Code ,
4293 Ins_Expenditure_Org_Id );
4294
4295 IF L_DEBUG = 'Y' THEN
4296 gms_error_pkg.gms_debug('DBP - After GBC Updation','C');
4297 END IF;
4298
4299 End LOOP;
4300
4301 IF L_DEBUG = 'Y' THEN
4302 gms_error_pkg.gms_debug('IN BURDEN EVENT - END','C');
4303 END IF;
4304
4305 Exception
4306
4307 When Others then
4308
4309 IF L_DEBUG = 'Y' THEN
4310 gms_error_pkg.gms_debug('IN BURDEN EVENT WHEN OTHERS ','C');
4311 END IF;
4312
4313 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
4314 'SQLCODE',
4315 SQLCODE,
4316 'SQLERRM',
4317 SQLERRM,
4318 X_Exec_Type => 'C',
4319 X_Err_Code => X_Err_Code,
4320 X_Err_Buff => X_Err_Buff);
4321
4322 RAISE NO_PROCESSING_OF_AWARD;
4323
4324 End DO_BURDEN_EVENT_PROCESSING;
4325 ---------------------------------------------------------------------------------------
4326
4327 ----------------------------------------------------------------------------------------
4328 --Procedure DO_REV_EVENT_PROCESSING
4329 -----------------------------------------------------------------------------------------
4330 -- Bug 3235390 : Modified the logic as mentioned below
4331 -- a. Code to create events in pa_events and gms_event_attribute table is
4332 -- shifted to CREATE_PA_EVENTS procedure.
4333 -- b. Events will be inserted into GBC and GEI and will be marked as billed/accrued.
4334 -- c. Events will be assigned a negative seqeunce number which starts from -1001
4335 -- d. Distinct events and their format will be temporarly stored in plsql table
4336 -- e. Newly introduced procedure CREATE_PA_EVENTS will fetch the consolidated
4337 -- records from the plsql table and will insert events into Pa_events and
4338 -- gms_event_attribute tables and updates GEI with newly generated event_num.
4339 -- Even the NULL events logic is shifted to create_pa_events procedure.
4340 ----------------------------------------------------------------------------------------------------
4341
4342 PROCEDURE DO_REV_EVENT_PROCESSING(X_Act_Project_Id IN NUMBER,
4343 X_Task_Id IN NUMBER,
4344 X_Expenditure_Type IN VARCHAR2,
4345 X_Expenditure_Org_Id IN NUMBER,
4346 X_Units IN VARCHAR2,
4347 X_Rev_Run_Total IN NUMBER,
4348 X_Project_Id IN NUMBER,
4349 X_Rev_Event_Amount IN NUMBER,
4350 X_Rev_Carrying_Out_Org_Id IN NUMBER,
4351 X_rev_or_bill_date IN DATE,
4352 X_calling_process IN VARCHAR2,
4353 X_Request_id IN NUMBER,
4354 C_Installment_Id IN NUMBER,
4355 X_Install_Count IN NUMBER,
4356 X_Installment_Total IN OUT NOCOPY Inst_tab2,
4357 X_Err_Code IN OUT NOCOPY NUMBER,
4358 X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
4359
4360 CURSOR GET_RAW_ROWS_FROM_INTERSECT IS
4361 SELECT 'Y'
4362 FROM gms_event_intersect gei,
4363 gms_award_distributions adl
4364 WHERE gei.award_project_id = X_Project_Id
4365 AND gei.request_id = X_Request_Id
4366 AND gei.event_type = 'REVENUE'
4367 AND gei.event_num is NULL
4368 AND adl.expenditure_item_id = gei.expenditure_item_id
4369 AND adl.adl_line_num = gei.adl_line_num
4370 AND adl.document_type ='EXP'
4371 AND adl.adl_status ='A'
4372 AND adl.project_id = X_Act_Project_Id
4373 AND adl.task_id = X_Task_Id
4374 AND ROWNUM =1 ;
4375
4376 Evt_Num NUMBER(15);
4377 Evt_Description VARCHAR2(2000);
4378 --Inst_Num VARCHAR2(15); Bug 2380344
4379 Ins_Act_Proj_Num VARCHAR2(30);
4380 Ins_Act_Task_Num VARCHAR2(30);
4381 --Ins_Exp_Org_Name VARCHAR2(60);
4382 -- The widht of the variable is changed for UTF8 changes for HRMS schema. Refer bug 2302839.
4383 Ins_Exp_Org_Name HR_ALL_ORGANIZATION_UNITS_TL.NAME%TYPE;
4384 Evt_format VARCHAR2(2000);
4385 X_event_exists VARCHAR2(1);
4386
4387 Begin
4388
4389 IF L_DEBUG = 'Y' THEN
4390 gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - START','C');
4391 END IF;
4392
4393 OPEN GET_RAW_ROWS_FROM_INTERSECT;
4397
4394 FETCH GET_RAW_ROWS_FROM_INTERSECT INTO X_event_exists;
4395
4396 IF GET_RAW_ROWS_FROM_INTERSECT%FOUND THEN
4398 /* Getting Actual Project Number, Task Number and Expenditure Organization Name */
4399 Begin
4400 Select
4401 a.segment1,
4402 b.task_number,
4403 c.name
4404 into
4405 Ins_Act_Proj_Num,
4406 Ins_Act_Task_Num,
4407 Ins_Exp_Org_Name
4408 from
4409 pa_projects_all a,
4410 pa_tasks b,
4411 hr_organization_units c
4412 where a.project_id = X_Act_Project_Id and
4413 b.task_id = X_Task_Id and
4414 c.organization_id = X_Expenditure_Org_Id;
4415 End;
4416
4417 --Concatenating Installment Number to Event Description
4418 Evt_Description := Ins_Act_Proj_Num||'- '||Ins_Act_Task_Num||' - '||X_Expenditure_Type;
4419 --Moved X_Rev_Run_Total and X_Units concatenation to PROCESS_TEMP_EVENTS procedure
4420 ---||'- '||to_char(X_Rev_Run_Total)||' '||X_Units; -- Bug 2380344 : Removed inst_num
4421 Evt_format := X_Act_Project_Id||' - '||X_Task_Id||' - '||X_Expenditure_Type||' - '||X_Expenditure_Org_Id ; -- Bug 3235390
4422
4423 IF L_DEBUG = 'Y' THEN
4424 gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - Value of Evt_Description '||Evt_Description,'C');
4425 gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - Value of Evt_format '||Evt_format,'C');
4426 END IF;
4427
4428 /*x_temp_negative_evt_num := x_temp_negative_evt_num - 1 ; Bug 3523930 - Moved this into process tempevents*/
4429 PROCESS_TEMP_EVENTS (X_Act_Project_Id,
4430 X_task_id,
4431 'Y', /* Added for bug 3523930 */
4432 Evt_format,
4433 Evt_Description,
4434 X_calling_process,
4435 X_Units,
4436 X_Rev_Run_total,
4437 X_Rev_Event_Amount,
4438 evt_num,
4439 x_err_code,
4440 x_err_buff) ;
4441
4442 IF L_DEBUG = 'Y' THEN
4443 gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of X_Err_Code '||X_Err_Code,'C');
4444 gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of x_err_buff '||x_err_buff,'C');
4445 END IF;
4446
4447 IF X_Err_Code <> 0 then
4448 Raise NO_PROCESSING_OF_AWARD ;
4449 END IF;
4450
4451
4452 UPDATE_GMS_EVENT_INTERSECT(Evt_Num,
4453 X_Project_Id,
4454 X_Request_Id,
4455 X_Act_Project_Id,
4456 X_Task_Id );
4457
4458 IF L_DEBUG = 'Y' THEN
4459 gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - After UPDATE_GMS_EVENT_INTERSECT','C');
4460 gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - END','C');
4461 END IF;
4462
4463 END IF;
4464 CLOSE GET_RAW_ROWS_FROM_INTERSECT;
4465
4466 End DO_REV_EVENT_PROCESSING;
4467
4468 -------------------------------------------------------------------------------------------
4469 --Procedure GET_BURDEN_COMPONENT_DATA returns the burden_components and the burden amounts
4470 -------------------------------------------------------------------------------------------
4471 PROCEDURE GET_BURDEN_COMPONENT_DATA(P_project_id IN NUMBER,
4472 P_task_id IN NUMBER,
4473 P_expenditure_org_id IN NUMBER,
4474 P_ind_compiled_set_id IN NUMBER,
4475 P_burdenable_raw_cost IN NUMBER,
4476 P_expenditure_type IN VARCHAR2,
4477 P_Burden_Components_Count OUT NOCOPY NUMBER,
4478 P_Burden_Component_Data OUT NOCOPY Burden_Component_Tab_Type )IS
4479
4480 CURSOR Get_Components_Cursor IS
4481 SELECT cm.ind_cost_code,
4482 icc.expenditure_type icc_expenditure_type,
4483 sum(pa_currency.round_currency_amt (P_burdenable_raw_cost * cm.compiled_multiplier)) Tot_Exp_Item_Burden_Cost
4484 FROM pa_ind_cost_codes icc,
4485 pa_compiled_multipliers cm,
4486 --pa_ind_compiled_sets ics, /* For bug 6969435 */
4487 pa_cost_base_exp_types cbet,
4488 PA_COST_BASE_COST_CODES CBCC /* For bug 6969435 */
4489 --pa_cost_bases cb,/* For bug 6969435 */
4490 --pa_ind_rate_sch_revisions irsr,/* For bug 6969435 */
4491 --pa_ind_rate_schedules_all_bg irs/* For bug 6969435 */
4492 WHERE --ics.ind_rate_sch_revision_id = irsr.ind_rate_sch_revision_id/* For bug 6969435 */
4493 --AND irs.ind_rate_sch_id = irsr.ind_rate_sch_id/* For bug 6969435 */
4494 --AND irsr.cost_plus_structure = cbet.cost_plus_structure/* For bug 6969435 */
4495 cbet.cost_base = cm.cost_base
4496 --AND cb.cost_base = cbet.cost_base/* For bug 6969435 */
4497 --AND ics.cost_base = cbet.cost_base/* For bug 6969435 */
4498 --AND cb.cost_base_type = cbet.cost_base_type/* For bug 6969435 */
4499 AND cbet.cost_base_type = 'INDIRECT COST'
4500 AND cbet.expenditure_type = P_expenditure_type
4501 --AND ics.organization_id = P_expenditure_org_id/* For bug 6969435 */
4502 --AND ics.ind_compiled_set_id = cm.ind_compiled_set_id/* For bug 6969435 */
4503 AND icc.ind_cost_code = cm.ind_cost_code
4507 AND cbcc.cost_base_type = cbet.cost_base_type /* For bug 6969435 */
4504 AND cm.ind_compiled_set_id = P_ind_compiled_set_id /* For bug 6969435 */
4505 AND cbcc.cost_plus_structure = cbet.cost_plus_structure /* For bug 6969435 */
4506 AND cbcc.cost_base = cbet.cost_base /* For bug 6969435 */
4508 AND cm.cost_base_cost_code_Id = cbcc.cost_base_cost_code_Id /* For bug 6969435 */
4509 AND cm.ind_cost_code = cbcc.ind_cost_code /* For bug 6969435 */
4510 and cm.compiled_multiplier <> 0
4511 group by cm.ind_cost_code, icc.expenditure_type;
4512
4513 St_Burden_Components_Count NUMBER := 0;
4514
4515 Begin
4516
4517 FOR Get_Components_Record IN Get_Components_Cursor
4518 LOOP
4519 -- commenting this out so that datafixes will work ...differential billing ..
4520 --If Get_Components_Record.Tot_Exp_Item_Burden_Cost <> 0 then
4521 St_Burden_Components_Count := St_Burden_Components_Count + 1;
4522 P_Burden_Component_Data(St_Burden_Components_Count).Actual_Project_Id := P_Project_Id;
4523 P_Burden_Component_Data(St_Burden_Components_Count).Actual_Task_Id := P_Task_Id;
4524 P_Burden_Component_Data(St_Burden_Components_Count).Expenditure_Org_Id := P_expenditure_org_id;
4525 P_Burden_Component_Data(St_Burden_Components_Count).Burden_Expenditure_Type := Get_Components_Record.Icc_Expenditure_Type;
4526 P_Burden_Component_Data(St_Burden_Components_Count).Burden_Cost_Code := Get_Components_Record.Ind_Cost_Code;
4527 P_Burden_Component_Data(St_Burden_Components_Count).Burden_Cost := Get_Components_Record.Tot_Exp_Item_Burden_Cost;
4528 --End If;
4529 END LOOP;
4530
4531 P_Burden_Components_Count := St_Burden_Components_Count;
4532
4533 End GET_BURDEN_COMPONENT_DATA;
4534 -----------------------------------------------------------------------------------------
4535 -- Procedure FORMAT_SPECIFIC_BILLING: This procedure is the core of the billing extension. It
4536 -- builds the select statement given the Invoice Format Details, execution of which then processes
4537 -- all the expenditure items which meet the selection criteria. This procedure is executed once for
4538 -- each installment within the Award being processed. The expenditure items picked up have to have
4539 -- an expenditure item date which falls within the start and end date of the installment. This procedure
4540 -- also checks to see that the amount on the expenditure items doesnot exceed the amount left on the
4541 -- installment that can be billed.
4542 -----------------------------------------------------------------------------------------
4543 PROCEDURE FORMAT_SPECIFIC_BILLING(X_Project_Id IN NUMBER,
4544 X_Award_Id IN NUMBER,
4545 X_Class_Category IN VARCHAR2,
4546 X_rev_or_bill_date IN DATE,
4547 --X_Revenue_Limit_Flag IN VARCHAR2,
4548 X_Invoice_Limit_Flag IN VARCHAR2, /*Bug 6642901*/
4549 X_Request_Id IN NUMBER,
4550 X_Sel_Grp_Diff_Array IN Mark_Sel_Grp_Diff_Array,
4551 X_Cnt_Of_Columns_Selected IN NUMBER,
4552 X_Rt_Jstfy_Flag_Array IN Mark_Sel_Grp_Diff_Array,
4553 X_Padding_Length_Array IN Padding_Length_Array,
4554 X_Text_Array IN Free_Text_Array,
4555 X_sql_select IN VARCHAR2,
4556 X_Carrying_Out_Org_Id IN NUMBER,
4557 X_calling_process IN VARCHAR2,
4558 X_invfmt_incl_task IN VARCHAR2, /* Added for bug 3523930 */
4559 C_Installment_Id IN NUMBER,
4560 C_Start_Date_Active IN DATE,
4561 C_End_Date_Active IN DATE,
4562 X_Err_Num OUT NOCOPY NUMBER,
4563 X_Err_Stage OUT NOCOPY VARCHAR2,
4564 g_mode IN VARCHAR2, /* added for bug 5026657 */
4565 g_labor_exp_to_process OUT NOCOPY VARCHAR2, /* added for bug 5026657 */
4566 g_non_labor_neg_exp_processed OUT NOCOPY VARCHAR2 /* added for bug 5026657 */
4567 ) IS
4568 X_Run_Total Running_Total_Array;
4569 X_Old_Values Selected_Values_Rows;
4570 X_New_Values Selected_Values_Rows;
4571
4572 cur_select INTEGER := 0;
4573 X_Rows_Processed INTEGER := 0;
4574 X_Expenditure_Item_Id PA_EXPENDITURE_ITEMS_ALL.EXPENDITURE_ITEM_ID%TYPE;
4575 X_Expenditure_Item_Date PA_EXPENDITURE_ITEMS_ALL.EXPENDITURE_ITEM_DATE%TYPE;
4576 X_Task_Id PA_EXPENDITURE_ITEMS_ALL.TASK_ID%TYPE;
4577 X_Bill_Hold_Flag PA_EXPENDITURE_ITEMS_ALL.BILL_HOLD_FLAG%TYPE; --VARCHAR2(1);
4578 X_Billable_Flag PA_EXPENDITURE_ITEMS_ALL.BILLABLE_FLAG%TYPE; --VARCHAR2(1);
4579 X_Adjusted_Expenditure_Item_Id PA_EXPENDITURE_ITEMS_ALL.ADJUSTED_EXPENDITURE_ITEM_ID%TYPE;
4580 X_First_Indicator BOOLEAN := TRUE;
4581
4582 -- 11.5 Changes Start
4583 X_Adl_Line_Num gms_award_distributions.adl_line_num%type;
4584 X_Cdl_Line_Num gms_award_distributions.cdl_line_num%type; --bug 2909746
4585 X_Parent_Adl_Line_Num gms_award_distributions.parent_adl_line_num%type;
4586 X_Adl_Status gms_award_distributions.adl_status%type;
4587 X_Bill_Award_Id gms_award_distributions.award_id%type;
4588 St_Err_Code NUMBER(1);
4589 St_Err_Buff Varchar2(2000);
4590 X_Installment_Status Varchar2(1) :=null;
4594
4591 X_Count Number :=0;
4592 X_Money_On_Curr_Inst number(22,5);
4593 -- 11.5 Changes End
4595 X_Money_Left_In_Inst NUMBER(22,5) := 0; -- Amount left in Installment that can be billed
4596 X_Total_Funding_Amount NUMBER(22,5) := 0; -- Total Funding by Installment,Task for a particular Project
4597 X_Total_Rev_Bill_Amount NUMBER(22,5) := 0; -- Total Revenue or Billed Amount(Depending on the Calling Process)
4598 -- by Installment, Task for a particular Project
4599 X_Raw_Cost PA_EXPENDITURE_ITEMS_ALL.RAW_COST%TYPE; -- Amount on the Current Transaction being Processed
4600 X_Amount_In_Intersect NUMBER(22,5) := 0; -- Sum of Amounts in Intersect table for current Trx being processed
4601 X_Amount_To_Insert NUMBER(22,5) := 0; -- Amount to be Inserted into Intersect Table,(X_Raw_Cost - X_Amount_In_Intersect)
4602 X_Event_Amount NUMBER(22,5) := 0; -- Running total for the Amount for which Event is to be created
4603 C_Inst_Task_Run_Total NUMBER(22,5):= 0; -- Running Total for the amount that will be billed on this Installment.
4604 -- Adds the amount on the Trx being processed to current total. When processing is done for
4605 -- this Installment, this amount will be added to the existing billed amount on Installment
4606 -- and Installment updated with the total amount.
4607 X_Amount_To_Accrue_Bill_Insert NUMBER;
4608
4609 X_Err_Nbr NUMBER(15) := NULL;
4610 X_Err_Stg VARCHAR2(200) := NULL;
4611
4612 X_Lock_Exp_Id VARCHAR2(30);
4613
4614 X_Adl_Lock_Exp_Id gms_award_distributions.expenditure_item_id%type; -- 11.5 change
4615
4616 X_Orig_Item_Billed_Flag VARCHAR2(2);
4617 X_Actual_project_id NUMBER(15);
4618 X_Adl_Orig_Item_Billed_Flag VARCHAR2(1); -- 11.5 change
4619
4620 X_Burden_Component_Data Burden_Component_Tab_Type;
4621 X_Burden_Components_Count NUMBER := 0;
4622 X_Amt_In_Tmp_By_Component NUMBER := 0;
4623 X_Tot_Burd_Amt_In_Tmp NUMBER := 0;
4624 X_Tot_Burden_Amt_In_View NUMBER := 0;
4625 X_Burd_Amt_To_Insert_By_Comp NUMBER := 0;
4626 X_Tot_Burd_Amt_To_Insert NUMBER := 0;
4627
4628 /* bug 5242484 start */
4629 X_old_expenditure_item_id NUMBER(15) := -9999 ;
4630 X_event_rollback_amount NUMBER(22,5) := 0;
4631 k NUMBER := 0;
4632 /* bug 5242484 end */
4633
4634 /* Bug 3523930 Start*/
4635 X_old_task_id pa_expenditure_items_all.task_id%type;
4636 X_new_task_id pa_expenditure_items_all.task_id%type;
4637 X_old_actprj_id pa_expenditure_items_all.project_id%type;
4638 X_new_actprj_id pa_expenditure_items_all.project_id%type;
4639 /* Bug 3523930 End*/
4640 ss_text VARCHAR2(300);
4641 RESOURCE_BUSY EXCEPTION;
4642 PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -00054);
4643
4644 -- Bug 3630577 : performance fix ..
4645 X_expenditure_type pa_expenditure_items_all.expenditure_type%type;
4646 X_expenditure_org_id pa_expenditure_items_all.override_to_organization_id%type;
4647 X_ind_compiled_set_id pa_cost_distribution_lines_all.ind_compiled_set_id%type;
4648 X_burdenable_raw_cost gms_award_distributions.burdenable_raw_cost%type;
4649 X_transaction_source pa_transaction_sources.transaction_source%type;
4650
4651 Begin
4652
4653 /* To set project_id NULL to be able to use Suresh's view to derive Burden Components and Burden Cost */
4654 -- GMS_BURDEN_COSTING.SET_CURRENT_PROJECT_ID(NULL);
4655 -- The above line has been commented out NOCOPY for bug 2442827
4656
4657 /* bug 5026657 */
4658 g_labor_exp_to_process := 'N';
4659 g_non_labor_neg_exp_processed := 'N';
4660
4661 -- dbms_output.put_line(X_sql_select);
4662 cur_select := DBMS_SQL.OPEN_CURSOR;
4663 -----------------------------------------------------------
4664 -- Initializing Old Values Table and New Values Table
4665 For i in 1..X_Cnt_Of_Columns_Selected LOOP
4666 X_Old_Values(i) := NULL;
4667 X_New_Values(i) := NULL;
4668 X_Run_Total(i) := 0;
4669 END LOOP;
4670 /* Bug 3523930 Start -Initializing the Project and task values too*/
4671 X_old_task_id := NULL;
4672 X_new_task_id :=NULL;
4673 X_old_actprj_id :=NULL;
4674 X_new_actprj_id :=NULL;
4675 /* Bug 3523930 End*/
4676 ------------------------------------------------------------
4677 --------------------------------------------------------------------
4678 -- Parsing the Select statement and defining Bind Variable for the --
4679 -- Input parameter Project Id --
4680 DBMS_SQL.PARSE(cur_select,X_sql_select,dbms_sql.native);
4681 --dbms_output.put_line('After Parse');
4682 DBMS_SQL.BIND_VARIABLE(cur_select,':X_Award_Id', X_Award_Id);
4683 DBMS_SQL.BIND_VARIABLE(cur_select,':X_rev_or_bill_date',X_rev_or_bill_date);
4684 -- DBMS_SQL.BIND_VARIABLE(cur_select,':C_Start_Date_Active',C_Start_Date_Active);
4685 DBMS_SQL.BIND_VARIABLE(cur_select,':C_End_Date_Active',C_End_Date_Active);
4686 --dbms_output.put_line('After Bind');
4687 DBMS_SQL.BIND_VARIABLE(cur_select,':C_Installment_id',C_Installment_id);
4688 ---------------------------------------------------------------------
4689 ----------------------------------------------------------
4690 -- Defining Fetch Variables for all the Columns Fetched --
4691 For i in 1..X_Cnt_Of_Columns_Selected LOOP
4692 DBMS_SQL.DEFINE_COLUMN(cur_select,i, X_Old_Values(i),1000);
4693 END LOOP;
4694 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 1, X_Raw_Cost);
4695 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 2, X_Expenditure_Item_Id);
4699 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 6, X_Billable_Flag,1);
4696 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 3, X_Expenditure_Item_Date);
4697 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 4, X_Task_Id);
4698 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 5, X_Bill_Hold_Flag,1);
4700 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 7, X_Adjusted_Expenditure_Item_Id);
4701
4702 -- 11.5 Changes Start
4703 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 8, X_Adl_Line_Num);
4704 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 9, X_Parent_Adl_Line_Num);
4705 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 10, X_Adl_Status,1);
4706 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 11, X_Bill_Award_Id);
4707 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 12, X_Actual_Project_Id);
4708 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 13, X_Cdl_Line_Num); --bug 2909746
4709 -- 11.5 Changes End
4710 -- Bug 3630577 : performance fix ..
4711 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 14, X_expenditure_type,30);
4712 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 15, X_expenditure_org_id);
4713 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 16, X_ind_compiled_set_id);
4714 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 17, X_burdenable_raw_cost);
4715 DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 18, X_transaction_source,30);
4716
4717 ----------------------------------------------------------------
4718 ----------------------------------------------------
4719 -- Executing the Cursor cur_select --
4720 X_Rows_Processed := DBMS_SQL.EXECUTE(cur_select);
4721 ----------------------------------------------------
4722 --------------------------------------------------------------------
4723 -- Beginning Loop to process rows returned from Cursor cur_select for current Installment --
4724 LOOP
4725
4726 BEGIN
4727
4728 SAVEPOINT EXPENDITURE_ITEM_PROCESSING;
4729
4730 --dbms_output.put_line('In Loop');
4731
4732 /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
4733
4734 If DBMS_SQL.FETCH_ROWS(cur_select) > 0 then --Start of 'Cursor_Rows_Check_If'
4735
4736 /* Initializing the X_Burden_Component_Data table */
4737 X_Burden_Component_Data.DELETE;
4738
4739 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 1, X_Raw_Cost);
4740 --dbms_output.put_line('Raw Cost '||to_char(X_Raw_Cost));
4741 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 2, X_Expenditure_Item_Id);
4742 --dbms_output.put_line('Exp Item Id '||to_char(X_Expenditure_Item_Id));
4743 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 3, X_Expenditure_Item_Date);
4744 --dbms_output.put_line('Exp Item Date '||to_char(X_Expenditure_Item_Date));
4745 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 4, X_Task_Id);
4746 --dbms_output.put_line('Task Id'||to_char(X_Task_Id));
4747 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 5, X_Bill_Hold_Flag);
4748 --dbms_output.put_line('Bill Hold Flag'||X_Bill_Hold_Flag);
4749 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 6, X_Billable_Flag);
4750
4751 --dbms_output.put_line('Billable Flag '||X_Billable_Flag);
4752 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 7, X_Adjusted_Expenditure_Item_Id);
4753 --dbms_output.put_line('Adjusted Expenditure Item Id '||X_Adjusted_Expenditure_Item_Id);
4754
4755 --11.5 Changes Start
4756
4757 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 8, X_Adl_Line_Num);
4758 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 9, X_Parent_Adl_Line_Num);
4759 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 10,X_Adl_Status);
4760 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 11,X_Bill_Award_Id);
4761 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 12,X_Actual_Project_Id);
4762 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 13,X_Cdl_Line_Num); --bug 2909746
4763
4764 --11.5 Changes End
4765 -- Bug 3630577 : performance fix ..
4766 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 14,X_expenditure_type);
4767 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 15,X_expenditure_org_id);
4768 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 16,X_ind_compiled_set_id);
4769 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 17,X_burdenable_raw_cost);
4770 DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 18,X_transaction_source);
4771
4772 IF L_DEBUG = 'Y' THEN
4773 gms_error_pkg.gms_debug('Expenditure Item Id :'||X_Expenditure_Item_Id,'C');
4774 gms_error_pkg.gms_debug('X_Adl_Line_Num:'||X_Adl_Line_Num,'C');
4775 gms_error_pkg.gms_debug('X_Cdl_Line_Num:'||X_Cdl_Line_Num,'C'); --bug 2909746
4776 gms_error_pkg.gms_debug('X_Expenditure_Item_Date:'||X_Expenditure_Item_Date,'C');
4777 gms_error_pkg.gms_debug('X_Raw_Cost:'||X_Raw_Cost,'C');
4778 gms_error_pkg.gms_debug('X_Bill_Hold_Flag:'||X_Bill_Hold_Flag,'C');
4779 END IF;
4780
4781 -- Lock the Expenditure Item
4782 select expenditure_item_id
4783 into
4784 X_Lock_Exp_Id
4785 from
4786 pa_expenditure_items_all
4787 where
4788 expenditure_item_id = X_Expenditure_Item_Id
4792
4789 FOR UPDATE NOWAIT;
4790
4791 -- 11.5 Change, Lock Adl Expenditure Item too
4793 select expenditure_item_id
4794 into
4795 X_Adl_Lock_Exp_Id
4796 from
4797 gms_award_distributions
4798 where expenditure_item_id = X_Expenditure_Item_Id
4799 and adl_line_num=X_Adl_Line_Num
4800 and document_type='EXP'
4801 and adl_status = 'A'
4802 FOR UPDATE NOWAIT;
4803
4804 /* This is to see that the Adjusting Expenditure Item is picked up first for Billing */
4805 -- 11.5 change, pick billed_flag from adl table and award_id required in where clause
4806 --Bug 3235390 commented out
4807 /*
4808 If X_Adjusted_Expenditure_Item_Id IS NOT NULL then
4809 Begin
4810 Select
4811 nvl(adl.billed_flag,'N')
4812 into
4813 X_Orig_Item_Billed_Flag
4814 from
4815 gms_award_distributions adl
4816 where
4817 expenditure_item_id = X_Adjusted_Expenditure_Item_Id
4818 and
4819 award_id = X_Bill_award_id
4820 and
4821 adl_status='A'
4822 and
4823 document_type ='EXP'
4824 and
4825 adl_line_num =
4826 (select max(adl_line_num)
4827 from gms_award_distributions
4828 where expenditure_item_id = X_Adjusted_Expenditure_Item_Id
4829 and award_id = X_Bill_award_id
4830 and adl_status='A'
4831 and document_type ='EXP');
4832 End;
4833
4834 End If; */ --Bug 3235390
4835
4836 -----------------------------------------------------------------------------------------------------
4837 /*Resetting Burden Totals from View and Tmp table to zero for every Exp Item being processed */
4838 X_Tot_Burd_Amt_In_Tmp := 0;
4839 X_Tot_Burden_Amt_In_View := 0;
4840 X_Tot_Burd_Amt_To_Insert := 0;
4841 X_UPD_BILLING_FLAG := FALSE; -- Bug 3254097 : Intializing the flag
4842
4843 ----------------------------------------------------------------------------------------------------
4844
4845
4846 /* If (X_Adjusted_Expenditure_Item_Id IS NOT NULL and X_Orig_Item_Billed_Flag <> 'Y' ) then
4847
4848 GOTO DO_NOT_PROCESS; DO NOT GO ANY FURTHER WITH PROCESSING OF THIS ITEM
4849
4850 End If; */ --Bug 3235390: Commented out
4851
4852 --------------------------------------------------------------------
4853 -- Rounding fix : Bug 1417062
4854
4855 X_Raw_Cost := pa_currency.round_currency_amt(nvl(X_Raw_Cost,0));
4856
4857 -----------------------------------------------------------------------------
4858 /* For the particular Installment,Task get Total Billed Amount and Total Funding Amount */
4859 GET_SUMM_FUNDING(NULL, -- C_Installment_Id, Made Null for 11.5
4860 X_Expenditure_Item_Date,
4861 X_Award_Id,
4862 X_Task_Id,
4863 X_calling_process,
4864 X_Total_Funding_Amount,
4865 X_Total_Rev_Bill_Amount,
4866 St_Err_Code,
4867 St_Err_Buff);
4868
4869 If St_Err_Code <> 0 then
4870 --ROLLBACK;
4871 --RAISE FND_API.G_EXC_ERROR;
4872 Raise NO_PROCESSING_OF_AWARD ;
4873 End If;
4874 -----------------------------------------------------------------------------
4875 X_Money_Left_In_Inst := (X_Total_Funding_Amount - X_Total_Rev_Bill_Amount);
4876 ----------------------------------------------------------------------------------------------------------------
4877 --dbms_output.put_line('Money Left in Installment = '||to_char(X_Money_Left_In_Inst));
4878 ------------------------------------------------------------------------------
4879
4880 -- Bug 2441525 : if the raw cost is greater than the funding left then there is no need for deriving burden.
4881
4882 --IF NVL(X_Raw_Cost,0) > NVL(X_Money_Left_In_Inst,0) AND X_Revenue_Limit_Flag = 'Y' THEN -- hard limit
4883 -- GOTO DO_NOT_PROCESS; /* Do not go any further with processing of this item */
4884 --END IF;
4885 -- Above code commented for bug 4289410
4886
4887
4888 X_Installment_Status := null; -- Initialize
4889
4890 /* Installment Check */
4891
4892 INSTALLMENT_CHECK(C_Installment_Id,
4893 X_Award_Id,
4894 X_Task_Id,
4895 X_Calling_Process,
4896 X_Expenditure_Item_Date,
4897 X_Money_Left_In_Inst,
4898 X_Money_On_Curr_Inst,
4899 X_Installment_Status,
4900 St_Err_Code,
4901 St_Err_Buff);
4902
4903 If St_Err_Code <> 0 then
4904 --ROLLBACK;
4905 --RAISE FND_API.G_EXC_ERROR;
4906 Raise NO_PROCESSING_OF_AWARD ;
4907 End If;
4908
4909 IF L_DEBUG = 'Y' THEN
4910 gms_error_pkg.gms_debug('After INSTALLMENT_CHECK X_error_code:'||St_Err_Code,'C');
4911 END IF;
4912
4913 /* Commented IF for bug 5349106 */
4914 -- If X_Installment_Status ='I' then
4915 -- GOTO DO_NOT_PROCESS; /* Do not go any further with processing of this item */
4916 -- End if;
4917
4918 /* Getting the Burden Components and Burden Amount from View for each Raw Expenditure Item in an array form */
4919
4920 X_Burden_Components_Count := 0;
4921
4922
4923 If (nvl(x_burdenable_raw_cost,0) <> 0 and x_ind_compiled_set_id is not null) then
4927 X_Expenditure_Org_Id,
4924 If allow_burden(x_transaction_source) then
4925 GET_BURDEN_COMPONENT_DATA(X_Actual_Project_Id,
4926 X_Task_Id,
4928 X_ind_compiled_set_id,
4929 X_burdenable_raw_cost,
4930 X_Expenditure_Type,
4931 X_Burden_Components_Count,
4932 X_Burden_Component_Data);
4933 End If; --If allow_burden(x_transaction_source) then
4934 End If;
4935 -----------------------------------------------------------------------------
4936 IF L_DEBUG = 'Y' THEN
4937 gms_error_pkg.gms_debug('X_Burden_Components_Count:'||X_Burden_Components_Count,'C');
4938 END IF;
4939 -----------------------------------------------------------------------------
4940 /* For each Trx fetched Get total Raw Amount for the Trx already existing in Intersect table */
4941 GET_AMOUNT_IN_INTERSECT(X_Expenditure_Item_Id,
4942 X_Adl_Line_Num,
4943 X_Calling_Process,
4944 X_Amount_In_Intersect
4945 );
4946 --dbms_output.put_line('Amount in intersect = '||to_char(X_Amount_In_Intersect));
4947 -----------------------------------------------------------------------------
4948
4949 --For i in 1..X_Burden_Components_Count LOOP
4950 --dbms_output.put_line('Data '||X_Burden_Component_Data(i).Burden_Cost_Code);
4951 -- null;
4952 --End LOOP;
4953
4954 For i in 1..X_Burden_Components_Count LOOP
4955 GET_BURD_AMT_IN_INTERSECT(X_Expenditure_Item_Id ,
4956 X_Adl_Line_Num,
4957 X_Calling_Process ,
4958 X_Burden_Component_Data(i).Burden_Cost_Code ,
4959 X_Amt_In_Tmp_By_Component );
4960 X_Tot_Burd_Amt_In_Tmp := X_Tot_Burd_Amt_In_Tmp + X_Amt_In_Tmp_By_Component;
4961 End LOOP;
4962 --dbms_output.put_line('Burden Amt in Temp table = '||to_char(X_Tot_Burd_Amt_In_Tmp));
4963 ------------------------------------------------------------------------------
4964
4965 For i in 1..X_Burden_Components_Count LOOP
4966
4967 X_Tot_Burden_Amt_In_View := X_Tot_Burden_Amt_In_View
4968 + X_Burden_Component_Data(i).Burden_Cost;
4969 End LOOP;
4970
4971 /* Check if the current transaction amount takes it over the Money Left In Installment. If it does, donot do any */
4972 /* further processing on it . If not, then do the checking for Invoice Formats */
4973
4974 /*IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
4975
4976 /* For bug 5026657 */
4977 /* Commented revenue limit flag and added condition for invoice limit flag for bug 6642901*/
4978 IF ( /*(X_Revenue_Limit_Flag = 'Y')*/ (X_Invoice_Limit_Flag = 'Y') AND
4979 (g_mode = 'LABOR') AND
4980 ( (X_Raw_Cost + X_Tot_Burden_Amt_In_View) - (X_Amount_In_Intersect + X_Tot_Burd_Amt_In_Tmp)
4981 > (X_Money_Left_In_Inst - C_Inst_Task_Run_Total) ) ) THEN
4982 g_labor_exp_to_process := 'Y' ;
4983
4984 END IF;
4985
4986 IF L_DEBUG = 'Y' THEN
4987 gms_error_pkg.gms_debug('X_Tot_Burden_Amt_In_View '||X_Tot_Burden_Amt_In_View,'C');
4988 gms_error_pkg.gms_debug('X_Raw_Cost '||X_Raw_Cost,'C');
4989 gms_error_pkg.gms_debug('X_Amount_In_Intersect '||X_Amount_In_Intersect,'C');
4990 gms_error_pkg.gms_debug('X_Tot_Burd_Amt_In_Tmp '||X_Tot_Burd_Amt_In_Tmp,'C');
4991 gms_error_pkg.gms_debug('X_Money_Left_In_Inst '||X_Money_Left_In_Inst,'C');
4992 gms_error_pkg.gms_debug('C_Inst_Task_Run_Total '||C_Inst_Task_Run_Total,'C');
4993 gms_error_pkg.gms_debug('g_labor_exp_to_process '||g_labor_exp_to_process,'C');
4994 -- gms_error_pkg.gms_debug('X_Revenue_Limit_Flag '||X_Revenue_Limit_Flag,'C'); commented and added below line for the bug 6642901
4995 gms_error_pkg.gms_debug('X_Invoice_Limit_Flag '||X_Invoice_Limit_Flag,'C');
4996 gms_error_pkg.gms_debug('g_mode '||g_mode,'C');
4997 END IF;
4998
4999 IF ( (
5000 ((X_Raw_Cost + X_Tot_Burden_Amt_In_View) - (X_Amount_In_Intersect + X_Tot_Burd_Amt_In_Tmp)
5001 <= (X_Money_Left_In_Inst - C_Inst_Task_Run_Total)) AND
5002 (X_Total_Funding_Amount <> -99 and X_Total_Rev_Bill_Amount <> -99) AND
5003 -- (X_Revenue_Limit_Flag = 'Y')
5004 (X_Invoice_Limit_Flag = 'Y')
5005 )
5006 OR
5007 /*(X_Revenue_Limit_Flag = 'N')*/ (X_Invoice_Limit_Flag = 'N')) then --IIIII
5008
5009
5010 GET_ACCRUE_BILL_OR_INSERT_AMT(X_Expenditure_Item_Id,
5011 X_Adl_Line_Num,
5012 X_Calling_Process,
5013 X_Raw_Cost,
5014 X_Billable_Flag,
5015 X_Bill_Hold_Flag,
5016 X_Amount_To_Accrue_Bill_Insert,
5017 X_Err_Num,
5018 X_Err_Stage);
5019
5020 For i in 1..X_Burden_Components_Count LOOP
5021 GET_BURDEN_AMT_TO_INSERT(X_Expenditure_Item_Id,
5022 X_Adl_Line_Num,
5023 X_Calling_Process,
5024 X_Burden_Component_Data(i).Burden_Cost_Code,
5025 X_Billable_Flag,
5026 X_Bill_Hold_Flag,
5030 -- Rounding fix : Bug 1417062
5027 X_Burden_Component_Data(i).Burden_Cost,
5028 X_Burd_Amt_To_Insert_By_Comp);
5029
5031 X_Burd_Amt_To_Insert_By_Comp := pa_currency.round_currency_amt(nvl(X_Burd_Amt_To_Insert_By_Comp,0));
5032
5033
5034 INSERT_GMS_BURDEN_COMPONENTS(X_Project_Id,
5035 X_Expenditure_Item_Id,
5036 X_Adl_Line_Num,
5037 X_Request_Id,
5038 X_Calling_Process,
5039 X_Burden_Component_Data(i).Actual_Project_Id,
5040 X_Burden_Component_Data(i).Actual_Task_Id,
5041 X_Burden_Component_Data(i).Burden_Expenditure_Type,
5042 X_Burden_Component_Data(i).Burden_Cost_Code,
5043 X_Burden_Component_Data(i).Expenditure_Org_Id,
5044 X_Burd_Amt_To_Insert_By_Comp,
5045 X_Err_Num,
5046 X_Err_Stage);
5047
5048 X_Tot_Burd_Amt_To_Insert := X_Tot_Burd_Amt_To_Insert + X_Burd_Amt_To_Insert_By_Comp;
5049
5050 End LOOP;
5051
5052 C_Inst_Task_Run_Total := nvl(C_Inst_Task_Run_Total,0) + (nvl(X_Amount_To_Accrue_Bill_Insert,0) + nvl(X_Tot_Burd_Amt_To_Insert,0));
5053
5054 /* For bug 5026657 */
5055
5056 /* Commented revenue limit flag and added condition for invoice limit flag for bug 6642901*/
5057 IF ( /*(X_Revenue_Limit_Flag = 'Y')*/ (X_Invoice_Limit_Flag = 'Y') AND
5058 (g_mode = 'NON LABOR') AND
5059 (nvl(X_Amount_To_Accrue_Bill_Insert,0) + nvl(X_Tot_Burd_Amt_To_Insert,0)) < 0 ) THEN
5060
5061 g_non_labor_neg_exp_processed := 'Y' ;
5062
5063 END IF;
5064
5065 -- GET_INSTALLMENT_NUM, to get installment numbers in case of amounts across installments
5066
5067 GET_INSTALLMENT_NUM(C_Installment_id,
5068 X_Award_Id,
5069 X_Task_Id,
5070 X_Expenditure_item_date,
5071 X_Calling_Process,
5072 X_Money_On_Curr_Inst,
5073 C_Inst_Task_Run_Total,
5074 X_Installment_Status,
5075 X_Installment_tab,
5076 X_Count,
5077 St_Err_Code,
5078 St_Err_Buff);
5079
5080
5081 If St_Err_Code <> 0 then
5082 Raise NO_PROCESSING_OF_AWARD ;
5083 End If;
5084
5085 IF L_DEBUG = 'Y' THEN
5086 gms_error_pkg.gms_debug('After GET_INSTALLMENT_NUM X_error_code:'||St_Err_Code,'C');
5087 END IF;
5088
5089 /* bug 5242484 - start */
5090 IF ( X_old_expenditure_item_id = X_expenditure_item_id ) THEN
5091 IF ( X_Count = 1) THEN
5092 X_ei_rollback_inst_tab(1).rev_bill_amount := X_ei_rollback_inst_tab(1).rev_bill_amount + C_Inst_Task_Run_Total;
5093 ELSE
5094 FOR k in 1..X_Count LOOP
5095 X_ei_rollback_inst_tab(k).rev_bill_amount := X_ei_rollback_inst_tab(k).rev_bill_amount + X_Installment_tab(k).rev_bill_amount;
5096 END LOOP;
5097 END IF;
5098 ELSE
5099 IF ( X_Count = 1) THEN
5100 X_ei_rollback_inst_tab(1).rev_bill_amount := C_Inst_Task_Run_Total;
5101 X_ei_rollback_inst_tab(1).installment_id := C_Installment_id;
5102
5103 ELSE
5104 FOR k in 1..X_Count LOOP
5105 X_ei_rollback_inst_tab(k).rev_bill_amount := X_Installment_tab(k).rev_bill_amount ;
5106 X_ei_rollback_inst_tab(k).installment_id := X_Installment_tab(k).installment_id;
5107 END LOOP;
5108 END IF;
5109
5110 END IF;
5111 /* bug 5242484 - end */
5112
5113 --Updating GMS_SUMMARY_PROJECT_FUNDINGS Billed Amount with the Amount of the current transaction
5114
5115 UPD_GSPF_WRAPPER(C_Installment_Id,
5116 X_Task_Id,
5117 X_Actual_Project_Id,
5118 X_Calling_Process,
5119 C_Inst_Task_Run_Total,
5120 X_Count,
5121 X_Installment_tab,
5122 X_Installment_total,
5123 St_Err_Code,
5124 St_Err_Buff);
5125
5126 If St_Err_Code <> 0 then
5127 Raise NO_PROCESSING_OF_AWARD ;
5128 End If;
5129
5130 IF L_DEBUG = 'Y' THEN
5131 gms_error_pkg.gms_debug('After UPD_GSPF_WRAPPER X_error_code:'||St_Err_Code,'C');
5132 END IF;
5133
5134 -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG at the end of the process
5135
5136 --Resetting the Inst_Task_Bill_Amount Running Total to Zero for Next transaction
5137 C_Inst_Task_Run_Total := 0;
5138
5139 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
5140
5141 If X_First_Indicator then --Begin of 1st If for 'First_Row_Indicator' (First Row values go into Old Table)
5142 -- for Invoice Format Checking
5143
5144 -- Copy Values from Cursor into Old_Values Table --
5145 --dbms_output.put_line('In First Indicator True Check');
5146 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5147 DBMS_SQL.COLUMN_VALUE(cur_select,i,X_Old_Values(i));
5148 IF L_DEBUG = 'Y' THEN
5149 gms_error_pkg.gms_debug('In First Indicator X_old_values('||i||')='||X_Old_Values(i),'C');
5150 END IF;
5151 END LOOP;
5152 /* Bug 3523930 -Setting the old values for project/task */
5153 X_old_task_id := X_task_id;
5154 X_old_actprj_id := X_Actual_Project_Id;
5155 gms_error_pkg.gms_debug('When First Indicator X_old_task_id ='||X_old_task_id,'C');
5159 --Create Running Total For Columns not in Group By--
5156 gms_error_pkg.gms_debug('When First Indicator X_old_project_id ='||X_old_actprj_id,'C');
5157 /* Bug 3523930- Changes end */
5158 ----------------------------------------------
5160 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5161 If X_Sel_Grp_Diff_Array(i) = 'N' then
5162 null;
5163 --X_Run_Total(i) := to_number(X_Old_Values(i));
5164 Else
5165 X_Run_Total(i) := -1;
5166 End If;
5167 End LOOP;
5168
5169 Else -- Else for 1st If for 'First_Row_Indicator' (2nd Row Values go into New Table)
5170 -- for Invoice Format Checking
5171
5172 -- Copy Values from Cursor into New_Values Table --
5173 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5174 DBMS_SQL.COLUMN_VALUE(cur_select,i,X_New_Values(i));
5175 IF L_DEBUG = 'Y' THEN
5176 gms_error_pkg.gms_debug('When !First Indicator X_new_values('||i||')='||X_New_Values(i),'C');
5177 END IF;
5178 END LOOP;
5179 /* Bug 3523930 -Setting the new values for project/task */
5180 X_new_task_id := X_task_id;
5181 X_new_actprj_id := X_Actual_Project_Id;
5182 gms_error_pkg.gms_debug('When !First Indicator X_new_task_id ='||X_New_task_id,'C');
5183 gms_error_pkg.gms_debug('When !First Indicator X_new_project_id ='||X_New_actprj_id,'C');
5184 /* Bug 3523930- Changes end */
5185 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5186 null;
5187 --dbms_output.put_line('NEW VALUES ARRE '||X_New_Values(i) );
5188 END LOOP;
5189 End If; -- End of 1st If for 'First_Row_Indicator'
5190
5191 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
5192
5193 /*************************************************************************************************/
5194
5195 If X_First_Indicator then --Begin of 2nd If for 'First_Row_Indicator'Check
5196 X_First_Indicator := FALSE;
5197 Else -- Else of 2nd If for 'First_Row_Indicator 'Check
5198 --Compare Old and New and accordingly create event
5199 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5200 If X_Sel_Grp_Diff_Array(i) = 'Y' then --Begin of If for 'Check_Ind' 999999999999999
5201 IF L_DEBUG = 'Y' THEN
5202 gms_error_pkg.gms_debug('Inside X_sel_grp_diff_array(i) = Y','C');
5203 END IF;
5204 /* Bug 3523930- Where condition changed */
5205 If ((X_Old_Values(i) <> X_New_Values(i) and X_invfmt_incl_task='N')
5206 or (X_invfmt_incl_task='Y'
5207 and (X_Old_Values(i) <> X_New_Values(i)
5208 or X_old_task_id <> X_new_task_id
5209 or X_old_actprj_id <> X_new_actprj_id))) then -- 888888888
5210 IF L_DEBUG = 'Y' THEN
5211 gms_error_pkg.gms_debug('Old Values are not equal to new values','C');
5212 END IF;
5213 ------------------------------------------------
5214 -- This procedure builds the Event Description, Creates the Event and Updates the --
5215 --GMS_EVENT_INTERSECT table with the corresponding Event Number --
5216
5217 -- Following IF .. End if statement commented for NULL Events logic ..
5218 -- zero $ amount logic shifted to DO_EVENT_PROCESSING
5219
5220 --If X_Event_Amount <> 0 then
5221 --dbms_output.put_line('Creating Event');
5222 DO_EVENT_PROCESSING(X_Cnt_Of_Columns_Selected,
5223 X_Sel_Grp_Diff_Array,
5224 X_Rt_Jstfy_Flag_Array,
5225 X_Old_Values,
5226 X_Padding_Length_Array,
5227 X_Run_Total,
5228 X_Text_Array,
5229 X_Project_Id,
5230 /*X_Task_Id, Changed for bug 3523930 */
5231 X_old_task_id,
5232 X_invfmt_incl_task, /* Added for bug 3523930 */
5233 X_Event_Amount,
5234 X_Carrying_Out_Org_Id,
5235 X_rev_or_bill_date,
5236 X_calling_process,
5237 X_Request_id,
5238 C_Installment_Id,
5239 X_Count,
5240 X_Installment_total,
5241 St_Err_Code,
5242 St_Err_Buff) ;
5243
5244 If St_Err_Code <> 0 then
5245 Raise NO_PROCESSING_OF_AWARD ;
5246 End If;
5247
5248 IF L_DEBUG = 'Y' THEN
5249 gms_error_pkg.gms_debug('After DO_EVENT_PROCESSING X_error_code:'||St_Err_Code,'C');
5250 END IF;
5251
5252 --End If;
5253 ----------------------------------------------
5254 --Copy New_Values to Old_Values--
5255 gms_error_pkg.gms_debug('Restting old task/project with new task/projet','C');
5256 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5257 X_Old_Values(i) := X_New_Values(i);
5258 End LOOP;
5259 /* Bug 3523930 */
5260 X_old_task_id := X_New_task_id;
5261 X_old_actprj_id := X_new_actprj_id;
5262 -----------------------------------------------
5263 ---------------------------------------------
5264 --Reset Cumulative Total --
5265 X_Event_Amount := 0;
5269 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5266 ---------------------------------------------
5267 ---------------------------------------------
5268 -- Reset Running Total Array to ZERO --
5270 X_Run_Total(i) := 0;
5271 End LOOP;
5272 EXIT ; --We donot check for any of the other columns
5273 --if a different one is found
5274 Else --888888888
5275 NULL;
5276 End If; -- Check for Old_Values <> New_Values -- 888888888
5277 Else -- Else for 'Check_Ind' 999999999999999
5278 --Do not Compare Old and New Value
5279 NULL;
5280 End If; -- End of If for 'Check_Ind' 999999999999999
5281 END LOOP;
5282 End If;-- End of 2nd If for 'First_Row_Indicator'Check
5283 ----------------------------------------------
5284
5285 /***********************************************************************************************/
5286
5287
5288 -- Inserting a row into GMS_EVENT_INTERSECT for every row Fetched --
5289 -- after checking to see if rows already exist for that Expenditure Item Id --
5290 --dbms_output.put_line('Before GMS_EVENT_INTERSECT');
5291 INSERT_GMS_EVENT_INTERSECT(X_Project_Id,
5292 X_Raw_Cost,
5293 X_Expenditure_Item_Id,
5294 X_Adl_Line_Num,
5295 X_Request_id,
5296 X_Amount_To_Insert,
5297 x_calling_process,
5298 X_Billable_Flag,
5299 X_Bill_Hold_Flag,
5300 X_Err_Nbr,
5301 X_Err_Stg); -- Insert into GMS_EVENT_INTERSECT
5302 If X_Err_Nbr <> 0 then
5303 --dbms_output.put_line('After GMS EVENT INTERSECT '||to_char(X_Err_Nbr)||X_Err_Stg);
5304 RETURN;
5305 End If;
5306
5307 /* bug 5242484 - start */
5308 IF ( X_old_expenditure_item_id = X_expenditure_item_id ) THEN
5309
5310 X_event_rollback_amount := X_event_rollback_amount + X_Amount_To_Insert;
5311
5312 ELSE
5313
5314 X_old_expenditure_item_id := X_expenditure_item_id;
5315
5316 X_event_rollback_amount := X_Amount_To_Insert;
5317
5318 END IF;
5319 /* for bug 5242484 - end */
5320 --------------------------------------------------------
5321 -- Maintaining Cumulative Total for Creating Event --
5322 X_Event_Amount := X_Event_Amount + X_Amount_To_Insert ;
5323 --------------------------------------------------------
5324 -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG so that the flag gets updated only when
5325 -- the expenditure is processed.
5326
5327 IF X_UPD_BILLING_FLAG -- Bug 3233706
5328 OR ((X_Amount_To_Insert = 0 ) AND (X_Tot_Burd_Amt_To_Insert = 0 )) THEN -- added for bug 5182669
5329 ---OR ((X_Raw_Cost + X_Tot_Burden_Amt_In_View) = (X_Amount_In_Intersect + X_Tot_Burd_Amt_In_Tmp)) then --bug 5122434--commented for bug 5182669
5330
5331
5332 -- Update GMS_AWARD_DISTRIBUTIONS set Billed_Flag to 'Y' indicating item has been picked for Invoicing
5333
5334 IF L_DEBUG = 'Y' THEN
5335 gms_error_pkg.gms_debug('Format specific Billing : Calling UPD_ADL_BILLING_FLAG for expenditure '||X_Expenditure_Item_Id,'C');
5336 END IF;
5337
5338 UPD_ADL_BILLING_FLAG(X_Expenditure_Item_Id,
5339 X_Adl_Line_Num,
5340 X_Calling_Process,
5341 X_Billable_Flag,
5342 X_Bill_Hold_Flag,
5343 St_Err_Code,
5344 St_Err_Buff);
5345
5346 IF L_DEBUG = 'Y' THEN
5347 gms_error_pkg.gms_debug('After UPD_ADL_BILLING_FLAG X_error_code:'||St_Err_Code,'C');
5348 END IF;
5349
5350 If St_Err_Code <> 0 then
5351 Raise NO_PROCESSING_OF_AWARD ;
5352 End If;
5353
5354 END IF; -- Bug 3254097
5355
5356 -------------------------------------------------------------------------------------
5357 -- Maintaining Cumulative Total for the Columns in Select_Text which donot have Group_By_Text--
5358 For i in 1..X_Cnt_Of_Columns_Selected LOOP
5359 If X_Sel_Grp_Diff_Array(i) = 'N' then
5360 -- X_Run_Total(i) := X_Run_Total(i) + nvl(to_number(X_New_Values(i)),0);
5361 null;
5362 Else -- (If Ind is 'T' or 'Y')
5363 X_Run_Total(i) := -1;
5364 End If;
5365 End LOOP;
5366 -------------------------------------------------------------------------------------
5367 END IF ;-- End of IF for Installment Check IIIII
5368
5369 /*IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
5370
5371 Else -- Else for 'Cursor_Rows_Check_If'
5372 --dbms_output.put_line('For last Row or If no rows present');
5373 -- This is for the Last Row being processed --
5374 --This procedure builds the Event Description, Creates the Event and Updates the --
5375 -- GMS_EVENT_INTERSECT table with the corresponding Event Number --
5376
5377 -- Following IF .. End if statement commented for NULL Events logic ..
5378 -- zero $ amount logic shifted to DO_EVENT_PROCESSING
5379
5380 --If X_Event_Amount <> 0 then
5381
5385 X_Old_Values,
5382 DO_EVENT_PROCESSING(X_Cnt_Of_Columns_Selected,
5383 X_Sel_Grp_Diff_Array,
5384 X_Rt_Jstfy_Flag_Array,
5386 X_Padding_Length_Array,
5387 X_Run_Total,
5388 X_Text_Array,
5389 X_Project_Id,
5390 /* X_Task_Id, Changed for bug 3523930*/
5391 X_old_task_id,
5392 X_invfmt_incl_task, /* Added for bug 3523930 */
5393 X_Event_Amount,
5394 X_Carrying_Out_Org_Id,
5395 X_rev_or_bill_date,
5396 X_calling_process,
5397 X_Request_id,
5398 C_Installment_Id,
5399 X_Count,
5400 X_Installment_total,
5401 St_Err_Code,
5402 St_Err_Buff) ;
5403
5404 If St_Err_Code <> 0 then
5405 Raise NO_PROCESSING_OF_AWARD ;
5406 End If;
5407 --End If;
5408
5409 EXIT;
5410
5411
5412 End If; -- End of 'Cursor_Rows_Check_If'
5413
5414 /* bug 5242484 - start */
5415 /* Commented revenue limit flag and added condition for invoice limit flag for bug 6642901*/
5416 IF (
5417 ((X_Raw_Cost + X_Tot_Burden_Amt_In_View) - (X_Amount_In_Intersect + X_Tot_Burd_Amt_In_Tmp)
5418 > (X_Money_Left_In_Inst - C_Inst_Task_Run_Total)) AND
5419 (X_Total_Funding_Amount <> -99 and X_Total_Rev_Bill_Amount <> -99) AND
5420 --(X_Revenue_Limit_Flag = 'Y')
5421 (X_Invoice_Limit_Flag = 'Y')
5422 AND ( X_expenditure_item_id = X_old_expenditure_item_id )
5423 ) THEN
5424
5425 IF L_DEBUG = 'Y' THEN
5426 gms_error_pkg.gms_debug('Calling Procedure EI rollback with parameters :- ','C');
5427 gms_error_pkg.gms_debug('EI rollback : Expenditure_item_id is '||x_expenditure_item_id,'C');
5428 gms_error_pkg.gms_debug('EI rollback : Adl_line_num is '||x_adl_line_num,'C');
5429 gms_error_pkg.gms_debug('EI rollback : Project id is '||X_old_actprj_id,'C');
5430 gms_error_pkg.gms_debug('EI rollback : Task id is '||X_old_task_id,'C');
5431 gms_error_pkg.gms_debug('EI rollback : Rollback amt is '||x_event_rollback_amount,'C');
5432 gms_error_pkg.gms_debug('EI rollback : Installment Count is '||x_Count,'C');
5433 END IF;
5434
5435 ei_rollback(x_award_id,
5436 'INVOICE',
5437 x_expenditure_item_id,
5438 x_adl_line_num,
5439 X_old_actprj_id,
5440 X_old_task_id,
5441 X_Count);
5442
5443 X_Event_Amount := X_Event_Amount - X_event_rollback_amount;
5444
5445 gms_error_pkg.gms_debug('Rolled back EI '||X_expenditure_item_id||' ! ','C');
5446
5447 END IF;
5448 /* bug 5242484 - end */
5449
5450 <<DO_NOT_PROCESS>>
5451
5452 NULL;
5453
5454 /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
5455
5456 EXCEPTION
5457 WHEN RESOURCE_BUSY THEN
5458 ROLLBACK TO EXPENDITURE_ITEM_PROCESSING;
5459 ss_text := SQLCODE||' '||SQLERRM;
5460
5461 END;
5462
5463 END LOOP;
5464
5465
5466 DBMS_SQL.CLOSE_CURSOR(cur_select);
5467
5468 EXCEPTION
5469 WHEN OTHERS THEN
5470 ss_text := SQLCODE||' '||SQLERRM;
5471 IF L_DEBUG = 'Y' THEN
5472 gms_error_pkg.gms_debug(ss_text ,'C');
5473 END IF;
5474 RAISE NO_PROCESSING_OF_AWARD;
5475
5476 End FORMAT_SPECIFIC_BILLING;
5477
5478 -----------------------------------------------------------------------------------------------------
5479 -- Procedure REVENUE_ACCRUAL: This is a new process to be used in addition to FORMAT_SPECIFIC_BILLING
5480 -- to handle Revenue Accrual process separately because of the requirement to create Revenue Events
5481 -- by Actual project
5482 -----------------------------------------------------------------------------------------------------
5483 Procedure REVENUE_ACCRUAL(X_Project_Id IN NUMBER,
5484 X_Award_Id IN NUMBER,
5485 X_Class_Category IN VARCHAR2,
5486 X_rev_or_bill_date IN DATE,
5487 X_Revenue_Limit_Flag IN VARCHAR2,
5488 X_request_id IN NUMBER,
5489 X_Rev_Carrying_Out_Org_Id IN NUMBER,
5490 X_calling_process IN VARCHAR2,
5491 X_Trx_Type IN VARCHAR2,
5492 C_Installment_Id IN NUMBER,
5493 C_Start_Date_Active IN DATE,
5494 C_End_Date_Active IN DATE,
5495 X_Err_Num OUT NOCOPY NUMBER,
5496 X_Err_Stage OUT NOCOPY VARCHAR2,
5497 g_labor_exp_to_process OUT NOCOPY VARCHAR2, /* added for bug 5026657 */
5498 g_non_labor_neg_exp_processed OUT NOCOPY VARCHAR2) IS /* added for bug 5026657 */
5499 --Bug : 2909746 - change the order by clause from adl.adl_line_num to adl.cdl_line_num
5500 -- 11.5, rev_cur_select cursor changed, so that certain columns are picked up from the adl table
5501 CURSOR rev_cur_select IS
5502 Select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)
5506 , ei.expenditure_type
5503 INDEX(adl gms_award_distributions_n7) */ /* Added INDEX(adl gms_award_distributions_n7) for 6969435 */
5504 p.project_id
5505 , adl.task_id
5507 , nvl(ei.override_to_organization_id,e.incurred_by_organization_id) EXPENDITURE_ORG
5508 , ei.quantity * (adl.distribution_value/100)*DECODE(adl.line_num_reversed,NULL,1,-1) --Added decode to get correct quantity
5509 , unit.meaning
5510 , decode(ei.system_linkage_function,'BTC',adl.raw_cost,adl.raw_cost)
5511 , ei.expenditure_item_id
5512 , ei.expenditure_item_date
5513 , ei.bill_hold_flag
5514 , adl.billable_flag
5515 , ei.adjusted_expenditure_item_id
5516 , adl.adl_line_num
5517 , adl.cdl_line_num --Bug 2909746
5518 , adl.parent_adl_line_num
5519 , adl.adl_status
5520 , adl.award_id
5521 , adl.ind_compiled_set_id
5522 , adl.burdenable_raw_cost
5523 , ei.transaction_source
5524 from
5525 gms_award_distributions adl /* Moved this up in the order for 6969435*/
5526 ,pa_expenditure_items_all ei
5527 ,pa_expenditures e
5528 ,pa_expenditure_types et
5529 ,pa_lookups unit
5530 ,pa_projects_all p
5531 ,pa_project_types pt
5532 ,pa_tasks t3
5533 ,pa_tasks t5
5534 where
5535 adl.award_id = X_Award_Id
5536 and ei.expenditure_item_id = adl.expenditure_item_id
5537 and adl.fc_status = 'A'
5538 and ((adl.line_num_reversed is null and adl.reversed_flag is null and ei.cost_distributed_flag='Y') or
5539 ((adl.line_num_reversed is not null or adl.reversed_flag is not null) and adl.cost_distributed_flag = 'Y')) --Bug 1852802
5540 and nvl(adl.billable_flag,'N')='Y'
5541 and ei.system_linkage_function <> 'BTC'
5542 and (adl.revenue_distributed_flag in ('N','Z') or adl.revenue_distributed_flag is null) -- For bug 4386936 -- reverting this for bug 4594090 /* Modified this for 6969435 */
5543 and ei.expenditure_item_date <= nvl(trunc(X_rev_or_bill_date),SYSDATE)
5544 and trunc(ei.expenditure_item_date) <= trunc(C_End_Date_Active)
5545 and adl.document_type = 'EXP' -- To pick up only actuals and not encumbrances
5546 and adl.adl_status = 'A'
5547 and ei.expenditure_type = et.expenditure_type
5548 and e.expenditure_id = ei.expenditure_id
5549 and et.unit_of_measure = unit.lookup_code
5550 and ( (ei.system_linkage_function in( 'ST', 'OT') and X_Trx_Type = 'LABOR')
5551 OR (ei.system_linkage_function not in( 'ST' , 'OT') and X_Trx_Type = 'NON_LABOR'))
5552 and unit.lookup_type = 'UNIT'
5553 and ei.task_id = t3.task_id
5554 and t3.top_task_id = t5.task_id
5555 and t5.ready_to_distribute_flag = 'Y'
5556 and t3.project_id = p.project_id
5557 and p.project_status_code <> 'CLOSED' -- Bug 3254097 : Modified 'CLOSED ' to 'CLOSED'
5558 and pt.project_type = p.project_type
5559 and pt.direct_flag = 'N'
5560 and exists ( select 1
5561 from gms_summary_project_fundings gspf
5562 where gspf.installment_id = C_installment_id
5563 and gspf.project_id = adl.project_id
5564 and (gspf.task_id is NULL or
5565 gspf.task_id = adl.task_id or
5566 gspf.task_id = (select t.top_task_id
5567 from pa_tasks t
5568 where t.task_id = adl.task_id
5569 )
5570 )
5571 )
5572 order by DECODE( NVL(ei.net_zero_adjustment_flag,'N'),'N', NVL(ei.raw_cost,
5573 gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)),
5574 'Y', DECODE(SIGN(NVL(ei.raw_cost,
5575 gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id))),
5576 1,-NVL(ei.raw_Cost,
5577 gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)),
5578 NVL(ei.raw_cost,
5579 gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)))),
5580 NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)),
5581 NVL(ei.adjusted_expenditure_item_id,ei.expenditure_item_id),
5582 adl.raw_cost, adl.cdl_line_num , -- Bug 3235390
5583 p.project_id,ei.task_id,ei.expenditure_type,EXPENDITURE_ORG;
5584
5585 X_Rev_Act_Project_Id NUMBER(15);
5586 X_Rev_Task_Id NUMBER(15);
5587 X_Rev_Expenditure_Type VARCHAR2(30);
5588 X_Rev_Expenditure_Org_Id NUMBER(15);
5589 X_Rev_Quantity NUMBER(15);
5590 X_Rev_Units VARCHAR2(30);
5591 X_Rev_Expenditure_Cost NUMBER(22,5);
5592 X_Rev_Expenditure_Item_Id NUMBER(15);
5593 X_Rev_Expenditure_Item_Date DATE;
5594 X_Rev_Bill_Hold_Flag VARCHAR2(1);
5595 X_Rev_Billable_Flag VARCHAR2(1);
5596 X_Rev_Adjusted_Exp_Item_Id NUMBER(15);
5597
5598 /* -- 11.5 Additions -- */
5599 X_Rev_Adl_Line_Num NUMBER(15);
5600 X_Rev_Cdl_Line_Num NUMBER(15); --bug 2909746
5601 X_Rev_parent_Adl_Line_Num NUMBER(15);
5602 X_Rev_Adl_Status VARCHAR2(1);
5603 X_Rev_Award_Id NUMBER(15);
5604 St_Err_Code VARCHAR2(30);
5605 St_Err_Buff VARCHAR2(2000);
5606 X_Rev_Installment_Status VARCHAR2(1) :=null;
5607 X_Rev_Count NUMBER :=0;
5608 X_Rev_Money_On_Curr_Inst NUMBER(22,5);
5609 /* -- 11.5 Additions -- */
5610
5611 X_Rev_Lock_Exp_Id NUMBER(15);
5612 X_Rev_Adl_Lock_Exp_Id NUMBER(15);
5613
5614 X_Rev_Orig_Item_Distr_Flag VARCHAR2(1);
5615 X_Rev_Total_Funding_Amount NUMBER(22,6):= 0;
5619 C_Rev_Inst_Task_Run_Total NUMBER(22,5):= 0;
5616 X_Total_Rev_Amount NUMBER(22,6):= 0;
5617 X_Rev_Amount_In_Intersect NUMBER(22,6):= 0;
5618 X_Rev_Money_Left_In_Inst NUMBER(22,6):= 0;
5620 X_Rev_Amount_To_Insert NUMBER(22,5):= 0;
5621 X_Rev_Event_Amount NUMBER(22,5):= 0;
5622 X_Rev_Run_Total NUMBER(15) := 0;
5623
5624 X_Rev_First_Row_Ind BOOLEAN := TRUE;
5625
5626 X_Act_Project_Id_Old NUMBER(15);
5627 X_Task_Id_Old NUMBER(15);
5628 X_Expenditure_Type_Old VARCHAR2(30);
5629 X_Expenditure_Org_Id_Old NUMBER(15);
5630 X_Quantity_Old NUMBER(15) := 0;
5631 X_Units_Old VARCHAR2(30);
5632
5633 /* bug 5242484 - start */
5634 X_old_expenditure_item_id NUMBER(15) := -9999 ;
5635 X_event_rollback_amount NUMBER(22,5) := 0;
5636 X_event_rollback_qty NUMBER(15) := 0;
5637 k NUMBER := 0;
5638 /* bug 5242484 - end */
5639
5640 X_Act_Project_Id_New NUMBER(15);
5641 X_Task_Id_New NUMBER(15);
5642 X_Expenditure_Type_New VARCHAR2(30);
5643 X_Expenditure_Org_Id_New NUMBER(15);
5644 X_Quantity_New NUMBER(15) := 0;
5645 X_Units_New VARCHAR2(30);
5646
5647 X_Rev_Burden_Component_Data Burden_Component_Tab_Type;
5648 X_Rev_Burden_Components_Count NUMBER := 0;
5649 X_Rev_Amt_In_Tmp_By_Component NUMBER := 0;
5650 X_Rev_Tot_Burd_Amt_In_Tmp NUMBER := 0;
5651 X_Rev_Tot_Burden_Amt_In_View NUMBER := 0;
5652 X_Rev_Burd_Amt_To_Ins_By_Comp NUMBER := 0;
5653 X_Rev_Tot_Burd_Amt_To_Insert NUMBER := 0;
5654
5655 X_Err_Nbr NUMBER(15) := NULL;
5656 X_Err_Stg VARCHAR2(200) := NULL;
5657 ss_text VARCHAR2(300);
5658 RESOURCE_BUSY EXCEPTION;
5659 PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -00054);
5660
5661 X_ind_compiled_Set_id gms_award_distributions.ind_compiled_set_id%type;
5662 X_burdenable_raw_cost gms_award_distributions.burdenable_raw_cost%type;
5663 X_transaction_source pa_expenditure_items_all.transaction_source%type;
5664
5665 Begin
5666
5667
5668 /* To set project_id NULL to be able to use Suresh's view to derive Burden Components and Burden Cost */
5669 --GMS_BURDEN_COSTING.SET_CURRENT_PROJECT_ID(NULL);
5670 --The above line has been commented out NOCOPY for bug 2442827
5671
5672 /* bug 5026657 */
5673 g_labor_exp_to_process := 'N';
5674 g_non_labor_neg_exp_processed := 'N';
5675
5676
5677 OPEN rev_cur_select;
5678 Begin
5679 LOOP
5680 Begin
5681 SAVEPOINT REV_EXP_ITEM_PROCESSING;
5682
5683 FETCH rev_cur_select into
5684 X_Rev_Act_Project_Id
5685 ,X_Rev_Task_Id
5686 ,X_Rev_Expenditure_Type
5687 ,X_Rev_Expenditure_Org_Id
5688 ,X_Rev_Quantity
5689 ,X_Rev_Units
5690 ,X_Rev_Expenditure_Cost
5691 ,X_Rev_Expenditure_Item_Id
5692 ,X_Rev_Expenditure_Item_Date
5693 ,X_Rev_Bill_Hold_Flag
5694 ,X_Rev_Billable_Flag
5695 ,X_Rev_Adjusted_Exp_Item_Id
5696 ,X_Rev_Adl_Line_Num
5697 ,X_Rev_Cdl_Line_Num --Bug 2909746
5698 ,X_Rev_Parent_Adl_Line_Num
5699 ,X_Rev_Adl_Status
5700 ,X_Rev_Award_Id
5701 ,X_ind_compiled_Set_id
5702 ,X_burdenable_raw_cost
5703 ,X_transaction_source;
5704
5705 EXIT WHEN rev_cur_select%NOTFOUND;
5706
5707 X_Rev_Burden_Component_Data.DELETE;
5708
5709 IF L_DEBUG = 'Y' THEN
5710 gms_error_pkg.gms_debug('Expenditure Item Id :'||X_Rev_Expenditure_Item_Id,'C');
5711 gms_error_pkg.gms_debug('X_Adl_Line_Num:'||X_Rev_Adl_Line_Num,'C');
5712 gms_error_pkg.gms_debug('X_Cdl_Line_Num:'||X_Rev_Cdl_Line_Num,'C'); -- Bug 2909746
5713 gms_error_pkg.gms_debug('X_Expenditure_Item_Date:'||X_Rev_Expenditure_Item_Date,'C');
5714 gms_error_pkg.gms_debug('X_Raw_Cost:'||X_Rev_Expenditure_Cost,'C');
5715 gms_error_pkg.gms_debug('X_Bill_Hold_Flag:'||X_Rev_Bill_Hold_Flag,'C');
5716 END IF;
5717
5718 -- Lock the Expenditure Item
5719 select expenditure_item_id
5720 into
5721 X_Rev_Lock_Exp_Id
5722 from
5723 pa_expenditure_items_all
5724 where
5725 expenditure_item_id = X_Rev_Expenditure_Item_Id
5726 FOR UPDATE NOWAIT;
5727
5728 -- 11.5 Change, Lock Adl Expenditure Item too
5729
5730 select expenditure_item_id
5731 into
5732 X_Rev_Adl_Lock_Exp_Id
5733 from
5734 gms_award_distributions
5735 where expenditure_item_id = X_Rev_Expenditure_Item_Id
5736 and adl_line_num=X_Rev_Adl_Line_Num
5737 and document_type='EXP'
5738 and adl_status = 'A'
5739 FOR UPDATE NOWAIT;
5740
5741 /* This is to see that the Adjusting Expenditure Item is picked up first for Billing */
5742 -- Bug 3235390 : commented out
5743 /* If X_Rev_Adjusted_Exp_Item_Id IS NOT NULL then
5744 Begin
5745 Select
5746 nvl(revenue_distributed_flag,'N')
5747 into
5748 X_Rev_Orig_Item_Distr_Flag
5749 from
5750 gms_award_distributions
5751 where expenditure_item_id = X_Rev_Adjusted_Exp_Item_Id
5752 and award_id = X_Rev_award_id
5753 and adl_status='A'
5754 and document_type ='EXP'
5755 and adl_line_num =
5756 (select max(adl_line_num)
5757 from gms_award_distributions
5758 where expenditure_item_id = X_Rev_Adjusted_Exp_Item_Id
5759 and award_id = X_Rev_award_id
5763 End;
5760 and adl_status='A'
5761 and document_type ='EXP');
5762
5764 End If; */ --bug 3235390
5765
5766 -----------------------------------------------------------------------------------------------------
5767 /*Resetting Burden Totals from View and Tmp table to zero for every Exp Item being processed */
5768 X_Rev_Tot_Burd_Amt_In_Tmp := 0;
5769 X_Rev_Tot_Burden_Amt_In_View := 0;
5770 X_Rev_Tot_Burd_Amt_To_Insert := 0;
5771 X_UPD_BILLING_FLAG := FALSE; -- Bug 3254097 : Intializing the flag
5772
5773 ----------------------------------------------------------------------------------------------------
5774 /* If (X_Rev_Adjusted_Exp_Item_Id IS NOT NULL and X_Rev_Orig_Item_Distr_Flag <> 'Y' ) then
5775
5776 GOTO DO_NOT_PROCESS_REV; Do not go any further with processing of this item
5777
5778 End If; */ --Bug 3235390
5779
5780 ------------------------------------------------------------------------------------
5781 -- Rounding fix : Bug 1417062
5782
5783 X_Rev_Expenditure_Cost := pa_currency.round_currency_amt(nvl(X_Rev_Expenditure_Cost,0));
5784
5785 -----------------------------------------------------------------------------
5786 /* For the particular Installment,Task get Total Billed Amount and Total Funding Amount */
5787 GET_SUMM_FUNDING(NULL,-- C_Installment_Id, Made Null for 11.5
5788 X_Rev_Expenditure_Item_Date,
5789 X_Rev_Award_Id,
5790 X_Rev_Task_Id,
5791 X_calling_process,
5792 X_Rev_Total_Funding_Amount,
5793 X_Total_Rev_Amount,
5794 St_Err_Code,
5795 St_Err_Buff);
5796
5797 If St_Err_Code <> 0 then
5798 Raise NO_PROCESSING_OF_AWARD ;
5799 End If;
5800 -----------------------------------------------------------------------------
5801 X_Rev_Money_Left_In_Inst := (X_Rev_Total_Funding_Amount - X_Total_Rev_Amount);
5802 -----------------------------------------------------------------------------
5803
5804 -- Bug 2441525 : If the raw cost is greater than the funding left then there is no need for deriving burden.
5805
5806 -- IF NVL(X_Rev_Expenditure_Cost,0) > NVL(X_Rev_Money_Left_In_Inst,0) AND X_Revenue_Limit_Flag = 'Y' THEN -- hard limit
5807 -- GOTO DO_NOT_PROCESS_REV; /* Do not go any further with processing of this item */
5808 -- END IF;
5809 -- Above code commented out .. Bug 4289410
5810
5811 -- 11.5 changes start
5812
5813 X_Rev_Installment_Status := null; -- Initialize
5814
5815 /* Installment Check */
5816
5817 INSTALLMENT_CHECK(C_Installment_Id,
5818 X_Rev_Award_Id,
5819 X_Rev_Task_Id,
5820 X_Calling_Process,
5821 X_Rev_Expenditure_Item_Date,
5822 X_Rev_Money_Left_In_Inst,
5823 X_Rev_Money_On_Curr_Inst,
5824 X_Rev_Installment_Status,
5825 St_Err_Code,
5826 St_Err_Buff);
5827
5828 If St_Err_Code <> 0 then
5829 Raise NO_PROCESSING_OF_AWARD ;
5830 End If;
5831
5832 /* Commented for bug 5349106 */
5833 -- If X_Rev_Installment_Status ='I' then
5834 -- GOTO DO_NOT_PROCESS_REV; /* Do not go any further with processing of this item */
5835 -- End if;
5836 -- 11.5 changes end
5837 ----------------------------------------------------------------------------
5838 /* Getting the Burden Components and Burden Amount from View for each Raw Expenditure Item in an array form */
5839
5840 X_Rev_Burden_Components_Count := 0;
5841
5842 If (nvl(x_burdenable_raw_cost,0) <> 0 and x_ind_compiled_set_id is not null) then
5843
5844 If allow_burden(x_transaction_source) then
5845
5846 GET_BURDEN_COMPONENT_DATA(X_Rev_Act_Project_Id,
5847 X_Rev_Task_Id,
5848 X_Rev_Expenditure_Org_Id,
5849 X_ind_compiled_set_id,
5850 X_burdenable_raw_cost,
5851 X_Rev_Expenditure_Type,
5852 X_Rev_Burden_Components_Count,
5853 X_Rev_Burden_Component_Data);
5854 End If; --If allow_burden(x_transaction_source) then
5855
5856 End If;
5857 ----------------------------------------------------------------------------
5858 IF L_DEBUG = 'Y' THEN
5859 gms_error_pkg.gms_debug('X_Rev_Burden_Components_Count:'||X_Rev_Burden_Components_Count,'C');
5860 END IF;
5861 -----------------------------------------------------------------------------
5862 /* For each Trx fetched Get total amount for the Trx already existing in Intersect table */
5863 GET_AMOUNT_IN_INTERSECT(X_Rev_Expenditure_Item_Id,
5864 X_Rev_Adl_Line_Num,
5865 X_Calling_Process,
5866 X_Rev_Amount_In_Intersect
5867 );
5868 -----------------------------------------------------------------------------
5869
5870 -----------------------------------------------------------------------------
5871 For i in 1..X_Rev_Burden_Components_Count LOOP
5872 GET_BURD_AMT_IN_INTERSECT(X_Rev_Expenditure_Item_Id,
5873 X_Rev_Adl_Line_Num,
5874 X_Calling_Process,
5875 X_Rev_Burden_Component_Data(i).Burden_Cost_Code,
5879
5876 X_Rev_Amt_In_Tmp_By_Component);
5877
5878 X_Rev_Tot_Burd_Amt_In_Tmp := X_Rev_Tot_Burd_Amt_In_Tmp + X_Rev_Amt_In_Tmp_By_Component;
5880 End LOOP;
5881 ------------------------------------------------------------------------------
5882 -----------------------------------------------------------------------------
5883 For i in 1..X_Rev_Burden_Components_Count LOOP
5884 X_Rev_Tot_Burden_Amt_In_View := X_Rev_Tot_Burden_Amt_In_View + X_Rev_Burden_Component_Data(i).Burden_Cost;
5885 End LOOP;
5886 ------------------------------------------------------------------------------
5887 /* For bug 5026657 */
5888 IF ( (X_Revenue_Limit_Flag = 'Y') AND
5889 (X_Trx_Type = 'LABOR') AND
5890 ( (X_Rev_Expenditure_Cost + X_Rev_Tot_Burden_Amt_In_View) - (X_Rev_Amount_In_Intersect + X_Rev_Tot_Burd_Amt_In_Tmp)
5891 > (X_Rev_Money_Left_In_Inst - C_Rev_Inst_Task_Run_Total) ) ) THEN
5892 g_labor_exp_to_process := 'Y' ;
5893
5894 END IF;
5895
5896 IF ( (
5897 ( (X_Rev_Expenditure_Cost + X_Rev_Tot_Burden_Amt_In_View) - (X_Rev_Amount_In_Intersect + X_Rev_Tot_Burd_Amt_In_Tmp)
5898 <= ( X_Rev_Money_Left_In_Inst - C_Rev_Inst_Task_Run_Total) )
5899 AND (X_Rev_Total_Funding_Amount <> -99 and X_Total_Rev_Amount <> -99)
5900 AND (X_Revenue_Limit_Flag = 'Y')
5901 )
5902 OR
5903 (X_Revenue_Limit_Flag = 'N')
5904 ) then --??????????????
5905
5906 GET_ACCRUE_BILL_OR_INSERT_AMT(X_Rev_Expenditure_Item_Id,
5907 X_Rev_Adl_line_Num,
5908 X_Calling_Process,
5909 X_Rev_Expenditure_Cost,
5910 X_Rev_Billable_Flag,
5911 X_Rev_Bill_Hold_Flag,
5912 X_Rev_Amount_To_Insert,
5913 X_Err_Num,
5914 X_Err_Stage);
5915
5916 FOR i in 1..X_Rev_Burden_Components_Count LOOP
5917 GET_BURDEN_AMT_TO_INSERT(X_Rev_Expenditure_Item_Id,
5918 X_Rev_Adl_Line_Num,
5919 X_Calling_Process,
5920 X_Rev_Burden_Component_Data(i).Burden_Cost_Code,
5921 X_Rev_Billable_Flag,
5922 X_Rev_Bill_Hold_Flag,
5923 X_Rev_Burden_Component_Data(i).Burden_Cost,
5924 X_Rev_Burd_Amt_To_Ins_By_Comp);
5925
5926 -- Rounding fix : Bug 1417062
5927 X_Rev_Burd_Amt_To_Ins_By_Comp := pa_currency.round_currency_amt(nvl(X_Rev_Burd_Amt_To_Ins_By_Comp,0));
5928
5929 INSERT_GMS_BURDEN_COMPONENTS(X_Project_Id,
5930 X_Rev_Expenditure_Item_Id,
5931 X_Rev_Adl_Line_Num,
5932 X_Request_Id,
5933 X_Calling_Process,
5934 X_Rev_Burden_Component_Data(i).Actual_Project_Id,
5935 X_Rev_Burden_Component_Data(i).Actual_Task_Id,
5936 X_Rev_Burden_Component_Data(i).Burden_Expenditure_Type,
5937 X_Rev_Burden_Component_Data(i).Burden_Cost_Code,
5938 X_Rev_Burden_Component_Data(i).Expenditure_Org_Id,
5939 X_Rev_Burd_Amt_To_Ins_By_Comp,
5940 X_Err_Num,
5941 X_Err_Stage);
5942
5943 X_Rev_Tot_Burd_Amt_To_Insert := X_Rev_Tot_Burd_Amt_To_Insert + X_Rev_Burd_Amt_To_Ins_By_Comp;
5944
5945 END LOOP;
5946
5947 C_Rev_Inst_Task_Run_Total := nvl(C_Rev_Inst_Task_Run_Total,0) + (nvl(X_Rev_Amount_To_Insert,0) + nvl(X_Rev_Tot_Burd_Amt_To_Insert,0));
5948
5949 /* For bug 5026657 */
5950
5951 IF ( (X_Revenue_Limit_Flag = 'Y') AND
5952 (X_Trx_Type = 'NON_LABOR') AND
5953 (nvl(X_Rev_Amount_To_Insert,0) + nvl(X_Rev_Tot_Burd_Amt_To_Insert,0)) < 0 ) THEN
5954
5955 g_non_labor_neg_exp_processed := 'Y' ;
5956
5957 END IF;
5958
5959 ------------------------------------------------------------------------------
5960 -- 11.5 changes start
5961
5962 -- GET_INSTALLMENT_NUM, to get installment numbers in case of amounts across installments
5963
5964 GET_INSTALLMENT_NUM(C_Installment_id,
5965 X_Rev_Award_Id,
5966 X_Rev_Task_Id,
5967 X_Rev_Expenditure_item_date,
5968 X_Calling_Process,
5969 X_Rev_Money_On_Curr_Inst,
5970 C_Rev_Inst_Task_Run_Total,
5971 X_Rev_Installment_Status,
5972 X_Rev_Installment_tab,
5973 X_Rev_Count,
5974 St_Err_Code,
5975 St_Err_Buff);
5976
5977 If St_Err_Code <> 0 then
5978 Raise NO_PROCESSING_OF_AWARD ;
5979 End If;
5980
5981 -- 11.5 changes end
5982
5983 /* bug 5242484 - end */
5984 IF ( X_old_expenditure_item_id = X_Rev_expenditure_item_id ) THEN
5985 IF ( X_Rev_Count = 1) THEN
5986 X_ei_rollback_inst_tab(1).rev_bill_amount := X_ei_rollback_inst_tab(1).rev_bill_amount + C_Rev_Inst_Task_Run_Total;
5987 ELSE
5988 FOR k in 1..X_Rev_Count LOOP
5989 X_ei_rollback_inst_tab(k).rev_bill_amount := X_ei_rollback_inst_tab(k).rev_bill_amount + X_Rev_Installment_tab(k).rev_bill_amount;
5993 IF ( X_Rev_Count = 1) THEN
5990 END LOOP;
5991 END IF;
5992 ELSE
5994 X_ei_rollback_inst_tab(1).rev_bill_amount := C_Rev_Inst_Task_Run_Total;
5995 X_ei_rollback_inst_tab(1).installment_id := C_Installment_id;
5996
5997 ELSE
5998 FOR k in 1..X_Rev_Count LOOP
5999 X_ei_rollback_inst_tab(k).rev_bill_amount := X_Rev_Installment_tab(k).rev_bill_amount ;
6000 X_ei_rollback_inst_tab(k).installment_id := X_Rev_Installment_tab(k).installment_id;
6001 END LOOP;
6002 END IF;
6003
6004 END IF;
6005 /* bug 5242484 - end */
6006
6007 ------------------------------------------------------------------------------
6008 --Updating GMS_SUMMARY_PROJECT_FUNDINGS Billed Amount with the Amount of the current transaction
6009
6010 UPD_GSPF_WRAPPER(C_Installment_Id,
6011 X_Rev_Task_Id,
6012 X_Rev_Act_Project_Id,
6013 X_Calling_Process,
6014 C_Rev_Inst_Task_Run_Total,
6015 X_Rev_Count,
6016 X_Rev_Installment_tab,
6017 X_Rev_Installment_total,
6018 St_Err_Code,
6019 St_Err_Buff);
6020
6021 If St_Err_Code <> 0 then
6022 Raise NO_PROCESSING_OF_AWARD ;
6023 End If;
6024
6025 -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG at the end of the process.
6026
6027 --Resetting the Inst_Task_Bill_Amount Running Total to Zero for Next transaction
6028 C_Rev_Inst_Task_Run_Total := 0;
6029
6030 ----------------------------------------------------------------------------------
6031 If X_Rev_First_Row_Ind then
6032 X_Act_Project_Id_Old := X_Rev_Act_Project_Id;
6033 X_Task_Id_Old := X_Rev_Task_Id;
6034 X_Expenditure_Type_Old := X_Rev_Expenditure_Type;
6035 X_Expenditure_Org_Id_Old := X_Rev_Expenditure_Org_Id;
6036 X_Units_Old := X_Rev_Units;
6037 X_Quantity_Old := X_Rev_Quantity;
6038 X_Rev_Run_Total := X_Quantity_Old;
6039
6040 Else
6041 X_Act_Project_Id_New := X_Rev_Act_Project_Id;
6042 X_Task_Id_New := X_Rev_Task_Id;
6043 X_Expenditure_Type_New := X_Rev_Expenditure_Type;
6044 X_Expenditure_Org_Id_New := X_Rev_Expenditure_Org_Id;
6045 X_Units_New := X_Rev_Units;
6046 X_Quantity_New := X_Rev_Quantity;
6047
6048 End If;
6049
6050 ----------------------------------------------------------------------------
6051
6052 If X_Rev_First_Row_Ind then
6053 X_Rev_First_Row_Ind := FALSE;
6054 Else
6055
6056 If ( (X_Act_Project_Id_Old <> X_Act_Project_Id_New) OR
6057 (X_Task_Id_Old <> X_Task_Id_New) OR
6058 (X_Expenditure_Type_Old <> X_Expenditure_Type_New) OR
6059 (X_Expenditure_Org_Id_Old <> X_Expenditure_Org_Id_New) ) then
6060
6061 -- Following IF .. End if statement commented for NULL Events logic ..
6062 -- zero $ amount logic shifted to DO_REV_EVENT_PROCESSING
6063
6064 --If (X_Rev_Event_Amount <> 0) then
6065 DO_REV_EVENT_PROCESSING(X_Act_Project_Id_Old,
6066 X_Task_Id_Old,
6067 X_Expenditure_Type_Old,
6068 X_Expenditure_Org_Id_Old,
6069 X_Units_Old,
6070 X_Rev_Run_Total,
6071 X_Project_Id,
6072 X_Rev_Event_Amount,
6073 X_Rev_Carrying_Out_Org_Id,
6074 X_rev_or_bill_date,
6075 X_calling_process,
6076 X_Request_id,
6077 C_Installment_Id,
6078 X_Rev_Count,
6079 X_Rev_Installment_total,
6080 St_Err_Code,
6081 St_Err_Buff);
6082 --End If;
6083
6084 /* Copying New values to Old values */
6085 X_Act_Project_Id_Old := X_Act_Project_Id_New;
6086 X_Task_Id_Old := X_Task_Id_New;
6087 X_Expenditure_Type_Old := X_Expenditure_Type_New;
6088 X_Expenditure_Org_Id_Old := X_Expenditure_Org_Id_New;
6089
6090 X_Units_Old := X_Units_New;
6091
6092 /* Resetting X_Rev_Event_Amount */
6093 X_Rev_Event_Amount := 0;
6094
6095 /* Resetting Running Total for Hours etc for Event Description */
6096 X_Rev_Run_Total := 0;
6097
6098 End If;
6099
6100 End If;
6101 ---------------------------------------------------
6102 INSERT_GMS_EVENT_INTERSECT(X_Project_Id,
6103 X_Rev_Expenditure_Cost,
6104 X_Rev_Expenditure_Item_Id,
6105 X_Rev_Adl_Line_Num,
6106 X_Request_id,
6107 X_Rev_Amount_To_Insert,
6108 X_Calling_process,
6109 X_Rev_Billable_Flag,
6110 X_Rev_Bill_Hold_Flag,
6111 X_Err_Nbr,
6112 X_Err_Stg); -- Insert into GMS_EVENT_INTERSECT
6113 If X_Err_Nbr <> 0 then
6114 RETURN;
6115 End If;
6116
6117 /* for bug 5242484 - start */
6118 IF ( X_old_expenditure_item_id = X_Rev_expenditure_item_id ) THEN
6119
6120 X_event_rollback_amount := X_event_rollback_amount + X_Rev_Amount_To_Insert;
6121 X_event_rollback_qty := X_event_rollback_qty + X_Quantity_New;
6122
6123 ELSE
6124
6125 X_old_expenditure_item_id := X_Rev_expenditure_item_id;
6126
6127 X_event_rollback_amount := X_Rev_Amount_To_Insert;
6128 X_event_rollback_qty := X_Quantity_New ;
6129
6130 END IF;
6131 /* for bug 5242484 - end */
6132
6133
6134 -- Maintaining Cumulative Total for Creating Event --
6135 X_Rev_Event_Amount := X_Rev_Event_Amount + X_Rev_Amount_To_Insert;
6136
6137 -- Maintaining total for Quantity etc for Description
6138 X_Rev_Run_Total := X_Rev_Run_Total + X_Quantity_New;
6139
6140 -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG so that the flag gets updated only when
6141 -- the expenditure is processed.
6142
6143 IF X_UPD_BILLING_FLAG -- Bug 3233706
6144 OR ((X_Rev_Amount_To_Insert = 0) AND ( X_Rev_Tot_Burd_Amt_To_Insert = 0 ) ) THEN -- added for bug 5182669
6145 --OR ((X_Rev_Expenditure_Cost + X_Rev_Tot_Burden_Amt_In_View) = (X_Rev_Amount_In_Intersect + X_Rev_Tot_Burd_Amt_In_Tmp)) then -- bug 5122434--Commented for bug 5182269
6146
6147 IF L_DEBUG = 'Y' THEN
6148 gms_error_pkg.gms_debug('Revenue accrual : Calling UPD_ADL_BILLING_FLAG For expenditure_item_id '||X_Rev_Expenditure_Item_Id,'C');
6149 END IF;
6150
6151 UPD_ADL_BILLING_FLAG(X_Rev_Expenditure_Item_Id,
6152 X_Rev_Adl_Line_Num,
6153 X_Calling_Process,
6154 X_Rev_Billable_Flag,
6155 X_Rev_Bill_Hold_Flag,
6156 St_Err_Code,
6157 St_Err_Buff);
6158
6159 If St_Err_Code <> 0 then
6160 Raise NO_PROCESSING_OF_AWARD ;
6161 End If;
6162 END IF;
6163 --------------------------------------------------
6164
6165
6166 End If; --????????????
6167
6168 /* for bug 5242484 - start */
6169 IF (
6170 ( (X_Rev_Expenditure_Cost + X_Rev_Tot_Burden_Amt_In_View) - (X_Rev_Amount_In_Intersect + X_Rev_Tot_Burd_Amt_In_Tmp)
6171 > ( X_Rev_Money_Left_In_Inst - C_Rev_Inst_Task_Run_Total) )
6172 AND (X_Rev_Total_Funding_Amount <> -99 and X_Total_Rev_Amount <> -99)
6173 AND (X_Revenue_Limit_Flag = 'Y')
6174 AND ( X_Rev_expenditure_item_id = X_old_expenditure_item_id )
6175 ) THEN
6176
6177 IF L_DEBUG = 'Y' THEN
6178 gms_error_pkg.gms_debug('Calling Procedure EI rollback with parameters :- ','C');
6179 gms_error_pkg.gms_debug('EI rollback : Expenditure_item_id is '||x_Rev_expenditure_item_id,'C');
6180 gms_error_pkg.gms_debug('EI rollback : Adl_line_num is '||x_Rev_adl_line_num,'C');
6181 gms_error_pkg.gms_debug('EI rollback : Project id is '||x_act_project_id_old,'C');
6182 gms_error_pkg.gms_debug('EI rollback : Task id is '||x_task_id_old,'C');
6183 gms_error_pkg.gms_debug('EI rollback : Rollback amt is '||x_event_rollback_amount,'C');
6184 gms_error_pkg.gms_debug('EI rollback : Rollback qty is '||x_event_rollback_qty,'C');
6185 gms_error_pkg.gms_debug('EI rollback : Installment Count is '||x_Rev_Count,'C');
6186 END IF;
6187
6188 ei_rollback(x_Rev_award_id,
6189 'REVENUE',
6190 x_Rev_expenditure_item_id,
6191 x_rev_adl_line_num,
6192 x_act_project_id_old,
6193 x_task_id_old,
6194 X_Rev_Count);
6195
6196 X_Rev_Run_Total := X_Rev_Run_Total - x_event_rollback_qty ;
6197 X_Rev_Event_Amount := X_Rev_Event_Amount - X_event_rollback_amount;
6198
6199 gms_error_pkg.gms_debug('Rolled back EI '||X_Rev_expenditure_item_id||' ! ','C');
6200 /* for bug 5242484 - end */
6201
6202 END IF;
6203
6204 <<DO_NOT_PROCESS_REV>>
6205
6206 NULL;
6207
6208 EXCEPTION
6209 WHEN RESOURCE_BUSY THEN
6210 ROLLBACK TO REV_EXP_ITEM_PROCESSING;
6211 ss_text := SQLCODE||' '||SQLERRM;
6212
6213 WHEN OTHERS THEN
6214 ss_text := SQLCODE||' '||SQLERRM;
6215 -- insert into ss_log(id,err_text) values (2,ss_text);
6216 ROLLBACK TO REV_EXP_ITEM_PROCESSING;
6217 End;
6218 End LOOP;
6219
6220 /* For last row Processing */
6221 -- Following IF .. End if statement commented for NULL Events logic ..
6222 -- zero $ amount logic shifted to DO_REV_EVENT_PROCESSING
6223
6224 --If X_Rev_Event_Amount <> 0 then
6225 -- X_LAST_CALL_FOR_REVENUE := TRUE; -- Bug 3254097
6226 IF L_DEBUG = 'Y' THEN
6227 gms_error_pkg.gms_debug('IN REVENUE_ACCRUAL, last call ...','C');
6228 END IF;
6229 DO_REV_EVENT_PROCESSING(X_Act_Project_Id_Old,
6230 X_Task_Id_Old,
6231 X_Expenditure_Type_Old,
6235 X_Project_Id,
6232 X_Expenditure_Org_Id_Old,
6233 X_Units_Old,
6234 X_Rev_Run_Total,
6236 X_Rev_Event_Amount,
6237 X_Rev_Carrying_Out_Org_Id,
6238 X_rev_or_bill_date,
6239 X_calling_process,
6240 X_Request_id,
6241 C_Installment_Id,
6242 X_Rev_Count,
6243 X_Rev_Installment_total,
6244 St_Err_Code,
6245 St_Err_Buff);
6246 --X_LAST_CALL_FOR_REVENUE := FALSE; -- Bug 3254097
6247 --End If;
6248
6249 End;
6250 CLOSE rev_cur_select;
6251
6252 End REVENUE_ACCRUAL;
6253
6254 ------------------------------------------------------------------------
6255 ------------------------------------------------------------------------
6256 --Procedure UPDATE_PROJECT_MANAGER : This procedure updates Award Project Manager
6257 --with current Award Manager
6258 --Stoped use of this procedure because GMS will be updating project manager
6259 --through award form only to fix bug 1907565
6260 ------------------------------------------------------------------------
6261 PROCEDURE UPDATE_PROJECT_MANAGER(X_Project_Id IN NUMBER,
6262 X_Award_Id IN NUMBER) IS
6263 X_Person_Id NUMBER(15);
6264 X_end_date_active DATE := NULL; -- Bug fix for 863428
6265 Begin
6266
6267 Begin
6268 Select
6269 person_id,
6270 end_date_active
6271 into
6272 X_Person_Id,
6273 X_end_date_active -- Bug fix for 863428
6274 from
6275 GMS_PERSONNEL
6276 where award_id = X_Award_Id
6277 and trunc(sysdate) between trunc(start_date_active) and trunc(end_date_active)
6278 and award_role = 'AM';
6279 EXCEPTION
6280 WHEN NO_DATA_FOUND THEN
6281 Begin
6282 Select
6283 person_id
6284 into
6285 X_Person_Id
6286 from
6287 GMS_PERSONNEL
6288 where award_id = X_Award_Id
6289 and award_role = 'AM'
6290 and end_date_active IS NULL;
6291 EXCEPTION
6292 WHEN NO_DATA_FOUND THEN
6293 Begin
6294 Select
6295 person_id
6296 into
6297 X_Person_Id
6298 from
6299 GMS_PERSONNEL
6300 where award_id = X_Award_Id
6301 and award_role = 'AM'
6302 and end_date_active = (select max(end_date_active)
6303 from gms_personnel
6304 where
6305 award_id = X_Award_Id
6306 and award_role = 'AM');
6307
6308 End ;
6309 End ;
6310 End;
6311
6312
6313 Begin
6314
6315 update pa_project_parties
6316 set resource_source_id=X_Person_Id,
6317 end_date_active = X_end_date_active
6318 where project_id = X_Project_Id
6319 and project_role_id =(select project_role_id
6320 from pa_project_role_types
6321 where project_role_type = 'PROJECT MANAGER');
6322 Exception
6323 when others then
6324 RAISE;
6325 End;
6326
6327 End UPDATE_PROJECT_MANAGER;
6328
6329 -----------------------------------------------------------------------------------------
6330 -- Procedure AWARD_BILLING: This is the actual Billing Extension which gets called by the core
6331 -- Billing or Revenue Programs.
6332 -----------------------------------------------------------------------------------------
6333 PROCEDURE AWARD_BILLING
6334 ( X_project_id IN NUMBER,
6335 X_top_Task_id IN NUMBER DEFAULT NULL,
6336 X_calling_process IN VARCHAR2 DEFAULT NULL,
6337 X_calling_place IN VARCHAR2 DEFAULT NULL,
6338 X_amount IN NUMBER DEFAULT NULL,
6339 X_percentage IN NUMBER DEFAULT NULL,
6340 X_rev_or_bill_date IN DATE DEFAULT NULL,
6341 X_bill_extn_assignment_id IN NUMBER DEFAULT NULL,
6342 X_bill_extension_id IN NUMBER DEFAULT NULL,
6343 X_request_id IN NUMBER DEFAULT NULL) IS
6344 sql_select VARCHAR2(4000);
6345 sql_from VARCHAR2(2000);
6346 sql_where VARCHAR2(2000);
6347 sql_orderby VARCHAR2(2000);
6348 l_sql_orderby VARCHAR2(2000); --Bug 3235390
6349
6350 X_Award_Id NUMBER(15);
6351 X_Award_Rev_Distribution_Rule VARCHAR2(30);
6352 X_Award_Bill_Distribution_Rule VARCHAR2(30);
6353 X_Award_Status VARCHAR2(30);
6354 X_Revenue_Limit_Flag VARCHAR2(1);
6355 X_Invoice_Limit_Flag VARCHAR2(1); /*Bug 6642901 */
6356 /* Added for bug 5026657 */
6357 g_process_again VARCHAR2(1) DEFAULT 'N';
6361 f_non_labor_neg_exp_processed VARCHAR2(1) DEFAULT 'N';
6358 g_labor_exp_to_process VARCHAR2(1) DEFAULT 'N';
6359 g_non_labor_neg_exp_processed VARCHAR2(1) DEFAULT 'N';
6360 f_labor_exp_to_process VARCHAR2(1) DEFAULT 'N';
6362
6363 CURSOR GET_INSTALLMENTS IS
6364 Select
6365 Installment_Id,
6366 Start_Date_Active,
6367 End_Date_Active
6368 from
6369 GMS_INSTALLMENTS
6370 where
6371 Award_Id = X_Award_Id
6372 /* and active_flag = 'Y' bug 6878405 */
6373 and nvl(billable_flag,'N') = 'Y'
6374 order by End_Date_Active;
6375
6376 -- Added for Bug 1744641: To Generate errors when an exception occurs
6377 -- during the process of generation of invoice/Revenue.
6378 Cursor GMS_AWARDS_CURSOR is
6379 select
6380 a.Award_number,
6381 a.Award_short_name,
6382 a.award_id
6383 from
6384 GMS_AWARDS a
6385 where
6386 a.Award_Project_Id = X_Project_Id;
6387
6388 /* Fetch Variables for GET_INSTALLMENTS */
6389 C_Installment_Id NUMBER(15);
6390 C_Start_Date_Active DATE;
6391 C_End_Date_Active DATE;
6392
6393 X_Labor_Sel_Grp_Diff_Ind Mark_Sel_Grp_Diff_Array;
6394 X_Lbr_Rt_Jstfy_Flag Mark_Sel_Grp_Diff_Array;
6395 X_Lbr_Padding_Length Padding_Length_Array;
6396 X_Lbr_Text_Array Free_Text_Array;
6397 X_Lbr_Cnt_Of_Columns_Selected NUMBER(3) := 0;
6398 X_LABOR_CONCAT_SELECT VARCHAR2(2000);
6399 X_LABOR_CONCAT_FROM VARCHAR2(2000);
6400 X_LABOR_CONCAT_WHERE VARCHAR2(2000);
6401 X_LABOR_CONCAT_ORDERBY VARCHAR2(2000);
6402 X_LABOR_ORDERBY_IS_NULL VARCHAR2(1);
6403
6404 X_Non_Labor_Sel_Grp_Diff_Ind Mark_Sel_Grp_Diff_Array;
6405 X_Nlbr_Rt_Jstfy_Flag Mark_Sel_Grp_Diff_Array;
6406 X_Nlbr_Padding_Length Padding_Length_Array;
6407 X_Nlbr_Text_Array Free_Text_Array;
6408 X_Nlbr_Cnt_Of_Columns_Selected NUMBER(3) := 0;
6409 X_NON_LABOR_CONCAT_SELECT VARCHAR2(2000);
6410 X_NON_LABOR_CONCAT_FROM VARCHAR2(2000);
6411 X_NON_LABOR_CONCAT_WHERE VARCHAR2(2000);
6412 X_NON_LABOR_CONCAT_ORDERBY VARCHAR2(2000);
6413 X_NON_LABOR_ORDERBY_IS_NULL VARCHAR2(1);
6414 /* Following two variables added for bug 3523930 */
6415 X_LABOR_tsk_lvl_fmt VARCHAR2(1) :='N';
6416 X_NON_LABOR_tsk_lvl_fmt VARCHAR2(1) :='N';
6417
6418 X_Format_Specific_Where VARCHAR2(2000) := NULL;
6419 X_Fixed_Select VARCHAR2(2000) := NULL;
6420 X_Fixed_Where VARCHAR2(2000) := NULL;
6421 X_Fixed_From VARCHAR2(2000) := NULL;
6422
6423 X_Class_Category VARCHAR2(30) := NULL;
6424 X_Carrying_Out_Org_Id NUMBER(15);
6425 X_Rev_Carrying_Out_Org_Id NUMBER(15);
6426
6427 X_Sponsored_Type_Flag VARCHAR2(1);
6428 X_Project_Type VARCHAR2(30);
6429
6430 X_Trx_Type VARCHAR2(15);
6431
6432 X_Period_Status VARCHAR2(1);
6433
6434 X_Err_Num NUMBER;
6435 X_Err_Stage VARCHAR2(200);
6436
6437 x_pa_err_msg VARCHAR2(2000);
6438 x_pa_status NUMBER;
6439
6440 St_Err_Code NUMBER(1);
6441 St_Err_Buff Varchar2(2000);
6442
6443 X_award_number VARCHAR2(15);--For bug 1744641
6444 X_award_name varchar2(250);--For bug 1744641
6445 X_awd_id NUMBER;
6446
6447 /* bug 5242484 - start */
6448 k NUMBER := 0;
6449 x_tot_inst_count NUMBER := 0;
6450 /* bug 5242484 - end */
6451
6452 f_dummy NUMBER := 0 ;--For Bug 5026657
6453
6454 X_Position Number(3);
6455
6456 -- ##This is to process awards that has no expenditures to process
6457 NO_EXP_TO_PROCESS Exception;
6458
6459 Begin
6460
6461 SAVEPOINT AWARD_BILLING_BEGIN; -- Added for bug 4243374
6462 gms_error_pkg.set_debug_context; -- Added for Bug: 2510024
6463
6464 -- Code added for bug 1744641
6465 open GMS_AWARDS_CURSOR;
6466 Fetch gms_awards_cursor into X_award_number,X_award_name, x_awd_id;
6467 Close GMS_AWARDS_CURSOR;
6468 --End of the Code added for bug 1744641
6469
6470 /* GMS INSTALLATION CHECK */
6471 If gms_install.enabled then
6472
6473 IF L_DEBUG = 'Y' THEN
6474 gms_error_pkg.gms_debug('GMS INSTALLED -- START AWARD BILLING FOR Award Project:','C');
6475 gms_error_pkg.gms_debug('X_Project_id:'||X_Project_id,'C');
6476 END IF;
6477
6478 -- Bug 1980810 : Added to set currency related global variables
6479 -- Call to pa_currency.round_currency_amt function will use
6480 -- global variables and thus improves performance
6481
6482 pa_currency.set_currency_info;
6483
6484 -- Concurrency Control
6485 gms_bill_concurrency(X_request_id,
6486 X_Project_id,
6487 St_Err_Code,
6488 St_Err_Buff);
6489 IF L_DEBUG = 'Y' THEN
6490 gms_error_pkg.gms_debug('After gms_bill_concurrency x_error_code :'||St_Err_Code,'C');
6491 END IF;
6492
6493 If St_Err_Code <> 0 then
6494 gms_error_pkg.gms_message('GMS_BILLING_CONCURRENCY',
6495 'PRJ',
6496 X_Project_id,
6497 X_Exec_Type => 'C',
6498 X_Err_Code => St_Err_Code,
6499 X_Err_Buff => St_Err_Buff);
6500
6501 Raise NO_PROCESSING_OF_AWARD ;
6502
6503 End if;
6504
6505 /*-------------------------------------------------------------------------
6506 || Following Begin ... End code has been added for concurrency control.
6507 || If a user is updating any billing related data, billing process should
6508 || not run for that award. Corollary: If billing process is running for an
6509 || award, users should not be able to update any billing data on the award
6513 -- ## Code change starts here for Bug 1652198....
6510 || form. Bug 1652198.....
6511 || Procedure: lock_award_records created for this.
6512 ------------------------------------------------------------------------- */
6514 /**FOr Bug 4506225 :MOved the code after the call to GMS_TAX
6515 lock_award_records(X_Project_id,
6516 St_Err_Code,
6517 St_Err_Buff);
6518
6519 IF L_DEBUG = 'Y' THEN
6520 gms_error_pkg.gms_debug('After lock_award_records St_Err_Code :'||St_Err_Code,'C');
6521 END IF;
6522
6523 If St_Err_Code <> 0 then
6524 gms_error_pkg.gms_message('GMS_BILLING_CONCURRENCY',
6525 'PRJ',
6526 X_Project_id,
6527 X_Exec_Type => 'C',
6528 X_Err_Code => St_Err_Code,
6529 X_Err_Buff => St_Err_Buff);
6530
6531 Raise NO_PROCESSING_OF_AWARD ;
6532
6533 End if;
6534 ---End of moving of code for bug 4506225*/
6535 -- ## Code change ends here for Bug 1652198....
6536
6537
6538 -- Process failure rollback
6539 billing_rollback(X_Project_id,
6540 --X_calling_process,
6541 NULL, -- event_num
6542 St_Err_Code,
6543 St_Err_Buff);
6544
6545 IF L_DEBUG = 'Y' THEN
6546 gms_error_pkg.gms_debug('After billing_rollback x_error_code :'||St_Err_Code,'C');
6547 END IF;
6548
6549 If St_Err_Code <> 0 then
6550 gms_error_pkg.gms_message('GMS_BILLING_ROLLBACK_FAILURE',
6551 'PRJ',
6552 X_Project_id,
6553 X_Exec_Type => 'C',
6554 X_Err_Code => St_Err_Code,
6555 X_Err_Buff => St_Err_Buff);
6556 Raise ROLLBACK_FAILURE;
6557
6558 End if;
6559
6560 -- This function check was done for performance reasons
6561 -- If there are no transactions to be processed, RETURN from this process.
6562 -- We're filtering by bare minimum conditions only.
6563
6564 IF NOT IS_PROCESSING_REQD(X_Calling_Process , X_Awd_Id ) THEN
6565
6566 IF L_DEBUG = 'Y' THEN
6567 gms_error_pkg.gms_debug('No records to process - NOT IS_PROCESSING_REQD :'||St_Err_Code,'C');
6568 END IF;
6569 RAISE NO_EXP_TO_PROCESS;
6570 -- NO recored for processing, we raising an exception to cleanup GMS processing
6571
6572 END IF;
6573
6574
6575 /* Selecting the Project Type. GO THROUGH BILL_EXTENSION only if
6576 Project_Type = 'AWARD_PROJECT'
6577 */
6578 Begin
6579 Select
6580 project_type,
6581 carrying_out_organization_id --This is being selected again here because Revenue
6582 into --doesn't have access to GET_FORMAT_SELECT
6583 X_Project_Type,
6584 X_Rev_Carrying_Out_Org_Id
6585 from
6586 PA_PROJECTS_ALL
6587 where
6588 project_id = X_Project_Id;
6589
6590 EXCEPTION
6591 WHEN OTHERS THEN
6592 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
6593 'SQLCODE',
6594 SQLCODE,
6595 'SQLERRM',
6596 SQLERRM,
6597 X_Exec_Type => 'C',
6598 X_Err_Code => St_Err_Code,
6599 X_Err_Buff => St_Err_Buff);
6600 --RAISE_APPLICATION_ERROR(-20526,St_Err_Buff);
6601 Raise NO_PROCESSING_OF_AWARD ;
6602 --RETURN;
6603
6604 End;
6605
6606 IF L_DEBUG = 'Y' THEN
6607 gms_error_pkg.gms_debug('Project Type is :'||X_Project_Type,'C');
6608 END IF;
6609
6610 /* ===============================================================================
6611 || Code for period validation has been commented out.
6612 || bug number: 1510848, release 11.5D
6613 =============================================================================== */
6614
6615 If X_Project_Type = 'AWARD_PROJECT' then --
6616
6617 -- Selecting the Class Category--
6618 Begin
6619 select
6620 cc.class_category
6621 into
6622 X_Class_Category
6623 from
6624 pa_class_categories cc
6625 where
6626 sysdate between cc.start_date_active and
6627 nvl(cc.end_date_active,SYSDATE + 1) and
6628 cc.autoaccounting_flag = 'Y';
6629 EXCEPTION
6630 WHEN NO_DATA_FOUND THEN
6631 X_Class_Category := NULL;
6632 End;
6633
6634 IF L_DEBUG = 'Y' THEN
6635 gms_error_pkg.gms_debug('After Class Category select','C');
6636 END IF;
6637
6638 Begin
6639 select
6640 a.Award_Id,
6641 a.Revenue_Distribution_Rule,
6642 a.Billing_Distribution_Rule,
6643 a.Status,
6644 -- ag.Revenue_Limit_Flag -- Bug 1841288
6645 nvl(a.hard_limit_flag,'N') -- Bug 1841288 : Taken hard_limit_flag from gms_awards instead of pa_agreements_all
6646 ,nvl(a.invoice_limit_flag,'N') -- Bug 6642901
6647 into
6648 X_Award_Id, -- Adding this because Revenue Process doesnot have access to GET_FORMAT_SELECT proc.
6649 X_Award_Rev_Distribution_Rule,
6650 X_Award_Bill_Distribution_Rule,
6651 X_Award_Status,
6652 X_Revenue_Limit_Flag,
6653 X_Invoice_limit_Flag -- Bug 6642901
6654 from
6655 GMS_AWARDS a
6659 -- and a.agreement_id = ag.agreement_id; -- Bug 1841288 : Removed the join
6656 --PA_AGREEMENTS_ALL ag -- Bug 1841288 : Removed join from PA_AGREEMENTS_ALL Table
6657 where
6658 a.Award_Project_Id = X_Project_Id;
6660 End;
6661
6662 IF L_DEBUG = 'Y' THEN
6663 gms_error_pkg.gms_debug('Distribution Rule:Revenue:'||X_Award_Rev_Distribution_Rule,'C');
6664 gms_error_pkg.gms_debug('Distribution Rule:Invoice:'||X_Award_Bill_Distribution_Rule,'C');
6665 END IF;
6666
6667 --------------------------------------------------------------------------------------------------------- +
6668 -- Bug 3143102 : Following code takes care of the scenario where the labor and/or non-labor format
6669 -- has an invalid element ..
6670 If (X_calling_process = 'Invoice' and X_Award_Bill_Distribution_Rule = 'COST') THEN
6671
6672 IF NOT Is_Invoice_Format_Valid(X_project_id,NULL,NULL,'BILLING_PROCESS') THEN
6673
6674 IF L_DEBUG = 'Y' THEN
6675 gms_error_pkg.gms_debug('Labor/Non-Labor format is Invalid','C');
6676 END IF;
6677
6678 RAISE INVALID_INVOICE_FORMAT;
6679
6680 End If;
6681
6682 End If;
6683
6684 IF L_DEBUG = 'Y' THEN
6685 gms_error_pkg.gms_debug('Labor/Non-Labor format is Valid','C');
6686 END IF;
6687 --------------------------------------------------------------------------------------------------------- +
6688
6689 -- CALL TAX UPDATION PROCEDURE
6690
6691 gms_tax(X_Project_Id,
6692 X_Award_Id,
6693 X_Rev_Or_Bill_Date,
6694 X_Request_Id,
6695 St_Err_Code,
6696 St_Err_Buff
6697 );
6698
6699 If St_Err_Code <> 0 then
6700 --ROLLBACK;
6701 --RAISE FND_API.G_EXC_ERROR;
6702 --Raise NO_PROCESSING_OF_AWARD ;--4506225
6703 Raise GMS_TAX_FAILURE; --4506225
6704 End If;
6705
6706 IF L_DEBUG = 'Y' THEN
6707 gms_error_pkg.gms_debug('After tax, x_error_code :'||St_Err_Code,'C');
6708 END IF;
6709 --For Bug 4506225 :Moved the code after gms_Tax
6710 lock_award_records(X_Project_id,
6711 St_Err_Code,
6712 St_Err_Buff);
6713
6714 IF L_DEBUG = 'Y' THEN
6715 gms_error_pkg.gms_debug('After lock_award_records St_Err_Code :'||St_Err_Code,'C');
6716 END IF;
6717
6718 If St_Err_Code <> 0 then
6719 gms_error_pkg.gms_message('GMS_BILLING_CONCURRENCY',
6720 'PRJ',
6721 X_Project_id,
6722 X_Exec_Type => 'C',
6723 X_Err_Code => St_Err_Code,
6724 X_Err_Buff => St_Err_Buff);
6725
6726 Raise NO_PROCESSING_OF_AWARD ;
6727
6728 End if;
6729 --End of bug fix for Bug 4506225
6730 --commit;
6731
6732 If X_Award_Status in ('ACTIVE','ON_HOLD') then -- Do processing only if Award Status is Active
6733
6734 --UPDATE_PROJECT_MANAGER(X_Project_Id,X_Award_Id);
6735 /* Stopped updating in billing process because now onwards GMS
6736 will update project manager through award form only to fix bug 1907565 gnema*/
6737
6738 -- Bug 3235390 : Intializing the variables used .
6739 x_temp_negative_evt_num := -1000;
6740
6741 IF (
6742 -- (X_calling_process = 'Revenue' and X_Award_Rev_Distribution_Rule = 'COST') OR
6743 (X_calling_process = 'Invoice' and X_Award_Bill_Distribution_Rule = 'COST')
6744 ) then -- Check for Billing Distribution Rule
6745 Begin
6746
6747 GET_FORMAT_SELECT(X_Project_Id,
6748 X_Award_Id,
6749 X_Carrying_Out_Org_Id,
6750 X_Labor_Sel_Grp_Diff_Ind,
6751 X_Non_Labor_Sel_Grp_Diff_Ind,
6752 X_Lbr_Cnt_Of_Columns_Selected,
6753 X_Nlbr_Cnt_Of_Columns_Selected,
6754 X_Lbr_Rt_Jstfy_Flag,
6755 X_Nlbr_Rt_Jstfy_Flag,
6756 X_Lbr_Padding_Length,
6757 X_Nlbr_Padding_Length,
6758 X_Lbr_Text_Array,
6759 X_Nlbr_Text_Array,
6760 X_LABOR_CONCAT_SELECT,
6761 X_LABOR_CONCAT_FROM,
6762 X_LABOR_CONCAT_WHERE,
6763 X_LABOR_CONCAT_ORDERBY,
6764 X_LABOR_ORDERBY_IS_NULL,
6765 X_NON_LABOR_CONCAT_SELECT,
6766 X_NON_LABOR_CONCAT_FROM,
6767 X_NON_LABOR_CONCAT_WHERE,
6768 X_NON_LABOR_CONCAT_ORDERBY,
6769 X_NON_LABOR_ORDERBY_IS_NULL,
6770 X_LABOR_tsk_lvl_fmt, /* added for bug 3523930 */
6771 X_NON_LABOR_tsk_lvl_fmt, /* added for bug 3523930 */
6772 X_Err_Num,
6773 X_Err_Stage);
6774
6775 --dbms_output.put_line('After GET_FORMAT_SELECT Proc '||'Award Id '||to_char(X_Award_Id) );
6776
6777 IF L_DEBUG = 'Y' THEN
6778 gms_error_pkg.gms_debug('After Format Selection','C');
6779 END IF;
6780
6781
6782 sql_select := 'select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)*/ ';
6783 sql_from := 'from ';
6784 sql_where := 'where ';
6785 X_Fixed_Select := ' adl.raw_cost, ei.expenditure_item_id, ei.expenditure_item_date, ei.task_id,
6786 ei.bill_hold_flag, adl.billable_flag, ei.adjusted_expenditure_item_id, adl.adl_line_num,adl.parent_adl_line_num,
6790
6787 adl.adl_status, adl.award_id, adl.project_id, adl.cdl_line_num,ei.expenditure_type,
6788 nvl(ei.override_to_organization_id,e.incurred_by_organization_id),adl.ind_compiled_Set_id,adl.burdenable_raw_cost,
6789 ei.transaction_source '; --bug 2909746
6791 X_Fixed_From := 'pa_expenditure_items_all ei ,pa_expenditures_all e, pa_expenditure_types et,'
6792 ||' pa_projects_all p, pa_project_types pt,'
6793 ||' pa_tasks t3, pa_tasks t5, gms_award_distributions adl ';
6794
6795 /* --- 11.5 changes --- */
6796 --1. gms_award_distributions added in the from clause
6797 --2. 4 new columns being selected from gms_award_distributions, raw_cost picked differently
6798
6799
6800 /* The DYNAMIC WHERE CLAUSE BUILDING below for Revenue is NOT USED any more. Replaced by the Procedure
6801 REVENUE_ACCRUAL
6802 */
6803 If X_calling_process = 'Revenue' then
6804
6805 null;
6806
6807 Elsif X_calling_process = 'Invoice' then
6808
6809 /* --- 11.5 Changes ---
6810 -- 1.Columns like billed_flag,award_id, revenue_distributed_flag being picked from gms_award_distributions
6811 -- 2.Column attribute2 IS NULL changed to adl.document_type <>'ENC'
6812 -- 3.condtions to join gms_award_distributions and pa_expenditure_items_all added
6813 -- 4.check for adl lines with adl status <> 'I'
6814 */
6815
6816 X_Fixed_Where := ' adl.award_id = :X_Award_Id '
6817 ||'and ei.expenditure_item_id = adl.expenditure_item_id '
6818 ||'and adl.adl_status <> ''I'' '
6819 ||'and ei.system_linkage_function <> ''BTC'' '
6820 ||'and p.project_status_code <> ''CLOSED'' '
6821 ||'and pt.project_type = p.project_type '
6822 ||'and pt.direct_flag = ''N'' '
6823 ||'and t3.project_id = p.project_id ' --Changed t to t2, then changed t2 to t3 to get rid or ORA-09118
6824 ||'and ei.task_id = t3.task_id '
6825 ||'and t3.top_task_id = t5.task_id '
6826 ||'and t5.ready_to_bill_flag = ''Y'' '
6827 ||'and ((adl.line_num_reversed is null and adl.reversed_flag is null and ei.cost_distributed_flag = ''Y'') '
6828 ||' or ((adl.line_num_reversed is not null or adl.reversed_flag is not null) and adl.cost_distributed_flag = ''Y''))' -- Bug 1852802
6829 ||'and nvl(ei.bill_hold_flag,''N'') = ''N'' '
6830 ||'and ei.expenditure_item_date <= nvl(trunc(:X_rev_or_bill_date),SYSDATE) '
6831 ||'and trunc(ei.expenditure_item_date) <= trunc(:C_End_Date_Active) '
6832 ||'and nvl(adl.billed_flag,''N'') <> ''Y'' ' -- To pick up items where Billed Flag <> 'Y'
6833 ||'and ei.expenditure_type = et.expenditure_type '
6834 ||'and e.expenditure_id = ei.expenditure_id '
6835 ||'and adl.fc_status = ''A'' '
6836 ||'and adl.adl_status = ''A'' '
6837 ||'and nvl(adl.billable_flag,''N'') = ''Y'' '
6838 ||'and adl.document_type = ''EXP'' '
6839 ||'and exists '
6840 ||'(select 1 '
6841 ||'from gms_summary_project_fundings gspf '
6842 ||'where gspf.installment_id = :C_Installment_Id '
6843 ||'and ( '
6844 ||' (gspf.task_id = adl.task_id) '
6845 ||'OR (gspf.task_id is NULL) '
6846 ||'OR (gspf.task_id = (select t1.top_task_id from pa_tasks t1 where t1.task_id = adl.task_id)) '
6847 ||' ) '
6848 ||'and gspf.project_id = adl.project_id '
6849 ||') ';
6850
6851 End If;
6852
6853 /* bug 5242484 - start */
6854 select count(*)
6855 into x_tot_inst_count
6856 from gms_installments
6857 where award_id = X_Award_id
6858 /* and active_flag = 'Y' bug 6878405 */
6859 and nvl(billable_flag,'N') = 'Y';
6860
6861 FOR k in 1..x_tot_inst_count LOOP
6862 X_ei_rollback_inst_tab(k).rev_bill_amount := 0;
6863 X_ei_rollback_inst_tab(k).installment_id := 0;
6864 END LOOP;
6865 /* bug 5242484 - end */
6866
6867 ------------------------------------------------------------------
6868 /* Opening the Cursor to Process each Installment of this Award (For INVOICE Processing) */
6869 ------------------------------------------------------------------
6870 OPEN GET_INSTALLMENTS;
6871 BEGIN
6872 LOOP
6873 FETCH GET_INSTALLMENTS into
6874 C_Installment_Id,
6875 C_Start_Date_Active,
6876 C_End_Date_Active;
6877
6878
6879 EXIT WHEN GET_INSTALLMENTS%NOTFOUND;
6880
6881
6882 -- BUG 3235390 : Deleting data from gms_events_temp_format
6883 DELETE gms_events_temp_format;
6884
6885 /* For bug 5026657 */
6886 f_dummy := 0;
6887
6888 WHILE f_dummy<2 LOOP /* dummy loop for re-processing , bug 5026657 */
6889
6890 f_dummy := f_dummy + 1;
6891
6892
6893 IF L_DEBUG = 'Y' THEN
6894 gms_error_pkg.gms_debug('In installment loop, Installment_Id :'||C_Installment_Id,'C');
6895 END IF;
6896
6897 /*============================================================================================*/
6898 /* Processing Begins here for the rows which have expenditure type which are LABOR related */
6899 /*==============================================================================================*/
6900 X_Format_Specific_Where := 'and ei.system_linkage_function in (''ST'',''OT'') ';
6901 sql_select := sql_select||X_LABOR_CONCAT_SELECT;
6902 sql_select := sql_select||X_Fixed_Select;
6903
6904 sql_from := sql_from||X_LABOR_CONCAT_FROM;
6905 sql_from := sql_from||X_Fixed_From;
6906
6907 sql_where := sql_where||X_LABOR_CONCAT_WHERE;
6908 sql_where := sql_where||X_Fixed_Where;
6909 sql_where := sql_where||X_Format_Specific_Where;
6910
6911 /* ------ GROUP BY CHANGES ------- */
6912 select instr(UPPER(X_LABOR_CONCAT_SELECT),'SUM',1,1)
6916 if x_position=0 then
6913 into X_position
6914 from dual;
6915
6917 sql_orderby := ' order by ';
6918 elsif x_position >0 then
6919 sql_orderby := ' group by ';
6920 end if;
6921 /* ------ GROUP BY CHANGES ------- */
6922
6923 -- Bug 3235390 : Modified the order by clause
6924 l_sql_orderby :=' DECODE( NVL(ei.net_zero_adjustment_flag,'||''''||'N'||''''||'),'||''''||'N' ||''''||
6925 ', NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||',ei.expenditure_item_id)),'
6926 ||''''||'Y'||''''||', DECODE(SIGN(NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
6927 ||''''||'Invoice'||''''||',ei.expenditure_item_id))),'
6928 ||'1,-NVL(ei.raw_Cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||
6929 ',ei.expenditure_item_id)),' ||' NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
6930 ||''''||'Invoice'||''''||',ei.expenditure_item_id)))),'
6931 || 'NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''
6932 ||',ei.expenditure_item_id)),NVL(ei.adjusted_expenditure_item_id,ei.expenditure_item_id),'
6933 || 'adl.raw_cost, adl.cdl_line_num';
6934
6935
6936 if x_position=0 then
6937 sql_orderby := sql_orderby || l_sql_orderby ||',';
6938 elsif x_position >0 then
6939 sql_orderby := sql_orderby || ' ei.raw_cost,adl.raw_cost, ei.net_zero_adjustment_flag, ';
6940 end if;
6941
6942 -- Bug 1652198, moved format order by first.
6943 sql_orderby := sql_orderby || X_LABOR_CONCAT_ORDERBY;
6944
6945 --sql_orderby := sql_orderby||' adl.output_vat_tax_id, adl.output_tax_exempt_flag, adl.output_tax_exempt_number, adl.output_tax_exempt_reason_code ';
6946 sql_orderby := sql_orderby||' adl.output_tax_classification_code, adl.output_tax_exempt_flag, adl.output_tax_exempt_number, adl.output_tax_exempt_reason_code ';
6947
6948 --Bug 2909746 : Added cdl_line_num in the order by clause
6949
6950 If X_LABOR_ORDERBY_IS_NULL = 'N' then
6951
6952 sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
6953
6954 Elsif X_LABOR_ORDERBY_IS_NULL = 'Y' then
6955
6956 sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
6957
6958 End If;
6959
6960 -- 11.5 Change, Added adl.adl_line_num in the order by clause
6961
6962 /* ------ GROUP BY CHANGES ------- */
6963 if x_position >0 then
6964 sql_orderby := sql_orderby||' , ei.expenditure_item_date '||
6965 ', ei.task_id,ei.bill_hold_flag, adl.billable_flag, ei.adjusted_expenditure_item_id, '||
6966 ' adl.parent_adl_line_num, adl.adl_status, adl.award_id, adl.project_id, '||
6967 'ei.expenditure_type,nvl(ei.override_to_organization_id,e.incurred_by_organization_id),'||
6968 ' adl.ind_compiled_Set_id, adl.burdenable_raw_cost, ei.transaction_source';
6969 end if;
6970
6971 /* ------ GROUP BY CHANGES ------- */
6972
6973 For i in 1..X_Lbr_Cnt_Of_Columns_Selected LOOP
6974 null;
6975 --dbms_output.put_line('Column :'||X_Labor_Sel_Grp_Diff_Ind(i));
6976 END LOOP;
6977 For i in 1..X_Nlbr_Cnt_Of_Columns_Selected LOOP
6978 null;
6979 --dbms_output.put_line('Column :'||X_Non_Labor_Sel_Grp_Diff_Ind(i));
6980 END LOOP;
6981
6982 -- Bug 3235390 : Modified the below logic to introduce new order by clause
6983 -- sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ;
6984 IF x_position=0 THEN
6985 sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ;
6986 ELSIF x_position >0 THEN
6987 sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ||' order by ' || l_sql_orderby ;
6988 END IF;
6989
6990
6991 --dbms_output.put_line('Processing LABOR Transactions ');
6992
6993 IF L_DEBUG = 'Y' THEN
6994 gms_error_pkg.gms_debug('Before FORMAT_SPECIFIC_BILLING call','C');
6995
6996 END IF;
6997
6998 /* bug 5413530 */
6999 X_Trans_type := 'LABOR';
7000 IF ( f_dummy = 2 ) THEN G_trans_type := 'LABOR';
7001 END IF;
7002
7003 FORMAT_SPECIFIC_BILLING(X_Project_Id,
7004 X_Award_Id,
7005 X_Class_Category,
7006 X_rev_or_bill_date,
7007 -- X_Revenue_Limit_Flag,
7008 X_Invoice_Limit_Flag, /* for bug 6642901*/
7009 X_request_id,
7010 X_Labor_Sel_Grp_Diff_Ind,
7011 X_Lbr_Cnt_Of_Columns_Selected,
7012 X_Lbr_Rt_Jstfy_Flag,
7013 X_Lbr_Padding_Length,
7014 X_Lbr_Text_Array,
7015 sql_select,
7016 X_Carrying_Out_Org_Id,
7017 X_calling_process,
7018 X_LABOR_tsk_lvl_fmt, /* added for bug 3523930 */
7019 C_Installment_Id,
7020 C_Start_Date_Active,
7021 C_End_Date_Active,
7022 X_Err_Num,
7023 X_Err_Stage,
7024 'LABOR', /* added for bug 5026657 */
7025 f_labor_exp_to_process, /* added for bug 5026657 */
7026 f_non_labor_neg_exp_processed); /* added for bug 5026657 */
7027
7028 g_labor_exp_to_process := f_labor_exp_to_process;
7029
7030 /*======================================================================================*/
7034 sql_from := 'from ';
7031 /* Processing begins here for rows which have Expenditure Types which are NON-LABOR related */
7032 /*=======================================================================================*/
7033 sql_select := 'select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)*/ ';
7035 sql_where := 'where ';
7036 X_Format_Specific_Where := 'and ei.system_linkage_function not in (''ST'',''OT'') ';
7037 sql_select := sql_select||X_NON_LABOR_CONCAT_SELECT;
7038 sql_select := sql_select||X_Fixed_Select;
7039
7040 sql_from := sql_from||X_NON_LABOR_CONCAT_FROM;
7041 sql_from := sql_from||X_Fixed_From;
7042
7043 sql_where := sql_where||X_NON_LABOR_CONCAT_WHERE;
7044 sql_where := sql_where||X_Fixed_Where;
7045 sql_where := sql_where||X_Format_Specific_Where;
7046
7047 /* ------ GROUP BY CHANGES ------- */
7048
7049 x_position := 0;
7050
7051 select instr(UPPER(X_NON_LABOR_CONCAT_SELECT),'SUM',1,1)
7052 into X_position
7053 from dual;
7054
7055 if x_position=0 then
7056 sql_orderby := ' order by ';
7057 elsif x_position >0 then
7058 sql_orderby := ' group by ';
7059 end if;
7060 /* ------ GROUP BY CHANGES ------- */
7061
7062 -- Bug 3235390 : Modified the order by clause
7063 l_sql_orderby := ' DECODE( NVL(ei.net_zero_adjustment_flag,'||''''||'N'||''''||'),'||''''||'N' ||''''||
7064 ', NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||',ei.expenditure_item_id)),'
7065 ||''''||'Y'||''''||', DECODE(SIGN(NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
7066 ||''''||'Invoice'||''''||',ei.expenditure_item_id))),'
7067 ||'1,-NVL(ei.raw_Cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||
7068 ',ei.expenditure_item_id)),' ||' NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
7069 ||''''||'Invoice'||''''||',ei.expenditure_item_id)))),'
7070 || 'NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''
7071 ||',ei.expenditure_item_id)),NVL(ei.adjusted_expenditure_item_id,ei.expenditure_item_id),'
7072 || 'adl.raw_cost, adl.cdl_line_num';
7073
7074
7075 if x_position=0 then
7076 sql_orderby := sql_orderby ||l_sql_orderby||',' ;
7077 elsif x_position >0 then
7078 sql_orderby := sql_orderby || ' ei.raw_cost,adl.raw_cost, ei.net_zero_adjustment_flag, ';
7079 end if;
7080
7081 -- Bug 1652198, moved format order by first.
7082 sql_orderby := sql_orderby || X_NON_LABOR_CONCAT_ORDERBY;
7083
7084
7085 --sql_orderby := sql_orderby||' adl.output_vat_tax_id, adl.output_tax_exempt_flag, adl.output_tax_exempt_number, adl.output_tax_exempt_reason_code ';
7086
7087 sql_orderby := sql_orderby||' adl.output_tax_classification_code, adl.output_tax_exempt_flag, adl.output_tax_exempt_number, adl.output_tax_exempt_reason_code ';
7088
7089 --Bug 2909746 : Added cdl_line_num in the order by clause
7090 If X_NON_LABOR_ORDERBY_IS_NULL = 'N' then
7091
7092 sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
7093
7094 Elsif X_NON_LABOR_ORDERBY_IS_NULL = 'Y' then
7095
7096 sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
7097
7098 End If;
7099
7100 -- 11.5 Change, Added adl.adl_line_num in the order by clause
7101
7102 /* ------ GROUP BY CHANGES ------- */
7103 if x_position >0 then
7104 sql_orderby := sql_orderby||' , ei.expenditure_item_date '||
7105 ', ei.task_id,ei.bill_hold_flag, adl.billable_flag, ei.adjusted_expenditure_item_id, '||
7106 ' adl.parent_adl_line_num, adl.adl_status, adl.award_id, adl.project_id, '||
7107 'ei.expenditure_type,nvl(ei.override_to_organization_id,e.incurred_by_organization_id),'||
7108 ' adl.ind_compiled_Set_id, adl.burdenable_raw_cost, ei.transaction_source';
7109 end if;
7110
7111 /* ------ GROUP BY CHANGES ------- */
7112
7113 -- Bug 3235390 : Modified the below logic to introduce new order by clause
7114
7115 IF x_position=0 THEN
7116 sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ;
7117 ELSIF x_position >0 THEN
7118 sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby || ' Order By '||l_sql_orderby ;
7119 END IF;
7120
7121 --dbms_output.put_line('Processing NON LABOR Transactions ');
7122
7123 /* bug 5413530 */
7124 X_Trans_type := 'NON-LABOR';
7125
7126 FORMAT_SPECIFIC_BILLING(X_Project_Id,
7127 X_Award_Id,
7128 X_Class_Category,
7129 X_rev_or_bill_date,
7130 -- X_Revenue_Limit_Flag,
7131 X_Invoice_Limit_Flag, /* for bug 6642901 */
7132 X_request_id,
7133 X_Non_Labor_Sel_Grp_Diff_Ind,
7134 X_Nlbr_Cnt_Of_Columns_Selected,
7135 X_Nlbr_Rt_Jstfy_Flag,
7136 X_Nlbr_Padding_Length,
7137 X_Nlbr_Text_Array,
7138 sql_select,
7139 X_Carrying_Out_Org_Id,
7140 X_calling_process,
7141 X_NON_LABOR_tsk_lvl_fmt, /* added for bug 3523930 */
7142 C_Installment_Id,
7143 C_Start_Date_Active,
7144 C_End_Date_Active,
7145 X_Err_Num,
7146 X_Err_Stage,
7147 'NON LABOR', /* added for bug 5026657 */
7148 f_labor_exp_to_process, /* added for bug 5026657 */
7152
7149 f_non_labor_neg_exp_processed); /* added for bug 5026657 */
7150
7151 g_non_labor_neg_exp_processed := f_non_labor_neg_exp_processed ;
7153 -------------------------------------------------------------------------
7154 sql_select := 'select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)*/ '; -- Bug 2380344 : Hardcoded Index for Performance Fix
7155 sql_from := 'from ';
7156 sql_where := 'where ';
7157
7158 /* Added for bug 5026657 */
7159 IF (g_labor_exp_to_process = 'Y' and g_non_labor_neg_exp_processed = 'Y') THEN
7160 g_process_again := 'Y';
7161 ELSE
7162 g_process_again := 'N';
7163 END IF;
7164
7165 IF L_DEBUG = 'Y' THEN
7166 gms_error_pkg.gms_debug('f_dummy is '||f_dummy,'C');
7167 gms_error_pkg.gms_debug('g_process_again is '||g_process_again,'C');
7168 gms_error_pkg.gms_debug('g_labor_exp_to_process is '||g_labor_exp_to_process,'C');
7169 gms_error_pkg.gms_debug('g_non_labor_neg_exp_processed is '||g_non_labor_neg_exp_processed,'C');
7170 END IF;
7171
7172 /* Added for bug 5026657 */
7173 /* Commented revenue limit flag condition and added invoice limit flag check for bug 6642901
7174 IF ( X_Revenue_Limit_Flag = 'N' OR
7175 ( X_Revenue_Limit_Flag = 'Y' AND g_process_again = 'N' ) ) THEN -- %%%%%%% */
7176
7177 IF ( X_Invoice_Limit_Flag = 'N' OR
7178 ( X_Invoice_Limit_Flag = 'Y' AND g_process_again = 'N' ) ) THEN
7179
7180 f_dummy := f_dummy + 1;
7181
7182 -- Bug 3235390 : Calling the CREATE_PA_EVENTS procedure to insert records in pa_events
7183 -- gms_event_attribute table from temporary table.
7184
7185 CREATE_PA_EVENTS (X_project_id ,
7186 X_Calling_Process ,
7187 X_rev_or_bill_Date ,
7188 X_Carrying_Out_Org_Id,
7189 X_Request_Id ,
7190 X_Installment_total,
7191 St_Err_Code,
7192 St_Err_Buff );
7193
7194 IF St_Err_Code <> 0 THEN
7195 raise NO_PROCESSING_OF_AWARD ;
7196 END IF;
7197
7198
7199 /* Moved this here from inside FORMAT_SPECIFIC_BILLING so that Burden for Labor and NonLabor appear together */
7200
7201 DO_BURDEN_EVENT_PROCESSING(X_Project_Id,
7202 X_rev_or_bill_Date,
7203 X_Calling_Process,
7204 X_Carrying_Out_Org_Id,
7205 X_Request_Id,
7206 X_Installment_total,
7207 St_Err_Code,
7208 St_Err_Buff);
7209 --C_Installment_Id);
7210
7211 If St_Err_Code <> 0 then
7212 --ROLLBACK;
7213 --RAISE FND_API.G_EXC_ERROR;
7214 Raise NO_PROCESSING_OF_AWARD ;
7215 End If;
7216
7217
7218 END IF ; -- end if for %%%%%%% , bug 5026657
7219
7220 END LOOP ; -- dummy loop of re-processing , bug 5026657
7221
7225 END LOOP;
7222 X_Installment_total.delete ; -- initalize installment_amount table for new installment
7223 X_Installment_tab.delete; -- initalize install_tab for new installment
7224
7226
7227 -- Update the expenditures with bill_hold_flag set to Once (before the process) to 'N'
7228
7229 One_Time_Bill_Hold(X_Project_Id,
7230 X_Award_Id,
7231 X_Rev_Or_Bill_Date,
7232 X_Request_Id,
7233 St_Err_Code,
7234 St_Err_Buff);
7235
7236 If St_Err_Code <> 0 then
7237
7238 --ROLLBACK;
7239 --RAISE FND_API.G_EXC_ERROR;
7240 Raise NO_PROCESSING_OF_AWARD ;
7241
7242 End if;
7243
7244 END;
7245 CLOSE GET_INSTALLMENTS;
7246
7247
7248 End;
7249
7250 --9999999999999999999999999999999999999999999
7251
7252 ElsIf (X_calling_process = 'Revenue' and X_Award_Rev_Distribution_Rule = 'COST') then -- Elsif for Billing_Distribution_Rule Check
7253
7254 --dbms_output.put_line('Got into New Revenue Process ');
7255
7256 ------------------------------------------------------------------
7257 /* Opening the Cursor to Process each Installment of this Award (For REVENUE Processing) */
7258 ------------------------------------------------------------------
7259 OPEN GET_INSTALLMENTS;
7260 BEGIN
7261 LOOP
7262 FETCH GET_INSTALLMENTS into
7263 C_Installment_Id,
7264 C_Start_Date_Active,
7265 C_End_Date_Active;
7266 EXIT WHEN GET_INSTALLMENTS%NOTFOUND;
7267
7268 IF L_DEBUG = 'Y' THEN
7269 gms_error_pkg.gms_debug('Revenue Process, In installment loop, installment :'||C_Installment_Id,'C');
7270 END IF;
7271
7272 f_dummy := 0 ; --For Bug 5026657
7273
7274 -- BUG 3235390 : Deleting data from gms_events_temp_format
7275 DELETE gms_events_temp_format;
7276
7277 WHILE f_dummy<2 LOOP /* dummy loop for re-processing , bug 5026657 */
7278
7279 f_dummy := f_dummy + 1;
7280
7281 IF L_DEBUG = 'Y' THEN
7282 gms_error_pkg.gms_debug('Entering dummy loop....f_dummy is '||f_dummy,'C');
7283 END IF;
7284
7285 /* Processing Labor Transactions */
7286 X_Trx_Type := 'LABOR';
7287
7288 REVENUE_ACCRUAL(X_Project_Id,
7289 X_Award_Id,
7290 X_Class_Category,
7291 X_rev_or_bill_date,
7292 X_Revenue_Limit_Flag,
7293 X_request_id,
7294 X_Rev_Carrying_Out_Org_Id,
7295 X_calling_process,
7296 X_Trx_Type,
7297 C_Installment_Id,
7298 C_Start_Date_Active,
7299 C_End_Date_Active,
7300 X_Err_Num,
7301 X_Err_Stage,
7302 f_labor_exp_to_process, /* Added for bug 5026657 */
7303 f_non_labor_neg_exp_processed); /* Added for bug 5026657 */
7304
7305 g_labor_exp_to_process := f_labor_exp_to_process ; /* Added for bug 5026657 */
7306
7307 /* Processing Non_Labor Transactions */
7308 X_Trx_Type := 'NON_LABOR';
7309
7310 REVENUE_ACCRUAL(X_Project_Id,
7311 X_Award_Id,
7312 X_Class_Category,
7313 X_rev_or_bill_date,
7314 X_Revenue_Limit_Flag,
7315 X_request_id,
7316 X_Rev_Carrying_Out_Org_Id,
7317 X_calling_process,
7318 X_Trx_Type,
7319 C_Installment_Id,
7320 C_Start_Date_Active,
7321 C_End_Date_Active,
7322 X_Err_Num,
7323 X_Err_Stage,
7324 f_labor_exp_to_process, /* Added for bug 5026657 */
7325 f_non_labor_neg_exp_processed); /* Added for bug 5026657 */
7326
7327 g_non_labor_neg_exp_processed := f_non_labor_neg_exp_processed ; /* Added for bug 5026657 */
7328
7329 -- Bug 3235390 : Calling the CREATE_PA_EVENTS procedure to insert records in pa_events
7330 -- gms_event_attribute table from temporary table.
7331
7332 /* Added for bug 5026657 */
7333 IF (g_labor_exp_to_process = 'Y' and g_non_labor_neg_exp_processed = 'Y') THEN
7334 g_process_again := 'Y';
7335 ELSE
7336 g_process_again := 'N';
7337 END IF;
7338
7339 /* Added for bug 5026657 */
7340 IF L_DEBUG = 'Y' THEN
7341 gms_error_pkg.gms_debug('f_dummy is '||f_dummy,'C');
7342 gms_error_pkg.gms_debug('g_process_again is '||g_process_again,'C');
7343 gms_error_pkg.gms_debug('g_labor_exp_to_process is '||g_labor_exp_to_process,'C');
7344 gms_error_pkg.gms_debug('g_non_labor_neg_exp_processed is '||g_non_labor_neg_exp_processed,'C');
7345 END IF;
7346
7347 /* Added for bug 5026657 */
7348 IF ( X_Revenue_Limit_Flag = 'N' OR
7349 ( X_Revenue_Limit_Flag = 'Y' AND g_process_again = 'N' ) ) THEN -- %%%%%%%
7350
7351 f_dummy := f_dummy + 1;
7352
7356 X_Rev_Carrying_Out_Org_Id,
7353 CREATE_PA_EVENTS (X_project_id ,
7354 X_Calling_Process ,
7355 X_rev_or_bill_Date ,
7357 X_Request_Id ,
7358 X_Rev_Installment_total,
7359 St_Err_Code,
7360 St_Err_Buff );
7361
7362 IF St_Err_Code <> 0 THEN
7363 raise NO_PROCESSING_OF_AWARD ;
7364 END IF;
7365
7366 /* Moved this here from inside REVENUE_ACCRUAL to club Labor and Nonlabor Burden together */
7367
7368 DO_BURDEN_EVENT_PROCESSING(X_Project_Id,
7369 X_rev_or_bill_Date,
7370 X_Calling_Process,
7371 X_Rev_Carrying_Out_Org_Id,
7372 X_Request_Id,
7373 X_Rev_Installment_total,
7374 St_Err_Code,
7375 St_Err_Buff);
7376
7377 If St_Err_Code <> 0 then
7378 Raise NO_PROCESSING_OF_AWARD ;
7379 End If;
7380
7381 --C_Installment_Id
7382
7383 END IF ; -- end if for %%%%%%% , bug 5026657
7384
7385 END LOOP ; -- dummy loop of re-processing , bug 5026657
7386
7387 X_Rev_Installment_total.delete ; -- initalize installment_amount table for new installment
7388 X_Rev_Installment_tab.delete; -- initalize install_tab for new installment
7389
7390 END LOOP;
7391
7392
7393 END;
7394 CLOSE GET_INSTALLMENTS;
7395
7396 End If; -- End If for Billing Distribution Rule Check
7397
7398 --999999999999999999999999999999999999999999
7399
7400 End If; -- End of If for check to see if Award Status is 'ACTIVE' or 'ON_HOLD'
7401
7402
7403 End If; -- End of If for Project_Type_Flag Check to see if it is 'AWARD_PROJECT'
7404
7405 -- Null Event Deletion ...
7406 /*******
7407 For bug 4957529
7408 If X_BURDEN_NULL_EVENT_PROCESSED OR
7409 X_REVRAW_NULL_EVENT_PROCESSED OR
7410 X_INVRAW_NULL_EVENT_PROCESSED then
7411
7412 DELETE_NULL_EVENTS (X_project_id,
7413 X_request_id,
7414 X_Calling_Process,
7415 St_Err_Code,
7416 St_Err_Buff);
7417
7418 End if;
7419 ****/
7420 -- Concurrency Control Code Starts
7421
7422 Begin
7423
7424 Delete
7425 from gms_concurrency_control
7426 where process_name = 'GMS_BLNG'
7427 and process_key = X_project_id;
7428
7429 Exception
7430
7431 When Others then
7432 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
7433 'SQLCODE',
7434 SQLCODE,
7435 'SQLERRM',
7436 SQLERRM,
7437 X_Exec_Type => 'C',
7438 X_Err_Code => St_Err_Code,
7439 X_Err_Buff => St_Err_Buff);
7440 Raise NO_PROCESSING_OF_AWARD ;
7441
7442 End;
7443
7444 -- Concurrency Control Code Ends
7445
7446 COMMIT; -- Commit to release locks on award and expenditures
7447
7448 End if; -- GMS INSTALLATION CHECK
7449
7450 IF L_DEBUG = 'Y' THEN
7451 gms_error_pkg.gms_debug('End Award Billing ','C');
7452 END IF;
7453
7454 Exception
7455 When NO_PROCESSING_OF_AWARD then
7456
7457 -- ## This exception is declared at the package level
7458 -- ## This exception is called from many procedures called by AWARD_BILLING
7459 -- ## It is only handled in this program
7460 -- ## When this exception is raised, all data for that award_project_id
7461 -- ## which has been modified or created is rolled back thus ensuring consistency
7462 -- ## Further processing for that award is ignored.
7463 -- Added for Bug 1744641: To Generate errors when an exception occurs
7464 -- during the process of generation of invoice/Revenue.
7465 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7466 gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7467 GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7468 End If;
7469 gms_error_pkg.gms_exception_lines_proc ( 'GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7470 'PRJ',
7471 x_calling_place,
7472 x_project_id ,
7473 x_award_number ,
7474 x_award_name );
7475
7476 -- End of the code added for bug 1744641
7477 IF L_DEBUG = 'Y' THEN
7478 gms_error_pkg.gms_debug('WHEN NO_PROCESSING_OF_AWARD - AWARD_BILLING','C');
7479 END IF;
7480 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7481 'PRJ',
7482 X_Project_id,
7483 X_Exec_Type => 'C',
7484 X_Err_Code => St_Err_Code,
7485 X_Err_Buff => St_Err_Buff);
7486
7487 -- ROLLBACK; -- If record not found , rollback to release lock --For Bug 4243374
7488 ROLLBACK to AWARD_BILLING_BEGIN; -- If record not found , rollback to release lock
7489 /* Rollback to Savepoint introduced instead of Rollback for bug 4243374 */
7490 RETURN;
7491
7495 -- ## This exception happens when Awards form is modifying billing related data
7492 When AWARD_DATA_LOCKED then
7493
7494 -- ## This exception is declared at the package level
7496 -- ## for the Award being processed.
7497 -- ## When this exception is raised, all data for that award_project_id
7498 -- ## which has been modified or created is rolled back thus ensuring consistency
7499 -- ## Further processing for that award is ignored.
7500 -- Added for Bug 1744641: To Generate errors when an exception occurs
7501 -- during the process of generation of invoice/Revenue.
7502 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7503 gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7504 GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7505 End If;
7506 gms_error_pkg.gms_exception_lines_proc( 'GMS_BILL_AWARD_LOCK' ,
7507 'PROJECT_ID',
7508 x_calling_place ,
7509 x_project_id ,
7510 x_award_number ,
7511 x_award_name );
7512 gms_error_pkg.gms_exception_lines_proc( 'GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7513 'PRJ',
7514 x_calling_place,
7515 x_project_id );
7516 -- End of the code added for bug 1744641
7517 IF L_DEBUG = 'Y' THEN
7518 gms_error_pkg.gms_debug('WHEN AWARD_DATA_LOCKED - AWARD_BILLING','C');
7519 END IF;
7520 gms_error_pkg.gms_message('GMS_BILL_AWARD_LOCK',
7521 'PROJECT_ID',
7522 X_Project_id,
7523 X_Exec_Type => 'C',
7524 X_Err_Code => St_Err_Code,
7525 X_Err_Buff => St_Err_Buff);
7526
7527 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7528 'PRJ',
7529 X_Project_id,
7530 X_Exec_Type => 'C',
7531 X_Err_Code => St_Err_Code,
7532 X_Err_Buff => St_Err_Buff);
7533 ROLLBACK; -- If record not found , rollback to release lock
7534 RETURN;
7535
7536 When ROLLBACK_FAILURE then
7537
7538 -- Added for Bug 1744641: To Generate errors when an exception occurs
7539 -- during the process of generation of invoice/Revenue.
7540 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7541 gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7542 GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7543 End If;
7544 gms_error_pkg.gms_exception_lines_proc('GMS_BILLING_ROLLBACK_FAILURE' ,
7545 'PRJ',
7546 x_calling_place,
7547 x_project_id ,
7548 x_award_number ,
7549 x_award_name);
7550 -- End of code added for bug 1744641.
7551 IF L_DEBUG = 'Y' THEN
7552 gms_error_pkg.gms_debug('WHEN ROLLBACK_FAILURE - AWARD_BILLING','C');
7553 END IF;
7554 rollback; -- release lock and any changes carried out.
7555 RETURN;
7556
7557 --RAISE_APPLICATION_ERROR(-20558,St_Err_Buff);
7558
7559 When NO_EXP_TO_PROCESS then
7560
7561 -- This exception is raised when there are no transactions to be processed
7562 -- Billing rollback happens before this in which transactions may have been
7563 -- processed, so unlike all other exceptions, in this exception, we do the following:
7564 -- 1. Delete concurrency control record.
7565 -- 2. COMMIT
7566 -- 3. RETURN
7567
7568 Delete
7569 from gms_concurrency_control
7570 where process_name = 'GMS_BLNG'
7571 and process_key = X_project_id;
7572
7573 COMMIT;
7574
7575 RETURN;
7576
7577 When INVALID_INVOICE_FORMAT then
7578
7579 -- ## This exception is declared at the package level
7580 -- ## This exception happens when Awards form has an invoice format (labor or
7581 -- ## non-labor) that has an element not supported by Grants.
7582 -- ## Refer to Grants userguide Chapter 28 for valid formats (columns that can be used)
7583 -- ## When this exception is raised, all data for that award_project_id
7584 -- ## which has been modified or created is rolled back thus ensuring consistency
7585 -- ## Further processing for that award is ignored.
7586 -- Added for Bug 3143102: QI LABOR/NON-LABOR INVOICE FORMATS NOT SUPPORTED BY GMS
7587
7588 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7589 gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7590 GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7591 End If;
7592 gms_error_pkg.gms_exception_lines_proc('GMS_INVALID_INVOICE_FORMAT' ,
7593 NULL,
7594 x_calling_place ,
7595 x_project_id ,
7596 x_award_number ,
7597 x_award_name );
7601 END IF;
7598
7599 IF L_DEBUG = 'Y' THEN
7600 gms_error_pkg.gms_debug('WHEN INVALID INVOICE FORMAT - AWARD_BILLING','C');
7602 gms_error_pkg.gms_message('GMS_INVALID_INVOICE_FORMAT',
7603 X_Exec_Type => 'C',
7604 X_Err_Code => St_Err_Code,
7605 X_Err_Buff => St_Err_Buff);
7606
7607 ROLLBACK; -- If record not found , rollback to release lock
7608
7609 Delete
7610 from gms_concurrency_control
7611 where process_name = 'GMS_BLNG'
7612 and process_key = X_project_id;
7613 COMMIT;
7614
7615 RETURN;
7616 --Added for bug 4506225
7617 When GMS_TAX_FAILURE then
7618 -- ## This exception is declared at the package level
7619 -- ## This exception is raised when the call to GMS_TAX in procedure award_billing
7620 -- ## returns a non zero value.One possible cause for GMS_TAX to return a non_zero
7621 -- ## value is an inactive award sponsor.
7622 -- ## Added for bug 4243374.
7623 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7624 gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7625 GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7626 End If;
7627 gms_error_pkg.gms_exception_lines_proc ( 'GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7628 'PRJ',
7629 x_calling_place,
7630 x_project_id ,
7631 x_award_number ,
7632 x_award_name );
7633
7634 IF L_DEBUG = 'Y' THEN
7635 gms_error_pkg.gms_debug('WHEN GMS_TAX_FAILURE - AWARD_BILLING','C');
7636 END IF;
7637 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7638 'PRJ',
7639 X_Project_id,
7640 X_Exec_Type => 'C',
7641 X_Err_Code => St_Err_Code,
7642 X_Err_Buff => St_Err_Buff);
7643
7644 Delete
7645 from gms_concurrency_control
7646 where process_name = 'GMS_BLNG'
7647 and process_key = X_project_id;
7648
7649 return;
7650
7651 --End of bug fix 4506225
7652 When Others then
7653 -- Added for Bug 1744641: To Generate errors when an exception occurs
7654 -- during the process of generation of invoice/Revenue.
7655 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7656 gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7657 GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7658 End If;
7659 gms_error_pkg.gms_exception_lines_proc('GMS_UNEXPECTED_ERROR',
7660 'PRJ',
7661 x_calling_place,
7662 x_project_id ,
7663 x_award_number ,
7664 x_award_name,
7665 SQLCODE,
7666 SQLERRM );
7667 gms_error_pkg.gms_exception_lines_proc('GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7668 'PRJ',
7669 x_calling_place ,
7670 x_project_id
7671 );
7672 --End of Code added for bug 1744641
7673 IF L_DEBUG = 'Y' THEN
7674 gms_error_pkg.gms_debug('WHEN OTHERS - AWARD_BILLING','C');
7675 END IF;
7676 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
7677 'SQLCODE',
7678 SQLCODE,
7679 'SQLERRM',
7680 SQLERRM,
7681 X_Exec_Type => 'C',
7682 X_Err_Code => St_Err_Code,
7683 X_Err_Buff => St_Err_Buff);
7684
7685 gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7686 'PRJ',
7687 X_Project_id,
7688 X_Exec_Type => 'C',
7689 X_Err_Code => St_Err_Code,
7690 X_Err_Buff => St_Err_Buff);
7691
7692
7693 rollback; -- release lock and any changes carried out.
7694 RETURN;
7695
7696 --RAISE_APPLICATION_ERROR(-20557,St_Err_Buff);
7697
7698 End AWARD_BILLING;
7699
7700 END GMS_BILLING;