[Home] [Help]
PACKAGE BODY: APPS.FA_GCCID_PKG
Source
1 PACKAGE BODY FA_GCCID_PKG as
2 /* $Header: FAFBGCB.pls 120.6.12010000.1 2008/07/28 13:11:56 appldev ship $tpershad ship */
3
4 G_check_dist_accts boolean := TRUE;
5
6 g_custom_gen_ccid boolean := fa_cache_pkg.fa_custom_gen_ccid;
7 g_profile_init boolean := fa_cache_pkg.fa_profile_init;
8
9 FUNCTION fafb_load_functions(p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
10 return boolean is
11 h_i BINARY_INTEGER:=0; /* Index to the table */
12 begin <<load_functions>>
13 h_i:= h_i+1; /* h_i=1 */
14 fafb_accts(h_i).type_name := 'AP_INTERCOMPANY_ACCT';
15 fafb_accts(h_i).type_code := 'AP_INTERCO';
16 fafb_accts(h_i).flag := 'N';
17 h_i:=h_i+1;
18 fafb_accts(h_i).type_name := 'AR_INTERCOMPANY_ACCT';
19 fafb_accts(h_i).type_code := 'AR_INTERCO';
20 fafb_accts(h_i).flag := 'N';
21 h_i:=h_i+1;
22 fafb_accts(h_i).type_name := 'COST_OF_REMOVAL_CLEARING_ACCT';
23 fafb_accts(h_i).type_code := 'COR_CLEARING';
24 fafb_accts(h_i).flag := 'G';
25 h_i:=h_i+1; /* h_i=4 */
26 fafb_accts(h_i).type_name := 'COST_OF_REMOVAL_GAIN_ACCT';
27 fafb_accts(h_i).type_code := 'COR_GAIN';
28 fafb_accts(h_i).flag := 'G';
29 h_i:=h_i+1; /* h_i=5 */
30 fafb_accts(h_i).type_name := 'COST_OF_REMOVAL_LOSS_ACCT';
31 fafb_accts(h_i).type_code := 'COR_LOSS';
32 fafb_accts(h_i).flag := 'G';
33 h_i:=h_i+1; /* h_i=6 */
34 fafb_accts(h_i).type_name := 'DEFERRED_DEPRN_EXPENSE_ACCT';
35 fafb_accts(h_i).type_code := 'DEF_DEPRN_EXP';
36 fafb_accts(h_i).flag := 'N';
37 h_i:=h_i+1; /* h_i=7 */
38 fafb_accts(h_i).type_name := 'DEFERRED_DEPRN_RESERVE_ACCT';
39 fafb_accts(h_i).type_code := 'DEF_DEPRN_RSV';
40 fafb_accts(h_i).flag := 'N';
41 h_i:=h_i+1; /* h_i=8 */
42 fafb_accts(h_i).type_name := 'NBV_RETIRED_GAIN_ACCT';
43 fafb_accts(h_i).type_code := 'NBV_GAIN';
44 fafb_accts(h_i).flag := 'G';
45 h_i:=h_i+1;
46 fafb_accts(h_i).type_name := 'NBV_RETIRED_LOSS_ACCT';
47 fafb_accts(h_i).type_code := 'NBV_LOSS';
48 fafb_accts(h_i).flag := 'G';
49 h_i:=h_i+1; /* h_i=10 */
50 fafb_accts(h_i).type_name := 'PROCEEDS_OF_SALE_CLEARING_ACCT';
51 fafb_accts(h_i).type_code := 'POS_CLEARING';
52 fafb_accts(h_i).flag := 'G';
53 h_i:=h_i+1; /* h_i=11 */
54 fafb_accts(h_i).type_name := 'PROCEEDS_OF_SALE_GAIN_ACCT';
55 fafb_accts(h_i).type_code := 'POS_GAIN';
56 fafb_accts(h_i).flag := 'G';
57 h_i:=h_i+1;
58 fafb_accts(h_i).type_name := 'PROCEEDS_OF_SALE_LOSS_ACCT';
59 fafb_accts(h_i).type_code := 'POS_LOSS';
60 fafb_accts(h_i).flag := 'G';
61 h_i:=h_i+1;
62 fafb_accts(h_i).type_name := 'REVAL_RSV_RETIRED_GAIN_ACCT';
63 fafb_accts(h_i).type_code := 'REV_RSV_GAIN';
64 fafb_accts(h_i).flag := 'A';
65 h_i:=h_i+1; /* h_i=14 */
66 fafb_accts(h_i).type_name := 'REVAL_RSV_RETIRED_LOSS_ACCT';
67 fafb_accts(h_i).type_code := 'REV_RSV_LOSS';
68 fafb_accts(h_i).flag := 'A';
69 h_i:=h_i+1;
70 fafb_accts(h_i).type_name := 'ASSET_CLEARING_ACCT';
71 fafb_accts(h_i).type_code := 'ASSET_CLEARING';
72 fafb_accts(h_i).flag := 'A';
73 h_i:=h_i+1;
74 fafb_accts(h_i).type_name := 'ASSET_COST_ACCT';
75 fafb_accts(h_i).type_code := 'ASSET_COST';
76 fafb_accts(h_i).flag := 'A';
77 h_i:=h_i+1; /* h_i=17 */
78 fafb_accts(h_i).type_name := 'CIP_CLEARING_ACCT';
79 fafb_accts(h_i).type_code := 'CIP_CLEARING';
80 fafb_accts(h_i).flag := 'A';
81 h_i:=h_i+1;
82 fafb_accts(h_i).type_name := 'CIP_COST_ACCT';
83 fafb_accts(h_i).type_code := 'CIP_COST';
84 fafb_accts(h_i).flag := 'A';
85 h_i:=h_i+1;
86 fafb_accts(h_i).type_name := 'DEPRN_RESERVE_ACCT';
87 fafb_accts(h_i).type_code := 'DEPRN_RSV';
88 fafb_accts(h_i).flag := 'A';
89 h_i:=h_i+1; /* h_i=20 */
90 fafb_accts(h_i).type_name := 'BONUS_DEPRN_RESERVE_ACCT';
91 fafb_accts(h_i).type_code := 'BONUS_DEPRN_RSV';
92 fafb_accts(h_i).flag := 'A';
93 h_i:=h_i+1;
94 fafb_accts(h_i).type_name := 'REVAL_AMORTIZATION_ACCT';
95 fafb_accts(h_i).type_code := 'REV_AMORT';
96 fafb_accts(h_i).flag := 'A';
97 h_i:=h_i+1;
98 fafb_accts(h_i).type_name := 'REVAL_RESERVE_ACCT';
99 fafb_accts(h_i).type_code := 'REV_RSV';
100 fafb_accts(h_i).flag := 'A';
101 h_i:=h_i+1; /* h_i=23 */
102 fafb_accts(h_i).type_name := 'DEPRN_EXPENSE_ACCT';
103 fafb_accts(h_i).type_code := 'DEPRN_EXP';
104 fafb_accts(h_i).flag := 'D';
105 h_i:=h_i+1;
106 fafb_accts(h_i).type_name := 'BONUS_DEPRN_EXPENSE_ACCT';
107 fafb_accts(h_i).type_code := 'BONUS_DEPRN_EXP';
108 fafb_accts(h_i).flag := 'D';
109 h_i:=h_i+1; /* h_i=25 */
110 fafb_accts(h_i).type_name := 'DEPRN_ADJUSTMENT_ACCT';
111 fafb_accts(h_i).type_code := 'DEPRN_ADJ';
112 fafb_accts(h_i).flag := 'N';
113
114 return TRUE;
115 EXCEPTION
116 WHEN OTHERS THEN
117 FA_SRVR_MSG.ADD_SQL_ERROR
118 ( CALLING_FN => 'FA_GCCID_PKG.fafb_load_functions'
119 ,p_log_level_rec => p_log_level_rec);
120 return FALSE;
121 end fafb_load_functions;
122
123 ------------------------------------------------------------------
124 FUNCTION fafb_search_functions(X_fin_trx_code varchar2,
125 X_function_code out nocopy varchar2,
126 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
127 return boolean
128 is
129 h_i binary_integer:=0;
130 h_j binary_integer:=0;
131 begin <<fafb_search_functions>>
132 FOR h_i in 1..FA_FLEX_TYPE.NUM_ACCTS+1
133 LOOP
134 h_j:=h_i;
135 EXIT WHEN h_i > FA_FLEX_TYPE.NUM_ACCTS;
136 if fafb_accts(h_i).type_name = X_fin_trx_code
137 then
138 X_function_code := fafb_accts(h_i).type_code;
139 exit;
140 end if;
141 END LOOP;
142
143 if h_j > FA_FLEX_TYPE.NUM_ACCTS then
144 FA_SRVR_MSG.ADD_MESSAGE
145 (CALLING_FN => 'FA_GCCID_PKG.fafb_search_functions',
146 NAME => 'FA_FLEX_NO_ACCOUNT',
147 p_log_level_rec => p_log_level_rec);
148 return FALSE;
149 end if;
150 return TRUE;
151 EXCEPTION
152 WHEN OTHERS THEN
153 FA_SRVR_MSG.ADD_SQL_ERROR
154 ( CALLING_FN => 'FA_GCCID_PKG.fafb_search_functions'
155 ,p_log_level_rec => p_log_level_rec);
156 return FALSE;
157 end fafb_search_functions;
158
159 -------------------------------------------------------------------
160 FUNCTION fafbgcc (X_book_type_code in fa_book_controls.book_type_code%type,
161 X_fn_trx_code in varchar2,
162 X_dist_ccid in number,
163 X_acct_segval in varchar2,
164 X_account_ccid in number,
165 X_distribution_id in number,
166 X_rtn_ccid out nocopy number,
167 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
168 return boolean
169 is
170 h_acct_segval varchar2(30);
171 h_dist_ccid number;
172 h_dist_id number;
173 h_acct_ccid number;
174 h_segs_def_ccid number;
175 h_rtn_ccid number;
176 h_flex_num number:=null;
177 h_flex_function_code varchar2(30);
178 h_ret_value boolean;
179 h_ccid_success boolean := FALSE;
180 h_ccid_found boolean := FALSE;
181 h_gen_expense varchar2(1) := NULL;
182 h_val_date date;
183
184 h_ccid_valid varchar2(10) := NULL;
185
186 CURSOR validate_ccid IS
187 SELECT 'VALID'
188 FROM gl_code_combinations glcc
189 WHERE glcc.code_combination_id = X_rtn_ccid
190 AND glcc.enabled_flag = 'Y'
191 AND nvl(glcc.end_date_active, h_val_date) >=
192 h_val_date;
193
194 BEGIN <<fafbgcc>>
195
196 h_dist_ccid := X_dist_ccid;
197 h_acct_segval := X_acct_segval;
198 h_dist_id := X_distribution_id;
199 h_acct_ccid := X_account_ccid;
200
201 h_ret_value := fafb_load_functions;
202 if not h_ret_value then
203 FA_SRVR_MSG.ADD_MESSAGE
204 (CALLING_FN => 'FA_GCCID_PKG.fafbgcc',
205 p_log_level_rec => p_log_level_rec);
206 end if;
207
208 -- no need to call the cache here as it will already be loaded
209 h_flex_num := FA_CACHE_PKG.fazcbc_record.accounting_flex_structure;
210 h_segs_def_ccid := FA_CACHE_PKG.fazcbc_record.flexbuilder_defaults_ccid;
211
212 h_ret_value := fafb_search_functions(X_fin_trx_code => X_fn_trx_code,
213 X_function_code => h_flex_function_code,
214 p_log_level_rec => p_log_level_rec);
215 if not h_ret_value then
216 FA_SRVR_MSG.ADD_MESSAGE
217 (CALLING_FN => 'FA_GCCID_PKG.fafbgcc',
218 p_log_level_rec => p_log_level_rec);
219 return FALSE;
220 end if;
221 if (p_log_level_rec.statement_level)
222 then
223 FA_DEBUG_PKG.ADD(
224 fname => 'FA_GCCID_PKG.fafbgcc',
225 element => 'dist_ccid in fafbgcc is ',
226 value => X_dist_ccid,
227 p_log_level_rec => p_log_level_rec);
228 FA_DEBUG_PKG.ADD(
229 fname => 'FA_GCCID_PKG.fafbgcc',
230 element => 'flexbuilder defs ccid ',
231 value => h_segs_def_ccid,
232 p_log_level_rec => p_log_level_rec);
233 end if;
234
235 -- BUG# 2215671
236 -- Pass the validation date to start process to use the correct
237 -- period date instead of system date. G_validation_date will
238 -- only be populated from FAPOST which is the only code where
239 -- generation can occur for ccids from a prior or future period.
240 -- bridgway
241
242 if (G_validation_date is null) then
243 if not fa_cache_pkg.fazcdp
244 (x_book_type_code => x_book_type_code,
245 x_period_counter => null,
246 x_effective_date => null,
247 p_log_level_rec => p_log_level_rec) then
248
249 fa_srvr_msg.add_message(calling_fn => 'fa_gccid_pkg.fafbgcc',
250 p_log_level_rec => p_log_level_rec);
251 return false;
252 end if;
253 h_val_date := fa_cache_pkg.fazcdp_record.calendar_period_close_date;
254 else
255 h_val_date := to_date(G_validation_date, 'DD/MM/RRRR'); --bug#5911720
256 end if;
257
258 /*
259 Call the START_PROCESS which will start the flex workflow process
260 */
261 if (p_log_level_rec.statement_level)
262 then
263 FA_DEBUG_PKG.ADD (
264 fname => 'FA_GCCID_PKG.fafbgcc',
265 element => 'validation_date in fafbgcb is ',
266 value =>h_val_date,
267 p_log_level_rec => p_log_level_rec);
268
269 FA_DEBUG_PKG.ADD (
270 fname => 'FA_GCCID_PKG.fafbgcc',
271 element => 'distribution ccid in fafbgcc is ',
272 value =>X_dist_ccid,
273 p_log_level_rec => p_log_level_rec);
274 FA_DEBUG_PKG.ADD (
275 fname => 'FA_GCCID_PKG.fafbgcc',
276 element => 'Acct Type in fafbgcc is ',
277 value =>h_flex_function_code,
278 p_log_level_rec => p_log_level_rec);
279 FA_DEBUG_PKG.ADD (
280 fname => 'FA_GCCID_PKG.fafbgcc',
281 element => 'segval in fafbgcc is ',
282 value =>h_acct_segval,
283 p_log_level_rec => p_log_level_rec);
284 FA_DEBUG_PKG.ADD (
285 fname => 'FA_GCCID_PKG.fafbgcc',
286 element => 'seg defs ccid in fafbgcc is ',
287 value =>h_segs_def_ccid,
288 p_log_level_rec => p_log_level_rec);
289 FA_DEBUG_PKG.ADD (
290 fname => 'FA_GCCID_PKG.fafbgcc',
291 element => 'acct ccid in fafbgcc is ',
292 value =>h_acct_ccid,
293 p_log_level_rec => p_log_level_rec);
294 FA_DEBUG_PKG.ADD (
295 fname => 'FA_GCCID_PKG.fafbgcc',
296 element => 'flex num in fafbgcc is ',
297 value =>h_flex_num,
298 p_log_level_rec => p_log_level_rec);
299 end if;
300
301 -- call get_ccid to check if ccid exists in fa_distribution_accounts
302 -- G_check_dist_accts will be true when called from form transactions
303 -- and false when called from fafbgcc_proc. When called from fafbgcc_proc
304 -- not necessary to check fa_distribution_accounts again since get_ccid
305 -- is already called in fafbgcc_proc
306
307 --- BEGIN USE CUSTOM GEN CCID
308 if not g_profile_init then
309 if not fa_cache_pkg.fazprof then
310 null;
311 end if;
312 g_custom_gen_ccid := fa_cache_pkg.fa_custom_gen_ccid;
313 g_profile_init := TRUE;
314 end if;
315
316 if (g_custom_gen_ccid) then
317
318 if (p_log_level_rec.statement_level) then
319 FA_DEBUG_PKG.ADD(
320 fname => 'FA_GCCID_PKG.fafbgcc',
321 element => 'entering ',
322 value => 'custom gen ccid logic',
323 p_log_level_rec => p_log_level_rec);
324 end if;
325
326
327 h_ret_value := FA_CUSTOM_GEN_CCID_PKG.gen_ccid(
328 X_fn_trx_code=>X_fn_trx_code,
329 X_book_type_code=>X_book_type_code,
330 X_flex_num=>h_flex_num,
331 X_dist_ccid=>h_dist_ccid,
332 X_acct_segval=>h_acct_segval,
333 X_default_ccid=>h_segs_def_ccid,
334 X_account_ccid=>h_acct_ccid,
335 X_distribution_id=>h_dist_id,
336 X_rtn_ccid=>h_rtn_ccid,
337 p_log_level_rec => p_log_level_rec);
338
339 if not h_ret_value then
340
341 X_rtn_ccid := -1;
342 h_ret_value := FALSE;
343
344 else
345
346 X_rtn_ccid := h_rtn_ccid;
347
348 if (X_rtn_ccid is NULL) OR (X_rtn_ccid <= 0) THEN
349
350 h_ret_value := FALSE;
351
352 else -- (X_rtn_ccid > 0)
353
354 open validate_ccid;
355 fetch validate_ccid into h_ccid_valid;
356 if (validate_ccid%NOTFOUND) then
357
358 h_ret_value := FALSE;
359
360 else
361
362 h_ret_value := TRUE;
363
364 end if;
365
366 close validate_ccid;
367
368 end if;
369
370 end if;
371
372 if (not h_ret_value) then
373 FA_SRVR_MSG.ADD_MESSAGE
374 (CALLING_FN => 'FAFLEX_PKG_WF.START_PROCESS',
375 NAME => 'FA_FLEXBUILDER_FAIL_CCID',
376 TOKEN1 => 'ACCOUNT_TYPE',
377 VALUE1 => X_fn_trx_code,
378 TOKEN2 => 'BOOK_TYPE_CODE',
379 VALUE2 => X_book_type_code,
380 TOKEN3 => 'DIST_ID',
381 VALUE3 => h_dist_id,
382 TOKEN4 => 'CONCAT_SEGS',
383 VALUE4 => 'from custom gen ccid',
384 p_log_level_rec => p_log_level_rec);
385 end if;
386
387 return h_ret_value;
388
389 --- ELSE DO NOT USE CUSTOM GEN CCID
390 else
391
392 if (G_check_dist_accts) then
393 h_ccid_success := FA_GCCID_PKG.get_ccid(
394 X_book_type_code,
395 X_distribution_id,
396 X_fn_trx_code,
397 h_val_date,
398 h_ccid_found,
399 X_rtn_ccid
400 ,p_log_level_rec => p_log_level_rec);
401 end if;
402
403 -- Call workflow to generate ccid only when ccid is not in
404 -- fa_distribution_accounts
405 if (not h_ccid_found OR X_rtn_ccid = -1) then
406 -- Bonus: BONUS_DEPRN_EXP_ACCT is not included in fa_distribution_accounts
407
408 if (X_fn_trx_code = 'DEPRN_EXPENSE_ACCT') then
409
410 --fnd_profile.get('FA_GEN_EXPENSE_ACCOUNT', h_gen_expense);
411 if (not fa_cache_pkg.fa_gen_expense_account) then
412 X_rtn_ccid := X_dist_ccid;
413 return TRUE;
414 end if;
415 end if;
416
417 h_ret_value := FAFLEX_PKG_WF.START_PROCESS(
418 X_flex_account_type=>h_flex_function_code,
419 X_book_type_code=>X_book_type_code,
420 X_flex_num=>h_flex_num,
421 X_dist_ccid=>h_dist_ccid,
422 X_acct_segval=>h_acct_segval,
423 X_default_ccid=>h_segs_def_ccid,
424 X_account_ccid=>h_acct_ccid,
425 X_distribution_id=>h_dist_id,
426 X_validation_date=>h_val_date,
427 X_return_ccid=>h_rtn_ccid
428 ,p_log_level_rec => p_log_level_rec);
429 if (p_log_level_rec.statement_level)
430 then
431 FA_DEBUG_PKG.ADD (
432 fname => 'FA_GCCID_PKG.fafbgcc',
433 element => ' return from Start Process ',
434 value =>h_ret_value,
435 p_log_level_rec => p_log_level_rec);
436 end if;
437 if not h_ret_value then
438 /* BUG# 1504839
439 this error is not needed. We already dump an error to the
440 stack in FAFLEX_WF_PKG
441
442 Flexbuilder failed to generate the code combination id. Pls
443 inform your systems administrator
444
445 FA_SRVR_MSG.ADD_MESSAGE
446 (CALLING_FN => 'FA_GCCID_PKG.fafbgcc',
447 NAME => 'FA_FLEX_FUNCTION_FAILED',
448 p_log_level_rec => p_log_level_rec);
449 */
450
451 X_rtn_ccid := -1;
452 return FALSE;
453 end if;
454 X_rtn_ccid := h_rtn_ccid;
455 if (X_rtn_ccid is null)
456 then
457 return FALSE;
458 end if;
459 else
460 -- not h_ccid_success is the case where ccid is found in
461 -- fa_distribution_accounts but it is not valid. Otherwise ccid
462 -- is valid.
463 if (not h_ccid_success) then
464 h_ret_value := FALSE;
465 else
466 -- ccid is valid
467 h_ret_value := TRUE;
468 end if;
469 end if;
470 end if; -- custom_gen_ccid
471
472 -- in case there is some problem return false when ccid is -1
473 if (X_rtn_ccid = -1) then
474 h_ret_value := FALSE;
475 end if;
476
477 return h_ret_value;
478
479 EXCEPTION
480 WHEN OTHERS THEN
481 FA_SRVR_MSG.ADD_SQL_ERROR ( CALLING_FN => 'FA_GCCID_PKG.fafbgcc'
482 ,p_log_level_rec => p_log_level_rec);
483 return FALSE;
484
485 END ; /* fafbgcc */
486
487 -------------------------------------------------------------------
488 PROCEDURE fafbgcc_proc
489 (X_book_type_code in fa_book_controls.book_type_code%type,
490 X_fn_trx_code in varchar2,
491 X_dist_ccid in integer,
492 X_acct_segval in varchar2,
493 X_account_ccid in integer,
494 X_distribution_id in integer,
495 X_rtn_ccid out nocopy number,
496 X_concat_segs out nocopy varchar2,
497 X_return_value out nocopy integer,
498 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
499 as
500 h_ret_value boolean;
501 h_rtn_ccid integer;
502 h_ccid_success boolean;
503 h_ccid_found boolean;
504
505 h_val_date date;
506
507 begin
508 -- initialize out variables to failure condition
509 X_rtn_ccid := -1;
510 h_rtn_ccid := -1;
511 X_return_value := 0;
512
513 -- for pro*c, we need to load the plsql cache for
514 -- book controls and profile options
515 if not FA_CACHE_PKG.fazcbc(X_book_type_code, p_log_level_rec) then
516 FA_SRVR_MSG.ADD_MESSAGE
517 (CALLING_FN => 'FA_GCCID_PKG.fafbgcc',
518 p_log_level_rec => p_log_level_rec);
519 X_return_value := 0;
520 return;
521 end if;
522
523 g_custom_gen_ccid := fa_cache_pkg.fa_custom_gen_ccid;
524 g_profile_init := TRUE;
525
526 -- BUG# 2215671
527 -- Pass the validation date to start process to use the correct
528 -- period date instead of system date. G_validation_date will
529 -- only be populated from FAPOST which is the only code where
530 -- generation can occur for ccids from a prior or future period.
531 -- bridgway
532
533 if (G_validation_date is null) then
534 if not fa_cache_pkg.fazcdp
535 (x_book_type_code => x_book_type_code,
536 x_period_counter => null,
537 x_effective_date => null,
538 p_log_level_rec => p_log_level_rec) then
539 X_return_value := 0;
540 fa_srvr_msg.add_message(calling_fn => 'fa_gccid_pkg.fafbgcc',
541 p_log_level_rec => p_log_level_rec);
542 return;
543 end if;
544 h_val_date := fa_cache_pkg.fazcdp_record.calendar_period_close_date;
545 else
546 h_val_date := to_date(G_validation_date, 'DD/MM/RRRR'); --bug#5911720
547 end if;
548
549 -- set G_check_dist_accts to FALSE so get_ccid does not get
550 -- called again if ccid is not in fa_distribution_accounts
551 -- and need to call fafbgcc to generate the ccid
552
553 if not g_custom_gen_ccid then
554 G_check_dist_accts := FALSE;
555 h_ccid_success := FA_GCCID_PKG.get_ccid(
556 X_book_type_code,
557 to_number(X_distribution_id),
558 X_fn_trx_code,
559 h_val_date,
560 h_ccid_found,
561 h_rtn_ccid,
562 p_log_level_rec);
563 end if;
564
565 if (not h_ccid_found OR h_rtn_ccid = -1) then
566 h_ret_value := FA_GCCID_PKG.fafbgcc(X_book_type_code,
567 X_fn_trx_code,
568 to_number(X_dist_ccid),
569 X_acct_segval,
570 to_number(X_account_ccid),
571 to_number(X_distribution_id),
572 h_rtn_ccid,
573 p_log_level_rec);
574 if (h_ret_value) then
575 X_return_value := 1; /* True */
576 else
577 X_return_value := 0; /* False */
578 end if;
579 X_rtn_ccid := h_rtn_ccid;
580 X_concat_segs := FA_GCCID_PKG.global_concat_segs;
581 elsif (not h_ccid_success) then
582 X_rtn_ccid := h_rtn_ccid;
583 X_concat_segs := FA_GCCID_PKG.global_concat_segs;
584 X_return_value := 0; /* False */
585 else
586 X_rtn_ccid := h_rtn_ccid;
587 X_concat_segs := FA_GCCID_PKG.global_concat_segs;
588 X_return_value := 1; /* True */
589 end if;
590
591 -- in case there is some problem and ccid is not generated
592 -- return false.
593 if (X_rtn_ccid = -1) then
594 X_return_value := 0; /* False */
595 end if;
596
597 if (p_log_level_rec.statement_level)
598 then
599 FA_DEBUG_PKG.ADD (
600 fname => 'fafbgcc_proc',
601 element=>'rtn ccid',
602 value=>h_rtn_ccid,
603 p_log_level_rec => p_log_level_rec);
604 end if;
605 return;
606 EXCEPTION
607
608 WHEN OTHERS THEN
609 if (p_log_level_rec.statement_level)
610 then
611 FA_DEBUG_PKG.ADD (
612 fname => 'fafbgcc_proc',
613 element=>'Errored',
614 value=>1,
615 p_log_level_rec => p_log_level_rec);
616
617 end if;
618 X_return_value := 0;
619 return;
620 END fafbgcc_proc;
621
622 --------------------------------------------------------------------------
623 FUNCTION get_ccid (X_book_type_code IN VARCHAR2,
624 X_distribution_id IN NUMBER,
625 X_fn_trx_code IN VARCHAR2,
626 X_validation_date IN DATE,
627 X_ccid_found OUT NOCOPY BOOLEAN,
628 X_rtn_ccid OUT NOCOPY NUMBER,
629 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null)
630 RETURN BOOLEAN is
631 h_cost_ccid number :=0;
632 h_clearing_ccid number :=0;
633 h_expense_ccid number :=0;
634 h_reserve_ccid number :=0;
635 h_cip_cost_ccid number :=0;
636 h_cip_clearing_ccid number :=0;
637 h_nbv_retired_gain_ccid number :=0;
638 h_nbv_retired_loss_ccid number :=0;
639 h_pos_gain_ccid number :=0;
640 h_pos_loss_ccid number :=0;
641 h_cost_removal_gain_ccid number :=0;
642 h_cost_removal_loss_ccid number :=0;
643 h_cor_clearing_ccid number :=0;
644 h_pos_clearing_ccid number :=0;
645
646 h_reval_rsv_ret_gain_ccid number := 0;
647 h_reval_rsv_ret_loss_ccid number := 0;
648 h_deferred_dep_exp_ccid number := 0;
649 h_deferred_dep_rsv_ccid number := 0;
650 h_deprn_adjustment_ccid number := 0;
651 h_reval_amortization_ccid number := 0;
652 h_reval_reserve_ccid number := 0;
653 h_bonus_deprn_expense_ccid number := 0;
654 h_bonus_deprn_reserve_ccid number := 0;
655
656 -- added following variables for fix to bug 969990
657 h_flex_num number := null;
658 h_ccid_valid varchar2(10) := NULL;
659 n_segs number;
660 all_segments fnd_flex_ext.SegmentArray;
661 delim varchar2(1);
662 get_segs_success boolean;
663 h_ret_value boolean := FALSE;
664
665 -- added the following for bug 1085809
666 h_pregen boolean := TRUE;
667
668
669 CURSOR get_accounts IS
670 SELECT nvl(ASSET_COST_ACCOUNT_CCID, -1),
671 nvl(ASSET_CLEARING_ACCOUNT_CCID, -1),
672 nvl(DEPRN_EXPENSE_ACCOUNT_CCID, -1),
673 nvl(DEPRN_RESERVE_ACCOUNT_CCID, -1),
674 nvl(CIP_COST_ACCOUNT_CCID, -1),
675 nvl(CIP_CLEARING_ACCOUNT_CCID, -1),
676 nvl(NBV_RETIRED_GAIN_CCID,-1),
677 nvl(NBV_RETIRED_LOSS_CCID,-1),
678 nvl(PROCEEDS_SALE_GAIN_CCID,-1),
679 nvl(PROCEEDS_SALE_LOSS_CCID,-1),
680 nvl(COST_REMOVAL_GAIN_CCID,-1),
681 nvl(COST_REMOVAL_LOSS_CCID,-1),
682 nvl(COST_REMOVAL_CLEARING_CCID,-1),
683 nvl(PROCEEDS_SALE_CLEARING_CCID,-1),
684 nvl(REVAL_RSV_GAIN_ACCOUNT_CCID, -1),
685 nvl(REVAL_RSV_LOSS_ACCOUNT_CCID, -1),
686 nvl(DEFERRED_EXP_ACCOUNT_CCID, -1),
687 nvl(DEFERRED_RSV_ACCOUNT_CCID, -1),
688 nvl(DEPRN_ADJ_ACCOUNT_CCID, -1),
689 nvl(REVAL_AMORT_ACCOUNT_CCID, -1),
690 nvl(REVAL_RSV_ACCOUNT_CCID, -1),
691 nvl(BONUS_EXP_ACCOUNT_CCID, -1),
692 nvl(BONUS_RSV_ACCOUNT_CCID, -1),
693 accounting_flex_structure
694 FROM FA_DISTRIBUTION_ACCOUNTS da,
695 FA_BOOK_CONTROLS bc
696 WHERE bc.book_type_code = X_book_type_code
697 AND da.book_type_code = bc.book_type_code
698 AND da.distribution_id = X_distribution_id;
699
700 CURSOR validate_ccid IS
701 SELECT 'VALID'
702 FROM gl_code_combinations glcc
703 WHERE glcc.code_combination_id = X_rtn_ccid
704 AND glcc.enabled_flag = 'Y'
705 AND nvl(glcc.end_date_active, X_validation_date) >=
706 X_validation_date;
707
708 BEGIN
709 -- initialize out variables to failure condition
710 X_rtn_ccid := -1;
711 X_ccid_found := FALSE;
712
713 -- bug# 1085809: do not check distribution_accounts for an account if
714 -- the associated pregeneration profile option is set to 'N'
715
716 if (X_fn_trx_code = 'DEPRN_EXPENSE_ACCT') then
717 -- fnd_profile.get('FA_PREGEN_ASSET_ACCOUNT', h_pregen);
718 h_pregen := fa_cache_pkg.fa_pregen_asset_account;
719 end if;
720
721 if (X_fn_trx_code in ('ASSET_COST_ACCT',
722 'ASSET_CLEARING_ACCT',
723 'DEPRN_RESERVE_ACCT',
724 'CIP_COST_ACCT',
725 'CIP_CLEARING_ACCT',
726 'REVAL_AMORTIZATION_ACCT',
727 'REVAL_RESERVE_ACCT',
728 'BONUS_DEPRN_EXPENSE_ACCT',
729 'BONUS_DEPRN_RESERVE_ACCT'
730 )) then
731 --fnd_profile.get('FA_PREGEN_CAT_ACCOUNT', h_pregen);
732 h_pregen := fa_cache_pkg.fa_pregen_cat_account;
733 end if;
734
735 if (X_fn_trx_code in ('NBV_RETIRED_GAIN_ACCT',
736 'NBV_RETIRED_LOSS_ACCT',
737 'PROCEEDS_OF_SALE_GAIN_ACCT',
738 'PROCEEDS_OF_SALE_LOSS_ACCT',
739 'COST_OF_REMOVAL_GAIN_ACCT',
740 'COST_OF_REMOVAL_LOSS_ACCT',
741 'COST_OF_REMOVAL_CLEARING_ACCT',
742 'PROCEEDS_OF_SALE_CLEARING_ACCT',
743 'REVAL_RSV_RETIRED_GAIN_ACCT',
744 'REVAL_RSV_RETIRED_LOSS_ACCT',
745 'DEFERRED_DEPRN_EXPENSE_ACCT',
746 'DEFERRED_DEPRN_RESERVE_ACCT',
747 'DEPRN_ADJUSTMENT_ACCT'
748 )) then
749 --fnd_profile.get('FA_PREGEN_BOOK_ACCOUNT', h_pregen);
750 h_pregen := fa_cache_pkg.fa_pregen_book_account;
751 end if;
752
753 if (h_pregen) then
754 OPEN get_accounts;
755 FETCH get_accounts into
756 h_cost_ccid,
757 h_clearing_ccid,
758 h_expense_ccid,
759 h_reserve_ccid,
760 h_cip_cost_ccid,
761 h_cip_clearing_ccid,
762 h_nbv_retired_gain_ccid,
763 h_nbv_retired_loss_ccid,
764 h_pos_gain_ccid,
765 h_pos_loss_ccid,
766 h_cost_removal_gain_ccid,
767 h_cost_removal_loss_ccid,
768 h_cor_clearing_ccid,
769 h_pos_clearing_ccid,
770 h_reval_rsv_ret_gain_ccid,
771 h_reval_rsv_ret_loss_ccid,
772 h_deferred_dep_exp_ccid,
773 h_deferred_dep_rsv_ccid,
774 h_deprn_adjustment_ccid,
775 h_reval_amortization_ccid,
776 h_reval_reserve_ccid,
777 h_bonus_deprn_expense_ccid,
778 h_bonus_deprn_reserve_ccid,
779 h_flex_num;
780
781 if (get_accounts%FOUND) then
782 if (X_fn_trx_code = 'ASSET_COST_ACCT') then
783 X_rtn_ccid := h_cost_ccid;
784 elsif (X_fn_trx_code = 'ASSET_CLEARING_ACCT') then
785 X_rtn_ccid := h_clearing_ccid;
786 elsif (X_fn_trx_code = 'DEPRN_RESERVE_ACCT') then
787 X_rtn_ccid := h_reserve_ccid;
788 elsif (X_fn_trx_code = 'DEPRN_EXPENSE_ACCT') then
789 X_rtn_ccid := h_expense_ccid;
790 elsif (X_fn_trx_code = 'CIP_COST_ACCT') then
791 X_rtn_ccid := h_cip_cost_ccid;
792 elsif (X_fn_trx_code = 'CIP_CLEARING_ACCT') then
793 X_rtn_ccid := h_cip_clearing_ccid;
794 elsif (X_fn_trx_code = 'NBV_RETIRED_GAIN_ACCT') then
795 X_rtn_ccid := h_nbv_retired_gain_ccid;
796 elsif (X_fn_trx_code = 'NBV_RETIRED_LOSS_ACCT') then
797 X_rtn_ccid := h_nbv_retired_loss_ccid;
798 elsif (X_fn_trx_code = 'PROCEEDS_OF_SALE_GAIN_ACCT') then
799 X_rtn_ccid := h_pos_gain_ccid;
800 elsif (X_fn_trx_code = 'PROCEEDS_OF_SALE_LOSS_ACCT') then
801 X_rtn_ccid := h_pos_loss_ccid;
802 elsif (X_fn_trx_code = 'COST_OF_REMOVAL_GAIN_ACCT') then
803 X_rtn_ccid := h_cost_removal_gain_ccid;
804 elsif (X_fn_trx_code = 'COST_OF_REMOVAL_LOSS_ACCT') then
805 X_rtn_ccid := h_cost_removal_loss_ccid; --BUG# 1390143
806 elsif (X_fn_trx_code = 'COST_OF_REMOVAL_CLEARING_ACCT') then
807 X_rtn_ccid := h_cor_clearing_ccid;
808 elsif (X_fn_trx_code = 'PROCEEDS_OF_SALE_CLEARING_ACCT') then
809 X_rtn_ccid := h_pos_clearing_ccid;
810 elsif (X_fn_trx_code = 'REVAL_RSV_RETIRED_GAIN_ACCT') then
811 X_rtn_ccid := h_reval_rsv_ret_gain_ccid;
812 elsif (X_fn_trx_code = 'REVAL_RSV_RETIRED_LOSS_ACCT') then
813 X_rtn_ccid := h_reval_rsv_ret_loss_ccid;
814 elsif (X_fn_trx_code = 'DEFERRED_DEPRN_EXPENSE_ACCT') then
815 X_rtn_ccid := h_deferred_dep_exp_ccid;
816 elsif (X_fn_trx_code = 'DEFERRED_DEPRN_RESERVE_ACCT') then
817 X_rtn_ccid := h_deferred_dep_rsv_ccid;
818 elsif (X_fn_trx_code = 'DEPRN_ADJUSTMENT_ACCT') then
819 X_rtn_ccid := h_deprn_adjustment_ccid;
820 elsif (X_fn_trx_code = 'REVAL_AMORTIZATION_ACCT') then
821 X_rtn_ccid := h_reval_amortization_ccid;
822 elsif (X_fn_trx_code = 'REVAL_RESERVE_ACCT') then
823 X_rtn_ccid := h_reval_reserve_ccid;
824 elsif (X_fn_trx_code = 'BONUS_DEPRN_EXPENSE_ACCT') then
825 X_rtn_ccid := h_bonus_deprn_expense_ccid;
826 elsif (X_fn_trx_code = 'BONUS_DEPRN_RESERVE_ACCT') then
827 X_rtn_ccid := h_bonus_deprn_reserve_ccid;
828 end if;
829
830 if (X_rtn_ccid > 0) then
831 -- fix for bug 969990
832 X_ccid_found := TRUE;
833 open validate_ccid;
834 fetch validate_ccid into h_ccid_valid;
835 if (validate_ccid%NOTFOUND) then
836 get_segs_success := FND_FLEX_EXT.get_segments(
837 application_short_name => 'SQLGL',
838 key_flex_code => 'GL#',
839 structure_number => h_flex_num,
840 combination_id => X_rtn_ccid,
841 n_segments => n_segs,
842 segments => all_segments);
843 delim := FND_FLEX_EXT.get_delimiter(
844 application_short_name => 'SQLGL',
845 key_flex_code => 'GL#',
846 structure_number => h_flex_num);
847 FA_GCCID_PKG.global_concat_segs :=
848 FND_FLEX_EXT.concatenate_segments(
849 n_segments => n_segs,
850 segments => all_segments,
851 delimiter => delim);
852
853 FA_SRVR_MSG.ADD_MESSAGE
854 (CALLING_FN=>'FAFLEX_PKG_WF.START_PROCESS',
855 NAME=>'FA_FLEXBUILDER_FAIL_CCID',
856 TOKEN1 => 'ACCOUNT_TYPE',
857 VALUE1 => X_fn_trx_code,
858 TOKEN2 => 'BOOK_TYPE_CODE',
859 VALUE2 => X_book_type_code,
860 TOKEN3 => 'DIST_ID',
861 VALUE3 => X_distribution_id,
862 TOKEN4 => 'CONCAT_SEGS',
863 VALUE4 => FA_GCCID_PKG.global_concat_segs,
864 p_log_level_rec => p_log_level_rec);
865
866 fnd_message.set_name('FND', 'FLEX-COMBINATION DISABLED');
867 fnd_msg_pub.add; -- end 1504839
868
869
870 h_ret_value := FALSE;
871 else
872 h_ret_value := TRUE;
873 end if;
874 close validate_ccid;
875 else
876 h_ret_value := FALSE;
877 end if;
878 else
879 h_ret_value := FALSE;
880 end if;
881 CLOSE get_accounts;
882 else
883 h_ret_value := FALSE;
884 end if; -- pregen profile
885 RETURN h_ret_value;
886 END get_ccid;
887
888 --------------------------------------------------------------------------
889
890 PROCEDURE fafbgcc_proc_msg(X_mesg_count IN OUT NOCOPY number,
891 X_mesg_string IN OUT NOCOPY VARCHAR2,
892 p_log_level_rec IN FA_API_TYPES.log_level_rec_type default null) IS
893
894 begin
895
896 X_mesg_count := fnd_msg_pub.count_msg;
897
898 if (X_mesg_count > 0) then
899
900 X_mesg_string := fnd_global.Local_Chr(10) || substr(fnd_msg_pub.get
901 (fnd_msg_pub.G_FIRST, fnd_api.G_FALSE),
902 1, 512);
903
904 for i in 1..2 loop -- (X_mesg_count - 1) loop
905
906 X_mesg_string := X_mesg_string || fnd_global.Local_Chr(10) ||
907 substr(fnd_msg_pub.get
908 (fnd_msg_pub.G_NEXT,
909 fnd_api.G_FALSE), 1, 512);
910 end loop;
911
912 fnd_msg_pub.delete_msg();
913
914 else
915 X_mesg_count := 0;
916 X_mesg_string := 'NONE';
917 end if;
918
919 end fafbgcc_proc_msg;
920
921 END FA_GCCID_PKG;