1 PACKAGE BODY EAM_PM_CONCURRENT_REQUESTS AS
2 /* $Header: EAMPMCRB.pls 120.2.12020000.2 2013/01/30 13:13:23 srkotika ship $ */
3
4 procedure generate_pm_schedules(
5 errbuf out NOCOPY varchar2,
6 retcode out NOCOPY varchar2,
7 p_start_date in varchar2,
8 p_end_date in varchar2,
9 p_org_id in number,
10 p_user_id in number,
11 p_location_id in number,
12 p_category_structure_id in number,
13 p_category_id in number,
14 p_owning_dept_id in number,
15 p_item_type_name in varchar2,
16 p_item_type in number,
17 p_inventory_item_name in varchar2,
18 p_asset_group_id in number,
19 p_asset_number in varchar2,
20 p_set_name in varchar2,
21 p_set_name_id in number,
22 p_view_only in number,
23 p_project_number in varchar2,
24 p_project_id in number,
25 p_task_number in varchar2,
26 p_task_id in number,
27 p_parent_wo in varchar2,
28 p_parent_wo_id in number,
29 p_planner in varchar2, -- WO defaulst ER
30 p_planner_code in number) is
31 x_group_id number;
32 x_req_id number;
33 x_count number := null;
34 x_return_status varchar2(1);
35 x_msg varchar2(3000);
36 x_forecast_id number;
37 l_project_control_level number;
38 proj_val exception;
39
40 cursor sugg_c is
41 select pm_forecast_id
42 from eam_forecasted_work_orders
43 where group_id = x_group_id;
44
45 begin
46
47 --Validation for Project
48
49 if p_project_id is not null OR p_project_number is not null then
50 select project_control_level into l_project_control_level
51 from pjm_org_parameters where organization_id = p_org_id;
52
53 if l_project_control_level = 2 then
54 -- project control is at task level
55 -- task is mandatory
56 if p_task_number is null AND p_task_id is null then
57 --FND_MESSAGE.SET_NAME ('EAM', 'EAM_PROJ_TSK_REQD');
58 --FND_MSG_PUB.ADD;
59 --RAISE FND_API.G_EXC_ERROR;
60 RAISE proj_val;
61 end if;
62 end if;
63 end if;
64
65
66 retcode := '0';
67
68 select wip_job_schedule_interface_s.nextval
69 into x_group_id
70 from dual;
71
72 eam_pm_engine.run_pm_scheduler(1, -- create mode
73 'N', -- excludes non scheduled pm
74 fnd_date.canonical_to_date(p_start_date),
75 fnd_date.canonical_to_date(p_end_date),
76 x_group_id,
77 p_org_id,
78 p_user_id,
79 p_location_id,
80 p_category_id,
81 p_owning_dept_id,
82 p_item_type,
83 p_asset_group_id,
84 p_asset_number,
85 p_set_name_id );
86
87 --added for p_view_only, if it is yes, then don't perform the real action
88 --1 is Yes
89 if ( p_view_only = 1) then
90 return;
91 end if;
92
93 open sugg_c;
94 fetch sugg_c into x_forecast_id;
95 if ( sugg_c%NOTFOUND ) then
96 close sugg_c;
97 return;
98 end if;
99
100 LOOP
101 eam_wb_utils.add_forecast(x_forecast_id);
102 fetch sugg_c into x_forecast_id;
103 EXIT WHEN ( sugg_c%NOTFOUND );
104 END LOOP;
105 close sugg_c;
106
107
108 eam_wb_utils.convert_work_orders2(x_group_id,
109 p_project_id, p_task_id, p_parent_wo_id, p_planner_code,
110 x_return_status, x_msg);
111 commit;
112
113 exception
114 when proj_val then
115 retcode := '2';
116 errbuf := 'Specified project has control at task level. The task is required for further processing.';
117 fnd_file.put_line(FND_FILE.LOG, 'Exception: ' || errbuf);
118 when others then
119 retcode := '2';
120 errbuf := 'PM Schedule Engine: ORA-' || -sqlcode;
121 fnd_file.put_line(FND_FILE.LOG, 'Exception' || errbuf);
122 end generate_pm_schedules;
123
124
125 procedure convert_forecast_work_orders(
126 errbuf out NOCOPY varchar2,
127 retcode out NOCOPY varchar2,
128 p_group_id in number) is
129 x_count number;
130 x_req_id number;
131 begin
132 eam_pm_utils.transfer_to_wdj(p_group_id);
133
134 select count(*) into x_count
135 from wip_job_schedule_interface
136 where group_id = p_group_id;
137
138 if ( x_count > 0 ) then
139 x_req_id := fnd_request.submit_request(
140 'WIP', 'WICMLP', NULL, NULL, FALSE,
141 to_char(p_group_id), '0', '2');
142
143 commit;
144
145 if ( x_req_id = 0 ) then
146 retcode := '2';
147 errbuf := 'Unexpected error when submitting wip mass load concurrent request';
148 end if;
149 end if;
150 exception when others then
151 retcode := '2';
152 errbuf := 'Converting Forecasted Work Orders: ORA-' || -sqlcode;
153 end convert_forecast_work_orders;
154
155 END eam_pm_concurrent_requests;
156