DBA Data[Home] [Help]

PACKAGE BODY: APPS.AP_WEB_ACCTG_PKG

Source


1 PACKAGE BODY AP_WEB_ACCTG_PKG AS
2 /* $Header: apwacctb.pls 120.14.12010000.3 2008/10/22 09:33:03 meesubra ship $ */
3 
4 --Cache for FND_FLEX_APIS.GET_QUALIFIER_SEGNUM
5 gqs_cost_center_segnum t_cost_center_segnum_table;
6 
7 PROCEDURE GetEmployeeCostCenter(
8         p_employee_id                   IN NUMBER,
9         p_emp_ccid                      IN NUMBER,
10         p_cost_center                   OUT NOCOPY VARCHAR2) IS
11 
12   l_debug_info varchar2(200);
13 
14 BEGIN
15 
16   --
17   -- Call CustomDefaultCostCenter for cost center, otherwise retrieve
18   -- cost center segment by deriving from employee ccid.
19   --
20    -----------------------------------------------------
21    l_debug_info := 'AP_WEB_CUST_DFLEX_PKG.CustomDefaultCostCenter';
22    -----------------------------------------------------
23   p_cost_center := AP_WEB_CUST_DFLEX_PKG.CustomDefaultCostCenter(p_employee_id);
24 
25   if (p_cost_center is null) then
26     p_cost_center := GetCostCenter(p_emp_ccid);
27   end if;
28 END GetEmployeeCostCenter;
29 
30 FUNCTION GetCostCenter(
31         p_ccid                          IN NUMBER,
32         p_chart_of_accounts_id          IN NUMBER)
33 RETURN VARCHAR2 IS
34 
35   l_debug_info varchar2(200);
36 
37   l_chart_of_accounts_id        number := p_chart_of_accounts_id;
38   l_segments                    FND_FLEX_EXT.SEGMENTARRAY;
39   l_num_of_segments             NUMBER;
40   l_cost_ctr_seg_num            NUMBER;
41 
42 BEGIN
43 
44   -- Only get the chart of accounts ID if none/null is passed in
45   IF (l_chart_of_accounts_id IS NULL) THEN
46     -----------------------------------------------------
47     l_debug_info := 'AP_WEB_DB_AP_INT_PKG.GetCOAofSOB';
48     -----------------------------------------------------
49     IF (NOT AP_WEB_DB_AP_INT_PKG.GetCOAofSOB(l_chart_of_accounts_id)) THEN
50       l_chart_of_accounts_id := NULL;
51     END IF;
52   END IF;
53 
54     -----------------------------------------------------
55     l_debug_info := 'Retrieve segments from code combination id';
56     -----------------------------------------------------
57     IF (NOT FND_FLEX_EXT.GET_SEGMENTS('SQLGL',
58                                       'GL#',
59                                       l_chart_of_accounts_id,
60                                       p_ccid,
61                                       l_num_of_segments,
62                                       l_segments)) THEN
63       return NULL;
64     END IF;
65 
66     -----------------------------------------------------
67     l_debug_info := 'Get Cost Center segment number';
68     -----------------------------------------------------
69     BEGIN
70       -- Check cache
71       l_cost_ctr_seg_num := gqs_cost_center_segnum(l_chart_of_accounts_id);
72     EXCEPTION
73         -- Not found in cache, retrieve segment number
74         WHEN NO_DATA_FOUND THEN
75       IF (NOT FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(
76                                           101,
77                                           'GL#',
78                                           l_chart_of_accounts_id,
79                                           'FA_COST_CTR',
80                                           l_cost_ctr_seg_num)) THEN
81         return NULL;
82       END IF;
83 
84       -- Put segment number in cache for chart of accounts ID
85       gqs_cost_center_segnum(l_chart_of_accounts_id) := l_cost_ctr_seg_num;
86     END;
87     -----------------------------------------------------
88     l_debug_info := 'Get Cost Center segment';
89     -----------------------------------------------------
90     return l_segments(l_cost_ctr_seg_num);
91 
92 
93 EXCEPTION
94  WHEN OTHERS THEN
95    AP_WEB_DB_UTIL_PKG.RaiseException( 'GetCostCenter' );
96    APP_EXCEPTION.RAISE_EXCEPTION;
97 
98 END GetCostCenter;
99 
100 
101 PROCEDURE GetCostCenterApprovalRule(
102         p_alphanumeric_allowed_flag     OUT NOCOPY      VARCHAR2,
103         p_uppercase_only_flag           OUT NOCOPY      VARCHAR2,
104         p_numeric_mode_enabled_flag     OUT NOCOPY      VARCHAR2,
105         p_maximum_size                  OUT NOCOPY      NUMBER) IS
106 
107   l_debug_info varchar2(200);
108 
109 l_chart_of_accounts_id      gl_sets_of_books.chart_of_accounts_id%type;
110 l_cost_center_seg_num       NUMBER;
111 l_appcol_name               fnd_id_flex_segments_vl.application_column_name%type;
112 l_seg_name                  fnd_id_flex_segments_vl.segment_name%type;
113 l_prompt                    fnd_id_flex_segments_vl.form_left_prompt%type;
114 l_value_set_name            fnd_flex_value_sets.flex_value_set_name%type;
115 
116 BEGIN
117 
118     -----------------------------------------------------
119     l_debug_info := 'AP_WEB_DB_AP_INT_PKG.GetCOAofSOB';
120     -----------------------------------------------------
121    IF (NOT AP_WEB_DB_AP_INT_PKG.GetCOAofSOB(l_chart_of_accounts_id)) THEN
122         l_chart_of_accounts_id := NULL;
123    END IF;
124 
125     -----------------------------------------------------
126     l_debug_info := 'Get the segment number corresponding to the costcenter qualifier.';
127     -----------------------------------------------------
128    IF (NOT FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(
129                                 101,
130                                 'GL#',
131                                 l_chart_of_accounts_id,
132                                 'FA_COST_CTR',
133                                 l_cost_center_seg_num)) then
134      return;
135    END IF;
136 
137     -----------------------------------------------------
138     l_debug_info := 'Get the valueset associated with the Department (costcenter qualifier)';
139     -----------------------------------------------------
140    IF (NOT FND_FLEX_APIS.GET_SEGMENT_INFO(
141                                 101,
142                                 'GL#',
143                                 l_chart_of_accounts_id,
144                                 l_cost_center_seg_num,
145                                 l_appcol_name,
146                                 l_seg_name,
147                                 l_prompt,
148                                 l_value_set_name)) then
149      return;
150    END IF;
151 
152     -----------------------------------------------------
153     l_debug_info := 'Get Cost Center Approval rules';
154     -----------------------------------------------------
155    select alphanumeric_allowed_flag, uppercase_only_flag, numeric_mode_enabled_flag, maximum_size
156    into p_alphanumeric_allowed_flag, p_uppercase_only_flag ,p_numeric_mode_enabled_flag, p_maximum_size
157    from fnd_flex_value_sets
158    where flex_value_set_name like l_value_set_name;
159 
160 EXCEPTION
161  WHEN OTHERS THEN
162    AP_WEB_DB_UTIL_PKG.RaiseException( 'GetCostCenterApprovalRule' );
163    APP_EXCEPTION.RAISE_EXCEPTION;
164 
165 END GetCostCenterApprovalRule;
166 
167 
168 /*Bug 2690715 : Declared a function to get the dependent segment
169                 of cost center segment.
170 */
171 FUNCTION GetDependentSegment(
172         p_value_set_name        IN     fnd_flex_value_sets.flex_value_set_name%type,
173         p_chart_of_accounts_id  IN AP_WEB_DB_AP_INT_PKG.glsob_chartOfAccountsID,
174         p_dependent_seg_num     OUT NOCOPY  NUMBER) RETURN BOOLEAN IS
175 
176         l_parent_flex_value_set_id fnd_flex_value_sets.parent_flex_value_set_id%type;
177 
178 BEGIN
179 
180           select PARENT_FLEX_VALUE_SET_ID into l_parent_flex_value_set_id
181           from fnd_flex_value_sets
182           where flex_value_set_name like p_value_set_name
183           and PARENT_FLEX_VALUE_SET_ID is not null;
184 
185         IF (l_parent_flex_value_set_id IS NOT NULL) THEN
186 
187           SELECT s.segment_num into p_dependent_seg_num
188           FROM fnd_id_flex_segments s, fnd_segment_attribute_values sav,
189           fnd_segment_attribute_types sat
190             WHERE s.application_id = 101
191             AND s.id_flex_code = 'GL#'
192             AND s.id_flex_num = p_chart_of_accounts_id
193             AND s.enabled_flag = 'Y'
194             AND s.application_column_name = sav.application_column_name
195             AND sav.application_id = 101
196             AND sav.id_flex_code = 'GL#'
197             AND sav.id_flex_num = p_chart_of_accounts_id
198             AND sav.attribute_value = 'Y'
199             AND sav.segment_attribute_type = sat.segment_attribute_type
200             AND sat.application_id = 101
201             AND sat.id_flex_code = 'GL#'
202             AND sat.unique_flag = 'Y'
203             AND s.FLEX_VALUE_SET_ID=l_parent_flex_value_set_id
204             AND rownum =1;
205    END IF;
206 
207 
208         return TRUE;
209 
210 EXCEPTION
211   WHEN NO_DATA_FOUND THEN
212     return FALSE;
213   WHEN OTHERS THEN
214     AP_WEB_DB_UTIL_PKG.RaiseException('GetDependentSegment');
215     APP_EXCEPTION.RAISE_EXCEPTION;
216     return FALSE;
217 END GetDependentSegment;
218 
219 
220 PROCEDURE ValidateCostCenter(
221         p_cost_center                   IN VARCHAR2,
222         p_employee_id                   IN NUMBER,
223         p_emp_set_of_books_id           IN NUMBER,
224         p_default_emp_ccid              IN VARCHAR2,
225         p_chart_of_accounts_id          IN NUMBER,
226         p_cost_center_valid             OUT NOCOPY BOOLEAN) IS
227 
228   l_debug_info varchar2(200);
229 
230 l_flex_segment_delimiter  varchar2(1);
231 l_cost_center_seg_num     number;
232 l_num_segments            number;
233 l_default_emp_segments    FND_FLEX_EXT.SEGMENTARRAY;
234 l_appcol_name               fnd_id_flex_segments_vl.application_column_name%type;
235 l_seg_name                  fnd_id_flex_segments_vl.segment_name%type;
236 l_prompt                    fnd_id_flex_segments_vl.form_left_prompt%type;
237 l_value_set_name            fnd_flex_value_sets.flex_value_set_name%type;
238 l_dependent_seg_num         number := 0;
239 l_concatenated_segments   varchar2(2000);
240 
241 BEGIN
242 
243    -- Get the character used as the segment delimiter. This would be
244    -- used to prepare the concatenated segment from segment array to a string.
245     -----------------------------------------------------
246     l_debug_info := 'Get segment delimiter';
247     -----------------------------------------------------
248    l_flex_segment_delimiter := FND_FLEX_EXT.GET_DELIMITER(
249                                         'SQLGL',
250                                         'GL#',
251                                         p_chart_of_accounts_id);
252 
253    -- Get the segment number corresponding to the costcenter qualifier.
254    -- This is used to overlay the costcenter segment
255     -----------------------------------------------------
256     l_debug_info := 'Get cost center segment number';
257     -----------------------------------------------------
258    if (NOT FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(
259                                 101,
260                                 'GL#',
261                                 p_chart_of_accounts_id,
262                                 'FA_COST_CTR',
263                                 l_cost_center_seg_num)) then
264         p_cost_center_valid := FALSE;
265         return;
266    end if;
267 
268    -- Get the segment array and number of segments for the employee
269    -- code combination id.
270     -----------------------------------------------------
271     l_debug_info := 'Get employee default segments';
272     -----------------------------------------------------
273    if (NOT FND_FLEX_EXT.GET_SEGMENTS(
274                                 'SQLGL',
275                                 'GL#',
276                                 p_chart_of_accounts_id,
277                                 p_default_emp_ccid,
278                                 l_num_segments,
279                                 l_default_emp_segments)) then
280         p_cost_center_valid := FALSE;
281         return;
282     end if;
283 
284     /*Bug 2690715 : Called function to get the dependent segment
285                 of cost center segment and then do the validation.
286     */
287     -----------------------------------------------------
288     l_debug_info := 'FND_FLEX_APIS.GET_SEGMENT_INFO';
289     -----------------------------------------------------
290     IF (FND_FLEX_APIS.GET_SEGMENT_INFO(
291                                     101,
292                                     'GL#',
293                                     p_chart_of_accounts_id,
294                                     l_cost_center_seg_num,
295                                     l_appcol_name,
296                                     l_seg_name,
297                                     l_prompt,
298                                     l_value_set_name)) then
299 
300         -----------------------------------------------------
301         l_debug_info := 'GetDependentSegment';
302         -----------------------------------------------------
303         IF (GetDependentSegment(l_value_set_name,
304                             p_chart_of_accounts_id,
305                             l_dependent_seg_num)) THEN
306                 NULL;
307         END IF;
308 
309     END IF;
310 
311 /*Bug 2690715 : Dont set the segment to NULL , if dependent valueset
312                 of cost center segment exists.
313 */
314    IF (l_dependent_seg_num IS NULL) THEN
315     FOR i in 1 .. l_num_segments LOOP
316        l_default_emp_segments(i) := '';
317     END LOOP;
318    END IF;
322     -----------------------------------------------------
319 
320     -- Overlay the costcenter segment with the costcenter entered in the
321     -- expense report
323     l_debug_info := 'Overlay cost center segment with expense report cost center';
324     -----------------------------------------------------
325     l_default_emp_segments(l_cost_center_seg_num) := p_cost_center;
326 
327     -- Get the concatenated segments with all segments set to null, except the
328     -- costcenter, Concatenates segments from segment array
329     -- (l_default_emp_segments) to a string(l_concatenated_segments).
330     -----------------------------------------------------
331     l_debug_info := 'Concatenate segments';
332     -----------------------------------------------------
333     l_concatenated_segments :=  FND_FLEX_EXT.concatenate_segments(l_num_segments,
334                                 l_default_emp_segments,
335                                 l_flex_segment_delimiter);
336 
337     /* -----------------------------------------------------------------------+
338     + Validate only the costcenter segment, since we are passing other        +
339     + segments as null we need to set allow_nulls to true                     +
340     + Allow_nulls will allow required segments that are NULL to be valid      +
341     + allow_orphans will validate dependent segment values without associated +
342     + parent values, allowing ANY possible dependent value, regardless        +
343     + of what the parent value would be,  to be considered valid.             +
344     +------------------------------------------------------------------------*/
345 /*Bug 2706584: Passed VRULE as a parameter to Validate_Segs so that
346                it does not pass the cost center for which
347                Posting Allowed is  Unchecked.
348 */
349 
350 /*Bug 2690715:Validate using only segment of COST CENTER if
351               No Dependent Segment is present.Else validate
352               using Combination,Flex Field does not support
353               partial combination validation. i.e Like 01-520----
354              can not be successfully validated.
355 */
356     -----------------------------------------------------
357     l_debug_info := 'Validate segments';
358     -----------------------------------------------------
359 IF (l_dependent_seg_num IS NULL) THEN
360     if ( fnd_flex_keyval.validate_segs(operation=>'CHECK_SEGMENTS',
361                appl_short_name=>'SQLGL',
362                key_flex_code=>'GL#',
363                structure_number=>p_chart_of_accounts_id,
364                concat_segments=>l_concatenated_segments,
365                VRULE=>'GL_GLOBAL\nDETAIL_POSTING_ALLOWED\nI\nNAME=AP_ALL_POSTING_NA\nY\0\nSUMMARY_FLAG\nI\nNAME=Flex-Parent not allowed\nN',
366                allow_nulls=>TRUE,
367                allow_orphans=>TRUE ) ) then
368         p_cost_center_valid := TRUE;
369         return;
370     else
371         p_cost_center_valid := FALSE;
372         return;
373     end if;
374 ELSE
375     if ( fnd_flex_keyval.validate_segs(operation=>'CHECK_COMBINATION',
376                appl_short_name=>'SQLGL',
377                key_flex_code=>'GL#',
378                structure_number=>p_chart_of_accounts_id,
379                concat_segments=>l_concatenated_segments,
380                VRULE=>'GL_GLOBAL\nDETAIL_POSTING_ALLOWED\nI\nNAME=AP_ALL_POSTING_NA\nY\0\nSUMMARY_FLAG\nI\nNAME=Flex-Parent not allowed\nN',
381                allow_nulls=>TRUE,
382                allow_orphans=>TRUE ) ) then
383         p_cost_center_valid := TRUE;
384         return;
385     else
386         p_cost_center_valid := FALSE;
387         return;
388     end if;
389 END IF;
390 
391 EXCEPTION
392         WHEN NO_DATA_FOUND THEN
393                 p_cost_center_valid := FALSE;
394 
395         WHEN OTHERS THEN
396                 p_cost_center_valid := FALSE;
397 
398 END ValidateCostCenter;
399 
400 
401 PROCEDURE GetExpenseTypeCostCenter(
402         p_exp_type_parameter_id		IN NUMBER,
403         p_cost_center			OUT NOCOPY VARCHAR2) IS
404 
405   l_debug_info varchar2(200);
406 
407 l_chart_of_accounts_id    number;
408 l_flex_segment_delimiter  varchar2(1);
409 l_cost_center_seg_num     number;
410 l_num_segments            number;
411 l_exp_type_template_array       FND_FLEX_EXT.SEGMENTARRAY;
412 l_FlexConcactenated       AP_EXPENSE_REPORT_PARAMS.flex_concactenated%TYPE;
413 
414 BEGIN
415 
416     -----------------------------------------------------
417     l_debug_info := 'AP_WEB_DB_AP_INT_PKG.GetCOAofSOB';
418     -----------------------------------------------------
419    IF (NOT AP_WEB_DB_AP_INT_PKG.GetCOAofSOB(l_chart_of_accounts_id)) THEN
420         l_chart_of_accounts_id := NULL;
421    END IF;
422 
423    -- Get the character used as the segment delimiter. This would be
424    -- used to prepare the concatenated segment from segment array to a string.
425     -----------------------------------------------------
426     l_debug_info := 'Get segment delimeter';
427     -----------------------------------------------------
428    l_flex_segment_delimiter := FND_FLEX_EXT.GET_DELIMITER(
429                                         'SQLGL',
430                                         'GL#',
431                                         l_chart_of_accounts_id);
432 
433    -- Get the segment number corresponding to the costcenter qualifier.
434    -- This is used to get the cost center for the expense type
435     -----------------------------------------------------
436     l_debug_info := 'Get segment number';
440                                 'GL#',
437     -----------------------------------------------------
438    if (NOT FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(
439                                 101,
441                                 l_chart_of_accounts_id,
442                                 'FA_COST_CTR',
443                                 l_cost_center_seg_num)) then
444         return;
445    end if;
446 
447    begin
448     -----------------------------------------------------
449     l_debug_info := 'Get FLEX_CONCACTENATED';
450     -----------------------------------------------------
451      SELECT FLEX_CONCACTENATED into l_FlexConcactenated
452      FROM   ap_expense_report_params_all
453      WHERE parameter_id = p_exp_type_parameter_id;
454    exception
455      when others then
456        return;
457    end;
458 
459    /* Bug 4212250: Since l_FlexConcactenated is null, no need to
460     *              proceed further.
461     */
462    IF l_FlexConcactenated IS NULL THEN
463       return;
464    END IF;
465 
466     -----------------------------------------------------
467     l_debug_info := 'Break up segments';
468     -----------------------------------------------------
469    l_num_segments := FND_FLEX_EXT.Breakup_Segments(l_FlexConcactenated,
470                                                     l_flex_segment_delimiter,
471                                                     l_exp_type_template_array);
472 
473    IF nvl(l_num_segments,0) = 0 THEN
474       return;
475    ELSE
476       IF (l_exp_type_template_array(l_cost_center_seg_num) IS NOT NULL) THEN
477          p_cost_center := l_exp_type_template_array(l_cost_center_seg_num);
478       ELSE
479          return;
480       END IF;
481    END IF;
482 
483 EXCEPTION
484  WHEN OTHERS THEN
485    AP_WEB_DB_UTIL_PKG.RaiseException( 'GetExpenseTypeCostCenter' );
486    APP_EXCEPTION.RAISE_EXCEPTION;
487 
488 END GetExpenseTypeCostCenter;
489 
490 
491 PROCEDURE GetCostCenterSegmentName(
492         p_cost_center_segment_name      OUT NOCOPY VARCHAR2) IS
493 
494   l_debug_info varchar2(200);
495 
496   l_chart_of_accounts_id    number;
497 
498 BEGIN
499 
500       /* This query will exclude terminated contingent
501          workers and terminated employees who became
502          contingent workers to avoid duplicate rows.
503          Otherwise 2 rows for the same person could be
504          possible. */
505       -- Query up the Chart of Accounts Id for the Employee
506       SELECT GS.chart_of_accounts_id
507       INTO   l_chart_of_accounts_id
508       FROM   ap_system_parameters S,
509              gl_sets_of_books GS
510       WHERE  GS.set_of_books_id = S.set_of_books_id
511       AND    rownum = 1;
512       -- Get the Column Name which implements the Cost Center Segment
513       IF ( FND_FLEX_APIS.GET_SEGMENT_COLUMN(101,
514                                             'GL#',
515                                             l_chart_of_accounts_id,
516                                             'FA_COST_CTR',
517                                             p_cost_center_segment_name) )
518       THEN
519          RETURN;
520       ELSE
521          -- RAISE EXCEPTION THAT COST CTR IMPLEMENTATION COULD NOT BE FOUND!!!
522          p_cost_center_segment_name := 'SEGMENT2';
523          RETURN;
524       END IF;
525 
526       EXCEPTION
527          WHEN NO_DATA_FOUND THEN
528             -- RAISE EXCEPTION FOR INVALID CHART OF ACCOUNTS
529             p_cost_center_segment_name := 'SEGMENT2';
530             RETURN;
531          WHEN OTHERS THEN
532             -- RAISE SOME EXCEPTION
533             p_cost_center_segment_name := 'SEGMENT2';
534             RETURN;
535 
536 END GetCostCenterSegmentName;
537 
538 
539 -------------------------------------------------------------------------
540 --
541 -- PROCEDURE GetDistributionSegments
542 --
543 -- Parameters
544 --        p_chart_of_accounts_id          Flexfield structure num
545 --        p_report_distribution_id        report_distribution_id
546 --        p_segments                      AP_OIE_KFF_SEGMENTS_T
547 --
548 -- Returns VARCHAR2
549 --   Returns the segment values array of the key flexfield
550 --
551 -- Description
552 --   There is no equivalent for this function. This function takes
553 --   the segment values stored in ap_exp_report_dists and returns
554 --   the segment values array according to the kff structure.
555 --
556 -- Modification History
557 --  ALING    30-SEP-04        Created.
558 --
559 -------------------------------------------------------------------------
560 PROCEDURE GetDistributionSegments(
561         p_chart_of_accounts_id          IN    GL_SETS_OF_BOOKS.chart_of_accounts_id%TYPE,
562         p_report_distribution_id        IN    NUMBER,
563         p_segments                      OUT NOCOPY AP_OIE_KFF_SEGMENTS_T) IS
564 --------------------------------------------------------------------------------
565 
566   l_debug_info                  VARCHAR2(1000);
567   sqlstmt                       varchar2(2000);
568   colname                       fnd_id_flex_segments.application_column_name%type;
569   c                             integer;
570   l_concat_segments             VARCHAR2(1000);
571   rows                          integer;
572   l_num_segments                NUMBER;
576 cursor cflex(p_chart_accounts_id IN NUMBER) is
573   l_segment_array               FND_FLEX_EXT.SEGMENTARRAY;
574   l_flex_segment_delimiter  varchar2(1);
575 
577   SELECT flex.application_column_name
578   FROM   fnd_id_flex_segments flex
579   WHERE  flex.application_id = 101
580   AND    flex.id_flex_code = 'GL#'
581   AND    flex.id_flex_num = p_chart_accounts_id
582   AND    flex.enabled_flag='Y'
583   AND    flex.display_flag='Y'
584   order by segment_num;
585 
586 BEGIN
587 
588    -- Get the character used as the segment delimiter. This would be
589    -- used to prepare the concatenated segment from segment array to a string.
590     -----------------------------------------------------
591     l_debug_info := 'Get segment delimiter';
592     -----------------------------------------------------
593    l_flex_segment_delimiter := FND_FLEX_EXT.GET_DELIMITER(
594                                         'SQLGL',
595                                         'GL#',
596                                         p_chart_of_accounts_id);
597 
598   ------------------------------------------------------------
599   l_debug_info := 'First build the select statment';
600   ------------------------------------------------------------
601   sqlstmt := null;
602   if cflex%isopen then close cflex;
603   end if;
604 
605   open cflex(p_chart_of_accounts_id);
606 
607     LOOP
608       FETCH cflex INTO colname;
609       EXIT WHEN cflex%NOTFOUND;
610 
611         IF sqlstmt IS NOT NULL THEN
612           sqlstmt := sqlstmt || '||''' || l_flex_segment_delimiter || '''||' ||colname;
613         ELSE
614           sqlstmt := colname;
615         END IF;
616 
617     END LOOP;
618 
619   sqlstmt := 'SELECT '||sqlstmt||' FROM AP_EXP_REPORT_DISTS
620               WHERE report_distribution_id = :report_distribution_id';
621 
622   close cflex;
623 
624   -----------------
625   -- Now execute it
626   -----------------
627   c := dbms_sql.open_cursor;
628   -----------------------------------------------------
629   l_debug_info := 'parse cursor';
630   -----------------------------------------------------
631   dbms_sql.parse(c, sqlstmt, dbms_sql.native);
632 
633   -----------------------------------------------------
634   l_debug_info := 'bind values to the placeholder';
635   -----------------------------------------------------
636   dbms_sql.bind_variable(c, ':report_distribution_id', p_report_distribution_id);
637 
638   -----------------------------------------------------
639   l_debug_info := 'setup output';
640   -----------------------------------------------------
641   dbms_sql.define_column(c, 1, l_concat_segments, 1000);
642 
643   -----------------------------------------------------
644   l_debug_info := 'execute cursor';
645   -----------------------------------------------------
646   rows := dbms_sql.execute(c);
647 
648   -----------------------------------------------------
649   l_debug_info := 'fetch a row';
650   -----------------------------------------------------
651   IF dbms_sql.fetch_rows(c) > 0 then
652     -- fetch columns from the row
653     dbms_sql.column_value(c, 1, l_concat_segments);
654   END IF;
655 
656   dbms_sql.column_value(c, 1, l_concat_segments);
657 
658   dbms_sql.close_cursor(c);
659 
660 
661   IF cflex%isopen THEN
662      CLOSE cflex;
663   END IF;
664 
665   --------------------------------------------------------------
666   l_debug_info:='Break Up Segments';
667   --------------------------------------------------------------
668   l_num_segments := FND_FLEX_EXT.Breakup_Segments(l_concat_segments,
669                                                   l_flex_segment_delimiter,
670                                                   l_segment_array);
671 
672 
673   -----------------------------------------------------
674   l_debug_info := 'Assign values to p_segments';
675   -----------------------------------------------------
676   p_segments := AP_OIE_KFF_SEGMENTS_T('');
677   p_segments.extend(l_segment_array.count);
678   FOR i IN 1..l_segment_array.count LOOP
679         p_segments(i) := l_segment_array(i);
680   END LOOP;
681 
682 
683 EXCEPTION
684   WHEN OTHERS THEN
685     IF cflex%isopen THEN
686       close cflex;
687     END IF;
688     IF dbms_sql.is_open(c) THEN
689       dbms_sql.close_cursor(c);
690     END IF;
691 
692     IF (SQLCODE <> -20001) THEN
693       FND_MESSAGE.SET_NAME('SQLAP','AP_DEBUG');
694       FND_MESSAGE.SET_TOKEN('ERROR',SQLERRM);
695       FND_MESSAGE.SET_TOKEN('CALLING_SEQUENCE', 'GetDistributionSegments');
696       FND_MESSAGE.SET_TOKEN('DEBUG_INFO',l_debug_info);
697     END IF;
698     APP_EXCEPTION.RAISE_EXCEPTION;
699 END GetDistributionSegments;
700 
701 
702 PROCEDURE GetConcatenatedSegments(
703         p_chart_of_accounts_id          IN NUMBER,
704         p_segments                      IN AP_OIE_KFF_SEGMENTS_T,
705         p_concatenated_segments         OUT NOCOPY VARCHAR2) IS
706 
707   l_debug_info                  VARCHAR2(100);
708 
709   l_flex_segment_delimiter      VARCHAR2(1);
710   l_segments                    FND_FLEX_EXT.SEGMENTARRAY;
711 
712 BEGIN
713 
714   IF (p_chart_of_accounts_id is null) THEN
718 
715     FND_MESSAGE.Set_Name('SQLAP', 'OIE_MISS_CHART_OF_ACC_ID');
716     RAISE AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR;
717   END IF;
719   ----------------------------------------
720   l_debug_info := 'Get Segment Delimiter like .';
721   ----------------------------------------
722   l_flex_segment_delimiter := FND_FLEX_EXT.GET_DELIMITER(
723                                         'SQLGL',
724                                         'GL#',
725                                         p_chart_of_accounts_id);
726 
727   IF (l_flex_segment_delimiter IS NULL) THEN
728     RAISE AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR;
729   END IF; /* l_flex_segment_delimiter IS NULL */
730 
731   ------------------------------------------------------------------------
732   l_debug_info := 'Convert AP_OIE_KFF_SEGMENTS_T to FND_FLEX_EXT.SEGMENTARRAY';
733   ------------------------------------------------------------------------
734   FOR i IN 1..p_segments.count LOOP
735         l_segments(i) := p_segments(i);
736   END LOOP;
737 
738   ------------------------------------------------------------------------
739   l_debug_info := 'calling FND_FLEX_EXT.concatenate_segments';
740   ------------------------------------------------------------------------
741   p_concatenated_segments :=  FND_FLEX_EXT.concatenate_segments(l_segments.count,
742                               l_segments,
743                               l_flex_segment_delimiter);
744 
745 EXCEPTION
746  WHEN OTHERS THEN
747    AP_WEB_DB_UTIL_PKG.RaiseException( 'GetConcatenatedSegments' );
748    APP_EXCEPTION.RAISE_EXCEPTION;
749 
750 END GetConcatenatedSegments;
751 
752 
753 PROCEDURE BuildAccount(
754         p_report_header_id              IN NUMBER,
755         p_report_line_id                IN NUMBER,
756         p_employee_id                   IN NUMBER,
757         p_cost_center                   IN VARCHAR2,
758         p_line_cost_center              IN VARCHAR2,
759         p_exp_type_parameter_id         IN NUMBER,
760         p_segments                      IN AP_OIE_KFF_SEGMENTS_T,
761         p_ccid                          IN NUMBER,
762         p_build_mode                    IN VARCHAR2,
763         p_new_segments                  OUT NOCOPY AP_OIE_KFF_SEGMENTS_T,
764         p_new_ccid                      OUT NOCOPY NUMBER,
765         p_return_error_message          OUT NOCOPY VARCHAR2) IS
766 
767 
768   l_debug_info                  VARCHAR2(100);
769 
770   l_default_emp_ccid            AP_WEB_DB_EXPRPT_PKG.expHdr_employeeCCID;
771   l_chart_of_accounts_id        NUMBER;
772   l_cost_center_seg_num         NUMBER;
773   l_flex_segment_delimiter      VARCHAR2(1);
774   l_default_emp_segments        FND_FLEX_EXT.SEGMENTARRAY;
775   l_FlexConcactenated           AP_EXPENSE_REPORT_PARAMS.FLEX_CONCACTENATED%TYPE;
776   l_exp_type_template_array     FND_FLEX_EXT.SEGMENTARRAY;
777   l_exp_line_acct_segs_array    FND_FLEX_EXT.SEGMENTARRAY;
778   l_num_segments                NUMBER:=NULL;
779   l_concatenated_segments   varchar2(2000);
780 
781 BEGIN
782 
783   if (AP_WEB_CUS_ACCTG_PKG.BuildAccount(
784         p_report_header_id => p_report_header_id,
785         p_report_line_id => p_report_line_id,
786         p_employee_id => p_employee_id,
787         p_cost_center => p_cost_center,
788         p_exp_type_parameter_id => p_exp_type_parameter_id,
789         p_segments => p_segments,
790         p_ccid => p_ccid,
791         p_build_mode => p_build_mode,
792         p_new_segments => p_new_segments,
793         p_new_ccid => p_new_ccid,
794         p_return_error_message => p_return_error_message)) then
795 
796     --------------------------------------------------------------------
797     l_debug_info := 'Custom BuildAccount';
798     --------------------------------------------------------------------
799 
800     return;
801 
802   end if;
803 
804   if (p_build_mode not in (C_DEFAULT, C_DEFAULT_VALIDATE, C_BUILD_VALIDATE, C_VALIDATE)) then
805 
806     --------------------------------------------------------------------
807     l_debug_info := 'Invalid p_build_mode';
808     --------------------------------------------------------------------
809 
810     return;
811 
812   end if;
813 
814   -----------------------------------------------------
815   l_debug_info := 'Get the HR defaulted Employee CCID';
816   -----------------------------------------------------
817   IF (NOT AP_WEB_DB_EXPRPT_PKG.GetDefaultEmpCCID(
818          p_employee_id          => p_employee_id,
819          p_default_emp_ccid     => l_default_emp_ccid)) THEN
820       NULL;
821   END IF;
822 
823   IF (l_default_emp_ccid is null) THEN
824     FND_MESSAGE.Set_Name('SQLAP', 'AP_WEB_EXP_MISSING_EMP_CCID');
825     RAISE AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR;
826   END IF;
827 
828   -----------------------------------------------------
829   l_debug_info := 'Get the Employee Chart of Accounts ID';
830   -----------------------------------------------------
831   IF (NOT AP_WEB_DB_EXPRPT_PKG.GetChartOfAccountsID(
832          p_employee_id          => p_employee_id,
833          p_chart_of_accounts_id => l_chart_of_accounts_id)) THEN
834       NULL;
835   END IF;
836 
837   IF (l_chart_of_accounts_id is null) THEN
838     FND_MESSAGE.Set_Name('SQLAP', 'OIE_MISS_CHART_OF_ACC_ID');
839     RAISE AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR;
840   END IF;
841 
845   IF (l_default_emp_ccid IS NOT NULL) THEN
842   -----------------------------------------------------------------
843   l_debug_info := 'Get employee default ccid account segments';
844   -----------------------------------------------------------------
846     IF (NOT FND_FLEX_EXT.GET_SEGMENTS(
847                                 'SQLGL',
848                                 'GL#',
849                                 l_chart_of_accounts_id,
850                                 l_default_emp_ccid,
851                                 l_num_segments,
852                                 l_default_emp_segments)) THEN
853       RAISE AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR;
854     END IF; /* GET_SEGMENTS */
855   END IF;
856 
857   ----------------------------------------
858   l_debug_info := 'Get Cost Center Segment Number';
859   ----------------------------------------
860   IF (NOT FND_FLEX_APIS.GET_QUALIFIER_SEGNUM(
861                                 101,
862                                 'GL#',
863                                 l_chart_of_accounts_id,
864                                 'FA_COST_CTR',
865                                 l_cost_center_seg_num)) THEN
866     /* We could not find the cost center segment, but we can still overlay the
867      * expense type mask, so do nothing */
868     null;
869   END IF;
870 
871   ----------------------------------------
872   l_debug_info := 'Get Segment Delimiter like .';
873   ----------------------------------------
874   l_flex_segment_delimiter := FND_FLEX_EXT.GET_DELIMITER(
875                                         'SQLGL',
876                                         'GL#',
877                                         l_chart_of_accounts_id);
878 
879   IF (l_flex_segment_delimiter IS NULL) THEN
880     FND_MSG_PUB.Add;
881     RAISE AP_WEB_OA_MAINFLOW_PKG.G_EXC_ERROR;
882   END IF;
883 
884 
885   ----------------------------------------
886   l_debug_info := 'Check if p_ccid or p_segments is passed';
887   ----------------------------------------
888   if (p_ccid is not null) then
889 
890     ----------------------------------------
891     l_debug_info := 'Convert p_ccid into a segment array';
892     ----------------------------------------
893     IF (NOT FND_FLEX_EXT.GET_SEGMENTS('SQLGL',
894                                       'GL#',
895                                       l_chart_of_accounts_id,
896                                       p_ccid,
897                                       l_num_segments,
898                                       l_exp_line_acct_segs_array)) THEN
899       return;
900     END IF;
901 
902   elsif (p_segments is not null and p_segments.count > 0) then
903 
904     ----------------------------------------
905     l_debug_info := 'Convert p_segments into a segment array';
906     ----------------------------------------
907 
908     IF (l_num_segments IS NULL) THEN
909       l_num_segments := p_segments.count;
910     END IF;
911 
912     -----------------------------------------------------
913     l_debug_info := 'Assign values to l_exp_line_acct_segs_array';
914     -----------------------------------------------------
915     FOR i IN 1..l_num_segments LOOP
916           l_exp_line_acct_segs_array(i) := p_segments(i);
917     END LOOP;
918 
919   end if /* p_ccid is not null or p_segments is not null */;
920 
921 
922   if (p_exp_type_parameter_id is not null) then
923     ------------------------------------------------------------------------
924     l_debug_info := 'calling AP_WEB_DB_EXPRPT_PKG.GetFlexConcactenated';
925     ------------------------------------------------------------------------
926     IF (AP_WEB_DB_EXPRPT_PKG.GetFlexConcactenated(
927                p_parameter_id => p_exp_type_parameter_id,
928                p_FlexConcactenated => l_FlexConcactenated)) THEN
929 
930        IF l_FlexConcactenated is not null THEN
931 
932           --------------------------------------------------------------
933           l_debug_info:='Break Up Segments';
934           --------------------------------------------------------------
935           l_num_segments := FND_FLEX_EXT.Breakup_Segments(l_FlexConcactenated,
936                                                           l_flex_segment_delimiter,
937                                                           l_exp_type_template_array);
938        END IF;
939 
940     END IF;
941 
942   end if; /* p_exp_type_parameter_id is not null */
943 
944 
945   --------------------------------------------------------------
946   l_debug_info:='Check Build Account Mode';
947   --------------------------------------------------------------
948   if (p_build_mode in (C_DEFAULT, C_DEFAULT_VALIDATE, C_BUILD_VALIDATE)) then
949 
950 
951      -- Overlay the incoming segment values with the segment values
952      -- defined in expense type template IF the incoming segment value
953      -- is NULL.
954 
955         FOR i IN 1..l_num_segments LOOP
956           -- If the incoming segment is not null, then keep this value, do nothing.
957           IF (p_segments IS NOT NULL AND
958               p_segments.EXISTS(i) AND
959               p_segments(i) IS NOT NULL) THEN
960 
961             NULL;
962 
963           ELSIF (l_exp_type_template_array is not null and
964               l_exp_type_template_array.count > 0 and
968 
965               l_exp_type_template_array(i) IS NOT NULL) THEN
966 
967             l_exp_line_acct_segs_array(i) := l_exp_type_template_array(i);
969           ELSE
970 
971           /* If cost center is not defined on the expense type mask, override it from line
972            * or header, if defined, in that order.  */
973 
974             IF i = l_cost_center_seg_num AND p_line_cost_center is not null THEN
975               l_exp_line_acct_segs_array(i) := p_line_cost_center;
976 
977             ELSIF i = l_cost_center_seg_num AND p_cost_center is not null THEN
978               l_exp_line_acct_segs_array(i) := p_cost_center;
979 
980             ELSIF (p_build_mode in (C_DEFAULT, C_DEFAULT_VALIDATE)) THEN
981               l_exp_line_acct_segs_array(i) := l_default_emp_segments(i);
982             END IF;
983 
984           END IF; /* l_exp_type_template_array(i) IS NOT NULL */
985 
986         END LOOP; /* 1..l_num_segments */
987 
988   end if; /* p_build_mode in (C_DEFAULT, C_DEFAULT_VALIDATE, C_BUILD_VALIDATE) */
989 
990 
991   --------------------------------------------------------------
992   l_debug_info:='Check Build Account Mode';
993   --------------------------------------------------------------
994   if (p_build_mode in (C_DEFAULT_VALIDATE, C_BUILD_VALIDATE, C_VALIDATE)) then
995 
996       --------------------------------------------------------------
997       l_debug_info:='Build Account Mode contains VALIDATE';
998       --------------------------------------------------------------
999 
1000       --------------------------------------------------------------
1001       l_debug_info := 'Retrieve new ccid';
1002       --------------------------------------------------------------
1003       -- Work around for bug 1569108
1004       l_concatenated_segments :=  FND_FLEX_EXT.concatenate_segments(l_num_segments,
1005                         l_exp_line_acct_segs_array,
1006                         l_flex_segment_delimiter);
1007 
1008       ------------------------------------------------------------------------
1009       l_debug_info := 'calling FND_FLEX_KEYVAL.validate_segs';
1010       ------------------------------------------------------------------------
1011       IF (FND_FLEX_KEYVAL.validate_segs('CREATE_COMBINATION',
1012                                         'SQLGL',
1013                                         'GL#',
1014                                         l_chart_of_accounts_id,
1015                                         l_concatenated_segments)) THEN
1016 
1017         p_new_ccid := FND_FLEX_KEYVAL.combination_id;
1018 
1019       ELSE
1020 
1021         p_return_error_message := FND_FLEX_KEYVAL.error_message;
1022         FND_MESSAGE.set_encoded(FND_FLEX_KEYVAL.encoded_error_message);
1023         fnd_msg_pub.add();
1024 
1025       END IF; /* FND_FLEX_KEYVAL.validate_segs */
1026 
1027   end if; /* p_build_mode in (C_DEFAULT_VALIDATE, C_BUILD_VALIDATE, C_VALIDATE) */
1028 
1029   -----------------------------------------------------
1030   l_debug_info := 'Assign values to p_new_segments';
1031   -----------------------------------------------------
1032   p_new_segments := AP_OIE_KFF_SEGMENTS_T('');
1033   p_new_segments.extend(l_num_segments);
1034   FOR i IN 1..l_num_segments LOOP
1035         p_new_segments(i) := l_exp_line_acct_segs_array(i);
1036   END LOOP;
1037 
1038 
1039 EXCEPTION
1040  WHEN OTHERS THEN
1041    AP_WEB_DB_UTIL_PKG.RaiseException( 'BuildAccount' );
1042    APP_EXCEPTION.RAISE_EXCEPTION;
1043 
1044 END BuildAccount;
1045 
1046 
1047 PROCEDURE BuildDistProjectAccount(
1048         p_report_header_id              IN              NUMBER,
1049         p_report_line_id                IN              NUMBER,
1050         p_report_distribution_id        IN              NUMBER,
1051         p_exp_type_parameter_id         IN              NUMBER,
1052         p_new_segments                  OUT NOCOPY AP_OIE_KFF_SEGMENTS_T,
1053         p_new_ccid                      OUT NOCOPY      NUMBER,
1054         p_return_error_message          OUT NOCOPY      VARCHAR2,
1055         p_return_status                 OUT NOCOPY      VARCHAR2) IS
1056 
1057   CURSOR pa_cur IS
1058     SELECT
1059            aerh.employee_id,
1060            aerh.flex_concatenated header_cost_center,
1061            aerh.default_currency_code reimbursement_currency_code,
1062            aerh.week_end_date,
1063            aerh.attribute_category header_attribute_category,
1064            aerh.attribute1 header_attribute1,
1065            aerh.attribute2 header_attribute2,
1066            aerh.attribute3 header_attribute3,
1067            aerh.attribute4 header_attribute4,
1068            aerh.attribute5 header_attribute5,
1069            aerh.attribute6 header_attribute6,
1070            aerh.attribute7 header_attribute7,
1071            aerh.attribute8 header_attribute8,
1072            aerh.attribute9 header_attribute9,
1073            aerh.attribute10 header_attribute10,
1074            aerh.attribute11 header_attribute11,
1075            aerh.attribute12 header_attribute12,
1076            aerh.attribute13 header_attribute13,
1077            aerh.attribute14 header_attribute14,
1078            aerh.attribute15 header_attribute15,
1079            aerl.start_expense_date,
1080            dist.amount,
1081            aerl.credit_card_trx_id,
1082            aerl.expenditure_item_date,
1083            aerl.expenditure_type,
1084            aerl.pa_quantity,
1088            aerl.attribute_category line_attribute_category,
1085            dist.expenditure_organization_id,
1086            aerl.adjustment_reason,
1087            aerl.category_code,
1089            aerl.attribute1 line_attribute1,
1090            aerl.attribute2 line_attribute2,
1091            aerl.attribute3 line_attribute3,
1092            aerl.attribute4 line_attribute4,
1093            aerl.attribute5 line_attribute5,
1094            aerl.attribute6 line_attribute6,
1095            aerl.attribute7 line_attribute7,
1096            aerl.attribute8 line_attribute8,
1097            aerl.attribute9 line_attribute9,
1098            aerl.attribute10 line_attribute10,
1099            aerl.attribute11 line_attribute11,
1100            aerl.attribute12 line_attribute12,
1101            aerl.attribute13 line_attribute13,
1102            aerl.attribute14 line_attribute14,
1103            aerl.attribute15 line_attribute15,
1104            dist.cost_center line_flex_concat,
1105            aerl.ap_validation_error,
1106            dist.project_id,
1107            dist.task_id,
1108            dist.award_id,
1109            s.base_currency_code,
1110            s.default_exchange_rate_type,
1111            sob.chart_of_accounts_id,
1112            erp.pa_expenditure_type new_expenditure_type
1113     FROM   ap_expense_report_headers aerh,
1114            ap_expense_report_lines aerl,
1115            ap_exp_report_dists dist,
1116            ap_system_parameters s,
1117            fnd_currencies_vl c,
1118            gl_sets_of_books sob,
1119            ap_expense_report_params erp
1120     WHERE  c.currency_code = s.base_currency_code
1121     AND    sob.set_of_books_id = s.set_of_books_id
1122     AND    erp.parameter_id = p_exp_type_parameter_id
1123     AND    dist.report_distribution_id = p_report_distribution_id
1124     AND    dist.report_line_id = aerl.report_line_id
1125     AND    aerh.report_header_id = aerl.report_header_id;
1126 
1127   ln_default_exchange_rate      NUMBER;
1128   ln_acct_raw_cost              NUMBER;
1129   ln_vendor_id                  NUMBER;
1130   ln_award_set_id               NUMBER;
1131   lv_expense_report_cost_center AP_WEB_DB_EXPRPT_PKG.expHdr_flexConcat;
1132   lv_procedure_billable_flag    VARCHAR2(200);
1133   lv_msg_type                   VARCHAR2(2000);
1134   l_pa_CCID                     gl_code_combinations.code_combination_id%TYPE;
1135   lv_concat_segs                VARCHAR2(2000);
1136   lv_concat_ids                 VARCHAR2(2000);
1137   lv_concat_description         VARCHAR2(2000);
1138   l_segments                    FND_FLEX_EXT.SEGMENTARRAY;
1139   ln_segment_count              NUMBER := 0;
1140   lv_flex_segment_delimiter     VARCHAR2(1);
1141   lb_gms_accounting_created     BOOLEAN := false;
1142 
1143   pa_rec pa_cur%ROWTYPE;
1144   l_debug_info varchar2(200);
1145   l_default_emp_ccid       AP_WEB_DB_EXPRPT_PKG.expHdr_employeeCCID;
1146 BEGIN
1147 
1148   IF    p_report_header_id is null
1149      OR p_report_line_id is null
1150      OR p_report_distribution_id is null
1151      OR p_exp_type_parameter_id is null THEN
1152     p_new_ccid := to_number(null);
1153     p_return_status := 'ERROR';
1154     RETURN;
1155   END IF;
1156 
1157   if (AP_WEB_CUS_ACCTG_PKG.BuildDistProjectAccount(
1158          p_report_header_id => p_report_header_id,
1159          p_report_line_id => p_report_line_id,
1160          p_report_distribution_id => p_report_distribution_id,
1161          p_exp_type_parameter_id => p_exp_type_parameter_id,
1162          p_new_segments => p_new_segments,
1163          p_new_ccid => p_new_ccid,
1164          p_return_error_message => p_return_error_message,
1165          p_return_status => p_return_status)) then
1166 
1167       --------------------------------------------------------------------
1168       l_debug_info := 'Custom BuildDistProjectAccount';
1169       --------------------------------------------------------------------
1170 
1171      return;
1172 
1173   end if;
1174 
1175   p_return_status := 'SUCCESS';
1176 
1177   OPEN pa_cur;
1178   FETCH pa_cur into pa_rec;
1179   IF pa_cur%NOTFOUND THEN
1180     CLOSE pa_cur;
1181     p_new_ccid := to_number(null);
1182     p_return_status := 'ERROR';
1183     RETURN;
1184   END IF;
1185   CLOSE pa_cur;
1186 
1187     -----------------------------------------------------
1188     l_debug_info := 'Get vendor ID if exists for this employee';
1189     -----------------------------------------------------
1190   IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorID(pa_rec.employee_id, ln_vendor_id)) THEN
1191       ln_vendor_id := NULL;
1192   END IF; /* GetVendorID */
1193 
1194   -- For PATC: Get the default exchange rate for the week_end_date reimbursement currency/functional currency
1195     -----------------------------------------------------
1196     l_debug_info := 'AP_UTILITIES_PKG.get_exchange_rate';
1197     -----------------------------------------------------
1198   ln_default_exchange_rate := AP_UTILITIES_PKG.get_exchange_rate(pa_rec.base_currency_code,
1199                                                                  pa_rec.reimbursement_currency_code,
1200                                                                  pa_rec.default_exchange_rate_type,
1201                                                                  pa_rec.week_end_date,
1202                                                                 'ValidatePATransaction');
1203 
1204   -- Calculate the receipt amount in the functional currency
1208   END IF;
1205   ln_acct_raw_cost := NULL;
1206   IF ln_default_exchange_rate IS NOT NULL AND ln_default_exchange_rate <> 0 THEN
1207     ln_acct_raw_cost := AP_UTILITIES_PKG.AP_ROUND_CURRENCY(pa_rec.amount/ln_default_exchange_rate, pa_rec.base_currency_code);
1209 
1210     -----------------------------------------------------
1211     l_debug_info := 'Call PATC to get billable flag value';
1212     -----------------------------------------------------
1213   AP_WEB_PROJECT_PKG.ValidatePATransaction(p_project_id         => pa_rec.project_id,
1214                                            p_task_id            => pa_rec.task_id,
1215                                            p_ei_date            => pa_rec.expenditure_item_date,
1216                                            p_expenditure_type   => pa_rec.new_expenditure_type,
1217                                            p_non_labor_resource => NULL,
1218                                            p_person_id          => pa_rec.employee_id,
1219                                            p_quantity           => NULL,
1220                                            p_denom_currency_code=> pa_rec.reimbursement_currency_code,
1221                                            p_acct_currency_code => pa_rec.base_currency_code,
1222                                            p_denom_raw_cost     => pa_rec.amount,
1223                                            p_acct_raw_cost      => ln_acct_raw_cost,
1224                                            p_acct_rate_type     => pa_rec.default_exchange_rate_type,
1225                                            p_acct_rate_date     => pa_rec.week_end_date,
1226                                            p_acct_exchange_rate => ln_default_exchange_rate,
1227                                            p_transfer_ei        => NULL,
1228                                            p_incurred_by_org_id => pa_rec.expenditure_organization_id,
1229                                            p_nl_resource_org_id => NULL,
1230                                            p_transaction_source => NULL,
1231                                            p_calling_module     => 'SelfService',
1232                                            p_vendor_id          => ln_vendor_id,
1233                                            p_entered_by_user_id => NULL,
1234                                            p_attribute_category => pa_rec.line_attribute_category,
1235                                            p_attribute1         => pa_rec.line_attribute1,
1236                                            p_attribute2         => pa_rec.line_attribute2,
1237                                            p_attribute3         => pa_rec.line_attribute3,
1238                                            p_attribute4         => pa_rec.line_attribute4,
1239                                            p_attribute5         => pa_rec.line_attribute5,
1240                                            p_attribute6         => pa_rec.line_attribute6,
1241                                            p_attribute7         => pa_rec.line_attribute7,
1242                                            p_attribute8         => pa_rec.line_attribute8,
1243                                            p_attribute9         => pa_rec.line_attribute9,
1244                                            p_attribute10        => pa_rec.line_attribute10,
1245                                            p_attribute11        => pa_rec.line_attribute11,
1246                                            p_attribute12        => pa_rec.line_attribute12,
1247                                            p_attribute13        => pa_rec.line_attribute13,
1248                                            p_attribute14        => pa_rec.line_attribute14,
1249                                            p_attribute15        => pa_rec.line_attribute15,
1250                                            p_msg_type           => lv_msg_type,
1251                                            p_msg_data           => p_return_error_message,
1252                                            p_billable_flag      => lv_procedure_billable_flag);
1253 
1254   IF (p_return_error_message is not null) AND (lv_msg_type = AP_WEB_DFLEX_PKG.C_CustValidResMsgTypeError) THEN
1255     /* validation failed, we cannot generate the projects CCID */
1256     p_new_ccid := to_number(null);
1257     p_return_status := 'VALIDATION_ERROR';
1258     RETURN;
1259   ELSE
1260     /* For some reason the projects API returns error even though validation is succesful.
1261      * When the message data is also provided then the validation actually failed. Since these
1262      * same variables are used elsewhere resetting them to null when validation was succesful */
1263     lv_msg_type := NULL;
1264     p_return_error_message := NULL;
1265   END IF;
1266 
1267   -- Get Award Set ID before calling A/C generator
1268   ln_award_set_id := null;
1269 
1270   IF (GMS_OIE_INT_PKG.IsGrantsEnabled() and pa_rec.award_id is not null) THEN
1271     -----------------------------------------------------
1272     l_debug_info := 'GMS_OIE_INT_PKG.CreateACGenADL';
1273     -----------------------------------------------------
1274     ln_award_set_id := GMS_OIE_INT_PKG.CreateACGenADL(p_award_id   => pa_rec.award_id,
1275                                                       p_project_id => pa_rec.project_id,
1276                                                       p_task_id    => pa_rec.task_id);
1277     lb_gms_accounting_created := true;
1278   END IF;
1279 
1280   IF (pa_rec.line_flex_concat is not null) THEN
1281     lv_expense_report_cost_center := pa_rec.line_flex_concat;
1282   ELSE
1283     lv_expense_report_cost_center := pa_rec.header_cost_center;
1284   END IF;
1285 
1286   --bug 4629320
1290     -----------------------------------------------------
1287   IF AP_WEB_DB_EXPRPT_PKG.GetDefaultEmpCCID(pa_rec.employee_id, l_default_emp_ccid) THEN
1288      null;
1289   END IF;
1291     l_debug_info := 'pa_acc_gen_wf_pkg.ap_er_generate_account';
1292     -----------------------------------------------------
1293   IF ( NOT pa_acc_gen_wf_pkg.ap_er_generate_account (p_project_id                 => pa_rec.project_id,
1294                                                      p_task_id                    => pa_rec.task_id,
1295                                                      p_expenditure_type           => pa_rec.new_expenditure_type,
1296                                                      p_vendor_id                  => ln_vendor_id,
1297                                                      p_expenditure_organization_id=> pa_rec.expenditure_organization_id,
1298 
1299                                                      p_expenditure_item_date      => pa_rec.expenditure_item_date,
1300                                                      p_billable_flag              => lv_procedure_billable_flag,
1301                                                      p_chart_of_accounts_id       => pa_rec.chart_of_accounts_id,
1302                                                      p_calling_module             => 'SelfService',
1303                                                      p_employee_id                => pa_rec.employee_id,
1304                                                      p_employee_ccid              => l_default_emp_ccid,
1305                                                      p_expense_type               => p_exp_type_parameter_id,
1306                                                      p_expense_cc                 => lv_expense_report_cost_center,
1307                                                      p_attribute_category         => pa_rec.header_attribute_category,
1308                                                      p_attribute1                 => pa_rec.header_attribute1,
1309                                                      p_attribute2                 => pa_rec.header_attribute2,
1310                                                      p_attribute3                 => pa_rec.header_attribute3,
1311                                                      p_attribute4                 => pa_rec.header_attribute4,
1312                                                      p_attribute5                 => pa_rec.header_attribute5,
1313                                                      p_attribute6                 => pa_rec.header_attribute6,
1314                                                      p_attribute7                 => pa_rec.header_attribute7,
1315                                                      p_attribute8                 => pa_rec.header_attribute8,
1316                                                      p_attribute9                 => pa_rec.header_attribute9,
1317                                                      p_attribute10                => pa_rec.header_attribute10,
1318                                                      p_attribute11                => pa_rec.header_attribute11,
1319                                                      p_attribute12                => pa_rec.header_attribute12,
1320                                                      p_attribute13                => pa_rec.header_attribute13,
1321                                                      p_attribute14                => pa_rec.header_attribute14,
1322                                                      p_attribute15                => pa_rec.header_attribute15,
1323                                                      p_line_attribute_category    => pa_rec.line_attribute_category,
1324                                                      p_line_attribute1            => pa_rec.line_attribute1,
1325                                                      p_line_attribute2            => pa_rec.line_attribute2,
1326                                                      p_line_attribute3            => pa_rec.line_attribute3,
1327                                                      p_line_attribute4            => pa_rec.line_attribute4,
1328                                                      p_line_attribute5            => pa_rec.line_attribute5,
1329                                                      p_line_attribute6            => pa_rec.line_attribute6,
1330                                                      p_line_attribute7            => pa_rec.line_attribute7,
1331                                                      p_line_attribute8            => pa_rec.line_attribute8,
1332                                                      p_line_attribute9            => pa_rec.line_attribute9,
1333                                                      p_line_attribute10           => pa_rec.line_attribute10,
1334                                                      p_line_attribute11           => pa_rec.line_attribute11,
1335                                                      p_line_attribute12           => pa_rec.line_attribute12,
1336                                                      p_line_attribute13           => pa_rec.line_attribute13,
1337                                                      p_line_attribute14           => pa_rec.line_attribute14,
1338                                                      p_line_attribute15           => pa_rec.line_attribute15,
1339                                                      x_return_ccid                => l_pa_ccid,
1340                                                      x_concat_segs                => lv_concat_segs,
1341                                                      x_concat_ids                 => lv_concat_ids,
1342                                                      x_concat_descrs              => lv_concat_description,
1343                                                      x_error_message              => p_return_error_message,
1344                                                      x_award_set_id               => ln_award_set_id)) THEN
1345 
1346     IF (p_return_error_message is not null) THEN
1350       RETURN;
1347       /* could not generate the projects CCID */
1348       p_new_ccid := to_number(null);
1349       p_return_status := 'GENERATION_ERROR';
1351 
1352   END IF;
1353 
1354   END IF; /*  pa_acc_gen_wf_pkg.ap_er_generate_account */
1355 
1356   IF (lb_gms_accounting_created = true) THEN
1357     -----------------------------------------------------
1358     l_debug_info := 'gms_oie_int_pkg.DeleteACGenADL';
1359     -----------------------------------------------------
1360     IF gms_oie_int_pkg.DeleteACGenADL(ln_award_set_id) THEN
1361       null;
1362     END IF;
1363   END IF;
1364 
1365     -----------------------------------------------------
1366     l_debug_info := 'Get segment delimeter';
1367     -----------------------------------------------------
1368   lv_flex_segment_delimiter := FND_FLEX_EXT.GET_DELIMITER('SQLGL','GL#',pa_rec.chart_of_accounts_id);
1369 
1370     -----------------------------------------------------
1371     l_debug_info := 'Break up segments';
1372     -----------------------------------------------------
1373   ln_segment_count := FND_FLEX_EXT.Breakup_Segments(lv_concat_segs, lv_flex_segment_delimiter, l_segments);
1374 
1375    -----------------------------------------------------
1376    l_debug_info := 'Assign values to p_new_segments';
1377    -----------------------------------------------------
1378    p_new_segments := AP_OIE_KFF_SEGMENTS_T('');
1379    p_new_segments.extend(ln_segment_count);
1380    FOR i IN 1..ln_segment_count LOOP
1381       p_new_segments(i) := l_segments(i);
1382    END LOOP;
1383 
1384   -- create account if don't already exist
1385   IF (l_pa_ccid = -1) THEN
1386 
1387     -----------------------------------------------------
1388     l_debug_info := 'Validate segments';
1389     -----------------------------------------------------
1390     IF (FND_FLEX_KEYVAL.validate_segs('CREATE_COMBINATION',
1391                                       'SQLGL',
1392                                       'GL#',
1393                                       pa_rec.chart_of_accounts_id,
1394                                       lv_concat_segs)) THEN
1395       l_pa_ccid := FND_FLEX_KEYVAL.combination_id;
1396     ELSE
1397       p_return_error_message := FND_FLEX_KEYVAL.error_message;
1398       /* could not generate the projects CCID */
1399       p_new_ccid := to_number(null);
1400       p_return_status := 'GENERATION_ERROR';
1401       return;
1402     END IF; /* FND_FLEX_KEYVAL.validate_segs */
1403 
1404   END IF; /* l_pa_ccid = -1 */
1405 
1406   IF (l_pa_ccid is null OR l_pa_ccid = -1) THEN
1407     p_new_ccid := to_number(null);
1408     p_return_status := 'GENERATION_ERROR';
1409   ELSE
1410     p_new_ccid := l_pa_ccid;
1411   END IF;
1412 
1413 EXCEPTION
1414   WHEN OTHERS THEN
1415     /* could not generate the projects CCID */
1416     p_new_ccid := to_number(null);
1417     p_return_status := 'ERROR';
1418 
1419 END BuildDistProjectAccount;
1420 
1421 PROCEDURE ValidateProjectAccounting(
1422 	p_report_line_id                IN              NUMBER,
1423 	p_web_parameter_id		IN		NUMBER,
1424 	p_project_id			IN		NUMBER,
1425 	p_task_id			IN		NUMBER,
1426 	p_award_id			IN              NUMBER,
1427 	p_award_number			IN              VARCHAR2,
1428 	p_expenditure_org_id		IN		NUMBER,
1429 	p_amount			IN		NUMBER,
1430 	p_return_error_message		OUT NOCOPY	VARCHAR2,
1431 	p_msg_count			OUT NOCOPY	NUMBER,
1432 	p_msg_data			OUT NOCOPY	VARCHAR2
1433 	) IS
1434 
1435  CURSOR pa_cur IS
1436 	SELECT
1437            aerh.employee_id,
1438            aerh.flex_concatenated header_cost_center,
1439            aerh.default_currency_code reimbursement_currency_code,
1440            aerh.week_end_date,
1441            aerh.attribute_category header_attribute_category,
1442            aerh.attribute1 header_attribute1,
1443            aerh.attribute2 header_attribute2,
1444            aerh.attribute3 header_attribute3,
1445            aerh.attribute4 header_attribute4,
1446            aerh.attribute5 header_attribute5,
1447            aerh.attribute6 header_attribute6,
1448            aerh.attribute7 header_attribute7,
1449            aerh.attribute8 header_attribute8,
1450            aerh.attribute9 header_attribute9,
1451            aerh.attribute10 header_attribute10,
1452            aerh.attribute11 header_attribute11,
1453            aerh.attribute12 header_attribute12,
1454            aerh.attribute13 header_attribute13,
1455            aerh.attribute14 header_attribute14,
1456            aerh.attribute15 header_attribute15,
1457            aerl.start_expense_date,
1458            aerl.end_expense_date,
1459            aerl.credit_card_trx_id,
1460            aerl.expenditure_item_date,
1461            aerl.expenditure_type,
1462            aerl.pa_quantity,
1463            aerl.adjustment_reason,
1464            aerl.category_code,
1465            aerl.attribute_category line_attribute_category,
1466            aerl.attribute1 line_attribute1,
1467            aerl.attribute2 line_attribute2,
1468            aerl.attribute3 line_attribute3,
1469            aerl.attribute4 line_attribute4,
1470            aerl.attribute5 line_attribute5,
1471            aerl.attribute6 line_attribute6,
1472            aerl.attribute7 line_attribute7,
1473            aerl.attribute8 line_attribute8,
1474            aerl.attribute9 line_attribute9,
1475            aerl.attribute10 line_attribute10,
1476            aerl.attribute11 line_attribute11,
1480            aerl.attribute15 line_attribute15,
1477            aerl.attribute12 line_attribute12,
1478            aerl.attribute13 line_attribute13,
1479            aerl.attribute14 line_attribute14,
1481            aerl.ap_validation_error,
1482            s.base_currency_code,
1483            s.default_exchange_rate_type,
1484            sob.chart_of_accounts_id,
1485            erp.pa_expenditure_type new_expenditure_type
1486     FROM   ap_expense_report_headers_all aerh,
1487            ap_expense_report_lines_all aerl,
1488            ap_system_parameters_all s,
1489            fnd_currencies_vl c,
1490            gl_sets_of_books sob,
1491            ap_expense_report_params_all erp
1492     WHERE  c.currency_code = s.base_currency_code
1493     AND    sob.set_of_books_id = s.set_of_books_id
1494     AND    erp.parameter_id = p_web_parameter_id
1495     AND    aerh.report_header_id = aerl.report_header_id
1496     AND	   aerl.report_line_id = p_report_line_id;
1497 
1498  pa_rec				pa_cur%ROWTYPE;
1499  lv_msg_type			VARCHAR2(2000);
1500  lv_procedure_billable_flag	VARCHAR2(200);
1501  ln_vendor_id			NUMBER;
1502  ln_default_exchange_rate	NUMBER;
1503  ln_acct_raw_cost		NUMBER;
1504  l_errors			AP_WEB_UTILITIES_PKG.expError;
1505  l_receipts_errors              AP_WEB_UTILITIES_PKG.receipt_error_stack;
1506  I				INTEGER;
1507 BEGIN
1508  IF p_report_line_id is null or p_web_parameter_id is null THEN
1509 	p_return_error_message := 'ERROR';
1510 	RETURN;
1511  END IF;
1512 
1513  -- Bug: 7176464
1514  IF (AP_WEB_CUS_ACCTG_PKG.CustomValidateProjectDist(
1515                          p_report_line_id,
1516                          p_web_parameter_id,
1517                          p_project_id,
1518                          p_task_id,
1519                          p_award_id,
1520                          p_expenditure_org_id,
1521                          p_amount,
1522                          p_return_error_message)) THEN
1523       -- Custom Validate Project Allocations
1524       IF (p_return_error_message is not null) THEN
1525 
1526         AP_WEB_UTILITIES_PKG.AddExpError(l_errors,
1527                       p_return_error_message,
1528                       lv_msg_type,
1529 		      'PATC',
1530                       1,
1531                       AP_WEB_UTILITIES_PKG.C_PATCMessageCategory, AP_WEB_UTILITIES_PKG.IsMobileApp);
1532         p_msg_count := 1;
1533         p_msg_data := p_return_error_message;
1534         fnd_msg_pub.count_and_get(p_count => p_msg_count,p_data  => p_msg_data);
1535         -- Bug 7497991 Commenting Return Statement to continue ValidationS
1536         -- return;
1537       END IF;
1538  END IF;
1539 
1540  OPEN pa_cur;
1541 
1542  FETCH pa_cur into pa_rec;
1543  IF pa_cur%NOTFOUND THEN
1544    CLOSE pa_cur;
1545    p_return_error_message := 'ERROR';
1546    RETURN;
1547  END IF;
1548  CLOSE pa_cur;
1549 
1550  AP_WEB_UTILITIES_PKG.InitMessages(1, l_receipts_errors);
1551 
1552  IF (NOT AP_WEB_DB_AP_INT_PKG.GetVendorID(pa_rec.employee_id, ln_vendor_id)) THEN
1553 	ln_vendor_id := NULL;
1554  END IF; /* GetVendorID */
1555 
1556  ln_default_exchange_rate := AP_UTILITIES_PKG.get_exchange_rate(pa_rec.base_currency_code,
1557                                                                  pa_rec.reimbursement_currency_code,
1558                                                                  pa_rec.default_exchange_rate_type,
1559                                                                  pa_rec.week_end_date,
1560                                                                 'ValidatePATransaction');
1561 
1562  -- Calculate the receipt amount in the functional currency
1563  ln_acct_raw_cost := NULL;
1564  IF ln_default_exchange_rate IS NOT NULL AND ln_default_exchange_rate <> 0 THEN
1565 	ln_acct_raw_cost := AP_UTILITIES_PKG.AP_ROUND_CURRENCY(p_amount/ln_default_exchange_rate, pa_rec.base_currency_code);
1566  END IF;
1567 
1568 
1569  AP_WEB_PROJECT_PKG.ValidatePATransaction(p_project_id  => p_project_id,
1570 				   p_task_id            => p_task_id,
1571 				   p_ei_date            => pa_rec.start_expense_date,
1572 				   p_expenditure_type   => pa_rec.new_expenditure_type,
1573 				   p_non_labor_resource => NULL,
1574 				   p_person_id          => pa_rec.employee_id,
1575 				   p_quantity           => NULL,
1576 				   p_denom_currency_code=> pa_rec.reimbursement_currency_code,
1577 				   p_acct_currency_code => pa_rec.base_currency_code,
1578 				   p_denom_raw_cost     => p_amount,
1579 				   p_acct_raw_cost      => ln_acct_raw_cost,
1580 				   p_acct_rate_type     => pa_rec.default_exchange_rate_type,
1581 				   p_acct_rate_date     => pa_rec.week_end_date,
1582 				   p_acct_exchange_rate => ln_default_exchange_rate,
1583 				   p_transfer_ei        => NULL,
1584 				   p_incurred_by_org_id => p_expenditure_org_id,
1585 				   p_nl_resource_org_id => NULL,
1586 				   p_transaction_source => NULL,
1587 				   p_calling_module     => 'SelfService',
1588 				   p_vendor_id          => ln_vendor_id,
1589 				   p_entered_by_user_id => NULL,
1590 				   p_attribute_category => pa_rec.line_attribute_category,
1591 				   p_attribute1         => pa_rec.line_attribute1,
1592 				   p_attribute2         => pa_rec.line_attribute2,
1593 				   p_attribute3         => pa_rec.line_attribute3,
1594 				   p_attribute4         => pa_rec.line_attribute4,
1595 				   p_attribute5         => pa_rec.line_attribute5,
1596 				   p_attribute6         => pa_rec.line_attribute6,
1597 				   p_attribute7         => pa_rec.line_attribute7,
1598 				   p_attribute8         => pa_rec.line_attribute8,
1599 				   p_attribute9         => pa_rec.line_attribute9,
1600 				   p_attribute10        => pa_rec.line_attribute10,
1601 				   p_attribute11        => pa_rec.line_attribute11,
1602 				   p_attribute12        => pa_rec.line_attribute12,
1603 				   p_attribute13        => pa_rec.line_attribute13,
1604 				   p_attribute14        => pa_rec.line_attribute14,
1605 				   p_attribute15        => pa_rec.line_attribute15,
1606 				   p_msg_type           => lv_msg_type,
1607 				   p_msg_data           => p_return_error_message,
1608 				   p_billable_flag      => lv_procedure_billable_flag);
1609 
1610  if (p_return_error_message IS NOT NULL AND lv_msg_type = AP_WEB_DFLEX_PKG.C_CustValidResMsgTypeError) then
1611               AP_WEB_UTILITIES_PKG.AddExpError(l_errors,
1612                       p_return_error_message,
1613                       lv_msg_type,
1614 		      'PATC',
1615                       1,
1616                       AP_WEB_UTILITIES_PKG.C_PATCMessageCategory, AP_WEB_UTILITIES_PKG.IsMobileApp);
1617  else
1618       -- Bug: 6936055, GMS Integration, Award Validation
1619       if (GMS_OIE_INT_PKG.IsGrantsEnabled() and p_award_id is not null and
1620 		not GMS_OIE_INT_PKG.DoGrantsValidation(p_project_id  => p_project_id,
1621 		  				       p_task_id     => p_task_id,
1622 						       p_award_id    => p_award_id,
1623 						       p_award_number => p_award_number,
1624 						       p_expenditure_type   => pa_rec.new_expenditure_type,
1625 						       p_expenditure_item_date => pa_rec.start_expense_date,
1626 						       p_calling_module => 'SelfService',
1627 						       p_err_msg => p_return_error_message)) then
1628 		AP_WEB_UTILITIES_PKG.AddExpError(l_errors,
1629                       p_return_error_message,
1630                       AP_WEB_UTILITIES_PKG.C_ErrorMessageType,
1631 		      'GMS',
1632                       1,
1633                       AP_WEB_UTILITIES_PKG.C_PATCMessageCategory, AP_WEB_UTILITIES_PKG.IsMobileApp);
1634       else
1635 	p_return_error_message := null;
1636 	lv_msg_type := null;
1637       end if;
1638  end if;
1639   if (p_return_error_message is null and pa_rec.end_expense_date is not null) then
1640          AP_WEB_PROJECT_PKG.ValidatePATransaction(p_project_id  => p_project_id,
1641                                      p_task_id            => p_task_id,
1642                                      p_ei_date            => pa_rec.end_expense_date,
1643                                      p_expenditure_type   => pa_rec.new_expenditure_type,
1644                                      p_non_labor_resource => NULL,
1645                                      p_person_id          => pa_rec.employee_id,
1646                                      p_quantity           => NULL,
1647                                      p_denom_currency_code=> pa_rec.reimbursement_currency_code,
1648                                      p_acct_currency_code => pa_rec.base_currency_code,
1649                                      p_denom_raw_cost     => p_amount,
1650                                      p_acct_raw_cost      => ln_acct_raw_cost,
1651                                      p_acct_rate_type     => pa_rec.default_exchange_rate_type,
1652                                      p_acct_rate_date     => pa_rec.week_end_date,
1653                                      p_acct_exchange_rate => ln_default_exchange_rate,
1654                                      p_transfer_ei        => NULL,
1655                                      p_incurred_by_org_id => p_expenditure_org_id,
1656                                      p_nl_resource_org_id => NULL,
1657                                      p_transaction_source => NULL,
1658                                      p_calling_module     => 'SelfService',
1659                                      p_vendor_id          => ln_vendor_id,
1660                                      p_entered_by_user_id => NULL,
1661                                      p_attribute_category => pa_rec.line_attribute_category,
1662                                      p_attribute1         => pa_rec.line_attribute1,
1663                                      p_attribute2         => pa_rec.line_attribute2,
1664                                      p_attribute3         => pa_rec.line_attribute3,
1665                                      p_attribute4         => pa_rec.line_attribute4,
1666                                      p_attribute5         => pa_rec.line_attribute5,
1667                                      p_attribute6         => pa_rec.line_attribute6,
1668                                      p_attribute7         => pa_rec.line_attribute7,
1669                                      p_attribute8         => pa_rec.line_attribute8,
1670                                      p_attribute9         => pa_rec.line_attribute9,
1671                                      p_attribute10        => pa_rec.line_attribute10,
1672                                      p_attribute11        => pa_rec.line_attribute11,
1673                                      p_attribute12        => pa_rec.line_attribute12,
1674                                      p_attribute13        => pa_rec.line_attribute13,
1675                                      p_attribute14        => pa_rec.line_attribute14,
1676                                      p_attribute15        => pa_rec.line_attribute15,
1677                                      p_msg_type           => lv_msg_type,
1678                                      p_msg_data           => p_return_error_message,
1679                                      p_billable_flag      => lv_procedure_billable_flag);
1680 
1681       if (p_return_error_message IS NOT NULL AND lv_msg_type = AP_WEB_DFLEX_PKG.C_CustValidResMsgTypeError) then
1682         AP_WEB_UTILITIES_PKG.AddExpError(l_errors,
1683                 p_return_error_message,
1684                 lv_msg_type,
1685                 'PATC',
1686                 1,
1687                 AP_WEB_UTILITIES_PKG.C_PATCMessageCategory, AP_WEB_UTILITIES_PKG.IsMobileApp);
1688       else
1689         -- Bug: 6936055, GMS Integration, Award Validation
1690         if (GMS_OIE_INT_PKG.IsGrantsEnabled() and p_award_id is not null and
1691 		not GMS_OIE_INT_PKG.DoGrantsValidation(p_project_id  => p_project_id,
1692 		  				       p_task_id     => p_task_id,
1693 						       p_award_id    => p_award_id,
1694 						       p_award_number => p_award_number,
1695 						       p_expenditure_type   => pa_rec.new_expenditure_type,
1696 						       p_expenditure_item_date => pa_rec.end_expense_date,
1697 						       p_calling_module => 'SelfService',
1698 						       p_err_msg => p_return_error_message)) then
1699 		AP_WEB_UTILITIES_PKG.AddExpError(l_errors,
1700                       p_return_error_message,
1701                       AP_WEB_UTILITIES_PKG.C_ErrorMessageType,
1702 		      'GMS',
1703                       1,
1704                       AP_WEB_UTILITIES_PKG.C_PATCMessageCategory, AP_WEB_UTILITIES_PKG.IsMobileApp);
1705         else
1706 	  p_return_error_message := null;
1707 	  lv_msg_type := null;
1708         end if;
1709       end if;
1710    end if;
1711 
1712  fnd_msg_pub.count_and_get(p_count => p_msg_count,p_data  => p_msg_data);
1713 
1714  EXCEPTION
1715    WHEN OTHERS THEN
1716      fnd_msg_pub.count_and_get(p_count => p_msg_count,p_data  => p_msg_data);
1717  END ValidateProjectAccounting;
1718 
1719 END AP_WEB_ACCTG_PKG;