DBA Data[Home] [Help]

PACKAGE BODY: APPS.FARX_BL

Source


1 PACKAGE BODY FARX_BL as
2 /* $Header: farxblb.pls 120.23.12010000.1 2008/07/28 13:22:37 appldev ship $ */
3 
4 
5 -- balances_reports is Intended as private function...
6 -- please do not call directly.
7 -- Performs all report activities, given book, period range,
8 -- and report type as parameters.  Adj_Mode is currently not used.
9 
10 -- General Overview:  Consists of two main steps:
11 -- 1. Insert info into temporary table FA_BALANCES_REPORT_GT:
12 --   A. Beginning balances for all accounts (subdivided by assets)
13 --   B. Ending balances
14 --   C. Effects of depreciation/amortization
15 --   D. Effects of transactional adjustments
16 -- 2. Select from this table in a more reportable format, insert
17 -- into interface table.
18 --
19 --
20 
21 procedure balances_reports
22    (Book		in	varchar2,
23     Start_Period_Name	in	varchar2,
24     End_Period_Name	in	varchar2,
25     Report_Type		in	varchar2,
26     Adj_Mode		in	varchar2,
27     Report_Style        in      varchar2,
28     Request_id  	in	number,
29     user_id		in	number,
30     calling_fn		in	varchar2,
31     mesg	 out nocopy varchar2,
32     success	 out nocopy boolean)
33 
34   is
35     Period1_PC			number;
36     Period1_POD			date;
37     Period1_PCD			date;
38     Period2_PC			number;
39     Period2_PCD			date;
40     Distribution_Source_Book	varchar2(15);
41     Balance_Type		varchar2(2);
42     bal_seg			varchar2(25);
43     cost_seg			varchar2(25);
44     acct_seg			varchar2(25);
45     acct_flex_structure		number;
46     acct_all_segs               fa_rx_shared_pkg.Seg_Array;
47     aj_acct_all_segs		fa_rx_shared_pkg.Seg_Array;
48     seg_no                      number;
49     n_segs                      number;
50     n_ajsegs			number;
51     gl_balancing_seg  		number;
52     gl_account_seg		number;
53     fa_cost_ctr_seg		number;
54 
55     h_concat_key                varchar2(500);
56     h_concat_cat		varchar2(500);
57 
58 
59     h_login_id			number;
60     h_request_id		number;
61 
62     h_ccid			number;
63     h_account			varchar2(25);
64     h_ajccid			number;
65     h_asset			varchar2(15);
66     h_tag_number		varchar2(15);
67     h_serial_number		varchar2(35);
68     h_inventorial		varchar2(3);
69     h_description		varchar2(80);
70     h_begin			number;
71     h_end			number;
72     h_addition			number;
73     h_adjustment		number;
74     h_reclass			number;
75     h_retirement		number;
76     h_revaluation		number;
77     h_transfer			number;
78     h_depreciation		number;
79     h_capitalization		number;
80     h_tax			number;
81     h_out_of_bal_flag		varchar2(1);
82 
83     h_ccid_error		number;
84     h_br_ajccid			number;
85     h_br_account		varchar2(15);
86     h_br_rowid			rowid;
87 
88     h_nonqual_col_name		varchar2(30);
89     h_nonqual_seg_name		varchar2(30);
90     h_nonqual_seg_num		varchar2(30);
91 
92     h_nq_col_names	fa_rx_shared_pkg.Seg_Array;
93     h_nq_seg_names	fa_rx_shared_pkg.Seg_Array;
94     h_nq_seg_nums	fa_rx_shared_pkg.Seg_Array;
95     h_ctr  number;
96 
97     get_segments_success	boolean;
98 
99     get_segments_failure	exception;
100 
101 
102     h_mesg_name   varchar2(50);
103     h_mesg_str	  varchar2(2000);
104     h_table_token	varchar2(30);
105     h_flex_error	varchar2(30);
106 
107     -- Additional variables added for globalization -- statutory reporting requirements
108 
109     h_key_flex_struct           number;		/* StatReq */
110     h_cat_flex_struct           number;		/* StatReq */
111 
112     h_asset_key_ccid		number;
113     h_category_id		number;		/* StatReq */
114 
115     h_key_segs                  fa_rx_shared_pkg.Seg_Array; /* StatReq */
116     h_cat_segs			fa_rx_shared_pkg.Seg_Array; /* StatReq */
117 
118     h_asset_id			NUMBER;		/* StatReq */
119     h_stl_depreciation_rate	NUMBER;		/* StatReq */
120     h_date_placed_in_service	DATE;		/* StatReq */
121     h_life_in_months		NUMBER;		/* StatReq */
122     h_account_description	VARCHAR2(500);	/* StatReq */
123 
124     h_short_account_description VARCHAR2(240);
125     h_short_location		VARCHAR2(500);
126     h_shortconcat_key		VARCHAR2(240);
127     h_stl_method_flag		VARCHAR2(5);	/* StatReq */
128     h_rate_source_rule		VARCHAR2(10);	/* StatReq */
129 
130     h_method_code		VARCHAR2(12);	/* StatReq */
131 
132     h_Cost_Account		VARCHAR2(25);	/* StatReq */
133     h_Cost_Begin_Balance	NUMBER;		/* StatReq */
134     h_location			VARCHAR2(1500);	/* StatReq */
135 
136     -- bug 5975548 (Increased length to 1500 from 500 for following variables)
137     h_invoice_number		VARCHAR2(1500);	/* StatReq */
138     h_invoice_descr		VARCHAR2(1500);	/* StatReq */
139     h_vendor_name		VARCHAR2(1500);	/* StatReq */
140     h_retirement_type		VARCHAR2(1500);	/* StatReq */
141     -- End of changes for bug 5975548
142 
143     -- Added for bug 5975548
144     h_short_invoice_number	VARCHAR2(500);
145     h_short_invoice_descr	VARCHAR2(500);
146     h_short_vendor_name		VARCHAR2(500);
147     h_short_retirement_type	VARCHAR2(500);
148     -- End of changes for bug 5975548
149 
150     return_status		BOOLEAN;	/* StatReq */
151     acct_appl_col		VARCHAR2(240);	/* StatReq */
152     acct_segname		VARCHAR2(240);	/* StatReq */
153     acct_prompt			VARCHAR2(240);	/* StatReq */
154     acct_valueset_name		VARCHAR2(240);	/* StatReq */
155 
156   -- Additional variables for Drill Down Report
157     h_group_asset               VARCHAR2(15);  -- Group Asset_number
158 
159   -- Used in finding account segments for FA_BALANCES_REPORT_GT
160 
161   CURSOR BAL_REPORT_AJCCID IS
162     SELECT DISTINCT ADJUSTMENT_CCID, CATEGORY_BOOKS_ACCOUNT, ROWID
163 	FROM FA_BALANCES_REPORT_GT;
164 
165   -- Main selector from FA_BALANCES_REPORT_GT for asset cost
166   -- and CIP cost reports.
167 
168   CURSOR COST_REPORT (c_book VARCHAR2, c_to_date DATE, c_from_date DATE) IS		/* StatReq */
169     SELECT DISTINCT
170 	ad.asset_id,							/* StatReq */
171 	DHCC.CODE_COMBINATION_ID,
172         BAL.Category_Books_Account,
173 	BAL.Cost_Account,						/* StatReq */
174 	AD.Asset_Number,
175 	AD.tag_number,
176 	AD.description,
177 	ad.serial_number, ad.inventorial, ad.asset_key_ccid,		/* StatReq */
178 	ah.category_id,							/* StatReq */
179 	b.date_placed_in_service,					/* StatReq */
180 	m.method_code,							/* StatReq */
181 	b.life_in_months,						/* StatReq */
182 	m.stl_method_flag,						/* StatReq */
183 	m.rate_source_rule,						/* StatReq */
184 	NVL(SUM(DECODE(BAL.Source_Type_Code,
185 		'BEGIN', NVL(BAL.Cost_Begin_Balance, 0), NULL)), 0),	/* StatReq */
186 	NVL(SUM (DECODE (BAL.Source_Type_Code,
187 		'BEGIN', NVL(BAL.Amount,0), NULL)), 0),
188 	SUM (DECODE (BAL.Source_Type_Code,
189 		DECODE(REPORT_TYPE,'COST','ADDITION', 'CIP ADDITION'),
190 		NVL(BAL.Amount,0), NULL)),
191 	SUM (DECODE (BAL.Source_Type_Code,
192 		DECODE(REPORT_TYPE, 'CIP COST', 'ADDITION'),
193 		-NVL(BAL.Amount,0), NULL)),
194 	SUM (DECODE (BAL.Source_Type_Code,
195 		DECODE(REPORT_TYPE,'COST','ADJUSTMENT','CIP ADJUSTMENT'),
196 		 NVL(BAL.Amount,0), NULL)),
197 	SUM (DECODE (BAL.Source_Type_Code,
198 		'RECLASS', NVL(BAL.Amount,0), NULL)),
199 	SUM (DECODE (BAL.Source_Type_Code,
200 		DECODE(REPORT_TYPE,'COST','RETIREMENT','CIP RETIREMENT'),
201 		 -NVL(BAL.Amount,0), NULL)),
202 	SUM (DECODE (BAL.Source_Type_Code,
203 		'REVALUATION', NVL(BAL.Amount,0), NULL)),
204 	SUM (DECODE (BAL.Source_Type_Code,
205 		'TRANSFER', NVL(BAL.Amount,0), NULL)),
206 	NVL(SUM (DECODE (BAL.Source_Type_Code,
207 		'END', NVL(BAL.Amount,0), NULL)), 0),
208         nvl(AD1.Asset_Number,LU.Meaning)   -- Added for Drill Down Report
209     FROM
210 	FA_ASSET_HISTORY AH,						/* StatReq */
211 	fa_category_books cb,
212 	FA_METHODS M,							/* StatReq */
213 	FA_BOOKS B,							/* StatReq */
214 	FA_BALANCES_REPORT_GT BAL,
215 	FA_ADDITIONS AD,
216 	GL_CODE_COMBINATIONS DHCC,
217 	GL_CODE_COMBINATIONS AJCC,
218         FA_ADDITIONS AD1,
219         FA_LOOKUPS LU
220     WHERE	AD.Asset_ID		= 	BAL.Asset_ID
221     AND	DHCC.Code_Combination_ID	= 	BAL.Distribution_CCID
222     AND	AJCC.Code_Combination_ID (+) 	= 	BAL.Adjustment_CCID
223     AND B.ASSET_ID			= 	AD.ASSET_ID
224     AND B.Book_Type_Code		= 	c_book
225     AND B.Date_Ineffective		is 	NULL
226     AND B.Transaction_Header_Id_Out 	is 	NULL
227     AND nvl(M.LIFE_IN_MONTHS, -9)	= 	nvl(B.LIFE_IN_MONTHS, -9)
228     AND M.METHOD_CODE			= 	B.DEPRN_METHOD_CODE
229     AND AH.ASSET_ID			=	AD.ASSET_ID
230     and ah.category_id = cb.category_id
231     and cb.book_type_code = c_book
232     and decode(ah.asset_type,'CIP',cb.cip_cost_acct, cb.asset_cost_acct) = BAL.Category_Books_Account
233     AND c_to_date between ah.date_effective and nvl(ah.date_ineffective, c_to_date)
234     AND AD1.Asset_ID(+)                 = nvl(BAL.Group_Asset_ID,-99) -- Added for Drill Down Report
235     AND LU.Lookup_Type (+)              = 'ASSET TYPE'
236     AND LU.Lookup_Code (+)              = AD.Asset_Type
237     GROUP BY
238 	ad.asset_id,
239 	dhcc.code_combination_id,
240 	BAL.Category_Books_Account,
241 	BAL.Cost_Account,
242 	AD.ASSET_NUMBER,
243 	AD.tag_number,
244 	AD.description,
245 	ad.serial_number, ad.inventorial, ad.asset_key_ccid,
246 	ah.category_id,
247 	b.date_placed_in_service,
248 	m.method_code,
249 	b.life_in_months,
250 	m.stl_method_flag,
251 	m.rate_source_rule,
252         nvl(AD1.ASSET_NUMBER,LU.Meaning); -- Added for Drill Down Report
253 
254   -- Main selector from FA_BALANCES_REPORT_GT for accum deprn
255   -- and reval reserve reports.
256 
257 
258    CURSOR RESERVE_REPORT (c_book VARCHAR2, c_to_date DATE) IS		/* StatReq */
259      SELECT DISTINCT
260         ad.asset_id,							/* StatReq */
261 	DHCC.CODE_COMBINATION_ID,
262 	BAL.Category_Books_Account,
263 	BAL.Cost_Account,						/* StatReq */
264 	AD.Asset_Number,
265 	AD.tag_number,
266 	AD.description,
267 	ad.serial_number, ad.inventorial, ad.asset_key_ccid,
268 	ah.category_id,							/* StatReq */
269 	b.date_placed_in_service,					/* StatReq */
270 	m.method_code,							/* StatReq */
271 	b.life_in_months,						/* StatReq */
272 	m.stl_method_flag,						/* StatReq */
273 	m.rate_source_rule,						/* StatReq */
274 	NVL(SUM(DECODE(BAL.Source_Type_Code,
275 		'BEGIN', NVL(BAL.Cost_Begin_Balance, 0), NULL)), 0),	/* StatReq */
276 	SUM (DECODE (BAL.Source_Type_Code,
277 		'BEGIN', NVL(BAL.Amount,0), NULL)),
278 	SUM (DECODE (BAL.Source_Type_Code,
279 		'ADDITION', NVL(BAL.Amount,0), NULL)),
280 	SUM (DECODE (BAL.Source_Type_Code,
281 		'DEPRECIATION', NVL(BAL.Amount,0), NULL)),
282 	SUM (DECODE (BAL.Source_Type_Code,
283 		'RECLASS', NVL(BAL.Amount,0), NULL)),
284 	SUM (DECODE (BAL.Source_Type_Code,
285 		'RETIREMENT', -NVL(BAL.Amount,0), NULL)),
286 	SUM (DECODE (BAL.Source_Type_Code,
287 		'REVALUATION', NVL(BAL.Amount,0), NULL)),
288 	SUM (DECODE (BAL.Source_Type_Code,
289 		'TAX', NVL(BAL.Amount,0), NULL)),
290 	SUM (DECODE (BAL.Source_Type_Code,
291 		'TRANSFER', NVL(BAL.Amount,0), NULL)),
292 	SUM (DECODE (BAL.Source_Type_Code,
293 		'END', NVL(BAL.Amount,0), NULL)),
294         nvl(AD1.Asset_Number,LU.Meaning)   -- This is for Group Asset ID
295     FROM
296 	FA_ASSET_HISTORY AH,						/* StatReq */
297 	FA_METHODS M,							/* StatReq */
298 	FA_BOOKS B,							/* StatReq */
299 	FA_BALANCES_REPORT_GT BAL,
300 	FA_ADDITIONS AD,
301 	GL_CODE_COMBINATIONS DHCC,
302 	GL_CODE_COMBINATIONS AJCC,
303         FA_ADDITIONS AD1,  -- This is only used to get Group Asset Number
304         FA_LOOKUPS LU
305     WHERE	AD.Asset_ID	= BAL.Asset_ID
306     AND	DHCC.Code_Combination_ID	= BAL.Distribution_CCID
307     AND	AJCC.Code_Combination_ID (+)	= BAL.Adjustment_CCID
308     AND B.Book_Type_Code		= 	c_book			/* StatReq */
309     AND B.ASSET_ID			= 	AD.ASSET_ID             /* StatReq */
310     AND B.Date_Ineffective		is 	NULL			/* StatReq */
311     AND B.Transaction_Header_Id_Out 	is 	NULL			/* StatReq */
312     AND nvl(M.LIFE_IN_MONTHS, -9)	= 	nvl(B.LIFE_IN_MONTHS, -9) /* StatReq */
313     AND M.METHOD_CODE			= 	B.DEPRN_METHOD_CODE	/* StatReq */
314     AND AH.ASSET_ID			=	AD.ASSET_ID		/* StatReq */
315     AND AH.DATE_EFFECTIVE		<=	c_to_date		/* StatReq */
316     AND NVL(AH.DATE_INEFFECTIVE, SYSDATE + 1) >	c_to_date		/* StatReq */
317     AND (B.GROUP_ASSET_ID               is null OR
318          nvl(Report_Style,'S') = 'D') -- Added for Drill down report
319     AND AD1.Asset_ID(+)                 = nvl(BAL.Group_Asset_ID,-99)
320     AND LU.Lookup_Type (+)              = 'ASSET TYPE'
321     AND LU.Lookup_Code (+)              = AD.Asset_Type
322     GROUP BY
323 	ad.asset_id, 							/* StatReq */
324 	DHCC.CODE_COMBINATION_ID,
325 	BAL.Category_Books_Account,
326 	BAL.Cost_Account,						/* StatReq */
327 	AD.ASSET_NUMBER,
328 	AD.TAG_NUMBER,
329 	AD.DESCRIPTION,	ad.serial_number, ad.inventorial, ad.asset_key_ccid,
330 	ah.category_id,							/* StatReq */
331 	b.date_placed_in_service,					/* StatReq */
332 	m.method_code,							/* StatReq */
333 	b.life_in_months,						/* StatReq */
334 	m.stl_method_flag,						/* StatReq */
335 	m.rate_source_rule,						/* StatReq */
336         nvl(AD1.ASSET_NUMBER,LU.Meaning); -- Added for Drill Down Report
337 
338   CURSOR PERIOD_INFO IS
339     SELECT	P1.Period_Counter,
340 		P1.Period_Open_Date,
341 		P1.Period_Close_Date,
342 		P2.Period_Counter,
343 		NVL(P2.Period_Close_Date, SYSDATE),
344 		BC.Distribution_Source_Book,
345 		BC.Accounting_Flex_Structure
346     FROM	FA_DEPRN_PERIODS P1,
347 		FA_DEPRN_PERIODS P2,
348 		FA_BOOK_CONTROLS BC
349     WHERE	BC.Book_Type_Code	= Book
350     AND		P1.Book_Type_Code	= Book			AND
351 		P1.Period_Name		= Start_Period_Name
352     AND		P2.Book_Type_Code	= Book			AND
353 		P2.Period_Name		= End_Period_Name;
354 
355     -- Cursor for Drill Down Report
356     CURSOR GROUP_ASSETS IS
357       SELECT DISTINCT BAL.Group_Asset_ID Group_Asset_ID
358         FROM FA_BALANCES_REPORT_GT BAL
359        WHERE BAL.Asset_ID = BAL.Group_Asset_ID;
360 
361     CURSOR GROUP_RESERVE_AMOUNTS (p_group_asset_id number) is
362       SELECT
363 	NVL(SUM(DECODE(BAL.Source_Type_Code,
364 		'BEGIN', NVL(BAL.Cost_Begin_Balance, 0), NULL)), 0)	/* StatReq */
365       FROM  FA_BALANCES_REPORT_GT  BAL
366       WHERE BAL.Group_Asset_id = p_group_asset_id
367         AND BAL.Group_Asset_id <> BAL.Asset_id;
368 
369     CURSOR GROUP_COST_AMOUNTS (p_group_asset_id number) is
370       SELECT
371 	NVL(SUM(DECODE(BAL.Source_Type_Code,
372 		'BEGIN', NVL(BAL.Cost_Begin_Balance, 0), NULL)), 0),
373 	NVL(SUM (DECODE (BAL.Source_Type_Code,
374 		'BEGIN', NVL(BAL.Amount,0), NULL)), 0),
375 	SUM (DECODE (BAL.Source_Type_Code,
376 		DECODE(REPORT_TYPE,'COST','ADDITION', 'CIP ADDITION'),
377 		NVL(BAL.Amount,0), NULL)),
378 	SUM (DECODE (BAL.Source_Type_Code,
379 		DECODE(REPORT_TYPE, 'CIP COST', 'ADDITION'),
380 		-NVL(BAL.Amount,0), NULL)),
381 	SUM (DECODE (BAL.Source_Type_Code,
382 		DECODE(REPORT_TYPE,'COST','ADJUSTMENT','CIP ADJUSTMENT'),
383 		 NVL(BAL.Amount,0), NULL)),
384 	SUM (DECODE (BAL.Source_Type_Code,
385 		'RECLASS', NVL(BAL.Amount,0), NULL)),
386 	SUM (DECODE (BAL.Source_Type_Code,
387 		DECODE(REPORT_TYPE,'COST','RETIREMENT','CIP RETIREMENT'),
388 		 -NVL(BAL.Amount,0), NULL)),
389 	SUM (DECODE (BAL.Source_Type_Code,
390 		'REVALUATION', NVL(BAL.Amount,0), NULL)),
391 	SUM (DECODE (BAL.Source_Type_Code,
392 		'TRANSFER', NVL(BAL.Amount,0), NULL)),
393 	NVL(SUM (DECODE (BAL.Source_Type_Code,
394 		'END', NVL(BAL.Amount,0), NULL)), 0)
395       FROM  FA_BALANCES_REPORT_GT  BAL
396       WHERE BAL.Group_Asset_id = p_group_asset_id
397         AND BAL.Group_Asset_id <> BAL.Asset_id;
398 
399 --  cursor non_qualified_segs is
400 --        SELECT s.application_column_name,
401 --               s.segment_name,
402 --		s.segment_num
403 --          FROM fnd_id_flex_segments_vl s
404 --         WHERE s.application_id = 101
405 --           AND s.id_flex_code = 'GL#'
406 --           AND s.id_flex_num  = Acct_Flex_STructure
407 --           AND s.enabled_flag = 'Y'
408 --	and 1 = (select count(*)
409 --	from fnd_segment_attribute_values
410 --	where application_id = s.application_id
411 --	and id_flex_code = s.id_flex_code
412 --	and id_flex_num = s.id_flex_num and attribute_value = 'Y'
413 --	and application_column_name = s.application_column_name);
414 
415 
416   begin
417 
418 fa_debug_pkg.add('farxblb','report_style in main (1)', Report_Style);
419 
420 --    acct_all_segs(1) := '';
421 --    acct_all_segs(2) := '';
422 --    acct_all_segs(3) := '';
423 --    acct_all_segs(4) := '';
424 --    acct_all_segs(5) := '';
425 --    acct_all_segs(6) := '';
426 --    acct_all_segs(7) := '';
427     --  acct_all_segs(8) := '';
428     --  acct_all_segs(9) := '';
429     --  acct_all_segs(10) := '';
430     --  acct_all_segs(11) := '';
431     --  acct_all_segs(12) := '';
432     --  acct_all_segs(13) := '';
433     --  acct_all_segs(14) := '';
434     --  acct_all_segs(15) := '';
435     --  acct_all_segs(16) := '';
436     --  acct_all_segs(17) := '';
437     --  acct_all_segs(18) := '';
438     --  acct_all_segs(19) := '';
439     --  acct_all_segs(20) := '';
440     --  acct_all_segs(21) := '';
441     --  acct_all_segs(22) := '';
442     --  acct_all_segs(23) := '';
443     --  acct_all_segs(24) := '';
444     --  acct_all_segs(25) := '';
445     --  acct_all_segs(26) := '';
446     --  acct_all_segs(27) := '';
447     --  acct_all_segs(28) := '';
448     --  acct_all_segs(29) := '';
449     --  acct_all_segs(30) := '';
450 
451 
452 
453     success := FALSE;
454 
455     h_request_id := request_id;
456 
457 
458     fnd_profile.get('LOGIN_ID',h_login_id);
459 
460 
461 
462   -- Select dates corresponding to given period range.
463   -- Error out if periods given in range do not exist.
464   -- Also get structure_id
465 
466   h_mesg_name := 'FA_AMT_SEL_PERIODS';
467 
468     OPEN PERIOD_INFO;
469     FETCH PERIOD_INFO INTO
470     	Period1_PC,
471 	Period1_POD,
472 	Period1_PCD,
473 	Period2_PC,
474 	Period2_PCD,
475 	Distribution_Source_Book,
476 	Acct_Flex_Structure;
477 
478     if (PERIOD_INFO%NOTFOUND) then
479 	h_mesg_name := 'FA_SHARED_SEL_DEPRN_PERIODS';
480   	h_mesg_str := fnd_message.get;
481   	fa_rx_conc_mesg_pkg.log(h_mesg_str);
482 
483 	CLOSE PERIOD_INFO;
484 	return;
485     end if;
486     CLOSE PERIOD_INFO;
487 
488 
489     if (Report_Type = 'RESERVE' or Report_Type = 'REVAL RESERVE') then
490 	Balance_Type := 'CR';
491     else
492 	Balance_Type := 'DR';
493     end if;
494 
495     h_mesg_name := 'FA_SHARED_DELETE_FAILED';
496     h_table_token := 'FA_BALANCES_REPORT_GT';
497 
498     -- no longer needed with GT
499     -- DELETE FROM FA_BALANCES_REPORT_GT;
500 
501     h_table_token := 'FA_LOOKUPS';
502 
503 -- bug 1068054
504 
505     Delete from fa_lookups_b
506     where lookup_type = 'REPORT TYPE';
507 
508 
509     Delete from fa_lookups_tl
510     where lookup_type = 'REPORT TYPE';
511 
512 
513     h_mesg_name := 'FA_SHARED_INSERT_FAILED';
514 -- bug 1068054
515 
516     INSERT INTO FA_LOOKUPS_B
517 	(lookup_type,
518 	 lookup_code,
519 	 last_updated_by,
520 	 last_update_date,
521 	 enabled_flag)
522      VALUES
523 	('REPORT TYPE',
524 	 Report_Type,
525 	 1,
526 	 SYSDATE,
527 	 'Y');
528 
529     insert into FA_LOOKUPS_TL (
530 	LOOKUP_TYPE,
531 	LOOKUP_CODE,
532 	MEANING,
533 	LAST_UPDATE_DATE,
534 	LAST_UPDATED_BY,
535 	LANGUAGE,
536 	SOURCE_LANG)
537 	Select 'REPORT TYPE',
538 	 	Report_Type,
539 	 	Report_Type,
540 		SYSDATE,
541 		1,
542 	    L.LANGUAGE_CODE,
543     userenv('LANG')
544   from FND_LANGUAGES L
545   where L.INSTALLED_FLAG in ('I', 'B')
546   and not exists
547     (select NULL
548     from FA_LOOKUPS_TL T
549     where T.LOOKUP_TYPE = 'REPORT TYPE'
550     and T.LOOKUP_CODE = Report_Type
551     and T.LANGUAGE = L.LANGUAGE_CODE);
552 
553 
554 
555      /* StatReq - Added category flex structure to the following
556                   SQL Statement */
557 	select
558 		category_flex_structure,
559 		asset_key_flex_structure
560 	into
561 		h_cat_flex_struct,
562 		h_key_flex_struct
563 	from
564 		fa_system_controls;
565 
566 
567     /* Get Beginning Balance */
568     /* Use Period1_PC-1, to get balance as of end of period immediately
569        preceding Period1_PC */
570 --    Get_Balance (Book, Distribution_Source_Book,
571 --		 Period1_PC-1, Period1_POD,
572 --		 Report_Type, Balance_Type,
573 --		 'BEGIN');
574 
575    h_mesg_name := 'FA_RX_BEGIN_BALANCES';
576 
577     INSERT INTO FA_BALANCES_REPORT_GT
578        (Asset_ID,
579         Group_Asset_ID, -- Added for Member Track
580 	Distribution_CCID,
581 	Adjustment_CCID,
582 	Category_Books_Account,
583 	Cost_Account,
584 	Source_Type_Code,
585 	Amount,
586 	Cost_Begin_Balance)
587     SELECT
588 	DH.Asset_ID,
589         DECODE(AH.Asset_Type,'GROUP',DH.Asset_ID,BK.Group_Asset_ID),
590 	DH.Code_Combination_ID,
591 	null,
592 	DECODE (Report_Type,
593 		'COST', CB.Asset_Cost_Acct,
594 		'CIP COST', CB.CIP_Cost_Acct,
595 		'RESERVE', CB.Deprn_Reserve_Acct,
596 		'REVAL RESERVE', CB.Reval_Reserve_Acct),
597 	CB.Asset_Cost_Acct,
598 	DECODE(Report_Type,
599 		'RESERVE', DECODE(DD.Deprn_Source_Code,
600 			'D', 'BEGIN', 'T', 'BEGIN', 'ADDITION'), -- Added 'T'
601 		'REVAL RESERVE', DECODE(DD.Deprn_Source_Code,
602 			'D', 'BEGIN', 'T', 'BEGIN', 'ADDITION'), -- Added 'T'
603 		'BEGIN'),
604 	DECODE (Report_Type,
605 		'COST', DD.Cost,
606 		'CIP COST', DD.Cost,
607 		'RESERVE', DD.Deprn_Reserve,
608 		'REVAL RESERVE', DD.Reval_Reserve),
609 	DD.COST
610     FROM
611 	FA_CATEGORY_BOOKS	CB,
612 	FA_DISTRIBUTION_HISTORY	DH,
613 	FA_ASSET_HISTORY	AH,
614 	FA_DEPRN_DETAIL		DD,
615         FA_BOOKS                BK  -- Added for Member Track
616     WHERE	DH.Book_Type_Code	= Distribution_Source_Book
617     AND	DD.Asset_ID		= AH.Asset_ID		AND
618 	DD.Book_Type_Code	= Book			AND
619 	DD.Distribution_ID	= DH.Distribution_ID	AND
620 	DD.Period_Counter	<= Period1_Pc - 1		AND
621 	DD.Period_Counter	=
622        (SELECT	MAX (SUB_DD.Period_Counter)
623 	FROM	FA_DEPRN_DETAIL	SUB_DD
624 	WHERE	SUB_DD.Asset_ID		= DH.Asset_ID		AND
625 		SUB_DD.Book_Type_Code	= Book			AND
626 		SUB_DD.Distribution_ID	= DH.Distribution_ID	AND
627 		SUB_DD.Period_Counter	<= Period1_Pc - 1)
628     AND	AH.Asset_ID		= DH.Asset_ID			AND
629 	((AH.Asset_Type		<> 'EXPENSED' AND
630 		Report_Type IN ('COST', 'CIP COST')) OR
631 	 (AH.Asset_Type		in ('CAPITALIZED', 'GROUP')  AND
632 		Report_Type IN ('RESERVE', 'REVAL RESERVE')) OR
633          (AH.Asset_Type         <> 'EXPENSED' AND nvl(Report_Style,'S') = 'D'))
634     AND ((Period1_Pod BETWEEN AH.Date_Effective AND
635 		NVL(AH.Date_Ineffective, Period1_Pod) AND
636 		DD.Deprn_Source_Code = 'D')	OR
637 	 (DD.Deprn_Run_Date BETWEEN AH.Date_Effective AND
638 		NVL(AH.Date_Ineffective, DD.Deprn_Run_Date) AND
639 		DD.Deprn_Source_Code = 'B')     OR
640          (Period1_Pod BETWEEN AH.Date_Effective AND
641 		NVL(AH.Date_Ineffective, Period1_Pod) AND
642 --		DD.Deprn_Source_Code = 'T' AND
643                 nvl(Report_Style,'S') = 'D'))
644     AND	CB.Category_ID		= AH.Category_ID
645     AND CB.Book_Type_Code	= Book
646     AND	DECODE (Report_Type,
647 		'COST', DECODE (AH.Asset_Type,
648 				'CAPITALIZED', CB.Asset_Cost_Acct,
649                                 DECODE(Report_Style,'D',DECODE(AH.Asset_Type,'GROUP',CB.Asset_Cost_Acct,null),
650 				null)), -- Added for second decode for drill down report
651 		'CIP COST',
652 			DECODE (AH.Asset_Type,
653 				'CIP', CB.CIP_Cost_Acct,
654 				null),
655 		'RESERVE', CB.Deprn_Reserve_Acct,
656 		'REVAL RESERVE', CB.Reval_Reserve_Acct) is not null
657     AND BK.Book_Type_Code       = CB.book_type_code
658     AND   BK.Asset_ID             = DD.Asset_ID   AND
659         DECODE(DD.Deprn_Source_Code, 'D', Period1_pod,
660                         Period1_pcd) BETWEEN
661                 BK.Date_Effective AND
662                         NVL(BK.Date_Ineffective, sysdate) AND
663         NVL(BK.Period_Counter_Fully_Retired, Period1_PC)
664                 > period1_pc - 1
665 UNION ALL-- Added to get assets added with reserve when multiple periods intervall bug	3756517
666 	SELECT
667 	DH.Asset_ID,
668         DECODE(AH.Asset_Type,'GROUP',DH.Asset_ID,BK.Group_Asset_ID),
669 	DH.Code_Combination_ID,
670 	null,
671 	DECODE (Report_Type,
672 		'RESERVE', CB.Deprn_Reserve_Acct,
673 		'REVAL RESERVE', CB.Reval_Reserve_Acct),
674 	CB.Asset_Cost_Acct,
675 	DECODE(Report_Type,
676 		'RESERVE', DECODE(DD.Deprn_Source_Code,
677 			'D', 'BEGIN', 'T', 'BEGIN', 'ADDITION'), -- Added 'T'
678 		'REVAL RESERVE', DECODE(DD.Deprn_Source_Code,
679 			'D', 'BEGIN', 'T', 'BEGIN', 'ADDITION'), -- Added 'T'
680 		'BEGIN'),
681 	DECODE (Report_Type,
682 		'COST', DD.Cost,
683 		'CIP COST', DD.Cost,
684 		'RESERVE', DD.Deprn_Reserve,
685 		'REVAL RESERVE', DD.Reval_Reserve),
686 	DD.COST
687     FROM
688 	FA_CATEGORY_BOOKS	CB,
689 	FA_DISTRIBUTION_HISTORY	DH,
690 	FA_ASSET_HISTORY	AH,
691 	FA_DEPRN_DETAIL		DD,
692         FA_BOOKS                BK,
693 	FA_DEPRN_PERIODS	DP_BROW
694     WHERE	DH.Book_Type_Code	= distribution_source_book
695     AND	DD.Asset_ID		= AH.Asset_ID		AND
696 	DD.Book_Type_Code	= book			AND
697 	DD.Distribution_ID	= DH.Distribution_ID	AND
698 	dd.deprn_reserve <> 0 				AND
699 	dd.deprn_source_code = 'B' 			AND
700 	DD.Period_Counter	between period1_pc and period2_pc
701     AND	AH.Asset_ID		= DH.Asset_ID			AND
702 	(	(AH.Asset_Type		in ('CAPITALIZED', 'GROUP')  AND
703 		Report_Type IN ('RESERVE', 'REVAL RESERVE')))
704 AND
705     DP_BROW.book_type_code = dd.book_type_code and
706     DP_BROW.period_counter = dd.period_counter +1
707 and DP_BROW.period_close_date between ah.date_effective and nvl(ah.date_ineffective,sysdate)
708     AND	CB.Category_ID		= AH.Category_ID	AND
709 	CB.Book_Type_Code	= book
710     AND	DECODE (Report_Type,
711 		'RESERVE', CB.Deprn_Reserve_Acct,
712 		'REVAL RESERVE', CB.Reval_Reserve_Acct) is not null
713     AND BK.Book_Type_Code       = CB.book_type_code
714     AND   BK.Asset_ID             = DD.Asset_ID   AND
715    	ah.date_effective  between               BK.Date_Effective AND
716                         NVL(BK.Date_Ineffective, sysdate);
717 
718 
719 
720 
721 
722 
723 
724     h_mesg_name := 'FA_RX_END_BALANCES';
725 
726     INSERT INTO FA_BALANCES_REPORT_GT
727        (Asset_ID,
728         Group_Asset_ID, -- Added for Drill Down Report
729 	Distribution_CCID,
730 	Adjustment_CCID,
731 	Category_Books_Account,
732 	Cost_Account,
733 	Source_Type_Code,
734 	Amount)
735     SELECT
736 	DH.Asset_ID,
737         DECODE(AH.Asset_Type,'GROUP',DH.Asset_ID,BK.Group_Asset_ID), -- Added for Drill Down Report
738        	DH.Code_Combination_ID,
739 	null,
740 	DECODE (Report_Type,
741 		'COST', CB.Asset_Cost_Acct,
742 		'CIP COST', CB.CIP_Cost_Acct,
743 		'RESERVE', CB.Deprn_Reserve_Acct,
744 		'REVAL RESERVE', CB.Reval_Reserve_Acct),
745 	CB.Asset_Cost_Acct,
746 	DECODE(Report_Type,
747 		'RESERVE', DECODE(DD.Deprn_Source_Code,
748 				'D', 'END', 'T', 'END', 'ADDITION'), -- Added 'T'
749 		'REVAL RESERVE', DECODE(DD.Deprn_Source_Code,
750 				'D', 'END', 'T', 'END', 'ADDITION'), -- Added 'T'
751 		'END'),
752 	DECODE (Report_Type,
753 		'COST', DD.Cost,
754 		'CIP COST', DD.Cost,
755 		'RESERVE', DD.Deprn_Reserve,
756 		'REVAL RESERVE', DD.Reval_Reserve)
757     FROM
758 	FA_CATEGORY_BOOKS	CB,
759 	FA_DISTRIBUTION_HISTORY	DH,
760 	FA_ASSET_HISTORY	AH,
761 	FA_DEPRN_DETAIL		DD,
762         FA_BOOKS                BK
763     WHERE	DH.Book_Type_Code	= Distribution_Source_Book
764     AND	DD.Asset_ID		= AH.Asset_ID		AND
765 	DD.Book_Type_Code	= Book			AND
766 	DD.Distribution_ID	= DH.Distribution_ID	AND
767 	DD.Period_Counter	<= period2_pc		AND
768 	DD.Period_Counter	=
769        (SELECT	MAX (SUB_DD.Period_Counter)
770 	FROM	FA_DEPRN_DETAIL	SUB_DD
771 	WHERE	SUB_DD.Asset_ID		= DH.Asset_ID		AND
772 		SUB_DD.Book_Type_Code	= Book			AND
773 		SUB_DD.Distribution_ID	= DH.Distribution_ID	AND
774 		SUB_DD.Period_Counter	<= period2_pc)
775     AND	AH.Asset_ID		= DH.Asset_ID			AND
776 	((AH.Asset_Type		<> 'EXPENSED' AND
777 		Report_Type IN ('COST', 'CIP COST')) OR
778          (AH.Asset_Type         in ('CAPITALIZED', 'GROUP')  AND
779 		Report_Type IN ('RESERVE', 'REVAL RESERVE')) OR
780          (AH.Asset_Type         <> 'EXPENSED' AND nvl(Report_Style,'S') = 'D'))
781     AND ((Period2_Pcd BETWEEN AH.Date_Effective AND
782 		NVL(AH.Date_Ineffective, Period2_Pcd) AND
783 		DD.Deprn_Source_Code = 'D') OR
784 	 (DD.deprn_run_date between ah.date_effective AND
785 		NVL(ah.date_ineffective, DD.Deprn_run_date) AND
786 		DD.deprn_source_code = 'B') OR
787          (Period2_Pcd BETWEEN AH.Date_Effective AND
788 		NVL(AH.Date_Ineffective, Period2_Pcd) AND
789 --		DD.Deprn_Source_Code = 'T' AND
790                 nvl(Report_Style,'S') = 'D'))
791     AND DD.deprn_source_code in ('D', 'T')
792     AND	CB.Category_ID		= AH.Category_ID	AND
793 	CB.Book_Type_Code	= Book
794     AND	DECODE (Report_Type,
795 		'COST', DECODE (AH.Asset_Type,
796 				'CAPITALIZED', CB.Asset_Cost_Acct,
797                                 DECODE(Report_Style,'D',DECODE(AH.Asset_Type,'GROUP',CB.Asset_Cost_Acct,null),
798 				null)),
799 		'CIP COST',
800 			DECODE (AH.Asset_Type,
801 				'CIP', CB.CIP_Cost_Acct,
802 				null),
803 		'RESERVE', CB.Deprn_Reserve_Acct,
804 		'REVAL RESERVE', CB.Reval_Reserve_Acct) is not null
805     AND BK.Book_Type_Code       = CB.book_type_code     AND
806         BK.Asset_ID             = DD.Asset_ID   AND
807         Period2_pcd   BETWEEN
808                 BK.Date_Effective AND
809                         NVL(BK.Date_Ineffective, sysdate) AND
810         NVL(BK.Period_Counter_Fully_Retired, Period2_PC+1)
811                 > period1_pc - 1;
812 
813 
814   h_mesg_name := 'FA_INS_ADJ_GET_VOST_ADJS';
815 
816     INSERT INTO FA_BALANCES_REPORT_GT
817        (Asset_ID,
818         Group_Asset_ID, -- Added for Drill Down Report
819 	Distribution_CCID,
820 	Adjustment_CCID,
821 	Category_Books_Account,
822 	Cost_Account,
823 	Source_Type_Code,
824 	Amount)
825     SELECT
826         DH.Asset_ID,
827         DECODE(AH.Asset_Type,'GROUP',DH.Asset_ID,BK.Group_Asset_ID), -- Added for Drill Down Report
828 	DH.Code_Combination_ID,
829 	lines.code_combination_id, --AJ.Code_Combination_ID,
830 	null,
831 	CB.Asset_Cost_Acct,
832 	AJ.Source_Type_Code,
833 	SUM (DECODE (AJ.Debit_Credit_Flag, Balance_Type, 1, -1) *
834 		AJ.Adjustment_Amount)
835     FROM	FA_LOOKUPS		RT,
836 	FA_CATEGORY_BOOKS	CB,
837 	FA_ASSET_HISTORY	AH1,
838 	FA_DISTRIBUTION_HISTORY	DH,
839 	FA_TRANSACTION_HEADERS	TH,
840 	FA_ASSET_HISTORY	AH,
841 	FA_ADJUSTMENTS		AJ,
842         FA_BOOKS                BK
843 
844       /* SLA changes */
845         ,xla_ae_headers headers
846         ,xla_ae_lines lines
847         ,xla_distribution_links links
848         ,fa_book_controls bc
849 
850     WHERE	RT.Lookup_Type		= 'REPORT TYPE' AND
851 	RT.Lookup_Code		= Report_Type
852     AND BC.BOOK_TYPE_CODE       = Book
853     AND	DH.Book_Type_Code	= Distribution_Source_Book
854     AND	AJ.Asset_ID		= DH.Asset_ID		AND
855 	AJ.Book_Type_Code	= Book			AND
856 	AJ.Distribution_ID	= DH.Distribution_ID	AND
857 	AJ.Adjustment_Type	in
858 		(Report_Type, DECODE(Report_Type,
859 			'REVAL RESERVE', 'REVAL AMORT')) AND
860 	AJ.Period_Counter_Created BETWEEN
861 			Period1_PC AND Period2_PC
862     AND	TH.Transaction_Header_ID	= AJ.Transaction_Header_ID
863     AND	AH.Asset_ID		= DH.Asset_ID		AND
864 	((AH.Asset_Type		<> 'EXPENSED' AND
865 		Report_Type IN ('COST', 'CIP COST')) OR
866          (AH.Asset_Type         in ('CAPITALIZED', 'GROUP')  AND
867 		Report_Type IN ('RESERVE', 'REVAL RESERVE')) OR
868          (AH.Asset_Type         <> 'EXPENSED' AND nvl(Report_Style,'S') = 'D'))	AND
869 	TH.Transaction_Header_ID BETWEEN
870 		AH.Transaction_Header_ID_In AND
871 		NVL (AH.Transaction_Header_ID_Out - 1,
872 			TH.Transaction_Header_ID)
873     AND	(DECODE (RT.Lookup_Code, AJ.Adjustment_Type, 1, 0) *
874 		AJ.Adjustment_Amount) <> 0
875     AND AH1.ASSET_ID		= AJ.ASSET_ID 			/* StatReq */
876     AND AH1.DATE_EFFECTIVE     <= DH.DATE_EFFECTIVE		/* StatReq */
877     AND NVL(AH1.DATE_INEFFECTIVE, SYSDATE) > DH.DATE_EFFECTIVE	/* StatReq */
878     AND	CB.Category_ID		= AH1.Category_ID	AND	/* StatReq */
879 	CB.Book_Type_Code	= Book				/* StatReq */
880     AND BK.Book_Type_Code       = Book   -- Added for Drill Down Report
881     AND BK.Asset_ID             = DH.Asset_ID
882 --    AND BK.DATE_EFFECTIVE      <= DH.DATE_EFFECTIVE
883 --    AND NVL(BK.DATE_INEFFECTIVE, SYSDATE) > DH.DATE_EFFECTIVE
884     AND BK.DATE_EFFECTIVE      <= nvl(DH.DATE_INEFFECTIVE, sysdate)
885     AND NVL(BK.DATE_INEFFECTIVE, SYSDATE + 1) > nvl(DH.DATE_INEFFECTIVE, sysdate)
886     /* SLA Changes */
887     and links.Source_distribution_id_num_1 = aj.transaction_header_id
888     and links.Source_distribution_id_num_2 = aj.adjustment_line_id
889     and links.application_id               = 140
890     and links.source_distribution_type     = 'TRX'
891     and headers.ae_header_id               = links.ae_header_id
892     and headers.ledger_id                  = bc.set_of_books_id
893     and headers.application_id             = 140
894     and lines.ae_header_id                 = links.ae_header_id
895     and lines.ae_line_num                  = links.ae_line_num
896     and lines.application_id               = 140
897     GROUP BY
898 	DH.Asset_ID,
899         DECODE(AH.Asset_Type,'GROUP',DH.Asset_ID,BK.Group_Asset_ID), -- Added for Drill Down Report
900 	DH.Code_Combination_ID,
901 	lines.code_combination_id, --AJ.Code_Combination_ID,
902 	CB.Asset_Cost_Acct,
903 	AJ.Source_Type_Code;
904 
905 
906     if (Report_Type = 'RESERVE' or Report_Type = 'REVAL RESERVE') then
907 --	Get_Deprn_Effects (Book, Distribution_Source_Book,
908 --			   Period1_PC, Period2_PC,
909 --			   Report_Type);
910 
911   h_mesg_name := 'FA_INS_ADJ_GET_RSV_ADJ';
912 
913     INSERT INTO FA_BALANCES_REPORT_GT
914        (Asset_ID,
915         Group_Asset_ID, -- Added for Drill Down Report
916 	Distribution_CCID,
917 	Adjustment_CCID,
918 	Category_Books_Account,
919 	Cost_Account,
920 	Source_Type_Code,
921 	Amount)
922     SELECT	DH.Asset_ID,
923         DECODE(AH.Asset_Type,'GROUP',DH.Asset_ID,BK.Group_Asset_ID), -- Added for Drill Down Report
924 	DH.Code_Combination_ID,
925 	null,
926 	DECODE (RT.Lookup_Code,
927 		'RESERVE', CB.Deprn_Reserve_Acct,
928 		'REVAL RESERVE', CB.Reval_Reserve_Acct),
929 	CB.Asset_Cost_Acct,
930 	DECODE(DD.Deprn_Source_Code,
931 		'D', 'DEPRECIATION', 'T', 'DEPRECIATION', 'ADDITION'),
932 	SUM (DECODE (RT.Lookup_Code,
933 		'RESERVE', DD.Deprn_Amount,
934 		'REVAL RESERVE', -DD.Reval_Amortization))
935     FROM	FA_LOOKUPS		RT,
936 	FA_CATEGORY_BOOKS	CB,
937 	FA_DISTRIBUTION_HISTORY	DH,
938 	FA_ASSET_HISTORY	AH,
939 	FA_DEPRN_DETAIL		DD,
940 	FA_DEPRN_PERIODS	DP,
941         FA_BOOKS                BK -- Added for Drill Down Report
942     WHERE	DH.Book_Type_Code	= Distribution_Source_Book
943     AND	AH.Asset_ID		= DH.Asset_ID
944     AND ((AH.Asset_Type		in ('CAPITALIZED', 'GROUP')) OR
945           AH.Asset_Type        <> 'EXPENSED' AND nvl(Report_Style,'S') = 'D') -- Added for Drill Down Report
946     AND AH.Date_Effective 	<= nvl(DP.Period_Close_Date,sysdate)	AND
947 	NVL (AH.Date_Ineffective, SYSDATE) >=
948 			nvl(DP.Period_Close_Date,sysdate)
949     AND	CB.Category_ID		= AH.Category_ID	AND
950 	CB.Book_Type_Code	= Book
951     AND	((DD.Deprn_Source_Code 	= 'B'
952 		AND DD.Period_Counter < Period2_PC)	OR
953 	 (DD.Deprn_Source_Code 	= 'D') OR
954          (DD.Deprn_Source_Code  = 'T' and nvl(Report_Style,'S') = 'D'))	AND
955 	DD.Book_Type_Code	= Book			AND
956 	DD.Asset_ID		= DH.Asset_ID		AND
957 	DD.Distribution_ID	= DH.Distribution_ID	AND
958 	DD.Period_Counter between
959 		Period1_PC and Period2_PC
960     AND	DP.Book_Type_Code	= DD.Book_Type_Code	AND
961 	DP.Period_Counter	= DD.Period_Counter
962     AND RT.LOOKUP_TYPE          = 'REPORT TYPE'
963     AND	DECODE (RT.Lookup_Code,
964 		'RESERVE', CB.Deprn_Reserve_Acct,
965 		'REVAL RESERVE', CB.Reval_Reserve_Acct) is not null
966     AND	DECODE (RT.Lookup_Code,
967 		'RESERVE', DD.Deprn_Amount,
968 		'REVAL RESERVE', NVL(DD.Reval_Amortization,0)) <> 0
969     AND BK.Book_Type_Code       = Book        -- Added for Drill Down Report
970     AND BK.Asset_ID             = DH.Asset_ID
971     AND nvl(DP.Period_Close_Date,sysdate)     BETWEEN BK.Date_Effective and nvl(BK.Date_Ineffective, Sysdate)
972     GROUP BY
973 	DH.Asset_ID,
974         DECODE(AH.Asset_Type,'GROUP',DH.Asset_ID,BK.Group_Asset_ID), -- Added for Drill Down Report
975 	DH.Code_Combination_ID,
976 	DECODE (RT.Lookup_Code,
977 		'RESERVE', CB.Deprn_Reserve_Acct,
978 		'REVAL RESERVE', CB.Reval_Reserve_Acct),
979 	CB.Asset_Cost_Acct,
980 	DD.Deprn_Source_Code;
981 
982 
983     end if;
984 
985 
986 -- Get segment numbers corresponding to the given structure_id.
987 -- Will need these later for getting segments for given ccids.
988 
989    h_mesg_name := 'FA_RX_SEGNUMS';
990 
991    fa_rx_shared_pkg.get_acct_segment_numbers (
992 	BOOK => Book,
993 	BALANCING_SEGNUM => gl_balancing_seg,
994 	ACCOUNT_SEGNUM => gl_account_seg,
995 	CC_SEGNUM => fa_cost_ctr_seg,
996 	CALLING_FN => 'FA_BALANCES_REPORT');
997 
998    /* StatReq - The following statement has been added to get the natural account segment's valueset */
999 
1000    return_status := FND_FLEX_APIS.GET_SEGMENT_INFO
1001 			(101, 'GL#', Acct_Flex_Structure, Gl_Account_Seg,
1002 			 Acct_Appl_Col, Acct_Segname, Acct_Prompt, Acct_Valueset_Name);
1003 
1004       fa_rx_shared_pkg.get_acct_segment_index (
1005         BOOK => Book,
1006         BALANCING_SEGNUM => gl_balancing_seg,
1007         ACCOUNT_SEGNUM => gl_account_seg,
1008         CC_SEGNUM => fa_cost_ctr_seg,
1009         CALLING_FN => 'FA_BALANCES_REPORT');
1010 
1011 
1012 
1013 --   open non_qualified_segs;
1014 --   loop
1015 --     fetch non_qualified_segs into
1016 --    h_nonqual_col_name,
1017 --    h_nonqual_seg_name,
1018 --    h_nonqual_seg_num;
1019 --
1020 --     if (non_qualified_segs%NOTFOUND) then exit; end if;
1021 --
1022 --   fa_rx_dynamic_columns_pkg.add_column (
1023 --  X_request_id	=> h_request_id,
1024 --  X_attribute_name => h_nonqual_seg_name,
1025 --  X_column_name	=> h_nonqual_col_name,
1026 --  X_ordering	=> 'NONE',
1027 -- X_BREAK        => 'N',
1028 -- X_DISPLAY_LENGTH   => 30,
1029 -- X_DISPLAY_FORMAT   => 'VARCHAR2',
1030 -- X_DISPLAY_STATUS   => 'YES',
1031 --  calling_fn => 'BALANCES REP');
1032 --
1033 --   end loop;
1034 --   close non_qualified_segs;
1035 --
1036 --   mesg := 'Error looping through adjustment ccids';
1037 
1038 -- Each FA_BALANCES_REPORT_GT row corresponds to one of the following:
1039 -- (1) begin balance, (2) end balance, (3) an adjustment, (4)
1040 -- depreciation.  Each corresponds to a given account.  Sometimes,
1041 -- the account is the default from FA_CATEGORY_BOOKS; in this case
1042 -- the account segment itself is stored here and we can simply select
1043 -- it later.  However, sometimes the "account" is stored as a ccid.
1044 -- In this case, we must find the accounting segment corresponding
1045 -- to that ccid, and store it now, so we can select it later.
1046 -- Use get_segments to find the accounting segment now.  Doing it now
1047 -- vastly simplifies selecting later.
1048 
1049   h_mesg_name := 'FA_RX_ADJ_SEGMENTS';
1050 
1051   OPEN BAL_REPORT_AJCCID;
1052   loop
1053     fetch BAL_REPORT_AJCCID into
1054 	h_br_ajccid,
1055 	h_br_account,
1056 	h_br_rowid;
1057 
1058     if (BAL_REPORT_AJCCID%NOTFOUND) then exit;  end if;
1059 
1060     if (h_br_account is null and h_br_ajccid is not null ) then
1061 
1062 	h_mesg_name := 'FA_RX_CONCAT_SEGS';
1063 	h_ccid_error := h_br_ajccid;
1064 
1065 	fa_rx_shared_pkg.get_acct_segments (
1066 	  combination_id => h_br_ajccid,
1067 	  n_segments => n_segs,
1068 	  segments => acct_all_segs,
1069 	  calling_fn => 'FA_BALANCES_REPORT');
1070 
1071 	h_mesg_name := 'FA_POST_SQL_UPDATE_TABLE';
1072 	h_table_token := 'FA_BALANCES_REPORT_GT';
1073 
1074 	update fa_balances_report_gt
1075 	set category_books_account = acct_all_segs(gl_account_seg)
1076 	where rowid = h_br_rowid;
1077 
1078     end if;
1079   end loop;
1080   CLOSE BAL_REPORT_AJCCID;
1081 
1082 
1083 -- Now report in data in FA_BALANCES_REPORT_GT (if an accum deprn
1084 -- or reval reserve report).
1085 
1086   if (report_type in ('RESERVE','REVAL RESERVE')) then
1087 
1088    mesg := 'Error getting reserve balances';
1089 
1090 
1091   h_mesg_name := 'FA_DEPRN_SQL_DCUR';
1092 
1093    open RESERVE_REPORT (book, Period2_PCD);	/* StatReq */
1094    loop
1095 
1096 	h_mesg_name := 'FA_DEPRN_SQL_FCUR';
1097 
1098      fetch RESERVE_REPORT into
1099 	h_asset_id,							/* StatReq */
1100 	h_ccid,
1101 	h_account,
1102 	h_cost_account,							/* StatReq */
1103 	h_asset,
1104 	h_tag_number,
1105 	h_description, h_serial_number, h_inventorial, h_asset_key_ccid,
1106 	h_category_id,							/* StatReq */
1107 	h_date_placed_in_service,					/* StatReq */
1108 	h_method_code,							/* StatReq */
1109 	h_life_in_months,						/* StatReq */
1110 	h_stl_method_flag,						/* StatReq */
1111 	h_rate_source_rule,						/* StatReq */
1112 	h_cost_begin_balance,						/* StatReq */
1113 	h_begin,
1114 	h_addition,
1115 	h_depreciation,
1116 	h_reclass,
1117 	h_retirement,
1118 	h_revaluation,
1119 	h_tax,
1120 	h_transfer,
1121 	h_end,
1122         h_group_asset;
1123 
1124      if (RESERVE_REPORT%NOTFOUND) then exit;  end if;
1125 
1126     h_mesg_name := 'FA_RX_CONCAT_SEGS';
1127     h_ccid_error := h_ccid;
1128 
1129     fa_rx_shared_pkg.get_acct_segments (
1130       combination_id => h_ccid,
1131       n_segments => n_segs,
1132       segments => acct_all_segs,
1133       calling_fn => 'FA_BALANCES_REPORT');
1134 
1135      /* StatReq - The following 6 function calls have been added to retrieve more
1136 	detailed asset information */
1137 
1138      h_account_description :=
1139      	fa_rx_shared_pkg.get_flex_val_meaning(NULL, acct_valueset_name, h_account);
1140 
1141      h_vendor_name :=
1142      	fa_rx_shared_pkg.get_asset_info('VENDOR_NAME', h_asset_id, period1_pod, period2_pcd, book,
1143 					acct_all_segs(gl_balancing_seg));
1144      h_invoice_number :=
1145      	fa_rx_shared_pkg.get_asset_info('INVOICE_NUMBER', h_asset_id, period1_pod, period2_pcd, book,
1146 					acct_all_segs(gl_balancing_seg));
1147      h_invoice_descr :=
1148      	fa_rx_shared_pkg.get_asset_info('INVOICE_DESCR', h_asset_id, period1_pod, period2_pcd, book,
1149 					acct_all_segs(gl_balancing_seg));
1150      h_location :=
1151      	fa_rx_shared_pkg.get_asset_info('LOCATION', h_asset_id, period1_pod, period2_pcd, distribution_source_book,
1152 					acct_all_segs(gl_balancing_seg));
1153      h_retirement_type :=
1154 	fa_rx_shared_pkg.get_asset_info('RETIREMENT_TYPE',h_asset_id, period1_pod, period2_pcd, book,
1155 					acct_all_segs(gl_balancing_seg));
1156 
1157 
1158    h_adjustment := nvl(h_tax,0) + nvl(h_revaluation,0);
1159 
1160    if (nvl(h_begin,0) + nvl(h_addition,0) + nvl(h_depreciation,0)
1161 	+ nvl(h_reclass,0) - nvl(h_retirement,0) + nvl(h_transfer,0)
1162 	+ nvl(h_adjustment,0) = nvl(h_end,0)) then
1163      h_out_of_bal_flag := 'N';
1164    else h_out_of_bal_flag := 'Y';
1165    end if;
1166 
1167    if h_asset_key_ccid is not null then
1168         h_mesg_name := 'FA_RX_CONCAT_SEGS';
1169         h_flex_error := 'KEY#';
1170         h_ccid_error := h_asset_key_ccid;
1171 
1172         fa_rx_shared_pkg.concat_asset_key (
1173         struct_id => h_key_flex_struct,
1174         ccid => h_asset_key_ccid,
1175         concat_string => h_concat_key,
1176         segarray => h_key_segs);
1177 
1178     else
1179 	h_concat_key := null;
1180 
1181     end if;
1182 
1183    /* StatReq - The following if statement has been added to retrieve the category
1184       each asset */
1185 
1186    if h_category_id is not null then
1187         h_mesg_name := 'FA_RX_CONCAT_SEGS';
1188         h_flex_error := 'CAT#';
1189         h_ccid_error := h_category_id;
1190 
1191         fa_rx_shared_pkg.concat_category (
1192         struct_id => h_cat_flex_struct,
1193         ccid => h_category_id,
1194         concat_string => h_concat_cat,
1195         segarray => h_cat_segs);
1196 
1197     else
1198 	h_concat_cat := null;
1199     end if;
1200 
1201    /* StatReq - The following if statement has been added to calculate the annual depreciation rate
1202 	        for straight-line, calculated depreciation methods */
1203 
1204   if (h_stl_method_flag = 'YES' and h_rate_source_rule = 'CALCULATED')
1205   then
1206 	h_stl_depreciation_rate	:= 12 / h_life_in_months * 100;
1207   else
1208 	h_stl_depreciation_rate := NULL;
1209   end if;
1210 
1211   h_short_account_description := substr(h_account_description,1,239);
1212 
1213   h_short_location := substr(h_location, 1, 499);
1214 
1215   h_shortconcat_key := substr(h_concat_key,1,239);
1216 
1217   -- Added following code for bug 5975548
1218   h_short_invoice_number := substrb(h_invoice_number, 1, 499);
1219   h_short_invoice_descr := substrb(h_invoice_descr, 1, 499);
1220   h_short_vendor_name	:= substrb(h_vendor_name, 1, 499);
1221   h_short_retirement_type := substrb(h_retirement_type, 1, 499);
1222   -- End of bug fix 5975548
1223 
1224   h_mesg_name := 'FA_SHARED_INSERT_FAILED';
1225   h_table_token := 'FA_BALANCES_REP_ITF';
1226 
1227 -- insert into interface table
1228     insert /*+ noappend */ into fa_balances_rep_itf
1229 	(request_id, company, cost_center, account,
1230 	 cost_account,
1231 	 inventorial, asset_key,	asset_number, tag_number, description,
1232 	 category, deprn_method,
1233 	 account_description, date_placed_in_service, book_type_code,
1234 	 life_in_months, stl_depreciation_rate,
1235 	 concat_vendor_name, concat_invoice_number,
1236 	 concat_invoice_description, concat_location,
1237 	 concat_retirement_type, cost_begin_balance,
1238 	 begin_balance, additions,
1239 	 retirements, revaluations, reclasses, transfers, depreciation,
1240 	 amortization, end_balance, out_of_balance_flag, serial_number,
1241 	 created_by, creation_date,
1242 	 last_updated_by, last_update_date, last_update_login,
1243          group_asset_number  ) values (
1244 	 Request_Id, acct_all_segs(gl_balancing_seg),
1245 	 acct_all_segs(fa_cost_ctr_seg), h_account,
1246 	 h_cost_account,
1247 	 h_inventorial, h_shortconcat_key,
1248 	 -- 'BAL','CC','ACCT',
1249 	 h_asset, h_tag_number, h_description,
1250 	 h_concat_cat, h_method_code,
1251 	 h_short_account_description, h_date_placed_in_service, book,
1252 	 h_life_in_months, h_stl_depreciation_rate,
1253 	 h_short_vendor_name, h_short_invoice_number, h_short_invoice_descr,	-- bug 5975548
1254 	 h_short_location,
1255  	 h_short_retirement_type, h_cost_begin_balance,	-- bug 5975548
1256 	 h_begin, h_addition, h_retirement,
1257 	 h_revaluation, h_reclass, h_transfer, h_depreciation,
1258 	 h_depreciation, h_end, h_out_of_bal_flag, h_serial_number,
1259 	 User_Id, sysdate, user_id, sysdate, h_Login_id,
1260          h_group_asset);
1261 
1262 
1263     end loop;
1264 
1265   h_mesg_name := 'FA_DEPRN_SQL_CCUR';
1266 
1267     close RESERVE_REPORT;
1268 
1269     if nvl(Report_Style,'S') = 'D' then
1270       -- Following logic is summarize the member level amounts into group level
1271       For group_asset in GROUP_ASSETS loop
1272 
1273         open GROUP_RESERVE_AMOUNTS(group_asset.group_asset_id);
1274         fetch GROUP_RESERVE_AMOUNTS into h_cost_begin_balance;
1275         close GROUP_RESERVE_AMOUNTS;
1276 
1277         select distinct asset_number
1278           into h_group_asset
1279           from fa_additions
1280          where asset_id=group_asset.group_asset_id;
1281 
1282         Update fa_balances_rep_itf
1283            set cost_begin_balance = h_cost_begin_balance
1284          where request_id = Request_Id
1285            and asset_number = h_group_asset;
1286 
1287       end loop;
1288     end if; -- Report_Style
1289 
1290   else
1291 
1292 
1293 -- Now report on data in FA_BALANCES_REPORT_GT (for asset cost and
1294 -- CIP cost reports).
1295 
1296    mesg := 'Error selecting cost balances';
1297 
1298   h_mesg_name := 'FA_DEPRN_SQL_DCUR';
1299    open COST_REPORT (book, Period2_PCD, period1_pod);
1300 
1301    loop
1302   h_mesg_name := 'FA_DEPRN_SQL_FCUR';
1303 
1304      fetch COST_REPORT into
1305 	h_asset_id,
1306 	h_ccid,
1307 	h_account,
1308 	h_cost_account,
1309 	h_asset,
1310 	h_tag_number,
1311 	h_description,
1312 	h_serial_number, h_inventorial, h_asset_key_ccid,
1313 	h_category_id,
1314 	h_date_placed_in_service,
1315 	h_method_code,
1316 	h_life_in_months,
1317 	h_stl_method_flag,
1318 	h_rate_source_rule,
1319 	h_cost_begin_balance,
1320 	h_begin,
1321 	h_addition,
1322 	h_capitalization,
1323 	h_adjustment,
1324 	h_reclass,
1325 	h_retirement,
1326 	h_revaluation,
1327 	h_transfer,
1328 	h_end,
1329         h_group_asset;
1330 
1331      if (COST_REPORT%NOTFOUND) then exit;  end if;
1332 
1333      h_mesg_name := 'FA_RX_CONCAT_SEGS';
1334      h_ccid_error := h_ccid;
1335 
1336      fa_rx_shared_pkg.get_acct_segments (
1337        combination_id => h_ccid,
1338        n_segments => n_segs,
1339        segments => acct_all_segs,
1340        calling_fn => 'FA_BALANCES_REPORT');
1341 
1342      /* StatReq - The following 6 function calls have been added to retrieve more
1343 	detailed asset information */
1344 
1345      h_account_description :=
1346      	fa_rx_shared_pkg.get_flex_val_meaning(NULL, acct_valueset_name, h_account);
1347 
1348      h_vendor_name :=
1349      	fa_rx_shared_pkg.get_asset_info('VENDOR_NAME', h_asset_id, period1_pod, period2_pcd, book,
1350 					acct_all_segs(gl_balancing_seg));
1351      h_invoice_number :=
1352      	fa_rx_shared_pkg.get_asset_info('INVOICE_NUMBER', h_asset_id, period1_pod, period2_pcd, book,
1353 					acct_all_segs(gl_balancing_seg));
1354      h_invoice_descr :=
1355      	fa_rx_shared_pkg.get_asset_info('INVOICE_DESCR', h_asset_id, period1_pod, period2_pcd, book,
1356 					acct_all_segs(gl_balancing_seg));
1357      h_location :=
1358      	fa_rx_shared_pkg.get_asset_info('LOCATION', h_asset_id, period1_pod, period2_pcd, distribution_source_book,
1359 					acct_all_segs(gl_balancing_seg));
1360      h_retirement_type :=
1361 	fa_rx_shared_pkg.get_asset_info('RETIREMENT_TYPE',h_asset_id, period1_pod, period2_pcd, book,
1362 					acct_all_segs(gl_balancing_seg));
1363 
1364 
1365    if (nvl(h_begin,0) + nvl(h_addition,0) - nvl(h_capitalization,0)
1366 	+ nvl(h_reclass,0) - nvl(h_retirement,0) + nvl(h_transfer,0)
1367 	+ nvl(h_adjustment,0) + nvl(h_revaluation,0) = nvl(h_end,0)) then
1368      h_out_of_bal_flag := 'N';
1369    else h_out_of_bal_flag := 'Y';
1370    end if;
1371 
1372    if h_asset_key_ccid is not null then
1373         h_mesg_name := 'FA_RX_CONCAT_SEGS';
1374         h_flex_error := 'KEY#';
1375         h_ccid_error := h_asset_key_ccid;
1376 
1377         fa_rx_shared_pkg.concat_asset_key (
1378         struct_id => h_key_flex_struct,
1379         ccid => h_asset_key_ccid,
1380         concat_string => h_concat_key,
1381         segarray => h_key_segs);
1382 
1383     else
1384 	h_concat_key := null;
1385 
1386     end if;
1387 
1388 
1389    /* StatReq - The following if statement has been added to retrieve the category
1390       for each asset */
1391 
1392    if h_category_id is not null then
1393         h_mesg_name := 'FA_RX_CONCAT_SEGS';
1394         h_flex_error := 'CAT#';
1395         h_ccid_error := h_category_id;
1396 
1397         fa_rx_shared_pkg.concat_category (
1398         struct_id => h_cat_flex_struct,
1399         ccid => h_category_id,
1400         concat_string => h_concat_cat,
1401         segarray => h_cat_segs);
1402 
1403     else
1404 	h_concat_cat := null;
1405     end if;
1406 
1407    /* StatReq - The following if statement has been added to calculate the annual depreciation rate
1408 	        for straight-line, calculated depreciation methods */
1409 
1410   if (h_stl_method_flag = 'YES' and h_rate_source_rule = 'CALCULATED')
1411   then
1412 	h_stl_depreciation_rate	:= 12 / h_life_in_months * 100;
1413   else
1414 	h_stl_depreciation_rate := NULL;
1415   end if;
1416 
1417   h_short_account_description := substr(h_account_description,1,239);
1418 
1419   h_short_location := substr(h_location, 1, 499);
1420 
1421   h_shortconcat_key := substr(h_concat_key,1, 239);
1422 
1423   -- Added following code for bug 5975548
1424   h_short_invoice_number := substrb(h_invoice_number, 1, 499);
1425   h_short_invoice_descr := substrb(h_invoice_descr, 1, 499);
1426   h_short_vendor_name	:= substrb(h_vendor_name, 1, 499);
1427   h_short_retirement_type := substrb(h_retirement_type, 1, 499);
1428   -- End of bug fix 5975548
1429 
1430   h_mesg_name := 'FA_SHARED_INSERT_FAILED';
1431   h_table_token := 'FA_BALANCES_REP_ITF';
1432 
1433 --insert into interface table
1434     insert /*+ noappend */ into fa_balances_rep_itf
1435 	(request_id, company, cost_center, account,
1436 	 cost_account,							/* StatReq */
1437 	 asset_key, asset_number, tag_number, description,
1438 	 inventorial, serial_number,
1439 	 category, deprn_method,					/* StatReq */
1440 	 account_description, date_placed_in_service, book_type_code,   /* StatReq */
1441 	 life_in_months, stl_depreciation_rate,				/* StatReq */
1442 	 concat_vendor_name, concat_invoice_number,			/* StatReq */
1443 	 concat_invoice_description, concat_location,			/* StatReq */
1444 	 concat_retirement_type, cost_begin_balance,			/* StatReq */
1445 	 begin_balance, additions, adjustments,
1446  	 retirements, revaluations, reclasses, capitalizations, transfers,
1447 	 end_balance, out_of_balance_flag, created_by, creation_date,
1448 	 last_updated_by, last_update_date, last_update_login, group_asset_number
1449 --	 , segment1, segment2, segment3, segment4, segment5,
1450 --	 segment6, segment7, segment8, segment9, segment10,
1451 --	 segment11, segment12, segment13, segment14, segment15,
1452 --	 segment16, segment17, segment18, segment19, segment20,
1453 --	 segment21, segment22, segment23, segment24, segment25,
1454 --	 segment26, segment27, segment28, segment29, segment30
1455 	 ) values (
1456 	 Request_Id, acct_all_segs(gl_balancing_seg),
1457 	 acct_all_segs(fa_cost_ctr_seg), h_account,
1458 	 h_cost_account,
1459 	 h_shortconcat_key,
1460 	 -- 'BAL','CC','ACCT',
1461 	 h_asset, h_tag_number, h_description,
1462 	 h_inventorial, h_serial_number,
1463 	 h_concat_cat, h_method_code,
1464 	 h_short_account_description, h_date_placed_in_service, book,
1465 	 h_life_in_months, h_stl_depreciation_rate,
1466 	 h_short_vendor_name, h_short_invoice_number, h_short_invoice_descr,	-- bug 5975548
1467          h_short_location,
1468 	 h_short_retirement_type, h_cost_begin_balance,	-- bug 5975548
1469 	 h_begin, h_addition, h_adjustment, h_retirement,
1470 	 h_revaluation, h_reclass, h_capitalization, h_transfer,
1471 	 h_end, h_out_of_bal_flag, User_Id, sysdate, User_Id,
1472 	 sysdate, h_Login_Id, h_group_Asset);
1473 
1474     end loop;
1475   h_mesg_name := 'FA_DEPRN_SQL_CCUR';
1476 
1477     close COST_REPORT;
1478 
1479     if nvl(Report_Style,'S') = 'D' then
1480       -- Following logic is summarize the member level amounts into group level
1481       For group_asset in GROUP_ASSETS loop
1482 
1483         open GROUP_COST_AMOUNTS(group_asset.group_asset_id);
1484         fetch GROUP_COST_AMOUNTS into h_cost_begin_balance,
1485 	                         h_begin,
1486 	                         h_addition,
1487 	                         h_capitalization,
1488 	                         h_adjustment,
1489 	                         h_reclass,
1490 	                         h_retirement,
1491 	                         h_revaluation,
1492 	                         h_transfer,
1493 	                         h_end;
1494         close GROUP_COST_AMOUNTS;
1495 
1496         select distinct asset_number
1497           into h_group_asset
1498           from fa_additions
1499          where asset_id=group_asset.group_asset_id;
1500 
1501         Update fa_balances_rep_itf
1502            set cost_begin_balance = h_cost_begin_balance,
1503                begin_balance      = h_begin,
1504                additions          = h_addition,
1505                capitalizations    = h_capitalization,
1506                adjustments        = h_adjustment,
1507                reclasses          = h_reclass,
1508                retirements        = h_retirement,
1509                revaluations       = h_revaluation,
1510                transfers          = h_transfer,
1511                end_balance        = h_end
1512          where request_id = Request_Id
1513            and asset_number = h_group_asset;
1514 
1515       end loop;
1516     end if; -- Report_Style
1517 
1518   end if;   -- if report_type like %RESERVE
1519 
1520   success := TRUE;
1521 
1522   exception
1523     when others then success := FALSE;
1524 
1525   fa_rx_conc_mesg_pkg.log(SQLERRM);
1526 
1527   fnd_message.set_name('OFA',h_mesg_name);
1528 
1529   if h_mesg_name in ('FA_SHARED_DETELE_FAILED','FA_SHARED_INSERT_FAILED') then
1530 	fnd_message.set_token('TABLE',h_table_token,FALSE);
1531   end if;
1532   if h_mesg_name = 'FA_RX_CONCAT_SEGS' then
1533 	fnd_message.set_token('CCID',to_char(h_ccid_error),FALSE);
1534 	fnd_message.set_token('FLEX_CODE','GL#',FALSE);
1535   end if;
1536 
1537   h_mesg_str := fnd_message.get;
1538   fa_rx_conc_mesg_pkg.log(h_mesg_str);
1539 
1540 end balances_reports;
1541 
1542 
1543 PROCEDURE CIP_BALANCES_RPT (
1544   book			in	varchar2,
1545   start_period_name	in	varchar2,
1546   end_period_name	in	varchar2,
1547   request_id		in	number,
1548   user_id		in	number,
1549   retcode	 out nocopy number,
1550   errbuf	 out nocopy varchar2) is
1551 
1552 h_success boolean;
1553 BEGIN
1554 
1555   farx_bl.balances_reports (
1556     book => book,
1557     start_period_name => start_period_name,
1558     end_period_name => end_period_name,
1559     report_type => 'CIP COST',
1560     adj_mode => 'ADJUSTMENTS',
1561     request_id => request_id,
1562     user_id => user_id,
1563     calling_fn => 'CIP_BALANCES_RPT',
1564     mesg => errbuf,
1565     success => h_success);
1566 
1567   if (h_success) then retcode := 0;  else retcode := 2;  end if;
1568 
1569   commit;
1570 END CIP_BALANCES_RPT;
1571 
1572 
1573 PROCEDURE ASSET_COST_BALANCES_RPT (
1574   book			in	varchar2,
1575   start_period_name	in	varchar2,
1576   end_period_name	in	varchar2,
1577   report_style          in      varchar2,
1578   request_id		in	number,
1579   user_id		in	number,
1580   retcode	 out nocopy number,
1581   errbuf	 out nocopy varchar2) is
1582 
1583 h_success boolean;
1584 BEGIN
1585 
1586 fa_debug_pkg.initialize;
1587 fa_debug_pkg.add('farxblb','report_style', report_style);
1588 
1589 
1590   farx_bl.balances_reports (
1591     book => book,
1592     start_period_name => start_period_name,
1593     end_period_name => end_period_name,
1594     report_type => 'COST',
1595     adj_mode => 'ADJUSTMENTS',
1596     report_style => report_style,
1597     request_id => request_id,
1598     user_id => user_id,
1599     calling_fn => 'ASSET_COST_BALANCES_RPT',
1600     mesg => errbuf,
1601     success => h_success);
1602 
1603 
1604   if (h_success) then retcode := 0;  else retcode := 2;  end if;
1605 
1606   commit;
1607 END ASSET_COST_BALANCES_RPT;
1608 
1609 PROCEDURE ACCUM_DEPRN_BALANCES_RPT (
1610   book			in	varchar2,
1611   start_period_name	in	varchar2,
1612   end_period_name	in	varchar2,
1613   report_style          in      varchar2,
1614   request_id		in	number,
1615   user_id		in	number,
1616   retcode	 out nocopy number,
1617   errbuf	 out nocopy varchar2) is
1618 
1619   h_success boolean;
1620 
1621 BEGIN
1622 
1623 fa_debug_pkg.initialize;
1624 fa_debug_pkg.add('farxblb','report_style', report_style);
1625 
1626   farx_bl.balances_reports (
1627     book => book,
1628     start_period_name => start_period_name,
1629     end_period_name => end_period_name,
1630     report_type => 'RESERVE',
1631     adj_mode => 'ADJUSTMENTS',
1632     report_style => report_style,
1633     request_id => request_id,
1634     user_id => user_id,
1635     calling_fn => 'ACCUM_DEPRN_BALANCES_RPT',
1636     mesg => errbuf,
1637     success => h_success);
1638 
1639   if (h_success) then retcode := 0;  else retcode := 2;  end if;
1640 
1641   commit;
1642 END ACCUM_DEPRN_BALANCES_RPT;
1643 
1644 
1645 
1646 PROCEDURE REVAL_RESERVE_BALANCES_RPT (
1647   book			in	varchar2,
1648   start_period_name	in	varchar2,
1649   end_period_name	in	varchar2,
1650   request_id		in	number,
1651   user_id		in	number,
1652   retcode	 out nocopy number,
1653   errbuf	 out nocopy varchar2) is
1654 
1655   h_success  boolean;
1656 BEGIN
1657 
1658   farx_bl.balances_reports (
1659     book => book,
1660     start_period_name => start_period_name,
1661     end_period_name => end_period_name,
1662     report_type => 'REVAL RESERVE',
1663     adj_mode => 'ADJUSTMENTS',
1664     request_id => request_id,
1665     user_id => user_id,
1666     calling_fn => 'REVAL_RESERVE_BALANCES_RPT',
1667     mesg => errbuf,
1668     success => h_success);
1669 
1670   if (h_success) then retcode := 0;  else retcode := 2;  end if;
1671 
1672   commit;
1673 END REVAL_RESERVE_BALANCES_RPT;
1674 
1675 
1676 END FARX_BL;