DBA Data[Home] [Help]

PACKAGE BODY: APPS.GCS_PERIOD_INIT_PKG

Source


1 PACKAGE BODY GCS_PERIOD_INIT_PKG AS
2 /* $Header: gcspinib.pls 120.4 2007/05/15 21:33:40 skamdar ship $ */
3 
4   --
5   -- GLOBAL DATA TYPES
6   --
7 
8   --Bugfix 5449718: Add Net To RE Information to PL/SQL Record
9   TYPE r_entry_info IS RECORD
10 			(category_code           VARCHAR2(50),
11 			 num_init_stat_sources   NUMBER(15),
12 			 num_recur_sources       NUMBER(15),
13 			 num_recur_stat_sources  NUMBER(15),
14                          net_to_re_flag          VARCHAR2(1));
15   TYPE t_entry_info IS TABLE OF r_entry_info;
16 
17   --
18   -- PRIVATE GLOBAL VARIABLES
19   --
20   g_api      VARCHAR2(40) := 'gcs.plsql.GCS_PERIOD_INIT_PKG';
21 
22   g_entry_info t_entry_info;
23 
24   --
25   -- PRIVATE EXCEPTIONS
26   --
27   GCS_PI_ENTRY_FAILURE	EXCEPTION;
28 
29   --
30   -- PRIVATE FUNCTIONS
31   --
32 
33   --
34   -- Function
35   --   prepare_entry_header
36   -- Purpose
37   --   Create a period initialization/recurring entry if not already exists,
38   --   else clean up its entry lines. Return the entry id found or created.
39   --
40   FUNCTION prepare_entry_header(
41     p_errbuf              OUT NOCOPY VARCHAR2,
42     p_retcode             OUT NOCOPY VARCHAR2,
43     p_hierarchy_id        NUMBER,
44     p_entity_id           NUMBER,
45     p_currency_code       VARCHAR2,
46     p_start_cal_period_id NUMBER,
47     p_end_cal_period_id   NUMBER,
48     p_balance_type_code   VARCHAR2,
49     p_category_code       VARCHAR2) RETURN NUMBER
50   IS
51     fn_name                VARCHAR2(30) := 'PREPARE_ENTRY_HEADER';
52 
53     l_entry_id             NUMBER;
54     l_entry_existed        VARCHAR2(1);
55 
56     l_target_entity_code   VARCHAR2(30);
57     l_is_elim_entity       VARCHAR2(1);
58     l_cons_entity_id       NUMBER;
59     l_query_entity_id      NUMBER; -- Use the parent entity id if this is
60                                    -- an elimination entity with the target
61                                    -- entity code 'PARENT'
62 
63     CURSOR find_entry(c_entity_id NUMBER) IS
64       SELECT min(entry_id), decode(min(entry_id), NULL, 'N', 'Y')
65       FROM   GCS_ENTRY_HEADERS
66       WHERE  hierarchy_id = p_hierarchy_id
67       AND    entity_id = c_entity_id
68       AND    currency_code = p_currency_code
69       AND    balance_type_code = p_balance_type_code
70       AND    start_cal_period_id = p_start_cal_period_id
71       AND    nvl(end_cal_period_id, -1) = nvl(p_end_cal_period_id, -1)
72       AND    category_code = p_category_code
73       AND    period_init_entry_flag = 'Y';
74   BEGIN
75     IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
76       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
77                      g_api || '.' || fn_name,
78                      GCS_UTILITY_PKG.g_module_enter || fn_name ||
79                      to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
80     END IF;
81     --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_enter ||
82     --                 fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
83 
84     -- Initialize this, and overwrite if necessary
85     l_query_entity_id := p_entity_id;
86 
87     SELECT target_entity_code
88     INTO   l_target_entity_code
89     FROM   gcs_categories_b
90     WHERE  category_code = p_category_code;
91 
92     IF (l_target_entity_code = 'PARENT') THEN
93       SELECT nvl(decode(dim_attribute_varchar_member, 'E', 'Y', 'N'), 'N')
94       INTO   l_is_elim_entity
95       FROM   FEM_ENTITIES_ATTR
96       WHERE  attribute_id = GCS_UTILITY_PKG.g_dimension_attr_info
97                             ('ENTITY_ID-ENTITY_TYPE_CODE').attribute_id
98       AND    version_id = GCS_UTILITY_PKG.g_dimension_attr_info
99                             ('ENTITY_ID-ENTITY_TYPE_CODE').version_id
100       AND    entity_id = p_entity_id
101       AND    value_set_id = GCS_UTILITY_PKG.g_gcs_dimension_info
102                             ('ENTITY_ID').associated_value_set_id;
103 
104       IF (l_is_elim_entity = 'Y') THEN
105         SELECT oper_fea.dim_attribute_numeric_member
106         INTO   l_query_entity_id
107         FROM   fem_entities_attr oper_fea,
108                fem_entities_attr elim_fea
109         WHERE  elim_fea.attribute_id = GCS_UTILITY_PKG.g_dimension_attr_info
110                                        ('ENTITY_ID-ELIMINATION_ENTITY').attribute_id
111         AND    elim_fea.version_id = GCS_UTILITY_PKG.g_dimension_attr_info
112                                        ('ENTITY_ID-ELIMINATION_ENTITY').version_id
113         AND    elim_fea.value_set_id = GCS_UTILITY_PKG.g_gcs_dimension_info
114                                        ('ENTITY_ID').associated_value_set_id
115         AND    elim_fea.dim_attribute_numeric_member = p_entity_id
116         AND    oper_fea.entity_id = elim_fea.entity_id
117         AND    oper_fea.attribute_id = GCS_UTILITY_PKG.g_dimension_attr_info
118                                        ('ENTITY_ID-OPERATING_ENTITY').attribute_id
119         AND    oper_fea.version_id = GCS_UTILITY_PKG.g_dimension_attr_info
120                                        ('ENTITY_ID-OPERATING_ENTITY').version_id
121         AND    oper_fea.value_set_id = GCS_UTILITY_PKG.g_gcs_dimension_info
122                                        ('ENTITY_ID').associated_value_set_id;
123       END IF;
124     END IF;
125 
126     OPEN find_entry(l_query_entity_id);
127     FETCH find_entry INTO l_entry_id, l_entry_existed;
128     CLOSE find_entry;
129 
130     IF (l_entry_existed = 'N') THEN
131       -- need a new entry header
132       GCS_ENTRY_PKG.create_entry_header(
133         p_errbuf, p_retcode,
134         l_entry_id,
135         p_hierarchy_id,
136         l_query_entity_id,
137         p_start_cal_period_id,
138         p_end_cal_period_id,
139         'AUTOMATIC',
140         p_balance_type_code,
141         p_currency_code,
142         'ALL_RUN_FOR_PERIOD',
143         p_category_code,
144         null, null, 'Y');
145 
146       IF (p_retcode = fnd_api.g_ret_sts_unexp_error) THEN
147         RAISE GCS_PI_ENTRY_FAILURE;
148       END IF;
149 
150     ELSIF (l_entry_existed = 'Y') THEN
151       -- clear original entry lines
152       DELETE FROM GCS_ENTRY_LINES
153       WHERE entry_id = l_entry_id;
154     END IF;
155 
156     RETURN l_entry_id;
157 
158   EXCEPTION
159     WHEN GCS_PI_ENTRY_FAILURE THEN
160       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EXCEPTION) THEN
161         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
162                        g_api || '.' || fn_name,
163                        GCS_UTILITY_PKG.g_module_failure || fn_name ||
164                        to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
165       END IF;
166       --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_failure ||
167       --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
168       RAISE GCS_PI_ENTRY_FAILURE;
169     WHEN OTHERS THEN
170       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
171         FND_LOG.STRING(FND_LOG.LEVEL_UNEXPECTED,
172                        g_api || '.' || fn_name,
173                        GCS_UTILITY_PKG.g_module_failure || fn_name ||
174                        to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
175       END IF;
176       --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_failure ||
177       --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
178       RAISE;
179   END prepare_entry_header;
180 
181   --
182   -- Procedure
183   --   maintain_entries
184   -- Purpose
185   --   Create or update the initialization and recurring entries.
186   --
187   PROCEDURE maintain_entries(
188     p_errbuf               OUT NOCOPY VARCHAR2,
189     p_retcode              OUT NOCOPY VARCHAR2,
190     p_run_name             VARCHAR2,
191     p_hierarchy_id         NUMBER,
192     p_entity_id            NUMBER,
193     p_currency_code        VARCHAR2,
194     p_is_elim_entity       VARCHAR2,
195     p_cons_entity_id       NUMBER,
196     p_cons_entity_curr     VARCHAR2,
197     p_translation_required VARCHAR2,
198     p_next_cal_period_id   NUMBER,
199     p_balance_type_code    VARCHAR2,
200     p_bal_by_org_flag      VARCHAR2,
201     p_sec_track_col_name   VARCHAR2,
202     p_re_template          GCS_TEMPLATES_PKG.TemplateRecord,
203     p_cross_year_flag      VARCHAR2,
204     p_cat_index            NUMBER,
205     --Bugfix 5449718: Added parameter to get the current calendar period year
206     p_cal_period_year      NUMBER)
207   IS
208     fn_name                VARCHAR2(30) := 'MAINTAIN_ENTRIES';
209 
210     l_category_code        VARCHAR2(30);
211     l_net_to_re_flag       VARCHAR2(30);
212 
213     l_last_cal_period_id   NUMBER;
214 
215     l_init_entry_id        NUMBER;
216     l_init_xlate_entry_id  NUMBER;
217     l_init_stat_entry_id   NUMBER;
218     l_recur_entry_id       NUMBER;
219     l_recur_xlate_entry_id NUMBER;
220     l_recur_stat_entry_id  NUMBER;
221 
222       CURSOR last_period_c IS
223       SELECT	lp.cal_period_id
224       FROM	fem_cal_periods_b lp,
225 		fem_cal_periods_b fp,
226 		fem_cal_periods_attr lp_year,
227 		fem_cal_periods_attr fp_year,
228 		fem_cal_periods_attr lp_num
229       WHERE	fp.cal_period_id = p_next_cal_period_id
230       AND	lp.dimension_group_id = fp.dimension_group_id
231       AND	lp.calendar_id = fp.calendar_id
232       AND	lp_year.cal_period_id = lp.cal_period_id
233       AND	lp_year.attribute_id = GCS_UTILITY_PKG.g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR').attribute_id
234       AND	lp_year.version_id = GCS_UTILITY_PKG.g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR').version_id
235       AND	fp_year.cal_period_id = fp.cal_period_id
236       AND	fp_year.attribute_id = GCS_UTILITY_PKG.g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR').attribute_id
237       AND	fp_year.version_id = GCS_UTILITY_PKG.g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR').version_id
238       AND	lp_year.number_assign_value = fp_year.number_assign_value
239       AND	lp_num.cal_period_id = lp.cal_period_id
240       AND	lp_num.attribute_id = GCS_UTILITY_PKG.g_dimension_attr_info('CAL_PERIOD_ID-GL_PERIOD_NUM').attribute_id
241       AND	lp_num.version_id = GCS_UTILITY_PKG.g_dimension_attr_info('CAL_PERIOD_ID-GL_PERIOD_NUM').version_id
242       ORDER BY lp_num.number_assign_value desc;
243 
244   BEGIN
245     IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
246       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
247                      g_api || '.' || fn_name,
248                      GCS_UTILITY_PKG.g_module_enter || fn_name ||
249                      to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
250     END IF;
251     --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_enter ||
252     --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
253 
254     l_category_code := g_entry_info(p_cat_index).category_code;
255 
256     --Bugfix 5449718: No longer need to query  Net to RE Flag as its available on g_entry_info
257     /*
258     SELECT	net_to_re_flag
259     INTO	l_net_to_re_flag
260     FROM	gcs_categories_b
261     WHERE	category_code = l_category_code;
262     */
263     l_net_to_re_flag := g_entry_info(p_cat_index).net_to_re_flag;
264 
265     --SKAMDAR: Added debugging statement
266     fnd_file.put_line(fnd_file.log, '<<<<<Maintain Entries>>>>');
267     fnd_file.put_line(fnd_file.log, 'Category Code: ' || l_category_code);
268     fnd_file.put_line(fnd_file.log, 'Net to RE Flag: ' || l_net_to_re_flag);
269     fnd_file.put_line(fnd_file.log, '<<<<<Maintain Entries>>>>');
270 
271     -- INITIALIZATION ENTRIES FOR NEXT PERIOD
272     -- entity-currency entry
273     IF (p_cross_year_flag <> 'Y' OR l_net_to_re_flag <> 'Y') THEN
274 
275       fnd_file.put_line(fnd_file.log, 'In the individual period area');
276 
277       l_init_entry_id := prepare_entry_header(
278 		p_errbuf, p_retcode, p_hierarchy_id, p_entity_id,
279 		p_currency_code, p_next_cal_period_id, p_next_cal_period_id,
280 		p_balance_type_code, l_category_code);
281 
282       --Bugfix 5449718: Removed calls to initialize the xlate entry as they are no longer required
283       /*
284       -- check if translation entry is required
285       IF (p_translation_required = 'Y') THEN
286         l_init_xlate_entry_id := prepare_entry_header(
287 		p_errbuf, p_retcode, p_hierarchy_id, p_entity_id,
288 		p_cons_entity_curr, p_next_cal_period_id, p_next_cal_period_id,
289 		p_balance_type_code, l_category_code);
290       END IF;
291       */
292 
293       -- check if STAT entry is required
294       IF (g_entry_info(p_cat_index).num_init_stat_sources > 0) THEN
295         l_init_stat_entry_id := prepare_entry_header(
296 		p_errbuf, p_retcode, p_hierarchy_id, p_entity_id,
297 		'STAT', p_next_cal_period_id, p_next_cal_period_id,
298 		p_balance_type_code, l_category_code);
299       END IF;
300 
301     -- CARRY-FORWARD RECURRING ENTRIES FOR NEXT YEAR
302     ELSE
303       fnd_file.put_line(fnd_file.log, 'Entering the carry forward area');
304 
305       -- Get the last period of the new year
306       OPEN last_period_c;
307       FETCH last_period_c INTO l_last_cal_period_id;
308       CLOSE last_period_c;
309 
310       -- check if entity-currency entry is required
311       IF (g_entry_info(p_cat_index).num_recur_sources > 0) THEN
312         l_recur_entry_id := prepare_entry_header(
313 		p_errbuf, p_retcode, p_hierarchy_id, p_entity_id,
314 		p_currency_code, p_next_cal_period_id, l_last_cal_period_id,
315 		p_balance_type_code, l_category_code);
316 
317         --Bugfix 5449718: Removed calls to initialize the xlate entry as they are no longer required
318         /*
319         -- check if translation entry is required
320         IF (p_translation_required = 'Y') THEN
321           l_recur_xlate_entry_id := prepare_entry_header(
322 		p_errbuf, p_retcode, p_hierarchy_id, p_entity_id,
323 		p_cons_entity_curr, p_next_cal_period_id, l_last_cal_period_id,
324 		p_balance_type_code, l_category_code);
325         END IF;
326         */
327       END IF;
328 
329       -- check if STAT entry is required
330       IF (g_entry_info(p_cat_index).num_recur_stat_sources > 0) THEN
331         l_recur_stat_entry_id := prepare_entry_header(
332 		p_errbuf, p_retcode, p_hierarchy_id, p_entity_id,
333 		'STAT', p_next_cal_period_id, l_last_cal_period_id,
334 		p_balance_type_code, l_category_code);
335       END IF;
336     END IF;  -- if cross year
337 
338     -- calculate the lines
339     GCS_PERIOD_INIT_DYNAMIC_PKG.insert_entry_lines(p_run_name,
340 						   p_hierarchy_id,
341 						   p_entity_id,
342 						   p_currency_code,
343 						   p_bal_by_org_flag,
344 						   p_sec_track_col_name,
345 						   p_is_elim_entity,
346 						   p_cons_entity_id,
347 						   p_re_template,
348 						   p_cross_year_flag,
349 						   l_category_code,
350 						   l_init_entry_id,
351 						   l_init_xlate_entry_id,
352 						   l_init_stat_entry_id,
353 						   l_recur_entry_id,
354 						   l_recur_xlate_entry_id,
355 						   l_recur_stat_entry_id,
356                                                    --Bugfix 5449718: Passing the calendar period year and net to re flag
357                                                    p_cal_period_year,
358                                                    l_net_to_re_flag);
359 
360     IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
361       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
362                      g_api || '.' || fn_name,
363                      GCS_UTILITY_PKG.g_module_success || fn_name ||
364                      to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
365     END IF;
366     --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_success ||
367     --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
368 
369   EXCEPTION
370     WHEN GCS_PI_ENTRY_FAILURE THEN
371       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EXCEPTION) THEN
372         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
373                        g_api || '.' || fn_name,
374                        GCS_UTILITY_PKG.g_module_failure || fn_name ||
375                        to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
376       END IF;
377       --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_failure ||
378       --                 fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
379       RAISE GCS_PI_ENTRY_FAILURE;
380     WHEN OTHERS THEN
381       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
382         FND_LOG.STRING(FND_LOG.LEVEL_UNEXPECTED,
383                        g_api || '.' || fn_name,
384                        GCS_UTILITY_PKG.g_module_failure || fn_name ||
385                        to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
386       END IF;
387       --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_failure ||
388       --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
389       RAISE;
390   END maintain_entries;
391 
392 
393   --
394   -- PUBLIC FUNCTIONS
395   --
396 
397   PROCEDURE Create_Period_Init_Entries(
398     p_errbuf               OUT NOCOPY VARCHAR2,
399     p_retcode              OUT NOCOPY VARCHAR2,
400     p_run_name             VARCHAR2,
401     p_hierarchy_id         NUMBER,
402     p_relationship_id      NUMBER,
403     p_entity_id            NUMBER,
404     p_cons_entity_id       NUMBER,
405     p_translation_required VARCHAR2,
406     p_cal_period_id        NUMBER,
407     p_balance_type_code    VARCHAR2,
408     p_category_code        VARCHAR2 DEFAULT NULL)
409   IS
410     fn_name                VARCHAR2(30) := 'CREATE_PERIOD_INIT_ENTRIES';
411 
412     l_bal_by_org_flag      VARCHAR2(1);
413     l_sec_track_col_name   VARCHAR2(30);
414     l_entity_curr          VARCHAR2(30);
415     l_cons_entity_curr     VARCHAR2(30);
416     l_is_elim_entity       VARCHAR2(1);
417     l_re_template          GCS_TEMPLATES_PKG.TemplateRecord;
418 
419     l_cal_period_info      GCS_UTILITY_PKG.r_cal_period_info;
420     l_last_period_of_year  VARCHAR2(1);
421   BEGIN
422     IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
423       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
424                      g_api || '.' || fn_name,
425                      GCS_UTILITY_PKG.g_module_enter || fn_name ||
426                      to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
427 
428       -- parameters passed in
429       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
430                      g_api || '.' || fn_name,
431                      'p_run_name = ' || p_run_name);
432       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
433                      g_api || '.' || fn_name,
434                      'p_hierarchy_id = ' || to_char(p_hierarchy_id));
435       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
436                      g_api || '.' || fn_name,
437                      'p_relationship_id = ' || to_char(p_relationship_id));
438       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
439                      g_api || '.' || fn_name,
440                      'p_entity_id = ' || to_char(p_entity_id));
441       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
442                      g_api || '.' || fn_name,
443                      'p_cons_entity_id = ' || to_char(p_cons_entity_id));
444       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
445                      g_api || '.' || fn_name,
446                      'p_translation_required = ' || p_translation_required);
447       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
448                      g_api || '.' || fn_name,
449                      'p_cal_period_id = ' || to_char(p_cal_period_id));
450       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
451                      g_api || '.' || fn_name,
452                      'p_balance_type_code = ' || p_balance_type_code);
453       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
454                      g_api || '.' || fn_name,
455                      'p_category_code = ' || p_category_code);
456     END IF;
457     --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_enter ||
458     --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
459 
460     -- In case of an error, roll back to this point
461     SAVEPOINT gcs_period_init_start;
462 
463     -- ***** Setup *****
464     g_fnd_user_id := fnd_global.user_id;
465     g_fnd_login_id := fnd_global.login_id;
466 
467     GCS_UTILITY_PKG.init_dimension_info;
468     GCS_UTILITY_PKG.init_dimension_attr_info;
469 
470     -- get entity and parent entity's currencies
471     SELECT currency_code
472     INTO   l_entity_curr
473     FROM   GCS_ENTITY_CONS_ATTRS
474     WHERE  hierarchy_id = p_hierarchy_id
475     AND    entity_id = p_entity_id;
476 
477     --Bugfix 5449718: We do not need to create initialized entries for translated results
478     --Commenting the query below
479     /*
480     IF (p_translation_required = 'Y') THEN
481       SELECT currency_code
482       INTO   l_cons_entity_curr
483       FROM   GCS_ENTITY_CONS_ATTRS
484       WHERE  hierarchy_id = p_hierarchy_id
485       AND    entity_id = p_cons_entity_id;
486     END IF;
487     */
488 
489     -- get hierarchy setting: balance by org and/or secondary dim
490     SELECT balance_by_org_flag, column_name
491     INTO   l_bal_by_org_flag, l_sec_track_col_name
492     FROM   gcs_hierarchies_b
493     WHERE  hierarchy_id = p_hierarchy_id;
494 
495     -- determine if the entity is an elimination entity
496     SELECT nvl(decode(dim_attribute_varchar_member, 'E', 'Y', 'N'), 'N')
497     INTO   l_is_elim_entity
498     FROM   FEM_ENTITIES_ATTR
499     WHERE  attribute_id = GCS_UTILITY_PKG.g_dimension_attr_info
500                           ('ENTITY_ID-ENTITY_TYPE_CODE').attribute_id
501     AND    version_id = GCS_UTILITY_PKG.g_dimension_attr_info
502                           ('ENTITY_ID-ENTITY_TYPE_CODE').version_id
503     AND    entity_id = p_entity_id
504     AND    value_set_id = GCS_UTILITY_PKG.g_gcs_dimension_info
505                           ('ENTITY_ID').associated_value_set_id;
506 
507     -- get retained earnings template
508     GCS_TEMPLATES_PKG.get_dimension_template(p_hierarchy_id, 'RE',
509                                              p_balance_type_code,
510                                              l_re_template);
511 
512     GCS_UTILITY_PKG.get_cal_period_details(p_cal_period_id,
513                                            l_cal_period_info);
514 
515     IF (l_cal_period_info.cal_period_number =
516                        l_cal_period_info.cal_periods_per_year) THEN
517       l_last_period_of_year := 'Y';
518     ELSE
519       l_last_period_of_year := 'N';
520     END IF;
521 
522     -- ***** Main Process *****
523     -- populate g_entry_info: find categories to be processed
524 
525     --Bugfix 5449718: Modify query into two separate queries for performance purposes
526     IF (l_is_elim_entity = 'Y') THEN
527       --If the entity passed from the engine is an elimination entity must generate period initializiation entries for any
528       --category that hits the parent or elimination entities
529       SELECT gcb.category_code,
530              count(gcerd.stat_entry_id),
531              count(decode(gcb.net_to_re_flag, 'N', null, gcerd.entry_id)),
532              count(decode(gcb.net_to_re_flag, 'N', null, gcerd.stat_entry_id)),
533              min(gcb.net_to_re_flag)
534       BULK COLLECT INTO g_entry_info
535       FROM   gcs_cons_eng_run_dtls gcerd,
536              gcs_categories_b      gcb
537       WHERE  gcerd.run_name                  = p_run_name
538       AND    gcerd.consolidation_entity_id   = p_cons_entity_id
539       AND    gcerd.child_entity_id           IS NOT NULL
540       AND    gcerd.category_code             = gcb.category_code
541       AND    gcb.target_entity_code         IN ('PARENT', 'ELIMINATION')
542       GROUP  BY gcb.category_code;
543 
544     ELSE
545       --If the entity passed is an operating entity you should only process categories where the target is a child
546       SELECT gcb.category_code,
547              count(gcerd.stat_entry_id),
548              count(decode(gcb.net_to_re_flag, 'N', null, gcerd.entry_id)),
549              count(decode(gcb.net_to_re_flag, 'N', null, gcerd.stat_entry_id)),
550              min(gcb.net_to_re_flag)
551       BULK COLLECT INTO g_entry_info
552       FROM   gcs_cons_eng_run_dtls gcerd,
553              gcs_categories_b      gcb
554       WHERE  gcerd.run_name                  = p_run_name
555       AND    gcerd.consolidation_entity_id   = p_cons_entity_id
556       AND    gcerd.child_entity_id           = p_entity_id
557       AND    gcerd.category_code             = gcb.category_code
558       AND    gcb.target_entity_code          = 'CHILD'
559       --Bugfix 6037112
560       AND    gcb.category_type_code          <> 'PROCESS'
561       GROUP  BY gcb.category_code;
562     END IF;
563 
564     -- Process by category
565     FOR cat_index IN 1..g_entry_info.COUNT LOOP
566       --Bugfix 5449718: Added the current calendar period year as a parameter
567       maintain_entries(p_errbuf,
568                        p_retcode,
569                        p_run_name,
570                        p_hierarchy_id,
571                        p_entity_id,
572                        l_entity_curr,
573                        l_is_elim_entity,
574                        p_cons_entity_id,
575                        l_cons_entity_curr,
576                        p_translation_required,
577                        l_cal_period_info.next_cal_period_id,
578                        p_balance_type_code,
579                        l_bal_by_org_flag,
580                        l_sec_track_col_name,
581                        l_re_template,
582                        l_last_period_of_year,
583                        cat_index,
584                        l_cal_period_info.cal_period_year);
585     END LOOP;
586 
587     IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_PROCEDURE) THEN
588       FND_LOG.STRING(FND_LOG.LEVEL_PROCEDURE,
589                      g_api || '.' || fn_name,
590                      GCS_UTILITY_PKG.g_module_success || fn_name ||
591                      to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
592     END IF;
593     --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_success ||
594     --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
595 
596   EXCEPTION
597     WHEN GCS_PI_ENTRY_FAILURE THEN
598       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EXCEPTION) THEN
599         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
600                        g_api || '.' || fn_name,
601                        GCS_UTILITY_PKG.g_module_failure || fn_name ||
602                        to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
603       END IF;
604       --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_failure ||
605       --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
606 
607       ROLLBACK TO gcs_period_init_start;
608       -- p_errbuf and p_retcode are set by GCS_ENTRY_PKG.create_entry_header()
609     WHEN NO_DATA_FOUND THEN
610       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_EXCEPTION) THEN
611         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
612                        g_api || '.' || fn_name,
613                        'Entity Curr = ' || l_entity_curr);
614         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
615                        g_api || '.' || fn_name,
616                        'Cons Entity Curr = ' || l_cons_entity_curr);
617         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
618                        g_api || '.' || fn_name,
619                        'Balance By Org Flag = ' || l_bal_by_org_flag);
620         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
621                        g_api || '.' || fn_name,
622                        'Secondary Tracking Column = ' || l_sec_track_col_name);
623         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
624                        g_api || '.' || fn_name,
625                        'Is Elimination Entity = ' || l_is_elim_entity);
626 
627         FND_LOG.STRING(FND_LOG.LEVEL_EXCEPTION,
628                        g_api || '.' || fn_name,
629                        GCS_UTILITY_PKG.g_module_failure || fn_name ||
630                        to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
631       END IF;
632       --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_failure ||
633       --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
634 
635       ROLLBACK TO gcs_period_init_start;
636       p_errbuf := 'GCS_PI_NO_DATA_FOUND';
637       p_retcode := '2';
638     WHEN OTHERS THEN
639       IF (FND_LOG.G_CURRENT_RUNTIME_LEVEL <= FND_LOG.LEVEL_UNEXPECTED) THEN
640         FND_LOG.STRING(FND_LOG.LEVEL_UNEXPECTED,
641                        g_api || '.' || fn_name,
642                        SUBSTR(SQLERRM, 1, 4000));
643         FND_LOG.STRING(FND_LOG.LEVEL_UNEXPECTED,
644                        g_api || '.' || fn_name,
645                        GCS_UTILITY_PKG.g_module_failure || fn_name ||
646                        to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
647       END IF;
648       --FND_FILE.PUT_LINE(FND_FILE.LOG, GCS_UTILITY_PKG.g_module_failure ||
649       --                  fn_name || to_char(sysdate, ' DD-MON-YYYY HH:MI:SS'));
650 
651       ROLLBACK TO gcs_period_init_start;
652       p_errbuf := 'GCS_PI_UNHANDLED_EXCEPTION';
653       p_retcode := '2';
654   END Create_Period_Init_Entries;
655 
656 END GCS_PERIOD_INIT_PKG;