DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_AP_INTEGRATION

Source


1 PACKAGE BODY pa_ap_integration AS
2 --$Header: PAAPINTB.pls 120.18.12020000.6 2013/03/28 06:01:04 arbandyo ship $
3 g_po_match_date DATE := NULL;
4 
5 PROCEDURE UPD_PA_DETAILS_SUPPLIER_MERGE
6                            ( p_old_vendor_id   IN po_vendors.vendor_id%type,
7                              p_new_vendor_id   IN po_vendors.vendor_id%type,
8                              p_paid_inv_flag   IN ap_invoices_all.PAYMENT_STATUS_FLAG%type,
9                              p_invoice_id      IN ap_invoices_all.invoice_id%TYPE DEFAULT NULL,  /* Bug# 8845025 */
10                              x_stage          OUT NOCOPY VARCHAR2,
11                              x_status         OUT NOCOPY VARCHAR2)
12 
13 IS
14  /* bug 8845025 start */
15   TYPE eiid_tbl IS TABLE OF PA_EXPENDITURE_ITEMS_ALL.expenditure_item_id%TYPE INDEX BY BINARY_INTEGER;
16   TYPE lnum_tbl IS TABLE OF PA_COST_DISTRIBUTION_LINES_ALL.line_num%TYPE INDEX BY BINARY_INTEGER;
17 
18   eiid_rec eiid_tbl;
19   lnum_rec lnum_tbl;
20 
21   type expid_tbl IS TABLE OF PA_EXPENDITURES_ALL.expenditure_id%TYPE INDEX BY BINARY_INTEGER;
22   expid_rec expid_tbl;
23   /* bug 8845025 end */
24 Begin
25 x_stage := 'Updating Pa_implementations Table';
26 Update pa_implementations_all set  Vendor_Id = p_new_vendor_id
27 Where  Vendor_Id = p_old_vendor_id;
28 
29 x_stage := 'Updating Pa_Expenditures_All Table';
30    /* Added for bug# 8845025 */
31    UPDATE pa_expenditures_all e
32    SET   e.vendor_id = p_new_vendor_id
33          -- Bug#10254549 added the last updated columns
34          ,last_update_date = sysdate
35          ,last_updated_by = fnd_global.user_id
36          ,last_update_login =fnd_global.login_id
37    WHERE e.vendor_id = p_old_vendor_id  and
38          orig_exp_txn_reference1 = nvl(p_invoice_id, orig_exp_txn_reference1) and -- Added nvl for the Bug 14387738
39          exists (
40           select 1 from ap_invoices_all i
41           where invoice_id = nvl(p_invoice_id, invoice_id) -- added nvl for the Bug 14387738
42           and to_char(invoice_id) = orig_exp_txn_reference1
43           and vendor_id = p_new_vendor_id
44           and payment_status_flag = DECODE (NVL (p_paid_inv_flag, 'Y'), 'N', 'N',  i.payment_status_flag)
45                  )
46       returning expenditure_id BULK COLLECT INTO expid_rec;
47 
48 /*Code change for 	7125912 */
49 /* commenting for bug 8845025
50 UPDATE pa_expenditures_all e
51    SET e.vendor_id = p_new_vendor_id
52        -- Bug#10254549 added the last updated columns
53        ,last_update_date = sysdate
54        ,last_updated_by = fnd_global.user_id
55        ,last_update_login =fnd_global.login_id
56  WHERE e.vendor_id = p_old_vendor_id
57    AND e.expenditure_id in (
58           SELECT ---- /*+ LEADING(ei)
59              ei.expenditure_id
60             FROM pa_cost_distribution_lines_all c,
61                  pa_expenditure_items_all ei,
62                  ap_invoices_all i
63            WHERE TO_CHAR (i.invoice_id) = c.system_reference2
64              AND c.expenditure_item_id = ei.expenditure_item_id
65             -- AND ei.expenditure_id = e.expenditure_id
66              AND c.system_reference1 = TO_CHAR(p_old_vendor_id)
67              AND i.vendor_id = p_new_vendor_id
68              AND i.payment_status_flag = DECODE (NVL (p_paid_inv_flag, 'Y'), 'N', 'N', i.payment_status_flag)
69                 )  ;  */
70 /*Code change for 	7125912  END */
71 x_stage := 'Updating Pa_Expenditure_Items_All Table';
72 
73 /*Changed for Bug:5864959*/
74 /* Bug 13013074 Added no_unnest hint */
75 Update pa_expenditure_items_all ei
76 set vendor_id =  p_new_vendor_id
77 ,last_update_date = sysdate     --bug 14012059
78 ,last_updated_by = fnd_global.user_id -- bug 14012059
79 Where  Vendor_Id = p_old_vendor_id
80   and exists
81        (select /*+ no_unnest */ 1
82         from  pa_cost_distribution_lines_all c,
83               ap_invoices_all i
84         where i.invoice_id = to_number(c.system_reference2)
85         and   c.expenditure_item_id = ei.expenditure_item_id
86         and   c.system_reference1 = p_old_vendor_id
87         and   i.vendor_id = p_new_vendor_id
88         and   i.PAYMENT_STATUS_FLAG =
89 decode(nvl(p_paid_inv_flag,'Y'),'N','N',i.PAYMENT_STATUS_FLAG)
90         );
91 
92 x_stage := 'Updating Pa_Cost_Distribution_Lines_All Table';
93 /* Added for bug# 8845025 */
94 
95   FORALL I IN 1 .. expid_rec.count
96    UPDATE  PA_COST_DISTRIBUTION_LINES_ALL
97    SET     System_reference1 = to_char(p_new_vendor_id)
98            -- Bug#10254549 added the program update columns
99            ,program_id = FND_GLOBAL.CONC_PROGRAM_ID()
100            ,program_update_date = sysdate
101    WHERE   expenditure_item_id IN (
102              SELECT expenditure_item_id
103              FROM PA_EXPENDITURE_ITEMS_ALL ei
104              WHERE ei.expenditure_id = expid_rec(i)
105              );
106 
107 /* Commented for bug# 88845025
108 If nvl(p_paid_inv_flag,'Y') = 'N' Then
109 
110 --Code change for 	7125912
111  Declare Cursor c1 is
112       Select c.rowid row_id, c.expenditure_item_id, c.line_num
113       from pa_cost_distribution_lines_all c, ap_invoices_all i
114       where to_char(i.invoice_id) = c.system_reference2
115       --and i.vendor_id = to_number(c.system_reference1) --Vendor_ID on Invoice is already  changed...so this is not needed
116       and c.system_reference1 = to_char(p_old_vendor_id)
117       and i.vendor_id = p_new_vendor_id
118       and i.PAYMENT_STATUS_FLAG = 'N';
119 
120 --Code change for 	7125912 END
121   Begin
122 
123   x_stage := 'Updating Pa_Cost_Distribution_Lines_All Table For UNPAID Invoices';
124 
125   For Rec in C1 Loop
126 
127 	Update pa_cost_distribution_lines_all
128 	Set    System_reference1 = (p_new_vendor_id)
129                -- Bug#10254549 added the program update columns
130                ,program_id = FND_GLOBAL.CONC_PROGRAM_ID()
131                ,program_update_date = sysdate
132 	Where  rowid = rec.row_id;
133 
134   End Loop;
135   End;
136 
137 Else  -- p_paid_inv_flag <> 'N'
138 
139   x_stage := 'Updating Pa_Cost_Distribution_Lines_All Table For ALL Invoices';
140 
141   Update Pa_Cost_Distribution_Lines_All cdl
142   Set    System_Reference1 = to_char(p_new_vendor_id)
143           -- Bug#10254549 added the program update columns
144          ,program_id = FND_GLOBAL.CONC_PROGRAM_ID()
145          ,program_update_date = sysdate
146   Where  System_Reference1 = to_char(p_old_vendor_id)
147   And    system_reference1 is not null
148   And    system_reference2 is not null
149   And    system_reference3 is not null
150   and exists (select 1  -- added this for bug8562065
151                    from ap_invoices_all inv
152                   where to_char(inv.invoice_id) = cdl.system_reference2
153                     and inv.vendor_id = p_new_vendor_id
154               );
155 
156 
157 End If;  for bug 8845025*/
158 
159 --R12 need to update vendor ID on pa_bc_packets
160 x_stage := 'Updating Pa_Bc_Packets Table';
161 Update pa_bc_packets
162 set  Vendor_Id = p_new_vendor_id
163 Where  Vendor_Id = p_old_vendor_id
164 And  Status_Code = 'A';
165 
166 --R12 need to update vendor ID on pa_bc_commitments
167 x_stage := 'Updating Pa_Bc_Commitments_All Table';
168 Update pa_bc_commitments_all
169 set  Vendor_Id = p_new_vendor_id
170 Where  Vendor_Id = p_old_vendor_id;
171 
172   x_stage := 'Updating Pa_Project_Asset_Lines_All Table For ALL Invoices';
173 
174 update pa_project_asset_lines_all set po_vendor_id = p_new_vendor_id
175 where  po_vendor_id = p_old_vendor_id
176 and    po_vendor_id is not null;
177 
178 /* Added for bug 2649043  */
179 
180   x_stage := 'Updating PA_CI_SUPPLIER_DETAILS Table For ALL Invoices';
181 
182 update PA_CI_SUPPLIER_DETAILS set vendor_id = p_new_vendor_id
183 where  vendor_id = p_old_vendor_id
184 and    vendor_id is not null;
185 
186 /* Summarization Changes */
187 
188 -- FP.M Resource LIst Data Model Impact Changes, 09-JUN-04, jwhite -----------------------------
189 -- Augmented original code with additional filter
190 
191 /* -- Original Code
192 Declare
193 Cursor c_resource_list is
194 Select distinct resource_list_id from pa_resource_list_members
195 where vendor_id = p_old_vendor_id and enabled_flag = 'Y';
196 */
197 
198 -- FP.M Data Model Logic
199 
200 Declare
201 Cursor c_resource_list is
202 Select distinct resource_list_id from pa_resource_list_members
203 where vendor_id = p_old_vendor_id
204 and enabled_flag = 'Y'
205  and nvl(migration_code,'M')= 'M';
206 
207 -- End: FP.M Resource LIst Data Model Impact Changes -----------------------------
208 
209 
210 
211 /*****
212 l_new_vendor_exists_member varchar2(1) := 'N';
213 l_new_vendor_exists_resource varchar2(1) := 'N';
214 *******Bug# 4029384*/
215 
216 l_new_vendor_exists_member number := 0;      /*Bug# 4029384*/
217 l_new_vendor_exists_resource number := 0;   /*Bug#  4029384*/
218 
219 l_new_vendor_name po_vendors.vendor_name%type;
220 
221 l_expenditure_category pa_resource_list_members.expenditure_category%type;
222 l_parent_member_id pa_resource_list_members.resource_list_member_id%type;
223 l_resource_list_member_id pa_resource_list_members.resource_list_member_id%type;
224 l_track_as_labor_flag varchar2(10);
225 l_err_code Varchar2(200);
226 l_err_stage Varchar2(200);
227 l_err_stack Varchar2(2000);
228 l_resource_id pa_resources.resource_id%type;
229 
230 Begin
231 x_stage := 'Start For Summarization';
232 for rec1 in c_resource_list loop
233 
234    x_stage := 'New Vendor Name';
235    Select vendor_name into l_new_vendor_name from po_vendors where vendor_id = p_new_vendor_id;
236 
237    Begin
238    x_stage:='See whether New vendor exists as resource in PA tables';
239 
240    Select nvl(count(a.name),0) into l_new_vendor_exists_resource from pa_resource_types b, pa_resources a
241    where  a.RESOURCE_TYPE_ID=b.RESOURCE_TYPE_ID and b.RESOURCE_TYPE_CODE='VENDOR'
242    And    a.name = l_new_vendor_name;
243 
244    Exception When no_data_found then l_new_vendor_exists_resource := 0;
245 
246    End;
247 
248    If  l_new_vendor_exists_resource = 0 Then -- Insert New vendor as a resource
249 
250    x_stage := 'New Vendor Does Not Exists ... Creating New vendor as resource';
251 
252 				PA_CREATE_RESOURCE.Create_Resource
253 				(p_resource_name             =>  l_new_vendor_name,
254                                  p_resource_type_Code        =>  'VENDOR',
255                                  p_description               =>  l_new_vendor_name,
256                                  p_unit_of_measure           =>  NULL,
257                                  p_rollup_quantity_flag      =>  NULL,
258                                  p_track_as_labor_flag       =>  NULL,
259                                  p_start_date                =>  to_date('01/01/1950','DD/MM/YYYY'),
260                                  p_end_date                  =>  NULL,
261                                  p_person_id                 =>  NULL,
262                                  p_job_id                    =>  NULL,
263                                  p_proj_organization_id      =>  NULL,
264                                  p_vendor_id                 =>  p_new_vendor_id,
265                                  p_expenditure_type          =>  NULL,
266                                  p_event_type                =>  NULL,
267                                  p_expenditure_category      =>  NULL,
268                                  p_revenue_category_code     =>  NULL,
269                                  p_non_labor_resource        =>  NULL,
270                                  p_system_linkage            =>  NULL,
271                                  p_project_role_id           =>  NULL,
272                                  p_resource_id               =>  l_resource_id,
273                                  p_err_code                  =>  l_err_code,
274                                  p_err_stage                 =>  x_stage,
275                                  p_err_stack                 =>  l_err_stack);
276    End If;
277 
278 
279        -- FP.M Resource LIst Data Model Impact Changes, 09-JUN-04, jwhite -----------------------------
280        -- Augmented original code with additional filter for migration_code
281 
282 
283 	Begin
284 
285 /* --Origianal Code
286 
287 		Select nvl(count(*),0) into l_new_vendor_exists_member from pa_resource_list_members
288 		where 	resource_list_id = rec1.resource_list_id and VENDOR_ID = p_new_vendor_id;
289 */
290 
291 
292   -- FP.M Data Model
293 
294                 Select nvl(count(*),0)
295                 into l_new_vendor_exists_member
296                 from pa_resource_list_members
297 		where 	resource_list_id = rec1.resource_list_id
298                 and VENDOR_ID = p_new_vendor_id
299                     and nvl(migration_code,'M') = 'M';
300 
301 
302 		exception when no_data_found then l_new_vendor_exists_member := 0;
303 
304 	End;
305 
306 
307 /* --Origianal Code
308 
309 		update pa_resource_list_members set enabled_flag = 'N'
310 		where  resource_list_id = rec1.resource_list_id
311 		and    vendor_id = p_old_vendor_id;
312 */
313 
314 
315 
316   -- FP.M Data Model
317 
318                 update pa_resource_list_members set
319                 enabled_flag = 'N'
320 		where  resource_list_id = rec1.resource_list_id
321 		and    vendor_id = p_old_vendor_id
322                     and nvl(migration_code,'M') = 'M';
323 
324        -- End: FP.M Resource LIst Data Model Impact Changes -----------------------------
325 
326 
327 
328    If  l_new_vendor_exists_member = 0 Then -- Insert New vendor as a resource list member
329 
330 	    x_stage:=' New Vendor Does not esists as resource member.. creating resource member';
331 
332 	Declare
333 
334 	L_RESOURCE_LIST_ID              PA_RESOURCE_LIST_MEMBERS.RESOURCE_LIST_ID%TYPE;
335 	L_RESOURCE_ID			PA_RESOURCE_LIST_MEMBERS.RESOURCE_ID%TYPE;
336 	L_ORGANIZATION_ID         	PA_RESOURCE_LIST_MEMBERS.ORGANIZATION_ID%TYPE;
337 	L_EXPENDITURE_CATEGORY		PA_RESOURCE_LIST_MEMBERS.EXPENDITURE_CATEGORY%TYPE;
338 	L_REVENUE_CATEGORY		PA_RESOURCE_LIST_MEMBERS.REVENUE_CATEGORY%TYPE;
339         l_res_grouped                   PA_RESOURCE_LISTS_ALL_BG.group_resource_type_id%TYPE;  /*Bug# 4029384*/
340 	Begin
341 
342 
343  -- FP.M Resource LIst Data Model Impact Changes, 09-JUN-04, jwhite -----------------------------
344  -- Augmented original code with additional filter
345 
346 /* -- Original Logic
347 
348 
349 	SELECT
350 	RESOURCE_LIST_ID, RESOURCE_ID, ORGANIZATION_ID, EXPENDITURE_CATEGORY, REVENUE_CATEGORY
351  	INTO
352  	L_RESOURCE_LIST_ID, L_RESOURCE_ID, L_ORGANIZATION_ID,L_EXPENDITURE_CATEGORY, L_REVENUE_CATEGORY
353  	From pa_resource_list_members
354  	Where RESOURCE_LIST_ID = rec1.resource_list_id
355  	And   resource_list_member_id  = (Select parent_member_id from pa_resource_list_members
356 				   where RESOURCE_LIST_ID = rec1.resource_list_id
357 				   and vendor_id= p_old_vendor_id);
358 */
359 
360 
361  -- FP.M Data Model Logic
362 
363 /*Bug# 4029384*/
364         select group_resource_type_id
365         into l_res_grouped
366         from pa_resource_lists_all_BG
367         where  RESOURCE_LIST_ID = rec1.resource_list_id;
368 
369        IF (l_res_grouped <> 0) THEN    /*To check if resource list is grouped */
370 
371 	SELECT
372  	 RESOURCE_LIST_ID, RESOURCE_ID, ORGANIZATION_ID, EXPENDITURE_CATEGORY, REVENUE_CATEGORY
373  	INTO
374  	 L_RESOURCE_LIST_ID, L_RESOURCE_ID, L_ORGANIZATION_ID,L_EXPENDITURE_CATEGORY, L_REVENUE_CATEGORY
375  	From pa_resource_list_members
376  	Where RESOURCE_LIST_ID = rec1.resource_list_id
377  	And   resource_list_member_id  = (Select parent_member_id from pa_resource_list_members
378 	     			          where RESOURCE_LIST_ID = rec1.resource_list_id
379 				           and vendor_id= p_old_vendor_id
380                                            and nvl(migration_code,'M') = 'M' );
381 
382  -- End: FP.M Resource LIst Data Model Impact Changes -----------------------------
383 
384        ELSE /*If resource list is not grouped*/
385 
386         SELECT
387          RESOURCE_LIST_ID, RESOURCE_ID, ORGANIZATION_ID, EXPENDITURE_CATEGORY, REVENUE_CATEGORY
388         INTO
389          L_RESOURCE_LIST_ID, L_RESOURCE_ID, L_ORGANIZATION_ID,L_EXPENDITURE_CATEGORY, L_REVENUE_CATEGORY
390         From pa_resource_list_members
391         Where RESOURCE_LIST_ID = rec1.resource_list_id
392          and vendor_id =p_old_vendor_id
393          and nvl(migration_code,'M') = 'M';
394 
395 
396        END IF;   /*End of changes of Bug# 4029384*/
397 
398 			PA_CREATE_RESOURCE.Create_Resource_list_member
399                          (p_resource_list_id          =>  rec1.resource_list_id,
400                           p_resource_name             =>  l_new_vendor_name,
401                           p_resource_type_Code        =>  'VENDOR',
402                           p_alias                     =>  l_new_vendor_name,
403                           p_sort_order                =>  NULL,
404                           p_display_flag              =>  'Y',
405                           p_enabled_flag              =>  'Y',
406                           p_person_id                 =>  NULL,
407                           p_job_id                    =>  NULL,
408                           p_proj_organization_id      =>  L_ORGANIZATION_ID,
409                           p_vendor_id                 =>  p_new_vendor_id,
410                           p_expenditure_type          =>  NULL,
411                           p_event_type                =>  NULL,
412                           p_expenditure_category      =>  l_expenditure_category,
413                           p_revenue_category_code     =>  L_REVENUE_CATEGORY,
414                           p_non_labor_resource        =>  NULL,
415                           p_system_linkage            =>  NULL,
416                           p_project_role_id           =>  NULL,
417                           p_parent_member_id          =>  l_parent_member_id,
418                           p_resource_list_member_id   =>  l_resource_list_member_id,
419                           p_track_as_labor_flag       =>  l_track_as_labor_flag,
420                           p_err_code                  =>  l_err_code,
421                           p_err_stage                 =>  x_stage,
422                           p_err_stack                 =>  l_err_stack);
423 	End;
424    End If;
425 
426 
427    x_stage := ' Calling Resource List change api to update summarization data';
428    /* The following code need to be called from API for resource list merger and refresh summary amounts */
429 
430 		pa_proj_accum_main.ref_rl_accum(
431                		    	l_err_stack,
432                    		l_err_code,
433                    		NULL,
434                    		NULL,
435                    		rec1.resource_list_id);
436 
437 End Loop;
438 
439 
440 
441 end; /** End Summarization **/
442 
443 End UPD_PA_DETAILS_SUPPLIER_MERGE;
444 
445 
446 FUNCTION Allow_Supplier_Merge ( p_vendor_id         IN po_vendors.vendor_id%type
447                             )
448 RETURN varchar2
449 IS
450     l_budget_exists    Varchar2(1);
451     l_allow_merge_flg  Varchar2(1); -- FP.M Change
452 BEGIN
453 
454  -- FP.M Resource LIst Data Model Impact Changes, 09-JUN-04, jwhite -----------------------------
455  -- Augmented original code with additional filter
456 
457 /* -- Original Logic
458 
459 select 'Y' into l_budget_exists
460 from pa_resource_assignments assign, pa_resource_list_members member, pa_budget_lines budget
461 where assign.RESOURCE_LIST_MEMBER_ID=member.RESOURCE_LIST_MEMBER_ID
462 and   member.vendor_id = p_vendor_id
463 and   budget.resource_assignment_id = assign.resource_assignment_id
464 and   rownum < 2 ;
465 
466 
467 */
468 
469    -- FP.M Data Model Logic
470 
471     select 'Y'
472     into l_budget_exists
473     from pa_resource_assignments assign
474     , pa_resource_list_members member
475     , pa_budget_lines budget
476     where assign.RESOURCE_LIST_MEMBER_ID=member.RESOURCE_LIST_MEMBER_ID
477     and   member.vendor_id = p_vendor_id
478     and   budget.resource_assignment_id = assign.resource_assignment_id
479     and   rownum < 2
480      and  nvl(member.migration_code,'M') = 'M';
481 
482 
483   -- End: FP.M Resource LIst Data Model Impact Changes -----------------------------
484 
485 
486 -- Since Budget exists for the vendor to be merged Do not allow Supplier merge
487 
488 Return 'N';
489 
490    -- FP.M change.
491    -- pa_resource_utils.chk_supplier_in_use function checks to see if the given supplier ID is used by any
492    -- planning resource lists or resource breakdown structures.  If it is in use, it returns 'Y'; if not,
493    -- it returns 'N'. If the value returned is Y, Supplier merge is not allowed.
494 
495 Exception
496  When no_data_found then
497    select decode(pa_resource_utils.chk_supplier_in_use(p_vendor_id),'Y','N','Y')
498    into   l_allow_merge_flg
499    from   dual;
500 Return  l_allow_merge_flg;
501 END Allow_Supplier_Merge;
502 
503 /***************************************************************************
504    Procedure        : get_asset_addition_flag
505    Purpose          : When Expense Reports are sent to AP from PA,
506                       the intermediate tables ap_expense_report_headers_all
507                       and ap_expense_report_lines_all are populated. A Process
508                       process in AP then populates the
509                       Invoice Distribution tables. As there is no way in the
510                       intermediate tables, to find out if the expense report is
511                       associated with a 'Capital Project', which should not be
512                       interfaced from AP to FA, unlike Invoice Distribution line
513                       table, where asset_addition_flag is used. This API is to
514                       find out if the given project_id is a 'CAPITAL' project
515                       and if so, populate the 'out' vairable to 'P', else 'U'.
516    Arguments        : p_project_id            IN - project id
517                       x_asset_addition_flag  OUT - asset addition flag
518 ****************************************************************************/
519 
520 
521 PROCEDURE get_asset_addition_flag
522              (p_project_id           IN  pa_projects_all.project_id%TYPE,
523               x_asset_addition_flag  OUT NOCOPY ap_invoice_distributions_all.assets_addition_flag%TYPE)
524 IS
525 
526    l_project_type_class_code  pa_project_types_all.project_type_class_code%TYPE;
527 
528 BEGIN
529 
530   /* For Given Project Id, Get the Project_Type_Class_Code depending on the Project_Type */
531   SELECT  ptype.project_type_class_code
532     INTO  l_project_type_class_code
533     FROM  pa_project_types_all ptype,
534           pa_projects_all      proj
535    WHERE  ptype.project_type     = proj.project_type
536      --R12 AND  NVL(ptype.org_id, -99) = NVL(proj.org_id, -99)
537      AND  ptype.org_id = proj.org_id
538      AND  proj.project_id        = p_project_id;
539 
540    /* IF Project is CAPITAL then set asset_addition_flag to 'P' else 'U' */
541 
542    IF (l_project_type_class_code = 'CAPITAL') THEN
543 
544      x_asset_addition_flag  := 'P';
545 
546    ELSE
547 
548      x_asset_addition_flag  := 'U';
549 
550    END IF;
551 
552 EXCEPTION
553 
554    WHEN OTHERS THEN
555      RAISE;
556 
557 END get_asset_addition_flag;
558 
559 /***************************************************************************
560    Function         : Get_Project_Type
561    Purpose          : This function will check if the project id passed to this
562                       is a 'CAPITAL' Project.If it is then this will return
563                       'P' otherwise 'U'
564    Arguments        : p_project_id            IN           - project id
565                       Returns 'P' if the project is Capital otherwise 'U'
566 ****************************************************************************/
567 
568 FUNCTION Get_Project_Type
569        (p_project_id IN pa_projects_all.project_id%TYPE)RETURN VARCHAR2 IS
570 l_project_type VARCHAR2(1);
571 
572 BEGIN
573 
574 /* For Given Project Id, Get the Project_Type_Class_Code depending on the Project_Type */
575 
576  SELECT decode(ptype.project_type_class_code,'CAPITAL','P','U')
577   INTO  l_project_type
578   FROM  pa_project_types_all ptype,
579         pa_projects_all      proj
580  WHERE proj.project_type = ptype.project_type
581  -- R12 AND   NVL(ptype.org_id, -99) = NVL(proj.org_id, -99)
582  AND   ptype.org_id = proj.org_id
583  AND   proj.project_id   = p_project_id ;
584 
585  RETURN l_project_type;
586 
587  EXCEPTION
588     WHEN OTHERS THEN
589         RAISE;
590   END Get_Project_Type;
591 
592 -- ==========================================================================================================================================
593 -- Bug 5201382 R12.PJ:XB3:DEV:NEW API TO RETRIEVE THE DATES FOR PROFILE PA_AP_EI_DATE_DEFAULT
594 -- p_transaction_date : API would return transaction date when profile value was set to 'Transaction Date'
595 --                       a. For Invoice transaction invoice_date should be passed as parameter
596 --                       b. For PO or Receipt Matched Invoice  Transactions invoice_date should be passed as parameter
597 --                       c. For RCV Transactions transaction_date should be passed.
598 --                       d. For payments and discounts ap dist exp_item_date should be passed.
599 -- p_gl_date          : API would return transaction date when profile value was set to 'Transaction GL Date'
600 --                      a. For Invoice transactions gl_date should be passed b. For payments and discounts the accounting date must be passed
601 --                      c. for RCV transactions accounting date should be passed.
602 -- p_po_exp_item_date : API would return the purchase order expenditure item date for po matched cases when profile value was set to
603 --                      'PO Expenditure Item Date/Transaction Date'. This is used for PO matched cases. It may be NULL when
604 --                       p_po_distribution_id was passed to the API.
605 -- p_po_distribution_id: The parameter value is used to determine the purchase order expenditure item date for po matched cases when profile
606 --                        value was set to 'PO Expenditure Item Date/Transaction Date'. when p_po_exp_item_date was passed  then
607 --                        p_po_distribution_id is not used to derive the expenditure item date.
608 -- p_creation_date : API would return this date when profile value was set to 'Transaction System Date'
609 -- p_calling_program : a. when called during the PO Match case : PO-MATCH b. When called from Invoice form        : APXINWKB
610 --                     c. When called from supplier cost xface for discounts : DISCOUNT d. When called from supplier cost xface for Payment: PAYMENT
611 --                     e. When called from supplier cost xface for Receipts  : RECEIPT
612 -- ==========================================================================================================================================
613 FUNCTION Get_si_cost_exp_item_date ( p_transaction_date      IN pa_expenditure_items_all.expenditure_item_date%TYPE,
614                                      p_gl_date               IN pa_cost_distribution_lines_all.gl_date%TYPE,
615                                      p_po_exp_item_date      IN pa_expenditure_items_all.expenditure_item_date%TYPE,
616                                      p_creation_date         IN pa_expenditure_items_all.creation_date%TYPE,
617                                      p_po_distribution_id    IN pa_expenditure_items_all.document_distribution_id%TYPE,
618                                      p_calling_program       IN varchar2  )
619  RETURN date is
620     l_return_date          date ;
621     l_pa_exp_date_default  varchar2(50) ;
622     l_pa_debug_flag        varchar2(1) ;
623 
624     cursor c_po_date is
625       select expenditure_item_date
626         from po_distributions_all
627        where po_distribution_id = p_po_distribution_id ;
628 
629  BEGIN
630     l_pa_debug_flag :=  NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
631     l_pa_exp_date_default := FND_PROFILE.VALUE('PA_AP_EI_DATE_DEFAULT');
632 
633    IF l_pa_debug_flag = 'Y' THEN
634       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
635          FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION', 'Default Exp item date profile:'||l_pa_exp_date_default) ;
636       END IF ;
637    END IF ;
638 
639 /*bug 14057183*/
640    IF g_po_match_date is NOT NULL AND p_calling_program = 'PO-MATCH' THEN
641    return g_po_match_date;
642    END IF;
643 
644    /* Changes for bug 8289798 : Modified the case statements to handle lookup codes , rather than meanings*/
645    CASE l_pa_exp_date_default
646          WHEN 'INVTRNSDT' THEN
647                 l_return_date := p_transaction_date ;
648          WHEN 'INVGLDT' THEN
649                 l_return_date := p_gl_date ;
650          WHEN 'INVSYSDT' THEN
651                 l_return_date := p_creation_date ;
652          -- Bug: 5262492 (R12.PJ:XB5:QA:APL: PROJECT EI DATE NULL FOR PO/REC MATCHED INVOICE LINE/DISTRIBU
653          WHEN 'POTRNSDT' THEN
654               IF p_po_exp_item_date is not NULL then
655                  l_return_date := p_po_exp_item_date  ;
656               ELSE
657                 IF l_pa_debug_flag = 'Y' THEN
658                    IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
659                       FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION', 'PO expenditure item date is NULL') ;
660                    END IF ;
661                 END IF ;
662 
663                 IF p_po_distribution_id is not NULL then
664                    open c_po_date ;
665 		   fetch c_po_date into l_return_date ;
666 		   close c_po_date ;
667                    IF l_pa_debug_flag = 'Y' THEN
668                       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
669                          FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION',
670 			                'Determining the date based on the PO distribution IDL') ;
671                       END IF ;
672                    END IF ;
673 		ELSE
674 		-- Bug : 4940969
675 		-- In the case of unmatched invoice the Invoice date must get @ defaulted as the EI date.
676 		   l_return_date := p_transaction_date ;
677 
678                 END IF ;
679 	      END IF ;
680          ELSE
681                 l_return_date := p_transaction_date ; --Changed from null to p_transaction_date for Bug 9701340
682 
683    END CASE;
684 
685     IF l_pa_debug_flag = 'Y' THEN
686       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
687          FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION', 'Date returned :'||to_char(l_return_date, 'DD-MON-YYYY')) ;
688       END IF ;
689    END IF ;
690 
691    return l_return_date ;
692 
693 
694  End Get_si_cost_exp_item_date ;
695 
696 
697 FUNCTION Get_si_default_exp_org RETURN varchar2 is
698    l_default_exp_org HR_ALL_ORGANIZATION_UNITS_TL.NAME%TYPE; /* Bug 5555041 */
699    l_organization_id HR_ALL_ORGANIZATION_UNITS_TL.ORGANIZATION_ID%TYPE; /* Bug 5555041 */
700    l_default_exp_org1 HR_ALL_ORGANIZATION_UNITS_TL.NAME%TYPE; /* Bug 7575377 */
701 
702 /* Bug 5555041 - Start */
703    CURSOR c_get_org_id(p_org_name HR_ALL_ORGANIZATION_UNITS_TL.NAME%TYPE) IS
704    SELECT organization_id
705    FROM hr_all_organization_units_tl
706    WHERE name = p_org_name;
707 
708    CURSOR c_get_org_name(p_organization_id HR_ALL_ORGANIZATION_UNITS_TL.ORGANIZATION_ID%TYPE) IS
709    SELECT name
710    FROM per_organization_units
711    WHERE organization_id = p_organization_id;
712 /* Bug 5555041 - End */
713 BEGIN
714     l_default_exp_org := FND_PROFILE.VALUE('PA_DEFAULT_EXP_ORG');
715 
716 /* Bug 5555041 - Start */
717     OPEN  c_get_org_id(l_default_exp_org);
718     FETCH c_get_org_id INTO l_organization_id;
719     CLOSE c_get_org_id;
720 
721     OPEN c_get_org_name(l_organization_id);
722     FETCH c_get_org_name INTO l_default_exp_org1; /* Modified for bug 7575377 */
723     CLOSE c_get_org_name;
724 /* Bug 5555041 - End */
725 
726     return l_default_exp_org1 ; /* Modified for bug 7575377 */
727 END Get_si_default_exp_org ;
728 
729 
730 /*13706985  - Start*/
731 
732 /***************************************************************************
733    Procedure        :	Get_Po_Match_Si_Exp_Item_Date
734    Purpose           :	Bug#13706985 PO match action does not verify whether EI
735 				date falls in a closed PA period or not. During PO match AP invokes API
736 				PA_AP_INTEGRATION.Get_Si_Cost_Exp_Item_Date to retrieve the
737 				EI date and stamps the date returned by the API as the EI date.
738 				This procedure is an enhancement to the previous function
739 				which returns specific error messages to the calling
740 				program based on the validation of the expenditure item date
741    Arguments        :	     p_transaction_date		IN
742 				     p_gl_date				IN
743 				     p_po_exp_item_date		IN
744 				     p_creation_date			IN
745 				     p_po_distribution_id		IN
746 				     p_calling_program		IN
747 				     p_exp_item_date		OUT
748 				     p_date_valid_flag		OUT
749 				     p_pa_message_name	OUT
750 ****************************************************************************/
751 
752 PROCEDURE Get_Po_Match_Si_Exp_Item_Date
753              (	p_transaction_date			IN  DATE,
754 		p_gl_date					IN  DATE,
755 		p_po_exp_item_date		IN  DATE,
756 		p_creation_date			IN  DATE,
757 		p_po_distribution_id		IN  po_distributions_all.po_distribution_id%TYPE,
758 		p_calling_program			IN  VARCHAR2,
759 	  	p_exp_item_date			OUT NOCOPY DATE,
760 		p_is_date_valid			OUT NOCOPY VARCHAR2,
761 		p_pa_message_name		OUT  NOCOPY varchar2,
762 		p_token_value1			OUT NOCOPY VARCHAR2,
763 		p_token_value2			OUT NOCOPY VARCHAR2)
764 
765 IS
766 
767 	l_return_date			DATE ;
768 	l_pa_exp_date_default	VARCHAR2(50) ;
769 	l_pa_debug_flag		VARCHAR2(1) ;
770 	l_gms_installed		BOOLEAN; /*Added for bug 14050469*/
771 	l_po_exp_item_date	DATE;
772 	l_pa_date			DATE;
773 
774 	l_award_id			NUMBER ;
775 	l_project_id			NUMBER;
776 	l_task_id				NUMBER;
777 	l_expenditure_type	VARCHAR2(30);
778 	l_profile_date			DATE;
779 	l_DESTINATION_TYPE_CODE  VARCHAR2(25); /* Added for bug 16312792 */
780 
781 
782 	V_PROJECT_ID NUMBER;
783 	V_TASK_ID NUMBER;
784 	V_PROFILE_DATE DATE;
785 	V_EXPENDITURE_TYPE VARCHAR2(30);
786 	V_NON_LABOR_RESOURCE VARCHAR2(30);
787 	V_EMPLOYEE_ID NUMBER;
788 	V_QUANTITY NUMBER;
789 	V_DENOM_CURRENCY_CODE VARCHAR2(15);
790 	V_ACCT_CURRENCY_CODE VARCHAR2(15);
791 	V_INVOICE_AMOUNT NUMBER;
792 	V_ACCT_RAW_COST NUMBER;
793 	V_RATE_DATE DATE;
794 	V_RATE_TYPE VARCHAR2(30);
795 	V_RATE NUMBER;
796 	V_TRANSFER_EI NUMBER;
797 	V_EXP_ORG_ID NUMBER(15);
798 	V_NL_RES_ORG_ID NUMBER(15);
799 	V_TRANSACTION_SOURCE VARCHAR2(30);
800 	V_VENDOR_ID NUMBER;
801 	V_ENTERED_BY_USER_ID NUMBER;
802 	V_ATTRIBUTE_CATEGORY VARCHAR2(150);
803 	V_ATTRIBUTE1 VARCHAR2(150);
804 	V_ATTRIBUTE2 VARCHAR2(150);
805 	V_ATTRIBUTE3 VARCHAR2(150);
806 	V_ATTRIBUTE4 VARCHAR2(150);
807 	V_ATTRIBUTE5 VARCHAR2(150);
808 	V_ATTRIBUTE6 VARCHAR2(150);
809 	V_ATTRIBUTE7 VARCHAR2(150);
810 	V_ATTRIBUTE8 VARCHAR2(150);
811 	V_ATTRIBUTE9 VARCHAR2(150);
812 	V_ATTRIBUTE10 VARCHAR2(150);
813 	V_ATTRIBUTE11 VARCHAR2(150);
814 	V_ATTRIBUTE12 VARCHAR2(150);
815 	V_ATTRIBUTE13 VARCHAR2(150);
816 	V_ATTRIBUTE14 VARCHAR2(150);
817 	V_ATTRIBUTE15 VARCHAR2(150);
818 
819 	V_Msg_Application VARCHAR2(10) := 'PA';
820 	V_MsgType VARCHAR2(150);
821 	V_MsgToken1 VARCHAR2(150);
822 	V_MsgToken2 VARCHAR2(150);
823 	V_MsgToken3 VARCHAR2(150);
824 	V_MsgName1 VARCHAR2(2000);
825 	V_MsgName2 VARCHAR2(2000);
826 	V_Gms_Message VARCHAR2(2000);
827 	V_billable_flag VARCHAR2(1);
828 	V_MSGCOUNT NUMBER;
829 
830 	cursor c_po_date is
831 	select expenditure_item_date
832         from po_distributions_all
833 	where po_distribution_id = p_po_distribution_id ;
834 
835 
836 /* The cursor for getting all the variables to be passed to the patc.get_status proc. The use of ap_invoices_all is not done here as we dont have the invoice id being passed by AP */
837 	cursor patc_cursor is
838 	select
839 	POD.project_id PROJECT_ID,
840 	POD.task_id TASK_ID,
841 	decode(NVL(FND_PROFILE.VALUE('PA_AP_EI_DATE_DEFAULT'),'POTRNSDT'),
842 	'INVTRNSDT',
843 	p_transaction_date,
844 	'INVGLDT',
845 	p_gl_date,
846 	'INVSYSDT',
847 	p_creation_date,
848 	'POTRNSDT',
849 	l_po_exp_item_date) PROFILE_DATE,
850 	POD.expenditure_type EXPENDITURE_TYPE,
851 	NULL NON_LABOR_RESOURCE,
852 	NULL EMPLOYEE_ID,
853 	QUANTITY_ORDERED QUANTITY,
854 	NULL ,
855 	G.CURRENCY_CODE,
856 	NULL,
857 	NULL ACCT_RAW_COST,
858 	NULL ,
859 	NULL ,
860 	NULL ,
861 	NULL TRANSFER_EI,
862 	POD.EXPENDITURE_ORGANIZATION_ID,
863 	NULL NL_RESOURCE_ORG_ID,
864 	'AP INVOICE' TRANSACTION_SOURCE,
865 	NULL,
866 	NULL ENTERED_BY_USER_ID,
867 	NULL,
868 	NULL,
869 	NULL,
870 	NULL,
871 	NULL,
872 	NULL,
873 	NULL,
874 	NULL,
875 	NULL,
876 	NULL,
877 	NULL,
878 	NULL,
879 	NULL,
880 	NULL,
881 	NULL,
882 	NULL
883 	from po_distributions_all pod,
884 	po_headers_all poh,
885 	GL_SETS_OF_BOOKS G
886 	where
887 	poh.po_header_id = pod.po_header_id
888 	and pod.po_distribution_id = p_po_distribution_id
889 	and G.set_of_books_id = pod.set_of_books_id;
890 
891  BEGIN
892      l_pa_debug_flag :=  NVL(FND_PROFILE.value('PA_DEBUG_MODE'), 'N');
893     /*In case of null value of profile option, we would use source doucment ei date*/
894     l_pa_exp_date_default := NVL(FND_PROFILE.VALUE('PA_AP_EI_DATE_DEFAULT'),'POTRNSDT');
895 
896 /* Verfication variable to check if gms is installed */
897     l_gms_installed :=  pa_gms_api.vert_install; /*Added for bug 14050469*/
898 
899      IF p_po_exp_item_date is NULL THEN  /*bug 14057183*/
900 		IF p_po_distribution_id is not NULL then
901 			open c_po_date;
902 			fetch c_po_date into l_po_exp_item_date ;
903 			close c_po_date;
904 		END IF;
905      END IF;
906 
907    IF l_pa_debug_flag = 'Y' THEN
908       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
909          FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION', 'Default Exp item date profile:'||l_pa_exp_date_default) ;
910       END IF ;
911    END IF ;
912 
913 /*bug 14050469 - Divided the single query for selecting all 3 - award id, project id and task id to two queries and also added the gms validation
914 for checking if the user is a gms user*/
915 
916 begin
917 select  pod.project_id,pod.task_id,pod.expenditure_type,DESTINATION_TYPE_CODE /* Added for bug 16312792 */
918 into l_project_id,l_task_id,l_expenditure_type,l_DESTINATION_TYPE_CODE  /* Added for bug 16312792 */
919         from po_distributions_all pod
920      where
921        pod.po_distribution_id = p_po_distribution_id;
922 exception when no_data_found then
923 l_project_id := NULL;
924 l_task_id := NULL;
925 l_expenditure_type := NULL;
926 l_DESTINATION_TYPE_CODE := NULL;  /* Added for bug 16312792 */
927 end;
928 
929 /*If gms is installed then call the gms_transactions_pub.validate_transaction to validate the award information   */
930 
931 IF l_gms_installed THEN /*Added for bug 14050469 */
932 
933 begin
934  select  awd.award_id,
935 		 decode(NVL(FND_PROFILE.VALUE('PA_AP_EI_DATE_DEFAULT'),'POTRNSDT'),
936 								'INVTRNSDT',
937 								p_transaction_date,
938 								'INVGLDT',
939 								p_gl_date,
940 								'INVSYSDT',
941 								p_creation_date,
942 								'POTRNSDT',
943 								l_po_exp_item_date)
944  into l_award_id,l_profile_date
945         from    gms_awards_all               awd,
946              po_distributions_all pod,
947              gms_award_distributions      adl
948      where   adl.award_id          = awd.award_id
949        and   pod.po_distribution_id = p_po_distribution_id
950        and   pod.award_id                = adl.award_set_id
951        and   adl.adl_line_num            = 1 ;
952 exception when no_data_found then l_award_id := NULL;
953 end;
954 
955 
956 
957 gms_transactions_pub.validate_transaction( l_project_id,
958 							  l_task_id,
959 							   l_award_id,
960 							   l_expenditure_type,
961 							  l_profile_date ,
962 							   'APTXNIMP',
963 							   V_Gms_Message ) ; /* Collect the out message into V_Gms_Message  */
964 
965 
966 
967 END IF;
968 
969 
970 /* Open and fetch the cursor into the local variables defined. We pass these variables into patc.get_status */
971 
972 OPEN patc_cursor;
973 FETCH patc_cursor INTO
974 V_PROJECT_ID,
975 V_TASK_ID,
976 V_PROFILE_DATE,
977 V_EXPENDITURE_TYPE,
978 V_NON_LABOR_RESOURCE,
979 V_EMPLOYEE_ID,
980 V_QUANTITY,
981 V_DENOM_CURRENCY_CODE,
982 V_ACCT_CURRENCY_CODE,
983 V_INVOICE_AMOUNT,
984 V_ACCT_RAW_COST,
985 V_RATE_TYPE,
986 V_RATE_DATE,
987 V_RATE,
988 V_TRANSFER_EI,
989 V_EXP_ORG_ID,
990 V_NL_RES_ORG_ID,
991 V_TRANSACTION_SOURCE,
992 V_VENDOR_ID,
993 V_ENTERED_BY_USER_ID,
994 V_ATTRIBUTE_CATEGORY,
995 V_ATTRIBUTE1,
996 V_ATTRIBUTE2,
997 V_ATTRIBUTE3,
998 V_ATTRIBUTE4,
999 V_ATTRIBUTE5,
1000 V_ATTRIBUTE6,
1001 V_ATTRIBUTE7,
1002 V_ATTRIBUTE8,
1003 V_ATTRIBUTE9,
1004 V_ATTRIBUTE10,
1005 V_ATTRIBUTE11,
1006 V_ATTRIBUTE12,
1007 V_ATTRIBUTE13,
1008 V_ATTRIBUTE14,
1009 V_ATTRIBUTE15;
1010 CLOSE patc_cursor;
1011 
1012 /* Call the standard proc patc.get_status and collect the output 14057813*/
1013 PATC.GET_STATUS(
1014   X_PROJECT_ID         => V_PROJECT_ID,
1015   X_TASK_ID            => V_TASK_ID,
1016   X_EI_DATE            => V_PROFILE_DATE,
1017   X_EXPENDITURE_TYPE   => V_EXPENDITURE_TYPE,
1018   X_NON_LABOR_RESOURCE => NULL,
1019   X_PERSON_ID          => V_EMPLOYEE_ID,
1020   X_QUANTITY           => V_QUANTITY,
1021   X_DENOM_CURRENCY_CODE =>V_DENOM_CURRENCY_CODE,
1022   X_ACCT_CURRENCY_CODE => V_ACCT_CURRENCY_CODE,
1023   X_DENOM_RAW_COST     => V_INVOICE_AMOUNT,
1024   X_ACCT_RAW_COST      => V_INVOICE_AMOUNT,
1025   X_ACCT_RATE_TYPE     => V_RATE_TYPE,
1026   X_ACCT_RATE_DATE     => V_RATE_DATE,
1027   X_ACCT_EXCHANGE_RATE => V_RATE,
1028   X_TRANSFER_EI        => V_TRANSFER_EI,
1029   X_INCURRED_BY_ORG_ID => V_EXP_ORG_ID,
1030   X_NL_RESOURCE_ORG_ID => V_NL_RES_ORG_ID,
1031   X_TRANSACTION_SOURCE => V_TRANSACTION_SOURCE,
1032   X_CALLING_MODULE     => 'APXINENT',
1033   X_VENDOR_ID          => V_VENDOR_ID,
1034   X_ENTERED_BY_USER_ID => V_ENTERED_BY_USER_ID,
1035   X_ATTRIBUTE_CATEGORY => V_ATTRIBUTE_CATEGORY,
1036   X_ATTRIBUTE1         => V_ATTRIBUTE1,
1037   X_ATTRIBUTE2         => V_ATTRIBUTE2,
1038   X_ATTRIBUTE3         => V_ATTRIBUTE3,
1039   X_ATTRIBUTE4         => V_ATTRIBUTE4,
1040   X_ATTRIBUTE5         => V_ATTRIBUTE5,
1041   X_ATTRIBUTE6         => V_ATTRIBUTE6,
1042   X_ATTRIBUTE7         => V_ATTRIBUTE7,
1043   X_ATTRIBUTE8         => V_ATTRIBUTE8,
1044   X_ATTRIBUTE9         => V_ATTRIBUTE9,
1045   X_ATTRIBUTE10        => V_ATTRIBUTE10,
1046   X_ATTRIBUTE11        => V_ATTRIBUTE11,
1047   X_ATTRIBUTE12        => V_ATTRIBUTE12,
1048   X_ATTRIBUTE13        => V_ATTRIBUTE13,
1049   X_ATTRIBUTE14        => V_ATTRIBUTE14,
1050   X_ATTRIBUTE15        => V_ATTRIBUTE15,
1051   X_MSG_APPLICATION    => V_Msg_Application ,
1052   X_MSG_TYPE           => V_MsgType,
1053   X_MSG_TOKEN1         => V_MsgToken1,
1054   X_MSG_TOKEN2         => V_MsgToken2,
1055   X_MSG_TOKEN3         => V_MsgToken3,
1056   X_MSG_COUNT          => V_MsgCount,
1057   X_STATUS			=> V_MsgName1,    /*Collect the out put message into  */
1058   X_BILLABLE_FLAG      => V_billable_flag,
1059   p_sys_link_function		=>  'VI'
1060  );
1061 
1062 /*According to the message V_MsgName1 we need Populate the PA Token with proper meaningful sentence*/
1063 
1064 IF V_MsgName1 = 'PA_EX_QTY_EXIST' then
1065 
1066 p_token_value1  :=  'This item requires a valid quantity';
1067 
1068 elsif V_MsgName1 = 'PA_PJR_NO_ASSIGNMENT' then
1069 
1070 p_token_value1  :=  'No Assigment exists for this Project Resource';
1071 
1072 elsif V_MsgName1 = 'PA_CWK_TXN_NOT_ALLOWED' then
1073 
1074 p_token_value1  :=  'The project/task transaction controls prohibit contingent worker transactions.';
1075 
1076 elsif V_MsgName1 = 'PA_TR_EPE_PROJ_TXN_CTRLS' then
1077 
1078 p_token_value1  :=  'This item would violate a project-level transaction control.';
1079 
1080 elsif V_MsgName1 = 'PA_TR_EPE_TASK_TXN_CTRLS' then
1081 
1082 p_token_value1  :=  'This item would violate a task-level transaction control.';
1083 
1084 elsif V_MsgName1 = 'PA_CWK_TC_NOT_ALLOWED' then
1085 
1086 p_token_value1  :=  ' You cannot enter contingent worker timecards for this organization.';
1087 
1088 elsif V_MsgName1 = 'PA_WP_RES_NOT_DEFINED' then
1089 
1090 p_token_value1  :=  ' The resource is not assigned to the task.';
1091 
1092 elsif V_MsgName1 = 'EXP_TYPE_INACTIVE' then
1093 
1094 if l_pa_exp_date_default = 'INVTRNSDT' then
1095 		p_token_value1  :=  'The expenditure type is not active on the Transaction date.';
1096 	elsif l_pa_exp_date_default = 'INVGLDT' then
1097 		p_token_value1  :=  'The expenditure type is not active on the Transaction GL date.';
1098 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1099 		p_token_value1  :=  'The expenditure type is not active on the Transaction System date.';
1100 	elsif l_pa_exp_date_default = 'POTRNSDT' then
1101 		p_token_value1  :=  'The expenditure type is not active on the Source Document date.';
1102 end if;
1103 
1104 
1105 elsif V_MsgName1 = 'PA_TR_EPE_NLR_ORG_NOT_ACTIVE' then
1106 
1107 if l_pa_exp_date_default = 'INVTRNSDT' then
1108 		p_token_value1  :=  'The Non Labor Resource Organization is not active on the Transaction date.';
1109 	elsif l_pa_exp_date_default = 'INVGLDT' then
1110 		p_token_value1  :=  'The Non Labor Resource Organization is not active on the Transaction GL date.';
1111 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1112 		p_token_value1  :=  'The Non Labor Resource Organization is not active on the Transaction System date.';
1113 	elsif l_pa_exp_date_default = 'POTRNSDT' then
1114 		p_token_value1  :=  'The Non Labor Resource Organization is not active on the Source Document date.';
1115 end if;
1116 
1117 elsif V_MsgName1 = 'PA_ER_CANNOT_XFACE_EMP' then
1118 
1119 p_token_value1  :=  ' This expense report cannot be interfaced to Oracle Projects because the employee vendor does not have a valid employee ID.';
1120 
1121 elsif V_MsgName1 = 'PA_ER_CANNOT_XFACE' then
1122 
1123 p_token_value1  :=  'This expense report cannot be interfaced to Oracle Projects because the supplier is not defined as an employee.';
1124 
1125 elsif V_MsgName1 = 'PA_INVALID_EXPENDITURE_TYPE' then
1126 
1127 p_token_value1  :=  'The Expenditure Type is Invalid';
1128 
1129 elsif V_MsgName1 = 'INVALID_ETYPE_SYSLINK' then
1130 
1131 p_token_value1  :=  'Invalid expenditure type and expenditure type class combination';
1132 
1133 elsif V_MsgName1 = 'ETYPE_SLINK_INACTIVE' then
1134 
1135 p_token_value1  :=  'The Expenditure Type and Expenditure Type Class combination is inactive.';
1136 
1137 elsif V_MsgName1 = 'PA_PROJECT_NOT_VALID' then
1138 
1139 p_token_value1  :=  'The project is not chargeable';
1140 
1141 elsif V_MsgName1 = 'PA_EX_TEMPLATE_PROJECT' then
1142 
1143 p_token_value1  :=  'Template projects cannot be charged.';
1144 
1145 elsif V_MsgName1 = 'PA_NEW_TXNS_NOT_ALLOWED' then
1146 
1147 p_token_value1  :=  'The project status does not allow creation of new transactions.';
1148 
1149 elsif V_MsgName1 = 'INVALID_PA_DATE' then
1150 
1151 if l_pa_exp_date_default = 'INVTRNSDT' then
1152 		p_token_value1  :=  'There is no open or future PA period for the given Transaction Date.';
1153 	elsif l_pa_exp_date_default = 'INVGLDT' then
1154 		p_token_value1  :=  'There is no open or future PA period for the given Transaction GL Date.';
1155 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1156 		p_token_value1  :=  'There is no open or future PA period for the given Transaction System Date.';
1157 	elsif l_pa_exp_date_default = 'POTRNSDT' then
1158 		p_token_value1  :=  'There is no open or future PA period for the given Source Document Date.';
1159 end if;
1160 
1161 
1162 elsif V_MsgName1 = 'PA_NO_ASSIGNMENT' then
1163 
1164 p_token_value1  :=  'No assignment exists with the given information.';
1165 
1166 elsif V_MsgName1 = 'NO_ASSIGNMENT' then
1167 
1168 p_token_value1  :=  'No assignment.';
1169 
1170 elsif V_MsgName1 = 'PA_NO_ASSIGNMENT' then
1171 
1172 p_token_value1  :=  'No assignment exists with the given information.';
1173 
1174 elsif V_MsgName1 = 'NO_PO_ASSIGNMENT' then
1175 
1176 if l_pa_exp_date_default = 'INVTRNSDT' then
1177 		p_token_value1  :=  'No active assignment for entered PO and Transasction date';
1178 	elsif l_pa_exp_date_default = 'INVGLDT' then
1179 		p_token_value1  :=  'No active assignment for entered PO and Transasction GL date';
1180 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1181 		p_token_value1  :=  'No active assignment for entered PO and Transasction System date';
1182 	elsif l_pa_exp_date_default = 'POTRNSDT' then
1183 		p_token_value1  :=  'No active assignment for entered PO and Source Document date';
1184 end if;
1185 
1186 
1187 elsif V_MsgName1 = 'PA_TRX_CANT_BE_CAP' then
1188 
1189 p_token_value1  :=  'The capitalizable flag may not be set to Y when the Retirement Cost Flag for the task is Y.';
1190 
1191 elsif V_MsgName1 = 'PA_EXP_ORG_NOT_ACTIVE' then
1192 
1193 p_token_value1  :=  'The expenditure organization is not active.';
1194 
1195 elsif V_MsgName1 = 'PA_EX_PROJECT_DATE'  then
1196 
1197 
1198 	if l_pa_exp_date_default = 'INVTRNSDT' then
1199 		p_token_value1  :=  'The  Transaction date is not within the active dates of the project';
1200 	elsif l_pa_exp_date_default = 'INVGLDT' then
1201 		p_token_value1  :=  'The  Transaction GL date is not within the active dates of the project';
1202 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1203 		p_token_value1  :=  'The  Transaction System date is not within the active dates of the project';
1204 	elsif l_pa_exp_date_default = 'POTRNSDT' then
1205 		p_token_value1  :=  'The  Source Document date is not within the active dates of the project';
1206 	end if;
1207 
1208 elsif V_MsgName1 = 'PA_EX_PROJECT_CLOSED' then
1209 
1210 p_token_value1  :=  'You cannot charge expenditure items to a closed project';
1211 
1212 elsif V_MsgName1 = 'PA_EXP_TASK_EFF'  then
1213 
1214 	if l_pa_exp_date_default = 'INVTRNSDT' then
1215 		p_token_value1  :=  'The Transaction date is not within the active dates of the task';
1216 	elsif l_pa_exp_date_default = 'INVGLDT' then
1217 		p_token_value1  :=  'The Transaction GL date is not within the active dates of the task';
1218 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1219 		p_token_value1  :=  'The Transaction System date is not within the active dates of the task';
1220 	elsif l_pa_exp_date_default = 'POTRNSDT' then
1221 		p_token_value1  :=  'The Source Document date is not within the active dates of the task';
1222 	end if;
1223 
1224 elsif V_MsgName1 = 'PA_EXP_TASK_STATUS' then
1225 p_token_value1  :=  'The task is not chargeable';
1226 
1227 elsif V_MsgName1 = 'PA_EXP_PJ_TC' then
1228 
1229 p_token_value1  :=  'A project-level expenditure transaction control has been violated ';
1230 
1231 elsif V_MsgName1 = 'PA_EXP_TASK_TC' then
1232 
1233 p_token_value1  :=  'A task-level expenditure transaction control has been violated';
1234 
1235 elsif V_MsgName1 = 'PA_NO_VALID_ASSIGN' then
1236 
1237 p_token_value1  :=  'No valid assignment exists in HR';
1238 
1239 elsif V_MsgName1 is NULL then
1240 
1241 p_token_value1  :=  ' ';
1242 
1243 end if;
1244 
1245 /*Just Similar to the above we will send a text message to the AP for GMS validation*/
1246 /*Populate the GMS Token*/
1247 
1248 if V_Gms_Message='GMS_AWARD_REQUIRED' then
1249 
1250 p_token_value2 := 'An award number is required for this project';
1251 
1252 elsif V_Gms_Message='GMS_NOT_FUNDING_AWARD' then
1253 
1254 p_token_value2 := 'The entered award does not fund the project and task combination';
1255 
1256 elsif V_Gms_Message='GMS_INVALID_AWARD' then
1257 
1258 p_token_value2 := 'The entered award number is not a valid award';
1259 
1260 elsif V_Gms_Message='GMS_INVALID_EXP_TYPE' then
1261 
1262 p_token_value2 := 'The entered expenditure type is not available for this award.';
1263 
1264 elsif V_Gms_Message='GMS_NOT_A_SPONSORED_PROJECT' then
1265 
1266 p_token_value2 := 'Non-sponsored projects cannot have an associated award number';
1267 
1268 elsif V_Gms_Message='GMS_EXP_ITEM_DATE_INVALID'  then
1269 
1270 /* Whenever there are date validations, make sure to use the correct sentence as required  */
1271 
1272 	IF l_pa_exp_date_default = 'INVTRNSDT' then
1273 		p_token_value2 := 'The entered Transasction date is not in the active date range for this award';
1274 	elsif l_pa_exp_date_default = 'INVGLDT' then
1275 		p_token_value2 := 'The entered Transasction GL date is not in the active date range for this award';
1276 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1277 		p_token_value2 := 'The entered Transasction System date is not in the active date range for this award';
1278 	elsif  l_pa_exp_date_default = 'POTRNSDT' then
1279 		p_token_value2 := 'The entered Soruce Document date is not in the active date range for this award';
1280 	END IF;
1281 
1282 elsif V_Gms_Message='GMS_EXP_ITEM_DT_BEFORE_AWD_ST' then
1283 
1284 	IF l_pa_exp_date_default = 'INVTRNSDT' then
1285 		p_token_value2 := 'Transaction date is less than award start date';
1286 	elsif l_pa_exp_date_default = 'INVGLDT' then
1287 		p_token_value2 := 'Transaction GL date is less than award start date';
1288 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1289 		p_token_value2 := 'Transaction System date is less than award start date';
1290 	elsif  l_pa_exp_date_default = 'POTRNSDT' then
1291 		p_token_value2 := 'Source Document date is less than award start date';
1292 	END IF;
1293 
1294 elsif V_Gms_Message='GMS_EXP_ITEM_DT_AFTER_AWD_END' then
1295 
1296 	IF l_pa_exp_date_default = 'INVTRNSDT' then
1297 		p_token_value2 := 'Transaction date does not fall between award start date and award end date';
1298 	elsif l_pa_exp_date_default = 'INVGLDT' then
1299 		p_token_value2 := 'Transaction GL date does not fall between award start date and award end date';
1300 	elsif l_pa_exp_date_default = 'INVSYSDT' then
1301 		p_token_value2 := 'Transaction System Date does not fall between award start date and award end date';
1302 	elsif  l_pa_exp_date_default = 'POTRNSDT' then
1303 		p_token_value2 := 'Source Document date does not fall between award start date and award end date';
1304 	END IF;
1305 
1306 elsif V_Gms_Message='GMS_AWARD_IS_CLOSED' then  /* Bug 14580572: Removed Space */
1307 
1308 p_token_value2 := 'The close date for this award has passed.  Expenses cannot be charged to an award after its close date.'; /*  Added the changes for bug 16193073 */ /*Modified for bug 16401667 */
1309 elsif V_Gms_Message='GMS_AWARD_NOT_ACTIVE' then /* Bug 14580572: Removed Space */
1310 
1311 p_token_value2 := 'This award is closed or on hold. Expenses cannot be charged to an award if it has a status of closed or on hold.';/*  Added the changes for bug 16193073 */ /*Modified for bug#16401667 */
1312 
1313 elsif V_Gms_Message='GMS_UNEXPECTED_ERROR' then
1314 
1315 p_token_value2 := 'An unexpected program error has occurred';
1316 
1317 elsif V_Gms_Message is NULL then  /*If the award is fine, then populate the token with a blank message such that nothing is displayed in its place */
1318 
1319 p_token_value2 := ' ';
1320 
1321 end if;
1322 
1323    CASE l_pa_exp_date_default
1324          WHEN 'INVTRNSDT' THEN
1325 
1326 		/* Validate the Transaction Date and if not valid then collect the error message into p_pa_message */
1327 		Validate_EI_Date(V_Gms_Message, V_MsgName1,p_transaction_date,l_po_exp_item_date,l_pa_exp_date_default,l_return_date,p_pa_message_name,p_is_date_valid);
1328 
1329 
1330          WHEN 'INVGLDT' THEN
1331 
1332 		Validate_EI_Date(V_Gms_Message, V_MsgName1,p_gl_date,l_po_exp_item_date,l_pa_exp_date_default,l_return_date,p_pa_message_name,p_is_date_valid);
1333 
1334 
1335          WHEN 'INVSYSDT' THEN
1336 
1337 		Validate_EI_Date(V_Gms_Message, V_MsgName1,sysdate,l_po_exp_item_date,l_pa_exp_date_default,l_return_date,p_pa_message_name,p_is_date_valid);
1338 
1339 
1340             WHEN 'POTRNSDT' THEN
1341               IF p_po_exp_item_date is not NULL then
1342                  l_return_date := p_po_exp_item_date  ;
1343 
1344 		/* Validate the Source Document Date and if not valid then return the generic error message  */
1345 		/*  Added this validation for bug 16193073 */
1346 
1347 		Validate_EI_Date(V_Gms_Message, V_MsgName1,p_po_exp_item_date,l_po_exp_item_date,l_pa_exp_date_default,l_return_date,p_pa_message_name,p_is_date_valid);
1348 
1349 		IF p_pa_message_name IS NULL THEN  		/*  Added this IF for bug 16193073 */
1350 
1351 		l_pa_date := pa_utils2.get_pa_date(	l_return_date, SYSDATE, pa_moac_utils.get_current_org_id);
1352 
1353 			IF l_pa_date is not NULL THEN
1354 			p_pa_message_name := NULL;
1355 			p_is_date_valid := 'Y';
1356 			ELSE
1357 			p_pa_message_name := 'PA_PO_MATCH_DER_DATE_INVALID';
1358 			p_token_value1 := ' ';/* 14529067 */
1359 			p_token_value2 := ' ';/* 14529067 */
1360 			g_po_match_date := p_po_exp_item_date;
1361 			p_is_date_valid := 'N';
1362 
1363 			END IF;
1364 
1365 		END IF; 		/*  16193073 */
1366 
1367               ELSE
1368 
1369 	                IF l_pa_debug_flag = 'Y' THEN
1370 		           IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
1371 			      FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION', 'PO expenditure item date is NULL') ;
1372 	                   END IF ;
1373 	                END IF ;
1374 
1375 			IF p_po_distribution_id is not NULL then
1376 
1377 			open c_po_date ;
1378 			fetch c_po_date into l_return_date ;
1379 			close c_po_date ;
1380 
1381 		/* Validate the Source Document Date and if not valid then return the generic error message  */
1382 
1383 		/*  Added this validation for bug 16193073 */
1384 
1385 		Validate_EI_Date(V_Gms_Message, V_MsgName1,l_po_exp_item_date,p_po_exp_item_date,l_pa_exp_date_default,l_return_date,p_pa_message_name,p_is_date_valid);
1386 
1387 		l_pa_date := pa_utils2.get_pa_date(	l_return_date, SYSDATE, pa_moac_utils.get_current_org_id);
1388 
1389 		IF p_pa_message_name IS NULL THEN  		/*  Added this IF for bug 16193073 */
1390 
1391 			IF l_pa_date is not NULL THEN
1392 			p_pa_message_name := NULL;
1393 			p_is_date_valid := 'Y';
1394 			ELSE
1395 			p_pa_message_name := 'PA_PO_MATCH_DER_DATE_INVALID';
1396 			p_token_value1 := ' ';/* 14529067 */
1397 			p_token_value2 := ' ';/* 14529067 */
1398 			g_po_match_date := p_po_exp_item_date;
1399 
1400 			/*  Added this  for bug 16193073 */
1401 			IF (p_po_exp_item_date is null) Then
1402 				g_po_match_date := l_po_exp_item_date;
1403 			END IF;
1404 			/*  End this validation for bug 16193073 */
1405 			p_is_date_valid := 'N';
1406 
1407 			END IF;
1408 
1409 		END IF; 		/*  16193073 */
1410 
1411 
1412 			IF l_pa_debug_flag = 'Y' THEN
1413 			IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
1414                          FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION','Determining the date based on the PO distribution IDL') ;
1415 			END IF ;
1416 	                END IF ;
1417 
1418 		ELSE
1419 
1420 			-- In the case of unmatched invoice the Invoice date must get @ defaulted as the EI date.
1421 			l_return_date := p_transaction_date ;
1422 
1423 			END IF ;
1424 
1425 	         END IF ;
1426 
1427 	/* Added for bug 15934260 */
1428         if
1429         (
1430         nvl(V_MsgName1,' ') = 'PA_EXP_ORG_NOT_ACTIVE'
1431         or nvl(V_MsgName1,' ') = 'PA_NEW_TXNS_NOT_ALLOWED'
1432         or nvl(V_MsgName1,' ') = 'PA_PROJECT_NOT_VALID'
1433         or nvl(V_MsgName1,' ') = 'PA_INVALID_EXPENDITURE_TYPE'
1434         or nvl(V_MsgName1,' ') = 'PA_EX_TEMPLATE_PROJECT'
1435         or nvl(V_MsgName1,' ') = 'PA_EX_PROJECT_CLOSED'
1436         or nvl(V_MsgName1,' ') = 'PA_EX_QTY_EXIST'
1437         or nvl(V_Gms_Message,' ') = 'GMS_AWARD_REQUIRED'
1438         or nvl(V_Gms_Message,' ') = 'GMS_NOT_FUNDING_AWARD'
1439         or nvl(V_Gms_Message,' ') = 'GMS_AWARD_IS_CLOSED'
1440         or nvl(V_Gms_Message,' ') = 'GMS_UNEXPECTED_ERROR'
1441         or nvl(V_Gms_Message,' ') = 'GMS_NOT_A_SPONSORED_PROJECT'
1442         or nvl(V_Gms_Message,' ') = 'GMS_INVALID_EXP_TYPE'
1443         or nvl(V_Gms_Message,' ') = 'GMS_INVALID_AWARD'
1444 	or nvl(V_Gms_Message,' ') = 'GMS_AWARD_NOT_ACTIVE'
1445         )
1446         then
1447 
1448         p_pa_message_name := 'PA_PO_MATCH_ERR';
1449         p_exp_item_date := l_return_date;
1450         g_po_match_date := l_return_date;
1451         p_is_date_valid := 'N';
1452 
1453         end if;
1454         /* Added for bug 15934260 */
1455 
1456          ELSE
1457                 l_return_date := NULL ;
1458 
1459    END CASE;
1460 
1461     IF l_pa_debug_flag = 'Y' THEN
1462       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_STATEMENT) THEN
1463          FND_LOG.string(FND_LOG.LEVEL_STATEMENT,'PA_AP_INTEGRATION', 'Date returned :'||to_char(l_return_date, 'DD-MON-YYYY')) ;
1464       END IF ;
1465    END IF ;
1466 
1467    /* Added for bug 16312792 */
1468    IF nvl(l_DESTINATION_TYPE_CODE,'X') = 'INVENTORY' THEN
1469       IF V_MsgName1 = 'EXP_TYPE_INACTIVE' OR
1470          V_MsgName1 = 'PA_INVALID_EXPENDITURE_TYPE' OR
1471          V_MsgName1 = 'INVALID_ETYPE_SYSLINK' OR
1472          V_MsgName1 = 'ETYPE_SLINK_INACTIVE' OR
1473          V_MsgName1 = 'INVALID_PA_DATE' OR
1474          V_MsgName1 = 'PA_EXP_ORG_NOT_ACTIVE' OR
1475          V_Gms_Message='GMS_INVALID_EXP_TYPE' OR
1476          V_Gms_Message='GMS_EXP_ITEM_DATE_INVALID' THEN
1477 
1478               V_MsgName1 := NULL;
1479               V_Gms_Message := NULL;
1480               p_token_value1 := NULL;
1481               p_token_value2 := NULL;
1482 		          p_is_date_valid := 'Y';
1483 		          p_pa_message_name	:= NULL;
1484 
1485       END IF;
1486    END IF;
1487    /* Added for bug 16312792 */
1488 
1489     p_exp_item_date := l_return_date ;
1490 
1491 /*  Added the changes for bug 16193073 */
1492 
1493 IF (trim(p_token_value1) is not null ) THEN
1494 p_token_value1  := '1.'||p_token_value1;
1495 END IF;
1496 IF (trim(p_token_value1) is not null  AND trim(p_token_value2) is not null ) THEN
1497 p_token_value2  := '2.'||p_token_value2;
1498 END IF;
1499 IF (trim(p_token_value1) is null AND trim(p_token_value2) is not null ) THEN
1500  p_token_value2  := '1.'||p_token_value2;
1501 END IF;
1502 
1503 /*  End for bug 16193073 */
1504 EXCEPTION
1505 
1506    WHEN OTHERS THEN
1507 
1508      RAISE;
1509 
1510 END Get_Po_Match_Si_Exp_Item_Date;
1511 
1512 
1513 PROCEDURE Validate_Ei_Date(
1514 			gms_message	IN  VARCHAR2 DEFAULT NULL,
1515 			pa_message		IN  VARCHAR2 DEFAULT NULL  ,
1516 			profile_date		IN   DATE DEFAULT NULL  ,
1517 			source_doc_date	IN   DATE DEFAULT NULL  ,
1518 			profile			IN   VARCHAR2 DEFAULT NULL  ,
1519 			x_exp_item_date			OUT NOCOPY DATE,
1520 			x_pa_message_name		OUT NOCOPY VARCHAR2,
1521 			x_is_date_valid			OUT NOCOPY VARCHAR2
1522 )
1523 IS
1524 
1525 l_pa_date	DATE;
1526 
1527 BEGIN
1528 
1529 
1530 if nvl(gms_message,' ') = ' ' and nvl(pa_message,' ') = ' ' then
1531 
1532 /* both award and project are ok */
1533 
1534 x_exp_item_date  := profile_date ;
1535 x_is_date_valid := 'Y';
1536 x_pa_message_name := NULL;
1537 
1538 elsif
1539 (
1540 nvl(pa_message,' ') = 'PA_EXP_ORG_NOT_ACTIVE'   		/* changed gms_message to pa_message for bug 16193073 */
1541 or nvl(pa_message,' ') = 'PA_NEW_TXNS_NOT_ALLOWED'    /* changed gms_message to pa_message for bug 16193073 */
1542 or nvl(pa_message,' ') = 'PA_PROJECT_NOT_VALID'			/* changed gms_message to pa_message for bug 16193073 */
1543 or nvl(pa_message,' ') = 'PA_INVALID_EXPENDITURE_TYPE'	/* changed gms_message to pa_message for bug 16193073 */
1544 or nvl(pa_message,' ') = 'PA_EX_TEMPLATE_PROJECT'		/* changed gms_message to pa_message for bug 16193073 */
1545 or nvl(pa_message,' ') = 'PA_EX_PROJECT_CLOSED'		/* changed gms_message to pa_message for bug 16193073 */
1546 or nvl(pa_message,' ') = 'PA_EX_QTY_EXIST'				/* changed gms_message to pa_message for bug 16193073 */
1547 or nvl(gms_message,' ') = 'GMS_AWARD_REQUIRED'
1548 or nvl(gms_message,' ') = 'GMS_NOT_FUNDING_AWARD'
1549 or nvl(gms_message,' ') = 'GMS_AWARD_IS_CLOSED'
1550 or nvl(gms_message,' ') = 'GMS_UNEXPECTED_ERROR'
1551 or nvl(gms_message,' ') = 'GMS_NOT_A_SPONSORED_PROJECT'
1552 or nvl(gms_message,' ') = 'GMS_INVALID_EXP_TYPE'
1553 or nvl(gms_message,' ') = 'GMS_INVALID_AWARD'
1554 or nvl(gms_message,' ') = 'GMS_AWARD_NOT_ACTIVE'
1555 )
1556 then
1557 
1558 x_pa_message_name := 'PA_PO_MATCH_ERR';
1559 x_exp_item_date := source_doc_date;
1560 g_po_match_date := source_doc_date;
1561 x_is_date_valid := 'N';
1562 
1563 else
1564 
1565 /*either award or project is not ok or both award and project are not ok*/
1566 
1567 l_pa_date := pa_utils2.get_pa_date(	source_doc_date, SYSDATE, pa_moac_utils.get_current_org_id);
1568 
1569 			if l_pa_date is not null then
1570 
1571 				if profile = 'INVGLDT' then
1572 				x_pa_message_name := 'PA_PO_MATCH_GL_DATE_INVALID';
1573 				elsif profile = 'INVTRNSDT' then
1574 				x_pa_message_name := 'PA_PO_MATCH_TXN_DATE_INVALID';
1575 				elsif profile = 'INVSYSDT' then
1576 				x_pa_message_name := 'PA_PO_MATCH_TXNSYS_INVALID';
1577 				end if;
1578 
1579 
1580 
1581 
1582 			else
1583 
1584 				if profile = 'INVGLDT' then
1585 				x_pa_message_name := 'PA_PO_MATCH_GL_DATE_ERR';
1586 				elsif profile = 'INVTRNSDT' then
1587 				x_pa_message_name := 'PA_PO_MATCH_TXN_DATE_ERR';
1588 				elsif profile = 'INVSYSDT' then
1589 				x_pa_message_name := 'PA_PO_MATCH_TXNSYS_ERR';
1590 				end if;
1591 
1592 
1593 			end if;
1594 
1595 				x_exp_item_date := source_doc_date;
1596 				g_po_match_date := source_doc_date;
1597 				x_is_date_valid := 'N';
1598 
1599 
1600 end if;
1601 
1602 exception
1603 
1604 when others then
1605 
1606 raise;
1607 
1608 END Validate_Ei_Date;
1609 
1610 /*13706985  - End*/
1611 
1612 END pa_ap_integration;