DBA Data[Home] [Help]

PACKAGE BODY: APPS.GL_AUTOREVERSE_DATE_PKG

Source


1 PACKAGE BODY GL_AUTOREVERSE_DATE_PKG as
2 /* $Header: glustarb.pls 120.5.12010000.2 2010/02/19 10:09:50 skotakar ship $ */
3 
4 -- private functions
5 PROCEDURE get_business_day( X_Date_Rule                 VARCHAR2,
6                             X_Trxn_Calendar_Id          NUMBER,
7                             X_Je_Source                 VARCHAR2,
8                             X_Reversal_Date    IN OUT NOCOPY   DATE) IS
9 
10   NORMAL_EXIT         EXCEPTION;
11 
12   eff_date_rule       VARCHAR2(1);
13   business_day_flag   VARCHAR2(1);
14 
15   CURSOR get_effective_date_rule IS
16       SELECT effective_date_rule_code
17       FROM   gl_je_sources
18       WHERE  je_source_name = X_Je_Source;
19 
20   CURSOR is_business_day IS
21       SELECT business_day_flag
22       FROM   gl_transaction_dates
23       WHERE  transaction_calendar_id = X_Trxn_Calendar_Id
24       AND    transaction_date = X_Reversal_Date;
25 
26   CURSOR roll_backward IS
27       SELECT max(transaction_date)
28       FROM   gl_transaction_dates
29       WHERE  transaction_calendar_id = X_Trxn_Calendar_Id
30       AND    business_day_flag = 'Y'
31       AND    transaction_date <= X_Reversal_Date;
32 
33   CURSOR roll_forward IS
34       SELECT min(transaction_date)
35       FROM   gl_transaction_dates
36       WHERE  transaction_calendar_id = X_Trxn_Calendar_Id
37       AND    business_day_flag = 'Y'
38       AND    transaction_date >= X_Reversal_Date;
39 
40 BEGIN
41 
42     IF (X_Je_Source = 'Manual') THEN
43     -- Manual source journals created by Enter Journals form
44     -- should always have the business day rolled
45        eff_date_rule := 'R';
46     ELSE
47        OPEN get_effective_date_rule;
48        FETCH get_effective_date_rule INTO eff_date_rule;
49 
50        IF (get_effective_date_rule%NOTFOUND) THEN
51          CLOSE get_effective_date_rule;
52          Error_Buffer := 'Cannot find effective date rule for this source '
53                    ||X_Je_Source;
54          Raise GET_REV_PERIOD_DATE_FAILED;
55        END IF;
56 
60        END IF;
57        -- 1. Reversal date is valid when effective date rule is Leave Alone
58        IF eff_date_rule = 'L' THEN
59           Raise NORMAL_EXIT;
61     END IF;
62 
63     OPEN is_business_day;
64     FETCH is_business_day INTO business_day_flag;
65 
66     IF (is_business_day%NOTFOUND) THEN
67       CLOSE is_business_day;
68       Error_Buffer := 'The reversal date '||X_Reversal_Date||
69                  ' is not in the transaction calendar.';
70       Raise GET_REV_PERIOD_DATE_FAILED;
71     END IF;
72 
73     -- 2. Exit normal if business day
74     IF (business_day_flag = 'Y') THEN
75       Raise NORMAL_EXIT;
76     END IF;
77 
78     -- 3. Error out non-business day when effective date rule is fail
79     IF (business_day_flag = 'N' AND eff_date_rule = 'F') THEN
80        Error_Buffer := 'The reversal date '||X_Reversal_Date||
81                   ' is not a business day.';
82        Raise GET_REV_PERIOD_DATE_FAILED;
83     END IF;
84 
85     -- 4. now the effective date can only be Roll Date
86     --    Roll to find a business day
87     IF X_Date_Rule = 'LAST_DAY' THEN
88        OPEN roll_backward;
89        FETCH roll_backward INTO X_Reversal_Date;
90 
91        IF (X_Reversal_Date IS NULL) THEN
92           CLOSE roll_backward;
93           Error_Buffer := 'Cannot find a business day by rolling backwards from '
94                      ||X_Reversal_Date;
95           Raise GET_REV_PERIOD_DATE_FAILED;
96        END IF;
97     ELSE
98        OPEN roll_forward;
99        FETCH roll_forward INTO X_Reversal_Date;
100 
101        IF (X_Reversal_Date IS NULL) THEN
102           CLOSE roll_forward;
103           Error_Buffer := 'Cannot find a business day by rolling forward from '
104                      ||X_Reversal_Date;
105           Raise GET_REV_PERIOD_DATE_FAILED;
106        END IF;
107     END IF;
108 
109 
110 EXCEPTION
111     WHEN NORMAL_EXIT THEN
112         null;
113     WHEN OTHERS THEN
114         Error_Buffer := 'get_business_day.'||Error_Buffer;
115         Raise;
116 END get_business_day;
117 
118 PROCEDURE get_reversal_date(X_Reversal_Period           VARCHAR2,
119                             X_Adj_Period_Flag           VARCHAR2,
120                             X_Period_Rule               VARCHAR2,
121                             X_Date_Rule                 VARCHAR2,
122                             X_Cons_Ledger               VARCHAR2,
123                             X_Trxn_Calendar_Id          NUMBER,
124                             X_Je_Source                 VARCHAR2,
125                             X_Je_Date                   DATE,
126                             X_Start_Date                DATE,
127                             X_End_Date                  DATE,
128                             X_Reversal_Date    IN OUT NOCOPY   DATE) IS
129   NORMAL_EXIT      EXCEPTION;
130   WRONG_CRITERIA   EXCEPTION;
131   reversal_date    DATE;
132 BEGIN
133       ------    ADB Consolidation Ledger  -----------
134       -- When the reversal period rule is same period, use the journal's
135       -- date as the reversal date. For an average journal, this should
136       -- be the 1st day of the month. When the reversal period rule
137       -- is NEXT_(ADJ_)PERIOD, use the 1st day of the reversal period.
138 
139       IF X_Cons_Ledger = 'Y' THEN
140          IF X_Period_Rule = 'SAME_PERIOD' THEN
141             reversal_date := X_Je_Date;
142          ELSE
143             reversal_date := X_Start_Date;
144          END IF;
145          Raise NORMAL_EXIT;
146       END IF;
147 
148       ------    ADB Non-Consolidation Ledger ----------
149       -- 1. get reversal date from date_rule
150 
151       IF X_Period_Rule = 'SAME_PERIOD' THEN
152 
153          IF X_Date_Rule = 'NEXT_DAY' THEN
154             reversal_date := X_Je_Date + 1;
155             IF reversal_date > X_End_Date THEN
156                Error_Buffer := 'Cannot find a valid reversal date; '
157                              ||'The next day '||reversal_date
158                              ||' is outside the reversal period '
159                              ||X_Reversal_Period||'.';
160 
161                Raise GET_REV_PERIOD_DATE_FAILED;
162             END IF;
163          ELSIF X_Date_Rule = 'LAST_DAY' THEN
164             reversal_date := X_End_Date;
165          ELSE
166             Raise WRONG_CRITERIA;
167          END IF;
168       ELSE -- next (non-adj) period
169          IF X_Date_Rule = 'FIRST_DAY' THEN
170             reversal_date := X_Start_Date;
171          ELSIF X_Date_Rule = 'LAST_DAY' THEN
172             reversal_date := X_End_Date;
173          ELSE
174             Raise WRONG_CRITERIA;
175          END IF;
176       END IF;
177       -- 2. No effective date check for Adjusting Period
178       -- IF X_Adj_Period_Flag = 'Y' THEN
179       --   Raise NORMAL_EXIT;
180       -- END IF;
181 
182       -- 3. Check if reversal date is business day. If not, find one.
183       get_business_day(X_Date_Rule, X_Trxn_Calendar_Id, X_Je_Source,
184                        reversal_date);
185       -- 4. Check if reversal date is still in the reversal period.
186       IF (reversal_date < X_Start_Date OR reversal_date > X_End_Date) THEN
187          Error_Buffer := 'Cannot find a businness day within the reversal period '||X_Reversal_Period||' as reversal date.';
188          Raise GET_REV_PERIOD_DATE_FAILED;
189       END IF;
190       IF ( reversal_date < X_Je_Date) THEN
194 
191          Error_Buffer := 'Cannot find a valid reversal date because the first valid day is before the journal date.';
192          Raise GET_REV_PERIOD_DATE_FAILED;
193       END IF;
195       X_Reversal_Date := reversal_date;
196 
197 EXCEPTION
198     WHEN NORMAL_EXIT THEN
199         X_Reversal_Date := reversal_date;
200     WHEN WRONG_CRITERIA THEN
201         Error_Buffer := 'Invalid REVERSAL_DATE_CODE, '||X_Date_Rule||', in GL_AUTOREVERSE_OPTIONS.';
202         Raise GET_REV_PERIOD_DATE_FAILED;
203     WHEN OTHERS THEN
204         Error_Buffer := '.get_reversal_date.'||Error_Buffer;
205         Raise;
206 END get_reversal_date;
207 
208      -- Public Procedure
209 
210 PROCEDURE get_reversal_period_date(X_Ledger_Id    	      NUMBER,
211                                    X_Je_Category              VARCHAR2,
212                                    X_Je_Source                VARCHAR2,
213                                    X_Je_Period_Name           VARCHAR2,
214                                    X_Je_Date                  DATE,
215                                    X_Reversal_Method  IN OUT NOCOPY  VARCHAR2,
216                                    X_Reversal_Period  IN OUT NOCOPY  VARCHAR2,
217                                    X_Reversal_Date    IN OUT NOCOPY  DATE) IS
218     adb_lgr           VARCHAR2(1);
219     cons_lgr          VARCHAR2(1);
220     trxn_calendar_id  VARCHAR2(15);
221     method_code       VARCHAR2(1);
222     period_rule       VARCHAR2(30);
223     date_rule         VARCHAR2(30);
224     reversal_period   VARCHAR2(15);
225     adj_period_flag   VARCHAR2(1);
226     pstatus           VARCHAR2(1);
227     period_set        VARCHAR2(15);
228     v_period_type        VARCHAR2(15);
229     reversal_date     DATE;
230     start_date        DATE;
231     end_date          DATE;
232     l_criteria_set_id NUMBER :=0;
233 
234     CURSOR get_lgr IS
235     SELECT enable_average_balances_flag,
236            consolidation_ledger_flag,
237            transaction_calendar_id,
238            period_set_name,
239            accounted_period_type,
240 	   criteria_set_id
241     FROM   gl_ledgers
242     WHERE  ledger_id = X_Ledger_Id;
243 
244     CURSOR get_criteria IS
245     SELECT decode(method_code,'C','Y','N'),
246            reversal_period_code,reversal_date_code
247     FROM   gl_autoreverse_options
248     WHERE  criteria_set_id = l_Criteria_Set_Id
249     AND    je_category_name = X_Je_Category;
250 
251 
252     CURSOR same_period IS
253     SELECT period_name,closing_status,start_date,end_date,
254            adjustment_period_flag
255     FROM   gl_period_statuses p
256     WHERE  p.application_id = 101
257     AND    p.ledger_id = X_Ledger_Id
258     AND    p.period_name = X_Je_Period_Name;
259 
260     CURSOR next_period IS
261     SELECT period_name, closing_status, start_date, end_date,
262            adjustment_period_flag
263     FROM   gl_period_statuses p1
264     WHERE  p1.application_id = 101
265     AND    p1.ledger_id = X_Ledger_Id
266     AND    p1.effective_period_num =
267      ( SELECT min(effective_period_num)
268        FROM   gl_period_statuses p1
269        WHERE  p1.application_id = 101
270        AND    p1.ledger_id = X_Ledger_Id
271        AND    p1.effective_period_num >
272           ( SELECT effective_period_num
273             FROM gl_period_statuses p2
274             WHERE p2.application_id = 101
275             AND   p2.ledger_id = X_Ledger_Id
276             AND   p2.period_name = X_Je_Period_Name));
277 
278     CURSOR next_nonadj_period IS
279     SELECT period_name, closing_status, start_date, end_date
280     FROM   gl_period_statuses p
281     WHERE  p.application_id = 101
282     AND    p.ledger_id = X_Ledger_Id
283     AND    p.effective_period_num =
284      ( SELECT min(effective_period_num)
285        FROM   gl_period_statuses p1
286        WHERE  p1.application_id = 101
287        AND    p1.ledger_id = X_Ledger_Id
288        AND    adjustment_period_flag = 'N'
289        AND    p1.effective_period_num >
290           ( SELECT effective_period_num
291             FROM gl_period_statuses p2
292             WHERE p2.application_id = 101
293             AND   p2.ledger_id = X_Ledger_Id
294             AND   p2.period_name = X_Je_Period_Name));
295 
296      -- When the journal'next day falls into the next period,
297      -- reverse into the next non-adj period if the journal period is non-adj,
298      -- reverse into the next adjusting period if the journal period is adj.
299      -- note: min() neccessary because there may be overlapping adj periods
300      CURSOR next_day_to_period IS
301         SELECT period_name, closing_status, start_date, end_date
302         FROM   gl_period_statuses p
303         WHERE  p.application_id = 101
304         AND    p.ledger_id = X_Ledger_Id
305         AND    p.effective_period_num =
306           ( SELECT min(effective_period_num)
307             FROM   gl_period_statuses p1
308             WHERE  p1.application_id = 101
309             AND    p1.ledger_id = X_Ledger_Id
310             AND    reversal_date between p1.start_date and p1.end_date
311             AND    p1.adjustment_period_flag = adj_period_flag);
312 
313 BEGIN
314 
315     Error_Buffer := Null;
316 
317     OPEN get_lgr;
318     FETCH get_lgr INTO adb_lgr,cons_lgr,trxn_calendar_id,
319                   period_set,v_period_type,l_criteria_set_id;
320 
321     if (get_lgr%NOTFOUND) then
322       CLOSE get_lgr;
326     end if;
323       Error_Buffer := 'Cannot find ledger info for ledger id '
324                       ||X_Ledger_Id;
325       Raise NO_DATA_FOUND;
327 
328     if (l_criteria_set_id IS NULL) THEN
329 
330       get_default_reversal_data
331                        (X_Category_name        => X_Je_Category,
332                         X_adb_lgr_flag         =>adb_lgr,
333                         X_cons_lgr_flag        =>cons_lgr,
334                         X_Reversal_Method_code =>method_code,
335                         X_Reversal_Period_code =>period_rule,
336                         X_Reversal_Date_code   =>date_rule) ;
337 
338      CLOSE get_lgr;
339     else
340 
341        CLOSE get_lgr;
342        OPEN get_criteria;
343        FETCH get_criteria INTO method_code,period_rule,date_rule;
344 
345        if (get_criteria%NOTFOUND) then
346           CLOSE get_criteria;
347         Error_Buffer :=
348             'Cannot find reversal criteria for je category '||X_Je_Category;
349         Raise NO_DATA_FOUND;
350        end if;
351 
352 	CLOSE get_criteria;
353 
354     end if;
355 
356     IF (period_rule = 'NO_DEFAULT') THEN
357        Raise NO_DEFAULT;
358     ELSIF (period_rule = 'SAME_PERIOD') THEN
359 
360        OPEN same_period;
361        FETCH same_period INTO reversal_period,pstatus,start_date,end_date,
362                               adj_period_flag;
363        IF (same_period%NOTFOUND) THEN
364 
365             CLOSE same_period;
366             Error_Buffer := 'Invalid journal period '||X_Je_Period_Name;
367             Raise GET_REV_PERIOD_DATE_FAILED;
368        END IF;
369        CLOSE same_period;
370 
371     ELSIF (period_rule = 'NEXT_PERIOD') THEN
372        OPEN next_period;
373        FETCH next_period INTO reversal_period,pstatus,start_date,end_date,
374                               adj_period_flag;
375        IF (next_period%NOTFOUND) THEN
376             CLOSE next_period;
377             Error_Buffer := 'Cannot find the next period of '||X_Je_Period_Name;
378             Raise GET_REV_PERIOD_DATE_FAILED;
379        END IF;
380 
381        CLOSE next_period;
382     ELSIF (period_rule = 'NEXT_NON_ADJ_PERIOD') THEN
383        OPEN next_nonadj_period;
384        FETCH next_nonadj_period INTO reversal_period,pstatus,
385                                      start_date,end_date;
386        IF (next_nonadj_period%NOTFOUND) THEN
387             CLOSE next_nonadj_period;
388             Error_Buffer := 'Cannot find the next non-adjusting period of '||X_Je_Period_Name;
389             Raise GET_REV_PERIOD_DATE_FAILED;
390        END IF;
391        CLOSE next_nonadj_period;
392     ELSIF (period_rule = 'NEXT_DAY') THEN
393 
394      IF (adb_lgr  <> 'Y' OR
395           (adb_lgr =  'Y' AND cons_lgr =  'Y')) THEN
396             method_code := 'N';
397             Raise NO_DEFAULT;
398      ELSE
399 
400        reversal_date := X_Je_date + 1;
401 
402        -- Fetch the journal period info
403        OPEN same_period;
404        FETCH same_period INTO reversal_period,pstatus,start_date,end_date,
405                                   adj_period_flag;
406 
407        IF (same_period%NOTFOUND) THEN
408            CLOSE same_period;
409            Error_Buffer := 'Invalid journal period '||X_Je_Period_Name;
410            Raise GET_REV_PERIOD_DATE_FAILED;
411        END IF;
412        CLOSE same_period;
413 
414        -- Reset reversal date to a business day
415        -- when neccessary
416        -- IF adj_period_flag = 'N' THEN
417            get_business_day('NEXT_DAY', trxn_calendar_id, X_Je_Source,
418                        reversal_date);
419        -- END IF;
420 
421       -- if the reversal is not in the journal period, find the reversal period
422        IF ( reversal_date > end_date) THEN
423            OPEN next_day_to_period;
424            FETCH next_day_to_period INTO reversal_period,pstatus,
425                                      start_date,end_date;
426 
427            IF (next_day_to_period%NOTFOUND) THEN
428                --CLOSE next_day_to_period;
429                /*Added this code as part of bug9295385*/
430                --For the Adj journal, if the NEXT_DAY has no Adjusment period defined
431                --then pick up the period from the next non-adjusting period in which
432                --the NEXT_DAY falls into.
433                IF adj_period_flag  = 'Y' THEN
434 		       OPEN next_nonadj_period;
435 		       FETCH next_nonadj_period INTO reversal_period,pstatus,
436 						     start_date,end_date;
437 		       IF (next_nonadj_period%NOTFOUND) THEN
438 			    CLOSE next_nonadj_period;
439 			    Error_Buffer := 'Cannot find the next non-adjusting period of '||X_Je_Period_Name;
440 			    Raise GET_REV_PERIOD_DATE_FAILED;
441 		       END IF;
442 		       CLOSE next_nonadj_period;
443 		ELSE
444 		/*End of Addition*/
445 		   CLOSE next_day_to_period;
446                    Error_Buffer := 'Cannot find a reversal period for the next day '||reversal_date;
447                    Raise GET_REV_PERIOD_DATE_FAILED;
448                 END IF;---adj flag
449            END IF;
450            CLOSE next_day_to_period;
451        END IF;
452 
453      END IF; -- check for adb_lgr ends
454 
455     ELSE
456         Error_Buffer := 'Invalid Reversal_Period_Code in GL_REVERSE_OPTIONS for '||X_Je_Category;
457         Raise GET_REV_PERIOD_DATE_FAILED;
458     END IF;
459 
460     IF NOT (pstatus = 'O' OR pstatus = 'F') THEN
461        Error_Buffer := 'Reversal period '||reversal_period
462                   ||' is not open or futur-enterable';
463        Raise GET_REV_PERIOD_DATE_FAILED;
464     END IF;
465 
469 	-- as follows. When a new criteria set is created in Journal
466     IF (adb_lgr = 'Y' AND period_rule <> 'NEXT_DAY') THEN
467 
468         -- If the X_Date_Rule is NULL then default the date rules
470 	-- reversal criteria form then we don't know the type of ledger
471 	-- and so it is not able to default the date rule.
472 	-- Now it is the time to default it.
473 
474       IF ((Date_Rule IS NULL) AND (cons_lgr = 'N')) THEN
475          IF (X_JE_CATEGORY = 'Income Statement Close') OR
476               (X_JE_CATEGORY = 'Income Offset') THEN
477 	       date_rule := 'LAST_DAY';
478 	    ELSIF (X_JE_CATEGORY = 'Balance Sheet Close') THEN
479 	       date_rule := 'FIRST_DAY';
480          END IF;
481       END IF;
482 
483       get_reversal_date(reversal_period,adj_period_flag,
484                         period_rule,date_rule,cons_lgr,trxn_calendar_id,
485                         X_Je_Source,X_Je_Date,start_date,end_date,
486                         reversal_date);
487     END IF;
488 
489     X_Reversal_Period := reversal_period;
490     X_Reversal_Date := reversal_date;
491     X_Reversal_Method := method_code;
492 
493     -- populate message buffer for debugging
494     Error_Buffer := 'Get reversal info. Category='||X_Je_Category
495                     ||',Source='||X_Je_Source
496                     ||',Je Period='||X_Je_Period_Name||',Je Date='||X_Je_Date
497                     ||',Reversal Method='||X_Reversal_Method
498                     ||',Reversal Period='||X_Reversal_Period
499                     ||',Reversal Date='||to_char(X_Reversal_Date);
500 EXCEPTION
501     WHEN NO_DEFAULT THEN
502          X_Reversal_Method := method_code;
503          Error_Buffer := 'Get reversal info. Category='||X_Je_Category
504                     ||',Source='||X_Je_Source
505                     ||',Je Period='||X_Je_Period_Name||',Je Date='||X_Je_Date
506                     ||',Reversal Method='||X_Reversal_Method
507                     ||',Reversal Period Rule='||period_rule;
508     WHEN GET_REV_PERIOD_DATE_FAILED THEN
509 
510          Error_Buffer :=
511                     'GL_AUTOREVERSE_DATE_PKG.get_reversal_period_date.'
512                     ||Error_Buffer
513                     ||' Package parameters: Category='||X_Je_Category
514                     ||',Source='||X_Je_Source
515                     ||',Je Period='||X_Je_Period_Name||',Je Date='||X_Je_Date
516                     ||',Reversal Period Rule='||period_rule
517                     ||',Reversal Date Rule='||date_rule;
518          Raise;
519     WHEN OTHERS THEN
520          Error_Buffer :=
521                     'GL_AUTOREVERSE_DATE_PKG.get_reversal_period_date.'
522                     ||Error_Buffer||' : '||SUBSTRB(SQLERRM,1,100)
523                     ||' Package parameters: Category='||X_Je_Category
524                     ||',Source='||X_Je_Source
525                     ||',Je Period='||X_Je_Period_Name||',Je Date='||X_Je_Date
526                     ||',Reversal Period Rule='||period_rule
527                     ||',Reversal Date Rule='||date_rule;
528          Raise;
529          -- APP_EXCEPTION.raise_exception;
530 END get_reversal_period_date;
531 
532  -- Public procedure
533 
534 PROCEDURE GET_DEFAULT_REVERSAL_DATA
535                        (X_Category_name             VARCHAR2,
536                         X_adb_lgr_flag             VARCHAR2 DEFAULT 'N',
537                         X_cons_lgr_flag            VARCHAR2 DEFAULT 'N' ,
538                         X_Reversal_Method_code     IN OUT NOCOPY  VARCHAR2,
539                         X_Reversal_Period_code     IN OUT NOCOPY  VARCHAR2,
540                         X_Reversal_Date_code       IN OUT NOCOPY  VARCHAR2) IS
541 
542    BEGIN
543         IF ((X_CATEGORY_NAME = 'Income Statement Close') OR
544             (X_CATEGORY_NAME = 'Income Offset')OR
545              (X_CATEGORY_NAME = 'MRC Open Balances') OR
546               (X_CATEGORY_NAME = 'Revalue Profit/Loss')) THEN
547 
548 		 X_Reversal_Method_Code := 'Y';
549         ELSE
550 	         X_Reversal_Method_Code := 'N';
551 	END IF;
552 
553         IF ((X_CATEGORY_NAME = 'Income Statement Close') OR
554 	     (X_CATEGORY_NAME = 'Income Offset')) THEN
555 
556     	    	 X_Reversal_Period_code := 'SAME_PERIOD';
557 
558         ELSIF (X_CATEGORY_NAME = 'Balance Sheet Close') THEN
559 		 X_Reversal_Period_code := 'NEXT_PERIOD';
560         ELSE
561 		 X_Reversal_Period_code := 'NO_DEFAULT';
562         END IF;
563 
564        IF (X_adb_lgr_flag = 'Y') AND
565 	    (X_cons_lgr_flag = 'N') THEN
566 
567          IF (X_CATEGORY_NAME = 'Income Statement Close') OR
568              (X_CATEGORY_NAME = 'Income Offset') THEN
569 
570 	      X_Reversal_Date_code := 'LAST_DAY';
571 
572 	  ELSIF (X_CATEGORY_NAME = 'Balance Sheet Close') THEN
573 
574 		X_Reversal_Date_code := 'FIRST_DAY';
575           ELSE
576 		X_Reversal_Date_code := NULL;
577           END IF;
578        ELSE
579 		X_Reversal_Date_code := NULL;
580        END IF;
581 
582    EXCEPTION
583 	WHEN OTHERS THEN
584 	  Error_Buffer := '.get_defualt_reversal_data'||Error_Buffer;
585           Raise;
586   END GET_DEFAULT_REVERSAL_DATA;
587 
588  -- Public procedure
589 
590 PROCEDURE Get_Default_Reversal_Method
591                        (X_Ledger_Id                NUMBER,
592 			X_Category_name            VARCHAR2,
593                         X_Reversal_Method_code     IN OUT NOCOPY  VARCHAR2) IS
594 
595 
596 	adb_flag VARCHAR2(1);
597         cons_flag VARCHAR2(1);
598         reversal_period_rule  VARCHAR2(15);
599 	reversal_date_rule    VARCHAR2(15);
600 
601   BEGIN
602 	   SELECT DECODE(method_code,'C', 'Y', 'N'),
603                   gll.enable_average_balances_flag,
607                   adb_flag, cons_flag
604            	  gll.consolidation_ledger_flag
605 	   INTO
606 		  X_Reversal_Method_code,
608  	   FROM   GL_LEDGERS gll, GL_AUTOREVERSE_OPTIONS glao
609 	   WHERE  gll.ledger_id            = X_Ledger_Id
610 	   AND    glao.criteria_set_id(+)  = gll.Criteria_Set_Id
611            AND    glao.je_category_name(+) = X_Category_Name;
612 
613           -- The following call returns at least reversal method.
614 	  -- Journal Import, Recurring journal programs requires
615 	  -- reversal method code.
616 
617 	   IF (X_Reversal_Method_code IS NULL) THEN
618 
619               get_default_reversal_data
620                        (X_Category_name        => X_Category_Name,
621                         X_adb_lgr_flag         =>adb_flag,
622                         X_cons_lgr_flag        =>cons_flag,
623                         X_Reversal_Method_code =>X_Reversal_Method_code,
624                         X_Reversal_Period_code =>Reversal_Period_rule ,
625                         X_Reversal_Date_code   =>Reversal_Date_rule) ;
626           END IF;
627 
628 END Get_Default_Reversal_Method;
629 
630 END GL_AUTOREVERSE_DATE_PKG;