DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_INS_ADJUST_PKG

Source


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