5: G_DEBUG VARCHAR2(1) := AHL_DEBUG_PUB.is_log_enabled;
6: ------------------------------------
7: -- Common constants and variables --
8: ------------------------------------
9: l_log_current_level NUMBER := fnd_log.g_current_runtime_level;
10: l_log_statement NUMBER := fnd_log.level_statement;
11: l_log_procedure NUMBER := fnd_log.level_procedure;
12: l_log_error NUMBER := fnd_log.level_error;
13: l_log_unexpected NUMBER := fnd_log.level_unexpected;
6: ------------------------------------
7: -- Common constants and variables --
8: ------------------------------------
9: l_log_current_level NUMBER := fnd_log.g_current_runtime_level;
10: l_log_statement NUMBER := fnd_log.level_statement;
11: l_log_procedure NUMBER := fnd_log.level_procedure;
12: l_log_error NUMBER := fnd_log.level_error;
13: l_log_unexpected NUMBER := fnd_log.level_unexpected;
14: -----------------------------------------------------------------
7: -- Common constants and variables --
8: ------------------------------------
9: l_log_current_level NUMBER := fnd_log.g_current_runtime_level;
10: l_log_statement NUMBER := fnd_log.level_statement;
11: l_log_procedure NUMBER := fnd_log.level_procedure;
12: l_log_error NUMBER := fnd_log.level_error;
13: l_log_unexpected NUMBER := fnd_log.level_unexpected;
14: -----------------------------------------------------------------
15: ------------------ Locking Exception ----------------------------
8: ------------------------------------
9: l_log_current_level NUMBER := fnd_log.g_current_runtime_level;
10: l_log_statement NUMBER := fnd_log.level_statement;
11: l_log_procedure NUMBER := fnd_log.level_procedure;
12: l_log_error NUMBER := fnd_log.level_error;
13: l_log_unexpected NUMBER := fnd_log.level_unexpected;
14: -----------------------------------------------------------------
15: ------------------ Locking Exception ----------------------------
16: record_locked EXCEPTION;
9: l_log_current_level NUMBER := fnd_log.g_current_runtime_level;
10: l_log_statement NUMBER := fnd_log.level_statement;
11: l_log_procedure NUMBER := fnd_log.level_procedure;
12: l_log_error NUMBER := fnd_log.level_error;
13: l_log_unexpected NUMBER := fnd_log.level_unexpected;
14: -----------------------------------------------------------------
15: ------------------ Locking Exception ----------------------------
16: record_locked EXCEPTION;
17: pragma exception_init (record_locked, -54);
73: IF(p_simulation_plan_id IS NULL) THEN
74: FND_MESSAGE.Set_Name('AHL','AHL_SIM_NULL_SIM_PLAN_ID');
75: FND_MSG_PUB.ADD;
76: IF (l_log_unexpected >= l_log_current_level) THEN
77: fnd_log.string ( l_log_unexpected, 'ahl.plsql.', 'For this API flow, Simulation Plan Id is mandatory but found null in input ' );
78: END IF;
79: RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
80: END IF;
81:
80: END IF;
81:
82: --Logging
83: IF (l_log_statement >= l_log_current_level) THEN
84: fnd_log.string(l_log_statement,L_DEBUG_KEY,'p_simulation_plan_id sent from UI: '||p_simulation_plan_id);
85: END IF;
86:
87: -- Check for locks of the ue records
88: FOR i IN 1..2
176: END IF;
177:
178: -- Logging
179: IF (l_log_procedure >= l_log_current_level) THEN
180: fnd_log.string ( l_log_procedure,L_DEBUG_KEY ||'.end','At the end of PLSQL procedure Delete_Simulation_Plan');
181: END IF;
182:
183: EXCEPTION
184: WHEN FND_API.G_EXC_ERROR THEN
303: FND_MSG_PUB.ADD;
304:
305: -- Logging
306: IF (l_log_unexpected >= l_log_current_level) THEN
307: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'For this API flow, Simulation Plan Id is mandatory but found null in input ' );
308: END IF;
309: RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
310: END IF;
311:
310: END IF;
311:
312: -- Logging
313: IF (l_log_statement >= l_log_current_level) THEN
314: fnd_log.string(l_log_statement,L_DEBUG_KEY,'p_simulation_plan_id sent from UI: '||p_simulation_plan_id||' p_run_bue_flag: '||p_run_bue_flag);
315: END IF;
316:
317: -- Logic
318: -- Reset variable
329: AND simulation_type = 'UMP';
330: EXCEPTION
331: WHEN NO_DATA_FOUND THEN
332: IF (l_log_unexpected >= l_log_current_level) THEN
333: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'No primary plan data' );
334: END IF;
335: RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
336: END;
337:
387: EXCEPTION
388: WHEN OTHERS
389: THEN
390: IF (l_log_unexpected >= l_log_current_level) THEN
391: fnd_log.string ( l_log_unexpected,L_DEBUG_KEY, 'No Unit in the plan');
392: END IF;
393: END;
394:
395: -- Remove unit and simulation association for pri plan for those associations where start date is greater than sysdate
405: )
406: --Added by debadey for bug 13869885
407: AND trunc(association_start)>=trunc(SYSDATE);
408: IF (l_log_unexpected >= l_log_current_level) THEN
409: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'Deleted applicable unit assoc from primary plan ');
410: END IF;
411:
412: -- Update applicable rows for the primary plan
413: FOR rec in primary_assoc_for_upd(p_simulation_plan_id, l_primary_plan_id)
419: last_update_login = fnd_global.login_id
420: WHERE fleet_unit_assoc_id = rec.fleet_unit_assoc_id
421: AND simulation_plan_id = l_primary_plan_id;
422: IF (l_log_unexpected >= l_log_current_level) THEN
423: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'Updated end date for primary plan fleet assoc id '||rec.fleet_unit_assoc_id );
424: END IF;
425: END LOOP;
426:
427: -- Delete simulation plan rows where end date is less than sysdate
428: DELETE FROM AHL_FLEET_UNIT_ASSOCS
429: WHERE simulation_plan_id = p_simulation_plan_id
430: AND NVL(trunc(association_end), trunc(SYSDATE)) < trunc(SYSDATE);
431: IF (l_log_unexpected >= l_log_current_level) THEN
432: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'Deleted applicable unit assoc from sim plan ');
433: END IF;
434: -- Update sim plan assoc to syadte
435: FOR rec in sim_assoc_for_upd(p_simulation_plan_id)
436: LOOP
441: last_update_login = fnd_global.login_id
442: WHERE simulation_plan_id = p_simulation_plan_id
443: AND fleet_unit_assoc_id = rec.fleet_unit_assoc_id;
444: IF (l_log_unexpected >= l_log_current_level) THEN
445: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'Updated assoc start for sim plan for assoc id '||rec.fleet_unit_assoc_id);
446: END IF;
447: END LOOP;
448:
449: -- convert the sim plan unit rows into primary plan rows
454: WHERE SIMULATION_PLAN_ID= p_simulation_plan_id
455: AND ahl_util_uc_pkg.get_uc_status_code(assoc.unit_config_header_id) <>'EXPIRED'-- added to avoid expired units;
456: AND NOT (association_start IS NULL AND association_end IS NULL);
457: IF (l_log_statement >= l_log_current_level) THEN
458: fnd_log.string(l_log_statement,L_DEBUG_KEY,'Updates mades in assocs table from sim to pri');
459: END IF;
460:
461: -- delete any remaining assocs
462: DELETE FROM AHL_FLEET_UNIT_ASSOCS
462: DELETE FROM AHL_FLEET_UNIT_ASSOCS
463: WHERE SIMULATION_PLAN_ID= p_simulation_plan_id;
464:
465: IF (l_log_statement >= l_log_current_level) THEN
466: fnd_log.string(l_log_statement,L_DEBUG_KEY,'Deleted remaining records from assocs table');
467: END IF;
468: ELSE
469: -- Already lock exists on the rows
470: ROLLBACK TO Implement_Simulation_Plan;
485: WHERE simulation_plan_id = p_simulation_plan_id;
486:
487: -- Logging
488: IF (l_log_statement >= l_log_current_level) THEN
489: fnd_log.string(l_log_statement,L_DEBUG_KEY,'Updates mades in ue table');
490: END IF;
491: ELSE
492: ROLLBACK TO Implement_Simulation_Plan;
493: FND_MESSAGE.Set_Name('AHL','AHL_SIM_ROWS_LOCKED');
502: COMMIT;
503: SAVEPOINT Implement_Simulation_Plan;
504: --Logging
505: IF (l_log_statement >= l_log_current_level) THEN
506: fnd_log.string(l_log_statement,L_DEBUG_KEY,'Commit done');
507: END IF;
508: END IF;
509:
510: -- Invoke BUE for primary plan if user has opted for the same
511: IF (UPPER(p_run_bue_flag) = 'Y') THEN
512: IF(unit_config_header_tbl IS NOT NULL AND unit_config_header_tbl.COUNT>0) THEN
513: -- Logging
514: IF (l_log_statement >= l_log_current_level) THEN
515: fnd_log.string(l_log_statement,L_DEBUG_KEY,'Invoke BUE for the units. Unit number ='||unit_config_header_tbl.COUNT);
516: END IF;
517: FOR i IN unit_config_header_tbl.FIRST..unit_config_header_tbl.LAST
518: LOOP
519: IF (l_log_statement >= l_log_current_level) THEN
516: END IF;
517: FOR i IN unit_config_header_tbl.FIRST..unit_config_header_tbl.LAST
518: LOOP
519: IF (l_log_statement >= l_log_current_level) THEN
520: fnd_log.string(l_log_statement,L_DEBUG_KEY,'Invoking BUE for unit '||unit_config_header_tbl(i));
521: END IF;
522: BEGIN
523: l_req_id := fnd_request.submit_request('AHL','AHLUEFF',NULL,NULL,FALSE, NULL, unit_config_header_tbl(i), NULL, NULL, NULL, NULL);
524: EXCEPTION
525: WHEN OTHERS THEN
526: -- Even if exception is there that is acceptable. BUE will be run for primary plan frequently
527: -- But log the issue
528: IF (l_log_unexpected >= l_log_current_level) THEN
529: fnd_log.string ( l_log_unexpected,L_DEBUG_KEY, 'Exception while invoking BUE for primary plan.');
530: END IF;
531: END;
532:
533: -- Logging
531: END;
532:
533: -- Logging
534: IF (l_log_statement >= l_log_current_level) THEN
535: fnd_log.string(l_log_statement, L_DEBUG_KEY, 'Request id generated by concurrent program is '||l_req_id);
536: END IF;
537:
538: END LOOP;
539: END IF;
540: END IF;
541:
542: -- Logging
543: IF (l_log_procedure >= l_log_current_level) THEN
544: fnd_log.string ( l_log_procedure,L_DEBUG_KEY ||'.end','At the end of PLSQL procedure Implement_Simulation_Plan');
545: END IF;
546: EXCEPTION
547: WHEN FND_API.G_EXC_ERROR THEN
548: x_return_status := FND_API.G_RET_STS_ERROR;
626: IF(p_simulation_ue_id IS NULL) THEN
627: FND_MESSAGE.Set_Name('AHL','AHL_SIM_NULL_SIM_PLAN_ID');
628: FND_MSG_PUB.ADD;
629: IF (l_log_unexpected >= l_log_current_level) THEN
630: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Remove_Unit_From_Plan', 'For this API flow, Simulation Ue Id is mandatory but found null in input ' );
631: END IF;
632: RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
633: END IF;
634:
633: END IF;
634:
635: --Logging
636: IF (l_log_statement >= l_log_current_level) THEN
637: fnd_log.string(l_log_statement,L_DEBUG_KEY,'p_simulation_ue_id sent from UI: '||p_simulation_ue_id);
638: END IF;
639:
640: -- Logic
641: BEGIN
649: WHEN NO_DATA_FOUND THEN
650: FND_MESSAGE.Set_Name('AHL','AHL_SIM_INVALID_SIM_UE_ID');
651: FND_MSG_PUB.ADD;
652: IF (l_log_unexpected >= l_log_current_level) THEN
653: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Remove_Unit_From_Plan', 'There are no rows for the selected simulation effectivity id' );
654: END IF;
655: RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
656: END;
657: IF (l_sim_plan_id IS NULL) THEN
657: IF (l_sim_plan_id IS NULL) THEN
658: FND_MESSAGE.Set_Name('AHL','AHL_SIM_INVALID_SIM_PLAN_ID');
659: FND_MSG_PUB.ADD;
660: IF (l_log_unexpected >= l_log_current_level)THEN
661: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Remove_Unit_From_Plan', 'NULL Simulation Plan id ' );
662: END IF;
663: RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
664: END IF;
665: IF (l_unit_config_header_id IS NULL) THEN
665: IF (l_unit_config_header_id IS NULL) THEN
666: FND_MESSAGE.Set_Name('AHL','AHL_SIM_INVALID_UNIT_HEADER_ID');
667: FND_MSG_PUB.ADD;
668: IF (l_log_unexpected >= l_log_current_level) THEN
669: fnd_log.string ( l_log_unexpected, 'ahl.plsql.Remove_Unit_From_Plan', 'NULL Unit id ' );
670: END IF;
671: RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
672: END IF;
673:
734:
735: -- Standard check of p_commit
736: IF FND_API.TO_BOOLEAN(p_commit) THEN
737: IF (l_log_procedure >= l_log_current_level) THEN
738: fnd_log.string ( l_log_procedure,L_DEBUG_KEY,'Committing changes');
739: END IF;
740: COMMIT;
741: END IF;
742: -- Logging
740: COMMIT;
741: END IF;
742: -- Logging
743: IF (l_log_procedure >= l_log_current_level) THEN
744: fnd_log.string ( l_log_procedure,L_DEBUG_KEY ||'.end','At the end of PLSQL procedure');
745: END IF;
746: EXCEPTION
747: WHEN FND_API.G_EXC_ERROR THEN
748: x_return_status := FND_API.G_RET_STS_ERROR;