DBA Data[Home] [Help]

PACKAGE BODY: APPS.OKC_CREATE_PO_FROM_K_PUB

Source


1 PACKAGE BODY OKC_CREATE_PO_FROM_K_PUB AS
2 /* $Header: OKCPKPOB.pls 120.0 2005/05/25 19:37:03 appldev noship $ */
3 	l_debug VARCHAR2(1) := NVL(FND_PROFILE.VALUE('AFLOG_ENABLED'),'N');
4 
5 
6 -- Local private procedures not declared in specification
7 
8 PROCEDURE submit_pdoi_errors_report(   p_api_version              IN  NUMBER
9 			               ,p_init_msg_list            IN  VARCHAR2
10 			               ,p_chr_id                   IN  okc_k_headers_b.ID%TYPE
11                            ,x_return_status            OUT NOCOPY VARCHAR2
12 			               ,x_msg_count                OUT NOCOPY NUMBER
13 			               ,x_msg_data                 OUT NOCOPY VARCHAR2);
14 
15 
16 PROCEDURE my_debug( p_msg    IN VARCHAR2,
17 				p_level  IN NUMBER DEFAULT 1  ,
18 				p_module IN VARCHAR2 DEFAULT 'OKC');
19 
20 
21 ----------------------------------------------------------------------------
22 --  Global Constants--------------------------------------------------------
23 ----------------------------------------------------------------------------
24 --  Standard API Constants
25 
26 G_UNEXPECTED_ERROR              CONSTANT VARCHAR2(200) := 'OKC_CONTRACTS_UNEXP_ERROR';
27 G_SQLCODE_TOKEN                 CONSTANT VARCHAR2(200) := 'SQLCODE';
28 G_SQLERRM_TOKEN                 CONSTANT VARCHAR2(200) := 'SQLERRM';
29 G_PKG_NAME                      CONSTANT VARCHAR2(200) := 'OKC_CREATE_PO_FROM_K_PUB';
30 G_APP_NAME                      CONSTANT VARCHAR2(3)   :=  OKC_API.G_APP_NAME;
31 G_APP_NAME1                     CONSTANT VARCHAR2(3)   := 'OKC';
32 
33 G_API_TYPE                      CONSTANT VARCHAR2(30)  := '_PROCESS';
34 G_SCOPE                         CONSTANT VARCHAR2(4)   := '_PVT';
35 
36 -- Related objects constants
37 
38 g_crj_rty_code                    CONSTANT VARCHAR2(20)  := 'CONTRACTCREATESPO';
39 g_crj_chr_jtot_object_code        CONSTANT VARCHAR2(20)  := 'OKX_PO_HEADERS';
40 
41 -- Holds the value of request_data from subsequent calls
42 l_request_data                  VARCHAR2(100);
43 -------------------------------------------------------------------------------
44 -- Procedure:       create_po_from_k
45 -- Version:         1.0
46 -- Purpose:         craete a PO from a contract.
47 --                  This API is used in a concurrent program definition
48 --                  This will be a wrapper for create_PO_from_k
49 --                  procedure described below
50 PROCEDURE create_po_from_k(ERRBUF                   OUT NOCOPY VARCHAR2
51                           ,RETCODE                  OUT NOCOPY NUMBER
52 			  ,p_contract_id            IN  okc_k_headers_b.ID%TYPE
53 			  ) IS
54 
55 l_api_version       CONSTANT NUMBER        := 1;
56 lx_return_status    VARCHAR2(1)    := OKC_API.G_RET_STS_SUCCESS;
57 lx_msg_count        NUMBER := 0;
58 lx_msg_data         VARCHAR2(2000);
59 lx_po_number         VARCHAR2(20);
60 l_k_number           VARCHAR2(120);
61 l_k_number_modifier  VARCHAR2(120);
62 lx_k_buyer_name      VARCHAR2(120);
63 l_notify             VARCHAR2(1);
64 
65   BEGIN
66 
67 -- This is the main program that gets called. However, for a single
68 -- submission of a request, this routine gets called multiple times.
69 -- The reason for this is that this request submits a child request
70 -- every time it is called. Refer to the documentation on concurrent
71 -- program APIs for child requests for an explanation of how the
72 -- works. Following is the sequence of events:
73 --
74 -- First time call
75 -- ---------------
76 -- Call routine to populate PO interface tables and also submit a
77 -- child request for PDOI to import the data from the interface
78 -- tables. It is identified as the initial call since there is no
79 -- value in the request_data. While exiting, a value is stored in
80 -- request_data (STAGE2)
81 --
82 -- Second call
83 -- -----------
84 -- After the child request completes, the concurrent manager calls
85 -- this procedure again with the same parameter. This time,
86 -- request_data will have the value (STAGE2) from the earlier run. If
87 -- this value is present, then branch off and submit the concurrent
88 -- program for PDOI interface error reporting. Also perform the
89 -- tieback (clean up related objects for any invalid entries)
90 
91 -- select contract number and contract number modifier
92 
93   SELECT contract_number, contract_number_modifier
94   INTO l_k_number, l_k_number_modifier
95   FROM okc_k_headers_b
96   WHERE id = p_contract_id;
97 
98   l_k_number_modifier := nvl(l_k_number_modifier, ' ');
99 
100 -- Examine the value of request_data. If this is null, then this is
101 -- the first time that this is being called
102 
103   l_request_data   := fnd_conc_global.request_data;
104 
105 
106   IF l_request_data IS NULL
107   THEN
108 
109   -- First time call; populate PO interface and trigger off the PDOI
110   -- concurrent program as a child-request
111 
112   -- Call the main routine (overloaded procedure with same name)
113   OKC_CREATE_PO_FROM_K_PUB.create_po_from_k(p_api_version   => l_api_version
114                                         ,p_init_msg_list => OKC_API.G_TRUE
115                                         ,x_return_status => lx_return_status
116                                         ,x_msg_count     => lx_msg_count
117                                         ,x_msg_data      => lx_msg_data
118                                         ,p_contract_id   => p_contract_id
119                                         );
120 
121 -- check return status
122   IF lx_return_status <> OKC_API.G_RET_STS_SUCCESS THEN
123         RETCODE := 2;
124         ERRBUF:=lx_msg_data;
125 	   RETURN;
126     ELSE
127         RETCODE:=0;
128     END IF;
129 
130 -- If request_data contains STAGE2, then this is the second time that
131 -- this program is being called. At the end of the first call, STAGE2
132 -- was placed in request_data
133 -- For stage2, submit the PDOI Interface errors report and also do
134 -- the tieback (cleanup of related objects)
135   ELSIF l_request_data = 'STAGE2'
136   THEN
137 
138         OKC_CREATE_PO_FROM_K_PVT.tieback_related_objs_from_po(
139                                                               p_api_version   => l_api_version
140                                                              ,p_init_msg_list => OKC_API.G_TRUE
141                                                              ,x_return_status => lx_return_status
142                                                              ,x_msg_count     => lx_msg_count
143                                                              ,x_msg_data      => lx_msg_data
144 							     ,x_po_number     => lx_po_number
145                                                              ,p_chr_id        => p_contract_id
146 							                                  );
147 
148 -- Tieback returns Error for any fatal errors and if the PO did not
149 -- get created by PDOI, returns a Warning if the header got created
150 -- but any lines did notget created; returns success otherwise
151 
152       IF lx_return_status = OKC_API.G_RET_STS_SUCCESS
153 	   THEN
154               retcode := 0;
155               errbuf  := NULL;
156 
157 		  IF l_notify = 'T'
158               THEN
159  			   OKC_CREATE_PO_FROM_K_PVT.notify_buyer(p_api_version               => l_api_version
160                                                           ,p_init_msg_list             => OKC_API.G_TRUE
161                                                           ,p_application_name          => G_APP_NAME1
162 		       	      			          ,p_message_subject           => 'OKC_K2PO_NOTIF_SUBJECT'
163 		        	    				          ,p_message_body 	         => 'OKC_K2PO_NOTIF_BODY'
164 		        	    				          ,p_message_body_token1       =>	'PONUMBER'
165 		        	    	                            ,p_message_body_token1_value => lx_po_number
166 		        	    				          ,p_message_body_token2 	   => 'KNUMBER'
167 		        	    				          ,p_message_body_token2_value => l_k_number
168                         				          ,p_message_body_token3 	   => 'KNUMMODIFIER'
169 		        	    				          ,p_message_body_token3_value => l_k_number_modifier
170 		        	    				          ,p_chr_id                    => p_contract_id
171 							                ,x_k_buyer_name              => lx_k_buyer_name
172                         	    	 			    ,x_return_status   	         => lx_return_status
173                         	    				    ,x_msg_count                 => lx_msg_count
174                         	                            ,x_msg_data                  => lx_msg_data
175                                                           );
176 
177 			-- check return status
178            	      IF (lx_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
179     				RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
180   		  	ELSIF (lx_return_status = OKC_API.G_RET_STS_ERROR) THEN
181     				RAISE OKC_API.G_EXCEPTION_ERROR;
182   		  	END IF;
183 
184 
185 		  END IF;
186 
187       ELSIF lx_return_status = OKC_API.G_RET_STS_WARNING
188 	   THEN
189 		      retcode := 1;
190 		      errbuf  := lx_msg_data;
191 
192               IF l_notify = 'T'
193               THEN
194  			   OKC_CREATE_PO_FROM_K_PVT.notify_buyer(p_api_version               => l_api_version
195                                                           ,p_init_msg_list             => OKC_API.G_TRUE
196                                                           ,p_application_name          => G_APP_NAME1
197 		        	            			    ,p_message_subject           => 'OKC_K2PO_NOTIF_SUBJECT'
198 		        	   				          ,p_message_body 	         => 'OKC_K2PO_NOTIF_BODY'
199 		        	   				          ,p_message_body_token1       =>	'PONUMBER'
200 		        	    			                ,p_message_body_token1_value => lx_po_number
201 		        	   				          ,p_message_body_token2 	     => 'KNUMBER'
202 		        	   				          ,p_message_body_token2_value => l_k_number
203                         			                ,p_message_body_token3 	     => 'KNUMMODIFIER'
204 		        					          ,p_message_body_token3_value => l_k_number_modifier
205 		        					          ,p_chr_id                    => p_contract_id
206 							                ,x_k_buyer_name              => lx_k_buyer_name
207                         	    				    ,x_return_status   	         => lx_return_status
208                         	    				    ,x_msg_count                 => lx_msg_count
209                         	                            ,x_msg_data                  => lx_msg_data
210                                                           );
211 
212 			-- check return status
213               	IF (lx_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
214     				RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
215   		  	ELSIF (lx_return_status = OKC_API.G_RET_STS_ERROR) THEN
216     				RAISE OKC_API.G_EXCEPTION_ERROR;
217   		  	END IF;
218 
219 
220 		  END IF;
221 
222 	   ELSE
223               retcode := 2;
224               errbuf  := lx_msg_data;
225 	   END IF;
226 
227 
228        IF retcode <> 0 then
229 
230                submit_pdoi_errors_report(
231                                          p_api_version   => l_api_version
232                                         ,p_init_msg_list => OKC_API.G_TRUE
233                                         ,x_return_status => lx_return_status
234                                         ,x_msg_count     => lx_msg_count
235                                         ,x_msg_data      => lx_msg_data
236                                         ,p_chr_id        => p_contract_id
237 							         	);
238 
239             -- check return status
240             IF (lx_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
241     			RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
242   		ELSIF (lx_return_status = OKC_API.G_RET_STS_ERROR) THEN
243     			RAISE OKC_API.G_EXCEPTION_ERROR;
244   		END IF;
245 
246       END IF;
247 
248 
249   ELSE
250 -- This should never occur as the only valid values are NULL, STAGE2
251 --  Abort with an error if this happens
252 
253 	   errbuf := 'Invalid request data: ' || l_request_data;
254 	   retcode := 2; -- Conc request completed with error
255 
256   END IF; -- end of if request_data is null
257 
258 END create_po_from_k;
259 
260 
261 PROCEDURE create_po_from_k(p_api_version             IN  NUMBER
262 			               ,p_init_msg_list            IN  VARCHAR2
263                            ,p_commit                   IN  VARCHAR2
264 			               ,p_contract_id              IN  okc_k_headers_b.ID%TYPE
265                            ,x_return_status            OUT NOCOPY VARCHAR2
266 			               ,x_msg_count                OUT NOCOPY NUMBER
267 			               ,x_msg_data                 OUT NOCOPY VARCHAR2)IS
268 
269 l_api_name          CONSTANT VARCHAR2(30) := 'CREATE_PO_FROM_K';
270 l_api_version       CONSTANT NUMBER        := 1;
271 lx_return_status    VARCHAR2(1)    := OKC_API.G_RET_STS_SUCCESS;
272 lx_msg_count        NUMBER := 0;
273 lx_msg_data         VARCHAR2(2000);
274   BEGIN
275    -- call START_ACTIVITY to create savepoint, check compatibility
276    -- and initialize message list
277   lx_return_status := OKC_API.START_ACTIVITY(
278                                         p_api_name      => l_api_name,
279                                         p_pkg_name      => g_pkg_name,
280                                         p_init_msg_list => p_init_msg_list,
281                                         l_api_version   => l_api_version,
282                                         p_api_version   => p_api_version,
283                                         p_api_type      => g_api_type,
284                                         x_return_status => lx_return_status);
285 
286   -- check if activity started successfully
287   IF (lx_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
288      RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
289   ELSIF (lx_return_status = OKC_API.G_RET_STS_ERROR) THEN
290      RAISE OKC_API.G_EXCEPTION_ERROR;
291   END IF;
292 
293   -- call the main routine
294   OKC_CREATE_PO_FROM_K_PVT.create_po_from_k(p_api_version   => l_api_version
295                                         ,p_init_msg_list => OKC_API.G_TRUE
296                                         ,x_return_status => lx_return_status
297                                         ,x_msg_count     => lx_msg_count
298                                         ,x_msg_data      => lx_msg_data
299                                         ,p_chr_id        => p_contract_id
300                                         );
301 
302 
303   -- check return status
304   IF lx_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
305             RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
306   ELSIF lx_return_status = OKC_API.G_RET_STS_ERROR THEN
307             RAISE OKC_API.G_EXCEPTION_ERROR;
308   END IF;
309 
310      IF p_commit = OKC_API.G_TRUE THEN
311         COMMIT;
312      END IF;
313   -- end activity
314   OKC_API.END_ACTIVITY( x_msg_count             => lx_msg_count,
315                         x_msg_data              => lx_msg_data);
316 
317   x_return_status := lx_return_status;
318   x_msg_count     := lx_msg_count;
319   x_msg_data      := lx_msg_data;
320 
321   EXCEPTION
322     when OKC_API.G_EXCEPTION_ERROR then
323       x_return_status := OKC_API.HANDLE_EXCEPTIONS(
324                                                 p_api_name  => l_api_name,
325                                                 p_pkg_name  => g_pkg_name,
326                                                 p_exc_name  => 'OKC_API.G_RET_STS_ERROR',
327                                                 x_msg_count => x_msg_count,
328                                                 x_msg_data  => x_msg_data,
329                                                 p_api_type  => g_api_type);
330 
331     when OKC_API.G_EXCEPTION_UNEXPECTED_ERROR then
332       x_return_status := OKC_API.HANDLE_EXCEPTIONS(
333                                                 p_api_name  => l_api_name,
334                                                 p_pkg_name  => g_pkg_name,
335                                                 p_exc_name  => 'OKC_API.G_RET_STS_UNEXP_ERROR',
336                                                 x_msg_count => x_msg_count,
337                                                 x_msg_data  => x_msg_data,
338                                                 p_api_type  => g_api_type);
339 
340     when OTHERS then
341       x_return_status := OKC_API.HANDLE_EXCEPTIONS(
342                                                 p_api_name  => l_api_name,
343                                                 p_pkg_name  => g_pkg_name,
344                                                 p_exc_name  => 'OTHERS',
345                                                 x_msg_count => x_msg_count,
346                                                 x_msg_data  => x_msg_data,
347                                                 p_api_type  => g_api_type);
348 
349 
350   END create_po_from_k;
351 
352 ---------------------------------------------------------------------------------
353 ---- Procedure:       submit_req_for_po_creation
354 ---- Version:         1.0
355 ---- Purpose:         submit the concurrent program that Populates PO interface from Contract
356 ----
357 
358   PROCEDURE submit_req_for_po_creation(
359                           p_api_version     IN  NUMBER
360 				 ,p_contract_id     IN  NUMBER
361                          ,p_init_msg_list   IN  VARCHAR2
362                          ,x_return_status   OUT NOCOPY VARCHAR2
363                          ,x_msg_count       OUT NOCOPY NUMBER
364                          ,x_msg_data        OUT NOCOPY  VARCHAR2) IS
365 
366 l_request_id              fnd_concurrent_requests.request_id%TYPE;
367 x_phase                   varchar2(50);
368 x_status                  varchar2(50);
369 x_dev_phase               varchar2(50);
370 x_dev_status              varchar2(50);
371 x_message                 varchar2(50);
372 l_create_po_finished      boolean;
373 l_notify                  varchar2(1):= 'F';
374 l_po_number               number;
375 l_k_number_modifier       number;
376 
377 BEGIN
378  -- Submit the request to create the po
379  my_debug('20: Submitting request to Populates PO interface from Contract');
380 
381 
382  l_request_id := fnd_request.submit_request(
383 					  application => 'OKC'
384 					 ,program     => 'OKCRKPOI'
385 					 ,argument1   => p_contract_id  -- contract id
386                                   	 );
387 
388 
389  IF l_request_id = 0
390  THEN
391     my_debug('40: Error submitting request for OKCRKPOI',4);
392     RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
393  END IF;
394 
395 -- commit to complete the request submission
396 
397     COMMIT;
398     my_debug('45: Submitted request to Populates PO interface from Contract.  Request id: ' || l_request_id);
399     my_debug('50: Waiting to complete concurrent request',4);
400     l_create_po_finished := FND_CONCURRENT.WAIT_FOR_REQUEST(
401                                           request_id => l_request_id,
402                                           interval   => 30,
403                                           max_wait => 1800,
404                                           phase => x_phase,
405                                           status => x_status,
406                                           dev_phase => x_dev_phase,
407                                           dev_status => x_dev_status,
408                                           message => x_message);
409 
410     IF l_create_po_finished THEN
411         my_debug('60: l_create_po_finished equal true',4);
412     ELSE
413         my_debug('70: l_create_po_finished equal false',4);
414     END IF;
415 
416     IF x_dev_phase = 'COMPLETE' AND x_dev_status IN ('NORMAL','WARNING')
417      THEN
418 
419         -- If x_dev_phase = 'COMPLETE' and x_dev_status IN ('NORMAL','WARNING')
420         -- the PO was successfully created. Notify the buyer of a PO creation
421         -- Select po_number and contract number modifier
422 
423         SELECT po.segment1
424 	    INTO l_po_number
425 	    FROM po_headers_all po
426 	    WHERE po.po_header_id =
427 	    ( SELECT object1_id1
428 		  FROM okc_k_rel_objs rel
429           WHERE rel.chr_id            = p_contract_id       -- for the current contract
430 	      AND rel.cle_id IS NULL                     -- related obj pertains to header
431 	      AND rel.rty_code          = g_crj_rty_code -- for PO creation
432 	      AND rel.jtot_object1_code = g_crj_chr_jtot_object_code -- correct jtot object
433 	    );
434 
435         SELECT contract_number_modifier
436         INTO l_k_number_modifier
437         FROM okc_k_headers_b
438         WHERE id = p_contract_id;
439 
440         l_k_number_modifier := nvl(l_k_number_modifier, ' ');
441 
442         my_debug('80: create po from contract conc program finished successfully',4);
443         OKC_API.set_message(p_app_name => 'OKC'
444 		                   ,p_msg_name => 'OKC_K2PO_NOTIF_SUBJECT'
445 		                   ,p_token1	 => 'PONUMBER'
446 		                   ,p_token1_value => l_po_number
447                            ,p_token2	 => 'KNUMBER'
448 		                   ,p_token2_value => p_contract_id
449                            ,p_token3	 => 'KNUMMODIFIER'
450 		                   ,p_token3_value => l_k_number_modifier
451                             );
452         x_return_status := OKC_API.G_RET_STS_SUCCESS;
453         x_msg_count := 0;
454         x_msg_data  := '';
455     ELSE
456         my_debug('90: create po from contract conc program finished with error',4);
457         OKC_API.set_message(p_app_name => 'OKC'
458 		                   ,p_msg_name => 'OKC_ERROR_PO_CREATED_DETAILS'
459 		                   ,p_token1	 => 'ERROR'
460 		                   ,p_token1_value => sqlerrm
461                            ,p_token2	 => 'KNUMBER'
462 		                   ,p_token2_value => p_contract_id
463                            ,p_token3	 => 'KNUMMODIFIER'
464 		                   ,p_token3_value => l_k_number_modifier
465                             );
466 
467         x_return_status := OKC_API.G_RET_STS_ERROR;
468         x_msg_data := sqlerrm;
469         x_msg_count := 1;
470     END IF;
471 
472 
473     my_debug('100: x_dev_phase equal' || x_dev_phase , 4);
474     my_debug('110: x_dev_status equal' || x_dev_status , 4);
475 
476 EXCEPTION
477 
478 WHEN OKC_API.G_EXCEPTION_UNEXPECTED_ERROR
479 THEN
480 
481     x_return_status := OKC_API.G_RET_STS_UNEXP_ERROR;
482 
483     OKC_API.set_message(p_app_name => 'OKC'
484 		     ,p_msg_name => 'OKC_ERROR_CONC_REQUEST'
485 		     ,p_token1	 => 'ERROR'
486 		     ,p_token1_value => sqlerrm || '-' || p_contract_id
487                  );
488 
489     x_msg_data      := 'Could not submit concurrent request';
490     x_msg_count     := 1;
491 
492 WHEN OTHERS
493 THEN
494     x_return_status := okc_api.g_ret_sts_unexp_error;
495 
496      OKC_API.set_message(p_app_name => 'OKC'
497 		     ,p_msg_name => 'OKC_ERROR_PO_FROM_K'
498 		     ,p_token1	 => 'ERROR'
499 		     ,p_token1_value => sqlerrm || '-' || p_contract_id
500                  );
501 
502     x_msg_data := sqlerrm;
503     x_msg_count := 1;
504 
505 END submit_req_for_po_creation;
506 ------------------------------------------------------------
507 -- Procedure submit_pdoi_errors_report - local
508 -- ......
509 -- ....
510 ------------------------------------------------------------
511 
512 PROCEDURE submit_pdoi_errors_report( p_api_version              IN  NUMBER
513 			            ,p_init_msg_list            IN  VARCHAR2
514 			            ,p_chr_id                   IN  okc_k_headers_b.ID%TYPE
515                                    ,x_return_status            OUT NOCOPY VARCHAR2
516 			               ,x_msg_count                OUT NOCOPY NUMBER
517 			               ,x_msg_data                 OUT NOCOPY VARCHAR2)IS
518 
519 l_request_id              fnd_concurrent_requests.request_id%TYPE;
520 
521 BEGIN
522 
523 -- May need to add checks here (later) to not fire these processes if
524 -- the initial ones errored out
525 
526 -- Submit the request to report errors on the interface
527  my_debug('20: Submitting request for PDOI Interface errors');
528 
529 
530  l_request_id := fnd_request.submit_request(
531 					  application => 'PO'
532 					 ,program     => 'POXPIERR'
533 					 ,sub_request => FALSE         -- Indicates that this is a child
534 								       -- of the parent request
535 					 ,argument1   => 'PO_DOCS_OPEN_INTERFACE' -- Source program
536 					 ,argument2   => 'N'          -- Purge Data
537 					 );
538 
539  IF l_request_id = 0
540  THEN
541     my_debug('40: Error submitting request for POXPIERR',4);
542     RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
543  END IF;
544 
545  my_debug('60: Submitted request for PDOI Interface errors.  Request id: ' || l_request_id);
546 
547 END submit_pdoi_errors_report;
548 
549 ------------------------------------------------------------
550 -- Procedure my_Debug - local
551 ------------------------------------------------------------
552 
553 PROCEDURE my_debug( p_msg    IN VARCHAR2,
554 				p_level  IN NUMBER   DEFAULT 1,
555 				p_module IN VARCHAR2 DEFAULT 'OKC') IS
556  BEGIN
557 
558     fnd_file.put_line(fnd_file.log, g_pkg_name ||':'|| p_msg);
559  -- okc_debug.Log(p_msg,p_level,p_module);
560  -- dbms_output.put_line(substr(p_msg,1,240));
561 
562 END my_debug;
563 
564 -------------------------------------------------------------------------------
565 -- Procedure:       notify_buyer
566 -- Version:         1.0
567 -- Purpose: notify the buyer of a purchase order creation
568 -------------------------------------------------------------------------------
569 PROCEDURE notify_buyer(p_api_version                  IN NUMBER
570                       		,p_init_msg_list                IN VARCHAR2
571                       		,p_commit                       IN VARCHAR2
572 		      		,p_application_name             IN VARCHAR2
573 		      		,p_message_subject              IN FND_NEW_MESSAGES.MESSAGE_NAME%TYPE
574 		      		,p_message_body 	        IN FND_NEW_MESSAGES.MESSAGE_NAME%TYPE
575 		      		,p_message_body_token1 		IN VARCHAR2
576 		      		,p_message_body_token1_value 	IN VARCHAR2
577 		      		,p_message_body_token2 		IN VARCHAR2
578 		      		,p_message_body_token2_value 	IN VARCHAR2
579                                 ,p_message_body_token3 		IN VARCHAR2
580 		      		,p_message_body_token3_value 	IN VARCHAR2
581 		      		,p_trace_mode      		IN VARCHAR2
582                       		,p_chr_id     		        IN OKC_K_HEADERS_B.ID%TYPE
583                       		,x_k_buyer_name               OUT NOCOPY VARCHAR2
584                       		,x_return_status   	 OUT NOCOPY VARCHAR2
585                       		,x_msg_count                    OUT NOCOPY NUMBER
586                       		,x_msg_data                     OUT NOCOPY VARCHAR2) IS
587 
588 l_api_name	 CONSTANT VARCHAR2(30) 	:= 'notify_buyer';
589 l_api_version	 CONSTANT NUMBER	:=1;
590 lx_return_status VARCHAR2(1)	 	:= OKC_API.G_RET_STS_SUCCESS;
591 lx_msg_count	 NUMBER			;
592 lx_msg_data	 FND_NEW_MESSAGES.message_text%TYPE;
593 
594 BEGIN
595   lx_return_status := OKC_API.START_ACTIVITY(
596 					p_api_name      => l_api_name,
597 					p_pkg_name      => g_pkg_name,
598 					p_init_msg_list => p_init_msg_list,
599 					l_api_version   => l_api_version,
600 					p_api_version   => p_api_version,
601 					p_api_type      => g_api_type,
602 					x_return_status => lx_return_status);
603 
604   IF (lx_return_status = OKC_API.G_RET_STS_UNEXP_ERROR) THEN
605     RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
606   ELSIF (lx_return_status = OKC_API.G_RET_STS_ERROR) THEN
607     RAISE OKC_API.G_EXCEPTION_ERROR;
608   END IF;
609 
610 
611 
612   -- trace mode initialization turned ON
613   IF p_trace_mode = okc_api.g_true OR
614 	FND_PROFILE.VALUE('AFLOG_ENABLED') = 'Y'  -- FND: Debug Log Enabled
615   THEN
616 	okc_util.init_trace;
617   END IF;
618 
619   -- call the main routine
620 
621   OKC_CREATE_PO_FROM_K_PVT.notify_buyer(
622                    p_api_version      	        => l_api_version
623                   ,p_init_msg_list    	        => OKC_API.G_FALSE
624                   ,p_application_name	        => p_application_name
625 		      ,p_message_subject  		  => p_message_subject
626 		      ,p_message_body    		  => p_message_body
627 		      ,p_message_body_token1	        => p_message_body_token1
628 		      ,p_message_body_token1_value	  => p_message_body_token1_value
629 		      ,p_message_body_token2	        => p_message_body_token2
630 		      ,p_message_body_token2_value	  => p_message_body_token2_value
631                   ,p_message_body_token3	        => p_message_body_token3
632 		      ,p_message_body_token3_value	  => p_message_body_token3_value
633 		      ,p_chr_id                       => p_chr_id
634                   ,x_k_buyer_name                 => x_k_buyer_name
635                   ,x_return_status                => lx_return_status
636                   ,x_msg_count                    => lx_msg_count
637                   ,x_msg_data                     => lx_msg_data
638                   );
639 
640   -- trace mode initialization turned OFF
641   IF p_trace_mode = okc_api.g_true  OR  FND_PROFILE.VALUE('AFLOG_ENABLED') = 'Y' THEN
642 	okc_util.stop_trace;
643   END IF;
644 
645 
646   -- check return status
647   IF lx_return_status = OKC_API.G_RET_STS_UNEXP_ERROR THEN
648     RAISE OKC_API.G_EXCEPTION_UNEXPECTED_ERROR;
649   ELSIF lx_return_status = OKC_API.G_RET_STS_ERROR THEN
650     RAISE OKC_API.G_EXCEPTION_ERROR;
651   END IF;
652 
653 
654 
655   -- if we got this far, then we are successful
656   IF p_commit = OKC_API.G_TRUE THEN
657     COMMIT;
658   END IF;
659 
660   -- end activity
661   OKC_API.END_ACTIVITY(x_msg_count		=> lx_msg_count,
662   		       x_msg_data		=> lx_msg_data);
663 
664   x_return_status := lx_return_status;
665   x_msg_count     := lx_msg_count;
666   x_msg_data      := lx_msg_data;
667 
668   EXCEPTION
669     when OKC_API.G_EXCEPTION_ERROR then
670       x_return_status := OKC_API.HANDLE_EXCEPTIONS(
671 						p_api_name  => l_api_name,
672 						p_pkg_name  => g_pkg_name,
673 						p_exc_name  => 'OKC_API.G_RET_STS_ERROR',
674 						x_msg_count => lx_msg_count,
675 						x_msg_data  => lx_msg_data,
676 						p_api_type  => g_api_type);
677 
678     when OKC_API.G_EXCEPTION_UNEXPECTED_ERROR then
679       x_return_status := OKC_API.HANDLE_EXCEPTIONS(
680 						p_api_name  => l_api_name,
681 						p_pkg_name  => g_pkg_name,
682 						p_exc_name  => 'OKC_API.G_RET_STS_UNEXP_ERROR',
683 						x_msg_count => lx_msg_count,
684 						x_msg_data  => lx_msg_data,
685 						p_api_type  => g_api_type);
686 
687     when OTHERS then
688       x_return_status := OKC_API.HANDLE_EXCEPTIONS(
689 						p_api_name  => l_api_name,
690 						p_pkg_name  => g_pkg_name,
691 						p_exc_name  => 'OTHERS',
692 						x_msg_count => lx_msg_count,
693 						x_msg_data  => lx_msg_data,
694 						p_api_type  => g_api_type);
695 END notify_buyer;
696 
697 
698 END OKC_CREATE_PO_FROM_K_PUB;