[Home] [Help]
PACKAGE BODY: APPS.JL_CO_FA_ACCOUNTING_PKG
Source
1 PACKAGE BODY jl_co_fa_accounting_pkg AS
2 /* $Header: jlcofgab.pls 120.15 2007/11/21 11:44:47 hbalijep ship $ */
3
4 /* ======================================================================*
5 | FND Logging infrastructure |
6 * ======================================================================*/
7 G_PKG_NAME CONSTANT VARCHAR2(30) := 'JL_CO_FA_ACCOUNTING_PKG';
8 G_CURRENT_RUNTIME_LEVEL CONSTANT NUMBER := FND_LOG.G_CURRENT_RUNTIME_LEVEL;
9 G_LEVEL_UNEXPECTED CONSTANT NUMBER := FND_LOG.LEVEL_UNEXPECTED;
10 G_LEVEL_ERROR CONSTANT NUMBER := FND_LOG.LEVEL_ERROR;
11 G_LEVEL_EXCEPTION CONSTANT NUMBER := FND_LOG.LEVEL_EXCEPTION;
12 G_LEVEL_EVENT CONSTANT NUMBER := FND_LOG.LEVEL_EVENT;
13 G_LEVEL_PROCEDURE CONSTANT NUMBER := FND_LOG.LEVEL_PROCEDURE;
14 G_LEVEL_STATEMENT CONSTANT NUMBER := FND_LOG.LEVEL_STATEMENT;
15 G_MODULE_NAME CONSTANT VARCHAR2(80) := 'JL.PLSQL.JL_CO_FA_ACCOUNTING_PKG.';
16
17 -----------------------------------------------------------------------------
18 -- Variables corresponding to Who columns --
19 -----------------------------------------------------------------------------
20
21 x_last_updated_by jl_co_fa_adjustments.last_updated_by%TYPE ;
22 x_last_update_login jl_co_fa_adjustments.last_update_login%TYPE;
23 x_request_id jl_co_fa_adjustments.request_id%TYPE;
24 x_program_application_id jl_co_fa_adjustments.program_application_id%TYPE;
25 x_program_id jl_co_fa_adjustments.program_id%TYPE;
26 x_sysdate date;
27
28 -----------------------------------------------------------------------------
29 -- PROCEDURE --
30 -- account_transactions --
31 -- --
32 -- DESCRIPTION --
33 -- Main procedure to execute the Colombian accounting to General Ledger --
34 -- --
35 -- PURPOSE: --
36 -- Oracle Applications Rel. 11.0 --
37 -- --
38 -- PARAMETERS: --
39 -- ERRBUF Parameter used by concurrent process --
40 -- RETCODE Parameter used by concurrent process --
41 -- p_tax_book Tax depreciation book type code --
42 -----------------------------------------------------------------------------
43
44 PROCEDURE account_transactions (ERRBUF OUT NOCOPY VARCHAR2,
45 RETCODE OUT NOCOPY VARCHAR2,
46 p_tax_book IN VARCHAR2
47 )
48 IS
49
50 l_api_name CONSTANT VARCHAR2(30) := 'ACCOUNT_TRANSACTIONS';
51
52 -----------------------------------------------------------------------------
53 -- Accounting flexfield structure parameters --
54 -----------------------------------------------------------------------------
55 -- LER, 18-Jun-99 Balancing and cost center qualifier variables are --
56 -- not more used. --
57 -----------------------------------------------------------------------------
58
59 x_appl_id NUMBER := 101;
60 x_apps_short_name VARCHAR2(5) := 'SQLGL';
61 x_key_flex_code VARCHAR2(3) := 'GL#';
62 -- x_balancing_qualifier VARCHAR2(20) := 'GL_BALANCING';
63 -- x_cost_ctr_qualifier VARCHAR2(20) := 'FA_COST_CTR';
64 x_account_qualifier VARCHAR2(20) := 'GL_ACCOUNT';
65 x_delimiter VARCHAR2(1) ;
66
67 -----------------------------------------------------------------------------
68 -- Book and period parameters --
69 -----------------------------------------------------------------------------
70
71 x_chart_of_accounts_id fa_book_controls.accounting_flex_structure%TYPE;
72 x_corporate_book fa_book_controls.book_type_code%TYPE;
73 x_period_counter fa_book_controls.last_period_counter%TYPE;
74 x_account_period fa_book_controls.last_period_counter%TYPE;
75 x_period_name fa_deprn_periods.period_name%TYPE;
76 x_deprn_date fa_deprn_periods.period_open_date%TYPE;
77
78 x_currency_code gl_sets_of_books.currency_code%TYPE;
79 x_precision fnd_currencies.precision%TYPE;
80 x_extended_precision fnd_currencies.extended_precision%TYPE;
81 x_minumum_accountable_unit fnd_currencies.minimum_accountable_unit%TYPE;
82
83 -----------------------------------------------------------------------------
84 -- Journal entry categories --
85 -----------------------------------------------------------------------------
86
87 x_je_category_name gl_je_categories.je_category_name%TYPE;
88 x_je_std_category_name gl_je_categories.je_category_name%TYPE;
89 x_je_depreciation gl_je_categories.je_category_name%TYPE;
90
91 x_je_infln_adjustment gl_je_categories.je_category_name%TYPE;
92 x_je_cip_infln_adjustment gl_je_categories.je_category_name%TYPE;
93 x_je_ia_addition gl_je_categories.je_category_name%TYPE;
94 x_je_ia_cip_addition gl_je_categories.je_category_name%TYPE;
95 x_je_ia_adjustment gl_je_categories.je_category_name%TYPE;
96 x_je_ia_cip_adjustment gl_je_categories.je_category_name%TYPE;
97 x_je_ia_reclass gl_je_categories.je_category_name%TYPE;
98 x_je_ia_cip_reclass gl_je_categories.je_category_name%TYPE;
99 x_je_ia_transfer gl_je_categories.je_category_name%TYPE;
100 x_je_ia_cip_transfer gl_je_categories.je_category_name%TYPE;
101 x_je_ia_retirement gl_je_categories.je_category_name%TYPE;
102 x_je_ia_cip_retirement gl_je_categories.je_category_name%TYPE;
103 x_je_appraisal gl_je_categories.je_category_name%TYPE;
104
105 ---------------------------------------------------------------------------------
106 -- Segments and CCIDs for natural accounts used by package --
107 -- LER, 18-Jun-99 a. Balancing and cost center segment are not more used --
108 -- b. CCIDs are not more stored in FA_BOOKS_CONTROLS.GDF; --
109 -- these GDF store the natural accouns in Rel. 11.5 --
110 ---------------------------------------------------------------------------------
111
112 -- x_balancing_segment NUMBER;
113 x_account_segment NUMBER;
114 -- x_cost_ctr_segment NUMBER;
115
116 x_deprn_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
117 -- x_ia_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
118 -- x_ix_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
119 -- x_ia_deprn_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
120 -- x_ix_deprn_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
121 x_expense_ccid fa_category_books.asset_cost_account_ccid%TYPE;
122 -- x_ia_cip_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
123 -- x_ix_cip_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
124 -- x_ta_revaluation_ccid fa_category_books.asset_cost_account_ccid%TYPE;
125 -- x_ta_surplus_ccid fa_category_books.asset_cost_account_ccid%TYPE;
126 -- x_ta_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
127 -- x_ta_reserve_expense_ccid fa_category_books.asset_cost_account_ccid%TYPE;
128 -- x_ta_reserve_recovery_ccid fa_category_books.asset_cost_account_ccid%TYPE;
129
130 x_old_deprn_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
131 -- x_old_ia_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
132 -- x_old_ix_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
133 -- x_old_ia_deprn_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
134 -- x_old_ix_deprn_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
135 x_old_expense_ccid fa_category_books.asset_cost_account_ccid%TYPE;
136 -- x_old_ia_cip_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
137 -- x_old_ix_cip_cost_ccid fa_category_books.asset_cost_account_ccid%TYPE;
138 -- x_old_ta_revaluation_ccid fa_category_books.asset_cost_account_ccid%TYPE;
139 -- x_old_ta_surplus_ccid fa_category_books.asset_cost_account_ccid%TYPE;
140 -- x_old_ta_reserve_ccid fa_category_books.asset_cost_account_ccid%TYPE;
141 -- x_old_ta_reserve_expense_ccid fa_category_books.asset_cost_account_ccid%TYPE;
142 -- x_old_ta_reserve_recovery_ccid fa_category_books.asset_cost_account_ccid%TYPE;
143
144 x_deprn_reserve_segm fa_category_books.asset_cost_acct%TYPE;
145 x_ia_cost_segm fa_category_books.asset_cost_acct%TYPE;
146 x_ix_cost_segm fa_category_books.asset_cost_acct%TYPE;
147 x_ia_deprn_reserve_segm fa_category_books.asset_cost_acct%TYPE;
148 x_ix_deprn_reserve_segm fa_category_books.asset_cost_acct%TYPE;
149 x_ia_cip_cost_segm fa_category_books.asset_cost_acct%TYPE;
150 x_ix_cip_cost_segm fa_category_books.asset_cost_acct%TYPE;
151 x_ta_revaluation_segm fa_category_books.asset_cost_acct%TYPE;
152 x_ta_surplus_segm fa_category_books.asset_cost_acct%TYPE;
153 x_ta_reserve_segm fa_category_books.asset_cost_acct%TYPE;
154 x_ta_reserve_expense_segm fa_category_books.asset_cost_acct%TYPE;
155 x_ta_reserve_recovery_segm fa_category_books.asset_cost_acct%TYPE;
156
157 x_old_deprn_reserve_segm fa_category_books.asset_cost_acct%TYPE;
158 x_old_ia_cost_segm fa_category_books.asset_cost_acct%TYPE;
159 x_old_ia_deprn_reserve_segm fa_category_books.asset_cost_acct%TYPE;
160 x_old_ia_cip_cost_segm fa_category_books.asset_cost_acct%TYPE;
161 x_old_ta_revaluation_segm fa_category_books.asset_cost_acct%TYPE;
162 x_old_ta_surplus_segm fa_category_books.asset_cost_acct%TYPE;
163 x_old_ta_reserve_segm fa_category_books.asset_cost_acct%TYPE;
164
165 x_old_ix_cost_segm fa_category_books.asset_cost_acct%TYPE;
166 x_old_ix_deprn_reserve_segm fa_category_books.asset_cost_acct%TYPE;
167 x_old_ix_cip_cost_segm fa_category_books.asset_cost_acct%TYPE;
168 x_old_ta_reserve_expense_segm fa_category_books.asset_cost_acct%TYPE;
169 x_old_ta_reserve_recovery_segm fa_category_books.asset_cost_acct%TYPE;
170
171 x_natural_account fa_category_books.asset_cost_acct%TYPE;
172 x_natural_account1 fa_category_books.asset_cost_acct%TYPE;
173 x_returned_ccid fa_category_books.asset_cost_account_ccid%TYPE;
174 x_concat_segs VARCHAR2(240);
175 x_return_value NUMBER;
176
177 -----------------------------------------------------------------------------
178 -- Name of the accounts used in JL_CO_FA_ADJUSTMENTS.ADJUSTMENT_TYPE --
179 -----------------------------------------------------------------------------
180
181 x_cost_name fa_adjustments.adjustment_type%TYPE := 'COST';
182 x_cip_cost_name fa_adjustments.adjustment_type%TYPE := 'CIP COST';
183 x_reserve_name fa_adjustments.adjustment_type%TYPE := 'RESERVE';
184 x_expense_name fa_adjustments.adjustment_type%TYPE := 'EXPENSE';
185 x_nbv_retired_name fa_adjustments.adjustment_type%TYPE := 'NBV RETIRED';
186 x_reval_amort_name fa_adjustments.adjustment_type%TYPE := 'REVAL AMORT';
187 x_reval_reserve_name fa_adjustments.adjustment_type%TYPE := 'REVAL RESERVE';
188 x_proceeds_name fa_adjustments.adjustment_type%TYPE := 'PROCEEDS';
189 x_removal_cost_name fa_adjustments.adjustment_type%TYPE := 'REMOVALCOST';
190
191 x_ia_cost_name fa_adjustments.adjustment_type%TYPE := 'IA COST';
192 x_ix_cost_name fa_adjustments.adjustment_type%TYPE := 'IX COST';
193 x_ia_cip_cost_name fa_adjustments.adjustment_type%TYPE := 'IA CIP COST';
194 x_ix_cip_cost_name fa_adjustments.adjustment_type%TYPE := 'IX CIP COST';
195 x_ia_reserve_name fa_adjustments.adjustment_type%TYPE := 'IA DEPRN RESRVE';
196 x_ix_reserve_name fa_adjustments.adjustment_type%TYPE := 'IX DEPRN RESRVE';
197 x_ia_expense_name fa_adjustments.adjustment_type%TYPE := 'IA DEPRN EXPNSE';
198 x_ix_expense_name fa_adjustments.adjustment_type%TYPE := 'IX DEPRN EXPNSE';
199
200 x_ta_revaluation_name fa_adjustments.adjustment_type%TYPE := 'TA REVALUATION';
201 x_ta_surplus_name fa_adjustments.adjustment_type%TYPE := 'TA SURPLUS';
202 x_ta_reserve_name fa_adjustments.adjustment_type%TYPE := 'TA RESERVE';
203 x_ta_expense_name fa_adjustments.adjustment_type%TYPE := 'TA RESRVE EXPEN';
204 x_ta_recovery_name fa_adjustments.adjustment_type%TYPE := 'TA RESRVE RECOV';
205
206 x_account_name fa_adjustments.adjustment_type%TYPE;
207
208 -----------------------------------------------------------------------------
209 -- Variables for transaction tracking --
210 -----------------------------------------------------------------------------
211
212 x_transaction_header_id_in fa_transaction_headers.transaction_header_id%TYPE;
213 x_transaction_header_id_out fa_transaction_headers.transaction_header_id%TYPE;
214 x_date_effective fa_transaction_headers.date_effective%TYPE;
215 x_category_id fa_asset_history.category_id%TYPE;
216 x_prior_category_id fa_asset_history.category_id%TYPE;
217 x_old_category_id fa_asset_history.category_id%TYPE;
218 x_asset_id fa_additions.asset_id%TYPE;
219
220 x_distribution_id fa_distribution_history.distribution_id%TYPE;
221 x_debit_credit_flag fa_adjustments.debit_credit_flag%TYPE;
222 x_code_combination_id fa_adjustments.code_combination_id%TYPE;
223 x_adjustment_amount fa_adjustments.adjustment_amount%TYPE;
224 x_adjustment_type fa_adjustments.adjustment_type%TYPE;
225
226 x_cost_dr NUMBER;
227 x_cost_cr NUMBER;
228 x_reserve_dr NUMBER;
229 x_reserve_cr NUMBER;
230 x_expense_dr NUMBER;
231 x_expense_cr NUMBER;
232
233 x_adj_cost fa_deprn_summary.adjusted_cost%TYPE;
234 x_adj_deprn_reserve fa_deprn_summary.deprn_reserve%TYPE;
235 x_adj_ytd_deprn fa_deprn_summary.ytd_deprn%TYPE;
236 x_adj_reval_deprn_expense fa_deprn_summary.reval_deprn_expense%TYPE;
237 x_adj_reval_reserve fa_deprn_summary.reval_reserve%TYPE;
238 x_corp_cost fa_deprn_summary.adjusted_cost%TYPE;
239 x_corp_deprn_reserve fa_deprn_summary.deprn_reserve%TYPE;
240 x_corp_ytd_deprn fa_deprn_summary.ytd_deprn%TYPE;
241 x_corp_reval_deprn_expense fa_deprn_summary.reval_deprn_expense%TYPE;
242 x_corp_reval_reserve fa_deprn_summary.reval_reserve%TYPE;
243
244 x_corp_retirement_id fa_retirements.retirement_id%TYPE;
245 x_date_retired fa_retirements.date_retired%TYPE;
246 x_corp_cost_retired fa_retirements.cost_retired%TYPE;
247 x_corp_units_retired fa_retirements.units%TYPE;
248 x_corp_nbv_retired fa_retirements.nbv_retired%TYPE;
249 x_corp_reval_reserve_retired fa_retirements.reval_reserve_retired%TYPE;
250 x_corp_gain_loss_amount fa_retirements.gain_loss_amount%TYPE;
251 x_adj_retirement_id fa_retirements.retirement_id%TYPE;
252 x_adj_cost_retired fa_retirements.cost_retired%TYPE;
253 x_adj_units_retired fa_retirements.units%TYPE;
254 x_adj_nbv_retired fa_retirements.nbv_retired%TYPE;
255 x_adj_reval_reserve_retired fa_retirements.reval_reserve_retired%TYPE;
256 x_adj_gain_loss_amount fa_retirements.gain_loss_amount%TYPE;
257
258 x_retirement_type VARCHAR2 (1);
259 x_retirement_type_code fa_transaction_headers.transaction_type_code%TYPE;
260 x_source_transaction_header_id fa_transaction_headers.transaction_header_id%TYPE;
261 x_nbv_debit_credit_flag fa_adjustments.debit_credit_flag%TYPE;
262 x_nbv_retired_ccid fa_adjustments.code_combination_id%TYPE;
263 x_ia_cost_retired NUMBER;
264 x_ia_reserve NUMBER;
265 x_ia_reserve_retired NUMBER;
266 x_gain_loss_changed BOOLEAN;
267
268 x_global_source fa_transaction_headers.transaction_type_code%TYPE;
269 x_global_appraisal fa_transaction_headers.transaction_type_code%TYPE := 'APPRAISAL';
270 x_adj_cost_line NUMBER;
271 x_corp_cost_line NUMBER;
272 x_deprn_to_cost NUMBER;
273 x_addition_flag BOOLEAN;
274 x_adjustment_flag BOOLEAN;
275 x_factor NUMBER;
276 x_factor_1 NUMBER;
277 x_factor_11 NUMBER;
278 x_factor_12 NUMBER;
279 x_factor_2 NUMBER;
280 x_ta_factor NUMBER;
281 x_ta_line_amount NUMBER;
282
283 x_value_1 NUMBER;
284 x_value_2 NUMBER;
285 x_value_3 NUMBER;
286 x_value_4 NUMBER;
287 x_value_5 NUMBER;
288 x_period_1 NUMBER;
289 l_book_type_code fa_books.book_type_code%type;
290
291 -- x_nbv_retired NUMBER;
292
293 -----------------------------------------------------------------------------
294 -- Exception variables --
295 -----------------------------------------------------------------------------
296
297 e_period_was_closed EXCEPTION;
298 e_not_finished_by_ccid EXCEPTION;
299 e_ccid_not_found EXCEPTION;
300
301 -----------------------------------------------------------------------------
302 -- Variables for number and message errors --
303 -----------------------------------------------------------------------------
304
305 call_status BOOLEAN;
306 err_num NUMBER;
307 err_msg VARCHAR2(200);
308 x_error_ccid BOOLEAN;
309 x_temporal BOOLEAN;
310 x_char VARCHAR2 (200);
311
312 -----------------------------------------------------------------------------
313 -- Get transactions for tracking --
314 -----------------------------------------------------------------------------
315
316 CURSOR c_transac (pc_tax_book IN VARCHAR2,
317 pc_corporate_book IN VARCHAR2,
318 pc_period_counter IN NUMBER
319 )
320 IS
321 SELECT ah.category_id,
322 th.asset_id,
323 th.transaction_header_id,
324 th.book_type_code,
325 th.transaction_type_code,
326 th.transaction_subtype,
327 th.transaction_date_entered,
328 th.date_effective,
329 th.source_transaction_header_id,
330 ad.asset_number,
331 ah.asset_type,
332 nvl (ah.units,0) units,
333 bk.date_placed_in_service,
334 bk.period_counter_capitalized,
335 nvl (bk.cost,0) adj_cost,
336 fnd_number.canonical_to_number(nvl (bk.global_attribute2,0)) appraisal_balance,
337 fnd_number.canonical_to_number(nvl (bk.global_attribute7,0)) deprn_to_cost,
338 bk.rowid book_rowid
339 FROM fa_transaction_headers th,
340 fa_deprn_periods dp,
341 fa_additions ad,
342 fa_asset_history ah,
343 fa_books bk
344 WHERE dp.book_type_code = pc_tax_book
345 AND dp.period_counter = pc_period_counter
346 AND th.book_type_code = dp.book_type_code
347 AND dp.period_open_date <= th.date_effective
348 AND th.date_effective <= dp.period_close_date
349 AND th.transaction_type_code IN ('REVALUATION',
350 'ADDITION',
351 'CIP ADDITION',
352 'ADJUSTMENT',
353 'CIP ADJUSTMENT',
354 'FULL RETIREMENT',
355 'PARTIAL RETIREMENT',
356 'REINSTATEMENT'
357 )
358 AND ad.asset_id = th.asset_id
359 AND ah.asset_id = th.asset_id
360 AND ah.date_effective <= th.date_effective
361 AND th.date_effective < nvl (ah.date_ineffective, sysdate)
362 AND bk.book_type_code = pc_tax_book
363 AND bk.asset_id = th.asset_id
364 AND bk.date_effective <= th.date_effective
365 AND th.date_effective < nvl (bk.date_ineffective, sysdate)
366 UNION
367 SELECT ah.category_id,
368 th.asset_id,
369 th.transaction_header_id,
370 th.book_type_code,
371 th.transaction_type_code,
372 th.transaction_subtype,
373 th.transaction_date_entered,
374 th.date_effective,
375 th.source_transaction_header_id,
376 ad.asset_number,
377 ah.asset_type,
378 nvl (ah.units,0),
379 bk.date_placed_in_service,
380 bk.period_counter_capitalized,
381 nvl (bk.cost,0),
382 fnd_number.canonical_to_number(nvl (bk.global_attribute2,0)),
383 fnd_number.canonical_to_number(nvl (bk.global_attribute7,0)),
384 bk.rowid
385 FROM fa_transaction_headers th,
386 fa_deprn_periods dp,
387 fa_additions ad,
388 fa_asset_history ah,
389 fa_books bk
390 WHERE dp.book_type_code = pc_corporate_book
391 AND dp.period_counter = pc_period_counter
392 AND th.book_type_code = dp.book_type_code
393 AND dp.period_open_date <= th.date_effective
394 AND th.date_effective <= dp.period_close_date
395 AND th.transaction_type_code IN ('TRANSFER OUT',
396 'RECLASS',
397 'CIP RECLASS',
398 'TRANSFER',
399 'CIP TRANSFER',
400 'UNIT ADJUSTMENT'
401 )
402 AND ad.asset_id = th.asset_id
403 AND ah.asset_id = th.asset_id
404 AND ah.date_effective <= th.date_effective
405 AND th.date_effective < nvl (ah.date_ineffective, sysdate)
406 AND bk.book_type_code = pc_tax_book
407 AND bk.asset_id = th.asset_id
408 AND bk.date_effective <= th.date_effective
409 AND th.date_effective < nvl (bk.date_ineffective, sysdate)
410 ORDER BY 1,2,3 ;
411
412 -----------------------------------------------------------------------------
413 -- Get CCID for globalization accounts of a asset category --
414 -----------------------------------------------------------------------------
415
416 CURSOR c_accounts (pc_category_id IN NUMBER,
417 pc_book_type_code IN VARCHAR2
418 )
419 IS
420 SELECT reserve_account_ccid,
421 deprn_reserve_acct,
422 global_attribute3,
423 global_attribute4,
424 global_attribute5,
425 global_attribute6,
426 global_attribute9,
427 global_attribute10,
428 global_attribute11,
429 global_attribute12,
430 global_attribute13,
431 global_attribute14,
432 global_attribute15
433 FROM fa_category_books
434 WHERE category_id = pc_category_id
435 AND book_type_code = pc_book_type_code ;
436
437 -----------------------------------------------------------------------------
438 -- Get CCID and segment for the Depreciation Reserve account --
439 -----------------------------------------------------------------------------
440
441 CURSOR c_reserve_acct (pc_category_id IN NUMBER,
442 pc_book_type_code IN VARCHAR2
443 )
444 IS
445 SELECT reserve_account_ccid,
446 deprn_reserve_acct
447 FROM fa_category_books
448 WHERE category_id = pc_category_id
449 AND book_type_code = pc_book_type_code ;
450
451 -----------------------------------------------------------------------------
452 -- Get the prior asset category (used in reclassifications) --
453 -----------------------------------------------------------------------------
454
455 CURSOR c_prior_category (pc_asset_id IN NUMBER,
456 pc_transaction_header_id IN NUMBER
457 )
458 IS
459 SELECT category_id
460 FROM fa_asset_history
461 WHERE asset_id = pc_asset_id
462 AND transaction_header_id_out = pc_transaction_header_id;
463
464 -----------------------------------------------------------------------------
465 -- Get historical and adjusted depreciation at asset level --
466 -----------------------------------------------------------------------------
467
468 CURSOR c_deprn_summary (pc_book_type_code IN VARCHAR2,
469 pc_asset_id IN NUMBER,
470 pc_period_counter IN NUMBER
471 )
472 IS
473 SELECT nvl (deprn_reserve,0),
474 nvl (reval_reserve,0),
475 nvl (reval_deprn_expense,0)
476 FROM fa_deprn_summary
477 WHERE asset_id = pc_asset_id
478 AND book_type_code = pc_book_type_code
479 AND period_counter = pc_period_counter;
480
481 ----------------------------------------------------------------------------
482 -- Get all adjustment rows of a transaction with Amount # 0 --
483 -- Bug 3931540: Cursor c_tr_adjustments has been splitted in 2 cursors --
484 -- to improve performace and handle the condition of --
485 -- pc_adj_type null or not null --
486 ----------------------------------------------------------------------------
487
488 CURSOR c_tr_adjustments_no_adj_type (pc_transaction_header_id IN NUMBER,
489 pc_book_type_code IN VARCHAR2,
490 pc_period_counter IN NUMBER -- Bug 3680318
491 )
492 IS
493 SELECT ADJ.distribution_id,
494 ADJ.source_type_code,
495 ADJ.adjustment_type,
496 ADJ.debit_credit_flag,
497 --ADJ.code_combination_id,
498 XLN.code_combination_id,
499 ADJ.adjustment_amount,
500 ADJ.annualized_adjustment,
501 ADJ.period_counter_adjusted,
502 ADJ.period_counter_created,
503 ADJ.asset_invoice_id
504 FROM fa_adjustments ADJ,
505 --SLA Changes. New Tables Added
506 xla_ae_headers XHD,
507 xla_ae_lines XLN,
508 xla_distribution_links XDL
509 WHERE ADJ.transaction_header_id = pc_transaction_header_id
510 AND ADJ.book_type_code = pc_book_type_code
511 AND ADJ.period_counter_created = pc_period_counter --Bug 3680318,4060555
512 AND ADJ.adjustment_amount <> 0
513 --SLA Changes. New Joins added.
514 AND XDL.source_distribution_id_num_1 = ADJ.transaction_header_id
515 AND XDL.source_distribution_id_num_2 = ADJ.adjustment_line_id
516 AND XLN.ae_header_id = XHD.ae_header_id
517 AND XDL.application_id = 140
518 AND XDL.source_distribution_type = 'TRX'
519 AND XLN.ae_header_id = XDL.ae_header_id
520 AND XLN.ae_line_num = XDL.ae_line_num
521 AND XLN.application_id = 140
522 ORDER BY 1,2,3;
523
524
525 ----------------------------------------------------------------------------
526 -- Get all adjustment rows of a transaction with Amount # 0 --
527 -- Bug 3931540: Cursor c_tr_adjustments has been splitted in 2 cursors --
528 -- to improve performace and handle the condition of --
529 -- pc_adj_type null or not null --
530 ----------------------------------------------------------------------------
531
532 CURSOR c_tr_adjustments_adj_type (pc_transaction_header_id IN NUMBER,
533 pc_book_type_code IN VARCHAR2,
534 pc_adjustment_type IN VARCHAR2,
535 pc_period_counter IN NUMBER -- Bug 3680318
536 )
537 IS
538 SELECT ADJ.distribution_id,
539 ADJ.source_type_code,
540 ADJ.adjustment_type,
541 ADJ.debit_credit_flag,
542 --ADJ.code_combination_id,
543 XLN.code_combination_id,
544 ADJ.adjustment_amount,
545 ADJ.annualized_adjustment,
546 ADJ.period_counter_adjusted,
547 ADJ.period_counter_created,
548 ADJ.asset_invoice_id
549 FROM fa_adjustments ADJ,
550 --SLA Changes. New Tables Added
551 xla_ae_headers XHD,
552 xla_ae_lines XLN,
553 xla_distribution_links XDL
554 WHERE ADJ.transaction_header_id = pc_transaction_header_id
555 AND ADJ.book_type_code = pc_book_type_code
556 AND ADJ.period_counter_created = pc_period_counter --Bug 3680318,4060555
557 AND ADJ.adjustment_amount <> 0
558 AND ADJ.adjustment_type = pc_adjustment_type
559 --SLA Changes. New Joins added.
560 AND XDL.source_distribution_id_num_1 = ADJ.transaction_header_id
561 AND XDL.source_distribution_id_num_2 = ADJ.adjustment_line_id
562 AND XLN.ae_header_id = XHD.ae_header_id
563 AND XDL.application_id = 140
564 AND XDL.source_distribution_type = 'TRX'
565 AND XLN.ae_header_id = XDL.ae_header_id
566 AND XLN.ae_line_num = XDL.ae_line_num
567 AND XLN.application_id = 140
568 ORDER BY 1,2,3;
569
570
571 -----------------------------------------------------------------------------
572 -- For an adjustment row in a book (Corp/Tax) find its corresponding in --
573 -- the associated book (Tax/Corp) --
574 -----------------------------------------------------------------------------
575
576 CURSOR c_tr_rel_adjustments (pc_transaction_header_id IN NUMBER,
577 pc_book_type_code IN VARCHAR2,
578 pc_source_type_code IN VARCHAR2,
579 pc_adjustment_type IN VARCHAR2,
580 pc_debit_credit_flag IN VARCHAR2,
581 pc_distribution_id IN NUMBER
582 )
583 IS
584 --SELECT ADJ. code_combination_id,
585 SELECT XLN.code_combination_id,
586 ADJ.adjustment_amount
587 FROM fa_adjustments ADJ,
588 --SLA Changes. New Tables Added
589 xla_ae_headers XHD,
590 xla_ae_lines XLN,
591 xla_distribution_links XDL
592 WHERE ADJ.transaction_header_id = pc_transaction_header_id
593 AND ADJ.book_type_code = pc_book_type_code
594 AND ADJ.source_type_code = pc_source_type_code
595 AND ADJ.adjustment_type = pc_adjustment_type
596 AND ADJ.debit_credit_flag = pc_debit_credit_flag
597 AND ADJ.distribution_id = pc_distribution_id
598 AND ADJ.adjustment_amount <> 0
599 --SLA Changes. New Joins added.
600 AND XDL.source_distribution_id_num_1 = ADJ.transaction_header_id
601 AND XDL.source_distribution_id_num_2 = ADJ.adjustment_line_id
602 AND XLN.ae_header_id = XHD.ae_header_id
603 AND XDL.application_id = 140
604 AND XDL.source_distribution_type = 'TRX'
605 AND XLN.ae_header_id = XDL.ae_header_id
606 AND XLN.ae_line_num = XDL.ae_line_num
607 AND XLN.application_id = 140;
608
609 -----------------------------------------------------------------------------
610 -- Get the total value for a concept recorded in FA_ADJUSTMENTS --
611 -----------------------------------------------------------------------------
612
613 CURSOR c_sum_adjustments (pc_asset_id IN NUMBER,
614 pc_book_type_code IN VARCHAR2,
615 pc_transaction_header_id IN NUMBER,
616 pc_adjustment_type IN VARCHAR2,
617 pc_debit_credit_flag IN VARCHAR2
618 )
619 IS
620 SELECT nvl (sum (nvl (adjustment_amount,0)), 0)
621 FROM fa_adjustments
622 WHERE asset_id = pc_asset_id
623 AND book_type_code = pc_book_type_code
624 AND transaction_header_id = pc_transaction_header_id
625 AND adjustment_type = pc_adjustment_type
626 AND debit_credit_flag = pc_debit_credit_flag ;
627
628 -----------------------------------------------------------------------------
629 -- Get the total value for a transaction type and concept --
630 -----------------------------------------------------------------------------
631
632 CURSOR c_sum_all_adjustments (pc_asset_id IN NUMBER,
633 pc_book_type_code IN VARCHAR2,
634 pc_period_counter IN NUMBER,
635 pc_adjustment_type IN VARCHAR2,
636 pc_debit_credit_flag IN VARCHAR2
637 )
638 IS
639 SELECT nvl (sum (nvl (adjustment_amount,0)), 0)
640 FROM fa_adjustments
641 WHERE asset_id = pc_asset_id
642 AND book_type_code = pc_book_type_code
643 AND period_counter_created = pc_period_counter
644 AND adjustment_type = pc_adjustment_type
645 AND debit_credit_flag = pc_debit_credit_flag ;
646
647 -----------------------------------------------------------------------------
648 -- Get the cost and depreciation retired in a retirement transaction --
649 -----------------------------------------------------------------------------
650
651 CURSOR c_retirement (pc_transaction_header_id IN NUMBER)
652 IS
653 SELECT retirement_id,
654 nvl (cost_retired,0),
655 nvl (units,0),
656 nvl (nbv_retired,0),
657 nvl (reval_reserve_retired,0),
658 nvl (gain_loss_amount,0)
659 FROM fa_retirements
660 WHERE transaction_header_id_in = pc_transaction_header_id ;
661
662 -----------------------------------------------------------------------------
663 -- Get the cost and depreciation retired in a retirement transaction --
664 -----------------------------------------------------------------------------
665
666 CURSOR c_reinstatement (pc_transaction_header_id IN NUMBER)
667 IS
668 SELECT rt.retirement_id,
669 nvl (rt.cost_retired,0),
670 nvl (rt.units,0),
671 nvl (rt.nbv_retired,0),
672 nvl (rt.reval_reserve_retired,0),
673 nvl (rt.gain_loss_amount,0),
674 dp.period_counter,
675 th.transaction_type_code
676 FROM fa_retirements rt,
677 fa_deprn_periods dp,
678 fa_transaction_headers th
679 WHERE rt.transaction_header_id_out = pc_transaction_header_id
680 AND dp.book_type_code = rt.book_type_code
681 AND dp.period_open_date <= rt.date_effective
682 AND rt.date_effective <= dp.period_close_date
683 AND th.transaction_header_id = rt.transaction_header_id_in ;
684
685 -----------------------------------------------------------------------------
686 -- Get the source partial unit retirement transaction id in a Corporate --
687 -- book for the same retirement type in a Tax book --
688 -----------------------------------------------------------------------------
689
690 CURSOR c_source_retirement (pc_transaction_header_id IN NUMBER)
691 IS
692 SELECT transaction_header_id_in
693 FROM fa_retirements
694 WHERE retirement_id = (SELECT retirement_id
695 FROM fa_distribution_history
696 WHERE distribution_id = (SELECT distribution_id
697 FROM fa_distribution_history
698 WHERE transaction_header_id_out = pc_transaction_header_id
699 AND rownum = 1));
700
701 -----------------------------------------------------------------------------
702 -- Get the Transaction Header Id. corresponding to the source retirement --
703 -- in a Reinstatement transaction --
704 -----------------------------------------------------------------------------
705
706 CURSOR c_prior_retirement (pc_transaction_header_id IN NUMBER)
707 IS
708 SELECT transaction_header_id_in,
709 fnd_number.canonical_to_number(nvl (global_attribute7,0))
710 FROM fa_books
711 WHERE transaction_header_id_out = pc_transaction_header_id;
712
713 -------------------------------------------------------------------------------
714
715 -----------------------------------------------------------------------------
716 -- Assets depreciated in the period --
717 -----------------------------------------------------------------------------
718
719 CURSOR c_assets_depreciated (pc_book_type_code IN VARCHAR2,
720 pc_period_counter IN NUMBER,
721 pc_deprn_date IN DATE
722 )
723 IS
724 SELECT ah.category_id,
725 ds.asset_id,
726 ad.asset_number,
727 bk.transaction_header_id_in,
728 fnd_number.canonical_to_number(nvl (bk.global_attribute7,0)) deprn_to_cost,
729 bk.rowid book_rowid
730 FROM fa_additions ad,
731 fa_asset_history ah,
732 fa_books bk,
733 fa_deprn_summary ds
734 WHERE ds.book_type_code = pc_book_type_code
735 AND ds.period_counter = pc_period_counter
736 AND ad.asset_id = ds.asset_id
737 AND ah.asset_id = ds.asset_id
738 AND ah.date_effective <= pc_deprn_date
739 AND pc_deprn_date < nvl (ah.date_ineffective, sysdate)
740 AND bk.book_type_code = ds.book_type_code
741 AND bk.asset_id = ds.asset_id
742 AND bk.date_effective <= pc_deprn_date
743 AND pc_deprn_date < nvl (bk.date_ineffective, sysdate)
744 ORDER BY ah.category_id,
745 ds.asset_id ;
746
747 -----------------------------------------------------------------------------
748 -- Get depreciation for an asset at distribution lines level --
749 -----------------------------------------------------------------------------
750
751 CURSOR c_lines_depreciated (pc_tax_book IN VARCHAR2,
752 pc_period_counter IN NUMBER,
753 pc_asset_id IN NUMBER,
754 pc_corporate_book IN VARCHAR2
755 )
756 IS
757 SELECT dd.distribution_id,
758 nvl (dd.deprn_amount, 0) adj_deprn_amount,
759 nvl (dd.deprn_adjustment_amount, 0) adj_deprn_adjustment_amount,
760 nvl (dc.deprn_amount, 0) corp_deprn_amount,
761 nvl (dc.deprn_adjustment_amount, 0) corp_deprn_adjustment_amount,
762 dh.code_combination_id
763 FROM fa_deprn_detail dd,
764 fa_deprn_detail dc,
765 fa_distribution_history dh
766 WHERE dd.asset_id = pc_asset_id
767 AND dd.book_type_code = pc_tax_book
768 AND dd.period_counter = pc_period_counter
769 AND dc.asset_id = dd.asset_id
770 AND dc.book_type_code = pc_corporate_book
771 AND dc.period_counter = dd.period_counter
772 AND dc.distribution_id = dd.distribution_id
773 AND dh.distribution_id = dd.distribution_id;
774
775 BEGIN
776
777 IF ( G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
778 FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME||l_api_name||'.BEGIN',G_PKG_NAME||': '||l_api_name||'(+)');
779 END IF;
780
781 -----------------------------------------------------------------------------
782 -- Procedure starts and writes the concurrent parameters on log file --
783 -----------------------------------------------------------------------------
784
785 fnd_message.set_name ('JL', 'JL_CO_FA_PARAMETER');
786 fnd_file.put_line (FND_FILE.LOG, fnd_message.get);
787 fnd_file.put_line (FND_FILE.LOG, '----------------------------------------');
788 fnd_message.set_name ('JL', 'JL_CO_FA_BOOK');
789 fnd_message.set_token ('BOOK', p_tax_book);
790 fnd_file.put_line (1, fnd_message.get);
791 fnd_file.put_line (FND_FILE.LOG, '----------------------------------------');
792
793 -----------------------------------------------------------------------------
794 -- Define Who columns --
795 -----------------------------------------------------------------------------
796
797 x_last_updated_by := fnd_global.user_id;
798 x_last_update_login := fnd_global.login_id;
799 x_request_id := fnd_global.conc_request_id;
800 x_program_application_id := fnd_global.prog_appl_id;
801 x_program_id := fnd_global.conc_program_id;
802 x_sysdate := SYSDATE;
803
804 -----------------------------------------------------------------------------
805 -- Depreciation Tax book parameters --
806 -----------------------------------------------------------------------------
807
808 SELECT bc.accounting_flex_structure,
809 bc.distribution_source_book,
810 bc.last_period_counter,
811 nvl (bc.global_attribute5, last_period_counter),
812 -- bc.je_depreciation_category,
813 bc.global_attribute6,
814 bc.global_attribute7,
815 bc.global_attribute8,
816 bc.global_attribute9,
817 bc.global_attribute10,
818 bc.global_attribute11,
819 bc.global_attribute12,
820 bc.global_attribute13,
821 bc.global_attribute14,
822 bc.global_attribute15,
823 bc.global_attribute16,
824 bc.global_attribute17,
825 bc.global_attribute18,
826 dp.period_name,
827 dp.period_close_date,
828 sb.currency_code
829 INTO x_chart_of_accounts_id,
830 x_corporate_book,
831 x_period_counter,
832 x_account_period,
833 -- x_je_depreciation,
834 x_je_infln_adjustment,
835 x_je_ia_reclass,
836 x_je_ia_cip_reclass,
837 x_je_ia_transfer,
838 x_je_ia_cip_transfer,
839 x_je_ia_retirement,
840 x_je_ia_cip_retirement,
841 x_je_appraisal,
842 x_je_ia_addition,
843 x_je_ia_cip_addition,
844 x_je_ia_adjustment,
845 x_je_ia_cip_adjustment,
846 x_je_cip_infln_adjustment,
847 x_period_name,
848 x_deprn_date,
849 x_currency_code
850 FROM fa_book_controls bc,
851 fa_deprn_periods dp,
852 gl_sets_of_books sb
853 WHERE bc.book_type_code = p_tax_book
854 AND dp.book_type_code = bc.book_type_code
855 AND dp.period_counter = bc.last_period_counter
856 AND sb.set_of_books_id = bc.set_of_books_id ;
857
858 SELECT je_category_name
859 INTO x_je_depreciation
860 FROM xla_event_class_attrs
861 WHERE application_id = 140
862 AND entity_code = 'DEPRECIATION'
863 AND event_class_code = 'DEPRECIATION';
864
865 -----------------------------------------------------------------------------
866 -- Write close globalization period name on log file --
867 -----------------------------------------------------------------------------
868
869 fnd_message.set_name ('JL', 'JL_ZZ_FA_PERIOD_NAME');
870 fnd_message.set_token ('PERIOD_NAME', x_period_name);
871 fnd_file.put_line (1, fnd_message.get);
872
873 -----------------------------------------------------------------------------
874 -- Verify conditions to execute --
875 -----------------------------------------------------------------------------
876
877 IF ( x_period_counter <> x_account_period + 1 ) THEN
878 RAISE e_period_was_closed;
879 END IF;
880
881 -----------------------------------------------------------------------------
882 -- Get currency parameters --
883 -----------------------------------------------------------------------------
884
885 fnd_currency.get_info (x_currency_code,
886 x_precision,
887 x_extended_precision,
888 x_minumum_accountable_unit
889 );
890
891 -----------------------------------------------------------------------------
892 -- Identify the segment numbers for qualified segments: --
893 -- Balance - Cost center - Natural account --
894 -- LER, 18-Jun-99 Balancing and cost center segment are not more used --
895 -----------------------------------------------------------------------------
896
897 -- x_temporal := fnd_flex_apis.get_qualifier_segnum (x_appl_id,
898 -- x_key_flex_code,
899 -- x_chart_of_accounts_id,
900 -- x_balancing_qualifier,
901 -- x_balancing_segment
902 -- );
903
904 -- x_temporal := fnd_flex_apis.get_qualifier_segnum (x_appl_id,
905 -- x_key_flex_code,
906 -- x_chart_of_accounts_id,
907 -- x_cost_ctr_qualifier,
908 -- x_cost_ctr_segment
909 -- );
910
911 x_temporal := fnd_flex_apis.get_qualifier_segnum (x_appl_id,
912 x_key_flex_code,
913 x_chart_of_accounts_id,
914 x_account_qualifier,
915 x_account_segment
916 );
917
918 -----------------------------------------------------------------------------
919 -- Get character used as delimiter to show accounting flexfield --
920 -----------------------------------------------------------------------------
921
922 x_delimiter := fnd_flex_ext.get_delimiter (x_apps_short_name,
923 x_key_flex_code,
924 x_chart_of_accounts_id
925 );
926
927 -----------------------------------------------------------------------------
928 -- Transactions for tracking --
929 -----------------------------------------------------------------------------
930
931 x_asset_id := 0;
932 x_category_id := 0;
933 x_old_category_id := 0;
934
935 FOR tr IN c_transac (p_tax_book,
936 x_corporate_book,
937 x_period_counter
938 ) LOOP
939
940 -----------------------------------------------------------------------------
941 -- Write asset and transaction number on log file --
942 -----------------------------------------------------------------------------
943
944 fnd_message.set_name ('JL', 'JL_CO_FA_TRANSACTION');
945 fnd_message.set_token ('ASSET', tr.asset_number);
946 fnd_message.set_token ('TRANSACTION_ID', tr.transaction_header_id);
947 fnd_message.set_token ('TRANSACTION_TYPE', tr.transaction_type_code);
948 fnd_file.put_line (1, fnd_message.get);
949
950 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
951 x_char := 'tr.deprn_to_cost = ' || to_char(tr.deprn_to_cost);
952 fnd_file.put_line (FND_FILE.LOG, x_char);
953 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
954 END IF;
955 -----------------------------------------------------------------------------
956 -- Asset category parameters --
957 -- LER, 18-Jun-99 CCIDs are not more stored in FA_BOOKS_CONTROLS.GDF; --
958 -- now are only stored the natural accouns --
959 -----------------------------------------------------------------------------
960
961 IF (tr.category_id <> x_category_id) THEN
962 x_category_id := tr.category_id;
963
964 OPEN c_accounts (x_category_id,
965 p_tax_book
966 ) ;
967 -- FETCH c_accounts INTO x_deprn_reserve_ccid,
968 -- x_deprn_reserve_segm,
969 -- x_ia_cost_ccid,
970 -- x_ix_cost_ccid,
971 -- x_ia_deprn_reserve_ccid,
972 -- x_ix_deprn_reserve_ccid,
973 -- x_ia_cip_cost_ccid,
974 -- x_ix_cip_cost_ccid,
975 -- x_ta_revaluation_ccid,
976 -- x_ta_surplus_ccid,
977 -- x_ta_reserve_ccid,
978 -- x_ta_reserve_expense_ccid,
979 -- x_ta_reserve_recovery_ccid ;
980 FETCH c_accounts INTO x_deprn_reserve_ccid,
981 x_deprn_reserve_segm,
982 x_ia_cost_segm,
983 x_ix_cost_segm,
984 x_ia_deprn_reserve_segm,
985 x_ix_deprn_reserve_segm,
986 x_ia_cip_cost_segm,
987 x_ix_cip_cost_segm,
988 x_ta_revaluation_segm,
989 x_ta_surplus_segm,
990 x_ta_reserve_segm,
991 x_ta_reserve_expense_segm,
992 x_ta_reserve_recovery_segm ;
993 CLOSE c_accounts;
994
995 -- extract_account (x_chart_of_accounts_id,
996 -- x_apps_short_name,
997 -- x_key_flex_code,
998 -- x_account_segment,
999 -- x_ia_cost_ccid,
1000 -- x_ia_cost_segm
1001 -- );
1002 -- extract_account (x_chart_of_accounts_id,
1003 -- x_apps_short_name,
1004 -- x_key_flex_code,
1005 -- x_account_segment,
1006 -- x_ix_cost_ccid,
1007 -- x_ix_cost_segm
1008 -- );
1009 -- extract_account (x_chart_of_accounts_id,
1010 -- x_apps_short_name,
1011 -- x_key_flex_code,
1012 -- x_account_segment,
1013 -- x_ia_deprn_reserve_ccid,
1014 -- x_ia_deprn_reserve_segm
1015 -- );
1016 -- extract_account (x_chart_of_accounts_id,
1017 -- x_apps_short_name,
1018 -- x_key_flex_code,
1019 -- x_account_segment,
1020 -- x_ix_deprn_reserve_ccid,
1021 -- x_ix_deprn_reserve_segm
1022 -- );
1023 -- extract_account (x_chart_of_accounts_id,
1024 -- x_apps_short_name,
1025 -- x_key_flex_code,
1026 -- x_account_segment,
1027 -- x_ia_cip_cost_ccid,
1028 -- x_ia_cip_cost_segm
1029 -- );
1030 -- extract_account (x_chart_of_accounts_id,
1031 -- x_apps_short_name,
1032 -- x_key_flex_code,
1033 -- x_account_segment,
1034 -- x_ix_cip_cost_ccid,
1035 -- x_ix_cip_cost_segm
1036 -- );
1037 -- extract_account (x_chart_of_accounts_id,
1038 -- x_apps_short_name,
1039 -- x_key_flex_code,
1040 -- x_account_segment,
1041 -- x_ta_revaluation_ccid,
1042 -- x_ta_revaluation_segm
1043 -- );
1044 -- extract_account (x_chart_of_accounts_id,
1045 -- x_apps_short_name,
1046 -- x_key_flex_code,
1047 -- x_account_segment,
1048 -- x_ta_surplus_ccid,
1049 -- x_ta_surplus_segm
1050 -- );
1051 -- extract_account (x_chart_of_accounts_id,
1052 -- x_apps_short_name,
1053 -- x_key_flex_code,
1054 -- x_account_segment,
1055 -- x_ta_reserve_ccid,
1056 -- x_ta_reserve_segm
1057 -- );
1058 -- extract_account (x_chart_of_accounts_id,
1059 -- x_apps_short_name,
1060 -- x_key_flex_code,
1061 -- x_account_segment,
1062 -- x_ta_reserve_recovery_ccid,
1063 -- x_ta_reserve_recovery_segm
1064 -- );
1065 END IF;
1066
1067 -----------------------------------------------------------------------------
1068 -- Asset parameters --
1069 -- Bug Fix 1098809 The assignment of tr.deprn_to_cost to x_deprn_to_cost --
1070 -- is taken out of the IF statement. --
1071 -- Earlier for a given asset and category_id, if there --
1072 -- are multiple transaction in the period, deprn_to_cost --
1073 -- of only first transaction is assigned to the --
1074 -- x_deprn_to_cost. --
1075 -- The above statement is incorrect. --
1076 -- Bug Fix 1212946 The variable x_deprn_to_cost need not be initialized --
1077 -- for each transaction. For each asset, if there are --
1078 -- multiple transactions, we need recalculated --
1079 -- deprn_to_cost after each transaction. --
1080 -- Therefore, previous changes are reverted. --
1081 -----------------------------------------------------------------------------
1082
1083 IF (tr.asset_id <> x_asset_id) THEN
1084 x_asset_id := tr.asset_id;
1085 x_deprn_to_cost := tr.deprn_to_cost;
1086 x_addition_flag := TRUE;
1087 x_adjustment_flag := TRUE;
1088 END IF;
1089
1090 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1091 x_char := 'Initial x_deprn_to_cost = ' || to_char(x_deprn_to_cost);
1092 fnd_file.put_line (FND_FILE.LOG, x_char);
1093 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
1094 END IF;
1095
1096 -----------------------------------------------------------------------------
1097 -- REVALUATION = Inflation Adjustments --
1098 -----------------------------------------------------------------------------
1099
1100 IF ( tr.transaction_type_code = 'REVALUATION' ) THEN
1101 x_global_source := 'INFLN ADJUST';
1102
1103 FOR ra IN c_tr_adjustments_no_adj_type (tr.transaction_header_id,
1104 tr.book_type_code,
1105 x_period_counter
1106 ) LOOP
1107
1108 --FA SLA Changes.
1109 IF ra.code_combination_id is null then
1110 l_book_type_code := tr.book_type_code;
1111 RAISE e_ccid_not_found;
1112 END IF;
1113
1114 IF (ra.debit_credit_flag = 'DR') THEN
1115 x_debit_credit_flag := 'CR';
1116 ELSE
1117 x_debit_credit_flag := 'DR';
1118 END IF;
1119
1120 IF (ra.adjustment_type = x_cost_name) THEN
1121
1122 -----------------------------------------------------------------------------
1123 -- Capitalized cost inflation adjustments --
1124 -----------------------------------------------------------------------------
1125
1126 change_account (x_chart_of_accounts_id,
1127 x_apps_short_name,
1128 x_key_flex_code,
1129 x_account_segment,
1130 ra.code_combination_id,
1131 x_ia_cost_segm,
1132 x_delimiter,
1133 x_returned_ccid,
1134 x_error_ccid
1135 );
1136
1137 insert_adjustment (tr.transaction_header_id,
1138 x_global_source,
1139 x_je_infln_adjustment,
1140 x_ia_cost_name,
1141 ra.debit_credit_flag,
1142 x_returned_ccid,
1143 p_tax_book,
1144 tr.asset_id,
1145 ra.adjustment_amount,
1146 ra.distribution_id,
1147 ra.annualized_adjustment,
1148 NULL,
1149 NULL,
1150 ra.period_counter_adjusted,
1151 ra.period_counter_created,
1152 ra.asset_invoice_id,
1153 NULL,
1154 NULL
1155 );
1156
1157 change_account (x_chart_of_accounts_id,
1158 x_apps_short_name,
1159 x_key_flex_code,
1160 x_account_segment,
1161 ra.code_combination_id,
1162 x_ix_cost_segm,
1163 x_delimiter,
1164 x_returned_ccid,
1165 x_error_ccid
1166 );
1167
1168 insert_adjustment (tr.transaction_header_id,
1169 x_global_source,
1170 x_je_infln_adjustment,
1171 x_ix_cost_name,
1172 x_debit_credit_flag,
1173 x_returned_ccid,
1174 p_tax_book,
1175 tr.asset_id,
1176 ra.adjustment_amount,
1177 ra.distribution_id,
1178 ra.annualized_adjustment,
1179 NULL,
1180 NULL,
1181 ra.period_counter_adjusted,
1182 ra.period_counter_created,
1183 ra.asset_invoice_id,
1184 NULL,
1185 NULL
1186 );
1187
1188 ELSIF (ra.adjustment_type = x_reserve_name) THEN
1189
1190 -----------------------------------------------------------------------------
1191 -- Depreciation reserve inflation adjustments --
1192 -----------------------------------------------------------------------------
1193
1194 change_account (x_chart_of_accounts_id,
1195 x_apps_short_name,
1196 x_key_flex_code,
1197 x_account_segment,
1198 ra.code_combination_id,
1199 x_ix_deprn_reserve_segm,
1200 x_delimiter,
1201 x_returned_ccid,
1202 x_error_ccid
1203 );
1204
1205 insert_adjustment (tr.transaction_header_id,
1206 x_global_source,
1207 x_je_infln_adjustment,
1208 x_ix_reserve_name,
1209 x_debit_credit_flag,
1210 x_returned_ccid,
1211 p_tax_book,
1212 tr.asset_id,
1213 ra.adjustment_amount,
1214 ra.distribution_id,
1215 ra.annualized_adjustment,
1216 NULL,
1217 NULL,
1218 ra.period_counter_adjusted,
1219 ra.period_counter_created,
1220 ra.asset_invoice_id,
1221 NULL,
1222 NULL
1223 );
1224
1225 change_account (x_chart_of_accounts_id,
1226 x_apps_short_name,
1227 x_key_flex_code,
1228 x_account_segment,
1229 ra.code_combination_id,
1230 x_ia_deprn_reserve_segm,
1231 x_delimiter,
1232 x_returned_ccid,
1233 x_error_ccid
1234 );
1235
1236 insert_adjustment (tr.transaction_header_id,
1237 x_global_source,
1238 x_je_infln_adjustment,
1239 x_ia_reserve_name,
1240 ra.debit_credit_flag,
1241 x_returned_ccid,
1242 p_tax_book,
1243 tr.asset_id,
1244 ra.adjustment_amount,
1245 ra.distribution_id,
1246 ra.annualized_adjustment,
1247 NULL,
1248 NULL,
1249 ra.period_counter_adjusted,
1250 ra.period_counter_created,
1251 ra.asset_invoice_id,
1252 NULL,
1253 NULL
1254 );
1255
1256 ELSIF (ra.adjustment_type = x_cip_cost_name) THEN
1257 x_global_source := 'CIP INFLN ADJST';
1258
1259 -----------------------------------------------------------------------------
1260 -- CIP cost inflation adjustments --
1261 -----------------------------------------------------------------------------
1262
1263 change_account (x_chart_of_accounts_id,
1264 x_apps_short_name,
1265 x_key_flex_code,
1266 x_account_segment,
1267 ra.code_combination_id,
1268 x_ia_cip_cost_segm,
1269 x_delimiter,
1270 x_returned_ccid,
1271 x_error_ccid
1272 );
1273
1274 insert_adjustment (tr.transaction_header_id,
1275 x_global_source,
1276 x_je_cip_infln_adjustment,
1277 x_ia_cip_cost_name,
1278 ra.debit_credit_flag,
1279 x_returned_ccid,
1280 p_tax_book,
1281 tr.asset_id,
1282 ra.adjustment_amount,
1283 ra.distribution_id,
1284 ra.annualized_adjustment,
1285 NULL,
1286 NULL,
1287 ra.period_counter_adjusted,
1288 ra.period_counter_created,
1289 ra.asset_invoice_id,
1290 NULL,
1291 NULL
1292 );
1293
1294 change_account (x_chart_of_accounts_id,
1295 x_apps_short_name,
1296 x_key_flex_code,
1297 x_account_segment,
1298 ra.code_combination_id,
1299 x_ix_cip_cost_segm,
1300 x_delimiter,
1301 x_returned_ccid,
1302 x_error_ccid
1303 );
1304
1305 insert_adjustment (tr.transaction_header_id,
1306 x_global_source,
1307 x_je_cip_infln_adjustment,
1308 x_ix_cip_cost_name,
1309 x_debit_credit_flag,
1310 x_returned_ccid,
1311 p_tax_book,
1312 tr.asset_id,
1313 ra.adjustment_amount,
1314 ra.distribution_id,
1315 ra.annualized_adjustment,
1316 NULL,
1317 NULL,
1318 ra.period_counter_adjusted,
1319 ra.period_counter_created,
1320 ra.asset_invoice_id,
1321 NULL,
1322 NULL
1323 );
1324 END IF;
1325 END LOOP;
1326
1327 -----------------------------------------------------------------------------
1328 -- ADDITION / ADJUSTMENT --
1329 -----------------------------------------------------------------------------
1330
1331 ELSIF tr.transaction_type_code IN ('ADDITION',
1332 'CIP ADDITION',
1333 'ADJUSTMENT',
1334 'CIP ADJUSTMENT'
1335 ) THEN
1336
1337 IF (tr.transaction_type_code = 'ADDITION') THEN
1338 x_global_source := 'IA ADDITION';
1339 x_je_category_name := x_je_ia_addition;
1340 x_je_std_category_name := x_je_ia_addition;
1341 x_temporal := x_addition_flag;
1342
1343 ELSIF (tr.transaction_type_code = 'CIP ADDITION') THEN
1344 x_global_source := 'IA CIP ADDITION';
1345 x_je_category_name := x_je_ia_cip_addition;
1346 x_je_std_category_name := x_je_ia_cip_addition;
1347 x_temporal := x_addition_flag;
1348
1349 ELSIF (tr.transaction_type_code = 'ADJUSTMENT') THEN
1350 x_global_source := 'IA ADJUSTMENT';
1351 x_je_category_name := x_je_ia_adjustment;
1352 x_je_std_category_name := x_je_ia_adjustment;
1353 x_temporal := x_adjustment_flag;
1354
1355 ELSIF (tr.transaction_type_code = 'CIP ADJUSTMENT') THEN
1356 x_global_source := 'IA CIP ADJUST';
1357 x_je_category_name := x_je_ia_cip_adjustment;
1358 x_je_std_category_name := x_je_ia_cip_adjustment;
1359 x_temporal := x_adjustment_flag;
1360
1361 END IF;
1362
1363 -----------------------------------------------------------------------------
1364 -- Looking for ADDITION / ADJUSTMENT transactions in Corporate book --
1365 -- when Source_Transaction_Header_Id is NULL. --
1366 -----------------------------------------------------------------------------
1367
1368 IF (x_temporal = TRUE) THEN
1369 IF (tr.source_transaction_header_id IS NULL) THEN
1370 IF tr.transaction_type_code IN ('ADDITION',
1371 'ADJUSTMENT'
1372 ) THEN
1373
1374 -----------------------------------------------------------------------------
1375 -- Adjustments to Depreciation Reserve --
1376 -----------------------------------------------------------------------------
1377
1378 OPEN c_sum_all_adjustments (tr.asset_id,
1379 p_tax_book,
1380 x_period_counter,
1381 x_reserve_name,
1382 'DR'
1383 );
1384 FETCH c_sum_all_adjustments INTO x_value_1;
1385 CLOSE c_sum_all_adjustments;
1386
1387 OPEN c_sum_all_adjustments (tr.asset_id,
1388 x_corporate_book,
1389 x_period_counter,
1390 x_reserve_name,
1391 'DR'
1392 );
1393 FETCH c_sum_all_adjustments INTO x_value_2;
1394 IF (c_sum_all_adjustments%FOUND = FALSE) THEN
1395 x_value_2 := 0;
1396 END IF;
1397 CLOSE c_sum_all_adjustments;
1398
1399 OPEN c_sum_adjustments (tr.asset_id,
1400 p_tax_book,
1401 tr.transaction_header_id,
1402 x_reserve_name,
1403 'DR'
1404 );
1405 FETCH c_sum_adjustments INTO x_adjustment_amount;
1406 IF (c_sum_adjustments%FOUND = FALSE) THEN
1407 x_adjustment_amount := 0;
1408 END IF;
1409 CLOSE c_sum_adjustments;
1410
1411 IF x_adjustment_amount = 0 THEN
1412 x_reserve_dr := 0;
1413 ELSE
1414 x_reserve_dr := (x_value_1 - x_value_2) / x_adjustment_amount;
1415 END IF;
1416
1417 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1418 x_char := 'Value 1 = ' || to_char(x_value_1);
1419 fnd_file.put_line (FND_FILE.LOG, x_char);
1420 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
1421 x_char := 'Value 2= ' || to_char(x_value_2);
1422 fnd_file.put_line (FND_FILE.LOG, x_char);
1423 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
1424 x_char := 'x_adjustment = ' || to_char(x_adjustment_amount);
1425 fnd_file.put_line (FND_FILE.LOG, x_char);
1426 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
1427 x_char := 'x_reserve_dr = ' || to_char(x_reserve_dr);
1428 fnd_file.put_line (FND_FILE.LOG, x_char);
1429 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
1430 END IF;
1431
1432 OPEN c_sum_all_adjustments (tr.asset_id,
1433 p_tax_book,
1434 x_period_counter,
1435 x_reserve_name,
1436 'CR'
1437 );
1438 FETCH c_sum_all_adjustments INTO x_value_1;
1439 CLOSE c_sum_all_adjustments;
1440
1441 OPEN c_sum_all_adjustments (tr.asset_id,
1442 x_corporate_book,
1443 x_period_counter,
1444 x_reserve_name,
1445 'CR'
1446 );
1447 FETCH c_sum_all_adjustments INTO x_value_2;
1448 IF (c_sum_all_adjustments%FOUND = FALSE) THEN
1449 x_value_2 := 0;
1450 END IF;
1451 CLOSE c_sum_all_adjustments;
1452
1453 OPEN c_sum_adjustments (tr.asset_id,
1454 p_tax_book,
1455 tr.transaction_header_id,
1456 x_reserve_name,
1457 'CR'
1458 );
1459 FETCH c_sum_adjustments INTO x_adjustment_amount;
1460 IF (c_sum_adjustments%FOUND = FALSE) THEN
1461 x_adjustment_amount := 0;
1462 END IF;
1463 CLOSE c_sum_adjustments;
1464
1465 IF (x_adjustment_amount = 0) THEN
1466 x_reserve_cr := 0;
1467 ELSE
1468 x_reserve_cr := (x_value_1 - x_value_2) / x_adjustment_amount;
1469 END IF;
1470
1471 -----------------------------------------------------------------------------
1472 -- Adjustments to Depreciation Expense --
1473 -----------------------------------------------------------------------------
1474
1475 OPEN c_sum_all_adjustments (tr.asset_id,
1476 p_tax_book,
1477 x_period_counter,
1478 x_expense_name,
1479 'DR'
1480 );
1481 FETCH c_sum_all_adjustments INTO x_value_1;
1482 CLOSE c_sum_all_adjustments;
1483
1484 OPEN c_sum_all_adjustments (tr.asset_id,
1485 x_corporate_book,
1486 x_period_counter,
1487 x_expense_name,
1488 'DR'
1489 );
1490 FETCH c_sum_all_adjustments INTO x_value_2;
1491 IF (c_sum_all_adjustments%FOUND = FALSE) THEN
1492 x_value_2 := 0;
1493 END IF;
1494 CLOSE c_sum_all_adjustments;
1495
1496 OPEN c_sum_adjustments (tr.asset_id,
1497 p_tax_book,
1498 tr.transaction_header_id,
1499 x_expense_name,
1500 'DR'
1501 );
1502 FETCH c_sum_adjustments INTO x_adjustment_amount;
1503 IF (c_sum_adjustments%FOUND = FALSE) THEN
1504 x_adjustment_amount := 0;
1505 END IF;
1506 CLOSE c_sum_adjustments;
1507
1508 IF x_adjustment_amount = 0 THEN
1509 x_expense_dr := 0;
1510 ELSE
1511 x_expense_dr := (x_value_1 - x_value_2) / x_adjustment_amount;
1512 END IF;
1513
1514 OPEN c_sum_all_adjustments (tr.asset_id,
1515 p_tax_book,
1516 x_period_counter,
1517 x_expense_name,
1518 'CR'
1519 );
1520 FETCH c_sum_all_adjustments INTO x_value_1;
1521 CLOSE c_sum_all_adjustments;
1522
1523 OPEN c_sum_all_adjustments (tr.asset_id,
1524 x_corporate_book,
1525 x_period_counter,
1526 x_expense_name,
1527 'CR'
1528 );
1529 FETCH c_sum_all_adjustments INTO x_value_2;
1530 IF (c_sum_all_adjustments%FOUND = FALSE) THEN
1531 x_value_2 := 0;
1532 END IF;
1533 CLOSE c_sum_all_adjustments;
1534
1535 OPEN c_sum_adjustments (tr.asset_id,
1536 p_tax_book,
1537 tr.transaction_header_id,
1538 x_expense_name,
1539 'CR'
1540 );
1541 FETCH c_sum_adjustments INTO x_adjustment_amount;
1542 IF (c_sum_adjustments%FOUND = FALSE) THEN
1543 x_adjustment_amount := 0;
1544 END IF;
1545 CLOSE c_sum_adjustments;
1546
1547 IF (x_adjustment_amount = 0) THEN
1548 x_expense_cr := 0;
1549 ELSE
1550 x_expense_cr := (x_value_1 - x_value_2) / x_adjustment_amount;
1551 END IF;
1552
1553 x_account_name := x_cost_name;
1554 ELSE
1555 x_account_name := x_cip_cost_name;
1556 END IF;
1557
1558 -----------------------------------------------------------------------------
1559 -- Adjustments to Cost (Capitalized or CIP) --
1560 -----------------------------------------------------------------------------
1561
1562 OPEN c_sum_all_adjustments (tr.asset_id,
1563 p_tax_book,
1564 x_period_counter,
1565 x_account_name,
1566 'DR'
1567 );
1568 FETCH c_sum_all_adjustments INTO x_value_1;
1569 CLOSE c_sum_all_adjustments;
1570
1571 OPEN c_sum_all_adjustments (tr.asset_id,
1572 x_corporate_book,
1573 x_period_counter,
1574 x_account_name,
1575 'DR'
1576 );
1577 FETCH c_sum_all_adjustments INTO x_value_2;
1578 IF (c_sum_all_adjustments%FOUND = FALSE) THEN
1579 x_value_2 := 0;
1580 END IF;
1581 CLOSE c_sum_all_adjustments;
1582
1583 OPEN c_sum_adjustments (tr.asset_id,
1584 p_tax_book,
1585 tr.transaction_header_id,
1586 x_account_name,
1587 'DR'
1588 );
1589 FETCH c_sum_adjustments INTO x_adjustment_amount;
1590 IF (c_sum_adjustments%FOUND = FALSE) THEN
1591 x_adjustment_amount := 0;
1592 END IF;
1593 CLOSE c_sum_adjustments;
1594
1595 IF x_adjustment_amount = 0 THEN
1596 x_cost_dr := 0;
1597 ELSE
1598 x_cost_dr := (x_value_1 - x_value_2) / x_adjustment_amount;
1599 END IF;
1600
1601 OPEN c_sum_all_adjustments (tr.asset_id,
1602 p_tax_book,
1603 x_period_counter,
1604 x_account_name,
1605 'CR'
1606 );
1607 FETCH c_sum_all_adjustments INTO x_value_1;
1608 CLOSE c_sum_all_adjustments;
1609
1610 OPEN c_sum_all_adjustments (tr.asset_id,
1611 x_corporate_book,
1612 x_period_counter,
1613 x_account_name,
1614 'CR'
1615 );
1616 FETCH c_sum_all_adjustments INTO x_value_2;
1617 IF (c_sum_all_adjustments%FOUND = FALSE) THEN
1618 x_value_2 := 0;
1619 END IF;
1620 CLOSE c_sum_all_adjustments;
1621
1622 OPEN c_sum_adjustments (tr.asset_id,
1623 p_tax_book,
1624 tr.transaction_header_id,
1625 x_account_name,
1626 'CR'
1627 );
1628 FETCH c_sum_adjustments INTO x_adjustment_amount;
1629 IF (c_sum_adjustments%FOUND = FALSE) THEN
1630 x_adjustment_amount := 0;
1631 END IF;
1632 CLOSE c_sum_adjustments;
1633
1634 IF x_adjustment_amount = 0 THEN
1635 x_cost_cr := 0;
1636 ELSE
1637 x_cost_cr := (x_value_1 - x_value_2) / x_adjustment_amount;
1638 END IF;
1639
1640 IF (tr.transaction_type_code IN ('ADDITION',
1641 'CIP ADDITION')
1642 ) THEN
1643 x_addition_flag := FALSE;
1644 ELSE
1645 x_adjustment_flag := FALSE;
1646 END IF;
1647 END IF;
1648
1649 -----------------------------------------------------------------------------
1650 -- Retrieve adjustments generated by standard depreciation program --
1651 -----------------------------------------------------------------------------
1652
1653 FOR ra IN c_tr_adjustments_no_adj_type (tr.transaction_header_id,
1654 tr.book_type_code,
1655 x_period_counter
1656 ) LOOP
1657
1658 --FA SLA Changes.
1659 IF ra.code_combination_id is null then
1660 l_book_type_code := tr.book_type_code;
1661 RAISE e_ccid_not_found;
1662 END IF;
1663
1664
1665 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1666 x_char := 'Adjustment for Line = ' || to_char(ra.distribution_id) || ' ' || ra.adjustment_type;
1667 fnd_file.put_line (FND_FILE.LOG, x_char);
1668 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
1669 END IF;
1670
1671 IF (tr.source_transaction_header_id IS NULL) THEN
1672 IF (ra.adjustment_type IN (x_cost_name,
1673 x_cip_cost_name)
1674 ) THEN
1675 IF (ra.debit_credit_flag = 'DR') THEN
1676 x_adjustment_amount := round (ra.adjustment_amount * x_cost_dr, x_precision);
1677 ELSE
1678 x_adjustment_amount := round (ra.adjustment_amount * x_cost_cr, x_precision);
1679 END IF;
1680 ELSIF (ra.adjustment_type = x_reserve_name) THEN
1681 IF (ra.debit_credit_flag = 'DR') THEN
1682 x_adjustment_amount := round (ra.adjustment_amount * x_reserve_dr, x_precision);
1683 ELSE
1684 x_adjustment_amount := round (ra.adjustment_amount * x_reserve_cr, x_precision);
1685 END IF;
1686 ELSIF (ra.adjustment_type = x_expense_name) THEN
1687 IF (ra.debit_credit_flag = 'DR') THEN
1688
1689 x_adjustment_amount := round (ra.adjustment_amount * x_expense_dr, x_precision);
1690 ELSE
1691 x_adjustment_amount := round (ra.adjustment_amount * x_expense_cr, x_precision);
1692 END IF;
1693 END IF;
1694 ELSE
1695 OPEN c_tr_rel_adjustments (tr.source_transaction_header_id,
1696 x_corporate_book,
1697 ra.source_type_code,
1698 ra.adjustment_type,
1699 ra.debit_credit_flag,
1700 ra.distribution_id
1701 );
1702 FETCH c_tr_rel_adjustments INTO x_code_combination_id,
1703 x_adjustment_amount;
1704 IF (c_tr_rel_adjustments%FOUND = FALSE) THEN
1705 x_adjustment_amount := 0;
1706 END IF;
1707 CLOSE c_tr_rel_adjustments;
1708 x_adjustment_amount := round (ra.adjustment_amount - x_adjustment_amount, x_precision);
1709 END IF;
1710
1711 IF (ra.debit_credit_flag = 'DR') THEN
1712 x_debit_credit_flag := 'CR';
1713 ELSE
1714 x_debit_credit_flag := 'DR';
1715 END IF;
1716
1717 IF (ra.adjustment_type = x_cost_name) THEN
1718
1719 -----------------------------------------------------------------------------
1720 -- Cost inflation adjustments of the capitalized assets --
1721 -----------------------------------------------------------------------------
1722
1723 IF (tr.transaction_type_code = 'ADDITION'
1724 AND tr.period_counter_capitalized = x_period_counter
1725 AND tr.asset_type = 'CAPITALIZED'
1726 ) THEN
1727
1728 insert_adjustment (tr.transaction_header_id,
1729 x_global_source,
1730 x_je_category_name,
1731 x_cost_name,
1732 ra.debit_credit_flag,
1733 ra.code_combination_id,
1734 p_tax_book,
1735 tr.asset_id,
1736 x_adjustment_amount,
1737 ra.distribution_id,
1738 ra.annualized_adjustment,
1739 NULL,
1740 NULL,
1741 ra.period_counter_adjusted,
1742 ra.period_counter_created,
1743 ra.asset_invoice_id,
1744 NULL,
1745 NULL
1746 );
1747 ELSE
1748 change_account (x_chart_of_accounts_id,
1749 x_apps_short_name,
1750 x_key_flex_code,
1751 x_account_segment,
1752 ra.code_combination_id,
1753 x_ia_cost_segm,
1754 x_delimiter,
1755 x_returned_ccid,
1756 x_error_ccid
1757 );
1758
1759 insert_adjustment (tr.transaction_header_id,
1760 x_global_source,
1761 x_je_category_name,
1762 x_ia_cost_name,
1763 ra.debit_credit_flag,
1764 x_returned_ccid,
1765 p_tax_book,
1766 tr.asset_id,
1767 x_adjustment_amount,
1768 ra.distribution_id,
1769 ra.annualized_adjustment,
1770 NULL,
1771 NULL,
1772 ra.period_counter_adjusted,
1773 ra.period_counter_created,
1774 ra.asset_invoice_id,
1775 NULL,
1776 NULL
1777 );
1778
1779 change_account ( x_chart_of_accounts_id,
1780 x_apps_short_name,
1781 x_key_flex_code,
1782 x_account_segment,
1783 ra.code_combination_id,
1784 x_ix_cost_segm,
1785 x_delimiter,
1786 x_returned_ccid,
1787 x_error_ccid
1788 );
1789
1790 insert_adjustment (tr.transaction_header_id,
1791 x_global_source,
1792 x_je_category_name,
1793 x_ix_cost_name,
1794 x_debit_credit_flag,
1795 x_returned_ccid,
1796 p_tax_book,
1797 tr.asset_id,
1798 x_adjustment_amount,
1799 ra.distribution_id,
1800 ra.annualized_adjustment,
1801 NULL,
1802 NULL,
1803 ra.period_counter_adjusted,
1804 ra.period_counter_created,
1805 ra.asset_invoice_id,
1806 NULL,
1807 NULL
1808 );
1809 END IF;
1810
1811 ELSIF (ra.adjustment_type = x_expense_name) THEN
1812
1813 -----------------------------------------------------------------------------
1814 -- Depreciation to cost inflation adjustments of the capitalized assets --
1815 -----------------------------------------------------------------------------
1816
1817 x_deprn_to_cost := x_deprn_to_cost + x_adjustment_amount;
1818
1819 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
1820 x_char := 'x_deprn_to_cost A = ' || to_char(x_deprn_to_cost);
1821 fnd_file.put_line (FND_FILE.LOG, x_char);
1822 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
1823 END IF;
1824
1825 insert_adjustment (tr.transaction_header_id,
1826 'DEPRECIATION',
1827 x_je_depreciation,
1828 x_expense_name,
1829 ra.debit_credit_flag,
1830 ra.code_combination_id,
1831 p_tax_book,
1832 tr.asset_id,
1833 x_adjustment_amount,
1834 ra.distribution_id,
1835 ra.annualized_adjustment,
1836 NULL,
1837 NULL,
1838 x_period_counter,
1839 x_period_counter,
1840 ra.asset_invoice_id,
1841 NULL,
1842 NULL
1843 );
1844
1845 fa_gccid_pkg.fafbgcc_proc (p_tax_book,
1846 'DEPRN_RESERVE_ACCT',
1847 ra.code_combination_id,
1848 x_deprn_reserve_segm,
1849 x_deprn_reserve_ccid,
1850 ra.distribution_id,
1851 x_returned_ccid,
1852 x_concat_segs,
1853 x_return_value
1854 );
1855
1856 IF (x_return_value = 0) then
1857 fnd_message.set_name ('JL', 'JL_CO_FA_CCID_NOT_CREATED');
1858 fnd_message.set_token ('ACCOUNT', x_concat_segs);
1859 --Bug 2929483. Missing log message handling has been added.
1860 fnd_file.put_line (FND_FILE.LOG, fnd_message.get);
1861 x_error_ccid := TRUE;
1862 ELSE
1863 insert_adjustment (tr.transaction_header_id,
1864 'DEPRECIATION',
1865 x_je_depreciation,
1866 x_reserve_name,
1867 x_debit_credit_flag,
1868 x_returned_ccid,
1869 p_tax_book,
1870 tr.asset_id,
1871 x_adjustment_amount,
1872 ra.distribution_id,
1873 ra.annualized_adjustment,
1874 NULL,
1875 NULL,
1876 x_period_counter,
1877 x_period_counter,
1878 ra.asset_invoice_id,
1879 NULL,
1880 NULL
1881 );
1882 END IF;
1883
1884 ELSIF (ra.adjustment_type = x_reserve_name) THEN
1885
1886 -----------------------------------------------------------------------------
1887 -- Depreciation reserve inflation adjustments --
1888 -----------------------------------------------------------------------------
1889
1890 change_account (x_chart_of_accounts_id,
1891 x_apps_short_name,
1892 x_key_flex_code,
1893 x_account_segment,
1894 ra.code_combination_id,
1895 x_ix_deprn_reserve_segm,
1896 x_delimiter,
1897 x_returned_ccid,
1898 x_error_ccid
1899 );
1900
1901 insert_adjustment (tr.transaction_header_id,
1902 x_global_source,
1903 x_je_category_name,
1904 x_ix_reserve_name,
1905 x_debit_credit_flag,
1906 x_returned_ccid,
1907 p_tax_book,
1908 tr.asset_id,
1909 x_adjustment_amount,
1910 ra.distribution_id,
1911 ra.annualized_adjustment,
1912 NULL,
1913 NULL,
1914 ra.period_counter_adjusted,
1915 ra.period_counter_created,
1916 ra.asset_invoice_id,
1917 NULL,
1918 NULL
1919 );
1920
1921 change_account (x_chart_of_accounts_id,
1922 x_apps_short_name,
1923 x_key_flex_code,
1924 x_account_segment,
1925 ra.code_combination_id,
1926 x_ia_deprn_reserve_segm,
1927 x_delimiter,
1928 x_returned_ccid,
1929 x_error_ccid
1930 );
1931
1932 insert_adjustment (tr.transaction_header_id,
1933 x_global_source,
1934 x_je_category_name,
1935 x_ia_reserve_name,
1936 ra.debit_credit_flag,
1937 x_returned_ccid,
1938 p_tax_book,
1939 tr.asset_id,
1940 x_adjustment_amount,
1941 ra.distribution_id,
1942 ra.annualized_adjustment,
1943 NULL,
1944 NULL,
1945 ra.period_counter_adjusted,
1946 ra.period_counter_created,
1947 ra.asset_invoice_id,
1948 NULL,
1949 NULL
1950 );
1951
1952 ELSIF (ra.adjustment_type = x_cip_cost_name) THEN
1953
1954 -----------------------------------------------------------------------------
1955 -- Cost inflation adjustments to the CIP assets --
1956 -----------------------------------------------------------------------------
1957
1958 change_account (x_chart_of_accounts_id,
1959 x_apps_short_name,
1960 x_key_flex_code,
1961 x_account_segment,
1962 ra.code_combination_id,
1963 x_ia_cip_cost_segm,
1964 x_delimiter,
1965 x_returned_ccid,
1966 x_error_ccid
1967 );
1968
1969 insert_adjustment (tr.transaction_header_id,
1970 x_global_source,
1971 x_je_category_name,
1972 x_ia_cip_cost_name,
1973 ra.debit_credit_flag,
1974 x_returned_ccid,
1975 p_tax_book,
1976 tr.asset_id,
1977 x_adjustment_amount,
1978 ra.distribution_id,
1979 ra.annualized_adjustment,
1980 NULL,
1981 NULL,
1982 ra.period_counter_adjusted,
1983 ra.period_counter_created,
1984 ra.asset_invoice_id,
1985 NULL,
1986 NULL
1987 );
1988
1989 IF (tr.transaction_type_code <> 'ADDITION'
1990 OR tr.period_counter_capitalized <> x_period_counter
1991 OR tr.asset_type <> 'CAPITALIZED'
1992 ) THEN
1993
1994 change_account ( x_chart_of_accounts_id,
1995 x_apps_short_name,
1996 x_key_flex_code,
1997 x_account_segment,
1998 ra.code_combination_id,
1999 x_ix_cip_cost_segm,
2000 x_delimiter,
2001 x_returned_ccid,
2002 x_error_ccid
2003 );
2004
2005 insert_adjustment (tr.transaction_header_id,
2006 x_global_source,
2007 x_je_category_name,
2008 x_ix_cip_cost_name,
2009 x_debit_credit_flag,
2010 x_returned_ccid,
2011 p_tax_book,
2012 tr.asset_id,
2013 x_adjustment_amount,
2014 ra.distribution_id,
2015 ra.annualized_adjustment,
2016 NULL,
2017 NULL,
2018 ra.period_counter_adjusted,
2019 ra.period_counter_created,
2020 ra.asset_invoice_id,
2021 NULL,
2022 NULL
2023 );
2024 END IF;
2025 END IF;
2026 END LOOP;
2027 END IF;
2028
2029 -----------------------------------------------------------------------------
2030 -- RECLASSIFICATION / TRANSFER / UNIT ADJUSTMENT --
2031 -----------------------------------------------------------------------------
2032
2033 ELSIF tr.transaction_type_code IN ('RECLASS',
2034 'CIP RECLASS',
2035 'TRANSFER',
2036 'CIP TRANSFER',
2037 'UNIT ADJUSTMENT'
2038 ) THEN
2039
2040 IF (tr.transaction_type_code = 'RECLASS') THEN
2041 x_global_source := 'IA RECLASS';
2042 x_je_category_name := x_je_ia_reclass;
2043 x_je_std_category_name := x_je_ia_reclass;
2044
2045 ELSIF (tr.transaction_type_code = 'CIP RECLASS') THEN
2046 x_global_source := 'IA CIP RECLASS';
2047 x_je_category_name := x_je_ia_cip_reclass;
2048 x_je_std_category_name := x_je_ia_cip_reclass;
2049
2050 ELSIF (tr.transaction_type_code = 'TRANSFER') THEN
2051 x_global_source := 'IA TRANSFER';
2052 x_je_category_name := x_je_ia_transfer;
2053 x_je_std_category_name := x_je_ia_transfer;
2054
2055 ELSIF (tr.transaction_type_code = 'CIP TRANSFER') THEN
2056 x_global_source := 'IA CIP TRANSFER';
2057 x_je_category_name := x_je_ia_cip_transfer;
2058 x_je_std_category_name := x_je_ia_cip_transfer;
2059
2060 ELSIF (tr.transaction_type_code = 'UNIT ADJUSTMENT') THEN
2061 IF (tr.asset_type = 'CAPITALIZED') THEN
2062 x_global_source := 'IA TRANSFER';
2063 x_je_category_name := x_je_ia_transfer;
2064 x_je_std_category_name := x_je_ia_transfer;
2065
2066 ELSIF (tr.asset_type = 'CIP') THEN
2067 x_global_source := 'IA CIP TRANSFER';
2068 x_je_category_name := x_je_ia_cip_transfer;
2069 x_je_std_category_name := x_je_ia_cip_transfer;
2070 END IF;
2071
2072 END IF;
2073
2074 -----------------------------------------------------------------------------
2075 -- Get historical and adjusted values to reserve inflation adjustments --
2076 -----------------------------------------------------------------------------
2077
2078 OPEN c_deprn_summary (x_corporate_book,
2079 tr.asset_id,
2080 x_period_counter - 1
2081 );
2082 FETCH c_deprn_summary INTO x_corp_deprn_reserve,
2083 x_corp_reval_reserve,
2084 x_corp_reval_deprn_expense;
2085 CLOSE c_deprn_summary;
2086
2087 OPEN c_deprn_summary (p_tax_book,
2088 tr.asset_id,
2089 x_period_counter - 1
2090 );
2091 FETCH c_deprn_summary INTO x_adj_deprn_reserve,
2092 x_adj_reval_reserve,
2093 x_adj_reval_deprn_expense;
2094 CLOSE c_deprn_summary;
2095
2096 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2097 x_char := 'Corp Reserve = ' || to_char(x_corp_deprn_reserve);
2098 fnd_file.put_line (FND_FILE.LOG, x_char);
2099 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2100 x_char := 'Adj Reserve = ' || to_char(x_adj_deprn_reserve);
2101 fnd_file.put_line (FND_FILE.LOG, x_char);
2102 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2103 END IF;
2104
2105 OPEN c_sum_adjustments (tr.asset_id,
2106 x_corporate_book,
2107 tr.transaction_header_id,
2108 x_reserve_name,
2109 'DR'
2110 );
2111 FETCH c_sum_adjustments INTO x_adjustment_amount;
2112 CLOSE c_sum_adjustments;
2113
2114 OPEN c_sum_adjustments (tr.asset_id,
2115 p_tax_book,
2116 tr.transaction_header_id,
2117 x_reserve_name,
2118 'DR'
2119 );
2120 FETCH c_sum_adjustments INTO x_adj_cost;
2121 CLOSE c_sum_adjustments;
2122
2123 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2124 x_char := 'Sum Corp Reserve = ' || to_char(x_adjustment_amount);
2125 fnd_file.put_line (FND_FILE.LOG, x_char);
2126 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2127 x_char := 'Sum Adj Reserve = ' || to_char(x_adj_cost);
2128 fnd_file.put_line (FND_FILE.LOG, x_char);
2129 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2130 END IF;
2131
2132 x_adjustment_amount := x_adj_cost - x_adjustment_amount;
2133
2134 -- The 0% revaluation :
2135 -- In this case, accum. deprn in both corp and tax books at the beginning
2136 -- of the period is same. The deprn to IA Cost at the beginning of the period
2137 -- may or may not be zero.
2138 -- Now, if the revaluation is non zero in the current period, we still don't
2139 -- have the basis to calculate x_factor_1 because (x_adj_deprn_reserve - x_corp_
2140 -- deprn_reserve) = 0. In this scenario, adjusted accum deprn should be equal to
2141 -- IA to accum. depr and the deprn to IA cost = 0.
2142 -- This in turn, means x_factor_11 = 0 and x_factor_12 = 1.
2143
2144 IF (x_adj_deprn_reserve = x_corp_deprn_reserve) THEN
2145 x_factor_1 := 0;
2146 ELSE
2147 x_factor_1 := x_adjustment_amount / (x_adj_deprn_reserve - x_corp_deprn_reserve);
2148 END IF;
2149
2150 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2151 x_char := 'x_adjustment_amount = ' || to_char(x_adjustment_amount);
2152 fnd_file.put_line (FND_FILE.LOG, x_char);
2153 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2154 x_char := 'Factor_1 = ' || to_char(x_factor_1);
2155 fnd_file.put_line (FND_FILE.LOG, x_char);
2156 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2157 END IF;
2158
2159 IF ((x_adj_cost <> 0) AND (x_adjustment_amount <> 0)) THEN
2160 x_factor_12 := x_deprn_to_cost * x_factor_1;
2161
2162 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2163 x_char := 'Factor_12 = ' || to_char(x_factor_12);
2164 fnd_file.put_line (FND_FILE.LOG, x_char);
2165 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2166 END IF;
2167
2168 x_factor_11 := x_factor_12 / x_adjustment_amount;
2169 x_factor_12 := (x_adjustment_amount - x_factor_12) / x_adjustment_amount;
2170 ELSE
2171 x_factor_11 := 0;
2172 x_factor_12 := 0;
2173 END IF;
2174
2175 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2176 x_char := 'Factor_11 = ' || to_char(x_factor_11);
2177 fnd_file.put_line (FND_FILE.LOG, x_char);
2178 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2179 x_char := 'Factor_12 = ' || to_char(x_factor_12);
2180 fnd_file.put_line (FND_FILE.LOG, x_char);
2181 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2182 END IF;
2183
2184 --x_ta_factor := abs (tr.appraisal_balance) / tr.adj_cost;
2185
2186 ----------------------------------------------------------------------------
2187 --BUG 3865352
2188 ----------------------------------------------------------------------------
2189 IF tr.adj_cost = 0 THEN
2190 x_ta_factor := 0;
2191 ELSE
2192 x_ta_factor := abs (tr.appraisal_balance) / tr.adj_cost;
2193 END IF;
2194
2195
2196
2197 -----------------------------------------------------------------------------
2198 -- For Reclassifications, get the account of the prior asset category --
2199 -- LER, 18-Jun-99 CCIDs are not more stered in FA_BOOKS_CONTROLS.GDF --
2200 -- now are only stored the natural accouns --
2201 -----------------------------------------------------------------------------
2202
2203 IF tr.transaction_type_code IN ('RECLASS',
2204 'CIP RECLASS'
2205 ) THEN
2206
2207 OPEN c_prior_category (tr.asset_id,
2208 tr.transaction_header_id
2209 );
2210 FETCH c_prior_category INTO x_prior_category_id;
2211 CLOSE c_prior_category;
2212
2213 IF (x_prior_category_id <> x_old_category_id) THEN
2214 x_old_category_id := x_prior_category_id;
2215
2216 OPEN c_accounts (x_prior_category_id,
2217 p_tax_book
2218 ) ;
2219 -- FETCH c_accounts INTO x_old_deprn_reserve_ccid,
2220 -- x_old_deprn_reserve_segm,
2221 -- x_old_ia_cost_ccid,
2222 -- x_old_ix_cost_ccid,
2223 -- x_old_ia_deprn_reserve_ccid,
2224 -- x_old_ix_deprn_reserve_ccid,
2225 -- x_old_ia_cip_cost_ccid,
2226 -- x_old_ia_cip_cost_ccid,
2227 -- x_old_ta_revaluation_ccid,
2228 -- x_old_ta_surplus_ccid,
2229 -- x_old_ta_reserve_ccid,
2230 -- x_old_ta_reserve_expense_ccid,
2231 -- x_old_ta_reserve_recovery_ccid ;
2232 FETCH c_accounts INTO x_old_deprn_reserve_ccid,
2233 x_old_deprn_reserve_segm,
2234 x_old_ia_cost_segm,
2235 x_old_ix_cost_segm,
2236 x_old_ia_deprn_reserve_segm,
2237 x_old_ix_deprn_reserve_segm,
2238 x_old_ia_cip_cost_segm,
2239 x_old_ia_cip_cost_segm,
2240 x_old_ta_revaluation_segm,
2241 x_old_ta_surplus_segm,
2242 x_old_ta_reserve_segm,
2243 x_old_ta_reserve_expense_segm,
2244 x_old_ta_reserve_recovery_segm ;
2245 CLOSE c_accounts;
2246
2247 -- extract_account (x_chart_of_accounts_id,
2248 -- x_apps_short_name,
2249 -- x_key_flex_code,
2250 -- x_account_segment,
2251 -- x_old_ia_cost_ccid,
2252 -- x_old_ia_cost_segm
2253 -- );
2254 -- extract_account (x_chart_of_accounts_id,
2255 -- x_apps_short_name,
2256 -- x_key_flex_code,
2257 -- x_account_segment,
2258 -- x_old_ia_deprn_reserve_ccid,
2259 -- x_old_ia_deprn_reserve_segm
2260 -- );
2261 -- extract_account (x_chart_of_accounts_id,
2262 -- x_apps_short_name,
2263 -- x_key_flex_code,
2264 -- x_account_segment,
2265 -- x_old_ia_cip_cost_ccid,
2266 -- x_old_ia_cip_cost_segm
2267 -- );
2268 -- extract_account (x_chart_of_accounts_id,
2269 -- x_apps_short_name,
2270 -- x_key_flex_code,
2271 -- x_account_segment,
2272 -- x_old_ta_revaluation_ccid,
2273 -- x_old_ta_revaluation_segm
2274 -- );
2275 -- extract_account (x_chart_of_accounts_id,
2276 -- x_apps_short_name,
2277 -- x_key_flex_code,
2278 -- x_account_segment,
2279 -- x_old_ta_surplus_ccid,
2280 -- x_old_ta_surplus_segm
2281 -- );
2282 -- extract_account (x_chart_of_accounts_id,
2283 -- x_apps_short_name,
2284 -- x_key_flex_code,
2285 -- x_account_segment,
2286 -- x_old_ta_reserve_ccid,
2287 -- x_old_ta_reserve_segm
2288 -- );
2289 END IF;
2290 END IF;
2291
2292 -----------------------------------------------------------------------------
2293 -- Loop for related rows in FA_ADJUSTMENTS for the transaction --
2294 -----------------------------------------------------------------------------
2295
2296 FOR ra IN c_tr_adjustments_no_adj_type (tr.transaction_header_id,
2297 tr.book_type_code,
2298 x_period_counter
2299 ) LOOP
2300
2301
2302 --FA SLA Changes.
2303 IF ra.code_combination_id is null then
2304 l_book_type_code := tr.book_type_code;
2305 RAISE e_ccid_not_found;
2306 END IF;
2307
2308
2309
2310 OPEN c_tr_rel_adjustments (tr.transaction_header_id,
2311 p_tax_book,
2312 ra.source_type_code,
2313 ra.adjustment_type,
2314 ra.debit_credit_flag,
2315 ra.distribution_id
2316 );
2317
2318 FETCH c_tr_rel_adjustments INTO x_code_combination_id,
2319 x_adjustment_amount;
2320
2321 IF (c_tr_rel_adjustments%FOUND = TRUE) THEN
2322 x_adj_cost_line := x_adjustment_amount;
2323 x_adjustment_amount := x_adjustment_amount - ra.adjustment_amount ;
2324 END IF;
2325 IF (c_tr_rel_adjustments%FOUND = FALSE) THEN
2326 x_adjustment_amount := 0;
2327 END IF;
2328 CLOSE c_tr_rel_adjustments;
2329
2330 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2331 x_char := ra.adjustment_type || ' ' || ra.debit_credit_flag || ' ' || to_char(x_adjustment_amount);
2332 fnd_file.put_line (FND_FILE.LOG, x_char);
2333 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2334 END IF;
2335
2336 IF (ra.debit_credit_flag = 'DR') THEN
2337 x_debit_credit_flag := 'CR';
2338 ELSE
2339 x_debit_credit_flag := 'DR';
2340 END IF;
2341
2342 IF (ra.adjustment_type = x_cost_name) THEN
2343
2344 -----------------------------------------------------------------------------
2345 -- Capitalized cost inflation adjustments --
2346 -----------------------------------------------------------------------------
2347
2348 IF (tr.transaction_type_code = 'RECLASS'
2349 AND ra.debit_credit_flag = 'CR' ) THEN
2350 x_natural_account := x_old_ia_cost_segm;
2351 ELSE
2352 x_natural_account := x_ia_cost_segm;
2353 END IF;
2354
2355 change_account (x_chart_of_accounts_id,
2356 x_apps_short_name,
2357 x_key_flex_code,
2358 x_account_segment,
2359 ra.code_combination_id,
2360 x_natural_account,
2361 x_delimiter,
2362 x_returned_ccid,
2363 x_error_ccid
2364 );
2365
2366 insert_adjustment (tr.transaction_header_id,
2367 x_global_source,
2368 x_je_category_name,
2369 x_ia_cost_name,
2370 ra.debit_credit_flag,
2371 x_returned_ccid,
2372 p_tax_book,
2373 tr.asset_id,
2374 x_adjustment_amount,
2375 ra.distribution_id,
2376 ra.annualized_adjustment,
2377 NULL,
2378 NULL,
2379 ra.period_counter_adjusted,
2380 ra.period_counter_created,
2381 ra.asset_invoice_id,
2382 NULL,
2383 NULL
2384 );
2385
2386 ELSIF (ra.adjustment_type = x_reserve_name) THEN
2387
2388 -----------------------------------------------------------------------------
2389 -- Depreciation reserve inflation adjustments --
2390 -----------------------------------------------------------------------------
2391
2392 x_value_1 := round (x_adjustment_amount * x_factor_11, x_precision);
2393 x_value_2 := round (x_adjustment_amount * x_factor_12, x_precision);
2394
2395 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2396 x_char := 'x_value_1 = ' || to_char(x_value_1);
2397 fnd_file.put_line (FND_FILE.LOG, x_char);
2398 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2399 x_char := 'x_value_2 = ' || to_char(x_value_2);
2400 fnd_file.put_line (FND_FILE.LOG, x_char);
2401 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2402 END IF;
2403
2404 insert_adjustment (tr.transaction_header_id,
2405 x_global_source,
2406 x_je_std_category_name,
2407 x_reserve_name,
2408 ra.debit_credit_flag,
2409 ra.code_combination_id,
2410 p_tax_book,
2411 tr.asset_id,
2412 x_value_1,
2413 ra.distribution_id,
2414 ra.annualized_adjustment,
2415 NULL,
2416 NULL,
2417 ra.period_counter_adjusted,
2418 ra.period_counter_created,
2419 ra.asset_invoice_id,
2420 NULL,
2421 NULL
2422 );
2423
2424 IF (tr.transaction_type_code = 'RECLASS'
2425 AND ra.debit_credit_flag = 'DR' ) THEN
2426 x_natural_account := x_old_ia_deprn_reserve_segm;
2427 ELSE
2428 x_natural_account := x_ia_deprn_reserve_segm;
2429 END IF;
2430
2431 change_account (x_chart_of_accounts_id,
2432 x_apps_short_name,
2433 x_key_flex_code,
2434 x_account_segment,
2435 ra.code_combination_id,
2436 x_natural_account,
2437 x_delimiter,
2438 x_returned_ccid,
2439 x_error_ccid
2440 );
2441
2442 insert_adjustment (tr.transaction_header_id,
2443 x_global_source,
2444 x_je_category_name,
2445 x_ia_reserve_name,
2446 ra.debit_credit_flag,
2447 x_returned_ccid,
2448 p_tax_book,
2449 tr.asset_id,
2450 x_value_2,
2451 ra.distribution_id,
2452 ra.annualized_adjustment,
2453 NULL,
2454 NULL,
2455 ra.period_counter_adjusted,
2456 ra.period_counter_created,
2457 ra.asset_invoice_id,
2458 NULL,
2459 NULL
2460 );
2461
2462 ELSIF (ra.adjustment_type = x_expense_name) THEN
2463
2464 -----------------------------------------------------------------------------
2465 -- Calculate the adjustments to depreciation expense due to transaction --
2466 -----------------------------------------------------------------------------
2467
2468 insert_adjustment (tr.transaction_header_id,
2469 'DEPRECIATION',
2470 x_je_depreciation,
2471 x_expense_name,
2472 ra.debit_credit_flag,
2473 ra.code_combination_id,
2474 p_tax_book,
2475 tr.asset_id,
2476 x_adjustment_amount,
2477 ra.distribution_id,
2478 ra.annualized_adjustment,
2479 NULL,
2480 NULL,
2481 x_period_counter,
2482 x_period_counter,
2483 ra.asset_invoice_id,
2484 NULL,
2485 NULL
2486 );
2487
2488 -----------------------------------------------------------------------------
2489 -- LER, 18-Jun-99 The following section was cancelled because the --
2490 -- reserve was completely transferred in previous --
2491 -- section. --
2492 -----------------------------------------------------------------------------
2493
2494 -- fa_gccid_pkg.fafbgcc_proc (p_tax_book,
2495 -- 'DEPRN_RESERVE_ACCT',
2496 -- ra.code_combination_id,
2497 -- x_deprn_reserve_segm,
2498 -- x_deprn_reserve_ccid,
2499 -- ra.distribution_id,
2500 -- x_returned_ccid,
2501 -- x_concat_segs,
2502 -- x_return_value
2503 -- );
2504
2505 -- IF (x_return_value = 0) then
2506 -- fnd_message.set_name ('JL', 'JL_CO_FA_CCID_NOT_CREATED');
2507 -- fnd_message.set_token ('ACCOUNT', x_concat_segs);
2508 -- x_error_ccid := TRUE;
2509
2510 -- ELSE
2511 -- insert_adjustment (tr.transaction_header_id,
2512 -- 'DEPRECIATION',
2513 -- x_je_depreciation,
2514 -- x_reserve_name,
2515 -- x_debit_credit_flag,
2516 -- x_returned_ccid,
2517 -- p_tax_book,
2518 -- tr.asset_id,
2519 -- x_adjustment_amount,
2520 -- ra.distribution_id,
2521 -- ra.annualized_adjustment,
2522 -- NULL,
2523 -- NULL,
2524 -- x_period_counter,
2525 -- x_period_counter,
2526 -- ra.asset_invoice_id,
2527 -- NULL,
2528 -- NULL
2529 -- );
2530 -- END IF;
2531
2532 ELSIF (ra.adjustment_type = x_cip_cost_name) THEN
2533
2534 -----------------------------------------------------------------------------
2535 -- CIP cost inflation adjustments --
2536 -----------------------------------------------------------------------------
2537
2538 IF (tr.transaction_type_code = 'CIP RECLASS'
2539 AND ra.debit_credit_flag = 'CR' ) THEN
2540 x_natural_account := x_old_ia_cip_cost_segm;
2541 ELSE
2542 x_natural_account := x_ia_cip_cost_segm;
2543 END IF;
2544
2545 change_account (x_chart_of_accounts_id,
2546 x_apps_short_name,
2547 x_key_flex_code,
2548 x_account_segment,
2549 ra.code_combination_id,
2550 x_natural_account,
2551 x_delimiter,
2552 x_returned_ccid,
2553 x_error_ccid
2554 );
2555
2556 insert_adjustment (tr.transaction_header_id,
2557 x_global_source,
2558 x_je_category_name,
2559 x_ia_cip_cost_name,
2560 ra.debit_credit_flag,
2561 x_returned_ccid,
2562 p_tax_book,
2563 tr.asset_id,
2564 x_adjustment_amount,
2565 ra.distribution_id,
2566 ra.annualized_adjustment,
2567 NULL,
2568 NULL,
2569 ra.period_counter_adjusted,
2570 ra.period_counter_created,
2571 ra.asset_invoice_id,
2572 NULL,
2573 NULL
2574 );
2575 END IF;
2576
2577 -----------------------------------------------------------------------------
2578 -- Transferring Technical Appraisal Account Balances --
2579 -----------------------------------------------------------------------------
2580
2581 IF ra.adjustment_type IN (x_cost_name,
2582 x_cip_cost_name)
2583 THEN
2584
2585 x_ta_line_amount := round (x_adj_cost_line * x_ta_factor, x_precision);
2586
2587 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2588 x_char := 'Appraisal Line Amount = ' || to_char (x_ta_line_amount);
2589 fnd_file.put_line (FND_FILE.LOG, x_char);
2590 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2591 END IF;
2592
2593 IF (tr.appraisal_balance > 0) THEN
2594 IF (tr.transaction_type_code IN ('RECLASS', 'CIP RECLASS')
2595 AND ra.debit_credit_flag = 'CR' ) THEN
2596 x_natural_account := x_old_ta_revaluation_segm;
2597 x_natural_account1 := x_old_ta_surplus_segm;
2598 ELSE
2599 x_natural_account := x_ta_revaluation_segm;
2600 x_natural_account1 := x_ta_surplus_segm;
2601 END IF;
2602
2603 change_account (x_chart_of_accounts_id,
2604 x_apps_short_name,
2605 x_key_flex_code,
2606 x_account_segment,
2607 ra.code_combination_id,
2608 x_natural_account,
2609 x_delimiter,
2610 x_returned_ccid,
2611 x_error_ccid
2612 );
2613
2614 insert_adjustment (tr.transaction_header_id,
2615 x_global_appraisal,
2616 x_je_appraisal,
2617 x_ta_revaluation_name,
2618 ra.debit_credit_flag,
2619 x_returned_ccid,
2620 p_tax_book,
2621 tr.asset_id,
2622 x_ta_line_amount,
2623 ra.distribution_id,
2624 NULL,
2625 NULL,
2626 NULL,
2627 ra.period_counter_adjusted,
2628 ra.period_counter_created,
2629 NULL,
2630 NULL,
2631 NULL
2632 );
2633
2634 change_account (x_chart_of_accounts_id,
2635 x_apps_short_name,
2636 x_key_flex_code,
2637 x_account_segment,
2638 ra.code_combination_id,
2639 x_natural_account1,
2640 x_delimiter,
2641 x_returned_ccid,
2642 x_error_ccid
2643 );
2644
2645 insert_adjustment (tr.transaction_header_id,
2646 x_global_appraisal,
2647 x_je_appraisal,
2648 x_ta_surplus_name,
2649 x_debit_credit_flag,
2650 x_returned_ccid,
2651 p_tax_book,
2652 tr.asset_id,
2653 x_ta_line_amount,
2654 ra.distribution_id,
2655 NULL,
2656 NULL,
2657 NULL,
2658 ra.period_counter_adjusted,
2659 ra.period_counter_created,
2660 NULL,
2661 NULL,
2662 NULL
2663 );
2664
2665 ELSIF (tr.appraisal_balance < 0) THEN
2666
2667 IF (tr.transaction_type_code IN ('RECLASS', 'CIP RECLASS')
2668 AND ra.debit_credit_flag = 'CR' ) THEN
2669 x_natural_account := x_old_ta_reserve_segm;
2670 ELSE
2671 x_natural_account := x_ta_reserve_segm;
2672 END IF;
2673
2674 change_account (x_chart_of_accounts_id,
2675 x_apps_short_name,
2676 x_key_flex_code,
2677 x_account_segment,
2678 ra.code_combination_id,
2679 x_natural_account,
2680 x_delimiter,
2681 x_returned_ccid,
2682 x_error_ccid
2683 );
2684
2685 insert_adjustment (tr.transaction_header_id,
2686 x_global_appraisal,
2687 x_je_appraisal,
2688 x_ta_reserve_name,
2689 x_debit_credit_flag,
2690 x_returned_ccid,
2691 p_tax_book,
2692 tr.asset_id,
2693 x_ta_line_amount,
2694 ra.distribution_id,
2695 NULL,
2696 NULL,
2697 NULL,
2698 ra.period_counter_adjusted,
2699 ra.period_counter_created,
2700 NULL,
2701 NULL,
2702 NULL
2703 );
2704 END IF;
2705 END IF;
2706 END LOOP;
2707
2708 -----------------------------------------------------------------------------
2709 -- TRANSFER OUT NOCOPY - Transaction used in Partial Unit Retirements --
2710 -----------------------------------------------------------------------------
2711
2712 ELSIF (tr.transaction_type_code = 'TRANSFER OUT') THEN
2713 IF (tr.asset_type = 'CAPITALIZED') THEN
2714 x_global_source := 'IA TRANSFER';
2715 x_je_category_name := x_je_ia_transfer;
2716 x_je_std_category_name := x_je_ia_transfer;
2717 x_adjustment_type := x_cost_name;
2718
2719 ELSIF (tr.asset_type = 'CIP') THEN
2720 x_global_source := 'IA CIP TRANSFER';
2721 x_je_category_name := x_je_ia_cip_transfer;
2722 x_je_std_category_name := x_je_ia_cip_transfer;
2723 x_adjustment_type := x_cip_cost_name;
2724 END IF;
2725
2726 -----------------------------------------------------------------------------
2727 -- Get information about of the source retirement --
2728 -----------------------------------------------------------------------------
2729
2730 --x_ta_factor := abs (tr.appraisal_balance) / tr.adj_cost;
2731 ----------------------------------------------------------------------------
2732 --BUG 3865352 Added handling of Divisor equal to zero.
2733 ----------------------------------------------------------------------------
2734 IF tr.adj_cost = 0 THEN
2735 x_ta_factor := 0;
2736 ELSE
2737 x_ta_factor := abs (tr.appraisal_balance) / tr.adj_cost;
2738 END IF;
2739
2740
2741 OPEN c_source_retirement (tr.transaction_header_id);
2742 FETCH c_source_retirement INTO x_source_transaction_header_id;
2743 CLOSE c_source_retirement;
2744
2745 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2746 x_char := 'Source Transaction ID = ' || to_char(x_source_transaction_header_id);
2747 fnd_file.put_line (FND_FILE.LOG, x_char);
2748 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2749 END IF;
2750
2751 -----------------------------------------------------------------------------
2752 -- Get historical and adjusted values of the cost inflation adjustments --
2753 -----------------------------------------------------------------------------
2754
2755 OPEN c_sum_adjustments (tr.asset_id,
2756 x_corporate_book,
2757 x_source_transaction_header_id,
2758 x_adjustment_type,
2759 'CR'
2760 );
2761 FETCH c_sum_adjustments INTO x_adjustment_amount;
2762 CLOSE c_sum_adjustments;
2763
2764 OPEN c_sum_adjustments (tr.asset_id,
2765 p_tax_book,
2766 tr.transaction_header_id,
2767 x_adjustment_type,
2768 'CR'
2769 );
2770 FETCH c_sum_adjustments INTO x_adj_cost;
2771 CLOSE c_sum_adjustments;
2772
2773 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2774 x_char := 'Sum Corp Cost = ' || to_char(x_adjustment_amount);
2775 fnd_file.put_line (FND_FILE.LOG, x_char);
2776 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2777 x_char := 'Sum Adj Cost = ' || to_char(x_adj_cost);
2778 fnd_file.put_line (FND_FILE.LOG, x_char);
2779 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2780 END IF;
2781
2782 IF (x_adj_cost <> 0) THEN
2783 x_factor := (x_adj_cost - x_adjustment_amount) / x_adj_cost;
2784 ELSE
2785 x_factor := 0;
2786 END IF;
2787
2788 -----------------------------------------------------------------------------
2789 -- Get historical and adjusted values of the reserve inflation adjustments --
2790 -----------------------------------------------------------------------------
2791
2792 OPEN c_deprn_summary (x_corporate_book,
2793 tr.asset_id,
2794 x_period_counter - 1
2795 );
2796 FETCH c_deprn_summary INTO x_corp_deprn_reserve,
2797 x_corp_reval_reserve,
2798 x_corp_reval_deprn_expense;
2799 CLOSE c_deprn_summary;
2800
2801 OPEN c_deprn_summary (p_tax_book,
2802 tr.asset_id,
2803 x_period_counter - 1
2804 );
2805 FETCH c_deprn_summary INTO x_adj_deprn_reserve,
2806 x_adj_reval_reserve,
2807 x_adj_reval_deprn_expense;
2808 CLOSE c_deprn_summary;
2809
2810 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2811 x_char := 'Sum Corp Reserve = ' || to_char(x_adjustment_amount);
2812 fnd_file.put_line (FND_FILE.LOG, x_char);
2813 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2814 x_char := 'Sum Adj Reserve = ' || to_char(x_adj_cost);
2815 fnd_file.put_line (FND_FILE.LOG, x_char);
2816 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2817 END IF;
2818
2819 -----------------------------------------------------------------------------------
2820 -- LER, 18-Jun-99 It's enough with the depreciation reserve amounts --
2821 -- because these amounts should be completely transferred. --
2822 -- Then the following statements are unnecessary and they --
2823 -- can be replaced by the new lines at end of this section. --
2824 -----------------------------------------------------------------------------------
2825
2826 -- OPEN c_sum_adjustments (tr.asset_id,
2827 -- x_corporate_book,
2828 -- x_source_transaction_header_id,
2829 -- x_reserve_name,
2830 -- 'DR'
2831 -- );
2832 -- FETCH c_sum_adjustments INTO x_adjustment_amount;
2833 -- CLOSE c_sum_adjustments;
2834
2835 -- OPEN c_sum_adjustments (tr.asset_id,
2836 -- p_tax_book,
2837 -- tr.transaction_header_id,
2838 -- x_reserve_name,
2839 -- 'DR'
2840 -- );
2841 -- FETCH c_sum_adjustments INTO x_adj_cost;
2842 -- CLOSE c_sum_adjustments;
2843
2844 -- x_adjustment_amount := x_adj_cost - x_adjustment_amount;
2845 -- x_factor_1 := x_adjustment_amount / (x_adj_deprn_reserve - x_corp_deprn_reserve);
2846
2847 -- IF (x_adj_cost <> 0) THEN
2848 -- x_factor_12 := x_deprn_to_cost * x_factor_1;
2849
2850 -- x_char := 'Factor_12 = ' || to_char(x_factor_12);
2851 -- fnd_file.put_line (FND_FILE.LOG, x_char);
2852
2853 -- x_factor_11 := x_factor_12 / x_adj_cost;
2854 -- x_factor_12 := (x_adjustment_amount - x_factor_12) / x_adj_cost;
2855 -- ELSE
2856 -- x_factor_11 := 0;
2857 -- x_factor_12 := 0;
2858 -- END IF;
2859
2860 ---------------------------------------------------------------------------------
2861 -- LER 18-Jun-99 The following new statements improve the previous section --
2862 ---------------------------------------------------------------------------------
2863
2864 x_adjustment_amount := x_adj_deprn_reserve - x_corp_deprn_reserve;
2865 IF (x_adj_deprn_reserve > 0) THEN
2866 x_factor_11 := x_deprn_to_cost / x_adj_deprn_reserve;
2867 x_factor_12 := (x_adjustment_amount - x_deprn_to_cost) / x_adj_deprn_reserve;
2868 ELSE
2869 x_factor_11 := 0;
2870 x_factor_12 := 0;
2871 END IF;
2872
2873 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2874 x_char := 'Factor_11 = ' || to_char(x_factor_11);
2875 fnd_file.put_line (FND_FILE.LOG, x_char);
2876 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2877 x_char := 'Factor_12 = ' || to_char(x_factor_12);
2878 fnd_file.put_line (FND_FILE.LOG, x_char);
2879 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2880 END IF;
2881
2882 -----------------------------------------------------------------------------
2883 -- Get historical and adjusted values of the expense inflation adjustments --
2884 -----------------------------------------------------------------------------
2885
2886 OPEN c_sum_adjustments (tr.asset_id,
2887 x_corporate_book,
2888 x_source_transaction_header_id,
2889 x_expense_name,
2890 'CR'
2891 );
2892 FETCH c_sum_adjustments INTO x_adjustment_amount;
2893 CLOSE c_sum_adjustments;
2894
2895 OPEN c_sum_adjustments (tr.asset_id,
2896 p_tax_book,
2897 tr.transaction_header_id,
2898 x_expense_name,
2899 'CR'
2900 );
2901 FETCH c_sum_adjustments INTO x_adj_cost;
2902 CLOSE c_sum_adjustments;
2903
2904 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2905 x_char := 'Sum Corp Expense = ' || to_char(x_adjustment_amount);
2906 fnd_file.put_line (FND_FILE.LOG, x_char);
2907 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2908 x_char := 'Sum Adj Expense = ' || to_char(x_adj_cost);
2909 fnd_file.put_line (FND_FILE.LOG, x_char);
2910 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2911 END IF;
2912
2913 IF (x_adj_cost <> 0) THEN
2914 x_factor_2 := (x_adj_cost - x_adjustment_amount) / x_adj_cost;
2915 ELSE
2916 x_factor_2 := 0;
2917 END IF;
2918
2919 -----------------------------------------------------------------------------
2920 -- Find all adjusted rows in FA_ADJUSTMENTS for TAX book --
2921 -----------------------------------------------------------------------------
2922
2923 FOR ra IN c_tr_adjustments_no_adj_type (tr.transaction_header_id,
2924 p_tax_book,
2925 x_period_counter
2926 ) LOOP
2927
2928 --FA SLA Changes.
2929 IF ra.code_combination_id is null then
2930 l_book_type_code := p_tax_book;
2931 RAISE e_ccid_not_found;
2932 END IF;
2933
2934
2935 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2936 x_char := 'Distribution Id = ' || to_char(ra.distribution_id);
2937 fnd_file.put_line (FND_FILE.LOG, x_char);
2938 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2939 END IF;
2940
2941 IF (ra.debit_credit_flag = 'DR') THEN
2942 x_debit_credit_flag := 'CR';
2943 ELSE
2944 x_debit_credit_flag := 'DR';
2945 END IF;
2946
2947 IF (ra.adjustment_type = x_cost_name) THEN
2948
2949 -----------------------------------------------------------------------------
2950 -- Cost inflation adjustments --
2951 -----------------------------------------------------------------------------
2952
2953 x_adjustment_amount := round (ra.adjustment_amount * x_factor, x_precision);
2954
2955 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
2956 x_char := 'Cost Adjustment Amount = ' || to_char(x_adjustment_amount);
2957 fnd_file.put_line (FND_FILE.LOG, x_char);
2958 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
2959 END IF;
2960
2961 change_account (x_chart_of_accounts_id,
2962 x_apps_short_name,
2963 x_key_flex_code,
2964 x_account_segment,
2965 ra.code_combination_id,
2966 x_ia_cost_segm,
2967 x_delimiter,
2968 x_returned_ccid,
2969 x_error_ccid
2970 );
2971
2972 insert_adjustment (tr.transaction_header_id,
2973 x_global_source,
2974 x_je_category_name,
2975 x_ia_cost_name,
2976 ra.debit_credit_flag,
2977 x_returned_ccid,
2978 p_tax_book,
2979 tr.asset_id,
2980 x_adjustment_amount,
2981 ra.distribution_id,
2982 ra.annualized_adjustment,
2983 NULL,
2984 NULL,
2985 ra.period_counter_adjusted,
2986 ra.period_counter_created,
2987 ra.asset_invoice_id,
2988 NULL,
2989 NULL
2990 );
2991
2992 ELSIF (ra.adjustment_type = x_reserve_name) THEN
2993
2994 -----------------------------------------------------------------------------
2995 -- Depreciation reserve inflation adjustments --
2996 -----------------------------------------------------------------------------
2997
2998 x_adjustment_amount := round (ra.adjustment_amount * x_factor_11, x_precision);
2999
3000 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3001 x_char := 'Std Reserve Adjustment Amount = ' || to_char(x_adjustment_amount);
3002 fnd_file.put_line (FND_FILE.LOG, x_char);
3003 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3004 END IF;
3005
3006 insert_adjustment (tr.transaction_header_id,
3007 x_global_source,
3008 x_je_std_category_name,
3009 x_reserve_name,
3010 ra.debit_credit_flag,
3011 ra.code_combination_id,
3012 p_tax_book,
3013 tr.asset_id,
3014 x_adjustment_amount,
3015 ra.distribution_id,
3016 ra.annualized_adjustment,
3017 NULL,
3018 NULL,
3019 ra.period_counter_adjusted,
3020 ra.period_counter_created,
3021 ra.asset_invoice_id,
3022 NULL,
3023 NULL
3024 );
3025
3026 x_adjustment_amount := round (ra.adjustment_amount * x_factor_12, x_precision);
3027
3028 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3029 x_char := 'IA Reserve Adjustment Amount = ' || to_char(x_adjustment_amount);
3030 fnd_file.put_line (FND_FILE.LOG, x_char);
3031 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3032 END IF;
3033
3034 change_account (x_chart_of_accounts_id,
3035 x_apps_short_name,
3036 x_key_flex_code,
3037 x_account_segment,
3038 ra.code_combination_id,
3039 x_ia_deprn_reserve_segm,
3040 x_delimiter,
3041 x_returned_ccid,
3042 x_error_ccid
3043 );
3044
3045 insert_adjustment (tr.transaction_header_id,
3046 x_global_source,
3047 x_je_category_name,
3048 x_ia_reserve_name,
3049 ra.debit_credit_flag,
3050 x_returned_ccid,
3051 p_tax_book,
3052 tr.asset_id,
3053 x_adjustment_amount,
3054 ra.distribution_id,
3055 ra.annualized_adjustment,
3056 NULL,
3057 NULL,
3058 ra.period_counter_adjusted,
3059 ra.period_counter_created,
3060 ra.asset_invoice_id,
3061 NULL,
3062 NULL
3063 );
3064
3065
3066 ELSIF (ra.adjustment_type = x_expense_name) THEN
3067
3068 -----------------------------------------------------------------------------
3069 -- Adjustments to depreciation expense due to transaction --
3070 -----------------------------------------------------------------------------
3071
3072 x_adjustment_amount := round (ra.adjustment_amount * x_factor_2, x_precision);
3073
3074 insert_adjustment (tr.transaction_header_id,
3075 'DEPRECIATION',
3076 x_je_depreciation,
3077 x_expense_name,
3078 ra.debit_credit_flag,
3079 ra.code_combination_id,
3080 p_tax_book,
3081 tr.asset_id,
3082 x_adjustment_amount,
3083 ra.distribution_id,
3084 ra.annualized_adjustment,
3085 NULL,
3086 NULL,
3087 x_period_counter,
3088 x_period_counter,
3089 ra.asset_invoice_id,
3090 NULL,
3091 NULL
3092 );
3093
3094 -----------------------------------------------------------------------------
3095 -- LER, 18-Jun-99 The following section was cancelled because the --
3096 -- reserve was completely transferred in previous --
3097 -- section. --
3098 -----------------------------------------------------------------------------
3099
3100 -- fa_gccid_pkg.fafbgcc_proc (p_tax_book,
3101 -- 'DEPRN_RESERVE_ACCT',
3102 -- ra.code_combination_id,
3103 -- x_deprn_reserve_segm,
3104 -- x_deprn_reserve_ccid,
3105 -- ra.distribution_id,
3106 -- x_returned_ccid,
3107 -- x_concat_segs,
3108 -- x_return_value
3109 -- );
3110
3111 -- IF (x_return_value = 0) then
3112 -- fnd_message.set_name ('JL', 'JL_CO_FA_CCID_NOT_CREATED');
3113 -- fnd_message.set_token ('ACCOUNT', x_concat_segs);
3114 -- x_error_ccid := TRUE;
3115
3116 -- ELSE
3117 -- insert_adjustment (tr.transaction_header_id,
3118 -- 'DEPRECIATION',
3119 -- x_je_depreciation,
3120 -- x_reserve_name,
3121 -- x_debit_credit_flag,
3122 -- x_returned_ccid,
3123 -- p_tax_book,
3124 -- tr.asset_id,
3125 -- x_adjustment_amount,
3126 -- ra.distribution_id,
3127 -- ra.annualized_adjustment,
3128 -- NULL,
3129 -- NULL,
3130 -- x_period_counter,
3131 -- x_period_counter,
3132 -- ra.asset_invoice_id,
3133 -- NULL,
3134 -- NULL
3135 -- );
3136 -- END IF;
3137
3138 ELSIF (ra.adjustment_type = x_cip_cost_name) THEN
3139
3140 -----------------------------------------------------------------------------
3141 -- CIP cost inflation adjustments --
3142 -----------------------------------------------------------------------------
3143
3144 x_adjustment_amount := round (ra.adjustment_amount * x_factor, x_precision);
3145
3146 change_account (x_chart_of_accounts_id,
3147 x_apps_short_name,
3148 x_key_flex_code,
3149 x_account_segment,
3150 ra.code_combination_id,
3151 x_ia_cip_cost_segm,
3152 x_delimiter,
3153 x_returned_ccid,
3154 x_error_ccid
3155 );
3156
3157 insert_adjustment (tr.transaction_header_id,
3158 x_global_source,
3159 x_je_category_name,
3160 x_ia_cip_cost_name,
3161 ra.debit_credit_flag,
3162 x_returned_ccid,
3163 p_tax_book,
3164 tr.asset_id,
3165 x_adjustment_amount,
3166 ra.distribution_id,
3167 ra.annualized_adjustment,
3168 NULL,
3169 NULL,
3170 ra.period_counter_adjusted,
3171 ra.period_counter_created,
3172 ra.asset_invoice_id,
3173 NULL,
3174 NULL
3175 );
3176 END IF;
3177
3178 -----------------------------------------------------------------------------
3179 -- Transferring Technical Appraisal Account Balances --
3180 -----------------------------------------------------------------------------
3181
3182 IF ra.adjustment_type IN (x_cost_name,
3183 x_cip_cost_name
3184 ) THEN
3185
3186 x_ta_line_amount := round (ra.adjustment_amount * x_ta_factor, x_precision);
3187
3188 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3189 x_char := 'Appraisal Line Amount =' || to_char (x_ta_line_amount);
3190 fnd_file.put_line (FND_FILE.LOG, x_char);
3191 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3192 END IF;
3193
3194 IF (tr.appraisal_balance > 0) THEN
3195
3196 change_account (x_chart_of_accounts_id,
3197 x_apps_short_name,
3198 x_key_flex_code,
3199 x_account_segment,
3200 ra.code_combination_id,
3201 x_ta_revaluation_segm,
3202 x_delimiter,
3203 x_returned_ccid,
3204 x_error_ccid
3205 );
3206
3207 insert_adjustment (tr.transaction_header_id,
3208 x_global_appraisal,
3209 x_je_appraisal,
3210 x_ta_revaluation_name,
3211 ra.debit_credit_flag,
3212 x_returned_ccid,
3213 p_tax_book,
3214 tr.asset_id,
3215 x_ta_line_amount,
3216 ra.distribution_id,
3217 NULL,
3218 NULL,
3219 NULL,
3220 ra.period_counter_adjusted,
3221 ra.period_counter_created,
3222 NULL,
3223 NULL,
3224 NULL
3225 );
3226
3227 change_account (x_chart_of_accounts_id,
3228 x_apps_short_name,
3229 x_key_flex_code,
3230 x_account_segment,
3231 ra.code_combination_id,
3232 x_ta_surplus_segm,
3233 x_delimiter,
3234 x_returned_ccid,
3235 x_error_ccid
3236 );
3237
3238 insert_adjustment (tr.transaction_header_id,
3239 x_global_appraisal,
3240 x_je_appraisal,
3241 x_ta_surplus_name,
3242 x_debit_credit_flag,
3243 x_returned_ccid,
3244 p_tax_book,
3245 tr.asset_id,
3246 x_ta_line_amount,
3247 ra.distribution_id,
3248 NULL,
3249 NULL,
3250 NULL,
3251 ra.period_counter_adjusted,
3252 ra.period_counter_created,
3253 NULL,
3254 NULL,
3255 NULL
3256 );
3257
3258 ELSIF (tr.appraisal_balance < 0) THEN
3259
3260 change_account (x_chart_of_accounts_id,
3261 x_apps_short_name,
3262 x_key_flex_code,
3263 x_account_segment,
3264 ra.code_combination_id,
3265 x_ta_reserve_segm,
3266 x_delimiter,
3267 x_returned_ccid,
3268 x_error_ccid
3269 );
3270
3271 insert_adjustment (tr.transaction_header_id,
3272 x_global_appraisal,
3273 x_je_appraisal,
3274 x_ta_reserve_name,
3275 x_debit_credit_flag,
3276 x_returned_ccid,
3277 p_tax_book,
3278 tr.asset_id,
3279 x_ta_line_amount,
3280 ra.distribution_id,
3281 NULL,
3282 NULL,
3283 NULL,
3284 ra.period_counter_adjusted,
3285 ra.period_counter_created,
3286 NULL,
3287 NULL,
3288 NULL
3289 );
3290 END IF;
3291 END IF;
3292 END LOOP;
3293
3294 -----------------------------------------------------------------------------
3295 -- RETIREMENT / REINSTATEMENT --
3296 -----------------------------------------------------------------------------
3297
3298 ELSIF tr.transaction_type_code IN ('FULL RETIREMENT',
3299 'PARTIAL RETIREMENT',
3300 'REINSTATEMENT'
3301 ) THEN
3302 IF (tr.asset_type = 'CAPITALIZED') THEN
3303 x_global_source := 'IA RETIREMENT';
3304 x_adjustment_type := x_cost_name;
3305 x_je_std_category_name := x_je_ia_retirement;
3306 ELSE
3307 x_global_source := 'IA CIP RETIRE';
3308 x_adjustment_type := x_cip_cost_name;
3309 x_je_std_category_name := x_je_ia_cip_retirement;
3310 END IF;
3311
3312 -----------------------------------------------------------------------------
3313 -- Get corporate and adjusted depreciation values of the retirement --
3314 -----------------------------------------------------------------------------
3315 -- LER, 18-Jun-99 Moved after of the following section to lookup --
3316 -- the Period_Counter of the source Retirement --
3317 -----------------------------------------------------------------------------
3318
3319 -- IF (tr.transaction_type_code = 'REINSTATEMENT') THEN
3320 -- x_period_1 := x_period_counter - 1;
3321 -- ELSE
3322 -- x_period_1 := x_period_counter;
3323 -- END IF;
3324
3325 -- OPEN c_deprn_summary (x_corporate_book,
3326 -- tr.asset_id,
3327 -- x_period_1
3328 -- );
3329 -- FETCH c_deprn_summary INTO x_corp_deprn_reserve,
3330 -- x_corp_reval_reserve,
3331 -- x_corp_reval_deprn_expense;
3332 -- CLOSE c_deprn_summary;
3333
3334 -- OPEN c_deprn_summary (p_tax_book,
3335 -- tr.asset_id,
3336 -- x_period_1
3337 -- );
3338 -- FETCH c_deprn_summary INTO x_adj_deprn_reserve,
3339 -- x_adj_reval_reserve,
3340 -- x_adj_reval_deprn_expense;
3341 -- CLOSE c_deprn_summary;
3342
3343 -- x_ia_reserve := x_adj_deprn_reserve - x_corp_deprn_reserve;
3344
3345
3346 IF (tr.transaction_type_code = 'REINSTATEMENT') THEN
3347
3348 -----------------------------------------------------------------------------
3349 -- Get information about the reinstatement and previous transactions --
3350 -----------------------------------------------------------------------------
3351
3352 OPEN c_reinstatement (tr.source_transaction_header_id);
3353 FETCH c_reinstatement INTO x_corp_retirement_id,
3354 x_corp_cost_retired,
3355 x_corp_units_retired,
3356 x_corp_nbv_retired,
3357 x_corp_reval_reserve_retired,
3358 x_corp_gain_loss_amount,
3359 x_period_1,
3360 x_retirement_type_code;
3361 CLOSE c_reinstatement;
3362
3363 OPEN c_reinstatement (tr.transaction_header_id);
3364 FETCH c_reinstatement INTO x_adj_retirement_id,
3365 x_adj_cost_retired,
3366 x_adj_units_retired,
3367 x_adj_nbv_retired,
3368 x_adj_reval_reserve_retired,
3369 x_adj_gain_loss_amount,
3370 x_period_1,
3371 x_retirement_type_code;
3372 CLOSE c_reinstatement;
3373
3374 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3375 x_char := 'tr.transaction_header_id_in = ' || to_char (tr.transaction_header_id);
3376 fnd_file.put_line (FND_FILE.LOG, x_char);
3377 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3378 x_char := 'x_period_1 = ' || to_char(x_period_1);
3379 fnd_file.put_line (FND_FILE.LOG, x_char);
3380 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3381 END IF;
3382
3383 -----------------------------------------------------------------------------------
3384 -- LER, 18-Jun-99 Lines commented were moved outside of the IF section --
3385 -----------------------------------------------------------------------------------
3386
3387 -- x_adjustment_amount := x_adj_cost_retired - x_adj_nbv_retired;
3388 -- x_ia_reserve_retired := x_adjustment_amount - (x_corp_cost_retired - x_corp_nbv_retired);
3389 -- x_ia_reserve := x_ia_reserve + x_ia_reserve_retired;
3390
3391 OPEN c_prior_retirement (tr.transaction_header_id);
3392 FETCH c_prior_retirement INTO x_transaction_header_id_in,
3393 x_value_2;
3394 CLOSE c_prior_retirement;
3395
3396 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3397 x_char := 'x_transaction_header_id_in = ' || to_char(x_transaction_header_id_in);
3398 fnd_file.put_line (FND_FILE.LOG, x_char);
3399 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3400 x_char := 'x_value_1 = ' || to_char(x_value_2);
3401 fnd_file.put_line (FND_FILE.LOG, x_char);
3402 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3403 END IF;
3404
3405 OPEN c_prior_retirement (x_transaction_header_id_in);
3406 FETCH c_prior_retirement INTO x_transaction_header_id_out,
3407 x_value_1;
3408 CLOSE c_prior_retirement;
3409
3410 x_deprn_to_cost := x_deprn_to_cost + x_value_1 - x_value_2;
3411
3412 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3413 x_char := 'x_transaction_header_id_out = ' || to_char(x_transaction_header_id_out);
3414 fnd_file.put_line (FND_FILE.LOG, x_char);
3415 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3416 x_char := 'x_value_2 = ' || to_char(x_value_1);
3417 fnd_file.put_line (FND_FILE.LOG, x_char);
3418 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3419 x_char := 'x_ia_reserve = ' || to_char(x_ia_reserve);
3420 fnd_file.put_line (FND_FILE.LOG, x_char);
3421 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3422 x_char := 'x_ia_reserve_retired ' || to_char(x_ia_reserve_retired);
3423 fnd_file.put_line (FND_FILE.LOG, x_char);
3424 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3425 x_char := 'x_deprn_to_cost = ' || to_char(x_deprn_to_cost);
3426 fnd_file.put_line (FND_FILE.LOG, x_char);
3427 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3428 END IF;
3429
3430 ELSE
3431
3432 -----------------------------------------------------------------------------
3433 -- Get information about the retirement --
3434 -----------------------------------------------------------------------------
3435
3436 OPEN c_retirement (tr.transaction_header_id);
3437 FETCH c_retirement INTO x_adj_retirement_id,
3438 x_adj_cost_retired,
3439 x_adj_units_retired,
3440 x_adj_nbv_retired,
3441 x_adj_reval_reserve_retired,
3442 x_adj_gain_loss_amount;
3443 CLOSE c_retirement;
3444
3445 OPEN c_retirement (tr.source_transaction_header_id);
3446 FETCH c_retirement INTO x_corp_retirement_id,
3447 x_corp_cost_retired,
3448 x_corp_units_retired,
3449 x_corp_nbv_retired,
3450 x_corp_reval_reserve_retired,
3451 x_corp_gain_loss_amount;
3452 CLOSE c_retirement;
3453
3454 -----------------------------------------------------------------------------------
3455 -- LER, 18-Jun-99 Lines commented were moved outside of the IF section --
3456 -----------------------------------------------------------------------------------
3457
3458 -- x_adjustment_amount := x_adj_cost_retired - x_adj_nbv_retired;
3459 -- x_ia_reserve_retired := x_adjustment_amount - (x_corp_cost_retired - x_corp_nbv_retired);
3460 -- x_ia_reserve := x_ia_reserve + x_ia_reserve_retired;
3461
3462 x_period_1 := x_period_counter;
3463 x_retirement_type_code := tr.transaction_type_code;
3464 END IF;
3465
3466 x_adjustment_amount := x_adj_cost_retired - x_adj_nbv_retired;
3467 x_ia_reserve_retired := x_adjustment_amount - (x_corp_cost_retired - x_corp_nbv_retired);
3468 -- x_ia_reserve := x_ia_reserve + x_ia_reserve_retired;
3469
3470 x_value_3 := x_deprn_to_cost;
3471 x_value_5 := x_deprn_to_cost;
3472
3473 -----------------------------------------------------------------------------------
3474 -- Get corporate and adjusted depreciation values of the retirement --
3475 -----------------------------------------------------------------------------------
3476 -- LER, 18-Jun-99 Moved from the begin of the RETIREMENT transaction code --
3477 -----------------------------------------------------------------------------------
3478
3479 OPEN c_deprn_summary (x_corporate_book,
3480 tr.asset_id,
3481 x_period_1
3482 );
3483 FETCH c_deprn_summary INTO x_corp_deprn_reserve,
3484 x_corp_reval_reserve,
3485 x_corp_reval_deprn_expense;
3486 CLOSE c_deprn_summary;
3487
3488 OPEN c_deprn_summary (p_tax_book,
3489 tr.asset_id,
3490 x_period_1
3491 );
3492 FETCH c_deprn_summary INTO x_adj_deprn_reserve,
3493 x_adj_reval_reserve,
3494 x_adj_reval_deprn_expense;
3495 CLOSE c_deprn_summary;
3496
3497 x_ia_reserve := x_adj_deprn_reserve - x_corp_deprn_reserve + x_ia_reserve_retired;
3498
3499 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3500 x_char := 'x_adjustment = ' || to_char(x_adjustment_amount);
3501 fnd_file.put_line (FND_FILE.LOG, x_char);
3502 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3503 x_char := 'x_ia_reserve = ' || to_char(x_ia_reserve);
3504 fnd_file.put_line (FND_FILE.LOG, x_char);
3505 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3506 x_char := 'x_ia_reserve_retired ' || to_char(x_ia_reserve_retired);
3507 fnd_file.put_line (FND_FILE.LOG, x_char);
3508 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3509 x_char := 'x_value_3 ' || to_char(x_value_3);
3510 fnd_file.put_line (FND_FILE.LOG, x_char);
3511 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3512 x_char := 'adj_deprn_reserve = ' || to_char(x_adj_deprn_reserve);
3513 fnd_file.put_line (FND_FILE.LOG, x_char);
3514 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3515 x_char := 'corp_deprn_reserve = ' || to_char(x_corp_deprn_reserve);
3516 fnd_file.put_line (FND_FILE.LOG, x_char);
3517 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3518 END IF;
3519
3520 -----------------------------------------------------------------------------
3521 -- Identify if retirement Gain/Loss is different in Corporate and Tax --
3522 -----------------------------------------------------------------------------
3523
3524 x_corp_gain_loss_amount := x_corp_gain_loss_amount - x_corp_reval_reserve_retired;
3525 x_adj_gain_loss_amount := x_adj_gain_loss_amount - x_adj_reval_reserve_retired;
3526
3527 IF (x_adj_gain_loss_amount >= 0 AND x_corp_gain_loss_amount < 0
3528 OR x_adj_gain_loss_amount < 0 AND x_corp_gain_loss_amount >= 0) THEN
3529 x_gain_loss_changed := TRUE;
3530 ELSE
3531 x_gain_loss_changed := FALSE;
3532 END IF;
3533
3534 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3535 x_char := 'Gain/Loss Corp = ' || to_char(x_corp_gain_loss_amount);
3536 fnd_file.put_line (FND_FILE.LOG, x_char);
3537 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3538 x_char := 'Gain/Loss Adj = ' || to_char(x_adj_gain_loss_amount);
3539 fnd_file.put_line (FND_FILE.LOG, x_char);
3540 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3541 END IF;
3542
3543 -----------------------------------------------------------------------------
3544 -- Define values used in retire of Technical Appraisal balances --
3545 -----------------------------------------------------------------------------
3546
3547 IF (tr.adj_cost > 0) THEN
3548 x_ta_factor := tr.adj_cost;
3549 ELSE
3550 x_ta_factor := x_adj_cost_retired;
3551 END IF;
3552
3553 x_distribution_id := 0;
3554
3555 --x_ta_factor := abs (tr.appraisal_balance) / x_ta_factor;
3556 ----------------------------------------------------------------------------
3557 --BUG 3865352
3558 ----------------------------------------------------------------------------
3559 IF x_ta_factor = 0 THEN
3560 x_ta_factor := 0;
3561 ELSE
3562 x_ta_factor := abs (tr.appraisal_balance) / x_ta_factor;
3563 END IF;
3564
3565
3566
3567
3568 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3569 x_char := 'Asset cost = ' || to_char(tr.adj_cost);
3570 fnd_file.put_line (FND_FILE.LOG, x_char);
3571 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3572 x_char := 'Appraisal = ' || to_char(tr.appraisal_balance);
3573 fnd_file.put_line (FND_FILE.LOG, x_char);
3574 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3575 END IF;
3576
3577 -----------------------------------------------------------------------------
3578 -- Identify retirement type --
3579 -- Technical Reference Manual define that column --
3580 -- FA_TRANSACTION_HEADERS.TRANSACTION_SUBTYPE contains the retirement --
3581 -- type, but standard application always leave this column as NULL --
3582 -----------------------------------------------------------------------------
3583
3584 x_retirement_type := 'O';
3585 IF (tr.transaction_type_code = 'PARTIAL RETIREMENT'
3586 AND x_corp_units_retired > 0
3587 ) THEN
3588 x_retirement_type := 'U';
3589
3590 -----------------------------------------------------------------------------------
3591 -- LER, 18-Jun-99 Looking for adjustments to Acc. Depreciation at begin --
3592 -- of the current period (end of previous period) --
3593 -----------------------------------------------------------------------------------
3594
3595 x_period_1 := x_period_counter - 1;
3596
3597 OPEN c_deprn_summary (x_corporate_book,
3598 tr.asset_id,
3599 x_period_1
3600 );
3601 FETCH c_deprn_summary INTO x_corp_deprn_reserve,
3602 x_corp_reval_reserve,
3603 x_corp_reval_deprn_expense;
3604 CLOSE c_deprn_summary;
3605
3606 OPEN c_deprn_summary (p_tax_book,
3607 tr.asset_id,
3608 x_period_1
3609 );
3610 FETCH c_deprn_summary INTO x_adj_deprn_reserve,
3611 x_adj_reval_reserve,
3612 x_adj_reval_deprn_expense;
3613 CLOSE c_deprn_summary;
3614
3615 x_value_4 := x_adj_deprn_reserve - x_corp_deprn_reserve;
3616
3617 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3618 x_char := 'adj_deprn_reserve = ' || to_char(x_adj_deprn_reserve);
3619 fnd_file.put_line (FND_FILE.LOG, x_char);
3620 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3621 x_char := 'corp_deprn_reserve = ' || to_char(x_corp_deprn_reserve);
3622 fnd_file.put_line (FND_FILE.LOG, x_char);
3623 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3624 END IF;
3625
3626 -----------------------------------------------------------------------------
3627 -- Calculate Deprn. To Cost Inflation Adjusts. and Adjustments to Deprn. --
3628 -----------------------------------------------------------------------------
3629
3630 OPEN c_sum_adjustments (tr.asset_id,
3631 p_tax_book,
3632 tr.transaction_header_id,
3633 x_expense_name,
3634 'DR'
3635 );
3636 FETCH c_sum_adjustments INTO x_adj_cost_retired;
3637 CLOSE c_sum_adjustments;
3638
3639 -- OPEN c_sum_adjustments (tr.transaction_header_id,
3640 -- x_expense_name,
3641 -- 'CR'
3642 -- );
3643 -- FETCH c_sum_adjustments INTO x_adj_cost;
3644 -- CLOSE c_sum_adjustments;
3645 -- x_adj_cost_retired := x_adjustment_amount - x_adj_cost;
3646
3647 -- x_adjustment_amount := 0;
3648 -- x_adj_cost := 0;
3649
3650 OPEN c_sum_adjustments (tr.asset_id,
3651 x_corporate_book,
3652 tr.source_transaction_header_id,
3653 x_expense_name,
3654 'DR'
3655 );
3656 FETCH c_sum_adjustments INTO x_adjustment_amount;
3657 CLOSE c_sum_adjustments;
3658 OPEN c_sum_adjustments (tr.asset_id,
3659 x_corporate_book,
3660 tr.source_transaction_header_id,
3661 x_expense_name,
3662 'CR'
3663 );
3664 FETCH c_sum_adjustments INTO x_adj_cost;
3665 CLOSE c_sum_adjustments;
3666
3667 IF (x_adj_cost_retired <> 0) THEN
3668 x_factor_2 := (x_adj_cost_retired - x_adjustment_amount + x_adj_cost) / x_adj_cost_retired;
3669 ELSE
3670 x_factor_2 := 0;
3671 END IF;
3672
3673 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3674 x_char := 'Expense - Corp -Dr = ' || to_char(x_adjustment_amount);
3675 fnd_file.put_line (FND_FILE.LOG, x_char);
3676 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3677 x_char := 'Expense - Corp - Cr = ' || to_char(x_adj_cost);
3678 fnd_file.put_line (FND_FILE.LOG, x_char);
3679 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3680 x_char := 'Expense - Adj - Dr = ' || to_char(x_adj_cost_retired);
3681 fnd_file.put_line (FND_FILE.LOG, x_char);
3682 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3683 END IF;
3684 END IF;
3685
3686 --------------------------------------------------------------------------------
3687 -- Calculate the adjustments to depreciation expense debt to the retirement --
3688 --------------------------------------------------------------------------------
3689
3690 FOR ra IN c_tr_adjustments_adj_type (tr.transaction_header_id,
3691 tr.book_type_code,
3692 x_expense_name,
3693 x_period_counter
3694 ) LOOP
3695
3696 --FA SLA Changes.
3697 IF ra.code_combination_id is null then
3698 l_book_type_code := tr.book_type_code;
3699 RAISE e_ccid_not_found;
3700 END IF;
3701
3702
3703 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3704 x_char := 'Adjustment for Line = ' || to_char(ra.distribution_id) || ' ' || ra.adjustment_type;
3705 fnd_file.put_line (FND_FILE.LOG, x_char);
3706 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3707 END IF;
3708
3709 IF (x_retirement_type = 'O') THEN
3710 OPEN c_tr_rel_adjustments (tr.source_transaction_header_id,
3711 x_corporate_book,
3712 ra.source_type_code,
3713 ra.adjustment_type,
3714 ra.debit_credit_flag,
3715 ra.distribution_id
3716 );
3717 FETCH c_tr_rel_adjustments INTO x_code_combination_id,
3718 x_adjustment_amount;
3719
3720 IF (c_tr_rel_adjustments%FOUND = FALSE) THEN
3721 x_adjustment_amount := 0;
3722 END IF;
3723 CLOSE c_tr_rel_adjustments;
3724
3725 x_adjustment_amount := round (ra.adjustment_amount - x_adjustment_amount, x_precision);
3726
3727 ELSE
3728 x_adjustment_amount := round (ra.adjustment_amount * x_factor_2, x_precision);
3729
3730 END IF;
3731
3732 IF (tr.transaction_type_code = 'REINSTATEMENT') THEN
3733 x_value_3 := x_value_3 - x_adjustment_amount;
3734 ELSE
3735 x_deprn_to_cost := x_deprn_to_cost + x_adjustment_amount;
3736 x_value_3 := x_deprn_to_cost;
3737
3738 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3739 x_char := 'X_value_3 ' || to_char(x_value_3);
3740 fnd_file.put_line (FND_FILE.LOG, x_char);
3741 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3742 END IF;
3743 END IF;
3744
3745 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3746 x_char := 'x_deprn_to_cost A = ' || to_char(x_deprn_to_cost);
3747 fnd_file.put_line (FND_FILE.LOG, x_char);
3748 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3749 END IF;
3750
3751 IF (ra.debit_credit_flag = 'DR') THEN
3752 x_debit_credit_flag := 'CR';
3753 ELSE
3754 x_debit_credit_flag := 'DR';
3755 END IF;
3756
3757 insert_adjustment (tr.transaction_header_id,
3758 'DEPRECIATION',
3759 x_je_depreciation,
3760 x_expense_name,
3761 ra.debit_credit_flag,
3762 ra.code_combination_id,
3763 p_tax_book,
3764 tr.asset_id,
3765 x_adjustment_amount,
3766 ra.distribution_id,
3767 ra.annualized_adjustment,
3768 NULL,
3769 NULL,
3770 x_period_counter,
3771 x_period_counter,
3772 ra.asset_invoice_id,
3773 NULL,
3774 NULL
3775 );
3776
3777 fa_gccid_pkg.fafbgcc_proc (p_tax_book,
3778 'DEPRN_RESERVE_ACCT',
3779 ra.code_combination_id,
3780 x_deprn_reserve_segm,
3781 x_deprn_reserve_ccid,
3782 ra.distribution_id,
3783 x_returned_ccid,
3784 x_concat_segs,
3785 x_return_value
3786 );
3787
3788 IF (x_return_value = 0) then
3789 fnd_message.set_name ('JL', 'JL_CO_FA_CCID_NOT_CREATED');
3790 fnd_message.set_token ('ACCOUNT', x_concat_segs);
3791 --Bug 2929483. Missing log message handling has been added.
3792 fnd_file.put_line (FND_FILE.LOG, fnd_message.get);
3793 x_error_ccid := TRUE;
3794
3795 ELSE
3796 insert_adjustment (tr.transaction_header_id,
3797 'DEPRECIATION',
3798 x_je_depreciation,
3799 x_reserve_name,
3800 x_debit_credit_flag,
3801 x_returned_ccid,
3802 p_tax_book,
3803 tr.asset_id,
3804 x_adjustment_amount,
3805 ra.distribution_id,
3806 ra.annualized_adjustment,
3807 NULL,
3808 NULL,
3809 x_period_counter,
3810 x_period_counter,
3811 ra.asset_invoice_id,
3812 NULL,
3813 NULL
3814 );
3815 END IF;
3816 END LOOP;
3817
3818 -----------------------------------------------------------------------------
3819 -- Calculate Deprn. To Cost Inflation Adjusts. and Adjustments to Deprn. --
3820 -----------------------------------------------------------------------------
3821
3822 IF (x_retirement_type = 'O') THEN
3823 IF x_ia_reserve <> 0 THEN
3824 x_factor_1 := x_ia_reserve_retired / x_ia_reserve;
3825 ELSE
3826 x_factor_1 := 0;
3827 END IF;
3828
3829 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3830 x_char := 'Retirement ID for Tax book = ' || to_char(x_adj_retirement_id);
3831 fnd_file.put_line (FND_FILE.LOG, x_char);
3832 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3833 x_char := 'Retirement ID for Corp book = ' || to_char(x_corp_retirement_id);
3834 fnd_file.put_line (FND_FILE.LOG, x_char);
3835 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3836 x_char := 'Factor 1 = ' || to_char(x_factor_1);
3837 fnd_file.put_line (FND_FILE.LOG, x_char);
3838 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3839 x_char := 'x_deprn_to cost B = ' || to_char(x_deprn_to_cost);
3840 fnd_file.put_line (FND_FILE.LOG, x_char);
3841 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3842 END IF;
3843
3844 IF (x_ia_reserve_retired <> 0) THEN
3845 x_factor_12 := x_value_3 * x_factor_1;
3846
3847 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3848 x_char := 'Factor_12 = ' || to_char(x_factor_12);
3849 fnd_file.put_line (FND_FILE.LOG, x_char);
3850 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3851 END IF;
3852
3853 x_factor_11 := x_factor_12 / x_ia_reserve_retired;
3854 x_factor_12 := (x_ia_reserve_retired - x_factor_12) / x_ia_reserve_retired;
3855 ELSE
3856 x_factor_11 := 0;
3857 x_factor_12 := 0;
3858 END IF;
3859
3860 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3861 x_char := 'Factor_11 = ' || to_char(x_factor_11);
3862 fnd_file.put_line (FND_FILE.LOG, x_char);
3863 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3864 x_char := 'Factor_12 = ' || to_char(x_factor_12);
3865 fnd_file.put_line (FND_FILE.LOG, x_char);
3866 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3867 END IF;
3868
3869 ELSE
3870 -------------------------------------------------------------------------------------
3871 -- Find source data to calculate factors applied in partial retirements by units --
3872 -------------------------------------------------------------------------------------
3873
3874 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3875 x_char := 'Units Retired = ' || to_char(x_corp_units_retired);
3876 fnd_file.put_line (FND_FILE.LOG, x_char);
3877 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3878 END IF;
3879
3880 IF (x_retirement_type = 'U') THEN
3881 -- x_adj_cost_retired := 0;
3882 -- x_adjustment_amount := 0;
3883 -- x_adj_cost := 0;
3884
3885 OPEN c_sum_adjustments (tr.asset_id,
3886 p_tax_book,
3887 tr.transaction_header_id,
3888 x_adjustment_type,
3889 'CR'
3890 );
3891 FETCH c_sum_adjustments INTO x_adj_cost_retired;
3892 CLOSE c_sum_adjustments;
3893
3894 -- OPEN c_sum_adjustments (tr.transaction_header_id,
3895 -- x_adjustment_type,
3896 -- 'DR'
3897 -- );
3898 -- FETCH c_sum_adjustments INTO x_adj_cost;
3899 -- CLOSE c_sum_adjustments;
3900 -- x_adj_cost_retired := x_adjustment_amount - x_adj_cost;
3901
3902 OPEN c_sum_adjustments (tr.asset_id,
3903 x_corporate_book,
3904 tr.source_transaction_header_id,
3905 x_adjustment_type,
3906 'CR'
3907 );
3908 FETCH c_sum_adjustments INTO x_adjustment_amount;
3909 CLOSE c_sum_adjustments;
3910
3911 OPEN c_sum_adjustments (tr.asset_id,
3912 x_corporate_book,
3913 tr.source_transaction_header_id,
3914 x_adjustment_type,
3915 'DR'
3916 );
3917 FETCH c_sum_adjustments INTO x_adj_cost;
3918 CLOSE c_sum_adjustments;
3919
3920 IF (x_adj_cost_retired <> 0) THEN
3921 x_factor := (x_adj_cost_retired - x_adjustment_amount + x_adj_cost) / x_adj_cost_retired;
3922 ELSE
3923 x_factor := 0;
3924 END IF;
3925
3926 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3927 x_char := 'Sum Corp Cost Retired = ' || to_char(x_adjustment_amount - x_adj_cost);
3928 fnd_file.put_line (FND_FILE.LOG, x_char);
3929 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3930 x_char := 'Sum Adj Cost = ' || to_char(x_adj_cost_retired);
3931 fnd_file.put_line (FND_FILE.LOG, x_char);
3932 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3933 END IF;
3934
3935 OPEN c_sum_adjustments (tr.asset_id,
3936 p_tax_book,
3937 tr.transaction_header_id,
3938 x_reserve_name,
3939 'DR'
3940 );
3941 FETCH c_sum_adjustments INTO x_adj_cost_retired;
3942 CLOSE c_sum_adjustments;
3943
3944 -- OPEN c_sum_adjustments (tr.transaction_header_id,
3945 -- x_reserve_name,
3946 -- 'CR'
3947 -- );
3948 -- FETCH c_sum_adjustments INTO x_adj_cost;
3949 -- CLOSE c_sum_adjustments;
3950 -- x_adj_cost_retired := x_adjustment_amount - x_adj_cost;
3951
3952 -- x_adjustment_amount := 0;
3953 -- x_adj_cost := 0;
3954
3955 OPEN c_sum_adjustments (tr.asset_id,
3956 x_corporate_book,
3957 tr.source_transaction_header_id,
3958 x_reserve_name,
3959 'DR'
3960 );
3961 FETCH c_sum_adjustments INTO x_adjustment_amount;
3962 CLOSE c_sum_adjustments;
3963
3964 OPEN c_sum_adjustments (tr.asset_id,
3965 x_corporate_book,
3966 tr.source_transaction_header_id,
3967 x_reserve_name,
3968 'CR'
3969 );
3970 FETCH c_sum_adjustments INTO x_adj_cost;
3971 CLOSE c_sum_adjustments;
3972
3973 IF (x_adj_cost_retired <> 0) THEN
3974 x_factor_1 := (x_adj_cost_retired - x_adjustment_amount + x_adj_cost) / x_adj_cost_retired;
3975 ELSE
3976 x_factor_1 := 0;
3977 END IF;
3978
3979 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
3980 x_char := 'Sum Corp Reserve Retired = ' || to_char(x_adjustment_amount - x_adj_cost);
3981 fnd_file.put_line (FND_FILE.LOG, x_char);
3982 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3983 x_char := 'Sum Adj Reserve = ' || to_char(x_adj_cost_retired);
3984 fnd_file.put_line (FND_FILE.LOG, x_char);
3985 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3986 x_char := 'x_value_4 = ' || to_char(x_value_4);
3987 fnd_file.put_line (FND_FILE.LOG, x_char);
3988 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3989 x_char := 'x_value_5 = ' || to_char(x_value_5);
3990 fnd_file.put_line (FND_FILE.LOG, x_char);
3991 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
3992 END IF;
3993
3994 ----------------------------------------------------------------------------------
3995 -- LER, 18-Jun-99 New code to calculate factors_11/12 used in --
3996 -- calculations of each component of the IA to Acc. Deprn. --
3997 ----------------------------------------------------------------------------------
3998
3999 IF (x_ia_reserve_retired > 0) THEN
4000 --x_value_3 := (x_ia_reserve_retired - (x_deprn_to_cost - x_value_5)) / x_value_4;
4001 ----------------------------------------------------------------------------
4002 --BUG 3865352
4003 ----------------------------------------------------------------------------
4004 IF x_value_4 = 0 THEN
4005 x_value_3 := 0;
4006 ELSE
4007 x_value_3 := (x_ia_reserve_retired - (x_deprn_to_cost - x_value_5)) / x_value_4;
4008 END IF;
4009
4010
4011 x_value_3 := (x_value_4 - x_value_5) * x_value_3;
4012 x_factor_12 := x_value_3 * x_factor_1 / x_ia_reserve_retired ;
4013 x_factor_11 := (x_ia_reserve_retired - x_value_3) * x_factor_1/ x_ia_reserve_retired ;
4014 ELSE
4015 x_factor_11 := 0 ;
4016 x_factor_12 := 0 ;
4017 END IF;
4018
4019 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4020 x_char := 'x_factor_11 = ' || to_char(x_factor_11);
4021 fnd_file.put_line (FND_FILE.LOG, x_char);
4022 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4023 x_char := 'x_factor_12 = ' || to_char(x_factor_12);
4024 fnd_file.put_line (FND_FILE.LOG, x_char);
4025 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4026 END IF;
4027 END IF;
4028 END IF;
4029
4030 -----------------------------------------------------------------------------
4031 -- Find all rows in FA_ADJUSTMENTS for the retirement transaction --
4032 -----------------------------------------------------------------------------
4033
4034 FOR ra IN c_tr_adjustments_no_adj_type (tr.transaction_header_id,
4035 tr.book_type_code,
4036 x_period_counter
4037 ) LOOP
4038
4039 --FA SLA Changes.
4040 IF ra.code_combination_id is null then
4041 l_book_type_code := tr.book_type_code;
4042 RAISE e_ccid_not_found;
4043 END IF;
4044
4045
4046 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4047 x_char := 'Adjustment for Line = ' || to_char(ra.distribution_id) || ' ' || ra.adjustment_type;
4048 fnd_file.put_line (FND_FILE.LOG, x_char);
4049 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4050 END IF;
4051
4052 IF (ra.distribution_id <> x_distribution_id) THEN
4053
4054 -----------------------------------------------------------------------------
4055 -- Add row corresponding to NBV retired due to inflation adjustment --
4056 -----------------------------------------------------------------------------
4057
4058 IF (x_distribution_id > 0) THEN
4059 x_adjustment_amount := x_ia_cost_retired - x_ia_reserve_retired;
4060
4061 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4062 x_char := 'IANBV = ' || to_char(x_adjustment_amount);
4063 fnd_file.put_line (FND_FILE.LOG, x_char);
4064 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4065 END IF;
4066
4067 insert_adjustment (tr.transaction_header_id,
4068 x_global_source,
4069 x_je_ia_retirement,
4070 x_nbv_retired_name,
4071 x_nbv_debit_credit_flag,
4072 x_nbv_retired_ccid,
4073 p_tax_book,
4074 tr.asset_id,
4075 x_adjustment_amount,
4076 x_distribution_id,
4077 NULL,
4078 NULL,
4079 NULL,
4080 x_period_counter,
4081 x_period_counter,
4082 NULL,
4083 NULL,
4084 NULL
4085 );
4086 END IF;
4087
4088 x_ia_cost_retired := 0;
4089 x_ia_reserve_retired := 0;
4090 x_distribution_id := ra.distribution_id;
4091 END IF;
4092
4093 IF ra.adjustment_type IN (x_cip_cost_name,
4094 x_cost_name,
4095 x_reserve_name,
4096 x_expense_name
4097 ) THEN
4098
4099 -----------------------------------------------------------------------------
4100 -- Rows to add due to inflation adjustments --
4101 -- Calculate amount --
4102 -- Built accounting flexfield --
4103 -- Insert row in JL_CO_FA_ADJUSTMENTS --
4104 -----------------------------------------------------------------------------
4105
4106 IF (x_retirement_type = 'O') THEN
4107 x_adjustment_amount := ra.adjustment_amount;
4108
4109 OPEN c_tr_rel_adjustments (tr.source_transaction_header_id,
4110 x_corporate_book,
4111 ra.source_type_code,
4112 ra.adjustment_type,
4113 ra.debit_credit_flag,
4114 ra.distribution_id
4115 );
4116 FETCH c_tr_rel_adjustments INTO x_code_combination_id,
4117 x_adjustment_amount;
4118 CLOSE c_tr_rel_adjustments;
4119 END IF;
4120
4121 IF ra.adjustment_type = x_cip_cost_name THEN
4122 IF (x_retirement_type = 'U') THEN
4123 x_adjustment_amount := round (ra.adjustment_amount * x_factor, x_precision);
4124 ELSE
4125 x_adjustment_amount := round (ra.adjustment_amount - x_adjustment_amount, x_precision);
4126 END IF;
4127
4128 --------------------------------------------------------------------------------
4129 -- LER, 18-Jun-99 Fixed a bug. Add current value to x_ia_cost_retired --
4130 --------------------------------------------------------------------------------
4131
4132 x_ia_cost_retired := x_adjustment_amount + x_ia_cost_retired;
4133
4134 change_account (x_chart_of_accounts_id,
4135 x_apps_short_name,
4136 x_key_flex_code,
4137 x_account_segment,
4138 ra.code_combination_id,
4139 x_ia_cip_cost_segm,
4140 x_delimiter,
4141 x_returned_ccid,
4142 x_error_ccid
4143 );
4144
4145 insert_adjustment (tr.transaction_header_id,
4146 x_global_source,
4147 x_je_ia_cip_retirement,
4148 x_ia_cip_cost_name,
4149 ra.debit_credit_flag,
4150 x_returned_ccid,
4151 p_tax_book,
4152 tr.asset_id,
4153 x_adjustment_amount,
4154 ra.distribution_id,
4155 ra.annualized_adjustment,
4156 NULL,
4157 NULL,
4158 ra.period_counter_adjusted,
4159 ra.period_counter_created,
4160 ra.asset_invoice_id,
4161 NULL,
4162 NULL
4163 );
4164
4165 ELSIF ra.adjustment_type = x_cost_name THEN
4166 IF (x_retirement_type = 'U') THEN
4167 x_adjustment_amount := round (ra.adjustment_amount * x_factor, x_precision);
4168 ELSE
4169 x_adjustment_amount := round (ra.adjustment_amount - x_adjustment_amount, x_precision);
4170 END IF;
4171 x_ia_cost_retired := x_adjustment_amount + x_ia_cost_retired;
4172
4173 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4174 x_char := 'COST = ' || to_char(x_adjustment_amount);
4175 fnd_file.put_line (FND_FILE.LOG, x_char);
4176 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4177 END IF;
4178
4179 change_account (x_chart_of_accounts_id,
4180 x_apps_short_name,
4181 x_key_flex_code,
4182 x_account_segment,
4183 ra.code_combination_id,
4184 x_ia_cost_segm,
4185 x_delimiter,
4186 x_returned_ccid,
4187 x_error_ccid
4188 );
4189
4190 insert_adjustment (tr.transaction_header_id,
4191 x_global_source,
4192 x_je_ia_retirement,
4193 x_ia_cost_name,
4194 ra.debit_credit_flag,
4195 x_returned_ccid,
4196 p_tax_book,
4197 tr.asset_id,
4198 x_adjustment_amount,
4199 ra.distribution_id,
4200 ra.annualized_adjustment,
4201 NULL,
4202 NULL,
4203 ra.period_counter_adjusted,
4204 ra.period_counter_created,
4205 ra.asset_invoice_id,
4206 NULL,
4207 NULL
4208 );
4209
4210 ELSIF ra.adjustment_type = x_reserve_name THEN
4211 IF (x_retirement_type = 'U') THEN
4212 x_adjustment_amount := round (ra.adjustment_amount * x_factor_11, x_precision);
4213 x_ia_reserve := round (ra.adjustment_amount * x_factor_12, x_precision);
4214 ELSE
4215 x_ia_reserve := ra.adjustment_amount - x_adjustment_amount;
4216 x_adjustment_amount := round ((x_ia_reserve * x_factor_11), x_precision);
4217 x_ia_reserve := round ((x_ia_reserve * x_factor_12), x_precision);
4218
4219 -- x_nbv_retired := x_ia_reserve;
4220
4221 END IF;
4222
4223 IF (tr.transaction_type_code <> 'REINSTATEMENT') THEN
4224 x_deprn_to_cost := x_deprn_to_cost - x_adjustment_amount;
4225 END IF;
4226
4227 ----------------------------------------------------------------------------------
4228 -- Bug Fix 1098809 Add x_ia_reserve also to x_ia_reserve_retired --
4229 ----------------------------------------------------------------------------------
4230
4231 x_ia_reserve_retired := x_adjustment_amount + x_ia_reserve + x_ia_reserve_retired;
4232
4233 insert_adjustment (tr.transaction_header_id,
4234 x_global_source,
4235 x_je_std_category_name,
4236 x_reserve_name,
4237 ra.debit_credit_flag,
4238 ra.code_combination_id,
4239 p_tax_book,
4240 tr.asset_id,
4241 x_adjustment_amount,
4242 ra.distribution_id,
4243 ra.annualized_adjustment,
4244 NULL,
4245 NULL,
4246 ra.period_counter_adjusted,
4247 ra.period_counter_created,
4248 ra.asset_invoice_id,
4249 NULL,
4250 NULL
4251 );
4252
4253 change_account (x_chart_of_accounts_id,
4254 x_apps_short_name,
4255 x_key_flex_code,
4256 x_account_segment,
4257 ra.code_combination_id,
4258 x_ia_deprn_reserve_segm,
4259 x_delimiter,
4260 x_returned_ccid,
4261 x_error_ccid
4262 );
4263
4264 insert_adjustment (tr.transaction_header_id,
4265 x_global_source,
4266 x_je_ia_retirement,
4267 x_ia_reserve_name,
4268 ra.debit_credit_flag,
4269 x_returned_ccid,
4270 p_tax_book,
4271 tr.asset_id,
4272 x_ia_reserve,
4273 ra.distribution_id,
4274 ra.annualized_adjustment,
4275 NULL,
4276 NULL,
4277 ra.period_counter_adjusted,
4278 ra.period_counter_created,
4279 ra.asset_invoice_id,
4280 NULL,
4281 NULL
4282 );
4283
4284 END IF;
4285
4286 ELSIF ra.adjustment_type IN (x_nbv_retired_name,
4287 x_reval_amort_name,
4288 x_reval_reserve_name,
4289 x_proceeds_name,
4290 x_removal_cost_name
4291 ) THEN
4292
4293 -----------------------------------------------------------------------------
4294 -- Change Gain/Loss. Reverse the standard rows and create new rows with --
4295 -- the right account. --
4296 -- Get the standard row --
4297 -- Insert row reversing it --
4298 -- Insert new row with right account in JL_CO_FA_ADJUSTMENTS --
4299 -----------------------------------------------------------------------------
4300
4301 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4302 x_char := ra.adjustment_type;
4303 fnd_file.put_line (FND_FILE.LOG, x_char);
4304 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4305 END IF;
4306
4307 IF (x_gain_loss_changed = TRUE) THEN
4308
4309 OPEN c_tr_rel_adjustments (tr.source_transaction_header_id,
4310 x_corporate_book,
4311 ra.source_type_code,
4312 ra.adjustment_type,
4313 ra.debit_credit_flag,
4314 ra.distribution_id
4315 );
4316 FETCH c_tr_rel_adjustments INTO x_code_combination_id,
4317 x_adjustment_amount ;
4318
4319 IF (c_tr_rel_adjustments%FOUND = TRUE) THEN
4320
4321 --FA SLA Changes.
4322 IF x_code_combination_id is null then
4323 l_book_type_code := x_corporate_book;
4324 RAISE e_ccid_not_found;
4325 END IF;
4326
4327
4328
4329 IF (ra.debit_credit_flag = 'DR') THEN
4330 x_debit_credit_flag := 'CR';
4331 ELSE
4332 x_debit_credit_flag := 'DR';
4333 END IF;
4334
4335 insert_adjustment (tr.transaction_header_id,
4336 x_global_source,
4337 x_je_ia_retirement,
4338 ra.adjustment_type,
4339 x_debit_credit_flag,
4340 x_code_combination_id,
4341 p_tax_book,
4342 tr.asset_id,
4343 x_adjustment_amount,
4344 ra.distribution_id,
4345 ra.annualized_adjustment,
4346 NULL,
4347 NULL,
4348 ra.period_counter_adjusted,
4349 ra.period_counter_created,
4350 ra.asset_invoice_id,
4351 NULL,
4352 NULL
4353 );
4354
4355 insert_adjustment (tr.transaction_header_id,
4356 x_global_source,
4357 x_je_ia_retirement,
4358 ra.adjustment_type,
4359 ra.debit_credit_flag,
4360 ra.code_combination_id,
4361 p_tax_book,
4362 tr.asset_id,
4363 x_adjustment_amount,
4364 ra.distribution_id,
4365 ra.annualized_adjustment,
4366 NULL,
4367 NULL,
4368 ra.period_counter_adjusted,
4369 ra.period_counter_created,
4370 ra.asset_invoice_id,
4371 NULL,
4372 NULL
4373 );
4374 END IF;
4375
4376 CLOSE c_tr_rel_adjustments;
4377 END IF;
4378
4379 IF (ra.adjustment_type = x_nbv_retired_name) THEN
4380 x_nbv_retired_ccid := ra.code_combination_id;
4381 x_nbv_debit_credit_flag := ra.debit_credit_flag;
4382 END IF;
4383 END IF;
4384
4385 -----------------------------------------------------------------------------
4386 -- Retiring or Reinstating Technical Appraisal Account Balances --
4387 -- Account balances are full retired or reinstatement --
4388 -- No actions in Partial Retirements --
4389 -----------------------------------------------------------------------------
4390 -- LER, 18-Jun-99 Technical Appraisal Balance is retired only FULL --
4391 -- RETIREMENTS or Reinstatements reinstated FULL --
4392 -- RETIREMENTS. --
4393 ----------------------------------------------------------------------------------
4394
4395 -- IF (tr.transaction_type_code IN ('FULL RETIREMENT',
4396 -- 'REINSTATEMENT')
4397
4398 IF ( (x_retirement_type_code = 'FULL RETIREMENT')
4399 AND ra.adjustment_type IN (x_cost_name,
4400 x_cip_cost_name
4401 ) ) THEN
4402
4403 x_ta_line_amount := round (ra.adjustment_amount * x_ta_factor, x_precision);
4404
4405 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4406 x_char := 'TA adjustment line = ' || to_char(x_ta_line_amount);
4407 fnd_file.put_line (FND_FILE.LOG, x_char);
4408 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4409 END IF;
4410
4411 IF (ra.debit_credit_flag = 'DR') THEN
4412 x_debit_credit_flag := 'CR';
4413 ELSE
4414 x_debit_credit_flag := 'DR';
4415 END IF;
4416
4417 IF (tr.appraisal_balance > 0) THEN
4418
4419 change_account (x_chart_of_accounts_id,
4420 x_apps_short_name,
4421 x_key_flex_code,
4422 x_account_segment,
4423 ra.code_combination_id,
4424 x_ta_revaluation_segm,
4425 x_delimiter,
4426 x_returned_ccid,
4427 x_error_ccid
4428 );
4429
4430 insert_adjustment (tr.transaction_header_id,
4431 x_global_appraisal,
4432 x_je_appraisal,
4433 x_ta_revaluation_name,
4434 ra.debit_credit_flag,
4435 x_returned_ccid,
4436 p_tax_book,
4437 tr.asset_id,
4438 x_ta_line_amount,
4439 ra.distribution_id,
4440 NULL,
4441 NULL,
4442 NULL,
4443 ra.period_counter_adjusted,
4444 ra.period_counter_created,
4445 NULL,
4446 NULL,
4447 NULL
4448 );
4449
4450 change_account (x_chart_of_accounts_id,
4451 x_apps_short_name,
4452 x_key_flex_code,
4453 x_account_segment,
4454 ra.code_combination_id,
4455 x_ta_surplus_segm,
4456 x_delimiter,
4457 x_returned_ccid,
4458 x_error_ccid
4459 );
4460
4461 insert_adjustment (tr.transaction_header_id,
4462 x_global_appraisal,
4463 x_je_appraisal,
4464 x_ta_surplus_name,
4465 x_debit_credit_flag,
4466 x_returned_ccid,
4467 p_tax_book,
4468 tr.asset_id,
4469 x_ta_line_amount,
4470 ra.distribution_id,
4471 NULL,
4472 NULL,
4473 NULL,
4474 ra.period_counter_adjusted,
4475 ra.period_counter_created,
4476 NULL,
4477 NULL,
4478 NULL
4479 );
4480
4481 ELSIF (tr.appraisal_balance < 0) THEN
4482
4483 change_account (x_chart_of_accounts_id,
4484 x_apps_short_name,
4485 x_key_flex_code,
4486 x_account_segment,
4487 ra.code_combination_id,
4488 x_ta_reserve_segm,
4489 x_delimiter,
4490 x_returned_ccid,
4491 x_error_ccid
4492 );
4493
4494 insert_adjustment (tr.transaction_header_id,
4495 x_global_appraisal,
4496 x_je_appraisal,
4497 x_ta_reserve_name,
4498 x_debit_credit_flag,
4499 x_returned_ccid,
4500 p_tax_book,
4501 tr.asset_id,
4502 x_ta_line_amount,
4503 ra.distribution_id,
4504 NULL,
4505 NULL,
4506 NULL,
4507 ra.period_counter_adjusted,
4508 ra.period_counter_created,
4509 NULL,
4510 NULL,
4511 NULL
4512 );
4513
4514 change_account (x_chart_of_accounts_id,
4515 x_apps_short_name,
4516 x_key_flex_code,
4517 x_account_segment,
4518 ra.code_combination_id,
4519 x_ta_reserve_recovery_segm,
4520 x_delimiter,
4521 x_returned_ccid,
4522 x_error_ccid
4523 );
4524
4525 insert_adjustment (tr.transaction_header_id,
4526 x_global_appraisal,
4527 x_je_appraisal,
4528 x_ta_recovery_name,
4529 ra.debit_credit_flag,
4530 x_returned_ccid,
4531 p_tax_book,
4532 tr.asset_id,
4533 x_ta_line_amount,
4534 ra.distribution_id,
4535 NULL,
4536 NULL,
4537 NULL,
4538 ra.period_counter_adjusted,
4539 ra.period_counter_created,
4540 NULL,
4541 NULL,
4542 NULL
4543 );
4544 END IF;
4545 END IF;
4546
4547 END LOOP;
4548
4549 -----------------------------------------------------------------------------
4550 -- Add row corresponding to NBV retired due to inflation adjustment --
4551 -----------------------------------------------------------------------------
4552
4553 -- x_adjustment_amount := x_ia_cost_retired - x_ia_reserve_retired - x_nbv_retired;
4554 x_adjustment_amount := x_ia_cost_retired - x_ia_reserve_retired;
4555
4556 insert_adjustment (tr.transaction_header_id,
4557 x_global_source,
4558 x_je_ia_retirement,
4559 x_nbv_retired_name,
4560 x_nbv_debit_credit_flag,
4561 x_nbv_retired_ccid,
4562 p_tax_book,
4563 tr.asset_id,
4564 x_adjustment_amount,
4565 x_distribution_id,
4566 NULL,
4567 NULL,
4568 NULL,
4569 x_period_counter,
4570 x_period_counter,
4571 NULL,
4572 NULL,
4573 NULL
4574 );
4575 END IF;
4576
4577 -----------------------------------------------------------------------------
4578 -- End of transaction tracked --
4579 -- Update Depreciation to Cost Inflation Adjustments --
4580 -----------------------------------------------------------------------------
4581
4582 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4583 x_char := 'Update Deprn_to_cost = ' || to_char(x_deprn_to_cost);
4584 fnd_file.put_line (FND_FILE.LOG, x_char);
4585 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4586 END IF;
4587
4588 UPDATE fa_books
4589 SET global_attribute7 = fnd_number.number_to_canonical(x_deprn_to_cost)
4590 WHERE rowid = tr.book_rowid ;
4591
4592 END LOOP;
4593
4594 -----------------------------------------------------------------------------
4595 -- Procedure to calculate the Depreciation to Cost Inflation Adjustments --
4596 -----------------------------------------------------------------------------
4597
4598 x_category_id := 0;
4599 x_global_source := 'DEPRECIATION';
4600
4601 -----------------------------------------------------------------------------
4602 -- Assets for tracking --
4603 -----------------------------------------------------------------------------
4604
4605 FOR ad IN c_assets_depreciated (p_tax_book,
4606 x_period_counter,
4607 x_deprn_date
4608 ) LOOP
4609
4610 -----------------------------------------------------------------------------
4611 -- Write asset and transaction number on log file --
4612 -----------------------------------------------------------------------------
4613
4614 fnd_message.set_name ('JL', 'JL_CO_FA_TRANSACTION');
4615 fnd_message.set_token ('ASSET', ad.asset_number);
4616 fnd_message.set_token ('TRANSACTION_ID', NULL);
4617 fnd_message.set_token ('TRANSACTION_TYPE', 'DEPRECIATION');
4618 fnd_file.put_line (1, fnd_message.get);
4619
4620 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4621 x_char := 'Transaction Header Id In = ' || to_char(ad.transaction_header_id_in);
4622 fnd_file.put_line (FND_FILE.LOG, x_char);
4623 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4624 END IF;
4625
4626 -----------------------------------------------------------------------------
4627 -- Asset category parameters --
4628 -----------------------------------------------------------------------------
4629
4630 IF (ad.category_id <> x_category_id) THEN
4631 x_category_id := ad.category_id;
4632
4633 OPEN c_reserve_acct (x_category_id,
4634 p_tax_book
4635 ) ;
4636 FETCH c_reserve_acct INTO x_deprn_reserve_ccid,
4637 x_deprn_reserve_segm;
4638 CLOSE c_reserve_acct;
4639 END IF;
4640
4641 x_deprn_to_cost := ad.deprn_to_cost;
4642
4643 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4644 x_char := 'Deprn_to_Cost Inicial = ' || to_char(x_deprn_to_cost);
4645 fnd_file.put_line (FND_FILE.LOG, x_char);
4646 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4647 END IF;
4648
4649 -----------------------------------------------------------------------------
4650 -- Get distribution lines depreciated for the asset --
4651 -----------------------------------------------------------------------------
4652
4653 FOR ld IN c_lines_depreciated (p_tax_book,
4654 x_period_counter,
4655 ad.asset_id,
4656 x_corporate_book
4657 ) LOOP
4658
4659 -- IF (ld.adj_deprn_adjustment_amount = 0) THEN
4660 -- x_adjustment_amount := ld.adj_deprn_amount - ld.corp_deprn_amount;
4661 -- ELSE
4662 x_adjustment_amount := (ld.adj_deprn_amount - ld.adj_deprn_adjustment_amount) - (ld.corp_deprn_amount - ld.corp_deprn_adjustment_amount);
4663 -- END IF;
4664
4665 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4666 x_char := 'adj_deprn_amount = ' || to_char(ld.adj_deprn_amount);
4667 fnd_file.put_line (FND_FILE.LOG, x_char);
4668 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4669 x_char := 'adj_deprn_adjust_amount = ' || to_char(ld.adj_deprn_adjustment_amount);
4670 fnd_file.put_line (FND_FILE.LOG, x_char);
4671 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4672 x_char := 'corp_deprn_amount = ' || to_char(ld.corp_deprn_amount);
4673 fnd_file.put_line (FND_FILE.LOG, x_char);
4674 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4675 x_char := 'corp_deprn_adjust_amount = ' || to_char(ld.corp_deprn_adjustment_amount);
4676 fnd_file.put_line (FND_FILE.LOG, x_char);
4677 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4678 END IF;
4679
4680 x_adjustment_amount := round (x_adjustment_amount, x_precision);
4681 x_deprn_to_cost := x_deprn_to_cost + x_adjustment_amount;
4682
4683 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4684 x_char := 'x_adjustment_amount = ' || to_char(x_adjustment_amount);
4685 fnd_file.put_line (FND_FILE.LOG, x_char);
4686 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4687 x_char := 'x_deprn_to_cost = ' || to_char(x_deprn_to_cost);
4688 fnd_file.put_line (FND_FILE.LOG, x_char);
4689 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4690 END IF;
4691
4692 insert_adjustment (NULL,
4693 x_global_source,
4694 x_je_depreciation,
4695 x_expense_name,
4696 'DR',
4697 ld.code_combination_id,
4698 p_tax_book,
4699 ad.asset_id,
4700 x_adjustment_amount,
4701 ld.distribution_id,
4702 NULL,
4703 NULL,
4704 NULL,
4705 x_period_counter,
4706 x_period_counter,
4707 NULL,
4708 NULL,
4709 NULL
4710 );
4711
4712 fa_gccid_pkg.fafbgcc_proc (p_tax_book,
4713 'DEPRN_RESERVE_ACCT',
4714 ld.code_combination_id,
4715 x_deprn_reserve_segm,
4716 x_deprn_reserve_ccid,
4717 ld.distribution_id,
4718 x_returned_ccid,
4719 x_concat_segs,
4720 x_return_value
4721 );
4722
4723 IF (x_return_value = 0) then
4724 fnd_message.set_name ('JL', 'JL_CO_FA_CCID_NOT_CREATED');
4725 fnd_message.set_token ('ACCOUNT', x_concat_segs);
4726 --Bug 2929483. Missing log message handling has been added.
4727 fnd_file.put_line (FND_FILE.LOG, fnd_message.get);
4728 x_error_ccid := TRUE;
4729
4730 ELSE
4731 insert_adjustment (NULL,
4732 x_global_source,
4733 x_je_depreciation,
4734 x_reserve_name,
4735 'CR',
4736 x_returned_ccid,
4737 p_tax_book,
4738 ad.asset_id,
4739 x_adjustment_amount,
4740 ld.distribution_id,
4741 NULL,
4742 NULL,
4743 NULL,
4744 x_period_counter,
4745 x_period_counter,
4746 NULL,
4747 NULL,
4748 NULL
4749 );
4750 END IF;
4751 END LOOP;
4752
4753 -----------------------------------------------------------------------------
4754 -- End of procedure to calculate the Deprn. To Cost Infln. Adjustments --
4755 -- Update Depreciation to Cost Inflation Adjustments in GDF7 --
4756 -----------------------------------------------------------------------------
4757
4758 IF ( G_LEVEL_STATEMENT >= G_CURRENT_RUNTIME_LEVEL) THEN
4759 x_char := 'Update Deprn_to_cost = ' || to_char(x_deprn_to_cost);
4760 fnd_file.put_line (FND_FILE.LOG, x_char);
4761 FND_LOG.STRING(G_LEVEL_STATEMENT,G_MODULE_NAME||l_api_name, x_char);
4762 END IF;
4763
4764 UPDATE fa_books
4765 SET global_attribute7 = fnd_number.number_to_canonical(x_deprn_to_cost)
4766 WHERE rowid = ad.book_rowid ;
4767
4768 END LOOP;
4769
4770 -----------------------------------------------------------------------------
4771 -- Verify the program error condition --
4772 -----------------------------------------------------------------------------
4773
4774 IF (x_error_ccid = TRUE) THEN
4775 RAISE e_not_finished_by_ccid;
4776 ELSE
4777
4778 -----------------------------------------------------------------------------
4779 -- Update globalization close period counter --
4780 -----------------------------------------------------------------------------
4781
4782 UPDATE fa_book_controls
4783 SET global_attribute5 = x_period_counter
4784 WHERE book_type_code = p_tax_book;
4785
4786 COMMIT WORK;
4787 END IF;
4788
4789 IF ( G_LEVEL_PROCEDURE >= G_CURRENT_RUNTIME_LEVEL) THEN
4790 FND_LOG.STRING(G_LEVEL_PROCEDURE,G_MODULE_NAME||l_api_name||'.END',G_PKG_NAME||': '||l_api_name||'(-)');
4791 END IF;
4792
4793 EXCEPTION
4794
4795 WHEN e_ccid_not_found THEN
4796 fnd_message.set_name ('JL', 'JL_CO_GENERAL_ERROR');
4797 fnd_file.put_line (1, fnd_message.get);
4798 x_char := 'No Code Combination ID has been found. The Create Accounting Program needs to be run for the Book '
4799 || l_book_type_code ||' and the period '|| x_period_name;
4800 fnd_file.put_line (FND_FILE.LOG, x_char);
4801 ROLLBACK;
4802 call_status := fnd_concurrent.set_completion_status('ERROR','');
4803 RAISE_APPLICATION_ERROR (-20000, x_char);
4804
4805
4806
4807 WHEN e_period_was_closed THEN
4808 fnd_message.set_name ('JL', 'JL_CO_FA_SAME_AS_PERIOD_CLOSED');
4809 fnd_message.set_token ('PERIOD', x_period_name);
4810 fnd_message.set_token ('BOOK', p_tax_book);
4811 fnd_file.put_line (fnd_file.log, fnd_message.get);
4812 fnd_file.put_line (1, fnd_message.get);
4813 ROLLBACK;
4814 call_status := fnd_concurrent.set_completion_status('ERROR','');
4815 /*
4816 RAISE_APPLICATION_ERROR (err_num, err_msg);
4817 */
4818
4819 WHEN e_not_finished_by_ccid THEN
4820 fnd_message.set_name ('JL', 'JL_CO_FA_NOT_FINISHED_BY_CCID');
4821 fnd_file.put_line (1, fnd_message.get);
4822 ROLLBACK;
4823 call_status := fnd_concurrent.set_completion_status('ERROR','');
4824 /*
4825 RAISE_APPLICATION_ERROR (err_num, err_msg);
4826 */
4827
4828 WHEN OTHERS THEN
4829 fnd_message.set_name ('JL', 'JL_CO_FA_GENERAL_ERROR');
4830 fnd_file.put_line (1, fnd_message.get);
4831 err_num := SQLCODE;
4832 err_msg := substr (SQLERRM, 1, 190);
4833 ROLLBACK;
4834 err_msg := to_char(err_num) || err_msg;
4835 RAISE_APPLICATION_ERROR (-20000, err_msg);
4836
4837 END account_transactions;
4838
4839 ----------------------------------------------------------------------------
4840 -- PROCEDURE --
4841 -- extract_account --
4842 -- --
4843 -- DESCRIPTION --
4844 -- This procedure extracts the natural account from an input AFF --
4845 -- --
4846 -- PARAMETERS --
4847 -- p_chart_of_accounts_id Identification of accounting structure --
4848 -- p_apps_short_name Short name of the application --
4849 -- p_key_flex_code Code identification of the key flexfield --
4850 -- p_account_segment_num Number of the account segment into AFF --
4851 -- p_account_ccid Default CCID of the account required --
4852 -- p_account_segment Natural account segment --
4853 ----------------------------------------------------------------------------
4854 -- LER, 18-Jun-99 Procedure is not more used in Release 11.5 --
4855 -- because natural account segment will be --
4856 -- directly stored in FA_BOOK_CONTROLS.GDF --
4857 ----------------------------------------------------------------------------
4858
4859 PROCEDURE extract_account (p_chart_of_accounts_id IN NUMBER,
4860 p_apps_short_name IN VARCHAR2,
4861 p_key_flex_code IN VARCHAR2,
4862 p_account_segment_num IN NUMBER,
4863 p_account_ccid IN VARCHAR2,
4864 p_account_segment OUT NOCOPY VARCHAR2
4865 )
4866 IS
4867 x_num_segs NUMBER ;
4868 x_segs FND_FLEX_EXT.SegmentArray ;
4869 x_dummy BOOLEAN ;
4870
4871 BEGIN
4872
4873 ------------------------------------------------------------------------
4874 -- Get required segments from distribution line CCID --
4875 ------------------------------------------------------------------------
4876
4877 x_dummy := fnd_flex_ext.get_segments (p_apps_short_name,
4878 p_key_flex_code,
4879 p_chart_of_accounts_id,
4880 p_account_ccid,
4881 x_num_segs,
4882 x_segs
4883 );
4884
4885 p_account_segment := x_segs (p_account_segment_num);
4886
4887 END extract_account;
4888
4889 ----------------------------------------------------------------------------
4890 -- PROCEDURE --
4891 -- change_account --
4892 -- --
4893 -- DESCRIPTION --
4894 -- This procedure insert the natural account segment in the input AFF --
4895 -- and find or generate the CCID for it. --
4896 -- --
4897 -- PARAMETERS --
4898 -- p_chart_of_accounts_id Identification of accounting structure --
4899 -- p_apps_short_name Short name of the application --
4900 -- p_key_flex_code Code identification of the key flexfield --
4901 -- p_num_segment Number of the natural account segment --
4902 -- p_account_ccid CCID of the original account flexfield --
4903 -- p_account_segment New natural account segment --
4904 -- p_delimiter Delimiter character used by application --
4905 -- p_returned_ccid CCID find or generated by procedure --
4906 -- p_error_ccid Error flag if a new CCID can not be inserted --
4907 ----------------------------------------------------------------------------
4908
4909 PROCEDURE change_account (p_chart_of_accounts_id IN NUMBER,
4910 p_apps_short_name IN VARCHAR2,
4911 p_key_flex_code IN VARCHAR2,
4912 p_num_segment IN NUMBER,
4913 p_account_ccid IN NUMBER,
4914 p_account_segment IN VARCHAR2,
4915 p_delimiter IN VARCHAR2,
4916 p_returned_ccid OUT NOCOPY NUMBER,
4917 p_error_ccid IN OUT NOCOPY BOOLEAN
4918 )
4919 IS
4920 x_num_segs NUMBER ;
4921 x_segs FND_FLEX_EXT.SegmentArray ;
4922 x_flexfield VARCHAR2 (2000);
4923 x_dummy BOOLEAN ;
4924
4925
4926 BEGIN
4927
4928 ------------------------------------------------------------------------
4929 -- Get required segments from distribution line CCID --
4930 ------------------------------------------------------------------------
4931
4932 x_dummy := fnd_flex_ext.get_segments (p_apps_short_name,
4933 p_key_flex_code,
4934 p_chart_of_accounts_id,
4935 p_account_ccid,
4936 x_num_segs,
4937 x_segs
4938 );
4939
4940 ------------------------------------------------------------------------
4941 -- Insert the natural account into input distribution lines CCID --
4942 ------------------------------------------------------------------------
4943
4944 x_segs (p_num_segment) := p_account_segment;
4945
4946 ------------------------------------------------------------------------
4947 -- Find or generate the CCID for the new accounting flexfield --
4948 ------------------------------------------------------------------------
4949
4950 x_dummy := fnd_flex_ext.get_combination_id (p_apps_short_name,
4951 p_key_flex_code,
4952 p_chart_of_accounts_id,
4953 sysdate,
4954 x_num_segs,
4955 x_segs,
4956 p_returned_ccid
4957 );
4958 IF (x_dummy = FALSE) then
4959 x_flexfield := fnd_flex_ext.concatenate_segments (x_num_segs,
4960 x_segs,
4961 p_delimiter
4962 );
4963 fnd_message.set_name ('JL', 'JL_CO_FA_CCID_NOT_CREATED');
4964 fnd_message.set_token ('ACCOUNT', x_flexfield);
4965 --Bug 2929483. Missing log message handling has been added.
4966 fnd_file.put_line(FND_FILE.LOG,fnd_message.get);
4967 p_error_ccid := TRUE;
4968 END IF;
4969
4970 END change_account;
4971
4972 ----------------------------------------------------------------------------
4973 -- PROCEDURE --
4974 -- insert_adjustment --
4975 -- --
4976 -- DESCRIPTION --
4977 -- Insert a row in the table JL_CO_FA_ADJUSTMENT --
4978 -- --
4979 -- PARAMETERS --
4980 -- p_transaction_header_id --
4981 -- p_source_type_code --
4982 -- p_je_category_name --
4983 -- p_adjustment_type --
4984 -- p_debit_credit_flag --
4985 -- p_code_combination_id --
4986 -- p_book_type_code --
4987 -- p_asset_id --
4988 -- p_adjustment_amount --
4989 -- p_distribution_id --
4990 -- p_annualized_adjustment --
4991 -- p_je_header_reference_id --
4992 -- p_sequence_line --
4993 -- p_period_counter_adjusted --
4994 -- p_period_counter_created --
4995 -- p_asset_invoice_id --
4996 -- p_reference --
4997 -- p_posting_flag --
4998 ----------------------------------------------------------------------------
4999
5000 PROCEDURE insert_adjustment (p_transaction_header_id IN jl_co_fa_adjustments.transaction_header_id%TYPE,
5001 p_source_type_code IN jl_co_fa_adjustments.source_type_code%TYPE,
5002 p_je_category_name IN jl_co_fa_adjustments.je_category_name%TYPE,
5003 p_adjustment_type IN jl_co_fa_adjustments.adjustment_type%TYPE,
5004 p_debit_credit_flag IN jl_co_fa_adjustments.debit_credit_flag%TYPE,
5005 p_code_combination_id IN jl_co_fa_adjustments.code_combination_id%TYPE,
5006 p_book_type_code IN jl_co_fa_adjustments.book_type_code%TYPE,
5007 p_asset_id IN jl_co_fa_adjustments.asset_id%TYPE,
5008 p_adjustment_amount IN jl_co_fa_adjustments.adjustment_amount%TYPE,
5009 p_distribution_id IN jl_co_fa_adjustments.distribution_id%TYPE,
5010 p_annualized_adjustment IN jl_co_fa_adjustments.annualized_adjustment%TYPE,
5011 p_je_header_reference_id IN jl_co_fa_adjustments.je_header_reference_id%TYPE,
5012 p_sequence_line IN jl_co_fa_adjustments.sequence_line%TYPE,
5013 p_period_counter_adjusted IN jl_co_fa_adjustments.period_counter_adjusted%TYPE,
5014 p_period_counter_created IN jl_co_fa_adjustments.period_counter_created%TYPE,
5015 p_asset_invoice_id IN jl_co_fa_adjustments.asset_invoice_id%TYPE,
5016 p_reference IN jl_co_fa_adjustments.reference%TYPE,
5017 p_posting_flag IN jl_co_fa_adjustments.posting_flag%TYPE
5018 )
5019 IS
5020
5021 x_adjustment_amount NUMBER;
5022 x_debit_credit_flag fa_adjustments.debit_credit_flag%TYPE;
5023 call_status BOOLEAN;
5024 l_original_cost NUMBER;
5025
5026
5027 BEGIN
5028
5029 IF (p_adjustment_amount <> 0) THEN
5030
5031 --------------------------------------------------------------------------------
5032 -- Bug 4758713. Assets with Negative cost are allowed. When inflation amount
5033 -- is a Credit to accoumulated depreciation, this value shoud have
5034 -- been displayed a negative value.
5035 --------------------------------------------------------------------------------
5036
5037 --Bug 4758713. Retrieves the original cost to verify if the asset has negative cost.
5038 BEGIN
5039 SELECT original_cost
5040 INTO l_original_cost
5041 FROM FA_BOOKS
5042 WHERE book_type_code = p_book_type_code
5043 AND asset_id = p_asset_id;
5044 EXCEPTION
5045 WHEN OTHERS THEN
5046 --If exception occurs, we assume orignal cost as zero (positive).
5047 l_original_cost := 0;
5048 END;
5049
5050 --Bug 4758713. If asset has negative cost do not flip the flags DR and CR or sign.
5051 IF l_original_cost >= 0 THEN
5052 IF (p_adjustment_amount > 0) THEN
5053 x_adjustment_amount := p_adjustment_amount;
5054 x_debit_credit_flag := p_debit_credit_flag;
5055 ELSE
5056 x_adjustment_amount := - p_adjustment_amount;
5057 IF (p_debit_credit_flag = 'DR') THEN
5058 x_debit_credit_flag := 'CR';
5059 ELSE
5060 x_debit_credit_flag := 'DR';
5061 END IF;
5062 END IF;
5063 ELSE
5064 x_adjustment_amount := p_adjustment_amount;
5065 x_debit_credit_flag := p_debit_credit_flag;
5066 END IF;
5067
5068 IF p_code_combination_id IS NOT NULL THEN
5069 INSERT INTO jl_co_fa_adjustments
5070 (transaction_header_id,
5071 source_type_code,
5072 je_category_name,
5073 adjustment_type,
5074 debit_credit_flag,
5075 code_combination_id,
5076 book_type_code,
5077 asset_id,
5078 adjustment_amount,
5079 distribution_id,
5080 annualized_adjustment,
5081 je_header_reference_id,
5082 sequence_line,
5083 period_counter_adjusted,
5084 period_counter_created,
5085 asset_invoice_id,
5086 reference,
5087 posting_flag,
5088 created_by,
5089 creation_date,
5090 last_updated_by,
5091 last_update_date,
5092 last_update_login,
5093 request_id,
5094 program_application_id,
5095 program_id,
5096 program_update_date
5097 )
5098 VALUES (p_transaction_header_id,
5099 p_source_type_code,
5100 p_je_category_name,
5101 p_adjustment_type,
5102 x_debit_credit_flag,
5103 p_code_combination_id,
5104 p_book_type_code,
5105 p_asset_id,
5106 x_adjustment_amount,
5107 p_distribution_id,
5108 p_annualized_adjustment,
5109 p_je_header_reference_id,
5110 p_sequence_line,
5111 p_period_counter_adjusted,
5112 p_period_counter_created,
5113 p_asset_invoice_id,
5114 p_reference,
5115 p_posting_flag,
5116 x_last_updated_by,
5117 x_sysdate,
5118 x_last_updated_by,
5119 x_sysdate,
5120 x_last_update_login,
5121 x_request_id,
5122 x_program_application_id,
5123 x_program_id,
5124 x_sysdate
5125 );
5126 ELSE
5127 fnd_message.set_name ('JL', 'JL_CO_FA_NOT_FINISHED_BY_CCID');
5128 fnd_file.put_line (FND_FILE.LOG,fnd_message.get);
5129 ROLLBACK;
5130 call_status := fnd_concurrent.set_completion_status('ERROR','');
5131 END IF;
5132
5133 END IF;
5134
5135 END insert_adjustment;
5136
5137 ----------------------------------------------------------------------------
5138 -- End of body package file --
5139 ----------------------------------------------------------------------------
5140
5141 END jl_co_fa_accounting_pkg;