DBA Data[Home] [Help]

PACKAGE BODY: APPS.PA_FORECAST_WF

Source


1 PACKAGE BODY pa_forecast_wf AS
2 /* $Header: PAWFGFCB.pls 120.2 2006/03/22 20:39:09 nkumbi noship $*/
3 
4 -- forward declarations ------------------------------------------------
5 
6 PROCEDURE Set_Nf_Error_Msg_Attr (p_item_type IN VARCHAR2,
7 			         p_item_key  IN VARCHAR2,
8 				 p_msg_count IN NUMBER,
9 				 p_msg_data IN VARCHAR2
10                                  ) ;
11 
12 -- ---------------------------------------------------------------------
13 -- ---------------------------------------------------------------------
14 
15 
16 
17 --Name:               start_forecast_workflow
18 --Type:               Procedure
19 --Description:        This procedure intiates the forecast generation workflow
20 --
21 --Called subprograms: Various workflow procedures
22 --
23 --History:
24 --    26-MAR-01		jwhite		Created
25 --    23-Mar-06     nkumbi      Stubbed out the procedure as PAWFGPF workflow is obsolete in R12
26 
27 PROCEDURE start_forecast_workflow(p_project_id		 IN      NUMBER
28                                   , x_msg_count	         OUT NOCOPY NUMBER --File.Sql.39 bug 4440895
29  			          , x_msg_data	         OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
30 			          , x_return_status      OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
31                                   )
32 IS
33 
34 BEGIN
35 
36 null;
37 
38 
39 END start_forecast_workflow;
40 
41 
42 --Name:               process_forecast
43 --Type:               Procedure
44 --Description:        This procedure calls a forecasting procedure to actually
45 --                    generate the project forecast.
46 --
47 --                    If the generate_forecast procedure is successful, the
48 --                    Resultout = 'T'. Other notification text varies,
49 --                    accordingly.
50 --
51 --                    Otherwise, the Resultout = 'F' and one or more
52 --                    error messages, up to five messages, is displayed on the
53 --                    notification. Other notification text varies,
54 --                    accordingly.
55 --
56 --                    The process_forecast procedure is called from the
57 --                    forecast generation workflow.
58 --
59 --Called subprograms:
60 --
61 --History:
62 --    26-MAR-01		jwhite		Created
63 --
64 PROCEDURE process_forecast(itemtype   IN  VARCHAR2
65                           , itemkey   IN  VARCHAR2
66                           , actid     IN  NUMBER
67                           , funcmode  IN  VARCHAR2
68                           , resultout OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
69                           )
70 IS
71 
72 l_return_status           VARCHAR2(1)    :=NULL;
73 l_msg_count	          NUMBER         :=NULL;
74 l_msg_data	          VARCHAR2(2000) :=NULL;
75 l_msg_index_out           NUMBER         :=NULL;
76 
77 l_project_id	          NUMBER         := NULL;
78 l_wf_started_by_username  VARCHAR2(100)   := NULL; /* Modified length from 30 to 100 for bug 3148857 */
79 
80 
81 l_msg_subj_text    VARCHAR2(2000) :=NULL;
82 l_msg_desc_text    VARCHAR2(2000) :=NULL;
83 /* Added */
84 l_wf_started_by_id NUMBER;
85 l_wf_started_by_resp_id NUMBER;
86 l_wf_started_by_appl_id NUMBER;
87 l_plan_processing_code PA_BUDGET_VERSIONS.PLAN_PROCESSING_CODE%TYPE;
88 l_fcst_err_url     VARCHAR2(600);
89 l_msg_err_text     VARCHAR2(100);
90 
91 
92 
93 BEGIN
94 
95           -- Return if WF Not Running
96   	   IF (funcmode <> wf_engine.eng_run) THEN
97     	       resultout := wf_engine.eng_null;
98     	       RETURN;
99   	   END IF;
100 
101 
102            -- Assume WF Success
103            resultout := wf_engine.eng_completed||':'||'G';
104 
105 
106            -- Get Required Runtime Parmeters from WF
107            l_project_id := wf_engine.GetItemAttrNumber
108 			   (  itemtype => itemtype
109                            ,  itemkey =>  itemkey
110                            ,  aname => 'PROJECT_ID'
111                            );
112 /* Added for the deferred process */
113 
114            l_wf_started_by_id := wf_engine.GetItemAttrNumber
115 			   (  itemtype => itemtype
116                            ,  itemkey =>  itemkey
117                            ,  aname => 'WORKFLOW_STARTED_BY_UID'
118                            );
119 
120            l_wf_started_by_resp_id := wf_engine.GetItemAttrNumber
121 			   (  itemtype => itemtype
122                            ,  itemkey =>  itemkey
123                            ,  aname => 'WORKFLOW_STARTED_BY_RESP_ID'
124                            );
125 
126            l_wf_started_by_appl_id := wf_engine.GetItemAttrNumber
127 			   (  itemtype => itemtype
128                            ,  itemkey =>  itemkey
129                            ,  aname => 'WORKFLOW_STARTED_BY_APPL_ID'
130                            );
131 
132         FND_GLOBAL.Apps_Initialize ( user_id       => l_wf_started_by_id
133                                     , resp_id      => l_wf_started_by_resp_id
134                                     , resp_appl_id => l_wf_started_by_appl_id
135                                     );
136 /* Added for the deferred process */
137 
138            --dbms_output.put_line ('call Generate Forecast------------------');
139 
140            -- Generate Project Forecast!!!--------------------------------
141            PA_GENERATE_FORECAST_PUB.generate_forecast
142                                     (p_project_id     => l_project_id
143                                     , x_return_status => l_return_status
144                                     , x_msg_count     => l_msg_count
145                                     , x_msg_data      => l_msg_data
146                                     );
147            -- -------------------------------------------------------------
148 
149            --dbms_output.put_line ('-------l_return_status: '||l_return_status);
150            --dbms_output.put_line ('-------l_msg_count:     '||to_char(l_msg_count));
151            --dbms_output.put_line ('-------l_msg_data:      '||l_msg_data);
152 
153           /* The following code is added to set the subject and header as error
154              if the PLAN_PROCESSING_CODE in budget version is set to E */
155           -- Conditionally Populate NF MSG and Error Display Fields
156            BEGIN
157              SELECT PLAN_PROCESSING_CODE INTO l_plan_processing_code FROM
158                   PA_BUDGET_VERSIONS
159              WHERE
160                   PROJECT_ID = l_project_id AND
161                   BUDGET_TYPE_CODE = 'FORECASTING_BUDGET_TYPE';
162            EXCEPTION
163            WHEN NO_DATA_FOUND THEN
164              l_plan_processing_code := 'G';
165            WHEN OTHERS THEN
166              l_plan_processing_code := 'G';
167            END;
168 /*
169            status G - success  and also set up level error ex. profile value missing
170                   L - Line level error
171                   U - Work flow error
172 */
173            IF l_return_status = FND_API.G_RET_STS_SUCCESS AND l_plan_processing_code = 'E' THEN
174              resultout := wf_engine.eng_completed||':'||'L';
175            ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
176              resultout := wf_engine.eng_completed||':'||'G';
177            END IF;
178 
179 
180            IF (l_return_status = FND_API.G_RET_STS_SUCCESS) AND
181                  l_plan_processing_code = 'G'
182               THEN
183               -- Success!
184 
185                FND_MESSAGE.SET_NAME ('PA','PA_NFSUBJ_FORECAST_SUCCESS');
186 	       l_msg_subj_text := FND_MESSAGE.GET;
187 
188 	       FND_MESSAGE.SET_NAME ('PA','PA_NFDESC_FORECAST_SUCCESS');
189 	       l_msg_desc_text := FND_MESSAGE.GET;
190 
191               wf_engine.SetItemAttrText
192 			       ( itemtype => itemtype
193                                , itemkey =>  itemkey
194                                , aname =>    'MSG_SUBJECT_FYI'
195                                , avalue =>   l_msg_subj_text
196                                );
197 
198               wf_engine.SetItemAttrText
199 			       ( itemtype => itemtype
200                                , itemkey =>  itemkey
201                                , aname =>    'MSG_DESCRIPTION_FYI'
202                                , avalue =>   l_msg_desc_text
203                                );
204 
205            ELSIF l_return_status = FND_API.G_RET_STS_SUCCESS AND
206                  l_plan_processing_code = 'E'
207              THEN
208                FND_MESSAGE.SET_NAME ('PA','PA_NFSUBJ_FORECAST_FAILURE');
209                l_msg_subj_text := FND_MESSAGE.GET;
210 
211                FND_MESSAGE.SET_NAME ('PA','PA_NFSUBJ_FCST_LINE_FAILURE');
212                l_msg_desc_text := FND_MESSAGE.GET;
213 
214            -- Errors! Note that the WF only marked as failure if ORA error
215 
216               wf_engine.SetItemAttrText
217 			       ( itemtype => itemtype
218                                , itemkey =>  itemkey
219                                , aname =>    'MSG_SUBJECT_FYI'
220                                , avalue =>   l_msg_subj_text
221                                );
222 
223               wf_engine.SetItemAttrText
224 			       ( itemtype => itemtype
225                                , itemkey =>  itemkey
226                                , aname =>    'MSG_DESCRIPTION_FYI'
227                                , avalue =>   l_msg_desc_text
228                                );
229 
230              l_fcst_err_url :=
231  'JSP:/OA_HTML/OA.jsp?akRegionApplicationId=275&akRegionCode=PA_FCST_ERROR_LAYOUT&paProjectId='||l_project_id||'&paCallingFrom="Notification"';
232 /* Added for bug       to show the text ERRORS only if the process status is failure.  */
233 
234              wf_engine.SetItemAttrText
235                                ( itemtype => itemtype
236                                , itemkey  => itemkey
237                                , aname => 'FCST_ERROR_URL_INFO'
238                                , avalue => l_fcst_err_url
239                                );
240 
241               -- Conditionally Populate Error Messages and Related NF Display Fields
242 
243 
244               -- Application errors. WF SUCCESS! Send Notification to Default WF User.
245 
246                     set_nf_error_msg_attr (p_item_type => itemtype,
247 			                  p_item_key  => itemkey,
248 				          p_msg_count => l_msg_count,
249 				          p_msg_data  => l_msg_data
250                                           );
251 
252            ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
253 
254               FND_MESSAGE.SET_NAME ('PA','PA_NFSUBJ_FORECAST_FAILURE');
255 	      l_msg_subj_text := FND_MESSAGE.GET;
256 
257 	      FND_MESSAGE.SET_NAME ('PA','PA_NFDESC_FORECAST_FAILURE');
258 	      l_msg_desc_text := FND_MESSAGE.GET;
259 
260               wf_engine.SetItemAttrText
261 			       ( itemtype => itemtype
262                                , itemkey =>  itemkey
263                                , aname =>    'MSG_SUBJECT_FYI'
264                                , avalue =>   l_msg_subj_text
265                                );
266 
267               wf_engine.SetItemAttrText
268 			       ( itemtype => itemtype
269                                , itemkey =>  itemkey
270                                , aname =>    'MSG_DESCRIPTION_FYI'
271                                , avalue =>   l_msg_desc_text
272                                );
273 
274 
275               -- Hard ORA error. WF FAILURE! Send Notification to Projects Sys Admin.
276 
277                    -- Populate ORA Message Text
278                       set_nf_error_msg_attr (p_item_type => itemtype,
279 			                     p_item_key  => itemkey,
280 				             p_msg_count => l_msg_count,
281 				             p_msg_data  => l_msg_data
282                                              );
283 
284                    -- Set WF Status for Failure. Route to Sys Admin
285                    resultout := wf_engine.eng_completed||':'||'U';
286 
287            ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
288 
289               FND_MESSAGE.SET_NAME ('PA','PA_NFSUBJ_FORECAST_FAILURE');
290 	      l_msg_subj_text := FND_MESSAGE.GET;
291 
292 	      FND_MESSAGE.SET_NAME ('PA','PA_NFDESC_FORECAST_FAILURE');
293 	      l_msg_desc_text := FND_MESSAGE.GET;
294 
295               wf_engine.SetItemAttrText
296 			       ( itemtype => itemtype
297                                , itemkey =>  itemkey
298                                , aname =>    'MSG_SUBJECT_FYI'
299                                , avalue =>   l_msg_subj_text
300                                );
301 
302               wf_engine.SetItemAttrText
303 			       ( itemtype => itemtype
304                                , itemkey =>  itemkey
305                                , aname =>    'MSG_DESCRIPTION_FYI'
306                                , avalue =>   l_msg_desc_text
307                                );
308 
309               FND_MESSAGE.SET_NAME ('PA','PA_NFERR_FCST');
310               l_msg_err_text  := FND_MESSAGE.GET;
311 
312               wf_engine.SetItemAttrText
313                               ( itemtype => itemtype
314                                , itemkey => itemkey
315                                , aname   => 'ERROR_COMMENTS'
316                                , avalue  => l_msg_err_text
317                                );
318 
319 /*             wf_engine.SetItemAttrText
320                                ( itemtype => itemtype
321                                , itemkey  => itemkey
322                                , aname => 'FCST_ERROR_URL_INFO'
323                                , avalue => NULL
324                                );  */
325 
326                     set_nf_error_msg_attr (p_item_type => itemtype,
327 			                  p_item_key  => itemkey,
328 				          p_msg_count => l_msg_count,
329 				          p_msg_data  => l_msg_data
330                                           );
331            END IF; --Conditionally Populate NF MSG and Errors
332 
333 
334 
335 
336 
337 EXCEPTION
338  WHEN OTHERS THEN
339       WF_CORE.CONTEXT
340 		('PA_GENERATE_FORECAST_MP',
341 		 'Process_Forecast',
342 		  itemtype,
343 		  itemkey,
344 		  to_char(actid),
345 		  funcmode);
346 	 RAISE;
347 
348 END process_forecast;
349 
350 
351 
352 --Name:               set_nf_error_msg_attr
353 --Type:               Procedure
354 --Description:        This procedure populates the notificatin error message fields.
355 --
356 --Called subprograms: None.
357 --
358 --History:
359 --    26-MAR-01		jwhite		Cloned from PA_ASGMT_WFSTD package
360 --
361 
362 
363 PROCEDURE set_nf_error_msg_attr (p_item_type IN VARCHAR2,
364 			         p_item_key  IN VARCHAR2,
365 				 p_msg_count IN NUMBER,
366 				 p_msg_data IN VARCHAR2 ) IS
367 
368 l_project_id       NUMBER := NULL;
369 l_msg_index_out	   NUMBER ;
370 l_msg_data	   VARCHAR2(2000);
371 l_data	           VARCHAR2(2000);
372 l_item_attr_name   VARCHAR2(30);
373 l_msg_err_text     VARCHAR2(100);
374 BEGIN
375           IF p_msg_count = 0 THEN
376 	       RETURN;
377           END IF;
378 
379 	  IF p_msg_count = 1 THEN
380 	     IF p_msg_data IS NOT NULL THEN
381                 FND_MESSAGE.SET_ENCODED (p_msg_data);
382                 l_data := FND_MESSAGE.GET;
383                 wf_engine.SetItemAttrText
384 			       ( itemtype => p_item_type
385                                , itemkey =>  p_item_key
386                                , aname => 'ERROR_COMMENTS_1'
387                                , avalue => l_data
388                                );
389 	     END IF;
390              RETURN ;
391           END IF;
392 
393      	  IF p_msg_count > 1 THEN
394               FOR i in 1..p_msg_count
395 	    LOOP
396 	      IF i > 5 THEN
397 	  	 EXIT;
398 	      END IF;
399 	      pa_interface_utils_pub.get_messages
400 		(p_encoded        => FND_API.G_FALSE,
401  		 p_msg_index      => i,
402                  p_msg_count      => p_msg_count ,
403                  p_msg_data       => p_msg_data ,
404                  p_data           => l_data,
405                  p_msg_index_out  => l_msg_index_out );
406                  l_item_attr_name := 'ERROR_COMMENTS_'||i;
407                    wf_engine.SetItemAttrText
408 			       ( itemtype => p_item_type
409                                , itemkey =>  p_item_key
410                                , aname => l_item_attr_name
411                                , avalue => l_data
412                                );
413             END LOOP;
414 	  END IF;
415 EXCEPTION
416 	WHEN OTHERS THEN RAISE;
417 END set_nf_error_msg_attr;
418 
419 
420 
421 END pa_forecast_wf;