DBA Data[Home] [Help]

PACKAGE BODY: APPS.GMS_BILLING

Source


1 PACKAGE BODY GMS_BILLING AS
2 --  $Header: gmsinblb.pls 120.22.12020000.2 2012/07/18 09:31:48 admarath 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,
519                                      f_raw_rev_accumulated,
520                                      f_raw_creation_date,
521 				     f_request_id; --Added for bug 4957529
522          EXIT WHEN get_exp_raw_info%NOTFOUND;
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,
633                   x_err_buff
634                );
635             END IF;
636 
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
760 PROCEDURE DELETE_NULL_EVENTS (X_award_project_id  IN  NUMBER,
761                               X_request_id        IN  NUMBER,
762                               X_calling_process   IN  VARCHAR2,
763                               X_err_code          OUT NOCOPY NUMBER,
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;
895 
896 End if;
897 
898 -- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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',
1048 				Bill_Hold_Rec.expenditure_item_id,
1049 				'ADL',
1050 				Bill_Hold_Rec.adl_line_num,
1051 				X_Exec_Type => 'C',
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
1185 into x_award_project_id
1186 from gms_awards_all where award_id = x_award_id ;
1187 
1188 
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;
1299     X_Total_Rev_Bill_Amount  := -99;
1300 END GET_SUMM_FUNDING;
1301 --------------------------------------------------------------------------------
1302 
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
1430 
1431 Begin
1432 
1433    X_Err_Code := 0;
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,
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
1572 	and     adl_line_num 			 = F_Adl_Line_Num
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,
1718 				X_Exec_Type => 'C',
1719 				X_Err_Code => X_Err_Code,
1720 				X_Err_Buff => X_Err_Buff);
1721       --RAISE_APPLICATION_ERROR(-20509,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);
1856       --Raise NO_PROCESSING_OF_AWARD ;
1857 
1858       RETURN;
1859 
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
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;
2000          x_plsql_project_id     := X_Installment_Total(Rec_Count).Actual_Project_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,
2119                      X_Bill_Amount,
2120                      X_Rev_Amount,
2121 		     X_Request_Id,
2122 		     NULL,		-- Expenditure_Type
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 
2246            If X_calling_Process = 'Invoice' then
2247 	      X_Bill_Amount := X_Diff_amount;
2248 	      X_Rev_Amount := 0;
2249 	   Elsif X_Calling_Process = 'Revenue' then
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 */
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
2358 X_LABOR_SELECT VARCHAR2(2000) := NULL;
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
2474           X_Labor_Sel_Grp_Diff_Ind(X_Lbr_Cnt_Of_Columns_Selected) := 'N';
2475         End If;
2476       End If;
2477    END LOOP;
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',
2593 				X_Err_Code => X_Err_Code,
2594 				X_Err_Buff => X_Err_Buff);
2595       --ROLLBACK;
2596       --RAISE_APPLICATION_ERROR(-20515,X_Err_Buff);
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
2722 
2723      If X_Current_Amount_In_Intersect <> 0 then
2724          X_Amount_To_Accrue_Bill_Insert := (-1 * X_Current_Amount_In_Intersect);
2725      Else
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,
2843 	   X_Burden_Cost_Code,
2844            SYSDATE,
2845            fnd_global.user_id,
2846            SYSDATE,
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',
2972                                 X_Err_Code => X_Err_Code,
2973                                 X_Err_Buff => X_Err_Buff);
2974 	   --ROLLBACK;
2975            --RAISE_APPLICATION_ERROR(-20521,X_Err_Buff);
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 /* commented for bug   bug 9852339
3003  update GMS_EVENT_INTERSECT gei
3004  set
3005  gei.EVENT_NUM = X_Event_Num
3006  ,gei.last_update_date  = sysdate
3007  ,gei.last_updated_by   = fnd_global.user_id
3008  ,gei.last_update_login = fnd_global.login_id
3009  where gei.REQUEST_ID = X_Request_id and
3010  gei.award_project_id = X_Award_Project_Id and
3011  gei.EVENT_NUM IS NULL
3012  AND  EXISTS  ( -- Bug 3235390 : Added below conditions to check for project and task.
3013          SELECT gei2.expenditure_item_id
3014            FROM gms_award_distributions adl,
3015                 gms_event_intersect gei2
3016           WHERE gei2.expenditure_item_id = gei.expenditure_item_id
3017             AND adl.expenditure_item_id  = gei2.expenditure_item_id
3018             AND adl.adl_status = 'A'
3019             AND adl.document_type ='EXP'
3020             AND adl.project_id    = x_act_project_id
3021             AND adl.task_id    = x_task_id);
3022 
3023  */
3024 
3025  /*  re-writing the above query  for  bug 9852339  */
3026 
3027 UPDATE GMS_EVENT_INTERSECT GEI
3028    SET GEI.EVENT_NUM = X_Event_Num
3029           ,GEI.LAST_UPDATE_DATE = SYSDATE
3030           ,GEI.LAST_UPDATED_BY = FND_GLOBAL.USER_ID
3031           ,GEI.LAST_UPDATE_LOGIN = FND_GLOBAL.LOGIN_ID
3032 WHERE GEI.REQUEST_ID = X_Request_id
3033           AND GEI.AWARD_PROJECT_ID =  X_Award_Project_Id
3034           AND GEI.EVENT_NUM IS NULL
3035           AND EXISTS (
3036           SELECT
3037                     ADL.EXPENDITURE_ITEM_ID
3038           FROM
3039                     GMS_AWARD_DISTRIBUTIONS ADL
3040           WHERE ADL.EXPENDITURE_ITEM_ID = GEI.EXPENDITURE_ITEM_ID
3041                     AND ADL.ADL_STATUS = 'A'
3042                     AND ADL.DOCUMENT_TYPE ='EXP'
3043                     AND ADL.PROJECT_ID = x_act_project_id
3044                     AND ADL.TASK_ID  = x_task_id
3045           )	;
3046 
3047 
3048     If SQL%NOTFOUND THEN
3049       IF L_DEBUG = 'Y' THEN
3050       	gms_error_pkg.gms_debug('IN EVENT INTERSECT Updation - ERROR','C');
3051       END IF;
3052       gms_error_pkg.gms_message('GMS_NO_UPD_PRJ_REQ',
3053 				'PRJ',
3054 				X_Award_Project_Id,
3055 				'REQ',
3056 				X_Request_id,
3057 				X_Exec_Type => 'C',
3058 				X_Err_Code => X_Err_Code,
3059 				X_Err_Buff => X_Err_Buff);
3060 	Raise NO_PROCESSING_OF_AWARD ;
3061 
3062     End If;
3063     IF L_DEBUG = 'Y' THEN
3064     	gms_error_pkg.gms_debug('IN EVENT INTERSECT Updation - END','C');
3065     END IF;
3066 
3067 End UPDATE_GMS_EVENT_INTERSECT;
3068 
3069 --------------------------------------------------------------------------------------------
3070 
3071 --------------------------------------------------------------------------------------------
3072 --Procedure UPDATE_GMS_BURDEN_COMPONENTS: Updates GMS_BURDEN_COMPONENTS table with the Event Num of
3073 --the event created.
3074 --------------------------------------------------------------------------------------------
3075 PROCEDURE UPDATE_GMS_BURDEN_COMPONENTS(X_Event_Num	    IN NUMBER,
3076 				       X_Award_Project_Id   IN NUMBER,
3077 				       X_Request_Id	    IN NUMBER,
3078 				       X_Actual_Project_Id  IN NUMBER,
3079 				       X_Actual_Task_Id     IN NUMBER,
3080 				       X_Burden_Cost_Code   IN VARCHAR2,
3081 				       X_Expenditure_Org_Id IN NUMBER) IS
3082 
3083 X_Err_Code Varchar2(1);
3084 X_Err_Buff Varchar2(2000);
3085 Begin
3086  IF L_DEBUG = 'Y' THEN
3087  	gms_error_pkg.gms_debug('IN BURDEN COMPONENTS Updation - START','C');
3088  END IF;
3089  update /*+INDEX(GMS_BURDEN_COMPONENTS GMS_BURDEN_COMPONENTS_N3)*/ GMS_BURDEN_COMPONENTS
3090  set
3091  EVENT_NUM = X_Event_Num
3092  ,last_update_date  = sysdate
3093  ,last_updated_by   = fnd_global.user_id
3094  ,last_update_login = fnd_global.login_id
3095  where
3096  request_id = X_request_id             and
3097  award_project_id = X_Award_Project_Id and
3098  EVENT_NUM IS NULL                     and
3099  actual_project_id = X_Actual_Project_Id and
3100  actual_task_id    = X_Actual_Task_Id  and
3101  burden_cost_code  = X_Burden_Cost_Code and
3102  expenditure_org_id = X_Expenditure_Org_Id;
3103 
3104     If SQL%NOTFOUND THEN
3105       IF L_DEBUG = 'Y' THEN
3106       	gms_error_pkg.gms_debug('IN BURDEN COMPONENTS Updation - ERROR','C');
3107       END IF;
3108       gms_error_pkg.gms_message('GMS_NO_UPD_PRJ_REQ',
3109 				'PRJ',
3110 				X_Award_Project_Id,
3111 				'REQ',
3112 				X_Request_id,
3113 				X_Exec_Type => 'C',
3114 				X_Err_Code => X_Err_Code,
3115 				X_Err_Buff => X_Err_Buff);
3116 	Raise NO_PROCESSING_OF_AWARD ;
3117 
3118     End If;
3119 
3120     IF L_DEBUG = 'Y' THEN
3121     	gms_error_pkg.gms_debug('IN BURDEN COMPONENTS Updation - END','C');
3122     END IF;
3123 
3124 End UPDATE_GMS_BURDEN_COMPONENTS;
3125 ---------------------------------------------------------------------------------------------
3126 --PROCEDURE: EVENT_ATTRIBUTE_UPDATION, new procedure to update event number on Event_Attribute
3127 
3128 PROCEDURE EVENT_ATTRIBUTE_UPDATION(X_Event_Num        IN NUMBER,
3129 				   X_Award_Project_Id IN NUMBER,
3130 				   X_request_id       IN NUMBER,
3131 				   X_Err_Code	      IN OUT NOCOPY NUMBER,
3132 				   X_Err_Buff         IN OUT NOCOPY VARCHAR2) IS
3133 
3134 x_count number :=0;
3135 
3136 Begin
3137 
3138  IF L_DEBUG = 'Y' THEN
3139  	gms_error_pkg.gms_debug('IN EVENT ARRIBUTE UPDATION -- START','C');
3140  END IF;
3141 
3142  update GMS_EVENT_ATTRIBUTE
3143  set
3144  EVENT_NUM = X_Event_Num
3145  ,last_update_date  = sysdate
3146  ,last_updated_by   = fnd_global.user_id
3147  ,last_update_login = fnd_global.login_id
3148  where
3149  request_id = X_request_id             and
3150  project_id = X_Award_Project_Id and
3151  EVENT_NUM IS NULL;
3152 
3153  Begin
3154 
3155     Select 1
3156     into   x_count
3157     from   dual
3158     where  exists
3159     (select 1
3160      from   gms_event_attribute
3161      where  request_id = X_request_id
3162      and    project_id = X_Award_Project_Id
3163      and    EVENT_NUM IS NULL);
3164 
3165  Exception
3166 
3167    When no_data_found then
3168 
3169        x_count := 0;
3170  End;
3171 
3172 --    If SQL%NOTFOUND THEN
3173       If x_count > 0 then
3174 
3175       gms_error_pkg.gms_message('GMS_NO_UPD_PRJ_REQ',
3176 				'PRJ',
3177 				X_Award_Project_Id,
3178 				'REQ',
3179 				X_Request_id,
3180 				X_Exec_Type => 'C',
3181 				X_Err_Code => X_Err_Code,
3182 				X_Err_Buff => X_Err_Buff);
3183       RETURN;
3184     Else
3185       X_Err_Code := 0;
3186     End If;
3187 Exception
3188 
3189   When Others then
3190   IF L_DEBUG = 'Y' THEN
3191   	gms_error_pkg.gms_debug('IN EVENT ARRIBUTE WHEN OTHERS ','C');
3192   END IF;
3193   gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3194                                 'SQLCODE',
3195                                 SQLCODE,
3196                                 'SQLERRM',
3197                                 SQLERRM,
3198                                 X_Exec_Type => 'C',
3199                                 X_Err_Code => X_Err_Code,
3200                                 X_Err_Buff => X_Err_Buff);
3201   RAISE;
3202 
3203 End EVENT_ATTRIBUTE_UPDATION;
3204 
3205 ---------------------------------------------------------------------------------------------
3206 
3207 PROCEDURE UPDATE_GMS_SUMMARY_FUNDINGS(X_Installment_Id   IN NUMBER,
3208                                       X_Task_Id          IN NUMBER,
3209                                       X_Calling_Process  IN VARCHAR2,
3210                                       X_Rev_Bill_Amount  IN NUMBER,
3211 				      X_Err_Code	 IN OUT NOCOPY NUMBER,
3212 				      X_Err_Buff         IN OUT NOCOPY VARCHAR2) IS
3213 
3214 X_Total_Funding_Amount NUMBER(22,5) := 0;
3215 X_Total_Rev_Bill_Amount  NUMBER(22,5) := 0;
3216 
3217 Begin
3218    GET_SUMM_FUNDING(X_Installment_Id,
3219 		    NULL,
3220 		    NULL,
3221                     X_Task_Id,
3222                     X_Calling_Process,
3223                     X_Total_Funding_Amount,
3224                     X_Total_Rev_Bill_Amount,
3225 		    X_Err_Code,
3226 		    X_Err_Buff);
3227 
3228             	If X_Err_Code <> 0 then
3229 		        --ROLLBACK;
3230                  	--RAISE FND_API.G_EXC_ERROR;
3231 			Raise NO_PROCESSING_OF_AWARD ;
3232             	End If;
3233  Begin
3234  If X_Calling_Process = 'Invoice' then
3235 
3236     update GMS_SUMMARY_PROJECT_FUNDINGS spf
3237     set
3238     spf.TOTAL_BILLED_AMOUNT = (X_Rev_Bill_Amount + X_Total_Rev_Bill_Amount),
3239     spf.last_update_date    = sysdate,
3240     spf.last_updated_by     = fnd_global.user_id,
3241     spf.last_update_login   = fnd_global.login_id
3242     where
3243     spf.INSTALLMENT_ID = X_Installment_Id
3244     and (
3245          (spf.TASK_ID = X_Task_Id)
3246      or  (spf.TASK_ID IS NULL)
3247      or  (spf.TASK_ID = (select t.top_task_id from PA_TASKS t where
3248                          t.task_id = X_Task_Id))
3249      )
3250     and PROJECT_ID = (select project_id from pa_tasks where task_id = X_Task_Id);
3251 
3252     --DECODE(TASK_ID,NULL,X_Task_Id,TASK_ID) = X_Task_Id
3253 
3254  Elsif X_Calling_Process = 'Revenue' then
3255 
3256     update GMS_SUMMARY_PROJECT_FUNDINGS spf
3257     set
3258     spf.TOTAL_REVENUE_AMOUNT = (X_Rev_Bill_Amount + X_Total_Rev_Bill_Amount),
3259     spf.last_update_date    = sysdate,
3260     spf.last_updated_by     = fnd_global.user_id,
3261     spf.last_update_login   = fnd_global.login_id
3262     where
3263     spf.INSTALLMENT_ID = X_Installment_Id
3264     and (
3265          (spf.TASK_ID = X_Task_Id)
3266      or  (spf.TASK_ID IS NULL)
3267      or  (spf.TASK_ID = (select t.top_task_id from PA_TASKS t where
3268                          t.task_id = X_Task_Id))
3269      )
3270     and PROJECT_ID = (select project_id from pa_tasks where task_id = X_Task_Id);
3271 
3272     --DECODE(TASK_ID,NULL,X_Task_Id,TASK_ID) = X_Task_Id
3273 
3274 
3275  End If;
3276 
3277   If SQL%ROWCOUNT = 0 then
3278       gms_error_pkg.gms_message('GMS_NO_UPD_TASK_INST',
3279 				'TASK',
3280 				X_Task_Id,
3281 				'INST',
3282 				X_Installment_Id,
3283 				X_Exec_Type => 'C',
3284 				X_Err_Code => X_Err_Code,
3285 				X_Err_Buff => X_Err_Buff);
3286       --RAISE_APPLICATION_ERROR(-20524,X_Err_Buff);
3287       RETURN;
3288   Else
3289      X_Err_Code := 0;
3290   End If;
3291 
3292  End;
3293 
3294 END UPDATE_GMS_SUMMARY_FUNDINGS;
3295 
3296 -- PROCEDURE: UPD_GSPF_WRAPPER, new procedure for updating gms_summary_project_fundings
3297 
3298 PROCEDURE UPD_GSPF_WRAPPER(X_Installment_Id     IN NUMBER,
3299 			   X_Task_Id		IN NUMBER,
3300                            X_Actual_Project_Id  IN NUMBER,
3301 			   X_Calling_Process    IN VARCHAR2,
3302 			   X_Rev_Bill_Amount	IN NUMBER,
3303 			   X_Installment_Count  IN NUMBER,
3304 			   X_Install_tab        IN Inst_tab,
3305 			   X_Inst_total         IN OUT NOCOPY Inst_tab2,
3306 			   X_Err_Code		IN OUT NOCOPY NUMBER,
3307 			   X_Err_Buff		IN OUT NOCOPY VARCHAR2) IS
3308 Begin
3309 
3310      If X_Installment_Count = 1 then
3311 
3312         UPDATE_GMS_SUMMARY_FUNDINGS(X_Installment_Id,
3313 				    X_Task_Id,
3314 				    X_Calling_Process,
3315 				    X_Rev_Bill_Amount,
3316 			            X_Err_Code,
3317 				    X_Err_Buff);
3318 
3319             	If X_Err_Code <> 0 then
3320 			Raise NO_PROCESSING_OF_AWARD ;
3321             	End If;
3322 
3323         INSTALLMENT_AMOUNT(X_Installment_id,
3324 			   X_Rev_Bill_Amount,
3325 			   X_Inst_Total,
3326                            X_Actual_Project_Id,
3327                            X_Task_Id,
3328 			   X_Err_Code,
3329 			   X_Err_Buff);
3330 
3331                 If X_Err_Code <> 0 then
3332 			Raise NO_PROCESSING_OF_AWARD ;
3333                 End If;
3334     Else
3335 
3336       for X_Count_Reqd in 1..X_Installment_Count
3337       loop
3338 	  UPDATE_GMS_SUMMARY_FUNDINGS(X_Install_tab(X_Count_Reqd).Installment_Id,
3339 				      X_Task_Id,
3340                                       X_Calling_Process,
3341 				      X_Install_tab(X_Count_Reqd).Rev_Bill_Amount,
3342 				      X_Err_Code,
3343 				      X_Err_Buff);
3344 
3345             	If X_Err_Code <> 0 then
3346 			Raise NO_PROCESSING_OF_AWARD ;
3347             	End If;
3348 
3349           INSTALLMENT_AMOUNT(X_Install_tab(X_Count_Reqd).Installment_Id,
3350                            X_Install_tab(X_Count_Reqd).Rev_Bill_Amount,
3351                            X_Inst_Total,
3352                            X_Actual_Project_Id,
3353                            X_Task_Id,
3354                            X_Err_Code,
3355                            X_Err_Buff);
3356 
3357                 If X_Err_Code <> 0 then
3358 			Raise NO_PROCESSING_OF_AWARD ;
3359                 End If;
3360 
3361        end loop;
3362     End if;
3363 
3364      X_Err_Code := 0;
3365 
3366 EXCEPTION
3367     WHEN OTHERS THEN
3368       gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3369 				'SQLCODE',
3370 			        SQLCODE,
3371 				'SQLERRM',
3372 				SQLERRM,
3373 				X_Exec_Type => 'C',
3374 				X_Err_Code => X_Err_Code,
3375 				X_Err_Buff => X_Err_Buff);
3376       RETURN;
3377 
3378 End UPD_GSPF_WRAPPER;
3379 
3380 -----------------------------------------------------------------------------------------
3381 -- Procedure UPD_ADL_BILLING_FLAG: Updates GMS_AWARD_DISTRIBUTIONS table sets the
3382 -- Billed Flag and Revenue Distributed flag to 'Y' for the expenditure item that has been processed
3383 -----------------------------------------------------------------------------------------
3384 PROCEDURE UPD_ADL_BILLING_FLAG(X_Expenditure_Item_Id IN NUMBER,
3385 			  X_Adl_Line_Num IN NUMBER,
3386 		          X_Calling_Process     IN VARCHAR2,
3387 		          X_Billable_Flag       IN VARCHAR2,
3388 		          X_Bill_Hold_Flag      IN VARCHAR2,
3389 			  X_Err_Code              IN OUT NOCOPY NUMBER,
3390                           X_Err_Buff              IN OUT NOCOPY VARCHAR2) IS
3391 
3392 Begin
3393 If X_Calling_Process = 'Invoice' then
3394  update
3395  GMS_AWARD_DISTRIBUTIONS
3396  set
3397  BILLED_FLAG = 'Y'
3398  ,last_update_date  = sysdate
3399  ,last_updated_by   = fnd_global.user_id
3400  ,last_update_login = fnd_global.login_id
3401  where expenditure_item_id = X_Expenditure_Item_Id
3402  and   adl_line_num = X_Adl_Line_Num
3403  and   document_type='EXP'
3404  and   adl_status = 'A';
3405 
3406 Elsif X_Calling_Process = 'Revenue' then
3407  update
3408  GMS_AWARD_DISTRIBUTIONS
3409  set
3410  revenue_distributed_flag = 'Y'
3411  ,last_update_date  = sysdate
3412  ,last_updated_by   = fnd_global.user_id
3413  ,last_update_login = fnd_global.login_id
3414  where expenditure_item_id = X_Expenditure_Item_Id
3415  and   adl_line_num = X_Adl_Line_Num
3416  and   document_type='EXP'
3417  and   adl_status = 'A';
3418 
3419 End If;
3420 
3421   If SQL%ROWCOUNT = 0 then
3422       gms_error_pkg.gms_message('GMS_NO_UPD_EXP_ADL',
3423 				'EXP',
3424 				X_Expenditure_Item_Id,
3425 				'ADL',
3426 				X_Adl_Line_Num,
3427 				X_Exec_Type => 'C',
3428 				X_Err_Code => X_Err_Code,
3429 				X_Err_Buff => X_Err_Buff);
3430       RETURN;
3431   Else
3432      X_Err_Code := 0;
3433   End If;
3434 
3435 End UPD_ADL_BILLING_FLAG;
3436 
3437 ------------------------------------------------------------------------------------------
3438 -- Procedure GET_RUN_TOTAL: This procedure get the running total for the event description
3439 ------------------------------------------------------------------------------------------
3440 Procedure GET_RUN_TOTAL(X_Req_id  IN NUMBER,
3441                         X_Proj_Id IN NUMBER,
3442                         X_Qty    OUT NOCOPY NUMBER)
3443 is
3444 Begin
3445   -- Bug 3235390 : Added decode to get correct quantity
3446   Select SUM(NVL( DECODE(adl.line_num_reversed, NULL, peia.quantity,-1*peia.quantity),0))
3447   into x_qty
3448   from   pa_expenditure_items_all peia,
3449          gms_event_intersect      gei,
3450          gms_award_distributions  adl
3451   where  peia.expenditure_item_id = gei.expenditure_item_id
3452   and    adl.expenditure_item_id  = gei.expenditure_item_id
3453   and    adl.adl_line_num = gei.adl_line_num
3454   and    adl.document_type        ='EXP'
3455   and    adl.adl_status           ='A'
3456   and    gei.request_id           = X_Req_id
3457   and    gei.award_project_id     = X_Proj_Id
3458   and    gei.event_num is null;
3459 Exception
3460   When no_data_found then
3461     x_qty:=0;
3462 End;
3463 
3464 ------------------------------------------------------------------------------------------
3465 -- Bug 3235390 : Introduced the following procedure
3466 -- PROCESS_TEMP_EVENTS : This procedure is used to insert / update the temporary
3467 --                       events stored in temporary global table  gms_events_temp_format.
3468 ------------------------------------------------------------------------------------------
3469 PROCEDURE PROCESS_TEMP_EVENTS  (p_act_project_id IN NUMBER,
3470 		                p_task_id        IN NUMBER,
3471 				p_invfmt_incl_task IN VARCHAR2, /* Bug 3523930*/
3472 		                p_format         IN VARCHAR2,
3473                                 p_description    IN VARCHAR2,
3474                                 p_calling_place  IN VARCHAR2,
3475                                 p_units          IN VARCHAR2,
3476                                 p_quantity       IN NUMBER,
3477 		                p_amount         IN NUMBER,
3478                                 p_event_num      OUT NOCOPY NUMBER,
3479 			        p_err_code       IN OUT NOCOPY NUMBER,
3480                                 p_err_buff       IN OUT NOCOPY VARCHAR2) IS
3481 
3482 
3483 l_description    VARCHAR2(2000);
3484 
3485 /* Added below 2 cursors for 3523930*/
3486 CURSOR C_event_exists_PTF IS
3487 SELECT event_num
3488    FROM gms_events_temp_format
3489 WHERE act_project_id = p_act_project_id
3490    AND task_id = p_task_id
3491    AND NVL(format,'X')  = NVL(p_format,'X');
3492 
3493 CURSOR C_event_exists_F IS
3494 SELECT event_num
3495   FROM gms_events_temp_format
3496 WHERE NVL(format,'X')  = NVL(p_format,'X');
3497 
3498 BEGIN
3499 
3500      IF L_DEBUG = 'Y' THEN
3501  	gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - START ','C');
3502 	gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - X_trans_type is '||X_trans_type,'C'); -- added debug for 5413530
3503 	gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - G_trans_type is '||G_trans_type,'C'); -- added debug for 5413530
3504      END IF;
3505 
3506      IF p_calling_place = 'Revenue' THEN
3507          l_description := p_description  ||'- '|| p_quantity || ' ' || p_units;
3508      ELSE
3509          l_description := p_description;
3510      END IF;
3511 
3512 
3513  OPEN C_event_exists_PTF;
3514  FETCH C_event_exists_PTF INTO p_event_num ;
3515 
3516  IF ( C_event_exists_PTF%FOUND AND
3517           ( ( p_format IS NULL AND X_trans_type = G_trans_type ) OR ( p_format IS NOT NULL ))) -- for bug 5413530
3518 THEN
3519  --If there exists a temporary event with exact match then we dont need to bother about the p_invfmt_incl_task = 'N'
3520  --and update the event with the amount
3521 
3522 	UPDATE gms_events_temp_format
3523            SET amount      = amount + p_amount,
3524                quantity    = quantity + p_quantity,
3525                description = decode(p_calling_place,'Revenue',p_description || '- '|| to_char(quantity + p_quantity) || ' ' ||p_units,p_description)
3526          WHERE event_num = p_Event_num
3527            AND act_project_id = p_act_project_id
3528            AND task_id = p_task_id
3529            AND nvl(format,'X') = nvl(p_format,'X'); -- for bug 5413530
3530 
3531         IF L_DEBUG = 'Y' THEN
3532  	   gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - After updating  '||p_event_num||' in gms_events_temp_format with amount '||p_amount ,'C');
3533         END IF;
3534 
3535  ELSE
3536 
3537       IF p_invfmt_incl_task = 'N' THEN
3538        --If there exists no temporary event with exact match and task id is not a format column then fetch
3539        --the event_num which is already creatd for this format and insert new line into gms_events_temp_format with
3540        --same event_num but with new task_id
3541 
3542         OPEN C_event_exists_F;
3543 	FETCH C_event_exists_F INTO p_event_num ;
3544 
3545         IF ( C_event_exists_F%NOTFOUND OR
3546 	     ( X_trans_type <> G_trans_type AND p_format IS NULL ) ) -- for bug 5413530
3547 	THEN
3548   	    --If there exists no temporary event with format match then generate new event_num
3549 	    p_Event_num            := x_temp_negative_evt_num;
3550             X_temp_negative_evt_num :=x_temp_negative_evt_num-1;
3551 	END If;
3552  	CLOSE C_event_exists_F;
3553 
3554       ELSE
3555           --If task is one of the column in format then generate new event as no match found
3556            p_Event_num            := x_temp_negative_evt_num;
3557 	   X_temp_negative_evt_num :=x_temp_negative_evt_num-1;
3558       END If;
3559 
3560       INSERT INTO gms_events_temp_format(Event_num ,
3561                  		    ACT_PROJECT_ID,
3562 		                    TASK_ID,
3563                                     QUANTITY,
3564 		                    AMOUNT,
3565 		                    FORMAT,
3566                                     DESCRIPTION)
3567         VALUES (p_event_num,
3568                 p_act_project_id,
3569    	        p_task_id,
3570                 p_quantity,
3571                 p_Amount,
3572                 p_format,
3573                 l_description );
3574 
3575         IF L_DEBUG = 'Y' THEN
3576  	   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');
3577         END IF;
3578 
3579  END IF;
3580  CLOSE C_event_exists_PTF;
3581 
3582 G_trans_type := X_trans_type ;   /* For bug 5413530 */
3583 
3584  IF L_DEBUG = 'Y' THEN
3585     gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - END ','C');
3586  END IF;
3587 
3588 EXCEPTION
3589     WHEN OTHERS THEN
3590 
3591         IF L_DEBUG = 'Y' THEN
3592           gms_error_pkg.gms_debug('IN PROCESS_TEMP_EVENTS - WHEN OTHERS ','C');
3593         END IF;
3594 
3595         IF C_event_exists_F%ISOPEN THEN
3596 	   CLOSE C_event_exists_F;
3597         END IF;
3598 
3599         IF C_event_exists_PTF%ISOPEN THEN
3600 	   CLOSE C_event_exists_PTF;
3601         END IF;
3602 
3603         gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3604                                   'SQLCODE',
3605                                   SQLCODE,
3606                                   'SQLERRM',
3607                                   SQLERRM,
3608                                   X_Exec_Type => 'C',
3609                                   X_Err_Code => p_Err_Code,
3610                                   X_Err_Buff => p_Err_Buff);
3611         Raise NO_PROCESSING_OF_AWARD ;
3612 
3613 End PROCESS_TEMP_EVENTS;
3614 
3615 ---------------------------------------------------------------------------------------
3616 --Procedure CREATE_PA_EVENTS
3617 -----------------------------------------------------------------------------------------
3618 -- Bug 3235390 : This newly introduced procedure does the following :
3619 --               a. Fetches consolidated records from the plsql table
3620 --               b. Inserts consolidated events into gms_event_attribute table
3621 --               b. If amount <> 0 then inserts events into Pa_events and
3622 --                  updates GEI and GEA with newly generated event_num.
3623 --               c. If amount = 0 then updates -1 on GEA and GEI and sets the
3624 --                  NULL events variables.
3625 ----------------------------------------------------------------------------------------------------
3626 
3627 PROCEDURE CREATE_PA_EVENTS          (p_project_id       In NUMBER,
3628 				     p_Calling_Process  IN VARCHAR2,
3629 				     p_completion_date  IN DATE,
3630                                      p_carrying_out_org_id IN NUMBER,
3631                                      p_Request_Id        IN NUMBER,
3632                                      p_installment_total IN OUT NOCOPY inst_tab2,
3633 				     p_Err_Code 	 IN OUT NOCOPY NUMBER,
3634 				     p_Err_Buff 	 IN OUT NOCOPY VARCHAR2) IS
3635 
3636 Evt_Num          NUMBER(15) := 0;
3637 Evt_Description  VARCHAR2(2000) := NULL;
3638 St_Error_Message VARCHAR2(2000);
3639 St_Status        NUMBER;
3640 X_count          NUMBER;
3641 X_rev_amt        NUMBER(22,5);
3642 X_bill_amt       NUMBER(22,5);
3643 
3644 CURSOR C_get_temp_pa_events IS
3645 SELECT event_num,
3646        format,
3647        description,
3648        SUM(amount) amount
3649   FROM gms_events_temp_format
3650 GROUP BY event_num,format,description
3651 ORDER BY event_num desc;
3652 
3653 CURSOR C_get_temp_gms_events (p_evt_num NUMBER,
3654                               p_format  VARCHAR2,
3655                               p_description VARCHAR2 ) IS
3656 SELECT act_project_id,
3657        task_id,
3658        SUM(amount) amount
3659   FROM gms_events_temp_format
3660  WHERE event_num = p_evt_num
3661    AND NVL(format,'X')  = NVL(p_format,'X')
3662    AND description = p_description
3663 GROUP BY act_project_id,task_id;
3664 
3665 BEGIN
3666 
3667  IF L_DEBUG = 'Y' THEN
3668     gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - START','C');
3669  END IF;
3670 
3671  FOR pa_events_rec IN  C_get_temp_pa_events LOOP
3672 
3673    IF nvl(pa_events_rec.amount,0) = 0 THEN
3674        Evt_num := -1;
3675 
3676        IF p_Calling_Process = 'Revenue' THEN
3677           X_REVRAW_NULL_EVENT_PROCESSED := TRUE;
3678        ELSIF p_Calling_Process = 'Invoice' THEN
3679           X_INVRAW_NULL_EVENT_PROCESSED := TRUE;
3680        END IF;
3681 
3682        IF L_DEBUG = 'Y' THEN
3683           gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - Encountered NULL event- After setting NULL event flags','C');
3684        END IF;
3685    END IF;
3686 
3687    FOR gms_events_rec IN  C_get_temp_gms_events(pa_events_rec.event_num,pa_events_rec.format,pa_events_rec.description) LOOP
3688 
3689        EVENT_WRAPPER(p_Project_Id,
3690 	      	     gms_events_rec.act_project_id,
3691 	             gms_events_rec.task_id,
3692 		     p_Calling_Process,
3693 		     gms_events_rec.amount,
3694                      p_installment_total,
3695 		     NULL, -- Burden Cost Code
3696 		     NULL, -- Exp Org
3697 		     p_Request_Id,
3698 		     p_Err_Code,
3699 		     p_Err_Buff);
3700 
3701       IF L_DEBUG = 'Y' THEN
3702          gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call for event '||pa_events_rec.event_num,'C');
3703          gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call for project_id '||gms_events_rec.act_project_id,'C');
3704          gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call for task_id '||gms_events_rec.task_id,'C');
3705          gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call value of p_Err_Code '||p_Err_Code,'C');
3706          gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_WRAPPER call value of p_Err_Buff '||p_Err_Buff,'C');
3707       END IF;
3708 
3709       IF p_Err_Code <> 0 THEN
3710          Raise NO_PROCESSING_OF_AWARD ;
3711       END IF;
3712 
3713    END LOOP;
3714 
3715    IF pa_events_rec.amount <> 0 THEN
3716 
3717        IF p_Calling_Process = 'Revenue' then
3718           X_rev_amt  := pa_events_rec.amount;
3719           X_bill_amt := 0;
3720        ELSIF p_Calling_Process = 'Invoice' then
3721           X_bill_amt := pa_events_rec.amount;
3722           X_rev_amt  := 0;
3723        END IF;
3724 
3725        Evt_Num := pa_billing_seq.next_eventnum(p_Project_Id,NULL); -- Bug 3235390
3726 
3727        pa_billing_pub.insert_event(
3728 				X_rev_amt            => X_rev_amt,
3729                                 X_bill_amt           => X_bill_amt,
3730                                 X_project_id         => p_project_id,
3731                                 X_event_type         => 'AWARD_BILLING',
3732                                 X_top_task_id        => NULL,
3733                                 X_organization_id    => p_Carrying_Out_Org_Id,
3734                                 X_completion_date    => p_completion_date,
3735                                 X_event_description  => pa_events_rec.description,
3736                                 X_event_num_reversed => NULL,
3737                                 X_attribute_category => NULL,
3738                                 X_attribute1         => NULL,
3739                                 X_attribute2         => NULL,
3740                                 X_attribute3         => NULL,
3741                                 X_attribute4         => NULL,
3742                                 X_attribute5         => NULL,
3743                                 X_attribute6         => NULL,
3744                                 X_attribute7         => NULL,
3745                                 X_attribute8         => NULL,
3746                                 X_attribute9         => NULL,
3747                                 X_attribute10        => NULL,
3748 				X_error_message      => St_Error_Message,
3749                                 X_status             => St_Status
3750 				);
3751 
3752        IF L_DEBUG = 'Y' THEN
3753           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');
3754           gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After insert_event call value of St_Error_Message '||St_Error_Message,'C');
3755           gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After insert_event call value of St_Status '||St_Status,'C');
3756        END IF;
3757 
3758        IF St_Status <> 0 THEN
3759           RAISE NO_PROCESSING_OF_AWARD;
3760        END IF;
3761 
3762 
3763 
3764    END IF;
3765 
3766    UPDATE gms_event_intersect
3767       SET Event_Num  = Evt_num
3768     WHERE Event_num =  pa_events_rec.event_num
3769     AND award_project_id = p_project_id; /* Added for bug 4172924*/
3770 
3771    IF L_DEBUG = 'Y' THEN
3772       gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After updating GEI ','C');
3773    END IF;
3774 
3775    EVENT_ATTRIBUTE_UPDATION( Evt_Num,
3776 	                     p_Project_Id,
3777 			     p_Request_Id,
3778 			     p_Err_Code,
3779 			     p_Err_Buff);
3780 
3781    IF L_DEBUG = 'Y' THEN
3782       gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_ATTRIBUTE_UPDATION value of p_Err_Code'||p_Err_Code,'C');
3783       gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - After EVENT_ATTRIBUTE_UPDATION value of p_Err_Buff'||p_Err_Buff,'C');
3784    END IF;
3785 
3786    IF p_Err_Code <> 0 THEN
3787       Raise NO_PROCESSING_OF_AWARD ;
3788    END IF;
3789 
3790  END LOOP;
3791 
3792  IF L_DEBUG = 'Y' THEN
3793     gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - END','C');
3794  END IF;
3795 
3796 EXCEPTION
3797 
3798     When Others then
3799 
3800       IF L_DEBUG = 'Y' THEN
3801       	gms_error_pkg.gms_debug('IN CREATE_PA_EVENTS - WHEN OTHERS ','C');
3802       END IF;
3803 
3804       gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
3805 				'SQLCODE',
3806 			        SQLCODE,
3807 				'SQLERRM',
3808 				SQLERRM,
3809 				X_Exec_Type => 'C',
3810 				X_Err_Code => p_Err_Code,
3811 				X_Err_Buff => p_Err_Buff);
3812 
3813      RAISE NO_PROCESSING_OF_AWARD;
3814 
3815 END CREATE_PA_EVENTS;
3816 
3817 -----------------------------------------------------------------------------------------
3818 -- Procedure DO_EVENT_PROCESSING: This procedure builds the Event description and creates the
3819 -- Billing or Revenue Event
3820 -----------------------------------------------------------------------------------------
3821 -- Bug 3235390 : Modified the logic as mentioned below
3822 --               a. Code to create events in pa_events and gms_event_attribute table is
3823 --                  shifted to CREATE_PA_EVENTS procedure.
3824 --               b. Events will be inserted into GBC and GEI and will be marked as billed/accrued.
3825 --               c. Events will be assigned a negative seqeunce number which starts from -1001
3826 --               d. Distinct events and their format will be temporarly stored in plsql table
3827 --               e. Newly introduced procedure CREATE_PA_EVENTS will fetch the consolidated
3828 --                  records from the plsql table and will insert events into Pa_events and
3829 --                  gms_event_attribute tables and updates GEI with newly generated event_num.
3830 --                  Even the NULL events logic is shifted to create_pa_events procedure.
3831 ----------------------------------------------------------------------------------------------------
3832 
3833 
3834 PROCEDURE DO_EVENT_PROCESSING(X_Count_Of_Columns IN NUMBER DEFAULT 0,
3835                               X_Sel_Grp_Diff_Ind IN Mark_Sel_Grp_Diff_Array ,
3836                               X_Right_Jstfy_Flag_Array IN Mark_Sel_Grp_Diff_Array,
3837                               X_Values IN Selected_Values_Rows,
3838                               X_Padding_Length IN Padding_Length_Array,
3839                               X_Run_Total IN Running_Total_Array ,
3840                               X_Text_Array IN Free_Text_Array,
3841                               X_Proj_Id IN NUMBER DEFAULT NULL,
3842 			      X_Task_Id IN NUMBER DEFAULT NULL,
3843 			      X_invfmt_incl_task IN VARCHAR2 DEFAULT 'N', /* Bug 3523930 */
3844                               X_Evt_Amount IN NUMBER DEFAULT NULL,
3845                               X_Carry_Out_Org_Id IN NUMBER DEFAULT NULL,
3846                               X_Through_Date IN DATE DEFAULT SYSDATE,
3847                               X_Call_Process IN VARCHAR2 DEFAULT NULL,
3848                               X_Req_Id IN NUMBER DEFAULT NULL,
3849                               C_Installment_Id IN NUMBER,
3850 			      X_Install_Count	IN NUMBER,
3851 			      X_Installment_Total IN OUT NOCOPY Inst_tab2,
3852 			      X_Err_Code IN OUT NOCOPY NUMBER,
3853 			      X_Err_Buff IN OUT NOCOPY VARCHAR2) IS
3854 
3855 CURSOR GET_RAW_ROWS_FROM_INTERSECT IS
3856 Select
3857  gei.award_project_id Award_Project_Id
3858 ,adl.project_id       Actual_Project_Id
3859 ,adl.task_id          Actual_Task_Id
3860 ,sum(gei.Amount) amount
3861 from
3862  gms_event_intersect gei,
3863  gms_award_distributions adl
3864 where
3865 gei.award_project_id    = X_Proj_Id  and
3866 gei.request_id          = X_Req_Id   and
3867 gei.event_type          = 'INVOICE'  and
3868 gei.event_num is NULL                and
3869 adl.expenditure_item_id = gei.expenditure_item_id and
3870 adl.adl_line_num = gei.adl_line_num and
3871 adl.document_type ='EXP'  and
3872 adl.adl_status ='A'
3873 group by
3874  gei.award_project_id,
3875  adl.project_id,
3876  adl.task_id;
3877 
3878 Evt_Num NUMBER(15);
3879 Evt_Description VARCHAR2(2000);
3880 Evt_format VARCHAR2(2000);
3881 X_Quantity NUMBER(22,5);
3882 
3883 -- 3120142
3884 x_pad1 number;
3885 x_pad2 number;
3886 x_pad3 number;
3887 -- 3120142
3888 
3889 Begin
3890 
3891   IF L_DEBUG = 'Y' THEN
3892  	gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - START ','C');
3893   END IF;
3894 
3895   /* Building the Event Description */
3896 
3897   For j in 1..X_Count_Of_Columns LOOP
3898 
3899 -- 3120142 Start
3900       gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3901 
3902   If X_Sel_Grp_Diff_Ind(j) = 'Y' then -- I
3903 
3904       --gms_error_pkg.gms_debug('****** X_Values(j) '||X_Values(j),'C');
3905       --gms_error_pkg.gms_debug('****** X_Padding_Length(j) '||X_Padding_Length(j),'C');
3906       --gms_error_pkg.gms_debug('****** length(X_Values(j)) '||length(X_Values(j)),'C');
3907 
3908       -- Grouping value ................... Start
3909 
3910       If   (X_Padding_Length(j)- length(X_Values(j))) <= 0 then
3911             X_pad1 := X_Padding_Length(j);
3912       Else
3913             X_pad1 := X_Padding_Length(j) - (abs(X_Padding_Length(j)- length(X_Values(j))));
3914       End If;
3915       gms_error_pkg.gms_debug('****** X_pad1 '||X_pad1,'C');
3916 
3917       If X_Right_Jstfy_Flag_Array(j) = 'N' then
3918          Evt_Description := Evt_Description||rpad(X_Values(j),X_Pad1)||' ';
3919       Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3920          Evt_Description := Evt_Description||lpad(X_Values(j),X_Pad1)||' ';
3921       End If;
3922 
3923       -- Grouping value ................... End
3924       gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3925 
3926   Elsif X_Sel_Grp_Diff_Ind(j) = 'N' then -- I
3927       -- Grouping Quantity ................... Start
3928       get_run_total(X_Req_id,X_Proj_Id,x_quantity);
3929       If   (X_Padding_Length(j)- length(to_char(x_quantity))) <= 0 then
3930             X_pad2 := X_Padding_Length(j);
3931       Else
3932             X_pad2 := X_Padding_Length(j) - (abs(X_Padding_Length(j)- length(to_char(x_quantity ))));
3933       End If;
3934       gms_error_pkg.gms_debug('****** X_pad2 '||X_pad1,'C');
3935 
3936       If X_Right_Jstfy_Flag_Array(j) = 'N' then
3937          Evt_Description := Evt_Description||rpad(to_char(x_quantity),x_pad2)||' ';
3938       Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3939          Evt_Description := Evt_Description||lpad(to_char(x_quantity),x_pad2)||' ';
3940       End If;
3941       -- Grouping Quantity ................... End
3942      gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3943 
3944   Elsif X_Sel_Grp_Diff_Ind(j) = 'T' then  -- I
3945 
3946     -- Grouping Text ................... Start
3947     If   (X_Padding_Length(j)- length(X_Text_Array(j))) <= 0 then
3948           X_pad3 := X_Padding_Length(j);
3949     Else
3950           X_pad3 := X_Padding_Length(j) - (abs(X_Padding_Length(j)- length(X_Text_Array(j))));
3951     End If;
3952 
3953     gms_error_pkg.gms_debug('****** X_pad3 '||X_pad3,'C');
3954 
3955     If X_Right_Jstfy_Flag_Array(j) = 'N' then
3956        Evt_Description := Evt_Description||rpad(X_Text_Array(j),x_pad3)||' ';
3957     Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3958        Evt_Description := Evt_Description||lpad(X_Text_Array(j),x_pad3)||' ';
3959     End If;
3960 
3961     -- Grouping Text ................... End
3962     gms_error_pkg.gms_debug('****** Evt_Description '||Evt_Description,'C');
3963  End If; -- I
3964 
3965 -- 3120142 End
3966 
3967 /* ------------------------------------------------------------- 3120142 --- commented out ----------------------
3968 
3969            If X_Sel_Grp_Diff_Ind(j) = 'Y' then
3970                If X_Right_Jstfy_Flag_Array(j) = 'N' then
3971                 Evt_Description := Evt_Description||rpad(X_Values(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3972 length(X_Values(j) ))))||' ';
3973                Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3974                  Evt_Description := Evt_Description||lpad(X_Values(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3975 length(X_Values(j) ))))||' ';
3976                End If;
3977            Elsif X_Sel_Grp_Diff_Ind(j) = 'N' then
3978 
3979                  get_run_total(X_Req_id,X_Proj_Id,x_quantity);
3980 
3981                If X_Right_Jstfy_Flag_Array(j) = 'N' then
3982                  Evt_Description := Evt_Description||rpad(to_char(x_quantity),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3983 length(to_char(x_quantity )))))||' ';
3984                Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3985                  Evt_Description := Evt_Description||rpad(to_char(x_quantity),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3986 length(to_char(x_quantity )))))||' ';
3987                End If;
3988            Elsif X_Sel_Grp_Diff_Ind(j) = 'T' then
3989                If X_Right_Jstfy_Flag_Array(j) = 'N' then
3990                  Evt_Description := Evt_Description||rpad(X_Text_Array(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3991 length(X_Text_Array(j) ))))||' ';
3992                Elsif X_Right_Jstfy_Flag_Array(j) = 'Y' then
3993                  Evt_Description := Evt_Description||rpad(X_Text_Array(j),X_Padding_Length(j) - (abs(X_Padding_Length(j)-
3994 length(X_Text_Array(j) ))))||' ';
3995                End If;
3996            End If;
3997  ------------------------------------------------------------- 3120142 --- commented out ---------------------- */
3998    End LOOP;
3999 
4000    FOR i IN 1..X_Count_Of_Columns LOOP
4001       IF X_Sel_Grp_Diff_Ind(i) = 'Y' then
4002           Evt_format := Evt_format||' - '||X_values(i);
4003       END IF;
4004 
4005    END LOOP;
4006 
4007    IF L_DEBUG = 'Y' THEN
4008       gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - Value of Evt_Description '||Evt_Description,'C');
4009       gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - Value of Evt_format '||Evt_format,'C');
4010    END IF;
4011 
4012    /*x_temp_negative_evt_num := x_temp_negative_evt_num - 1 ; Bug 3523930 - Moved this into process tempevents*/
4013    FOR raw_events IN GET_RAW_ROWS_FROM_INTERSECT LOOP
4014 
4015        PROCESS_TEMP_EVENTS  (raw_events.actual_project_id,
4016                              raw_events.actual_task_id,
4017 			     X_invfmt_incl_task, /* Added for bug 3523930 */
4018 		             Evt_format,
4019                              Evt_Description,
4020                              X_Call_Process,
4021                              NULL,
4022                              NULL,
4023 		             raw_events.amount,
4024                              evt_num,
4025     	                     x_err_code,
4026                              x_err_buff) ;
4027 
4028        IF L_DEBUG = 'Y' THEN
4029          gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of X_Err_Code '||X_Err_Code,'C');
4030          gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of x_err_buff '||x_err_buff,'C');
4031        END IF;
4032 
4033        IF X_Err_Code <> 0 then
4034          Raise NO_PROCESSING_OF_AWARD ;
4035        END IF;
4036 
4037       UPDATE_GMS_EVENT_INTERSECT(Evt_Num,
4038 	  		       X_Proj_Id,
4039 		  	       X_Req_Id,
4040                                raw_events.actual_project_id,
4041                                raw_events.actual_task_id );
4042 
4043       IF L_DEBUG = 'Y' THEN
4044          gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - After UPDATE_GMS_EVENT_INTERSECT','C');
4045       END IF;
4046 
4047    END LOOP;
4048 
4049 EXCEPTION
4050    WHEN OTHERS THEN
4051 
4052        IF L_DEBUG = 'Y' THEN
4053        	  gms_error_pkg.gms_debug('IN DO_EVENT_PROCESSING - WHEN OTHERS ','C');
4054        END IF;
4055        gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
4056 				'SQLCODE',
4057 			        SQLCODE,
4058 				'SQLERRM',
4059 				SQLERRM,
4060 				X_Exec_Type => 'C',
4061 				X_Err_Code => X_Err_Code,
4062 				X_Err_Buff => X_Err_Buff);
4063 END DO_EVENT_PROCESSING;
4064 
4065 ---------------------------------------------------------------------------------------
4066 --Procedure DO_BURDEN_EVENT_PROCESSING
4067 ---------------------------------------------------------------------------------------
4068 PROCEDURE DO_BURDEN_EVENT_PROCESSING(X_Project_Id   IN NUMBER,
4069 			             X_Through_Date IN DATE,
4070 				     X_Calling_Process IN VARCHAR2,
4071 				     X_Carrying_Out_Org_Id IN NUMBER,
4072 				     X_Request_Id IN NUMBER,
4073 				     X_Installment_total IN OUT NOCOPY Inst_tab2,
4074 				     X_Err_Code 	 IN OUT NOCOPY NUMBER,
4075 				     X_Err_Buff 	 IN OUT NOCOPY VARCHAR2) IS
4076 
4077 CURSOR GET_BURD_ROWS_FROM_INTERSECT IS
4078 Select
4079  Award_Project_Id
4080 ,Actual_Project_Id
4081 ,Actual_Task_Id
4082 ,Burden_Cost_Code
4083 ,Expenditure_Org_Id
4084 ,sum(Amount)
4085 from
4086 GMS_BURDEN_COMPONENTS
4087 where
4088 award_project_id    = X_Project_Id  and
4089 request_id          = X_Request_Id       and
4090 event_type          = decode(X_Calling_Process,'Revenue','REVENUE','Invoice','INVOICE') and
4091 event_num is NULL
4092 group by
4093  Award_Project_Id
4094 ,Actual_Project_Id
4095 ,Actual_Task_Id
4096 ,Burden_Cost_Code
4097 ,Expenditure_Org_Id ;
4098 
4099 Ins_Award_Project_Id     NUMBER := 0;
4100 Ins_Actual_Project_Id    NUMBER := 0;
4101 Ins_Actual_Task_Id       NUMBER := 0;
4102 Ins_Burden_Cost_Code     VARCHAR2(30) := NULL;
4103 Ins_Expenditure_Org_Id   NUMBER := 0;
4104 Ins_Amount               NUMBER := 0;
4105 
4106 Ins_Act_Proj_Num        VARCHAR2(30);
4107 Ins_Act_Task_Num        VARCHAR2(30);
4108 --Ins_Exp_Org_Name        VARCHAR2(60);
4109 --The width of the variable is changed for UTF8 changes for HRMS schema. Refer bug 2302839.
4110 Ins_Exp_Org_Name  HR_ALL_ORGANIZATION_UNITS_TL.NAME%TYPE;
4111 
4112 Evt_Num NUMBER(15) := 0;
4113 Evt_Description VARCHAR2(2000) := NULL;
4114 
4115 St_Error_Message VARCHAR2(2000);
4116 St_Status NUMBER;
4117 
4118 Begin
4119 
4120  IF L_DEBUG = 'Y' THEN
4121  	gms_error_pkg.gms_debug('IN BURDEN EVENT - START','C');
4122  END IF;
4123 
4124  OPEN GET_BURD_ROWS_FROM_INTERSECT;
4125  LOOP
4126   FETCH GET_BURD_ROWS_FROM_INTERSECT into
4127    Ins_Award_Project_Id
4128   ,Ins_Actual_Project_Id
4129   ,Ins_Actual_Task_Id
4130   ,Ins_Burden_Cost_Code
4131   ,Ins_Expenditure_Org_Id
4132   ,Ins_Amount;
4133           EXIT WHEN GET_BURD_ROWS_FROM_INTERSECT%NOTFOUND;
4134 
4135    If Ins_Amount <> 0 then
4136    -- DO NOT INSERT ZERO AMOUNT EVENTS
4137    IF L_DEBUG = 'Y' THEN
4138    	gms_error_pkg.gms_debug('DBP - If Ins_Amount <> 0 part ..','C');
4139    END IF;
4140 
4141        /* Getting Actual Project Number, Task Number and Expenditure Organization Name */
4142            Begin
4143              Select
4144                a.segment1,
4145                b.task_number,
4146                c.name
4147              into
4148                Ins_Act_Proj_Num,
4149   	       Ins_Act_Task_Num,
4150 	       Ins_Exp_Org_Name
4151              from
4152              pa_projects_all a,
4153 	     pa_tasks b,
4154              hr_organization_units c
4155              where a.project_id = Ins_Actual_Project_Id  and
4156 		   b.task_id    = Ins_Actual_Task_Id     and
4157                    c.organization_id = Ins_Expenditure_Org_Id;
4158            End;
4159 
4160  --------------------------------------------------------------------------
4161  /* Get the Installment Number to be concatenated with Event Description */
4162  --------------------------------------------------------------------------
4163  IF L_DEBUG = 'Y' THEN
4164  	gms_error_pkg.gms_debug('DBP - CALL EVENT WRAPPER','C');
4165  END IF;
4166  EVENT_WRAPPER(X_Project_Id,
4167 		Ins_Actual_Project_Id,
4168                 Ins_Actual_Task_Id,
4169                 X_Calling_Process,
4170                 Ins_Amount,
4171                 X_Installment_Total,
4172 --                Inst_Num,		Bug 2380344
4173 		Ins_Burden_Cost_Code,
4174 		Ins_Expenditure_Org_Id,
4175 		X_Request_Id,
4176                 X_Err_Code,
4177                 X_Err_Buff);
4178 
4179                 If X_Err_Code <> 0 then
4180 			--ROLLBACK;
4181                         --RAISE FND_API.G_EXC_ERROR;
4182 			Raise NO_PROCESSING_OF_AWARD ;
4183                 End If;
4184  IF L_DEBUG = 'Y' THEN
4185  	gms_error_pkg.gms_debug('DBP - AFTER EVENT WRAPPER','C');
4186  END IF;
4187 
4188 -------------------------------------------------------------------------------------
4189        /* Getting the Event Number */
4190                     Evt_Num := pa_billing_seq.next_eventnum(Ins_Award_Project_Id,NULL);
4191 
4192  IF L_DEBUG = 'Y' THEN
4193  	gms_error_pkg.gms_debug('DBP - Evt_Num::'||Evt_Num,'C');
4194  END IF;
4195 
4196 
4197        /* Building the Event Description */
4198   Evt_Description := Ins_Act_Proj_Num||'- '||Ins_Act_Task_Num||' - '||Ins_Burden_Cost_Code||'- '||Ins_Exp_Org_Name ;	-- Bug 2380344 : Removed Inst_Num
4199 
4200      If X_Calling_Process = 'Revenue' then
4201          pa_billing_pub.insert_event(
4202 				X_rev_amt => Ins_Amount,         /* X_rev_amt */
4203                                 X_bill_amt => 0,                      /* X_bill_amt */
4204                                 X_project_id => Ins_Award_Project_Id,            /* X_project_id */
4205                                 X_event_type => 'AWARD_BILLING',             /* X_event_type */
4206                                 X_top_task_id => NULL,                    /* X_top_task_id */
4207                                 X_organization_id => X_Carrying_Out_Org_Id,   /* X_organization_id */
4208                                 X_completion_date => X_Through_Date,      /* X_completion_date */
4209                                 X_event_description => Evt_Description,     /* X_event_description */
4210                                 X_event_num_reversed => NULL,         /* Event Num Reversed */
4211                                 X_attribute_category => NULL,                    /* X_attribute_category */
4212                                 X_attribute1 => NULL,	 /* X_attribute1 */
4213                                 X_attribute2 => NULL,                    /* X_attribute2 */
4214                                 X_attribute3 => NULL,                    /* X_attribute3 */
4215                                 X_attribute4 => NULL,                    /* X_attribute4 */
4216                                 X_attribute5 => NULL,                    /* X_attribute5 */
4217                                 X_attribute6 => NULL,                    /* X_attribute6 */
4218                                 X_attribute7 => NULL,                    /* X_attribute7 */
4219                                 X_attribute8 => NULL,                    /* X_attribute8 */
4220                                 X_attribute9 => NULL,                    /* X_attribute9 */
4221                                 X_attribute10 => NULL,                     /* X_attribute10 */
4222 				X_error_message => St_Error_Message,
4223                                 X_status => St_Status
4224 				);
4225 
4226      Elsif X_Calling_Process = 'Invoice' then
4227 
4228         pa_billing_pub.insert_event(
4229 				X_rev_amt => 0,         /* X_rev_amt */
4230                                 X_bill_amt => Ins_Amount,                      /* X_bill_amt */
4231                                 X_project_id => Ins_Award_Project_Id,            /* X_project_id */
4232                                 X_event_type => 'AWARD_BILLING',             /* X_event_type */
4233                                 X_top_task_id => NULL,                    /* X_top_task_id */
4234                                 X_organization_id => X_Carrying_Out_Org_Id,   /* X_organization_id */
4235                                 X_completion_date => X_Through_Date,      /* X_completion_date */
4236                                 X_event_description => Evt_Description,     /* X_event_description */
4237                                 X_event_num_reversed => NULL,         /* Event Num Reversed */
4238                                 X_attribute_category => NULL,                    /* X_attribute_category */
4239                                 X_attribute1 => NULL, /* X_attribute1 */
4240                                 X_attribute2 => NULL,                    /* X_attribute2 */
4241                                 X_attribute3 => NULL,                    /* X_attribute3 */
4242                                 X_attribute4 => NULL,                    /* X_attribute4 */
4243                                 X_attribute5 => NULL,                    /* X_attribute5 */
4244                                 X_attribute6 => NULL,                    /* X_attribute6 */
4245                                 X_attribute7 => NULL,                    /* X_attribute7 */
4246                                 X_attribute8 => NULL,                    /* X_attribute8 */
4247                                 X_attribute9 => NULL,                    /* X_attribute9 */
4248                                 X_attribute10 => NULL,                     /* X_attribute10 */
4249 				X_error_message => St_Error_Message,
4250                                 X_status => St_Status
4251 				);
4252      End If;
4253 
4254      IF L_DEBUG = 'Y' THEN
4255      	gms_error_pkg.gms_debug('After API Event->Status Code,Message:'||St_Status||','||St_Error_Message,'C');
4256      END IF;
4257      If St_Status <> 0 then
4258 
4259         IF L_DEBUG = 'Y' THEN
4260         	gms_error_pkg.gms_debug('!!! IN Burden EVENT - API Call Exception !!! ','C');
4261         END IF;
4262         RAISE NO_PROCESSING_OF_AWARD;
4263 
4264      End If;
4265 
4266      IF L_DEBUG = 'Y' THEN
4267      	gms_error_pkg.gms_debug('DBP - After Event Creation','C');
4268      END IF;
4269 
4270     /* ------------------------------------------------------------------------------- */
4271     -- Updating Event Attribute
4272 
4273     EVENT_ATTRIBUTE_UPDATION(Evt_Num,
4274                              X_Project_Id,
4275                              X_Request_Id,
4276                              X_Err_Code,
4277                              X_Err_Buff);
4278 
4279                 If X_Err_Code <> 0 then
4280 			Raise NO_PROCESSING_OF_AWARD ;
4281                 End If;
4282 
4283     IF L_DEBUG = 'Y' THEN
4284     	gms_error_pkg.gms_debug('DBP - After Event Attribute Updation','C');
4285     END IF;
4286 
4287  ElsIf Ins_Amount = 0 then
4288 
4289     IF L_DEBUG = 'Y' THEN
4290     	gms_error_pkg.gms_debug('DBP - In Ins_Amount = 0 part ...','C');
4291     END IF;
4292 
4293     -- ------------------------------------------------------------------------------------
4294     -- Event num NULL change ...
4295     -- -------------------------
4296     -- If event amount  = 0 , update GBC record with event_num of -2. Set package variable
4297     -- indicating that there are burden records created with event num -2. In procedure
4298     -- award_billing, there is a check for this flag. If flag is set, then procedure
4299     -- DELETE_NULL_EVENTS will be called.
4300     -- Event Number is -2 so that billing_rollback does not rollback events..
4301     -- ------------------------------------------------------------------------------------
4302               Evt_Num := -2;
4303 
4304               -- Set package variable to TRUE, accessed in award_billing procedure..
4305               X_BURDEN_NULL_EVENT_PROCESSED := TRUE;
4306 
4307     End If; -- DO NOT INSERT ZERO AMOUNT EVENTS
4308 
4309    /* ------------------------------------------------------------------------------- */
4310    -- Updating Burden Components
4311 
4312               UPDATE_GMS_BURDEN_COMPONENTS(Evt_Num ,
4313                                            Ins_Award_Project_Id,
4314                                            X_Request_Id ,
4315                                            Ins_Actual_Project_Id ,
4316                                        	   Ins_Actual_Task_Id ,
4317                                            Ins_Burden_Cost_Code ,
4318                                            Ins_Expenditure_Org_Id );
4319 
4320    IF L_DEBUG = 'Y' THEN
4321    	gms_error_pkg.gms_debug('DBP - After GBC Updation','C');
4322    END IF;
4323 
4324   End LOOP;
4325 
4326   IF L_DEBUG = 'Y' THEN
4327   	gms_error_pkg.gms_debug('IN BURDEN EVENT - END','C');
4328   END IF;
4329 
4330 Exception
4331 
4332     When Others then
4333 
4334       IF L_DEBUG = 'Y' THEN
4335       	gms_error_pkg.gms_debug('IN BURDEN EVENT WHEN OTHERS ','C');
4336       END IF;
4337 
4338       gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
4339 				'SQLCODE',
4340 			        SQLCODE,
4341 				'SQLERRM',
4342 				SQLERRM,
4343 				X_Exec_Type => 'C',
4344 				X_Err_Code => X_Err_Code,
4345 				X_Err_Buff => X_Err_Buff);
4346 
4347      RAISE NO_PROCESSING_OF_AWARD;
4348 
4349 End DO_BURDEN_EVENT_PROCESSING;
4350 ---------------------------------------------------------------------------------------
4351 
4352 ----------------------------------------------------------------------------------------
4353 --Procedure DO_REV_EVENT_PROCESSING
4354 -----------------------------------------------------------------------------------------
4355 -- Bug 3235390 : Modified the logic as mentioned below
4356 --               a. Code to create events in pa_events and gms_event_attribute table is
4357 --                  shifted to CREATE_PA_EVENTS procedure.
4358 --               b. Events will be inserted into GBC and GEI and will be marked as billed/accrued.
4359 --               c. Events will be assigned a negative seqeunce number which starts from -1001
4360 --               d. Distinct events and their format will be temporarly stored in plsql table
4361 --               e. Newly introduced procedure CREATE_PA_EVENTS will fetch the consolidated
4362 --                  records from the plsql table and will insert events into Pa_events and
4363 --                  gms_event_attribute tables and updates GEI with newly generated event_num.
4364 --                  Even the NULL events logic is shifted to create_pa_events procedure.
4365 ----------------------------------------------------------------------------------------------------
4366 
4367 PROCEDURE  DO_REV_EVENT_PROCESSING(X_Act_Project_Id          IN NUMBER,
4368                    	           X_Task_Id                 IN NUMBER,
4369                                    X_Expenditure_Type        IN VARCHAR2,
4370                                    X_Expenditure_Org_Id      IN NUMBER,
4371 				   X_Units		     IN VARCHAR2,
4372                                    X_Rev_Run_Total           IN NUMBER,
4373                                    X_Project_Id              IN NUMBER,
4374                                    X_Rev_Event_Amount        IN NUMBER,
4375                                    X_Rev_Carrying_Out_Org_Id IN NUMBER,
4376                                    X_rev_or_bill_date        IN DATE,
4377                                    X_calling_process	     IN VARCHAR2,
4378                                    X_Request_id              IN NUMBER,
4379                                    C_Installment_Id          IN NUMBER,
4380 			           X_Install_Count	     IN NUMBER,
4381 			           X_Installment_Total       IN OUT NOCOPY Inst_tab2,
4382 			           X_Err_Code 		     IN OUT NOCOPY NUMBER,
4383 			           X_Err_Buff 	 	     IN OUT NOCOPY VARCHAR2) IS
4384 
4385 CURSOR GET_RAW_ROWS_FROM_INTERSECT IS
4386 SELECT 'Y'
4387   FROM gms_event_intersect gei,
4388        gms_award_distributions adl
4389  WHERE gei.award_project_id    = X_Project_Id
4390    AND gei.request_id          = X_Request_Id
4391    AND gei.event_type          = 'REVENUE'
4392    AND gei.event_num is NULL
4393    AND adl.expenditure_item_id = gei.expenditure_item_id
4394    AND adl.adl_line_num = gei.adl_line_num
4395    AND adl.document_type ='EXP'
4396    AND adl.adl_status ='A'
4397    AND adl.project_id          = X_Act_Project_Id
4398    AND adl.task_id             = X_Task_Id
4399    AND ROWNUM =1 ;
4400 
4401 Evt_Num NUMBER(15);
4402 Evt_Description VARCHAR2(2000);
4403 --Inst_Num VARCHAR2(15);	Bug 2380344
4404 Ins_Act_Proj_Num VARCHAR2(30);
4405 Ins_Act_Task_Num VARCHAR2(30);
4406 --Ins_Exp_Org_Name VARCHAR2(60);
4407 -- The widht of the variable is changed for UTF8 changes for HRMS schema. Refer bug 2302839.
4408 Ins_Exp_Org_Name  HR_ALL_ORGANIZATION_UNITS_TL.NAME%TYPE;
4409 Evt_format VARCHAR2(2000);
4410 X_event_exists VARCHAR2(1);
4411 
4412 Begin
4413 
4414  IF L_DEBUG = 'Y' THEN
4415     gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - START','C');
4416  END IF;
4417 
4418  OPEN GET_RAW_ROWS_FROM_INTERSECT;
4419  FETCH GET_RAW_ROWS_FROM_INTERSECT INTO X_event_exists;
4420 
4421  IF GET_RAW_ROWS_FROM_INTERSECT%FOUND THEN
4422 
4423      /* Getting Actual Project Number, Task Number and Expenditure Organization Name */
4424      Begin
4425              Select
4426                a.segment1,
4427                b.task_number,
4428                c.name
4429              into
4430                Ins_Act_Proj_Num,
4431   	       Ins_Act_Task_Num,
4432 	       Ins_Exp_Org_Name
4433              from
4434              pa_projects_all a,
4435 	     pa_tasks b,
4436              hr_organization_units c
4437              where a.project_id = X_Act_Project_Id  and
4438 		   b.task_id    = X_Task_Id     and
4439                    c.organization_id = X_Expenditure_Org_Id;
4440      End;
4441 
4442      --Concatenating Installment Number to Event Description
4443      Evt_Description := Ins_Act_Proj_Num||'- '||Ins_Act_Task_Num||' - '||X_Expenditure_Type;
4444      --Moved X_Rev_Run_Total and X_Units concatenation to PROCESS_TEMP_EVENTS procedure
4445      ---||'- '||to_char(X_Rev_Run_Total)||' '||X_Units; -- Bug 2380344 : Removed inst_num
4446      Evt_format      := X_Act_Project_Id||' - '||X_Task_Id||' - '||X_Expenditure_Type||' - '||X_Expenditure_Org_Id ; -- Bug 3235390
4447 
4448      IF L_DEBUG = 'Y' THEN
4449         gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - Value of Evt_Description '||Evt_Description,'C');
4450         gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - Value of Evt_format '||Evt_format,'C');
4451      END IF;
4452 
4453    /*x_temp_negative_evt_num := x_temp_negative_evt_num - 1 ; Bug 3523930 - Moved this into process tempevents*/
4454      PROCESS_TEMP_EVENTS  (X_Act_Project_Id,
4455                            X_task_id,
4456 			   'Y',  /* Added for bug 3523930 */
4457                            Evt_format,
4458                            Evt_Description,
4459                            X_calling_process,
4460                            X_Units,
4461                            X_Rev_Run_total,
4462                            X_Rev_Event_Amount,
4463                            evt_num,
4464     	                   x_err_code,
4465                            x_err_buff) ;
4466 
4467      IF L_DEBUG = 'Y' THEN
4468         gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of X_Err_Code '||X_Err_Code,'C');
4469         gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - After PROCESS_TEMP_EVENTS value of x_err_buff '||x_err_buff,'C');
4470      END IF;
4471 
4472      IF X_Err_Code <> 0 then
4473         Raise NO_PROCESSING_OF_AWARD ;
4474      END IF;
4475 
4476 
4477       UPDATE_GMS_EVENT_INTERSECT(Evt_Num,
4478 	  		       X_Project_Id,
4479 		  	       X_Request_Id,
4480                                X_Act_Project_Id,
4481                                X_Task_Id );
4482 
4483      IF L_DEBUG = 'Y' THEN
4484         gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - After UPDATE_GMS_EVENT_INTERSECT','C');
4485       	gms_error_pkg.gms_debug('IN DO_REV_EVENT_PROCESSING - END','C');
4486      END IF;
4487 
4488   END IF;
4489   CLOSE GET_RAW_ROWS_FROM_INTERSECT;
4490 
4491 End DO_REV_EVENT_PROCESSING;
4492 
4493 -------------------------------------------------------------------------------------------
4494 --Procedure GET_BURDEN_COMPONENT_DATA returns the burden_components and the burden amounts
4495 -------------------------------------------------------------------------------------------
4496 PROCEDURE GET_BURDEN_COMPONENT_DATA(P_project_id              IN NUMBER,
4497 				    P_task_id                 IN NUMBER,
4498 				    P_expenditure_org_id      IN NUMBER,
4499 				    P_ind_compiled_set_id     IN NUMBER,
4500 			            P_burdenable_raw_cost     IN NUMBER,
4501 				    P_expenditure_type        IN VARCHAR2,
4502 				    P_Burden_Components_Count OUT NOCOPY   NUMBER,
4503 				    P_Burden_Component_Data   OUT NOCOPY   Burden_Component_Tab_Type )IS
4504 
4505 CURSOR Get_Components_Cursor IS
4506 SELECT cm.ind_cost_code,
4507        icc.expenditure_type icc_expenditure_type,
4508        --Bug 10151331 removed the rounding as part of the code fix
4509        --BUG 13682664 reverts the change of the Bug 10151331.
4510        sum(pa_currency.round_currency_amt (P_burdenable_raw_cost * cm.compiled_multiplier)) Tot_Exp_Item_Burden_Cost
4511        --sum(P_burdenable_raw_cost * cm.compiled_multiplier) Tot_Exp_Item_Burden_Cost
4512    FROM pa_ind_cost_codes icc,
4513        pa_compiled_multipliers cm,
4514        --pa_ind_compiled_sets ics,  /* For bug 6969435 */
4515        pa_cost_base_exp_types cbet,
4516        PA_COST_BASE_COST_CODES CBCC /* For bug 6969435 */
4517        --pa_cost_bases cb,/* For bug 6969435 */
4518        --pa_ind_rate_sch_revisions irsr,/* For bug 6969435 */
4519        --pa_ind_rate_schedules_all_bg irs/* For bug 6969435 */
4520  WHERE --ics.ind_rate_sch_revision_id = irsr.ind_rate_sch_revision_id/* For bug 6969435 */
4521    --AND irs.ind_rate_sch_id          = irsr.ind_rate_sch_id/* For bug 6969435 */
4522    --AND irsr.cost_plus_structure     = cbet.cost_plus_structure/* For bug 6969435 */
4523     cbet.cost_base               = cm.cost_base
4524    --AND cb.cost_base                 = cbet.cost_base/* For bug 6969435 */
4525    --AND ics.cost_base                = cbet.cost_base/* For bug 6969435 */
4526    --AND cb.cost_base_type            = cbet.cost_base_type/* For bug 6969435 */
4527    AND cbet.cost_base_type          = 'INDIRECT COST'
4528    AND cbet.expenditure_type        = P_expenditure_type
4529    --AND ics.organization_id          = P_expenditure_org_id/* For bug 6969435 */
4530    --AND ics.ind_compiled_set_id      = cm.ind_compiled_set_id/* For bug 6969435 */
4531    AND icc.ind_cost_code            = cm.ind_cost_code
4532    AND cm.ind_compiled_set_id      = P_ind_compiled_set_id /* For bug 6969435 */
4533    AND cbcc.cost_plus_structure     = cbet.cost_plus_structure   /* For bug 6969435 */
4534    AND cbcc.cost_base               = cbet.cost_base             /* For bug 6969435 */
4535    AND cbcc.cost_base_type          = cbet.cost_base_type        /* For bug 6969435 */
4536    AND cm.cost_base_cost_code_Id    = cbcc.cost_base_cost_code_Id /* For bug 6969435 */
4537    AND cm.ind_cost_code             = cbcc.ind_cost_code  /* For bug 6969435 */
4538    and cm.compiled_multiplier <> 0
4539    group by cm.ind_cost_code, icc.expenditure_type;
4540 
4541 St_Burden_Components_Count NUMBER := 0;
4542 
4543 Begin
4544 
4545    FOR Get_Components_Record IN Get_Components_Cursor
4546    LOOP
4547     --  commenting this out so that datafixes will work  ...differential billing ..
4548     --If Get_Components_Record.Tot_Exp_Item_Burden_Cost <> 0 then
4549      St_Burden_Components_Count := St_Burden_Components_Count + 1;
4550      P_Burden_Component_Data(St_Burden_Components_Count).Actual_Project_Id       := P_Project_Id;
4551      P_Burden_Component_Data(St_Burden_Components_Count).Actual_Task_Id          := P_Task_Id;
4552      P_Burden_Component_Data(St_Burden_Components_Count).Expenditure_Org_Id      := P_expenditure_org_id;
4553      P_Burden_Component_Data(St_Burden_Components_Count).Burden_Expenditure_Type := Get_Components_Record.Icc_Expenditure_Type;
4554      P_Burden_Component_Data(St_Burden_Components_Count).Burden_Cost_Code        := Get_Components_Record.Ind_Cost_Code;
4555      P_Burden_Component_Data(St_Burden_Components_Count).Burden_Cost             := Get_Components_Record.Tot_Exp_Item_Burden_Cost;
4556    --End If;
4557   END LOOP;
4558 
4559      P_Burden_Components_Count := St_Burden_Components_Count;
4560 
4561 End GET_BURDEN_COMPONENT_DATA;
4562 -----------------------------------------------------------------------------------------
4563 -- Procedure FORMAT_SPECIFIC_BILLING: This procedure is the core of the billing extension. It
4564 -- builds the select statement given the Invoice Format Details, execution of which then processes
4565 -- all the expenditure items which meet the selection criteria. This procedure is executed once for
4566 -- each installment within the Award being processed. The expenditure items picked up have to have
4567 -- an expenditure item date which falls within the start and end date of the installment. This procedure
4568 -- also checks to see that the amount on the expenditure items doesnot exceed the amount left on the
4569 -- installment that can be billed.
4570 -----------------------------------------------------------------------------------------
4571 PROCEDURE FORMAT_SPECIFIC_BILLING(X_Project_Id IN NUMBER,
4572                                   X_Award_Id IN NUMBER,
4573                                   X_Class_Category IN VARCHAR2,
4574                                   X_rev_or_bill_date IN DATE,
4575    				  --X_Revenue_Limit_Flag IN VARCHAR2,
4576    				                  X_Invoice_Limit_Flag IN VARCHAR2, /*Bug 6642901*/
4577                                   X_Request_Id IN NUMBER,
4578                                   X_Sel_Grp_Diff_Array IN Mark_Sel_Grp_Diff_Array,
4579                                   X_Cnt_Of_Columns_Selected IN NUMBER,
4580                                   X_Rt_Jstfy_Flag_Array IN Mark_Sel_Grp_Diff_Array,
4581                                   X_Padding_Length_Array IN Padding_Length_Array,
4582                                   X_Text_Array IN Free_Text_Array,
4583                                   X_sql_select IN VARCHAR2,
4584                                   X_Carrying_Out_Org_Id IN NUMBER,
4585                                   X_calling_process IN VARCHAR2,
4586 				  X_invfmt_incl_task IN VARCHAR2,  /* Added for bug 3523930 */
4587                                   C_Installment_Id IN NUMBER,
4588                                   C_Start_Date_Active IN DATE,
4589                                   C_End_Date_Active IN DATE,
4590                                   X_Err_Num OUT NOCOPY NUMBER,
4591                                   X_Err_Stage OUT NOCOPY VARCHAR2,
4592 				  g_mode IN VARCHAR2,               /* added for bug 5026657 */
4593 				  g_labor_exp_to_process OUT NOCOPY VARCHAR2,        /* added for bug 5026657 */
4594 				  g_non_labor_neg_exp_processed OUT NOCOPY VARCHAR2  /* added for bug 5026657 */
4595 				  ) IS
4596 X_Run_Total Running_Total_Array;
4597 X_Old_Values Selected_Values_Rows;
4598 X_New_Values Selected_Values_Rows;
4599 
4600 cur_select INTEGER := 0;
4601 X_Rows_Processed INTEGER := 0;
4602 X_Expenditure_Item_Id 		PA_EXPENDITURE_ITEMS_ALL.EXPENDITURE_ITEM_ID%TYPE;
4603 X_Expenditure_Item_Date   	PA_EXPENDITURE_ITEMS_ALL.EXPENDITURE_ITEM_DATE%TYPE;
4604 X_Task_Id                 	PA_EXPENDITURE_ITEMS_ALL.TASK_ID%TYPE;
4605 X_Bill_Hold_Flag          	PA_EXPENDITURE_ITEMS_ALL.BILL_HOLD_FLAG%TYPE; --VARCHAR2(1);
4606 X_Billable_Flag           	PA_EXPENDITURE_ITEMS_ALL.BILLABLE_FLAG%TYPE;  --VARCHAR2(1);
4607 X_Adjusted_Expenditure_Item_Id  PA_EXPENDITURE_ITEMS_ALL.ADJUSTED_EXPENDITURE_ITEM_ID%TYPE;
4608 X_First_Indicator         	BOOLEAN := TRUE;
4609 
4610 -- 11.5 Changes Start
4611 X_Adl_Line_Num			gms_award_distributions.adl_line_num%type;
4612 X_Cdl_Line_Num			gms_award_distributions.cdl_line_num%type; --bug 2909746
4613 X_Parent_Adl_Line_Num		gms_award_distributions.parent_adl_line_num%type;
4614 X_Adl_Status			gms_award_distributions.adl_status%type;
4615 X_Bill_Award_Id			gms_award_distributions.award_id%type;
4616 St_Err_Code  NUMBER(1);
4617 St_Err_Buff    Varchar2(2000);
4618 X_Installment_Status Varchar2(1) :=null;
4619 X_Count  Number :=0;
4620 X_Money_On_Curr_Inst number(22,5);
4621 -- 11.5 Changes End
4622 
4623 X_Money_Left_In_Inst  NUMBER(22,5) := 0;  -- Amount left in Installment that can be billed
4624 X_Total_Funding_Amount NUMBER(22,5) := 0; -- Total Funding by Installment,Task for a particular Project
4625 X_Total_Rev_Bill_Amount  NUMBER(22,5) := 0; -- Total Revenue or Billed Amount(Depending on the Calling Process)
4626                                             -- by Installment, Task for a particular Project
4627 X_Raw_Cost PA_EXPENDITURE_ITEMS_ALL.RAW_COST%TYPE; -- Amount on the Current Transaction being Processed
4628 X_Amount_In_Intersect NUMBER(22,5) := 0; -- Sum of Amounts in Intersect table for current Trx being processed
4629 X_Amount_To_Insert NUMBER(22,5) := 0; -- Amount to be Inserted into Intersect Table,(X_Raw_Cost - X_Amount_In_Intersect)
4630 X_Event_Amount NUMBER(22,5) := 0; -- Running total for the Amount for which Event is to be created
4631 C_Inst_Task_Run_Total NUMBER(22,5):= 0; -- Running Total for the amount that will be billed on this Installment.
4632                                -- Adds the amount on the Trx being processed to current total. When processing is done for
4633                                -- this Installment, this amount will be added to the existing billed amount on Installment
4634                                -- and Installment updated with the total amount.
4635 X_Amount_To_Accrue_Bill_Insert NUMBER;
4636 
4637 X_Err_Nbr NUMBER(15) := NULL;
4638 X_Err_Stg VARCHAR2(200) := NULL;
4639 
4640 X_Lock_Exp_Id  VARCHAR2(30);
4641 
4642 X_Adl_Lock_Exp_Id  gms_award_distributions.expenditure_item_id%type; -- 11.5 change
4643 
4644 X_Orig_Item_Billed_Flag  VARCHAR2(2);
4645 X_Actual_project_id NUMBER(15);
4646 X_Adl_Orig_Item_Billed_Flag VARCHAR2(1); -- 11.5 change
4647 
4648 X_Burden_Component_Data     Burden_Component_Tab_Type;
4649 X_Burden_Components_Count   NUMBER := 0;
4650 X_Amt_In_Tmp_By_Component       NUMBER := 0;
4651 X_Tot_Burd_Amt_In_Tmp      NUMBER := 0;
4652 X_Tot_Burden_Amt_In_View	  NUMBER := 0;
4653 X_Burd_Amt_To_Insert_By_Comp    NUMBER := 0;
4654 X_Tot_Burd_Amt_To_Insert     NUMBER := 0;
4655 
4656 /* bug 5242484 start */
4657 X_old_expenditure_item_id NUMBER(15) := -9999 ;
4658 X_event_rollback_amount NUMBER(22,5) := 0;
4659 k NUMBER := 0;
4660 /* bug 5242484 end */
4661 
4662 /* Bug 3523930 Start*/
4663 X_old_task_id pa_expenditure_items_all.task_id%type;
4664 X_new_task_id pa_expenditure_items_all.task_id%type;
4665 X_old_actprj_id pa_expenditure_items_all.project_id%type;
4666 X_new_actprj_id pa_expenditure_items_all.project_id%type;
4667 /* Bug 3523930 End*/
4668 ss_text VARCHAR2(300);
4669 RESOURCE_BUSY EXCEPTION;
4670 PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -00054);
4671 
4672  -- Bug 3630577 : performance fix ..
4673 X_expenditure_type    pa_expenditure_items_all.expenditure_type%type;
4674 X_expenditure_org_id  pa_expenditure_items_all.override_to_organization_id%type;
4675 X_ind_compiled_set_id pa_cost_distribution_lines_all.ind_compiled_set_id%type;
4676 X_burdenable_raw_cost gms_award_distributions.burdenable_raw_cost%type;
4677 X_transaction_source  pa_transaction_sources.transaction_source%type;
4678 
4679 Begin
4680 
4681   /* To set project_id NULL to be able to use Suresh's view to derive Burden Components and Burden Cost */
4682       -- GMS_BURDEN_COSTING.SET_CURRENT_PROJECT_ID(NULL);
4683        -- The above line has been commented out NOCOPY for bug 2442827
4684 
4685   /* bug 5026657  */
4686 g_labor_exp_to_process := 'N';
4687 g_non_labor_neg_exp_processed := 'N';
4688 
4689   -- dbms_output.put_line(X_sql_select);
4690   cur_select := DBMS_SQL.OPEN_CURSOR;
4691 -----------------------------------------------------------
4692  -- Initializing Old Values Table and New Values Table
4693    For i in 1..X_Cnt_Of_Columns_Selected LOOP
4694      X_Old_Values(i) := NULL;
4695      X_New_Values(i) := NULL;
4696      X_Run_Total(i) := 0;
4697    END LOOP;
4698 /* Bug 3523930 Start -Initializing the Project and task values too*/
4699 X_old_task_id := NULL;
4700 X_new_task_id :=NULL;
4701 X_old_actprj_id :=NULL;
4702 X_new_actprj_id :=NULL;
4703 /* Bug 3523930 End*/
4704 ------------------------------------------------------------
4705 --------------------------------------------------------------------
4706 -- Parsing the Select statement and defining Bind Variable for the --
4707 -- Input parameter Project Id --
4708   DBMS_SQL.PARSE(cur_select,X_sql_select,dbms_sql.native);
4709   --dbms_output.put_line('After Parse');
4710   DBMS_SQL.BIND_VARIABLE(cur_select,':X_Award_Id', X_Award_Id);
4711   DBMS_SQL.BIND_VARIABLE(cur_select,':X_rev_or_bill_date',X_rev_or_bill_date);
4712 --  DBMS_SQL.BIND_VARIABLE(cur_select,':C_Start_Date_Active',C_Start_Date_Active);
4713   DBMS_SQL.BIND_VARIABLE(cur_select,':C_End_Date_Active',C_End_Date_Active);
4714  --dbms_output.put_line('After Bind');
4715     DBMS_SQL.BIND_VARIABLE(cur_select,':C_Installment_id',C_Installment_id);
4716 ---------------------------------------------------------------------
4717 ----------------------------------------------------------
4718 -- Defining Fetch Variables for all the Columns Fetched --
4719   For i in 1..X_Cnt_Of_Columns_Selected LOOP
4720      DBMS_SQL.DEFINE_COLUMN(cur_select,i, X_Old_Values(i),1000);
4721   END LOOP;
4722      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 1, X_Raw_Cost);
4723      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 2, X_Expenditure_Item_Id);
4724      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 3, X_Expenditure_Item_Date);
4725      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 4, X_Task_Id);
4726      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 5, X_Bill_Hold_Flag,1);
4727      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 6, X_Billable_Flag,1);
4728      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 7, X_Adjusted_Expenditure_Item_Id);
4729 
4730 -- 11.5 Changes Start
4731      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 8,  X_Adl_Line_Num);
4732      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 9,  X_Parent_Adl_Line_Num);
4733      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 10, X_Adl_Status,1);
4734      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 11, X_Bill_Award_Id);
4735      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 12, X_Actual_Project_Id);
4736      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 13, X_Cdl_Line_Num); --bug 2909746
4737 -- 11.5 Changes End
4738  -- Bug 3630577 : performance fix ..
4739      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 14, X_expenditure_type,30);
4740      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 15, X_expenditure_org_id);
4741      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 16, X_ind_compiled_set_id);
4742      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 17, X_burdenable_raw_cost);
4743      DBMS_SQL.DEFINE_COLUMN(cur_select,X_Cnt_Of_Columns_Selected + 18, X_transaction_source,30);
4744 
4745 ----------------------------------------------------------------
4746 ----------------------------------------------------
4747 -- Executing the Cursor cur_select --
4748    X_Rows_Processed := DBMS_SQL.EXECUTE(cur_select);
4749 ----------------------------------------------------
4750 --------------------------------------------------------------------
4751 -- Beginning Loop to process rows returned from Cursor cur_select for current Installment --
4752 LOOP
4753 
4754  BEGIN
4755 
4756     SAVEPOINT EXPENDITURE_ITEM_PROCESSING;
4757 
4758   --dbms_output.put_line('In Loop');
4759 
4760 /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
4761 
4762    If DBMS_SQL.FETCH_ROWS(cur_select) > 0 then --Start of 'Cursor_Rows_Check_If'
4763 
4764       /* Initializing the X_Burden_Component_Data table */
4765           X_Burden_Component_Data.DELETE;
4766 
4767       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 1, X_Raw_Cost);
4768          --dbms_output.put_line('Raw Cost '||to_char(X_Raw_Cost));
4769       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 2, X_Expenditure_Item_Id);
4770           --dbms_output.put_line('Exp Item Id '||to_char(X_Expenditure_Item_Id));
4771       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 3, X_Expenditure_Item_Date);
4772           --dbms_output.put_line('Exp Item Date '||to_char(X_Expenditure_Item_Date));
4773       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 4, X_Task_Id);
4774           --dbms_output.put_line('Task Id'||to_char(X_Task_Id));
4775       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 5, X_Bill_Hold_Flag);
4776           --dbms_output.put_line('Bill Hold Flag'||X_Bill_Hold_Flag);
4777       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 6, X_Billable_Flag);
4778 
4779           --dbms_output.put_line('Billable Flag '||X_Billable_Flag);
4780       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 7, X_Adjusted_Expenditure_Item_Id);
4781           --dbms_output.put_line('Adjusted Expenditure Item Id '||X_Adjusted_Expenditure_Item_Id);
4782 
4783 --11.5 Changes Start
4784 
4785       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 8, X_Adl_Line_Num);
4786       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 9, X_Parent_Adl_Line_Num);
4787       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 10,X_Adl_Status);
4788       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 11,X_Bill_Award_Id);
4789       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 12,X_Actual_Project_Id);
4790       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 13,X_Cdl_Line_Num); --bug 2909746
4791 
4792 --11.5 Changes End
4793  -- Bug 3630577 : performance fix ..
4794       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 14,X_expenditure_type);
4795       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 15,X_expenditure_org_id);
4796       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 16,X_ind_compiled_set_id);
4797       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 17,X_burdenable_raw_cost);
4798       DBMS_SQL.COLUMN_VALUE(cur_select,X_Cnt_Of_Columns_Selected + 18,X_transaction_source);
4799 
4800 IF L_DEBUG = 'Y' THEN
4801 	gms_error_pkg.gms_debug('Expenditure Item Id :'||X_Expenditure_Item_Id,'C');
4802 	gms_error_pkg.gms_debug('X_Adl_Line_Num:'||X_Adl_Line_Num,'C');
4803 	gms_error_pkg.gms_debug('X_Cdl_Line_Num:'||X_Cdl_Line_Num,'C'); --bug 2909746
4804 	gms_error_pkg.gms_debug('X_Expenditure_Item_Date:'||X_Expenditure_Item_Date,'C');
4805 	gms_error_pkg.gms_debug('X_Raw_Cost:'||X_Raw_Cost,'C');
4806 	gms_error_pkg.gms_debug('X_Bill_Hold_Flag:'||X_Bill_Hold_Flag,'C');
4807 END IF;
4808 
4809     -- Lock the Expenditure Item
4810        select expenditure_item_id
4811        into
4812        X_Lock_Exp_Id
4813        from
4814        pa_expenditure_items_all
4815        where
4816        expenditure_item_id = X_Expenditure_Item_Id
4817        FOR UPDATE NOWAIT;
4818 
4819 -- 11.5 Change, Lock Adl Expenditure Item too
4820 
4821 	select expenditure_item_id
4822         into
4823 	X_Adl_Lock_Exp_Id
4824 	from
4825 	gms_award_distributions
4826 	where expenditure_item_id = X_Expenditure_Item_Id
4827 	and   adl_line_num=X_Adl_Line_Num
4828 	and   document_type='EXP'
4829 	and   adl_status = 'A'
4830 	FOR UPDATE NOWAIT;
4831 
4832 /* This is to see that the Adjusting Expenditure Item is picked up first for Billing */
4833 -- 11.5 change, pick billed_flag from adl table and award_id required in where clause
4834 --Bug 3235390 commented out
4835 /*
4836 If X_Adjusted_Expenditure_Item_Id IS NOT NULL then
4837  Begin
4838   Select
4839     nvl(adl.billed_flag,'N')
4840   into
4841     X_Orig_Item_Billed_Flag
4842   from
4843     gms_award_distributions adl
4844   where
4845     expenditure_item_id = X_Adjusted_Expenditure_Item_Id
4846   and
4847     award_id = X_Bill_award_id
4848   and
4849     adl_status='A'
4850   and
4851     document_type ='EXP'
4852   and
4853     adl_line_num =
4854                    (select max(adl_line_num)
4855 		    from   gms_award_distributions
4856 		    where  expenditure_item_id = X_Adjusted_Expenditure_Item_Id
4857 		    and    award_id = X_Bill_award_id
4858 		    and    adl_status='A'
4859 		    and    document_type ='EXP');
4860  End;
4861 
4862 End If; */ --Bug 3235390
4863 
4864 -----------------------------------------------------------------------------------------------------
4865    /*Resetting Burden Totals from View and Tmp table to zero for every Exp Item being processed */
4866     X_Tot_Burd_Amt_In_Tmp    := 0;
4867     X_Tot_Burden_Amt_In_View := 0;
4868     X_Tot_Burd_Amt_To_Insert := 0;
4869     X_UPD_BILLING_FLAG := FALSE; -- Bug 3254097 : Intializing the flag
4870 
4871 ----------------------------------------------------------------------------------------------------
4872 
4873 
4874    /* If (X_Adjusted_Expenditure_Item_Id IS NOT NULL and X_Orig_Item_Billed_Flag <> 'Y' ) then
4875 
4876        GOTO  DO_NOT_PROCESS;  DO NOT GO ANY FURTHER WITH PROCESSING OF THIS ITEM
4877 
4878     End If; */  --Bug 3235390: Commented out
4879 
4880 --------------------------------------------------------------------
4881        -- Rounding fix : Bug 1417062
4882 
4883         X_Raw_Cost := pa_currency.round_currency_amt(nvl(X_Raw_Cost,0));
4884 
4885          -----------------------------------------------------------------------------
4886          /* For the particular Installment,Task get Total Billed Amount and Total Funding Amount */
4887  	   GET_SUMM_FUNDING(NULL, -- C_Installment_Id, Made Null for 11.5
4888                             X_Expenditure_Item_Date,
4889                             X_Award_Id,
4890                             X_Task_Id,
4891                             X_calling_process,
4892                             X_Total_Funding_Amount,
4893                             X_Total_Rev_Bill_Amount,
4894 			    St_Err_Code,
4895 			    St_Err_Buff);
4896 
4897             	If St_Err_Code <> 0 then
4898 			--ROLLBACK;
4899                  	--RAISE FND_API.G_EXC_ERROR;
4900 			Raise NO_PROCESSING_OF_AWARD ;
4901             	End If;
4902          -----------------------------------------------------------------------------
4903    X_Money_Left_In_Inst := (X_Total_Funding_Amount - X_Total_Rev_Bill_Amount);
4904 ----------------------------------------------------------------------------------------------------------------
4905       --dbms_output.put_line('Money Left in Installment  = '||to_char(X_Money_Left_In_Inst));
4906         ------------------------------------------------------------------------------
4907 
4908 	-- Bug 2441525 : if the raw cost is greater than the funding left then there is no need for deriving burden.
4909 
4910 	--IF NVL(X_Raw_Cost,0) > NVL(X_Money_Left_In_Inst,0) AND X_Revenue_Limit_Flag = 'Y'  THEN   -- hard limit
4911         --   GOTO  DO_NOT_PROCESS;   /* Do not go any further with processing of this item */
4912         --END IF;
4913         -- Above code commented for bug 4289410
4914 
4915 
4916    X_Installment_Status := null; -- Initialize
4917 
4918 	/* Installment Check */
4919 
4920 	INSTALLMENT_CHECK(C_Installment_Id,
4921 			  X_Award_Id,
4922 			  X_Task_Id,
4923 			  X_Calling_Process,
4924 			  X_Expenditure_Item_Date,
4925 			  X_Money_Left_In_Inst,
4926 			  X_Money_On_Curr_Inst,
4927 			  X_Installment_Status,
4928 			  St_Err_Code,
4929 			  St_Err_Buff);
4930 
4931             	If St_Err_Code <> 0 then
4932 			--ROLLBACK;
4933                  	--RAISE FND_API.G_EXC_ERROR;
4934 			Raise NO_PROCESSING_OF_AWARD ;
4935             	End If;
4936 
4937                 IF L_DEBUG = 'Y' THEN
4938 	           gms_error_pkg.gms_debug('After INSTALLMENT_CHECK X_error_code:'||St_Err_Code,'C');
4939                 END IF;
4940 
4941 /* Commented IF for bug 5349106 */
4942 --		If X_Installment_Status ='I' then
4943 --		    GOTO  DO_NOT_PROCESS; /* Do not go any further with processing of this item */
4944 --		End if;
4945 
4946       /* Getting the Burden Components and Burden Amount from View for each Raw Expenditure Item in an array form */
4947 
4948           X_Burden_Components_Count := 0;
4949 
4950 
4951           If (nvl(x_burdenable_raw_cost,0) <> 0 and x_ind_compiled_set_id is not null) then
4952             If allow_burden(x_transaction_source) then
4953              GET_BURDEN_COMPONENT_DATA(X_Actual_Project_Id,
4954                                        X_Task_Id,
4955                                        X_Expenditure_Org_Id,
4956                                        X_ind_compiled_set_id,
4957                                        X_burdenable_raw_cost,
4958                                        X_Expenditure_Type,
4959 				       X_Burden_Components_Count,
4960 				       X_Burden_Component_Data);
4961             End If; --If allow_burden(x_transaction_source) then
4962           End If;
4963          -----------------------------------------------------------------------------
4964           IF L_DEBUG = 'Y' THEN
4965 	     gms_error_pkg.gms_debug('X_Burden_Components_Count:'||X_Burden_Components_Count,'C');
4966           END IF;
4967          -----------------------------------------------------------------------------
4968          /* For each Trx fetched Get total Raw Amount for the Trx already existing in Intersect table */
4969            GET_AMOUNT_IN_INTERSECT(X_Expenditure_Item_Id,
4970 				   X_Adl_Line_Num,
4971                                    X_Calling_Process,
4972                                    X_Amount_In_Intersect
4973                                    );
4974          --dbms_output.put_line('Amount in intersect = '||to_char(X_Amount_In_Intersect));
4975          -----------------------------------------------------------------------------
4976 
4977        --For i in 1..X_Burden_Components_Count LOOP
4978         --dbms_output.put_line('Data '||X_Burden_Component_Data(i).Burden_Cost_Code);
4979 	 -- null;
4980        --End LOOP;
4981 
4982        For i in 1..X_Burden_Components_Count LOOP
4983           GET_BURD_AMT_IN_INTERSECT(X_Expenditure_Item_Id ,
4984 				    X_Adl_Line_Num,
4985                                     X_Calling_Process ,
4986                                     X_Burden_Component_Data(i).Burden_Cost_Code ,
4987                                     X_Amt_In_Tmp_By_Component );
4988                X_Tot_Burd_Amt_In_Tmp := X_Tot_Burd_Amt_In_Tmp + X_Amt_In_Tmp_By_Component;
4989        End LOOP;
4990               --dbms_output.put_line('Burden Amt in Temp table = '||to_char(X_Tot_Burd_Amt_In_Tmp));
4991         ------------------------------------------------------------------------------
4992 
4993             For i in 1..X_Burden_Components_Count LOOP
4994 
4995                X_Tot_Burden_Amt_In_View :=  X_Tot_Burden_Amt_In_View
4996 					     + X_Burden_Component_Data(i).Burden_Cost;
4997             End LOOP;
4998 
4999 /* Check if the current transaction amount takes it over the Money Left In Installment. If it does, donot do any */
5000 /* further processing on it . If not, then do the checking for Invoice Formats */
5001 
5002 /*IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
5003 
5004 /* For bug 5026657 */
5005 /* Commented revenue limit flag and added condition for invoice limit flag for bug 6642901*/
5006 IF ( /*(X_Revenue_Limit_Flag = 'Y')*/ (X_Invoice_Limit_Flag = 'Y') AND
5007      (g_mode = 'LABOR')  AND
5008      ( (X_Raw_Cost + X_Tot_Burden_Amt_In_View) - (X_Amount_In_Intersect + X_Tot_Burd_Amt_In_Tmp)
5009                         > (X_Money_Left_In_Inst - C_Inst_Task_Run_Total) ) ) THEN
5010     g_labor_exp_to_process := 'Y' ;
5011 
5012 END IF;
5013 
5014 IF L_DEBUG = 'Y' THEN
5015 	gms_error_pkg.gms_debug('X_Tot_Burden_Amt_In_View  '||X_Tot_Burden_Amt_In_View,'C');
5016         gms_error_pkg.gms_debug('X_Raw_Cost  '||X_Raw_Cost,'C');
5017 	gms_error_pkg.gms_debug('X_Amount_In_Intersect  '||X_Amount_In_Intersect,'C');
5018 	gms_error_pkg.gms_debug('X_Tot_Burd_Amt_In_Tmp  '||X_Tot_Burd_Amt_In_Tmp,'C');
5019 	gms_error_pkg.gms_debug('X_Money_Left_In_Inst  '||X_Money_Left_In_Inst,'C');
5020 	gms_error_pkg.gms_debug('C_Inst_Task_Run_Total  '||C_Inst_Task_Run_Total,'C');
5021 	gms_error_pkg.gms_debug('g_labor_exp_to_process  '||g_labor_exp_to_process,'C');
5022 	--	gms_error_pkg.gms_debug('X_Revenue_Limit_Flag  '||X_Revenue_Limit_Flag,'C'); commented and added below line for the bug 6642901
5023     gms_error_pkg.gms_debug('X_Invoice_Limit_Flag '||X_Invoice_Limit_Flag,'C');
5024 	gms_error_pkg.gms_debug('g_mode  '||g_mode,'C');
5025 END IF;
5026 
5027  IF ( (
5028        ((X_Raw_Cost + X_Tot_Burden_Amt_In_View) - (X_Amount_In_Intersect + X_Tot_Burd_Amt_In_Tmp)
5029                         <= (X_Money_Left_In_Inst - C_Inst_Task_Run_Total)) AND
5030        (X_Total_Funding_Amount <> -99 and X_Total_Rev_Bill_Amount <> -99) AND
5031 --       (X_Revenue_Limit_Flag = 'Y')
5032          (X_Invoice_Limit_Flag = 'Y')
5033        )
5034       OR
5035      /*(X_Revenue_Limit_Flag = 'N')*/ (X_Invoice_Limit_Flag = 'N')) then --IIIII
5036 
5037 
5038      GET_ACCRUE_BILL_OR_INSERT_AMT(X_Expenditure_Item_Id,
5039 				   X_Adl_Line_Num,
5040                                    X_Calling_Process,
5041                                    X_Raw_Cost,
5042                                    X_Billable_Flag,
5043                                    X_Bill_Hold_Flag,
5044                                    X_Amount_To_Accrue_Bill_Insert,
5045                                    X_Err_Num,
5046                                    X_Err_Stage);
5047 
5048      For i in 1..X_Burden_Components_Count LOOP
5049             GET_BURDEN_AMT_TO_INSERT(X_Expenditure_Item_Id,
5050 				     X_Adl_Line_Num,
5051                                      X_Calling_Process,
5052                                      X_Burden_Component_Data(i).Burden_Cost_Code,
5053 				     X_Billable_Flag,
5054 				     X_Bill_Hold_Flag,
5055                                      X_Burden_Component_Data(i).Burden_Cost,
5056                                      X_Burd_Amt_To_Insert_By_Comp);
5057 
5058 		-- Rounding fix : Bug 1417062
5059 		-- Rounding fix : Bug 10151331 removed the rounding api call
5060                 --X_Burd_Amt_To_Insert_By_Comp := pa_currency.round_currency_amt(nvl(X_Burd_Amt_To_Insert_By_Comp,0));
5061                   X_Burd_Amt_To_Insert_By_Comp := nvl(X_Burd_Amt_To_Insert_By_Comp,0);
5062 
5063                INSERT_GMS_BURDEN_COMPONENTS(X_Project_Id,
5064                                             X_Expenditure_Item_Id,
5065 					    X_Adl_Line_Num,
5066 					    X_Request_Id,
5067 					    X_Calling_Process,
5068                                             X_Burden_Component_Data(i).Actual_Project_Id,
5069 					    X_Burden_Component_Data(i).Actual_Task_Id,
5070 					    X_Burden_Component_Data(i).Burden_Expenditure_Type,
5071 					    X_Burden_Component_Data(i).Burden_Cost_Code,
5072 					    X_Burden_Component_Data(i).Expenditure_Org_Id,
5073 					    X_Burd_Amt_To_Insert_By_Comp,
5074 					    X_Err_Num,
5075 					    X_Err_Stage);
5076 
5077              X_Tot_Burd_Amt_To_Insert := X_Tot_Burd_Amt_To_Insert + X_Burd_Amt_To_Insert_By_Comp;
5078 
5079      End LOOP;
5080 
5081            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));
5082 
5083 /* For bug 5026657 */
5084 
5085 /* Commented revenue limit flag and added condition for invoice limit flag for bug 6642901*/
5086 IF ( /*(X_Revenue_Limit_Flag = 'Y')*/ (X_Invoice_Limit_Flag = 'Y') AND
5087      (g_mode = 'NON LABOR')  AND
5088      (nvl(X_Amount_To_Accrue_Bill_Insert,0) + nvl(X_Tot_Burd_Amt_To_Insert,0)) < 0 )  THEN
5089 
5090     g_non_labor_neg_exp_processed := 'Y' ;
5091 
5092 END IF;
5093 
5094 -- GET_INSTALLMENT_NUM, to get installment numbers in case of amounts across installments
5095 
5096     GET_INSTALLMENT_NUM(C_Installment_id,
5097 			X_Award_Id,
5098 			X_Task_Id,
5099 			X_Expenditure_item_date,
5100 			X_Calling_Process,
5101 			X_Money_On_Curr_Inst,
5102 			C_Inst_Task_Run_Total,
5103 			X_Installment_Status,
5104 			X_Installment_tab,
5105 			X_Count,
5106 			St_Err_Code,
5107 			St_Err_Buff);
5108 
5109 
5110             	If St_Err_Code <> 0 then
5111 			Raise NO_PROCESSING_OF_AWARD ;
5112             	End If;
5113 
5114 IF L_DEBUG = 'Y' THEN
5115 	gms_error_pkg.gms_debug('After GET_INSTALLMENT_NUM X_error_code:'||St_Err_Code,'C');
5116 END IF;
5117 
5118 /* bug 5242484 - start */
5119        IF ( X_old_expenditure_item_id = X_expenditure_item_id )  THEN
5120 	   	IF ( X_Count = 1) THEN
5121                   X_ei_rollback_inst_tab(1).rev_bill_amount := X_ei_rollback_inst_tab(1).rev_bill_amount + C_Inst_Task_Run_Total;
5122                 ELSE
5123 	           FOR k in 1..X_Count LOOP
5124                        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;
5125                    END LOOP;
5126                 END IF;
5127        ELSE
5128 	       IF ( X_Count = 1) THEN
5129                   X_ei_rollback_inst_tab(1).rev_bill_amount := C_Inst_Task_Run_Total;
5130 	          X_ei_rollback_inst_tab(1).installment_id := C_Installment_id;
5131 
5132                ELSE
5133                   FOR k in 1..X_Count LOOP
5134                       X_ei_rollback_inst_tab(k).rev_bill_amount := X_Installment_tab(k).rev_bill_amount ;
5135 	              X_ei_rollback_inst_tab(k).installment_id := X_Installment_tab(k).installment_id;
5136                   END LOOP;
5137                END IF;
5138 
5139        END IF;
5140 /* bug 5242484 - end */
5141 
5142 --Updating GMS_SUMMARY_PROJECT_FUNDINGS Billed Amount with the Amount of the current transaction
5143 
5144 	 UPD_GSPF_WRAPPER(C_Installment_Id,
5145 		          X_Task_Id,
5146 			  X_Actual_Project_Id,
5147 			  X_Calling_Process,
5148 			  C_Inst_Task_Run_Total,
5149 			  X_Count,
5150 			  X_Installment_tab,
5151 			  X_Installment_total,
5152 			  St_Err_Code,
5153 			  St_Err_Buff);
5154 
5155                 If St_Err_Code <> 0 then
5156 			Raise NO_PROCESSING_OF_AWARD ;
5157                 End If;
5158 
5159 IF L_DEBUG = 'Y' THEN
5160 	gms_error_pkg.gms_debug('After UPD_GSPF_WRAPPER X_error_code:'||St_Err_Code,'C');
5161 END IF;
5162 
5163 -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG at the end of the process
5164 
5165     --Resetting the Inst_Task_Bill_Amount Running Total to Zero for Next transaction
5166            C_Inst_Task_Run_Total := 0;
5167 
5168 /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
5169 
5170     If X_First_Indicator then --Begin of 1st If for 'First_Row_Indicator' (First Row values go into Old Table)
5171                               -- for Invoice Format Checking
5172 
5173        -- Copy Values from Cursor into Old_Values Table --
5174         --dbms_output.put_line('In First Indicator True Check');
5175         For i in 1..X_Cnt_Of_Columns_Selected LOOP
5176          DBMS_SQL.COLUMN_VALUE(cur_select,i,X_Old_Values(i));
5177 		 IF L_DEBUG = 'Y' THEN
5178   	       gms_error_pkg.gms_debug('In First Indicator X_old_values('||i||')='||X_Old_Values(i),'C');
5179          END IF;
5180         END LOOP;
5181 	/* Bug 3523930 -Setting the old values for project/task */
5182 	X_old_task_id := X_task_id;
5183 	X_old_actprj_id := X_Actual_Project_Id;
5184 	gms_error_pkg.gms_debug('When First Indicator X_old_task_id ='||X_old_task_id,'C');
5185 	gms_error_pkg.gms_debug('When First Indicator X_old_project_id ='||X_old_actprj_id,'C');
5186 	/* Bug 3523930- Changes end */
5187           ----------------------------------------------
5188                 --Create Running Total For Columns not in Group By--
5189                  For i in 1..X_Cnt_Of_Columns_Selected LOOP
5190                    If X_Sel_Grp_Diff_Array(i) = 'N' then
5191 			null;
5192                      --X_Run_Total(i) := to_number(X_Old_Values(i));
5193                    Else
5194                      X_Run_Total(i) := -1;
5195                    End If;
5196                  End LOOP;
5197 
5198     Else -- Else for 1st If for 'First_Row_Indicator' (2nd Row Values go into New Table)
5199          -- for Invoice Format Checking
5200 
5201       -- Copy Values from Cursor into New_Values Table --
5202         For i in 1..X_Cnt_Of_Columns_Selected LOOP
5203          DBMS_SQL.COLUMN_VALUE(cur_select,i,X_New_Values(i));
5204  		 IF L_DEBUG = 'Y' THEN
5205   	       gms_error_pkg.gms_debug('When !First Indicator X_new_values('||i||')='||X_New_Values(i),'C');
5206          END IF;
5207         END LOOP;
5208 	/* Bug 3523930 -Setting the new values for project/task */
5209 	X_new_task_id := X_task_id;
5210 	X_new_actprj_id := X_Actual_Project_Id;
5211 	gms_error_pkg.gms_debug('When !First Indicator X_new_task_id ='||X_New_task_id,'C');
5212 	gms_error_pkg.gms_debug('When !First Indicator X_new_project_id ='||X_New_actprj_id,'C');
5213 	/* Bug 3523930- Changes end */
5214                      For i in 1..X_Cnt_Of_Columns_Selected LOOP
5215 			null;
5216                        --dbms_output.put_line('NEW VALUES ARRE '||X_New_Values(i) );
5217                      END LOOP;
5218     End If; -- End of 1st If for 'First_Row_Indicator'
5219 
5220 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
5221 
5222 /*************************************************************************************************/
5223 
5224     If X_First_Indicator then --Begin of 2nd If for 'First_Row_Indicator'Check
5225           X_First_Indicator := FALSE;
5226     Else -- Else of 2nd If for 'First_Row_Indicator 'Check
5227                  --Compare  Old and New and accordingly create event
5228        For i in 1..X_Cnt_Of_Columns_Selected LOOP
5229           If X_Sel_Grp_Diff_Array(i) = 'Y' then --Begin of If for 'Check_Ind' 999999999999999
5230 		    IF L_DEBUG = 'Y' THEN
5231      	       gms_error_pkg.gms_debug('Inside X_sel_grp_diff_array(i) = Y','C');
5232              END IF;
5233 	     /* Bug 3523930- Where condition changed */
5234              If ((X_Old_Values(i) <> X_New_Values(i) and X_invfmt_incl_task='N')
5235 		 or (X_invfmt_incl_task='Y'
5236 		     and (X_Old_Values(i) <> X_New_Values(i)
5237 			  or X_old_task_id <> X_new_task_id
5238 			  or X_old_actprj_id <> X_new_actprj_id))) then  -- 888888888
5239 		IF L_DEBUG = 'Y' THEN
5240      	           gms_error_pkg.gms_debug('Old Values are not equal to new values','C');
5241                 END IF;
5242            ------------------------------------------------
5243     -- This procedure builds the Event Description, Creates the Event and Updates the --
5244    --GMS_EVENT_INTERSECT table with the corresponding Event Number --
5245 
5246                -- Following IF .. End if statement commented for NULL Events logic ..
5247                -- zero $ amount logic shifted to DO_EVENT_PROCESSING
5248 
5249                 --If X_Event_Amount <> 0 then
5250                         --dbms_output.put_line('Creating Event');
5251                       DO_EVENT_PROCESSING(X_Cnt_Of_Columns_Selected,
5252                                           X_Sel_Grp_Diff_Array,
5253                                           X_Rt_Jstfy_Flag_Array,
5254                                           X_Old_Values,
5255                                   	  X_Padding_Length_Array,
5256                                   	  X_Run_Total,
5257                                   	  X_Text_Array,
5258                                   	  X_Project_Id,
5259 			                  /*X_Task_Id, Changed for bug 3523930 */
5260 					  X_old_task_id,
5261 					  X_invfmt_incl_task, /* Added for bug 3523930 */
5262                                   	  X_Event_Amount,
5263                                   	  X_Carrying_Out_Org_Id,
5264                                   	  X_rev_or_bill_date,
5265                                   	  X_calling_process,
5266                                   	  X_Request_id,
5267                                           C_Installment_Id,
5268 					  X_Count,
5269 					  X_Installment_total,
5270 					  St_Err_Code,
5271 					  St_Err_Buff) ;
5272 
5273 	            	If St_Err_Code <> 0 then
5274 				Raise NO_PROCESSING_OF_AWARD ;
5275        		     	End If;
5276 
5277 IF L_DEBUG = 'Y' THEN
5278 	gms_error_pkg.gms_debug('After DO_EVENT_PROCESSING X_error_code:'||St_Err_Code,'C');
5279 END IF;
5280 
5281                 --End If;
5282            ----------------------------------------------
5283                 --Copy New_Values to Old_Values--
5284 		 gms_error_pkg.gms_debug('Restting old task/project with new task/projet','C');
5285                  For i in 1..X_Cnt_Of_Columns_Selected LOOP
5286                      X_Old_Values(i) := X_New_Values(i);
5287                  End LOOP;
5288 		 /* Bug 3523930 */
5289 		 X_old_task_id := X_New_task_id;
5290 		 X_old_actprj_id := X_new_actprj_id;
5291            -----------------------------------------------
5292            ---------------------------------------------
5293             --Reset Cumulative Total --
5294                 X_Event_Amount := 0;
5295            ---------------------------------------------
5296            ---------------------------------------------
5297           -- Reset Running Total Array to ZERO --
5298              For i in 1..X_Cnt_Of_Columns_Selected LOOP
5299                          X_Run_Total(i) := 0;
5300              End LOOP;
5301                       EXIT ; --We donot check for any of the other columns
5302                              --if a different one is found
5303              Else --888888888
5304                 NULL;
5305              End If; -- Check for Old_Values <> New_Values -- 888888888
5306           Else -- Else for 'Check_Ind' 999999999999999
5307              --Do not Compare Old and New Value
5308                 NULL;
5309           End If; -- End of If for 'Check_Ind' 999999999999999
5310        END LOOP;
5311     End If;-- End of 2nd If for 'First_Row_Indicator'Check
5312          ----------------------------------------------
5313 
5314 /***********************************************************************************************/
5315 
5316 
5317    -- Inserting a row into GMS_EVENT_INTERSECT for every row Fetched --
5318    -- after checking to see if rows already exist for that Expenditure Item Id --
5319        --dbms_output.put_line('Before GMS_EVENT_INTERSECT');
5320            INSERT_GMS_EVENT_INTERSECT(X_Project_Id,
5321                                       X_Raw_Cost,
5322                                       X_Expenditure_Item_Id,
5323 				      X_Adl_Line_Num,
5324                                       X_Request_id,
5325                                       X_Amount_To_Insert,
5326                                       x_calling_process,
5327                                       X_Billable_Flag,
5328                                       X_Bill_Hold_Flag,
5329                                       X_Err_Nbr,
5330                                       X_Err_Stg); -- Insert into GMS_EVENT_INTERSECT
5331                If X_Err_Nbr <> 0 then
5332                 --dbms_output.put_line('After GMS EVENT INTERSECT '||to_char(X_Err_Nbr)||X_Err_Stg);
5333                    RETURN;
5334                End If;
5335 
5336    /* bug 5242484 - start */
5337        IF ( X_old_expenditure_item_id = X_expenditure_item_id )  THEN
5338 
5339            X_event_rollback_amount := X_event_rollback_amount + X_Amount_To_Insert;
5340 
5341        ELSE
5342 
5343            X_old_expenditure_item_id := X_expenditure_item_id;
5344 
5345 	   X_event_rollback_amount := X_Amount_To_Insert;
5346 
5347        END IF;
5348   /* for bug 5242484 - end */
5349     --------------------------------------------------------
5350     -- Maintaining Cumulative Total for Creating Event --
5351        X_Event_Amount := X_Event_Amount + X_Amount_To_Insert ;
5352     --------------------------------------------------------
5353     -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG so that the flag gets updated only when
5354     --               the expenditure is processed.
5355 
5356        IF X_UPD_BILLING_FLAG   -- Bug 3233706
5357  OR ((X_Amount_To_Insert = 0 ) AND (X_Tot_Burd_Amt_To_Insert = 0 )) THEN -- added for bug 5182669
5358  ---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
5359 
5360 
5361           -- Update GMS_AWARD_DISTRIBUTIONS set Billed_Flag to 'Y' indicating item has been picked for Invoicing
5362 
5363           IF L_DEBUG = 'Y' THEN
5364             gms_error_pkg.gms_debug('Format specific Billing : Calling UPD_ADL_BILLING_FLAG for expenditure '||X_Expenditure_Item_Id,'C');
5365           END IF;
5366 
5367           UPD_ADL_BILLING_FLAG(X_Expenditure_Item_Id,
5368 			  X_Adl_Line_Num,
5369 		          X_Calling_Process,
5370 	                  X_Billable_Flag,
5371                           X_Bill_Hold_Flag,
5372 			  St_Err_Code,
5373 			  St_Err_Buff);
5374 
5375           IF L_DEBUG = 'Y' THEN
5376               gms_error_pkg.gms_debug('After UPD_ADL_BILLING_FLAG X_error_code:'||St_Err_Code,'C');
5377           END IF;
5378 
5379           If St_Err_Code <> 0 then
5380 	      Raise NO_PROCESSING_OF_AWARD ;
5381           End If;
5382 
5383        END IF;  -- Bug 3254097
5384 
5385     -------------------------------------------------------------------------------------
5386     -- Maintaining Cumulative Total for the Columns in Select_Text which donot have Group_By_Text--
5387       For i in 1..X_Cnt_Of_Columns_Selected LOOP
5388        If X_Sel_Grp_Diff_Array(i) = 'N' then
5389        --   X_Run_Total(i) := X_Run_Total(i) + nvl(to_number(X_New_Values(i)),0);
5390 		null;
5391        Else -- (If Ind is 'T' or 'Y')
5392           X_Run_Total(i) := -1;
5393        End If;
5394       End LOOP;
5395     -------------------------------------------------------------------------------------
5396    END IF ;-- End of IF for Installment Check IIIII
5397 
5398 /*IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII*/
5399 
5400   Else  -- Else for 'Cursor_Rows_Check_If'
5401     --dbms_output.put_line('For last Row or If no rows present');
5402    -- This is for the Last Row being processed --
5403    --This procedure builds the Event Description, Creates the Event and Updates the --
5404    -- GMS_EVENT_INTERSECT table with the corresponding Event Number --
5405 
5406    -- Following IF .. End if statement commented for NULL Events logic ..
5407    -- zero $ amount logic shifted to DO_EVENT_PROCESSING
5408 
5409       --If X_Event_Amount <> 0 then
5410 
5411           DO_EVENT_PROCESSING(X_Cnt_Of_Columns_Selected,
5412                                   X_Sel_Grp_Diff_Array,
5413                                   X_Rt_Jstfy_Flag_Array,
5414                                   X_Old_Values,
5415                                   X_Padding_Length_Array,
5416                                   X_Run_Total,
5417                                   X_Text_Array,
5418                                   X_Project_Id,
5419 				  /* X_Task_Id, Changed for bug 3523930*/
5420 				  X_old_task_id,
5421 				  X_invfmt_incl_task, /* Added for bug 3523930 */
5422                                   X_Event_Amount,
5423                                   X_Carrying_Out_Org_Id,
5424                                   X_rev_or_bill_date,
5425                                   X_calling_process,
5426                                   X_Request_id,
5427                                   C_Installment_Id,
5428 			          X_Count,
5429                                   X_Installment_total,
5430                                   St_Err_Code,
5431                                   St_Err_Buff) ;
5432 
5433                         If St_Err_Code <> 0 then
5434 				Raise NO_PROCESSING_OF_AWARD ;
5435                         End If;
5436       --End If;
5437 
5438         EXIT;
5439 
5440 
5441   End If; -- End of 'Cursor_Rows_Check_If'
5442 
5443   /* bug 5242484 - start */
5444   /* Commented revenue limit flag and added condition for invoice limit flag for bug 6642901*/
5445 IF (
5446        ((X_Raw_Cost + X_Tot_Burden_Amt_In_View) - (X_Amount_In_Intersect + X_Tot_Burd_Amt_In_Tmp)
5447                         > (X_Money_Left_In_Inst - C_Inst_Task_Run_Total)) AND
5448        (X_Total_Funding_Amount <> -99 and X_Total_Rev_Bill_Amount <> -99) AND
5449        --(X_Revenue_Limit_Flag = 'Y')
5450        (X_Invoice_Limit_Flag = 'Y')
5451     AND ( X_expenditure_item_id = X_old_expenditure_item_id )
5452    )  THEN
5453 
5454 IF L_DEBUG = 'Y' THEN
5455 	gms_error_pkg.gms_debug('Calling Procedure EI rollback with parameters :- ','C');
5456         gms_error_pkg.gms_debug('EI rollback : Expenditure_item_id is '||x_expenditure_item_id,'C');
5457 	gms_error_pkg.gms_debug('EI rollback : Adl_line_num is '||x_adl_line_num,'C');
5458 	gms_error_pkg.gms_debug('EI rollback : Project id is '||X_old_actprj_id,'C');
5459 	gms_error_pkg.gms_debug('EI rollback : Task id is '||X_old_task_id,'C');
5460 	gms_error_pkg.gms_debug('EI rollback : Rollback amt is '||x_event_rollback_amount,'C');
5461 	gms_error_pkg.gms_debug('EI rollback : Installment Count is '||x_Count,'C');
5462 END IF;
5463 
5464      ei_rollback(x_award_id,
5465             'INVOICE',
5466 	    x_expenditure_item_id,
5467 	    x_adl_line_num,
5468 	    X_old_actprj_id,
5469             X_old_task_id,
5470 	    X_Count);
5471 
5472 X_Event_Amount := X_Event_Amount - X_event_rollback_amount;
5473 
5474 gms_error_pkg.gms_debug('Rolled back EI '||X_expenditure_item_id||' ! ','C');
5475 
5476 END IF;
5477 /* bug 5242484 - end */
5478 
5479 <<DO_NOT_PROCESS>>
5480 
5481  NULL;
5482 
5483 /*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*/
5484 
5485   EXCEPTION
5486     WHEN RESOURCE_BUSY THEN
5487          ROLLBACK TO EXPENDITURE_ITEM_PROCESSING;
5488        ss_text := SQLCODE||' '||SQLERRM;
5489 
5490 END;
5491 
5492  END LOOP;
5493 
5494 
5495      DBMS_SQL.CLOSE_CURSOR(cur_select);
5496 
5497   EXCEPTION
5498     WHEN OTHERS THEN
5499        ss_text := SQLCODE||' '||SQLERRM;
5500         IF L_DEBUG = 'Y' THEN
5501         	gms_error_pkg.gms_debug(ss_text ,'C');
5502         END IF;
5503       RAISE NO_PROCESSING_OF_AWARD;
5504 
5505 End FORMAT_SPECIFIC_BILLING;
5506 
5507 -----------------------------------------------------------------------------------------------------
5508 -- Procedure REVENUE_ACCRUAL: This is a new process to be used in addition to FORMAT_SPECIFIC_BILLING
5509 -- to handle Revenue Accrual process separately because of the requirement to create Revenue Events
5510 -- by Actual project
5511 -----------------------------------------------------------------------------------------------------
5512 Procedure REVENUE_ACCRUAL(X_Project_Id                IN NUMBER,
5513                           X_Award_Id                  IN NUMBER,
5514                           X_Class_Category            IN VARCHAR2,
5515                           X_rev_or_bill_date          IN DATE,
5516                           X_Revenue_Limit_Flag        IN VARCHAR2,
5517                           X_request_id                IN NUMBER,
5518                 	  X_Rev_Carrying_Out_Org_Id   IN NUMBER,
5519                 	  X_calling_process           IN VARCHAR2,
5520 			  X_Trx_Type		      IN VARCHAR2,
5521                		  C_Installment_Id            IN NUMBER,
5522               	          C_Start_Date_Active         IN DATE,
5523               	          C_End_Date_Active           IN DATE,
5524                           X_Err_Num                   OUT NOCOPY NUMBER,
5525                           X_Err_Stage                 OUT NOCOPY VARCHAR2,
5526 			  g_labor_exp_to_process      OUT NOCOPY VARCHAR2,                   /* added for bug 5026657 */
5527 			  g_non_labor_neg_exp_processed OUT NOCOPY VARCHAR2)  IS             /* added for bug 5026657 */
5528  --Bug : 2909746 - change the order by clause from adl.adl_line_num to adl.cdl_line_num
5529 -- 11.5, rev_cur_select cursor changed, so that certain columns are picked up from the adl table
5530  CURSOR rev_cur_select IS
5531  Select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)
5532            INDEX(adl gms_award_distributions_n7) */  /* Added INDEX(adl gms_award_distributions_n7) for 6969435 */
5533    p.project_id
5534  , adl.task_id
5535  , ei.expenditure_type
5536  , nvl(ei.override_to_organization_id,e.incurred_by_organization_id) EXPENDITURE_ORG
5537  , ei.quantity * (adl.distribution_value/100)*DECODE(adl.line_num_reversed,NULL,1,-1) --Added decode to get correct quantity
5538  , unit.meaning
5539  , decode(ei.system_linkage_function,'BTC',adl.raw_cost,adl.raw_cost)
5540  , ei.expenditure_item_id
5541  , ei.expenditure_item_date
5542  , ei.bill_hold_flag
5543  , adl.billable_flag
5544  , ei.adjusted_expenditure_item_id
5545  , adl.adl_line_num
5546  , adl.cdl_line_num --Bug 2909746
5547  , adl.parent_adl_line_num
5548  , adl.adl_status
5549  , adl.award_id
5550  , adl.ind_compiled_set_id
5551  , adl.burdenable_raw_cost
5552  , ei.transaction_source
5553  from
5554   gms_award_distributions adl /* Moved this up in the order for 6969435*/
5555  ,pa_expenditure_items_all ei
5556  ,pa_expenditures e
5557  ,pa_expenditure_types et
5558  ,pa_lookups unit
5559  ,pa_projects_all p
5560  ,pa_project_types pt
5561  ,pa_tasks t3
5562  ,pa_tasks t5
5563  where
5564      adl.award_id = X_Award_Id
5565  and ei.expenditure_item_id = adl.expenditure_item_id
5566  and adl.fc_status = 'A'
5567  and ((adl.line_num_reversed is null and adl.reversed_flag is null and ei.cost_distributed_flag='Y') or
5568        ((adl.line_num_reversed is not null or adl.reversed_flag is not null) and adl.cost_distributed_flag = 'Y')) --Bug 1852802
5569  and nvl(adl.billable_flag,'N')='Y'
5570  and ei.system_linkage_function <> 'BTC'
5571  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 */
5572  and ei.expenditure_item_date <= nvl(trunc(X_rev_or_bill_date),SYSDATE)
5573  and trunc(ei.expenditure_item_date) <=  trunc(C_End_Date_Active)
5574  and adl.document_type = 'EXP'   -- To pick up only actuals and not encumbrances
5575  and adl.adl_status = 'A'
5576  and ei.expenditure_type = et.expenditure_type
5577  and e.expenditure_id = ei.expenditure_id
5578  and et.unit_of_measure = unit.lookup_code
5579  and (  (ei.system_linkage_function in( 'ST', 'OT') and X_Trx_Type = 'LABOR')
5580       OR (ei.system_linkage_function not in( 'ST' , 'OT') and X_Trx_Type = 'NON_LABOR'))
5581  and unit.lookup_type = 'UNIT'
5582  and ei.task_id = t3.task_id
5583  and t3.top_task_id = t5.task_id
5584  and t5.ready_to_distribute_flag = 'Y'
5585  and t3.project_id = p.project_id
5586  and p.project_status_code <> 'CLOSED' -- Bug 3254097 : Modified 'CLOSED ' to 'CLOSED'
5587  and pt.project_type = p.project_type
5588  and pt.direct_flag = 'N'
5589  and exists ( select 1
5590 	      from   gms_summary_project_fundings gspf
5591 	      where  gspf.installment_id = C_installment_id
5592               and    gspf.project_id     = adl.project_id
5593 	      and    (gspf.task_id is NULL             or
5594 		      gspf.task_id       = adl.task_id or
5595 		      gspf.task_id       = (select t.top_task_id
5596 					    from   pa_tasks t
5597 					    where  t.task_id = adl.task_id
5598 				           )
5599 		      )
5600 	     )
5601  order by DECODE( NVL(ei.net_zero_adjustment_flag,'N'),'N', NVL(ei.raw_cost,
5602                gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)),
5603                                               'Y', DECODE(SIGN(NVL(ei.raw_cost,
5604                gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id))),
5605                                                   1,-NVL(ei.raw_Cost,
5606                gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)),
5607                                                    NVL(ei.raw_cost,
5608                gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)))),
5609                NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost(X_calling_process,ei.expenditure_item_id)),
5610               NVL(ei.adjusted_expenditure_item_id,ei.expenditure_item_id),
5611            adl.raw_cost, adl.cdl_line_num , -- Bug 3235390
5612           p.project_id,ei.task_id,ei.expenditure_type,EXPENDITURE_ORG;
5613 
5614  X_Rev_Act_Project_Id               	NUMBER(15);
5615  X_Rev_Task_Id                  	NUMBER(15);
5616  X_Rev_Expenditure_Type         	VARCHAR2(30);
5617  X_Rev_Expenditure_Org_Id		NUMBER(15);
5618  X_Rev_Quantity				NUMBER(15);
5619  X_Rev_Units				VARCHAR2(30);
5620  X_Rev_Expenditure_Cost			NUMBER(22,5);
5621  X_Rev_Expenditure_Item_Id		NUMBER(15);
5622  X_Rev_Expenditure_Item_Date		DATE;
5623  X_Rev_Bill_Hold_Flag			VARCHAR2(1);
5624  X_Rev_Billable_Flag			VARCHAR2(1);
5625  X_Rev_Adjusted_Exp_Item_Id	        NUMBER(15);
5626 
5627 /* -- 11.5 Additions -- */
5628  X_Rev_Adl_Line_Num			NUMBER(15);
5629  X_Rev_Cdl_Line_Num                     NUMBER(15); --bug 2909746
5630  X_Rev_parent_Adl_Line_Num		NUMBER(15);
5631  X_Rev_Adl_Status			VARCHAR2(1);
5632  X_Rev_Award_Id				NUMBER(15);
5633  St_Err_Code  			        VARCHAR2(30);
5634  St_Err_Buff    			VARCHAR2(2000);
5635  X_Rev_Installment_Status 		VARCHAR2(1) :=null;
5636  X_Rev_Count  				NUMBER :=0;
5637  X_Rev_Money_On_Curr_Inst 		NUMBER(22,5);
5638 /* -- 11.5 Additions -- */
5639 
5640  X_Rev_Lock_Exp_Id        NUMBER(15);
5641  X_Rev_Adl_Lock_Exp_Id    NUMBER(15);
5642 
5643  X_Rev_Orig_Item_Distr_Flag    VARCHAR2(1);
5644  X_Rev_Total_Funding_Amount     NUMBER(22,6):= 0;
5645  X_Total_Rev_Amount	        NUMBER(22,6):= 0;
5646  X_Rev_Amount_In_Intersect      NUMBER(22,6):= 0;
5647  X_Rev_Money_Left_In_Inst       NUMBER(22,6):= 0;
5648  C_Rev_Inst_Task_Run_Total 	NUMBER(22,5):= 0;
5649  X_Rev_Amount_To_Insert         NUMBER(22,5):= 0;
5650  X_Rev_Event_Amount 		NUMBER(22,5):= 0;
5651  X_Rev_Run_Total                NUMBER(15)  := 0;
5652 
5653  X_Rev_First_Row_Ind            BOOLEAN := TRUE;
5654 
5655  X_Act_Project_Id_Old         	NUMBER(15);
5656  X_Task_Id_Old		  	NUMBER(15);
5657  X_Expenditure_Type_Old	  	VARCHAR2(30);
5658  X_Expenditure_Org_Id_Old 	NUMBER(15);
5659  X_Quantity_Old			NUMBER(15) := 0;
5660  X_Units_Old			VARCHAR2(30);
5661 
5662  /* bug 5242484 - start */
5663  X_old_expenditure_item_id NUMBER(15) := -9999 ;
5664  X_event_rollback_amount NUMBER(22,5) := 0;
5665  X_event_rollback_qty NUMBER(15) := 0;
5666  k NUMBER := 0;
5667 /* bug 5242484 - end */
5668 
5669  X_Act_Project_Id_New		NUMBER(15);
5670  X_Task_Id_New			NUMBER(15);
5671  X_Expenditure_Type_New		VARCHAR2(30);
5672  X_Expenditure_Org_Id_New       NUMBER(15);
5673  X_Quantity_New			NUMBER(15) := 0;
5674  X_Units_New			VARCHAR2(30);
5675 
5676  X_Rev_Burden_Component_Data     Burden_Component_Tab_Type;
5677  X_Rev_Burden_Components_Count   NUMBER := 0;
5678  X_Rev_Amt_In_Tmp_By_Component       NUMBER := 0;
5679  X_Rev_Tot_Burd_Amt_In_Tmp      NUMBER := 0;
5680  X_Rev_Tot_Burden_Amt_In_View          NUMBER := 0;
5681  X_Rev_Burd_Amt_To_Ins_By_Comp    NUMBER := 0;
5682  X_Rev_Tot_Burd_Amt_To_Insert     NUMBER := 0;
5683 
5684  X_Err_Nbr NUMBER(15) := NULL;
5685  X_Err_Stg VARCHAR2(200) := NULL;
5686  ss_text VARCHAR2(300);
5687  RESOURCE_BUSY EXCEPTION;
5688  PRAGMA EXCEPTION_INIT(RESOURCE_BUSY, -00054);
5689 
5690  X_ind_compiled_Set_id gms_award_distributions.ind_compiled_set_id%type;
5691  X_burdenable_raw_cost gms_award_distributions.burdenable_raw_cost%type;
5692  X_transaction_source  pa_expenditure_items_all.transaction_source%type;
5693 
5694 Begin
5695 
5696 
5697    /* To set project_id NULL to be able to use Suresh's view to derive Burden Components and Burden Cost */
5698      --GMS_BURDEN_COSTING.SET_CURRENT_PROJECT_ID(NULL);
5699      --The above line has been commented out NOCOPY for bug 2442827
5700 
5701 /* bug 5026657  */
5702 g_labor_exp_to_process := 'N';
5703 g_non_labor_neg_exp_processed := 'N';
5704 
5705 
5706    OPEN rev_cur_select;
5707  Begin
5708  LOOP
5709   Begin
5710      SAVEPOINT REV_EXP_ITEM_PROCESSING;
5711 
5712      FETCH rev_cur_select into
5713       X_Rev_Act_Project_Id
5714      ,X_Rev_Task_Id
5715      ,X_Rev_Expenditure_Type
5716      ,X_Rev_Expenditure_Org_Id
5717      ,X_Rev_Quantity
5718      ,X_Rev_Units
5719      ,X_Rev_Expenditure_Cost
5720      ,X_Rev_Expenditure_Item_Id
5721      ,X_Rev_Expenditure_Item_Date
5722      ,X_Rev_Bill_Hold_Flag
5723      ,X_Rev_Billable_Flag
5724      ,X_Rev_Adjusted_Exp_Item_Id
5725      ,X_Rev_Adl_Line_Num
5726      ,X_Rev_Cdl_Line_Num --Bug 2909746
5727      ,X_Rev_Parent_Adl_Line_Num
5728      ,X_Rev_Adl_Status
5729      ,X_Rev_Award_Id
5730      ,X_ind_compiled_Set_id
5731      ,X_burdenable_raw_cost
5732      ,X_transaction_source;
5733 
5734            EXIT WHEN rev_cur_select%NOTFOUND;
5735 
5736       X_Rev_Burden_Component_Data.DELETE;
5737 
5738 IF L_DEBUG = 'Y' THEN
5739 	gms_error_pkg.gms_debug('Expenditure Item Id :'||X_Rev_Expenditure_Item_Id,'C');
5740 	gms_error_pkg.gms_debug('X_Adl_Line_Num:'||X_Rev_Adl_Line_Num,'C');
5741 	gms_error_pkg.gms_debug('X_Cdl_Line_Num:'||X_Rev_Cdl_Line_Num,'C'); -- Bug 2909746
5742 	gms_error_pkg.gms_debug('X_Expenditure_Item_Date:'||X_Rev_Expenditure_Item_Date,'C');
5743 	gms_error_pkg.gms_debug('X_Raw_Cost:'||X_Rev_Expenditure_Cost,'C');
5744 	gms_error_pkg.gms_debug('X_Bill_Hold_Flag:'||X_Rev_Bill_Hold_Flag,'C');
5745 END IF;
5746 
5747         -- Lock the Expenditure Item
5748        select expenditure_item_id
5749        into
5750        X_Rev_Lock_Exp_Id
5751        from
5752        pa_expenditure_items_all
5753        where
5754        expenditure_item_id = X_Rev_Expenditure_Item_Id
5755        FOR UPDATE NOWAIT;
5756 
5757 -- 11.5 Change, Lock Adl Expenditure Item too
5758 
5759 	select expenditure_item_id
5760         into
5761 	X_Rev_Adl_Lock_Exp_Id
5762 	from
5763 	gms_award_distributions
5764 	where expenditure_item_id = X_Rev_Expenditure_Item_Id
5765 	and   adl_line_num=X_Rev_Adl_Line_Num
5766 	and    document_type='EXP'
5767 	and    adl_status = 'A'
5768 	FOR UPDATE NOWAIT;
5769 
5770        /* This is to see that the Adjusting Expenditure Item is picked up first for Billing */
5771             -- Bug 3235390 : commented out
5772 /*	If X_Rev_Adjusted_Exp_Item_Id IS NOT NULL then
5773  	  Begin
5774          	Select
5775     	 	nvl(revenue_distributed_flag,'N')
5776   	 	into
5777     	 	X_Rev_Orig_Item_Distr_Flag
5778   	 	from
5779     	 	gms_award_distributions
5780   	 	where expenditure_item_id = X_Rev_Adjusted_Exp_Item_Id
5781          	and   award_id = X_Rev_award_id
5782   		and   adl_status='A'
5783   		and   document_type ='EXP'
5784   		and   adl_line_num =
5785                    	(select max(adl_line_num)
5786 		    	 from   gms_award_distributions
5787 		    	 where  expenditure_item_id = X_Rev_Adjusted_Exp_Item_Id
5788 			 and   award_id = X_Rev_award_id
5789 			 and   adl_status='A'
5790 			 and   document_type ='EXP');
5791 
5792         End;
5793         End If; */ --bug 3235390
5794 
5795  -----------------------------------------------------------------------------------------------------
5796    /*Resetting Burden Totals from View and Tmp table to zero for every Exp Item being processed */
5797     X_Rev_Tot_Burd_Amt_In_Tmp    := 0;
5798     X_Rev_Tot_Burden_Amt_In_View := 0;
5799     X_Rev_Tot_Burd_Amt_To_Insert := 0;
5800     X_UPD_BILLING_FLAG := FALSE; -- Bug 3254097 : Intializing the flag
5801 
5802 ----------------------------------------------------------------------------------------------------
5803      /*   If (X_Rev_Adjusted_Exp_Item_Id IS NOT NULL and X_Rev_Orig_Item_Distr_Flag <> 'Y' ) then
5804 
5805             GOTO  DO_NOT_PROCESS_REV;  Do not go any further with processing of this item
5806 
5807         End If; */ --Bug 3235390
5808 
5809   ------------------------------------------------------------------------------------
5810    -- Rounding fix : Bug 1417062
5811 
5812    X_Rev_Expenditure_Cost := pa_currency.round_currency_amt(nvl(X_Rev_Expenditure_Cost,0));
5813 
5814          -----------------------------------------------------------------------------
5815          /* For the particular Installment,Task get Total Billed Amount and Total Funding Amount */
5816            GET_SUMM_FUNDING(NULL,-- C_Installment_Id, Made Null for 11.5
5817 			    X_Rev_Expenditure_Item_Date,
5818 			    X_Rev_Award_Id,
5819                             X_Rev_Task_Id,
5820                             X_calling_process,
5821                             X_Rev_Total_Funding_Amount,
5822                             X_Total_Rev_Amount,
5823 			    St_Err_Code,
5824 			    St_Err_Buff);
5825 
5826             	If St_Err_Code <> 0 then
5827 			Raise NO_PROCESSING_OF_AWARD ;
5828             	End If;
5829          -----------------------------------------------------------------------------
5830           X_Rev_Money_Left_In_Inst := (X_Rev_Total_Funding_Amount - X_Total_Rev_Amount);
5831          -----------------------------------------------------------------------------
5832 
5833      -- Bug 2441525 : If the raw cost is greater than the funding left then there is  no need for deriving burden.
5834 
5835        --  IF NVL(X_Rev_Expenditure_Cost,0) > NVL(X_Rev_Money_Left_In_Inst,0) AND X_Revenue_Limit_Flag = 'Y'  THEN   -- hard limit
5836        --    GOTO  DO_NOT_PROCESS_REV;   /* Do not go any further with processing of this item */
5837        --  END IF;
5838        -- Above code commented out .. Bug 4289410
5839 
5840 -- 11.5 changes start
5841 
5842    X_Rev_Installment_Status := null; -- Initialize
5843 
5844 	/* Installment Check */
5845 
5846 	INSTALLMENT_CHECK(C_Installment_Id,
5847 			  X_Rev_Award_Id,
5848 			  X_Rev_Task_Id,
5849 			  X_Calling_Process,
5850 			  X_Rev_Expenditure_Item_Date,
5851 			  X_Rev_Money_Left_In_Inst,
5852 			  X_Rev_Money_On_Curr_Inst,
5853 			  X_Rev_Installment_Status,
5854 			  St_Err_Code,
5855 			  St_Err_Buff);
5856 
5857             	If St_Err_Code <> 0 then
5858 			Raise NO_PROCESSING_OF_AWARD ;
5859             	End If;
5860 
5861 /* Commented for bug 5349106 */
5862 --		If X_Rev_Installment_Status ='I' then
5863 --		    GOTO  DO_NOT_PROCESS_REV; /* Do not go any further with processing of this item */
5864 --		End if;
5865 -- 11.5 changes end
5866          ----------------------------------------------------------------------------
5867          /* Getting the Burden Components and Burden Amount from View for each Raw Expenditure Item in an array form */
5868 
5869           X_Rev_Burden_Components_Count := 0;
5870 
5871           If (nvl(x_burdenable_raw_cost,0) <> 0 and x_ind_compiled_set_id is not null) then
5872 
5873             If allow_burden(x_transaction_source) then
5874 
5875              GET_BURDEN_COMPONENT_DATA(X_Rev_Act_Project_Id,
5876 				       X_Rev_Task_Id,
5877 				       X_Rev_Expenditure_Org_Id,
5878 				       X_ind_compiled_set_id,
5879 				       X_burdenable_raw_cost,
5880 				       X_Rev_Expenditure_Type,
5881 				       X_Rev_Burden_Components_Count,
5882 				       X_Rev_Burden_Component_Data);
5883             End If; --If allow_burden(x_transaction_source) then
5884 
5885           End If;
5886          ----------------------------------------------------------------------------
5887           IF L_DEBUG = 'Y' THEN
5888 	     gms_error_pkg.gms_debug('X_Rev_Burden_Components_Count:'||X_Rev_Burden_Components_Count,'C');
5889           END IF;
5890          -----------------------------------------------------------------------------
5891          /* For each Trx fetched Get total amount for the Trx already existing in Intersect table */
5892            GET_AMOUNT_IN_INTERSECT(X_Rev_Expenditure_Item_Id,
5893                                    X_Rev_Adl_Line_Num,
5894                                    X_Calling_Process,
5895                                    X_Rev_Amount_In_Intersect
5896                                    );
5897          -----------------------------------------------------------------------------
5898 
5899          -----------------------------------------------------------------------------
5900          For i in 1..X_Rev_Burden_Components_Count LOOP
5901            GET_BURD_AMT_IN_INTERSECT(X_Rev_Expenditure_Item_Id,
5902                                      X_Rev_Adl_Line_Num,
5903 				     X_Calling_Process,
5904 				     X_Rev_Burden_Component_Data(i).Burden_Cost_Code,
5905 				     X_Rev_Amt_In_Tmp_By_Component);
5906 
5907            X_Rev_Tot_Burd_Amt_In_Tmp := X_Rev_Tot_Burd_Amt_In_Tmp + X_Rev_Amt_In_Tmp_By_Component;
5908 
5909          End LOOP;
5910         ------------------------------------------------------------------------------
5911         -----------------------------------------------------------------------------
5912          For i in 1..X_Rev_Burden_Components_Count LOOP
5913            X_Rev_Tot_Burden_Amt_In_View := X_Rev_Tot_Burden_Amt_In_View + X_Rev_Burden_Component_Data(i).Burden_Cost;
5914          End LOOP;
5915         ------------------------------------------------------------------------------
5916  /* For bug 5026657 */
5917 IF ( (X_Revenue_Limit_Flag = 'Y') AND
5918      (X_Trx_Type = 'LABOR')  AND
5919      ( (X_Rev_Expenditure_Cost + X_Rev_Tot_Burden_Amt_In_View) - (X_Rev_Amount_In_Intersect + X_Rev_Tot_Burd_Amt_In_Tmp)
5920                         > (X_Rev_Money_Left_In_Inst - C_Rev_Inst_Task_Run_Total) ) ) THEN
5921     g_labor_exp_to_process := 'Y' ;
5922 
5923 END IF;
5924 
5925  IF ( (
5926         (   (X_Rev_Expenditure_Cost + X_Rev_Tot_Burden_Amt_In_View)  - (X_Rev_Amount_In_Intersect + X_Rev_Tot_Burd_Amt_In_Tmp)
5927            <= ( X_Rev_Money_Left_In_Inst - C_Rev_Inst_Task_Run_Total) )
5928     AND (X_Rev_Total_Funding_Amount <> -99 and X_Total_Rev_Amount <> -99)
5929     AND (X_Revenue_Limit_Flag = 'Y')
5930        )
5931       OR
5932        (X_Revenue_Limit_Flag = 'N')
5933     ) then --??????????????
5934 
5935               GET_ACCRUE_BILL_OR_INSERT_AMT(X_Rev_Expenditure_Item_Id,
5936 					    X_Rev_Adl_line_Num,
5937                                   	    X_Calling_Process,
5938                                             X_Rev_Expenditure_Cost,
5939                                             X_Rev_Billable_Flag,
5940                                             X_Rev_Bill_Hold_Flag,
5941                                             X_Rev_Amount_To_Insert,
5942                                             X_Err_Num,
5943                                             X_Err_Stage);
5944 
5945            FOR i in 1..X_Rev_Burden_Components_Count LOOP
5946                   GET_BURDEN_AMT_TO_INSERT(X_Rev_Expenditure_Item_Id,
5947 					   X_Rev_Adl_Line_Num,
5948 					   X_Calling_Process,
5949 					   X_Rev_Burden_Component_Data(i).Burden_Cost_Code,
5950 					   X_Rev_Billable_Flag,
5951 					   X_Rev_Bill_Hold_Flag,
5952 					   X_Rev_Burden_Component_Data(i).Burden_Cost,
5953 					   X_Rev_Burd_Amt_To_Ins_By_Comp);
5954 
5955                -- Rounding fix : Bug 1417062
5956 	       -- Rounding fix : Bug 10151331 removed the rounding api call
5957 	       --X_Rev_Burd_Amt_To_Ins_By_Comp := pa_currency.round_currency_amt(nvl(X_Rev_Burd_Amt_To_Ins_By_Comp,0));
5958 	       X_Rev_Burd_Amt_To_Ins_By_Comp := nvl(X_Rev_Burd_Amt_To_Ins_By_Comp,0);
5959 
5960                INSERT_GMS_BURDEN_COMPONENTS(X_Project_Id,
5961                                             X_Rev_Expenditure_Item_Id,
5962 					    X_Rev_Adl_Line_Num,
5963                                             X_Request_Id,
5964                                             X_Calling_Process,
5965                                             X_Rev_Burden_Component_Data(i).Actual_Project_Id,
5966                                             X_Rev_Burden_Component_Data(i).Actual_Task_Id,
5967                                             X_Rev_Burden_Component_Data(i).Burden_Expenditure_Type,
5968                                             X_Rev_Burden_Component_Data(i).Burden_Cost_Code,
5969                                             X_Rev_Burden_Component_Data(i).Expenditure_Org_Id,
5970                                             X_Rev_Burd_Amt_To_Ins_By_Comp,
5971                                             X_Err_Num,
5972                                             X_Err_Stage);
5973 
5974                    X_Rev_Tot_Burd_Amt_To_Insert := X_Rev_Tot_Burd_Amt_To_Insert + X_Rev_Burd_Amt_To_Ins_By_Comp;
5975 
5976            END LOOP;
5977 
5978            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));
5979 
5980 /* For bug 5026657 */
5981 
5982 IF ( (X_Revenue_Limit_Flag = 'Y') AND
5983      (X_Trx_Type = 'NON_LABOR')  AND
5984      (nvl(X_Rev_Amount_To_Insert,0) + nvl(X_Rev_Tot_Burd_Amt_To_Insert,0)) < 0 )  THEN
5985 
5986     g_non_labor_neg_exp_processed := 'Y' ;
5987 
5988 END IF;
5989 
5990 ------------------------------------------------------------------------------
5991 -- 11.5 changes start
5992 
5993 -- GET_INSTALLMENT_NUM, to get installment numbers in case of amounts across installments
5994 
5995     GET_INSTALLMENT_NUM(C_Installment_id,
5996 			X_Rev_Award_Id,
5997 			X_Rev_Task_Id,
5998 			X_Rev_Expenditure_item_date,
5999 			X_Calling_Process,
6000 			X_Rev_Money_On_Curr_Inst,
6001 			C_Rev_Inst_Task_Run_Total,
6002 			X_Rev_Installment_Status,
6003 			X_Rev_Installment_tab,
6004 			X_Rev_Count,
6005 			St_Err_Code,
6006 			St_Err_Buff);
6007 
6008             	If St_Err_Code <> 0 then
6009 			Raise NO_PROCESSING_OF_AWARD ;
6010             	End If;
6011 
6012 -- 11.5 changes end
6013 
6014 /* bug 5242484 - end */
6015        IF ( X_old_expenditure_item_id = X_Rev_expenditure_item_id )  THEN
6016 	   	IF ( X_Rev_Count = 1) THEN
6017                   X_ei_rollback_inst_tab(1).rev_bill_amount := X_ei_rollback_inst_tab(1).rev_bill_amount + C_Rev_Inst_Task_Run_Total;
6018                 ELSE
6019 	           FOR k in 1..X_Rev_Count LOOP
6020                        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;
6021                    END LOOP;
6022                 END IF;
6023        ELSE
6024 	       IF ( X_Rev_Count = 1) THEN
6025                   X_ei_rollback_inst_tab(1).rev_bill_amount := C_Rev_Inst_Task_Run_Total;
6026 	          X_ei_rollback_inst_tab(1).installment_id := C_Installment_id;
6027 
6028                ELSE
6029                   FOR k in 1..X_Rev_Count LOOP
6030                       X_ei_rollback_inst_tab(k).rev_bill_amount := X_Rev_Installment_tab(k).rev_bill_amount ;
6031 	              X_ei_rollback_inst_tab(k).installment_id := X_Rev_Installment_tab(k).installment_id;
6032                   END LOOP;
6033                END IF;
6034 
6035        END IF;
6036  /* bug 5242484 - end */
6037 
6038 ------------------------------------------------------------------------------
6039 --Updating GMS_SUMMARY_PROJECT_FUNDINGS Billed Amount with the Amount of the current transaction
6040 
6041           	     UPD_GSPF_WRAPPER(C_Installment_Id,
6042                                       X_Rev_Task_Id,
6043                                       X_Rev_Act_Project_Id,
6044                                       X_Calling_Process,
6045                                       C_Rev_Inst_Task_Run_Total,
6046 			       	      X_Rev_Count,
6047 				      X_Rev_Installment_tab,
6048 				      X_Rev_Installment_total,
6049 			  	      St_Err_Code,
6050 			  	      St_Err_Buff);
6051 
6052 		If St_Err_Code <> 0 then
6053 			Raise NO_PROCESSING_OF_AWARD ;
6054                 End If;
6055 
6056 -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG at the end of the process.
6057 
6058     --Resetting the Inst_Task_Bill_Amount Running Total to Zero for Next transaction
6059            C_Rev_Inst_Task_Run_Total := 0;
6060 
6061 ----------------------------------------------------------------------------------
6062          If X_Rev_First_Row_Ind  then
6063            X_Act_Project_Id_Old 	:= X_Rev_Act_Project_Id;
6064            X_Task_Id_Old    		:= X_Rev_Task_Id;
6065            X_Expenditure_Type_Old       := X_Rev_Expenditure_Type;
6066            X_Expenditure_Org_Id_Old     := X_Rev_Expenditure_Org_Id;
6067            X_Units_Old			:= X_Rev_Units;
6068            X_Quantity_Old               := X_Rev_Quantity;
6069            X_Rev_Run_Total 		:= X_Quantity_Old;
6070 
6071          Else
6072            X_Act_Project_Id_New         := X_Rev_Act_Project_Id;
6073            X_Task_Id_New                := X_Rev_Task_Id;
6074            X_Expenditure_Type_New       := X_Rev_Expenditure_Type;
6075            X_Expenditure_Org_Id_New     := X_Rev_Expenditure_Org_Id;
6076            X_Units_New                  := X_Rev_Units;
6077            X_Quantity_New               := X_Rev_Quantity;
6078 
6079          End If;
6080 
6081 ----------------------------------------------------------------------------
6082 
6083          If X_Rev_First_Row_Ind then
6084               X_Rev_First_Row_Ind := FALSE;
6085          Else
6086 
6087              If ( (X_Act_Project_Id_Old       <> X_Act_Project_Id_New) OR
6088                   (X_Task_Id_Old              <> X_Task_Id_New)    OR
6089                   (X_Expenditure_Type_Old     <> X_Expenditure_Type_New) OR
6090                   (X_Expenditure_Org_Id_Old   <> X_Expenditure_Org_Id_New) ) then
6091 
6092 	         -- Following IF .. End if statement commented for NULL Events logic ..
6093                  -- zero $ amount logic shifted to DO_REV_EVENT_PROCESSING
6094 
6095                  --If (X_Rev_Event_Amount <> 0) then
6096                   DO_REV_EVENT_PROCESSING(X_Act_Project_Id_Old,
6097 					  X_Task_Id_Old,
6098 					  X_Expenditure_Type_Old,
6099 					  X_Expenditure_Org_Id_Old,
6100                                           X_Units_Old,
6101                                           X_Rev_Run_Total,
6102                                           X_Project_Id,
6103                                           X_Rev_Event_Amount,
6104                                           X_Rev_Carrying_Out_Org_Id,
6105                                           X_rev_or_bill_date,
6106                                           X_calling_process,
6107                                           X_Request_id,
6108                                           C_Installment_Id,
6109 					  X_Rev_Count,
6110 					  X_Rev_Installment_total,
6111 					  St_Err_Code,
6112 					  St_Err_Buff);
6113                  --End If;
6114 
6115                 /* Copying New values to Old values */
6116                    X_Act_Project_Id_Old     := X_Act_Project_Id_New;
6117                    X_Task_Id_Old            := X_Task_Id_New;
6118                    X_Expenditure_Type_Old   := X_Expenditure_Type_New;
6119                    X_Expenditure_Org_Id_Old := X_Expenditure_Org_Id_New;
6120 
6121                    X_Units_Old              := X_Units_New;
6122 
6123                /* Resetting X_Rev_Event_Amount */
6124                     X_Rev_Event_Amount := 0;
6125 
6126 		/* Resetting Running Total for Hours etc for Event Description */
6127                     X_Rev_Run_Total := 0;
6128 
6129              End If;
6130 
6131            End If;
6132 ---------------------------------------------------
6133      INSERT_GMS_EVENT_INTERSECT(X_Project_Id,
6134                                 X_Rev_Expenditure_Cost,
6135                                 X_Rev_Expenditure_Item_Id,
6136 				X_Rev_Adl_Line_Num,
6137                                 X_Request_id,
6138                                 X_Rev_Amount_To_Insert,
6139                                 X_Calling_process,
6140                                 X_Rev_Billable_Flag,
6141                                 X_Rev_Bill_Hold_Flag,
6142                                 X_Err_Nbr,
6143                                 X_Err_Stg); -- Insert into GMS_EVENT_INTERSECT
6144                If X_Err_Nbr <> 0 then
6145                    RETURN;
6146                End If;
6147 
6148     /* for bug 5242484 - start  */
6149        IF ( X_old_expenditure_item_id = X_Rev_expenditure_item_id )  THEN
6150 
6151            X_event_rollback_amount := X_event_rollback_amount + X_Rev_Amount_To_Insert;
6152            X_event_rollback_qty :=    X_event_rollback_qty + X_Quantity_New;
6153 
6154        ELSE
6155 
6156            X_old_expenditure_item_id := X_Rev_expenditure_item_id;
6157 
6158 	   X_event_rollback_amount := X_Rev_Amount_To_Insert;
6159 	   X_event_rollback_qty := X_Quantity_New ;
6160 
6161        END IF;
6162   /* for bug 5242484 - end */
6163 
6164 
6165     -- Maintaining Cumulative Total for Creating Event --
6166        X_Rev_Event_Amount := X_Rev_Event_Amount + X_Rev_Amount_To_Insert;
6167 
6168     -- Maintaining total for Quantity etc for Description
6169        X_Rev_Run_Total := X_Rev_Run_Total + X_Quantity_New;
6170 
6171     -- Bug 3254097 : Shifted the call to UPD_ADL_BILLING_FLAG so that the flag gets updated only when
6172     --               the expenditure is processed.
6173 
6174        IF X_UPD_BILLING_FLAG  -- Bug 3233706
6175  OR ((X_Rev_Amount_To_Insert = 0) AND (  X_Rev_Tot_Burd_Amt_To_Insert = 0 ) ) THEN -- added for bug 5182669
6176  --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
6177 
6178           IF L_DEBUG = 'Y' THEN
6179              gms_error_pkg.gms_debug('Revenue accrual : Calling UPD_ADL_BILLING_FLAG For expenditure_item_id '||X_Rev_Expenditure_Item_Id,'C');
6180           END IF;
6181 
6182           UPD_ADL_BILLING_FLAG(X_Rev_Expenditure_Item_Id,
6183 			  X_Rev_Adl_Line_Num,
6184                           X_Calling_Process,
6185                           X_Rev_Billable_Flag,
6186                           X_Rev_Bill_Hold_Flag,
6187 			  St_Err_Code,
6188 			  St_Err_Buff);
6189 
6190             	If St_Err_Code <> 0 then
6191 			Raise NO_PROCESSING_OF_AWARD ;
6192             	End If;
6193        END IF;
6194 --------------------------------------------------
6195 
6196 
6197  End If; --????????????
6198 
6199  /* for bug 5242484 - start  */
6200 IF (
6201         (   (X_Rev_Expenditure_Cost + X_Rev_Tot_Burden_Amt_In_View)  - (X_Rev_Amount_In_Intersect + X_Rev_Tot_Burd_Amt_In_Tmp)
6202            > ( X_Rev_Money_Left_In_Inst - C_Rev_Inst_Task_Run_Total) )
6203     AND (X_Rev_Total_Funding_Amount <> -99 and X_Total_Rev_Amount <> -99)
6204     AND (X_Revenue_Limit_Flag = 'Y')
6205     AND ( X_Rev_expenditure_item_id = X_old_expenditure_item_id )
6206    )  THEN
6207 
6208 IF L_DEBUG = 'Y' THEN
6209 	gms_error_pkg.gms_debug('Calling Procedure EI rollback with parameters :- ','C');
6210         gms_error_pkg.gms_debug('EI rollback : Expenditure_item_id is '||x_Rev_expenditure_item_id,'C');
6211 	gms_error_pkg.gms_debug('EI rollback : Adl_line_num is '||x_Rev_adl_line_num,'C');
6212 	gms_error_pkg.gms_debug('EI rollback : Project id is '||x_act_project_id_old,'C');
6213 	gms_error_pkg.gms_debug('EI rollback : Task id is '||x_task_id_old,'C');
6214 	gms_error_pkg.gms_debug('EI rollback : Rollback amt is '||x_event_rollback_amount,'C');
6215 	gms_error_pkg.gms_debug('EI rollback : Rollback qty is '||x_event_rollback_qty,'C');
6216 	gms_error_pkg.gms_debug('EI rollback : Installment Count is '||x_Rev_Count,'C');
6217 END IF;
6218 
6219      ei_rollback(x_Rev_award_id,
6220             'REVENUE',
6221 	    x_Rev_expenditure_item_id,
6222 	    x_rev_adl_line_num,
6223 	    x_act_project_id_old,
6224             x_task_id_old,
6225 	    X_Rev_Count);
6226 
6227 X_Rev_Run_Total := X_Rev_Run_Total - x_event_rollback_qty ;
6228 X_Rev_Event_Amount := X_Rev_Event_Amount - X_event_rollback_amount;
6229 
6230 gms_error_pkg.gms_debug('Rolled back EI '||X_Rev_expenditure_item_id||' ! ','C');
6231 /* for bug 5242484 - end  */
6232 
6233 END IF;
6234 
6235           <<DO_NOT_PROCESS_REV>>
6236 
6237             NULL;
6238 
6239           EXCEPTION
6240   	    WHEN RESOURCE_BUSY THEN
6241             ROLLBACK TO REV_EXP_ITEM_PROCESSING;
6242      		  ss_text := SQLCODE||' '||SQLERRM;
6243 
6244 	    WHEN OTHERS THEN
6245                   ss_text := SQLCODE||' '||SQLERRM;
6246                   -- insert into ss_log(id,err_text) values (2,ss_text);
6247             ROLLBACK TO REV_EXP_ITEM_PROCESSING;
6248   End;
6249  End LOOP;
6250 
6251      /* For last row Processing */
6252    -- Following IF .. End if statement commented for NULL Events logic ..
6253    -- zero $ amount logic shifted to DO_REV_EVENT_PROCESSING
6254 
6255    --If X_Rev_Event_Amount <> 0 then
6256        -- X_LAST_CALL_FOR_REVENUE := TRUE; -- Bug 3254097
6257        IF L_DEBUG = 'Y' THEN
6258        	gms_error_pkg.gms_debug('IN REVENUE_ACCRUAL, last call ...','C');
6259        END IF;
6260        DO_REV_EVENT_PROCESSING(X_Act_Project_Id_Old,
6261                                X_Task_Id_Old,
6262                                X_Expenditure_Type_Old,
6263                                X_Expenditure_Org_Id_Old,
6264  			       X_Units_Old,
6265                                X_Rev_Run_Total,
6266                                X_Project_Id,
6267                                X_Rev_Event_Amount,
6268                                X_Rev_Carrying_Out_Org_Id,
6269                                X_rev_or_bill_date,
6270                                X_calling_process,
6271                                X_Request_id,
6272                                C_Installment_Id,
6273 			       X_Rev_Count,
6274 			       X_Rev_Installment_total,
6275                                St_Err_Code,
6276                                St_Err_Buff);
6277 	--X_LAST_CALL_FOR_REVENUE := FALSE; -- Bug 3254097
6278    --End If;
6279 
6280  End;
6281  CLOSE rev_cur_select;
6282 
6283 End REVENUE_ACCRUAL;
6284 
6285 ------------------------------------------------------------------------
6286 ------------------------------------------------------------------------
6287 --Procedure UPDATE_PROJECT_MANAGER : This procedure updates Award Project Manager
6288 --with current Award Manager
6289 --Stoped use of this procedure because GMS will be updating project manager
6290 --through award form only to fix bug 1907565
6291 ------------------------------------------------------------------------
6292 PROCEDURE UPDATE_PROJECT_MANAGER(X_Project_Id IN NUMBER,
6293 				 X_Award_Id   IN NUMBER) IS
6294 X_Person_Id NUMBER(15);
6295 X_end_date_active DATE := NULL;  		-- Bug fix for 863428
6296 Begin
6297 
6298  Begin
6299   Select
6300   person_id,
6301   end_date_active
6302   into
6303   X_Person_Id,
6304   X_end_date_active				-- Bug fix for 863428
6305   from
6306   GMS_PERSONNEL
6307   where award_id = X_Award_Id
6308   and trunc(sysdate) between trunc(start_date_active) and trunc(end_date_active)
6309   and award_role = 'AM';
6310     EXCEPTION
6311        WHEN NO_DATA_FOUND THEN
6312            Begin
6313              Select
6314               person_id
6315              into
6316               X_Person_Id
6317              from
6318              GMS_PERSONNEL
6319              where award_id = X_Award_Id
6320              and award_role = 'AM'
6321              and end_date_active IS NULL;
6322                   EXCEPTION
6323                         WHEN NO_DATA_FOUND THEN
6324                                 Begin
6325                                         Select
6326                                         person_id
6327                                         into
6328                                         X_Person_Id
6329                                         from
6330                                         GMS_PERSONNEL
6331                                         where award_id = X_Award_Id
6332                                         and award_role = 'AM'
6333                                         and end_date_active = (select max(end_date_active)
6334                                                                from gms_personnel
6335                                                                where
6336                                                                    award_id = X_Award_Id
6337                                                                and award_role = 'AM');
6338 
6339                                 End ;
6340            End ;
6341    End;
6342 
6343 
6344  Begin
6345 
6346   update pa_project_parties
6347   set   resource_source_id=X_Person_Id,
6348         end_date_active = X_end_date_active
6349   where project_id = X_Project_Id
6350   and project_role_id =(select project_role_id
6351                         from   pa_project_role_types
6352                         where  project_role_type = 'PROJECT MANAGER');
6353  Exception
6354   when others then
6355        RAISE;
6356  End;
6357 
6358 End UPDATE_PROJECT_MANAGER;
6359 
6360 -----------------------------------------------------------------------------------------
6361 -- Procedure AWARD_BILLING: This is the actual Billing Extension which gets called by the core
6362 -- Billing or Revenue Programs.
6363 -----------------------------------------------------------------------------------------
6364 PROCEDURE AWARD_BILLING
6365 ( X_project_id IN NUMBER,
6366                          X_top_Task_id IN NUMBER DEFAULT NULL,
6367                          X_calling_process IN VARCHAR2 DEFAULT NULL,
6368                          X_calling_place IN VARCHAR2 DEFAULT NULL,
6369                          X_amount IN NUMBER DEFAULT NULL,
6370                          X_percentage IN NUMBER DEFAULT NULL,
6371                          X_rev_or_bill_date IN DATE DEFAULT NULL,
6372                          X_bill_extn_assignment_id IN NUMBER DEFAULT NULL,
6373                          X_bill_extension_id IN NUMBER DEFAULT NULL,
6374                          X_request_id IN NUMBER DEFAULT NULL) IS
6375 sql_select VARCHAR2(4000);
6376 sql_from VARCHAR2(2000);
6377 sql_where  VARCHAR2(2000);
6378 sql_orderby VARCHAR2(2000);
6379 l_sql_orderby VARCHAR2(2000); --Bug 3235390
6380 
6381 X_Award_Id NUMBER(15);
6382 X_Award_Rev_Distribution_Rule VARCHAR2(30);
6383 X_Award_Bill_Distribution_Rule VARCHAR2(30);
6384 X_Award_Status    VARCHAR2(30);
6385 X_Revenue_Limit_Flag VARCHAR2(1);
6386 X_Invoice_Limit_Flag VARCHAR2(1);  /*Bug 6642901 */
6387 /* Added for bug 5026657 */
6388 g_process_again VARCHAR2(1) DEFAULT 'N';
6389 g_labor_exp_to_process VARCHAR2(1) DEFAULT 'N';
6390 g_non_labor_neg_exp_processed VARCHAR2(1) DEFAULT 'N';
6391 f_labor_exp_to_process VARCHAR2(1) DEFAULT 'N';
6392 f_non_labor_neg_exp_processed VARCHAR2(1) DEFAULT 'N';
6393 
6394 CURSOR GET_INSTALLMENTS IS
6395 Select
6396 Installment_Id,
6397 Start_Date_Active,
6398 End_Date_Active
6399 from
6400 GMS_INSTALLMENTS
6401 where
6402 Award_Id = X_Award_Id
6403 /*  and active_flag = 'Y'  bug 6878405  */
6404 and nvl(billable_flag,'N') = 'Y'
6405 order by End_Date_Active;
6406 
6407 -- Added for Bug 1744641: To Generate errors when an exception occurs
6408 -- during the process of generation of invoice/Revenue.
6409 Cursor GMS_AWARDS_CURSOR is
6410 select
6411       a.Award_number,
6412       a.Award_short_name,
6413       a.award_id
6414     from
6415     GMS_AWARDS a
6416     where
6417       a.Award_Project_Id = X_Project_Id;
6418 
6419 /* Fetch Variables for GET_INSTALLMENTS */
6420  C_Installment_Id      NUMBER(15);
6421  C_Start_Date_Active   DATE;
6422  C_End_Date_Active     DATE;
6423 
6424 X_Labor_Sel_Grp_Diff_Ind Mark_Sel_Grp_Diff_Array;
6425 X_Lbr_Rt_Jstfy_Flag Mark_Sel_Grp_Diff_Array;
6426 X_Lbr_Padding_Length Padding_Length_Array;
6427 X_Lbr_Text_Array Free_Text_Array;
6428 X_Lbr_Cnt_Of_Columns_Selected NUMBER(3) := 0;
6429 X_LABOR_CONCAT_SELECT VARCHAR2(2000);
6430 X_LABOR_CONCAT_FROM VARCHAR2(2000);
6431 X_LABOR_CONCAT_WHERE VARCHAR2(2000);
6432 X_LABOR_CONCAT_ORDERBY VARCHAR2(2000);
6433 X_LABOR_ORDERBY_IS_NULL VARCHAR2(1);
6434 
6435 X_Non_Labor_Sel_Grp_Diff_Ind Mark_Sel_Grp_Diff_Array;
6436 X_Nlbr_Rt_Jstfy_Flag Mark_Sel_Grp_Diff_Array;
6437 X_Nlbr_Padding_Length Padding_Length_Array;
6438 X_Nlbr_Text_Array Free_Text_Array;
6439 X_Nlbr_Cnt_Of_Columns_Selected NUMBER(3) := 0;
6440 X_NON_LABOR_CONCAT_SELECT VARCHAR2(2000);
6441 X_NON_LABOR_CONCAT_FROM VARCHAR2(2000);
6442 X_NON_LABOR_CONCAT_WHERE VARCHAR2(2000);
6443 X_NON_LABOR_CONCAT_ORDERBY VARCHAR2(2000);
6444 X_NON_LABOR_ORDERBY_IS_NULL  VARCHAR2(1);
6445 /* Following two variables added for bug 3523930 */
6446 X_LABOR_tsk_lvl_fmt VARCHAR2(1) :='N';
6447 X_NON_LABOR_tsk_lvl_fmt VARCHAR2(1) :='N';
6448 
6449 X_Format_Specific_Where  VARCHAR2(2000) := NULL;
6450 X_Fixed_Select VARCHAR2(2000) := NULL;
6451 X_Fixed_Where VARCHAR2(2000) := NULL;
6452 X_Fixed_From VARCHAR2(2000) := NULL;
6453 
6454 X_Class_Category VARCHAR2(30) := NULL;
6455 X_Carrying_Out_Org_Id NUMBER(15);
6456 X_Rev_Carrying_Out_Org_Id NUMBER(15);
6457 
6458 X_Sponsored_Type_Flag   VARCHAR2(1);
6459 X_Project_Type		VARCHAR2(30);
6460 
6461 X_Trx_Type  VARCHAR2(15);
6462 
6463 X_Period_Status VARCHAR2(1);
6464 
6465 X_Err_Num NUMBER;
6466 X_Err_Stage VARCHAR2(200);
6467 
6468 x_pa_err_msg VARCHAR2(2000);
6469 x_pa_status NUMBER;
6470 
6471 St_Err_Code  NUMBER(1);
6472 St_Err_Buff    Varchar2(2000);
6473 
6474 X_award_number VARCHAR2(15);--For bug 1744641
6475 X_award_name   varchar2(250);--For bug 1744641
6476 X_awd_id       NUMBER;
6477 
6478 /* bug 5242484 - start */
6479 k NUMBER := 0;
6480 x_tot_inst_count NUMBER := 0;
6481 /* bug 5242484 - end */
6482 
6483 f_dummy NUMBER := 0 ;--For Bug 5026657
6484 
6485 X_Position Number(3);
6486 
6487 -- ##This is to process awards that has no expenditures to process
6488 NO_EXP_TO_PROCESS Exception;
6489 
6490 Begin
6491 
6492 SAVEPOINT AWARD_BILLING_BEGIN;   -- Added for bug 4243374
6493 gms_error_pkg.set_debug_context; -- Added for Bug: 2510024
6494 
6495 -- Code added for bug 1744641
6496 open GMS_AWARDS_CURSOR;
6497 Fetch gms_awards_cursor into X_award_number,X_award_name, x_awd_id;
6498 Close GMS_AWARDS_CURSOR;
6499 --End of the Code added for bug 1744641
6500 
6501 /* GMS INSTALLATION CHECK */
6502 If gms_install.enabled then
6503 
6504 IF L_DEBUG = 'Y' THEN
6505 	gms_error_pkg.gms_debug('GMS INSTALLED -- START AWARD BILLING FOR Award Project:','C');
6506 	gms_error_pkg.gms_debug('X_Project_id:'||X_Project_id,'C');
6507 END IF;
6508 
6509 -- Bug 1980810 : Added to set currency related global variables
6510 --		 Call to pa_currency.round_currency_amt function will use
6511 --		 global variables and thus improves performance
6512 
6513 pa_currency.set_currency_info;
6514 
6515 -- Concurrency Control
6516      gms_bill_concurrency(X_request_id,
6517 			  X_Project_id,
6518 			  St_Err_Code,
6519 			  St_Err_Buff);
6520 IF L_DEBUG = 'Y' THEN
6521 	gms_error_pkg.gms_debug('After gms_bill_concurrency x_error_code :'||St_Err_Code,'C');
6522 END IF;
6523 
6524   If St_Err_Code <> 0  then
6525       gms_error_pkg.gms_message('GMS_BILLING_CONCURRENCY',
6526                                 'PRJ',
6527                                 X_Project_id,
6528                                 X_Exec_Type => 'C',
6529                                 X_Err_Code => St_Err_Code,
6530                                 X_Err_Buff => St_Err_Buff);
6531 
6532      Raise NO_PROCESSING_OF_AWARD ;
6533 
6534   End if;
6535 
6536 /*-------------------------------------------------------------------------
6537 || Following Begin ... End code has been added for concurrency control.
6538 || If a user is updating any billing related data, billing process should
6539 || not run for that award. Corollary: If billing process is running for an
6540 || award, users should not be able to update any billing data on the award
6541 || form. Bug 1652198.....
6542 || Procedure: lock_award_records created for this.
6543  ------------------------------------------------------------------------- */
6544 -- ## Code change starts here for Bug 1652198....
6545 /**FOr Bug 4506225 :MOved the code after the call to GMS_TAX
6546    lock_award_records(X_Project_id,
6547 		      St_Err_Code,
6548 		      St_Err_Buff);
6549 
6550   IF L_DEBUG = 'Y' THEN
6551   	gms_error_pkg.gms_debug('After lock_award_records St_Err_Code :'||St_Err_Code,'C');
6552   END IF;
6553 
6554     If St_Err_Code <> 0  then
6555       gms_error_pkg.gms_message('GMS_BILLING_CONCURRENCY',
6556                                 'PRJ',
6557                                 X_Project_id,
6558                                 X_Exec_Type => 'C',
6559                                 X_Err_Code => St_Err_Code,
6560                                 X_Err_Buff => St_Err_Buff);
6561 
6562      Raise NO_PROCESSING_OF_AWARD ;
6563 
6564   End if;
6565 ---End of moving of code for bug 4506225*/
6566 -- ## Code change ends here for Bug 1652198....
6567 
6568 
6569 -- Process failure rollback
6570          billing_rollback(X_Project_id,
6571 		          --X_calling_process,
6572                           NULL, -- event_num
6573                           St_Err_Code,
6574                           St_Err_Buff);
6575 
6576 IF L_DEBUG = 'Y' THEN
6577 	gms_error_pkg.gms_debug('After billing_rollback x_error_code :'||St_Err_Code,'C');
6578 END IF;
6579 
6580   If St_Err_Code <> 0  then
6581       gms_error_pkg.gms_message('GMS_BILLING_ROLLBACK_FAILURE',
6582                                 'PRJ',
6583                                 X_Project_id,
6584                                 X_Exec_Type => 'C',
6585                                 X_Err_Code => St_Err_Code,
6586                                 X_Err_Buff => St_Err_Buff);
6587      Raise ROLLBACK_FAILURE;
6588 
6589   End if;
6590 
6591 -- This function check was done for performance reasons
6592 -- If there are no transactions to be processed, RETURN from this process.
6593 -- We're  filtering by bare minimum conditions only.
6594 
6595 IF NOT IS_PROCESSING_REQD(X_Calling_Process , X_Awd_Id ) THEN
6596 
6597    IF L_DEBUG = 'Y' THEN
6598    	gms_error_pkg.gms_debug('No records to process - NOT IS_PROCESSING_REQD :'||St_Err_Code,'C');
6599    END IF;
6600    RAISE NO_EXP_TO_PROCESS;
6601    -- NO recored for processing, we raising an exception to cleanup GMS processing
6602 
6603 END IF;
6604 
6605 
6606 /* Selecting the Project Type. GO THROUGH BILL_EXTENSION only if
6607    Project_Type = 'AWARD_PROJECT'
6608 */
6609   Begin
6610      Select
6611      project_type,
6612      carrying_out_organization_id --This is being selected again here because Revenue
6613      into                         --doesn't have access to GET_FORMAT_SELECT
6614      X_Project_Type,
6615      X_Rev_Carrying_Out_Org_Id
6616      from
6617      PA_PROJECTS_ALL
6618      where
6619      project_id = X_Project_Id;
6620 
6621    EXCEPTION
6622     WHEN OTHERS THEN
6623       gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
6624 				'SQLCODE',
6625 			        SQLCODE,
6626 				'SQLERRM',
6627 				SQLERRM,
6628 				X_Exec_Type => 'C',
6629 				X_Err_Code => St_Err_Code,
6630 				X_Err_Buff => St_Err_Buff);
6631       --RAISE_APPLICATION_ERROR(-20526,St_Err_Buff);
6632       Raise NO_PROCESSING_OF_AWARD ;
6633       --RETURN;
6634 
6635   End;
6636 
6637    IF L_DEBUG = 'Y' THEN
6638    	gms_error_pkg.gms_debug('Project Type is :'||X_Project_Type,'C');
6639    END IF;
6640 
6641 /* ===============================================================================
6642 || Code for period validation has been commented out.
6643 || bug number: 1510848, release 11.5D
6644   =============================================================================== */
6645 
6646 If X_Project_Type = 'AWARD_PROJECT' then --
6647 
6648   -- Selecting the Class Category--
6649   Begin
6650   select
6651   cc.class_category
6652   into
6653   X_Class_Category
6654   from
6655   pa_class_categories cc
6656   where
6657   sysdate between cc.start_date_active and
6658   nvl(cc.end_date_active,SYSDATE + 1) and
6659   cc.autoaccounting_flag = 'Y';
6660   EXCEPTION
6661    WHEN NO_DATA_FOUND THEN
6662      X_Class_Category := NULL;
6663   End;
6664 
6665    IF L_DEBUG = 'Y' THEN
6666    	gms_error_pkg.gms_debug('After Class Category select','C');
6667    END IF;
6668 
6669   Begin
6670     select
6671       a.Award_Id,
6672       a.Revenue_Distribution_Rule,
6673       a.Billing_Distribution_Rule,
6674       a.Status,
6675       -- ag.Revenue_Limit_Flag -- Bug 1841288
6676       nvl(a.hard_limit_flag,'N') -- Bug 1841288 : Taken hard_limit_flag from gms_awards instead of pa_agreements_all
6677       ,nvl(a.invoice_limit_flag,'N') -- Bug 6642901
6678     into
6679       X_Award_Id, -- Adding this because Revenue Process doesnot have access to GET_FORMAT_SELECT proc.
6680       X_Award_Rev_Distribution_Rule,
6681       X_Award_Bill_Distribution_Rule,
6682       X_Award_Status,
6683       X_Revenue_Limit_Flag,
6684       X_Invoice_limit_Flag -- Bug 6642901
6685     from
6686     GMS_AWARDS a
6687     --PA_AGREEMENTS_ALL ag -- Bug 1841288 : Removed join from PA_AGREEMENTS_ALL Table
6688     where
6689       a.Award_Project_Id = X_Project_Id;
6690   -- and a.agreement_id = ag.agreement_id;  -- Bug 1841288 : Removed the join
6691   End;
6692 
6693   IF L_DEBUG = 'Y' THEN
6694   	gms_error_pkg.gms_debug('Distribution Rule:Revenue:'||X_Award_Rev_Distribution_Rule,'C');
6695   	gms_error_pkg.gms_debug('Distribution Rule:Invoice:'||X_Award_Bill_Distribution_Rule,'C');
6696   END IF;
6697 
6698 --------------------------------------------------------------------------------------------------------- +
6699 -- Bug 3143102 : Following code takes care of the scenario where the labor and/or non-labor format
6700 -- has an invalid element ..
6701   If (X_calling_process = 'Invoice' and X_Award_Bill_Distribution_Rule = 'COST') THEN
6702 
6703       IF NOT Is_Invoice_Format_Valid(X_project_id,NULL,NULL,'BILLING_PROCESS') THEN
6704 
6705          IF L_DEBUG = 'Y' THEN
6706   	    gms_error_pkg.gms_debug('Labor/Non-Labor format is Invalid','C');
6707          END IF;
6708 
6709          RAISE INVALID_INVOICE_FORMAT;
6710 
6711       End If;
6712 
6713   End If;
6714 
6715   IF L_DEBUG = 'Y' THEN
6716   	gms_error_pkg.gms_debug('Labor/Non-Labor format is Valid','C');
6717   END IF;
6718 --------------------------------------------------------------------------------------------------------- +
6719 
6720 -- CALL TAX UPDATION PROCEDURE
6721 
6722      gms_tax(X_Project_Id,
6723 	     X_Award_Id,
6724 	     X_Rev_Or_Bill_Date,
6725 	     X_Request_Id,
6726 	     St_Err_Code,
6727 	     St_Err_Buff
6728 	     );
6729 
6730     If St_Err_Code <> 0 then
6731        --ROLLBACK;
6732        --RAISE FND_API.G_EXC_ERROR;
6733 	--Raise NO_PROCESSING_OF_AWARD ;--4506225
6734 	Raise GMS_TAX_FAILURE; --4506225
6735    End If;
6736 
6737 IF L_DEBUG = 'Y' THEN
6738 	gms_error_pkg.gms_debug('After tax, x_error_code :'||St_Err_Code,'C');
6739 END IF;
6740  --For Bug 4506225 :Moved the code after gms_Tax
6741  lock_award_records(X_Project_id,
6742                       St_Err_Code,
6743                       St_Err_Buff);
6744 
6745   IF L_DEBUG = 'Y' THEN
6746         gms_error_pkg.gms_debug('After lock_award_records St_Err_Code :'||St_Err_Code,'C');
6747   END IF;
6748 
6749     If St_Err_Code <> 0  then
6750       gms_error_pkg.gms_message('GMS_BILLING_CONCURRENCY',
6751                                 'PRJ',
6752                                 X_Project_id,
6753                                 X_Exec_Type => 'C',
6754                                 X_Err_Code => St_Err_Code,
6755                                 X_Err_Buff => St_Err_Buff);
6756 
6757      Raise NO_PROCESSING_OF_AWARD ;
6758 
6759   End if;
6760 --End of bug fix for Bug 4506225
6761    --commit;
6762 
6763 If X_Award_Status in ('ACTIVE','ON_HOLD') then  -- Do processing only if Award Status is Active
6764 
6765         --UPDATE_PROJECT_MANAGER(X_Project_Id,X_Award_Id);
6766           /* Stopped updating in billing process because now onwards GMS
6767               will update project manager through award form only to fix  bug 1907565 gnema*/
6768 
6769  -- Bug 3235390  : Intializing the variables used .
6770  x_temp_negative_evt_num := -1000;
6771 
6772 IF (
6773      -- (X_calling_process = 'Revenue' and X_Award_Rev_Distribution_Rule = 'COST')  OR
6774       (X_calling_process = 'Invoice' and X_Award_Bill_Distribution_Rule = 'COST')
6775     ) then -- Check for Billing Distribution Rule
6776  Begin
6777 
6778   GET_FORMAT_SELECT(X_Project_Id,
6779                     X_Award_Id,
6780                     X_Carrying_Out_Org_Id,
6781                     X_Labor_Sel_Grp_Diff_Ind,
6782                     X_Non_Labor_Sel_Grp_Diff_Ind,
6783                     X_Lbr_Cnt_Of_Columns_Selected,
6784                     X_Nlbr_Cnt_Of_Columns_Selected,
6785                     X_Lbr_Rt_Jstfy_Flag,
6786                     X_Nlbr_Rt_Jstfy_Flag,
6787                     X_Lbr_Padding_Length,
6788                     X_Nlbr_Padding_Length,
6789                     X_Lbr_Text_Array,
6790                     X_Nlbr_Text_Array,
6791  		    X_LABOR_CONCAT_SELECT,
6792                     X_LABOR_CONCAT_FROM,
6793                     X_LABOR_CONCAT_WHERE,
6794                     X_LABOR_CONCAT_ORDERBY,
6795    		    X_LABOR_ORDERBY_IS_NULL,
6796                     X_NON_LABOR_CONCAT_SELECT,
6797                     X_NON_LABOR_CONCAT_FROM,
6798                     X_NON_LABOR_CONCAT_WHERE,
6799                     X_NON_LABOR_CONCAT_ORDERBY,
6800                     X_NON_LABOR_ORDERBY_IS_NULL,
6801 		    X_LABOR_tsk_lvl_fmt,  /* added for bug 3523930 */
6802 		    X_NON_LABOR_tsk_lvl_fmt,  /* added for bug 3523930 */
6803                     X_Err_Num,
6804                     X_Err_Stage);
6805 
6806          --dbms_output.put_line('After GET_FORMAT_SELECT Proc '||'Award Id '||to_char(X_Award_Id) );
6807 
6808 IF L_DEBUG = 'Y' THEN
6809 	gms_error_pkg.gms_debug('After Format Selection','C');
6810 END IF;
6811 
6812 
6813   sql_select := 'select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)*/  ';
6814   sql_from   := 'from ';
6815   sql_where  := 'where ';
6816   X_Fixed_Select := ' adl.raw_cost, ei.expenditure_item_id, ei.expenditure_item_date, ei.task_id,
6817   ei.bill_hold_flag, adl.billable_flag, ei.adjusted_expenditure_item_id, adl.adl_line_num,adl.parent_adl_line_num,
6818   adl.adl_status, adl.award_id, adl.project_id, adl.cdl_line_num,ei.expenditure_type,
6819   nvl(ei.override_to_organization_id,e.incurred_by_organization_id),adl.ind_compiled_Set_id,adl.burdenable_raw_cost,
6820   ei.transaction_source '; --bug 2909746
6821 
6822   X_Fixed_From := 'pa_expenditure_items_all ei ,pa_expenditures_all e, pa_expenditure_types et,'
6823   ||' pa_projects_all p, pa_project_types pt,'
6824   ||' pa_tasks t3, pa_tasks t5, gms_award_distributions adl ';
6825 
6826 /* --- 11.5 changes --- */
6827 --1. gms_award_distributions  added in the from clause
6828 --2. 4 new columns being selected from gms_award_distributions, raw_cost picked differently
6829 
6830 
6831  /* The DYNAMIC WHERE CLAUSE BUILDING below for Revenue is NOT USED any more. Replaced by the Procedure
6832     REVENUE_ACCRUAL
6833   */
6834 If X_calling_process = 'Revenue' then
6835 
6836  null;
6837 
6838 Elsif X_calling_process = 'Invoice' then
6839 
6840 /* ---   11.5 Changes ---
6841 -- 1.Columns like billed_flag,award_id, revenue_distributed_flag being picked from gms_award_distributions
6842 -- 2.Column attribute2 IS NULL changed to adl.document_type <>'ENC'
6843 -- 3.condtions to join gms_award_distributions and pa_expenditure_items_all added
6844 -- 4.check for adl lines with adl status <> 'I'
6845 */
6846 
6847 X_Fixed_Where := ' adl.award_id = :X_Award_Id '
6848   ||'and ei.expenditure_item_id = adl.expenditure_item_id '
6849   ||'and adl.adl_status <> ''I'' '
6850   ||'and ei.system_linkage_function <> ''BTC'' '
6851   ||'and p.project_status_code <> ''CLOSED'' '
6852   ||'and pt.project_type = p.project_type '
6853   ||'and pt.direct_flag = ''N'' '
6854   ||'and t3.project_id = p.project_id '   --Changed t to t2, then changed t2 to t3 to get rid or ORA-09118
6855   ||'and ei.task_id = t3.task_id '
6856   ||'and t3.top_task_id = t5.task_id '
6857   ||'and t5.ready_to_bill_flag = ''Y'' '
6858   ||'and ((adl.line_num_reversed is null and adl.reversed_flag is null and ei.cost_distributed_flag = ''Y'') '
6859   ||'     or  ((adl.line_num_reversed is not null or adl.reversed_flag is not null) and adl.cost_distributed_flag = ''Y''))' -- Bug 1852802
6860   ||'and nvl(ei.bill_hold_flag,''N'') = ''N'' '
6861   ||'and ei.expenditure_item_date <= nvl(trunc(:X_rev_or_bill_date),SYSDATE) '
6862   ||'and trunc(ei.expenditure_item_date) <= trunc(:C_End_Date_Active) '
6863   ||'and nvl(adl.billed_flag,''N'') <> ''Y'' ' -- To pick up items where Billed Flag <> 'Y'
6864   ||'and ei.expenditure_type = et.expenditure_type '
6865   ||'and e.expenditure_id = ei.expenditure_id '
6866   ||'and adl.fc_status = ''A'' '
6867   ||'and adl.adl_status = ''A'' '
6868   ||'and nvl(adl.billable_flag,''N'') = ''Y'' '
6869   ||'and adl.document_type = ''EXP''  '
6870   ||'and  exists '
6871   ||'(select 1 '
6872   ||'from gms_summary_project_fundings gspf '
6873   ||'where gspf.installment_id = :C_Installment_Id '
6874   ||'and ( '
6875   ||'    (gspf.task_id  = adl.task_id) '
6876   ||'OR  (gspf.task_id is NULL) '
6877   ||'OR  (gspf.task_id = (select t1.top_task_id from pa_tasks t1 where t1.task_id = adl.task_id)) '
6878   ||'   ) '
6879   ||'and gspf.project_id     = adl.project_id '
6880   ||') ';
6881 
6882 End If;
6883 
6884 /* bug 5242484 - start */
6885 select count(*)
6886 into x_tot_inst_count
6887 from gms_installments
6888 where award_id = X_Award_id
6889 /* and active_flag = 'Y' bug 6878405 */
6890 and nvl(billable_flag,'N') = 'Y';
6891 
6892 FOR k in 1..x_tot_inst_count LOOP
6893 X_ei_rollback_inst_tab(k).rev_bill_amount := 0;
6894 X_ei_rollback_inst_tab(k).installment_id := 0;
6895 END LOOP;
6896 /* bug 5242484 - end */
6897 
6898 ------------------------------------------------------------------
6899 /* Opening the Cursor to Process each Installment of this Award (For INVOICE Processing) */
6900 ------------------------------------------------------------------
6901 OPEN GET_INSTALLMENTS;
6902  BEGIN
6903    LOOP
6904     FETCH GET_INSTALLMENTS into
6905     C_Installment_Id,
6906     C_Start_Date_Active,
6907     C_End_Date_Active;
6908 
6909 
6910     EXIT WHEN GET_INSTALLMENTS%NOTFOUND;
6911 
6912 
6913  -- BUG 3235390 : Deleting data from gms_events_temp_format
6914  DELETE gms_events_temp_format;
6915 
6916  /* For bug 5026657 */
6917  f_dummy := 0;
6918 
6919 WHILE f_dummy<2 LOOP   /* dummy loop for re-processing , bug 5026657 */
6920 
6921 f_dummy := f_dummy + 1;
6922 
6923 
6924 IF L_DEBUG = 'Y' THEN
6925 	gms_error_pkg.gms_debug('In installment loop, Installment_Id :'||C_Installment_Id,'C');
6926 END IF;
6927 
6928 /*============================================================================================*/
6929 /* Processing Begins here for the rows which have expenditure type which are LABOR related */
6930 /*==============================================================================================*/
6931 X_Format_Specific_Where := 'and ei.system_linkage_function in (''ST'',''OT'') ';
6932 sql_select := sql_select||X_LABOR_CONCAT_SELECT;
6933 sql_select := sql_select||X_Fixed_Select;
6934 
6935 sql_from := sql_from||X_LABOR_CONCAT_FROM;
6936 sql_from := sql_from||X_Fixed_From;
6937 
6938 sql_where := sql_where||X_LABOR_CONCAT_WHERE;
6939 sql_where := sql_where||X_Fixed_Where;
6940 sql_where := sql_where||X_Format_Specific_Where;
6941 
6942 /* ------ GROUP BY CHANGES ------- */
6943 select instr(UPPER(X_LABOR_CONCAT_SELECT),'SUM',1,1)
6944 into   X_position
6945 from   dual;
6946 
6947 if x_position=0 then
6948    sql_orderby := ' order by ';
6949 elsif x_position >0 then
6950    sql_orderby := ' group by ';
6951 end if;
6952 /* ------ GROUP BY CHANGES ------- */
6953 
6954 -- Bug 3235390 : Modified the order by clause
6955 l_sql_orderby :=' DECODE( NVL(ei.net_zero_adjustment_flag,'||''''||'N'||''''||'),'||''''||'N' ||''''||
6956  ', NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||',ei.expenditure_item_id)),'
6957    ||''''||'Y'||''''||', DECODE(SIGN(NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
6958    ||''''||'Invoice'||''''||',ei.expenditure_item_id))),'
6959    ||'1,-NVL(ei.raw_Cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||
6960    ',ei.expenditure_item_id)),' ||' NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
6961    ||''''||'Invoice'||''''||',ei.expenditure_item_id)))),'
6962    || 'NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''
6963    ||',ei.expenditure_item_id)),NVL(ei.adjusted_expenditure_item_id,ei.expenditure_item_id),'
6964    || 'adl.raw_cost, adl.cdl_line_num';
6965 
6966 
6967 if x_position=0 then
6968  sql_orderby := sql_orderby || l_sql_orderby ||',';
6969 elsif x_position >0 then
6970    sql_orderby := sql_orderby || ' ei.raw_cost,adl.raw_cost, ei.net_zero_adjustment_flag, ';
6971 end if;
6972 
6973 -- Bug 1652198, moved format order by first.
6974   sql_orderby := sql_orderby || X_LABOR_CONCAT_ORDERBY;
6975 
6976 --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 ';
6977 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 ';
6978 
6979 --Bug 2909746 : Added cdl_line_num in the order by clause
6980 
6981 If X_LABOR_ORDERBY_IS_NULL = 'N' then
6982 
6983   sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
6984 
6985 Elsif X_LABOR_ORDERBY_IS_NULL = 'Y' then
6986 
6987   sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
6988 
6989 End If;
6990 
6991 -- 11.5 Change, Added adl.adl_line_num in the order by clause
6992 
6993 /* ------ GROUP BY CHANGES ------- */
6994 if x_position >0 then
6995 sql_orderby := sql_orderby||' ,  ei.expenditure_item_date '||
6996                ', ei.task_id,ei.bill_hold_flag, adl.billable_flag, ei.adjusted_expenditure_item_id, '||
6997                ' adl.parent_adl_line_num, adl.adl_status, adl.award_id, adl.project_id,  '||
6998 	       'ei.expenditure_type,nvl(ei.override_to_organization_id,e.incurred_by_organization_id),'||
6999 	       ' adl.ind_compiled_Set_id, adl.burdenable_raw_cost,  ei.transaction_source';
7000 end if;
7001 
7002 /* ------ GROUP BY CHANGES ------- */
7003 
7004       For i in 1..X_Lbr_Cnt_Of_Columns_Selected LOOP
7005 	   null;
7006             --dbms_output.put_line('Column :'||X_Labor_Sel_Grp_Diff_Ind(i));
7007       END LOOP;
7008       For i in 1..X_Nlbr_Cnt_Of_Columns_Selected LOOP
7009 		null;
7010             --dbms_output.put_line('Column :'||X_Non_Labor_Sel_Grp_Diff_Ind(i));
7011       END LOOP;
7012 
7013   -- Bug 3235390 : Modified the below logic to introduce new order by clause
7014   -- sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ;
7015   IF  x_position=0 THEN
7016       sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ;
7017   ELSIF x_position >0 THEN
7018       sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ||'  order by ' ||  l_sql_orderby  ;
7019   END IF;
7020 
7021 
7022 --dbms_output.put_line('Processing LABOR Transactions ');
7023 
7024 IF L_DEBUG = 'Y' THEN
7025 	gms_error_pkg.gms_debug('Before FORMAT_SPECIFIC_BILLING call','C');
7026 
7027 END IF;
7028 
7029 /* bug 5413530 */
7030 X_Trans_type := 'LABOR';
7031 IF ( f_dummy = 2 ) THEN G_trans_type := 'LABOR';
7032 END IF;
7033 
7034      FORMAT_SPECIFIC_BILLING(X_Project_Id,
7035                              X_Award_Id,
7036                              X_Class_Category,
7037                              X_rev_or_bill_date,
7038 			--     X_Revenue_Limit_Flag,
7039 				     X_Invoice_Limit_Flag, /* for bug 6642901*/
7040                              X_request_id,
7041                              X_Labor_Sel_Grp_Diff_Ind,
7042                              X_Lbr_Cnt_Of_Columns_Selected,
7043                              X_Lbr_Rt_Jstfy_Flag,
7044                              X_Lbr_Padding_Length,
7045                              X_Lbr_Text_Array,
7046                              sql_select,
7047                              X_Carrying_Out_Org_Id,
7048                              X_calling_process,
7049 			     X_LABOR_tsk_lvl_fmt,  /* added for bug 3523930 */
7050                              C_Installment_Id,
7051                              C_Start_Date_Active,
7052                              C_End_Date_Active,
7053                              X_Err_Num,
7054                              X_Err_Stage,
7055 			     'LABOR',            /* added for bug 5026657 */
7056 			     f_labor_exp_to_process, /* added for bug 5026657 */
7057 			     f_non_labor_neg_exp_processed); /* added for bug 5026657 */
7058 
7059 g_labor_exp_to_process := f_labor_exp_to_process;
7060 
7061 /*======================================================================================*/
7062 /* Processing begins here for rows which have Expenditure Types which are NON-LABOR related */
7063 /*=======================================================================================*/
7064 sql_select := 'select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)*/  ';
7065 sql_from   := 'from ';
7066 sql_where  := 'where ';
7067 X_Format_Specific_Where := 'and ei.system_linkage_function not in (''ST'',''OT'') ';
7068 sql_select := sql_select||X_NON_LABOR_CONCAT_SELECT;
7069 sql_select := sql_select||X_Fixed_Select;
7070 
7071 sql_from := sql_from||X_NON_LABOR_CONCAT_FROM;
7072 sql_from := sql_from||X_Fixed_From;
7073 
7074 sql_where := sql_where||X_NON_LABOR_CONCAT_WHERE;
7075 sql_where := sql_where||X_Fixed_Where;
7076 sql_where := sql_where||X_Format_Specific_Where;
7077 
7078 /* ------ GROUP BY CHANGES ------- */
7079 
7080 x_position := 0;
7081 
7082 select instr(UPPER(X_NON_LABOR_CONCAT_SELECT),'SUM',1,1)
7083 into   X_position
7084 from   dual;
7085 
7086 if x_position=0 then
7087    sql_orderby := ' order by ';
7088 elsif x_position >0 then
7089    sql_orderby := ' group by ';
7090 end if;
7091 /* ------ GROUP BY CHANGES ------- */
7092 
7093 -- Bug 3235390 : Modified the order by clause
7094 l_sql_orderby := ' DECODE( NVL(ei.net_zero_adjustment_flag,'||''''||'N'||''''||'),'||''''||'N' ||''''||
7095  ', NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||',ei.expenditure_item_id)),'
7096    ||''''||'Y'||''''||', DECODE(SIGN(NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
7097    ||''''||'Invoice'||''''||',ei.expenditure_item_id))),'
7098    ||'1,-NVL(ei.raw_Cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''||
7099    ',ei.expenditure_item_id)),' ||' NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('
7100    ||''''||'Invoice'||''''||',ei.expenditure_item_id)))),'
7101    || 'NVL(ei.raw_cost,gms_billing.get_total_adl_raw_cost('||''''||'Invoice'||''''
7102    ||',ei.expenditure_item_id)),NVL(ei.adjusted_expenditure_item_id,ei.expenditure_item_id),'
7103    || 'adl.raw_cost, adl.cdl_line_num';
7104 
7105 
7106   if x_position=0 then
7107       sql_orderby :=  sql_orderby ||l_sql_orderby||',' ;
7108   elsif x_position >0 then
7109    sql_orderby := sql_orderby || ' ei.raw_cost,adl.raw_cost, ei.net_zero_adjustment_flag, ';
7110   end if;
7111 
7112 -- Bug 1652198, moved format order by first.
7113   sql_orderby := sql_orderby || X_NON_LABOR_CONCAT_ORDERBY;
7114 
7115 
7116 --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 ';
7117 
7118 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 ';
7119 
7120 --Bug 2909746 : Added cdl_line_num in the order by clause
7121 If X_NON_LABOR_ORDERBY_IS_NULL = 'N' then
7122 
7123      sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
7124 
7125 Elsif X_NON_LABOR_ORDERBY_IS_NULL = 'Y' then
7126 
7127      sql_orderby := sql_orderby||' ,ei.expenditure_item_id, adl.cdl_line_num,adl.adl_line_num ';
7128 
7129 End If;
7130 
7131 -- 11.5 Change, Added adl.adl_line_num in the order by clause
7132 
7133 /* ------ GROUP BY CHANGES ------- */
7134 if x_position >0 then
7135 sql_orderby := sql_orderby||' ,  ei.expenditure_item_date '||
7136                ', ei.task_id,ei.bill_hold_flag, adl.billable_flag, ei.adjusted_expenditure_item_id, '||
7137                ' adl.parent_adl_line_num, adl.adl_status, adl.award_id, adl.project_id, '||
7138 	       'ei.expenditure_type,nvl(ei.override_to_organization_id,e.incurred_by_organization_id),'||
7139 	       ' adl.ind_compiled_Set_id, adl.burdenable_raw_cost,  ei.transaction_source';
7140 end if;
7141 
7142 /* ------ GROUP BY CHANGES ------- */
7143 
7144   -- Bug 3235390 : Modified the below logic to introduce new order by clause
7145 
7146   IF  x_position=0 THEN
7147       sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby ;
7148   ELSIF x_position >0 THEN
7149       sql_select := sql_select||' '||sql_from||' '||sql_where||' '||sql_orderby || ' Order By '||l_sql_orderby  ;
7150   END IF;
7151 
7152 --dbms_output.put_line('Processing NON LABOR Transactions ');
7153 
7154 /* bug 5413530 */
7155 X_Trans_type := 'NON-LABOR';
7156 
7157   FORMAT_SPECIFIC_BILLING(X_Project_Id,
7158                           X_Award_Id,
7159                           X_Class_Category,
7160                           X_rev_or_bill_date,
7161 			 -- X_Revenue_Limit_Flag,
7162 			 X_Invoice_Limit_Flag, /* for bug 6642901 */
7163                           X_request_id,
7164                           X_Non_Labor_Sel_Grp_Diff_Ind,
7165                           X_Nlbr_Cnt_Of_Columns_Selected,
7166                           X_Nlbr_Rt_Jstfy_Flag,
7167                           X_Nlbr_Padding_Length,
7168                           X_Nlbr_Text_Array,
7169                           sql_select,
7170                           X_Carrying_Out_Org_Id,
7171                           X_calling_process,
7172 			  X_NON_LABOR_tsk_lvl_fmt,  /* added for bug 3523930 */
7173                           C_Installment_Id,
7174                           C_Start_Date_Active,
7175                           C_End_Date_Active,
7176                           X_Err_Num,
7177                           X_Err_Stage,
7178 			  'NON LABOR',            /* added for bug 5026657 */
7179 			  f_labor_exp_to_process, /* added for bug 5026657 */
7180 			  f_non_labor_neg_exp_processed); /* added for bug 5026657 */
7181 
7182 g_non_labor_neg_exp_processed := f_non_labor_neg_exp_processed ;
7183 
7184 -------------------------------------------------------------------------
7185   sql_select := 'select /*+INDEX(ei PA_EXPENDITURE_ITEMS_U1)*/  ';		-- Bug 2380344 : Hardcoded Index for Performance Fix
7186   sql_from   := 'from ';
7187   sql_where  := 'where ';
7188 
7189 /* Added for bug 5026657 */
7190 IF (g_labor_exp_to_process = 'Y' and g_non_labor_neg_exp_processed = 'Y') THEN
7191 g_process_again := 'Y';
7192 ELSE
7193 g_process_again := 'N';
7194 END IF;
7195 
7196 IF L_DEBUG = 'Y' THEN
7197 	gms_error_pkg.gms_debug('f_dummy is '||f_dummy,'C');
7198         gms_error_pkg.gms_debug('g_process_again is '||g_process_again,'C');
7199 	gms_error_pkg.gms_debug('g_labor_exp_to_process is '||g_labor_exp_to_process,'C');
7200 	gms_error_pkg.gms_debug('g_non_labor_neg_exp_processed is '||g_non_labor_neg_exp_processed,'C');
7201 END IF;
7202 
7203 /* Added for bug 5026657 */
7204 /* Commented revenue limit flag condition and added invoice limit flag check for bug 6642901
7205 IF ( X_Revenue_Limit_Flag = 'N' OR
7206      ( X_Revenue_Limit_Flag = 'Y' AND g_process_again = 'N' ) ) THEN     -- %%%%%%% */
7207 
7208 IF ( X_Invoice_Limit_Flag = 'N' OR
7209      ( X_Invoice_Limit_Flag = 'Y' AND g_process_again = 'N' ) ) THEN
7210 
7211 f_dummy := f_dummy + 1;
7212 
7213 -- Bug 3235390 : Calling the CREATE_PA_EVENTS procedure to insert records in pa_events
7214 --               gms_event_attribute table from temporary table.
7215 
7216 CREATE_PA_EVENTS (X_project_id          ,
7217 	          X_Calling_Process ,
7218                   X_rev_or_bill_Date ,
7219                   X_Carrying_Out_Org_Id,
7220                   X_Request_Id ,
7221                   X_Installment_total,
7222 		  St_Err_Code,
7223 	          St_Err_Buff );
7224 
7225 IF St_Err_Code <> 0 THEN
7226    raise NO_PROCESSING_OF_AWARD ;
7227 END IF;
7228 
7229 
7230 /* Moved this here from inside FORMAT_SPECIFIC_BILLING so that Burden for Labor and NonLabor appear together */
7231 
7232         DO_BURDEN_EVENT_PROCESSING(X_Project_Id,
7233                                    X_rev_or_bill_Date,
7234                                    X_Calling_Process,
7235                                    X_Carrying_Out_Org_Id,
7236                                    X_Request_Id,
7237 				   X_Installment_total,
7238 				   St_Err_Code,
7239 				   St_Err_Buff);
7240                                    --C_Installment_Id);
7241 
7242                 If St_Err_Code <> 0 then
7243 			--ROLLBACK;
7244                         --RAISE FND_API.G_EXC_ERROR;
7245 			Raise NO_PROCESSING_OF_AWARD ;
7246                 End If;
7247 
7248 
7249 END IF ;    -- end if for  %%%%%%%   , bug 5026657
7250 
7251 END LOOP ;  -- dummy loop of re-processing , bug 5026657
7252 
7253  X_Installment_total.delete ; -- initalize installment_amount table for new installment
7254  X_Installment_tab.delete; -- initalize install_tab  for new installment
7255 
7256 END LOOP;
7257 
7258  -- Update the expenditures with bill_hold_flag set to Once (before the process) to 'N'
7259 
7260   One_Time_Bill_Hold(X_Project_Id,
7261 		     X_Award_Id,
7262 		     X_Rev_Or_Bill_Date,
7263 		     X_Request_Id,
7264 		     St_Err_Code,
7265 		     St_Err_Buff);
7266 
7267     If St_Err_Code <> 0 then
7268 
7269        --ROLLBACK;
7270        --RAISE FND_API.G_EXC_ERROR;
7271 	Raise NO_PROCESSING_OF_AWARD ;
7272 
7273     End if;
7274 
7275  END;
7276  CLOSE GET_INSTALLMENTS;
7277 
7278 
7279 End;
7280 
7281 --9999999999999999999999999999999999999999999
7282 
7283 ElsIf  (X_calling_process = 'Revenue' and X_Award_Rev_Distribution_Rule = 'COST') then -- Elsif for Billing_Distribution_Rule Check
7284 
7285  --dbms_output.put_line('Got into New Revenue Process ');
7286 
7287 ------------------------------------------------------------------
7288 /* Opening the Cursor to Process each Installment of this Award (For REVENUE Processing) */
7289 ------------------------------------------------------------------
7290 OPEN GET_INSTALLMENTS;
7291  BEGIN
7292    LOOP
7293     FETCH GET_INSTALLMENTS into
7294     C_Installment_Id,
7295     C_Start_Date_Active,
7296     C_End_Date_Active;
7297        EXIT WHEN GET_INSTALLMENTS%NOTFOUND;
7298 
7299 IF L_DEBUG = 'Y' THEN
7300 	gms_error_pkg.gms_debug('Revenue Process, In installment loop, installment :'||C_Installment_Id,'C');
7301 END IF;
7302 
7303 f_dummy := 0 ; --For Bug 5026657
7304 
7305   -- BUG 3235390 : Deleting data from gms_events_temp_format
7306   DELETE gms_events_temp_format;
7307 
7308 WHILE f_dummy<2 LOOP   /* dummy loop for re-processing , bug 5026657 */
7309 
7310 f_dummy := f_dummy + 1;
7311 
7312   IF L_DEBUG = 'Y' THEN
7313 	gms_error_pkg.gms_debug('Entering dummy loop....f_dummy is '||f_dummy,'C');
7314 END IF;
7315 
7316 /* Processing Labor Transactions */
7317     X_Trx_Type := 'LABOR';
7318 
7319            REVENUE_ACCRUAL(X_Project_Id,
7320                            X_Award_Id,
7321                            X_Class_Category,
7322                            X_rev_or_bill_date,
7323                            X_Revenue_Limit_Flag,
7324                            X_request_id,
7325                            X_Rev_Carrying_Out_Org_Id,
7326                            X_calling_process,
7327 			   X_Trx_Type,
7328                            C_Installment_Id,
7329                            C_Start_Date_Active,
7330                            C_End_Date_Active,
7331                            X_Err_Num,
7332                            X_Err_Stage,
7333 			   f_labor_exp_to_process,  /* Added for bug 5026657 */
7334 			   f_non_labor_neg_exp_processed); /* Added for bug 5026657 */
7335 
7336 g_labor_exp_to_process := f_labor_exp_to_process ; /* Added for bug 5026657 */
7337 
7338  /* Processing Non_Labor Transactions */
7339     X_Trx_Type := 'NON_LABOR';
7340 
7341 	   REVENUE_ACCRUAL(X_Project_Id,
7342                            X_Award_Id,
7343                            X_Class_Category,
7344                            X_rev_or_bill_date,
7345                            X_Revenue_Limit_Flag,
7346                            X_request_id,
7347                            X_Rev_Carrying_Out_Org_Id,
7348                            X_calling_process,
7349                            X_Trx_Type,
7350                            C_Installment_Id,
7351                            C_Start_Date_Active,
7352                            C_End_Date_Active,
7353                            X_Err_Num,
7354                            X_Err_Stage,
7355 			   f_labor_exp_to_process, /* Added for bug 5026657 */
7356 			   f_non_labor_neg_exp_processed); /* Added for bug 5026657 */
7357 
7358 g_non_labor_neg_exp_processed := f_non_labor_neg_exp_processed ; /* Added for bug 5026657 */
7359 
7360 -- Bug 3235390 : Calling the CREATE_PA_EVENTS procedure to insert records in pa_events
7361 --               gms_event_attribute table from temporary table.
7362 
7363 /* Added for bug 5026657 */
7364 IF (g_labor_exp_to_process = 'Y' and g_non_labor_neg_exp_processed = 'Y') THEN
7365 g_process_again := 'Y';
7366 ELSE
7367 g_process_again := 'N';
7368 END IF;
7369 
7370 /* Added for bug 5026657 */
7371 IF L_DEBUG = 'Y' THEN
7372 	gms_error_pkg.gms_debug('f_dummy is '||f_dummy,'C');
7373         gms_error_pkg.gms_debug('g_process_again is '||g_process_again,'C');
7374 	gms_error_pkg.gms_debug('g_labor_exp_to_process is '||g_labor_exp_to_process,'C');
7375 	gms_error_pkg.gms_debug('g_non_labor_neg_exp_processed is '||g_non_labor_neg_exp_processed,'C');
7376 END IF;
7377 
7378 /* Added for bug 5026657 */
7379 IF ( X_Revenue_Limit_Flag = 'N' OR
7380      ( X_Revenue_Limit_Flag = 'Y' AND g_process_again = 'N' ) ) THEN     -- %%%%%%%
7381 
7382 f_dummy := f_dummy + 1;
7383 
7384 CREATE_PA_EVENTS (X_project_id          ,
7385 	          X_Calling_Process ,
7386                   X_rev_or_bill_Date ,
7387                   X_Rev_Carrying_Out_Org_Id,
7388                   X_Request_Id ,
7389                   X_Rev_Installment_total,
7390 		  St_Err_Code,
7391 	          St_Err_Buff );
7392 
7393 IF St_Err_Code <> 0 THEN
7394    raise NO_PROCESSING_OF_AWARD ;
7395 END IF;
7396 
7397 /* Moved this here from inside REVENUE_ACCRUAL to club Labor and Nonlabor Burden together */
7398 
7399  DO_BURDEN_EVENT_PROCESSING(X_Project_Id,
7400                              X_rev_or_bill_Date,
7401                              X_Calling_Process,
7402                              X_Rev_Carrying_Out_Org_Id,
7403                              X_Request_Id,
7404 			     X_Rev_Installment_total,
7405 		             St_Err_Code,
7406                              St_Err_Buff);
7407 
7408                 If St_Err_Code <> 0 then
7409 			Raise NO_PROCESSING_OF_AWARD ;
7410                 End If;
7411 
7412                              --C_Installment_Id
7413 
7414  END IF ;    -- end if for  %%%%%%%   , bug 5026657
7415 
7416  END LOOP ;  -- dummy loop of re-processing , bug 5026657
7417 
7418  X_Rev_Installment_total.delete ; -- initalize installment_amount table for new installment
7419  X_Rev_Installment_tab.delete; -- initalize install_tab  for new installment
7420 
7421    END LOOP;
7422 
7423 
7424  END;
7425   CLOSE GET_INSTALLMENTS;
7426 
7427 End If; -- End If for Billing Distribution Rule Check
7428 
7429 --999999999999999999999999999999999999999999
7430 
7431 End If; -- End of If for check to see if Award Status is 'ACTIVE' or 'ON_HOLD'
7432 
7433 
7434 End If;  -- End of If for Project_Type_Flag Check to see if it is 'AWARD_PROJECT'
7435 
7436  -- Null Event Deletion ...
7437 /*******
7438 For bug 4957529
7439  If X_BURDEN_NULL_EVENT_PROCESSED  OR
7440     X_REVRAW_NULL_EVENT_PROCESSED  OR
7441     X_INVRAW_NULL_EVENT_PROCESSED  then
7442 
7443     DELETE_NULL_EVENTS (X_project_id,
7444 		        X_request_id,
7445 			X_Calling_Process,
7446 		        St_Err_Code,
7447                         St_Err_Buff);
7448 
7449  End if;
7450 ****/
7451  -- Concurrency Control Code  Starts
7452 
7453  Begin
7454 
7455    Delete
7456    from   gms_concurrency_control
7457    where  process_name = 'GMS_BLNG'
7458    and    process_key  = X_project_id;
7459 
7460  Exception
7461 
7462    When Others then
7463       gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
7464 				'SQLCODE',
7465 			        SQLCODE,
7466 				'SQLERRM',
7467 				SQLERRM,
7468 				X_Exec_Type => 'C',
7469 				X_Err_Code => St_Err_Code,
7470 				X_Err_Buff => St_Err_Buff);
7471 	Raise NO_PROCESSING_OF_AWARD ;
7472 
7473  End;
7474 
7475  -- Concurrency Control Code  Ends
7476 
7477  COMMIT; -- Commit to release locks on award and expenditures
7478 
7479 End if;  -- GMS INSTALLATION CHECK
7480 
7481 IF L_DEBUG = 'Y' THEN
7482 	gms_error_pkg.gms_debug('End Award Billing ','C');
7483 END IF;
7484 
7485 Exception
7486  When NO_PROCESSING_OF_AWARD then
7487 
7488  -- ## This exception is declared at the package level
7489  -- ## This exception is called from many procedures called by AWARD_BILLING
7490  -- ## It is only handled in this program
7491  -- ## When this exception is raised, all data for that award_project_id
7492  -- ## which has been modified or created is rolled back thus ensuring consistency
7493  -- ## Further processing for that award is ignored.
7494     -- Added for Bug 1744641: To Generate errors when an exception occurs
7495     -- during the process of generation of invoice/Revenue.
7496          If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7497          gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7498          GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7499          End If;
7500          gms_error_pkg.gms_exception_lines_proc ( 'GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7501                                                 'PRJ',
7502                                                 x_calling_place,
7503                                                 x_project_id ,
7504                                                 x_award_number ,
7505                                                 x_award_name );
7506 
7507          -- End of the code added for bug 1744641
7508          IF L_DEBUG = 'Y' THEN
7509          	gms_error_pkg.gms_debug('WHEN NO_PROCESSING_OF_AWARD - AWARD_BILLING','C');
7510          END IF;
7511          gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7512                                 'PRJ',
7513                                 X_Project_id,
7514                                 X_Exec_Type => 'C',
7515                                 X_Err_Code => St_Err_Code,
7516                                 X_Err_Buff => St_Err_Buff);
7517 
7518        --  ROLLBACK; -- If record not found , rollback to release lock --For Bug 4243374
7519 	 ROLLBACK to AWARD_BILLING_BEGIN; -- If record not found , rollback to release lock
7520          /* Rollback to Savepoint introduced instead of Rollback for bug 4243374 */
7521          RETURN;
7522 
7523   When AWARD_DATA_LOCKED then
7524 
7525  -- ## This exception is declared at the package level
7526  -- ## This exception happens when Awards form is modifying billing related data
7527  -- ## for the Award being processed.
7528  -- ## When this exception is raised, all data for that award_project_id
7529  -- ## which has been modified or created is rolled back thus ensuring consistency
7530  -- ## Further processing for that award is ignored.
7531          -- Added for Bug 1744641: To Generate errors when an exception occurs
7532          -- during the process of generation of invoice/Revenue.
7533 	 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7534          gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7535          GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7536         End If;
7537          gms_error_pkg.gms_exception_lines_proc( 'GMS_BILL_AWARD_LOCK' ,
7538                                                 'PROJECT_ID',
7539                                                 x_calling_place ,
7540                                                 x_project_id ,
7541                                                 x_award_number ,
7542                                                 x_award_name );
7543          gms_error_pkg.gms_exception_lines_proc( 'GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7544                                                 'PRJ',
7545                                                 x_calling_place,
7546                                                 x_project_id );
7547  	  -- End of the code added for bug 1744641
7548          IF L_DEBUG = 'Y' THEN
7549          	gms_error_pkg.gms_debug('WHEN AWARD_DATA_LOCKED - AWARD_BILLING','C');
7550          END IF;
7551          gms_error_pkg.gms_message('GMS_BILL_AWARD_LOCK',
7552                                 'PROJECT_ID',
7553                                 X_Project_id,
7554                                 X_Exec_Type => 'C',
7555                                 X_Err_Code => St_Err_Code,
7556                                 X_Err_Buff => St_Err_Buff);
7557 
7558          gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7559                                 'PRJ',
7560                                 X_Project_id,
7561                                 X_Exec_Type => 'C',
7562                                 X_Err_Code => St_Err_Code,
7563                                 X_Err_Buff => St_Err_Buff);
7564          ROLLBACK; -- If record not found , rollback to release lock
7565          RETURN;
7566 
7567  When ROLLBACK_FAILURE then
7568 
7569  	 -- Added for Bug 1744641: To Generate errors when an exception occurs
7570          -- during the process of generation of invoice/Revenue.
7571         If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7572          gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7573          GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7574         End If;
7575         gms_error_pkg.gms_exception_lines_proc('GMS_BILLING_ROLLBACK_FAILURE' ,
7576                                                 'PRJ',
7577                                                 x_calling_place,
7578                                                 x_project_id ,
7579                                                 x_award_number ,
7580                                                 x_award_name);
7581          -- End of code added for bug 1744641.
7582          IF L_DEBUG = 'Y' THEN
7583          	gms_error_pkg.gms_debug('WHEN ROLLBACK_FAILURE  - AWARD_BILLING','C');
7584          END IF;
7585          rollback; -- release lock and any changes carried out.
7586          RETURN;
7587 
7588        --RAISE_APPLICATION_ERROR(-20558,St_Err_Buff);
7589 
7590  When NO_EXP_TO_PROCESS then
7591 
7592  -- This exception is raised when there are no transactions to be processed
7593  -- Billing rollback happens before this in which transactions may have been
7594  -- processed, so unlike all other exceptions, in this exception, we do the following:
7595  -- 1. Delete concurrency control record.
7596  -- 2. COMMIT
7597  -- 3. RETURN
7598 
7599    Delete
7600    from   gms_concurrency_control
7601    where  process_name = 'GMS_BLNG'
7602    and    process_key  = X_project_id;
7603 
7604    COMMIT;
7605 
7606    RETURN;
7607 
7608  When INVALID_INVOICE_FORMAT then
7609 
7610  -- ## This exception is declared at the package level
7611  -- ## This exception happens when Awards form has an invoice format (labor or
7612  -- ## non-labor) that has an element not supported by Grants.
7613  -- ## Refer to Grants userguide Chapter 28 for valid formats (columns that can be used)
7614  -- ## When this exception is raised, all data for that award_project_id
7615  -- ## which has been modified or created is rolled back thus ensuring consistency
7616  -- ## Further processing for that award is ignored.
7617  -- Added for Bug 3143102: QI LABOR/NON-LABOR INVOICE FORMATS NOT SUPPORTED BY GMS
7618 
7619 	 If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7620          gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7621          GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7622         End If;
7623          gms_error_pkg.gms_exception_lines_proc('GMS_INVALID_INVOICE_FORMAT' ,
7624                                                 NULL,
7625                                                 x_calling_place ,
7626                                                 x_project_id ,
7627                                                 x_award_number ,
7628                                                 x_award_name );
7629 
7630          IF L_DEBUG = 'Y' THEN
7631          	gms_error_pkg.gms_debug('WHEN INVALID INVOICE FORMAT - AWARD_BILLING','C');
7632          END IF;
7633          gms_error_pkg.gms_message('GMS_INVALID_INVOICE_FORMAT',
7634                                 X_Exec_Type => 'C',
7635                                 X_Err_Code => St_Err_Code,
7636                                 X_Err_Buff => St_Err_Buff);
7637 
7638          ROLLBACK; -- If record not found , rollback to release lock
7639 
7640             Delete
7641             from   gms_concurrency_control
7642             where  process_name = 'GMS_BLNG'
7643             and    process_key  = X_project_id;
7644          COMMIT;
7645 
7646          RETURN;
7647 --Added for bug 4506225
7648 When GMS_TAX_FAILURE then
7649  -- ## This exception is declared at the package level
7650  -- ## This exception is raised when the call to GMS_TAX in procedure award_billing
7651  -- ## returns a non zero value.One possible cause for GMS_TAX to return a non_zero
7652  -- ## value is an inactive award sponsor.
7653  -- ## Added for bug 4243374.
7654          If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7655          gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7656          GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7657          End If;
7658          gms_error_pkg.gms_exception_lines_proc ( 'GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7659                                                 'PRJ',
7660                                                 x_calling_place,
7661                                                 x_project_id ,
7662                                                 x_award_number ,
7663                                                 x_award_name );
7664 
7665          IF L_DEBUG = 'Y' THEN
7666                 gms_error_pkg.gms_debug('WHEN GMS_TAX_FAILURE - AWARD_BILLING','C');
7667          END IF;
7668          gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7669                                 'PRJ',
7670                                 X_Project_id,
7671                                 X_Exec_Type => 'C',
7672                                 X_Err_Code => St_Err_Code,
7673                                 X_Err_Buff => St_Err_Buff);
7674 
7675        Delete
7676         from   gms_concurrency_control
7677         where  process_name = 'GMS_BLNG'
7678         and    process_key  = X_project_id;
7679 
7680         return;
7681 
7682 --End of bug fix 4506225
7683  When Others then
7684  	-- Added for Bug 1744641: To Generate errors when an exception occurs
7685         -- during the process of generation of invoice/Revenue.
7686        If (nvl(GMS_ERROR_PKG.X_Request_Trace_Id,-1)<>X_Request_id) then
7687          gms_error_pkg.gms_exception_head_proc(x_calling_process) ;
7688          GMS_ERROR_PKG.X_Request_Trace_Id:=X_request_id;
7689         End If;
7690         gms_error_pkg.gms_exception_lines_proc('GMS_UNEXPECTED_ERROR',
7691                                                'PRJ',
7692                                                x_calling_place,
7693                                                x_project_id ,
7694                                                x_award_number ,
7695                                                x_award_name,
7696                                                SQLCODE,
7697                                                SQLERRM  );
7698 	gms_error_pkg.gms_exception_lines_proc('GMS_UNEXPECTED_ERR_NO_PROCESS' ,
7699                                                'PRJ',
7700                                                x_calling_place ,
7701                                                x_project_id
7702                                                );
7703       --End of Code added for bug 1744641
7704       IF L_DEBUG = 'Y' THEN
7705       	gms_error_pkg.gms_debug('WHEN OTHERS - AWARD_BILLING','C');
7706       END IF;
7707       gms_error_pkg.gms_message('GMS_UNEXPECTED_ERROR',
7708                                 'SQLCODE',
7709                                 SQLCODE,
7710                                 'SQLERRM',
7711                                 SQLERRM,
7712                                 X_Exec_Type => 'C',
7713                                 X_Err_Code => St_Err_Code,
7714                                 X_Err_Buff => St_Err_Buff);
7715 
7716       gms_error_pkg.gms_message('GMS_UNEXPECTED_ERR_NO_PROCESS',
7717                                 'PRJ',
7718                                 X_Project_id,
7719                                 X_Exec_Type => 'C',
7720                                 X_Err_Code => St_Err_Code,
7721                                 X_Err_Buff => St_Err_Buff);
7722 
7723 
7724          rollback; -- release lock and any changes carried out.
7725          RETURN;
7726 
7727       --RAISE_APPLICATION_ERROR(-20557,St_Err_Buff);
7728 
7729 End AWARD_BILLING;
7730 
7731 END GMS_BILLING;