The following lines contain the word 'select', 'insert', 'update' or 'delete':
* The procedure Delete_Simulation_Plan is called from the UI to delete a simulation plan's fleet-unit association selected
*/
PROCEDURE Delete_Simulation_Plan
(
p_api_version IN NUMBER,
p_init_msg_list IN VARCHAR2 := Fnd_Api.G_FALSE,
p_commit IN VARCHAR2 := Fnd_Api.G_TRUE,
p_validation_level IN NUMBER := Fnd_Api.G_VALID_LEVEL_FULL,
p_module_type IN VARCHAR2 := NULL,
p_simulation_plan_id IN NUMBER,
x_return_status OUT NOCOPY VARCHAR2,
x_msg_count OUT NOCOPY NUMBER,
x_msg_data OUT NOCOPY VARCHAR2)
IS
-- Cursor for checking lock in ue table
CURSOR check_lock_ue_tbl(p_simulation_plan_id NUMBER)
IS
SELECT 1
FROM AHL_UE_SIMULATIONS
WHERE simulation_plan_id = p_simulation_plan_id FOR UPDATE;
SELECT 1
FROM AHL_FLEET_UNIT_ASSOCS
WHERE simulation_plan_id = p_simulation_plan_id FOR UPDATE;
L_API_NAME CONSTANT VARCHAR2(30) := 'Delete_Simulation_Plan';
SAVEPOINT Delete_Simulation_Plan;
-- No locking. Exit and do update
EXIT;
DELETE
FROM AHL_UE_SIMULATIONS
WHERE simulation_plan_id = p_simulation_plan_id;
ROLLBACK TO Delete_Simulation_Plan;
DELETE
FROM AHL_FLEET_UNIT_ASSOCS
WHERE simulation_plan_id = p_simulation_plan_id;
ROLLBACK TO Delete_Simulation_Plan;
DELETE
FROM ahl_ump_maint_reqmnts
WHERE simulation_plan_id = p_simulation_plan_id
AND object_type = 'SIM';
DELETE
FROM ahl_ump_resource_reqmnts
WHERE simulation_plan_id = p_simulation_plan_id
AND object_type = 'SIM';
DELETE
FROM ahl_ump_material_reqmnts
WHERE simulation_plan_id = p_simulation_plan_id
AND object_type = 'SIM';
ROLLBACK TO Delete_Simulation_Plan;
fnd_log.string ( l_log_procedure,L_DEBUG_KEY ||'.end','At the end of PLSQL procedure Delete_Simulation_Plan');
ROLLBACK TO Delete_Simulation_Plan;
ROLLBACK TO Delete_Simulation_Plan;
ROLLBACK TO Delete_Simulation_Plan;
fnd_msg_pub.add_exc_msg(p_pkg_name => G_PKG_NAME, p_procedure_name => 'Delete_Simulation_Plan', p_error_text => SUBSTR(SQLERRM,1,500));
END Delete_Simulation_Plan;
* The procedure Implement_Simulation_Plan is called from the UI to implement a simulation plan selected
*/
PROCEDURE Implement_Simulation_Plan
(
p_api_version IN NUMBER,
p_init_msg_list IN VARCHAR2 := Fnd_Api.G_FALSE,
p_commit IN VARCHAR2 := Fnd_Api.G_TRUE,
p_validation_level IN NUMBER := Fnd_Api.G_VALID_LEVEL_FULL,
p_module_type IN VARCHAR2 := NULL,
p_simulation_plan_id IN NUMBER,
p_run_bue_flag IN VARCHAR2 := 'N',
x_return_status OUT NOCOPY VARCHAR2,
x_msg_count OUT NOCOPY NUMBER,
x_msg_data OUT NOCOPY VARCHAR2)
IS
-- Cursor for checking lock in Ue table
CURSOR check_lock_ue_tbl(p_simulation_plan_id NUMBER)
IS
SELECT 1
FROM AHL_UE_SIMULATIONS
WHERE simulation_plan_id = p_simulation_plan_id FOR UPDATE;
SELECT 1
FROM AHL_FLEET_UNIT_ASSOCS
WHERE simulation_plan_id = p_simulation_plan_id FOR UPDATE;
SELECT fleet_unit_assoc_id
FROM AHL_FLEET_UNIT_ASSOCS
WHERE NVL(trunc(association_end), trunc(SYSDATE)) >= trunc(SYSDATE)
AND simulation_plan_id = p_pri_plan_id
AND association_start IS NOT NULL
AND unit_config_header_id IN
(SELECT DISTINCT unit_config_header_id
FROM AHL_FLEET_UNIT_ASSOCS
WHERE SIMULATION_PLAN_ID= p_simulation_plan_id
AND ahl_util_uc_pkg.get_uc_status_code(unit_config_header_id) <>'EXPIRED'-- added to avoid expired units
);
SELECT fleet_unit_assoc_id
FROM AHL_FLEET_UNIT_ASSOCS
WHERE trunc(association_start) < trunc(SYSDATE)
AND NVL(trunc(association_end), trunc(SYSDATE)) >= trunc(SYSDATE)
AND NOT (association_start IS NULL AND association_end IS NULL)
AND simulation_plan_id = p_simulation_plan_id
AND ahl_util_uc_pkg.get_uc_status_code(unit_config_header_id) <>'EXPIRED';
unit_config_header_tbl.DELETE;
SELECT simulation_plan_id
INTO l_primary_plan_id
FROM AHL_SIMULATION_PLANS_B
WHERE PRIMARY_PLAN_FLAG='Y'
AND simulation_type = 'UMP';
SELECT DISTINCT unit_config_header_id
BULK COLLECT
INTO unit_config_header_tbl
FROM AHL_FLEET_UNIT_ASSOCS ua
WHERE ua.simulation_plan_id = p_simulation_plan_id
AND ahl_util_uc_pkg.get_uc_status_code(ua.unit_config_header_id) <>'EXPIRED'-- added to avoid expired units;
DELETE
FROM AHL_FLEET_UNIT_ASSOCS
WHERE simulation_plan_id = l_primary_plan_id
AND UNIT_CONFIG_HEADER_ID IN
(SELECT DISTINCT unit_config_header_id
FROM AHL_FLEET_UNIT_ASSOCS
WHERE simulation_plan_id= p_simulation_plan_id
AND ahl_util_uc_pkg.get_uc_status_code(UNIT_CONFIG_HEADER_ID) <>'EXPIRED'
AND NOT (association_start IS NULL AND association_end IS NULL)-- added to avoid expired units
)
--Added by debadey for bug 13869885
AND trunc(association_start)>=trunc(SYSDATE);
fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'Deleted applicable unit assoc from primary plan ');
UPDATE AHL_FLEET_UNIT_ASSOCS
SET association_end = SYSDATE-1,
last_update_date = SYSDATE,
last_updated_by = fnd_global.user_id,
last_update_login = fnd_global.login_id
WHERE fleet_unit_assoc_id = rec.fleet_unit_assoc_id
AND simulation_plan_id = l_primary_plan_id;
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 );
-- Delete simulation plan rows where end date is less than sysdate
DELETE FROM AHL_FLEET_UNIT_ASSOCS
WHERE simulation_plan_id = p_simulation_plan_id
AND NVL(trunc(association_end), trunc(SYSDATE)) < trunc(SYSDATE);
fnd_log.string ( l_log_unexpected, 'ahl.plsql.Implement_Simulation_Plan', 'Deleted applicable unit assoc from sim plan ');
UPDATE AHL_FLEET_UNIT_ASSOCS
SET association_start = SYSDATE,
last_update_date = SYSDATE,
last_updated_by = fnd_global.user_id,
last_update_login = fnd_global.login_id
WHERE simulation_plan_id = p_simulation_plan_id
AND fleet_unit_assoc_id = rec.fleet_unit_assoc_id;
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);
UPDATE AHL_FLEET_UNIT_ASSOCS assoc
SET SIMULATION_PLAN_ID =l_primary_plan_id,
last_update_date = SYSDATE,
last_updated_by = fnd_global.login_id
WHERE SIMULATION_PLAN_ID= p_simulation_plan_id
AND ahl_util_uc_pkg.get_uc_status_code(assoc.unit_config_header_id) <>'EXPIRED'-- added to avoid expired units;
fnd_log.string(l_log_statement,L_DEBUG_KEY,'Updates mades in assocs table from sim to pri');
-- delete any remaining assocs
DELETE FROM AHL_FLEET_UNIT_ASSOCS
WHERE SIMULATION_PLAN_ID= p_simulation_plan_id;
fnd_log.string(l_log_statement,L_DEBUG_KEY,'Deleted remaining records from assocs table');
-- Delete the simulation plan ues
DELETE
FROM AHL_UE_SIMULATIONS
WHERE simulation_plan_id = p_simulation_plan_id;
fnd_log.string(l_log_statement,L_DEBUG_KEY,'Updates mades in ue table');
SELECT 1
FROM AHL_UE_SIMULATIONS
WHERE simulation_plan_id = p_simulation_plan_id FOR UPDATE;
SELECT 1
FROM AHL_FLEET_UNIT_ASSOCS
WHERE simulation_plan_id = p_simulation_plan_id
AND unit_config_header_id = p_unit_header_id FOR UPDATE;
SELECT simulation_plan_id,
unit_config_header_id
INTO l_sim_plan_id,
l_unit_config_header_id
FROM ahl_simulation_forecast_v
WHERE simulation_ue_id = p_simulation_ue_id;
fnd_log.string ( l_log_unexpected, 'ahl.plsql.Remove_Unit_From_Plan', 'There are no rows for the selected simulation effectivity id' );
DELETE
FROM AHL_FLEET_UNIT_ASSOCS
WHERE unit_config_header_id = l_unit_config_header_id
AND simulation_plan_id = l_sim_plan_id;
DELETE
FROM AHL_UE_SIMULATIONS
WHERE unit_config_header_id = l_unit_config_header_id
AND simulation_plan_id = l_sim_plan_id;