DBA Data[Home] [Help]

PACKAGE BODY: APPS.EAM_ASSIGN_WORK_PVT

Source


1 PACKAGE BODY EAM_ASSIGN_WORK_PVT  as
2 /* $Header: EAMASRQB.pls 120.0 2005/05/25 16:24:47 appldev noship $ */
3 
4 G_PKG_NAME CONSTANT VARCHAR2(30) :='EAM_ASSIGN_WORK_PVT';
5 
6 
7 
8 Procedure assign_work(
9   p_api_version 	in NUMBER,
10   p_init_msg_list 	in VARCHAR2 	:= FND_API.G_FALSE,
11   p_commit 		in VARCHAR2 	:= FND_API.G_FALSE,
12   p_validation_level 	in NUMBER	:= FND_API.G_VALID_LEVEL_FULL,
13   x_return_status 	out NOCOPY 	VARCHAR2,
14   x_msg_count 		out NOCOPY 	NUMBER,
15   x_msg_data 		out NOCOPY 	VARCHAR2,
16   p_wip_entity_id 	in NUMBER,
17   p_req_type 		in NUMBER,
18   p_req_num 		in VARCHAR2,
19   p_req_id 		in NUMBER
20 
21 ) is
22      l_api_name       	CONSTANT 	VARCHAR2(30) := 'assign_work';
23      l_api_version    	CONSTANT 	NUMBER       := 1.0;
24      l_work_request_id         		NUMBER;
25      l_organization_id         		NUMBER;
26      l_servicereq_count        		NUMBER := 0 ;
27      l_status_type              	NUMBER;
28      eam_mng_req_assgn_error    	Exception ;
29      eam_mng_work_req_error     	Exception;
30      temp      				NUMBER;
31 BEGIN
32 
33     -- Standard Start of API savepoint
34     SAVEPOINT eam_assign_work;
35 
36     -- Standard call to check for call compatibility.
37     IF NOT fnd_api.compatible_api_call
38          (l_api_version
39          ,p_api_version
40          ,l_api_name
41          ,g_pkg_name) THEN
42        RAISE fnd_api.g_exc_unexpected_error;
43     END IF;
44 
45       -- Initialize message list if p_init_msg_list is set to TRUE.
46     IF fnd_api.to_boolean(p_init_msg_list) THEN
47        fnd_msg_pub.initialize;
48     END IF;
49 
50     --  Initialize API return status to success
51     x_return_status := fnd_api.g_ret_sts_success;
52 
53       -- Standard check of p_commit.
54      select 	organization_id   , status_type
55      into 	l_organization_id , l_status_type
56      from 	wip_discrete_jobs
57      where  	wip_entity_id	=   p_wip_entity_id;
58 
59 
60 
61      If (p_req_type=1) then  --work request
62    --checking if the work request is not assigned to another work order
63    --if it is assigned then error out
64 
65      select 	wip_entity_id into temp
66        from 	wip_eam_work_requests
67       where 	work_request_id	 = p_req_id
68         and 	organization_id  = l_organization_id;
69 
70        if (temp is null) then
71    	Update	wip_eam_work_requests
72         set 	wip_entity_id		=	p_wip_entity_id,
73             	work_request_status_id	=	decode(l_status_type,4,6,5,6,4) ,
74             	last_update_date	=	sysdate,
75             	last_updated_by		=	FND_GLOBAL.user_id
76         where 	work_request_id		=	p_req_id
77           and 	organization_id		=	l_organization_id;
78 
79  end if;--for if (temp is not null) then
80 
81   if (temp is not null) then
82   raise  eam_mng_work_req_error;
83   end if;
84 end if;--for   If (p_req_type=1) then
85 
86      If (p_req_type=2) then  -- service request
87        	select	count(1)
88    	  into 	l_servicereq_count
89        	  from  eam_wo_service_association
90        	 where  maintenance_organization_id = l_organization_id
91        	   and 	wip_entity_id	  	    = p_wip_entity_id
92 	   and  (enable_flag IS NULL OR enable_flag = 'Y');      -- Fix for 3773450
93 
94 	if 	l_servicereq_count > 0 then
95             	raise eam_mng_req_assgn_error ;
96        	end if ;
97 
98 	if (p_req_id is not null)  then
99      		   insert into eam_wo_service_association
100      			(wo_service_entity_assoc_id,
101     			maintenance_organization_id,
102 		     	wip_entity_id,
103      			service_request_id,
104      			creation_date,
105      			created_by,
106      			last_update_login,
107      			program_id,
108      			attribute1,
109      			attribute2,
110      			attribute3,
111      			attribute4,
112      			attribute5,
113      			attribute6,
114      			attribute7,
115      			attribute8,
116      			attribute9,
117      			attribute10,
118      			attribute11,
119      			attribute12,
120      			attribute13,
121      			attribute14,
122      			attribute15,
123      			attribute_category,
124      			last_updated_by,
125      			last_update_date,
126 			enable_flag)		-- Fix for 3773450
127      		values
128      			(eam_wo_service_association_s.nextval,
129      			l_organization_id,
130      			p_wip_entity_id,
131      			p_req_id,
132      			sysdate,
133      			FND_GLOBAL.USER_ID,
134      			FND_GLOBAL.LOGIN_ID,
135      			null,--fnd_global.conc_program_id,
136      			null,
137      			null,
138      			null,
139      			null,
140      			null,
141      			null,
142      			null,
143      			null,
144      			null,
145      			null,
146      			null,
147      			null,
148      			null,
149      			null,
150      			null,
151      			null,
152      			fnd_global.user_id,
153      			sysdate,
154 			'Y');		-- Fix for 3773450
155      		end if;
156      End if;
157 
158 
159     IF fnd_api.to_boolean(p_commit) THEN
160          COMMIT WORK;
161     END IF;
162 
163       -- Standard call to get message count and if count is 1, get message info.
164       fnd_msg_pub.count_and_get(
165          	 p_encoded => fnd_api.g_false
166         	,p_count   => x_msg_count
167         	,p_data    => x_msg_data);
168 
169  EXCEPTION
170       WHEN	eam_mng_work_req_error THEN
171 	     	ROLLBACK TO eam_assign_work;
172          	x_return_status := fnd_api.g_ret_sts_error;
173                 eam_execution_jsp.add_message(p_app_short_name => 'EAM',
174                                             p_msg_name => 'EAM_MNG_WORK_REQ_ERROR');
175 
176       WHEN	eam_mng_req_assgn_error THEN
177 	     	ROLLBACK TO eam_assign_work;
178          	x_return_status := fnd_api.g_ret_sts_error;
179                 eam_execution_jsp.add_message(p_app_short_name => 'EAM',
180                                           p_msg_name => 'EAM_MNG_REQ_ASSGN_ERROR');
181      --    	fnd_msg_pub.count_and_get(
182      --       		p_encoded => fnd_api.g_false
183      --      		,p_count => x_msg_count
184      --      		,p_data => x_msg_data);
185 
186 
187       WHEN	fnd_api.g_exc_error THEN
188 	     	ROLLBACK TO eam_assign_work;
189          	x_return_status := fnd_api.g_ret_sts_error;
190          	fnd_msg_pub.count_and_get(
191             		 p_encoded => fnd_api.g_false
192            		,p_count => x_msg_count
193            		,p_data => x_msg_data);
194 
195       WHEN 	fnd_api.g_exc_unexpected_error THEN
196 		ROLLBACK TO eam_assign_work;
197          	x_return_status := fnd_api.g_ret_sts_unexp_error;
198          	fnd_msg_pub.count_and_get(
199             		 p_encoded => fnd_api.g_false
200            		,p_count => x_msg_count
201            		,p_data => x_msg_data);
202 
203       WHEN 	OTHERS THEN
204 		ROLLBACK TO eam_assign_work;
205          	x_return_status := fnd_api.g_ret_sts_unexp_error;
206          	IF fnd_msg_pub.check_msg_level(
207                    fnd_msg_pub.g_msg_lvl_unexp_error) THEN
208                    fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
209          	END IF;
210          	fnd_msg_pub.count_and_get(
211              		 p_encoded => fnd_api.g_false
212            		,p_count => x_msg_count
213            		,p_data => x_msg_data);
214 end assign_work;
215 
216 
217 procedure delete_assignment(
218   p_api_version 	in NUMBER,
219   p_init_msg_list 	in VARCHAR2 	:= FND_API.G_FALSE,
220   p_commit 		in VARCHAR2 	:= FND_API.G_FALSE,
221   p_validation_level 	in NUMBER 	:= FND_API.G_VALID_LEVEL_FULL,
222   x_return_status 	out NOCOPY 	VARCHAR2,
223   x_msg_count 		out NOCOPY 	NUMBER,
224   x_msg_data 		out NOCOPY 	VARCHAR2,
225   p_wip_entity_id 	in NUMBER,
226   p_req_type 		in NUMBER,
227   p_req_num 		in VARCHAR2,
228   p_req_id 		in NUMBER
229 
230 ) is
231      l_api_name       	CONSTANT 	VARCHAR2(30) := 'delete_assignment';
232      l_api_version    	CONSTANT 	NUMBER       := 1.0;
233      l_work_request_id         		NUMBER;
234      l_organization_id                 	NUMBER;
235 BEGIN
236 
237     -- Standard Start of API savepoint
238     SAVEPOINT eam_delete_assignment;
239 
240     -- Standard call to check for call compatibility.
241     IF NOT fnd_api.compatible_api_call(
242           l_api_version
243          ,p_api_version
244          ,l_api_name
245          ,g_pkg_name) THEN
246        RAISE fnd_api.g_exc_unexpected_error;
247     END IF;
248 
249       -- Initialize message list if p_init_msg_list is set to TRUE.
250       IF fnd_api.to_boolean(p_init_msg_list) THEN
251          fnd_msg_pub.initialize;
252       END IF;
253 
254     --  Initialize API return status to success
255     x_return_status := fnd_api.g_ret_sts_success;
256 
257       -- Standard check of p_commit.
258      select 	organization_id
259        into 	l_organization_id
260        from 	wip_discrete_jobs
261       where  	wip_entity_id	=   p_wip_entity_id;
262 
263      if (p_req_type=1) then  --work request
264 
265 
266      update 	wip_eam_work_requests
267      	set 	wip_entity_id		=	null,
268      		work_request_status_id = 	3,
269      		last_update_date	=	sysdate,
270      		last_updated_by		= 	FND_GLOBAL.user_id
271      where 	work_request_id		=	p_req_id
272        and 	organization_id		=	l_organization_id;
273      end if;
274 
275      if(p_req_type=2) then
276 
277       Begin
278       if (p_req_id is not null)  then
279 	      update eam_wo_service_association			-- Fix for 3773450
280 	      set enable_flag = 'N',
281       		  last_update_date = sysdate,
282      		  last_updated_by  = FND_GLOBAL.user_id,
283 		  last_update_login = FND_GLOBAL.login_id
284 	      where 	service_request_id	=	p_req_id
285 	      and 	wip_entity_id		=	p_wip_entity_id
286 	      and 	maintenance_organization_id =	l_organization_id
287 	      and       (enable_flag IS NULL or enable_flag = 'Y');
288       end if;
289      exception
290      WHEN OTHERS THEN
291 
292               eam_execution_jsp.add_message(p_app_short_name => 'EAM', p_msg_name => 'EAM_EZWO_BAD_SERVICE_REQUEST');
293                         x_return_status := FND_API.G_RET_STS_ERROR;
294       end;
295      end if;
296 
297 
298     IF fnd_api.to_boolean(p_commit) THEN
299          COMMIT WORK;
300     END IF;
301 
302       -- Standard call to get message count and if count is 1, get message info.
303       fnd_msg_pub.count_and_get(
304          p_encoded => fnd_api.g_false
305         ,p_count => x_msg_count
306         ,p_data => x_msg_data);
307    EXCEPTION
308 
309       WHEN fnd_api.g_exc_error THEN
310 
311          ROLLBACK TO eam_delete_assignment;
312          x_return_status := fnd_api.g_ret_sts_error;
313          fnd_msg_pub.count_and_get(
314              p_encoded => fnd_api.g_false
315            ,p_count => x_msg_count
316            ,p_data => x_msg_data);
317       WHEN fnd_api.g_exc_unexpected_error THEN
318 
319          ROLLBACK TO eam_delete_assignment;
320          x_return_status := fnd_api.g_ret_sts_unexp_error;
321          fnd_msg_pub.count_and_get(
322              p_encoded => fnd_api.g_false
323            ,p_count => x_msg_count
324            ,p_data => x_msg_data);
325       WHEN OTHERS THEN
326 
327          ROLLBACK TO eam_delete_assignment;
328          x_return_status := fnd_api.g_ret_sts_unexp_error;
329          IF fnd_msg_pub.check_msg_level(
330                fnd_msg_pub.g_msg_lvl_unexp_error) THEN
331             fnd_msg_pub.add_exc_msg(g_pkg_name, l_api_name);
332          END IF;
333          fnd_msg_pub.count_and_get(
334              p_encoded => fnd_api.g_false
335            ,p_count => x_msg_count
336            ,p_data => x_msg_data);
337 end delete_assignment;
338 
339 
340    -- Enter further code below as specified in the Package spec.
341 END; -- Package Body EAM_ASSIGN_WORK_PVT