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
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:
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'
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'
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(
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
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
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' );
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:
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,
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,
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:
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,
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,
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:
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,
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:
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,
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
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:
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
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
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:
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;
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:
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'),
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
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(
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')
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
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:
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)
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:
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:
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
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
745: and s2.application_id = x_application_id
746: and s2.ledger_id = x_ledger_id);
747:
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:
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
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
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:
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
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')
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:
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:
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,
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
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,
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,
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;
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
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,
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
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;
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:
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:
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:
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:
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:
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:
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;
1357: 'gl_period_statuses_pkg.get_journal_range');
1358: RAISE;
1359: END get_journal_range;
1360:
1361: END gl_period_statuses_pkg;