DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_MASSADD_PREP_ENERGY_PKG

Source


1 package body FA_MASSADD_PREP_ENERGY_PKG as
2   /* $Header: FAMAPREPEB.pls 120.11.12010000.1 2008/07/28 13:12:23 appldev ship $ */
3 
4   -- Private type declarations
5 
6   -- Private constant declarations
7 
8   -- Private variable declarations
9   -- Function and procedure implementations
10 
11   function create_new_asset(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
12                             p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
13     return boolean is
14     l_total_cost number;
15     l_debug_str  varchar2(1000);
16     l_calling_fn varchar2(40) := 'create_new_asset';
17   begin
18     if (px_mass_add_rec.EXPENSE_CODE_COMBINATION_ID is not null) and
19        (px_mass_add_rec.location_id is not null) and
20        (px_mass_add_rec.asset_category_id is not null) and
21        (px_mass_add_rec.asset_key_ccid is not null) then
22       l_debug_str := 'Check the cost';
23       if (p_log_level_rec.statement_level) then
24         fa_debug_pkg.add(l_calling_fn,
25                          l_debug_str,
26                          '',
27                          p_log_level_rec => p_log_level_rec);
28       end if;
29       select nvl(sum(fixed_assets_cost), 0)
30         into l_total_cost
31         from fa_mass_additions
32        where split_merged_code = 'MC'
33          and parent_mass_addition_id = px_mass_add_rec.mass_addition_id
34           or mass_addition_id = px_mass_add_rec.mass_addition_id;
35       if (l_total_cost >= 0) then
36         l_debug_str := 'Cost is positive';
37         update fa_mass_additions
38            set EXPENSE_CODE_COMBINATION_ID = px_mass_add_rec.EXPENSE_CODE_COMBINATION_ID,
39                location_id                 = px_mass_add_rec.location_id,
40                asset_category_id           = px_mass_add_rec.asset_category_id,
41                asset_key_ccid              = px_mass_add_rec.asset_key_ccid,
42                posting_status              = 'POST',
43                queue_name                  = 'POST',
44                last_update_date            = sysdate,
45                last_updated_by             = FND_GLOBAL.user_id
46         where mass_addition_id = px_mass_add_rec.mass_addition_id;
47       else
48         l_debug_str := 'Cost is negative';
49         if (p_log_level_rec.statement_level) then
50           fa_debug_pkg.add(l_calling_fn,
51                            l_debug_str,
52                            '',
53                            p_log_level_rec => p_log_level_rec);
54         end if;
55         update fa_mass_additions
56            set EXPENSE_CODE_COMBINATION_ID = px_mass_add_rec.EXPENSE_CODE_COMBINATION_ID,
57                location_id                 = px_mass_add_rec.location_id,
58                asset_category_id           = px_mass_add_rec.asset_category_id,
59                asset_key_ccid              = px_mass_add_rec.asset_key_ccid,
60                posting_status              = 'ON HOLD',
61                queue_name                  = 'ON HOLD',
62                last_update_date            = sysdate,
63                last_updated_by             = FND_GLOBAL.user_id
64         where mass_addition_id = px_mass_add_rec.mass_addition_id;
65 
66       end if;
67     else
68       l_debug_str := 'Expense Account not generated';
69       if (p_log_level_rec.statement_level) then
70         fa_debug_pkg.add(l_calling_fn,
71                          l_debug_str,
72                          '',
73                          p_log_level_rec => p_log_level_rec);
74       end if;
75       update fa_mass_additions
76          set EXPENSE_CODE_COMBINATION_ID = nvl(px_mass_add_rec.EXPENSE_CODE_COMBINATION_ID,
77                                                EXPENSE_CODE_COMBINATION_ID),
78              location_id                 = nvl(px_mass_add_rec.location_id,
79                                                location_id),
80              asset_category_id           = nvl(px_mass_add_rec.asset_category_id,
81                                                asset_category_id),
82              asset_key_ccid              = nvl(px_mass_add_rec.asset_key_ccid,
83                                                asset_key_ccid),
84              posting_status              = 'ON HOLD',
85              queue_name                  = 'ON HOLD',
86              last_update_date            = sysdate,
87              last_updated_by             = FND_GLOBAL.user_id
88         where mass_addition_id = px_mass_add_rec.mass_addition_id;
89 
90     end if;
91     commit;
92     return true;
93   EXCEPTION
94     WHEN no_data_found THEN
95       return false;
96     WHEN OTHERS THEN
97       ROLLBACK;
98       return false;
99   END;
100 
101   /*===============================End Of FUNCTION/PROCEDURE===============================*/
102   function cost_adjustment(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
103                            p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
104     return boolean is
105     l_total_cost number;
106     l_debug_str  varchar2(1000);
107     l_calling_fn varchar2(40) := 'cost_asjustment';
108   begin
109     if (px_mass_add_rec.add_to_asset_id is not null) then
110       l_debug_str := 'Check the cost validity';
111       if (p_log_level_rec.statement_level) then
112         fa_debug_pkg.add(l_calling_fn,
113                          l_debug_str,
114                          '',
115                          p_log_level_rec => p_log_level_rec);
116       end if;
117       select nvl(sum(fixed_assets_cost), 0)
118         into l_total_cost
119         from fa_mass_additions
120        where split_merged_code = 'MC'
121          and parent_mass_addition_id = px_mass_add_rec.mass_addition_id
122          and merged_code = 'MC'
123          and posting_status = 'MERGED';
124 
125       select l_total_cost + nvl(cost, 0)
126         into l_total_cost
127         from fa_books
128        where book_type_code = px_mass_add_rec.book_type_code
129          and asset_id = px_mass_add_rec.add_to_asset_id
130          and transaction_header_id_out is null;
131       if (l_total_cost > 0) then
132         l_debug_str := 'Cost is positive';
133         if (p_log_level_rec.statement_level) then
134           fa_debug_pkg.add(l_calling_fn,
135                            l_debug_str,
136                            '',
137                            p_log_level_rec => p_log_level_rec);
138         end if;
139         update fa_mass_additions
140            set add_to_asset_id  = px_mass_add_rec.add_to_asset_id,
141                posting_status   = 'POST',
142                queue_name       = 'POST',
143                last_update_date = sysdate,
144                last_updated_by  = FND_GLOBAL.user_id
145         where mass_addition_id = px_mass_add_rec.mass_addition_id;
146 
147       else
148         l_debug_str := 'Cost is negative';
149         if (p_log_level_rec.statement_level) then
150           fa_debug_pkg.add(l_calling_fn,
151                            l_debug_str,
152                            '',
153                            p_log_level_rec => p_log_level_rec);
154         end if;
155         update fa_mass_additions
156            set posting_status   = 'POST',
157                queue_name       = 'POST',
158                last_update_date = sysdate,
159                last_updated_by  = FND_GLOBAL.user_id
160         where mass_addition_id = px_mass_add_rec.mass_addition_id;
161 
162       end if;
163     end if;
164 
165     return true;
166   EXCEPTION
167     WHEN no_data_found THEN
168 
169       return false;
170     WHEN OTHERS THEN
171 
172       ROLLBACK;
173       return false;
174   END;
175   /*===============================End Of FUNCTION/PROCEDURE===============================*/
176   function check_addition_or_adj(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
177                                  x_status        OUT NOCOPY varchar2,
178                                  p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
179     return boolean is
180     l_asset_id number := 0;
181   begin
182     select ad.asset_id
183       into l_asset_id
184       from fa_additions ad, fa_books bk
185      where asset_key_ccid = px_mass_add_rec.asset_category_id
186        and asset_key_ccid = px_mass_add_rec.ASSET_KEY_CCID
187        and ad.asset_id = bk.asset_id
188        and bk.book_type_code = px_mass_add_rec.book_type_code
189        and bk.transaction_header_id_out is null
190        and rownum < 2;
191     px_mass_add_rec.add_to_asset_id := l_asset_id;
192     x_status                        := 'ADJUSTMENT';
193     return true;
194   exception
195     when no_data_found then
196       px_mass_add_rec.add_to_asset_id := null;
197       x_status                        := 'ADDITION';
198       return true;
199     when others then
200       x_status := 'FAILED';
201       return false;
202   end;
203   /*===============================End Of FUNCTION/PROCEDURE===============================*/
204   function prepare_asset_key(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
205                              p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
206     return boolean is
207 
208     TYPE varchar30_tbl IS TABLE OF varchar2(30) INDEX BY BINARY_INTEGER;
209     l_akey_segment varchar30_tbl;
210     l_akey_ccid    number;
211     akey_ccid_seq  number;
212     l_select       varchar2(2000);
213     l_from         varchar2(2000);
214     l_where        varchar2(2000);
215     l_query        varchar2(6000);
216     l_coa          NUMBER;
217     l_sob_id       NUMBER;
218     l_dyanmic_cur  number;
219 
220     l_segment    varchar30_tbl;
221     l_category   FA_Categories.Category_ID%TYPE;
222     l_key_ccid   FA_Asset_Keywords.Code_Combination_ID%TYPE;
223     l_asset_type FA_Mass_Additions.Asset_Type%TYPE;
224 
225     l_mass_addition_id    FA_Mass_Additions.Mass_Addition_ID%TYPE;
226     l_invoice_number      FA_Mass_Additions.Invoice_Number%TYPE;
227     l_feeder_sys_name     FA_Mass_Additions.Feeder_System_Name%TYPE;
228     l_fixed_assets_cost   FA_Mass_Additions.Fixed_Assets_Cost%TYPE;
229     l_description         FA_Mass_Additions.Description%TYPE;
230     l_queue_name          FA_Mass_Additions.Queue_Name%TYPE;
231     l_asset_Key_segment1  FA_Mass_Additions.Asset_Key_segment1%TYPE;
232     l_asset_Key_segment2  FA_Mass_Additions.Asset_Key_segment2%TYPE;
233     l_asset_Key_segment3  FA_Mass_Additions.Asset_Key_segment3%TYPE;
234     l_asset_Key_segment4  FA_Mass_Additions.Asset_Key_segment4%TYPE;
235     l_asset_Key_segment5  FA_Mass_Additions.Asset_Key_segment5%TYPE;
236     l_asset_Key_segment6  FA_Mass_Additions.Asset_Key_segment6%TYPE;
237     l_asset_Key_segment7  FA_Mass_Additions.Asset_Key_segment7%TYPE;
238     l_asset_Key_segment8  FA_Mass_Additions.Asset_Key_segment8%TYPE;
239     l_asset_Key_segment9  FA_Mass_Additions.Asset_Key_segment9%TYPE;
240     l_asset_Key_segment10 FA_Mass_Additions.Asset_Key_segment10%TYPE;
241     l_payables_ccid       FA_Mass_Additions.Payables_Code_Combination_ID%TYPE;
242     l_dist_ccid           NUMBER;
243     l_dist_line_num       NUMBER;
244     l_mass_add_rec        Fa_Mass_Additions%ROWTYPE;
245 
246     l_cur_status  number;
247     l_debug_str   varchar2(1000);
248     l_plsql_block VARCHAR2(500);
249     l_table       varchar(30);
250     l_product     varchar2(10);
251     TYPE AssetKeyCurType IS REF CURSOR;
252     l_AssetKeyCur AssetKeyCurType;
253     l_calling_fn  varchar2(40) := 'prepare_asset_key';
254   begin
255     l_query := null;
256     if (px_mass_add_rec.ASSET_KEY_CCID is null) then
257       l_debug_str := 'Getting SOB id and COA';
258       --code to get asset key using fedder system
259       SELECT Gl_sob.Set_Of_Books_id, Chart_Of_Accounts_ID
260         INTO l_sob_id, l_coa
261         FROM GL_Sets_Of_Books GL_sob, FA_Book_Controls FA_BC
262        WHERE GL_sob.Set_Of_Books_ID = FA_BC.Set_Of_Books_ID
263          AND Book_Type_Code = px_mass_add_rec.book_type_code;
264 
265       if (upper(px_mass_add_rec.FEEDER_SYSTEM_NAME) = 'ORACLE PAYABLES') then
266         l_debug_str   := 'Feeder System Oracle Payables';
267         l_table       := 'AP_INVOICE_DISTRIBUTIONS_ALL';
268         l_product     := 'AP';
269         l_plsql_block := 'BEGIN EJINMAP.get_asset_key_map(:l_table,:l_product,:l_sob_id,:l_select,:l_from,:l_where); END;';
270         EXECUTE IMMEDIATE l_plsql_block
271           USING l_table, l_product, l_sob_id, l_select, l_from, l_where;
272 
273         /*        EJINMAP.get_asset_key_map('AP_INVOICE_DISTRIBUTIONS_ALL',
274         'AP',
275         l_sob_id,
276         l_select,
277         l_from,
278         l_where);*/
279         l_query := 'select ' || l_select || ',Payables_Code_Combination_ID
280                    from ' || l_from ||
281                    ',FA_Mass_Additions FA  where ' || l_where ||
282                    ' AND TRANS.Invoice_ID= FA.Invoice_ID
283                     AND TRANS.Distribution_Line_Number=FA.AP_Distribution_Line_Number
284                     AND Posting_Status IN (''NEW'',''ON HOLD'')
285                     AND book_type_code=:px_mass_add_rec.book_type_code
286                     AND Feeder_System_Name=''ORACLE PAYABLES''';
287 
288       elsif (upper(px_mass_add_rec.FEEDER_SYSTEM_NAME) =
289             'ORACLE GENERAL LEDGER') then
290         l_debug_str := 'Feeder System Oracle General Ledger';
291         l_debug_str := 'Feeder System Oracle Payables';
292         l_table     := 'GL_JE_LINES';
293         l_product   := 'GL';
294 
295         l_plsql_block := 'BEGIN EJINMAP.get_asset_key_map(:l_table,:l_product,:l_sob_id,:l_select,:l_from,:l_where); END;';
296         EXECUTE IMMEDIATE l_plsql_block
297           USING l_table, l_product, l_sob_id, OUT l_select, OUT l_from, OUT l_where;
298 
299         l_query := 'SELECT AFF.Code_Combination_ID ,Mass_Addition_ID
300                    ,Invoice_Number ,FA.AP_Distribution_Line_Number
301                    ,Feeder_System_Name ,Fixed_Assets_Cost
302                    ,FA.Description Description ,Queue_Name ' ||
303                    l_select || ',Payables_Code_Combination_ID
304                    from ' || l_from ||
305                    ',FA_Mass_Additions FA  where ' || l_where ||
306                    'AND TRANS.Je_Header_ID = FA.Je_Header_ID
307                     AND TRANS.Je_Line_Num = FA.Je_Line_Num
308                     AND book_type_code = :px_mass_add_rec.book_type_code
309                     AND Posting_Status IN (''NEW'',''ON HOLD'')
310                     AND Feeder_System_Name = ''GL''';
311       else
312         l_debug_str := 'Feeder System Other';
313         --if (upper(px_mass_add_rec.FEEDER_SYSTEM_NAME) = 'OTHERS') then
314         SELECT asset_key_segment1,
315                asset_key_segment2,
316                asset_key_segment3,
317                asset_key_segment4,
318                asset_key_segment5,
319                asset_key_segment6,
320                asset_key_segment7,
321                asset_key_segment8,
322                asset_key_segment9,
323                asset_key_segment10
324           INTO l_akey_segment(1),
325                l_akey_segment(2),
326                l_akey_segment(3),
327                l_akey_segment(4),
328                l_akey_segment(5),
329                l_akey_segment(6),
330                l_akey_segment(7),
331                l_akey_segment(8),
332                l_akey_segment(9),
333                l_akey_segment(10)
334           FROM fa_mass_additions
335          WHERE mass_addition_id = px_mass_add_rec.mass_addition_id;
336 
337         BEGIN
338           l_debug_str := 'Get the Asset Key';
339           if (p_log_level_rec.statement_level) then
340             fa_debug_pkg.add(l_calling_fn,
341                              l_debug_str,
342                              '',
343                              p_log_level_rec => p_log_level_rec);
344           end if;
345           SELECT code_combination_id
346             INTO l_akey_ccid
347             FROM fa_asset_keywords
348            WHERE nvl(segment1, '-1') = nvl(l_akey_segment(1), '-1')
349              and nvl(segment2, '-1') = nvl(l_akey_segment(2), '-1')
350              and nvl(segment3, '-1') = nvl(l_akey_segment(3), '-1')
351              and nvl(segment4, '-1') = nvl(l_akey_segment(4), '-1')
352              and nvl(segment5, '-1') = nvl(l_akey_segment(5), '-1')
353              and nvl(segment6, '-1') = nvl(l_akey_segment(6), '-1')
354              and nvl(segment7, '-1') = nvl(l_akey_segment(7), '-1')
355              and nvl(segment8, '-1') = nvl(l_akey_segment(8), '-1')
356              and nvl(segment9, '-1') = nvl(l_akey_segment(9), '-1')
357              and nvl(segment10, '-1') = nvl(l_akey_segment(10), '-1');
358           px_mass_add_rec.asset_key_ccid := l_akey_ccid;
359         EXCEPTION
360           WHEN no_data_found THEN
361             SELECT FA_Asset_keywords_S.Nextval
362               INTO akey_ccid_seq
363               FROM DUAL;
364             l_debug_str := 'Insert the asset key';
365             if (p_log_level_rec.statement_level) then
366               fa_debug_pkg.add(l_calling_fn,
367                                l_debug_str,
368                                '',
369                                p_log_level_rec => p_log_level_rec);
370             end if;
371             INSERT INTO fa_asset_keywords
372               (CODE_COMBINATION_ID,
373                SEGMENT1,
374                SEGMENT2,
375                SEGMENT3,
376                SEGMENT4,
377                SEGMENT5,
378                SEGMENT6,
379                SEGMENT7,
380                SEGMENT8,
381                SEGMENT9,
382                SEGMENT10,
383                SUMMARY_FLAG,
384                ENABLED_FLAG,
385                START_DATE_ACTIVE,
386                END_DATE_ACTIVE,
387                LAST_UPDATE_DATE,
388                LAST_UPDATED_BY,
389                LAST_UPDATE_LOGIN)
390             VALUES
391               (akey_ccid_seq,
392                l_akey_segment(1),
393                l_akey_segment(2),
394                l_akey_segment(3),
395                l_akey_segment(4),
396                l_akey_segment(5),
397                l_akey_segment(6),
398                l_akey_segment(7),
399                l_akey_segment(8),
400                l_akey_segment(9),
401                l_akey_segment(10),
402                'Y',
403                'Y',
404                NULL,
405                NULL,
406                sysdate,
407                FND_GLOBAL.USER_ID,
408                -1);
409 
410             px_mass_add_rec.asset_key_ccid := akey_ccid_seq;
411           WHEN OTHERS THEN
412             ROLLBACK;
413         END;
414       end if;
415 
416       if (length(l_query) is not null) then
417         l_debug_str := 'Preparing the query, Define the Columns';
418         if (p_log_level_rec.statement_level) then
419           fa_debug_pkg.add(l_calling_fn,
420                            l_debug_str,
421                            '',
422                            p_log_level_rec => p_log_level_rec);
423         end if;
424         OPEN l_AssetKeyCur FOR l_query
425           using px_mass_add_rec.book_type_code;
426 
427         loop
428 
429           FETCH l_AssetKeyCur
430             INTO l_dist_ccid, l_mass_addition_ID, l_invoice_number, l_Dist_Line_Num, l_feeder_sys_name,
431                  l_fixed_assets_cost, l_description, l_queue_name, l_asset_Key_segment1, l_asset_Key_segment2,
432                  l_asset_Key_segment3, l_asset_Key_segment4, l_asset_Key_segment5, l_asset_Key_segment6,
433                  l_asset_Key_segment7, l_asset_Key_segment8, l_asset_Key_segment9, l_asset_Key_segment10,
434                  l_payables_ccid;
435 
436           EXIT WHEN l_AssetKeyCur%NOTFOUND;
437 
438           BEGIN
439             SELECT code_combination_id
440               INTO px_mass_add_rec.asset_key_ccid
441               FROM fa_asset_keywords
442              WHERE nvl(segment1, '-1') = nvl(l_asset_key_segment1, '-1')
443                and nvl(segment2, '-1') = nvl(l_asset_key_segment2, '-1')
444                and nvl(segment3, '-1') = nvl(l_asset_key_segment3, '-1')
445                and nvl(segment4, '-1') = nvl(l_asset_key_segment4, '-1')
446                and nvl(segment5, '-1') = nvl(l_asset_key_segment5, '-1')
447                and nvl(segment6, '-1') = nvl(l_asset_key_segment6, '-1')
448                and nvl(segment7, '-1') = nvl(l_asset_key_segment7, '-1')
449                and nvl(segment8, '-1') = nvl(l_asset_key_segment8, '-1')
450                and nvl(segment9, '-1') = nvl(l_asset_key_segment9, '-1')
451                and nvl(segment10, '-1') = nvl(l_asset_key_segment10, '-1');
452 
453           exception
454             when no_data_found then
455               SELECT FA_Asset_keywords_S.Nextval
456                 INTO akey_ccid_seq
457                 FROM DUAL;
458               INSERT INTO fa_asset_keywords
459                 (CODE_COMBINATION_ID,
460                  SEGMENT1,
461                  SEGMENT2,
462                  SEGMENT3,
463                  SEGMENT4,
464                  SEGMENT5,
465                  SEGMENT6,
466                  SEGMENT7,
467                  SEGMENT8,
468                  SEGMENT9,
469                  SEGMENT10,
470                  SUMMARY_FLAG,
471                  ENABLED_FLAG,
472                  START_DATE_ACTIVE,
473                  END_DATE_ACTIVE,
474                  LAST_UPDATE_DATE,
475                  LAST_UPDATED_BY,
476                  LAST_UPDATE_LOGIN)
477               VALUES
478                 (akey_ccid_seq,
479                  l_akey_segment(1),
480                  l_akey_segment(2),
481                  l_akey_segment(3),
482                  l_akey_segment(4),
483                  l_akey_segment(5),
484                  l_akey_segment(6),
485                  l_akey_segment(7),
486                  l_akey_segment(8),
487                  l_akey_segment(9),
488                  l_akey_segment(10),
489                  'Y',
490                  'Y',
491                  NULL,
492                  NULL,
493                  sysdate,
494                  -1,
495                  -1);
496 
497               px_mass_add_rec.asset_key_ccid := akey_ccid_seq;
498           end;
499         end loop;
500 
501         close l_AssetKeyCur;
502       end if;
503     end if;
504     return true;
505   exception
506     when others then
507       return false;
508   end;
509   /*===============================End Of FUNCTION/PROCEDURE===============================*/
510   function prepare_category(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
511                             p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
512     return boolean is
513     l_gl_ccid_rec  GL_CODE_COMBINATIONS%ROWTYPE;
514     l_mass_add_rec FA_MASSADD_PREPARE_PKG.mass_add_rec;
515     l_err_mesg     varchar2(500);
516     l_calling_fn   varchar2(40) := 'prepare_category';
517     TYPE varchar30_tbl IS TABLE OF varchar2(30) INDEX BY BINARY_INTEGER;
518     TYPE num_tbl IS TABLE OF number INDEX BY BINARY_INTEGER;
519     l_seg_num                   num_tbl;
520     l_segment                   varchar30_tbl;
521     l_major_category            varchar2(50);
522     l_minor_category            varchar2(50);
523     l_major_index               number;
524     l_minor_index               number;
525     l_major_ccid                number;
526     l_minor_ccid                number;
527     l_clearing_acct_ccid        number;
528     l_category_id               number;
529     l_gl_ccid_enabled_flag      varchar2(1);
530     l_ACCOUNTING_FLEX_STRUCTURE fa_book_controls.accounting_flex_structure%type;
531     l_bal_seg_num               NUMBER;
532     l_lookup_code               varchar2(30);
533     l_debug_str                 varchar2(1000);
534     h_chart_of_accounts_id    GL_SETS_OF_BOOKS.chart_of_accounts_id%TYPE;
535 
536     CURSOR lookup_cur(c_lookup_type varchar2) IS
537       select lookup_code
538         from fa_lookups
539        where lookup_type = c_lookup_type
540          and enabled_flag = 'Y';
541 
542   begin
543     Select sob.chart_of_accounts_id
544       into h_chart_of_accounts_id
545       From fa_book_controls bc, gl_sets_of_books sob
546      Where sob.set_of_books_id = bc.set_of_books_id
547        And bc.book_type_code = px_mass_add_rec.book_type_code;
548 
549     if (px_mass_add_rec.PAYABLES_CODE_COMBINATION_ID is not null) then
550       l_debug_str := 'Get the Accounting Flex Field';
551       if (p_log_level_rec.statement_level) then
552         fa_debug_pkg.add(l_calling_fn,
553                          l_debug_str,
554                          '',
555                          p_log_level_rec => p_log_level_rec);
556       end if;
557       for i in 1 .. 30 loop
558         l_segment(i) := null;
559         l_seg_num(i) := -1;
560       end loop;
561       l_debug_str := 'Get the Category Mapping';
562       if (p_log_level_rec.statement_level) then
563         fa_debug_pkg.add(l_calling_fn,
564                          l_debug_str,
565                          '',
566                          p_log_level_rec => p_log_level_rec);
567       end if;
568       FOR rec IN lookup_cur('CATEGORY MAPPING FOR COA') LOOP
569         l_seg_num(to_number(substr(rec.lookup_code, 8))) := 1;
570       END LOOP;
571 
572       select Segment1,
573              Segment2,
574              Segment3,
575              Segment4,
576              Segment5,
577              Segment6,
578              Segment7,
579              Segment8,
580              Segment9,
581              Segment10,
582              Segment11,
583              Segment12,
584              Segment13,
585              Segment14,
586              Segment15,
587              Segment16,
588              Segment17,
589              Segment18,
590              Segment19,
591              Segment20,
592              Segment21,
593              Segment22,
594              Segment23,
595              Segment24,
596              Segment25,
597              Segment26,
598              Segment27,
599              Segment28,
600              Segment29,
601              Segment30,
602              enabled_flag
603         into l_segment(1),
604              l_segment(2),
605              l_segment(3),
606              l_segment(4),
607              l_segment(5),
608              l_segment(6),
609              l_segment(7),
610              l_segment(8),
611              l_segment(9),
612              l_segment(10),
613              l_segment(11),
614              l_segment(12),
615              l_segment(13),
616              l_segment(14),
617              l_segment(15),
618              l_segment(16),
619              l_segment(17),
620              l_segment(18),
621              l_segment(19),
622              l_segment(20),
623              l_segment(21),
624              l_segment(22),
625              l_segment(23),
626              l_segment(24),
627              l_segment(25),
628              l_segment(26),
629              l_segment(27),
630              l_segment(28),
631              l_segment(29),
632              l_segment(30),
633              l_gl_ccid_enabled_flag
634         from gl_code_combinations
635         where code_combination_id =
636              px_mass_add_rec.payables_code_combination_id
637 	and chart_of_accounts_id = h_chart_of_accounts_id;
638 
639       for i in 1 .. 30 loop
640         IF (l_seg_num(i) < 0) THEN
641           l_segment(i) := null;
642         END IF;
643       end loop;
644       if (px_mass_add_rec.asset_type = 'CAPITALIZED') then
645         l_debug_str := 'Get the Clearing Account for Capitalized Assets';
646         if (p_log_level_rec.statement_level) then
647           fa_debug_pkg.add(l_calling_fn,
648                            l_debug_str,
649                            '',
650                            p_log_level_rec => p_log_level_rec);
651         end if;
652         select max(code_combination_id)
653           into l_clearing_acct_ccid
654           from gl_code_combinations gl_ccid
655          where decode(l_segment(1), null, '-1', gl_ccid.Segment1) =
656                nvl(l_segment(1), '-1')
657            and decode(l_segment(2), null, '-1', gl_ccid.Segment2) =
658                nvl(l_segment(2), '-1')
659            and decode(l_segment(3), null, '-1', gl_ccid.Segment3) =
660                nvl(l_segment(3), '-1')
661            and decode(l_segment(4), null, '-1', gl_ccid.Segment4) =
662                nvl(l_segment(4), '-1')
663            and decode(l_segment(5), null, '-1', gl_ccid.Segment5) =
664                nvl(l_segment(5), '-1')
665            and decode(l_segment(6), null, '-1', gl_ccid.Segment6) =
666                nvl(l_segment(6), '-1')
667            and decode(l_segment(7), null, '-1', gl_ccid.Segment7) =
668                nvl(l_segment(7), '-1')
669            and decode(l_segment(8), null, '-1', gl_ccid.Segment8) =
670                nvl(l_segment(8), '-1')
671            and decode(l_segment(9), null, '-1', gl_ccid.Segment9) =
672                nvl(l_segment(9), '-1')
673            and decode(l_segment(10), null, '-1', gl_ccid.Segment10) =
674                nvl(l_segment(10), '-1')
675            and decode(l_segment(11), null, '-1', gl_ccid.Segment11) =
676                nvl(l_segment(11), '-1')
677            and decode(l_segment(12), null, '-1', gl_ccid.Segment12) =
678                nvl(l_segment(12), '-1')
679            and decode(l_segment(13), null, '-1', gl_ccid.Segment13) =
680                nvl(l_segment(13), '-1')
681            and decode(l_segment(14), null, '-1', gl_ccid.Segment14) =
682                nvl(l_segment(14), '-1')
683            and decode(l_segment(15), null, '-1', gl_ccid.Segment15) =
684                nvl(l_segment(15), '-1')
685            and decode(l_segment(16), null, '-1', gl_ccid.Segment16) =
686                nvl(l_segment(16), '-1')
687            and decode(l_segment(17), null, '-1', gl_ccid.Segment17) =
688                nvl(l_segment(17), '-1')
689            and decode(l_segment(18), null, '-1', gl_ccid.Segment18) =
690                nvl(l_segment(18), '-1')
691            and decode(l_segment(19), null, '-1', gl_ccid.Segment19) =
692                nvl(l_segment(19), '-1')
693            and decode(l_segment(20), null, '-1', gl_ccid.Segment20) =
694                nvl(l_segment(20), '-1')
695            and decode(l_segment(21), null, '-1', gl_ccid.Segment21) =
696                nvl(l_segment(21), '-1')
697            and decode(l_segment(22), null, '-1', gl_ccid.Segment22) =
698                nvl(l_segment(22), '-1')
699            and decode(l_segment(23), null, '-1', gl_ccid.Segment23) =
700                nvl(l_segment(23), '-1')
701            and decode(l_segment(24), null, '-1', gl_ccid.Segment24) =
702                nvl(l_segment(24), '-1')
703            and decode(l_segment(25), null, '-1', gl_ccid.Segment25) =
704                nvl(l_segment(25), '-1')
705            and decode(l_segment(26), null, '-1', gl_ccid.Segment26) =
706                nvl(l_segment(26), '-1')
707            and decode(l_segment(27), null, '-1', gl_ccid.Segment27) =
708                nvl(l_segment(27), '-1')
709            and decode(l_segment(28), null, '-1', gl_ccid.Segment28) =
710                nvl(l_segment(28), '-1')
711            and decode(l_segment(29), null, '-1', gl_ccid.Segment29) =
712                nvl(l_segment(29), '-1')
713            and decode(l_segment(30), null, '-1', gl_ccid.Segment30) =
714                nvl(l_segment(30), '-1')
715            and chart_of_accounts_id = h_chart_of_accounts_id
716            and exists
717          (select 1
718                   from fa_category_books cat
719                  where cat.ASSET_CLEARING_ACCOUNT_CCID =
720                        gl_ccid.code_combination_id
721                    and cat.book_type_code = px_mass_add_rec.book_type_code);
722         l_debug_str := 'Get the Category for Capitalized Assets';
723         if (p_log_level_rec.statement_level) then
724           fa_debug_pkg.add(l_calling_fn,
725                            l_debug_str,
726                            '',
727                            p_log_level_rec => p_log_level_rec);
728         end if;
729         select category_id
730           into px_mass_add_rec.ASSET_CATEGORY_ID
731           from fa_category_books
732          where ASSET_CLEARING_ACCOUNT_CCID = l_clearing_acct_ccid
733            and book_type_code = px_mass_add_rec.book_type_code
734            and rownum = 1;
735       elsif (px_mass_add_rec.asset_type = 'CIP') then
736         l_debug_str := 'Get the Clearing Account for CIP Assets';
737         if (p_log_level_rec.statement_level) then
738           fa_debug_pkg.add(l_calling_fn,
739                            l_debug_str,
740                            '',
741                            p_log_level_rec => p_log_level_rec);
742         end if;
743         select max(code_combination_id)
744           into l_clearing_acct_ccid
745           from gl_code_combinations gl_ccid
746          where decode(l_segment(1), null, '-1', gl_ccid.Segment1) =
747                nvl(l_segment(1), '-1')
748            and decode(l_segment(2), null, '-1', gl_ccid.Segment2) =
749                nvl(l_segment(2), '-1')
750            and decode(l_segment(3), null, '-1', gl_ccid.Segment3) =
751                nvl(l_segment(3), '-1')
752            and decode(l_segment(4), null, '-1', gl_ccid.Segment4) =
753                nvl(l_segment(4), '-1')
754            and decode(l_segment(5), null, '-1', gl_ccid.Segment5) =
755                nvl(l_segment(5), '-1')
756            and decode(l_segment(6), null, '-1', gl_ccid.Segment6) =
757                nvl(l_segment(6), '-1')
758            and decode(l_segment(7), null, '-1', gl_ccid.Segment7) =
759                nvl(l_segment(7), '-1')
760            and decode(l_segment(8), null, '-1', gl_ccid.Segment8) =
761                nvl(l_segment(8), '-1')
762            and decode(l_segment(9), null, '-1', gl_ccid.Segment9) =
763                nvl(l_segment(9), '-1')
764            and decode(l_segment(10), null, '-1', gl_ccid.Segment10) =
765                nvl(l_segment(10), '-1')
766            and decode(l_segment(11), null, '-1', gl_ccid.Segment11) =
767                nvl(l_segment(11), '-1')
768            and decode(l_segment(12), null, '-1', gl_ccid.Segment12) =
769                nvl(l_segment(12), '-1')
770            and decode(l_segment(13), null, '-1', gl_ccid.Segment13) =
771                nvl(l_segment(13), '-1')
772            and decode(l_segment(14), null, '-1', gl_ccid.Segment14) =
773                nvl(l_segment(14), '-1')
774            and decode(l_segment(15), null, '-1', gl_ccid.Segment15) =
775                nvl(l_segment(15), '-1')
776            and decode(l_segment(16), null, '-1', gl_ccid.Segment16) =
777                nvl(l_segment(16), '-1')
778            and decode(l_segment(17), null, '-1', gl_ccid.Segment17) =
779                nvl(l_segment(17), '-1')
780            and decode(l_segment(18), null, '-1', gl_ccid.Segment18) =
781                nvl(l_segment(18), '-1')
782            and decode(l_segment(19), null, '-1', gl_ccid.Segment19) =
783                nvl(l_segment(19), '-1')
784            and decode(l_segment(20), null, '-1', gl_ccid.Segment20) =
785                nvl(l_segment(20), '-1')
786            and decode(l_segment(21), null, '-1', gl_ccid.Segment21) =
787                nvl(l_segment(21), '-1')
788            and decode(l_segment(22), null, '-1', gl_ccid.Segment22) =
789                nvl(l_segment(22), '-1')
790            and decode(l_segment(23), null, '-1', gl_ccid.Segment23) =
791                nvl(l_segment(23), '-1')
792            and decode(l_segment(24), null, '-1', gl_ccid.Segment24) =
793                nvl(l_segment(24), '-1')
794            and decode(l_segment(25), null, '-1', gl_ccid.Segment25) =
795                nvl(l_segment(25), '-1')
796            and decode(l_segment(26), null, '-1', gl_ccid.Segment26) =
797                nvl(l_segment(26), '-1')
798            and decode(l_segment(27), null, '-1', gl_ccid.Segment27) =
799                nvl(l_segment(27), '-1')
800            and decode(l_segment(28), null, '-1', gl_ccid.Segment28) =
801                nvl(l_segment(28), '-1')
802            and decode(l_segment(29), null, '-1', gl_ccid.Segment29) =
803                nvl(l_segment(29), '-1')
804            and decode(l_segment(30), null, '-1', gl_ccid.Segment30) =
805                nvl(l_segment(30), '-1')
806            and chart_of_accounts_id = h_chart_of_accounts_id
807            and exists
808          (select 1
809                   from fa_category_books cat
810                  where cat.WIP_CLEARING_ACCOUNT_CCID =
811                        gl_ccid.code_combination_id
812                    and cat.book_type_code = px_mass_add_rec.book_type_code);
813         l_debug_str := 'Get the Clearing Account for CIP Assets';
814         if (p_log_level_rec.statement_level) then
815           fa_debug_pkg.add(l_calling_fn,
816                            l_debug_str,
817                            '',
818                            p_log_level_rec => p_log_level_rec);
819         end if;
820         select category_id
821           into px_mass_add_rec.ASSET_CATEGORY_ID
822           from fa_category_books
823          where WIP_CLEARING_ACCOUNT_CCID = l_clearing_acct_ccid
824            and book_type_code = px_mass_add_rec.book_type_code
825            and rownum = 1;
826       END IF;
827 
828     end if;
829     return true;
830   exception
831     when too_many_rows then
832       return false;
833     when no_data_found then
834       return false;
835     when others then
836       return false;
837   end;
838   /*===============================End Of FUNCTION/PROCEDURE===============================*/
839   -- Author  : SKCHAWLA
840   -- Created : 5/16/2005 2:30:36 PM
841   -- Purpose : To Prepare asset key and category id for common customers
842 
843   function prep_asset_key_category(p_book_type_code varchar2,
844                                    p_log_level_rec  IN FA_API_TYPES.log_level_rec_type default null)
845     return boolean is
846     l_mass_add_rec FA_MASSADD_PREPARE_PKG.mass_add_rec;
847     l_batch_size   number := 500;
848     l_count        number;
849     Result         boolean;
850     l_status       number;
851     l_debug_str    varchar2(1000);
852 
853     l_mass_add_rec_tbl FA_MASSADD_PREPARE_PKG.mass_add_rec_tbl;
854 
855     --l_mass_add_dist_tbl mass_add_dist_tbl;
856     l_calling_fn        varchar2(40) := 'prepare_aset_key_category';
857     --Cursor to get all mass_addition lines
858     --check about the book_type_code
859     cursor GET_MASS_ADD(l_book varchar2) is
860       Select MASS_ADDITION_ID,
861              ASSET_NUMBER,
862              TAG_NUMBER,
863              DESCRIPTION,
864              ASSET_CATEGORY_ID,
865              MANUFACTURER_NAME,
866              SERIAL_NUMBER,
867              MODEL_NUMBER,
868              BOOK_TYPE_CODE,
869              DATE_PLACED_IN_SERVICE,
870              FIXED_ASSETS_COST,
871              PAYABLES_UNITS,
872              FIXED_ASSETS_UNITS,
873              PAYABLES_CODE_COMBINATION_ID,
874              EXPENSE_CODE_COMBINATION_ID,
875              LOCATION_ID,
876              ASSIGNED_TO,
877              FEEDER_SYSTEM_NAME,
878              CREATE_BATCH_DATE,
879              CREATE_BATCH_ID,
880              LAST_UPDATE_DATE,
881              LAST_UPDATED_BY,
882              REVIEWER_COMMENTS,
883              INVOICE_NUMBER,
884              VENDOR_NUMBER,
885              PO_VENDOR_ID,
886              PO_NUMBER,
887              POSTING_STATUS,
888              QUEUE_NAME,
889              INVOICE_DATE,
890              INVOICE_CREATED_BY,
891              INVOICE_UPDATED_BY,
892              PAYABLES_COST,
893              INVOICE_ID,
894              PAYABLES_BATCH_NAME,
895              DEPRECIATE_FLAG,
896              PARENT_MASS_ADDITION_ID,
897              PARENT_ASSET_ID,
898              SPLIT_MERGED_CODE,
899              AP_DISTRIBUTION_LINE_NUMBER,
900              POST_BATCH_ID,
901              ADD_TO_ASSET_ID,
902              AMORTIZE_FLAG,
903              NEW_MASTER_FLAG,
904              ASSET_KEY_CCID,
905              ASSET_TYPE,
906              DEPRN_RESERVE,
907              YTD_DEPRN,
908              BEGINNING_NBV,
909              CREATED_BY,
910              CREATION_DATE,
911              LAST_UPDATE_LOGIN,
912              SALVAGE_VALUE,
913              ACCOUNTING_DATE,
914              ATTRIBUTE1,
915              ATTRIBUTE2,
916              ATTRIBUTE3,
917              ATTRIBUTE4,
918              ATTRIBUTE5,
919              ATTRIBUTE6,
920              ATTRIBUTE7,
921              ATTRIBUTE8,
922              ATTRIBUTE9,
923              ATTRIBUTE10,
924              ATTRIBUTE11,
925              ATTRIBUTE12,
926              ATTRIBUTE13,
927              ATTRIBUTE14,
928              ATTRIBUTE15,
929              ATTRIBUTE_CATEGORY_CODE,
930              FULLY_RSVD_REVALS_COUNTER,
931              MERGE_INVOICE_NUMBER,
932              MERGE_VENDOR_NUMBER,
933              PRODUCTION_CAPACITY,
934              REVAL_AMORTIZATION_BASIS,
935              REVAL_RESERVE,
936              UNIT_OF_MEASURE,
937              UNREVALUED_COST,
938              YTD_REVAL_DEPRN_EXPENSE,
939              ATTRIBUTE16,
940              ATTRIBUTE17,
941              ATTRIBUTE18,
942              ATTRIBUTE19,
943              ATTRIBUTE20,
944              ATTRIBUTE21,
945              ATTRIBUTE22,
946              ATTRIBUTE23,
947              ATTRIBUTE24,
948              ATTRIBUTE25,
949              ATTRIBUTE26,
950              ATTRIBUTE27,
951              ATTRIBUTE28,
952              ATTRIBUTE29,
953              ATTRIBUTE30,
954              MERGED_CODE,
955              SPLIT_CODE,
956              MERGE_PARENT_MASS_ADDITIONS_ID,
957              SPLIT_PARENT_MASS_ADDITIONS_ID,
958              PROJECT_ASSET_LINE_ID,
959              PROJECT_ID,
960              TASK_ID,
961              SUM_UNITS,
962              DIST_NAME,
963              GLOBAL_ATTRIBUTE1,
964              GLOBAL_ATTRIBUTE2,
965              GLOBAL_ATTRIBUTE3,
966              GLOBAL_ATTRIBUTE4,
967              GLOBAL_ATTRIBUTE5,
968              GLOBAL_ATTRIBUTE6,
969              GLOBAL_ATTRIBUTE7,
970              GLOBAL_ATTRIBUTE8,
971              GLOBAL_ATTRIBUTE9,
972              GLOBAL_ATTRIBUTE10,
973              GLOBAL_ATTRIBUTE11,
974              GLOBAL_ATTRIBUTE12,
975              GLOBAL_ATTRIBUTE13,
976              GLOBAL_ATTRIBUTE14,
977              GLOBAL_ATTRIBUTE15,
978              GLOBAL_ATTRIBUTE16,
979              GLOBAL_ATTRIBUTE17,
980              GLOBAL_ATTRIBUTE18,
981              GLOBAL_ATTRIBUTE19,
982              GLOBAL_ATTRIBUTE20,
983              GLOBAL_ATTRIBUTE_CATEGORY,
984              CONTEXT,
985              INVENTORIAL,
986              SHORT_FISCAL_YEAR_FLAG,
987              CONVERSION_DATE,
988              ORIGINAL_DEPRN_START_DATE,
989              GROUP_ASSET_ID,
990              CUA_PARENT_HIERARCHY_ID,
991              UNITS_TO_ADJUST,
992              BONUS_YTD_DEPRN,
993              BONUS_DEPRN_RESERVE,
994              AMORTIZE_NBV_FLAG,
995              AMORTIZATION_START_DATE,
996              TRANSACTION_TYPE_CODE,
997              TRANSACTION_DATE,
998              WARRANTY_ID,
999              LEASE_ID,
1000              LESSOR_ID,
1001              PROPERTY_TYPE_CODE,
1002              PROPERTY_1245_1250_CODE,
1003              IN_USE_FLAG,
1004              OWNED_LEASED,
1005              NEW_USED,
1006              ASSET_ID,
1007              MATERIAL_INDICATOR_FLAG,
1008              cast(multiset (select MASSADD_DIST_ID dist_id,
1009                           MASS_ADDITION_ID mass_add_id,
1010                           UNITS,
1011                           DEPRN_EXPENSE_CCID,
1012                           LOCATION_ID,
1013                           EMPLOYEE_ID
1014                      from FA_MASSADD_DISTRIBUTIONS mass_dist
1015                     where mass_dist.mass_addition_id =
1016                           mass_add.mass_addition_id) as
1017                   fa_mass_add_dist_tbl) dists
1018         FROM fa_mass_additions mass_add
1019        where posting_status in ('NEW', 'ON-HOLD', 'POST')
1020          and book_type_code = l_book
1021          and nvl(merged_code, '1') not in ('MC')
1022          and (asset_key_ccid is null or asset_category_id is null);
1023 
1024   begin
1025     --Open the cursor for the mass additions
1026     open GET_MASS_ADD(p_book_type_code);
1027 
1028     -- Process all the records
1029     while true loop
1030       l_debug_str := 'In Loop';
1031       if (p_log_level_rec.statement_level) then
1032         fa_debug_pkg.add(l_calling_fn,
1033                          l_debug_str,
1034                          '',
1035                          p_log_level_rec => p_log_level_rec);
1036       end if;
1037       --fetch the records as per batch size
1038       fetch GET_MASS_ADD BULK COLLECT
1039         INTO l_mass_add_rec_tbl limit l_batch_size;
1040 
1041       --exit from the loop if no more records
1042       if (GET_MASS_ADD%NOTFOUND) and (l_mass_add_rec_tbl.count < 1) then
1043         exit;
1044       end if;
1045 
1046       --Loop to get process each mass addition line
1047       for l_count in 1 .. l_mass_add_rec_tbl.count loop
1048         l_debug_str := 'Calling prepare_asset_key';
1049         if not prepare_asset_key(l_mass_add_rec_tbl(l_count)) then
1050           l_debug_str := 'prepare_asset_key returned failure';
1051           if (p_log_level_rec.statement_level) then
1052             fa_debug_pkg.add(l_calling_fn,
1053                              l_debug_str,
1054                              '',
1055                              p_log_level_rec => p_log_level_rec);
1056           end if;
1057         end if;
1058         l_debug_str := 'Calling prepare_category';
1059         if (p_log_level_rec.statement_level) then
1060           fa_debug_pkg.add(l_calling_fn,
1061                            l_debug_str,
1062                            '',
1063                            p_log_level_rec => p_log_level_rec);
1064         end if;
1065         if not prepare_category(l_mass_add_rec_tbl(l_count)) then
1066           l_debug_str := 'prepare_category returned failuer';
1067           if (p_log_level_rec.statement_level) then
1068             fa_debug_pkg.add(l_calling_fn,
1069                              l_debug_str,
1070                              '',
1071                              p_log_level_rec => p_log_level_rec);
1072           end if;
1073         end if;
1074       end loop;
1075       l_debug_str := 'Calling update_mass_additions';
1076       if (p_log_level_rec.statement_level) then
1077         fa_debug_pkg.add(l_calling_fn,
1078                          l_debug_str,
1079                          '',
1080                          p_log_level_rec => p_log_level_rec);
1081       end if;
1082       if not
1083           FA_MASSADD_PREPARE_PKG.update_mass_additions(l_mass_add_rec_tbl,
1084                                                        p_log_level_rec => p_log_level_rec) then
1085         l_debug_str := 'update_mass_additions returned failure';
1086       end if;
1087       commit;
1088     end loop;
1089     close GET_MASS_ADD;
1090     Result := True;
1091     return(Result);
1092   exception
1093     when others then
1094       return false;
1095   end prep_asset_key_category;
1096   /**********************Funtion to merge the mass addition lines****************************/
1097   function merge_lines(p_book_type_code varchar2,
1098                        p_log_level_rec  IN FA_API_TYPES.log_level_rec_type default null)
1099     return boolean is
1100 
1101     cursor parent_mass_add(l_book_type_code varchar2) is
1102       SELECT Mass_Addition_ID,
1103              Asset_Key_CCID,
1104              Asset_Category_ID,
1105              book_type_code
1106         FROM FA_Mass_Additions
1107        WHERE Posting_Status IN ('NEW', 'ON HOLD', 'POST')
1108          AND Asset_Category_ID IS NOT NULL
1109          AND Asset_Key_CCID IS NOT NULL
1110          and book_type_code = l_book_type_code
1111        order by asset_category_id,
1112                 asset_key_ccid,
1113                 decode(merged_code, 'MP', 1, NULL, 2), -->Use an existing parent if any
1114                 fixed_assets_cost desc,
1115                 decode(posting_status, 'POST', 1, 'NEW', 2, 'ON HOLD', 3);
1116 
1117     cursor child_mass_add(l_mass_add_id number, l_asset_key_ccid number, l_asset_category_id number, l_book_type_code varchar2) is
1118       select mass_addition_id, asset_category_id, asset_key_ccid
1119         from fa_mass_additions
1120        where posting_status in ('NEW', 'ON HOLD', 'POSTED')
1121          and mass_addition_id <> l_mass_add_id
1122          and asset_category_id = l_asset_category_id
1123          and asset_key_ccid = l_asset_key_ccid
1124          and merged_code is null
1125          and book_type_code = l_book_type_code;
1126 
1127     merged_parent number;
1128     Result        boolean;
1129   begin
1130     for parent_rec in parent_mass_add(p_book_type_code) loop
1131       merged_parent := -1;
1132       for child_rec in child_mass_add(parent_rec.mass_addition_id,
1133                                       parent_rec.asset_key_ccid,
1134                                       parent_rec.asset_category_id,
1135                                       parent_rec.book_type_code) loop
1136         update fa_mass_additions
1137            set posting_status                 = 'MERGED',
1138                MERGE_PARENT_MASS_ADDITIONS_ID = parent_rec.mass_addition_id,
1139                merged_code                    = 'MC',
1140                last_update_date               = sysdate,
1141                last_updated_by                = -1,
1142                last_update_login              = -1
1143          where mass_addition_id = child_rec.mass_addition_id;
1144         merged_parent := 1;
1145       end loop;
1146       if (merged_parent = 1) then
1147         update fa_mass_additions
1148            set merged_code       = 'MP',
1149                last_update_date  = sysdate,
1150                last_updated_by   = -1,
1151                last_update_login = -1
1152          where mass_addition_id = parent_rec.mass_addition_id;
1153       end if;
1154     end loop;
1155     commit;
1156     Result := True;
1157     return(Result);
1158   exception
1159     when no_data_found then
1160       return false;
1161     when others then
1162       return false;
1163 
1164   end merge_lines;
1165 
1166   /*********************Prepare Expense Account******************************************/
1167   function prepare_expense_ccid(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
1168                                 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
1169     return boolean is
1170     l_exp_acct_col_name fnd_id_flex_segments.application_column_name%TYPE;
1171     TYPE varchar30_tbl IS TABLE OF varchar2(30) INDEX BY BINARY_INTEGER;
1172     l_segment                   varchar30_tbl;
1173     l_exp_acct_index            number;
1174     l_exp_acct_ccid             number;
1175     l_gl_ccid_enabled_flag      varchar2(1);
1176     l_ACCOUNTING_FLEX_STRUCTURE fa_book_controls.accounting_flex_structure%type;
1177 
1178     h_chart_of_accounts_id    GL_SETS_OF_BOOKS.chart_of_accounts_id%TYPE;
1179     h_flex_segment_delimiter  varchar2(5);
1180     h_flex_segment_number     number;
1181     h_num_of_segments         NUMBER;
1182     h_concat_array_segments   FND_FLEX_EXT.SEGMENTARRAY;
1183     h_new_deprn_exp_acct      VARCHAR2(26);
1184     h_cost_acct_ccid          NUMBER := 0;
1185     l_API_VERSION             NUMBER := 1.0;
1186     l_SOURCE_DISTRIB_ID_NUM_1 NUMBER;
1187     l_SOURCE_DISTRIB_ID_NUM_2 NUMBER;
1188     l_SOURCE_DISTRIB_ID_NUM_3 NUMBER;
1189     l_SOURCE_DISTRIB_ID_NUM_4 NUMBER;
1190     l_SOURCE_DISTRIB_ID_NUM_5 NUMBER;
1191     l_ACCOUNT_TYPE_CODE       VARCHAR2(30) := 'FA_EXPENSE_ACCOUNT';
1192     l_DEPRN_EXPENSE_ACCT_CCID NUMBER;
1193     l_PAYABLES_CCID           NUMBER;
1194     l_default_ccid            number;
1195 
1196     l_ACCOUNT_DEFINITION_TYPE_CODE VARCHAR2(30) := 'S';
1197     l_ACCOUNT_DEFINITION_CODE      VARCHAR2(30) := 'FA_EXPENSE_ACCOUNT';
1198     l_TRANSACTION_COA_ID           NUMBER := 101;
1199     l_MODE                         VARCHAR2(30) := 'ONLINE';
1200     l_RETURN_STATUS                VARCHAR2(1);
1201     l_MSG_COUNT                    NUMBER;
1202     l_MSG_DATA                     VARCHAR2(255);
1203 
1204     l_TARGET_CCID           NUMBER;
1205     l_CONCATENATED_SEGMENTS VARCHAR2(4000);
1206     l_plsql_block           varchar2(5000);
1207     l_calling_fn            varchar2(40) := 'prepare_expense_ccid';
1208   begin
1209 
1210     select FLEXBUILDER_DEFAULTS_CCID
1211     into l_default_ccid
1212     from fa_book_controls
1213     where book_type_code = px_mass_add_rec.book_type_code;
1214 
1215     SELECT deprn_expense_account_ccid, asset_cost_account_ccid
1216       INTO l_DEPRN_EXPENSE_ACCT_CCID, h_cost_acct_ccid
1217       FROM fa_category_books
1218      WHERE book_type_code = px_mass_add_rec.book_type_code
1219        AND category_id = px_mass_add_rec.asset_category_id;
1220 
1221     Select sob.chart_of_accounts_id
1222       into h_chart_of_accounts_id
1223       From fa_book_controls bc, gl_sets_of_books sob
1224      Where sob.set_of_books_id = bc.set_of_books_id
1225        And bc.book_type_code = px_mass_add_rec.book_type_code;
1226     l_TRANSACTION_COA_ID := h_chart_of_accounts_id;
1227 
1228     l_PAYABLES_CCID           := px_mass_add_rec.payables_code_combination_id;
1229 
1230     l_plsql_block := 'begin
1231                       fa_xla_tab_pkg.WRITE_ONLINE_TAB(
1232                       P_API_VERSION                  => :l_API_VERSION,
1233                       P_SOURCE_DISTRIB_ID_NUM_1      => :l_SOURCE_DISTRIB_ID_NUM_1,
1234                       P_SOURCE_DISTRIB_ID_NUM_2      => :l_SOURCE_DISTRIB_ID_NUM_2,
1235                       P_SOURCE_DISTRIB_ID_NUM_3      => :l_SOURCE_DISTRIB_ID_NUM_3,
1236                       P_SOURCE_DISTRIB_ID_NUM_4      => :l_SOURCE_DISTRIB_ID_NUM_4,
1237                       P_SOURCE_DISTRIB_ID_NUM_5      => :l_SOURCE_DISTRIB_ID_NUM_5,
1238                       P_ACCOUNT_TYPE_CODE            => :l_ACCOUNT_TYPE_CODE,
1239                       DEFAULT_CCID                   => :l_default_ccid,
1240                       DEPRN_EXPENSE_ACCOUNT_CCID     => :l_DEPRN_EXPENSE_ACCT_CCID,
1241                       PAYABLES_CCID                  => :l_PAYABLES_CCID,
1242                       X_RETURN_STATUS                => :l_RETURN_STATUS,
1243                       X_MSG_COUNT                    => :l_MSG_COUNT ,
1244                       X_MSG_DATA                     => :l_MSG_DATA);
1245                       end;';
1246 
1247     EXECUTE IMMEDIATE l_plsql_block
1248       USING l_API_VERSION, l_SOURCE_DISTRIB_ID_NUM_1, l_SOURCE_DISTRIB_ID_NUM_2, l_SOURCE_DISTRIB_ID_NUM_3,
1249       l_SOURCE_DISTRIB_ID_NUM_4, l_SOURCE_DISTRIB_ID_NUM_5, l_ACCOUNT_TYPE_CODE,l_default_ccid,
1250        l_DEPRN_EXPENSE_ACCT_CCID, l_PAYABLES_CCID, out l_RETURN_STATUS, out l_MSG_COUNT, out l_MSG_DATA;
1251 
1252     l_plsql_block := 'begin
1253                       FA_XLA_TAB_PKG.run(
1254                       P_API_VERSION                  => :l_API_VERSION,
1255                       P_ACCOUNT_DEFINITION_TYPE_CODE => :l_ACCOUNT_DEFINITION_TYPE_CODE,
1256                       P_ACCOUNT_DEFINITION_CODE      => :l_ACCOUNT_DEFINITION_CODE,
1257                       P_TRANSACTION_COA_ID           => :l_TRANSACTION_COA_ID ,
1258                       P_MODE                         => :l_MODE,
1259                       X_RETURN_STATUS                => :l_RETURN_STATUS,
1260                       X_MSG_COUNT                    => :l_MSG_COUNT,
1261                       X_MSG_DATA                     => :l_MSG_DATA);
1262                       end;';
1263 
1264     EXECUTE IMMEDIATE l_plsql_block
1265       USING l_API_VERSION, l_ACCOUNT_DEFINITION_TYPE_CODE, l_ACCOUNT_DEFINITION_CODE, l_TRANSACTION_COA_ID, l_MODE,
1266       out l_RETURN_STATUS, out l_MSG_COUNT, out l_MSG_DATA;
1267 
1268     l_plsql_block := 'begin
1269     fa_xla_tab_pkg.READ_ONLINE_TAB(
1270      P_API_VERSION                  => :l_API_VERSION,
1271      P_SOURCE_DISTRIB_ID_NUM_1      => :l_SOURCE_DISTRIB_ID_NUM_1,
1272      P_SOURCE_DISTRIB_ID_NUM_2      => :l_SOURCE_DISTRIB_ID_NUM_2,
1273      P_SOURCE_DISTRIB_ID_NUM_3      => :l_SOURCE_DISTRIB_ID_NUM_3,
1274      P_SOURCE_DISTRIB_ID_NUM_4      => :l_SOURCE_DISTRIB_ID_NUM_4,
1275      P_SOURCE_DISTRIB_ID_NUM_5      => :l_SOURCE_DISTRIB_ID_NUM_5,
1276      P_ACCOUNT_TYPE_CODE            => :l_ACCOUNT_TYPE_CODE,
1277      X_TARGET_CCID                  => :l_TARGET_CCID,
1278      X_CONCATENATED_SEGMENTS        => :l_CONCATENATED_SEGMENTS,
1279      X_RETURN_STATUS                => :l_RETURN_STATUS,
1280      X_MSG_COUNT                    => :l_MSG_COUNT ,
1281      X_MSG_DATA                     => :l_MSG_DATA);
1282      end;';
1283 
1284     EXECUTE IMMEDIATE l_plsql_block
1285       USING l_API_VERSION, l_SOURCE_DISTRIB_ID_NUM_1, l_SOURCE_DISTRIB_ID_NUM_2, l_SOURCE_DISTRIB_ID_NUM_3,
1286       l_SOURCE_DISTRIB_ID_NUM_4, l_SOURCE_DISTRIB_ID_NUM_5, l_ACCOUNT_TYPE_CODE, out l_TARGET_CCID,
1287       out l_CONCATENATED_SEGMENTS, out l_RETURN_STATUS, out l_MSG_COUNT, out l_MSG_DATA;
1288 
1289     px_mass_add_rec.expense_code_combination_id := l_target_ccid;
1290 
1291     return true;
1292   exception
1293     when no_data_found then
1294       return false;
1295     when too_many_rows then
1296       return false;
1297     when others then
1298       return false;
1299 
1300   end;
1301 
1302   /********************************Prepare Location*******************/
1303   function prepare_location_id(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
1304                                p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
1305     return boolean is
1306     l_location_col_name fnd_id_flex_segments.application_column_name%TYPE;
1307     TYPE varchar30_tbl IS TABLE OF varchar2(30) INDEX BY BINARY_INTEGER;
1308     TYPE num_tbl IS TABLE OF number INDEX BY BINARY_INTEGER;
1309     l_segment                   varchar30_tbl;
1310     l_seg_num                   num_tbl;
1311     l_location_index            number;
1312     l_location_seg              number;
1313     l_gl_ccid_enabled_flag      varchar2(1);
1314     l_ACCOUNTING_FLEX_STRUCTURE fa_book_controls.accounting_flex_structure%type;
1315     l_location_id               number;
1316     l_debug_str                 varchar2(1000);
1317     l_loc_seg_name              varchar2(30) := null;
1318     l_calling_fn                varchar2(40) := 'prepare_location_id';
1319     loc_seg_clr_acct_map        varchar30_tbl;
1320     loc_seg_clr_acct_map_index  num_tbl;
1321     l_loc_query                 varchar2(1000);
1322     TYPE LocationCurType IS REF CURSOR;
1323     l_LocationCur LocationCurType;
1324 
1325     CURSOR lookup_cur(c_lookup_type varchar2) IS
1326       select lookup_code
1327         from fa_lookups
1328        where lookup_type = c_lookup_type
1329          and enabled_flag = 'Y';
1330   begin
1331     for i in 1 .. 30 loop
1332       l_segment(i) := null;
1333       l_seg_num(i) := -1;
1334     end loop;
1335     select location_id
1336       into l_location_id
1337       from fa_locations
1338      where rownum = 1;
1339     l_debug_str := 'Getting Mapping for Location';
1340     if (p_log_level_rec.statement_level) then
1341       fa_debug_pkg.add(l_calling_fn,
1342                        l_debug_str,
1343                        '',
1344                        p_log_level_rec => p_log_level_rec);
1345     end if;
1346     FOR rec IN lookup_cur('LOCATION MAPPING CLEAR ACCT') LOOP
1347       l_loc_seg_name := rec.lookup_code;
1348       l_seg_num(to_number(substr(l_loc_seg_name, 8))) := 1;
1349     END LOOP;
1350     if (l_loc_seg_name is not null) then
1351       l_debug_str := 'Get values from payables_ccid';
1352       if (p_log_level_rec.statement_level) then
1353         fa_debug_pkg.add(l_calling_fn,
1354                          l_debug_str,
1355                          '',
1356                          p_log_level_rec => p_log_level_rec);
1357       end if;
1358       select Segment1,
1359              Segment2,
1360              Segment3,
1361              Segment4,
1362              Segment5,
1363              Segment6,
1364              Segment7,
1365              Segment8,
1366              Segment9,
1367              Segment10,
1368              Segment11,
1369              Segment12,
1370              Segment13,
1371              Segment14,
1372              Segment15,
1373              Segment16,
1374              Segment17,
1375              Segment18,
1376              Segment19,
1377              Segment20,
1378              Segment21,
1379              Segment22,
1380              Segment23,
1381              Segment24,
1382              Segment25,
1383              Segment26,
1384              Segment27,
1385              Segment28,
1386              Segment29,
1387              Segment30,
1388              enabled_flag
1389         into l_segment(1),
1390              l_segment(2),
1391              l_segment(3),
1392              l_segment(4),
1393              l_segment(5),
1394              l_segment(6),
1395              l_segment(7),
1396              l_segment(8),
1397              l_segment(9),
1398              l_segment(10),
1399              l_segment(11),
1400              l_segment(12),
1401              l_segment(13),
1402              l_segment(14),
1403              l_segment(15),
1404              l_segment(16),
1405              l_segment(17),
1406              l_segment(18),
1407              l_segment(19),
1408              l_segment(20),
1409              l_segment(21),
1410              l_segment(22),
1411              l_segment(23),
1412              l_segment(24),
1413              l_segment(25),
1414              l_segment(26),
1415              l_segment(27),
1416              l_segment(28),
1417              l_segment(29),
1418              l_segment(30),
1419              l_gl_ccid_enabled_flag
1420         from gl_code_combinations
1421        where code_combination_id =
1422              px_mass_add_rec.payables_code_combination_id;
1423 
1424       for i in 1 .. 30 loop
1425         IF (l_seg_num(i) < 0) THEN
1426           l_segment(i) := null;
1427         END IF;
1428       end loop;
1429       l_debug_str := 'Get the Loaction';
1430       if (p_log_level_rec.statement_level) then
1431         fa_debug_pkg.add(l_calling_fn,
1432                          l_debug_str,
1433                          '',
1434                          p_log_level_rec => p_log_level_rec);
1435       end if;
1436       /* Location lookups mapping */
1437 
1438       FOR rec IN lookup_cur('LOCATION SEGMENT1 CLEAR ACCT') LOOP
1439         loc_seg_clr_acct_map(1) := rec.lookup_code;
1440 
1441       END LOOP;
1442 
1443       FOR rec IN lookup_cur('LOCATION SEGMENT2 CLEAR ACCT') LOOP
1444         loc_seg_clr_acct_map(2) := rec.lookup_code;
1445 
1446       END LOOP;
1447       FOR rec IN lookup_cur('LOCATION SEGMENT3 CLEAR ACCT') LOOP
1448         loc_seg_clr_acct_map(3) := rec.lookup_code;
1449 
1450       END LOOP;
1451       FOR rec IN lookup_cur('LOCATION SEGMENT4 CLEAR ACCT') LOOP
1452         loc_seg_clr_acct_map(4) := rec.lookup_code;
1453 
1454       END LOOP;
1455       FOR rec IN lookup_cur('LOCATION SEGMENT5 CLEAR ACCT') LOOP
1456         loc_seg_clr_acct_map(5) := rec.lookup_code;
1457 
1458       END LOOP;
1459       FOR rec IN lookup_cur('LOCATION SEGMENT6 CLEAR ACCT') LOOP
1460         loc_seg_clr_acct_map(6) := rec.lookup_code;
1461 
1462       END LOOP;
1463       FOR rec IN lookup_cur('LOCATION SEGMENT7 CLEAR ACCT') LOOP
1464         loc_seg_clr_acct_map(7) := rec.lookup_code;
1465 
1466       END LOOP;
1467       l_loc_query := 'select max(location_id) from fa_locations fa_loc where fa_loc.' ||
1468                      l_loc_seg_name || '= ' ||
1469                      l_segment(to_number(substr(l_loc_seg_name, 8))) || '
1470                      and location_id in (select location_id
1471 			                 from fa_locations fa_loc2, gl_code_combinations gl_code
1472 					 where fa_loc.segment1 = gl_code.' ||
1473                      loc_seg_clr_acct_map(1) ||
1474                      ' and fa_loc.segment2 = gl_code.' ||
1475                      loc_seg_clr_acct_map(2) ||
1476                      ' and fa_loc.segment3 = gl_code.' ||
1477                      loc_seg_clr_acct_map(3) ||
1478                      ' and fa_loc.segment4 = gl_code.' ||
1479                      loc_seg_clr_acct_map(4) ||
1480                      ' and fa_loc.segment5 = gl_code.' ||
1481                      loc_seg_clr_acct_map(5) ||
1482                      ' and fa_loc.segment6 = gl_code.' ||
1483                      loc_seg_clr_acct_map(6) ||
1484                      ' and fa_loc.segment7 = gl_code.' ||
1485                      loc_seg_clr_acct_map(7);
1486       OPEN l_LocationCur FOR l_loc_query;
1487       FETCH l_LocationCur
1488         INTO px_mass_add_rec.LOCATION_ID;
1489       close l_LocationCur;
1490     else
1491 
1492       px_mass_add_rec.LOCATION_ID := l_location_id;
1493     END IF;
1494     if (px_mass_add_rec.LOCATION_ID is null) then
1495       px_mass_add_rec.LOCATION_ID := l_location_id;
1496     end if;
1497     return true;
1498   exception
1499     when no_data_found then
1500       px_mass_add_rec.LOCATION_ID := l_location_id;
1501       return true;
1502     when too_many_rows then
1503       px_mass_add_rec.LOCATION_ID := l_location_id;
1504       return true;
1505     when others then
1506       px_mass_add_rec.LOCATION_ID := l_location_id;
1507       return false;
1508   end;
1509   /*===============================End Of FUNCTION/PROCEDURE===============================*/
1510   function prepare_group_asset_id(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
1511                                   p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
1512     return boolean is
1513     l_debug_str       varchar2(1000);
1514     l_status          number;
1515     l_group_asset_rec FA_CREATE_GROUP_ASSET_PKG.group_asset_rec_type;
1516     l_calling_fn      varchar2(40) := 'prepare_group_asset';
1517   begin
1518     l_group_asset_rec.asset_id         := null;
1519     l_group_asset_rec.mass_addition_id := px_mass_add_rec.mass_addition_id;
1520     l_group_asset_rec.rec_mode         := 'PREPARE';
1521 
1522     l_debug_str := 'energy calling create_group_asset';
1523     if (p_log_level_rec.statement_level) then
1524       fa_debug_pkg.add(l_calling_fn,
1525                        l_debug_str,
1526                        '',
1527                        p_log_level_rec => p_log_level_rec);
1528     end if;
1529     if not
1530         FA_CREATE_GROUP_ASSET_PKG.create_group_asset(l_group_asset_rec,
1531                                                      p_log_level_rec => p_log_level_rec) then
1532       l_debug_str := 'energy create_group_asset returned failure';
1533       if (p_log_level_rec.statement_level) then
1534         fa_debug_pkg.add(l_calling_fn,
1535                          l_debug_str,
1536                          '',
1537                          p_log_level_rec => p_log_level_rec);
1538       end if;
1539     end if;
1540     px_mass_add_rec.group_asset_id := l_group_asset_rec.group_asset_id;
1541     return true;
1542   end;
1543   /*===============================End Of FUNCTION/PROCEDURE===============================*/
1544   function prepare_attributes(px_mass_add_rec IN out NOCOPY FA_MASSADD_PREPARE_PKG.mass_add_rec,
1545                               p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
1546     return boolean is
1547     l_status         varchar2(10);
1548     l_debug_str      varchar2(1000);
1549     old_expense_ccid number := -1;
1550     new_expense_ccid number := -1;
1551     l_calling_fn     varchar2(40) := 'prepare_attributes';
1552   begin
1553     if (px_mass_add_rec.location_id is null) then
1554       if not prepare_location_id(px_mass_add_rec,
1555                                  p_log_level_rec => p_log_level_rec) then
1556         l_debug_str := ' energy prepare_location_id returned failure';
1557         if (p_log_level_rec.statement_level) then
1558           fa_debug_pkg.add(l_calling_fn,
1559                            l_debug_str,
1560                            '',
1561                            p_log_level_rec => p_log_level_rec);
1562         end if;
1563       end if;
1564     end if;
1565     if (px_mass_add_rec.expense_code_combination_id is null) then
1566       if not prepare_expense_ccid(px_mass_add_rec,
1567                                   p_log_level_rec => p_log_level_rec) then
1568         l_debug_str := 'energy prepare_expense_ccid returned failure';
1569         if (p_log_level_rec.statement_level) then
1570           fa_debug_pkg.add(l_calling_fn,
1571                            l_debug_str,
1572                            '',
1573                            p_log_level_rec => p_log_level_rec);
1574         end if;
1575       end if;
1576     end if;
1577 
1578     update fa_mass_additions
1579     set location_id = px_mass_add_rec.location_id,
1580         expense_code_combination_id = px_mass_add_rec.expensE_code_combination_id
1581     where mass_addition_id = px_mass_add_rec.mass_addition_id;
1582     commit;
1583 
1584     if (px_mass_add_rec.group_asset_id is null) then
1585       if not prepare_group_asset_id(px_mass_add_rec,
1586                                     p_log_level_rec => p_log_level_rec) then
1587         l_debug_str := 'energy prepare group_asset_id returned failure';
1588         if (p_log_level_rec.statement_level) then
1589           fa_debug_pkg.add(l_calling_fn,
1590                            l_debug_str,
1591                            '',
1592                            p_log_level_rec => p_log_level_rec);
1593         end if;
1594       end if;
1595     end if;
1596     l_debug_str := 'Calling check_addition_or_adj';
1597     if not (check_addition_or_adj(px_mass_add_rec,
1598                                   l_status,
1599                                   p_log_level_rec => p_log_level_rec)) then
1600       l_debug_str := 'check_addition_or_adj';
1601       if (p_log_level_rec.statement_level) then
1602         fa_debug_pkg.add(l_calling_fn,
1603                          l_debug_str,
1604                          '',
1605                          p_log_level_rec => p_log_level_rec);
1606       end if;
1607     end if;
1608 
1609     if (l_status = 'ADDITION') then
1610       l_debug_str := 'Calling create_new_asset';
1611       if not (create_new_asset(px_mass_add_rec,
1612                                p_log_level_rec => p_log_level_rec)) then
1613         l_debug_str := 'create_new_asset';
1614         if (p_log_level_rec.statement_level) then
1615           fa_debug_pkg.add(l_calling_fn,
1616                            l_debug_str,
1617                            '',
1618                            p_log_level_rec => p_log_level_rec);
1619         end if;
1620       end if;
1621     end if;
1622 
1623     if (l_status = 'ADUSTMENT') then
1624       l_debug_str := 'Calling cost_adjustment';
1625       if not (cost_adjustment(px_mass_add_rec,
1626                               p_log_level_rec => p_log_level_rec)) then
1627         l_debug_str := 'cost_adjustment';
1628         if (p_log_level_rec.statement_level) then
1629           fa_debug_pkg.add(l_calling_fn,
1630                            l_debug_str,
1631                            '',
1632                            p_log_level_rec => p_log_level_rec);
1633         end if;
1634       end if;
1635     end if;
1636     l_debug_str := 'Validating expense account for distributions';
1637     if (p_log_level_rec.statement_level) then
1638       fa_debug_pkg.add(l_calling_fn,
1639                        l_debug_str,
1640                        '',
1641                        p_log_level_rec => p_log_level_rec);
1642     end if;
1643     if (px_mass_add_rec.distributions_table.count > 0) then
1644       old_expense_ccid := px_mass_add_rec.distributions_table(1)
1645                          .deprn_expense_ccid;
1646       for dist_count in 2 .. px_mass_add_rec.distributions_table.count loop
1647 
1648         new_expense_ccid := px_mass_add_rec.distributions_table(dist_count)
1649                            .deprn_expense_ccid;
1650         if (old_expense_ccid <> new_expense_ccid) then
1651           l_debug_str                    := 'Distributions has different expense account';
1652           px_mass_add_rec.POSTING_STATUS := 'ON HOLD';
1653           px_mass_add_rec.queue_name     := 'ON HOLD';
1654         end if;
1655         old_expense_ccid := new_expense_ccid;
1656       end loop;
1657     end if;
1658 
1659     return true;
1660   exception
1661     when others then
1662       return false;
1663   end;
1664 
1665 end FA_MASSADD_PREP_ENERGY_PKG;