DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKL_CREDIT_LINE_WF

Source


1 PACKAGE BODY OKL_CREDIT_LINE_WF AS
2 /* $Header: OKLRDWFB.pls 120.6 2011/05/13 11:23:27 rgooty ship $ */
3 
4   G_NO_MATCHING_RECORD          CONSTANT VARCHAR2(200)  := 'OKL_LLA_NO_MATCHING_RECORD';
5   G_REQUIRED_VALUE              CONSTANT VARCHAR2(200)  := OKL_API.G_REQUIRED_VALUE;
6   G_INVALID_VALUE               CONSTANT VARCHAR2(200)  := OKL_API.G_INVALID_VALUE;
7   G_COL_NAME_TOKEN              CONSTANT VARCHAR2(200)  := OKL_API.G_COL_NAME_TOKEN;
8   G_PARENT_TABLE_TOKEN	        CONSTANT VARCHAR2(200)   := OKL_API.G_PARENT_TABLE_TOKEN;
9   G_CHILD_TABLE_TOKEN	        CONSTANT VARCHAR2(200)    := OKL_API.G_CHILD_TABLE_TOKEN;
10   G_UNEXPECTED_ERROR            CONSTANT VARCHAR2(200)  := 'OKC_CONTRACTS_UNEXP_ERROR';
11   G_SQLERRM_TOKEN               CONSTANT VARCHAR2(200)  := 'SQLerrm';
12   G_SQLCODE_TOKEN               CONSTANT VARCHAR2(200)  := 'SQLcode';
13   G_API_TYPE                    CONSTANT VARCHAR2(200)  := '_PVT';
14   G_CHAR_AMPERSAND              CONSTANT VARCHAR2(1)    := '&';
15 -------------------------------------------------------------------------------------------------
16 ----------------------------- Messages and constant names ---------------------------------------
17 -------------------------------------------------------------------------------------------------
18   G_KHR_STATUS_NOT_COMPLETE               VARCHAR2(200)  := 'OKL_LLA_NOT_COMPLETE';
19   G_TRANS_APP_NAME              CONSTANT VARCHAR2(200)  := 'OKL LA Credit Line Approval';
20   G_INVALID_APP                          VARCHAR2(200)  := 'OKL_LLA_INVALID_APPLICATION';
21 
22   G_MSG_TOKEN_CONTRACT_NUMBER   CONSTANT VARCHAR2(30) := 'CONTRACT_NUMBER';
23   G_EVENT_APPROVE_WF            CONSTANT VARCHAR2(50) := 'oracle.apps.okl.la.approve_credit_line';
24   G_EVENT_APPROVE_AME           CONSTANT VARCHAR2(50) := 'oracle.apps.okl.la.approve_credit_line';
25   G_LEASE_CONTRACT_APPROVAL_WF  CONSTANT VARCHAR2(2)  := 'WF';
26   G_LEASE_CONTRACT_APPROVAL_AME CONSTANT VARCHAR2(3)  := 'AME';
27 -- cklee : start: 5/18/2005
28   G_TRX_TYPE_CONTRACT_APPROVAL  CONSTANT VARCHAR2(20) := 'CREDIT_LINE_APPROVAL';
29   G_TRX_TCN_TYPE                CONSTANT VARCHAR2(3)  := 'CLA';--10/03/2005 cklee. 'CPR';
30 -- cklee : end: 5/18/2005
31   G_TRX_TSU_CODE_SUBMITTED      CONSTANT VARCHAR2(10) := 'SUBMITTED';
32   G_TRX_TSU_CODE_PROCESSED      CONSTANT VARCHAR2(10) := 'PROCESSED';
33   G_SOURCE_TRX_TYPE_WF          CONSTANT VARCHAR2(10) := 'WF';
34 
35   G_KHR_STS_PENDING_APPROVAL    CONSTANT VARCHAR2(20) := 'PENDING_APPROVAL';
36   G_KHR_STS_COMPLETE            CONSTANT VARCHAR2(10) := 'COMPLETE';
37   G_KHR_STS_INCOMPLETE          CONSTANT VARCHAR2(15) := 'INCOMPLETE';
38   G_KHR_STS_APPROVED            CONSTANT VARCHAR2(15) := 'APPROVED';
39   G_KHR_STS_DECLINED            CONSTANT VARCHAR2(15) := 'DECLINED';
40 
41   G_WF_ITM_CONTRACT_ID         CONSTANT VARCHAR2(20) := 'CONTRACT_ID';
42   G_WF_ITM_CONTRACT_NUMBER     CONSTANT VARCHAR2(20) := 'CONTRACT_NUMBER';
43   G_WF_ITM_APPLICATION_ID      CONSTANT VARCHAR2(20) := 'APPLICATION_ID';
44   G_WF_ITM_TRANSACTION_TYPE_ID CONSTANT VARCHAR2(20) := 'TRX_TYPE_ID';
45   G_WF_ITM_TRANSACTION_ID      CONSTANT VARCHAR2(20) := 'TRANSACTION_ID';
46   G_WF_ITM_REQUESTER           CONSTANT VARCHAR2(20) := 'REQUESTER';
47   G_WF_ITM_REQUESTER_ID        CONSTANT VARCHAR2(20) := 'REQUESTER_ID';
48   G_WF_ITM_APPROVER            CONSTANT VARCHAR2(20) := 'APPROVER';
49   G_WF_ITM_APPROVAL_REQ_MSG    CONSTANT VARCHAR2(30) := 'APPROVAL_REQUEST_MESSAGE';
50   G_WF_ITM_RESULT              CONSTANT VARCHAR2(10) := 'RESULT';
51   G_WF_ITM_PARENT_ITEM_KEY     CONSTANT VARCHAR2(20) := 'PARENT_ITEM_KEY';
52   G_WF_ITM_PARENT_ITEM_TYPE    CONSTANT VARCHAR2(20) := 'PARENT_ITEM_TYPE';
53   G_WF_ITM_APPROVED_YN         CONSTANT VARCHAR2(15) := 'APPROVED_YN';
54   G_WF_ITM_MASTER              CONSTANT VARCHAR2(10) := 'MASTER';
55   G_WF_ITM_MESSAGE_DESCRIPTION CONSTANT VARCHAR2(30) := 'MESSAGE_DESCRIPTION';
56   G_WF_ITM_MESSAGE_DOC         CONSTANT VARCHAR2(15) := 'MESSAGE_DOC';
57   G_WF_ITM_MESSAGE_SUBJECT     CONSTANT VARCHAR2(20) := 'MESSAGE_SUBJECT';
58   G_WF_ITM_APP_REQUEST_SUB     CONSTANT VARCHAR2(30) := 'APP_REQUEST_SUB';
59   G_WF_ITM_APP_REMINDER_SUB    CONSTANT VARCHAR2(30) := 'APP_REMINDER_SUB';
60   G_WF_ITM_APP_APPROVED_SUB     CONSTANT VARCHAR2(30) := 'APP_APPROVED_SUB';
61   G_WF_ITM_APP_REJECTED_SUB     CONSTANT VARCHAR2(30) := 'APP_REJECTED_SUB';
62   G_WF_ITM_APP_REMINDER_HEAD    CONSTANT VARCHAR2(30) := 'APP_REMINDER_HEAD';
63   G_WF_ITM_APP_APPROVED_HEAD     CONSTANT VARCHAR2(30) := 'APP_APPROVED_HEAD';
64   G_WF_ITM_APP_REJECTED_HEAD     CONSTANT VARCHAR2(30) := 'APP_REJECTED_HEAD';
65 
66   G_WF_ITM_RESULT_APPROVED     CONSTANT VARCHAR2(15) := 'APPROVED';
67   G_WF_ITM_APPROVED_YN_YES     CONSTANT VARCHAR2(1)  := 'Y';
68   G_WF_ITM_APPROVED_YN_NO      CONSTANT VARCHAR2(1)  := 'N';
69 
70   G_ITEM_TYPE_WF CONSTANT VARCHAR2(10)         := 'OKLCLAPP';
71   G_APPROVAL_PROCESS_WF CONSTANT VARCHAR2(30)  := 'CRTLINE_APPROVAL_WF';
72 
73   G_DEFAULT_USER CONSTANT VARCHAR2(10) := 'SYSADMIN';
74   G_DEFAULT_USER_DESC CONSTANT VARCHAR2(30) := 'System Administrator';
75   G_WF_USER_ORIG_SYSTEM_HR CONSTANT VARCHAR2(5) := 'PER';
76 
77 
78  ---------------------------------------------------------------------------
79  -- PROCEDURE l_get_agent
80  ---------------------------------------------------------------------------
81   -- Start of comments
82   --
83   -- Procedure Name  : l_get_agent
84   -- Description     :
85   -- Business Rules  :
86   -- Parameters      : p_user_id, x_return_status, x_name, x_description
87   -- Version         : 1.0
88   -- End of comments
89   ---------------------------------------------------------------------------
90   PROCEDURE l_get_agent(p_user_id     IN  NUMBER,
91                         x_return_status  OUT NOCOPY VARCHAR2,
92                         x_name        OUT NOCOPY VARCHAR2,
93                         x_description OUT NOCOPY VARCHAR2) IS
94 
95     CURSOR wf_users_csr(c_user_id NUMBER)
96     IS
97     SELECT NAME, DISPLAY_NAME
98     FROM   WF_USERS
99     WHERE  orig_system_id = c_user_id
100    	AND    ORIG_SYSTEM = G_WF_USER_ORIG_SYSTEM_HR;
101 
102     CURSOR fnd_users_csr(c_user_id NUMBER)
103     IS
104     SELECT USER_NAME, DESCRIPTION
105     FROM   FND_USER
106     WHERE  user_id = c_user_id;
107   BEGIN
108     x_return_status      := OKL_API.G_RET_STS_SUCCESS;
109     OPEN  wf_users_csr(p_user_id);
110     FETCH wf_users_csr INTO x_name, x_description;
111     CLOSE wf_users_csr;
112     IF x_name IS NULL THEN
113       OPEN  fnd_users_csr(p_user_id);
114       FETCH fnd_users_csr INTO x_name, x_description;
115       CLOSE fnd_users_csr;
116       IF x_name IS NULL THEN
117         x_name        := G_DEFAULT_USER_DESC;
118         x_description := G_DEFAULT_USER_DESC;
119       END IF;
120     END IF;
121   EXCEPTION
122     WHEN OTHERS THEN
123       x_return_status      := OKL_API.G_RET_STS_UNEXP_ERROR;
124   END l_get_agent;
125 
126  ---------------------------------------------------------------------------
127  -- PROCEDURE l_change_k_status
128  ---------------------------------------------------------------------------
129   -- Start of comments
130   --
131   -- Procedure Name  : l_change_k_status
132   -- Description     :
133   -- Business Rules  : This updates the credit line status.
134   -- Parameters      : p_api_version, p_init_msg_list, x_return_status, x_msg_count,
135   --                   x_msg_data, p_khr_status, p_chr_id.
136   -- Version         : 1.0
137   -- End of comments
138   ---------------------------------------------------------------------------
139   PROCEDURE l_change_k_status(p_api_version    IN  NUMBER,
140                               p_init_msg_list  IN  VARCHAR2 DEFAULT OKL_API.G_FALSE,
141                               x_return_status  OUT NOCOPY VARCHAR2,
142                               x_msg_count      OUT NOCOPY NUMBER,
143                               x_msg_data       OUT NOCOPY VARCHAR2,
144                               p_khr_status     IN  OKC_K_HEADERS_V.STS_CODE%TYPE,
145                               p_chr_id         IN  NUMBER) IS
146 
147     l_api_name     CONSTANT VARCHAR2(30) := 'l_change_k_status';
148     lx_khr_status  varchar2(30);
149 
150   BEGIN
151     x_return_status      := OKL_API.G_RET_STS_SUCCESS;
152     -- Call start_activity to create savepoint, check compatibility
153     -- and initialize message list
154     x_return_status := OKL_API.START_ACTIVITY (
155                                l_api_name,
156                                p_init_msg_list,
157                                '_PVT',
158                                x_return_status);
159 
160     -- Check if activity started successfully
161     IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
162        RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
163     ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
164        RAISE OKL_API.G_EXCEPTION_ERROR;
165     END IF;
166 
167 --------------------------------------------------------------------------------
168 -- The status of the credit line will initiate to 'SUBMITTED' and the credit line
169 -- process API will do the validations before invoke:
170 -- OKL_CREDIT_LINE_WF.raise_approval_event().
171 -- cklee May-06-2005
172 --------------------------------------------------------------------------------
173     OKL_CREDIT_PUB.update_credit_line_status(
174                             p_api_version    => p_api_version,
175                             p_init_msg_list  => p_init_msg_list,
176                             x_return_status  => x_return_status,
177                             x_msg_count      => x_msg_count,
178                             x_msg_data       => x_msg_data,
179                             x_status_code    => lx_khr_status,
180                             p_status_code    => p_khr_status,
181                             p_credit_line_id => p_chr_id);
182 
183     IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
184       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
185     ELSIF (x_return_Status = OKL_API.G_RET_STS_ERROR)  THEN
186       RAISE OKL_API.G_EXCEPTION_ERROR;
187     END IF;
188 
189     OKL_API.END_ACTIVITY (x_msg_count,
190                           x_msg_data );
191   EXCEPTION
192     WHEN OKL_API.G_EXCEPTION_ERROR THEN
193     x_return_status := OKL_API.HANDLE_EXCEPTIONS(
194                                l_api_name,
195                                G_PKG_NAME,
196                                'OKL_API.G_RET_STS_ERROR',
197                                x_msg_count,
198                                x_msg_data,
199                                '_PVT');
200     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
201     x_return_status :=OKL_API.HANDLE_EXCEPTIONS(
202                               l_api_name,
203                               G_PKG_NAME,
204                               'OKL_API.G_RET_STS_UNEXP_ERROR',
205                               x_msg_count,
206                               x_msg_data,
207                               '_PVT');
208     WHEN OTHERS THEN
209     x_return_status :=OKL_API.HANDLE_EXCEPTIONS(
210                               l_api_name,
211                               G_PKG_NAME,
212                               'OTHERS',
213                               x_msg_count,
214                               x_msg_data,
215                               '_PVT');
216   END l_change_k_status;
217 
218  ---------------------------------------------------------------------------
219  -- FUNCTION get_message
220  ---------------------------------------------------------------------------
221   -- Start of comments
222   --
223   -- Function Name  : get_message
224   -- Description     :
225   -- Business Rules  : Sets tha appropriate message for approval and for
226   --                   approved or rejected credit line.
227   -- Parameters      : p_msg_name, p_contract_number
228   -- Version         : 1.0
229   -- End of comments
230   ---------------------------------------------------------------------------
231   FUNCTION get_message(p_msg_name        IN VARCHAR2,
232                        p_contract_number IN VARCHAR2)
233     RETURN VARCHAR2
234   IS
235     l_message VARCHAR2(100);
236   BEGIN
237     IF p_msg_name IS NOT NULL THEN
238        Fnd_Message.SET_NAME(APPLICATION => G_APP_NAME
239                            ,NAME => p_msg_name);
240        Fnd_Message.SET_TOKEN(TOKEN => G_MSG_TOKEN_CONTRACT_NUMBER,
241                              VALUE => p_contract_number);
242        l_message := fnd_message.get();
243 	END IF;
244 
245 	RETURN l_message;
246   EXCEPTION
247    WHEN OTHERS THEN
248       RETURN NULL;
249   END get_message;
250 
251   --------------------------------------------------------------------------------------------------
252   ----------------------------------Rasing Business Event ------------------------------------------
253   --------------------------------------------------------------------------------------------------
254  ---------------------------------------------------------------------------
255  -- PROCEDURE raise_approval_event
256  ---------------------------------------------------------------------------
257   -- Start of comments
258   --
259   -- Procedure Name  : raise_approval_event
260   -- Description     :
261   -- Business Rules  : Raises the credit line approval event
262   -- Parameters      : p_api_version, p_init_msg_list, x_return_status, x_msg_count,
263   --                   x_msg_data, p_contract_id.
264   -- Version         : 1.0
265   -- End of comments
266   ---------------------------------------------------------------------------
267   PROCEDURE raise_approval_event (p_api_version    IN  NUMBER,
268                                   p_init_msg_list  IN  VARCHAR2 DEFAULT OKL_API.G_FALSE,
269                                   x_return_status  OUT NOCOPY VARCHAR2,
270                                   x_msg_count      OUT NOCOPY NUMBER,
271                                   x_msg_data       OUT NOCOPY VARCHAR2,
272                                   p_contract_id    IN  OKC_K_HEADERS_B.ID%TYPE)
273   IS
274 
275     -- Get Contract Details
276     CURSOR c_fetch_k_number(p_contract_id OKC_K_HEADERS_V.ID%TYPE)
277     IS
278     SELECT chrv.contract_number,
279            chrv.sts_code
280     FROM okc_k_headers_v chrv
281     WHERE chrv.id = p_contract_id;
282 
283     -- Get the valid application id from FND
284     CURSOR c_get_app_id_csr
285     IS
286     SELECT APPLICATION_ID
287     FROM   FND_APPLICATION
288     WHERE  APPLICATION_SHORT_NAME = G_APP_NAME;
289 
290     -- Modified cursor by bkatraga for bug 9118673
291     -- Get the Transaction Type Id from OAM
292     CURSOR c_get_trx_type_csr(c_trx_type  VARCHAR2)
293     IS
294     SELECT B.TRANSACTION_TYPE_ID,
295            B.FND_APPLICATION_ID
296       FROM AME_CALLING_APPS B,
297            AME_CALLING_APPS_TL T
298      WHERE B.APPLICATION_ID = T.APPLICATION_ID
299        AND T.LANGUAGE = 'US'
300        AND T.APPLICATION_NAME = c_trx_type;
301 
302 /*  --commented for performance issue#5484903
303     SELECT transaction_type_id,
304            fnd_application_id
305     FROM   AME_CALLING_APPS
306     WHERE  application_name = c_trx_type; */
307 
308     CURSOR l_wf_item_key_csr IS
309     SELECT okl_wf_item_s.NEXTVAL item_key
310     FROM  dual;
311 
312     CURSOR l_trx_try_csr  IS
313     SELECT id
314     FROM   okl_trx_types_b
315     WHERE  trx_type_class = G_TRX_TYPE_CONTRACT_APPROVAL;
316 
317 
318     l_return_status    VARCHAR2(3);
319     l_api_version      NUMBER;
320     l_api_name         CONSTANT VARCHAR2(30) := 'raise_approval_event';
321     l_msg_count	       NUMBER;
322     l_init_msg_list    VARCHAR2(10);
323     l_msg_data		       VARCHAR2(2000);
324     l_parameter_list   wf_parameter_list_t;
325     l_key              VARCHAR2(240);
326     l_event_name       VARCHAR2(240);
327     l_application_id   FND_APPLICATION.APPLICATION_ID%TYPE;
328     l_trans_appl_id    AME_CALLING_APPS.APPLICATION_ID%TYPE;
329     l_trans_type_id    AME_CALLING_APPS.TRANSACTION_TYPE_ID%TYPE;
330    	l_contract_num     OKC_K_HEADERS_V.CONTRACT_NUMBER%TYPE;
331     l_chrv_id          OKC_K_HEADERS_V.ID%TYPE ;
332     l_sts_code         OKC_K_HEADERS_V.STS_CODE%TYPE;
333    	l_requester        VARCHAR2(200);
334     l_name             VARCHAR2(200);
335     l_requester_id     VARCHAR2(200);
336     l_trxH_in_rec      Okl_Trx_Contracts_Pvt.tcnv_rec_type;
337     l_trxH_out_rec     Okl_Trx_Contracts_Pvt.tcnv_rec_type;
338    	l_approval_option  VARCHAR2(5);
339 
340   BEGIN
341 
342     l_return_status := OKL_API.G_RET_STS_SUCCESS;
343     l_api_version 	 := 1.0;
344     l_init_msg_list := OKL_API.G_FALSE;
345     l_chrv_id       := p_contract_id;
346     x_return_status := OKL_API.G_RET_STS_SUCCESS;
347 
348     -- Call start_activity to create savepoint, check compatibility
349     -- and initialize message list
350     x_return_status := OKL_API.START_ACTIVITY(l_api_name,
351                                               p_init_msg_list,
352                                               '_PVT',
353                                               x_return_status);
354     -- Check if activity started successfully
355     IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
356        RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
357     ELSIF (x_return_status = OKL_API.G_RET_STS_ERROR) THEN
358        RAISE OKL_API.G_EXCEPTION_ERROR;
359     END IF;
360 
361    -- Create Internal Transaction
362 
363     -- Get the user id, Item key
364     l_requester_id := FND_GLOBAL.USER_ID;
365 
366     l_get_agent(p_user_id       => l_requester_id,
367                 x_return_status => x_return_status,
368 	               x_name          => l_requester,
369 	               x_description   => l_name);
370 
371     IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
372       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
373     ELSIF (x_return_Status = OKL_API.G_RET_STS_ERROR)  THEN
374        RAISE OKL_API.G_EXCEPTION_ERROR;
375     END IF;
376 
377     FOR l_wf_item_key_rec IN l_wf_item_key_csr
378     LOOP
379         l_key := l_wf_item_key_rec.item_key;
380     END LOOP;
381 
382     FOR l_trx_try_rec IN l_trx_try_csr
383     LOOP
384          l_trxH_in_rec.try_id         := l_trx_try_rec.id;
385     END LOOP;
386 
387     l_trxH_in_rec.tcn_type                   := G_TRX_TCN_TYPE;
388     l_trxH_in_rec.tsu_code                   := G_TRX_TSU_CODE_SUBMITTED;
389     l_trxH_in_rec.description                := l_requester_id; -- requestor user_id
390     l_trxH_in_rec.date_transaction_occurred  := SYSDATE; -- sysdate
391     l_trxH_in_rec.source_trx_id              := l_key;
392     l_trxH_in_rec.source_trx_type            := G_SOURCE_TRX_TYPE_WF;
393 
394   -- Create Transaction Header
395     Okl_Trx_Contracts_Pub.create_trx_contracts(p_api_version     => l_api_version
396                                                ,p_init_msg_list  => l_init_msg_list
397                                                ,x_return_status  => l_return_status
398                                                ,x_msg_count      => l_msg_count
399                                                ,x_msg_data       => l_msg_data
400                                                ,p_tcnv_rec       => l_trxH_in_rec
401                                                ,x_tcnv_rec       => l_trxH_out_rec);
402 
403     IF (l_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
404         RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
405     ELSIF (l_return_Status = Okl_Api.G_RET_STS_ERROR) THEN
406         RAISE Okl_Api.G_EXCEPTION_ERROR;
407     END IF;
408 	-- end, mvasudev
409 
410 		l_approval_option := fnd_profile.value('OKL_CREDIT_LINE_APPROVAL_PROCESS');
411 		IF l_approval_option = G_LEASE_CONTRACT_APPROVAL_AME THEN
412 
413 	    -- Get the Contract Number
414 		    OPEN  c_fetch_k_number(l_chrv_id);
415 		    FETCH c_fetch_k_number INTO l_contract_num,l_sts_code;
416 		    IF c_fetch_k_number%NOTFOUND THEN
417 		      OKL_API.set_message(p_app_name     => G_APP_NAME,
418 		                          p_msg_name     => G_NO_MATCHING_RECORD,
419 		                          p_token1       => G_COL_NAME_TOKEN,
420 		                          p_token1_value => 'OKC_K_HEADERS_V.ID');
421 		      RAISE OKL_API.G_EXCEPTION_ERROR;
422 		    END IF;
423 		    CLOSE c_fetch_k_number;
424 
425 			-- Get the Application ID
426 		    OPEN  c_get_app_id_csr;
427 		    FETCH c_get_app_id_csr INTO l_application_id;
428 		    IF c_get_app_id_csr%NOTFOUND THEN
429 		      OKL_API.set_message(p_app_name     => G_APP_NAME,
430 		                          p_msg_name     => G_NO_MATCHING_RECORD,
431 		                          p_token1       => G_COL_NAME_TOKEN,
432 		                          p_token1_value => 'Application id');
433 		      RAISE OKL_API.G_EXCEPTION_ERROR;
434 		    END IF;
435 		    CLOSE c_get_app_id_csr;
436 
437 			-- Get the Transaction Type ID
438 		    OPEN  c_get_trx_type_csr(G_TRANS_APP_NAME);
439 		    FETCH c_get_trx_type_csr INTO l_trans_type_id,
440 		                                  l_trans_appl_id;
441 		    IF c_get_trx_type_csr%NOTFOUND THEN
442 		      OKL_API.set_message(p_app_name     => G_APP_NAME,
443 		                          p_msg_name     => G_NO_MATCHING_RECORD,
444 		                          p_token1       => G_COL_NAME_TOKEN,
445 		                          p_token1_value => 'AME Transcation TYPE id, Application id');
446 		      RAISE OKL_API.G_EXCEPTION_ERROR;
447 		    END IF;
448 		    CLOSE c_get_trx_type_csr;
449 
450 
451 		    IF l_application_id = l_trans_appl_id THEN
452          l_event_name := G_EVENT_APPROVE_AME;
453 
454          wf_event.AddParameterToList(G_WF_ITM_CONTRACT_ID,p_contract_id,l_parameter_list);
455          wf_event.AddParameterToList(G_WF_ITM_CONTRACT_NUMBER,l_contract_num,l_parameter_list);
456          wf_event.AddParameterToList(G_WF_ITM_APPLICATION_ID,l_application_id,l_parameter_list);
457          wf_event.AddParameterToList(G_WF_ITM_TRANSACTION_TYPE_ID,l_trans_type_id,l_parameter_list);
458          wf_event.AddParameterToList(G_WF_ITM_TRANSACTION_ID,l_trxH_out_rec.trx_number,l_parameter_list);
459          wf_event.AddParameterToList(G_WF_ITM_REQUESTER,l_requester,l_parameter_list);
460          wf_event.AddParameterToList(G_WF_ITM_REQUESTER_ID,l_requester_id,l_parameter_list);
461 	 --added by akrangan
462 	wf_event.AddParameterToList('ORG_ID',mo_global.get_current_org_id ,l_parameter_list);
463 
464 		    ELSE
465 		      OKL_API.set_message(p_app_name     => G_APP_NAME,
466 		                          p_msg_name     => G_INVALID_APP);
467 		      RAISE OKL_API.G_EXCEPTION_ERROR;
468 		    END IF; -- l_application_id
469 
470 	 	ELSIF l_approval_option = G_LEASE_CONTRACT_APPROVAL_WF THEN
471 		   l_event_name := G_EVENT_APPROVE_WF;
472 
473 			  FOR c_fetch_k_number_rec IN c_fetch_k_number(l_chrv_id)
474 			  LOOP
475 			    l_contract_num := c_fetch_k_number_rec.contract_number;
476 			  END LOOP;
477 
478      wf_event.AddParameterToList(G_WF_ITM_CONTRACT_ID,p_contract_id,l_parameter_list);
479      wf_event.AddParameterToList(G_WF_ITM_CONTRACT_NUMBER,l_contract_num,l_parameter_list);
480      wf_event.AddParameterToList(G_WF_ITM_REQUESTER,l_requester,l_parameter_list);
481      wf_event.AddParameterToList(G_WF_ITM_REQUESTER_ID,l_requester_id,l_parameter_list);
482      wf_event.AddParameterToList(G_WF_ITM_TRANSACTION_ID,l_trxH_out_rec.trx_number,l_parameter_list);
483      --added by akrangan
484 	wf_event.AddParameterToList('ORG_ID',mo_global.get_current_org_id ,l_parameter_list);
485     ELSE
486 	     RAISE OKL_API.G_EXCEPTION_ERROR;
487 		END IF; -- l_approval_option
488 
489     -- We need to status to Approved Pending since We are sending for approval
490     l_change_k_status(p_api_version   => p_api_version,
491                       p_init_msg_list => p_init_msg_list,
492                       x_return_status => x_return_status,
493                       x_msg_count     => x_msg_count,
494                       x_msg_data      => x_msg_data,
495                       p_khr_status    => G_KHR_STS_PENDING_APPROVAL,
496                       p_chr_id        => l_chrv_id);
497 
498     IF (x_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
499       RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
500     ELSIF (x_return_Status = OKL_API.G_RET_STS_ERROR)  THEN
501       RAISE OKL_API.G_EXCEPTION_ERROR;
502     END IF;
503 
504      -- Raise Event
505      wf_event.RAISE(p_event_name => l_event_name,
506                     p_event_key  => l_key,
507                     p_parameters => l_parameter_list);
508      l_parameter_list.DELETE;
509 
510     OKL_API.END_ACTIVITY(x_msg_count   => x_msg_count,
511                           x_msg_data   => x_msg_data);
512   EXCEPTION
513     WHEN OKL_API.G_EXCEPTION_ERROR THEN
514       x_return_status := OKL_API.G_RET_STS_ERROR;
515       IF c_fetch_k_number%ISOPEN THEN
516         CLOSE c_fetch_k_number;
517       END IF;
518       IF c_get_app_id_csr%ISOPEN THEN
519         CLOSE c_get_app_id_csr;
520       END IF;
521       IF c_get_trx_type_csr%ISOPEN THEN
522         CLOSE c_get_trx_type_csr;
523       END IF;
524       IF l_wf_item_key_csr%ISOPEN THEN
525         CLOSE l_wf_item_key_csr;
526       END IF;
527       x_return_status := OKL_API.HANDLE_EXCEPTIONS(
528                         p_api_name  => l_api_name,
529                         p_pkg_name  => G_PKG_NAME,
530                         p_exc_name  => 'OKL_API.G_RET_STS_ERROR',
531                         x_msg_count => x_msg_count,
532                         x_msg_data  => x_msg_data,
533                         p_api_type  => G_API_TYPE);
534     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
535       x_return_status := OKL_API.G_RET_STS_UNEXP_ERROR;
536       IF c_fetch_k_number%ISOPEN THEN
537         CLOSE c_fetch_k_number;
538       END IF;
539       IF c_get_app_id_csr%ISOPEN THEN
540         CLOSE c_get_app_id_csr;
541       END IF;
542       IF c_get_trx_type_csr%ISOPEN THEN
543         CLOSE c_get_trx_type_csr;
544       END IF;
545       IF l_wf_item_key_csr%ISOPEN THEN
546         CLOSE l_wf_item_key_csr;
547       END IF;
548       x_return_status := OKL_API.HANDLE_EXCEPTIONS(
549                         p_api_name  => l_api_name,
550                         p_pkg_name  => G_PKG_NAME,
551                         p_exc_name  => 'OKL_API.G_RET_STS_UNEXP_ERROR',
552                         x_msg_count => x_msg_count,
553                         x_msg_data  => x_msg_data,
554                         p_api_type  => G_API_TYPE);
555     WHEN OTHERS THEN
556       IF c_fetch_k_number%ISOPEN THEN
557         CLOSE c_fetch_k_number;
558       END IF;
559       IF c_get_app_id_csr%ISOPEN THEN
560         CLOSE c_get_app_id_csr;
561       END IF;
562       IF c_get_trx_type_csr%ISOPEN THEN
563         CLOSE c_get_trx_type_csr;
564       END IF;
565       IF l_wf_item_key_csr%ISOPEN THEN
566         CLOSE l_wf_item_key_csr;
567       END IF;
568       -- store SQL error message on message stack
569         x_return_status := OKL_API.HANDLE_EXCEPTIONS(
570                         p_api_name  => l_api_name,
571                         p_pkg_name  => G_PKG_NAME,
572                         p_exc_name  => 'OTHERS',
573                         x_msg_count => x_msg_count,
574                         x_msg_data  => x_msg_data,
575                         p_api_type  => G_API_TYPE);
576   END raise_approval_event;
577 
578  ---------------------------------------------------------------------------
579  -- FUNCTION compile_message
580  ---------------------------------------------------------------------------
581   -- Start of comments
582   --
583   -- Function Name  : compile_message
584   -- Description     :
585   -- Business Rules  : Creates the message body of the notifications
586   -- Parameters      : p_contract_id
587   -- Version         : 1.0
588   -- End of comments
589   ---------------------------------------------------------------------------
590   FUNCTION compile_message(p_contract_id IN NUMBER)
591     RETURN VARCHAR2
592   IS
593 
594     CURSOR l_okl_crtline_csr(p_contract_id OKC_K_HEADERS_V.ID%TYPE)
595     IS
596       SELECT ID,
597              CONTRACT_NUMBER,
598              DESCRIPTION,
599              STS_MEANING,
600              CURRENCY_CODE,
601              CUSTOMER_NAME,
602              CUST_ACCT_NUMBER,
603              TOTAL_LIMIT,
604              START_DATE,
605              END_DATE
606       FROM okl_creditlines_uv
607       WHERE id =  p_contract_id;
608 
609     CURSOR l_okl_crtline_contents_csr(p_contract_id OKC_K_HEADERS_V.ID%TYPE)
610     IS
611       SELECT KHR_ID,
612              TODO_ITEM_CODE,
613              TODO_ITEM_MEANING,
614              MANDATORY_FLAG_MEANING,
615              MANDATORY_FLAG,
616              CHECK_OFF_RESULTS,
617              FUNC_VAL_RSTS_MEANING,
618              FUNCTION_ID,
619              FUNCTION_NAME,
620              CHECKIST_RESULTS
621       FROM okl_credit_checklists_uv
622       WHERE khr_id =  p_contract_id;
623 
624     l_msg_count      NUMBER;
625     l_msg_data       VARCHAR2(2000);
626     l_api_version    NUMBER ;
627     l_init_msg_list  VARCHAR2(3) ;
628     l_return_status  VARCHAR2(3) ;
629     l_true_tax       VARCHAR2(200);
630     l_cap_amt        NUMBER;
631     l_res_value      NUMBER;
632     l_message        VARCHAR2(12000);
633     l_flag           VARCHAR2(10);
634 
635     -- Bug 11896595  by RGOOTY : START
636     CURSOR c_get_org_id (p_contract_id IN OKC_K_HEADERS_ALL_B.ID%TYPE)
637     IS
638      select chr.org_id
639        from okc_k_headers_all_b chr
640       where chr.id = p_contract_id;
641 
642     l_org_id              NUMBER;
643     l_orig_access_mode    VARCHAR2(3);
644     l_orig_org_id         NUMBER;
645     -- Bug 11896595  by RGOOTY : End
646 
647   BEGIN
648 
649 --    l_flag          := 'Passed'; -- cklee 06/01/2005
650     l_api_version   := 1;
651     l_init_msg_list := OKC_API.G_TRUE;
652     l_return_status := OKL_API.G_RET_STS_SUCCESS;
653 
654     --For bug 11896595  by RGOOTY : START
655     l_orig_org_id      :=  MO_GLOBAL.GET_CURRENT_ORG_ID;
656     l_orig_access_mode :=  MO_GLOBAL.GET_ACCESS_MODE;
657     -- For Bug 12547729: RGOOTY: Start
658     OPEN c_get_org_id(p_contract_id);
659     FETCH c_get_org_id INTO l_org_id;
660     CLOSE c_get_org_id;
661 
662     IF l_org_id IS NOT NULL
663     THEN
664       MO_GLOBAL.SET_POLICY_CONTEXT('S',l_org_id);
665     END IF;
666     --For bug 11896595  by RGOOTY : END
667     -- For Bug 12547729: RGOOTY: End
668 
669     FOR l_okl_crtline_rec IN l_okl_crtline_csr(p_contract_id)
670     LOOP
671       -- Start
672       l_message := l_message || '<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">';
673 
674        -- Empty Row
675       l_message := l_message || '<tr><td colspan=6>' || G_CHAR_AMPERSAND || 'nbsp;</td></tr>';
676 
677       l_message := l_message || '<tr><td colspan=6>'
678                              || '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
679 
680       -- Credit Line, Currency
681       l_message := l_message || '<tr><td width="18%" align="right">'
682                              || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
683      	                                                p_attribute_code => 'OKL_CREDIT')
684                              || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
685                              || '<td width="36%"><b>'
686                      							 || l_okl_crtline_rec.contract_number
687                       						 || '</b></td>'
688                      							 || '<td width="13%" align="right">'
689                              || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
690      	                                                p_attribute_code => 'OKL_CURRENCY')
691                      							 || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
692                       						 || '<td width="33%"><b>'
693                      							 || l_okl_crtline_rec.currency_code
694                      							 || '</b></td>'
695                      							 || '</tr>';
696 
697 		-- Description, Effective From
698       l_message := l_message || '<tr><td width="18%" align="right">'
699                              || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
700      	                                                p_attribute_code => 'OKL_DESCRIPTION')
701                              || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
702                              || '<td width="36%"><b>'
703                      							 || l_okl_crtline_rec.description
704                      							 || '</b></td>'
705                      							 || '<td width="13%" align="right">'
706 	                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
707      	                                                p_attribute_code => 'OKL_EFFECTIVE_FROM')
708                          			 || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
709                      							 || '<td width="33%"><b>'
710                      							 || to_date(l_okl_crtline_rec.start_date,'dd-mm-yyyy')
711                         				 || '</b></td>'
712                      							 || '</tr>';
713 
714 		-- Customer, Effective To
715       l_message := l_message || '<tr><td width="18%" align="right">'
716                              || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
717      	                                                p_attribute_code => 'OKL_CUSTOMER')
718                              || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
719                              || '<td width="36%"><b>'
720                        					 || l_okl_crtline_rec.customer_name
721                      							 || '</b></td>'
722                      							 || '<td width="13%" align="right">'
723 	                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
724      	                                                p_attribute_code => 'OKL_EFFECTIVE_TO')
725                      							 || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
726                      							 || '<td width="33%"><b>'
727                      							 || to_date(l_okl_crtline_rec.end_date,'dd-mm-yyyy')
728                      							 || '</b></td>'
729                      							 || '</tr>';
730 
731 		-- Customer Account, Total Credit Limit
732       l_message := l_message || '<tr><td width="18%" align="right">'
733                              || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
734      	                                                p_attribute_code => 'OKL_KDTLS_CUSTOMER_ACCOUNT_N')
735                              || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
736                              || '<td width="36%"><b>'
737                      							 || l_okl_crtline_rec.cust_acct_number
738                       						 || '</b></td>'
739                      							 || '<td width="13%" align="right">'
740 	                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
741        	                                                p_attribute_code => 'OKL_TOTAL_CREDIT_LIMIT')
742 		                      				 || '</td><td width="1%">' || G_CHAR_AMPERSAND || 'nbsp;</td>'
743                      							 || '<td width="33%"><b>'
744                      							 || TO_CHAR(l_okl_crtline_rec.total_limit,'999,999,999,999,999,999.00')
745                      							 || '</b></td>'
746                      							 || '</tr>';
747 
748 	  -- Empty Row
749       l_message := l_message || '<tr><td colspan=6>' || G_CHAR_AMPERSAND || 'nbsp;</td></tr>';
750 
751       FOR each_row IN l_okl_crtline_contents_csr(p_contract_id) LOOP
752          l_flag := 'Passed'; -- cklee 06/01/2005
753          IF(each_row.mandatory_flag = 'Y' and  each_row.CHECKIST_RESULTS <> 'Passed') THEN --cklee 06/01/2005
754            l_flag := 'Failed';
755            EXIT;
756          END IF;
757       END LOOP;
758 
759       IF l_flag = 'Passed' THEN
760         l_flag := Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
761                                                         p_attribute_code => 'OKL_PASSED');
762       ELSIF l_flag = 'Failed' THEN
763         l_flag := Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
764                                                         p_attribute_code => 'OKL_FAILED');
765       END IF;
766 
767 	  -- Checklist Validation Result
768       l_message := l_message || '<tr><td width="18%" align="right">'
769                              || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CREDIT',
770      	                                                p_attribute_code => 'OKL_CHKLIST_VAL_RESULT')
771                              || '</td><td width="1%">=</td>'
772                              || '<td width="36%" colspan="4"><b>'
773                              || l_flag
774 							 || '</b></td>';
775 	  -- Empty Row
776       l_message := l_message || '<tr><td colspan=6>' || G_CHAR_AMPERSAND || 'nbsp;</td></tr>';
777 
778    -- End
779  	  l_message := l_message || '
780                   </TABLE>';
781 
782     END LOOP; -- l_okl_crtline_rec
783 
784     l_message := l_message || '<table class="x1h" cellpadding="1" cellspacing="0" border="1" width="100%">';
785 
786     -- Headers for the creditline details table.
787     -- Checklist Item
788     l_message := l_message || '<tr> <th scope="col" class="x1r"> <span title="'
789                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
790      	                                                p_attribute_code => 'OKL_ITEM')
791                            || '" class="x24">'
792                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
793      	                                                p_attribute_code => 'OKL_ITEM')
794                            || '</span></th>';
795 
796     -- Description
797     l_message := l_message || '<th scope="col" class="x1r"> <span title="'
798                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
799      	                                                p_attribute_code => 'OKL_DESCRIPTION')
800                            || '" class="x24">'
801                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
802      	                                                p_attribute_code => 'OKL_DESCRIPTION')
803                            || '</span></th>';
804 
805     -- Function
806     l_message := l_message || '<th scope="col" class="x1r"> <span title="'
807                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
808      	                                                p_attribute_code => 'OKL_FUNCTION')
809                            || '" class="x24">'
810                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
811      	                                                p_attribute_code => 'OKL_FUNCTION')
812                            || '</span></th>';
813 
814     -- Mandatory
815     l_message := l_message || '<th scope="col" class="x1r"> <span title="'
816                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
817      	                                                p_attribute_code => 'OKL_MANDATORY')
818                            || '" class="x24">'
819                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
820      	                                                p_attribute_code => 'OKL_MANDATORY')
821                            || '</span></th>';
822 
823     -- Results
824     l_message := l_message || '<th scope="col" class="x1r"> <span title="'
825                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
826      	                                                p_attribute_code => 'OKL_RESULTS')
827                            || '" class="x24">'
828                            || Okl_Accounting_Util.Get_Message_Token(p_region_code    => 'OKL_LA_CHECKLIST',
829      	                                                p_attribute_code => 'OKL_RESULTS')
830                            || '</span></th></tr>';
831 
832 
833     FOR l_okl_crtline_contents_rec IN l_okl_crtline_contents_csr(p_contract_id)
834     LOOP
835       IF (l_okl_crtline_contents_rec.todo_item_code is not null)THEN
836          l_message := l_message || '<tr><td class="x1l x4x">'
837                                 || l_okl_crtline_contents_rec.todo_item_code
838                                 || '</td>';
839       ELSE
840          l_message := l_message || '<tr><td class="x1l x4x"><br></td>';
841       END IF;
842       IF(l_okl_crtline_contents_rec.todo_item_meaning is not null)THEN
843          l_message := l_message || '<td class="x1l x4x">'
844                                 || l_okl_crtline_contents_rec.todo_item_meaning
845                                 || '</td>';
846       ELSE
847          l_message := l_message || '<td class="x1l x4x"><br></td>';
848       END IF;
849       IF(l_okl_crtline_contents_rec.function_name is not null) THEN
850       l_message := l_message || '<td class="x1l x4x">'
851                              || l_okl_crtline_contents_rec.function_name
852                              || '</td>';
853       ELSE
854          l_message := l_message || '<td class="x1l x4x"><br></td>';
855       END IF;
856       IF( l_okl_crtline_contents_rec.mandatory_flag_meaning is not null) THEN
857       l_message := l_message || '<td class="x1l x4x">'
858                              || l_okl_crtline_contents_rec.mandatory_flag_meaning
859                              || '</td>';
860       ELSE
861          l_message := l_message || '<td class="x1l x4x"><br></td>';
862       END IF;
863       IF(l_okl_crtline_contents_rec.function_id is not null) THEN
864          l_message := l_message || '<td class="x1l x4x">'
865                                 || l_okl_crtline_contents_rec.func_val_rsts_meaning
866                                 || '</td></tr>';
867       ELSE
868          l_message := l_message || '<td class="x1l x4x">'
869                                 || l_okl_crtline_contents_rec.check_off_results
870                                 || '</td></tr>';
871       END IF;
872     END LOOP;
873     l_message := l_message || '</table>';
874 
875     --For bug 11896595  by RGOOTY
876     MO_GLOBAL.SET_POLICY_CONTEXT(l_orig_access_mode,l_orig_org_id);
877     RETURN l_message;
878 
879   EXCEPTION
880    WHEN OTHERS THEN
881      RETURN NULL;
882   END compile_message;
883 
884   /*
885   -- This API is for Lease Contract Approval via WF
886   */
887  ---------------------------------------------------------------------------
888  -- PROCEDURE get_credit_line_approver
889  ---------------------------------------------------------------------------
890   -- Start of comments
891   --
892   -- Procedure Name  : get_credit_line_approver
893   -- Description     :
894   -- Business Rules  : returns whether the approver is found or not.
895   -- Parameters      : itemtype, itemkey, actid, funcmode,resultout.
896   -- Version         : 1.0
897   -- End of comments
898   ---------------------------------------------------------------------------
899   PROCEDURE get_credit_line_approver(itemtype   IN VARCHAR2,
900                                      itemkey    IN VARCHAR2,
901                                      actid      IN NUMBER,
902                                      funcmode   IN VARCHAR2,
903            		                        resultout  OUT  NOCOPY VARCHAR2)
904   IS
905     CURSOR l_fnd_users_csr(p_user_id NUMBER)
906     IS
907     SELECT USER_NAME
908     FROM   FND_USER
909     WHERE  user_id = p_user_id;
910 
911     l_api_name         CONSTANT VARCHAR2(200) := 'get_credit_line_approver';
912    	l_user_id          VARCHAR2(200);
913     l_contract_number  OKC_K_HEADERS_V.contract_number%TYPE;
914 	   l_return_status    VARCHAR2(1);
915 
916   BEGIN
917      l_return_status := OKL_API.G_RET_STS_SUCCESS;
918 
919 	 -- "RUN"
920      IF (funcmode = 'RUN') THEN
921 		 --l_user_id := fnd_profile.value('OKL_LEASE_CONTRACT_APPROVER');
922          l_user_id :=   wf_engine.GetItemAttrText (itemtype  => itemtype,
923                                                     itemkey   => itemkey,
924                                                     aname     => G_WF_ITM_REQUESTER_ID);
925 
926          l_contract_number :=   wf_engine.GetItemAttrText (itemtype  => itemtype,
927                                                            itemkey   => itemkey,
928                                                            aname     => G_WF_ITM_CONTRACT_NUMBER);
929 
930          resultout := 'COMPLETE:NOT_FOUND'; -- default
931 		 IF l_user_id IS NOT NULL THEN
932 			 FOR l_fnd_users_rec IN l_fnd_users_csr(l_user_id)
933 			 LOOP
934 			     wf_engine.SetItemAttrText (itemtype  => itemtype,
935 			                                itemkey   => itemkey,
936 			                                aname     => G_WF_ITM_APPROVER,
937    				                            avalue    => l_fnd_users_rec.user_name);
938 
939 
940         wf_engine.SetItemAttrText (itemtype   => itemtype,
941 			                            	   itemkey    => itemkey,
942                              			   aname   			=> G_WF_ITM_MESSAGE_SUBJECT,
943                                    avalue     => get_message('OKL_CRTLINE_APPROVAL_SUMMARY',l_contract_number));
944 
945   	     resultout := 'COMPLETE:FOUND';
946 			 END LOOP;
947 		 END IF; -- l_user_id
948 
949     -- CANCEL mode
950 	ELSIF (funcmode = 'CANCEL') THEN
951         resultout := 'COMPLETE:';
952         RETURN;
953     -- TIMEOUT mode
954     ELSIF (funcmode = 'TIMEOUT') THEN
955         resultout := 'COMPLETE:';
956         RETURN;
957     END IF; -- funcmode
958   EXCEPTION
959   WHEN OTHERS THEN
960       wf_core.context(G_PKG_NAME,
961                       l_api_name,
962                       itemtype,
963                       itemkey,
964                       TO_CHAR(actid),
965                       funcmode);
966       RAISE;
967 
968   END get_credit_line_approver;
969 
970  --------------------------------------------------------------------------------------------------
971  --------------------------------- Set Approval Status --------------------------------------------
972  --------------------------------------------------------------------------------------------------
973  ---------------------------------------------------------------------------
974  -- PROCEDURE Set_Parent_Attributes
975  ---------------------------------------------------------------------------
976   -- Start of comments
977   --
978   -- Procedure Name  : Set_Parent_Attributes
979   -- Description     :
980   -- Business Rules  : sets the parent attributes.
981   -- Parameters      : itemtype, itemkey, actid, funcmode,resultout.
982   -- Version         : 1.0
983   -- End of comments
984   ---------------------------------------------------------------------------
985   PROCEDURE Set_Parent_Attributes(itemtype  IN  VARCHAR2,
986                                   itemkey   IN  VARCHAR2,
987                                   actid     IN  NUMBER,
988                                   funcmode  IN  VARCHAR2,
989                                   resultout OUT NOCOPY VARCHAR2) IS
990 
991     l_approved_yn     VARCHAR2(30);
992     l_parent_key      VARCHAR2(240);
993     l_parent_type     VARCHAR2(240);
994     l_result          VARCHAR2(30);
995    	l_api_name        CONSTANT VARCHAR2(30) := 'Set_Parent_Attributes';
996 	   l_contract_number okc_k_headers_v.contract_number%TYPE;
997 
998   BEGIN
999     SAVEPOINT set_atts;
1000     IF (funcmode = 'RUN') THEN
1001       -- Get current approval status
1002       l_result := wf_engine.GetItemAttrText (itemtype  => itemtype,
1003                                              itemkey   => itemkey,
1004                                              aname     => G_WF_ITM_RESULT);
1005 
1006        l_parent_key :=  wf_engine.GetItemAttrText (itemtype  => itemtype,
1007                                 			                itemkey   => itemkey,
1008                                				                aname     => G_WF_ITM_PARENT_ITEM_KEY);
1009 
1010        l_parent_type :=  wf_engine.GetItemAttrText (itemtype   => itemtype,
1011                                  			                itemkey    => itemkey,
1012                                 				                aname      => G_WF_ITM_PARENT_ITEM_TYPE);
1013 
1014        l_contract_number :=   wf_engine.GetItemAttrText (itemtype  => itemtype,
1015                                                          itemkey   => itemkey,
1016                                                          aname     => G_WF_ITM_CONTRACT_NUMBER);
1017 
1018       IF l_result = G_WF_ITM_RESULT_APPROVED THEN
1019         l_approved_yn := G_WF_ITM_APPROVED_YN_YES;
1020         wf_engine.SetItemAttrText (itemtype   => itemtype,
1021                             				   itemkey    => itemkey,
1022                             				   aname   			=> G_WF_ITM_MESSAGE_SUBJECT,
1023                                    avalue     => get_message('OKL_LLA_REQUEST_APPROVED_SUB',l_contract_number));
1024       ELSE
1025         l_approved_yn := G_WF_ITM_APPROVED_YN_NO;
1026         wf_engine.SetItemAttrText (itemtype   => itemtype,
1027                             				   itemkey    => itemkey,
1028                             				   aname   			=> G_WF_ITM_MESSAGE_SUBJECT,
1029                                    avalue     => get_message('OKL_LLA_REQUEST_REJECTED_SUB',l_contract_number));
1030       END IF;
1031 
1032       wf_engine.SetItemAttrText(itemtype  => l_parent_type,
1033                                 itemkey   => l_parent_key,
1034                             				aname     => G_WF_ITM_APPROVED_YN,
1035                	                avalue    => l_approved_yn);
1036        resultout := 'COMPLETE:';
1037       RETURN;
1038     END IF;
1039     -- CANCEL mode
1040     IF (funcmode = 'CANCEL') THEN
1041       resultout := 'COMPLETE:';
1042       RETURN;
1043     END IF;
1044     -- TIMEOUT mode
1045     IF (funcmode = 'TIMEOUT') THEN
1046       resultout := 'COMPLETE:';
1047       RETURN;
1048     END IF;
1049   EXCEPTION
1050     WHEN OTHERS THEN
1051       wf_core.context(G_PKG_NAME,
1052                       	l_api_name,
1053                        itemtype,
1054                        itemkey,
1055                        TO_CHAR(actid),
1056                        funcmode);
1057         RAISE;
1058   END Set_Parent_Attributes;
1059 --------------------------------------------------------------------------------------------------
1060 ----------------------------------Main Approval Process ------------------------------------------
1061 --------------------------------------------------------------------------------------------------
1062  ---------------------------------------------------------------------------
1063  -- PROCEDURE update_approval_status
1064  ---------------------------------------------------------------------------
1065   -- Start of comments
1066   --
1067   -- Procedure Name  : update_approval_status
1068   -- Description     :
1069   -- Business Rules  : Updates the credit line status from pending approval
1070   --                   to approved or declined.
1071   -- Parameters      : itemtype, itemkey, actid, funcmode,resultout.
1072   -- Version         : 1.0
1073   -- End of comments
1074   ---------------------------------------------------------------------------
1075   PROCEDURE update_approval_status(itemtype  IN  VARCHAR2,
1076                                    itemkey   IN  VARCHAR2,
1077                                    actid     IN  NUMBER,
1078                                    funcmode  IN  VARCHAR2,
1079                                    resultout OUT NOCOPY VARCHAR2)
1080   IS
1081     CURSOR l_okl_trx_contracts_csr(p_trx_number IN VARCHAR2)
1082     IS
1083    	SELECT id
1084     FROM   okl_trx_contracts
1085    	WHERE  trx_number = p_trx_number
1086     --rkuttiya added for 12.1.1. Multi GAAP Project
1087         AND  representation_type = 'PRIMARY';
1088     --
1089 
1090     l_return_status	       VARCHAR2(3) ;
1091     l_api_version          NUMBER	;
1092     l_msg_count		          NUMBER;
1093     l_init_msg_list        VARCHAR2(10);
1094     l_msg_data		           VARCHAR2(2000);
1095 	   l_api_name             CONSTANT VARCHAR2(30) := 'update_approval_status';
1096     l_chrv_id              OKC_K_HEADERS_V.ID%TYPE;
1097     l_approved_yn          VARCHAR2(30);
1098     l_trx_number           VARCHAR2(100);
1099     lv_approval_status_ame VARCHAR2(10);
1100     l_trxH_in_rec          Okl_Trx_Contracts_Pvt.tcnv_rec_type;
1101     l_trxH_out_rec         Okl_Trx_Contracts_Pvt.tcnv_rec_type;
1102 
1103   BEGIN
1104 
1105     l_return_status := OKL_API.G_RET_STS_SUCCESS;
1106     l_api_version := 1.0;
1107     l_init_msg_list  := OKL_API.G_FALSE;
1108 
1109     -- We getting the contract_Id from WF
1110     l_chrv_id := wf_engine.GetItemAttrText(itemtype => itemtype,
1111                                            itemkey  => itemkey,
1112                                            aname    => G_WF_ITM_CONTRACT_ID);
1113     --Run Mode
1114     IF funcmode = 'RUN' THEN
1115       l_approved_yn :=  wf_engine.GetItemAttrText (itemtype  => itemtype,
1116                                                     itemkey   => itemkey,
1117                                                     aname     => G_WF_ITM_APPROVED_YN);
1118       lv_approval_status_ame := wf_engine.GetItemAttrText(itemtype  => itemtype,
1119                                                           itemkey   => itemkey,
1120                                                           aname     => 'APPROVED_YN');
1121 
1122       IF (l_approved_yn = G_WF_ITM_APPROVED_YN_YES OR lv_approval_status_ame = G_WF_ITM_APPROVED_YN_YES)THEN
1123          l_change_k_status(p_api_version   => l_api_version,
1124                            p_init_msg_list => l_init_msg_list,
1125                            x_return_status => l_return_status,
1126                            x_msg_count     => l_msg_count,
1127                            x_msg_data      => l_msg_data,
1128                            p_khr_status    => G_KHR_STS_APPROVED,
1129                            p_chr_id        => l_chrv_id);
1130          IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1131            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1132          ELSIF (l_return_Status = OKL_API.G_RET_STS_ERROR)  THEN
1133            RAISE OKL_API.G_EXCEPTION_ERROR;
1134          END IF;
1135 
1136       ELSE
1137          l_change_k_status(p_api_version   => l_api_version,
1138                            p_init_msg_list => l_init_msg_list,
1139                            x_return_status => l_return_status,
1140                            x_msg_count     => l_msg_count,
1141                            x_msg_data      => l_msg_data,
1142 --------------------------------------------------------------------------------
1143 -- cklee's Note: no rejected status available. we use DECLINED instead
1144 --------------------------------------------------------------------------------
1145                            p_khr_status    => G_KHR_STS_DECLINED,
1146                            p_chr_id        => l_chrv_id);
1147          IF (l_return_status = OKL_API.G_RET_STS_UNEXP_ERROR) THEN
1148            RAISE OKL_API.G_EXCEPTION_UNEXPECTED_ERROR;
1149          ELSIF (l_return_Status = OKL_API.G_RET_STS_ERROR)  THEN
1150            RAISE OKL_API.G_EXCEPTION_ERROR;
1151          END IF;
1152       END IF;
1153 
1154       -- trx's trx_number IS wf's trx_id
1155       l_trx_number :=  wf_engine.GetItemAttrText (itemtype  => itemtype,
1156                                                   itemkey   => itemkey,
1157                                                   aname     => G_WF_ITM_TRANSACTION_ID);
1158 
1159       FOR l_okl_trx_contracts_rec IN l_okl_trx_contracts_csr(l_trx_number)
1160       LOOP
1161             l_trxH_in_rec.id := l_okl_trx_contracts_rec.id;
1162       END LOOP;
1163 
1164       l_trxH_in_rec.tsu_code := G_TRX_TSU_CODE_PROCESSED;
1165 
1166       Okl_Trx_Contracts_Pub.update_trx_contracts(
1167            p_api_version      => l_api_version
1168           ,p_init_msg_list    => l_init_msg_list
1169           ,x_return_status    => l_return_status
1170           ,x_msg_count        => l_msg_count
1171           ,x_msg_data         => l_msg_data
1172           ,p_tcnv_rec         => l_trxH_in_rec
1173           ,x_tcnv_rec         => l_trxH_out_rec);
1174 
1175       IF (l_return_status = Okl_Api.G_RET_STS_UNEXP_ERROR) THEN
1176           RAISE Okl_Api.G_EXCEPTION_UNEXPECTED_ERROR;
1177       ELSIF (l_return_Status = Okl_Api.G_RET_STS_ERROR) THEN
1178           RAISE Okl_Api.G_EXCEPTION_ERROR;
1179       END IF;
1180 
1181       resultout := 'COMPLETE:';
1182       RETURN;
1183    END IF;
1184     --Transfer Mode
1185     IF funcmode = 'TRANSFER' THEN
1186       resultout := wf_engine.eng_null;
1187       RETURN;
1188     END IF;
1189     -- CANCEL mode
1190     IF (funcmode = 'CANCEL') THEN
1191       resultout := 'COMPLETE:';
1192       RETURN;
1193     END IF;
1194     -- TIMEOUT mode
1195     IF (funcmode = 'TIMEOUT') THEN
1196       resultout := 'COMPLETE:';
1197       RETURN;
1198     END IF;
1199   EXCEPTION
1200     WHEN OKL_API.G_EXCEPTION_ERROR THEN
1201       wf_core.context(G_PKG_NAME,
1202                       l_api_name,
1203                        itemtype,
1204                        itemkey,
1205                        TO_CHAR(actid),
1206                        funcmode);
1207 	  RAISE;
1208     WHEN OKL_API.G_EXCEPTION_UNEXPECTED_ERROR THEN
1209       wf_core.context(G_PKG_NAME,
1210                       l_api_name,
1211                        itemtype,
1212                        itemkey,
1213                        TO_CHAR(actid),
1214                        funcmode);
1215 	  RAISE;
1216     WHEN OTHERS THEN
1217       wf_core.context(G_PKG_NAME,
1218                       l_api_name,
1219                        itemtype,
1220                        itemkey,
1221                        TO_CHAR(actid),
1222                        funcmode);
1223 	  RAISE;
1224   END update_approval_status;
1225 
1226  ---------------------------------------------------------------------------
1227  -- PROCEDURE pop_approval_doc
1228  ---------------------------------------------------------------------------
1229   -- Start of comments
1230   --
1231   -- Procedure Name  : pop_approval_doc
1232   -- Description     :
1233   -- Business Rules  : This procedure is invoked dynamically by Workflow API's
1234   --                   in order to populate the message body item attribute
1235   --                   during notification submission.
1236   -- Parameters      : document_id, display_type, document, document_type.
1237   -- Version         : 1.0
1238   -- End of comments
1239   ---------------------------------------------------------------------------
1240   PROCEDURE pop_approval_doc (document_id   IN VARCHAR2,
1241                               display_type  IN VARCHAR2,
1242                               document      IN OUT nocopy VARCHAR2,
1243                               document_type IN OUT nocopy VARCHAR2) IS
1244 
1245     l_message      VARCHAR2(32000);
1246    	l_contract_id  NUMBER;
1247   BEGIN
1248 
1249         l_contract_id := wf_engine.GetItemAttrText (itemtype  => G_ITEM_TYPE_WF,
1250                                 				                itemkey   => document_id,
1251                                  			                aname     => G_WF_ITM_CONTRACT_ID);
1252         document := compile_message(l_contract_id);
1253         document_type := display_type;
1254 
1255         RETURN;
1256 
1257   EXCEPTION
1258      WHEN OTHERS THEN NULL;
1259 
1260   END pop_approval_doc;
1261 
1262  ---------------------------------------------------------------------------
1263  -- PROCEDURE check_approval_process
1264  ---------------------------------------------------------------------------
1265   -- Start of comments
1266   --
1267   -- Procedure Name  : check_approval_process
1268   -- Description     :
1269   -- Business Rules  : Checks whether the profile option is set to WF or AME
1270   --                   and sets the parameter accordingly.
1271   -- Parameters      : itemtype, itemkey, actid, funcmode,resultout.
1272   -- Version         : 1.0
1273   -- End of comments
1274   ---------------------------------------------------------------------------
1275   PROCEDURE check_approval_process( itemtype	 IN  VARCHAR2,
1276             				                    itemkey  	IN  VARCHAR2,
1277 			                            	    actid		   IN  NUMBER,
1278 			                                 funcmode	 IN  VARCHAR2,
1279             				                    resultout OUT NOCOPY VARCHAR2 )
1280     IS
1281       l_approval_option VARCHAR2(5);
1282       l_contract_id     VARCHAR2(240);
1283       l_contract_number okc_k_headers_b.contract_number%TYPE;
1284       l_api_name        CONSTANT VARCHAR2(30) := 'check_approval_process';
1285 
1286     BEGIN
1287 
1288       IF (funcmode = 'RUN') THEN
1289        		l_approval_option := fnd_profile.value('OKL_CREDIT_LINE_APPROVAL_PROCESS');
1290        		IF l_approval_option = G_LEASE_CONTRACT_APPROVAL_AME THEN
1291 
1292            l_contract_id  := wf_engine.GetItemAttrText(itemtype  => itemtype,
1293                                                        itemkey   => itemkey,
1294                                                        aname     => G_WF_ITM_CONTRACT_ID);
1295 
1296            l_contract_number := wf_engine.GetItemAttrText(itemtype  => itemtype,
1297                                                           itemkey   => itemkey,
1298                                                           aname     => G_WF_ITM_CONTRACT_NUMBER);
1299 
1300 	          wf_engine.SetItemAttrText (itemtype  => itemtype,
1301                  					                itemkey   => itemkey,
1302 					                                 aname     => G_WF_ITM_MESSAGE_DESCRIPTION,
1303 	         	                           avalue    => compile_message(l_contract_id));
1304 
1305    	       wf_engine.SetItemAttrText (itemtype  => itemtype,
1306                  					                itemkey   => itemkey,
1307 					                                 aname     => G_WF_ITM_APP_REQUEST_SUB,
1308 	         	                           avalue    => get_message('OKL_LLA_REQUEST_APPROVAL_SUB',l_contract_number));
1309 
1310 	          wf_engine.SetItemAttrText (itemtype  => itemtype,
1311                  					                itemkey   => itemkey,
1312 					                                 aname     => G_WF_ITM_APP_REMINDER_SUB,
1313 	         	                           avalue    => get_message('OKL_LLA_REQ_APPR_SUB_REMINDER',l_contract_number));
1314 
1315 	          wf_engine.SetItemAttrText (itemtype  => itemtype,
1316                  					                itemkey   => itemkey,
1317 					                                 aname     => G_WF_ITM_APP_APPROVED_SUB,
1318 	         	                           avalue    => get_message('OKL_LLA_REQUEST_APPROVED_SUB',l_contract_number));
1319 
1320 	          wf_engine.SetItemAttrText (itemtype  => itemtype,
1321                  					                itemkey   => itemkey,
1322 					                                 aname     => G_WF_ITM_APP_REJECTED_SUB,
1323 	         	                           avalue    => get_message('OKL_LLA_REQUEST_REJECTED_SUB',l_contract_number));
1324 
1325 	          wf_engine.SetItemAttrText (itemtype  => itemtype,
1326                  					                itemkey   => itemkey,
1327 					                                 aname     => G_WF_ITM_APP_REMINDER_HEAD,
1328 	         	                           avalue    => get_message('OKL_LLA_REQ_APPROVAL_REMINDER',l_contract_number));
1329 
1330 	          wf_engine.SetItemAttrText (itemtype  => itemtype,
1331                  					                itemkey   => itemkey,
1332 					                                 aname     => G_WF_ITM_APP_APPROVED_HEAD,
1333 	         	                           avalue    => get_message('OKL_LLA_REQUEST_APPROVED_SUB',l_contract_number));
1334 
1335 	          wf_engine.SetItemAttrText (itemtype  => itemtype,
1336                  					                itemkey   => itemkey,
1337 					                                 aname     => G_WF_ITM_APP_REJECTED_HEAD,
1338 	         	                           avalue    => get_message('OKL_LLA_REQUEST_REJECTED_SUB',l_contract_number));
1339 
1340      		   resultout := 'COMPLETE:AME';
1341 	    	ELSIF l_approval_option = G_LEASE_CONTRACT_APPROVAL_WF THEN
1342 		        resultout := 'COMPLETE:WF';
1343 		    END IF;
1344 
1345        --resultout := 'COMPLETE:';
1346        RETURN;
1347 
1348      END IF;
1349       --
1350       -- CANCEL mode
1351       --
1352       IF (funcmode = 'CANCEL') THEN
1353         --
1354         resultout := 'COMPLETE:';
1355         RETURN;
1356         --
1357       END IF;
1358       --
1359       -- TIMEOUT mode
1360       --
1361       IF (funcmode = 'TIMEOUT') THEN
1362         --
1363         resultout := 'COMPLETE:';
1364         RETURN;
1365         --
1366       END IF;
1367 
1368     EXCEPTION
1369       WHEN OTHERS THEN
1370         wf_core.context(G_PKG_NAME , l_api_name, itemtype, itemkey, actid, funcmode);
1371         RAISE;
1372 
1373   END check_approval_process;
1374 
1375  ---------------------------------------------------------------------------
1376  -- PROCEDURE wf_approval_process
1377  ---------------------------------------------------------------------------
1378   -- Start of comments
1379   --
1380   -- Procedure Name  : wf_approval_process
1381   -- Description     :
1382   -- Business Rules  : This is raised when the profile option is WF.
1383   -- Parameters      : itemtype, itemkey, actid, funcmode,resultout.
1384   -- Version         : 1.0
1385   -- End of comments
1386   ---------------------------------------------------------------------------
1387   PROCEDURE wf_approval_process( itemtype	 IN  VARCHAR2,
1388 	         			                    itemkey  	IN  VARCHAR2,
1389 			                         	    actid		   IN  NUMBER,
1390 			                              funcmode	 IN  VARCHAR2,
1391 				                             resultout OUT NOCOPY VARCHAR2 )IS
1392 
1393 
1394     CURSOR l_wf_item_key_csr IS
1395     SELECT okl_wf_item_s.NEXTVAL item_key
1396     FROM  dual;
1397 
1398     l_key             VARCHAR2(240);
1399     l_process         VARCHAR2(30);
1400    	l_item_type       VARCHAR2(10) ;
1401     l_contract_id     VARCHAR2(240);
1402    	l_contract_number okc_k_headers_v.contract_number%TYPE;
1403     l_requester 	     VARCHAR2(240);
1404     l_requester_id    VARCHAR2(240);
1405    	l_api_name        CONSTANT VARCHAR2(30) := 'wf_Approval_Process';
1406 
1407     BEGIN
1408 
1409      l_process  := G_APPROVAL_PROCESS_WF;
1410      l_item_type := G_ITEM_TYPE_WF;
1411 
1412      OPEN l_wf_item_key_csr;
1413      FETCH l_wf_item_key_csr INTO l_key;
1414      CLOSE l_wf_item_key_csr;
1415 
1416       IF (funcmode = 'RUN') THEN
1417 
1418         wf_engine.CreateProcess(itemtype	 => l_item_type,
1419             				                itemkey   => l_key,
1420                                 process   => l_process);
1421 
1422         wf_engine.SetItemParent(itemtype	        => l_item_type,
1423             				                itemkey  	       => l_key,
1424                                 parent_itemtype  => itemtype,
1425                                 parent_itemkey   => itemkey,
1426                                 parent_context   => G_WF_ITM_MASTER);
1427 
1428         wf_engine.SetItemAttrText (itemtype  => l_item_type,
1429                				                itemkey   => l_key,
1430 				                               aname     => G_WF_ITM_PARENT_ITEM_KEY,
1431          	                         avalue    => itemkey);
1432 
1433         wf_engine.SetItemAttrText (itemtype  => l_item_type,
1434                				                itemkey   => l_key,
1435 				                               aname     => G_WF_ITM_PARENT_ITEM_TYPE,
1436          	                         avalue    => itemtype);
1437 
1438 		-- Re populate Item Attributes for the Detail Process
1439 
1440 	        l_contract_id :=   wf_engine.GetItemAttrText (itemtype  => itemtype,
1441 	                                                      itemkey   => itemkey,
1442 	                                                      aname     => G_WF_ITM_CONTRACT_ID);
1443 
1444 	        l_contract_number :=   wf_engine.GetItemAttrText (itemtype  => itemtype,
1445       	                                                    itemkey   => itemkey,
1446 	                                                          aname     => G_WF_ITM_CONTRACT_NUMBER);
1447 
1448 	        l_requester :=   wf_engine.GetItemAttrText (itemtype  => itemtype,
1449 	                                                    itemkey   => itemkey,
1450 	                                                    aname     => G_WF_ITM_REQUESTER);
1451 
1452 	        l_requester_id :=   wf_engine.GetItemAttrText (itemtype  => itemtype,
1453 	                                                       itemkey   => itemkey,
1454 	                                                       aname     => G_WF_ITM_REQUESTER_ID);
1455 
1456 	        wf_engine.SetItemAttrText (itemtype  => l_item_type,
1457                					                itemkey   => l_key,
1458 					                               aname     => G_WF_ITM_CONTRACT_ID,
1459 	         	                         avalue    => l_contract_id);
1460 
1461 	        wf_engine.SetItemAttrText (itemtype  => l_item_type,
1462                					                itemkey   => l_key,
1463 					                               aname     => G_WF_ITM_CONTRACT_NUMBER,
1464 	         	                         avalue    => l_contract_number);
1465 
1466 	        wf_engine.SetItemAttrText (itemtype  => l_item_type,
1467                					                itemkey   => l_key,
1468 					                               aname     => G_WF_ITM_REQUESTER,
1469 	         	                         avalue    => l_requester);
1470 
1471 	        wf_engine.SetItemAttrText (itemtype  => l_item_type,
1472 					                               itemkey   => l_key,
1473                					                aname     => G_WF_ITM_REQUESTER_ID,
1474 	         	                         avalue    => l_requester_id);
1475        -- Set the Message Document
1476          wf_engine.SetItemAttrDocument (itemtype    => l_item_type,
1477                                         itemkey     => l_key,
1478                                         aname   	  	=> G_WF_ITM_MESSAGE_DOC,
1479                                         documentid  => 'plsql:OKL_CREDIT_LINE_WF.pop_approval_doc/'||l_key);
1480 
1481         -- Now, Start the Detail Process
1482         wf_engine.StartProcess(itemtype	 => l_item_type,
1483             				               itemkey   => l_key);
1484 
1485         resultout := 'COMPLETE:';
1486         RETURN;
1487 
1488       END IF;
1489       --
1490       -- CANCEL mode
1491       --
1492       IF (funcmode = 'CANCEL') THEN
1493         --
1494         resultout := 'COMPLETE:';
1495         RETURN;
1496         --
1497       END IF;
1498       --
1499       -- TIMEOUT mode
1500       --
1501       IF (funcmode = 'TIMEOUT') THEN
1502         --
1503         resultout := 'COMPLETE:';
1504         RETURN;
1505         --
1506       END IF;
1507 
1508     EXCEPTION
1509       WHEN OTHERS THEN
1510 
1511         IF l_wf_item_key_csr%ISOPEN THEN
1512            CLOSE l_wf_item_key_csr;
1513         END IF;
1514 
1515         wf_core.context(G_PKG_NAME , l_api_name, itemtype, itemkey, actid, funcmode);
1516         RAISE;
1517 
1518   END wf_approval_process;
1519 
1520 
1521  ---------------------------------------------------------------------------
1522  -- PROCEDURE ame_approval_process
1523  ---------------------------------------------------------------------------
1524   -- Start of comments
1525   --
1526   -- Procedure Name  : ame_approval_process
1527   -- Description     :
1528   -- Business Rules  : This is raised when the profile option is AME.
1529   -- Parameters      : itemtype, itemkey, actid, funcmode,resultout.
1530   -- Version         : 1.0
1531   -- End of comments
1532   ---------------------------------------------------------------------------
1533   PROCEDURE ame_approval_process( itemtype	 IN  VARCHAR2,
1534 			          	                    itemkey  	IN  VARCHAR2,
1535 			                          	    actid		   IN  NUMBER,
1536 			                               funcmode	 IN  VARCHAR2,
1537 				                              resultout OUT NOCOPY VARCHAR2 )IS
1538 
1539     BEGIN
1540 
1541       IF (funcmode = 'RUN') THEN
1542          wf_engine.SetItemAttrDocument (itemtype     => itemtype,
1543                                         itemkey      => itemkey,
1544                                         aname   		   => G_WF_ITM_MESSAGE_DOC,
1545                                         documentid   => 'plsql:OKL_CREDIT_LINE_WF.pop_approval_doc/'||itemkey);
1546 
1547         resultout := 'COMPLETE:';
1548         RETURN;
1549       END IF;
1550       --
1551       -- CANCEL mode
1552       --
1553       IF (funcmode = 'CANCEL') THEN
1554         --
1555         resultout := 'COMPLETE:';
1556         RETURN;
1557         --
1558       END IF;
1559       --
1560       -- TIMEOUT mode
1561       --
1562       IF (funcmode = 'TIMEOUT') THEN
1563         --
1564         resultout := 'COMPLETE:';
1565         RETURN;
1566         --
1567       END IF;
1568 
1569     EXCEPTION
1570       WHEN OTHERS THEN
1571         wf_core.context('OKL_CREDIT_LINE_WF' , 'AME_APPROVAL_PROCESS', itemtype, itemkey, actid, funcmode);
1572         RAISE;
1573 
1574   END AME_APPROVAL_PROCESS;
1575 
1576 
1577 END OKL_CREDIT_LINE_WF;