DBA Data[Home] [Help]

PACKAGE BODY: APPS.CS_CONTRACTS_WFA

Source


1 PACKAGE BODY CS_CONTRACTS_WFA  AS
2 /* $Header: csctwfab.pls 115.0 99/07/16 08:55:44 porting ship  $ */
3 -- ***************************************************************************
4 -- *									     *
5 -- *			   Contract Item Type       			     *
6 -- *									     *
7 -- ***************************************************************************
8 PROCEDURE Selector
9 (
10 		itemtype      	IN VARCHAR2,
11 		itemkey       	IN VARCHAR2,
12 		actid         	IN NUMBER,
13 		funmode       	IN VARCHAR2,
14 		result    	OUT VARCHAR2
15 )
16 IS
17 BEGIN
18 	if (funmode = 'RUN') then
19 		--
20 		-- Return process to run
21 		--
22 		result := 'REQUISITION_APPROVAL';
23 		return;
24 	end if;
25 
26 	--
27 EXCEPTION
28 	when others then
29 		WF_CORE.context(CS_CONTRACTS_WFA.l_pkg_name,'Selector',itemtype,itemkey,actid,funmode);
30 		raise;
31 END Selector;
32 
33 PROCEDURE Approve_Contract
34 (
35 		itemtype      	IN VARCHAR2,
36 		itemkey       	IN VARCHAR2,
37 		actid         	IN NUMBER,
38 		funmode       	IN VARCHAR2,
39 		result    	OUT VARCHAR2
40 )
41 IS
42     l_return_status	VARCHAR2(1);
43     l_msg_count		NUMBER;
44     l_msg_data		VARCHAR2(2000);
45     l_errmsg_name	VARCHAR2(30);
46     l_API_ERROR		EXCEPTION;
47     l_wf_process_id	NUMBER;
48     l_status_id		NUMBER;
49     l_new_status	VARCHAR2(30);
50     l_dummy_id		NUMBER;
51     l_contract_id	NUMBER;
52     l_object_version_number NUMBER;
53 
54 BEGIN
55     	IF (funmode = 'RUN') THEN
56       	-- Get the workflow process ID
57       	CS_Contract_Wf_PUB.Decode_Contract_Wf_Itemkey(
58 		p_api_version		=>  1.0,
59 		p_init_msg_list		=>  FND_API.G_FALSE,
60 		x_return_status		=>  l_return_status,
61 		x_msg_count		=>  l_msg_count,
62 		x_msg_data		=>  l_msg_data,
63 		p_itemkey		=>  itemkey,
64 		p_contract_id		=>  l_contract_id,
65 		p_wf_process_id		=>  l_wf_process_id );
66 
67       	IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
68         		WF_CORE.context
69 			(
70 				pkg_name	=>  CS_CONTRACTS_WFA.l_pkg_name,
71 			 	proc_name	=>  'Decode_Contract_Wf_Itemkey',
72 			 	arg1		=>  'p_itemkey=>'||itemkey
73 			);
74 			l_errmsg_name := 'CS_WF_SR_CANT_DECODE_ITEMKEY';
75 			raise l_API_ERROR;
76       	END IF;
77 
78 	CS_CONTRACTS_PUB.Update_Contract
79  	(
80     		p_api_version                  	=> 1.0,
81     		p_init_msg_list                	=> TAPI_DEV_KIT.G_TRUE,
82     		p_validation_level             	=> 100,
83     		p_commit                       	=> TAPI_DEV_KIT.G_FALSE,
84     		x_return_status                	=> l_return_status,
85     		x_msg_count                    	=> l_msg_count,
86     		x_msg_data                     	=> l_msg_data,
87     		p_contract_id                  	=> l_contract_id,
88     		p_contract_status_id          	=> FND_PROFILE.VALUE('CS_CONTRACTS_ACTIVE_STATUS'),
89 		p_last_updated_by		=> FND_GLOBAL.user_id,
90 		p_last_update_date		=> sysdate,
91 		p_last_update_login		=> FND_GLOBAL.login_id,
92 		x_object_version_number		=> l_object_version_number
93 	);
94 
95       	IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
96         		WF_CORE.context
97 			(
98 				pkg_name	=>  CS_CONTRACTS_WFA.l_pkg_name,
99 			 	proc_name	=>  'Update_Contract',
100 			 	arg1		=>  'p_itemkey=>'||itemkey
101 			);
102 			l_errmsg_name := 'CS_WF_SR_CANT_UPDATE_STATUS';
103 			raise l_API_ERROR;
104       	END IF;
105 
106       result := 'COMPLETE';
107 
108     ELSIF (funmode = 'CANCEL') THEN
109       result := 'COMPLETE';
110     END IF;
111 
112 EXCEPTION
113     WHEN l_API_ERROR THEN
114       WF_CORE.Raise(l_errmsg_name);
115     WHEN OTHERS THEN
116       WF_CORE.Context(CS_CONTRACTS_WFA.l_pkg_name, 'Approve_Contract',
117 		      itemtype, itemkey, actid, funmode);
118       RAISE;
119 
120 END Approve_Contract;
121 
122 -- ---------------------------------------------------------------------------
123 -- Reject_Contract
124 --   This procedure corresponds to the Reject_Contract function activity.  It
125 -- ---------------------------------------------------------------------------
126 
127 PROCEDURE Reject_Contract
128 (
129 		itemtype      	IN VARCHAR2,
130 		itemkey       	IN VARCHAR2,
131 		actid         	IN NUMBER,
132 		funmode       	IN VARCHAR2,
133 		result    	OUT VARCHAR2
134 ) IS
135 
136 BEGIN
137 
138     	IF (funmode = 'RUN') THEN
139       		result := 'COMPLETE';
140     	ELSIF (funmode = 'CANCEL') THEN
141       		result := 'COMPLETE';
142     	END IF;
143 
144 EXCEPTION
145     WHEN OTHERS THEN
146       WF_CORE.Context(CS_CONTRACTS_WFA.l_pkg_name, 'Reject_Contract',
147 		      itemtype, itemkey, actid, funmode);
148       RAISE;
149 
150 END Reject_Contract;
151 
152 
153 -- Select_Approver
154 -- IN
155 --   itemtype  - A valid item type from (WF_ITEM_TYPES table).
156 --   itemkey   - A string generated from the application object's primary key.
157 --   actid     - The function activity(instance id).
158 --   funcmode  - Run/Cancel/Timeout
159 -- OUT
160 --   Resultout    - 'COMPLETE:T' if approver is found
161 --		  - 'COMPLETE:F' if approver is not found
162 --
163 -- USED BY ACTIVITIES
164 --  <ITEM_TYPE> <ACTIVITY>
165 --
166 PROCEDURE Select_Approver ( 	itemtype	in varchar2,
167 				itemkey  	in varchar2,
168 				actid		in number,
169 				funcmode	in varchar2,
170 				result	out varchar2	) is
171 --
172 	l_forward_from_username	varchar2(30);
173 	l_forward_to_username	varchar2(30);
174     	l_return_status		VARCHAR2(1);
175     	l_msg_count		NUMBER;
176     	l_msg_data		VARCHAR2(2000);
177     	l_employee_id		NUMBER;
178     	l_supervisor_name    	VARCHAR2(240);
179     	l_supervisor_role	VARCHAR2(100);
180     	l_supervisor_id 	NUMBER;
181     	l_errmsg_name		VARCHAR2(30);
182     	l_API_ERROR		EXCEPTION;
183 --
184 begin
185 	--
186 	-- RUN mode - normal process execution
187 	--
188 	if (funcmode = 'RUN') then
189 		l_forward_to_username := wf_engine.GetItemAttrText(
190 					itemtype => itemtype,
191     					itemkey => itemkey,
192     					aname  	=> 'FORWARD_TO_USERNAME' );
193 
194 		--
195 		-- Retrieve the last person the requisition was forwarded
196 		-- to for approval.
197 		--
198 		if ( l_forward_to_username is null ) then
199 		--
200   		  l_forward_to_username := wf_engine.GetItemAttrText(
201 					itemtype => itemtype,
202 		    			itemkey  => itemkey,
203 		    			aname => 'REQUESTOR_USERNAME' );
204 		--
205 		end if;
206 		--
207 		l_forward_from_username := l_forward_to_username;
208 		--
209 		wf_engine.SetItemAttrText (
210 				itemtype	=> itemtype,
211 	      			itemkey  	=> itemkey,
212   	      			aname		=> 'FORWARD_FROM_USERNAME',
213 				avalue		=>  l_forward_from_username);
214 
215 		-- ***** ******** IMPORTANT ***********************************
216 		-- For now, SKARUPPA is the person to approve all the contract
217 		-- This logic should be changed by the customer by calling an API
218 		-- which will return a valid oracle application user to approve
219 		-- Contracts.
220 		-- ***** ******** IMPORTANT ***********************************
221 
222 		l_forward_to_username := 'SKARUPPA';
223 
224 		wf_engine.SetItemAttrText (
225 				itemtype	=> itemtype,
226 	      			itemkey  	=> itemkey,
227   	      			aname 		=> 'FORWARD_TO_USERNAME',
228 				avalue		=>  l_forward_to_username);
229 		if ( l_forward_to_username is null ) then
230 			--
231 			result := 'COMPLETE:F';
232 			--
233 		else
234 			--
235 			result := 'COMPLETE:T';
236 			--
237 		end if;
238 	--
239 	end if;
240 	--
241   	-- CANCEL mode - activity
242 	--
243   	if (funcmode = 'CANCEL') then
244 		--
245     		result := 'COMPLETE:';
246     		return;
247 		--
248   	end if;
249 	--
250 	-- TIMEOUT mode
251 	--
252 	if (funcmode = 'TIMEOUT') then
253 		result := 'COMPLETE:';
254 		return;
255 	end if;
256 
257 exception
258 	WHEN l_API_ERROR then
259       		WF_CORE.Raise(l_errmsg_name);
260 	WHEN OTHERS then
261 		WF_CORE.context(CS_CONTRACTS_WFA.l_pkg_name,'Select_Approver',itemtype,itemkey,actid,funcmode);
262 		raise;
263 end Select_Approver;
264 
265 
266 
267 -- ***************************************************************************
268 -- *                                                                         *
269 -- *                           System: Error Item Type                       *
270 -- *                                                                         *
271 -- *  Following activities are used in the Service Request Error Process     *
272 -- *                                                                         *
273 -- ***************************************************************************
274 
275 
276 -- -------------------------------------------------------------------
277 -- Initialize_Errors
278 --   Retrieve the exception messages from the process that errored out
279 --   and store them in the item attributes of the error process.  Also,
280 --   get the role of the Workflow administrator.
281 -- -------------------------------------------------------------------
282 
283   PROCEDURE Initialize_Errors(    itemtype      VARCHAR2,
284 				  itemkey	VARCHAR2,
285 				  actid	        NUMBER,
286 				  funmode	VARCHAR2,
287 				  result    OUT VARCHAR2 ) IS
288 
289     l_error_item_type	VARCHAR2(8);
290     l_error_itemkey	VARCHAR2(240);
291     l_error_name	VARCHAR2(30);
292     l_error_msg		VARCHAR2(2000);
293     l_administrator	VARCHAR2(100);
294     l_monitor_url	VARCHAR2(500);
295 
296   BEGIN
297     IF (funmode = 'RUN') THEN
298 
299       --
300       -- Get the type and the key of the process that errored out
301       --
302       l_error_itemkey := WF_ENGINE.GetItemAttrText(
303 				itemtype	=> itemtype,
304 				itemkey		=> itemkey,
305 				aname		=> 'ERROR_ITEM_KEY' );
306 
307       l_error_item_type := WF_ENGINE.GetItemAttrText(
308 				itemtype	=> itemtype,
309 				itemkey		=> itemkey,
310 				aname		=> 'ERROR_ITEM_TYPE' );
311 
312       --
313       -- Get the error message
314       --
315       l_error_name := WF_ENGINE.GetItemAttrText(
316 				itemtype	=> itemtype,
317 				itemkey		=> itemkey,
318 				aname		=> 'ERROR_NAME' );
319 
320       IF (l_error_name IS NOT NULL) THEN
321         FND_MESSAGE.SET_NAME('CS', l_error_name);
322         l_error_msg := FND_MESSAGE.GET;
323       END IF;
324 
325       --
326       -- Get the workflow administrator
327       --
328       l_administrator := WF_ENGINE.GetItemAttrText(
329 				itemtype	=> l_error_item_type,
330 				itemkey		=> l_error_itemkey,
331 				aname		=> 'WF_ADMINISTRATOR' );
332       --
333       -- Set the item attributes of the error process
334       --
335       WF_ENGINE.SetItemAttrText(itemtype	=> itemtype,
336 				itemkey		=> itemkey,
337 				aname		=> 'ERROR_MESSAGE',
338 				avalue		=> l_error_msg );
339 
340       WF_ENGINE.SetItemAttrText(itemtype	=> itemtype,
341 				itemkey		=> itemkey,
342 				aname		=> 'SERVEREQ_WF_ADMIN',
343 				avalue		=> l_administrator );
344 
345       l_monitor_url := WF_MONITOR.GetEnvelopeURL
346 		     ( x_agent		=> FND_PROFILE.Value('APPS_WEB_AGENT'),
347 		       x_item_type	=> l_error_item_type,
348 		       x_item_key	=> l_error_itemkey,
349 		       x_admin_mode	=> 'YES'
350 		     );
351       WF_ENGINE.SetItemAttrText(itemtype	=> itemtype,
352 				itemkey		=> itemkey,
353 				aname		=> 'SERVEREQ_MONITOR_URL',
354 				avalue		=> l_monitor_url );
355 
356       result := 'COMPLETE';
357 
358     ELSIF (funmode = 'CANCEL') THEN
359       result := 'COMPLETE';
360     END IF;
361 
362   EXCEPTION
363     WHEN OTHERS THEN
364       WF_CORE.Context(CS_CONTRACTS_WFA.l_pkg_name, 'Initialize_Errors',
365 		      itemtype, itemkey, actid, funmode);
366       RAISE;
367   END Initialize_Errors;
368 
369 PROCEDURE Initialize_Request
370 (
371 	itemtype	VARCHAR2,
372 	itemkey		VARCHAR2,
373 	actid		NUMBER,
374 	funmode		VARCHAR2,
375 	result		OUT VARCHAR2
376 )
377 IS
378     l_msg_count		NUMBER;
379     l_msg_data		VARCHAR2(2000);
380     l_contract_id	NUMBER;
381     l_dummy		NUMBER;
382     l_return_status	VARCHAR2(1);
383     l_API_ERROR		EXCEPTION;
384 
385     CURSOR l_Contract_csr IS
386       SELECT *
387         FROM CS_Contracts_all
388        WHERE CONTRACT_ID = l_contract_id;
389 
390     l_Contract_rec 	l_Contract_csr%ROWTYPE;
391     l_errmsg_name	VARCHAR2(30);
392 
393   BEGIN
394     IF (funmode = 'RUN') THEN
395       -- Decode the item key to get the service contract number
396       CS_Contract_Wf_PUB.Decode_Contract_Wf_Itemkey(
397 		p_api_version		=>  1.0,
398 		x_return_status		=>  l_return_status,
399 		x_msg_count		=>  l_msg_count,
400 		x_msg_data		=>  l_msg_data,
401 		p_itemkey		=>  itemkey,
402 		p_contract_id		=>  l_contract_id,
403 		p_wf_process_id		=>  l_dummy );
404 
405       IF (l_return_status <> FND_API.G_RET_STS_SUCCESS) THEN
406         WF_CORE.context( pkg_name	=>  CS_CONTRACTS_WFA.l_pkg_name,
407 			 proc_name	=>  'Decode_Contract_Wf_Itemkey',
408 			 arg1		=>  'p_itemkey =>'||itemkey );
409 	l_errmsg_name := 'CS_WF_SR_CANT_DECODE_ITEMKEY';
410 	raise l_API_ERROR;
411       END IF;
412 
413       -- Extract the contract record
414       OPEN l_Contract_csr;
415       FETCH l_Contract_csr INTO l_Contract_rec;
416 
417       -- Initialize item attributes that will remain constant
418       WF_ENGINE.SetItemAttrNumber(
419 		itemtype	=> CS_Contract_Wf_PUB.l_itemtype,
420 		itemkey		=> itemkey,
421 		aname		=> 'CONTRACT_ID',
422 		avalue		=> l_Contract_rec.contract_id );
423 
424       WF_ENGINE.SetItemAttrNumber(
425 		itemtype	=> CS_Contract_Wf_PUB.l_itemtype,
426 		itemkey		=> itemkey,
427 		aname		=> 'CONTRACT_NUMBER',
428 		avalue		=> l_Contract_rec.contract_number );
429 
430       WF_ENGINE.SetItemAttrNumber(
431 		itemtype	=> CS_Contract_Wf_PUB.l_itemtype,
432 		itemkey		=> itemkey,
433 		aname		=> 'CONTRACT_AMOUNT',
434 		avalue		=> l_Contract_rec.contract_amount );
435 
436       CLOSE l_Contract_csr;
437 
438       result := 'COMPLETE';
439 
440     ELSIF (funmode = 'CANCEL') THEN
441       result := 'COMPLETE';
442     END IF;
443 
444   EXCEPTION
445     WHEN l_API_ERROR THEN
446       WF_CORE.Raise(l_errmsg_name);
447     WHEN OTHERS THEN
448       WF_CORE.Context(CS_CONTRACTS_WFA.l_pkg_name, 'Initialize_Request',
449 		      itemtype, itemkey, actid, funmode);
450       RAISE;
451 
452   END Initialize_Request;
453 
454 
455 
456 END CS_CONTRACTS_WFA;