DBA Data[Home] [Help]

PACKAGE BODY: APPS.FARX_AJ

Source


1 PACKAGE BODY FARX_AJ as
2 /* $Header: farxajb.pls 120.22.12020000.3 2013/01/30 11:25:52 deemitta ship $ */
3 
4   procedure cost_adjust (
5         book            in varchar2,
6         begin_period    in varchar2,
7         end_period      in varchar2,
8         request_id      in number,
9         user_id         in number,
10         retcode  out nocopy number,
11         errbuf   out nocopy varchar2) is
12 
13   h_count               number;
14   h_book                varchar2(15);
15   h_period1_pod         date;
16   h_period2_pcd         date;
17   h_precision           number;
18 
19   h_acct_segs           fa_rx_shared_pkg.Seg_Array;
20   h_acct_struct         number;
21   h_concat_acct         varchar2(500);
22   h_acct_seg            number;
23   h_cc_seg              number;
24   h_bal_seg             number;
25 
26   h_cat_struct          number;
27   h_concat_cat          varchar2(500);
28   h_cat_segs            fa_rx_shared_pkg.Seg_Array;
29 
30   h_loc_struct          number;
31   h_concat_loc          varchar2(500);
32   h_loc_segs            fa_rx_shared_pkg.Seg_Array;
33 
34   h_login_id            number;
35   h_request_id          number;
36 
37   h_mass_ref_id         number;
38   h_ccid                number;
39   h_category_id         number;
40   h_location_id         number;
41   h_emp_name            varchar2(240);
42   h_emp_number          varchar2(30);
43   h_cost_acct           varchar2(25);
44   h_asset_number        varchar2(15);
45   h_tag_number          varchar2(15);
46   h_serial_number       varchar2(35);
47   h_inventorial         varchar2(3);
48   h_before_cost         number;
49   h_after_cost          number;
50   h_vendor_name         varchar2(240);
51   h_invoice_number      varchar2(50);
52   h_line_number         number;
53   h_distribution_line_number number; -- Bug#9166346
54   h_thid                number;
55   h_description         varchar2(80);
56   h_invoice_descr       varchar2(80);
57   h_invoice_adjust      number;
58   h_asset_adjust        number;
59   h_inv_flag            varchar2(1);
60   h_is_inv_adj          varchar2(3);
61   h_group_asset_number  varchar2(15);
62   h_distribution_source_book varchar2(15);
63 
64   h_mesg_name           varchar2(50);
65   h_mesg_str            varchar2(2000);
66   h_flex_error          varchar2(5);
67   h_ccid_error          number;
68 
69 cursor cost_adjust is
70 SELECT  TH.MASS_REFERENCE_ID,
71         dhcc.code_combination_id,
72         cat_bk.category_id, dh.location_id,
73         emp.name, emp.employee_number,
74         DECODE(AH.ASSET_TYPE, 'CIP',CAT_BK.CIP_COST_ACCT,
75                 CAT_BK.ASSET_COST_ACCT),
76         AD.ASSET_NUMBER,
77         ad.description, ad.tag_number, ad.serial_number, ad.inventorial,
78         bk_out.cost, bk_in.cost,
79         DECODE(NVL(PO_IN.SEGMENT1,PO_OUT.SEGMENT1),NULL,NULL,
80             NVL(PO_IN.SEGMENT1,PO_OUT.SEGMENT1)||' - '||
81             NVL(PO_IN.VENDOR_NAME,PO_OUT.VENDOR_NAME)),
82         nvl(AI_IN.invoice_number,AI_OUT.invoice_number) ,
83         /* bug#9166346 */
84         nvl(AI_IN.INVOICE_LINE_NUMBER, AI_OUT.INVOICE_LINE_NUMBER),
85         NVL(AI_IN.AP_DISTRIBUTION_LINE_NUMBER, AI_OUT.AP_DISTRIBUTION_LINE_NUMBER),
86         TH.TRANSACTION_HEADER_ID,
87         NVL(AI_IN.DESCRIPTION,AI_OUT.DESCRIPTION),
88         ROUND(SUM((DH.UNITS_ASSIGNED/AH.UNITS) *
89                 (
90          decode(it.transaction_type,'INVOICE DELETE',
91                                 0-NVL(AI_IN.FIXED_ASSETS_COST,0),
92                         'INVOICE REINSTATE',
93                                 NVL(AI_IN.FIXED_ASSETS_COST,0),
94             NVL(AI_IN.FIXED_ASSETS_COST,0)-NVL(AI_OUT.FIXED_ASSETS_COST,0)
95                          )
96         )), h_precision),
97         ROUND(SUM((DH.UNITS_ASSIGNED/AH.UNITS) *
98                 DECODE(TH.INVOICE_TRANSACTION_ID,NULL,
99                     (NVL(BK_IN.COST,0) - NVL(BK_OUT.COST,0)),
100                 (
101                 decode(it.transaction_type,'INVOICE DELETE',
102                                 0-NVL(AI_IN.FIXED_ASSETS_COST,0),
103                         'INVOICE REINSTATE',
104                                 NVL(AI_IN.FIXED_ASSETS_COST,0),
105             NVL(AI_IN.FIXED_ASSETS_COST,0)-NVL(AI_OUT.FIXED_ASSETS_COST,0)
106                                      )
107                           ))), h_precision),
108         DECODE(IT.TRANSACTION_TYPE,'INVOICE ADDITION','M',
109                                    'INVOICE ADJUSTMENT','A',
110                                    'INVOICE TRANSFER','T',
111                                    'INVOICE DELETE','D',
112                                    'INVOICE REINSTATE','R',
113                                                 NULL),
114         DECODE(IT.TRANSACTION_TYPE, NULL, 'NO', 'YES'),
115         GAD.ASSET_NUMBER GROUP_ASSET_NUMBER
116 FROM FA_INVOICE_TRANSACTIONS    IT,
117      FA_ASSET_INVOICES          AI_IN,
118      FA_ASSET_INVOICES          AI_OUT,
119      FA_BOOKS                   BK_IN,
120      FA_BOOKS                   BK_OUT,
121      FA_TRANSACTION_HEADERS     TH,
122      ( select full_name name, employee_number, person_id employee_id
123        from per_people_f
124        where TRUNC(SYSDATE) BETWEEN EFFECTIVE_START_DATE AND EFFECTIVE_END_DATE
125       ) EMP,
126      FA_DISTRIBUTION_HISTORY    DH,
127      FA_ASSET_HISTORY           AH,
128      FA_CATEGORY_BOOKS          CAT_BK,
129      FA_LOOKUPS                 FALU,
130      PO_VENDORS                 PO_IN,
131      PO_VENDORS                 PO_OUT,
132      FA_ADDITIONS               AD,
133      GL_CODE_COMBINATIONS       DHCC,
134      FA_BOOKS                   ACTIVE_BK,
135      FA_ADDITIONS_B             GAD
136 WHERE
137         TH.TRANSACTION_TYPE_CODE IN ('ADJUSTMENT','CIP ADJUSTMENT') AND
138         TH.BOOK_TYPE_CODE = h_book                          AND
139         TH.INVOICE_TRANSACTION_ID = IT.INVOICE_TRANSACTION_ID (+)       AND
140         TH.DATE_EFFECTIVE BETWEEN
141                   h_period1_pod AND
142                   nvl(h_period2_pcd,sysdate)
143 -- added to get the active group asset
144 -- in respect to the group active at end of last period
145 AND     ACTIVE_BK.book_type_code = h_book AND
146         ACTIVE_BK.ASSET_ID = TH.ASSET_ID AND
147         ACTIVE_BK.date_effective <= nvl(h_period2_pcd,sysdate) AND
148         NVL(ACTIVE_BK.date_ineffective, sysdate) >= nvl(h_period2_pcd,sysdate) AND
149         ACTIVE_BK.group_asset_id = gad.asset_id (+)
150 AND
151         DH.TRANSACTION_HEADER_ID_IN <= TH.TRANSACTION_HEADER_ID AND
152         NVL(DH.TRANSACTION_HEADER_ID_OUT, TH.TRANSACTION_HEADER_ID +1)
153                 > TH.TRANSACTION_HEADER_ID                      AND
154 /*fix for bug no.3803578 */
155         DH.BOOK_TYPE_CODE = h_distribution_source_book  AND
156         DH.ASSET_ID = TH.ASSET_ID                                   AND
157         DH.CODE_COMBINATION_ID = DHCC.CODE_COMBINATION_ID
158 AND
159         emp.employee_id (+) = dh.assigned_to
160 AND
161         CAT_BK.CATEGORY_ID = AH.CATEGORY_ID                         AND
162         CAT_BK.BOOK_TYPE_CODE = h_book
163 AND
164         BK_IN.COST <> BK_OUT.COST
165 AND
166         AD.ASSET_ID = TH.ASSET_ID
167 AND
168         BK_IN.ASSET_ID(+) = TH.ASSET_ID                             AND
169         BK_IN.BOOK_TYPE_CODE(+) = h_book                    AND
170         BK_IN.TRANSACTION_HEADER_ID_IN(+) = TH.TRANSACTION_HEADER_ID
171 AND
172         BK_OUT.ASSET_ID(+) = TH.ASSET_ID                            AND
173         BK_OUT.BOOK_TYPE_CODE(+)||'' = h_book               AND
174         BK_OUT.TRANSACTION_HEADER_ID_OUT(+) = TH.TRANSACTION_HEADER_ID
175 AND
176         AI_IN.ASSET_ID (+) = TH.ASSET_ID                AND
177         AI_IN.INVOICE_TRANSACTION_ID_IN(+) = TH.INVOICE_TRANSACTION_ID
178 AND
179         AI_OUT.ASSET_ID(+)      = TH.ASSET_ID           AND
180         AI_OUT.INVOICE_TRANSACTION_ID_OUT(+) = TH.INVOICE_TRANSACTION_ID
181 AND
182         IT.BOOK_TYPE_CODE (+) = h_book
183 AND
184         AH.ASSET_ID = TH.ASSET_ID                       AND
185         TH.DATE_EFFECTIVE BETWEEN AH.DATE_EFFECTIVE AND
186                 NVL(AH.DATE_INEFFECTIVE,
187                     nvl(h_period2_pcd,sysdate))
188 AND
189         PO_IN.VENDOR_ID(+) = AI_IN.po_vendor_id         AND
190         PO_OUT.VENDOR_ID(+) = AI_OUT.PO_VENDOR_ID
191 AND
192         FALU.LOOKUP_CODE = AH.ASSET_TYPE                AND
193         FALU.LOOKUP_TYPE = 'ASSET TYPE'
194 GROUP BY
195         TH.MASS_REFERENCE_ID,
196         dhcc.code_combination_id,
197         FALU.MEANING,cat_bk.category_id, dh.location_id,
198         emp.name, emp.employee_number,
199         DECODE(AH.ASSET_TYPE, 'CIP',CAT_BK.CIP_COST_ACCT,
200                 CAT_BK.ASSET_COST_ACCT) ,
201         AD.ASSET_NUMBER,
202         AD.DESCRIPTION, ad.tag_number, ad.serial_number, ad.inventorial,
203         bk_out.cost, bk_in.cost,
204         DECODE(NVL(PO_IN.SEGMENT1,PO_OUT.SEGMENT1),NULL,NULL,
205             NVL(PO_IN.SEGMENT1,PO_OUT.SEGMENT1)||' - '||
206             NVL(PO_IN.VENDOR_NAME,PO_OUT.VENDOR_NAME)),
207         nvl(AI_IN.invoice_number,AI_OUT.invoice_number),
208         /* Bug#9166346 */
209         nvl(AI_IN.INVOICE_LINE_NUMBER, AI_OUT.INVOICE_LINE_NUMBER),
210         NVL(AI_IN.AP_DISTRIBUTION_LINE_NUMBER, AI_OUT.AP_DISTRIBUTION_LINE_NUMBER),
211         TH.TRANSACTION_HEADER_ID,
212         NVL(AI_IN.DESCRIPTION,AI_OUT.DESCRIPTION),
213         IT.TRANSACTION_TYPE,
214         GAD.ASSET_NUMBER;
215 
216 
217 begin
218   h_book := book;
219   h_request_id := request_id;
220 
221   select fcr.last_update_login into h_login_id
222   from fnd_concurrent_requests fcr
223   where fcr.request_id = h_request_id;
224 
225   h_mesg_name := 'FA_AMT_SEL_PERIODS';
226 /* fix for bug no.3803578. Added the following query to get the distribution_source_book*/
227 select distribution_source_book into h_distribution_source_book
228  from fa_book_controls
229  where book_type_code=h_book;
230 
231   select period_open_date
232   into h_period1_pod
233   from fa_deprn_periods
234   where book_type_code = h_book and period_name = begin_period;
235 
236   select count(*) into h_count
237   from fa_deprn_periods where period_name = end_period
238   and book_type_code = h_book;
239 
240   if (h_count > 0) then
241     select period_close_date
242     into h_period2_pcd
243     from fa_deprn_periods
244     where book_type_code = h_book and period_name = end_period;
245   else
246     h_period2_pcd := null;
247   end if;
248 
249   h_mesg_name := 'FA_REC_SQL_ACCT_FLEX';
250 
251   select accounting_flex_structure
252   into h_acct_struct
253   from fa_book_controls
254   where book_type_code = h_book;
255 
256   h_mesg_name := 'FA_FA_LOOKUP_IN_SYSTEM_CTLS';
257 
258   select location_flex_structure, category_flex_structure
259   into h_loc_struct, h_cat_struct
260   from fa_system_controls;
261 
262    h_mesg_name := 'FA_RX_SEGNUMS';
263 
264    fa_rx_shared_pkg.GET_ACCT_SEGMENT_NUMBERS (
265    BOOK         => h_book,
266    BALANCING_SEGNUM     => h_bal_seg,
267    ACCOUNT_SEGNUM       => h_acct_seg,
268    CC_SEGNUM            => h_cc_seg,
269    CALLING_FN           => 'COST_ADJUST');
270 
271   select cur.precision into h_precision
272   from fa_book_controls bc, gl_sets_of_books sob, fnd_currencies cur
273   where bc.book_type_code = h_book
274   and sob.set_of_books_id = bc.set_of_books_id
275   and sob.currency_code = cur.currency_code;
276 
277   h_mesg_name := 'FA_DEPRN_SQL_DCUR';
278 
279   open cost_adjust;
280   loop
281 
282     h_mesg_name := 'FA_DEPRN_SQL_FCUR';
283 
284     fetch cost_adjust into
285         h_mass_ref_id,
286         h_ccid,
287         h_category_id,
288         h_location_id,
289         h_emp_name,
290         h_emp_number,
291         h_cost_acct,
292         h_asset_number,
293         h_description,
294         h_tag_number,
295         h_serial_number, h_inventorial,
296         h_before_cost,
297         h_after_cost,
298         h_vendor_name,
299         h_invoice_number,
300         h_line_number,
301         h_distribution_line_number,
302         h_thid,
303         h_invoice_descr,
304         h_invoice_adjust,
305         h_asset_adjust,
306         h_inv_flag,
307         h_is_inv_adj,
308         h_group_asset_number;
309 
310     if (cost_adjust%NOTFOUND) then exit;   end if;
311 
312         h_mesg_name := 'FA_RX_CONCAT_SEGS';
313         h_flex_error := 'GL#';
314         h_ccid_error := h_ccid;
315 
316         fa_rx_shared_pkg.concat_acct (
317            struct_id => h_acct_struct,
318            ccid => h_ccid,
319            concat_string => h_concat_acct,
320            segarray => h_acct_segs);
321 
322      if (h_category_id is not null) then
323 
324         h_flex_error := 'CAT#';
325         h_ccid_error := h_category_id;
326 
327         fa_rx_shared_pkg.concat_category (
328            struct_id => h_cat_struct,
329            ccid => h_category_id,
330            concat_string => h_concat_cat,
331            segarray => h_cat_segs);
332 
333      end if;
334 
335      if (h_location_id is not null) then
336 
337         h_flex_error := 'LOC#';
338         h_ccid_error := h_location_id;
339 
340         fa_rx_shared_pkg.concat_location (
341            struct_id => h_loc_struct,
342            ccid => h_location_id,
343            concat_string => h_concat_loc,
344            segarray => h_loc_segs);
345 
346      end if;
347 
348     h_mesg_name := 'FA_SHARED_INSERT_FAILED';
349 
350     insert into fa_adjust_rep_itf (
351         request_id, mass_ref_id, company, cost_center,
352         expense_Acct, cost_acct, employee_name, employee_number,
353         location, category,
354         asset_number, description, tag_number, serial_number, inventorial,
355         before_cost, after_cost, vendor_name, invoice_number,
356         line_number,distribution_line_number, invoice_description, transaction_header_id,
357         invoice_adjustment, asset_adjustment, inv_trx_flag,
358         is_inv_adj_flag, created_by, creation_date,
359         last_updated_by, last_update_date, last_update_login, group_asset_number)
360         values (request_id, h_mass_ref_id, h_acct_segs(h_bal_seg),
361         h_acct_segs(h_cc_seg), h_acct_segs(h_acct_seg),
362         h_cost_acct, h_emp_name, h_emp_number,
363         h_concat_loc, h_concat_cat, h_asset_number,
364         h_description, h_tag_number, h_serial_number, h_inventorial,
365         h_before_cost, h_after_cost, h_vendor_name,
366         h_invoice_number, h_line_number,h_distribution_line_number, h_invoice_descr, h_thid,
367         h_invoice_adjust, h_asset_adjust,
368         h_inv_flag, h_is_inv_adj,
369         user_id, sysdate, user_id, sysdate, h_login_id, h_group_asset_number);
370 
371 
372 
373   end loop;
374 
375   h_mesg_name := 'FA_DEPRN_SQL_CCUR';
376 
377   close cost_adjust;
378 
379 exception when others then
380   if SQLCODE <> 0 then
381     fa_Rx_conc_mesg_pkg.log(SQLERRM);
382   end if;
383   fnd_message.set_name('OFA',h_mesg_name);
384   if h_mesg_name = 'FA_SHARED_INSERT_FAIL' then
385         fnd_message.set_token('TABLE','FA_ADJUST_REP_ITF',FALSE);
386   end if;
387   if h_mesg_name = 'FA_RX_CONCAT_SEGS' then
388         fnd_message.set_token('CCID',to_char(h_ccid_error),FALSE);
389         fnd_message.set_token('FLEX_CODE',h_flex_error,FALSE);
390   end if;
391 
392   h_mesg_str := fnd_message.get;
393   fa_rx_conc_mesg_pkg.log(h_mesg_str);
394   retcode := 2;
395 
396 
397 end cost_adjust;
398 
399 
400 
401 
402 procedure cost_clear_rec (
403         book            in varchar2,
404         period          in varchar2,
405         request_id      in number,
406         user_id         in number,
407         retcode  out nocopy number,
408         errbuf   out nocopy varchar2)  is
409 
410 
411   h_book                varchar2(15);
412   h_count               number;
413   h_period1_pod         date;
414   h_period1_pcd         date;
415 
416 
417   h_fa_ccid             number;
418   h_ar_ccid             number;
419   h_thcode              varchar2(80);
420   h_asset_number        varchar2(15);
421   h_description         varchar2(80);
422   h_tag_number          varchar2(15);
423   h_serial_number       varchar2(35);
424   h_inventorial         varchar2(3);
425   h_vendor_name         varchar2(240);
426   h_invoice_number      varchar2(50);
427   h_line_number         number;
428   h_distribution_line_number number; --Bug#9166346
429   h_inv_description     varchar2(80);
430   h_payables_cost       number;
431 
432   h_acct_struct         number;
433   h_ar_acct_segs        fa_rx_shared_pkg.Seg_Array;
434   h_fa_acct_segs        fa_rx_shared_pkg.Seg_Array;
435   h_concat_ar           varchar2(500);
436   h_concat_fa           varchar2(500);
437   h_bal_seg             number;
438   h_cc_seg              number;
439   h_acct_seg            number;
440 
441   h_request_id          number;
442   h_login_id            number;
443 
444   h_mesg_name           varchar2(50);
445   h_mesg_str            varchar2(2000);
446   h_flex_error          varchar2(5);
447   h_ccid_error          number;
448 
449 -- Bug 15953354. Made below query in sync with main query of FASCC.rdf report
450 cursor cost_clear_lines is
451 select code_combination_id ,
452        code_combination_id,
453        tr_type_code,
454        asset_number,
455        asset_desc,
456        tag_number,
457        serial_number,
458        inventorial,
459        po_vendor_name,
460        invoice_number,
461        invoice_line_number,
462        line_num,
463        description,
464        sum(cleared_cost)
465 from (
466 select distinct
467   adj1.adjustment_line_id,
468   glcc_ar.code_combination_id                    code_combination_id,
469   lu.meaning                                     tr_type_code,
470   ad.asset_number                                asset_number,
471   ad.description                                 asset_desc ,
472   ad.tag_number                                  tag_number,
473   ad.serial_number                               serial_number,
474   ad.inventorial                                 inventorial,
475   po_ai_in.vendor_name                           po_vendor_name,
476   ai_in.invoice_number                           invoice_number,
477   ai_in.invoice_line_number                      invoice_line_number,
478   ai_in.ap_distribution_line_number              line_num,
479   ai_in.description                              description,
480   decode(adj1.debit_credit_flag
481             , 'CR', adj1.adjustment_amount
482             , -adj1.adjustment_amount)           cleared_cost
483 FROM
484   fa_lookups lu                ,
485   fa_additions ad              ,
486   fa_asset_history ah          ,
487   fa_transaction_headers th    ,
488   fa_adjustments adj1      ,
489   po_vendors po_ai_in          ,
490   fa_asset_invoices ai_in  ,
491   gl_code_combinations glcc_ar ,
492   XLA_AE_HEADERS HEADERS       ,
493   XLA_AE_LINES LINES           ,
494   XLA_DISTRIBUTION_LINKS LINKS ,
495   fa_book_controls BC
496 WHERE bc.book_type_code = h_book
497 AND th.book_type_code = bc.book_type_code AND
498     th.date_effective BETWEEN h_period1_pod AND nvl(h_period1_pcd,sysdate)
499 AND adj1.book_type_code = th.book_type_code AND
500     adj1.transaction_header_id = th.transaction_header_id AND
501     adj1.adjustment_type = 'COST CLEARING'
502 AND lu.lookup_code = DECODE ( ah.asset_type ,
503                              'CIP' , DECODE ( th.transaction_type_code ,
504                                               'CIP ADDITION/VOID' , 'CIP ADDITION' ,
505                                               'ADDITION/VOID' , 'CIP ADDITION' ,
506                                               th.transaction_type_code )
507                              , DECODE ( th.transaction_type_code ,
508                                        'CIP ADDITION/VOID' , 'ADDITION' ,
509                                        'ADDITION/VOID' , 'ADDITION' ,
510                                        th.transaction_type_code ) )
511 AND lu.lookup_type                            = 'FAXOLTRX'
512 AND ad.asset_id                               = adj1.asset_id
513 AND ah.asset_id                               = th.asset_id
514 AND th.date_effective between ah.date_effective and nvl(ah.date_ineffective, sysdate)
515 AND ah.asset_type                             <> 'EXPENSED'
516 AND ai_in.asset_id (+)                            = adj1.asset_id
517 and ai_in.source_line_id (+)                    = adj1.source_line_id
518 AND po_ai_in.vendor_id (+)                    = ai_in.po_vendor_id
519 AND LINKS.SOURCE_DISTRIBUTION_ID_NUM_1  = ADJ1.TRANSACTION_HEADER_ID
520 AND LINKS.SOURCE_DISTRIBUTION_ID_NUM_2  = ADJ1.ADJUSTMENT_LINE_ID
521 AND LINKS.APPLICATION_ID                = 140
522 AND LINKS.SOURCE_DISTRIBUTION_TYPE      = 'TRX'
523 AND HEADERS.AE_HEADER_ID                = LINKS.AE_HEADER_ID
524 AND HEADERS.LEDGER_ID                   = BC.SET_OF_BOOKS_ID
525 AND HEADERS.APPLICATION_ID              = 140
526 AND LINES.AE_HEADER_ID                  = LINKS.AE_HEADER_ID
527 AND LINES.AE_LINE_NUM                   = LINKS.AE_LINE_NUM
528 AND LINES.APPLICATION_ID                = 140
529 AND glcc_ar.code_combination_id         = LINES.CODE_COMBINATION_ID)
530 group by
531        code_combination_id,
532        tr_type_code,
533        asset_number,
534        asset_desc,
535        tag_number,
536        serial_number,
537        inventorial,
538        po_vendor_name,
539        invoice_number,
540        invoice_line_number,
541        line_num,
542        description;
543 
544  cc_value       gl_code_combinations.segment1%TYPE;
545 begin
546 
547   retcode := 0;
548   h_book := book;
549   h_request_id := request_id;
550 
551   select fcr.last_update_login into h_login_id
552   from fnd_concurrent_requests fcr
553   where fcr.request_id = h_request_id;
554 
555   h_mesg_name := 'FA_AMT_SEL_PERIODS';
556 
557   select period_open_date, period_close_date
558   into h_period1_pod, h_period1_pcd
559   from fa_deprn_periods
560   where book_type_code = h_book and period_name = period;
561 
562   h_mesg_name := 'FA_REC_SQL_ACCT_FLEX';
563 
564   select accounting_flex_structure
565   into h_acct_struct
566   from fa_book_controls
567   where book_type_code = h_book;
568 
569    h_mesg_name := 'FA_RX_SEGNUMS';
570 
571    fa_rx_shared_pkg.GET_ACCT_SEGMENT_NUMBERS (
572    BOOK         => h_book,
573    BALANCING_SEGNUM     => h_bal_seg,
574    ACCOUNT_SEGNUM       => h_acct_seg,
575    CC_SEGNUM            => h_cc_seg,
576    CALLING_FN           => 'COST_CLEAR_REC');
577 
578 
579   h_mesg_name := 'FA_DEPRN_SQL_DCUR';
580 
581   open cost_clear_lines;
582   loop
583 
584     h_mesg_name := 'FA_DEPRN_SQL_FCUR';
585 
586     fetch cost_clear_lines into
587         h_fa_ccid,
588         h_ar_ccid,
589         h_thcode,
590         h_asset_number,
591         h_description,
592         h_tag_number,
593         h_serial_number,
594         h_inventorial,
595         h_vendor_name,
596         h_invoice_number,
597         h_line_number,
598         h_distribution_line_number,   -- Bug#9166346
599         h_inv_description,
600         h_payables_cost;
601 
602 
603 
604 
605     if (cost_clear_lines%NOTFOUND) then exit;  end if;
606 
607         h_mesg_name := 'FA_RX_CONCAT_SEGS';
608         h_flex_error := 'GL#';
609         h_ccid_error := h_ar_ccid;
610 
611         fa_rx_shared_pkg.concat_acct (
612            struct_id => h_acct_struct,
613            ccid => h_ar_ccid,
614            concat_string => h_concat_ar,
615            segarray => h_ar_acct_segs);
616 
617     if (h_fa_ccid is not null) then
618 
619         h_flex_error := 'GL#';
620         h_ccid_error := h_fa_ccid;
621 
622         fa_rx_shared_pkg.concat_acct (
623            struct_id => h_acct_struct,
624            ccid => h_fa_ccid,
625            concat_string => h_concat_fa,
626            segarray => h_fa_acct_segs);
627 
628       -- Bug 15953354  h_ar_acct_segs(h_bal_seg) := h_fa_acct_segs(h_bal_seg);
629     else
630         h_fa_acct_segs(h_bal_seg) := null;
631         h_fa_acct_segs(h_cc_seg) := null;
632         h_fa_acct_segs(h_acct_seg) := null;
633     end if;
634 
635 
636     h_mesg_name := 'FA_SHARED_INSERT_FAILED';
637     -- Bug#9166346
638     insert into fa_costclear_rep_itf (
639         request_id, company, cost_Center, account, transaction_type,
640         asset_number, description, tag_number, serial_number,
641         vendor_name, invoice_number, line_number,distribution_line_number, inventorial,
642         inv_description, payables_cost, created_by,
643         creation_date, last_updated_by, last_update_date,
644         last_update_login) values (request_id,
645         h_ar_acct_segs(h_bal_seg), h_ar_acct_segs(h_cc_seg),
646         h_ar_acct_segs(h_acct_seg), h_thcode, h_asset_number, h_description,
647         h_tag_number, h_serial_number, h_vendor_name,
648         h_invoice_number, h_line_number,h_distribution_line_number, h_inventorial, h_inv_description,
649         h_payables_cost, user_id, sysdate, user_id, sysdate, h_login_id);
650 
651 
652 
653   end loop;
654 
655   h_mesg_name := 'FA_DEPRN_SQL_CCUR';
656 
657   close cost_clear_lines;
658 
659 exception when others then
660   if SQLCODE <> 0 then
661     fa_Rx_conc_mesg_pkg.log(SQLERRM);
662   end if;
663   fnd_message.set_name('OFA',h_mesg_name);
664   if h_mesg_name = 'FA_SHARED_INSERT_FAIL' then
665         fnd_message.set_token('TABLE','FA_COSTCLEAR_REP_ITF',FALSE);
666   end if;
667   if h_mesg_name = 'FA_RX_CONCAT_SEGS' then
668         fnd_message.set_token('CCID',to_char(h_ccid_error),FALSE);
669         fnd_message.set_token('FLEX_CODE',h_flex_error,FALSE);
670   end if;
671 
672   h_mesg_str := fnd_message.get;
673   fa_rx_conc_mesg_pkg.log(h_mesg_str);
674   retcode := 2;
675 
676 end cost_clear_rec;
677 
678 END FARX_AJ;