[Home] [Help]
PACKAGE BODY: APPS.FA_INS_ADJUST_PKG
Source
1 PACKAGE BODY FA_INS_ADJUST_PKG as
2 /* $Header: FAXIAJ2B.pls 120.27.12020000.4 2012/11/14 10:05:51 rmandali ship $ */
3
4 g_release number := fa_cache_pkg.fazarel_release;
5
6 -----------------------------------------------------------------------
7 -- adj_ptr is the parameter in the original C-Code. Here adj_ptr is
8 -- global to this package and hence not required to be passed
9 -----------------------------------------------------------------------
10 FUNCTION fadoflx (X_book_type_code in varchar2,
11 X_account_type in varchar2,
12 X_dist_ccid in number,
13 X_spec_ccid in number,
14 X_account in varchar2,
15 X_calculated_ccid out nocopy number,
16 X_gen_ccid_flag in boolean,
17 X_asset_id in number,
18 X_cat_id in out nocopy number,
19 X_distribution_id in number,
20 X_source_type_code in varchar2,
21 p_log_level_rec in fa_api_types.log_level_rec_type
22 ) return boolean is
23
24 h_acct_ccid_col_name varchar2(30);
25 h_account_ccid number;
26 h_mesg_name varchar2(30);
27 h_asset_id number;
28 h_cat_id number;
29 h_calculated_ccid number;
30 h_status varchar2(1);
31
32 BEGIN <<fadoflx>>
33
34 if (p_log_level_rec.statement_level) then
35 FA_DEBUG_PKG.ADD
36 (fname => 'FA_INS_ADJUST_PKG.fadoflx',
37 element => 'Dist Ccid in fadoflx is',
38 value => X_dist_ccid,
39 p_log_level_rec => p_log_level_rec);
40 end if;
41
42 -- if X_gen_ccid_flag=TRUE then call the ccid calculation function to
43 -- determine the ccid, using the account and account type arguments
44 if (X_gen_ccid_flag and
45 G_release = 11) then
46 -- gen ccid
47 h_asset_id := X_asset_id;
48 h_cat_id := 0;
49 h_mesg_name := 'FA_GET_CAT_ID';
50
51 if (X_source_type_code <> 'RECLASS') then
52 -- reclass
53 SELECT asset_category_id
54 INTO h_cat_id
55 FROM fa_additions_b
56 WHERE asset_id=h_asset_id;
57
58 X_cat_id := h_cat_id;
59 end if; -- Reclass
60
61 -- replace direct fetch with call to cache
62 -- for reducing db hits
63
64 if not fa_cache_pkg.fazccb
65 (X_book => X_book_type_code,
66 X_cat_id => X_cat_id, p_log_level_rec => p_log_level_rec) then
67 FA_SRVR_MSG.ADD_MESSAGE
68 (NAME => 'FA_GET_CAT_ID',
69 CALLING_FN => 'FA_INS_ADJUST_PKG.fadoflx', p_log_level_rec => p_log_level_rec);
70 return FALSE;
71 end if;
72
73 if (X_account_type='ASSET_COST_ACCT') then
74 h_account_ccid := fa_cache_pkg.fazccb_record.asset_cost_account_ccid;
75 elsif (X_account_type='ASSET_CLEARING_ACCT') then
76 h_account_ccid := fa_cache_pkg.fazccb_record.asset_clearing_account_ccid;
77 elsif (X_account_type='CIP_COST_ACCT') then
78 h_account_ccid := fa_cache_pkg.fazccb_record.wip_cost_account_ccid;
79 elsif (X_account_type='CIP_CLEARING_ACCT') then
80 h_account_ccid := fa_cache_pkg.fazccb_record.wip_clearing_account_ccid;
81 elsif (X_account_type='REVAL_RESERVE_ACCT') then
82 h_account_ccid := fa_cache_pkg.fazccb_record.reval_reserve_account_ccid;
83 elsif (X_account_type='REVAL_AMORTIZATION_ACCT') then
84 h_account_ccid := fa_cache_pkg.fazccb_record.reval_amort_account_ccid;
85 elsif (X_account_type='DEPRN_RESERVE_ACCT') then
86 h_account_ccid := fa_cache_pkg.fazccb_record.reserve_account_ccid;
87 elsif (X_account_type='BONUS_DEPRN_RESERVE_ACCT') then
88 h_account_ccid := fa_cache_pkg.fazccb_record.bonus_reserve_acct_ccid;
89 elsif (X_account_type='IMPAIR_EXPENSE_ACCT') then
90 h_account_ccid := fa_cache_pkg.fazccb_record.impair_expense_account_ccid;
91 elsif (X_account_type='IMPAIR_RESERVE_ACCT') then
92 h_account_ccid := fa_cache_pkg.fazccb_record.impair_reserve_account_ccid;
93 elsif (X_account_type='REVAL_LOSS_ACCT') then
94 h_account_ccid := fa_cache_pkg.fazccb_record.reval_loss_account_ccid;
95 else
96 h_account_ccid := 0;
97 end if;
98
99 if (not FA_GCCID_PKG.fafbgcc
100 (X_book_type_code => X_book_type_code,
101 X_fn_trx_code => X_account_type,
102 X_dist_ccid => X_dist_ccid,
103 X_acct_segval => X_account,
104 X_account_ccid => h_account_ccid,
105 X_distribution_id => X_distribution_id,
106 X_rtn_ccid => h_calculated_ccid, p_log_level_rec => p_log_level_rec)) then
107 h_mesg_name := 'FA_GET_ACCOUNT_CCID';
108 FA_SRVR_MSG.ADD_MESSAGE
109 (NAME => 'FA_GET_ACCOUNT_CCID',
110 CALLING_FN => 'FA_INS_ADJUST_PKG.fadoflx', p_log_level_rec => p_log_level_rec);
111 return FALSE;
112 end if;
113
114 X_calculated_ccid := h_calculated_ccid;
115 if (p_log_level_rec.statement_level) then
116 FA_DEBUG_PKG.ADD (
117 'FA_INS_ADJUST_PKG.fadoflx',
118 'h_calc_ccid',
119 h_calculated_ccid, p_log_level_rec => p_log_level_rec);
120 end if;
121 elsif (X_gen_ccid_flag = TRUE and
122 G_release <> 11) then
123
124 -- SLA: no longer gen the ccid, leave null
125 X_calculated_ccid := NULL;
126
127 elsif (X_spec_ccid <> 0) then
128 -- gen ccid
129 X_calculated_ccid := X_spec_ccid;
130 if (p_log_level_rec.statement_level) then
131 FA_DEBUG_PKG.ADD (
132 'FA_INS_ADJUST_PKG.fadoflx',
133 'h_calc_ccid',
134 X_spec_ccid, p_log_level_rec => p_log_level_rec);
135 end if;
136 elsif (G_release = 11) then
137 X_calculated_ccid := X_dist_ccid;
138 else
139 X_calculated_ccid := null; -- SLA: formerly X_dist_ccid;
140 end if;
141 return TRUE;
142
143 EXCEPTION
144 WHEN OTHERS then
145 FA_SRVR_MSG.ADD_SQL_ERROR
146 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoflx',
147 p_log_level_rec => p_log_level_rec);
148 return FALSE;
149 END fadoflx;
150
151 --------------------------------------------------------------------------
152
153 FUNCTION factotp (total_amount out nocopy number,
154 adjustment_amount in number,
155 p_log_level_rec in fa_api_types.log_level_rec_type
156 ) return boolean is
157
158 h_debug_str varchar2(255);
159 h_total_amount number;
160 h_current_cost number;
161
162 BEGIN <<factotp>>
163 -- Calculate the total_amount to prorate based on the
164 -- adjustment_type.
165 if (not adj_ptr.leveling_flag) then
166 -- If the leveling_flag is off, then we just set
167 -- total_amount to the raw adjustment_amount
168 -- h_total_amount := adj_ptr.adjustment_amount;
169 h_total_amount := adjustment_amount;
170 elsif (adj_ptr.adjustment_type = 'COST' OR
171 adj_ptr.adjustment_type = 'CIP COST') then
172 -- Get the current FA_BOOKS.COST value
173 -- if (not fagetcc(X_cost =>h_current_cost) then
174 -- return FALSE;
175 -- end if;
176 -- h_total_amount := h_total_amount + h_current_cost;
177
178 -- Commented out the above to test fix for transfer user exit.
179 -- h_total_amount := adj_ptr.adjustment_amount;
180 h_total_amount := adjustment_amount;
181
182 elsif (adj_ptr.adjustment_type='RESERVE') then
183 h_total_amount := adjustment_amount + dpr_ptr.deprn_rsv;
184 elsif (adj_ptr.adjustment_type='REVAL RESERVE') then
185 h_total_amount := adjustment_amount + dpr_ptr.reval_rsv;
186 elsif (adj_ptr.adjustment_type='BONUS RESERVE') then
187 h_total_amount := adjustment_amount + dpr_ptr.bonus_deprn_rsv;
188 elsif (adj_ptr.adjustment_type='IMPAIR RESERVE') then
189 --changing this for 6866711/8392319
190 h_total_amount := adjustment_amount;
191 elsif (adj_ptr.adjustment_type='CAPITAL ADJ') then
192 h_total_amount := dpr_ptr.capital_adjustment;
193 elsif (adj_ptr.adjustment_type='GENERAL FUND') then
194 h_total_amount := dpr_ptr.general_fund;
195 else
196 h_total_amount := adjustment_amount;
197 end if;
198
199 total_amount := h_total_amount;
200 if (p_log_level_rec.statement_level) then
201 FA_DEBUG_PKG.ADD (
202 'FA_INS_ADJUST_PKG.factotp',
203 'total_amount',
204 h_total_amount,
205 p_log_level_rec => p_log_level_rec);
206 end if;
207 return TRUE;
208
209 END factotp;
210
211 --------------------------------------------------------------------------
212
213 FUNCTION facdamt (adj_dd_amount out nocopy number,
214 p_log_level_rec in fa_api_types.log_level_rec_type
215 ) return boolean is
216
217 h_adj_dd_amount number;
218
219 BEGIN <<facdamt>>
220 -- If the account type is an amount that we track in
221 -- FA_DEPRN_DETAIL, then figure out the detail_amount;
222 -- For those account types that we do not track
223 -- (ie DEPRN_EXPENSE), the detail amount is
224 -- set to zero.
225 if (not adj_ptr.leveling_flag) then
226 -- Leveling is turned off;adj_dd_amount should be zero here
227 null;
228 end if;
229
230 if (adj_ptr.adjustment_type='COST') then
231 h_adj_dd_amount := dpr_ptr.cost;
232 elsif (adj_ptr.adjustment_type='CIP COST') then
233 h_adj_dd_amount := dpr_ptr.cost;
234 elsif (adj_ptr.adjustment_type='RESERVE') then
235 h_adj_dd_amount := dpr_ptr.deprn_rsv;
236 elsif (adj_ptr.adjustment_type='REVAL RESERVE') then
237 h_adj_dd_amount := dpr_ptr.reval_rsv;
238 elsif (adj_ptr.adjustment_type='BONUS RESERVE') then
239 h_adj_dd_amount := dpr_ptr.bonus_deprn_rsv;
240 elsif (adj_ptr.adjustment_type='IMPAIR RESERVE') then
241 h_adj_dd_amount := dpr_ptr.impairment_rsv;
242 elsif (adj_ptr.adjustment_type='CAPITAL ADJ') then
243 h_adj_dd_amount := dpr_ptr.capital_adjustment;
244 elsif (adj_ptr.adjustment_type='GENERAL FUND') then
245 h_adj_dd_amount := dpr_ptr.general_fund;
246 else
247 h_adj_dd_amount := 0;
248 end if;
249
250 adj_dd_amount := h_adj_dd_amount;
251 if (p_log_level_rec.statement_level) then
252 FA_DEBUG_PKG.ADD
253 (fname => 'FA_INS_ADJUST_PKG.facdamt',
254 element => 'h_adj_dd_amount',
255 value => h_adj_dd_amount,
256 p_log_level_rec => p_log_level_rec);
257 end if;
258 return TRUE;
259
260 EXCEPTION
261 WHEN OTHERS then
262 FA_SRVR_MSG.ADD_SQL_ERROR
263 (CALLING_FN => 'FA_INS_ADJUST_PKG.facdamt',
264 p_log_level_rec => p_log_level_rec);
265 return FALSE;
266 END facdamt;
267
268 ----------------------------------------------------------------
269
270 FUNCTION fagetcc (X_cost out nocopy number,
271 p_log_level_rec in fa_api_types.log_level_rec_type
272 ) return boolean is
273
274 h_mesg_name varchar2(50);
275 h_asset_id number;
276 h_book FA_BOOKS.Book_Type_Code%TYPE;
277 h_cost number;
278
279 BEGIN <<fagetcc>>
280
281 h_asset_id := adj_ptr.asset_id;
282 h_book := adj_ptr.book_type_code;
283 h_mesg_name := 'FA_TFR_NO_BOOKS_ROW';
284
285 SELECT cost
286 INTO h_cost
287 FROM FA_BOOKS
288 WHERE asset_id = h_asset_id
289 AND book_type_code = h_book
290 AND date_ineffective is null;
291
292 X_cost := h_cost;
293
294 return TRUE;
295
296 EXCEPTION
297 WHEN NO_DATA_FOUND then
298 FA_SRVR_MSG.ADD_MESSAGE
299 (NAME => h_mesg_name,
300 CALLING_FN => 'FA_INS_ADJUST_PKG.fagetcc',
301 p_log_level_rec => p_log_level_rec);
302 return FALSE;
303 WHEN OTHERS then
304 FA_SRVR_MSG.ADD_SQL_ERROR
305 (CALLING_FN => 'FA_INS_ADJUST_PKG.fagetcc',
306 p_log_level_rec => p_log_level_rec);
307 return FALSE;
308
309 END fagetcc;
310
311 -----------------------------------------------------------------------
312 FUNCTION fainajc(X_flush_mode boolean,
313 X_mode boolean,
314 X_last_update_date date default sysdate,
315 X_last_updated_by number default -1,
316 X_last_update_login number default -1,
317 p_log_level_rec in fa_api_types.log_level_rec_type
318 ) return boolean is
319
320 h_max_cache_rows number := FA_ADJUST_TYPE_PKG.MAX_ADJ_CACHE_ROWS;
321 h_last_updated_by number;
322 h_last_update_login number;
323 h_mesg_name varchar2(30);
324 h_num_rows number;
325 h_i number;
326 h_j number;
327
328 BEGIN <<fainajc>>
329
330 -- Get the standard WHO columns -
331 h_last_updated_by := X_last_updated_by;
332 h_last_update_login := X_last_update_login;
333
334 if (X_flush_mode=FALSE) then
335 -- Test if the cache is full;
336 -- if MAX_ADJ_CACHE_ROWS = cache_index, then recursively
337 -- call this function fainajc() with flush_mode = TRUE.
338 if (h_cache_index > h_max_cache_rows OR h_cache_index < 0) then
339 -- error: we're out of bounds on the array
340 -- the cache index should always be 1 to MAX_ADJ_CACHE_ROWS
341 h_mesg_name := 'FA_INS_ADJ_MAX_ROWS';
342 raise NO_DATA_FOUND;
343 elsif (h_cache_index=h_max_cache_rows) then
344 -- The cache is full; we must dump it out.
345 -- "Full" means we're at cache_index > MAX_ADJ_CACHE_ROWS
346 h_mesg_name := 'FA_INS_ADJ_CANT_INSERT';
347 h_num_rows := h_cache_index;
348
349 -- BUG# 1823498 MRC changes
350 -- transfers and reclasses will be calling this directly
351 -- so using the GL SOB profile retrieved above, we need to
352 -- derive which table to insert into
353 -- -- bridgway 06/20/01
354
355 if (h_mrc_sob_type_code = 'R') then
356 FOR h_i in 1..h_num_rows LOOP
357 INSERT INTO FA_MC_ADJUSTMENTS
358 (set_of_books_id,
359 transaction_header_id,
360 asset_invoice_id,
361 source_type_code,
362 adjustment_type,
363 debit_credit_flag,
364 code_combination_id,
365 book_type_code,
366 period_counter_created,
367 asset_id,
368 adjustment_amount,
369 period_counter_adjusted,
370 distribution_id,
371 annualized_adjustment,
372 deprn_override_flag,
373 last_update_date,
374 last_updated_by,
375 last_update_login,
376 track_member_flag,
377 adjustment_line_id,
378 source_dest_code,
379 source_line_id,
380 converted_flag,
381 insertion_order)
382 VALUES (adj_table(h_i).set_of_books_id,
383 adj_table(h_i).transaction_header_id,
384 adj_table(h_i).asset_invoice_id,
385 adj_table(h_i).source_type_code,
386 adj_table(h_i).adjustment_type,
387 adj_table(h_i).debit_credit_flag,
388 adj_table(h_i).code_combination_id,
389 adj_table(h_i).book_type_code,
390 adj_table(h_i).period_counter_created,
391 adj_table(h_i).asset_id,
392 adj_table(h_i).adjustment_amount,
393 adj_table(h_i).period_counter_adjusted,
394 adj_table(h_i).distribution_id,
395 adj_table(h_i).annualized_adjustment,
396 adj_table(h_i).deprn_override_flag,
397 adj_table(h_i).last_update_date,
398 h_last_updated_by,
399 h_last_update_login,
400 adj_table(h_i).track_member_flag,
401 fa_adjustments_s.nextval, --adjustment_line_id
402 adj_table(h_i).source_dest_code,
403 adj_table(h_i).source_line_id,
404 'C',
405 adj_table(h_i).insertion_order);
406 h_j := h_i;
407 END LOOP;
408 else
409 FOR h_i in 1..h_num_rows LOOP
410 INSERT INTO FA_ADJUSTMENTS
411 (transaction_header_id,
412 asset_invoice_id,
413 source_type_code,
414 adjustment_type,
415 debit_credit_flag,
416 code_combination_id,
417 book_type_code,
418 period_counter_created,
419 asset_id,
420 adjustment_amount,
421 period_counter_adjusted,
422 distribution_id,
423 annualized_adjustment,
424 deprn_override_flag,
425 last_update_date,
426 last_updated_by,
427 last_update_login,
428 track_member_flag,
429 adjustment_line_id,
430 source_dest_code,
431 source_line_id,
432 insertion_order)
433 VALUES (adj_table(h_i).transaction_header_id,
434 adj_table(h_i).asset_invoice_id,
435 adj_table(h_i).source_type_code,
436 adj_table(h_i).adjustment_type,
437 adj_table(h_i).debit_credit_flag,
438 adj_table(h_i).code_combination_id,
439 adj_table(h_i).book_type_code,
440 adj_table(h_i).period_counter_created,
441 adj_table(h_i).asset_id,
442 adj_table(h_i).adjustment_amount,
443 adj_table(h_i).period_counter_adjusted,
444 adj_table(h_i).distribution_id,
445 adj_table(h_i).annualized_adjustment,
446 adj_table(h_i).deprn_override_flag,
447 adj_table(h_i).last_update_date,
448 h_last_updated_by,
449 h_last_update_login,
450 adj_table(h_i).track_member_flag,
451 fa_adjustments_s.nextval, --adjustment_line_id
452 adj_table(h_i).source_dest_code,
453 adj_table(h_i).source_line_id,
454 adj_table(h_i).insertion_order);
455 h_j := h_i;
456 END LOOP;
457 end if; -- end MRC
458
459 if (h_j <> h_cache_index) then
460 h_mesg_name := 'FA_INS_NEQ_CACHE';
461 raise NO_DATA_FOUND;
462 end if;
463
464 h_cache_index := 0;
465 h_num_rows:=h_cache_index;
466
467 end if; -- cache
468
469 -- Bug 2723165 : Added faxrnd rounding func.
470 IF (NOT FA_UTILS_PKG.faxrnd(X_amount => adj_ptr.adjustment_amount,
471 X_book => adj_ptr.book_type_code,
472 X_set_of_books_id => adj_ptr.set_of_books_id,
473 p_log_level_rec => p_log_level_rec)) THEN
474 FA_SRVR_MSG.add_message
475 (CALLING_FN => 'FA_INS_ADJUST_PKG.fainajc',
476 p_log_level_rec => p_log_level_rec);
477 return (FALSE);
478 END IF;
479
480 if (p_log_level_rec.statement_level) then
481 FA_DEBUG_PKG.ADD (
482 fname => 'fainajc',
483 element => 'h_cache_index',
484 value => h_cache_index,
485 p_log_level_rec => p_log_level_rec);
486 FA_DEBUG_PKG.ADD (
487 fname => 'fainajc',
488 element => 'adj amount',
489 value => adj_ptr.adjustment_amount,
490 p_log_level_rec => p_log_level_rec);
491 end if;
492
493 -- Insert the values into the cache now.
494 h_cache_index:=h_cache_index + 1;
495 h_num_rows:=h_cache_index;
496 adj_table(h_cache_index).set_of_books_id :=
497 adj_ptr.set_of_books_id;
498 adj_table(h_cache_index).transaction_header_id :=
499 adj_ptr.transaction_header_id;
500 adj_table(h_cache_index).asset_invoice_id :=
501 adj_ptr.asset_invoice_id;
502 adj_table(h_cache_index).source_type_code :=
503 adj_ptr.source_type_code;
504 adj_table(h_cache_index).adjustment_type :=
505 adj_ptr.adjustment_type;
506 adj_table(h_cache_index).debit_credit_flag :=
507 adj_ptr.debit_credit_flag;
508 adj_table(h_cache_index).code_combination_id :=
509 adj_ptr.code_combination_id;
510 adj_table(h_cache_index).book_type_code :=
511 adj_ptr.book_type_code;
512 adj_table(h_cache_index).period_counter_created :=
513 adj_ptr.period_counter_created;
514 adj_table(h_cache_index).asset_id :=
515 adj_ptr.asset_id;
516 adj_table(h_cache_index).adjustment_amount :=
517 adj_ptr.adjustment_amount;
518 adj_table(h_cache_index).period_counter_adjusted :=
519 adj_ptr.period_counter_adjusted;
520 adj_table(h_cache_index).distribution_id :=
521 adj_ptr.distribution_id;
522 adj_table(h_cache_index).annualized_adjustment :=
523 adj_ptr.annualized_adjustment;
524 adj_table(h_cache_index).deprn_override_flag :=
525 adj_ptr.deprn_override_flag;
526 adj_table(h_cache_index).last_update_date :=
527 adj_ptr.last_update_date;
528 adj_table(h_cache_index).track_member_flag :=
529 adj_ptr.track_member_flag;
530 adj_table(h_cache_index).source_dest_code :=
531 adj_ptr.source_dest_code;
532 adj_table(h_cache_index).source_line_id :=
533 adj_ptr.source_line_id;
534 adj_table(h_cache_index).insertion_order :=
535 adj_ptr.insertion_order;
536
537 if (p_log_level_rec.statement_level) then
538 FA_DEBUG_PKG.ADD (
539 fname => 'fainajc',
540 element => 'Adj Type',
541 value => adj_ptr.adjustment_type,
542 p_log_level_rec => p_log_level_rec);
543 FA_DEBUG_PKG.ADD (
544 fname => 'fainajc',
545 element => 'DR/CR Type',
546 value => adj_ptr.debit_credit_flag,
547 p_log_level_rec => p_log_level_rec);
548 FA_DEBUG_PKG.ADD (
549 fname => 'fainajc',
550 element => 'Code Combination Id',
551 value => adj_ptr.code_combination_id,
552 p_log_level_rec => p_log_level_rec);
553 FA_DEBUG_PKG.ADD (
554 fname => 'fainajc',
555 element => 'book_type_code',
556 value => adj_ptr.book_type_code,
557 p_log_level_rec => p_log_level_rec);
558 FA_DEBUG_PKG.ADD (
559 fname => 'fainajc',
560 element => 'asset id',
561 value => adj_ptr.asset_id,
562 p_log_level_rec => p_log_level_rec);
563 FA_DEBUG_PKG.ADD (
564 fname => 'fainajc',
565 element => 'adj amt',
566 value => adj_ptr.adjustment_amount,
567 p_log_level_rec => p_log_level_rec);
568 FA_DEBUG_PKG.ADD (
569 fname => 'fainajc',
570 element => 'prd ctr cr',
571 value => adj_ptr.period_counter_created,
572 p_log_level_rec => p_log_level_rec);
573 FA_DEBUG_PKG.ADD (
574 fname => 'fainajc',
575 element => 'prd ctr adj',
576 value => adj_ptr.period_counter_adjusted,
577 p_log_level_rec => p_log_level_rec);
578 FA_DEBUG_PKG.ADD (
579 fname => 'fainajc',
580 element => 'deprn_override_flag',
581 value => adj_ptr.deprn_override_flag,
582 p_log_level_rec => p_log_level_rec);
583 FA_DEBUG_PKG.ADD (
584 fname => 'fainajc',
585 element => 'track_member_flag',
586 value => adj_ptr.track_member_flag,
587 p_log_level_rec => p_log_level_rec);
588 end if;
589 elsif (X_flush_mode=TRUE and h_cache_index > 0) then
590 h_num_rows := h_cache_index;
591 h_mesg_name := 'FA_INS_ADJ_CANT_INSERT';
592 if (p_log_level_rec.statement_level) then
593 FA_DEBUG_PKG.ADD (
594 fname => 'fainajc',
595 element => 'Rows in CACHE-INSERT IN TRUE',
596 value => h_num_rows,
597 p_log_level_rec => p_log_level_rec);
598 end if;
599
600 -- BUG# 1823498 MRC changes
601 -- transfers and reclasses will be calling this directly
602 -- so using the GL SOB profile retrieved above, we need to
603 -- derive which table to insert into
604 -- -- bridgway 06/20/01
605
606 if (h_mrc_sob_type_code ='R') then
607 FOR h_i in 1..h_num_rows LOOP
608 INSERT INTO FA_MC_ADJUSTMENTS
609 (set_of_books_id,
610 transaction_header_id,
611 asset_invoice_id,
612 source_type_code,
613 adjustment_type,
614 debit_credit_flag,
615 code_combination_id,
616 book_type_code,
617 period_counter_created,
618 asset_id,
619 adjustment_amount,
620 period_counter_adjusted,
621 distribution_id,
622 annualized_adjustment,
623 deprn_override_flag,
624 last_update_date,
625 last_updated_by,
626 last_update_login,
627 track_member_flag,
628 adjustment_line_id,
629 source_dest_code,
630 source_line_id,
631 converted_flag,
632 insertion_order)
633 VALUES (adj_table(h_i).set_of_books_id,
634 adj_table(h_i).transaction_header_id,
635 adj_table(h_i).asset_invoice_id,
636 adj_table(h_i).source_type_code,
637 adj_table(h_i).adjustment_type,
638 adj_table(h_i).debit_credit_flag,
639 adj_table(h_i).code_combination_id,
640 adj_table(h_i).book_type_code,
641 adj_table(h_i).period_counter_created,
642 adj_table(h_i).asset_id,
643 adj_table(h_i).adjustment_amount,
644 adj_table(h_i).period_counter_adjusted,
645 adj_table(h_i).distribution_id,
646 adj_table(h_i).annualized_adjustment,
647 adj_table(h_i).deprn_override_flag,
648 adj_table(h_i).last_update_date,
649 h_last_updated_by,
650 h_last_update_login,
651 adj_table(h_i).track_member_flag,
652 fa_adjustments_s.nextval, -- adjustment_line_id,
653 adj_table(h_i).source_dest_code,
654 adj_table(h_i).source_line_id,
655 'C',
656 adj_table(h_i).insertion_order);
657 h_j := h_i;
658 END LOOP;
659 else
660 FOR h_i in 1..h_num_rows LOOP
661 INSERT INTO FA_ADJUSTMENTS
662 (transaction_header_id,
663 asset_invoice_id,
664 source_type_code,
665 adjustment_type,
666 debit_credit_flag,
667 code_combination_id,
668 book_type_code,
669 period_counter_created,
670 asset_id,
671 adjustment_amount,
672 period_counter_adjusted,
673 distribution_id,
674 annualized_adjustment,
675 deprn_override_flag,
676 last_update_date,
677 last_updated_by,
678 last_update_login,
679 track_member_flag,
680 adjustment_line_id,
681 source_dest_code,
682 source_line_id,
683 insertion_order)
684 VALUES (adj_table(h_i).transaction_header_id,
685 adj_table(h_i).asset_invoice_id,
686 adj_table(h_i).source_type_code,
687 adj_table(h_i).adjustment_type,
688 adj_table(h_i).debit_credit_flag,
689 adj_table(h_i).code_combination_id,
690 adj_table(h_i).book_type_code,
691 adj_table(h_i).period_counter_created,
692 adj_table(h_i).asset_id,
693 adj_table(h_i).adjustment_amount,
694 adj_table(h_i).period_counter_adjusted,
695 adj_table(h_i).distribution_id,
696 adj_table(h_i).annualized_adjustment,
697 adj_table(h_i).deprn_override_flag,
698 adj_table(h_i).last_update_date,
699 h_last_updated_by,
700 h_last_update_login,
701 adj_table(h_i).track_member_flag,
702 fa_adjustments_s.nextval, -- adjustment_line_id,
703 adj_table(h_i).source_dest_code,
704 adj_table(h_i).source_line_id,
705 adj_table(h_i).insertion_order);
706 h_j := h_i;
707 END LOOP;
708 end if; -- end mrc
709
710 if (h_j <> h_cache_index) then
711 h_mesg_name := 'FA_INS_NEQ_CACHE';
712 raise NO_DATA_FOUND;
713 end if;
714 h_cache_index := 0;
715 h_num_rows:=0;
716 end if; -- X_flush_mode
717 return TRUE;
718
719 EXCEPTION
720 WHEN NO_DATA_FOUND then
721 FA_SRVR_MSG.ADD_MESSAGE
722 (NAME => h_mesg_name,
723 CALLING_FN => 'FA_INS_ADJUST_PKG.fainajc',
724 p_log_level_rec => p_log_level_rec);
725 return FALSE;
726 WHEN OTHERS then
727 FA_SRVR_MSG.ADD_SQL_ERROR
728 (CALLING_FN => 'FA_INS_ADJUST_PKG.fainajc',
729 p_log_level_rec => p_log_level_rec);
730 return FALSE;
731 END fainajc;
732
733 -------------------------------------------------------------------
734
735 FUNCTION fadoact(X_last_update_date date default sysdate,
736 X_last_updated_by number default -1,
737 X_last_update_login number default -1,
738 p_log_level_rec in fa_api_types.log_level_rec_type)
739 return boolean is
740
741 h_dist_book varchar2(30);
742 h_asset_id number;
743 h_success boolean;
744 h_distribution_lines number;
745 h_distribution_id number :=0;
746 h_calculated_ccid number;
747 h_dist_ccid number;
748 h_units_assigned number;
749 h_adj_type varchar2(20);
750 h_mesg_name varchar2(30);
751 h_row_ctr number:=0;
752 h_amount_so_far number :=0;
753 h_amount_to_insert number :=0;
754 h_adj_dd_amount number;
755 h_total_amount number :=0;
756 h_adjustment_amount number :=0;
757 h_temp_adj_amount number :=0;
758 /* DIST ALLOC*/
759 h_books_cost number :=0;
760 h_adj_no_rows number :=0;
761 h_tot_cost number :=0;
762 h_asset_rsv number :=0;
763 h_dist_rsv number :=0;
764 h_new_dist_rsv number := 0;
765 h_amount_so_far_dist number :=0;
766 h_pd_fully_rsv number:=0;
767 h_group_asset_id number := 0;
768 h_dd_count number:=0;
769 h_period_of_addition varchar2(1);
770
771 CURSOR C1 IS
772 SELECT DISTRIBUTION_ID,
773 CODE_COMBINATION_ID,
774 UNITS_ASSIGNED
775 FROM FA_DISTRIBUTION_HISTORY
776 WHERE ASSET_ID = h_asset_id
777 AND BOOK_TYPE_CODE = h_dist_book
778 AND (
779 (adj_ptr.selection_mode <> FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_PARTIAL
780 AND date_ineffective is null
781 )
782 OR
783 (adj_ptr.selection_mode = FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_PARTIAL
784 AND transaction_header_id_in=adj_ptr.selection_thid
785 )
786 )
787 ORDER BY DISTRIBUTION_ID;
788
789 BEGIN <<fadoact>>
790
791 -- First Store the adj_ptr.adjustment_amount into h_adjustment_amount
792 -- This is done because adj_ptr.adjustment gets changed here and we
793 -- need to retain the original passed value for calculation of amount for
794 -- each distribution
795 h_adjustment_amount := adj_ptr.adjustment_amount;
796 h_temp_adj_amount := adj_ptr.adjustment_amount;
797
798 -- Flush out the unposted rows in the cache to the db
799 -- since there might be some pending rows out there,
800 -- and we can't read through the cache
801 h_asset_id := adj_ptr.asset_id;
802
803 if (p_log_level_rec.statement_level) then
804 FA_DEBUG_PKG.ADD
805 (fname => 'FA_INS_ADJUST_PKG.fadoact',
806 element => 'Before Flush',
807 value => 'TRUE',
808 p_log_level_rec => p_log_level_rec);
809 end if;
810
811 if (not fainajc
812 (X_flush_mode => TRUE,
813 X_mode => FALSE,
814 X_last_update_date => X_last_update_date,
815 X_last_updated_by => X_last_updated_by,
816 X_last_update_login => X_last_update_login,
817 p_log_level_rec => p_log_level_rec)) then
818 FA_SRVR_MSG.ADD_MESSAGE
819 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoact',
820 p_log_level_rec => p_log_level_rec);
821 return FALSE;
822 end if;
823
824 -- Call the Query Fin Info function in detail mode to figure
825 -- out how much to clear for this distribution
826 H_DPR_ROW.asset_id := adj_ptr.asset_id;
827 H_DPR_ROW.book := adj_ptr.book_type_code;
828 H_DPR_ROW.dist_id := h_distribution_id;
829 H_DPR_ROW.period_ctr := 0;
830 H_DPR_ROW.mrc_sob_type_code := h_mrc_sob_type_code;
831 H_DPR_ROW.set_of_books_id := h_set_of_books_id;
832
833 FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT
834 (H_DPR_ROW,
835 'STANDARD',
836 FALSE,
837 H_SUCCESS,
838 'FA_INS_ADJUST_PKG.fadoact',
839 -1,
840 p_log_level_rec => p_log_level_rec);
841
842 -- Assign H_DPR_ROW to dpr_ptr
843 dpr_ptr := H_DPR_ROW;
844 /* DIST ALLOC*/
845 if((adj_ptr.adjustment_type like '%RESERVE%') OR
846 (adj_ptr.adjustment_type like '%EXPENSE%')) then
847 if adj_ptr.adjustment_type = 'IMPAIR RESERVE' then
848 h_asset_rsv := H_DPR_ROW.impairment_rsv;
849 else
850 h_asset_rsv := H_DPR_ROW.deprn_rsv;
851 end if;
852 if(H_DPR_ROW.mrc_sob_type_code = 'R') then
853 select nvl(sum(decode(debit_credit_flag,
854 'DR', adjustment_amount,
855 adjustment_amount * -1)), 0)
856 into h_tot_cost
857 from FA_MC_ADJUSTMENTS
858 where asset_id = adj_ptr.asset_id
859 and book_type_code = adj_ptr.book_type_code
860 and adjustment_type = 'COST'
861 and set_of_books_id = h_set_of_books_id
862 and distribution_id in (select distribution_id from fa_distribution_history where asset_id = adj_ptr.asset_id and book_type_code = adj_ptr.book_type_code and date_ineffective is null);
863
864 select PERIOD_COUNTER_FULLY_RESERVED,cost,group_asset_id
865 into h_pd_fully_rsv,h_books_cost,h_group_asset_id
866 from fa_mc_books
867 where asset_id = adj_ptr.asset_id
868 and book_type_code = adj_ptr.book_type_code
869 and set_of_books_id = h_set_of_books_id
870 and date_ineffective is null;
871 else
872 select nvl(sum(decode(debit_credit_flag,
873 'DR', adjustment_amount,
874 adjustment_amount * -1)), 0),count(*)
875 into h_tot_cost,h_adj_no_rows
876 from fa_adjustments
877 where asset_id = adj_ptr.asset_id
878 and book_type_code = adj_ptr.book_type_code
879 and adjustment_type = 'COST'
880 and distribution_id in (select distribution_id from fa_distribution_history where asset_id = adj_ptr.asset_id and book_type_code = adj_ptr.book_type_code and date_ineffective is null);
881
882 select PERIOD_COUNTER_FULLY_RESERVED, cost, group_asset_id
883 into h_pd_fully_rsv,h_books_cost,h_group_asset_id
884 from fa_books
885 where asset_id = adj_ptr.asset_id
886 and book_type_code = adj_ptr.book_type_code
887 and date_ineffective is null;
888 if(h_adj_no_rows = 0) then
889 h_tot_cost := h_books_cost;
890 end if;
891 end if;
892 end if;
893 /* DIST ALLOC end*/
894 -- Calculate the total_amount to prorate based on the
895 -- adjustment_type.
896 if (p_log_level_rec.statement_level) then
897 FA_DEBUG_PKG.ADD
898 (fname => 'FA_INS_ADJUST_PKG.fadoact',
899 element => 'ALL BLANKS',
900 value => ' ',
901 p_log_level_rec => p_log_level_rec);
902 FA_DEBUG_PKG.ADD
903 (fname => 'FA_INS_ADJUST_PKG.fadoact',
904 element => 'adj_ptr.amount',
905 value => h_adjustment_amount,
906 p_log_level_rec => p_log_level_rec);
907 end if;
908
909 if (adj_ptr.source_type_code = 'RETIREMENT' and adj_ptr.adjustment_type = 'IMPAIR RESERVE') THEN
910 h_adjustment_amount := h_adjustment_amount + dpr_ptr.impairment_rsv ;
911 end if;
912
913 if (not factotp
914 (total_amount => h_total_amount,
915 adjustment_amount => h_adjustment_amount,
916 p_log_level_rec => p_log_level_rec)) then
917 FA_SRVR_MSG.ADD_MESSAGE
918 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoact',
919 p_log_level_rec => p_log_level_rec);
920 return FALSE;
921 end if;
922
923 if (p_log_level_rec.statement_level) then
924 FA_DEBUG_PKG.ADD
925 (fname => 'FA_INS_ADJUST_PKG.fadoact',
926 element => 'Total Amount',
927 value => h_total_amount,
928 p_log_level_rec => p_log_level_rec);
929 end if;
930
931 -- no need to call the book controls cache here - it shoudl already be loaded
932 h_dist_book := FA_CACHE_PKG.fazcbc_record.distribution_source_book;
933
934 h_mesg_name:='FA_INS_ADJ_CNT_ACTIVE';
935
936 if (adj_ptr.selection_mode <> FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_PARTIAL) then
937
938 SELECT COUNT(*)
939 INTO h_distribution_lines
940 FROM FA_DISTRIBUTION_HISTORY
941 WHERE ASSET_ID=h_asset_id
942 AND book_type_code=h_dist_book
943 AND DATE_INEFFECTIVE IS NULL;
944
945 else
946
947 -- the number of the newly created rows only
948 SELECT COUNT(*)
949 INTO h_distribution_lines
950 FROM FA_DISTRIBUTION_HISTORY
951 WHERE ASSET_ID=h_asset_id
952 AND book_type_code=h_dist_book
953 AND transaction_header_id_in=adj_ptr.selection_thid;
954
955 end if;
956
957 -- SLA: fail if count = 0
958 if ((SQL%NOTFOUND or h_distribution_lines = 0) and
959 G_release = 11) THEN
960 FA_SRVR_MSG.ADD_MESSAGE
961 (NAME=>h_mesg_name,
962 CALLING_FN => 'FA_GCCID_PKG.fadoact',
963 p_log_level_rec => p_log_level_rec);
964 return FALSE;
965 end if;
966
967 h_mesg_name:='FA_INS_ADJ_DCUR_C1';
968 for distribution IN C1 loop
969
970 h_mesg_name := 'FA_INS_ADJ_FCUR_C1';
971 h_distribution_id := distribution.distribution_id;
972 h_dist_ccid := distribution.code_combination_id;
973 h_units_assigned := distribution.units_assigned;
974 h_row_ctr := h_row_ctr+1;
975
976 -- Get the FA_DEPRN_DETAIL value for the PERIOD_ADJUSTED,
977 -- plus/minus any adjustments by calling Query Fin Info
978 -- in detail mode:
979 H_DPR_ROW.asset_id:=adj_ptr.asset_id;
980 H_DPR_ROW.book:=adj_ptr.book_type_code;
981 H_DPR_ROW.dist_id:=h_distribution_id;
982 H_DPR_ROW.period_ctr:=0;
983 H_DPR_ROW.mrc_sob_type_code := h_mrc_sob_type_code;
984 H_DPR_ROW.set_of_books_id := h_set_of_books_id;
985
986 FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT
987 (H_DPR_ROW,
988 'STANDARD',
989 FALSE,
990 H_SUCCESS,
991 -1,
992 p_log_level_rec => p_log_level_rec);
993 if not h_success then
994 FA_SRVR_MSG.ADD_MESSAGE
995 (CALLING_FN => 'FA_GCCID_PKG.fadoact',
996 p_log_level_rec => p_log_level_rec);
997 return FALSE;
998 end if;
999
1000 -- Assign H_DPR_ROW to dpr_ptr. They are of the same type
1001 dpr_ptr:=H_DPR_ROW;
1002
1003 -- Calculate the detail amount to subtract for leveling
1004 -- Test change, always treat cost adjustments in as false
1005
1006 if ((adj_ptr.leveling_flag=TRUE) AND
1007 (adj_ptr.adjustment_type<>'COST') AND
1008 (adj_ptr.adjustment_type<>'CIP COST')) then
1009 if (not facdamt(h_adj_dd_amount,
1010 p_log_level_rec => p_log_level_rec)) then
1011 FA_SRVR_MSG.ADD_MESSAGE
1012 (CALLING_FN => 'FA_GCCID_PKG.fadoact',
1013 p_log_level_rec => p_log_level_rec);
1014 return FALSE;
1015 end if;
1016 else
1017 h_adj_dd_amount:=0; -- Set to 0 if leveling off
1018 end if;
1019
1020 if (h_row_ctr<>h_distribution_lines) then
1021 -- not the last distribution
1022 /* DIST ALLOC*/
1023 if((adj_ptr.adjustment_type like '%RESERVE%') OR
1024 (adj_ptr.adjustment_type like '%EXPENSE%'))
1025 then
1026 if (h_dpr_row.cost = 0) then
1027 if not FA_ASSET_VAL_PVT.validate_period_of_addition(ADJ_PTR.ASSET_ID, adj_ptr.book_type_code,'CAPITALIZED',h_period_of_addition) then
1028 FA_SRVR_MSG.ADD_MESSAGE(CALLING_FN => 'FA_GCCID_PKG.fadoact');
1029 return FALSE;
1030 end if;
1031 if(h_period_of_addition = 'Y') then---Need to add MRC tables.
1032 if(H_DPR_ROW.mrc_sob_type_code = 'R') then
1033 select count(*)
1034 into h_dd_count
1035 from fa_deprn_detail_mrc_v
1036 where asset_id = adj_ptr.asset_id
1037 and book_type_code = adj_ptr.book_type_code
1038 and deprn_source_code = 'D';
1039 if(h_dd_count = 0)then
1040 select addition_cost_to_clear--, nvl(deprn_reserve,0)
1041 into h_dpr_row.cost--, h_dpr_row.deprn_rsv
1042 from fa_deprn_detail_mrc_v
1043 where asset_id = adj_ptr.asset_id
1044 and book_type_code = adj_ptr.book_type_code
1045 and deprn_source_code = 'B'
1046 and distribution_id = h_distribution_id;
1047 end if;
1048
1049 else
1050 select count(*)
1051 into h_dd_count
1052 from fa_deprn_detail
1053 where asset_id = adj_ptr.asset_id
1054 and book_type_code = adj_ptr.book_type_code
1055 and deprn_source_code = 'D';
1056 if(h_dd_count = 0)then
1057 select addition_cost_to_clear--, nvl(deprn_reserve,0)
1058 into h_dpr_row.cost--, h_dpr_row.deprn_rsv
1059 from fa_deprn_detail
1060 where asset_id = adj_ptr.asset_id
1061 and book_type_code = adj_ptr.book_type_code
1062 and deprn_source_code = 'B'
1063 and distribution_id = h_distribution_id;
1064 end if;
1065 end if;
1066
1067 end if;
1068 end if;
1069 if (h_tot_cost <> 0) then /* Bug 14739862 */
1070 h_new_dist_rsv := (h_asset_rsv + (h_total_amount)) * (h_dpr_row.cost /h_tot_cost);
1071 else
1072 h_new_dist_rsv := 0;
1073 end if;
1074
1075 IF (NOT FA_UTILS_PKG.faxrnd(X_amount => h_new_dist_rsv,
1076 X_book => adj_ptr.book_type_code,
1077 X_set_of_books_id => adj_ptr.set_of_books_id,
1078 p_log_level_rec => p_log_level_rec)) THEN
1079 FA_SRVR_MSG.add_message(CALLING_FN => 'FA_INS_ADJUST_PKG.fadoact');
1080 return (FALSE);
1081 END IF;
1082 if (p_log_level_rec.statement_level) then
1083 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_new_dist_rsv ',value => h_new_dist_rsv,p_log_level_rec => p_log_level_rec);
1084 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_asset_rsv ',value => h_asset_rsv,p_log_level_rec => p_log_level_rec);
1085 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_total_amount ',value => h_total_amount,p_log_level_rec => p_log_level_rec);
1086 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_dpr_row.cost ',value => h_dpr_row.cost,p_log_level_rec => p_log_level_rec);
1087 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_tot_cost ',value => h_tot_cost,p_log_level_rec => p_log_level_rec);
1088 end if;
1089 if adj_ptr.adjustment_type = 'IMPAIR RESERVE' then
1090 h_dist_rsv := H_DPR_ROW.impairment_rsv;
1091 else
1092 h_dist_rsv := H_DPR_ROW.deprn_rsv;
1093 end if;
1094 /*Bug#13501578 - cost is zero when allocating reserve to new distribution_id when partial unit retirement is done,
1095 this results in wrong reserve allocation and nbv retired,use old forumla */
1096 if h_dpr_row.cost <> 0 then
1097 h_amount_to_insert := (h_new_dist_rsv - h_dist_rsv) - h_adj_dd_amount ;
1098 else
1099 h_amount_to_insert := (h_total_amount * (h_units_assigned/adj_ptr.current_units) ) - h_adj_dd_amount;
1100 end if;
1101 if (p_log_level_rec.statement_level) then
1102 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_amount_to_insert ',value => h_amount_to_insert,p_log_level_rec => p_log_level_rec);
1103 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_new_dist_rsv ',value => h_new_dist_rsv,p_log_level_rec => p_log_level_rec);
1104 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_dpr_row.deprn_rsv ',value => h_dpr_row.deprn_rsv,p_log_level_rec => p_log_level_rec);
1105 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_dist_rsv ',value => h_dist_rsv,p_log_level_rec => p_log_level_rec);
1106 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_adj_dd_amount ',value => h_adj_dd_amount,p_log_level_rec => p_log_level_rec);
1107 END IF;
1108 else
1109 h_amount_to_insert := (h_total_amount * (h_units_assigned/adj_ptr.current_units) ) - h_adj_dd_amount;
1110 end if;
1111 /* DIST ALLOC end*/
1112 else
1113 -- Last distribution gets extra
1114 if (p_log_level_rec.statement_level) then
1115 FA_DEBUG_PKG.ADD
1116 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1117 element => 'Total Amount',
1118 value => h_total_amount,
1119 p_log_level_rec => p_log_level_rec);
1120 end if;
1121
1122 -- YYOON: Propagated from PRO*C version(faxiaj2.lpc)
1123
1124 if (adj_ptr.account_type = 'REVAL_RESERVE_ACCT'
1125 and adj_ptr.selection_mode <> FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_REVAL) then
1126
1127 --DIST ALLOC
1128 if((adj_ptr.adjustment_type like '%RESERVE%') OR
1129 (adj_ptr.adjustment_type like '%EXPENSE%'))
1130 and (nvl(h_pd_fully_rsv,-1) = -1 )
1131 then
1132 h_amount_to_insert := h_total_amount - h_amount_so_far ;
1133 if (p_log_level_rec.statement_level) then
1134 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_amount_so_far ',value => h_amount_so_far,p_log_level_rec => p_log_level_rec);
1135 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_total_amount ',value => h_total_amount,p_log_level_rec => p_log_level_rec);
1136 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_amount_to_insert ',value => h_amount_to_insert,p_log_level_rec => p_log_level_rec);
1137 END IF;
1138 ELSE
1139 h_amount_to_insert := h_total_amount - h_amount_so_far;
1140 end if;
1141
1142 else
1143
1144 --DIST ALLOC
1145 if((adj_ptr.adjustment_type like '%RESERVE%') OR
1146 (adj_ptr.adjustment_type like '%EXPENSE%'))
1147 --and (nvl(h_pd_fully_rsv,-1) = -1 ) Bug#13501656 Need to process even if fully reserved
1148 then
1149
1150 h_new_dist_rsv := (h_asset_rsv + h_total_amount) - h_amount_so_far_dist;
1151 IF (NOT FA_UTILS_PKG.faxrnd(X_amount => h_new_dist_rsv,
1152 X_book => adj_ptr.book_type_code,
1153 X_set_of_books_id => adj_ptr.set_of_books_id,
1154 p_log_level_rec => p_log_level_rec)) THEN
1155 FA_SRVR_MSG.add_message(CALLING_FN => 'FA_INS_ADJUST_PKG.fadoact');
1156 return (FALSE);
1157 END IF;
1158 if (p_log_level_rec.statement_level) then
1159 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_new_dist_rsv ',value => h_new_dist_rsv,p_log_level_rec => p_log_level_rec);
1160 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_asset_rsv ',value => h_asset_rsv,p_log_level_rec => p_log_level_rec);
1161 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_total_amount ',value => h_total_amount,p_log_level_rec => p_log_level_rec);
1162 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_amount_so_far ',value => h_amount_so_far,p_log_level_rec => p_log_level_rec);
1163 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_amount_so_far_dist ',value => h_amount_so_far_dist,p_log_level_rec => p_log_level_rec);
1164 END IF;
1165 if adj_ptr.adjustment_type = 'IMPAIR RESERVE' then
1166 h_dist_rsv := H_DPR_ROW.impairment_rsv;
1167 else
1168 h_dist_rsv := H_DPR_ROW.deprn_rsv;
1169 end if;
1170 /*Bug#13501578 - cost is zero when allocating reserve to new distribution_id when partial unit retirement is done,
1171 this results in wrong reserve allocation and nbv retired,use old forumla */
1172 if h_dpr_row.cost <> 0 then
1173 h_amount_to_insert := (h_new_dist_rsv - h_dist_rsv) - h_adj_dd_amount ;
1174 else
1175 h_amount_to_insert := h_adjustment_amount - h_amount_so_far;
1176 end if;
1177 if (p_log_level_rec.statement_level) then
1178 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_amount_to_insert ',value => h_amount_to_insert,p_log_level_rec => p_log_level_rec);
1179 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_new_dist_rsv ',value => h_new_dist_rsv,p_log_level_rec => p_log_level_rec);
1180 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_adj_dd_amount ',value => h_adj_dd_amount,p_log_level_rec => p_log_level_rec);
1181 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_dpr_row.deprn_rsv ',value => h_dpr_row.deprn_rsv,p_log_level_rec => p_log_level_rec);
1182 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact',element => '+++ h_dist_rsv ',value => h_dist_rsv,p_log_level_rec => p_log_level_rec);
1183 END IF;
1184 ELSE
1185 h_amount_to_insert := h_adjustment_amount - h_amount_so_far;
1186 END IF;
1187
1188 end if;
1189
1190 end if;
1191
1192 if (p_log_level_rec.statement_level) then
1193 FA_DEBUG_PKG.ADD
1194 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1195 element => 'ADJ_PTR.ADJUSTMENT_AMOUNT -LAST DIST',
1196 value => h_adjustment_amount,
1197 p_log_level_rec => p_log_level_rec);
1198 FA_DEBUG_PKG.ADD
1199 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1200 element => 'AMOUNT SO FAR-LAST DIST',
1201 value => h_amount_so_far,
1202 p_log_level_rec => p_log_level_rec);
1203 FA_DEBUG_PKG.ADD
1204 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1205 element => 'h_amount_to_insert',
1206 value => h_amount_to_insert,
1207 p_log_level_rec => p_log_level_rec);
1208 end if;
1209
1210 -- Round the h_amount_to_insert - faxrnd.....
1211 IF (NOT FA_UTILS_PKG.faxrnd(X_amount => h_amount_to_insert,
1212 X_book => adj_ptr.book_type_code,
1213 X_set_of_books_id => adj_ptr.set_of_books_id,
1214 p_log_level_rec => p_log_level_rec)) THEN
1215 FA_SRVR_MSG.add_message
1216 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoact',
1217 p_log_level_rec => p_log_level_rec);
1218 return (FALSE);
1219 END IF;
1220 if (p_log_level_rec.statement_level) then
1221 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact ##',element => '+++ h_amount_so_far_dist ',value => h_amount_so_far_dist,p_log_level_rec => p_log_level_rec);
1222 END IF;
1223 h_amount_so_far:=h_amount_so_far+h_amount_to_insert;
1224 h_amount_so_far_dist :=h_amount_so_far_dist +h_new_dist_rsv;
1225
1226 if (p_log_level_rec.statement_level) then
1227 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact ## 2 ',element => '+++ h_amount_so_far_dist ',value => h_amount_so_far_dist,p_log_level_rec => p_log_level_rec);
1228 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadoact ## 2 ',element => '+++ h_new_dist_rsv ',value => h_new_dist_rsv,p_log_level_rec => p_log_level_rec);
1229 FA_DEBUG_PKG.ADD
1230 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1231 element => 'dist ccid in fadoact',
1232 value => h_dist_ccid,
1233 p_log_level_rec => p_log_level_rec);
1234 FA_DEBUG_PKG.ADD
1235 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1236 element => 'Amount so far-amount inserted ',
1237 value => h_amount_so_far,
1238 p_log_level_rec => p_log_level_rec);
1239 end if;
1240
1241 -- Calculate the ccid to use
1242 if (not fadoflx
1243 (X_book_type_code => adj_ptr.book_type_code,
1244 X_account_type => adj_ptr.account_type,
1245 X_dist_ccid => h_dist_ccid,
1246 X_spec_ccid => adj_ptr.code_combination_id,
1247 X_account => adj_ptr.account,
1248 X_calculated_ccid => h_calculated_ccid,
1249 X_gen_ccid_flag => adj_ptr.gen_ccid_flag,
1250 X_asset_id => adj_ptr.asset_id,
1251 X_cat_id => adj_ptr.selection_retid,
1252 X_distribution_id => h_distribution_id,
1253 X_source_type_code => adj_ptr.source_type_code,
1254 p_log_level_rec => p_log_level_rec)) then
1255 FA_SRVR_MSG.ADD_MESSAGE
1256 (CALLING_FN => 'FA_GCCID_PKG.fadoact',
1257 NAME => h_mesg_name,
1258 p_log_level_rec => p_log_level_rec);
1259 return FALSE;
1260 end if;
1261
1262 -- Call the function fainajc, which performs the insert into
1263 -- FA_ADJUSTMENTS, caching the inserts if appropiate
1264 if adj_ptr.account_type='CIP_COST_ACCT' then
1265 h_adj_type:='CIP COST';
1266 else
1267 h_adj_type:=adj_ptr.adjustment_type;
1268 end if;
1269
1270 if (p_log_level_rec.statement_level) then
1271 FA_DEBUG_PKG.ADD
1272 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1273 element => 'Adj Amt in fadoact',
1274 value => h_amount_to_insert,
1275 p_log_level_rec => p_log_level_rec);
1276 end if;
1277
1278 adj_ptr.code_combination_id := h_calculated_ccid;
1279 adj_ptr.adjustment_type := h_adj_type;
1280 adj_ptr.adjustment_amount := h_amount_to_insert;
1281 adj_ptr.distribution_id := h_distribution_id;
1282 if (not fainajc
1283 (X_flush_mode => FALSE,
1284 X_mode => FALSE,
1285 X_last_update_date => X_last_update_date,
1286 X_last_updated_by => X_last_updated_by,
1287 X_last_update_login => X_last_update_login,
1288 p_log_level_rec => p_log_level_rec)) then
1289 FA_SRVR_MSG.ADD_MESSAGE
1290 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoact',
1291 p_log_level_rec => p_log_level_rec);
1292 return FALSE;
1293 end if;
1294 end loop;
1295
1296 adj_ptr.amount_inserted := h_amount_so_far;
1297 return TRUE;
1298
1299 exception
1300 when others then
1301 FA_SRVR_MSG.ADD_SQL_ERROR
1302 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoact',
1303 p_log_level_rec => p_log_level_rec);
1304 return FALSE;
1305
1306 END fadoact;
1307
1308 -------------------------------------------------------------------
1309
1310 FUNCTION fadoclr(X_last_update_date date default sysdate,
1311 X_last_updated_by number default -1,
1312 X_last_update_login number default -1,
1313 p_log_level_rec in fa_api_types.log_level_rec_type
1314 ) return boolean is
1315
1316 h_row_ctr number :=0;
1317 h_dist_book varchar2(30);
1318 h_asset_id number;
1319 h_selection_thid number;
1320 h_mesg_name varchar2(30);
1321 h_dist_ccid number;
1322 h_distribution_id number :=0;
1323 h_units_assigned number;
1324 h_thid_in number;
1325 h_calculated_ccid number;
1326 h_adj_dd_amount number:=0;
1327 h_amount_to_insert number :=0;
1328 h_amount_so_far number :=0;
1329
1330 -- The following variables are declared for QUERY_BALANCES_INT
1331 h_success boolean;
1332 hx_debug boolean :=FALSE;
1333 h_adj_type varchar2(20);
1334
1335 CURSOR FA_CLEAR IS
1336 SELECT distribution_id,
1337 code_combination_id,
1338 units_assigned,
1339 transaction_header_id_in
1340 FROM FA_DISTRIBUTION_HISTORY
1341 WHERE asset_id = h_asset_id
1342 AND book_type_code=h_dist_book
1343 AND (
1344 (adj_ptr.selection_mode <> FA_ADJUST_TYPE_PKG.FA_AJ_CLEAR_PARTIAL
1345 AND (date_ineffective is null
1346 OR transaction_header_id_out=adj_ptr.selection_thid
1347 )
1348 )
1349 OR
1350 (adj_ptr.selection_mode = FA_ADJUST_TYPE_PKG.FA_AJ_CLEAR_PARTIAL
1351 AND transaction_header_id_out=adj_ptr.selection_thid
1352 )
1353 )
1354 ORDER BY distribution_id;
1355
1356 BEGIN <<fadoclr>>
1357
1358 h_asset_id := adj_ptr.asset_id;
1359 h_selection_thid := adj_ptr.selection_thid;
1360 -- Flush out the unposted rows in the cache to the DB. Since there
1361 -- might be some pending rows and we can't read through the cache;
1362
1363 if (not fainajc
1364 (X_flush_mode => TRUE,
1365 X_mode => FALSE,
1366 X_last_update_date => X_last_update_date,
1367 X_last_updated_by => X_last_updated_by,
1368 X_last_update_login => X_last_update_login,
1369 p_log_level_rec => p_log_level_rec)) then
1370 FA_SRVR_MSG.ADD_MESSAGE
1371 (NAME => 'FA_GET_CAT_ID',
1372 CALLING_FN => 'FA_INS_ADJUST_PKG.fadoclr',
1373 p_log_level_rec => p_log_level_rec);
1374 return FALSE;
1375 end if;
1376
1377 -- no need to call book controls cache here - it should already be loaded
1378 h_dist_book := FA_CACHE_PKG.fazcbc_record.distribution_source_book;
1379 if (p_log_level_rec.statement_level) then
1380 FA_DEBUG_PKG.ADD
1381 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1382 element => 'Dist Ccid in fadoclr is',
1383 value => h_dist_ccid,
1384 p_log_level_rec => p_log_level_rec);
1385 end if;
1386 h_mesg_name := 'FA_INS_ADJ_OCUR_CLEAR';
1387
1388 for distval IN FA_CLEAR loop
1389 h_mesg_name := 'FA_INS_ADJ_FCUR_CLEAR';
1390 h_distribution_id := distval.distribution_id;
1391 h_dist_ccid := distval.code_combination_id;
1392 h_units_assigned := distval.units_assigned;
1393 h_thid_in := distval.transaction_header_id_in;
1394 h_row_ctr := h_row_ctr + 1;
1395
1396 -- Do not clear out rows created by the selection thid
1397 if (h_thid_in <> adj_ptr.selection_thid) then
1398 -- Call the Query Fin Info function in detail mode to figure
1399 -- out how much to clear for this distribution
1400 H_DPR_ROW.asset_id := adj_ptr.asset_id;
1401 H_DPR_ROW.book := adj_ptr.book_type_code;
1402 H_DPR_ROW.dist_id := h_distribution_id;
1403 H_DPR_ROW.period_ctr := 0;
1404 H_DPR_ROW.mrc_sob_type_code := h_mrc_sob_type_code;
1405 H_DPR_ROW.set_of_books_id := h_set_of_books_id;
1406
1407 FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT
1408 (H_DPR_ROW,
1409 'STANDARD',
1410 FALSE,
1411 H_SUCCESS,
1412 'FA_INS_ADJUST_PKG.fadoclr',
1413 -1,
1414 p_log_level_rec => p_log_level_rec);
1415
1416 -- Assign H_DPR_ROW to dpr_ptr. They are of same type
1417 dpr_ptr:=H_DPR_ROW;
1418
1419 -- call facdamt to calculate the detail amount for leveling
1420 if (not facdamt(adj_dd_amount=>h_adj_dd_amount,
1421 p_log_level_rec => p_log_level_rec)) then
1422 FA_SRVR_MSG.ADD_MESSAGE
1423 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoclr',
1424 NAME => h_mesg_name,
1425 p_log_level_rec => p_log_level_rec);
1426 end if;
1427
1428 h_amount_to_insert := h_adj_dd_amount;
1429
1430 if (p_log_level_rec.statement_level) then
1431 FA_DEBUG_PKG.ADD
1432 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1433 element => 'JUST BLANK',
1434 value => '00000000000000000000000000',
1435 p_log_level_rec => p_log_level_rec);
1436 FA_DEBUG_PKG.ADD
1437 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1438 element => 'DD ADJ AMOUNT-after FACDAMT',
1439 value => h_adj_dd_amount,
1440 p_log_level_rec => p_log_level_rec);
1441 FA_DEBUG_PKG.ADD
1442 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1443 element => 'amount to insert-after FACDAMT',
1444 value => h_amount_to_insert,
1445 p_log_level_rec => p_log_level_rec);
1446 end if;
1447
1448 -- round amount to insert (h_amount_to_insert) according to the
1449 -- functional currency faxrnd(...)
1450 IF (NOT FA_UTILS_PKG.faxrnd(X_amount => h_amount_to_insert,
1451 X_book => adj_ptr.book_type_code,
1452 X_set_of_books_id => adj_ptr.set_of_books_id,
1453 p_log_level_rec => p_log_level_rec)) THEN
1454 FA_SRVR_MSG.add_message(
1455 CALLING_FN => 'FA_INS_ADJUST_PKG.fadoclr',
1456 p_log_level_rec => p_log_level_rec);
1457 return (FALSE);
1458 END IF;
1459
1460 adj_ptr.adjustment_amount := h_amount_to_insert;
1461 h_amount_so_far := h_amount_so_far + h_amount_to_insert;
1462
1463 if (p_log_level_rec.statement_level) then
1464 FA_DEBUG_PKG.ADD
1465 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1466 element => 'amount to insert-AFTER ROUNDING',
1467 value => h_amount_to_insert,
1468 p_log_level_rec => p_log_level_rec);
1469 FA_DEBUG_PKG.ADD
1470 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1471 element => 'amount so far-AFTER ROUNDING',
1472 value => h_amount_so_far,
1473 p_log_level_rec => p_log_level_rec);
1474 end if;
1475
1476 -- Calculate the ccid to use
1477 if (not fadoflx
1478 (X_book_type_code => adj_ptr.book_type_code,
1479 X_account_type => adj_ptr.account_type,
1480 X_dist_ccid => h_dist_ccid,
1481 X_spec_ccid => adj_ptr.code_combination_id,
1482 X_account => adj_ptr.account,
1483 X_calculated_ccid => h_calculated_ccid,
1484 X_gen_ccid_flag => adj_ptr.gen_ccid_flag,
1485 X_asset_id => adj_ptr.asset_id,
1486 X_cat_id => adj_ptr.selection_retid,
1487 X_distribution_id => h_distribution_id,
1488 X_source_type_code => adj_ptr.source_type_code,
1489 p_log_level_rec => p_log_level_rec)) then
1490 FA_SRVR_MSG.ADD_MESSAGE
1491 (CALLING_FN => 'FA_GCCID_PKG.fadoclr',
1492 NAME => h_mesg_name,
1493 p_log_level_rec => p_log_level_rec);
1494 return FALSE;
1495 end if;
1496
1497 -- Bug 1131364
1498 if adj_ptr.account_type='CIP_COST_ACCT' then
1499 h_adj_type := 'CIP COST';
1500 else
1501 h_adj_type := adj_ptr.adjustment_type;
1502 end if;
1503
1504 -- Call the function fainajc, which performs the insert into
1505 -- FA_ADJUSTMENTS, caching the inserts if appropiate
1506 adj_ptr.adjustment_type := h_adj_type;
1507 adj_ptr.code_combination_id := h_calculated_ccid;
1508 adj_ptr.distribution_id := h_distribution_id;
1509 if (not fainajc
1510 (X_flush_mode => FALSE,
1511 X_mode => FALSE,
1512 X_last_update_date => X_last_update_date,
1513 X_last_updated_by => X_last_updated_by,
1514 X_last_update_login => X_last_update_login,
1515 p_log_level_rec => p_log_level_rec)) then
1516 FA_SRVR_MSG.ADD_MESSAGE
1517 (NAME => 'FA_GET_CAT_ID',
1518 CALLING_FN => 'FA_INS_ADJUST_PKG.fadoclr',
1519 p_log_level_rec => p_log_level_rec);
1520 return FALSE;
1521 end if;
1522 end if; -- thid<>adj_ptr.selection_thid
1523 end loop;
1524
1525 adj_ptr.amount_inserted := h_amount_so_far;
1526
1527 if (p_log_level_rec.statement_level) then
1528 FA_DEBUG_PKG.ADD
1529 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1530 element => 'AMOUNT INSERTED ',
1531 value => adj_ptr.amount_inserted,
1532 p_log_level_rec => p_log_level_rec);
1533 FA_DEBUG_PKG.ADD
1534 (fname => 'FA_INS_ADJUST_PKG.fadoclr',
1535 element => 'AMOUNT SO FAR ',
1536 value => h_amount_so_far,
1537 p_log_level_rec => p_log_level_rec);
1538 end if;
1539 return TRUE;
1540
1541 exception
1542 when others then
1543 FA_SRVR_MSG.ADD_SQL_ERROR
1544 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoclr',
1545 p_log_level_rec => p_log_level_rec);
1546 return FALSE;
1547
1548 END fadoclr;
1549
1550 -----------------------------------------------------------------------
1551
1552 FUNCTION fadosglf(X_last_update_date date default sysdate,
1553 X_last_updated_by number default -1,
1554 X_last_update_login number default -1,
1555 p_log_level_rec in fa_api_types.log_level_rec_type
1556 ) return boolean is
1557
1558 h_calculated_ccid number;
1559 h_dist_id number;
1560 h_adj_type varchar2(20);
1561
1562 BEGIN <<fadosglf>>
1563 if (not fainajc
1564 (X_flush_mode => TRUE,
1565 X_mode => FALSE,
1566 X_last_update_date => X_last_update_date,
1567 X_last_updated_by => X_last_updated_by,
1568 X_last_update_login => X_last_update_login,
1569 p_log_level_rec => p_log_level_rec)) then
1570 FA_SRVR_MSG.ADD_MESSAGE
1571 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadosglf',
1572 p_log_level_rec => p_log_level_rec);
1573 return FALSE;
1574 end if;
1575
1576 -- Calculate what CCID to use
1577 h_dist_id := adj_ptr.code_combination_id;
1578 if (not fadoflx
1579 (X_book_type_code => adj_ptr.book_type_code,
1580 X_account_type => adj_ptr.account_type,
1581 X_dist_ccid => h_dist_id,
1582 X_spec_ccid => adj_ptr.code_combination_id,
1583 X_account => adj_ptr.account,
1584 X_calculated_ccid => h_calculated_ccid,
1585 X_gen_ccid_flag => adj_ptr.gen_ccid_flag,
1586 X_asset_id => adj_ptr.asset_id,
1587 X_cat_id => adj_ptr.selection_retid,
1588 X_distribution_id => adj_ptr.distribution_id,
1589 X_source_type_code => adj_ptr.source_type_code,
1590 p_log_level_rec => p_log_level_rec)) then
1591 FA_SRVR_MSG.ADD_MESSAGE
1592 (CALLING_FN =>'FA_GCCID_PKG.fadosglf',
1593 p_log_level_rec => p_log_level_rec);
1594 return FALSE;
1595 end if;
1596
1597 -- Round the amount_to_insert according to functional currency */
1598 -- faxrnd(adj_ptr.adjustment_amount,adj_ptr.book_type_code
1599 if (not FA_UTILS_PKG.faxrnd(X_amount => adj_ptr.adjustment_amount,
1600 X_book => adj_ptr.book_type_code,
1601 X_set_of_books_id => adj_ptr.set_of_books_id,
1602 p_log_level_rec => p_log_level_rec))then
1603 FA_SRVR_MSG.add_message
1604 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadosglf',
1605 p_log_level_rec => p_log_level_rec);
1606 return (FALSE);
1607 end if;
1608
1609 if adj_ptr.account_type='CIP_COST_ACCT' then
1610 h_adj_type:='CIP COST';
1611 else
1612 h_adj_type:=adj_ptr.adjustment_type;
1613 end if;
1614
1615 adj_ptr.code_combination_id := h_calculated_ccid;
1616 adj_ptr.adjustment_type := h_adj_type;
1617 -- Call the function fainajc which performs the insert into
1618 -- FA_ADJUSTMENTS, caching the inserts if appropiate
1619 if (not fainajc
1620 (X_flush_mode => FALSE,
1621 X_mode => FALSE,
1622 X_last_update_date => X_last_update_date,
1623 X_last_updated_by => X_last_updated_by,
1624 X_last_update_login => X_last_update_login,
1625 p_log_level_rec => p_log_level_rec)) then
1626 FA_SRVR_MSG.ADD_MESSAGE
1627 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadosglf',
1628 p_log_level_rec => p_log_level_rec);
1629 return FALSE;
1630 end if;
1631
1632 adj_ptr.amount_inserted:=adj_ptr.adjustment_amount;
1633 if (p_log_level_rec.statement_level) then
1634 FA_DEBUG_PKG.ADD (fname => 'FA_INS_ADJUST_PKG.fadosglf',
1635 element => 'Amt Inserted-before return',
1636 value => adj_ptr.amount_inserted,
1637 p_log_level_rec => p_log_level_rec);
1638 end if;
1639 return TRUE;
1640
1641 exception
1642 when others then
1643 FA_SRVR_MSG.ADD_SQL_ERROR
1644 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadosglf',
1645 p_log_level_rec => p_log_level_rec);
1646 return FALSE;
1647
1648 END fadosglf;
1649
1650 -----------------------------------------------------------------------
1651
1652 FUNCTION fadosgl(X_last_update_date date default sysdate,
1653 X_last_updated_by number default -1,
1654 X_last_update_login number default -1,
1655 p_log_level_rec in fa_api_types.log_level_rec_type
1656 ) return boolean is
1657
1658 h_calculated_ccid number;
1659 h_dist_id number;
1660 h_adj_type varchar2(20);
1661
1662 BEGIN <<fadosgl>>
1663
1664 -- Calculate what CCID to use
1665 h_dist_id := adj_ptr.code_combination_id;
1666 if (not fadoflx
1667 (X_book_type_code => adj_ptr.book_type_code,
1668 X_account_type => adj_ptr.account_type,
1669 X_dist_ccid => h_dist_id,
1670 X_spec_ccid => adj_ptr.code_combination_id,
1671 X_account => adj_ptr.account,
1672 X_calculated_ccid => h_calculated_ccid,
1673 X_gen_ccid_flag => adj_ptr.gen_ccid_flag,
1674 X_asset_id => adj_ptr.asset_id,
1675 X_cat_id => adj_ptr.selection_retid,
1676 X_distribution_id => adj_ptr.distribution_id,
1677 X_source_type_code => adj_ptr.source_type_code,
1678 p_log_level_rec => p_log_level_rec)) then
1679 FA_SRVR_MSG.ADD_MESSAGE
1680 (CALLING_FN =>'FA_GCCID_PKG.fadosgl',
1681 p_log_level_rec => p_log_level_rec);
1682 return FALSE;
1683 end if;
1684
1685 -- Round the amount_to_insert according to functional currency
1686 -- faxrnd(adj_ptr.adjustment_amount,adj_ptr.book_type_code
1687 if (not FA_UTILS_PKG.faxrnd(X_amount => adj_ptr.adjustment_amount,
1688 X_book => adj_ptr.book_type_code,
1689 X_set_of_books_id => adj_ptr.set_of_books_id,
1690 p_log_level_rec => p_log_level_rec)) then
1691 FA_SRVR_MSG.add_message
1692 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadosgl',
1693 p_log_level_rec => p_log_level_rec);
1694 return (FALSE);
1695 end if;
1696
1697 if adj_ptr.account_type='CIP_COST_ACCT' then
1698 h_adj_type:='CIP COST';
1699 else
1700 h_adj_type:=adj_ptr.adjustment_type;
1701 end if;
1702
1703 adj_ptr.code_combination_id := h_calculated_ccid;
1704 adj_ptr.adjustment_type := h_adj_type;
1705
1706 -- Call the function fainajc which performs the insert into
1707 -- FA_ADJUSTMENTS, caching the inserts if appropiate
1708
1709 if (not fainajc
1710 (X_flush_mode => FALSE,
1711 X_mode => FALSE,
1712 X_last_update_date => X_last_update_date,
1713 X_last_updated_by => X_last_updated_by,
1714 X_last_update_login => X_last_update_login,
1715 p_log_level_rec => p_log_level_rec)) then
1716 FA_SRVR_MSG.ADD_MESSAGE
1717 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadosgl',
1718 p_log_level_rec => p_log_level_rec);
1719 return FALSE;
1720 end if;
1721
1722 adj_ptr.amount_inserted:=adj_ptr.adjustment_amount;
1723 return TRUE;
1724
1725 exception
1726 when others then
1727 FA_SRVR_MSG.ADD_SQL_ERROR
1728 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadosgl',
1729 p_log_level_rec => p_log_level_rec);
1730 return FALSE;
1731 END fadosgl;
1732
1733 -----------------------------------------------------------------
1734
1735 FUNCTION fadoret(X_last_update_date date default sysdate,
1736 X_last_updated_by number default -1,
1737 X_last_update_login number default -1,
1738 p_log_level_rec in fa_api_types.log_level_rec_type
1739 ) return boolean is
1740
1741 h_dist_book varchar2(30);
1742 h_asset_id number;
1743 h_success boolean;
1744 h_distribution_lines number;
1745 h_distribution_id number;
1746 h_trans_units number;
1747 h_dist_ccid number;
1748 h_calculated_ccid number;
1749 h_ret_id number;
1750 h_units_assigned number;
1751 h_adj_type varchar2(20);
1752 h_mesg_name varchar2(30);
1753 h_row_ctr number:=0;
1754 h_amount_so_far number :=0;
1755 h_amount_to_insert number:=0;
1756 h_adj_dd_amount number;
1757 h_total_amount number:=0;
1758 h_adjustment_amount number :=0;
1759
1760 CURSOR C1 IS
1761 SELECT DISTRIBUTION_ID,
1762 CODE_COMBINATION_ID,
1763 TRANSACTION_UNITS
1764 FROM FA_DISTRIBUTION_HISTORY
1765 WHERE ASSET_ID = h_asset_id
1766 AND BOOK_TYPE_CODE = h_dist_book
1767 AND RETIREMENT_ID = h_ret_id
1768 ORDER BY DISTRIBUTION_ID;
1769
1770 BEGIN <<fadoret>>
1771
1772 -- First store the passed adjustment amount in h_adjustment_amount
1773 -- This is done because adj_ptr.adjustment gets changed here and we
1774 -- need to retain the original passed value for calculation of amount for
1775 -- each distribution
1776 h_adjustment_amount := adj_ptr.adjustment_amount;
1777
1778 -- Flush out the unposted rows in the cache to the db
1779 -- since there might be some pending rows out there.
1780 if (not fainajc
1781 (X_flush_mode => TRUE,
1782 X_mode => FALSE,
1783 X_last_update_date => X_last_update_date,
1784 X_last_updated_by => X_last_updated_by,
1785 X_last_update_login => X_last_update_login,
1786 p_log_level_rec => p_log_level_rec)) then
1787 FA_SRVR_MSG.ADD_MESSAGE
1788 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoret',
1789 p_log_level_rec => p_log_level_rec);
1790 return FALSE;
1791 end if;
1792
1793 h_asset_id := adj_ptr.asset_id;
1794 h_ret_id := adj_ptr.selection_retid;
1795 H_DPR_ROW.asset_id := adj_ptr.asset_id;
1796 H_DPR_ROW.book := adj_ptr.book_type_code;
1797 H_DPR_ROW.dist_id := h_distribution_id;
1798 H_DPR_ROW.period_ctr := 0;
1799 H_DPR_ROW.mrc_sob_type_code := h_mrc_sob_type_code;
1800 H_DPR_ROW.set_of_books_id := h_set_of_books_id;
1801
1802 FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT(H_DPR_ROW,
1803 'STANDARD',
1804 FALSE,
1805 H_SUCCESS,
1806 'FA_INS_ADJUST_PKG.fadoret',
1807 -1,
1808 p_log_level_rec => p_log_level_rec);
1809 -- Assign H_DPR_ROW to dpr_ptr. They are of same type
1810 dpr_ptr:=H_DPR_ROW;
1811
1812 if (not factotp(total_amount=>h_total_amount,
1813 adjustment_amount=>h_adjustment_amount,
1814 p_log_level_rec => p_log_level_rec)) then
1815 FA_SRVR_MSG.ADD_MESSAGE
1816 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoret',
1817 p_log_level_rec => p_log_level_rec);
1818 return FALSE;
1819 end if;
1820
1821 -- no need t call book controls cache here should already be loaded
1822 h_dist_book := FA_CACHE_PKG.fazcbc_record.distribution_source_book;
1823 h_mesg_name:='FA_INS_ADJ_CNT_ACTIVE';
1824 SELECT COUNT(*)
1825 INTO h_distribution_lines
1826 FROM FA_DISTRIBUTION_HISTORY
1827 WHERE ASSET_ID = h_asset_id
1828 AND book_type_code = h_dist_book
1829 AND RETIREMENT_ID = h_ret_id;
1830
1831 if SQL%NOTFOUND THEN
1832 FA_SRVR_MSG.ADD_MESSAGE
1833 (NAME => h_mesg_name,
1834 CALLING_FN => 'FA_GCCID_PKG.fadoret',
1835 p_log_level_rec => p_log_level_rec);
1836 return FALSE;
1837 end if;
1838
1839 h_mesg_name:='FA_INS_ADJ_DCUR_C1';
1840 for distn IN C1 loop
1841 h_distribution_id := distn.distribution_id;
1842 h_mesg_name := 'FA_INS_ADJ_FCUR_C1';
1843 h_dist_ccid := distn.code_combination_id;
1844 h_trans_units := distn.transaction_units;
1845 h_row_ctr := h_row_ctr+1;
1846 H_DPR_ROW.asset_id := adj_ptr.asset_id;
1847 H_DPR_ROW.book := adj_ptr.book_type_code;
1848 H_DPR_ROW.dist_id := h_distribution_id;
1849 H_DPR_ROW.period_ctr:= 0;
1850 H_DPR_ROW.mrc_sob_type_code := h_mrc_sob_type_code;
1851 H_DPR_ROW.set_of_books_id := h_set_of_books_id;
1852
1853 -- Get the FA_DEPRN_DETAIL value for the period_adjusted, plus/minus
1854 -- any adjustments by calling Query Fin Info in detail mode
1855 FA_QUERY_BALANCES_PKG.QUERY_BALANCES_INT(H_DPR_ROW,
1856 'STANDARD',
1857 FALSE,
1858 H_SUCCESS,
1859 -1,
1860 p_log_level_rec => p_log_level_rec);
1861 if not h_success then
1862 FA_SRVR_MSG.ADD_MESSAGE
1863 (CALLING_FN => 'FA_GCCID_PKG.fadoret',
1864 p_log_level_rec => p_log_level_rec);
1865 return FALSE;
1866 end if;
1867 -- Assign H_DPR_ROW to dpr_ptr. They are of same type
1868 dpr_ptr:=H_DPR_ROW;
1869
1870 -- Calculate the detail amount to subtract for leveling
1871 -- Test change, always treat cost adjustments in as false
1872 if ((adj_ptr.leveling_flag=TRUE)) then
1873 if (not facdamt(h_adj_dd_amount,
1874 p_log_level_rec => p_log_level_rec)) then
1875 FA_SRVR_MSG.ADD_MESSAGE
1876 (CALLING_FN => 'FA_GCCID_PKG.fadoret',
1877 p_log_level_rec => p_log_level_rec);
1878 return FALSE;
1879 end if;
1880 else
1881 h_adj_dd_amount:=0; -- Set to 0 if leveling off
1882 end if;
1883
1884 if (h_row_ctr<>h_distribution_lines) then
1885 h_amount_to_insert := (h_total_amount * abs(h_trans_units)/adj_ptr.units_retired)
1886 - h_adj_dd_amount;
1887
1888 else
1889 h_amount_to_insert :=h_adjustment_amount - h_amount_so_far;
1890 end if;
1891
1892 IF (NOT FA_UTILS_PKG.faxrnd(X_amount => h_amount_to_insert,
1893 X_book => adj_ptr.book_type_code,
1894 X_set_of_books_id => adj_ptr.set_of_books_id,
1895 p_log_level_rec => p_log_level_rec)) THEN
1896 FA_SRVR_MSG.add_message
1897 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoret',
1898 p_log_level_rec => p_log_level_rec);
1899 return (FALSE);
1900 END IF;
1901
1902 h_amount_so_far:=h_amount_so_far+h_amount_to_insert;
1903 if (p_log_level_rec.statement_level) then
1904 FA_DEBUG_PKG.ADD
1905 (fname => 'FA_INS_ADJUST_PKG.fadoact',
1906 element => 'dist ccid in fadoact',
1907 value => h_dist_ccid,
1908 p_log_level_rec => p_log_level_rec);
1909 end if;
1910
1911 if (not fadoflx
1912 (X_book_type_code => adj_ptr.book_type_code,
1913 X_account_type => adj_ptr.account_type,
1914 X_dist_ccid => h_dist_ccid,
1915 X_spec_ccid => adj_ptr.code_combination_id,
1916 X_account => adj_ptr.account,
1917 X_calculated_ccid => h_calculated_ccid,
1918 X_gen_ccid_flag => adj_ptr.gen_ccid_flag,
1919 X_asset_id => adj_ptr.asset_id,
1920 X_cat_id => adj_ptr.selection_retid,
1921 X_distribution_id => h_distribution_id,
1922 X_source_type_code => adj_ptr.source_type_code,
1923 p_log_level_rec => p_log_level_rec)) then
1924 FA_SRVR_MSG.ADD_MESSAGE
1925 (CALLING_FN => 'FA_GCCID_PKG.fadoact',
1926 NAME=>h_mesg_name,
1927 p_log_level_rec => p_log_level_rec);
1928 return FALSE;
1929 end if;
1930
1931 if adj_ptr.account_type='CIP_COST_ACCT' then
1932 h_adj_type:='CIP COST';
1933 else
1934 h_adj_type:=adj_ptr.adjustment_type;
1935 end if;
1936
1937 adj_ptr.code_combination_id := h_calculated_ccid;
1938 adj_ptr.adjustment_type := h_adj_type;
1939 adj_ptr.adjustment_amount := h_amount_to_insert;
1940 adj_ptr.distribution_id := h_distribution_id;
1941
1942 if (not fainajc
1943 (X_flush_mode => FALSE,
1944 X_mode => FALSE,
1945 X_last_update_date => X_last_update_date,
1946 X_last_updated_by => X_last_updated_by,
1947 X_last_update_login => X_last_update_login,
1948 p_log_level_rec => p_log_level_rec)) then
1949 FA_SRVR_MSG.ADD_MESSAGE
1950 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoret',
1951 p_log_level_rec => p_log_level_rec);
1952 return FALSE;
1953 end if;
1954
1955 end loop;
1956 adj_ptr.amount_inserted := h_amount_so_far;
1957 return TRUE;
1958
1959 exception
1960 when others then
1961 FA_SRVR_MSG.ADD_SQL_ERROR
1962 (CALLING_FN => 'FA_INS_ADJUST_PKG.fadoret',
1963 p_log_level_rec => p_log_level_rec);
1964 return FALSE;
1965
1966 END fadoret;
1967
1968 -----------------------------------------------------------------
1969
1970 -- BUG# 2352985
1971 -- removing rows from cache and resetting cache index upon failure
1972 -- no dependancies unless code is ever implemented that uses the cache
1973 -- for multiple transactions / assets without flushing (like fadcje)
1974 -- bridgway
1975
1976 FUNCTION faxinaj(adj_ptr_passed in out nocopy FA_ADJUST_TYPE_PKG.fa_adj_row_struct,
1977 X_last_update_date date default sysdate,
1978 X_last_updated_by number default -1,
1979 X_last_update_login number default -1,
1980 p_log_level_rec in fa_api_types.log_level_rec_type
1981 ) return boolean is
1982
1983 BEGIN <<faxinaj>>
1984
1985 -- Assign the passed values from adj_ptr_passed to adj_ptr.
1986 adj_ptr := adj_ptr_passed;
1987
1988 -- put the mrc_sob_type in the global
1989 h_mrc_sob_type_code := nvl(adj_ptr_passed.mrc_sob_type_code, 'P');
1990 h_set_of_books_id := adj_ptr_passed.set_of_books_id;
1991
1992 IF (p_log_level_rec.statement_level) then
1993 FA_DEBUG_PKG.ADD
1994 (fname => 'FA_INS_ADJUST_PKG.faxinaj',
1995 element => 'adj amt - first',
1996 value => adj_ptr.adjustment_amount,
1997 p_log_level_rec => p_log_level_rec);
1998 FA_DEBUG_PKG.ADD
1999 (fname => 'FA_INS_ADJUST_PKG.faxinaj',
2000 element => 'deprn_override_flag',
2001 value => adj_ptr.deprn_override_flag,
2002 p_log_level_rec => p_log_level_rec);
2003 end if;
2004
2005 if (adj_ptr.flush_adj_flag=TRUE AND adj_ptr.transaction_header_id=0) then
2006 -- Flush out the unposted rows in the cache to the DB
2007 if (not fainajc
2008 (X_flush_mode => TRUE,
2009 X_mode => FALSE,
2010 X_last_update_date => X_last_update_date,
2011 X_last_updated_by => X_last_updated_by,
2012 X_last_update_login => X_last_update_login,
2013 p_log_level_rec => p_log_level_rec)) then
2014 adj_table.delete;
2015 h_cache_index := 0;
2016
2017 FA_SRVR_MSG.ADD_MESSAGE
2018 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2019 p_log_level_rec => p_log_level_rec);
2020 return FALSE;
2021 end if;
2022 else
2023 -- round the adj_ptr.annualized_adjustment
2024 if (not FA_UTILS_PKG.faxrnd(X_amount => adj_ptr.annualized_adjustment,
2025 X_book => adj_ptr.book_type_code,
2026 X_set_of_books_id => adj_ptr.set_of_books_id,
2027 p_log_level_rec => p_log_level_rec)) then
2028 adj_table.delete;
2029 h_cache_index := 0;
2030
2031 FA_SRVR_MSG.ADD_MESSAGE
2032 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2033 p_log_level_rec => p_log_level_rec);
2034 return FALSE;
2035 end if;
2036
2037 if (adj_ptr.selection_mode in (FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE , FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_PARTIAL)) then
2038 if (not fadoact
2039 (X_last_update_date => X_last_update_date,
2040 X_last_updated_by => X_last_updated_by,
2041 X_last_update_login => X_last_update_login,
2042 p_log_level_rec => p_log_level_rec)) then
2043 adj_table.delete;
2044 h_cache_index := 0;
2045
2046 FA_SRVR_MSG.ADD_MESSAGE
2047 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2048 p_log_level_rec => p_log_level_rec);
2049 return FALSE;
2050 end if;
2051 elsif (adj_ptr.selection_mode=FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_REVAL) then -- YYOON
2052 if (not fadoact
2053 (X_last_update_date => X_last_update_date,
2054 X_last_updated_by => X_last_updated_by,
2055 X_last_update_login => X_last_update_login,
2056 p_log_level_rec => p_log_level_rec)) then
2057 adj_table.delete;
2058 h_cache_index := 0;
2059
2060 FA_SRVR_MSG.ADD_MESSAGE
2061 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2062 p_log_level_rec => p_log_level_rec);
2063 return FALSE;
2064 end if;
2065 elsif (adj_ptr.selection_mode=FA_ADJUST_TYPE_PKG.FA_AJ_SINGLE) then
2066 if (not fadosgl
2067 (X_last_update_date => X_last_update_date,
2068 X_last_updated_by => X_last_updated_by,
2069 X_last_update_login => X_last_update_login,
2070 p_log_level_rec => p_log_level_rec)) then
2071 adj_table.delete;
2072 h_cache_index := 0;
2073
2074 FA_SRVR_MSG.ADD_MESSAGE
2075 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2076 p_log_level_rec => p_log_level_rec);
2077 return FALSE;
2078 end if;
2079 elsif (adj_ptr.selection_mode=FA_ADJUST_TYPE_PKG.FA_AJ_TRANSFER_SINGLE) then
2080 if (not fadosglf
2081 (X_last_update_date => X_last_update_date,
2082 X_last_updated_by => X_last_updated_by,
2083 X_last_update_login => X_last_update_login,
2084 p_log_level_rec => p_log_level_rec)) then
2085 adj_table.delete;
2086 h_cache_index := 0;
2087
2088 FA_SRVR_MSG.ADD_MESSAGE
2089 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2090 p_log_level_rec => p_log_level_rec);
2091 return FALSE;
2092 end if;
2093 elsif (adj_ptr.selection_mode in (FA_ADJUST_TYPE_PKG.FA_AJ_CLEAR, FA_ADJUST_TYPE_PKG.FA_AJ_CLEAR_PARTIAL)) then
2094 if (not fadoclr
2095 (X_last_update_date => X_last_update_date,
2096 X_last_updated_by => X_last_updated_by,
2097 X_last_update_login => X_last_update_login,
2098 p_log_level_rec => p_log_level_rec)) then
2099 adj_table.delete;
2100 h_cache_index := 0;
2101
2102 FA_SRVR_MSG.ADD_MESSAGE
2103 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2104 p_log_level_rec => p_log_level_rec);
2105 return FALSE;
2106 end if;
2107 elsif (adj_ptr.selection_mode=FA_ADJUST_TYPE_PKG.FA_AJ_RETIRE) then
2108 if (not fadoret
2109 (X_last_update_date => X_last_update_date,
2110 X_last_updated_by => X_last_updated_by,
2111 X_last_update_login => X_last_update_login,
2112 p_log_level_rec => p_log_level_rec)) then
2113 adj_table.delete;
2114 h_cache_index := 0;
2115
2116 FA_SRVR_MSG.ADD_MESSAGE
2117 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2118 p_log_level_rec => p_log_level_rec);
2119 return FALSE;
2120 end if;
2121 else
2122 -- undefined mode
2123 adj_table.delete;
2124 h_cache_index := 0;
2125
2126 FA_SRVR_MSG.ADD_MESSAGE
2127 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2128 NAME => 'FA_INS_ADJ_BAD_MODE',
2129 p_log_level_rec => p_log_level_rec);
2130 return FALSE;
2131 end if; -- of adj_ptr.selection_mode
2132 end if; -- end of else-not flush mode only
2133
2134 if (adj_ptr.flush_adj_flag=TRUE AND adj_ptr.transaction_header_id<>0) then
2135 -- Flush out the inserts into the cache if the flush_adj_flag
2136 -- was set and we are not in "flush only" mode
2137 if (not fainajc
2138 (X_flush_mode => TRUE,
2139 X_mode => FALSE,
2140 X_last_update_date => X_last_update_date,
2141 X_last_updated_by => X_last_updated_by,
2142 X_last_update_login => X_last_update_login,
2143 p_log_level_rec => p_log_level_rec)) then
2144 adj_table.delete;
2145 h_cache_index := 0;
2146
2147 FA_SRVR_MSG.ADD_MESSAGE
2148 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2149 p_log_level_rec => p_log_level_rec);
2150 return FALSE;
2151 end if;
2152 end if;
2153
2154 adj_ptr_passed.amount_inserted := adj_ptr.amount_inserted;
2155
2156 IF (p_log_level_rec.statement_level) then
2157 FA_DEBUG_PKG.ADD
2158 (fname => 'FA_INS_ADJUST_PKG.faxinaj',
2159 element => 'adj inserted - BEFORE RETURN',
2160 value => adj_ptr_passed.amount_inserted,
2161 p_log_level_rec => p_log_level_rec);
2162 end if;
2163 return TRUE;
2164
2165 exception
2166 when others then
2167 FA_SRVR_MSG.ADD_SQL_ERROR
2168 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinaj',
2169 p_log_level_rec => p_log_level_rec);
2170 return FALSE;
2171 END faxinaj;
2172
2173 -----------------------------------------------------------------
2174
2175 FUNCTION faxinadj (X_transaction_header_id in number,
2176 X_source_type_code in varchar2,
2177 X_adjustment_type in varchar2,
2178 X_debit_credit_flag in varchar2,
2179 X_code_combination_id in number,
2180 X_book_type_code in varchar2,
2181 X_period_counter_created in number,
2182 X_asset_id in number,
2183 X_adjustment_amount in number,
2184 X_period_counter_adjusted in number,
2185 X_distribution_id in number,
2186 X_annualized_adjustment in number,
2187 X_last_update_date in date default sysdate,
2188 X_account in varchar2,
2189 X_account_type in varchar2,
2190 X_current_units in number,
2191 X_selection_mode in varchar2,
2192 X_flush_adj_flag in varchar2,
2193 X_gen_ccid_flag in varchar2,
2194 X_leveling_flag in varchar2,
2195 X_asset_invoice_id in number,
2196 X_amount_inserted out nocopy number,
2197 X_last_updated_by number default -1,
2198 X_last_update_login number default -1,
2199 X_init_message_flag varchar2 default 'NO',
2200 p_log_level_rec in fa_api_types.log_level_rec_type
2201 ) return boolean is
2202
2203 adj_ptr_local FA_ADJUST_TYPE_PKG.fa_adj_row_struct;
2204
2205 BEGIN <<faxinadj>>
2206
2207 if (X_init_message_flag = 'YES') then
2208 -- initialize Message and Debug stacks
2209 FA_SRVR_MSG.Init_Server_Message;
2210 FA_DEBUG_PKG.Initialize;
2211 end if;
2212
2213 -- Get the parameters passed by form
2214 adj_ptr_local.transaction_header_id := X_transaction_header_id;
2215 adj_ptr_local.asset_invoice_id := X_asset_invoice_id;
2216 adj_ptr_local.source_type_code := X_source_type_code;
2217 adj_ptr_local.adjustment_type := X_adjustment_type;
2218 adj_ptr_local.debit_credit_flag := X_debit_credit_flag;
2219 adj_ptr_local.code_combination_id := X_code_combination_id;
2220 adj_ptr_local.book_type_code := X_book_type_code;
2221 adj_ptr_local.period_counter_created := X_period_counter_created;
2222 adj_ptr_local.asset_id := X_asset_id;
2223 adj_ptr_local.adjustment_amount := X_adjustment_amount;
2224 adj_ptr_local.period_counter_adjusted := X_period_counter_adjusted;
2225 adj_ptr_local.distribution_id := X_distribution_id;
2226 adj_ptr_local.annualized_adjustment := X_annualized_adjustment;
2227 adj_ptr_local.last_update_date := X_last_update_date;
2228 adj_ptr_local.account := X_account;
2229 adj_ptr_local.account_type := X_account_type;
2230
2231 if (X_current_units=0) then
2232 FA_SRVR_MSG.ADD_MESSAGE
2233 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinadj',
2234 NAME => 'FA_INS_ADJ_ZERO_UNITS',
2235 p_log_level_rec => p_log_level_rec);
2236 return FALSE;
2237 end if;
2238 adj_ptr_local.current_units := X_current_units;
2239
2240 if (X_selection_mode='ACTIVE') then
2241 adj_ptr_local.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE;
2242 elsif (X_selection_mode='SINGLE') then
2243 adj_ptr_local.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_SINGLE;
2244 else
2245 FA_SRVR_MSG.ADD_MESSAGE
2246 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinadj',
2247 NAME => 'FA_INS_ADJ_BAD_SEL_MODE',
2248 p_log_level_rec => p_log_level_rec);
2249 return FALSE;
2250 end if;
2251
2252 if (X_flush_adj_flag='TRUE') then
2253 adj_ptr_local.flush_adj_flag := TRUE;
2254 elsif (X_flush_adj_flag='FALSE') then
2255 adj_ptr_local.flush_adj_flag:=FALSE;
2256 else
2257 FA_SRVR_MSG.ADD_MESSAGE
2258 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinadj',
2259 NAME => 'FA_INS_ADJ_BAD_FLUSH_FLAG',
2260 p_log_level_rec => p_log_level_rec);
2261 return FALSE;
2262 end if;
2263
2264 if (X_gen_ccid_flag='TRUE') then
2265 adj_ptr_local.gen_ccid_flag := TRUE;
2266 elsif (X_gen_ccid_flag='FALSE') then
2267 adj_ptr_local.gen_ccid_flag:=FALSE;
2268 else
2269 FA_SRVR_MSG.ADD_MESSAGE
2270 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinadj',
2271 NAME => 'FA_INS_ADJ_BAD_GEN_CCID_FLAG',
2272 p_log_level_rec => p_log_level_rec);
2273 return FALSE;
2274 end if;
2275
2276 if (X_leveling_flag='TRUE') then
2277 adj_ptr_local.leveling_flag := TRUE;
2278 else
2279 adj_ptr_local.leveling_flag:=FALSE;
2280 end if;
2281
2282 adj_ptr_local.mrc_sob_type_code := 'P';
2283
2284 -- Call the Insert into Adjustments Function
2285 if (not faxinaj
2286 (adj_ptr_local,
2287 X_last_update_date,
2288 X_last_updated_by,
2289 X_last_update_login,
2290 p_log_level_rec => p_log_level_rec)) then
2291 FA_SRVR_MSG.ADD_MESSAGE
2292 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinadj',
2293 p_log_level_rec => p_log_level_rec);
2294 return FALSE;
2295 end if;
2296
2297 --Return the amount inserted to the form
2298 X_amount_inserted := adj_ptr_local.amount_inserted;
2299 return TRUE;
2300
2301 exception
2302 when others then
2303 FA_SRVR_MSG.ADD_SQL_ERROR
2304 (CALLING_FN => 'FA_INS_ADJUST_PKG.faxinadj',
2305 p_log_level_rec => p_log_level_rec);
2306 return FALSE;
2307
2308 END faxinadj;
2309
2310 END FA_INS_ADJUST_PKG;