DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_PURGE_VALIDATE_ICIP

Source


1 package body pa_purge_validate_icip as
2 /* $Header: PAICIPVB.pls 120.2 2005/08/19 16:34:27 mwasowic noship $ */
3 
4  Function Is_InterPrj_Provider_Project ( p_project_id      in NUMBER )
5  Return VARCHAR2  is
6 
7       cursor ISInterPrjRPrvdrPrj is
8       select 'This is an Inter-Project Provider Project'
9         from dual
10        where exists ( select NULL
11                         from pa_project_customers ppc
12                        where ppc.project_id = p_project_id
13                          and ppc.bill_another_project_flag = 'Y'
14                          and ppc.receiver_task_id is not null
15                     );
16 
17    l_dummy VARCHAR2(100);
18 
19  Begin
20 
21      Open ISInterPrjRPrvdrPrj;
22      Fetch ISInterPrjRPrvdrPrj into l_dummy;
23 
24      IF ISInterPrjRPrvdrPrj%NOTFOUND then
25         Close ISInterPrjRPrvdrPrj;
26          RETURN 'N';
27      END IF;
28 
29      If l_dummy is not null then
30         Close ISInterPrjRPrvdrPrj;
31          RETURN 'Y';
32      End If;
33 
34  EXCEPTION
35   WHEN OTHERS THEN
36        RETURN 'N';
37 
38  END Is_InterPrj_Provider_Project;
39 
40 
41  Function Is_InterPrj_Receiver_Project ( p_project_id    in NUMBER )
42  Return VARCHAR2  is
43 
44       cursor ISInterPrjRecvPrj IS
45       select 'This is an Inter-Project Receiver Project'
46         from dual
47        where exists ( select NULL
48                         from pa_tasks pt
49                        where pt.project_id = p_project_id
50                          and pt.receive_project_invoice_flag = 'Y'
51                          and exists ( select NULL
52                                       from   pa_project_customers ppc
53                                       where  ppc.receiver_task_id = pt.task_id )
54                     );
55 
56    l_dummy VARCHAR2(100);
57 
58  Begin
59 
60      Open ISInterPrjRecvPrj;
61      Fetch ISInterPrjRecvPrj into l_dummy;
62 
63      IF ISInterPrjRecvPrj%NOTFOUND then
64         Close ISInterPrjRecvPrj;
65          RETURN 'N';
66      END IF;
67 
68      If l_dummy is not null then
69         Close ISInterPrjRecvPrj;
70          RETURN 'Y';
71      End If;
72 
73  EXCEPTION
74   WHEN OTHERS THEN
75        RETURN 'N';
76 
77  END Is_InterPrj_Receiver_Project;
78 
79 
80 -- Start of comments
81 -- API name         : validate_IC
82 -- Type             : Public
83 -- Pre-reqs         : None
84 -- Function         : This procedure is for the Intercompany Billing validations.
85 --
86 -- Parameters       : p_project_Id			IN     NUMBER,
87 --                              The project id for which records have
88 --                              to be purged/archived.
89 --		      p_txn_to_date			IN     DATE,
90 --                              If the purging is being done on projects
91 --                              that are active then this parameter is
92 --                              determine the date to which the transactions
93 --                              need to be purged.
94 --		      p_active_flag			IN    VARCHAR2,
95 --                              The flag to specify purging is done on
96 --                              open or closed projects.
97 --		      X_Err_Stack			IN OUT VARCHAR2,
98 --                              Error stack
99 --		      X_Err_Stage		        IN OUT VARCHAR2,
100 --                              Stage in the procedure where error occurred
101 --		      X_Err_Code		        IN OUT NUMBER
102 --                              Error code returned from the procedure
103 -- End of comments
104 
105  procedure Validate_IC (
106 			p_project_id                     in NUMBER,
107                         p_txn_to_date                    in DATE,
108                         p_active_flag                    in VARCHAR2,
109                         x_err_code                       in OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
110                         x_err_stack                      in OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
111                         x_err_stage                      in OUT NOCOPY VARCHAR2 )  --File.Sql.39 bug 4440895
112  is
113 
114 /*** In part III of archive purge, projects with intercompany transactions are to be
115      purged. Hence check for the existence of any EIs with cross charge code 'I' and
116      draft invoices are not yet generated. ***/
117 
118   cursor  IsIntercompany_InvGen is
119       select 'INTERCOMPANY INV NOT GENERATED'
120         from dual
121       where exists (
122                select ei.expenditure_item_id
123                from pa_expenditure_items_all ei,
124                     pa_tasks t
125                where ei.task_id = t.task_id
126                  and t.project_id = p_project_id
127                  and ei.cc_cross_charge_code = 'I'
128                  and ( p_active_flag <> 'A'
129                     or ei.expenditure_item_date < p_txn_to_date  )
130         /*
131                  and not exists ( select null
132                                 from pa_draft_invoice_details_all di
133                                where di.cc_project_id = p_project_id
134                                  and di.expenditure_item_id = ei.expenditure_item_id
135                              )
136          */
137 		 and ei.cc_ic_processed_code <> 'Y'  /* Bug#2423804 changed the '=' to '<>'  */
138                    );
139 
140 /*  To purge any project that has Cross charged transactions we need to ensure that transactions
141     are fully processed.
142 
143     Cross Charged transactions are fully processed, which necessarily means
144 
145     1. All the check required for regular transactions are met (Such as Costs / revenues accepted
146        in General Ledger , Invoices to Receivables etc), which are already in place.
147     2. Expenditure Item is Borrowed and Lent Distributed (If applicable) and interfaced to and
148        accepted in General Ledger.
149     3. Expenditure Item is Intercompany Invoiced (If Applicable) and this Inter Company Invoice is
150        Interfaced to Accounts Receivables and Tied back to Projects. Also such interfaced invoices
151        are transferred successfully to Payables.
152 */
153 
154 /* Bug#2423804 Joined the project_id of pa_draft_invoices_all and pa_draft_invoice_details_all
155    instead of cc_project_id as the cc_project_id in pa_draft_invoices_all is populated as 0.
156    Also, the comparision of di.cc_project_id = p_project_id is changed as
157    did.cc_project_id = p_project_id.
158    These change is done in the cursors IsIcInv_Transferred_to_AR and IsIcInv_Accepted_in_AP  */
159 
160   cursor  IsIcInv_Transferred_to_AR is
161     select 'IC INV NOT TIEDBACK SUCCESSFULLY'
162       from dual
163      where exists (
164              select null
165                from pa_expenditure_items_all ei,
166                     pa_tasks t
167               where ei.task_id = t.task_id
168                 and t.project_id = p_project_id
169                 and ei.cc_cross_charge_code = 'I'
170                 and ei.cc_ic_processed_code = 'Y'
171                 and ei.cc_rejection_code is NULL
172                 and ( p_active_flag <> 'A'
173                     or ei.expenditure_item_date < p_txn_to_date  )
174                 and exists ( select null
175                                    from pa_draft_invoices_all di,
176                                         pa_draft_invoice_details_all did
177                                   where did.cc_project_id = p_project_id
178                                     and did.project_id = di.project_id
179 				    and di.draft_invoice_num = did.draft_invoice_num
180                                     and did.expenditure_item_id = ei.expenditure_item_id
181                                     and di.transfer_status_code <> 'A'
182                                )
183                    );
184 
185   cursor  IsIcInv_Accepted_in_AP is
186     select 'IC INV NOT ACCEPTED IN AP'
187      from dual
188      where exists (
189              select null
190                from pa_expenditure_items_all ei,
191                     pa_tasks t
192               where ei.task_id = t.task_id
193                 and t.project_id = p_project_id
194                 and ei.cc_cross_charge_code = 'I'
195                 and ei.cc_ic_processed_code = 'Y'
196                 and ei.cc_rejection_code is NULL
197                 and ( p_active_flag <> 'A'
198                     or ei.expenditure_item_date < p_txn_to_date  )
199                 and exists ( select null
200                                    from pa_draft_invoices_all di,
201                                         pa_draft_invoice_details_all did
202                                   where did.cc_project_id = p_project_id
203                                     and did.project_id = di.project_id
204                                     and did.expenditure_item_id = ei.expenditure_item_id
205 				    and di.draft_invoice_num = did.draft_invoice_num
206                                     and di.transfer_status_code = 'A'
207                                     and not exists ( select null
208                                                        from ap_invoices_all ap
209                                                       where ap.invoice_num = di.ra_invoice_number
210                                                     )
211                                )
212                    );
213 
214 
215       l_err_code         NUMBER ;
216       l_err_stack_old    VARCHAR2(2000);
217       l_err_stack        VARCHAR2(2000);
218       l_err_stage        VARCHAR2(500);
219       l_dummy            VARCHAR2(500);
220 
221       l_old_err_stage     VARCHAR2(500);
222       l_old_err_code      number;
223 
224  BEGIN
225      l_err_code  := 0 ;
226      l_err_stack_old := x_err_stack;
227 
228 
229      /* ATG changes */
230       l_old_err_stage   := x_err_stage ;
231       l_old_err_code    := x_err_code ;
232 
233      pa_debug.debug(' -- Performing Inter Company validation for project '||to_char(p_project_id));
234 
235     -- Check whether the intercompany invoice is generated or not
236 
237     Open IsIntercompany_InvGen;
238     Fetch IsIntercompany_InvGen into l_dummy;
239     If l_dummy is not null then
240        fnd_message.set_name('PA','PA_ARPR_IC_INV_NOT_GEN');
241        fnd_msg_pub.add;
242        l_err_code  := 10;
243        l_err_stage := 'After intercompany check ';
244        l_err_stack := l_err_stack|| ' -> After intercompany check';
245        pa_debug.debug('    * Intercompany Invoice is not Generated for the project '||
246                       to_char(p_project_id));
247     End If;
248     Close IsIntercompany_InvGen;
249     l_dummy := NULL;
250 
251     -- Check whether the intercompany invoice is successfully tied-back from AR
252 
253     Open IsIcInv_Transferred_to_AR;
254     Fetch IsIcInv_Transferred_to_AR into l_dummy;
255     If l_dummy is not null then
256        fnd_message.set_name('PA','PA_ARPR_IC_INV_NOT_TIEDBACK');
257        fnd_msg_pub.add;
258        l_err_code  := 10;
259        l_err_stage := 'After intercompany check ';
260        l_err_stack := l_err_stack|| ' -> After intercompany check';
261        pa_debug.debug('    * Intercompany Invoice is not Tiedback from AR for the project '||
262                       to_char(p_project_id));
263     End If;
264     Close IsIcInv_Transferred_to_AR;
265     l_dummy := NULL;
266 
267     -- Check whether the intercompany invoice is successfully accepted in AP
268 
269     Open IsIcInv_Accepted_in_AP;
270     Fetch IsIcInv_Accepted_in_AP into l_dummy;
271     If l_dummy is not null then
272        fnd_message.set_name('PA','PA_ARPR_IC_INV_NOT_IN_AP');
273        fnd_msg_pub.add;
274        l_err_code  := 10;
275        l_err_stage := 'After intercompany check ';
276        l_err_stack := l_err_stack|| ' -> After intercompany check';
277        pa_debug.debug('    * Intercompany Invoice is not Successfully Accepted in AP for the project '||
278                       to_char(p_project_id));
279     End If;
280     Close IsIcInv_Accepted_in_AP;
281     l_dummy := NULL;
282 
283 
284      x_err_code  := l_err_code ;
285      x_err_stage := l_err_stage ;
286      x_err_stack := l_err_stack_old ;
287 
288  EXCEPTION
289   WHEN PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error then
290        RAISE PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error ;
291 
292   WHEN OTHERS THEN
293     x_err_stage := l_err_stage ;
294     pa_debug.debug('Error Procedure Name  := PA_PURGE_VALIDATE_ICIP.VALIDATE_IC' );
295     pa_debug.debug('Error stage is '||l_err_stage );
296     pa_debug.debug('Error stack is '||l_err_stack );
297     pa_debug.debug(SQLERRM);
298 
299     /* ATG Changes */
300       x_err_stack := l_err_stack_old ;
301       x_err_stage   := l_old_err_stage ;
302       x_err_code    := l_old_err_code ;
303 
304     PA_PROJECT_UTILS2.g_sqlerrm := SQLERRM ;
305 
306     RAISE PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error ;
307 
308  END Validate_IC ;
309 
310 
311 -- Start of comments
312 -- API name         : validate_IP_Prvdr
313 -- Type             : Public
314 -- Pre-reqs         : None
315 -- Function         : This procedure is for the Interproject Billing validations.
316 --
317 -- Parameters       : p_project_Id                      IN     NUMBER,
318 --                              The project id for which records have
319 --                              to be purged/archived.
320 --                    p_txn_to_date                     IN     DATE,
321 --                              If the purging is being done on projects
322 --                              that are active then this parameter is
323 --                              determine the date to which the transactions
324 --                              need to be purged.
325 --                    p_active_flag                     IN    VARCHAR2,
326 --                              The flag to specify purging is done on
327 --                              open or closed projects.
328 --                    X_Err_Stack                       IN OUT VARCHAR2,
329 --                              Error stack
330 --                    X_Err_Stage                       IN OUT VARCHAR2,
331 --                              Stage in the procedure where error occurred
332 --                    X_Err_Code                        IN OUT NUMBER
333 --                              Error code returned from the procedure
334 -- End of comments
335 
336  PROCEDURE Validate_IP_Prvdr (
337                         p_project_id                     in NUMBER,
338                         p_txn_to_date                    in DATE,
339                         p_active_flag                    in VARCHAR2,
340                         x_err_code                       in OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
341                         x_err_stack                      in OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
342                         x_err_stage                      in OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
343  IS
344 
345 
346  /*  A provider project is a 'CONTRACT' project that performs work on behalf of another
347      (receiver) project so, no txn_to_date checking */
348 
349  /*  To Purge any Provider Project which has Inter-Project billing set-up attached (Bill to
350      Another Project set to Yes and receiver Task is identified), we need to ensure that the
351      transaction is fully processed.
352 
353      Expenditure Item is fully processed, which necessarily means
354 
355      1. All the check required for regular transactions are met (Such as Costs / revenues accepted
356         in GL, Invoices to receivables etc), which are already in place.
357      2. For Provider Project, Draft Invoice of provider project is interfaced to Receivables and
358         transferred to Payables as a supplier invoice cost for Receiver Project.
359 
360      Once both the above mentioned steps are performed, core Archive/Purge functionality in
361      place will take care of rest of the validations, as this Supplier Invoice will be visible as
362      a commitment for the receiver project.
363  */
364 
365     cursor IsIpInv_Transferred_to_AR is
366     select 'IP INV NOT TIEDBACK SUCCESSFULLY'
367       from dual
368      where exists (
369              select null
370                from pa_draft_invoices_all di,
371                     pa_project_customers ppc,
372                     pa_agreements_all pag
373               where di.project_id = p_project_id
374 		and di.agreement_id = pag.agreement_id
375 		and pag.customer_id = ppc.customer_id
376 	        and di.project_id = ppc.project_id
377 		and ppc.bill_another_project_flag = 'Y'
378 		and ppc.receiver_task_id IS NOT NULL
379                 and di.transfer_status_code <> 'A'
380                    );
381 
382     cursor IsIpInv_Accepted_in_AP is
383     select 'IP INV NOT ACCEPTED IN AP'
384       from dual
385      where exists (
386              select null
387                from pa_draft_invoices_all di,
388                     pa_project_customers ppc,
389 		    pa_agreements_all pag
390               where di.project_id = p_project_id
391 	        and di.project_id = ppc.project_id
392 	        and di.agreement_id = pag.agreement_id
393 		and pag.customer_id = ppc.customer_id
394 		and ppc.bill_another_project_flag = 'Y'
395 		and ppc.receiver_task_id IS NOT NULL
396                 and di.transfer_status_code ='A'
397 		and not exists ( select null
398 		                   from ap_invoices_all ap
399 				  where ap.invoice_num = di.ra_invoice_number
400 			       )
401                    );
402 
403 
404       l_err_code         NUMBER ;
405       l_err_stack_old    VARCHAR2(2000);
406       l_err_stack        VARCHAR2(2000);
407       l_err_stage        VARCHAR2(500);
408       l_dummy            VARCHAR2(500);
409 
410   l_old_err_stage     VARCHAR2(500);
411   l_old_err_code      number;
412 
413 
414  BEGIN
415 
416      l_err_code  := 0 ;
417      l_err_stack_old := x_err_stack;
418 
419 
420     /* ATG changes */
421       l_old_err_stage   := x_err_stage ;
422       l_old_err_code    := x_err_code ;
423 
424 
425      pa_debug.debug(' -- Performing Inter Project validation for provider project '||
426                         to_char(p_project_id));
427 
428       -- Check whether the interproject invoice is successfully tied-back from AR
429 
430      Open IsIpInv_Transferred_to_AR;
431      Fetch IsIpInv_Transferred_to_AR into l_dummy;
432 
433      If l_dummy is not null then
434         fnd_message.set_name('PA','PA_ARPR_IP_INV_NOT_TIEBACK');
435         fnd_msg_pub.add;
436         l_err_code  := 10;
437         l_err_stage := 'After interproject check ';
438         l_err_stack := l_err_stack|| ' -> After interproject check';
439         pa_debug.debug(' * Interproject Invoice is not Tiedback from AR for the project '||
440         		   to_char(p_project_id));
441      End If;
442 
443      Close IsIpInv_Transferred_to_AR;
444      l_dummy := NULL;
445 
446 
447       -- Check whether the interproject invoice is successfully accepted in AP
448 
449      Open IsIpInv_Accepted_in_AP;
450      Fetch IsIpInv_Accepted_in_AP into l_dummy;
451 
452      If l_dummy is not null then
453         fnd_message.set_name('PA','PA_ARPR_IP_INV_NOT_IN_AP');
454         fnd_msg_pub.add;
455         l_err_code  := 10;
456         l_err_stage := 'After interproject check ';
457         l_err_stack := l_err_stack|| ' -> After interproject check';
458         pa_debug.debug(' * Interproject Invoice is not Successfully Accepted in AP for the project '||
459 			  to_char(p_project_id));
460      End If;
461 
462      Close IsIpInv_Accepted_in_AP;
463      l_dummy := NULL;
464 
465      x_err_code  := l_err_code ;
466      x_err_stage := l_err_stage ;
467      x_err_stack := l_err_stack_old ;
468 
469  EXCEPTION
470   WHEN PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error then
471        RAISE PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error ;
472 
473   WHEN OTHERS THEN
474     x_err_stage := l_err_stage ;
475     pa_debug.debug('Error Procedure Name  := PA_PURGE_VALIDATE_ICIP.VALIDATE_IP_PRVDR' );
476     pa_debug.debug('Error stage is '||l_err_stage );
477     pa_debug.debug('Error stack is '||l_err_stack );
478     pa_debug.debug(SQLERRM);
479 
480     /* ATG Changes */
481       x_err_stack := l_err_stack_old ;
482       x_err_stage   := l_old_err_stage ;
483       x_err_code    := l_old_err_code ;
484 
485 
486 
487 
488     PA_PROJECT_UTILS2.g_sqlerrm := SQLERRM ;
489 
490     RAISE PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error ;
491 
492  END Validate_IP_Prvdr ;
493 
494 
495 -- Start of comments
496 -- API name         : validate_IP_Rcvr
497 -- Type             : Public
498 -- Pre-reqs         : None
499 -- Function         : This procedure is for the Interproject Billing validations.
500 --
501 -- Parameters       : p_project_Id                      IN     NUMBER,
502 --                              The project id for which records have
503 --                              to be purged/archived.
504 --                    p_txn_to_date                     IN     DATE,
505 --                              If the purging is being done on projects
506 --                              that are active then this parameter is
507 --                              determine the date to which the transactions
508 --                              need to be purged.
509 --                    p_active_flag                     IN    VARCHAR2,
510 --                              The flag to specify purging is done on
511 --                              open or closed projects.
512 --                    X_Err_Stack                       IN OUT VARCHAR2,
513 --                              Error stack
514 --                    X_Err_Stage                       IN OUT VARCHAR2,
515 --                              Stage in the procedure where error occurred
516 --                    X_Err_Code                        IN OUT NUMBER
517 --                              Error code returned from the procedure
518 -- End of comments
519 
520  PROCEDURE Validate_IP_Rcvr (
521                         p_project_id                     in NUMBER,
522                         x_err_code                       in OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
523                         x_err_stack                      in OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
524                         x_err_stage                      in OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
525  IS
526 
527 
528  /* To purge Receiver Project (in the case of interProject Billing Set-up), all associated
529     Provider Projects must be Purged (rest all other validation checks remains the same). */
530 
531  /*  cursor to get all the provider projects associated with the given receiver project */
532 
533       cursor c_provider_projects is
534       select ppc.project_id
535         from pa_project_customers ppc
536        where ppc.bill_another_project_flag = 'Y'
537          and ppc.receiver_task_id is not null
538 	 and ppc.customer_bill_split <> 0     /* Bug#2429956  */
539          and ppc.receiver_task_id in ( select task_id
540                                          from pa_tasks pt
541                                         where pt.project_id = p_project_id);
542 
543       l_err_code         NUMBER ;
544       l_err_stack_old    VARCHAR2(2000);
545       l_err_stack        VARCHAR2(2000);
546       l_err_stage        VARCHAR2(500);
547 
548       l_project_status_code  pa_projects_all.project_status_code%TYPE;
549 
550   l_old_err_stage     VARCHAR2(500);
551   l_old_err_code      number;
552 
553 
554 
555  BEGIN
556 
557      l_err_code  := 0 ;
558      l_err_stack_old := x_err_stack;
559 
560      /* ATG changes */
561       l_old_err_stage   := x_err_stage ;
562       l_old_err_code    := x_err_code ;
563 
564 
565      FOR c_prvdr_prj_rec in c_provider_projects LOOP
566 
567          select project_status_code
568            into l_project_status_code
569            from pa_projects_all
570           where project_id = c_prvdr_prj_rec.project_id;
571 
572       if pa_project_stus_utils.is_project_in_purge_status( l_project_status_code ) <> 'Y' then
573 
574        /* A provider to the given receiver project can again be a receiver project. So, checking
575           for existance of any provider projects if it is a receiver project by calling the
576           procedure Validate_IP_Rcvr recursively  */
577 
578        if Is_InterPrj_Receiver_Project(c_prvdr_prj_rec.project_id) = 'Y' then
579 
580           Validate_IP_Rcvr(c_prvdr_prj_rec.project_id,
581                            x_err_code,
582                            x_err_stack,
583                            x_err_stage );
584 
585          if pa_project_stus_utils.is_project_in_purge_status( l_project_status_code ) <> 'Y'
586          then
587 
588           if g_insert_errors_no_duplicate = 'N' then  /* Bug#2431705  */
589 
590             fnd_message.set_name('PA','PA_ARPR_PRVDR_NOT_PURGED');
591             fnd_msg_pub.add;
592             l_err_code  := 10;
593             l_err_stage := 'After interproject receiver check ';
594             l_err_stack := l_err_stack|| ' -> After interproject receiver check';
595             pa_debug.debug(' * Provider project is not purged corresponding to the receiver project '||
596                             to_char(p_project_id));
597 
598           end if;
599 
600 	  g_insert_errors_no_duplicate := 'Y';  /* Bug# 2431705  */
601 
602          EXIT;
603 
604          end if;
605 
606        else
607 
608          if pa_project_stus_utils.is_project_in_purge_status( l_project_status_code ) <> 'Y'
609          then
610 
611           if g_insert_errors_no_duplicate = 'N' then   /* Bug# 2431705 */
612 
613 	     fnd_message.set_name('PA','PA_ARPR_PRVDR_NOT_PURGED');
614              fnd_msg_pub.add;
615 	     l_err_code  := 10;
616 	     l_err_stage := 'After interproject receiver check ';
617   	     l_err_stack := l_err_stack|| ' -> After interproject receiver check';
618              pa_debug.debug(' * Provider project is not purged corresponding to the receiver project '||
619 	  		    to_char(p_project_id));
620 
621   	  end if;
622 
623 	  g_insert_errors_no_duplicate := 'Y';  /* Bug# 2431705  */
624 
625          EXIT;
626 
627 	 end if;
628 
629        end if;
630 
631       end if;
632 
633      END LOOP;
634 
635      x_err_code  := l_err_code ;
636      x_err_stage := l_err_stage ;
637      x_err_stack := l_err_stack_old ;
638 
639  EXCEPTION
640   WHEN PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error then
641        RAISE PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error ;
642 
643   WHEN OTHERS THEN
644     x_err_stage := l_err_stage ;
645     pa_debug.debug('Error Procedure Name  := PA_PURGE_VALIDATE_ICIP.VALIDATE_IP_Rcvr' );
646     pa_debug.debug('Error stage is '||l_err_stage );
647     pa_debug.debug('Error stack is '||l_err_stack );
648     pa_debug.debug(SQLERRM);
649     PA_PROJECT_UTILS2.g_sqlerrm := SQLERRM ;
650 
651     /* ATG Changes */
652       x_err_stack := l_err_stack_old ;
653       x_err_stage   := l_old_err_stage ;
654       x_err_code    := l_old_err_code ;
655 
656 
657     RAISE PA_PROJECT_UTILS2.PA_Arch_Pur_Subroutine_Error ;
658 
659  END Validate_IP_Rcvr ;
660 
661 
662 
663 -- API name         : Validate_IC_IP
664 -- Type             : Public
665 -- Pre-reqs         : None
666 -- Function         : This is the main procedure for the Intercompany and Interproject
667 --                    (only for Provider Project) Billing  validations.
668 
669 
670  PROCEDURE Validate_IC_IP (
671                            p_project_id                     in NUMBER,
672                            p_txn_to_date                    in DATE,
673                            p_active_flag                    in VARCHAR2,
674                            x_err_code                       in OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
675                            x_err_stack                      in OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
676                            x_err_stage                      in OUT NOCOPY VARCHAR2 ) --File.Sql.39 bug 4440895
677  IS
678 
679  BEGIN
680 
681       /* Validate Intercompany receiver projects  */
682 
683                Validate_IC (
684                         p_project_id,
685                         p_txn_to_date,
686                         p_active_flag,
687                         x_err_code,
688                         x_err_stack,
689                         x_err_stage );
690 
691      /* Validate interproject provider projects  */
692 
693    if Is_InterPrj_Provider_Project(p_project_id) = 'Y' then
694 
695                Validate_IP_Prvdr (
696                         p_project_id,
697                         p_txn_to_date,
698                         p_active_flag,
699                         x_err_code,
700                         x_err_stack,
701                         x_err_stage );
702 
703    end if;
704 
705   /* If any of the Project which is a Receiver Project (InterProject Setup) is pulled in purge batch,
706      we will NOT pull associated provider projects programmatically. But the code will Invalidate the
707      batch prompting user to pull all associated un-purged provider projects in the same batch or to
708      remove receiver project from the batch to make the batch valid for purge.
709      To implement the above logic with the receiver project and provider projects are in the same
710      purge batch, the Interproject receiver project validation is called after all the regular
711      checks are completed in pa_purge_validate.BatchVal.
712      Individually receiver and provider projects can be valid for regular checks but after the
713      receiver project validation, the receiver project can be invalid incase,
714       1. if any of its provider projects which is not in purge status and is not included in the
715          purge batch  or
716       2. included in the purge batch but is invalid for regular checks
717   */
718 
719 
720  END Validate_IC_IP;
721 
722 END ;