DBA Data[Home] [Help]

PACKAGE BODY: APPS.FA_XLA_EVENTS_PVT

Source


1 package body FA_XLA_EVENTS_PVT as
2 /* $Header: faeventb.pls 120.30.12020000.4 2012/12/04 18:35:05 spooyath ship $   */
3 
4 FUNCTION create_transaction_event
5            (p_asset_hdr_rec          IN FA_API_TYPES.asset_hdr_rec_type,
6             p_asset_type_rec         IN FA_API_TYPES.asset_type_rec_type,
7             px_trans_rec             IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
8             p_event_status           IN VARCHAR2 DEFAULT NULL,
9             p_calling_fn             IN VARCHAR2,
10             p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) return boolean IS
11 
12    l_trx_source_info  XLA_EVENTS_PUB_PKG.t_event_source_info;
13    l_security_context XLA_EVENTS_PUB_PKG.t_security;
14 
15    l_event_type_code  varchar2(30) ;
16    l_event_date       date         := px_trans_rec.transaction_date_entered;
17    l_event_status     varchar2(30) ;
18    l_valuation_method varchar2(30) := p_asset_hdr_rec.book_type_code;
19 
20    l_calling_fn       varchar2(80) := 'fa_xla_events_pvt.create_trx_event';
21 
22    invalid_calling_fn      exception;
23    invalid_event_status    exception;
24 
25 BEGIN
26 
27    if (p_asset_type_rec.asset_type = 'EXPENSED') then
28       return true;
29    end if;
30 
31    l_trx_source_info.application_id        := 140;
32    l_trx_source_info.legal_entity_id       := NULL;
33    l_trx_source_info.ledger_id             := p_asset_hdr_rec.set_of_books_id;
34    l_trx_source_info.transaction_number    := to_char(px_trans_rec.transaction_header_id);
35    l_trx_source_info.source_id_int_1       := px_trans_rec.transaction_header_id;
36    l_trx_source_info.source_id_char_1      := p_asset_hdr_rec.book_type_code;
37 
38    -- conditionally set the entity and type codes
39    -- based on calling interface and other factors
40 
41    l_trx_source_info.entity_type_code      := 'TRANSACTIONS';
42 
43    if (p_calling_fn = 'fa_addition_pvt.insert_asset') then
44       l_event_type_code                       := 'ADDITIONS';
45    elsif (p_calling_fn = 'fa_cip_pvt.do_cap_rev') then
46        if (p_asset_type_rec.asset_type = 'CIP') then
47           l_event_type_code                       := 'REVERSE_CAPITALIZATION';
48        else
49           l_event_type_code                       := 'CAPITALIZATION';
50        end if;
51    elsif (p_calling_fn = 'fa_adjustment_pvt.do_adjustment') then
52       l_event_type_code                       := 'ADJUSTMENTS';
53    elsif (p_calling_fn = 'fa_unplanned_pvt.do_unplanned') then
54       l_event_type_code                       := 'UNPLANNED_DEPRECIATION';
55    elsif (p_calling_fn = 'FA_RETIREMENT_PUB.do_all_books_retirement') then
56       l_event_type_code                       := 'RETIREMENTS';
57    elsif (p_calling_fn = 'FA_RETIREMENT_PUB.do_sub_regular_reinstatement') then
58       l_event_type_code                       := 'REINSTATEMENTS';
59    elsif (p_calling_fn = 'FA_DISTRIBUTION_PVT.do_distribution') then
60       if (px_trans_rec.transaction_type_code = 'RECLASS') then
61          l_event_type_code                       := 'CATEGORY_RECLASS';
62       elsif (px_trans_rec.transaction_type_code = 'UNIT ADJUSTMENT') then
63          l_event_type_code                       := 'UNIT_ADJUSTMENTS';
64       else -- all tax book transactions and TRANSFER and TRANSFER OUT
65          l_event_type_code                       := 'TRANSFERS';
66       end if;
67    elsif (p_calling_fn = 'fa_reval_pvt.do_reval') then
68       l_event_type_code                       := 'REVALUATION';
69    elsif (p_calling_fn = 'FA_REVALUATION_PVT.rollback_reval') then
70       l_event_type_code                       := 'ROLLBACK_REVALUATION';
71    elsif (p_calling_fn = 'FA_TAX_RSV_ADJ_PVT.do_tax_rsv_adj') then
72       l_event_type_code                       := 'DEPRECIATION_ADJUSTMENTS';
73    elsif (p_calling_fn = 'fa_ret_adj_pub.do_all_books') then
74       l_event_type_code                       := 'RETIREMENT_ADJUSTMENTS';
75    elsif (p_calling_fn = 'FA_GAINLOSS_UND_PKG.fagtax') then
76       l_event_type_code                       := 'TRANSFERS';
77    elsif (p_calling_fn = 'FA_TERMINAL_GAIN_LOSS_PVT.fadtgl') then
78       l_event_type_code                       := 'TERMINAL_GAIN_LOSS';
79    elsif (p_calling_fn = 'fa_deprn_rollback_pvt.do_rollback') then
80       l_event_type_code                       := 'ROLLBACK_TERMINAL_GAIN_LOSS';
81    else
82       raise invalid_calling_fn;
83    end if;
84 
85 
86    -- we are breaking by asset type so append CIP if needed
87    if (p_asset_type_rec.asset_type = 'CIP' and
88        p_calling_fn <> 'fa_cip_pvt.do_cap_rev') then
89        l_event_type_code                  := 'CIP_' || l_event_type_code;
90    end if;
91 
92    -- set the status correctly
93    -- only retirements / reinstatements should use incomplete
94    if (p_event_status is null or
95        p_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED) then
96       l_event_status := XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED;
97    elsif (p_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_INCOMPLETE) then
98       l_event_status := XLA_EVENTS_PUB_PKG.C_EVENT_INCOMPLETE;
99    elsif (p_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_NOACTION) then
100       l_event_status := XLA_EVENTS_PUB_PKG.C_EVENT_NOACTION;
101    else
102       -- invalid type
103       raise invalid_event_status;
104    end if;
105 
106    l_event_date := greatest(l_event_date,
107                             fa_cache_pkg.fazcdp_record.calendar_period_open_date);
108 
109    if (p_log_level_rec.statement_level) then
110         fa_debug_pkg.add(l_calling_fn, 'l_trx_source_info.application_id ',    l_trx_source_info.application_id
111                 ,p_log_level_rec => p_log_level_rec);
112         fa_debug_pkg.add(l_calling_fn, 'l_trx_source_info.legal_entity_id ',   l_trx_source_info.legal_entity_id
113                 ,p_log_level_rec => p_log_level_rec);
114         fa_debug_pkg.add(l_calling_fn, 'l_trx_source_info.ledger_id ',         l_trx_source_info.ledger_id
115                 ,p_log_level_rec => p_log_level_rec);
116         fa_debug_pkg.add(l_calling_fn, 'l_trx_source_info.transaction_number', l_trx_source_info.transaction_number
117                 ,p_log_level_rec => p_log_level_rec);
118         fa_debug_pkg.add(l_calling_fn, 'l_trx_source_info.source_id_int_1',    l_trx_source_info.source_id_int_1
119                 ,p_log_level_rec => p_log_level_rec);
120         fa_debug_pkg.add(l_calling_fn, 'l_trx_source_info.entity_type_code',   l_trx_source_info.entity_type_code
121                 ,p_log_level_rec => p_log_level_rec);
122         fa_debug_pkg.add(l_calling_fn, 'l_event_type_code',                    l_event_type_code
123                 ,p_log_level_rec => p_log_level_rec);
124         fa_debug_pkg.add(l_calling_fn, 'l_event_date',                         l_event_date
125                 ,p_log_level_rec => p_log_level_rec);
126         fa_debug_pkg.add(l_calling_fn, 'l_valuation_method',                   l_valuation_method
127                 ,p_log_level_rec => p_log_level_rec);
128 
129    end if;
130 
131    -- Call XLA API
132    px_trans_rec.event_id :=
133      XLA_EVENTS_PUB_PKG.create_event
134           (p_event_source_info   => l_trx_source_info,
135            p_event_type_code     => l_event_type_code,
136            p_event_date          => l_event_date,
137            p_event_status_code   => l_event_status,
138            p_event_number        => NULL,
139            p_reference_info      => NULL,
140            p_valuation_method    => l_valuation_method,
141            p_security_context    => l_security_context);
142 
143    return true;
144 
145 EXCEPTION
146   WHEN INVALID_CALLING_FN THEN
147        fa_srvr_msg.add_message
148           (name       => 'FA_INVALID_CALLING_FN',
149            calling_fn => l_calling_fn
150            ,p_log_level_rec => p_log_level_rec);
151        return FALSE;
152 
153   WHEN INVALID_EVENT_STATUS THEN
154        fa_srvr_msg.add_message
155           (name       => 'FA_EVENT_STATUS',
156            calling_fn => l_calling_fn
157            ,p_log_level_rec => p_log_level_rec);
158        return FALSE;
159 
160   WHEN OTHERS THEN
161        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
162               ,p_log_level_rec => p_log_level_rec);
163        return FALSE;
164 
165 END create_transaction_event;
166 
167 
168 -- this routine is used for events crossing multiple transactions
169 -- specifically invoice transfer, group reserve transfers
170 
171 FUNCTION create_dual_transaction_event
172            (p_asset_hdr_rec_src      IN FA_API_TYPES.asset_hdr_rec_type,
173             p_asset_hdr_rec_dest     IN FA_API_TYPES.asset_hdr_rec_type,
174             p_asset_type_rec_src     IN FA_API_TYPES.asset_type_rec_type,
175             p_asset_type_rec_dest    IN FA_API_TYPES.asset_type_rec_type,
176             px_trans_rec_src         IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
177             px_trans_rec_dest        IN OUT NOCOPY FA_API_TYPES.trans_rec_type,
178             p_event_status           IN VARCHAR2 DEFAULT NULL,
179             p_calling_fn             IN VARCHAR2,
180             p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null) return boolean is
181 
182    l_trx_source_info  XLA_EVENTS_PUB_PKG.t_event_source_info;
183    l_security_context XLA_EVENTS_PUB_PKG.t_security;
184 
185    l_event_type_code  varchar2(30) ;
186    l_event_date       date         := px_trans_rec_src.transaction_date_entered;
187    l_event_status     varchar2(30) ;
188    l_valuation_method varchar2(30) := p_asset_hdr_rec_src.book_type_code;
189 
190    l_calling_fn       varchar2(80) := 'fa_xla_events_pvt.create_dual_trx_event';
191 
192    invalid_calling_fn      exception;
193    invalid_event_status    exception;
194 
195 BEGIN
196 
197    if (p_asset_type_rec_src.asset_type = 'EXPENSED') then
198       return true;
199    end if;
200 
201    l_trx_source_info.application_id        := 140;
202    l_trx_source_info.legal_entity_id       := NULL;
203    l_trx_source_info.ledger_id             := p_asset_hdr_rec_src.set_of_books_id;
204    l_trx_source_info.transaction_number    := NULL; --to_char(px_trans_rec_src.transaction_header_id);
205    l_trx_source_info.source_id_int_1       := px_trans_rec_src.trx_reference_id;
206    l_trx_source_info.source_id_char_1      := p_asset_hdr_rec_src.book_type_code;
207 
208    -- conditionally set the entity and type codes
209    -- based on calling interface and other factors
210 
211    l_trx_source_info.entity_type_code      := 'INTER_ASSET_TRANSACTIONS';
212 
213    if (p_calling_fn = 'fa_inv_xfr_pub.do_transfer') then
214       if (p_asset_type_rec_src.asset_type  = 'CAPITALIZED' or
215           p_asset_type_rec_dest.asset_type = 'CAPITALIZED') then
216          l_event_type_code                       := 'SOURCE_LINE_TRANSFERS';
217       else
218          l_event_type_code                       := 'CIP_SOURCE_LINE_TRANSFERS';
219       end if;
220    elsif (p_calling_fn = 'fa_rsv_transfer_pub.do_all_books') then
221       l_event_type_code                       := 'RESERVE_TRANSFERS';
222    else
223       raise invalid_calling_fn;
224    end if;
225 
226 
227    -- set the status correctly
228    -- only retirements / reinstatements should use incomplete
229    if (p_event_status is null or
230        p_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED) then
231       l_event_status := XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED;
232    elsif (p_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_INCOMPLETE) then
233       l_event_status := XLA_EVENTS_PUB_PKG.C_EVENT_INCOMPLETE;
234    elsif (p_event_status = XLA_EVENTS_PUB_PKG.C_EVENT_NOACTION) then
235       l_event_status := XLA_EVENTS_PUB_PKG.C_EVENT_NOACTION;
236    else
237       -- invalid type
238       raise invalid_event_status;
239    end if;
240 
241    l_event_date := greatest(l_event_date,
242                             fa_cache_pkg.fazcdp_record.calendar_period_open_date);
243 
244    -- Call XLA API
245    px_trans_rec_src.event_id :=
246      XLA_EVENTS_PUB_PKG.create_event
247           (p_event_source_info   => l_trx_source_info,
248            p_event_type_code     => l_event_type_code,
249            p_event_date          => l_event_date,
250            p_event_status_code   => l_event_status,
251            p_event_number        => NULL,
252            p_reference_info      => NULL,
253            p_valuation_method    => l_valuation_method,
254            p_security_context    => l_security_context);
255 
256    px_trans_rec_dest.event_id := px_trans_rec_src.event_id;
257 
258    return true;
259 
260 EXCEPTION
261   WHEN INVALID_CALLING_FN THEN
262        fa_srvr_msg.add_message
263           (name       => 'FA_INVALID_CALLING_FN',
264            calling_fn => l_calling_fn
265            ,p_log_level_rec => p_log_level_rec);
266        return FALSE;
267 
268   WHEN INVALID_EVENT_STATUS THEN
269        fa_srvr_msg.add_message
270           (name       => 'FA_EVENT_STATUS',
271            calling_fn => l_calling_fn
272            ,p_log_level_rec => p_log_level_rec);
273        return FALSE;
274 
275   WHEN OTHERS THEN
276        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
277               ,p_log_level_rec => p_log_level_rec);
278        return FALSE;
279 
280 
281 
282 END create_dual_transaction_event;
283 
284 PROCEDURE create_deprn_event
285            (p_asset_id          IN     number,
286             p_book_type_code    IN     varchar2,
287             p_period_counter    IN     number,
288             p_period_close_date IN     date,
289             p_deprn_run_id      IN     number,
290             p_ledger_id         IN     number,
291             x_event_id             OUT NOCOPY number,
292             p_calling_fn        IN     VARCHAR2,
293             p_log_level_rec     IN     FA_API_TYPES.log_level_rec_type default null) IS
294 
295    l_deprn_source_info  XLA_EVENTS_PUB_PKG.t_event_source_info;
296    l_security_context   XLA_EVENTS_PUB_PKG.t_security;
297 
298    l_event_type_code  varchar2(30) ;
299    l_event_date       date         := p_period_close_date;
300    l_event_status     varchar2(30) ;
301    l_valuation_method varchar2(30) := p_book_type_code;
302 
303    l_calling_fn       varchar2(80) := 'fa_xla_events_pvt.create_deprn_event';
304 
305 BEGIN
306 
307    l_deprn_source_info.application_id        := 140;
308    l_deprn_source_info.ledger_id             := p_ledger_id;
309    l_deprn_source_info.source_id_int_1       := p_asset_id;
310    l_deprn_source_info.source_id_char_1      := p_book_type_code;
311    l_deprn_source_info.source_id_int_2       := p_period_counter;
312    l_deprn_source_info.source_id_int_3       := p_deprn_run_id;
313 
314    -- conditionally set the entity and type codes
315    -- based on calling interface and other factors
316 
317    l_deprn_source_info.entity_type_code      := 'DEPRECIATION';
318 
319    l_event_status := XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED;
320 
321    -- ER 14644811 : This function will be called from
322    -- FA_DEPRN_EVENTS_PKG.process_single_deprn_event
323 
324    if (p_calling_fn = 'fa_deprn_rollback_pub.do_all_books') then
325       l_event_type_code := 'ROLLBACK_DEPRECIATION';
326    else
327       l_event_type_code := 'DEPRECIATION';
328    end if;
329 
330    -- Call XLA API
331    x_event_id :=
332      XLA_EVENTS_PUB_PKG.create_event
333           (p_event_source_info   => l_deprn_source_info,
334            p_event_type_code     => l_event_type_code,
335            p_event_date          => l_event_date,
336            p_event_status_code   => l_event_status,
337            p_event_number        => NULL,
338            p_reference_info      => NULL,
339            p_valuation_method    => l_valuation_method,
340            p_security_context    => l_security_context);
341 
342 EXCEPTION
343   WHEN OTHERS THEN
344        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
345               ,p_log_level_rec => p_log_level_rec);
346        raise;
347 
348 END create_deprn_event;
349 
350 --
351 -- This routine is internally called from both the depreciation and
352 -- deferred stubs for event handling.  the calling program will insure
353 -- that all arrays passed in pertain to the same set of assets, book
354 -- and period and also that all assets belong to the same legal entity
355 -- since the bulk event creation api requires this to be passed
356 -- as a single parameter and not in the event array.
357 --
358 
359 PROCEDURE create_bulk_deprn_event
360            (p_asset_id_tbl      IN     number_tbl_type,
361             p_book_type_code    IN     varchar2,   -- tax for deferred
362             p_period_counter    IN     number,
363             p_period_close_date IN     date,
364             p_deprn_run_id      IN     number,
365             p_entity_type_code  IN     varchar2,
366             p_secondary_sob_id  IN     number default null,
367             x_event_id_tbl         OUT NOCOPY number_tbl_type,
368             p_calling_fn        IN     VARCHAR2,
369             p_log_level_rec     IN     FA_API_TYPES.log_level_rec_type default null) IS
370 
371    l_legal_entity_id              number;
372 
373    l_entity_event_info_tbl_in  xla_events_pub_pkg.t_array_entity_event_info_s;
374    l_entity_event_info_tbl_out xla_events_pub_pkg.t_array_entity_event_info_s;
375 
376    l_calling_fn                varchar2(80) := 'fa_xla_events_pvt.create_bulk_deprn_event';
377 
378    l_dummy_number              number_tbl_type;
379 
380 BEGIN
381 
382    for i in 1..p_asset_id_tbl.count loop
383       l_dummy_number (i) := i;
384    end loop;
385 
386    -- load the array as required by SLA:
387    -- verify event number and transaction number relevance here
388    -- since neither table uses a transaction sequence
389    forall i in 1..p_asset_id_tbl.count
390    insert into xla_events_int_gt
391      (APPLICATION_ID       ,
392       LEDGER_ID            ,
393       LEGAL_ENTITY_ID      ,
394       ENTITY_CODE          ,
395       event_type_code      ,
396       event_date           ,
397       event_number         ,
398       event_status_code    ,
399       transaction_number   ,
400       source_id_int_1      ,
401       source_id_char_1     ,
402       source_id_int_2      ,
403       source_id_int_3      ,
404       valuation_method
405      )
406      values
407      (140                  ,
408       nvl(p_secondary_sob_id,fa_cache_pkg.fazcbc_record.set_of_books_id),
409       l_legal_entity_id    ,
410       p_entity_type_code   ,
411       'DEPRECIATION'       ,
412       p_period_close_date  ,
413       l_dummy_number(i)    ,
414       XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED,
415       l_dummy_number(i)    ,
416       p_asset_id_tbl(i)    ,
417       p_book_type_code     ,
418       p_period_counter     ,
419       p_deprn_run_id       ,
420       p_book_type_code
421      );
422 
423    XLA_EVENTS_PUB_PKG.create_bulk_events
424                                    (p_source_application_id   => 140,
425                                     p_application_id          => 140,
426                                     p_legal_entity_id         => l_legal_entity_id,
427                                     p_ledger_id               => nvl(p_secondary_sob_id,fa_cache_pkg.fazcbc_record.set_of_books_id),
428                                     p_entity_type_code        => p_entity_type_code
429                                     );
430 
431    select event_id bulk collect
432      into x_event_id_tbl
433      from xla_events_int_gt
434     where source_id_int_3 = p_deprn_run_id
435     order by event_number;
436 
437 EXCEPTION
438   WHEN OTHERS THEN
439        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
440               ,p_log_level_rec => p_log_level_rec);
441        raise;
442 
443 END create_bulk_deprn_event;
444 
445 --
446 -- This routine is internally called from the deferred stub
447 -- for event handling.  the calling program will insure
448 -- that all arrays passed in pertain to the same set of assets, book
449 -- and period and also that all assets belong to the same legal entity
450 -- since the bulk event creation api requires this to be passed
451 -- as a single parameter and not in the event array.
452 --
453 
454 PROCEDURE create_bulk_deferred_event
455            (p_asset_id_tbl        IN     number_tbl_type,
456             p_corp_book           IN     varchar2,
457             p_tax_book            IN     varchar2,
458             p_corp_period_counter IN     number,
459             p_tax_period_counter  IN     number,
460             p_period_close_date   IN     date,
461             p_entity_type_code    IN     varchar2,
462             x_event_id_tbl           OUT NOCOPY number_tbl_type,
463             p_secondary_sob_id    IN     number default -1,
464             p_calling_fn          IN     VARCHAR2,
465             p_log_level_rec       IN     FA_API_TYPES.log_level_rec_type default null) IS
466 
467    l_dummy_number              number_tbl_type;
468    l_legal_entity_id           number;
469 
470    l_entity_event_info_tbl_in  xla_events_pub_pkg.t_array_entity_event_info_s;
471    l_entity_event_info_tbl_out xla_events_pub_pkg.t_array_entity_event_info_s;
472 
473    --Secondary Changes
474    l_sob_id number;
475 
476    l_calling_fn                varchar2(80) := 'fa_xla_events_pvt.create_bulk_deferred_event';
477 
478 BEGIN
479 
480    for i in 1..p_asset_id_tbl.count loop
481       l_dummy_number (i) := i;
482    end loop;
483 
484    -- Secondary Changes
485    if (p_secondary_sob_id <> fa_cache_pkg.fazcbc_record.set_of_books_id) then
486       l_sob_id := p_secondary_sob_id;
487    else
488       l_sob_id := fa_cache_pkg.fazcbc_record.set_of_books_id;
489    end if;
490 
491    -- load the array as required by SLA:
492    -- verify event number and transaction number relevance here
493    -- since neither table uses a transaction sequence
494    forall i in 1..p_asset_id_tbl.count
495    insert into xla_events_int_gt
496      (APPLICATION_ID       ,
497       LEDGER_ID            ,
498       LEGAL_ENTITY_ID      ,
499       ENTITY_CODE          ,
500       event_type_code      ,
501       event_date           ,
502       event_number         ,
503       event_status_code    ,
504       transaction_number   ,
505       source_id_int_1      ,
506       source_id_char_1     ,
507       source_id_char_2     ,
508       source_id_int_2      ,
509       valuation_method
510      )
511      values
512      (140                  ,
513       l_sob_id             ,
514       l_legal_entity_id    ,
515       p_entity_type_code   ,
516       'DEFERRED_DEPRECIATION'       ,
517       p_period_close_date  ,
518       l_dummy_number(i)    ,
519       XLA_EVENTS_PUB_PKG.C_EVENT_UNPROCESSED,
520       l_dummy_number(i)    ,
521       p_asset_id_tbl(i)    ,
522       p_corp_book          ,
523       p_tax_book           ,
524       p_corp_period_counter,
525       p_corp_book
526      );
527 
528    XLA_EVENTS_PUB_PKG.create_bulk_events
529                                    (p_source_application_id   => 140,
530                                     p_application_id          => 140,
531                                     p_legal_entity_id         => l_legal_entity_id,
532                                     p_ledger_id               => fa_cache_pkg.fazcbc_record.set_of_books_id,
533                                     p_entity_type_code        => p_entity_type_code
534                                     );
535 
536    select event_id bulk collect
537      into x_event_id_tbl
538      from xla_events_int_gt
539     order by event_number;
540 
541 
542 EXCEPTION
543   WHEN OTHERS THEN
544        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
545               ,p_log_level_rec => p_log_level_rec);
546        raise;
547 
548 END create_bulk_deferred_event;
549 
550 
551 -- update events
552 -- this is only called from gain/loss when processing the retirement
553 -- OPEN do we need to update the transaction date for unprocessed retirements?
554 
555 /*
556 
557 PROCEDURE update_event_status
558    (p_event_source_info            IN  xla_events_pub_pkg.t_event_source_info
559    ,p_event_class_code             IN  VARCHAR2   DEFAULT NULL
560    ,p_event_type_code              IN  VARCHAR2   DEFAULT NULL
561    ,p_event_date                   IN  DATE       DEFAULT NULL
562    ,p_event_status_code            IN  VARCHAR2
563    ,p_valuation_method             IN  VARCHAR2
564    ,p_security_context             IN  xla_events_pub_pkg.t_security
565 
566    ,p_log_level_rec        IN     FA_API_TYPES.log_level_rec_type default null);
567 
568 */
569 
570 FUNCTION update_transaction_event
571            (p_ledger_id              IN NUMBER,
572             p_transaction_header_id  IN NUMBER,
573             p_book_type_code         IN VARCHAR2,
574             p_event_type_code        IN VARCHAR2,
575             p_event_date             IN DATE,
576             p_event_status_code      IN VARCHAR2,
577             p_secondary_flag         IN BOOLEAN DEFAULT FALSE,
578             p_secondary_sob_id       IN number default null,
579             p_calling_fn             IN VARCHAR2,
580             p_log_level_rec          IN FA_API_TYPES.log_level_rec_type default null) return boolean IS
581 
582    l_trx_source_info   XLA_EVENTS_PUB_PKG.t_event_source_info;
583    l_security_context  XLA_EVENTS_PUB_PKG.t_security;
584    l_event_type        varchar2(30);
585    l_event_id          number;
586    l_event_date        date;
587 
588    l_calling_fn        varchar2(80) := 'fa_xla_events_pvt.update_transaction_event';
589 
590 begin
591 
592    l_trx_source_info.application_id        := 140;
593    l_trx_source_info.ledger_id             := p_ledger_id;
594    l_trx_source_info.source_id_int_1       := p_transaction_header_id;
595    l_trx_source_info.source_id_char_1      := p_book_type_code;
596    l_trx_source_info.entity_type_code      := 'TRANSACTIONS';
597 
598    -- Secondary Ledger changes
599    if (p_secondary_flag) then
600       select event_id
601         into l_event_id
602         from xla_events xeve,
603              xla_transaction_entities  xent
604        where xeve.application_id   = 140
605          and xeve.event_type_code  = p_event_type_code
606          and xent.application_id   = xeve.application_id
607          and source_id_char_1      = p_book_type_code
608          and source_id_int_1       = p_transaction_header_id
609          and ledger_id             = p_secondary_sob_id
610          and xeve.entity_id        = xent.entity_id;
611    else
612        select event_id
613          into l_event_id
614          from fa_transaction_headers
615         where transaction_header_id = p_transaction_header_id;
616    end if;
617 
618    l_event_date := greatest(p_event_date,
619                             fa_cache_pkg.fazcdp_record.calendar_period_open_date);
620 
621    XLA_EVENTS_PUB_PKG.update_event
622      (p_event_source_info            => l_trx_source_info,
623       p_event_id                     => l_event_id,
624       p_event_type_code              => p_event_type_code,
625       p_event_date                   => l_event_date,
626       p_event_status_code            => p_event_status_code,
627       p_valuation_method             => p_book_type_code,
628       p_security_context             => l_security_context);
629 
630   return true;
631 
632 EXCEPTION
633    WHEN OTHERS THEN
634        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
635               ,p_log_level_rec => p_log_level_rec);
636        return false;
637 
638 end update_transaction_event;
639 
640 FUNCTION update_inter_transaction_event
641            (p_ledger_id              IN NUMBER,
642             p_trx_reference_id       IN NUMBER,
643             p_book_type_code         IN VARCHAR2,
644             p_event_type_code        IN VARCHAR2,
645             p_event_date             IN DATE,
646             p_event_status_code      IN VARCHAR2,
647             p_is_secondary_ledger    IN boolean default false,
648             p_calling_fn             IN VARCHAR2,
649             p_log_level_rec in fa_api_types.log_level_rec_type default null
650            ) return boolean is
651 
652    l_trx_source_info   XLA_EVENTS_PUB_PKG.t_event_source_info;
653    l_security_context  XLA_EVENTS_PUB_PKG.t_security;
654    l_event_type        varchar2(30);
655    l_event_id          number;
656 
657    l_destination_trx_header_id number;--Secondary Change
658 
659    l_calling_fn        varchar2(80) := 'fa_xla_events_pvt.update_inter_transaction_event';
660 
661 begin
662 
663    l_trx_source_info.application_id        := 140;
664    l_trx_source_info.ledger_id             := p_ledger_id;
665    l_trx_source_info.source_id_int_1       := p_trx_reference_id;
666    l_trx_source_info.source_id_char_1      := p_book_type_code;
667    l_trx_source_info.entity_type_code      := 'INTER_ASSET_TRANSACTIONS';
668 
669    select event_id, dest_transaction_header_id
670      into l_event_id, l_destination_trx_header_id
671      from fa_trx_references
672     where trx_reference_id = p_trx_reference_id;
673 
674    --Secondary Changes
675    if (p_is_secondary_ledger) then
676 
677       select event_id
678         into l_event_id
679         from xla_events xeve,
680              xla_transaction_entities  xent
681        where xeve.application_id   = 140
682          and xeve.event_type_code in ('SOURCE_LINE_TRANSFERS', 'CIP_SOURCE_LINE_TRANSFERS')
683          and xent.application_id   = xeve.application_id
684          and source_id_char_1      = p_book_type_code
685          and source_id_int_1       = l_destination_trx_header_id; --need to check. Secondary Changes
686 
687    end if;
688 
689    XLA_EVENTS_PUB_PKG.update_event
690      (p_event_source_info            => l_trx_source_info,
691       p_event_id                     => l_event_id,
692       p_event_type_code              => p_event_type_code,
693       p_event_date                   => p_event_date,
694       p_event_status_code            => p_event_status_code,
695       p_valuation_method             => p_book_type_code,
696       p_security_context             => l_security_context);
697 
698   return true;
699 
700 EXCEPTION
701    WHEN OTHERS THEN
702        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
703               ,p_log_level_rec => p_log_level_rec);
704        return false;
705 
706 end update_inter_transaction_event;
707 
708 -- delete events (unrocessed additions/retirements/reinstatements/unprocessed deprn *only*)
709 -- this shoudl only be called from single transaction events
710 --  (specifically, when undoing retirement/reinstatements)
711 
712 FUNCTION delete_transaction_event
713            (p_ledger_id              IN NUMBER,
714             p_transaction_header_id  IN NUMBER,
715             p_book_type_code         IN VARCHAR2,
716             p_asset_type             IN VARCHAR2,
717             p_secondary_sob_id       IN number default null,
718             p_calling_fn             IN VARCHAR2,
719             p_log_level_rec          IN FA_API_TYPES.log_level_rec_type default null) return boolean IS
720 
721    l_event_id         NUMBER;
722    l_trx_source_info  XLA_EVENTS_PUB_PKG.t_event_source_info;
723    l_security_context XLA_EVENTS_PUB_PKG.t_security;
724    l_result           integer;
725 
726    --Secondary Changes
727    l_event_type_code  varchar2(30) ;
728 
729    l_calling_fn       varchar2(80) := 'fa_xla_events_pvt.delete_transaction_event';
730 
731 BEGIN
732 
733    l_trx_source_info.application_id        := 140;
734    l_trx_source_info.ledger_id             := p_ledger_id;
735    l_trx_source_info.source_id_int_1       := p_transaction_header_id;
736    l_trx_source_info.source_id_char_1      := p_book_type_code;
737    l_trx_source_info.entity_type_code      := 'TRANSACTIONS';
738 
739    if (p_secondary_sob_id is null) then
740       select event_id
741         into l_event_id
742         from fa_transaction_headers
743        where transaction_header_id = p_transaction_header_id;
744    end if;
745 
746    -- Secondary Changes
747    if (p_secondary_sob_id is not null) then
748 
749       if (p_calling_fn = 'fa_ret_pub.undo_all_books_reinstatement.secondary') then
750          select event_id
751            into l_event_id
752            from xla_events xeve,
753                 xla_transaction_entities  xent
754           where xeve.application_id  = 140
755             and xeve.event_type_code = 'REINSTATEMENTS'
756             and xent.application_id  = xeve.application_id
757             and source_id_char_1     = p_book_type_code
758             and source_id_int_1      = p_transaction_header_id
759             and ledger_id            = p_secondary_sob_id
760             and xeve.entity_id       = xent.entity_id;
761 
762       elsif (p_calling_fn = 'fa_ret_pub.undo_all_books_retirement.secondary') then
763          select event_id
764            into l_event_id
765            from xla_events xeve,
766                 xla_transaction_entities   xent
767           where xeve.application_id  = 140
768             and xeve.event_type_code = 'RETIREMENTS'
769             and xent.application_id  = xeve.application_id
770             and source_id_char_1     = p_book_type_code
771             and source_id_int_1      = p_transaction_header_id
772             and ledger_id            = p_secondary_sob_id
773             and xeve.entity_id       = xent.entity_id;
774 
775       elsif (p_calling_fn = 'fa_cip_pvt.do_cap_rev.secondary') then
776 
777          if (p_log_level_rec.statement_level) then
778             fa_debug_pkg.add(l_calling_fn, 'in del trx event  p_book_type_code', p_book_type_code ,p_log_level_rec => p_log_level_rec);
779             fa_debug_pkg.add(l_calling_fn, 'in del trx event  p_transaction_header_id', p_transaction_header_id ,p_log_level_rec => p_log_level_rec);
780          end if;
781 
782          select event_id
783            into l_event_id
784            from xla_events xeve,
785                 xla_transaction_entities   xent
786           where xeve.application_id  = 140
787             and xeve.event_type_code = 'CAPITALIZATION'
788             and xent.application_id  = xeve.application_id
789             and source_id_char_1     = p_book_type_code
790             and source_id_int_1      = p_transaction_header_id
791             and ledger_id            = p_secondary_sob_id
792             and xeve.entity_id       = xent.entity_id;
793 
794          if (p_log_level_rec.statement_level) then
795             fa_debug_pkg.add(l_calling_fn, 'in del trx event  l_event_id', l_event_id ,p_log_level_rec => p_log_level_rec);
796          end if;
797 
798       end if;
799    end if;
800 
801    If (nvl(p_asset_type,'XX') <> 'EXPENSED') then
802 
803       XLA_EVENTS_PUB_PKG.delete_event
804          (p_event_source_info            => l_trx_source_info,
805           p_event_id                     => l_event_id,
806           p_valuation_method             => p_book_type_code,
807           p_security_context             => l_security_context);
808 
809       BEGIN
810          l_result := XLA_EVENTS_PUB_PKG.delete_entity
811                        (p_source_info       => l_trx_source_info,
812                         p_valuation_method  => p_book_type_code,
813                         p_security_context  => l_security_context);
814 
815       EXCEPTION
816          WHEN OTHERS THEN
817               l_result := 1;
818               fa_debug_pkg.add(l_calling_fn, 'Unable to delete entity for trx event',
819                                l_event_id, p_log_level_rec => p_log_level_rec);
820       END; --annonymous
821 
822    End If;
823 
824    return true;
825 
826 EXCEPTION
827    WHEN OTHERS THEN
828        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
829               ,p_log_level_rec => p_log_level_rec);
830        return false;
831 
832 END delete_transaction_event;
833 
834 FUNCTION delete_deprn_event
835            (p_event_id               IN NUMBER,
836             p_ledger_id              IN NUMBER,
837             p_asset_id               IN NUMBER,
838             p_book_type_code         IN VARCHAR2,
839             p_period_counter         IN NUMBER,
840             p_deprn_run_id           IN NUMBER,
841             p_calling_fn             IN VARCHAR2,
842             p_log_level_rec          IN FA_API_TYPES.log_level_rec_type default null) return boolean IS
843 
844    l_event_id           NUMBER;
845    l_deprn_source_info  XLA_EVENTS_PUB_PKG.t_event_source_info;
846    l_security_context   XLA_EVENTS_PUB_PKG.t_security;
847    l_result             integer;
848 
849    l_calling_fn         varchar2(80) := 'fa_xla_events_pvt.delete_deprn_event';
850 
851 BEGIN
852 
853    l_deprn_source_info.application_id        := 140;
854    l_deprn_source_info.ledger_id             := p_ledger_id;
855    l_deprn_source_info.source_id_int_1       := p_asset_id;
856    l_deprn_source_info.source_id_char_1      := p_book_type_code;
857    l_deprn_source_info.source_id_int_2       := p_period_counter;
858    l_deprn_source_info.source_id_int_3       := p_deprn_run_id;
859    l_deprn_source_info.entity_type_code      := 'DEPRECIATION';
860 
861    XLA_EVENTS_PUB_PKG.delete_event
862       (p_event_source_info            => l_deprn_source_info,
863        p_event_id                     => p_event_id,
864        p_valuation_method             => p_book_type_code,
865        p_security_context             => l_security_context);
866 
867    --6702657
868    BEGIN
869       l_result := XLA_EVENTS_PUB_PKG.delete_entity
870                        (p_source_info       => l_deprn_source_info,
871                         p_valuation_method  => p_book_type_code,
872                         p_security_context  => l_security_context);
873 
874    EXCEPTION
875       WHEN OTHERS THEN
876         l_result := 1;
877         fa_debug_pkg.add(l_calling_fn, 'Unable to delete entity for event',
878                   p_event_id, p_log_level_rec => p_log_level_rec);
879         fa_debug_pkg.add(l_calling_fn, 'l_result', l_result, p_log_level_rec => p_log_level_rec);
880    END; --annonymous
881 
882    return true;
883 
884 EXCEPTION
885    WHEN OTHERS THEN
886        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
887               ,p_log_level_rec => p_log_level_rec);
888        return false;
889 
890 END delete_deprn_event;
891 
892 FUNCTION get_event_type
893            (p_event_id              IN NUMBER,
894             x_event_type_code       OUT NOCOPY VARCHAR2,
895             p_log_level_rec in fa_api_types.log_level_rec_type default null
896            ) return boolean IS
897 
898    l_calling_fn         varchar2(80) := 'fa_xla_events_pvt.get_event_type';
899 
900 BEGIN
901 
902    select event_type_code
903      into x_event_type_code
904      from xla_events
905     where application_id = 140
906       and event_id       = p_event_id;
907 
908    return true;
909 
910 EXCEPTION
911    WHEN OTHERS THEN
912        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
913               ,p_log_level_rec => p_log_level_rec);
914        return false;
915 
916 END;
917 
918 
919 FUNCTION get_trx_event_status
920            (p_set_of_books_id       IN number
921            ,p_transaction_header_id IN number
922            ,p_event_id              IN number
923            ,p_book_type_code        IN varchar2
924            ,x_event_status          OUT NOCOPY varchar2
925            ,p_log_level_rec in fa_api_types.log_level_rec_type default null
926            ) return boolean IS
927 
928    l_source_info              XLA_EVENTS_PUB_PKG.t_event_source_info;
929    l_security_context         XLA_EVENTS_PUB_PKG.t_security;
930 
931    l_calling_fn    varchar2(80) := 'fa_xla_events_pvt.get_trx_event_status';
932 
933 BEGIN
934 
935    l_source_info.application_id        := 140;
936    l_source_info.ledger_id             := p_set_of_books_id;
937    l_source_info.source_id_int_1       := p_transaction_header_id;
938    l_source_info.source_id_char_1      := p_book_type_code;
939    l_source_info.entity_type_code      := 'TRANSACTIONS';
940 
941    if (p_log_level_rec.statement_level) then
942       fa_debug_pkg.add(l_calling_fn, 'calling get event status for event ', p_event_id
943                       ,p_log_level_rec => p_log_level_rec);
944    end if;
945 
946    -- check the event status
947    x_event_status := XLA_EVENTS_PUB_PKG.get_event_status
948                         (p_event_source_info            => l_source_info,
949                          p_event_id                     => p_event_id,
950                          p_valuation_method             => p_book_type_code,
951                          p_security_context             => l_security_context);
952 
953    return true;
954 
955 EXCEPTION
956    WHEN OTHERS THEN
957        fa_srvr_msg.add_sql_error(calling_fn => l_calling_fn
958               ,p_log_level_rec => p_log_level_rec);
959        return false;
960 
961 
962 END;
963 
964 function get_secondary_sob_id
965            (p_book_type_code IN varchar2
966            ,p_log_level_rec  in fa_api_types.log_level_rec_type default null
967            ) return number is
968 
969    l_secondary_sob_id number;
970 
971 begin
972 
973    select set_of_books_id
974      into l_secondary_sob_id
975      from fa_mc_book_controls famcbc
976     where book_type_code = p_book_type_code
977       and nvl(enabled_flag,'N') = 'Y'
978       and not exists
979           (select 1
980              from fa_book_controls
981             where  book_type_code = p_book_type_code
982               and  book_class     = 'TAX'
983               and set_of_books_id = famcbc.set_of_books_id)
984       and exists
985           (select 1
986              from gl_ledgers
987             where ledger_id            = set_of_books_id
988               and ledger_category_code = 'SECONDARY');
989 
990    return l_secondary_sob_id;
991 
992 exception
993    when no_data_found then
994         return null;
995 
996    when others then
997         return null;
998 
999 end get_secondary_sob_id;
1000 
1001 FUNCTION get_secondary_event_id
1002            (p_book_type_code  IN varchar2,
1003             p_ledger_id       IN number,
1004             p_source_id_int_1 IN number
1005            ,p_log_level_rec  in fa_api_types.log_level_rec_type default null
1006            ) return number is
1007 
1008   l_secondary_cap_event_id number;
1009 
1010 begin
1011 
1012    select event_id
1013      into l_secondary_cap_event_id
1014      from xla_events xeve,
1015           xla_transaction_entities  xent
1016     where xeve.application_id   = 140
1017       and xeve.event_type_code  = 'CAPITALIZATION'
1018       and xent.application_id   = xeve.application_id
1019       and source_id_char_1      = p_book_type_code
1020       and source_id_int_1       = p_source_id_int_1
1021       and xeve.entity_id        = xent.entity_id
1022       and ledger_id             = p_ledger_id;
1023 
1024    return l_secondary_cap_event_id;
1025 
1026 exception
1027    when others then
1028         l_secondary_cap_event_id := null;
1029         return l_secondary_cap_event_id;
1030 
1031 end get_secondary_event_id;
1032 
1033 FUNCTION get_secondary_event_id
1034            (p_book_type_code  in varchar2,
1035             p_ledger_id       in number,
1036             p_source_id_int_1 in number,
1037             p_source_id_int_2 in number,
1038             p_source_id_int_3 in out nocopy number
1039            ,p_log_level_rec   in fa_api_types.log_level_rec_type default null
1040            ) return number is
1041 
1042   l_secondary_event_id number;
1043   l_secondary_deprn_run_id number;
1044 
1045 begin
1046 
1047    if (p_source_id_int_3 is null) then
1048 
1049       SELECT deprn_run_id
1050         into l_secondary_deprn_run_id
1051         from fa_mc_deprn_summary
1052        where set_of_books_id = p_ledger_id
1053          and book_type_code  = p_book_type_code
1054          and period_counter  =  p_source_id_int_2
1055          and asset_id        =  p_source_id_int_1;
1056 
1057    else
1058       l_secondary_deprn_run_id := p_source_id_int_3;
1059    end if;
1060 
1061    p_source_id_int_3 := l_secondary_deprn_run_id;
1062 
1063    select event_id
1064      into l_secondary_event_id
1065      from xla_events xeve,
1066           xla_transaction_entities  xent
1067     where xeve.application_id  = 140
1068       and xeve.event_type_code = 'DEPRECIATION'
1069       and xent.application_id  = xeve.application_id
1070       and source_id_char_1     = p_book_type_code
1071       and source_id_int_1      = p_source_id_int_1
1072       and source_id_int_2      = p_source_id_int_2
1073       and source_id_int_3      = l_secondary_deprn_run_id
1074       and xeve.entity_id       = xent.entity_id;
1075 
1076    return l_secondary_event_id;
1077 
1078 exception
1079    when others then
1080         l_secondary_event_id := null;
1081         return l_secondary_event_id;
1082 
1083 end get_secondary_event_id;
1084 
1085 end FA_XLA_EVENTS_PVT;