DBA Data[Home] [Help]

PACKAGE BODY: APPS.GCS_ENTRY_PKG

Source


1 PACKAGE BODY GCS_ENTRY_PKG AS
2   /* $Header: gcsentryb.pls 120.12 2007/10/17 22:27:17 skamdar ship $ */
3   --
4   -- PRIVATE GLOBAL VARIABLES
5   --
6   -- The API name
7   g_pkg_name CONSTANT VARCHAR2(30) := 'gcs.plsql.GCS_ENTRY_PKG';
8   -- dimension info from gcs_utility_pkg
9   g_dimension_attr_info gcs_utility_pkg.t_hash_dimension_attr_info := gcs_utility_pkg.g_dimension_attr_info;
10   g_gcs_dimension_info  gcs_utility_pkg.t_hash_gcs_dimension_info := gcs_utility_pkg.g_gcs_dimension_info;
11   -- A newline character. Included for convenience when writing long strings.
12   g_nl VARCHAR2(1) := '
13 ';
14   -- session id
15   g_session_id NUMBER;
16   -- Record to store entry name and description
17   TYPE r_entry_header IS RECORD(
18     NAME        VARCHAR2(80),
19     description VARCHAR2(240));
20   no_re_template_error EXCEPTION;
21   invalid_entity_error EXCEPTION;
22   invalid_rule_error EXCEPTION;
23   import_header_error EXCEPTION;
24   --
25   -- PRIVATE PROCEDURES
26   --
27   ---------------------------------------------------------------------------
28   --  Enhancement : 6416736, Created a new procedure
29   -- Procedure
30   --   import_hier_grp_entry()
31   -- Purpose
32   --   Inserts rows into gcs_entry_headers and gcs_entry_lines,
33   --   for all the hierarchies in the chosen hierarchy group
34   -- Arguments
35   --   p_entry_id            Entry ID
36   --   p_end_cal_period_id   End Calendar Period ID
37   --   p_hierarchy_grp_id    Hierarchy Group ID
38   --   p_entity_id           Entity ID associated with process (parent entity in case of rules)
39   --   p_start_cal_period_id Start Calendar Period ID
40   --   p_currency_code       Currency Code of Entry
41   --   p_process_code        Process COde for ther Entry
42   --   p_description         Description of the Entry
43   --   p_entry_name          Name of the Entry
44   --   p_category_code       Category Code
45   --   p_balance_type_code   Balance Type Code
46   --   p_ledger_id           Ledger ID for Writeback
47   --   p_cal_period_name     Calendar Period Name for Writeback
48   --   p_conversion_type     Conversion Type for Writeback
49   -- Notes
50   --
51 
52   /*
53   ** import_hier_grp_entry
54   */
55   PROCEDURE import_hier_grp_entry(p_entry_id            IN NUMBER,
56                                   p_end_cal_period_id   IN VARCHAR2,
57                                   p_hierarchy_grp_id    IN NUMBER,
58                                   p_entity_id           IN NUMBER,
59                                   p_start_cal_period_id IN VARCHAR2,
60                                   p_currency_code       IN VARCHAR2,
61                                   p_process_code        IN VARCHAR2,
62                                   p_description         IN VARCHAR2,
63                                   p_entry_name          IN VARCHAR2,
64                                   p_category_code       IN VARCHAR2,
65                                   p_balance_type_code   IN VARCHAR2,
66                                   p_ledger_id           IN VARCHAR2,
67                                   p_cal_period_name     IN VARCHAR2,
68                                   p_conversion_type     IN VARCHAR2) IS
69 
70     TYPE l_hierarchy_id_tbl_type IS TABLE OF GCS_HIERARCHIES_B.HIERARCHY_ID%TYPE INDEX BY BINARY_INTEGER;
71     l_hierarchy_id l_hierarchy_id_tbl_type;
72 
73     TYPE l_entry_id_tbl_type IS TABLE OF GCS_ENTRY_HEADERS.ENTRY_ID%TYPE INDEX BY BINARY_INTEGER;
74     l_entry_id l_entry_id_tbl_type;
75 
76     l_api_name            VARCHAR2(30) := 'IMPORT_HIER_GRP_ENTRY';
77     l_end_cal_period_id   NUMBER;
78     l_start_cal_period_id NUMBER;
79     l_net_to_re_flag      VARCHAR2(1);
80     l_entry_type_code     VARCHAR2(30);
81     l_balance_code        VARCHAR2(30);
82     l_entity_id           NUMBER(15);
83     l_precision           NUMBER(15, 5);
84     l_year_to_apply_re    NUMBER(4) := NULL;
85     l_event_name          VARCHAR2(100) := 'oracle.apps.gcs.transaction.adjustment.update';
86     l_event_key           VARCHAR2(100) := NULL;
87     l_parameter_list      wf_parameter_list_t;
88     l_user_id             NUMBER := fnd_global.user_id;
89     l_login_id            NUMBER := fnd_global.login_id;
90     l_wf_itemkey          VARCHAR2(100);
91 
92   BEGIN
93 
94     l_end_cal_period_id   := to_number(p_end_cal_period_id);
95     l_start_cal_period_id := to_number(p_start_cal_period_id);
96 
97     SAVEPOINT gcs_import_hier_grp_start;
98 
99     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
100       fnd_log.STRING(fnd_log.level_procedure,
101                      g_pkg_name || '.' || l_api_name,
102                      gcs_utility_pkg.g_module_enter || ' ' || l_api_name ||
103                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
104     END IF;
105 
106     IF fnd_log.g_current_runtime_level <= fnd_log.level_statement THEN
107       fnd_log.STRING(fnd_log.level_statement,
108                      g_pkg_name || '.' || l_api_name,
109                      'SELECT net_to_re_flag' || g_nl ||
110                      'INTO l_net_to_re_flag' || g_nl ||
111                      'FROM gcs_categories_b' || g_nl ||
112                      'WHERE category_code = ' || p_category_code);
113     END IF;
114 
115     SELECT net_to_re_flag
116       INTO l_net_to_re_flag
117       FROM gcs_categories_b
118      WHERE category_code = p_category_code;
119 
120     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
121       fnd_log.STRING(fnd_log.level_procedure,
122                      g_pkg_name || '.' || l_api_name,
123                      'SELECT CASE fcpa_start_year.number_assign_value
124                 WHEN NVL (fcpa_end_year.number_assign_value, 0)
125                    THEN NULL
126                 ELSE fcpa_start_year.number_assign_value + 1
127              END
128         INTO l_year_to_apply_re
129         FROM fem_cal_periods_attr fcpa_start_year,
130              fem_cal_periods_attr fcpa_end_year
131        WHERE fcpa_start_year.cal_period_id = ' ||
132                       l_start_cal_period_id || '
133          AND fcpa_start_year.attribute_id = ' ||
134                       g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
135                      .attribute_id || '
136          AND fcpa_start_year.version_id = ' ||
137                       g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
138                      .version_id || '
139          AND fcpa_end_year.cal_period_id(+) = ' ||
140                       l_end_cal_period_id || '
141          AND fcpa_end_year.attribute_id(+) = fcpa_start_year.attribute_id
142          AND fcpa_end_year.version_id(+) = fcpa_start_year.version_id');
143     END IF;
144 
145     IF (l_net_to_re_flag = 'N') THEN
146       l_year_to_apply_re := NULL;
147     ELSIF (l_end_cal_period_id = l_start_cal_period_id) THEN
148       l_year_to_apply_re := NULL;
149     ELSE
150       SELECT CASE fcpa_start_year.number_assign_value
151                WHEN NVL(fcpa_end_year.number_assign_value, 0) THEN
152                 NULL
153                ELSE
154                 fcpa_start_year.number_assign_value + 1
155              END
156         INTO l_year_to_apply_re
157         FROM fem_cal_periods_attr fcpa_start_year,
158              fem_cal_periods_attr fcpa_end_year
159        WHERE fcpa_start_year.cal_period_id = l_start_cal_period_id
160          AND fcpa_start_year.attribute_id =
161              g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
162       .attribute_id
163          AND fcpa_start_year.version_id =
164              g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
165       .version_id
166          AND fcpa_end_year.cal_period_id(+) = l_end_cal_period_id
167          AND fcpa_end_year.attribute_id(+) = fcpa_start_year.attribute_id
168          AND fcpa_end_year.version_id(+) = fcpa_start_year.version_id;
169     END IF;
170 
171     -- Retreive the hierarchies , present in teh chosen hierarchy group
172     -- Create a new entry ID for each of the hierarchy
173     SELECT hierarchy_id, gcs_entry_headers_s.NEXTVAL BULK COLLECT
174       INTO l_hierarchy_id, l_entry_id
175       FROM gcs_hier_grp_members
176      WHERE hierarchy_grp_id = p_hierarchy_grp_id;
177 
178     -- Insert the header information of the adjustment into gcs_entry_headers, for all of the hierarchies
179     FORALL l_counter IN l_hierarchy_id.FIRST .. l_hierarchy_id.LAST
180       INSERT INTO gcs_entry_headers
181         (entry_id,
182          entry_name,
183          hierarchy_id,
184          disabled_flag,
185          entity_id,
186          currency_code,
187          balance_type_code,
188          start_cal_period_id,
189          end_cal_period_id,
190          year_to_apply_re,
191          description,
192          entry_type_code,
193          assoc_entry_id,
194          processed_run_name,
195          category_code,
196          process_code,
197          creation_date,
198          created_by,
199          last_update_date,
200          last_updated_by,
201          last_update_login,
202          period_init_entry_flag)
203       VALUES
204         (l_entry_id(l_counter),
205          p_entry_name,
206          l_hierarchy_id(l_counter),
207          'N',
208          p_entity_id,
209          p_currency_code,
210          p_balance_type_code,
211          l_start_cal_period_id,
212          l_end_cal_period_id,
213          l_year_to_apply_re,
214          p_description,
215          'MANUAL',
216          null,
217          null,
218          p_category_code,
219          p_process_code,
220          sysdate,
221          l_user_id,
222          sysdate,
223          l_user_id,
224          l_user_id,
225          'N');
226 
227     -- Insert the lines information of the adjustment into gcs_entry_lines,
228     -- for all of the hierarchies
229 
230     FORALL l_counter IN l_entry_id.FIRST .. l_entry_id.LAST EXECUTE
231                                             IMMEDIATE
232                                             'INSERT INTO gcs_entry_lines(
233                           entry_id ,
234                           line_type_code,
235                           description ,
236                           company_cost_center_org_id,
237                           financial_elem_id,
238                           product_id ,
239                           natural_account_id,
240                           channel_id ,
241                           line_item_id,
242                           project_id ,
243                           customer_id,
244                           intercompany_id ,
245                           task_id ,
246                           user_dim1_id,
247                           user_dim2_id,
248                           user_dim3_id,
249                           user_dim4_id,
250                           user_dim5_id,
251                           user_dim6_id,
252                           user_dim7_id,
253                           user_dim8_id,
254                           user_dim9_id,
255                           user_dim10_id ,
256                           xtd_balance_e,
257                           ytd_balance_e ,
258                           ptd_debit_balance_e ,
259                           ptd_credit_balance_e,
260                           ytd_debit_balance_e ,
261                           ytd_credit_balance_e,
262                           creation_date ,
263                           created_by,
264                           last_update_date,
265                           last_updated_by ,
266                           last_update_login,
267                           entry_line_number )
268                   SELECT  :1,
269                           line_type_code,
270                           description ,
271                           company_cost_center_org_id,
272                           financial_elem_id,
273                           product_id ,
274                           natural_account_id,
275                           channel_id ,
276                           line_item_id,
277                           project_id ,
278                           customer_id,
279                           intercompany_id ,
280                           task_id ,
281                           user_dim1_id,
282                           user_dim2_id,
283                           user_dim3_id,
284                           user_dim4_id,
285                           user_dim5_id,
286                           user_dim6_id,
287                           user_dim7_id,
288                           user_dim8_id,
289                           user_dim9_id,
290                           user_dim10_id ,
291                           xtd_balance_e ,
292                           ytd_balance_e ,
293                           ptd_debit_balance_e,
294                           ptd_credit_balance_e,
295                           ytd_debit_balance_e ,
296                           ytd_credit_balance_e,
297                           creation_date ,
298                           created_by,
299                           last_update_date,
300                           last_updated_by ,
301                           last_update_login,
302                           entry_line_number
303                     FROM  gcs_entry_lines
304                    WHERE  entry_id  = :2 '
305                                             USING l_entry_id(l_counter),
306                                             p_entry_id
307       ;
308 
309     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
310       fnd_log.STRING(fnd_log.level_procedure,
311                      g_pkg_name || '.' || l_api_name,
312                      'SELECT decode(start_cal_period_id, end_cal_period_id, ''ONE_TIME'',
313                     ''RECURRING''), year_to_apply_re, hierarchy_id, balance_type_code,
314                     entity_id, NVL (minimum_accountable_unit, POWER (10, -PRECISION))' || g_nl ||
315                      'INTO l_entry_type_code, l_year_to_apply_re, l_hierarchy_id,
316                  l_balance_code, l_entity_id, l_precision' || g_nl ||
317                      'FROM fnd_currencies fc, gcs_entry_headers geh' || g_nl ||
318                      'WHERE fc.currency_code = geh.currency_code ' || g_nl ||
319                      'AND geh.entry_id = ' || l_entry_id(1));
320     END IF;
321 
322     SELECT DECODE(start_cal_period_id,
323                   end_cal_period_id,
324                   'ONE_TIME',
325                   'RECURRING'),
326            NVL(minimum_accountable_unit, POWER(10, -PRECISION))
327       INTO l_entry_type_code, l_precision
328       FROM fnd_currencies fc, gcs_entry_headers geh
329      WHERE fc.currency_code = geh.currency_code
330        AND geh.entry_id = l_entry_id(1);
331 
332     IF (l_entry_type_code = 'RECURRING') THEN
333       FORALL l_counter IN l_entry_id.FIRST .. l_entry_id.LAST
334         UPDATE gcs_entry_lines
335            SET ytd_debit_balance_e  = ROUND(ytd_debit_balance_e /
336                                             l_precision) * l_precision,
337                ytd_credit_balance_e = ROUND(ytd_credit_balance_e /
338                                             l_precision) * l_precision,
339                ytd_balance_e        = ROUND(nvl(ytd_debit_balance_e, 0) /
340                                             l_precision) * l_precision -
341                                       ROUND(nvl(ytd_credit_balance_e, 0) /
342                                             l_precision) * l_precision,
343                line_type_code       = CASE WHEN (SELECT feata.dim_attribute_varchar_member
344                              FROM fem_ext_acct_types_attr feata,
345                                   fem_ln_items_attr       flia
346                             WHERE gcs_entry_lines.line_item_id =
347                                   flia.line_item_id
348                               AND flia.value_set_id =
349                                   g_gcs_dimension_info('LINE_ITEM_ID')
350                            .associated_value_set_id
351                               AND flia.attribute_id =
352                                   g_dimension_attr_info('LINE_ITEM_ID-EXTENDED_ACCOUNT_TYPE')
353                            .attribute_id
354                               AND feata.attribute_id =
355                                   g_dimension_attr_info('EXT_ACCOUNT_TYPE_CODE-BASIC_ACCOUNT_TYPE_CODE')
356                            .attribute_id
357                               AND flia.version_id =
358                                   g_dimension_attr_info('LINE_ITEM_ID-EXTENDED_ACCOUNT_TYPE')
359                            .version_id
360                               AND feata.version_id =
361                                   g_dimension_attr_info('EXT_ACCOUNT_TYPE_CODE-BASIC_ACCOUNT_TYPE_CODE')
362                            .version_id
363                               AND feata.DIM_ATTRIBUTE_NUMERIC_MEMBER IS NULL
364                               AND feata.ext_account_type_code =
365                                   flia.dim_attribute_varchar_member) IN ('REVENUE', 'EXPENSE') THEN 'PROFIT_LOSS' ELSE 'BALANCE_SHEET' END
366          WHERE entry_id = l_entry_id(l_counter);
367 
368       IF l_year_to_apply_re IS NOT NULL THEN
369         FOR l_counter IN l_entry_id.FIRST .. l_entry_id.LAST LOOP
370 
371           gcs_templates_dynamic_pkg.calculate_re(p_entry_id      => l_entry_id(l_counter),
372                                                  p_hierarchy_id  => l_hierarchy_id(l_counter),
373                                                  p_bal_type_code => p_balance_type_code,
374                                                  p_entity_id     => p_entity_id);
375         END LOOP;
376       END IF;
377     ELSE
378       FORALL l_counter IN l_entry_id.FIRST .. l_entry_id.LAST
379         UPDATE gcs_entry_lines
380            SET ytd_debit_balance_e  = ROUND(ytd_debit_balance_e /
381                                             l_precision) * l_precision,
382                ytd_credit_balance_e = ROUND(ytd_credit_balance_e /
383                                             l_precision) * l_precision,
384                ytd_balance_e        = ROUND(nvl(ytd_debit_balance_e, 0) /
385                                             l_precision) * l_precision -
386                                       ROUND(nvl(ytd_credit_balance_e, 0) /
387                                             l_precision) * l_precision
388          WHERE entry_id = l_entry_id(l_counter);
389     END IF;
390 
391     FOR l_counter IN l_entry_id.FIRST .. l_entry_id.LAST LOOP
392       -- Enhancement for Adjustment Approval Process
393       IF fnd_profile.value('AME_INSTALLED_FLAG') = 'Y' THEN
394         GCS_ADJ_APPROVAL_WF_PKG.create_gcsadj_process(p_entry_id        => l_entry_id(l_counter),
395                                                       p_user_id         => fnd_global.user_id,
396                                                       p_user_name       => fnd_global.user_name,
397                                                       p_orig_entry_id   => l_entry_id(l_counter),
398                                                       p_ledger_id       => to_number(p_ledger_id),
399                                                       p_cal_period_name => p_cal_period_name,
400                                                       p_conversion_type => p_conversion_type,
401                                                       p_writeback_flag  => 'N',
402                                                       p_wfitemkey       => l_wf_itemkey);
403 
404       ELSE
405         wf_event.addparametertolist(p_name          => 'ENTRY_ID',
406                                     p_value         => l_entry_id(l_counter),
407                                     p_parameterlist => l_parameter_list);
408         BEGIN
409           FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
410                             g_pkg_name || '.' || l_api_name ||
411                             ' RAISE WF_EVENT');
412           FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
413           wf_event.RAISE(p_event_name => l_event_name,
414                          p_event_key  => l_event_key,
415                          p_parameters => l_parameter_list);
416         EXCEPTION
417           WHEN OTHERS THEN
418             FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
419                               g_pkg_name || '.' || l_api_name ||
420                               ' ERROR : ' || SQLERRM);
421             FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
422             IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
423               fnd_log.STRING(fnd_log.level_error,
424                              g_pkg_name || '.' || l_api_name,
425                              ' wf_event.raise failed ' || ' ' ||
426                              TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
427             END IF;
428         END;
429       END IF;
430 
431     END LOOP;
432 
433     -- Delete the rows in the gcs_entry_lines table (lines information) as the same data
434     -- is pushed for all of the hierarchies (present in the chosen hierarchy group).
435 
436     DELETE FROM gcs_entry_lines WHERE entry_id = p_entry_id;
437 
438     -- Write the appropriate information to the execution report
439     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
440       fnd_log.STRING(fnd_log.level_procedure,
441                      g_pkg_name || '.' || l_api_name,
442                      gcs_utility_pkg.g_module_success || ' ' || l_api_name ||
443                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
444     END IF;
445 
446   EXCEPTION
447     WHEN OTHERS THEN
448 
449       ROLLBACK TO gcs_import_hier_grp_start;
450       fnd_message.set_name('GCS', 'GCS_ENTRY_UNEXPECTED_ERR');
451       -- Write the appropriate information to the execution report
452 
453       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
454         fnd_log.STRING(fnd_log.level_error,
455                        g_pkg_name || '.' || l_api_name,
456                        gcs_utility_pkg.g_module_failure || ' ' || SQLERRM || ' ' ||
457                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
458         fnd_log.STRING(fnd_log.level_error,
459                        g_pkg_name || '.' || l_api_name,
460                        gcs_utility_pkg.g_module_failure || ' ' ||
461                        l_api_name || '() ' ||
462                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
463 
464         RAISE import_header_error;
465       END IF;
466 
467   END import_hier_grp_entry;
468 
469   /*
470   ** import_entry_headers
471   */
472   PROCEDURE import_entry_headers(p_entry_id            IN NUMBER,
473                                  p_end_cal_period_id   IN VARCHAR2,
474                                  p_hierarchy_id        IN NUMBER,
475                                  p_entity_id           IN NUMBER,
476                                  p_start_cal_period_id IN VARCHAR2,
477                                  p_currency_code       IN VARCHAR2,
478                                  p_process_code        IN VARCHAR2,
479                                  p_description         IN VARCHAR2,
480                                  p_entry_name          IN VARCHAR2,
481                                  p_category_code       IN VARCHAR2,
482                                  p_balance_type_code   IN VARCHAR2,
483                                  p_new_entry_id        IN NUMBER,
484                                  p_entry_lines_id      IN OUT NOCOPY NUMBER,
485                                  p_orig_entry_id       IN OUT NOCOPY NUMBER) IS
486     l_processed_entry_flag VARCHAR2(1);
487     l_existed_entry_flag   VARCHAR2(1);
488     l_new_entry_id         NUMBER(15);
489     l_end_cal_period_id    NUMBER;
490     l_start_cal_period_id  NUMBER;
491     -- l_balance_type_code      VARCHAR2 (30);
492     l_line_type_code   VARCHAR(30) := NULL;
493     l_year_to_apply_re NUMBER(4) := NULL;
494     l_errbuf           VARCHAR2(200);
495     l_retcode          VARCHAR2(1);
496     l_api_name         VARCHAR2(30) := 'IMPORT_ENTRY_HEADERS';
497 
498     --Bugfix 5449718: Added check for net to RE Flag
499     l_net_to_re_flag VARCHAR2(1);
500 
501   BEGIN
502     l_end_cal_period_id   := to_number(p_end_cal_period_id);
503     l_start_cal_period_id := to_number(p_start_cal_period_id);
504     FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
505                       g_pkg_name || '.' || l_api_name || ' ENTER');
506     FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
507     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
508       fnd_log.STRING(fnd_log.level_procedure,
509                      g_pkg_name || '.' || l_api_name,
510                      gcs_utility_pkg.g_module_enter || ' ' || l_api_name ||
511                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
512     END IF;
513     -- In case of an error, we will roll back to this point in time.
514     SAVEPOINT gcs_entry_upload_headers_start;
515     -- Bug fix 3805520
516     -- only when end-start cross year end boundary
517     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
518       fnd_log.STRING(fnd_log.level_procedure,
519                      g_pkg_name || '.' || l_api_name,
520                      'SELECT CASE fcpa_start_year.number_assign_value
521                 WHEN NVL (fcpa_end_year.number_assign_value, 0)
522                    THEN NULL
523                 ELSE fcpa_start_year.number_assign_value + 1
524              END
525         INTO l_year_to_apply_re
526         FROM fem_cal_periods_attr fcpa_start_year,
527              fem_cal_periods_attr fcpa_end_year
528        WHERE fcpa_start_year.cal_period_id = ' ||
529                       l_start_cal_period_id || '
530          AND fcpa_start_year.attribute_id = ' ||
531                       g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
532                      .attribute_id || '
533          AND fcpa_start_year.version_id = ' ||
534                       g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
535                      .version_id || '
536          AND fcpa_end_year.cal_period_id(+) = ' ||
537                       l_end_cal_period_id || '
538          AND fcpa_end_year.attribute_id(+) = fcpa_start_year.attribute_id
539          AND fcpa_end_year.version_id(+) = fcpa_start_year.version_id');
540     END IF;
541     /***
542      -- determine the balance type
543      IF fnd_log.g_current_runtime_level <= fnd_log.level_statement THEN
544         fnd_log.STRING(fnd_log.level_statement,
545                g_pkg_name || '.' || l_api_name,
546                   'SELECT DECODE (COUNT (entry_id), 0, ''ACTUAL'', ''ADB'')'
547                || g_nl
548                || 'INTO l_balance_type_code'
549                || g_nl
550                || 'FROM gcs_entry_lines'
551                || g_nl
552                || 'WHERE entry_id = '||p_new_entry_id
553                || g_nl
554                || 'AND FINANCIAL_ELEM_ID = 140'
555               );
556      END IF;
557      SELECT DECODE (COUNT (entry_id), 0, 'ACTUAL', 'ADB')
558        INTO l_balance_type_code
559        FROM gcs_entry_lines
560       WHERE entry_id = p_new_entry_id AND financial_elem_id = 140;
561     ***/
562 
563     --Bugfix 5449718: Added check for net to re flag before populated l_year_to_apply_re
564     BEGIN
565 
566       SELECT net_to_re_flag
567         INTO l_net_to_re_flag
568         FROM gcs_categories_b
569        WHERE category_code = p_category_code;
570 
571       IF (l_net_to_re_flag = 'N') THEN
572         l_year_to_apply_re := NULL;
573       ELSIF (l_end_cal_period_id = l_start_cal_period_id) THEN
574         l_year_to_apply_re := NULL;
575       ELSE
576         SELECT CASE fcpa_start_year.number_assign_value
577                  WHEN NVL(fcpa_end_year.number_assign_value, 0) THEN
578                   NULL
579                  ELSE
580                   fcpa_start_year.number_assign_value + 1
581                END
582           INTO l_year_to_apply_re
583           FROM fem_cal_periods_attr fcpa_start_year,
584                fem_cal_periods_attr fcpa_end_year
585          WHERE fcpa_start_year.cal_period_id = l_start_cal_period_id
586            AND fcpa_start_year.attribute_id =
587                g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
588         .attribute_id
589            AND fcpa_start_year.version_id =
590                g_dimension_attr_info('CAL_PERIOD_ID-ACCOUNTING_YEAR')
591         .version_id
592            AND fcpa_end_year.cal_period_id(+) = l_end_cal_period_id
593            AND fcpa_end_year.attribute_id(+) = fcpa_start_year.attribute_id
594            AND fcpa_end_year.version_id(+) = fcpa_start_year.version_id;
595       END IF;
596 
597     END;
598 
599     BEGIN
600       SELECT 'Y'
601         INTO l_existed_entry_flag
602         FROM gcs_entry_headers geh
603        WHERE geh.entry_id = p_entry_id;
604       -- case 1: this is a newly created entry
605       -- we'll just do an insertion
606     EXCEPTION
607       WHEN NO_DATA_FOUND THEN
608         insert_entry_header(p_entry_id            => p_new_entry_id,
609                             p_hierarchy_id        => p_hierarchy_id,
610                             p_entity_id           => p_entity_id,
611                             p_year_to_apply_re    => l_year_to_apply_re,
612                             p_start_cal_period_id => l_start_cal_period_id,
613                             p_end_cal_period_id   => l_end_cal_period_id,
614                             p_entry_type_code     => 'MANUAL',
615                             p_balance_type_code   => p_balance_type_code,
616                             p_currency_code       => p_currency_code,
617                             p_process_code        => p_process_code,
618                             p_description         => p_description,
619                             p_entry_name          => p_entry_name,
620                             p_category_code       => p_category_code,
621                             x_errbuf              => l_errbuf,
622                             x_retcode             => l_retcode);
623         p_entry_lines_id := p_new_entry_id;
624         p_orig_entry_id  := NULL;
625         RETURN;
626     END; -- end of case 1
627     IF l_existed_entry_flag = 'Y' THEN
628       -- case 2: update an existing entry which has never been process before
629       -- we simply update this entry
630       BEGIN
631         SELECT 'Y'
632           INTO l_processed_entry_flag
633           FROM DUAL
634          WHERE EXISTS (SELECT run_detail_id
635                   FROM gcs_cons_eng_run_dtls gcerd
636                  WHERE gcerd.entry_id = p_entry_id);
637       EXCEPTION
638         WHEN NO_DATA_FOUND THEN
639           IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
640             fnd_log.STRING(fnd_log.level_error,
641                            g_pkg_name || '.' || l_api_name,
642                            'UPDATE gcs_entry_headers' || g_nl ||
643                            'SET balance_type_code = ' ||
644                            p_balance_type_code || ',' || g_nl ||
645                            ' end_cal_period_id = ' || l_end_cal_period_id || ',' || g_nl ||
646                            ' entry_type_code = MANUAL,' || g_nl ||
647                            ' hierarchy_id = ' || p_hierarchy_id || ',' || g_nl ||
648                            ' entity_id = ' || p_entity_id || ',' || g_nl ||
649                            ' start_cal_period_id = ' ||
650                            l_start_cal_period_id || ',' || g_nl ||
651                            ' currency_code = ' || p_currency_code || ',' || g_nl ||
652                            ' process_code = ' || p_process_code || ',' || g_nl ||
653                            ' description = ' || p_description || ',' || g_nl ||
654                            ' entry_name = ' || p_entry_name || ',' || g_nl ||
655                            ' category_code = ' || p_category_code || ',' || g_nl ||
656                            ' last_update_date = SYSDATE,' || g_nl ||
657                            ' last_updated_by = ' || fnd_global.user_id ||
658                            ' WHERE entry_id = ' || p_entry_id);
659           END IF;
660           UPDATE gcs_entry_headers
661              SET balance_type_code   = p_balance_type_code,
662                  end_cal_period_id   = l_end_cal_period_id,
663                  year_to_apply_re    = l_year_to_apply_re,
664                  entry_type_code     = 'MANUAL',
665                  hierarchy_id        = p_hierarchy_id,
666                  entity_id           = p_entity_id,
667                  start_cal_period_id = l_start_cal_period_id,
668                  currency_code       = p_currency_code,
669                  process_code        = p_process_code,
670                  description         = p_description,
671                  entry_name          = p_entry_name,
672                  category_code       = p_category_code,
673                  last_update_date    = SYSDATE,
674                  last_updated_by     = fnd_global.user_id
675            WHERE entry_id = p_entry_id;
676           -- delete old entry lines and flag new lines as loaded
677           IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
678             fnd_log.STRING(fnd_log.level_procedure,
679                            g_pkg_name || '.' || l_api_name,
680                            'DELETE FROM gcs_entry_lines' || g_nl ||
681                            'WHERE entry_id = ' || p_entry_id);
682           END IF;
683           DELETE FROM gcs_entry_lines WHERE entry_id = p_entry_id;
684           IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
685             fnd_log.STRING(fnd_log.level_procedure,
686                            g_pkg_name || '.' || l_api_name,
687                            'UPDATE gcs_entry_lines' || g_nl ||
688                            'set entry_id = ' || p_entry_id || g_nl ||
689                            'WHERE entry_id = ' || p_new_entry_id);
690           END IF;
691           UPDATE gcs_entry_lines
692              SET entry_id = p_entry_id
693            WHERE entry_id = p_new_entry_id;
694           p_entry_lines_id := p_entry_id;
695           p_orig_entry_id  := p_entry_id;
696       END;
697     END IF; -- end of case 2
698     -- case 3: update an existing entry which has been process before
699     -- we disable the existing entry and create a new one
700     IF l_processed_entry_flag = 'Y' THEN
701       IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
702         fnd_log.STRING(fnd_log.level_procedure,
703                        g_pkg_name || '.' || l_api_name,
704                        'UPDATE gcs_entry_headers' || g_nl ||
705                        'SET disabled_flag = ''Y'', entry_name = substr(entry_name, 0, 55) || '' OLD -'' || ' ||
706                        p_new_entry_id || g_nl || 'WHERE entry_id = ' ||
707                        p_entry_id);
708       END IF;
709       UPDATE gcs_entry_headers
710          SET disabled_flag = 'Y',
711              entry_name    = substr(entry_name, 0, 55) || ' OLD -' ||
712                              p_new_entry_id,
713              --Bugfix 6351281: Update the disabled cal period id as well
714              disabled_cal_period_id = start_cal_period_id
715        WHERE entry_id = p_entry_id;
716       insert_entry_header(p_entry_id            => p_new_entry_id,
717                           p_hierarchy_id        => p_hierarchy_id,
718                           p_entity_id           => p_entity_id,
719                           p_year_to_apply_re    => l_year_to_apply_re,
720                           p_start_cal_period_id => l_start_cal_period_id,
721                           p_end_cal_period_id   => l_end_cal_period_id,
722                           p_entry_type_code     => 'MANUAL',
723                           p_balance_type_code   => p_balance_type_code,
724                           p_currency_code       => p_currency_code,
725                           p_process_code        => p_process_code,
726                           p_description         => p_description,
727                           p_entry_name          => p_entry_name,
728                           p_category_code       => p_category_code,
729                           x_errbuf              => l_errbuf,
730                           x_retcode             => l_retcode);
731       p_entry_lines_id := p_new_entry_id;
732       p_orig_entry_id  := p_entry_id;
733     END IF; -- end of case 3
734     -- Write the appropriate information to the execution report
735     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
736       fnd_log.STRING(fnd_log.level_procedure,
737                      g_pkg_name || '.' || l_api_name,
738                      gcs_utility_pkg.g_module_success || ' ' || l_api_name ||
739                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
740     END IF;
741     FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
742                       g_pkg_name || '.' || l_api_name || ' EXIT');
743     FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
744   EXCEPTION
745     WHEN OTHERS THEN
746       ROLLBACK TO gcs_entry_upload_headers_start;
747       fnd_message.set_name('GCS', 'GCS_ENTRY_UNEXPECTED_ERR');
748       -- Write the appropriate information to the execution report
749       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
750         fnd_log.STRING(fnd_log.level_error,
751                        g_pkg_name || '.' || l_api_name,
752                        gcs_utility_pkg.g_module_failure || ' ' ||
753                        l_api_name || '() ' ||
754                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
755         RAISE import_header_error;
756       END IF;
757   END import_entry_headers;
758 
759   -- Procedure
760   --   get_entry_header()
761   -- Purpose
762   --   generates a unique name, and appropriate description for all automated GCS II processes
763   -- Arguments
764   --   p_category_code  Category Code for Data Prep, Translation, Aggregation,Acquisitions and Disposals,
765   --                      Pre-Intercompany, Intercompany, Post-Intercompany,
766   --                      Minority Interest, Post-Minority Interest
767   --   p_entry_id       Entry ID
768   --   p_entity_id      Entity ID associated with process (parent entity in case of rules)
769   --   p_currency_code  Currency Code of Entry
770   --   p_rule_id        Required Only for Automated Rules
771   -- Notes
772   --
773   PROCEDURE get_entry_header(p_category_code VARCHAR2,
774                              p_xlate_flag    VARCHAR2,
775                              p_entry_id      NUMBER,
776                              p_entity_id     NUMBER,
777                              p_currency_code VARCHAR2,
778                              p_rule_id       NUMBER DEFAULT NULL,
779                              p_entry_header  IN OUT NOCOPY r_entry_header) IS
780     l_entity_name       VARCHAR2(150);
781     l_rule_name         VARCHAR2(80);
782     l_entry_description VARCHAR2(240);
783     l_temp              VARCHAR2(1);
784     l_api_name          VARCHAR2(30) := 'GET_ENTRY_HEADER';
785   BEGIN
786     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
787       fnd_log.STRING(fnd_log.level_procedure,
788                      g_pkg_name || '.' || l_api_name,
789                      gcs_utility_pkg.g_module_enter || ' ' || l_api_name ||
790                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
791     END IF;
792     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
793       fnd_log.STRING(fnd_log.level_procedure,
794                      g_pkg_name || '.' || l_api_name,
795                      'SELECT entity_name INTO l_entity_name ' ||
796                      ' FROM fem_entities_vl WHERE entity_id = ' ||
797                      p_entity_id);
798     END IF;
799     BEGIN
800       SELECT entity_name
801         INTO l_entity_name
802         FROM fem_entities_vl
803        WHERE entity_id = p_entity_id;
804     EXCEPTION
805       WHEN NO_DATA_FOUND THEN
806         RAISE invalid_entity_error;
807     END;
808     IF (p_category_code = 'DATAPREPARATION') THEN
809       l_entry_description := 'Data Preparation of ' || l_entity_name;
810     ELSIF (p_category_code = 'TRANSLATION') THEN
811       l_entry_description := 'Translation of ' || l_entity_name || ' to ' ||
812                              p_currency_code;
813     ELSIF (p_category_code = 'AGGREGATION') THEN
814       l_entry_description := 'Aggregation of ' || l_entity_name;
815     ELSIF (p_rule_id is not null) THEN
816       BEGIN
817         IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
818           fnd_log.STRING(fnd_log.level_procedure,
819                          g_pkg_name || '.' || l_api_name,
820                          'SELECT rule_name INTO l_rule_name ' ||
821                          ' FROM gcs_elim_rules_vl WHERE rule_id = ' ||
822                          p_rule_id);
823         END IF;
824         SELECT rule_name
825           INTO l_rule_name
826           FROM gcs_elim_rules_vl
827          WHERE rule_id = p_rule_id;
828       EXCEPTION
829         WHEN NO_DATA_FOUND THEN
830           RAISE invalid_rule_error;
831       END;
832       l_entry_description := substr(l_rule_name || ' Executed For ' ||
833                                     l_entity_name,
834                                     0,
835                                     239);
836     END IF;
837     p_entry_header.NAME        := p_entry_id;
838     p_entry_header.description := l_entry_description;
839     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
840       fnd_log.STRING(fnd_log.level_procedure,
841                      g_pkg_name || '.' || l_api_name,
842                      'return p_entry_header.name = ' || p_entry_id ||
843                      ' and p_entry_header.description = ' ||
844                      l_entry_description);
845     END IF;
846     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
847       fnd_log.STRING(fnd_log.level_procedure,
848                      g_pkg_name || '.' || l_api_name,
849                      gcs_utility_pkg.g_module_success || ' ' || l_api_name ||
850                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
851     END IF;
852   END get_entry_header;
853 
854   PROCEDURE insert_entry_header(x_errbuf                 OUT NOCOPY VARCHAR2,
855                                 x_retcode                OUT NOCOPY VARCHAR2,
856                                 p_entry_id               IN NUMBER,
857                                 p_hierarchy_id           IN NUMBER,
858                                 p_entity_id              IN NUMBER,
859                                 p_year_to_apply_re       IN NUMBER,
860                                 p_start_cal_period_id    IN NUMBER,
861                                 p_end_cal_period_id      IN NUMBER,
862                                 p_entry_type_code        IN VARCHAR2,
863                                 p_balance_type_code      IN VARCHAR2,
864                                 p_currency_code          IN VARCHAR2,
865                                 p_process_code           IN VARCHAR2,
866                                 p_category_code          IN VARCHAR2,
867                                 p_entry_name             IN VARCHAR2,
868                                 p_description            IN VARCHAR2,
869                                 p_period_init_entry_flag IN VARCHAR2 DEFAULT 'N') IS
870     l_api_name VARCHAR2(30) := 'INSERT_ENTRY_HEADER';
871   BEGIN
872     SAVEPOINT gcs_insert_header_start;
873     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
874       fnd_log.STRING(fnd_log.level_procedure,
875                      g_pkg_name || '.' || l_api_name,
876                      gcs_utility_pkg.g_module_enter || ' ' || l_api_name ||
877                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
878     END IF;
879     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
880       fnd_log.STRING(fnd_log.level_procedure,
881                      g_pkg_name || '.' || l_api_name,
882                      'INSERT INTO gcs_entry_headers' || g_nl ||
883                      '(entry_id, entry_name, hierarchy_id, disabled_flag,' || g_nl ||
884                      'entity_id, currency_code, balance_type_code,' || g_nl ||
885                      'start_cal_period_id, end_cal_period_id,' || g_nl ||
886                      'year_to_apply_re, description, entry_type_code,' || g_nl ||
887                      'assoc_entry_id, processed_run_name, category_code,' || g_nl ||
888                      'process_code, creation_date, created_by,' || g_nl ||
889                      'last_update_date, last_updated_by, last_update_login, period_init_entry_flag' || g_nl ||
890                      ')VALUES (' || p_entry_id || ', ''' || p_entry_name ||
891                      ''', ' || p_hierarchy_id || ', ''N'',' || g_nl ||
892                      p_entity_id || ', ''' || p_currency_code || ''', ''' ||
893                      p_balance_type_code || ''', ' || g_nl ||
894                      p_start_cal_period_id || ', ' || p_end_cal_period_id || ', ' || g_nl ||
895                      p_year_to_apply_re || ', ''' || p_description ||
896                      ''', ''' || p_entry_type_code || ''', ' || g_nl ||
897                      'NULL, NULL, ''' || p_category_code || ''', ''' || g_nl ||
898                      p_process_code || ''', SYSDATE, ' ||
899                      fnd_global.user_id || ', ' || g_nl || 'SYSDATE, ' ||
900                      fnd_global.user_id || ', ' || fnd_global.login_id ||
901                      ', ''' || p_period_init_entry_flag || ''');');
902     END IF;
903     INSERT INTO gcs_entry_headers
904       (entry_id,
905        entry_name,
906        hierarchy_id,
907        disabled_flag,
908        entity_id,
909        currency_code,
910        balance_type_code,
911        start_cal_period_id,
912        end_cal_period_id,
913        year_to_apply_re,
914        description,
915        entry_type_code,
916        assoc_entry_id,
917        processed_run_name,
918        category_code,
919        process_code,
920        creation_date,
921        created_by,
922        last_update_date,
923        last_updated_by,
924        last_update_login,
925        period_init_entry_flag)
926     VALUES
927       (p_entry_id,
928        p_entry_name,
929        p_hierarchy_id,
930        'N',
931        p_entity_id,
932        p_currency_code,
933        p_balance_type_code,
934        p_start_cal_period_id,
935        p_end_cal_period_id,
936        p_year_to_apply_re,
937        p_description,
938        p_entry_type_code,
939        NULL,
940        NULL,
941        p_category_code,
942        p_process_code,
943        SYSDATE,
944        fnd_global.user_id,
945        SYSDATE,
946        fnd_global.user_id,
947        fnd_global.login_id,
948        p_period_init_entry_flag);
949     x_retcode := fnd_api.g_ret_sts_success;
950     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
951       fnd_log.STRING(fnd_log.level_procedure,
952                      g_pkg_name || '.' || l_api_name,
953                      gcs_utility_pkg.g_module_success || ' ' || l_api_name ||
954                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
955     END IF;
956   EXCEPTION
957     WHEN DUP_VAL_ON_INDEX THEN
958       ROLLBACK TO gcs_insert_header_start;
959       fnd_message.set_name('GCS', 'GCS_INVALID_ENTRY_ID');
960       x_errbuf  := fnd_message.get;
961       x_retcode := fnd_api.g_ret_sts_error;
962       -- Write the appropriate information to the execution report
963       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
964         fnd_log.STRING(fnd_log.level_error,
965                        g_pkg_name || '.' || l_api_name,
966                        gcs_utility_pkg.g_module_failure || ' ' || x_errbuf ||
967                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
968       END IF;
969   END insert_entry_header;
970 
971   PROCEDURE create_entry_header(x_errbuf                 OUT NOCOPY VARCHAR2,
972                                 x_retcode                OUT NOCOPY VARCHAR2,
973                                 p_entry_id               IN OUT NOCOPY NUMBER,
974                                 p_hierarchy_id           IN NUMBER,
975                                 p_entity_id              IN NUMBER,
976                                 p_start_cal_period_id    IN NUMBER,
977                                 p_end_cal_period_id      IN NUMBER,
978                                 p_entry_type_code        IN VARCHAR2,
979                                 p_balance_type_code      IN VARCHAR2,
980                                 p_currency_code          IN VARCHAR2,
981                                 p_process_code           IN VARCHAR2,
982                                 p_category_code          IN VARCHAR2,
983                                 p_xlate_flag             IN VARCHAR2 DEFAULT 'N',
984                                 p_rule_id                IN NUMBER DEFAULT NULL,
985                                 p_period_init_entry_flag IN VARCHAR2 DEFAULT 'N') IS
986     l_header_info r_entry_header;
987     l_api_name    VARCHAR2(30) := 'CREATE_ENTRY_HEADER';
988   BEGIN
989     SAVEPOINT gcs_create_header_start;
990     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
991       fnd_log.STRING(fnd_log.level_procedure,
992                      g_pkg_name || '.' || l_api_name,
993                      gcs_utility_pkg.g_module_enter || ' ' || l_api_name ||
994                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
995     END IF;
996     IF p_entry_id IS NULL THEN
997       SELECT gcs_entry_headers_s.NEXTVAL INTO p_entry_id FROM DUAL;
998     END IF;
999     get_entry_header(p_category_code => p_category_code,
1000                      p_xlate_flag    => p_xlate_flag,
1001                      p_entry_id      => p_entry_id,
1002                      p_entity_id     => p_entity_id,
1003                      p_currency_code => p_currency_code,
1004                      p_rule_id       => p_rule_id,
1005                      p_entry_header  => l_header_info);
1006     insert_entry_header(p_entry_id               => p_entry_id,
1007                         p_hierarchy_id           => p_hierarchy_id,
1008                         p_entity_id              => p_entity_id,
1009                         p_year_to_apply_re       => NULL,
1010                         p_start_cal_period_id    => p_start_cal_period_id,
1011                         p_end_cal_period_id      => p_end_cal_period_id,
1012                         p_entry_type_code        => p_entry_type_code,
1013                         p_balance_type_code      => p_balance_type_code,
1014                         p_currency_code          => p_currency_code,
1015                         p_process_code           => p_process_code,
1016                         p_description            => l_header_info.description,
1017                         p_entry_name             => l_header_info.NAME,
1018                         p_category_code          => p_category_code,
1019                         x_errbuf                 => x_errbuf,
1020                         x_retcode                => x_retcode,
1021                         p_period_init_entry_flag => p_period_init_entry_flag);
1022     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1023       fnd_log.STRING(fnd_log.level_procedure,
1024                      g_pkg_name || '.' || l_api_name,
1025                      gcs_utility_pkg.g_module_success || ' ' || l_api_name ||
1026                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1027     END IF;
1028   EXCEPTION
1029     WHEN invalid_entity_error THEN
1030       ROLLBACK TO gcs_create_header_start;
1031       fnd_message.set_name('GCS', 'GCS_INVALID_ENTITY_ERR');
1032       x_errbuf  := fnd_message.get;
1033       x_retcode := fnd_api.g_ret_sts_unexp_error;
1034       -- Write the appropriate information to the execution report
1035       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1036         fnd_log.STRING(fnd_log.level_error,
1037                        g_pkg_name || '.' || l_api_name,
1038                        gcs_utility_pkg.g_module_failure || ' ' || x_errbuf ||
1039                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1040       END IF;
1041     WHEN invalid_rule_error THEN
1042       ROLLBACK TO gcs_create_header_start;
1043       fnd_message.set_name('GCS', 'GCS_INVALID_RULE_ERR');
1044       x_errbuf  := fnd_message.get;
1045       x_retcode := fnd_api.g_ret_sts_unexp_error;
1046       -- Write the appropriate information to the execution report
1047       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1048         fnd_log.STRING(fnd_log.level_error,
1049                        g_pkg_name || '.' || l_api_name,
1050                        gcs_utility_pkg.g_module_failure || ' ' || x_errbuf ||
1051                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1052       END IF;
1053     WHEN OTHERS THEN
1054       ROLLBACK TO gcs_create_header_start;
1055       fnd_message.set_name('GCS', 'GCS_ENTRY_UNEXPECTED_ERR');
1056       x_errbuf  := fnd_message.get;
1057       x_retcode := fnd_api.g_ret_sts_unexp_error;
1058       -- Write the appropriate information to the execution report
1059       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1060         fnd_log.STRING(fnd_log.level_error,
1061                        g_pkg_name || '.' || l_api_name,
1062                        gcs_utility_pkg.g_module_failure || ' ' || x_errbuf ||
1063                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1064       END IF;
1065   END create_entry_header;
1066   --
1067   -- PUBLIC PROCEDURES
1068   --
1069   ---------------------------------------------------------------------------
1070   /*
1071   ** Manual_Entries_Import
1072   */
1073   PROCEDURE manual_entries_import(p_entry_id_char       IN VARCHAR2,
1074                                   p_end_cal_period_id   IN VARCHAR2,
1075                                   p_hierarchy_id        IN NUMBER,
1076                                   p_entity_id_char      IN VARCHAR2,
1077                                   p_start_cal_period_id IN VARCHAR2,
1078                                   p_currency_code       IN VARCHAR2,
1079                                   p_process_code        IN VARCHAR2,
1080                                   p_description         IN VARCHAR2,
1081                                   p_entry_name          IN VARCHAR2,
1082                                   p_category_code       IN VARCHAR2,
1083                                   p_balance_type_code   IN VARCHAR2,
1084                                   p_writeback_needed    IN VARCHAR2,
1085                                   p_ledger_id           IN VARCHAR2,
1086                                   p_cal_period_name     IN VARCHAR2,
1087                                   p_conversion_type     IN VARCHAR2,
1088                                   p_new_entry_id        IN NUMBER,
1089                                   p_hierarchy_grp_flag  IN VARCHAR2) IS
1090     l_entry_type_code  VARCHAR2(30);
1091     l_balance_code     VARCHAR2(30);
1092     l_hierarchy_id     NUMBER(15);
1093     l_entry_id         NUMBER(15);
1094     l_entity_id        NUMBER(15);
1095     l_precision        NUMBER(15, 5);
1096     l_year_to_apply_re NUMBER(4) := NULL;
1097     l_event_name       VARCHAR2(100) := 'oracle.apps.gcs.transaction.adjustment.update';
1098     l_event_key        VARCHAR2(100) := NULL;
1099     l_parameter_list   wf_parameter_list_t;
1100     l_orig_entry_id    NUMBER(15);
1101     l_api_name         VARCHAR2(30) := 'MANUAL_ENTRIES_IMPORT';
1102     l_request_id       NUMBER(15);
1103     p_entry_id         NUMBER(15) := TO_NUMBER(p_entry_id_char);
1104     p_wf_itemkey       VARCHAR2(100);
1105     p_entity_id        NUMBER(15) := TO_NUMBER(p_entity_id_char);
1106 
1107   BEGIN
1108     -- In case of an error, we will roll back to this point in time.
1109 
1110     SAVEPOINT gcs_me_import_start;
1111 
1112     FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1113                       g_pkg_name || '.' || l_api_name || ' ENTER');
1114     FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1115 
1116     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1117       fnd_log.STRING(fnd_log.level_procedure,
1118                      g_pkg_name || '.' || l_api_name,
1119                      gcs_utility_pkg.g_module_enter || ' p_entry_id = ' ||
1120                      p_entry_id || ' p_end_cal_period_id = ' ||
1121                      p_end_cal_period_id || ' p_hierarchy_id = ' ||
1122                      p_hierarchy_id || ' p_entity_id = ' || p_entity_id ||
1123                      ' p_start_cal_period_id = ' || p_start_cal_period_id ||
1124                      ' p_currency_code = ' || p_currency_code ||
1125                      ' p_process_code = ' || p_process_code ||
1126                      ' p_description = ' || p_description ||
1127                      ' p_entry_name = ' || p_entry_name ||
1128                      ' p_category_code = ' || p_category_code ||
1129                      ' p_balance_type_code = ' || p_balance_type_code ||
1130                      ' p_writeback_needed = ' || p_writeback_needed ||
1131                      ' p_ledger_id  = ' || p_ledger_id ||
1132                      ' p_cal_period_name = ' || p_cal_period_name ||
1133                      ' p_conversion_type = ' || p_conversion_type ||
1134                      ' p_new_entry_id = ' || p_new_entry_id ||
1135                      ' p_hierarchy_grp_flag = ' || p_hierarchy_grp_flag || ' ' ||
1136                      TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1137     END IF;
1138 
1139     -- Enhancement : 6416736, Chack if the adjustments are submitted for a stand alone hierarchy or a hierarchy group.
1140 
1141     IF (p_hierarchy_grp_flag = 'Y') THEN
1142       -- Adjustment is submitted for a hierarchy group
1143       import_hier_grp_entry(p_new_entry_id,
1144                             p_end_cal_period_id,
1145                             p_hierarchy_id,
1146                             p_entity_id,
1147                             p_start_cal_period_id,
1148                             p_currency_code,
1149                             p_process_code,
1150                             p_description,
1151                             p_entry_name,
1152                             p_category_code,
1153                             p_balance_type_code,
1154                             p_ledger_id,
1155                             p_cal_period_name,
1156                             p_conversion_type);
1157     ELSE
1158       -- Adjustment is submitted for a stand alone hierarchy.
1159 
1160       import_entry_headers(p_entry_id,
1161                            p_end_cal_period_id,
1162                            p_hierarchy_id,
1163                            p_entity_id,
1164                            p_start_cal_period_id,
1165                            p_currency_code,
1166                            p_process_code,
1167                            p_description,
1168                            p_entry_name,
1169                            p_category_code,
1170                            p_balance_type_code,
1171                            p_new_entry_id,
1172                            l_entry_id,
1173                            l_orig_entry_id);
1174       IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1175         fnd_log.STRING(fnd_log.level_procedure,
1176                        g_pkg_name || '.' || l_api_name,
1177                        'SELECT decode(start_cal_period_id, end_cal_period_id, ''ONE_TIME'',
1178                     ''RECURRING''), year_to_apply_re, hierarchy_id, balance_type_code,
1179                     entity_id, NVL (minimum_accountable_unit, POWER (10, -PRECISION))' || g_nl ||
1180                        'INTO l_entry_type_code, l_year_to_apply_re, l_hierarchy_id,
1181                  l_balance_code, l_entity_id, l_precision' || g_nl ||
1182                        'FROM fnd_currencies fc, gcs_entry_headers geh' || g_nl ||
1183                        'WHERE fc.currency_code = geh.currency_code ' || g_nl ||
1184                        'AND geh.entry_id = ' || l_entry_id);
1185       END IF;
1186 
1187       SELECT DECODE(start_cal_period_id,
1188                     end_cal_period_id,
1189                     'ONE_TIME',
1190                     'RECURRING'),
1191              year_to_apply_re,
1192              hierarchy_id,
1193              balance_type_code,
1194              entity_id,
1195              NVL(minimum_accountable_unit, POWER(10, -PRECISION))
1196         INTO l_entry_type_code,
1197              l_year_to_apply_re,
1198              l_hierarchy_id,
1199              l_balance_code,
1200              l_entity_id,
1201              l_precision
1202         FROM fnd_currencies fc, gcs_entry_headers geh
1203        WHERE fc.currency_code = geh.currency_code
1204          AND geh.entry_id = l_entry_id;
1205 
1206       IF (l_entry_type_code = 'RECURRING') THEN
1207         -- update the line_type_code for recurring entry lines
1208         IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1209           fnd_log.STRING(fnd_log.level_procedure,
1210                          g_pkg_name || '.' || l_api_name,
1211                          'UPDATE gcs_entry_lines' || g_nl ||
1212                           'SET ytd_debit_balance_e = ROUND (ytd_debit_balance_e / l_precision)
1213                               * l_precision, ' || g_nl ||
1214                           'ytd_credit_balance_e = ROUND (ytd_credit_balance_e / l_precision)
1215                              * l_precision, ' || g_nl ||
1216                           'ytd_balance_e = ROUND (nvl(ytd_debit_balance_e, 0) / l_precision) * l_precision ' || g_nl ||
1217                           '- ROUND (nvl(ytd_credit_balance_e, 0) / l_precision) * l_precision, ' || g_nl ||
1218                           ' line_type_code =
1219                          CASE
1220                             WHEN (SELECT feata.dim_attribute_varchar_member
1221                                     FROM fem_ext_acct_types_attr feata,
1222                                          fem_ln_items_attr flia
1223                                    WHERE gcs_entry_lines.line_item_id = flia.line_item_id
1224                   AND flia.attribute_id = ' ||
1225                           g_dimension_attr_info('LINE_ITEM_ID-EXTENDED_ACCOUNT_TYPE')
1226                          .attribute_id || '
1227                   AND feata.attribute_id = ' ||
1228                           g_dimension_attr_info('EXT_ACCOUNT_TYPE_CODE-BASIC_ACCOUNT_TYPE_CODE')
1229                          .attribute_id || '
1230                   AND flia.version_id = ' ||
1231                           g_dimension_attr_info('LINE_ITEM_ID-EXTENDED_ACCOUNT_TYPE')
1232                          .version_id || '
1233                   AND feata.version_id = ' ||
1234                           g_dimension_attr_info('EXT_ACCOUNT_TYPE_CODE-BASIC_ACCOUNT_TYPE_CODE')
1235                          .version_id || '
1236                   AND feata.DIM_ATTRIBUTE_NUMERIC_MEMBER IS NULL
1237                                      AND flia.value_set_id =' ||
1238                           g_gcs_dimension_info('LINE_ITEM_ID')
1239                          .associated_value_set_id ||
1240                           '              AND feata.ext_account_type_code =
1241                                                    flia.dim_attribute_varchar_member) IN
1242                                                              (''REVENUE'', ''EXPENSE'')
1243                                THEN ''PROFIT_LOSS''
1244                             ELSE ''BALANCE_SHEET''
1245                          END ' ||
1246                           'WHERE entry_id = ' || l_entry_id);
1247         END IF;
1248 
1249         UPDATE gcs_entry_lines
1250            SET ytd_debit_balance_e  = ROUND(ytd_debit_balance_e /
1251                                             l_precision) * l_precision,
1252                ytd_credit_balance_e = ROUND(ytd_credit_balance_e /
1253                                             l_precision) * l_precision,
1254                ytd_balance_e        = ROUND(nvl(ytd_debit_balance_e, 0) /
1255                                             l_precision) * l_precision -
1256                                       ROUND(nvl(ytd_credit_balance_e, 0) /
1257                                             l_precision) * l_precision,
1258                line_type_code       = CASE WHEN (SELECT feata.dim_attribute_varchar_member
1259                              FROM fem_ext_acct_types_attr feata,
1260                                   fem_ln_items_attr       flia
1261                             WHERE gcs_entry_lines.line_item_id =
1262                                   flia.line_item_id
1263                               AND flia.value_set_id =
1264                                   g_gcs_dimension_info('LINE_ITEM_ID')
1265                            .associated_value_set_id
1266                               AND flia.attribute_id =
1267                                   g_dimension_attr_info('LINE_ITEM_ID-EXTENDED_ACCOUNT_TYPE')
1268                            .attribute_id
1269                               AND feata.attribute_id =
1270                                   g_dimension_attr_info('EXT_ACCOUNT_TYPE_CODE-BASIC_ACCOUNT_TYPE_CODE')
1271                            .attribute_id
1272                               AND flia.version_id =
1273                                   g_dimension_attr_info('LINE_ITEM_ID-EXTENDED_ACCOUNT_TYPE')
1274                            .version_id
1275                               AND feata.version_id =
1276                                   g_dimension_attr_info('EXT_ACCOUNT_TYPE_CODE-BASIC_ACCOUNT_TYPE_CODE')
1277                            .version_id
1278                               AND feata.DIM_ATTRIBUTE_NUMERIC_MEMBER IS NULL
1279                               AND feata.ext_account_type_code =
1280                                   flia.dim_attribute_varchar_member) IN ('REVENUE', 'EXPENSE') THEN 'PROFIT_LOSS' ELSE 'BALANCE_SHEET' END
1281          WHERE entry_id = l_entry_id;
1282 
1283         IF l_year_to_apply_re IS NOT NULL THEN
1284           gcs_templates_dynamic_pkg.calculate_re(p_entry_id      => l_entry_id,
1285                                                  p_hierarchy_id  => l_hierarchy_id,
1286                                                  p_bal_type_code => l_balance_code,
1287                                                  p_entity_id     => l_entity_id);
1288         END IF;
1289       ELSE
1290         IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1291           fnd_log.STRING(fnd_log.level_procedure,
1292                          g_pkg_name || '.' || l_api_name,
1293                          'UPDATE gcs_entry_lines' || g_nl ||
1294                          'SET  ytd_debit_balance_e = ROUND (ytd_debit_balance_e / l_precision) * l_precision, ' || g_nl ||
1295                          'ytd_credit_balance_e = ROUND (ytd_credit_balance_e / l_precision) * l_precision, ' || g_nl ||
1296                          'ytd_balance_e = ROUND (nvl(ytd_debit_balance_e, 0) / l_precision) * l_precision ' || g_nl ||
1297                          '- ROUND (nvl(ytd_credit_balance_e, 0) / l_precision) * l_precision, ' || g_nl ||
1298                          'WHERE entry_id = ' || l_entry_id);
1299         END IF;
1300         UPDATE gcs_entry_lines
1301            SET ytd_debit_balance_e  = ROUND(ytd_debit_balance_e /
1302                                             l_precision) * l_precision,
1303                ytd_credit_balance_e = ROUND(ytd_credit_balance_e /
1304                                             l_precision) * l_precision,
1305                ytd_balance_e        = ROUND(nvl(ytd_debit_balance_e, 0) /
1306                                             l_precision) * l_precision -
1307                                       ROUND(nvl(ytd_credit_balance_e, 0) /
1308                                             l_precision) * l_precision
1309          WHERE entry_id = l_entry_id;
1310       END IF;
1311 
1312       -- Enhancement for Adjustment Approval Process
1313       IF fnd_profile.value('AME_INSTALLED_FLAG') = 'Y' THEN
1314         GCS_ADJ_APPROVAL_WF_PKG.create_gcsadj_process(p_entry_id        => l_entry_id,
1315                                                       p_user_id         => fnd_global.user_id,
1316                                                       p_user_name       => fnd_global.user_name,
1317                                                       p_orig_entry_id   => l_orig_entry_id,
1318                                                       p_ledger_id       => to_number(p_ledger_id),
1319                                                       p_cal_period_name => p_cal_period_name,
1320                                                       p_conversion_type => p_conversion_type,
1321                                                       p_writeback_flag  => p_writeback_needed,
1322                                                       p_wfitemkey       => p_wf_itemkey);
1323 
1324         FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1325                           g_pkg_name || '.' || l_api_name || 'EXIT');
1326         FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1327 
1328         IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1329           fnd_log.STRING(fnd_log.level_procedure,
1330                          g_pkg_name || '.' || l_api_name,
1331                          gcs_utility_pkg.g_module_success || ' ' ||
1332                          l_api_name || '() ' ||
1333                          TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS')
1334 
1335                          );
1336         END IF;
1337       ELSE
1338 
1339         wf_event.addparametertolist(p_name          => 'ENTRY_ID',
1340                                     p_value         => l_entry_id,
1341                                     p_parameterlist => l_parameter_list);
1342         wf_event.addparametertolist(p_name          => 'ORIG_ENTRY_ID',
1343                                     p_value         => l_orig_entry_id,
1344                                     p_parameterlist => l_parameter_list);
1345         BEGIN
1346           FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1347                             g_pkg_name || '.' || l_api_name ||
1348                             ' RAISE WF_EVENT');
1349           FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1350           wf_event.RAISE(p_event_name => l_event_name,
1351                          p_event_key  => l_event_key,
1352                          p_parameters => l_parameter_list);
1353         EXCEPTION
1354           WHEN OTHERS THEN
1355             FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1356                               g_pkg_name || '.' || l_api_name ||
1357                               ' ERROR : ' || SQLERRM);
1358             FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1359             IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1360               fnd_log.STRING(fnd_log.level_error,
1361                              g_pkg_name || '.' || l_api_name,
1362                              ' wf_event.raise failed ' || ' ' ||
1363                              TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1364             END IF;
1365         END;
1366 
1367         -- Bug fix : 5260258
1368         IF (p_writeback_needed = 'Y') THEN
1369           l_request_id := fnd_request.submit_request(application => 'GCS',
1370                                                      program     => 'FCH_ENTRY_WRITEBACK',
1371                                                      sub_request => FALSE,
1372                                                      argument1   => l_entry_id,
1373                                                      argument2   => l_entry_id,
1374                                                      argument3   => to_number(p_ledger_id),
1375                                                      argument4   => p_cal_period_name,
1376                                                      argument5   => p_conversion_type);
1377 
1378           FND_FILE.PUT_LINE(FND_FILE.LOG,
1379                             'Submitted request id : ' || l_request_id);
1380           FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1381         END IF;
1382 
1383         FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1384                           g_pkg_name || '.' || l_api_name || ' EXIT');
1385         FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1386 
1387       END IF;
1388 
1389     END IF;
1390     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1391       fnd_log.STRING(fnd_log.level_procedure,
1392                      g_pkg_name || '.' || l_api_name,
1393                      gcs_utility_pkg.g_module_success || ' ' || l_api_name ||
1394                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1395     END IF;
1396 
1397   EXCEPTION
1398     WHEN OTHERS THEN
1399 
1400       ROLLBACK TO gcs_me_import_start;
1401       fnd_message.set_name('GCS', 'GCS_ENTRY_UNEXPECTED_ERR');
1402       FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1403                         g_pkg_name || '.' || l_api_name || ' ERROR : ' ||
1404                         SQLERRM);
1405       FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1406       -- Write the appropriate information to the execution report
1407       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1408         fnd_log.STRING(fnd_log.level_error,
1409                        g_pkg_name || '.' || l_api_name,
1410                        gcs_utility_pkg.g_module_failure || ' ' || SQLERRM || ' ' ||
1411                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1412       END IF;
1413   END manual_entries_import;
1414 
1415   ---------------------------------------------------------------------------
1416   /*
1417   ** upload_entry_headers
1418   */
1419   PROCEDURE upload_entry_headers(p_entry_id_char       IN OUT NOCOPY VARCHAR2,
1420                                  p_end_cal_period_id   IN VARCHAR2,
1421                                  p_hierarchy_id        IN NUMBER,
1422                                  p_entity_id           IN VARCHAR2,
1423                                  p_start_cal_period_id IN VARCHAR2,
1424                                  p_currency_code       IN VARCHAR2,
1425                                  p_process_code        IN VARCHAR2,
1426                                  p_description         IN VARCHAR2,
1427                                  p_entry_name          IN VARCHAR2,
1428                                  p_category_code       IN VARCHAR2,
1429                                  p_balance_type_code   IN VARCHAR2,
1430                                  p_writeback_needed    IN VARCHAR2,
1431                                  p_ledger_id           IN VARCHAR2,
1432                                  p_cal_period_name     IN VARCHAR2,
1433                                  p_conversion_type     IN VARCHAR2,
1434                                  p_hierarchy_grp_flag  IN VARCHAR2) IS
1435   BEGIN
1436     null;
1437   END upload_entry_headers;
1438   ---------------------------------------------------------------------------
1439   --
1440   -- Procedure
1441   --   delete_entry
1442   -- Purpose
1443   --   An API to delete an entry
1444   -- Arguments
1445   -- Notes
1446   --
1447   PROCEDURE delete_entry(p_entry_id IN NUMBER,
1448                          x_errbuf   OUT NOCOPY VARCHAR2,
1449                          x_retcode  OUT NOCOPY VARCHAR2) IS
1450     l_api_name VARCHAR2(30) := 'DELETE_ENTRY';
1451   BEGIN
1452     SAVEPOINT gcs_delete_entry_start;
1453     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1454       fnd_log.STRING(fnd_log.level_procedure,
1455                      g_pkg_name || '.' || l_api_name,
1456                      gcs_utility_pkg.g_module_enter || ' ' || l_api_name ||
1457                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1458     END IF;
1459     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1460       fnd_log.STRING(fnd_log.level_procedure,
1461                      g_pkg_name || '.' || l_api_name,
1462                      'DELETE FROM gcs_entry_headers' || g_nl ||
1463                      'WHERE entry_id = ' || p_entry_id);
1464     END IF;
1465     /*
1466           DELETE FROM gcs_entry_headers
1467                 WHERE entry_id = p_entry_id;
1468     */
1469     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1470       fnd_log.STRING(fnd_log.level_procedure,
1471                      g_pkg_name || '.' || l_api_name,
1472                      'DELETE FROM gcs_entry_lines' || g_nl ||
1473                      'WHERE entry_id = ' || p_entry_id);
1474     END IF;
1475     DELETE FROM gcs_entry_lines WHERE entry_id = p_entry_id;
1476     x_retcode := fnd_api.g_ret_sts_success;
1477     IF fnd_log.g_current_runtime_level <= fnd_log.level_procedure THEN
1478       fnd_log.STRING(fnd_log.level_procedure,
1479                      g_pkg_name || '.' || l_api_name,
1480                      gcs_utility_pkg.g_module_success || ' ' || l_api_name ||
1481                      '() ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1482     END IF;
1483   EXCEPTION
1484     WHEN NO_DATA_FOUND THEN
1485       ROLLBACK TO gcs_delete_entry_start;
1486       fnd_message.set_name('GCS', 'GCS_INVALID_ENTRY_ID');
1487       x_errbuf  := fnd_message.get;
1488       x_retcode := fnd_api.g_ret_sts_error;
1489       -- Write the appropriate information to the execution report
1490       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1491         fnd_log.STRING(fnd_log.level_error,
1492                        g_pkg_name || '.' || l_api_name,
1493                        gcs_utility_pkg.g_module_failure || ' ' || x_errbuf ||
1494                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1495       END IF;
1496     WHEN OTHERS THEN
1497       ROLLBACK TO gcs_delete_entry_start;
1498       fnd_message.set_name('GCS', 'GCS_ENTRY_UNEXPECTED_ERR');
1499       x_errbuf  := fnd_message.get;
1500       x_retcode := fnd_api.g_ret_sts_unexp_error;
1501       -- Write the appropriate information to the execution report
1502       IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1503         fnd_log.STRING(fnd_log.level_error,
1504                        g_pkg_name || '.' || l_api_name,
1505                        gcs_utility_pkg.g_module_failure || ' ' || x_errbuf ||
1506                        TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1507       END IF;
1508   END delete_entry;
1509 
1510   --
1511   -- Procedure
1512   --   raise_disable_event
1513   -- Purpose
1514   --   An API to disable an entry and track impact analysis and notify
1515   -- Arguments
1516   --   p_entry_id      Entry Identifier
1517   --   p_cal_period_id Calendar Period Identifier
1518   -- Notes
1519   --   Bugfix 5613302
1520   PROCEDURE raise_disable_event(p_entry_id      IN NUMBER,
1521                                 p_cal_period_id IN NUMBER) IS
1522     l_event_name     VARCHAR2(100) := 'oracle.apps.gcs.transaction.adjustment.disable';
1523     l_event_key      VARCHAR2(100) := NULL;
1524     l_parameter_list wf_parameter_list_t;
1525     l_api_name       VARCHAR2(30) := 'RAISE_DISABLE_EVENT';
1526 
1527   BEGIN
1528 
1529     FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1530                       g_pkg_name || '.' || l_api_name || ' ENTER');
1531     FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1532     wf_event.addparametertolist(p_name          => 'ENTRY_ID',
1533                                 p_value         => p_entry_id,
1534                                 p_parameterlist => l_parameter_list);
1535     wf_event.addparametertolist(p_name          => 'CAL_PERIOD_ID',
1536                                 p_value         => p_cal_period_id,
1537                                 p_parameterlist => l_parameter_list);
1538 
1539     BEGIN
1540       FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1541                         g_pkg_name || '.' || l_api_name ||
1542                         ' RAISE WF_EVENT');
1543       FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1544       wf_event.RAISE(p_event_name => l_event_name,
1545                      p_event_key  => l_event_key,
1546                      p_parameters => l_parameter_list);
1547       FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1548                         g_pkg_name || '.' || l_api_name || ' EXIT');
1549       FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1550     EXCEPTION
1551       WHEN OTHERS THEN
1552         FND_FILE.PUT_LINE(FND_FILE.OUTPUT,
1553                           g_pkg_name || '.' || l_api_name || ' ERROR : ' ||
1554                           SQLERRM);
1555         FND_FILE.NEW_LINE(FND_FILE.OUTPUT);
1556         IF fnd_log.g_current_runtime_level <= fnd_log.level_error THEN
1557           fnd_log.STRING(fnd_log.level_error,
1558                          g_pkg_name || '.' || l_api_name,
1559                          ' wf_event.raise failed ' || ' ' ||
1560                          TO_CHAR(SYSDATE, 'DD-MON-YYYY HH:MI:SS'));
1561         END IF;
1562     END;
1563   END raise_disable_event;
1564 END gcs_entry_pkg;
1565