[Home] [Help]
PACKAGE BODY: APPS.FA_GENACCTS_PKG
Source
1 PACKAGE BODY FA_GENACCTS_PKG as
2 /* $Header: fagendab.pls 120.25 2010/12/20 12:34:08 gigupta ship $ */
3
4
5 G_gen_expense varchar2(1) := NULL;
6 G_pregen_asset_acct varchar2(1) := NULL;
7 G_pregen_cat_acct varchar2(1) := NULL;
8 G_pregen_book_acct varchar2(1) := NULL;
9 G_FY_first_pc number := NULL; --added for BUG# 1339219
10 G_request_id number;
11
12 G_success_count NUMBER := 0;
13 G_failure_count NUMBER := 0;
14
15 g_log_level_rec fa_api_types.log_level_rec_type;
16
17 TYPE t_number is table of number index by binary_integer;
18 TYPE t_varchar is table of varchar2(150) index by binary_integer;
19
20
21 PROCEDURE GEN_ACCTS(
22 p_book_type_code IN VARCHAR2,
23 p_parent_request_id IN NUMBER,
24 p_total_requests IN NUMBER,
25 p_request_number IN NUMBER,
26 x_success_count OUT NOCOPY number,
27 x_failure_count OUT NOCOPY number,
28 x_return_status OUT NOCOPY number,
29 x_worker_jobs OUT NOCOPY number) IS
30
31 l_batch_size number;
32 l_dist_source_book varchar2(30);
33 l_calling_fn varchar2(40) := 'FA_GENACCTS_PKG.GEN_ACCTS';
34
35 -- book variables
36 h_default_ccid number;
37 h_flex_num number;
38 h_book_class varchar(30);
39 h_nbv_gain_acct varchar(30);
40 h_nbv_loss_acct varchar(30);
41 h_pos_gain_acct varchar(30);
42 h_pos_loss_acct varchar(30);
43 h_cor_gain_acct varchar(30);
44 h_cor_loss_acct varchar(30);
45 h_cor_clearing_acct varchar(30);
46 h_pos_clearing_acct varchar(30);
47 h_deferred_exp_acct varchar2(30);
48 h_deferred_rsv_acct varchar2(30);
49 h_reval_rsv_loss_acct varchar2(30);
50 h_reval_rsv_gain_acct varchar2(30);
51 h_deprn_adj_acct varchar2(30);
52 h_allow_reval_flag varchar2(3);
53 h_allow_deprn_adjust varchar2(3);
54 h_gl_posting_allowed varchar2(3);
55 h_allow_impairment_flag varchar2(1);
56 h_allow_sorp_flag varchar2(1); -- Bug 6666666 : Sorp Compliance Project
57
58 h_result boolean;
59 h_return_ccid number;
60 h_total_requests number;
61 h_request_number number;
62 status boolean;
63 h_submit_child boolean := FALSE;
64 msg_count NUMBER := 0;
65 msg_data varchar2(512);
66 h_req_data varchar2(10) := NULL;
67
68 -- new paralism
69 l_unassigned_cnt NUMBER := 0;
70 l_failed_cnt NUMBER := 0;
71 l_wip_cnt NUMBER := 0;
72 l_completed_cnt NUMBER := 0;
73 l_total_cnt NUMBER := 0;
74 l_count NUMBER := 0;
75 l_start_range NUMBER := 0;
76 l_end_range NUMBER := 0;
77
78
79
80 -- category_account variables
81 l_acct_ccid t_number;
82 l_acct_seg t_varchar;
83 l_reserve_acct t_varchar;
84 l_cost_acct t_varchar;
85 l_clearing_acct t_varchar;
86 l_expense_acct t_varchar;
87 l_cip_cost_acct t_varchar;
88 l_cip_clearing_acct t_varchar;
89 l_cost_ccid t_number;
90 l_clearing_ccid t_number;
91 l_reserve_ccid t_number;
92 l_cip_cost_ccid t_number;
93 l_cip_clearing_ccid t_number;
94 l_reval_rsv_acct t_varchar;
95 l_reval_amort_acct t_varchar;
96 l_reval_rsv_ccid t_number;
97 l_reval_amort_ccid t_number;
98 l_bonus_exp_acct t_varchar;
99 l_bonus_rsv_acct t_varchar;
100 l_bonus_rsv_ccid t_number;
101 l_impair_exp_acct t_varchar;
102 l_impair_exp_ccid t_number;
103 l_impair_rsv_acct t_varchar;
104 l_impair_rsv_ccid t_number;
105 l_capital_adj_acct t_varchar; -- Bug 6666666 : Sorp Compliance Project
106 l_capital_adj_ccid t_number; -- Bug 6666666 : Sorp Compliance Project
107 l_general_fund_acct t_varchar; -- Bug 6666666 : Sorp Compliance Project
108 l_general_fund_ccid t_number; -- Bug 6666666 : Sorp Compliance Project
109 l_reval_loss_acct t_varchar;
110 l_reval_loss_ccid t_number;
111
112 --distribution cursor variables
113 l_dist_id t_number;
114 l_asset_number t_varchar;
115 l_asset_id t_number;
116 l_asset_type t_varchar;
117 l_asset_category_id t_number;
118 l_dist_ccid t_number;
119 l_bonus_rule t_varchar; -- BUG# 1791317
120 l_group_asset_id t_number;
121 l_tracking_method t_varchar;
122
123 done_exc exception;
124 error_found exception;
125
126 CURSOR dist (p_book_type_code varchar2,
127 p_dist_source_book varchar2,
128 p_fy_first_pc number,
129 p_pregen_asset_acct varchar2,
130 p_pregen_cat_acct varchar2,
131 p_pregen_book_acct varchar2,
132 p_book_class varchar2,
133 p_gl_posting_allowed varchar2,
134 p_allow_deprn_adjust varchar2,
135 p_allow_reval_flag varchar2,
136 p_allow_impairment_flag varchar2,
137 p_allow_sorp_flag varchar2, -- Bug 6666666
138 p_start_range number,
139 p_end_range number
140 ) is
141 SELECT /*+ leading(dh) index(dh FA_DISTRIBUTION_HISTORY_U1) */
142 dh.distribution_id,
143 ad.asset_number,
144 ad.asset_id,
145 ad.asset_type,
146 ad.asset_category_id,
147 dh.code_combination_id,
148 bks.bonus_rule,
149 bks.group_asset_id,
150 bks.tracking_method
151 FROM fa_distribution_accounts da2,
152 fa_additions_b ad,
153 fa_distribution_history dh,
154 fa_books bks
155 WHERE dh.date_ineffective is null
156 AND dh.book_type_code = p_dist_source_book
157 AND da2.book_type_code(+) = p_book_type_code
158 AND da2.distribution_id(+) = dh.distribution_id
159 AND ad.asset_id = dh.asset_id
160 /* BUG# 1339219: do not select distributions for assets
161 which have been fully retired in a prior year */
162 AND bks.asset_id = dh.asset_id
163 AND bks.book_type_code = p_book_type_code
164 AND bks.transaction_header_id_out is null
165 AND (bks.period_counter_fully_retired is null OR
166 bks.period_counter_fully_retired >= p_FY_first_pc)
167 -- end BUG# 1339219
168 and dh.distribution_id between p_start_range and p_end_range
169 AND (((p_pregen_asset_acct = 'Y') AND
170 da2.deprn_expense_account_ccid is NULL) OR
171 ((p_pregen_cat_acct = 'Y') AND
172 (((ad.asset_type <> 'GROUP') AND
173 (da2.asset_cost_account_ccid is NULL or
174 da2.asset_clearing_account_ccid is NULL)) OR
175 --da2.deprn_expense_account_ccid is NULL OR
176 da2.deprn_reserve_account_ccid is NULL OR
177 ((ad.asset_type = 'CIP') AND
178 (da2.cip_cost_account_ccid is NULL OR
179 da2.cip_clearing_account_ccid is NULL)) OR
180 ((p_allow_reval_flag = 'YES' and
181 ad.asset_type <> 'GROUP') AND
182 (da2.reval_amort_account_ccid is NULL OR
183 da2.reval_rsv_account_ccid is NULL)) OR
184 ((bks.bonus_rule is not null ) AND
185 (da2.bonus_exp_account_ccid is NULL OR
186 da2.bonus_rsv_account_ccid is NULL)))) OR
187 ((p_pregen_book_acct = 'Y' and
188 ad.asset_type <> 'GROUP') AND
189 (da2.nbv_retired_gain_ccid is NULL OR
190 da2.nbv_retired_loss_ccid is NULL OR
191 da2.proceeds_sale_gain_ccid is NULL OR
192 da2.proceeds_sale_loss_ccid is NULL OR
193 da2.cost_removal_gain_ccid is NULL OR
194 da2.cost_removal_loss_ccid is NULL OR
195 da2.proceeds_sale_clearing_ccid is NULL OR
196 da2.cost_removal_clearing_ccid is NULL OR
197 ( (p_allow_sorp_flag = 'Y') AND -- Bug 6666666
198 (
199 da2.capital_adj_account_ccid is NULL OR
200 da2.general_fund_account_ccid is NULL OR
201 da2.reval_loss_account_ccid is NULL
202 )
203 ) OR
204 ((p_allow_impairment_flag = 'Y') AND
205 (da2.impair_expense_account_ccid is NULL OR
206 da2.impair_reserve_account_ccid is NULL)) OR
207 ((p_book_class = 'TAX') AND
208 (((da2.deferred_exp_account_ccid is NULL OR
209 da2.deferred_rsv_account_ccid is NULL)) OR
210 ((p_allow_deprn_adjust = 'YES') AND
211 da2.deprn_adj_account_ccid is NULL)))) OR
212 ((p_allow_reval_flag = 'YES') AND
213 (da2.reval_rsv_gain_account_ccid is NULL OR
214 da2.reval_rsv_loss_account_ccid is NULL))));
215
216 BEGIN
217
218 G_success_count := 0;
219 G_failure_count := 0;
220 x_success_count := 0;
221 x_failure_count := 0;
222 x_worker_jobs := 0;
223
224 if (not g_log_level_rec.initialized) then
225 if (NOT fa_util_pub.get_log_level_rec (
226 x_log_level_rec => g_log_level_rec
227 )) then
228 raise error_found;
229 end if;
230 end if;
231 -- Initialize server message stack and debug
232 FA_DEBUG_PKG.Initialize;
233
234 -- get book information
235 if not fa_cache_pkg.fazcbc(X_book => p_book_type_code, p_log_level_rec => g_log_level_rec) then
236 raise error_found;
237 end if;
238
239 l_batch_size := nvl(fa_cache_pkg.fa_batch_size, 1000);
240 l_dist_source_book := fa_cache_pkg.fazcbc_record.distribution_source_book;
241
242 fnd_profile.get('FA_GEN_EXPENSE_ACCOUNT', G_gen_expense);
243 fnd_profile.get('FA_PREGEN_ASSET_ACCOUNT', G_pregen_asset_acct);
244 fnd_profile.get('FA_PREGEN_CAT_ACCOUNT', G_pregen_cat_acct);
245 fnd_profile.get('FA_PREGEN_BOOK_ACCOUNT', G_pregen_book_acct);
246
247 -- if null set accordingly
248 if (G_gen_expense is null) then
249 G_gen_expense := 'N';
250 end if;
251
252 if (G_pregen_asset_acct is null) then
253 G_pregen_asset_acct := 'Y';
254 end if;
255
256 if (G_pregen_cat_acct is null) then
257 G_pregen_cat_acct := 'Y';
258 end if;
259
260 if (G_pregen_book_acct is null) then
261 G_pregen_book_acct:= 'Y';
262 end if;
263
264 /* Get the first period counter of the current Fiscal Year --BUG# 1339219 */
265 h_default_ccid := fa_cache_pkg.fazcbc_record.flexbuilder_defaults_ccid;
266 h_flex_num := fa_cache_pkg.fazcbc_record.accounting_flex_structure;
267 h_book_class := fa_cache_pkg.fazcbc_record.book_class;
268 h_nbv_gain_acct := fa_cache_pkg.fazcbc_record.nbv_retired_gain_acct;
269 h_nbv_loss_acct := fa_cache_pkg.fazcbc_record.nbv_retired_loss_acct;
270 h_pos_gain_acct := fa_cache_pkg.fazcbc_record.proceeds_of_sale_gain_acct;
271 h_pos_loss_acct := fa_cache_pkg.fazcbc_record.proceeds_of_sale_loss_acct;
272 h_pos_clearing_acct := fa_cache_pkg.fazcbc_record.proceeds_of_sale_clearing_acct;
273 h_cor_gain_acct := fa_cache_pkg.fazcbc_record.cost_of_removal_gain_acct;
274 h_cor_loss_acct := fa_cache_pkg.fazcbc_record.cost_of_removal_loss_acct;
275 h_cor_clearing_acct := fa_cache_pkg.fazcbc_record.cost_of_removal_clearing_acct;
276 h_reval_rsv_gain_acct := fa_cache_pkg.fazcbc_record.reval_rsv_retired_gain_acct;
277 h_reval_rsv_loss_acct := fa_cache_pkg.fazcbc_record.reval_rsv_retired_loss_acct;
278 h_deferred_exp_acct := fa_cache_pkg.fazcbc_record.deferred_deprn_expense_acct;
279 h_deferred_rsv_acct := fa_cache_pkg.fazcbc_record.deferred_deprn_reserve_acct;
280 h_deprn_adj_acct := fa_cache_pkg.fazcbc_record.deprn_adjustment_acct;
281 h_allow_reval_flag := fa_cache_pkg.fazcbc_record.allow_reval_flag;
282 h_allow_deprn_adjust := fa_cache_pkg.fazcbc_record.allow_deprn_adjustments;
283 h_gl_posting_allowed := fa_cache_pkg.fazcbc_record.gl_posting_allowed_flag;
284 h_allow_impairment_flag := nvl(fa_cache_pkg.fazcbc_record.allow_impairment_flag, 'N');
285 h_allow_sorp_flag := nvl(fa_cache_pkg.fazcbc_record.sorp_enabled_flag, 'N'); -- Bug 6666666
286
287 if g_log_level_rec.statement_level then
288 fa_debug_pkg.add(l_calling_fn,'Sorp Enabled Flag',h_allow_sorp_flag, p_log_level_rec => g_log_level_rec);
289 end if;
290
291 select dp.period_counter
292 into G_FY_first_pc
293 from fa_deprn_periods dp
294 where dp.book_type_code = p_book_type_code
295 and dp.fiscal_year = fa_cache_pkg.fazcbc_record.current_fiscal_year
296 and dp.period_num =
297 (select min(period_num)
298 from fa_deprn_periods dp2
299 where dp2.book_type_code = p_book_type_code
300 and dp2.fiscal_year = fa_cache_pkg.fazcbc_record.current_fiscal_year);
301
302 if not fa_cache_pkg.fazcdp
303 (x_book_type_code => p_book_type_code,
304 x_period_counter => null,
305 x_effective_date => null, p_log_level_rec => g_log_level_rec) then
306 raise error_found;
307 end if;
308
309 G_validation_date := fa_cache_pkg.fazcdp_record.calendar_period_close_date;
310
311 -- ------------------------------------------
312 -- Loop thru job list
313 -- -----------------------------------------
314
315 if g_log_level_rec.statement_level then
316 fa_debug_pkg.add(l_calling_fn, 'looping through: ', 'job list', p_log_level_rec => g_log_level_rec);
317 end if;
318
319
320
321 SELECT NVL(sum(decode(status,'UNASSIGNED', 1, 0)),0),
322 NVL(sum(decode(status,'FAILED', 1, 0)),0),
323 NVL(sum(decode(status,'IN PROCESS', 1, 0)),0),
324 NVL(sum(decode(status,'COMPLETED',1 , 0)),0),
325 count(*)
326 INTO l_unassigned_cnt,
327 l_failed_cnt,
328 l_wip_cnt,
329 l_completed_cnt,
330 l_total_cnt
331 FROM FA_WORKER_JOBS
332 WHERE request_id = p_parent_request_id;
333
334 if g_log_level_rec.statement_level then
335 fa_debug_pkg.add(l_calling_fn, 'Job status - Unassigned: ', l_unassigned_cnt, p_log_level_rec => g_log_level_rec);
336 fa_debug_pkg.add(l_calling_fn, 'Job status - In Process: ', l_wip_cnt, p_log_level_rec => g_log_level_rec);
337 fa_debug_pkg.add(l_calling_fn, 'Job status - Completed: ', l_completed_cnt, p_log_level_rec => g_log_level_rec);
338 fa_debug_pkg.add(l_calling_fn, 'Job status - Failed: ', l_failed_cnt, p_log_level_rec => g_log_level_rec);
339 fa_debug_pkg.add(l_calling_fn, 'Job status - Total: ', l_total_cnt, p_log_level_rec => g_log_level_rec);
340 end if;
341
342 IF (l_failed_cnt > 0) THEN
343 if g_log_level_rec.statement_level then
344 fa_debug_pkg.add(l_calling_fn, 'Another worker has errored out: ', 'Stop processing', p_log_level_rec => g_log_level_rec);
345 end if;
346 raise error_found; -- probably not
347 ELSIF (l_unassigned_cnt = 0) THEN
348 if g_log_level_rec.statement_level then
349 fa_debug_pkg.add(l_calling_fn, 'No more jobs left', 'Terminating.', p_log_level_rec => g_log_level_rec);
350 end if;
351 raise done_exc;
352 ELSIF (l_completed_cnt = l_total_cnt) THEN
353 if g_log_level_rec.statement_level then
354 fa_debug_pkg.add(l_calling_fn, 'All jobs completed, no more jobs. ', 'Terminating', p_log_level_rec => g_log_level_rec);
355 end if;
356 raise done_exc;
357 ELSIF (l_unassigned_cnt > 0) THEN
358 UPDATE FA_WORKER_JOBS
359 SET status = 'IN PROCESS',
360 worker_num = p_request_number
361 WHERE status = 'UNASSIGNED'
362 AND request_id = p_parent_request_id
363 AND rownum < 2;
364
365 l_count := sql%rowcount;
366
367 if g_log_level_rec.statement_level then
368 fa_debug_pkg.add(l_calling_fn, 'Taking job from job queue', l_count, p_log_level_rec => g_log_level_rec);
369 end if;
370 x_worker_jobs := l_count;
371 COMMIT;
372 END IF;
373
374 -- -----------------------------------
375 -- There could be rare situations where
376 -- between Section 30 and Section 50
377 -- the unassigned job gets taken by
378 -- another worker. So, if unassigned
379 -- job no longer exist. Do nothing.
380 -- -----------------------------------
381 IF (l_count > 0) THEN
382
383 if g_log_level_rec.statement_level then
384 fa_debug_pkg.add(l_calling_fn, 'entering', 'main logic', p_log_level_rec => g_log_level_rec);
385 end if;
386
387 DECLARE
388 BEGIN
389
390 if g_log_level_rec.statement_level then
391 fa_debug_pkg.add(l_calling_fn, 'selecting', 'ranges', p_log_level_rec => g_log_level_rec);
392 end if;
393
394 SELECT start_range,
395 end_range
396 INTO l_start_range,
397 l_end_range
398 FROM FA_WORKER_JOBS
399 WHERE request_id = p_parent_request_id
400 AND worker_num = p_request_number
401 AND status = 'IN PROCESS';
402
403 if g_log_level_rec.statement_level then
404 fa_debug_pkg.add(l_calling_fn, 'opening cursor', 'dist', p_log_level_rec => g_log_level_rec);
405 end if;
406
407 OPEN dist
408 (p_book_type_code => p_book_type_code,
409 p_dist_source_book => fa_cache_pkg.fazcbc_record.distribution_source_book,
410 p_fy_first_pc => G_fy_first_pc,
411 p_pregen_asset_acct => G_pregen_asset_acct,
412 p_pregen_cat_acct => G_pregen_cat_acct,
413 p_pregen_book_acct => G_pregen_book_acct,
414 p_book_class => h_book_class,
415 p_gl_posting_allowed => h_gl_posting_allowed,
416 p_allow_deprn_adjust => h_allow_deprn_adjust,
417 p_allow_reval_flag => h_allow_reval_flag,
418 p_allow_impairment_flag => h_allow_impairment_flag,
419 p_allow_sorp_flag => h_allow_sorp_flag, -- Bug 6666666
420 p_start_range => l_start_range,
421 p_end_range => l_end_range);
422
423 if g_log_level_rec.statement_level then
424 fa_debug_pkg.add(l_calling_fn, 'fecthing cursor', 'dist', p_log_level_rec => g_log_level_rec);
425 end if;
426
427 FETCH dist bulk collect
428 into l_dist_id,
429 l_asset_number,
430 l_asset_id,
431 l_asset_type,
432 l_asset_category_id,
433 l_dist_ccid,
434 l_bonus_rule,
435 l_group_asset_id,
436 l_tracking_method;
437
438 if g_log_level_rec.statement_level then
439 fa_debug_pkg.add(l_calling_fn, 'closing cursor', 'dist', p_log_level_rec => g_log_level_rec);
440 end if;
441
442 close dist;
443 /*
444 if (l_dist_id.count = 0) then
445 raise done_exc;
446 end if;
447 */
448
449 -- load the category values into the struct
450 if (g_pregen_cat_acct = 'Y' or
451 g_pregen_asset_acct = 'Y') then
452
453 if g_log_level_rec.statement_level then
454 fa_debug_pkg.add(l_calling_fn, 'processing ', 'cat and asset', p_log_level_rec => g_log_level_rec);
455 end if;
456
457 for i in 1..l_dist_id.count loop
458
459 if not (fa_cache_pkg.fazccb(X_book => p_book_type_code,
460 X_cat_id => l_asset_category_id(i),
461 p_log_level_rec => g_log_level_rec)) then
462 raise error_found;
463 end if;
464
465 l_cost_acct(i) := fa_cache_pkg.fazccb_record.asset_cost_acct;
466 l_clearing_acct(i) := fa_cache_pkg.fazccb_record.asset_clearing_acct;
467 l_cost_ccid(i) := fa_cache_pkg.fazccb_record.asset_cost_account_ccid;
468 l_clearing_ccid(i) := fa_cache_pkg.fazccb_record.asset_clearing_account_ccid;
469 l_reserve_acct(i) := fa_cache_pkg.fazccb_record.deprn_reserve_acct;
470 l_reserve_ccid(i) := fa_cache_pkg.fazccb_record.reserve_account_ccid;
471 l_expense_acct(i) := fa_cache_pkg.fazccb_record.deprn_expense_acct;
472 l_cip_cost_acct(i) := fa_cache_pkg.fazccb_record.cip_cost_acct;
473 l_cip_clearing_acct(i) := fa_cache_pkg.fazccb_record.cip_clearing_acct;
474 l_cip_cost_ccid(i) := fa_cache_pkg.fazccb_record.wip_cost_account_ccid;
475 l_cip_clearing_ccid(i) := fa_cache_pkg.fazccb_record.wip_clearing_account_ccid;
476 l_reval_amort_acct(i) := fa_cache_pkg.fazccb_record.reval_amortization_acct;
477 l_reval_amort_ccid(i) := fa_cache_pkg.fazccb_record.reval_amort_account_ccid;
478 l_reval_rsv_acct(i) := fa_cache_pkg.fazccb_record.reval_reserve_acct;
479 l_reval_rsv_ccid(i) := fa_cache_pkg.fazccb_record.reval_reserve_account_ccid;
480 l_bonus_exp_acct(i) := fa_cache_pkg.fazccb_record.bonus_deprn_expense_acct;
481 l_bonus_rsv_acct(i) := fa_cache_pkg.fazccb_record.bonus_deprn_reserve_acct;
482 l_bonus_rsv_ccid(i) := fa_cache_pkg.fazccb_record.bonus_reserve_acct_ccid;
483 l_impair_exp_acct(i) := fa_cache_pkg.fazccb_record.impair_expense_acct;
484 l_impair_exp_ccid(i) := fa_cache_pkg.fazccb_record.impair_expense_account_ccid;
485 l_impair_rsv_acct(i) := fa_cache_pkg.fazccb_record.impair_reserve_acct;
486 l_impair_rsv_ccid(i) := fa_cache_pkg.fazccb_record.impair_reserve_account_ccid;
487 -- Bug 6666666 : Start of SORP Code
488 l_capital_adj_acct(i) := fa_cache_pkg.fazccb_record.capital_adj_acct;
489 l_capital_adj_ccid(i) := fa_cache_pkg.fazccb_record.capital_adj_account_ccid;
490 l_general_fund_acct(i) := fa_cache_pkg.fazccb_record.general_fund_acct;
491 l_general_fund_ccid(i) := fa_cache_pkg.fazccb_record.general_fund_account_ccid;
492 -- Bug 6666666 : End of SORP Code
493 l_reval_loss_acct(i) := fa_cache_pkg.fazccb_record.reval_loss_acct;
494 l_reval_loss_ccid(i) := fa_cache_pkg.fazccb_record.reval_loss_account_ccid;
495 end loop;
496
497 else
498
499 if g_log_level_rec.statement_level then
500 fa_debug_pkg.add(l_calling_fn, 'skipping ', 'cat and asset', p_log_level_rec => g_log_level_rec);
501 end if;
502
503 -- BUG# 3280298
504 -- need to load the table values here with null if we're not
505 -- generating the category accounts to avoid 1403
506
507 for i in 1..l_dist_id.count loop
508
509 l_cost_acct(i) := null;
510 l_clearing_acct(i) := null;
511 l_cost_ccid(i) := null;
512 l_clearing_ccid(i) := null;
513 l_reserve_acct(i) := null;
514 l_reserve_ccid(i) := null;
515 l_expense_acct(i) := null;
516 l_cip_cost_acct(i) := null;
517 l_cip_clearing_acct(i) := null;
518 l_cip_cost_ccid(i) := null;
519 l_cip_clearing_ccid(i) := null;
520 l_reval_amort_acct(i) := null;
521 l_reval_amort_ccid(i) := null;
522 l_reval_rsv_acct(i) := null;
523 l_reval_rsv_ccid(i) := null;
524 l_bonus_exp_acct(i) := null;
525 l_bonus_rsv_acct(i) := null;
526 l_bonus_rsv_ccid(i) := null;
527 l_impair_exp_acct(i) := null;
528 l_impair_exp_ccid(i) := null;
529 l_impair_rsv_acct(i) := null;
530 l_impair_rsv_ccid(i) := null;
531 -- Bug 6666666 : Start of SORP Code
532 l_capital_adj_acct(i) := null;
533 l_capital_adj_ccid(i) := null;
534 l_general_fund_acct(i) := null;
535 l_general_fund_ccid(i) := null;
536 -- Bug 6666666 : End of SORP Code
537 l_reval_loss_acct(i) := null;
538 l_reval_loss_ccid(i) := null;
539
540 end loop;
541 end if;
542
543 if g_log_level_rec.statement_level then
544 fa_debug_pkg.add(l_calling_fn, 'looping and calling', 'GEN_CCID', p_log_level_rec => g_log_level_rec);
545 end if;
546
547 for i in 1..l_dist_id.count loop
548
549 -- clear the debug stack for each line
550 -- FA_DEBUG_PKG.Initialize;
551 -- reset the message level to prevent bogus errors
552 FA_SRVR_MSG.Set_Message_Level(message_level => 10, p_log_level_rec => g_log_level_rec);
553
554 GEN_CCID(
555 X_book_type_code => p_book_type_code,
556 X_flex_num => h_flex_num,
557 X_default_ccid => h_default_ccid,
558 X_book_class => h_book_class,
559 X_nbv_gain_acct => h_nbv_gain_acct,
560 X_nbv_loss_acct => h_nbv_loss_acct,
561 X_pos_gain_acct => h_pos_gain_acct,
562 X_pos_loss_acct => h_pos_loss_acct,
563 X_cor_gain_acct => h_cor_gain_acct,
564 X_cor_loss_acct => h_cor_loss_acct,
565 X_cor_clearing_acct => h_cor_clearing_acct,
566 X_pos_clearing_acct => h_pos_clearing_acct,
567 X_reval_rsv_gain_acct => h_reval_rsv_gain_acct,
568 X_reval_rsv_loss_acct => h_reval_rsv_loss_acct,
569 X_deferred_exp_acct => h_deferred_exp_acct,
570 X_deferred_rsv_acct => h_deferred_rsv_acct,
571 X_deprn_adj_acct => h_deprn_adj_acct,
572 X_allow_reval_flag => h_allow_reval_flag,
573 X_allow_deprn_adjust => h_allow_deprn_adjust,
574 X_allow_impairment_flag => h_allow_impairment_flag,
575 X_allow_sorp_flag => h_allow_sorp_flag, -- Bug 6666666
576 X_gl_posting_allowed => h_gl_posting_allowed,
577 X_asset_number => l_asset_number(i),
578 X_asset_id => l_asset_id(i),
579 X_dist_ccid => l_dist_ccid(i),
580 X_reserve_acct => l_reserve_acct(i),
581 X_cost_acct => l_cost_acct(i),
582 X_clearing_acct => l_clearing_acct(i),
583 X_expense_acct => l_expense_acct(i),
584 X_cip_cost_acct => l_cip_cost_acct(i),
585 X_cip_clearing_acct => l_cip_clearing_acct(i),
586 X_cost_ccid => l_cost_ccid(i),
587 X_clearing_ccid => l_clearing_ccid(i),
588 X_reserve_ccid => l_reserve_ccid(i),
589 X_distribution_id => l_dist_id(i),
590 X_cip_cost_ccid => l_cip_cost_ccid(i),
591 X_cip_clearing_ccid => l_cip_clearing_ccid(i),
592 X_asset_type => l_asset_type(i),
593 X_reval_amort_acct => l_reval_amort_acct(i),
594 X_reval_amort_ccid => l_reval_amort_ccid(i),
595 X_reval_rsv_acct => l_reval_rsv_acct(i),
596 X_reval_rsv_ccid => l_reval_rsv_ccid(i),
597 X_bonus_exp_acct => l_bonus_exp_acct(i),
598 X_bonus_rsv_acct => l_bonus_rsv_acct(i),
599 X_bonus_rsv_ccid => l_bonus_rsv_ccid(i),
600 X_bonus_rule => l_bonus_rule(i), -- BUG# 1791317
601 X_impair_exp_acct => l_impair_exp_acct(i),
602 X_impair_exp_ccid => l_impair_exp_ccid(i),
603 X_impair_rsv_acct => l_impair_rsv_acct(i),
604 X_impair_rsv_ccid => l_impair_rsv_ccid(i),
605 X_group_asset_id => l_group_asset_id(i),
606 X_capital_adj_acct => l_capital_adj_acct(i), -- Bug 6666666
607 X_capital_adj_ccid => l_capital_adj_ccid(i), -- Bug 6666666
608 X_general_fund_acct => l_general_fund_acct(i), -- Bug 6666666
609 X_general_fund_ccid => l_general_fund_ccid(i), -- Bug 6666666
610 X_reval_loss_acct => l_reval_loss_acct(i),
611 X_reval_loss_ccid => l_reval_loss_ccid(i),
612 X_tracking_method => l_tracking_method(i));
613
614 END LOOP; -- bulk update loop
615
616 if g_log_level_rec.statement_level then
617 fa_debug_pkg.add(l_calling_fn, 'updating', 'worker jobs', p_log_level_rec => g_log_level_rec);
618 end if;
619
620 UPDATE FA_WORKER_JOBS
621 SET status = 'COMPLETED'
622 WHERE request_id = p_parent_request_id
623 AND worker_num = p_request_number
624 AND status = 'IN PROCESS';
625
626 COMMIT;
627
628 -- Handle any exception that occured during
629 -- your child process
630
631 EXCEPTION
632 WHEN OTHERS THEN
633
634 FA_SRVR_MSG.ADD_SQL_ERROR(
635 CALLING_FN => 'FA_GENACCTS_PKG.gen_accts', p_log_level_rec => g_log_level_rec);
636
637 UPDATE FA_WORKER_JOBS
638 SET status = 'FAILED'
639 WHERE request_id = p_parent_request_id
640 AND worker_num = p_request_number
641 AND status = 'IN PROCESS';
642
643 COMMIT;
644 Raise error_found;
645
646 END; -- block
647
648 END IF; /* IF (l_count> 0) */
649
650
651 -- using these as dummys - leave as zero when we've done nothing
652 x_success_count := G_success_count;
653 x_failure_count := G_failure_count;
654
655 if (g_log_level_rec.statement_level) then
656 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
657 end if;
658
659 x_return_status := 0;
660
661 EXCEPTION
662 WHEN done_exc then
663 x_success_count := G_success_count;
664 x_failure_count := G_failure_count;
665
666 if (g_log_level_rec.statement_level) then
667 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
668 end if;
669
670 x_return_status := 0;
671
672 WHEN error_found then
673 x_success_count := G_success_count;
674 x_failure_count := G_failure_count;
675 fa_srvr_msg.add_message(calling_fn => 'fa_genaccts_pkg.gen_accts', p_log_level_rec => g_log_level_rec);
676 if (g_log_level_rec.statement_level) then
677 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
678 end if;
679 x_return_status := 2;
680
681 WHEN OTHERS THEN
682 x_success_count := G_success_count;
683 x_failure_count := G_failure_count;
684 FA_SRVR_MSG.ADD_SQL_ERROR(
685 CALLING_FN => 'FA_GENACCTS_PKG.gen_accts', p_log_level_rec => g_log_level_rec);
686 if (g_log_level_rec.statement_level) then
687 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
688 end if;
689 x_return_status := 2;
690
691 END GEN_ACCTS;
692
693 -----------------------------------------------------------------------
694
695 PROCEDURE GEN_CCID (
696 X_book_type_code in varchar2,
697 X_flex_num in number,
698 X_dist_ccid in number,
699 X_asset_number in varchar2,
700 X_asset_id in number,
701 X_reserve_acct in varchar2,
702 X_cost_acct in varchar2,
703 X_clearing_acct in varchar2,
704 X_expense_acct in varchar2,
705 X_cip_cost_acct in varchar2,
706 X_cip_clearing_acct in varchar2,
707 X_default_ccid in number,
708 X_cost_ccid in number,
709 X_clearing_ccid in number,
710 X_reserve_ccid in number,
711 X_distribution_id in number,
712 X_cip_cost_ccid in number,
713 X_cip_clearing_ccid in number,
714 X_asset_type in varchar2,
715 X_book_class in varchar2,
716 X_nbv_gain_acct in varchar2,
717 X_nbv_loss_acct in varchar2,
718 X_pos_gain_acct in varchar2,
719 X_pos_loss_acct in varchar2,
720 X_cor_gain_acct in varchar2,
721 X_cor_loss_acct in varchar2,
722 X_cor_clearing_acct in varchar2,
723 X_pos_clearing_acct in varchar2,
724 X_reval_rsv_gain_acct in varchar2,
725 X_reval_rsv_loss_acct in varchar2,
726 X_deferred_exp_acct in varchar2,
727 X_deferred_rsv_acct in varchar2,
728 X_deprn_adj_acct in varchar2,
729 X_reval_amort_acct in varchar2,
730 X_reval_amort_ccid in number,
731 X_reval_rsv_acct in varchar2,
732 X_reval_rsv_ccid in number,
733 X_bonus_exp_acct in varchar2,
734 X_bonus_rsv_acct in varchar2,
735 X_bonus_rsv_ccid in number,
736 X_allow_reval_flag in varchar2,
737 X_allow_deprn_adjust in varchar2,
738 X_allow_impairment_flag in varchar2,
739 X_allow_sorp_flag in varchar2, -- Bug 6666666
740 X_gl_posting_allowed in varchar2,
741 X_bonus_rule in varchar2,
742 X_impair_exp_acct in varchar2,
743 X_impair_exp_ccid in number,
744 X_impair_rsv_acct in varchar2,
745 X_impair_rsv_ccid in number,
746 X_capital_adj_acct in varchar2, -- Bug 6666666
747 X_capital_adj_ccid in number, -- Bug 6666666
748 X_general_fund_acct in varchar2, -- Bug 6666666
749 X_general_fund_ccid in number, -- Bug 6666666
750 X_reval_loss_acct in varchar2,
751 X_reval_loss_ccid in number,
752 X_group_asset_id in number,
753 X_tracking_method in varchar2) IS
754
755 result boolean;
756 h_count number;
757 h_return_ccid number;
758 h_acct_ccid number;
759 h_acct_seg varchar2(30);
760 h_flex_account_type varchar2(30);
761
762 h_cost_acct_ccid number := NULL;
763 h_clearing_acct_ccid number := NULL;
764 h_reserve_acct_ccid number := NULL;
765 h_expense_acct_ccid number := NULL;
766 h_cip_cost_ccid number := NULL;
767 h_cip_clearing_ccid number := NULL;
768 h_nbv_gain_ccid number := NULL;
769 h_nbv_loss_ccid number := NULL;
770 h_pos_gain_ccid number := NULL;
771 h_pos_loss_ccid number := NULL;
772 h_cor_gain_ccid number := NULL;
773 h_cor_loss_ccid number := NULL;
774 h_cor_clearing_ccid number := NULL;
775 h_pos_clearing_ccid number := NULL;
776
777 h_deferred_exp_ccid number := NULL;
778 h_deferred_rsv_ccid number := NULL;
779 h_reval_rsv_loss_ccid number := NULL;
780 h_reval_rsv_gain_ccid number := NULL;
781 h_deprn_adj_ccid number := NULL;
782 h_reval_rsv_ccid number := NULL;
783 h_reval_amort_ccid number := NULL;
784 h_bonus_exp_ccid number := NULL;
785 h_bonus_rsv_ccid number := NULL;
786 h_impair_exp_ccid number := NULL;
787 h_impair_rsv_ccid number := NULL;
788 h_capital_adj_ccid number := NULL; -- Bug 6666666
789 h_general_fund_ccid number := NULL; -- Bug 6666666
790 h_reval_loss_ccid number := NULL;
791
792 found boolean := FALSE;
793
794 h_user_id number;
795 h_login_id number;
796
797 CURSOR get_ccids IS
798 SELECT ASSET_COST_ACCOUNT_CCID,
799 ASSET_CLEARING_ACCOUNT_CCID,
800 DEPRN_EXPENSE_ACCOUNT_CCID,
801 DEPRN_RESERVE_ACCOUNT_CCID,
802 CIP_COST_ACCOUNT_CCID,
803 CIP_CLEARING_ACCOUNT_CCID,
804 NBV_RETIRED_GAIN_CCID,
805 NBV_RETIRED_LOSS_CCID,
806 PROCEEDS_SALE_GAIN_CCID,
807 PROCEEDS_SALE_LOSS_CCID,
808 COST_REMOVAL_GAIN_CCID,
809 COST_REMOVAL_LOSS_CCID,
810 PROCEEDS_SALE_CLEARING_CCID,
811 COST_REMOVAL_CLEARING_CCID,
812 reval_rsv_gain_account_ccid,
813 reval_rsv_loss_account_ccid,
814 deferred_exp_account_ccid,
815 deferred_rsv_account_ccid,
816 deprn_adj_account_ccid,
817 reval_amort_account_ccid,
818 reval_rsv_account_ccid,
819 bonus_exp_account_ccid,
820 bonus_rsv_account_ccid,
821 impair_expense_account_ccid,
822 impair_reserve_account_ccid,
823 capital_adj_account_ccid, -- Bug 6666666
824 general_fund_account_ccid, -- Bug 6666666
825 reval_loss_account_ccid
826 FROM FA_DISTRIBUTION_ACCOUNTS
827 WHERE BOOK_TYPE_CODE = X_book_type_code
828 AND DISTRIBUTION_ID = X_distribution_id;
829
830 BEGIN
831
832 FA_SRVR_MSG.ADD_MESSAGE
833 (CALLING_FN => NULL,
834 NAME => 'FA_FAGDA_DISTRIBUTION_ID',
835 TOKEN1 => 'DISTRIBUTION_ID',
836 VALUE1 => X_distribution_id, p_log_level_rec => g_log_level_rec);
837
838 open get_ccids;
839 fetch get_ccids
840 into h_cost_acct_ccid,
841 h_clearing_acct_ccid,
842 h_expense_acct_ccid,
843 h_reserve_acct_ccid,
844 h_cip_cost_ccid,
845 h_cip_clearing_ccid,
846 h_nbv_gain_ccid,
847 h_nbv_loss_ccid,
848 h_pos_gain_ccid,
849 h_pos_loss_ccid,
850 h_cor_gain_ccid,
851 h_cor_loss_ccid,
852 h_pos_clearing_ccid,
853 h_cor_clearing_ccid,
854 h_reval_rsv_loss_ccid,
855 h_reval_rsv_gain_ccid,
856 h_deferred_exp_ccid,
857 h_deferred_rsv_ccid,
858 h_deprn_adj_ccid,
859 h_reval_amort_ccid,
860 h_reval_rsv_ccid,
861 h_bonus_exp_ccid,
862 h_bonus_rsv_ccid,
863 h_impair_exp_ccid,
864 h_impair_rsv_ccid,
865 h_capital_adj_ccid,
866 h_general_fund_ccid,
867 h_reval_loss_ccid;
868
869 if (get_ccids%NOTFOUND) then
870 found := FALSE;
871 else
872 found := TRUE;
873 end if;
874
875 if (G_pregen_asset_acct = 'Y') then
876 if (((found and h_expense_acct_ccid is null) OR (not found)) AND
877 ((X_group_asset_id is null) or
878 (X_group_asset_id is not null and
879 X_tracking_method is not null))) then
880 /* Generate DEPRN_EXPENSE_ACCT */
881 if (G_gen_expense = 'Y') then
882 h_acct_seg := X_expense_acct;
883 h_acct_ccid := X_dist_ccid;
884 h_flex_account_type := 'DEPRN_EXP';
885 result := FAFLEX_PKG_WF.START_PROCESS(
886 X_flex_account_type => h_flex_account_type,
887 X_book_type_code => X_book_type_code,
888 X_flex_num => X_flex_num,
889 X_dist_ccid => X_dist_ccid,
890 X_acct_segval => h_acct_seg,
891 X_default_ccid => X_default_ccid,
892 X_account_ccid => h_acct_ccid,
893 X_distribution_id => X_distribution_id,
894 X_validation_date => G_validation_date,
895 X_return_ccid => h_return_ccid,
896 p_log_level_rec => g_log_level_rec);
897 if (result) then
898 h_expense_acct_ccid := h_return_ccid;
899 G_success_count := G_success_count + 1;
900 else
901 Add_Messages(
902 X_asset_number,
903 X_asset_id,
904 h_acct_ccid,
905 h_acct_seg,
906 h_flex_account_type,
907 X_book_type_code,
908 X_default_ccid,
909 X_dist_ccid);
910 end if;
911 else
912 h_expense_acct_ccid := X_dist_ccid;
913 end if;
914 end if;
915 end if;
916
917 if (G_pregen_cat_acct = 'Y') then
918 if (X_asset_type <> 'GROUP') then -- only prevents cost and clearing
919 if ((found and h_cost_acct_ccid is null) OR (not found)) then
920 /* Generate COST Account */
921 h_acct_seg := X_cost_acct;
922 h_acct_ccid := X_cost_ccid;
923 h_flex_account_type := 'ASSET_COST';
924 result := FAFLEX_PKG_WF.START_PROCESS(
925 X_flex_account_type => h_flex_account_type,
926 X_book_type_code => X_book_type_code,
927 X_flex_num => X_flex_num,
928 X_dist_ccid => X_dist_ccid,
929 X_acct_segval => h_acct_seg,
930 X_default_ccid => X_default_ccid,
931 X_account_ccid => h_acct_ccid,
932 X_distribution_id => X_distribution_id,
933 X_validation_date => G_validation_date,
934 X_return_ccid => h_return_ccid,
935 p_log_level_rec => g_log_level_rec);
936 if (result) then
937 G_success_count := G_success_count + 1;
938 h_cost_acct_ccid := h_return_ccid;
939 else
940 Add_Messages(
941 X_asset_number,
942 X_asset_id,
943 h_acct_ccid,
944 h_acct_seg,
945 h_flex_account_type,
946 X_book_type_code,
947 X_default_ccid,
948 X_dist_ccid);
949 end if;
950 end if;
951
952 if ((found and h_clearing_acct_ccid is null) OR (not found)) then
953 /* Generate Cost Clearing account */
954 h_acct_seg := X_clearing_acct;
955 h_acct_ccid := X_clearing_ccid;
956 h_flex_account_type := 'ASSET_CLEARING';
957 result := FAFLEX_PKG_WF.START_PROCESS(
958 X_flex_account_type => h_flex_account_type,
959 X_book_type_code => X_book_type_code,
960 X_flex_num => X_flex_num,
961 X_dist_ccid => X_dist_ccid,
962 X_acct_segval => h_acct_seg,
963 X_default_ccid => X_default_ccid,
964 X_account_ccid => h_acct_ccid,
965 X_distribution_id => X_distribution_id,
966 X_validation_date => G_validation_date,
967 X_return_ccid => h_return_ccid,
968 p_log_level_rec => g_log_level_rec);
969 if (result) then
970 G_success_count := G_success_count + 1;
971 h_clearing_acct_ccid := h_return_ccid;
972 else
973 Add_Messages(
974 X_asset_number,
975 X_asset_id,
976 h_acct_ccid,
977 h_acct_seg,
978 h_flex_account_type,
979 X_book_type_code,
980 X_default_ccid,
981 X_dist_ccid);
982 end if;
983 end if;
984 end if; -- group
985
986 if ((found and h_reserve_acct_ccid is null) OR (not found)) then
987 /* Generate DEPRN_RESERVE_ACCT */
988 h_acct_seg := X_reserve_acct;
989 h_acct_ccid := X_reserve_ccid;
990 h_flex_account_type := 'DEPRN_RSV';
991 result := FAFLEX_PKG_WF.START_PROCESS(
992 X_flex_account_type => h_flex_account_type,
993 X_book_type_code => X_book_type_code,
994 X_flex_num => X_flex_num,
995 X_dist_ccid => X_dist_ccid,
996 X_acct_segval => h_acct_seg,
997 X_default_ccid => X_default_ccid,
998 X_account_ccid => h_acct_ccid,
999 X_distribution_id => X_distribution_id,
1000 X_validation_date => G_validation_date,
1001 X_return_ccid => h_return_ccid,
1002 p_log_level_rec => g_log_level_rec);
1003 if (result) then
1004 G_success_count := G_success_count + 1;
1005 h_reserve_acct_ccid := h_return_ccid;
1006 else
1007 Add_Messages(
1008 X_asset_number,
1009 X_asset_id,
1010 h_acct_ccid,
1011 h_acct_seg,
1012 h_flex_account_type,
1013 X_book_type_code,
1014 X_default_ccid,
1015 X_dist_ccid);
1016 end if;
1017 end if;
1018
1019 if (X_asset_type = 'CIP') then
1020
1021 if ((found and h_cip_cost_ccid is null) OR (not found)) then
1022 /* Generate CIP COST account */
1023 h_acct_seg := X_cip_cost_acct;
1024 h_acct_ccid := X_cip_cost_ccid;
1025 h_flex_account_type := 'CIP_COST';
1026 result := FAFLEX_PKG_WF.START_PROCESS(
1027 X_flex_account_type => h_flex_account_type,
1028 X_book_type_code => X_book_type_code,
1029 X_flex_num => X_flex_num,
1030 X_dist_ccid => X_dist_ccid,
1031 X_acct_segval => h_acct_seg,
1032 X_default_ccid => X_default_ccid,
1033 X_account_ccid => h_acct_ccid,
1034 X_distribution_id => X_distribution_id,
1035 X_validation_date => G_validation_date,
1036 X_return_ccid => h_return_ccid,
1037 p_log_level_rec => g_log_level_rec);
1038 if (result) then
1039 G_success_count := G_success_count + 1;
1040 h_cip_cost_ccid := h_return_ccid;
1041 else
1042 Add_Messages(
1043 X_asset_number,
1044 X_asset_id,
1045 h_acct_ccid,
1046 h_acct_seg,
1047 h_flex_account_type,
1048 X_book_type_code,
1049 X_default_ccid,
1050 X_dist_ccid);
1051 end if;
1052 end if;
1053
1054 if ((found and h_cip_clearing_ccid is null) OR (not found)) then
1055 /* Generate CIP CLEARING account */
1056 h_acct_seg := X_cip_clearing_acct;
1057 h_acct_ccid := X_cip_clearing_ccid;
1058 h_flex_account_type := 'CIP_CLEARING';
1059 result := FAFLEX_PKG_WF.START_PROCESS(
1060 X_flex_account_type => h_flex_account_type,
1061 X_book_type_code => X_book_type_code,
1062 X_flex_num => X_flex_num,
1063 X_dist_ccid => X_dist_ccid,
1064 X_acct_segval => h_acct_seg,
1065 X_default_ccid => X_default_ccid,
1066 X_account_ccid => h_acct_ccid,
1067 X_distribution_id => X_distribution_id,
1068 X_validation_date => G_validation_date,
1069 X_return_ccid => h_return_ccid,
1070 p_log_level_rec => g_log_level_rec);
1071 if (result) then
1072 G_success_count := G_success_count + 1;
1073 h_cip_clearing_ccid := h_return_ccid;
1074 else
1075 Add_Messages(
1076 X_asset_number,
1077 X_asset_id,
1078 h_acct_ccid,
1079 h_acct_seg,
1080 h_flex_account_type,
1081 X_book_type_code,
1082 X_default_ccid,
1083 X_dist_ccid);
1084 end if;
1085 end if;
1086 end if; -- asset_type CIP
1087
1088 /* BUG# 1553682 */
1089 if (X_allow_reval_flag = 'YES' and
1090 X_asset_type <> 'GROUP' AND
1091 X_group_asset_id is null) then
1092
1093 if ((found and h_reval_amort_ccid is null) OR (not found)) then
1094 /* Generate REVAL AMORT account */
1095 h_acct_seg := X_reval_amort_acct;
1096 h_acct_ccid := X_reval_amort_ccid;
1097 h_flex_account_type := 'REV_AMORT';
1098 result := FAFLEX_PKG_WF.START_PROCESS(
1099 X_flex_account_type => h_flex_account_type,
1100 X_book_type_code => X_book_type_code,
1101 X_flex_num => X_flex_num,
1102 X_dist_ccid => X_dist_ccid,
1103 X_acct_segval => h_acct_seg,
1104 X_default_ccid => X_default_ccid,
1105 X_account_ccid => h_acct_ccid,
1106 X_distribution_id => X_distribution_id,
1107 X_validation_date => G_validation_date,
1108 X_return_ccid => h_return_ccid,
1109 p_log_level_rec => g_log_level_rec);
1110 if (result) then
1111 G_success_count := G_success_count + 1;
1112 h_reval_amort_ccid := h_return_ccid;
1113 else
1114 Add_Messages(
1115 X_asset_number,
1116 X_asset_id,
1117 h_acct_ccid,
1118 h_acct_seg,
1119 h_flex_account_type,
1120 X_book_type_code,
1121 X_default_ccid,
1122 X_dist_ccid);
1123 end if;
1124 end if;
1125
1126
1127 if ((found and h_reval_rsv_ccid is null) OR (not found)) then
1128 /* Generate REVAL RESERVE account */
1129 h_acct_seg := X_reval_rsv_acct;
1130 h_acct_ccid := X_reval_rsv_ccid;
1131 h_flex_account_type := 'REV_RSV';
1132 result := FAFLEX_PKG_WF.START_PROCESS(
1133 X_flex_account_type => h_flex_account_type,
1134 X_book_type_code => X_book_type_code,
1135 X_flex_num => X_flex_num,
1136 X_dist_ccid => X_dist_ccid,
1137 X_acct_segval => h_acct_seg,
1138 X_default_ccid => X_default_ccid,
1139 X_account_ccid => h_acct_ccid,
1140 X_distribution_id => X_distribution_id,
1141 X_validation_date => G_validation_date,
1142 X_return_ccid => h_return_ccid,
1143 p_log_level_rec => g_log_level_rec);
1144 if (result) then
1145 G_success_count := G_success_count + 1;
1146 h_reval_rsv_ccid := h_return_ccid;
1147 else
1148 Add_Messages(
1149 X_asset_number,
1150 X_asset_id,
1151 h_acct_ccid,
1152 h_acct_seg,
1153 h_flex_account_type,
1154 X_book_type_code,
1155 X_default_ccid,
1156 X_dist_ccid);
1157 end if;
1158 end if;
1159 end if; -- reval allowed flag
1160
1161
1162 if (X_bonus_rule is not null) then -- BUG# 1791317
1163
1164 if ((found and h_bonus_exp_ccid is null) OR (not found)) then
1165 /* Generate BONUS EXPENSE account */
1166 h_acct_seg := X_bonus_exp_acct;
1167 h_acct_ccid := 0; /* BONUS EXPENSE */
1168 h_flex_account_type := 'BONUS_DEPRN_EXP';
1169 result := FAFLEX_PKG_WF.START_PROCESS(
1170 X_flex_account_type => h_flex_account_type,
1171 X_book_type_code => X_book_type_code,
1172 X_flex_num => X_flex_num,
1173 X_dist_ccid => X_dist_ccid,
1174 X_acct_segval => h_acct_seg,
1175 X_default_ccid => X_default_ccid,
1176 X_account_ccid => h_acct_ccid,
1177 X_distribution_id => X_distribution_id,
1178 X_validation_date => G_validation_date,
1179 X_return_ccid => h_return_ccid,
1180 p_log_level_rec => g_log_level_rec);
1181 if (result) then
1182 G_success_count := G_success_count + 1;
1183 h_bonus_exp_ccid := h_return_ccid;
1184 else
1185 Add_Messages(
1186 X_asset_number,
1187 X_asset_id,
1188 h_acct_ccid,
1189 h_acct_seg,
1190 h_flex_account_type,
1191 X_book_type_code,
1192 X_default_ccid,
1193 X_dist_ccid);
1194 end if;
1195 end if;
1196
1197
1198 if ((found and h_bonus_rsv_ccid is null) OR (not found)) then
1199 /* Generate BONUS RESERVE account */
1200 h_acct_seg := X_bonus_rsv_acct;
1201 h_acct_ccid := X_bonus_rsv_ccid;
1202 h_flex_account_type := 'BONUS_DEPRN_RSV';
1203 result := FAFLEX_PKG_WF.START_PROCESS(
1204 X_flex_account_type => h_flex_account_type,
1205 X_book_type_code => X_book_type_code,
1206 X_flex_num => X_flex_num,
1207 X_dist_ccid => X_dist_ccid,
1208 X_acct_segval => h_acct_seg,
1209 X_default_ccid => X_default_ccid,
1210 X_account_ccid => h_acct_ccid,
1211 X_distribution_id => X_distribution_id,
1212 X_validation_date => G_validation_date,
1213 X_return_ccid => h_return_ccid,
1214 p_log_level_rec => g_log_level_rec);
1215 if (result) then
1216 G_success_count := G_success_count + 1;
1217 h_bonus_rsv_ccid := h_return_ccid;
1218 else
1219 Add_Messages(
1220 X_asset_number,
1221 X_asset_id,
1222 h_acct_ccid,
1223 h_acct_seg,
1224 h_flex_account_type,
1225 X_book_type_code,
1226 X_default_ccid,
1227 X_dist_ccid);
1228 end if;
1229 end if;
1230 end if; -- end bonus_rule not null
1231
1232 -- bugfix 5080401, applied if condition to avoid generating impairment expense and
1233 -- impairment reserve accounts if they are not defined in category books
1234 if (X_allow_impairment_flag = 'Y') then
1235 if (X_impair_exp_acct is not null) and (X_impair_rsv_ccid is not null) then
1236 if ((found and h_impair_exp_ccid is null) OR (not found)) then
1237 /* Generate IMPAIR EXP account */
1238 h_acct_seg := X_impair_exp_acct;
1239 h_acct_ccid := X_impair_exp_ccid;
1240 h_flex_account_type := 'IMPAIR_EXP';
1241 result := FAFLEX_PKG_WF.START_PROCESS(
1242 X_flex_account_type => h_flex_account_type,
1243 X_book_type_code => X_book_type_code,
1244 X_flex_num => X_flex_num,
1245 X_dist_ccid => X_dist_ccid,
1246 X_acct_segval => h_acct_seg,
1247 X_default_ccid => X_default_ccid,
1248 X_account_ccid => h_acct_ccid,
1249 X_distribution_id => X_distribution_id,
1250 X_validation_date => G_validation_date,
1251 X_return_ccid => h_return_ccid,
1252 p_log_level_rec => g_log_level_rec);
1253 if (result) then
1254 G_success_count := G_success_count + 1;
1255 h_impair_exp_ccid := h_return_ccid;
1256 else
1257 Add_Messages(
1258 X_asset_number,
1259 X_asset_id,
1260 h_acct_ccid,
1261 h_acct_seg,
1262 h_flex_account_type,
1263 X_book_type_code,
1264 X_default_ccid,
1265 X_dist_ccid);
1266 end if;
1267 end if;
1268
1269 if ((found and h_impair_rsv_ccid is null) OR (not found)) then
1270 /* Generate IMPAIR RESERVE account */
1271 h_acct_seg := X_impair_rsv_acct;
1272 h_acct_ccid := X_impair_rsv_ccid;
1273 h_flex_account_type := 'IMPAIR_RSV';
1274 result := FAFLEX_PKG_WF.START_PROCESS(
1275 X_flex_account_type => h_flex_account_type,
1276 X_book_type_code => X_book_type_code,
1277 X_flex_num => X_flex_num,
1278 X_dist_ccid => X_dist_ccid,
1279 X_acct_segval => h_acct_seg,
1280 X_default_ccid => X_default_ccid,
1281 X_account_ccid => h_acct_ccid,
1282 X_distribution_id => X_distribution_id,
1283 X_validation_date => G_validation_date,
1284 X_return_ccid => h_return_ccid,
1285 p_log_level_rec => g_log_level_rec);
1286 if (result) then
1287 G_success_count := G_success_count + 1;
1288 h_impair_rsv_ccid := h_return_ccid;
1289 else
1290 Add_Messages(
1291 X_asset_number,
1292 X_asset_id,
1293 h_acct_ccid,
1294 h_acct_seg,
1295 h_flex_account_type,
1296 X_book_type_code,
1297 X_default_ccid,
1298 X_dist_ccid);
1299 end if;
1300 end if;
1301 end if; -- impair account not null
1302 end if; -- impair allowed
1303
1304 -- Bug 6666666 : Start of changes for SORP Compliance Project
1305
1306 if (X_allow_sorp_flag = 'Y') then
1307
1308 if ((found and h_capital_adj_ccid is null) OR (not found)) then
1309 /* Generate Capital Adjustment account */
1310 h_acct_seg := X_capital_adj_acct;
1311 h_acct_ccid := X_capital_adj_ccid;
1312 h_flex_account_type := 'CAPITAL_ADJ';
1313 result := FAFLEX_PKG_WF.START_PROCESS(
1314 X_flex_account_type => h_flex_account_type,
1315 X_book_type_code => X_book_type_code,
1316 X_flex_num => X_flex_num,
1317 X_dist_ccid => X_dist_ccid,
1318 X_acct_segval => h_acct_seg,
1319 X_default_ccid => X_default_ccid,
1320 X_account_ccid => h_acct_ccid,
1321 X_distribution_id => X_distribution_id,
1322 X_validation_date => G_validation_date,
1323 X_return_ccid => h_return_ccid,
1324 p_log_level_rec => g_log_level_rec);
1325 if (result) then
1326 G_success_count := G_success_count + 1;
1327 h_capital_adj_ccid := h_return_ccid;
1328 else
1329 Add_Messages(
1330 X_asset_number,
1331 X_asset_id,
1332 h_acct_ccid,
1333 h_acct_seg,
1334 h_flex_account_type,
1335 X_book_type_code,
1336 X_default_ccid,
1337 X_dist_ccid);
1338 end if; -- Result
1339 end if; -- End Found Capital Adjustment
1340
1341 if ((found and h_general_fund_ccid is null) OR (not found)) then
1342 /* Generate General Fund account */
1343 h_acct_seg := X_general_fund_acct;
1344 h_acct_ccid := X_general_fund_ccid;
1345 h_flex_account_type := 'GENERAL_FUND';
1346 result := FAFLEX_PKG_WF.START_PROCESS(
1347 X_flex_account_type => h_flex_account_type,
1348 X_book_type_code => X_book_type_code,
1349 X_flex_num => X_flex_num,
1350 X_dist_ccid => X_dist_ccid,
1351 X_acct_segval => h_acct_seg,
1352 X_default_ccid => X_default_ccid,
1353 X_account_ccid => h_acct_ccid,
1354 X_distribution_id => X_distribution_id,
1355 X_validation_date => G_validation_date,
1356 X_return_ccid => h_return_ccid,
1357 p_log_level_rec => g_log_level_rec);
1358 if (result) then
1359 G_success_count := G_success_count + 1;
1360 h_general_fund_ccid := h_return_ccid;
1361 else
1362 Add_Messages(
1363 X_asset_number,
1364 X_asset_id,
1365 h_acct_ccid,
1366 h_acct_seg,
1367 h_flex_account_type,
1368 X_book_type_code,
1369 X_default_ccid,
1370 X_dist_ccid);
1371 end if; -- Result
1372 end if; -- End Found General Fund
1373
1374 if((found and h_reval_loss_ccid is null) OR (not found)) then
1375 /* Generate Revaluation loss Expense account */
1376 h_acct_seg := X_reval_loss_acct;
1377 h_acct_ccid := X_reval_loss_ccid;
1378 h_flex_account_type := 'REVAL_LOSS';
1379 result := FAFLEX_PKG_WF.START_PROCESS(
1380 X_flex_account_type => h_flex_account_type,
1381 X_book_type_code => X_book_type_code,
1382 X_flex_num => X_flex_num,
1383 X_dist_ccid => X_dist_ccid,
1384 X_acct_segval => h_acct_seg,
1385 X_default_ccid => X_default_ccid,
1386 X_account_ccid => h_acct_ccid,
1387 X_distribution_id => X_distribution_id,
1388 X_validation_date => G_validation_date,
1389 X_return_ccid => h_return_ccid,
1390 p_log_level_rec => g_log_level_rec);
1391 if (result) then
1392 G_success_count := G_success_count + 1;
1393 h_reval_loss_ccid := h_return_ccid;
1394 else
1395 Add_Messages(
1396 X_asset_number,
1397 X_asset_id,
1398 h_acct_ccid,
1399 h_acct_seg,
1400 h_flex_account_type,
1401 X_book_type_code,
1402 X_default_ccid,
1403 X_dist_ccid);
1404 end if; -- Result
1405 end if;--Revluation loss Expense account
1406
1407 end If; -- Allow Sorp Flag
1408
1409 -- Bug 6666666 : End of changes for SORP Compliance Project
1410
1411 end if; -- end category accts
1412
1413 if (G_pregen_book_acct = 'Y' AND
1414 X_asset_type <> 'GROUP') then
1415
1416 if ((found and h_nbv_gain_ccid is null) OR (not found)) then
1417 /* Generate NBV_RETIRED_GAIN_ACCT */
1418 h_acct_seg := X_nbv_gain_acct;
1419 h_acct_ccid := 0;
1420 h_flex_account_type := 'NBV_GAIN';
1421 result := FAFLEX_PKG_WF.START_PROCESS(
1422 X_flex_account_type => h_flex_account_type,
1423 X_book_type_code => X_book_type_code,
1424 X_flex_num => X_flex_num,
1425 X_dist_ccid => X_dist_ccid,
1426 X_acct_segval => h_acct_seg,
1427 X_default_ccid => X_default_ccid,
1428 X_account_ccid => h_acct_ccid,
1429 X_distribution_id => X_distribution_id,
1430 X_validation_date => G_validation_date,
1431 X_return_ccid => h_return_ccid,
1432 p_log_level_rec => g_log_level_rec);
1433 if (result) then
1434 G_success_count := G_success_count + 1;
1435 h_nbv_gain_ccid := h_return_ccid;
1436 else
1437 Add_Messages(
1438 X_asset_number,
1439 X_asset_id,
1440 h_acct_ccid,
1441 h_acct_seg,
1442 h_flex_account_type,
1443 X_book_type_code,
1444 X_default_ccid,
1445 X_dist_ccid);
1446 end if;
1447 end if;
1448
1449 if ((found and h_nbv_loss_ccid is null) OR (not found)) then
1450 /* Generate NBV_RETIRED_LOSS_ACCT */
1451 h_acct_seg := X_nbv_loss_acct;
1452 h_acct_ccid := 0;
1453 h_flex_account_type := 'NBV_LOSS';
1454 result := FAFLEX_PKG_WF.START_PROCESS(
1455 X_flex_account_type => h_flex_account_type,
1456 X_book_type_code => X_book_type_code,
1457 X_flex_num => X_flex_num,
1458 X_dist_ccid => X_dist_ccid,
1459 X_acct_segval => h_acct_seg,
1460 X_default_ccid => X_default_ccid,
1461 X_account_ccid => h_acct_ccid,
1462 X_distribution_id => X_distribution_id,
1463 X_validation_date => G_validation_date,
1464 X_return_ccid => h_return_ccid,
1465 p_log_level_rec => g_log_level_rec);
1466 if (result) then
1467 G_success_count := G_success_count + 1;
1468 h_nbv_loss_ccid := h_return_ccid;
1469 else
1470 Add_Messages(
1471 X_asset_number,
1472 X_asset_id,
1473 h_acct_ccid,
1474 h_acct_seg,
1475 h_flex_account_type,
1476 X_book_type_code,
1477 X_default_ccid,
1478 X_dist_ccid);
1479 end if;
1480 end if;
1481
1482 if ((found and h_pos_gain_ccid is null) OR (not found)) then
1483 /* Generate PROCEEDS_OF_SALE_GAIN_ACCT */
1484 h_acct_seg := X_pos_gain_acct;
1485 h_acct_ccid := 0;
1486 h_flex_account_type := 'POS_GAIN';
1487 result := FAFLEX_PKG_WF.START_PROCESS(
1488 X_flex_account_type => h_flex_account_type,
1489 X_book_type_code => X_book_type_code,
1490 X_flex_num => X_flex_num,
1491 X_dist_ccid => X_dist_ccid,
1492 X_acct_segval => h_acct_seg,
1493 X_default_ccid => X_default_ccid,
1494 X_account_ccid => h_acct_ccid,
1495 X_distribution_id => X_distribution_id,
1496 X_validation_date => G_validation_date,
1497 X_return_ccid => h_return_ccid,
1498 p_log_level_rec => g_log_level_rec);
1499 if (result) then
1500 G_success_count := G_success_count + 1;
1501 h_pos_gain_ccid := h_return_ccid;
1502 else
1503 Add_Messages(
1504 X_asset_number,
1505 X_asset_id,
1506 h_acct_ccid,
1507 h_acct_seg,
1508 h_flex_account_type,
1509 X_book_type_code,
1510 X_default_ccid,
1511 X_dist_ccid);
1512 end if;
1513 end if;
1514
1515 if ((found and h_pos_loss_ccid is null) OR (not found)) then
1516 /* Generate PROCEEDS_OF_SALE_LOSS_ACCT */
1517 h_acct_seg := X_pos_loss_acct;
1518 h_acct_ccid := 0;
1519 h_flex_account_type := 'POS_LOSS';
1520 result := FAFLEX_PKG_WF.START_PROCESS(
1521 X_flex_account_type => h_flex_account_type,
1522 X_book_type_code => X_book_type_code,
1523 X_flex_num => X_flex_num,
1524 X_dist_ccid => X_dist_ccid,
1525 X_acct_segval => h_acct_seg,
1526 X_default_ccid => X_default_ccid,
1527 X_account_ccid => h_acct_ccid,
1528 X_distribution_id => X_distribution_id,
1529 X_validation_date => G_validation_date,
1530 X_return_ccid => h_return_ccid,
1531 p_log_level_rec => g_log_level_rec);
1532 if (result) then
1533 G_success_count := G_success_count + 1;
1534 h_pos_loss_ccid := h_return_ccid;
1535 else
1536 Add_Messages(
1537 X_asset_number,
1538 X_asset_id,
1539 h_acct_ccid,
1540 h_acct_seg,
1541 h_flex_account_type,
1542 X_book_type_code,
1543 X_default_ccid,
1544 X_dist_ccid);
1545 end if;
1546 end if;
1547
1548 if ((found and h_cor_gain_ccid is null) OR (not found)) then
1549 /* Generate COST_OF_REMOVAL_GAIN_ACCT */
1550 h_acct_seg := X_cor_gain_acct;
1551 h_acct_ccid := 0;
1552 h_flex_account_type := 'COR_GAIN';
1553 result := FAFLEX_PKG_WF.START_PROCESS(
1554 X_flex_account_type => h_flex_account_type,
1555 X_book_type_code => X_book_type_code,
1556 X_flex_num => X_flex_num,
1557 X_dist_ccid => X_dist_ccid,
1558 X_acct_segval => h_acct_seg,
1559 X_default_ccid => X_default_ccid,
1560 X_account_ccid => h_acct_ccid,
1561 X_distribution_id => X_distribution_id,
1562 X_validation_date => G_validation_date,
1563 X_return_ccid => h_return_ccid,
1564 p_log_level_rec => g_log_level_rec);
1565 if (result) then
1566 G_success_count := G_success_count + 1;
1567 h_cor_gain_ccid := h_return_ccid;
1568 else
1569 Add_Messages(
1570 X_asset_number,
1571 X_asset_id,
1572 h_acct_ccid,
1573 h_acct_seg,
1574 h_flex_account_type,
1575 X_book_type_code,
1576 X_default_ccid,
1577 X_dist_ccid);
1578 end if;
1579 end if;
1580
1581 if ((found and h_cor_loss_ccid is null) OR (not found)) then
1582 /* Generate COST_OF_REMOVAL_LOSS_ACCT */
1583 h_acct_seg := X_cor_loss_acct;
1584 h_acct_ccid := 0;
1585 h_flex_account_type := 'COR_LOSS';
1586 result := FAFLEX_PKG_WF.START_PROCESS(
1587 X_flex_account_type => h_flex_account_type,
1588 X_book_type_code => X_book_type_code,
1589 X_flex_num => X_flex_num,
1590 X_dist_ccid => X_dist_ccid,
1591 X_acct_segval => h_acct_seg,
1592 X_default_ccid => X_default_ccid,
1593 X_account_ccid => h_acct_ccid,
1594 X_distribution_id => X_distribution_id,
1595 X_validation_date => G_validation_date,
1596 X_return_ccid => h_return_ccid,
1597 p_log_level_rec => g_log_level_rec);
1598 if (result) then
1599 G_success_count := G_success_count + 1;
1600 h_cor_loss_ccid := h_return_ccid;
1601 else
1602 Add_Messages(
1603 X_asset_number,
1604 X_asset_id,
1605 h_acct_ccid,
1606 h_acct_seg,
1607 h_flex_account_type,
1608 X_book_type_code,
1609 X_default_ccid,
1610 X_dist_ccid);
1611 end if;
1612 end if;
1613
1614 if ((found and h_cor_clearing_ccid is null) OR (not found)) then
1615 /* Generate COST_OF_REMOVAL_CLEARING_ACCT */
1616 h_acct_seg := X_cor_clearing_acct;
1617 h_acct_ccid := 0;
1618 h_flex_account_type := 'COR_CLEARING';
1619 result := FAFLEX_PKG_WF.START_PROCESS(
1620 X_flex_account_type => h_flex_account_type,
1621 X_book_type_code => X_book_type_code,
1622 X_flex_num => X_flex_num,
1623 X_dist_ccid => X_dist_ccid,
1624 X_acct_segval => h_acct_seg,
1625 X_default_ccid => X_default_ccid,
1626 X_account_ccid => h_acct_ccid,
1627 X_distribution_id => X_distribution_id,
1628 X_validation_date => G_validation_date,
1629 X_return_ccid => h_return_ccid,
1630 p_log_level_rec => g_log_level_rec);
1631 if (result) then
1632 G_success_count := G_success_count + 1;
1633 h_cor_clearing_ccid := h_return_ccid;
1634 else
1635 Add_Messages(
1636 X_asset_number,
1637 X_asset_id,
1638 h_acct_ccid,
1639 h_acct_seg,
1640 h_flex_account_type,
1641 X_book_type_code,
1642 X_default_ccid,
1643 X_dist_ccid);
1644 end if;
1645 end if;
1646
1647 if ((found and h_pos_clearing_ccid is null) OR (not found)) then
1648 /* Generate PROCEEDS_OF_SALE_CLEARING_ACCT */
1649 h_acct_seg := X_pos_clearing_acct;
1650 h_acct_ccid := 0;
1651 h_flex_account_type := 'POS_CLEARING';
1652 result := FAFLEX_PKG_WF.START_PROCESS(
1653 X_flex_account_type => h_flex_account_type,
1654 X_book_type_code => X_book_type_code,
1655 X_flex_num => X_flex_num,
1656 X_dist_ccid => X_dist_ccid,
1657 X_acct_segval => h_acct_seg,
1658 X_default_ccid => X_default_ccid,
1659 X_account_ccid => h_acct_ccid,
1660 X_distribution_id => X_distribution_id,
1661 X_validation_date => G_validation_date,
1662 X_return_ccid => h_return_ccid,
1663 p_log_level_rec => g_log_level_rec);
1664 if (result) then
1665 G_success_count := G_success_count + 1;
1666 h_pos_clearing_ccid := h_return_ccid;
1667 else
1668 Add_Messages(
1669 X_asset_number,
1670 X_asset_id,
1671 h_acct_ccid,
1672 h_acct_seg,
1673 h_flex_account_type,
1674 X_book_type_code,
1675 X_default_ccid,
1676 X_dist_ccid);
1677 end if;
1678 end if;
1679
1680 /* BUG# 1553682 */
1681
1682 if (X_book_class = 'TAX' and
1683 X_group_asset_id is null) then
1684
1685 if (X_allow_deprn_adjust = 'YES') then
1686
1687 if ((found and h_deprn_adj_ccid is null) OR (not found)) then
1688 /* Generate DEPRN_ADJ */
1689 h_acct_seg := X_deprn_adj_acct;
1690 h_acct_ccid := 0;
1691 h_flex_account_type := 'DEPRN_ADJ';
1692 result := FAFLEX_PKG_WF.START_PROCESS(
1693 X_flex_account_type => h_flex_account_type,
1694 X_book_type_code => X_book_type_code,
1695 X_flex_num => X_flex_num,
1696 X_dist_ccid => X_dist_ccid,
1697 X_acct_segval => h_acct_seg,
1698 X_default_ccid => X_default_ccid,
1699 X_account_ccid => h_acct_ccid,
1700 X_distribution_id => X_distribution_id,
1701 X_validation_date => G_validation_date,
1702 X_return_ccid => h_return_ccid,
1703 p_log_level_rec => g_log_level_rec);
1704 if (result) then
1705 G_success_count := G_success_count + 1;
1706 h_deprn_adj_ccid := h_return_ccid;
1707 else
1708 Add_Messages(
1709 X_asset_number,
1710 X_asset_id,
1711 h_acct_ccid,
1712 h_acct_seg,
1713 h_flex_account_type,
1714 X_book_type_code,
1715 X_default_ccid,
1716 X_dist_ccid);
1717 end if;
1718 end if;
1719 end if; -- allow deprn_adjust flag
1720
1721
1722 if ((found and h_deferred_exp_ccid is null) OR (not found)) then
1723 /* Generate DEFERRED_DEPRN_EXPENSE_ACCT */
1724 h_acct_seg := X_deferred_exp_acct;
1725 h_acct_ccid := 0;
1726 h_flex_account_type := 'DEF_DEPRN_EXP';
1727 result := FAFLEX_PKG_WF.START_PROCESS(
1728 X_flex_account_type => h_flex_account_type,
1729 X_book_type_code => X_book_type_code,
1730 X_flex_num => X_flex_num,
1731 X_dist_ccid => X_dist_ccid,
1732 X_acct_segval => h_acct_seg,
1733 X_default_ccid => X_default_ccid,
1734 X_account_ccid => h_acct_ccid,
1735 X_distribution_id => X_distribution_id,
1736 X_validation_date => G_validation_date,
1737 X_return_ccid => h_return_ccid,
1738 p_log_level_rec => g_log_level_rec);
1739 if (result) then
1740 G_success_count := G_success_count + 1;
1741 h_deferred_exp_ccid := h_return_ccid;
1742 else
1743 Add_Messages(
1744 X_asset_number,
1745 X_asset_id,
1746 h_acct_ccid,
1747 h_acct_seg,
1748 h_flex_account_type,
1749 X_book_type_code,
1750 X_default_ccid,
1751 X_dist_ccid);
1752 end if;
1753 end if;
1754
1755 if ((found and h_deferred_rsv_ccid is null) OR (not found)) then
1756 /* Generate DEFERRED_DEPRN_RESERVE_ACCT */
1757 h_acct_seg := X_deferred_rsv_acct;
1758 h_acct_ccid := 0;
1759 h_flex_account_type := 'DEF_DEPRN_RSV';
1760 result := FAFLEX_PKG_WF.START_PROCESS(
1761 X_flex_account_type => h_flex_account_type,
1762 X_book_type_code => X_book_type_code,
1763 X_flex_num => X_flex_num,
1764 X_dist_ccid => X_dist_ccid,
1765 X_acct_segval => h_acct_seg,
1766 X_default_ccid => X_default_ccid,
1767 X_account_ccid => h_acct_ccid,
1768 X_distribution_id => X_distribution_id,
1769 X_validation_date => G_validation_date,
1770 X_return_ccid => h_return_ccid,
1771 p_log_level_rec => g_log_level_rec);
1772 if (result) then
1773 G_success_count := G_success_count + 1;
1774 h_deferred_rsv_ccid := h_return_ccid;
1775 else
1776 Add_Messages(
1777 X_asset_number,
1778 X_asset_id,
1779 h_acct_ccid,
1780 h_acct_seg,
1781 h_flex_account_type,
1782 X_book_type_code,
1783 X_default_ccid,
1784 X_dist_ccid);
1785 end if;
1786 end if;
1787
1788 end if; -- X_book_Class = TAX
1789
1790
1791 if (X_allow_reval_flag = 'YES' and
1792 X_group_asset_id is null) then
1793
1794 if ((found and h_reval_rsv_gain_ccid is null) OR (not found)) then
1795 /* Generate REVAL_RSV_RETIRED_GAIN_ACCT */
1796 h_acct_seg := X_reval_rsv_gain_acct;
1797 h_acct_ccid := 0;
1798 h_flex_account_type := 'REV_RSV_GAIN';
1799 result := FAFLEX_PKG_WF.START_PROCESS(
1800 X_flex_account_type => h_flex_account_type,
1801 X_book_type_code => X_book_type_code,
1802 X_flex_num => X_flex_num,
1803 X_dist_ccid => X_dist_ccid,
1804 X_acct_segval => h_acct_seg,
1805 X_default_ccid => X_default_ccid,
1806 X_account_ccid => h_acct_ccid,
1807 X_distribution_id => X_distribution_id,
1808 X_validation_date => G_validation_date,
1809 X_return_ccid => h_return_ccid,
1810 p_log_level_rec => g_log_level_rec);
1811 if (result) then
1812 G_success_count := G_success_count + 1;
1813 h_reval_rsv_gain_ccid := h_return_ccid;
1814 else
1815 Add_Messages(
1816 X_asset_number,
1817 X_asset_id,
1818 h_acct_ccid,
1819 h_acct_seg,
1820 h_flex_account_type,
1821 X_book_type_code,
1822 X_default_ccid,
1823 X_dist_ccid);
1824 end if;
1825 end if;
1826
1827 if ((found and h_reval_rsv_loss_ccid is null) OR (not found)) then
1828 /* Generate REVAL_RSV_RETIRED_LOSS_ACCT */
1829 h_acct_seg := X_reval_rsv_loss_acct;
1830 h_acct_ccid := 0;
1831 h_flex_account_type := 'REV_RSV_LOSS';
1832 result := FAFLEX_PKG_WF.START_PROCESS(
1833 X_flex_account_type => h_flex_account_type,
1834 X_book_type_code => X_book_type_code,
1835 X_flex_num => X_flex_num,
1836 X_dist_ccid => X_dist_ccid,
1837 X_acct_segval => h_acct_seg,
1838 X_default_ccid => X_default_ccid,
1839 X_account_ccid => h_acct_ccid,
1840 X_distribution_id => X_distribution_id,
1841 X_validation_date => G_validation_date,
1842 X_return_ccid => h_return_ccid,
1843 p_log_level_rec => g_log_level_rec);
1844 if (result) then
1845 G_success_count := G_success_count + 1;
1846 h_reval_rsv_loss_ccid := h_return_ccid;
1847 else
1848 Add_Messages(
1849 X_asset_number,
1850 X_asset_id,
1851 h_acct_ccid,
1852 h_acct_seg,
1853 h_flex_account_type,
1854 X_book_type_code,
1855 X_default_ccid,
1856 X_dist_ccid);
1857 end if;
1858 end if;
1859
1860 end if; -- end if allow_reval_flag
1861
1862 end if; --end book level accts
1863
1864 close get_ccids;
1865
1866 -- insert or update all the CCID's obtained for distribution
1867 -- into FA_DISTRIBUTION_ACCOUNTS
1868
1869 h_user_id := fnd_global.user_id;
1870 h_login_id := fnd_global.login_id;
1871
1872 if (not found) then
1873
1874 INSERT INTO FA_DISTRIBUTION_ACCOUNTS(
1875 BOOK_TYPE_CODE,
1876 DISTRIBUTION_ID,
1877 ASSET_COST_ACCOUNT_CCID,
1878 ASSET_CLEARING_ACCOUNT_CCID,
1879 DEPRN_EXPENSE_ACCOUNT_CCID,
1880 DEPRN_RESERVE_ACCOUNT_CCID,
1881 CIP_COST_ACCOUNT_CCID,
1882 CIP_CLEARING_ACCOUNT_CCID,
1883 NBV_RETIRED_GAIN_CCID,
1884 NBV_RETIRED_LOSS_CCID,
1885 PROCEEDS_SALE_GAIN_CCID,
1886 PROCEEDS_SALE_LOSS_CCID,
1887 COST_REMOVAL_GAIN_CCID,
1888 COST_REMOVAL_LOSS_CCID,
1889 COST_REMOVAL_CLEARING_CCID,
1890 PROCEEDS_SALE_CLEARING_CCID,
1891 LAST_UPDATE_DATE,
1892 LAST_UPDATED_BY,
1893 CREATED_BY,
1894 CREATION_DATE,
1895 LAST_UPDATE_LOGIN,
1896 deferred_exp_account_ccid,
1897 deferred_rsv_account_ccid,
1898 reval_rsv_gain_account_ccid,
1899 reval_rsv_loss_account_ccid,
1900 deprn_adj_account_ccid,
1901 reval_amort_account_ccid,
1902 reval_rsv_account_ccid,
1903 bonus_exp_account_ccid,
1904 bonus_rsv_account_ccid,
1905 impair_expense_account_ccid,
1906 impair_reserve_account_ccid,
1907 capital_adj_account_ccid, -- Bug 6666666
1908 general_fund_account_ccid, -- Bug 6666666
1909 reval_loss_account_ccid
1910 )VALUES(
1911 X_book_type_code,
1912 X_distribution_id,
1913 h_cost_acct_ccid,
1914 h_clearing_acct_ccid,
1915 h_expense_acct_ccid,
1916 h_reserve_acct_ccid,
1917 h_cip_cost_ccid,
1918 h_cip_clearing_ccid,
1919 h_nbv_gain_ccid,
1920 h_nbv_loss_ccid,
1921 h_pos_gain_ccid,
1922 h_pos_loss_ccid,
1923 h_cor_gain_ccid,
1924 h_cor_loss_ccid,
1925 h_cor_clearing_ccid,
1926 h_pos_clearing_ccid,
1927 sysdate,
1928 h_user_id,
1929 h_user_id,
1930 sysdate,
1931 h_login_id,
1932 h_deferred_exp_ccid,
1933 h_deferred_rsv_ccid,
1934 h_reval_rsv_gain_ccid,
1935 h_reval_rsv_loss_ccid,
1936 h_deprn_adj_ccid,
1937 h_reval_amort_ccid,
1938 h_reval_rsv_ccid,
1939 h_bonus_exp_ccid,
1940 h_bonus_rsv_ccid,
1941 h_impair_exp_ccid,
1942 h_impair_rsv_ccid,
1943 h_capital_adj_ccid,
1944 h_general_fund_ccid,
1945 h_reval_loss_ccid);
1946 else
1947 UPDATE FA_DISTRIBUTION_ACCOUNTS
1948 SET ASSET_COST_ACCOUNT_CCID = h_cost_acct_ccid,
1949 ASSET_CLEARING_ACCOUNT_CCID = h_clearing_acct_ccid,
1950 DEPRN_EXPENSE_ACCOUNT_CCID = h_expense_acct_ccid,
1951 DEPRN_RESERVE_ACCOUNT_CCID = h_reserve_acct_ccid,
1952 CIP_COST_ACCOUNT_CCID = h_cip_cost_ccid,
1953 CIP_CLEARING_ACCOUNT_CCID = h_cip_clearing_ccid,
1954 NBV_RETIRED_GAIN_CCID = h_nbv_gain_ccid,
1955 NBV_RETIRED_LOSS_CCID = h_nbv_loss_ccid,
1956 PROCEEDS_SALE_GAIN_CCID = h_pos_gain_ccid,
1957 PROCEEDS_SALE_LOSS_CCID = h_pos_loss_ccid,
1958 COST_REMOVAL_GAIN_CCID = h_cor_gain_ccid,
1959 COST_REMOVAL_LOSS_CCID = h_cor_loss_ccid,
1960 COST_REMOVAL_CLEARING_CCID = h_cor_clearing_ccid,
1961 PROCEEDS_SALE_CLEARING_CCID = h_pos_clearing_ccid,
1962 LAST_UPDATE_DATE = sysdate,
1963 LAST_UPDATED_BY = h_user_id,
1964 LAST_UPDATE_LOGIN = h_login_id,
1965 deferred_exp_account_ccid = h_deferred_exp_ccid,
1966 deferred_rsv_account_ccid = h_deferred_rsv_ccid,
1967 reval_rsv_gain_account_ccid = h_reval_rsv_gain_ccid,
1968 reval_rsv_loss_account_ccid = h_reval_rsv_loss_ccid,
1969 deprn_adj_account_ccid = h_deprn_adj_ccid,
1970 reval_amort_account_ccid = h_reval_amort_ccid,
1971 reval_rsv_account_ccid = h_reval_rsv_ccid,
1972 bonus_exp_account_ccid = h_bonus_exp_ccid,
1973 bonus_rsv_account_ccid = h_bonus_rsv_ccid,
1974 impair_expense_account_ccid = h_impair_exp_ccid,
1975 impair_reserve_account_ccid = h_impair_rsv_ccid,
1976 capital_adj_account_ccid = h_capital_adj_ccid,
1977 general_fund_account_ccid = h_general_fund_ccid,
1978 reval_loss_account_ccid = h_reval_loss_ccid
1979 WHERE BOOK_TYPE_CODE = X_book_type_code
1980 AND DISTRIBUTION_ID = X_distribution_id;
1981 end if;
1982 COMMIT;
1983
1984 EXCEPTION
1985 WHEN OTHERS THEN
1986 FA_SRVR_MSG.ADD_SQL_ERROR(
1987 CALLING_FN => 'FA_GENACCTS_PKG.GEN_CCID', p_log_level_rec => g_log_level_rec);
1988 ROLLBACK WORK;
1989 wf_core.context('FA_FLEX_PKG',
1990 'StartProcess',
1991 X_book_type_code,
1992 X_dist_ccid,
1993 X_default_ccid,
1994 'FAFLEXWF');
1995 raise;
1996 END GEN_CCID;
1997
1998 ---------------------------------------------------------------------
1999
2000 PROCEDURE Add_Messages(
2001 X_asset_number IN VARCHAR2,
2002 X_asset_id IN NUMBER,
2003 X_account_ccid IN NUMBER,
2004 X_acct_seg IN VARCHAR2,
2005 X_flex_account_type IN VARCHAR2,
2006 X_book_type_code IN VARCHAR2,
2007 X_default_ccid IN NUMBER,
2008 X_dist_ccid IN NUMBER) IS
2009
2010 BEGIN
2011
2012 G_failure_count := G_failure_count + 1;
2013
2014 -- BUG# 1504839
2015 -- Main flex error is already dumped out in FAFLEX_WF_PKG, so there
2016 -- is not need to dump it here as well...
2017 -- book and account_type are also dumped out in the message from FAFLEX_WF_PKG
2018
2019 if (g_log_level_rec.statement_level) then
2020
2021 FA_SRVR_MSG.ADD_MESSAGE
2022 (CALLING_FN => 'FA_GENACCTS_PKG.GEN_CCID',
2023 NAME => 'FA_ASSET_NUMBER',
2024 TOKEN1 => 'ASSET_NUMBER',
2025 VALUE1 => X_asset_number, p_log_level_rec => g_log_level_rec);
2026 FA_SRVR_MSG.ADD_MESSAGE
2027 (CALLING_FN => 'FA_GENACCTS_PKG.GEN_CCID',
2028 NAME => 'FA_ASSET_ID',
2029 TOKEN1 => 'ASSET_ID',
2030 VALUE1 => X_asset_id, p_log_level_rec => g_log_level_rec);
2031
2032 FA_SRVR_MSG.ADD_MESSAGE
2033 (CALLING_FN => 'FA_GENACCTS_PKG.GEN_CCID',
2034 NAME => 'FA_FLEX_ACCOUNT_SEGMENT',
2035 TOKEN1 => 'ACCOUNT_SEGMENT',
2036 VALUE1 => X_acct_seg, p_log_level_rec => g_log_level_rec);
2037 FA_SRVR_MSG.ADD_MESSAGE
2038 (CALLING_FN => 'FA_GENACCTS_PKG.GEN_CCID',
2039 NAME => 'FA_FLEX_ACCOUNT_CCID',
2040 TOKEN1 => 'ACCOUNT_CCID',
2041 VALUE1 => X_account_ccid, p_log_level_rec => g_log_level_rec);
2042 FA_SRVR_MSG.ADD_MESSAGE
2043 (CALLING_FN => 'FA_GENACCTS_PKG.GEN_CCID',
2044 NAME => 'FA_FLEX_DEFAULT_CCID',
2045 TOKEN1 => 'DEFAULT_CCID',
2046 VALUE1 => X_default_ccid, p_log_level_rec => g_log_level_rec);
2047 FA_SRVR_MSG.ADD_MESSAGE
2048 (CALLING_FN => 'FA_GENACCTS_PKG.GEN_CCID',
2049 NAME => 'FA_FLEX_DISTRIBUTION_CCID',
2050 TOKEN1 => 'DISTRIBUTION_CCID',
2051 VALUE1 => X_dist_ccid, p_log_level_rec => g_log_level_rec);
2052 end if;
2053
2054 END Add_Messages;
2055
2056 -----------------------------------------------------------------------
2057
2058 PROCEDURE Load_Workers(
2059 p_book_type_code IN VARCHAR2,
2060 p_parent_request_id IN NUMBER,
2061 p_total_requests IN NUMBER,
2062 x_worker_jobs OUT NOCOPY NUMBER,
2063 x_return_status OUT NOCOPY number) IS
2064
2065 l_batch_size number;
2066 l_dist_source_book varchar2(30);
2067 l_calling_fn varchar2(60) := 'FA_GENACCTS_PKG.Load_Workers';
2068
2069 error_found exception;
2070
2071 BEGIN
2072
2073 if (not g_log_level_rec.initialized) then
2074 if (NOT fa_util_pub.get_log_level_rec (
2075 x_log_level_rec => g_log_level_rec
2076 )) then
2077 raise FND_API.G_EXC_ERROR;
2078 end if;
2079 end if;
2080
2081 if not (fa_cache_pkg.fazcbc(x_book => p_book_type_code, p_log_level_rec => g_log_level_rec)) then
2082 raise error_found;
2083 end if;
2084
2085 l_batch_size := nvl(fa_cache_pkg.fa_batch_size, 1000);
2086 l_dist_source_book := fa_cache_pkg.fazcbc_record.distribution_source_book;
2087
2088 INSERT INTO FA_WORKER_JOBS
2089 (START_RANGE, END_RANGE, WORKER_NUM, STATUS,REQUEST_ID)
2090 SELECT MIN(DISTRIBUTION_ID), MAX(DISTRIBUTION_ID), 0,
2091 'UNASSIGNED', p_parent_request_id FROM ( SELECT /*+ parallel(DH) */
2092 DISTRIBUTION_ID, FLOOR(RANK()
2093 OVER (ORDER BY DISTRIBUTION_ID)/l_batch_size ) UNIT_ID
2094 FROM FA_DISTRIBUTION_HISTORY DH
2095 WHERE DH.BOOK_TYPE_CODE = l_dist_source_book )
2096 GROUP BY UNIT_ID;
2097
2098 if g_log_level_rec.statement_level then
2099 fa_debug_pkg.add(l_calling_fn, 'rows inserted into worker jobs: ', SQL%ROWCOUNT);
2100 end if;
2101
2102 commit;
2103
2104 x_return_status := 0;
2105
2106 EXCEPTION
2107 WHEN error_found then
2108 rollback;
2109 if (g_log_level_rec.statement_level) then
2110 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
2111 end if;
2112 fa_srvr_msg.add_message(calling_fn => l_calling_fn, p_log_level_rec => g_log_level_rec);
2113 x_return_status := 2;
2114
2115 WHEN OTHERS THEN
2116 FA_SRVR_MSG.ADD_SQL_ERROR(
2117 CALLING_FN => 'FA_GENACCTS_PKG.gen_accts', p_log_level_rec => g_log_level_rec);
2118 rollback;
2119 if (g_log_level_rec.statement_level) then
2120 fa_debug_pkg.dump_debug_messages(max_mesgs => 0, p_log_level_rec => g_log_level_rec);
2121 end if;
2122 x_return_status := 2;
2123
2124 END Load_Workers;
2125
2126 -----------------------------------------------------------------------
2127
2128 END FA_GENACCTS_PKG;