DBA Data[Home] [Help]

APPS.FA_GAINLOSS_UPD_PKG SQL Statements

The following lines contain the word 'select', 'insert', 'update' or 'delete':

Line: 10

| FUNCTION   Set selection_mode accordingly for Tax book
|
|
| History     YYOON          05/23/06         Created
|                            added for the bug 5149832 and 5231996
|===========================================================================*/


Function faginfo(
        RET                 IN fa_ret_types.ret_struct,
        BK                  IN fa_ret_types.book_struct,
        cpd_ctr             IN NUMBER,
        today               IN DATE,
        user_id             IN NUMBER,
        calling_module      IN  varchar,
        candidate_mode      IN  varchar,
        set_adj_row         IN  boolean,
        unit_ret_in_corp    OUT nocopy boolean,
        ret_id_in_corp      OUT nocopy number,
        th_id_out_in_corp   OUT nocopy number,
        balance_tfr_in_tax  OUT nocopy number,
        adj_row             IN  OUT nocopy FA_ADJUST_TYPE_PKG.fa_adj_row_struct,
        p_log_level_rec     IN  FA_API_TYPES.log_level_rec_type default null
        ) return boolean IS

    l_unit_ret_in_corp    boolean;
Line: 38

    l_selection_retid     number;
Line: 59

               select r.retirement_id
                     ,r.units
                 into l_ret_id_in_corp
                     ,l_units_retired
               from fa_transaction_headers sth
                   ,fa_retirements r
                   ,fa_book_controls bc
               where sth.transaction_header_id = RET.th_id_in
                 and sth.asset_id = RET.asset_id
                 and sth.book_type_code = RET.book
                 and bc.book_type_code = sth.book_type_code
                 and bc.book_class = 'TAX'
                 and r.asset_id = sth.asset_id
                 and r.transaction_header_id_in = nvl(sth.source_transaction_header_id, sth.transaction_header_id)
                 and rownum = 1;
Line: 90

               select transaction_header_id_out
                 into l_id_out
               from fa_distribution_history
               where retirement_id =
                (select r.retirement_id
                 from fa_transaction_headers sth
                     ,fa_retirements r
                 where sth.transaction_header_id = RET.th_id_in
                   and sth.asset_id = RET.asset_id
                   and sth.book_type_code = RET.book
                   and r.asset_id = sth.asset_id
                   and r.transaction_header_id_in = nvl(sth.source_transaction_header_id, sth.transaction_header_id)
                )
                and transaction_header_id_out is not null
                and rownum = 1;
Line: 122

                    select count(*)
                      into l_balance_tfr_in_tax
                    from fa_adjustments
                    where book_type_code = RET.book
                      and asset_id = RET.asset_id
                      and transaction_header_id = l_id_out -- Corp's TRANSFER OUT THID
                      and source_type_code in ('TRANSFER', 'RETIREMENT')
                     --and adjustment_amount <> 0 -- BUG 6655838
                      and rownum = 1;
Line: 132

                    select count(*)
                      into l_balance_tfr_in_tax
                    from fa_adjustments_mrc_v
                    where book_type_code = RET.book
                      and asset_id = RET.asset_id
                      and transaction_header_id = l_id_out -- Corp's TRANSFER OUT THID
                      and source_type_code in ('TRANSFER', 'RETIREMENT') -- TRANSFER for part-ret, RETIREMENT for reinst of full retirement
                      --and adjustment_amount <> 0
                      and rownum = 1;
Line: 169

                 select 2 -- this has to be set to 2 to differ from 1 for a regular balance tfr; used for fagurt
Line: 176

                   (select max(distribution_id)
                    from fa_adjustments
                    where book_type_code = RET.book
                      and asset_id = RET.asset_id
                      -- and source_type_code in ('ADDITION')
                      and adjustment_amount <> 0
                      and transaction_header_id
                          = (select max(transaction_header_id)
                             from fa_transaction_headers
                             where book_type_code = RET.book
                               and asset_id = RET.asset_id
                               and transaction_header_id < RET.th_id_in -- ret thid in TAX
                            )
                   );
Line: 192

		 select 2 -- this has to be set to 2 to differ from 1 for a regular balance tfr; used for fagurt
Line: 199

                   (select max(distribution_id)
                    from fa_adjustments_mrc_v
                    where book_type_code = RET.book
                      and asset_id = RET.asset_id
                      -- and source_type_code in ('ADDITION')
                      and adjustment_amount <> 0
                      and transaction_header_id
                          = (select max(transaction_header_id)
                             from fa_transaction_headers
                             where book_type_code = RET.book
                               and asset_id = RET.asset_id
                               and transaction_header_id < RET.th_id_in -- ret thid in TAX
                            )
                   );
Line: 241

                 adj_row.selection_thid := 0;
Line: 242

                 adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 244

                    fa_debug_pkg.add(l_calling_fn, '++++ selection_mode', 'FA_STD_TYPES.FA_AJ_ACTIVE', p_log_level_rec);
Line: 248

                   adj_row.selection_retid := l_ret_id_in_corp;
Line: 250

                   adj_row.selection_mode := FA_STD_TYPES.FA_AJ_RETIRE;
Line: 252

                      fa_debug_pkg.add(l_calling_fn, '++++ selection_mode', 'FA_STD_TYPES.FA_AJ_RETIRE', p_log_level_rec);
Line: 255

                   adj_row.selection_thid := l_id_out;
Line: 256

                   adj_row.selection_mode := FA_STD_TYPES.FA_AJ_CLEAR_PARTIAL;
Line: 258

                      fa_debug_pkg.add(l_calling_fn, '++++ selection_mode', 'FA_STD_TYPES.FA_AJ_CLEAR_PARTIAL', p_log_level_rec);
Line: 267

               adj_row.selection_thid := 0;
Line: 268

               adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 270

                  fa_debug_pkg.add(l_calling_fn, '++++ in ELSE:  selection_mode', 'FA_STD_TYPES.FA_AJ_ACTIVE', p_log_level_rec);
Line: 349

        SELECT (MONTHS_BETWEEN(trunc(h_date_retired),
			       trunc(h_date_placed)) / 12) + 1
	INTO   h_years_kept
  	FROM   FA_RETIREMENTS
	WHERE  RETIREMENT_ID = h_retirement_id;
Line: 356

    	  SELECT  farecap.itc_recapture_id ,
	  	  h_itc_amount * farecap.itc_recapture_rate *
		  h_cost_frac
	  INTO
	    	  h_itc_recapture_id,
		  h_recaptured
	  FROM	  fa_itc_recapture_rates farecap,
		  fa_itc_rates farate
	  WHERE	  farecap.tax_year = farate.tax_year
	  AND	  farecap.life_in_months = farate.life_in_months
	  AND	  farecap.year_of_retirement = h_years_kept
	  AND	  farate.itc_amount_id = h_itc_amount_id;
Line: 384

     	    UPDATE	fa_retirements fr
	    SET	 	fr.itc_recaptured = h_recaptured,
			fr.itc_recapture_id = h_itc_recapture_id
    	    WHERE	fr.retirement_id = h_retirement_id;
Line: 389

     	    UPDATE	fa_retirements_mrc_v fr
	    SET	 	fr.itc_recaptured = h_recaptured,
			fr.itc_recapture_id = h_itc_recapture_id
    	    WHERE	fr.retirement_id = h_retirement_id;
Line: 419

|       It calculates GAIN/LOSS, NBV_RETIRED, STL_DEPRN_AMOUNT. Update the   |
| status in FA_RETIREMENTS table from 'PENDING' to 'PROCESSED'. It           |
| also inserts  GAIN/LOSS, PROCEEDS_OF_SALE, and COST_OF_REMOVAL to          |
| FA_ADJUSTMENTS table.                                                      |
|                                                                            |
|  HISTORY     01/12/89    R Rumanang  Created                               |
|              08/30/89    R Rumanang  Updated to insert to                  |
|                                      FA_ADJUSTMENTS.                       |
|              01/31/90    R Rumanang  Insert PROCEEDS_OF_SALE to            |
|                                      ADJUSTMENT                            |
|              05/03/91    M Chan      Rewrote for MPL 9                     |
|              12/30/96    S Behura    Rewriting in PL/SQL                   |
*============================================================================*/

FUNCTION fagurt(ret       in out nocopy fa_ret_types.ret_struct,
                bk        in out nocopy fa_ret_types.book_struct,
                cpd_ctr          number,
                dpr       in out nocopy FA_STD_TYPES.dpr_struct,
                cost_frac in     number,
                retpdnum  in out nocopy number,
                today     in     date,
                user_id          number,
		p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) return boolean IS

    reval_deprn_amt     number;
Line: 487

    X_LAST_UPDATE_DATE date := sysdate;
Line: 488

    X_last_updated_by number := -1;
Line: 489

    X_last_update_login number := -1;
Line: 519

    SELECT DISTRIBUTION_ID,
           CODE_COMBINATION_ID,
           LOCATION_ID,
           ASSIGNED_TO, -- bug 3519644
           TRANSACTION_HEADER_ID_OUT
    FROM   FA_DISTRIBUTION_HISTORY dist,
           FA_BOOK_CONTROLS bc
    -- Bug 5149832 WHERE  RETIREMENT_ID  = ret.retirement_id
    WHERE  RETIREMENT_ID  = nvl(l_ret_id_in_corp, ret.retirement_id)
    AND    ASSET_ID       = ret.asset_id
    -- Bug 5149832 AND    BOOK_TYPE_CODE = ret.book;
Line: 538

    SELECT DISTRIBUTION_ID
    FROM   FA_DISTRIBUTION_HISTORY dist,
           FA_BOOK_CONTROLS bc
    WHERE  dist.TRANSACTION_HEADER_ID_IN = c_th_id_out
    AND    dist.TRANSACTION_HEADER_ID_OUT is NULL
    AND    dist.CODE_COMBINATION_ID = c_ccid
    AND    dist.LOCATION_ID = c_location_id
    AND    dist.ASSET_ID       = ret.asset_id
    -- Bug 5149832 AND    BOOK_TYPE_CODE = ret.book
    AND    bc.book_type_code = RET.book
    AND    dist.BOOK_TYPE_CODE = bc.distribution_source_book
    AND    nvl (dist.assigned_to, -99) = nvl (c_assigned_to, -99); -- bug 3519644
Line: 557

    SELECT DISTRIBUTION_ID
    FROM   FA_DISTRIBUTION_HISTORY dist,
           FA_BOOK_CONTROLS bc
    WHERE
           dist.CODE_COMBINATION_ID = c_ccid
    AND    dist.LOCATION_ID = c_location_id
    AND    dist.ASSET_ID       = RET.asset_id
    AND    bc.book_type_code = RET.book
    AND    bc.book_class = 'TAX'
    AND    dist.BOOK_TYPE_CODE = bc.distribution_source_book
    AND    dist.transaction_header_id_in =
          (select max(adj.transaction_header_id) -- get the latest THID in the same period that caused DIST ID to change
           from fa_adjustments adj
           where adj.book_type_code = RET.book
             and adj.asset_id = RET.asset_id
             and adj.source_type_code in ('RETIREMENT', 'TRANSFER') -- RETIREMENT: balance tfr for Reinstatement, TRANSFER: balance tfr for Retirement
             and adj.period_counter_created = cpd_ctr
             and adj.adjustment_type = 'COST'
             and not exists -- check to see if adj.THID is from Corp
                 (select 1
                  from fa_transaction_headers th
                  where th.transaction_header_id = adj.transaction_header_id
                    and th.book_type_code = RET.book
                    and th.asset_id = RET.asset_id
                 )
          )
    ;
Line: 589

    SELECT DISTRIBUTION_ID,
           CODE_COMBINATION_ID
    FROM   FA_DISTRIBUTION_HISTORY dist,
           FA_BOOK_CONTROLS bc
    WHERE  TRANSACTION_HEADER_ID_OUT is NULL
    AND    ASSET_ID       = c_asset_id
    AND    bc.book_type_code = ret.book
    AND    dist.book_type_code = bc.distribution_source_book;
Line: 603

    SELECT SUM(NVL(DECODE(DEBIT_CREDIT_FLAG,
                            'CR', ADJUSTMENT_AMOUNT,
                                  -1 * ADJUSTMENT_AMOUNT), 0)*
               DECODE(ADJUSTMENT_TYPE, 'RESERVE', -1, 1))
    FROM   FA_ADJUSTMENTS
    WHERE  (DISTRIBUTION_ID       = c_dist_id
         OR DISTRIBUTION_ID       = c_new_dist_id)
    AND    BOOK_TYPE_CODE         = ret.book
    AND    PERIOD_COUNTER_CREATED = cpd_ctr
    AND    SOURCE_TYPE_CODE       = c_source_type_code
    AND    ADJUSTMENT_TYPE        = c_adjustment_type
    AND    TRANSACTION_HEADER_ID  = ret.th_id_in;
Line: 620

    SELECT SUM(NVL(DECODE(DEBIT_CREDIT_FLAG,
                            'CR', ADJUSTMENT_AMOUNT,
                                  -1 * ADJUSTMENT_AMOUNT), 0)*
               DECODE(ADJUSTMENT_TYPE, 'RESERVE', -1, 1))
    FROM   FA_ADJUSTMENTS_MRC_V
    WHERE  (DISTRIBUTION_ID       = c_dist_id
         OR DISTRIBUTION_ID       = c_new_dist_id)
    AND    BOOK_TYPE_CODE         = ret.book
    AND    PERIOD_COUNTER_CREATED = cpd_ctr
    AND    SOURCE_TYPE_CODE       = c_source_type_code
    AND    ADJUSTMENT_TYPE        = c_adjustment_type
    AND    TRANSACTION_HEADER_ID  = ret.th_id_in;
Line: 638

      select units
      from   fa_asset_history
      where  asset_id = c_asset_id
      and    transaction_header_id_out is null;
Line: 650

      select adjustment_amount
      from   fa_adjustments
      where  asset_id = bk.group_asset_id
      and    book_type_code = ret.book
      and    transaction_header_id = ret.th_id_in
      and    adjustment_type = 'RESERVE';
Line: 658

       select sum(decode(adjustment_type
                ,'COST', decode(debit_credit_flag,'CR', nvl(adjustment_amount,0), -1 * nvl(adjustment_amount,0))
                ,'RESERVE', decode(debit_credit_flag,'DR', -1 * nvl(adjustment_amount,0), nvl(adjustment_amount,0))
              ,0))
       from   fa_adjustments
       where  asset_id = ret.asset_id
       and    book_type_code = ret.book
       and    transaction_header_id = ret.th_id_in
       and    source_type_code='RETIREMENT'
       and    adjustment_type in ('COST', 'RESERVE');
Line: 783

       select  bc.proceeds_of_sale_clearing_acct,
               bc.proceeds_of_sale_gain_acct,
               bc.proceeds_of_sale_loss_acct,
               bc.cost_of_removal_clearing_acct,
               bc.cost_of_removal_gain_acct,
               bc.cost_of_removal_loss_acct,
               bc.nbv_retired_gain_acct,
               bc.nbv_retired_loss_acct,
               bc.reval_rsv_retired_gain_acct,
               bc.reval_rsv_retired_loss_acct,
               decode(bc.retire_reval_reserve_flag,'NO',0,
                      decode(cb.reval_reserve_acct,null,0,1)),
               ad.asset_category_id
       into    h_proc_of_sale_clearing_acct,
               h_proceeds_of_sale_gain_acct,
               h_proceeds_of_sale_loss_acct,
               h_cost_of_removal_clr_acct,
               h_cost_of_removal_gain_acct,
               h_cost_of_removal_loss_acct,
               h_nbv_retired_gain_acct,
               h_nbv_retired_loss_acct,
               h_reval_rsv_retired_gain_acct,
               h_reval_rsv_retired_loss_acct,
               h_retire_reval_flag,
               l_asset_cat_rec_m.category_id
       from    fa_book_controls bc,
               fa_additions_b ad, fa_category_books cb
       where   ad.asset_id = h_asset_id
       and     cb.category_id = ad.asset_category_id
       and     cb.book_type_code = h_book
       and     bc.book_type_code = cb.book_type_code;
Line: 880

                UPDATE  fa_retirements fr
                SET     fr.nbv_retired   = h_nbv_retired,
                        fr.gain_loss_amount = h_gain_loss,
                        fr.stl_deprn_amount = h_stl_deprn,
                        fr.reval_reserve_retired = h_reval_rsv_retired,
			bonus_reserve_retired = h_bonus_rsv_retired,
                        fr.unrevalued_cost_retired =
                                        h_unrevalued_cost_retired,
                        fr.status                = 'PROCESSED',
                        fr.last_update_date = h_today,
                        fr.last_updated_by  = h_user_id
                WHERE
                        fr.retirement_id         = h_retirement_id;
Line: 894

                UPDATE  fa_retirements_mrc_v fr
                SET     fr.nbv_retired   = h_nbv_retired,
                        fr.gain_loss_amount = h_gain_loss,
                        fr.stl_deprn_amount = h_stl_deprn,
                        fr.reval_reserve_retired = h_reval_rsv_retired,
			bonus_reserve_retired = h_bonus_rsv_retired,
                        fr.unrevalued_cost_retired =
                                        h_unrevalued_cost_retired,
                        fr.status                = 'PROCESSED',
                        fr.last_update_date = h_today,
                        fr.last_updated_by  = h_user_id
                WHERE
                        fr.retirement_id         = h_retirement_id;
Line: 919

       The amount that we inserted into the table must be positive.
    */

       -- Setting l_unit_ret_in_corp
       if NOT faginfo(
                RET, BK, cpd_ctr,today, user_id
               ,calling_module => l_calling_fn
               ,candidate_mode => 'RETIRE'
               ,set_adj_row => FALSE -- just to get l_unit_ret_in_corp and h_id_out
               ,unit_ret_in_corp => l_unit_ret_in_corp
               ,ret_id_in_corp => l_ret_id_in_corp
               ,th_id_out_in_corp => h_id_out
               ,balance_tfr_in_tax => l_balance_tfr_in_tax
               ,adj_row => adj_row
               ,p_log_level_rec => p_log_level_rec
                           ) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn);
Line: 959

       adj_row.last_update_date := today;
Line: 966

       adj_row.selection_thid := 0;
Line: 973

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 974

          adj_row.selection_retid := 0;
Line: 978

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 1002

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_RETIRE;
Line: 1003

          adj_row.selection_retid := ret.retirement_id;
Line: 1049

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
                fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                ,p_log_level_rec => p_log_level_rec);
Line: 1071

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn
                              ,p_log_level_rec => p_log_level_rec);
Line: 1113

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
             fa_srvr_msg.add_message(calling_fn => l_calling_fn
                          ,p_log_level_rec => p_log_level_rec);
Line: 1135

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn
                              ,p_log_level_rec => p_log_level_rec);
Line: 1177

          adj_row.selection_mode := fa_adjust_type_pkg.FA_AJ_TRANSFER_SINGLE;
Line: 1219

             SELECT count(*)
             INTO   tot_dist_lines
             FROM   FA_DISTRIBUTION_HISTORY dist,
                    FA_BOOK_CONTROLS bc
             WHERE  TRANSACTION_HEADER_ID_OUT is NULL
             AND    ASSET_ID       = RET.asset_id
             AND    bc.book_type_code = RET.book
             AND    dist.book_type_code = bc.distribution_source_book;
Line: 1230

             SELECT count(*)
             INTO   tot_dist_lines
             FROM   FA_DISTRIBUTION_HISTORY dist,
                    FA_BOOK_CONTROLS bc
             WHERE  dist.RETIREMENT_ID  = nvl(l_ret_id_in_corp, ret.retirement_id)
             AND    dist.ASSET_ID       = RET.asset_id
             AND    bc.book_type_code = RET.book
             AND    dist.book_type_code = bc.distribution_source_book;
Line: 1403

                                               X_last_update_date,
                                               X_last_updated_by,
                                               X_last_update_login
                                               ,p_log_level_rec => p_log_level_rec)) then
                fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                ,p_log_level_rec => p_log_level_rec);
Line: 1456

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 1457

          adj_row.selection_retid := 0;
Line: 1492

                                            X_last_update_date,
                                            X_last_updated_by,
                                            X_last_update_login
                                            ,p_log_level_rec => p_log_level_rec)) then
             fa_srvr_msg.add_message(calling_fn => l_calling_fn
                          ,p_log_level_rec => p_log_level_rec);
Line: 1514

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 1515

          adj_row.selection_retid := 0;
Line: 1518

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_RETIRE;
Line: 1519

          adj_row.selection_retid := ret.retirement_id;
Line: 1548

               value   => adj_row.selection_mode
               ,p_log_level_rec => p_log_level_rec);
Line: 1561

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn
                              ,p_log_level_rec => p_log_level_rec);
Line: 1592

            adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 1593

            adj_row.selection_retid := 0;
Line: 1608

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn
                              ,p_log_level_rec => p_log_level_rec);
Line: 1634

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn
                              ,p_log_level_rec => p_log_level_rec);
Line: 1656

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn
                              ,p_log_level_rec => p_log_level_rec);
Line: 1683

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
               fa_srvr_msg.add_message(calling_fn => l_calling_fn
                              ,p_log_level_rec => p_log_level_rec);
Line: 1779

    X_LAST_UPDATE_DATE date := sysdate;
Line: 1780

    X_last_updated_by number := -1;
Line: 1781

    X_last_update_login number := -1;
Line: 1802

       select  asset_cost_acct,
               nvl(cip_cost_acct, '0')
       into    h_asset_cost_acct,
               h_cip_cost_acct
       from    fa_additions_b    faadd,
               fa_category_books facb
       where   faadd.asset_id = h_asset_id
       and     facb.category_id = faadd.asset_category_id
       and     facb.book_type_code = h_book;
Line: 1820

       adj_row.last_update_date := today;
Line: 1827

       adj_row.selection_retid := 0;
Line: 1846

           adj_row.selection_thid := 0;
Line: 1850

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_CLEAR;
Line: 1853

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 1879

             fa_debug_pkg.add(l_calling_fn, '++ adj_row.selection_thid', adj_row.selection_thid, p_log_level_rec);
Line: 1886

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
              fa_srvr_msg.add_message(calling_fn => l_calling_fn
                            ,p_log_level_rec => p_log_level_rec);
Line: 1897

            select      distinct nvl(transaction_header_id_out,0)
            into        h_id_out
            from        fa_distribution_history
            where       asset_id = h_asset_id
            and         book_type_code = h_book
            and         retirement_id = h_ret_id;
Line: 1907

           adj_row.selection_thid := h_id_out;
Line: 1909

           adj_row.selection_mode := FA_STD_TYPES.FA_AJ_CLEAR_PARTIAL;
Line: 1913

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
              fa_srvr_msg.add_message(calling_fn => l_calling_fn
                            ,p_log_level_rec => p_log_level_rec);
Line: 1923

           adj_row.adjustment_amount := adj_row.amount_inserted-
						ret.cost_retired;
Line: 1927

            select      nvl(units,0)
            into        h_cur_units
            from        fa_asset_history
            where       asset_id = h_asset_id
            and         date_ineffective is null;
Line: 1936

              select count(*)
                into l_dummy
              from fa_distribution_history
              where asset_id = h_asset_id
                and date_ineffective is null
                and transaction_header_id_in = h_id_out;
Line: 1943

              select sum(nvl(units_assigned,0))
                into h_cur_units
              from fa_distribution_history
              where asset_id = h_asset_id
                and date_ineffective is null
                and transaction_header_id_in = h_id_out;
Line: 1967

              adj_row.selection_thid := h_id_out;
Line: 1969

              adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE_PARTIAL;
Line: 1974

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
                fa_srvr_msg.add_message(calling_fn => l_calling_fn
                            ,p_log_level_rec => p_log_level_rec);
Line: 2007

  |     insert them into fa_adjustments table.                          |
  |                                                                     |
  | History     11/13/92        L. Sun          Created                 |
  |                                                                     |
  |             12/31/96        S. Behura       Rewrote into PL/SQL     |
  |             11/08/97        S. Behura      Rewrote into PL/SQL(10.7)|
  *=====================================================================*/

FUNCTION farboe(asset_id number, book in varchar2,
                current_fiscal_yr number, cost_frac in number,
                start_pdnum number, end_pdnum number,
                adj_type in varchar2, pds_per_year number,
                dpr_evenly number, fiscal_year_name in varchar2,
                units_retired number, th_id_in number,
                cpd_ctr number, today in date,
                current_units number, retirement_id number, d_cal in varchar2,
                dpr in out nocopy FA_STD_TYPES.dpr_struct, p_cal in varchar2,
                pds_catchup number, depreciate_lastyr boolean,
                start_pp number, end_pp number,
                mrc_sob_type_code in varchar2,
                ret in fa_ret_types.ret_struct,
                bk in out nocopy fa_ret_types.book_struct,
		p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) Return BOOLEAN IS

    farboe_err          exception;
Line: 2157

    X_LAST_UPDATE_DATE date := sysdate;
Line: 2158

    X_last_updated_by number := -1;
Line: 2159

    X_last_update_login number := -1;
Line: 2165

     * rows yet, and the original select statement would not have
     * returned these adjustment amounts.  --y.i.
     */
    CURSOR DEPRN_ADJ IS
        SELECT  fadd.distribution_id,
                fadh.code_combination_id,
                -1 * h_cost_frac *
                    (decode (h_adj_type,
                             'EXPENSE', fadd.deprn_amount,
			     'BONUS EXPENSE', fadd.bonus_deprn_amount,
                             'REVAL EXPENSE', fadd.reval_deprn_expense,
                             'REVAL AMORT', fadd.reval_amortization) -
                     nvl(sum(decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                             faadj.adjustment_amount), 0)),
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.adjustment_amount), 0),
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.annualized_adjustment), 0),
                nvl(-1 * h_cost_frac *
                   (decode (h_adj_type,
                            'EXPENSE',(fadd.deprn_amount -
                                        fadd.deprn_adjustment_amount),
                            'BONUS EXPENSE',(fadd.bonus_deprn_amount -
                                        fadd.bonus_deprn_adjustment_amount),
                            'REVAL EXPENSE', fadd.reval_deprn_expense,
                            'REVAL AMORT', fadd.reval_amortization)),0),
                nvl(-1 * h_cost_frac *
                    (decode (h_adj_type,
                             'EXPENSE', fadd.deprn_amount,
			     'BONUS EXPENSE', fadd.bonus_deprn_amount,
                             'REVAL EXPENSE', fadd.reval_deprn_expense,
                             'REVAL AMORT', fadd.reval_amortization)),0),
                nvl(faadj.source_type_code, 'DEPRECIATION'),
                fadp.period_counter
                FROM
                    fa_distribution_history     fadh,
                    fa_deprn_detail             fadd,
                    fa_deprn_periods            fadp,
                    fa_adjustments              faadj
                WHERE
                       fadd.asset_id = h_asset_id
                AND    fadd.distribution_id = fadh.distribution_id
                AND    fadd.book_type_code = h_book
                AND    fadd.deprn_source_code = 'D'
                AND    fadd.period_counter = fadp.period_counter
                AND    fadp.period_num = h_i
                AND    fadp.book_type_code = h_book
                AND    fadp.fiscal_year = h_current_fiscal_yr
                AND    faadj.distribution_id(+) = fadd.distribution_id
                AND    faadj.book_type_code(+) = fadd.book_type_code
                AND    faadj.asset_id(+) = fadd.asset_id
                AND    faadj.period_counter_created(+) = fadd.period_counter
                AND    faadj.adjustment_type(+) = h_adj_type
        GROUP BY
                    fadd.distribution_id,
                    fadh.code_combination_id,
                    fadd.deprn_amount,
                    fadd.deprn_adjustment_amount,
                    fadd.bonus_deprn_amount,
                    fadd.bonus_deprn_adjustment_amount,
                    fadd.reval_deprn_expense,
                    fadd.reval_amortization,
                    faadj.distribution_id,
                    faadj.source_type_Code,
                    faadj.adjustment_amount,
		    fadp.period_counter
        UNION
        SELECT  fadh.distribution_id,
                fadh.code_combination_id,
                0,
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.adjustment_amount), 0),
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.annualized_adjustment), 0),
                0,
                0,
                nvl(faadj.source_type_code, 'DEPRECIATION'),
		fadp.period_counter
                FROM
                    fa_distribution_history     fadh,
                    fa_deprn_periods            fadp,
                    fa_adjustments              faadj
                WHERE
                       fadp.period_num = h_i
                AND    fadp.book_type_code = h_book
                AND    fadp.fiscal_year = h_current_fiscal_yr
                AND    fadp.period_counter = h_cpd_ctr
                AND    faadj.distribution_id = fadh.distribution_id
                AND    faadj.book_type_code = fadp.book_type_code
                AND    faadj.asset_id = h_asset_id
                AND    faadj.period_counter_created = fadp.period_counter
                AND    faadj.adjustment_type = h_adj_type
        GROUP BY
                    fadh.distribution_id,
                    fadh.code_combination_id,
                    faadj.distribution_id,
                    faadj.source_type_Code,
                    faadj.adjustment_amount,
		    fadp.period_counter;
Line: 2270

        SELECT  fadd.distribution_id,
                fadh.code_combination_id,
                -1 * h_cost_frac *
                    (decode (h_adj_type,
                             'EXPENSE', fadd.deprn_amount,
			     'BONUS EXPENSE', fadd.bonus_deprn_amount,
                             'REVAL EXPENSE', fadd.reval_deprn_expense,
                             'REVAL AMORT', fadd.reval_amortization) -
                     nvl(sum(decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                             faadj.adjustment_amount), 0)),
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.adjustment_amount), 0),
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.annualized_adjustment), 0),
                nvl(-1 * h_cost_frac *
                   (decode (h_adj_type,
                            'EXPENSE',(fadd.deprn_amount -
                                        fadd.deprn_adjustment_amount),
                            'BONUS EXPENSE',(fadd.bonus_deprn_amount -
                                        fadd.bonus_deprn_adjustment_amount),
                            'REVAL EXPENSE', fadd.reval_deprn_expense,
                            'REVAL AMORT', fadd.reval_amortization)),0),
                nvl(-1 * h_cost_frac *
                    (decode (h_adj_type,
                             'EXPENSE', fadd.deprn_amount,
			     'BONUS EXPENSE', fadd.bonus_deprn_amount,
                             'REVAL EXPENSE', fadd.reval_deprn_expense,
                             'REVAL AMORT', fadd.reval_amortization)),0),
                nvl(faadj.source_type_code, 'DEPRECIATION'),
		fadp.period_counter
                FROM
                    fa_distribution_history     fadh,
                    fa_deprn_detail_mrc_v       fadd,
                    fa_deprn_periods            fadp,
                    fa_adjustments_mrc_v        faadj
                WHERE
                       fadd.asset_id = h_asset_id
                AND    fadd.distribution_id = fadh.distribution_id
                AND    fadd.book_type_code = h_book
                AND    fadd.deprn_source_code = 'D'
                AND    fadd.period_counter = fadp.period_counter
                AND    fadp.period_num = h_i
                AND    fadp.book_type_code = h_book
                AND    fadp.fiscal_year = h_current_fiscal_yr
                AND    faadj.distribution_id(+) = fadd.distribution_id
                AND    faadj.book_type_code(+) = fadd.book_type_code
                AND    faadj.asset_id(+) = fadd.asset_id
                AND    faadj.period_counter_created(+) = fadd.period_counter
                AND    faadj.adjustment_type(+) = h_adj_type
        GROUP BY
                    fadd.distribution_id,
                    fadh.code_combination_id,
                    fadd.deprn_amount,
                    fadd.deprn_adjustment_amount,
                    fadd.bonus_deprn_amount,
                    fadd.bonus_deprn_adjustment_amount,
                    fadd.reval_deprn_expense,
                    fadd.reval_amortization,
                    faadj.distribution_id,
                    faadj.source_type_Code,
                    faadj.adjustment_amount,
		    fadp.period_counter
        UNION
        SELECT  fadh.distribution_id,
                fadh.code_combination_id,
                0,
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.adjustment_amount), 0),
                nvl(SUM(-1 * h_cost_frac *
                        decode (faadj.debit_credit_flag, 'DR', 1, -1) *
                        faadj.annualized_adjustment), 0),
                0,
                0,
                nvl(faadj.source_type_code, 'DEPRECIATION'),
		fadp.period_counter
                FROM
                    fa_distribution_history     fadh,
                    fa_deprn_periods            fadp,
                    fa_adjustments_mrc_v        faadj
                WHERE
                       fadp.period_num = h_i
                AND    fadp.book_type_code = h_book
                AND    fadp.fiscal_year = h_current_fiscal_yr
                AND    fadp.period_counter = h_cpd_ctr
                AND    faadj.distribution_id = fadh.distribution_id
                AND    faadj.book_type_code = fadp.book_type_code
                AND    faadj.asset_id = h_asset_id
                AND    faadj.period_counter_created = fadp.period_counter
                AND    faadj.adjustment_type = h_adj_type
        GROUP BY
                    fadh.distribution_id,
                    fadh.code_combination_id,
                    faadj.distribution_id,
                    faadj.source_type_Code,
                    faadj.adjustment_amount,
                    fadp.period_counter;
Line: 2443

		SELECT ytd_deprn, period_num, bonus_ytd_deprn, fiscal_year,
		       deprn_reserve
                INTO   h_ytd_deprn, h_pd_num, h_bonus_ytd_deprn, h_fiscal_year,
		       h_Brow_deprn_reserve /*Bug 7595090 added this variable to get initial depreciation reserve*/
		FROM
                        fa_deprn_summary ds,
			fa_deprn_periods dp
                WHERE
                	ds.asset_id = h_asset_id
                AND     ds.book_type_code = h_book
		AND	ds.deprn_source_code = 'BOOKS'
		AND	dp.book_type_code = h_book
		AND	dp.period_counter = ds.period_counter;
Line: 2459

                SELECT ytd_deprn,period_num, bonus_ytd_deprn, fiscal_year,
		       deprn_reserve
                INTO   h_ytd_deprn, h_pd_num, h_bonus_ytd_deprn, h_fiscal_year,
		       h_Brow_deprn_reserve /*Bug 7595090 added this variable to get initial depreciation reserve*/
                FROM
                        fa_deprn_summary_mrc_v ds,
                        fa_deprn_periods dp
                WHERE
                        ds.asset_id = h_asset_id
                AND     ds.book_type_code = h_book
                AND     ds.deprn_source_code = 'BOOKS'
                AND     dp.book_type_code = h_book
                AND     dp.period_counter = ds.period_counter;
Line: 2517

            SELECT  count(*)
            INTO    h_ret_count
            FROM
                    fa_deprn_periods            fadp,
                    fa_adjustments              faadj
            WHERE
                    fadp.period_num = h_i
            AND     fadp.book_type_code = h_book
            AND     fadp.fiscal_year = h_current_fiscal_yr
            AND     faadj.book_type_code = h_book
            AND     faadj.asset_id = h_asset_id
            AND     faadj.period_counter_created = fadp.period_counter
            AND     faadj.adjustment_type = h_adj_type
            AND     faadj.source_type_code = 'RETIREMENT'
            AND     faadj.adjustment_amount <> 0;
Line: 2533

            SELECT  count(*)
            INTO    h_adj_count
            FROM
                    fa_deprn_periods            fadp,
                    fa_adjustments              faadj
            WHERE
                    fadp.period_num = h_i
            AND     fadp.book_type_code = h_book
            AND     fadp.fiscal_year = h_current_fiscal_yr
            AND     faadj.book_type_code = h_book
            AND     faadj.asset_id = h_asset_id
            AND     faadj.period_counter_created = fadp.period_counter
            AND     faadj.adjustment_type = h_adj_type
            AND     faadj.source_type_code <> 'RETIREMENT'
            AND     faadj.adjustment_amount <> 0;
Line: 2551

            SELECT  count(*)
            INTO    h_ret_count
            FROM
                    fa_deprn_periods            fadp,
                    fa_adjustments_mrc_v        faadj
            WHERE
                    fadp.period_num = h_i
            AND     fadp.book_type_code = h_book
            AND     fadp.fiscal_year = h_current_fiscal_yr
            AND     faadj.book_type_code = h_book
            AND     faadj.asset_id = h_asset_id
            AND     faadj.period_counter_created = fadp.period_counter
            AND     faadj.adjustment_type = h_adj_type
            AND     faadj.source_type_code = 'RETIREMENT'
            AND     faadj.adjustment_amount <> 0;
Line: 2567

            SELECT  count(*)
            INTO    h_adj_count
            FROM
                    fa_deprn_periods            fadp,
                    fa_adjustments_mrc_v        faadj
            WHERE
                    fadp.period_num = h_i
            AND     fadp.book_type_code = h_book
            AND     fadp.fiscal_year = h_current_fiscal_yr
            AND     faadj.book_type_code = h_book
            AND     faadj.asset_id = h_asset_id
            AND     faadj.period_counter_created = fadp.period_counter
            AND     faadj.adjustment_type = h_adj_type
            AND     faadj.source_type_code <> 'RETIREMENT'
            AND     faadj.adjustment_amount <> 0;
Line: 2589

          SELECT  count(*)
          INTO    h_prior_pd_tfr
          FROM    fa_deprn_periods dp1,
                  fa_deprn_periods dp2,
                  fa_transaction_headers th
          WHERE   th.asset_id = h_asset_id
          AND     th.book_type_code = h_book
          AND     th.transaction_type_code = 'TRANSFER'
          AND     th.date_effective between dp1.period_open_date
                          and nvl(dp1.period_close_date, sysdate)
          AND     dp1.book_type_code = th.book_type_code
          AND     dp1.period_num = h_i
          AND     dp1.fiscal_year = h_current_fiscal_yr
          AND     th.transaction_date_entered between
                  dp2.calendar_period_open_date and
                  dp2.calendar_period_close_date
          AND     dp2.book_type_code = th.book_type_code
          AND     dp2.period_num < h_i;
Line: 2795

                SELECT  count(*)
                INTO    h_curr_pd_add
                FROM
                        fa_deprn_periods dp,
                        fa_transaction_headers th
                WHERE   th.asset_id = h_asset_id
                AND     th.book_type_code = h_book
                AND     th.transaction_type_code || '' = 'ADDITION'
                AND     th.date_effective between dp.period_open_date
                                and nvl(dp.period_close_date, sysdate)
                AND     dp.book_type_code = th.book_type_code
                AND     dp.period_num = h_i
                AND     dp.fiscal_year = h_current_fiscal_yr;
Line: 2814

			SELECT  sum(adjustment_amount)--bug fix 3905436
	                INTO    h_adj_exp_row
        	        FROM
        	                fa_adjustments adj,
        	                fa_deprn_periods dp,
        	                fa_transaction_headers th
        	        WHERE
        	                th.asset_id = h_asset_id
        	        AND     th.book_type_code = h_book
        	        AND     th.transaction_type_code || '' = 'ADDITION'
			AND     adj.asset_id = h_asset_id
        	        AND     adj.book_type_code = h_book
        	        AND     adj.source_type_code || '' = 'DEPRECIATION'
        	        AND     adj.ADJUSTMENT_type || '' = 'EXPENSE'
                        AND     adj.distribution_id = h_dist_id --bug fix 3905436
        	        AND     adj.period_counter_created = dp.period_counter
        	        AND     th.date_effective between dp.period_open_date
        	                        and nvl(dp.period_close_date, sysdate)
        	        AND     dp.book_type_code = th.book_type_code
        	        AND     dp.period_num = h_i
        	        AND     dp.fiscal_year = h_current_fiscal_yr;
Line: 2843

                SELECT  PRIOR_FY_EXPENSE
                INTO    h_prior_fy_exp
                FROM
                        fa_deprn_summary ds,
                        fa_deprn_periods dp,
                        fa_transaction_headers th
                WHERE
                        th.asset_id = h_asset_id
                AND     th.book_type_code = h_book
                AND     th.transaction_type_code || '' = 'ADDITION'
                AND     th.date_effective between dp.period_open_date
                                and nvl(dp.period_close_date, sysdate)
		    AND     ds.asset_id = h_asset_id
                AND     ds.book_type_code = h_book
                AND     ds.period_counter = dp.period_counter
                AND     dp.book_type_code = th.book_type_code
                AND     dp.period_num = h_i
                AND     dp.fiscal_year = h_current_fiscal_yr;
Line: 2896

                        SELECT  sum(adjustment_amount), max(th.transaction_header_id)
                        INTO    h_adj_exp_row, h_old_reinst_trx_id
                        FROM
                                fa_adjustments adj,
                                fa_deprn_periods dp,
                                fa_transaction_headers th
                        WHERE
                                th.asset_id = h_asset_id
                        AND     th.book_type_code = h_book
                        AND     th.transaction_type_code || '' = 'REINSTATEMENT'
                        AND     adj.source_type_code || '' = 'RETIREMENT'
                        AND     adj.ADJUSTMENT_type || '' = 'EXPENSE'
                        AND     adj.asset_id = h_asset_id
                        AND     adj.book_type_code = h_book
                        AND     adj.distribution_id = h_dist_id --bug fix 3905436
                        AND     adj.period_counter_created = dp.period_counter
                        AND     th.date_effective between dp.period_open_date
                                        and nvl(dp.period_close_date, sysdate)
                        AND     dp.book_type_code = th.book_type_code
                        AND     dp.period_num = h_i
                        AND     dp.fiscal_year = h_current_fiscal_yr;
Line: 2925

                  select dp1.period_counter
                        ,dp2.period_counter
                  into   h_old_reinst_pc
                        ,h_old_ret_pc
                  from   fa_transaction_headers trx,
                         fa_deprn_periods dp1,
                         fa_retirements old_ret,
                         fa_deprn_periods dp2
                  where  trx.transaction_header_id = h_old_reinst_trx_id
                    and  dp1.book_type_code = trx.book_type_code
                    and  trx.transaction_date_entered between dp1.CALENDAR_PERIOD_OPEN_DATE
                                                          and dp1.CALENDAR_PERIOD_CLOSE_DATE
                    and  old_ret.transaction_header_id_out = trx.transaction_header_id
                    and  dp2.book_type_code = trx.book_type_code
                    and  old_ret.date_retired between dp2.CALENDAR_PERIOD_OPEN_DATE
                                                  and dp2.CALENDAR_PERIOD_CLOSE_DATE
                   ;
Line: 2943

                  select dp.period_counter
                  into h_ret_prorate_pc
                  from fa_retirements new_ret
                      ,fa_conventions conv
                      ,fa_deprn_periods dp
                  where new_ret.transaction_header_id_in=ret.th_id_in
                    and conv.prorate_convention_code=new_ret.retirement_prorate_convention
                    and new_ret.date_retired between conv.start_date and conv.end_date
                    and dp.book_type_code = new_ret.book_type_code
                    and conv.prorate_date between dp.CALENDAR_PERIOD_OPEN_DATE
                                              and dp.CALENDAR_PERIOD_CLOSE_DATE
                  ;
Line: 3230

          select nvl(cb.bonus_deprn_expense_acct,'0')
          into h_bonus_deprn_exp_acct
          from fa_additions_b ad,
               fa_category_books cb
          where ad.asset_id = h_asset_id
          and   cb.category_id = ad.asset_category_id
          and   cb.book_type_code = h_book;
Line: 3264

       select  facb.deprn_expense_acct
        into   h_deprn_exp_acct
        from   fa_additions_b    faadd,
               fa_category_books facb,
               fa_book_controls bc
       where   faadd.asset_id = h_asset_id
         and   facb.category_id = faadd.asset_category_id
         and   facb.book_type_code = h_book
         and   bc.book_type_code = facb.book_type_code;
Line: 3282

       adj_row.last_update_date := today;
Line: 3292

       adj_row.selection_thid := 0;
Line: 3326

       SELECT  pcal.period_num
       INTO    h_start_pd_endpp
       FROM    fa_calendar_periods pcal,
               fa_deprn_periods dp
       WHERE   calendar_type = p_cal
       AND     dp.book_type_code = h_book
       AND     dp.fiscal_year = h_current_fiscal_yr
       AND     dp.period_num = h_start_pdnum
       AND     dp.calendar_period_close_date
                        between start_date and end_date;
Line: 3349

       select decode(fy1.fiscal_year, fy2.fiscal_year,1,0),
                    decode(BC.DEPR_FIRST_YEAR_RET_FLAG, 'YES', 1, 0),
                    decode(ctype.depr_when_acquired_flag,'YES',1,0),
                    decode(mt.rate_source_rule,
                                'CALCULATED', 1,
                                'TABLE', 2,
                                'FLAT', 3)
      INTO h_same_fy, h_depr_first_year_ret,
           h_dwacq, h_rate_source_rule
      FROM FA_FISCAL_YEAR fy1,
           FA_FISCAL_YEAR fy2,
           FA_BOOKS bk,
           FA_RETIREMENTS rt,
           FA_CONVENTION_TYPES ctype,
           FA_METHODS mt,
           FA_BOOK_CONTROLS bc
      WHERE   rt.date_retired between
                  fy1.start_date and fy1.end_date
        AND   bk.deprn_start_date between
                     fy2.start_date and fy2.end_date
        AND   rt.asset_id = h_asset_id
        AND   bk.asset_id = h_asset_id
        AND   bk.book_type_code = bc.book_type_code
        AND   bc.book_type_code = h_book
        AND   rt.retirement_id = h_retirement_id
        AND   bk.retirement_id = rt.retirement_id
        AND   bk.transaction_header_id_out is not null
        AND   bk.deprn_method_code = mt.method_code
        AND   nvl(bk.life_in_months,1) = nvl(mt.life_in_months,1)
        AND   bk.prorate_convention_code = ctype.prorate_convention_code
        AND   fy1.fiscal_year_name = bc.fiscal_year_name
        AND   fy2.fiscal_year_name = bc.fiscal_year_name;
Line: 3804

          adj_row.selection_retid := 0;
Line: 3806

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 3830

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
             fa_srvr_msg.add_message(calling_fn => l_calling_fn
                          ,p_log_level_rec => p_log_level_rec);
Line: 3842

          adj_row.selection_retid := retirement_id;
Line: 3844

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_RETIRE;
Line: 3857

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
             fa_srvr_msg.add_message(calling_fn => l_calling_fn
                          ,p_log_level_rec => p_log_level_rec);
Line: 3887

| allocated to each cost center (distribution). It inserts the amount into  |
| the FA_ADJUSTMENTS table.                                                 |
|       If the number of periods to be catchup is negative or the           |
| DEPRECIATE_LAST_YEAR_FLAG is set to 'NO', we need to back out depreciation|
| When the flag is set to NO, we need to back out the whole depreciation    |
| taken so far this year.                                                   |
|                                                                           |
|                                                                           |
| HISTORY       1/12/89         R Rumanang      Created                     |
|               6/23/89         R Rumanang      Standarized                 |
|               8/24/89         R Rumanang      Insert to FA_ADJUSTMENTS    |
|               04/15/91        M Chan          Rewritten for MPL 9         |
|               01/02/96        S Behura        Rewritten into PL/SQL       |
*===========================================================================*/

FUNCTION fagpdp(ret in out nocopy fa_ret_types.ret_struct,
                bk in out nocopy fa_ret_types.book_struct,
                dpr in out nocopy FA_STD_TYPES.dpr_struct,
                today in date, pds_catchup number,
                cpd_ctr number, cpdnum number,
                cost_frac in number, deprn_amt in out nocopy number,
		bonus_deprn_amt in out nocopy number,
                reval_deprn_amt in out nocopy number, reval_amort in out number,
                reval_reserve in out nocopy number, user_id number,
		p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) Return BOOLEAN IS

    fagpdp_err          exception;
Line: 3956

    X_LAST_UPDATE_DATE date := sysdate;
Line: 3957

    X_last_updated_by number := -1;
Line: 3958

    X_last_update_login number := -1;
Line: 4040

                SELECT   cp.period_num
                  INTO   h_work_pdnum
                  FROM   fa_calendar_periods cp
                 WHERE   h_ret_p_date
                         between cp.start_date and cp.end_date
                   AND   cp.calendar_type = h_d_cal;
Line: 4049

             end; -- end of - select
Line: 4079

                SELECT  to_number (to_char (dp.calendar_period_open_date, 'J'))
                INTO    :h_cpp_jstartdate
                FROM    fa_deprn_periods dp
                WHERE   dp.book_type_code = :h_book
                AND     dp.fiscal_year = :h_current_fiscal_yr
                AND     dp.period_num = :h_work_pdnum;
Line: 4087

                SELECT  to_number (to_char (dcp.start_date, 'J'))
                INTO    h_cpp_jstartdate
                FROM    fa_calendar_periods dcp,
                        fa_fiscal_year fy,
                        fa_book_controls bc
                WHERE   bc.book_type_code = h_book
                AND     bc.fiscal_year_name = fy.fiscal_year_name
                AND     dcp.calendar_type   = h_d_cal
                AND     fy.fiscal_year      = h_current_fiscal_yr
                AND     dcp.period_num      = h_work_pdnum
                AND     dcp.start_date
                             between fy.start_date and fy.end_date;
Line: 4109

                    SELECT to_number (to_char (bk.prorate_date, 'J'))
                    INTO   h_dpis_pr_jdt
                    FROM   fa_books bk,
                           fa_calendar_periods dcp
                    WHERE  bk.book_type_code = ret.book
                    AND    transaction_header_id_out is null
                    AND    asset_id = ret.asset_id
                    AND    dcp.calendar_type   = h_d_cal
                    AND    bk.prorate_date
		           BETWEEN dcp.start_date AND dcp.end_date
                    AND   h_ret_p_date
                           BETWEEN dcp.start_date AND dcp.end_date;
Line: 4130

                SELECT  period_num
                INTO    h_startpp
                FROM    fa_calendar_periods
                WHERE   calendar_type = h_p_cal
                AND     to_date (h_cpp_jstartdate,'J')
                        between start_date and end_date;
Line: 4137

                SELECT  to_number (to_char (dp.calendar_period_open_date, 'J'))
                INTO    h_cpp_jenddate
                FROM    fa_deprn_periods dp
                WHERE   dp.book_type_code = h_book
                AND     dp.fiscal_year = h_current_fiscal_yr
                AND     dp.period_num = h_stop_pdnum;
Line: 4144

                SELECT  period_num
                INTO    h_endpp
                FROM    fa_calendar_periods
                WHERE   calendar_type = h_p_cal
                AND     to_date (h_cpp_jenddate,'J')
                        between start_date and end_date;
Line: 4268

               select  facb.deprn_expense_acct
               into    h_deprn_exp_acct
               from    fa_additions_b    faadd,
                       fa_category_books facb,
                       fa_book_controls bc
               where   faadd.asset_id = h_asset_id
               and     facb.category_id = faadd.asset_category_id
               and     facb.book_type_code = h_book
               and     bc.book_type_code = facb.book_type_code;
Line: 4289

             adj_row.last_update_date := today;
Line: 4292

             adj_row.selection_thid := 0;
Line: 4317

                         element => 'Insert cost into fa_adj',
                         value   => ''
                         ,p_log_level_rec => p_log_level_rec);
Line: 4325

                adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 4326

                adj_row.selection_retid := 0;
Line: 4352

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then
                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 4363

                   select nvl(cb.bonus_deprn_expense_acct,'0')
                   into h_bonus_deprn_exp_acct
                   from fa_additions_b ad,
                        fa_category_books cb
                   where ad.asset_id = h_asset_id
                   and   cb.category_id = ad.asset_category_id
                   and   cb.book_type_code = h_book;
Line: 4376

                   adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 4377

                   adj_row.selection_retid := 0;
Line: 4382

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                      fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                            ,p_log_level_rec => p_log_level_rec);
Line: 4412

    		-- in case of future use, but we should not insert the
     		-- adjustment rows.

                end if;
Line: 4425

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                      fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                            ,p_log_level_rec => p_log_level_rec);
Line: 4443

                adj_row.selection_mode := FA_STD_TYPES.FA_AJ_RETIRE;
Line: 4444

                adj_row.selection_retid := ret.retirement_id;
Line: 4449

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                      fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                            ,p_log_level_rec => p_log_level_rec);
Line: 4463

                   select nvl(cb.bonus_deprn_expense_acct,'0')
                   into h_bonus_deprn_exp_acct
                   from fa_additions_b ad,
                        fa_category_books cb
                   where ad.asset_id = h_asset_id
                   and   cb.category_id = ad.asset_category_id
                   and   cb.book_type_code = h_book;
Line: 4476

                   adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 4477

                   adj_row.selection_retid := 0;
Line: 4482

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                      fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                            ,p_log_level_rec => p_log_level_rec);
Line: 4511

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                      fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                            ,p_log_level_rec => p_log_level_rec);
Line: 4532

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                      fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                            ,p_log_level_rec => p_log_level_rec);
Line: 4567

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_deprn_amt
            FROM   FA_ADJUSTMENTS faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'EXPENSE'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4591

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_deprn_amt
            FROM   FA_ADJUSTMENTS_MRC_V faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'EXPENSE'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4618

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_bonus_deprn_amt
            FROM   FA_ADJUSTMENTS faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'BONUS EXPENSE'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4640

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_bonus_deprn_amt
            FROM   FA_ADJUSTMENTS_MRC_V faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'BONUS EXPENSE'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4673

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_reval_deprn_amt
            FROM   FA_ADJUSTMENTS faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'REVAL EXPENSE'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4691

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_reval_deprn_amt
            FROM   FA_ADJUSTMENTS_MRC_V faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'REVAL EXPENSE'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4721

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_reval_amort
            FROM   FA_ADJUSTMENTS faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'REVAL AMORT'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4739

            SELECT SUM(faadj.adjustment_amount)
            INTO   h_reval_amort
            FROM   FA_ADJUSTMENTS_MRC_V faadj
            WHERE
                   faadj.transaction_header_id = h_th_id_in
            AND    faadj.source_type_code = 'RETIREMENT'
            AND    faadj.adjustment_type = 'REVAL AMORT'
            AND    faadj.book_type_Code = h_book
            AND    faadj.asset_id = h_asset_id
            AND    faadj.period_counter_created = h_cpd_ctr
            GROUP BY faadj.transaction_header_id;
Line: 4777

| FUNCTION    Calculate reserve retired and insert it into FA_ADJUSTMENTS.   |
|             It returns the  current depreciation reserve before adjusted.  |
|                                                                            |
| HISTORY     08/30/89    R Rumanang      Created                            |
|             11/21/89    R Rumanang      Put distribution_id in adjustments |
|             05/03/91    M Chan          Rewrote for MPL 9                  |
|             01/03/96    S Behura        Rewrote using PL/SQL               |
|                                                                            |
*============================================================================*/

FUNCTION fagprv(ret in out nocopy fa_ret_types.ret_struct,
                bk in out nocopy fa_ret_types.book_struct,
                cpd_ctr number, cost_frac in number,
                today in date, user_id number,
                deprn_amt in out nocopy number, reval_deprn_amt in out number,
                reval_amort in out nocopy number, deprn_reserve in out number,
                reval_reserve in out nocopy number,
		bonus_deprn_amt in out nocopy number,
		bonus_deprn_reserve in out nocopy number,
		p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) Return BOOLEAN IS

    CURSOR c_get_unit is
      select units
      from   fa_asset_history
      where  asset_id = bk.group_asset_id
      and    transaction_header_id_out is null;
Line: 4805

      select cost
      from   fa_books
      where  asset_id = bk.group_asset_id
      and    book_type_code = ret.book
      and    date_ineffective is null;
Line: 4840

    X_LAST_UPDATE_DATE date := sysdate;
Line: 4841

    X_last_updated_by number := -1;
Line: 4842

    X_last_update_login number := -1;
Line: 4887

       select adjusted_recoverable_cost
       into l_prev_adj_rec_cost
       from fa_books
       where transaction_header_id_out = ret.th_id_in;
Line: 4894

          select adjusted_recoverable_cost
          into l_new_adj_rec_cost
          from fa_books
          where transaction_header_id_in = ret.th_id_in;
Line: 4987

          select  facb.deprn_reserve_acct,
                  facb.reval_reserve_acct,
		  facb.bonus_deprn_reserve_acct,
                  decode(bc.retire_reval_reserve_flag,'NO',0,
                         decode(facb.reval_reserve_acct,null,0,1))
          into    h_deprn_rsv_acct,
                  h_reval_rsv_acct,
		  h_bonus_deprn_rsv_acct,
                  h_retire_reval_flag
          from    fa_additions_b    faadd,
                  fa_category_books facb,
                  fa_book_controls bc
          where   faadd.asset_id = h_asset_id
          and     facb.category_id = faadd.asset_category_id
          and     facb.book_type_code = h_book
          and     bc.book_type_code = facb.book_type_code;
Line: 5017

       adj_row.last_update_date := today;
Line: 5024

       adj_row.selection_retid := 0;
Line: 5038

          select   decode(RETIRE_REVAL_RESERVE_FLAG,'NO',0,1)
          into     h_retire_reval_flag
          from     fa_book_controls bc
          where    bc.book_type_code = h_book;
Line: 5056

          adj_row.selection_thid := 0;
Line: 5060

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_CLEAR;
Line: 5062

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 5086

             fa_debug_pkg.add(l_calling_fn, '++ adj_row.selection_thid', adj_row.selection_thid, p_log_level_rec);
Line: 5114

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

             fa_srvr_msg.add_message(calling_fn => l_calling_fn
                          ,p_log_level_rec => p_log_level_rec);
Line: 5151

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5178

	     adj_row.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_REVAL;
Line: 5179

	     -- adj_row.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE;
Line: 5195

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5223

             select   distinct nvl(transaction_header_id_out,0)
             into     h_id_out
             from     fa_distribution_history
             where    asset_id = h_asset_id
             and      book_type_code = h_book
             and      retirement_id = h_ret_id;
Line: 5240

            select sum(nvl(units_assigned,0))
            into h_sum_of_part_active_units
            from fa_distribution_history
            where asset_id = h_asset_id
              and transaction_header_id_in = h_id_out
              and date_ineffective is null;
Line: 5256

          adj_row.selection_thid := h_id_out;
Line: 5262

          adj_row.selection_mode := FA_STD_TYPES.FA_AJ_CLEAR_PARTIAL;
Line: 5273

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5284

          adj_row.adjustment_amount := adj_row.amount_inserted -
                                       tot_deprn_reserve;
Line: 5291

               value   => adj_row.amount_inserted);
Line: 5303

             select     nvl(units,0)
             into       h_cur_units
             from       fa_asset_history
             where      asset_id = h_asset_id
             and        date_ineffective is null;
Line: 5314

            select count(*)
              into l_dummy
            from fa_distribution_history
            where asset_id = h_asset_id
              and date_ineffective is null
              and transaction_header_id_in = h_id_out;
Line: 5322

            select sum(nvl(units_assigned,0))
              into h_cur_units
              from fa_distribution_history
            where asset_id = h_asset_id
              and date_ineffective is null
              and transaction_header_id_in = h_id_out;
Line: 5346

            adj_row.selection_thid := h_id_out;
Line: 5350

              adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE_PARTIAL;
Line: 5352

              adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 5359

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5378

	     adj_row.amount_inserted := 0;
Line: 5379

             adj_row.selection_thid := h_id_out;
Line: 5381

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_CLEAR;
Line: 5387

                   element => 'Insert fa_adjustments in fagprv2,accnt_type',
                   value   => adj_row.account_type
                   ,p_log_level_rec => p_log_level_rec);
Line: 5393

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5404

             adj_row.adjustment_amount := adj_row.amount_inserted -
                                       tot_bonus_deprn_reserve;
Line: 5408

             adj_row.selection_thid := 0;
Line: 5410

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 5414

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5448

             adj_row.selection_thid := h_id_out;
Line: 5450

             adj_row.selection_mode := FA_STD_TYPES.FA_AJ_CLEAR;
Line: 5454

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5464

             adj_row.adjustment_amount := adj_row.amount_inserted -
                                          tot_reval_reserve;
Line: 5470

               adj_row.selection_thid := 0;
Line: 5474

               adj_row.selection_mode := FA_ADJUST_TYPE_PKG.FA_AJ_ACTIVE_REVAL;
Line: 5479

                                       X_last_update_date,
                                       X_last_updated_by,
                                       X_last_update_login
                                       ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5617

                adj_row.selection_thid := 0;
Line: 5619

                adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 5631

                                             X_last_update_date,
                                             X_last_updated_by,
                                             X_last_update_login
                                             ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);
Line: 5671

                adj_row.selection_thid := 0;
Line: 5673

                adj_row.selection_mode := FA_STD_TYPES.FA_AJ_ACTIVE;
Line: 5685

                                             X_last_update_date,
                                             X_last_updated_by,
                                             X_last_update_login
                                             ,p_log_level_rec => p_log_level_rec)) then

                   fa_srvr_msg.add_message(calling_fn => l_calling_fn
                                      ,p_log_level_rec => p_log_level_rec);