DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_CUA_GAIN_LOSS_EXT_PKG

Source


1 PACKAGE BODY fa_cua_gain_loss_ext_pkg AS
2 /* $Header: FACPX11MB.pls 120.1 2002/12/20 02:29:43 glchen ship $ */
3 
4 -- ------------------------------------------------------------
5 -- facuas1: needs to be called from calculate_gain_loss process
6 --          after updating the status of fa_retirements to DELETED
7 --
8 --          This procedure re-derives the hierarchy attributes of
9 --          the reinstated assets
10 -- -----------------------------------------------------------
11 
12    PROCEDURE facuas1( x_book_type_code in varchar2
13                     , x_asset_id       in number
14                     , x_retire_status  in varchar2 ) IS
15 
16     v_err_code            varchar2(640) := '0';
17     v_err_stage           varchar2(640);
18     v_err_stack           varchar2(640);
19     v_dummy_varchar       varchar2(30);
20     v_batch_id            number;
21     v_batch_number        varchar2(30);
22     v_dummy_number        number;
23     v_amortize_flag       VARCHAR2(3);
24     v_amortization_date   date;
25     v_old_life_in_months  number;
26 
27     l_app varchar2(50);
28     l_name varchar2(30);
29     l_trans_rec   FA_API_TYPES.trans_rec_type;
30 
31     Cursor C_amort_date is
32       select greatest(calendar_period_open_date,least(sysdate, calendar_period_close_date))
33       from     fa_deprn_periods
34       where    book_type_code = x_book_type_code
35       and      period_close_date is null;
36 
37     Cursor check_hr_asset is
38      select 'Y'
39      from ( select a.transaction_header_id_in
40             from fa_books a
41                , fa_asset_hierarchy b
42             where a.book_type_code = x_book_type_code
43               and a.asset_id = x_asset_id
44               and a.asset_id = b.asset_id
45               and a.date_ineffective IS NULL ) a1,
46      fa_books c
47     where c.transaction_header_id_out = a1.transaction_header_id_in
48     and nvl(c.period_counter_fully_retired, 0) <> 0;
49 
50    CURSOR check_status is
51      select 1 from dual
52      where exists ( select 'X'
53                     from fa_mass_update_batch_details
54                     where batch_id = v_batch_id
55                     and status_code IN ('P', 'R' ) );
56   BEGIN
57     if(x_retire_status = 'DELETED') then
58        -- check if fully retired
59        open check_hr_asset;
60        fetch check_hr_asset into v_dummy_varchar;
61        close check_hr_asset;
62 
63       if(v_dummy_varchar = 'Y') then
64          -- get batch_id
65          v_dummy_varchar:= NULL;
66          select fa_mass_update_batch_hdrs_s.nextval
67          into v_batch_id
68          from dual;
69 
70          open  C_amort_date;
71          fetch C_amort_date into v_amortization_date;
72          close C_amort_date;
73 
74 
75          v_amortize_flag:= 'YES';
76 
77          fa_cua_mass_update2_pkg.g_override_book_check:= 'YES';
78 
79          -- Fix for Bug #2709865.  Use different variable names.
80          v_batch_number := to_char (v_batch_id);
81 
82          -- generate_batch_transactions
83          fa_cua_asset_apis.generate_batch_transactions(
84                              x_event_code           => 'HR_REINSTATEMENT'
85                            , x_book_type_code       => x_book_type_code
86                            , x_src_entity_name      => 'REINSTATED_ASSET'
87                            , x_src_entity_value     => x_asset_id
88                            , x_src_attribute_name   => v_dummy_varchar
89                            , x_src_attr_value_from  => v_dummy_varchar
90                            , x_src_attr_value_to    => v_dummy_varchar
91                            , x_amortize_expense_flg => v_amortize_flag
92                            , x_amortization_date    => v_amortization_date
93                            , x_batch_num            => v_batch_number
94                            , x_batch_id             => v_batch_id
95                            , x_err_code             => v_err_code
96                            , x_err_stage            => v_err_stage
97                            , x_err_stack            => v_err_stack );
98 
99          if  v_err_code <> '0' then
100            raise_application_error(-20000,v_err_code);
101          end if;
102 
103          l_trans_rec.mass_reference_id          := fnd_global.conc_request_id;
104          l_trans_rec.who_info.last_update_date  := sysdate;
105          l_trans_rec.who_info.last_updated_by   := fnd_global.user_id;
106          l_trans_rec.who_info.created_by        := l_trans_rec.who_info.last_updated_by;
107          l_trans_rec.who_info.creation_date     := sysdate;
108          l_trans_rec.who_info.last_update_login := fnd_global.login_id;
109          l_trans_rec.amortization_start_date    := v_amortization_date;
110          l_trans_rec.transaction_date_entered   := v_amortization_date;
111 
112          fa_cua_mass_update1_pkg.process_asset(
113                                  px_trans_rec    => l_trans_rec,
114                                  p_batch_id      => v_batch_id,
115                                  p_asset_id      => x_asset_id,
116                                  p_book          => x_book_type_code,
117                                  p_amortize_flag => v_amortize_flag,
118                                  x_err_code      => v_err_code,
119                                  x_err_attr_name => v_dummy_varchar );
120 
121         if v_err_code <> '0' then
122                delete from fa_mass_update_batch_headers
123                where batch_id = v_batch_id;
124 
125                delete from fa_mass_update_batch_details
126                where batch_id = v_batch_id;
127 
128                raise_application_error(-20000, v_err_code);
129          else
130               -- success
131              delete from fa_mass_update_batch_headers
132              where batch_id = v_batch_id;
133 
134              delete from fa_mass_update_batch_details
135              where batch_id = v_batch_id;
136          end if;
137 
138         end if;  -- v_dummy
139       end if;  --status
140 
141 EXCEPTION
142   when others then
143     raise;
144 END facuas1;
145 
146 END fa_cua_gain_loss_ext_pkg;