DBA Data[Home] [Help]

PACKAGE BODY: APPS.GL_PERIOD_STATUSES_PKG

Source


1 PACKAGE BODY gl_period_statuses_pkg AS
2 /* $Header: glipstab.pls 120.11 2006/08/11 12:31:49 aktelang ship $ */
3 
4 --
5 -- PRIVATE FUNCTIONS
6 --
7 
8   PROCEDURE check_for_gap (
9     x_periodsetname  IN    VARCHAR2,
10     x_periodtype     IN    VARCHAR2 ) IS
11 
12     not_assigned CONSTANT VARCHAR2(15) := 'NOT ASSIGNED';
13 
14     gap_date   DATE;
15     start_date DATE;
16     end_date   DATE;
17     beginning  DATE;
18     ending     DATE;
19 
20     CURSOR period_set IS
21       SELECT min(start_date) begins, max(end_date) ends
22       FROM gl_periods
23       WHERE period_set_name = x_periodsetname
24       AND   period_type     = x_periodtype;
25 
26     CURSOR gap_exists IS
27       SELECT accounting_date
28       FROM gl_date_period_map
29       WHERE period_name     = not_assigned
30       AND   period_set_name = x_periodsetname
31       AND   period_type     = x_periodtype
32       AND   accounting_date BETWEEN beginning AND ending;
33 
34     CURSOR gap_start IS
35       SELECT max(accounting_date)
36       FROM gl_date_period_map
37       WHERE period_name    <> not_assigned
38       AND   period_set_name = x_periodsetname
39       AND   period_type     = x_periodtype
40       AND   accounting_date < gap_date;
41 
42     CURSOR gap_end IS
43       SELECT min(accounting_date)
44       FROM gl_date_period_map
45       WHERE period_name    <> not_assigned
46       AND   period_set_name = x_periodsetname
47       AND   period_type     = x_periodtype
48       AND   accounting_date > gap_date;
49 
50  BEGIN
51     -- Open the gap_exists cursor and see if we get anything
52     OPEN period_set;
53     FETCH period_set INTO beginning, ending;
54     CLOSE period_set;
55     OPEN gap_exists;
56     FETCH gap_exists INTO gap_date;
57     IF gap_exists%NOTFOUND THEN
58       CLOSE gap_exists;
59     ELSE
60       CLOSE gap_exists;
61       -- Get the spanning dates
62       OPEN gap_start;
63       FETCH gap_start INTO start_date;
64       CLOSE gap_start;
65       OPEN gap_end;
66       FETCH gap_end INTO end_date;
67       CLOSE gap_end;
68       -- Tell the user
69       fnd_message.set_name('SQLGL', 'GL_GAP_IN_CALENDAR');
70       fnd_message.set_token('CALENDAR_NAME', x_periodsetname);
71       fnd_message.set_token('START_DATE', nvl(start_date, beginning));
72       fnd_message.set_token('END_DATE', nvl(end_date, ending));
73       RAISE app_exceptions.application_exception;
74     END IF;
75 
76   EXCEPTION
77     WHEN app_exceptions.application_exception THEN
78       RAISE;
79     WHEN OTHERS THEN
80       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
81       fnd_message.set_token('PROCEDURE',
82                             'gl_period_statuses_pkg.check_for_gap');
83       RAISE;
84   END check_for_gap;
85 
86 
87 --
88 -- PUBLIC FUNCTIONS
89 --
90 
91   FUNCTION default_actual_period(acc_id NUMBER,
92                                  led_id NUMBER) RETURN VARCHAR2 IS
93     CURSOR get_latest_opened IS
94       SELECT ps.period_name
95       FROM   gl_period_statuses ps,
96              gl_access_set_ledgers acc
97       WHERE  ps.application_id = 101
98       AND    ps.ledger_id = led_id
99       AND    ps.closing_status = 'O'
100       AND    acc.access_set_id = acc_id
101       AND    acc.ledger_id = ps.ledger_id
102       AND    acc.access_privilege_code IN ('B','F')
103       AND    ps.end_date between nvl(acc.start_date, ps.end_date-1)
104                          and nvl(acc.end_date, ps.end_date+1)
105       ORDER BY effective_period_num DESC;
106 
107     CURSOR get_earliest_future_ent IS
108       SELECT ps.period_name
109       FROM   gl_period_statuses ps,
110              gl_access_set_ledgers acc
111       WHERE  ps.application_id = 101
112       AND    ps.ledger_id = led_id
113       AND    ps.closing_status = 'F'
114       AND    acc.access_set_id = acc_id
115       AND    acc.ledger_id = ps.ledger_id
116       AND    acc.access_privilege_code IN ('B','F')
117       AND    ps.end_date between nvl(acc.start_date, ps.end_date-1)
118                          and nvl(acc.end_date, ps.end_date+1)
119       ORDER BY effective_period_num ASC;
120     default_period VARCHAR2(15);
121   BEGIN
122     OPEN get_latest_opened;
123     FETCH get_latest_opened INTO default_period;
124 
125     IF get_latest_opened%FOUND THEN
126       CLOSE get_latest_opened;
127       return(default_period);
128     ELSE
129       CLOSE get_latest_opened;
130 
131       OPEN get_earliest_future_ent;
132       FETCH get_earliest_future_ent INTO default_period;
133 
134       IF get_earliest_future_ent%FOUND THEN
135         CLOSE get_earliest_future_ent;
136         return(default_period);
137       ELSE
138         CLOSE get_earliest_future_ent;
139         fnd_message.set_name('SQLGL', 'GL_NO_OPEN_OR_FUTURE_PERIODS');
140         return(null);
141       END IF;
142     END IF;
143 
144   EXCEPTION
145     WHEN app_exceptions.application_exception THEN
146       RAISE;
147     WHEN OTHERS THEN
148       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
149       fnd_message.set_token('PROCEDURE',
150                             'gl_period_statuses_pkg.default_actual_period');
151       RAISE;
152   END default_actual_period;
153 
154 PROCEDURE get_next_period(
155         x_ledger_id       NUMBER,
156         x_period                VARCHAR2,
157         x_next_period   IN OUT NOCOPY  VARCHAR2 )  IS
158 
159   CURSOR c_period IS
160     SELECT ps1.period_name
161     FROM   gl_period_statuses ps1,
162            gl_period_statuses ps2
163     WHERE  ps1.application_id = 101
164     AND    ps1.ledger_id = x_ledger_id
165     AND    ps2.application_id = 101
166     AND    ps2.ledger_id = x_ledger_id
167     AND    ps2.period_name = x_period
168     AND    ( ps1.start_date =
169                ( SELECT MIN( ps3.start_date )
170                  FROM   gl_period_statuses ps3
171                  WHERE  ps3.application_id = 101
172                  AND    ps3.ledger_id = x_ledger_id
173                  AND    ps3.start_date > ps2.start_date ) )
174     AND     ps1.closing_status NOT IN ( 'N','C','P' );
175 
176   BEGIN
177     OPEN c_period;
178     FETCH c_period INTO x_next_period;
179     CLOSE c_period;
180 
181   EXCEPTION
182     WHEN NO_DATA_FOUND THEN
183       RETURN;
184     WHEN app_exceptions.application_exception THEN
185       RAISE;
186     WHEN OTHERS THEN
187       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
188       fnd_message.set_token('PROCEDURE',
189                             'gl_period_statuses_pkg.get_next_period');
190       RAISE;
191 
192   END get_next_period;
193 
194 
195 
196   PROCEDURE insert_led_ps(
197                         x_ledger_id       NUMBER,
198                         x_period_set_name       VARCHAR2,
199                         x_accounted_period_type VARCHAR2,
200                         x_last_update_date      DATE,
201                         x_last_updated_by       NUMBER,
202                         x_last_update_login     NUMBER,
203                         x_creation_date         DATE,
204                         x_created_by            NUMBER ) IS
205   BEGIN
206 
207     -- Before doing anything else...
208     check_for_gap(x_period_set_name, x_accounted_period_type);
209 
210     LOCK TABLE GL_PERIOD_STATUSES IN SHARE UPDATE MODE;
211 
212     INSERT INTO GL_PERIOD_STATUSES
213     ( application_id,
214       ledger_id,
215       set_of_books_id,
216       period_name,
217       closing_status,
218       start_date,
219       end_date,
220       period_type,
221       period_year,
222       period_num,
223       quarter_num,
224       last_update_date,
225       last_updated_by,
226       last_update_login,
227       creation_date,
228       created_by,
229       adjustment_period_flag,
230       quarter_start_date,
231       year_start_date,
232       effective_period_num,
233       migration_status_code)
234     SELECT
235       ag.application_id,
236       x_ledger_id,
237       x_ledger_id,
238       p.period_name,
239       'N',
240       p.start_date,
241       p.end_date,
242       p.period_type,
243       p.period_year,
244       p.period_num,
245       p.quarter_num,
246       x_last_update_date,
247       x_last_updated_by,
248       x_last_update_login,
249       x_creation_date,
250       x_created_by,
251       p.adjustment_period_flag,
252       p.quarter_start_date,
253       p.year_start_date,
254       p.period_year*10000 + p.period_num,
255       'N'
256     FROM
257       GL_APPLICATION_GROUPS ag,
258       GL_PERIODS p
259     WHERE p.period_set_name = x_period_set_name
260     AND   p.period_type = x_accounted_period_type
261     AND   ag.group_name = 'PERIOD_STATUS'
262     AND   EXISTS ( SELECT 'Application Installed'
263                    FROM   FND_PRODUCT_INSTALLATIONS pr
264 		   WHERE  pr.application_id = ag.application_id );
265 
266   EXCEPTION
267     WHEN NO_DATA_FOUND THEN
268       RETURN;
269     WHEN app_exceptions.application_exception THEN
270       RAISE;
271     WHEN OTHERS THEN
272       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
273       fnd_message.set_token('PROCEDURE',
274                             'gl_period_statuses_pkg.insert_led_ps');
275       RAISE;
276 
277   END insert_led_ps;
278 
279 
280   PROCEDURE insert_ps_api( x_appl_id               NUMBER,
281                            x_ledger_id       NUMBER,
282                            x_period_name           VARCHAR2,
283                            x_status                VARCHAR2,
284                            x_period_set_name       VARCHAR2,
285 			   x_user_id               NUMBER,
286 			   x_login_id              NUMBER ) IS
287 
288 
289   BEGIN
290 
291     LOCK TABLE GL_PERIOD_STATUSES IN SHARE UPDATE MODE;
292 
293     INSERT INTO GL_PERIOD_STATUSES
294     ( application_id,
295       ledger_id,
296       set_of_books_id,
297       period_name,
298       closing_status,
299       start_date,
300       end_date,
301       period_type,
302       period_year,
303       period_num,
304       quarter_num,
305       last_update_date,
306       last_updated_by,
307       last_update_login,
308       creation_date,
309       created_by,
310       adjustment_period_flag,
311       quarter_start_date,
312       year_start_date,
313       effective_period_num,
314       migration_status_code)
315     SELECT
316       x_appl_id,
317       x_ledger_id,
318       x_ledger_id,
319       x_period_name,
320       x_status,
321       GP.start_date,
322       GP.end_date,
323       GP.period_type,
324       GP.period_year,
325       GP.period_num,
326       GP.quarter_num,
327       sysdate,
328       x_user_id,
329       x_login_id,
330       sysdate,
331       x_user_id,
332       GP.adjustment_period_flag,
333       GP.quarter_start_date,
334       GP.year_start_date,
335       GP.period_year*10000 + GP.period_num,
336       'N'
337     FROM
338       GL_PERIODS GP,
339       GL_LEDGERS LD
340     WHERE GP.period_set_name =  nvl(x_period_set_name, LD.period_set_name)
341     AND   GP.period_name = x_period_name
342     AND   LD.ledger_id = x_ledger_id;
343 
344   EXCEPTION
345     WHEN NO_DATA_FOUND THEN
346       RAISE;
347     WHEN DUP_VAL_ON_INDEX THEN
348       NULL;
349     WHEN app_exceptions.application_exception THEN
350       RAISE;
351     WHEN OTHERS THEN
352       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
353       fnd_message.set_token('PROCEDURE',
354                             'gl_period_statuses_pkg.insert_ps_api');
355       RAISE;
356 
357   END insert_ps_api;
358 
359 
360   PROCEDURE insert_period(
361 			x_calendar_name		VARCHAR2,
362                       	x_period_name 		VARCHAR2,
363 			x_start_date		DATE,
364 			x_end_date		DATE,
365  			x_period_type 		VARCHAR2,
366                      	x_period_year 		NUMBER,
367                        	x_period_num  		NUMBER,
368 			x_quarter_num 		NUMBER,
369 			x_adj_period_flag 	VARCHAR2,
370 			x_last_updated_by	NUMBER,
371 			x_last_update_login	NUMBER,
372 			x_quarter_start_date	DATE,
373       			x_year_start_date	DATE) IS
374   BEGIN
375 
376     INSERT INTO GL_PERIOD_STATUSES
377     ( application_id,
378       ledger_id,
379       set_of_books_id,
380       period_name,
381       closing_status,
382       start_date,
383       end_date,
384       period_type,
385       period_year,
386       period_num,
387       quarter_num,
388       last_update_date,
389       last_updated_by,
390       last_update_login,
391       creation_date,
392       created_by,
393       adjustment_period_flag,
394       quarter_start_date,
395       year_start_date,
396       effective_period_num,
397       migration_status_code)
398     SELECT
399       ag.application_id,
400       led.ledger_id,
401       led.ledger_id,
402       x_period_name,
403       'N',
404       x_start_date,
405       x_end_date,
406       x_period_type,
407       x_period_year,
408       x_period_num,
409       x_quarter_num,
410       sysdate,
411       x_last_updated_by,
412       x_last_update_login,
413       sysdate,
414       x_last_updated_by,
415       x_adj_period_flag,
416       x_quarter_start_date,
417       x_year_start_date,
418       x_period_year * 10000 + x_period_num,
419       'N'
420     FROM
421       GL_APPLICATION_GROUPS ag,
422       GL_LEDGERS led
423     WHERE ag.group_name = 'PERIOD_STATUS'
424     AND   led.period_set_name = x_calendar_name
425     AND   led.accounted_period_type = x_period_type
426     AND   EXISTS ( SELECT 'Application Installed'
427                    FROM   FND_PRODUCT_INSTALLATIONS pr
428 		   WHERE  pr.application_id = ag.application_id );
429 
430   EXCEPTION
431     WHEN NO_DATA_FOUND THEN
432       RETURN;
433     WHEN app_exceptions.application_exception THEN
434       RAISE;
435     WHEN OTHERS THEN
436       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
437       fnd_message.set_token('PROCEDURE',
438                             'gl_period_statuses_pkg.insert_period');
439       RAISE;
440   END insert_period;
441 
442 
443   PROCEDURE update_period(
444 			x_calendar_name		VARCHAR2,
445  			x_old_period_name	VARCHAR2,
446                       	x_period_name 		VARCHAR2,
447 			x_start_date		DATE,
448 			x_end_date		DATE,
449  			x_period_type 		VARCHAR2,
450                      	x_period_year 		NUMBER,
451                        	x_period_num  		NUMBER,
452 			x_quarter_num 		NUMBER,
453 			x_adj_period_flag 	VARCHAR2,
454 			x_last_updated_by	NUMBER,
455 			x_last_update_login	NUMBER) IS
456   BEGIN
457 
458     UPDATE GL_PERIOD_STATUSES ps
459     SET    ps.period_name = x_period_name,
460            ps.start_date  = x_start_date,
461            ps.end_date    = x_end_date,
462            ps.period_type = x_period_type,
463            ps.period_year = x_period_year,
464            ps.quarter_num = x_quarter_num,
465            ps.period_num  = x_period_num,
466            ps.adjustment_period_flag = x_adj_period_flag,
467            ps.last_update_date  = sysdate,
468            ps.last_updated_by   = x_last_updated_by,
472   AND    ps.ledger_id IN
469            ps.last_update_login = x_last_update_login,
470            ps.effective_period_num = x_period_year * 10000 + x_period_num
471   WHERE  ps.period_name = x_old_period_name
473          ( SELECT led.ledger_id
474            FROM   GL_LEDGERS led
475            WHERE  led.period_set_name = x_calendar_name );
476 
477   exception
478     WHEN NO_DATA_FOUND THEN
479       RETURN;
480     WHEN app_exceptions.application_exception THEN
481       RAISE;
482     WHEN OTHERS THEN
483       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
484       fnd_message.set_token('PROCEDURE',
485                             'gl_period_statuses_pkg.update_period');
486       RAISE;
487   END update_period;
488 
489 
490   PROCEDURE delete_period(
491 		x_calendar_name		VARCHAR2,
492  		x_old_period_name	VARCHAR2) IS
493   BEGIN
494     DELETE gl_period_statuses ps
495     WHERE  ps.period_name = x_old_period_name
496     AND    ps.ledger_id in
497            (SELECT led.ledger_id
498             FROM   gl_ledgers led
499             WHERE  led.period_set_name = x_calendar_name);
500 
501   exception
502     WHEN NO_DATA_FOUND THEN
503       RETURN;
504     WHEN app_exceptions.application_exception THEN
505       RAISE;
506     WHEN OTHERS THEN
507       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
508       fnd_message.set_token('PROCEDURE',
509                             'gl_period_statuses_pkg.delete_period');
510       RAISE;
511   END delete_period;
512 
513 
514   PROCEDURE select_row( recinfo IN OUT NOCOPY gl_period_statuses%ROWTYPE )  IS
515   BEGIN
516     SELECT  *
517     INTO    recinfo
518     FROM    gl_period_statuses
519     WHERE   application_id = recinfo.application_id
520     AND     ledger_id = recinfo.ledger_id
521     AND     period_name = recinfo.period_name ;
522   EXCEPTION
523     WHEN NO_DATA_FOUND THEN
524       RETURN;
525     WHEN app_exceptions.application_exception THEN
526       RAISE;
527     WHEN OTHERS THEN
528       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
529       fnd_message.set_token('PROCEDURE',
530                             'gl_period_statuses_pkg.select_row');
531       RAISE;
532   END select_row;
533 
534 
535   PROCEDURE select_columns(
536               x_application_id            NUMBER,
537               x_ledger_id           NUMBER,
538               x_period_name               VARCHAR2,
539               x_closing_status    IN OUT NOCOPY  VARCHAR2,
540               x_start_date        IN OUT NOCOPY  DATE,
541               x_end_date          IN OUT NOCOPY  DATE,
542               x_period_num        IN OUT NOCOPY  NUMBER,
543               x_period_year       IN OUT NOCOPY  NUMBER ) IS
544     recinfo gl_period_statuses%ROWTYPE;
545   BEGIN
546     recinfo.application_id := x_application_id;
547     recinfo.ledger_id := x_ledger_id;
548     recinfo.period_name := x_period_name;
549     select_row( recinfo );
550     x_closing_status := recinfo.closing_status;
551     x_start_date := recinfo.start_date;
552     x_end_date := recinfo.end_date;
553     x_period_num := recinfo.period_num;
554     x_period_year := recinfo.period_year;
555   EXCEPTION
556     WHEN NO_DATA_FOUND THEN
557       RETURN;
558     WHEN app_exceptions.application_exception THEN
559       RAISE;
560     WHEN OTHERS THEN
561       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
562       fnd_message.set_token('PROCEDURE',
563                             'gl_period_statuses_pkg.select_columns');
564       RAISE;
565   END select_columns;
566 
567 
568   PROCEDURE initialize_period_statuses(
569               x_application_id            NUMBER,
570               x_ledger_id           NUMBER,
571               x_period_year               NUMBER,
572               x_period_num                NUMBER,
573               x_user_id                   NUMBER )  IS
574 
575     v_fut_ent_periods_limit   NUMBER(15);
576     v_num_periods_updated     NUMBER(15);
577     v_period_type             VARCHAR2(15);
578 
579   BEGIN
580     select led.future_enterable_periods_limit,
581            led.accounted_period_type
582     into   v_fut_ent_periods_limit,
583            v_period_type
584     from   gl_ledgers led
585     where  led.ledger_id = x_ledger_id;
586 
587     update gl_period_statuses ps
588        set ps.closing_status =
589             decode(ps.period_year, x_period_year,
590                    decode(ps.period_num, x_period_num,'O',
591                           'F'),
592                     'F'),
593            ps.last_update_date = sysdate,
594            ps.last_updated_by = x_user_id
595      where ps.ledger_id = x_ledger_id
596        and ps.application_id = x_application_id
597        and ps.period_name in
598            (select period_name
599               from gl_period_statuses ps1,
600                    gl_period_types pt
601              where v_period_type = pt.period_type
602                and ps1.application_id        = x_application_id
603                and ps1.ledger_id       = x_ledger_id
604                and ps1.period_type           = pt.period_type
605                and ((ps1.period_year * pt.number_per_fiscal_year +
609                    and (ps1.period_year * pt.number_per_fiscal_year +
606                      ps1.period_num) >=
607                     (x_period_year * pt.number_per_fiscal_year +
608                      x_period_num)
610                         ps1.period_num) <=
611                        (x_period_year * pt.number_per_fiscal_year +
612                         x_period_num +
613                         v_fut_ent_periods_limit))) ;
614 
615     -- Count the number of periods updated
616     v_num_periods_updated := SQL%ROWCOUNT;
617 
618     -- If some future enterable periods are not yet defined,
619     -- raise an error
620     IF (v_num_periods_updated <> (v_fut_ent_periods_limit + 1)) THEN
621       fnd_message.set_name('SQLGL', 'GL_MISSING_FUT_ENT_PERIODS');
622       RAISE NO_DATA_FOUND;
623     END IF;
624 
625   EXCEPTION
626     WHEN app_exceptions.application_exception THEN
627       RAISE;
628     WHEN OTHERS THEN
629       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
630       fnd_message.set_token('PROCEDURE',
631         'gl_period_statuses_pkg.initialize_period_statuses');
632       RAISE;
633   END initialize_period_statuses;
634 
635 PROCEDURE select_encumbrance_periods(
636 	x_application_id			NUMBER,
637         x_ledger_id       		NUMBER,
638 	x_first_period			IN OUT NOCOPY	VARCHAR2,
639 	x_first_period_start_date	IN OUT NOCOPY	DATE,
640 	x_second_period			IN OUT NOCOPY	VARCHAR2,
641 	x_second_period_year		IN OUT NOCOPY	NUMBER,
642 	x_second_period_start_date	IN OUT NOCOPY	DATE)  IS
643 
644   CURSOR c_period IS
645     SELECT 	PS1.period_name,
646    	    	PS1.start_date,
647        		PS2.period_name,
648        		PS2.period_year,
649        		PS2.start_date
650     FROM   	GL_LEDGERS LED,
651        		GL_PERIOD_STATUSES PS1,
652        		GL_PERIOD_STATUSES PS2,
653        		GL_PERIOD_TYPES GPT
654     WHERE  	PS1.application_id = x_application_id
655     AND    	PS1.closing_status || '' in ('C', 'P')
656     AND    	PS1.ledger_id = x_ledger_id
657     AND    	PS1.period_type = GPT.period_type
658     AND         PS1.period_year * GPT.number_per_fiscal_year +
659 		PS1.period_num + 1
660        		= PS2.period_year * GPT.number_per_fiscal_year + PS2.period_num
661     AND    	PS2.application_id = x_application_id
662     AND    	PS2.ledger_id = x_ledger_id
663     AND    	PS2.period_num = 1
664     AND    	LED.ledger_id = x_ledger_id
665     AND         PS2.period_year <= LED.latest_encumbrance_year;
666 
667   BEGIN
668     OPEN c_period;
669     FETCH c_period INTO x_first_period,
670 			x_first_period_start_date,
671 			x_second_period,
672 			x_second_period_year,
673 			x_second_period_start_date;
674     CLOSE c_period;
675 
676   EXCEPTION
677     WHEN NO_DATA_FOUND THEN
678       RETURN;
679     WHEN app_exceptions.application_exception THEN
680       RAISE;
681     WHEN OTHERS THEN
682       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
683       fnd_message.set_token('PROCEDURE',
684                         'gl_period_statuses_pkg.select_encumbrance_periods');
685       RAISE;
686 
687   END select_encumbrance_periods;
688 
689 
690 PROCEDURE select_prior_year_1st_period(
691         x_application_id                        NUMBER,
692         x_ledger_id                       NUMBER,
693 	x_period_year				NUMBER,
694 	x_period_name		IN OUT NOCOPY		VARCHAR2) IS
695 
696   CURSOR c_period IS
697     SELECT 	period_name
698     FROM   	GL_PERIOD_STATUSES
699     WHERE  	application_id = x_application_id
700     AND    	ledger_id = x_ledger_id
701     AND         period_year = x_period_year - 1
702     AND         period_num = (SELECT min(period_num)
703                      FROM   GL_PERIOD_STATUSES
704                      WHERE  application_id = x_application_id
705                      AND    ledger_id = x_ledger_id
706                      AND    period_year = x_period_year - 1);
707 
708   BEGIN
709     OPEN c_period;
710     FETCH c_period INTO x_period_name;
711     CLOSE c_period;
712 
713   EXCEPTION
714     WHEN NO_DATA_FOUND THEN
715       RETURN;
716     WHEN app_exceptions.application_exception THEN
717       RAISE;
718     WHEN OTHERS THEN
719       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
720       fnd_message.set_token('PROCEDURE',
721                         'gl_period_statuses_pkg.select_prior_year_1st_period');
722       RAISE;
723   END select_prior_year_1st_period;
724 
725 
726 
727 PROCEDURE select_year_1st_period(
728         x_application_id                        NUMBER,
729         x_ledger_id                       NUMBER,
730         x_period_year                           NUMBER,
731         x_period_name           IN OUT NOCOPY          VARCHAR2) IS
732 
733   CURSOR c_period IS
734     select
735         period_name
736     from
737         gl_period_statuses s1
738     where
739         s1.application_id = x_application_id
740     and s1.ledger_id = x_ledger_id
741     and s1.period_year = x_period_year
742     and s1.period_num = (select min(period_num)
743                          from  gl_period_statuses s2
744                          where s2.period_year = x_period_year
748   BEGIN
745                          and   s2.application_id = x_application_id
746                          and   s2.ledger_id = x_ledger_id);
747 
749     OPEN c_period;
750     FETCH c_period INTO x_period_name;
751     CLOSE c_period;
752 
753   EXCEPTION
754     WHEN NO_DATA_FOUND THEN
755       RETURN;
756     WHEN app_exceptions.application_exception THEN
757       RAISE;
758     WHEN OTHERS THEN
759       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
760       fnd_message.set_token('PROCEDURE',
761                         'gl_period_statuses_pkg.select_year_1st_period');
762       RAISE;
763   END select_year_1st_period;
764 
765 
766   PROCEDURE get_extended_quarter(
767               x_application_id                       NUMBER,
768               x_ledger_id                      NUMBER,
769               x_period_year                          NUMBER,
770               x_period_name                          VARCHAR2,
771               x_period_set_name                      VARCHAR2,
772               x_accounted_period_type                VARCHAR2,
773               x_period_used_for_ext_actuals   IN OUT NOCOPY VARCHAR2,
774               x_num_used_for_ext_actuals      IN OUT NOCOPY NUMBER,
775               x_year_used_for_ext_actuals     IN OUT NOCOPY NUMBER,
776               x_quarter_used_for_ext_actuals  IN OUT NOCOPY NUMBER ) IS
777 
778   CURSOR c_qtde IS
779   select
780         period_name, period_num, period_year, quarter_num
781   from
782         gl_period_statuses
783   where
784         application_id = x_application_id
785   and   ledger_id = x_ledger_id
786   and   period_year = x_period_year
787   and   period_num = (select max(glps.period_num)
788                       from gl_period_statuses glps
789                       where glps.closing_status in ('O','C','P')
790                       and glps.quarter_num = (
791                                 select quarter_num from gl_periods
792                                 where period_name = x_period_name
793                                 and period_set_name = x_period_set_name)
794                       and glps.period_year = x_period_year
795                       and glps.application_id = 101
796                       and glps.ledger_id = x_ledger_id
797                       and glps.period_type = x_accounted_period_type );
798   /* Removed the redundant join to the GL_PERIODS table
799   for perf.bug Fix 2925883*/
800 
801 
802   BEGIN
803     OPEN c_qtde;
804     FETCH c_qtde INTO x_period_used_for_ext_actuals,
805                       x_num_used_for_ext_actuals,
806                       x_year_used_for_ext_actuals,
807                       x_quarter_used_for_ext_actuals;
808     CLOSE c_qtde;
809 
810   EXCEPTION
811     WHEN NO_DATA_FOUND THEN
812       RETURN;
813     WHEN app_exceptions.application_exception THEN
814       RAISE;
815     WHEN OTHERS THEN
816       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
817       fnd_message.set_token('PROCEDURE',
818                         'gl_period_statuses_pkg.get_extended_quarter');
819       RAISE;
820   END get_extended_quarter;
821 
822 
823   PROCEDURE get_extended_year(
824               x_application_id                       NUMBER,
825               x_ledger_id                      NUMBER,
826               x_period_year                          NUMBER,
827               x_accounted_period_type                VARCHAR2,
828               x_period_used_for_ext_actuals   IN OUT NOCOPY VARCHAR2,
829               x_num_used_for_ext_actuals      IN OUT NOCOPY NUMBER,
830               x_year_used_for_ext_actuals     IN OUT NOCOPY NUMBER,
831               x_quarter_used_for_ext_actuals  IN OUT NOCOPY NUMBER ) IS
832 
833   CURSOR c_ytde IS
834     select
835         period_name, period_num, period_year, quarter_num
836     from
837         gl_period_statuses
838     where
839         application_id = x_application_id
840     and ledger_id = x_ledger_id
841     and period_year = x_period_year
842     and period_num = (select max(period_num)
843                       from gl_period_statuses
844                       where period_type = x_accounted_period_type
845                       and ledger_id = x_ledger_id
846                       and period_year = x_period_year
847                       and closing_status in ('O','C','P')
848                       and application_id = x_application_id);
849 
850   BEGIN
851     OPEN c_ytde;
852     FETCH c_ytde INTO x_period_used_for_ext_actuals,
853                       x_num_used_for_ext_actuals,
854                       x_year_used_for_ext_actuals,
855                       x_quarter_used_for_ext_actuals;
856     CLOSE c_ytde;
857 
858   EXCEPTION
859     WHEN NO_DATA_FOUND THEN
860       RETURN;
861     WHEN app_exceptions.application_exception THEN
862       RAISE;
863     WHEN OTHERS THEN
864       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
865       fnd_message.set_token('PROCEDURE',
866                         'gl_period_statuses_pkg.get_extended_year');
867       RAISE;
868   END get_extended_year;
869 
870 
871 
872   PROCEDURE Insert_Row(X_Rowid                   IN OUT NOCOPY VARCHAR2,
873                        X_Application_Id                 NUMBER,
877                        X_Last_Updated_By                NUMBER,
874                        X_Ledger_Id                NUMBER,
875                        X_Period_Name                    VARCHAR2,
876                        X_Last_Update_Date               DATE,
878                        X_Closing_Status                 VARCHAR2,
879                        X_Start_Date                     DATE,
880                        X_End_Date                       DATE,
881                        X_Period_Type                    VARCHAR2,
882                        X_Period_Year                    NUMBER,
883                        X_Period_Num                     NUMBER,
884                        X_Quarter_Num                    NUMBER,
885                        X_Adjustment_Period_Flag         VARCHAR2,
886                        X_Creation_Date                  DATE,
887                        X_Created_By                     NUMBER,
888                        X_Last_Update_Login              NUMBER,
889                        X_Attribute1                     VARCHAR2,
890                        X_Attribute2                     VARCHAR2,
891                        X_Attribute3                     VARCHAR2,
892                        X_Attribute4                     VARCHAR2,
893                        X_Attribute5                     VARCHAR2,
894                        X_Context                        VARCHAR2
895 
896    ) IS
897      CURSOR C IS SELECT rowid FROM gl_period_statuses
898                  WHERE application_id = X_Application_Id
899 
900                  AND   ledger_id = X_Ledger_Id
901 
902                  AND   period_name = X_Period_Name;
903 
904 
905 
906     BEGIN
907 
908 
909        INSERT INTO gl_period_statuses(
910                application_id,
911                ledger_id,
912                set_of_books_id,
913                period_name,
914                last_update_date,
915                last_updated_by,
916                closing_status,
917                start_date,
918                end_date,
919                period_type,
920                period_year,
921                period_num,
922                quarter_num,
923                adjustment_period_flag,
924                creation_date,
925                created_by,
926                last_update_login,
927                attribute1,
928                attribute2,
929                attribute3,
930                attribute4,
931                attribute5,
932                context,
933                effective_period_num,
934                migration_status_code
935              ) VALUES (
936                X_Application_Id,
937                X_Ledger_Id,
938                X_Ledger_Id,
939                X_Period_Name,
940                X_Last_Update_Date,
941                X_Last_Updated_By,
942                X_Closing_Status,
943                X_Start_Date,
944                X_End_Date,
945                X_Period_Type,
946                X_Period_Year,
947                X_Period_Num,
948                X_Quarter_Num,
949                X_Adjustment_Period_Flag,
950                X_Creation_Date,
951                X_Created_By,
952                X_Last_Update_Login,
953                X_Attribute1,
954                X_Attribute2,
955                X_Attribute3,
956                X_Attribute4,
957                X_Attribute5,
958                X_Context,
959                X_period_year * 10000 + x_period_num,
960                'N'
961              );
962 
963     OPEN C;
964     FETCH C INTO X_Rowid;
965     if (C%NOTFOUND) then
966       CLOSE C;
967       Raise NO_DATA_FOUND;
968     end if;
969     CLOSE C;
970   END Insert_Row;
971 
972 
973   PROCEDURE Lock_Row(X_Rowid                            VARCHAR2,
974                      X_Application_Id                   NUMBER,
975                      X_Ledger_Id                  NUMBER,
976                      X_Period_Name                      VARCHAR2,
977                      X_Closing_Status                   VARCHAR2,
978                      X_Start_Date                       DATE,
979                      X_End_Date                         DATE,
980                      X_Period_Type                      VARCHAR2,
981                      X_Period_Year                      NUMBER,
982                      X_Period_Num                       NUMBER,
983                      X_Quarter_Num                      NUMBER,
984                      X_Adjustment_Period_Flag           VARCHAR2,
985                      X_Attribute1                       VARCHAR2,
986                      X_Attribute2                       VARCHAR2,
987                      X_Attribute3                       VARCHAR2,
988                      X_Attribute4                       VARCHAR2,
989                      X_Attribute5                       VARCHAR2,
990                      X_Context                          VARCHAR2
991 
992   ) IS
993     CURSOR C IS
994         SELECT *
995         FROM   gl_period_statuses
996         WHERE  rowid = X_Rowid
997         FOR UPDATE of Application_Id NOWAIT;
998     Recinfo C%ROWTYPE;
999   BEGIN
1000     OPEN C;
1004       FND_MESSAGE.Set_Name('FND', 'FORM_RECORD_DELETED');
1001     FETCH C INTO Recinfo;
1002     if (C%NOTFOUND) then
1003       CLOSE C;
1005       APP_EXCEPTION.Raise_Exception;
1006     end if;
1007     CLOSE C;
1008     if (
1009                (Recinfo.application_id = X_Application_Id)
1010            AND (Recinfo.ledger_id = X_Ledger_Id)
1011            AND (Recinfo.period_name = X_Period_Name)
1012            AND (Recinfo.closing_status = X_Closing_Status)
1013            AND (Recinfo.start_date = X_Start_Date)
1014            AND (Recinfo.end_date = X_End_Date)
1015            AND (Recinfo.period_type = X_Period_Type)
1016            AND (Recinfo.period_year = X_Period_Year)
1017            AND (Recinfo.period_num = X_Period_Num)
1018            AND (Recinfo.quarter_num = X_Quarter_Num)
1019            AND (Recinfo.adjustment_period_flag = X_Adjustment_Period_Flag)
1020            AND (   (Recinfo.attribute1 = X_Attribute1)
1021                 OR (    (Recinfo.attribute1 IS NULL)
1022                     AND (X_Attribute1 IS NULL)))
1023            AND (   (Recinfo.attribute2 = X_Attribute2)
1024                 OR (    (Recinfo.attribute2 IS NULL)
1025                     AND (X_Attribute2 IS NULL)))
1026            AND (   (Recinfo.attribute3 = X_Attribute3)
1027                 OR (    (Recinfo.attribute3 IS NULL)
1028                     AND (X_Attribute3 IS NULL)))
1029            AND (   (Recinfo.attribute4 = X_Attribute4)
1030                 OR (    (Recinfo.attribute4 IS NULL)
1031                     AND (X_Attribute4 IS NULL)))
1032            AND (   (Recinfo.attribute5 = X_Attribute5)
1033                 OR (    (Recinfo.attribute5 IS NULL)
1034                     AND (X_Attribute5 IS NULL)))
1035            AND (   (Recinfo.context = X_Context)
1036                 OR (    (Recinfo.context IS NULL)
1037                     AND (X_Context IS NULL)))
1038 
1039             ) then
1040       return;
1041     else
1042       FND_MESSAGE.Set_Name('FND', 'FORM_RECORD_CHANGED');
1043       APP_EXCEPTION.RAISE_EXCEPTION;
1044     end if;
1045   END Lock_Row;
1046 
1047 
1048   PROCEDURE Update_Row(X_Rowid                          VARCHAR2,
1049                        X_Application_Id                 NUMBER,
1050                        X_Ledger_Id                NUMBER,
1051                        X_Period_Name                    VARCHAR2,
1052                        X_Last_Update_Date               DATE,
1053                        X_Last_Updated_By                NUMBER,
1054                        X_Closing_Status                 VARCHAR2,
1055                        X_Start_Date                     DATE,
1056                        X_End_Date                       DATE,
1057                        X_Period_Type                    VARCHAR2,
1058                        X_Period_Year                    NUMBER,
1059                        X_Period_Num                     NUMBER,
1060                        X_Quarter_Num                    NUMBER,
1061                        X_Adjustment_Period_Flag         VARCHAR2,
1062                        X_Last_Update_Login              NUMBER,
1063                        X_Attribute1                     VARCHAR2,
1064                        X_Attribute2                     VARCHAR2,
1065                        X_Attribute3                     VARCHAR2,
1066                        X_Attribute4                     VARCHAR2,
1067                        X_Attribute5                     VARCHAR2,
1068                        X_Context                        VARCHAR2
1069 
1070  ) IS
1071  BEGIN
1072 
1073    IF (X_Closing_Status IN ('C', 'P')) THEN
1074       UPDATE gl_period_statuses
1075       SET
1076         application_id                    =     X_Application_Id,
1077      	ledger_id                         =     X_Ledger_Id,
1078      	period_name                       =     X_Period_Name,
1079      	last_update_date                  =     X_Last_Update_Date,
1080      	last_updated_by                   =     X_Last_Updated_By,
1081      	closing_status                    =     X_Closing_Status,
1082      	start_date                        =     X_Start_Date,
1083      	end_date                          =     X_End_Date,
1084      	period_type                       =     X_Period_Type,
1085      	period_year                       =     X_Period_Year,
1086      	period_num                        =     X_Period_Num,
1087      	quarter_num                       =     X_Quarter_Num,
1088      	adjustment_period_flag            =     X_Adjustment_Period_Flag,
1089         elimination_confirmed_flag        =     'Y',
1090      	last_update_login                 =     X_Last_Update_Login,
1091      	attribute1                        =     X_Attribute1,
1092      	attribute2                        =     X_Attribute2,
1093      	attribute3                        =     X_Attribute3,
1094      	attribute4                        =     X_Attribute4,
1095      	attribute5                        =     X_Attribute5,
1096      	context                           =     X_Context,
1097      	effective_period_num	          =     X_Period_Year * 10000 + X_Period_Num
1098 
1099       WHERE rowid = X_rowid;
1100    ELSE
1101       UPDATE gl_period_statuses
1102       SET
1103         application_id                    =     X_Application_Id,
1104         ledger_id                         =     X_Ledger_Id,
1105      	period_name                       =     X_Period_Name,
1109      	start_date                        =     X_Start_Date,
1106      	last_update_date                  =     X_Last_Update_Date,
1107      	last_updated_by                   =     X_Last_Updated_By,
1108      	closing_status                    =     X_Closing_Status,
1110      	end_date                          =     X_End_Date,
1111      	period_type                       =     X_Period_Type,
1112      	period_year                       =     X_Period_Year,
1113      	period_num                        =     X_Period_Num,
1114      	quarter_num                       =     X_Quarter_Num,
1115      	adjustment_period_flag            =     X_Adjustment_Period_Flag,
1116      	last_update_login                 =     X_Last_Update_Login,
1117      	attribute1                        =     X_Attribute1,
1118      	attribute2                        =     X_Attribute2,
1119      	attribute3                        =     X_Attribute3,
1120      	attribute4                        =     X_Attribute4,
1121      	attribute5                        =     X_Attribute5,
1122      	context                           =     X_Context,
1123      	effective_period_num	          =     X_Period_Year * 10000 + X_Period_Num
1124       WHERE rowid = X_rowid;
1125    END IF;
1126 
1127 
1128     if (SQL%NOTFOUND) then
1129       Raise NO_DATA_FOUND;
1130     end if;
1131 
1132   END Update_Row;
1133 
1134   PROCEDURE Delete_Row(X_Rowid VARCHAR2) IS
1135   BEGIN
1136     DELETE FROM gl_period_statuses
1137     WHERE  rowid = X_Rowid;
1138 
1139     if (SQL%NOTFOUND) then
1140       Raise NO_DATA_FOUND;
1141     end if;
1142   END Delete_Row;
1143 
1144  PROCEDURE update_row_dff(
1145   		X_rowid	                           VARCHAR2,
1146   		X_attribute1	                   VARCHAR2,
1147   		X_attribute2	                   VARCHAR2,
1148   		X_attribute3	                   VARCHAR2,
1149 		X_attribute4	                   VARCHAR2,
1150 		X_attribute5	                   VARCHAR2,
1151 		X_context	                   VARCHAR2,
1152                 X_Last_Update_Date                 DATE,
1153                 X_Last_Updated_By                  NUMBER,
1154                 X_Last_Update_Login                NUMBER
1155  ) IS
1156     CURSOR C IS
1157         SELECT *
1158         FROM   gl_period_statuses
1159         WHERE  rowid = X_rowid
1160         FOR UPDATE of Application_Id NOWAIT;
1161     Recinfo C%ROWTYPE;
1162  BEGIN
1163     OPEN C;
1164     FETCH C INTO Recinfo;
1165     if (C%NOTFOUND) then
1166       CLOSE C;
1167       Raise NO_DATA_FOUND;
1168     else
1169 	   IF ((    (   (Recinfo.attribute1 <> X_Attribute1)
1170                       OR (    (Recinfo.attribute1 IS NOT NULL)
1171                           AND (X_Attribute1 IS NULL))
1172                       OR (    (Recinfo.attribute1 IS NULL)
1173                           AND (X_Attribute1 IS NOT NULL))
1174 		     )
1175                  OR (   (Recinfo.attribute2 <> X_Attribute2)
1176                       OR (    (Recinfo.attribute2 IS NOT NULL)
1177                           AND (X_Attribute2 IS NULL))
1178                       OR (    (Recinfo.attribute2 IS NULL)
1179                           AND (X_Attribute2 IS NOT NULL))
1180 		     )
1181                  OR (   (Recinfo.attribute3 <> X_Attribute3)
1182                       OR (    (Recinfo.attribute3 IS NOT NULL)
1183                           AND (X_Attribute3 IS NULL))
1184                       OR (    (Recinfo.attribute3 IS NULL)
1185                           AND (X_Attribute3 IS NOT NULL))
1186 		     )
1187                  OR (   (Recinfo.attribute4 <> X_Attribute4)
1188                       OR (    (Recinfo.attribute4 IS NOT NULL)
1189                           AND (X_Attribute4 IS NULL))
1190                       OR (    (Recinfo.attribute4 IS NULL)
1191                           AND (X_Attribute4 IS NOT NULL))
1192 		     )
1193                  OR (   (Recinfo.attribute5 <> X_Attribute5)
1194                       OR (    (Recinfo.attribute5 IS NOT NULL)
1195                           AND (X_Attribute5 IS NULL))
1196                       OR (    (Recinfo.attribute5 IS NULL)
1197                           AND (X_Attribute5 IS NOT NULL))
1198 		     )
1199                  OR (   (Recinfo.context <> X_Context)
1200                       OR (    (Recinfo.context IS NOT NULL)
1201                           AND (X_Context IS NULL))
1202                       OR (    (Recinfo.context IS NULL)
1203                           AND (X_Context IS NOT NULL))
1204 		     )
1205                 )) THEN
1206   	     UPDATE gl_period_statuses
1207              SET
1208                 Attribute1        = X_Attribute1,
1209                 Attribute2        = X_Attribute2,
1210                 Attribute3        = X_Attribute3,
1211                 Attribute4        = X_Attribute4,
1212                 Attribute5        = X_Attribute5,
1213                 Context           = X_Context,
1214                 Last_Update_Date  = X_Last_Update_Date,
1215                 Last_Updated_By   = X_Last_Updated_By,
1216                 Last_Update_Login = X_Last_Update_Login
1217              WHERE rowid = X_rowid;
1218            END IF;
1219     END IF;
1220   END Update_Row_Dff;
1221 
1222   PROCEDURE get_period_by_date(
1223   		x_application_id	NUMBER,
1224   		x_ledger_id	NUMBER,
1225   		x_given_date		DATE,
1226   		x_period_name	 IN OUT NOCOPY	VARCHAR2,
1227 		x_closing_status IN OUT NOCOPY	VARCHAR2,
1228 		x_period_year	 IN OUT NOCOPY	NUMBER,
1229 		x_period_num	 IN OUT NOCOPY NUMBER,
1230 		x_period_type	 IN OUT NOCOPY	VARCHAR2)  IS
1231   BEGIN
1232     SELECT  ps.period_name, ps.closing_status,
1233             ps.period_year, ps.period_num, ps.period_type
1234     INTO    x_period_name, x_closing_status, x_period_year,
1235             x_period_num, x_period_type
1236     FROM    gl_period_statuses ps,
1237             gl_date_period_map dpm,
1238             gl_ledgers led
1239     WHERE  led.ledger_id = x_ledger_id
1240     AND    dpm.accounting_date = x_given_date
1241     AND    dpm.period_set_name = led.period_set_name
1242     AND    dpm.period_type     = led.accounted_period_type
1243     AND    ps.period_name      = dpm.period_name
1244     AND    ps.ledger_id  = led.ledger_id
1245     AND    ps.application_id   = x_application_id
1246     AND    ps.adjustment_period_flag = 'N';
1247 
1248   EXCEPTION
1249     WHEN NO_DATA_FOUND THEN
1250       x_period_name := NULL;
1251       x_closing_status := NULL;
1252       RETURN;
1253       /*
1254       fnd_message.set_name('SQLGL', 'GL_IEA_NOT_IN_OPEN_FUTURE_PER');
1255       fnd_message.set_token('PROCEDURE',
1256                             'gl_period_statuses_pkg.get_period_by_date');
1257       APP_EXCEPTION.Raise_Exception;
1258       */
1259     WHEN app_exceptions.application_exception THEN
1260       RAISE;
1261     WHEN OTHERS THEN
1262       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1263       fnd_message.set_token('PROCEDURE',
1264                             'gl_period_statuses_pkg.get_period_by_date');
1265       RAISE;
1266   END get_period_by_date;
1267 
1268 
1269 PROCEDURE get_calendar_range(
1270   		x_ledger_id	NUMBER,
1271   		x_start_date  IN OUT NOCOPY	DATE,
1272   		x_end_date    IN OUT NOCOPY	DATE)  IS
1273   CURSOR not_never_opened_period IS
1274     SELECT  min(start_date), max(end_date)
1275     FROM    gl_period_statuses
1276     WHERE   application_id = 101
1277     AND     ledger_id = x_ledger_id
1278     AND     closing_status <> 'N';
1279 
1280   BEGIN
1281     OPEN not_never_opened_period;
1282     FETCH not_never_opened_period INTO x_start_date, x_end_date;
1283     CLOSE not_never_opened_period;
1284 
1285   EXCEPTION
1286     WHEN NO_DATA_FOUND THEN
1287       x_start_date := NULL;
1288       x_end_date := NULL;
1289       RETURN;
1290     WHEN app_exceptions.application_exception THEN
1291       RAISE;
1292     WHEN OTHERS THEN
1293       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1294       fnd_message.set_token('PROCEDURE',
1295                             'gl_period_statuses_pkg.get_calendar_range');
1296       RAISE;
1297   END get_calendar_range;
1298 
1299 
1300   PROCEDURE get_open_closed_calendar_range(
1301   		x_ledger_id	NUMBER,
1302   		x_start_date  IN OUT NOCOPY	DATE,
1303   		x_end_date    IN OUT NOCOPY	DATE)  IS
1304   CURSOR closed_opened_period IS
1305     SELECT  min(start_date), max(end_date)
1306     FROM    gl_period_statuses
1307     WHERE   application_id = 101
1308     AND     ledger_id = x_ledger_id
1309     AND     closing_status in ('C', 'O', 'P');
1310 
1311   BEGIN
1312     OPEN closed_opened_period;
1313     FETCH closed_opened_period INTO x_start_date, x_end_date;
1314     CLOSE closed_opened_period;
1315 
1316   EXCEPTION
1317     WHEN NO_DATA_FOUND THEN
1318       x_start_date := NULL;
1319       x_end_date := NULL;
1320       RETURN;
1321     WHEN app_exceptions.application_exception THEN
1322       RAISE;
1323     WHEN OTHERS THEN
1324       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1325       fnd_message.set_token('PROCEDURE',
1326                             'gl_period_statuses_pkg.get_open_closed_calendar_range');
1327       RAISE;
1328   END get_open_closed_calendar_range;
1329 
1330 
1331 PROCEDURE get_journal_range(
1332   		x_ledger_id	NUMBER,
1333   		x_start_date  IN OUT NOCOPY	DATE,
1334   		x_end_date    IN OUT NOCOPY	DATE)  IS
1335   CURSOR journal_period IS
1336     SELECT  min(start_date), max(end_date)
1337     FROM    gl_period_statuses
1338     WHERE   application_id = 101
1339     AND     ledger_id = x_ledger_id
1340     AND     closing_status||'' IN ('O', 'F');
1341 
1342   BEGIN
1343     OPEN journal_period;
1344     FETCH journal_period INTO x_start_date, x_end_date;
1345     CLOSE journal_period;
1346 
1347   EXCEPTION
1348     WHEN NO_DATA_FOUND THEN
1349       x_start_date := NULL;
1350       x_end_date := NULL;
1351       RETURN;
1352     WHEN app_exceptions.application_exception THEN
1353       RAISE;
1354     WHEN OTHERS THEN
1355       fnd_message.set_name('SQLGL', 'GL_UNHANDLED_EXCEPTION');
1356       fnd_message.set_token('PROCEDURE',
1357                             'gl_period_statuses_pkg.get_journal_range');
1358       RAISE;
1359   END get_journal_range;
1360 
1361 END gl_period_statuses_pkg;