DBA Data[Home] [Help]

PACKAGE BODY: APPS.OE_BLANKET_WF

Source


1 PACKAGE BODY OE_Blanket_WF as
2 /* $Header: OEXWBSOB.pls 120.4 2011/11/03 08:28:10 adandu ship $ */
3 
4 
5 PROCEDURE Submit_Draft_Internal (
6     itemtype  in varchar2,
7     itemkey   in varchar2,
8     actid     in number,
9     funcmode  in varchar2,
10     resultout in out nocopy varchar2)
11 IS
12 --
13 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
14 l_return_status VARCHAR2(30);
15 l_qa_return_status VARCHAR2(30);
16 l_msg_count NUMBER;
17 l_msg_data VARCHAR2(2000);
18 l_count NUMBER;
19 --
20 BEGIN
21     IF l_debug_level  > 0 THEN
22        oe_debug_pub.add(  'ENTERING OE_BLanket_WF.Submit_Draft_Internal:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
23     END IF;
24     OE_STANDARD_WF.Set_Msg_Context(actid);
25     IF (funcmode = 'RUN') then
26 
27      select count(1)
28      into l_count
29      from wf_items
30      where item_type  = OE_GLOBALS.G_WFI_NGO
31      and item_key     = itemkey;
32 
33      IF l_count = 0 THEN
34       /* only if it has not gone through negotiation QA check
35          Blanket_QA_Check API call */
36 
37         OE_CONTRACTS_UTIL.qa_articles ( p_api_version => 1.0,
38                                    p_doc_type    => 'B',
39                                    p_doc_id      => to_number(itemkey),
40                                    x_qa_return_status  => l_qa_return_status,
41                                    x_return_status     => l_return_status,
42                                    x_msg_count         => l_msg_count,
43                                    x_msg_data          => l_msg_data);
44       IF l_debug_level  > 0 THEN
45        oe_debug_pub.add(  'Contract returns: x_return_status:' || l_return_status || ' x_qa_return_status:' || l_qa_return_status, 1);
46       END IF;
47 
48       -- If API call is successful, but the check failed, return incomplete
49       IF l_return_status = FND_API.G_RET_STS_SUCCESS
50 	AND  l_qa_return_status <> FND_API.G_RET_STS_SUCCESS
51 	AND  l_qa_return_status <> 'W' THEN
52         resultout := 'COMPLETE:INCOMPLETE';
53         OE_STANDARD_WF.Save_Messages;
54         OE_STANDARD_WF.Clear_Msg_Context;
55         return;
56       ELSIF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
57       -- API call failed completely, fail the activity
58         app_exception.raise_exception;
59       END IF;
60 
61      END IF;
62      -- negotiation flow exists, no need to QA check
63 
64 -- UI will always display any msg
65 
66       OE_ORDER_WF_UTIL.Update_Quote_Blanket(p_item_type => OE_GLOBALS.G_WFI_BKT,
67                                             p_item_key => itemkey,
68                                             p_flow_status_code => 'DRAFT_SUBMITTED',
69                                             p_draft_submitted_flag => 'Y',
70                                             x_return_status => l_return_status);
71 
72       IF l_return_status = FND_API.G_RET_STS_ERROR THEN
73         resultout := 'COMPLETE:INCOMPLETE';
74         OE_STANDARD_WF.Save_Messages;
75         OE_STANDARD_WF.Clear_Msg_Context;
76         return;
77       ELSIF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
78         app_exception.raise_exception;
79       END IF;
80 
81       resultout := 'COMPLETE:COMPLETE';
82 
83 
84     END IF;
85 EXCEPTION
86     when others then
87        wf_core.context('OE_Blanket_WF', 'Submit_Draft_Internal', itemtype, itemkey, to_char(actid), funcmode);
88        -- start data fix project
89        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
90                                           p_itemtype => itemtype,
91                                           p_itemkey => itemkey);
92        -- end data fix project
93        OE_STANDARD_WF.Save_Messages;
94        OE_STANDARD_WF.Clear_Msg_Context;
95        raise;
96 
97 END Submit_Draft_Internal;
98 
99 
100 PROCEDURE Check_Negotiation_Exists(
101     itemtype  in varchar2,
102     itemkey   in varchar2,
103     actid     in number,
104     funcmode  in varchar2,
105     resultout in out nocopy varchar2)
106 IS
107 --
108 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
109 l_count NUMBER;
110 --
111 BEGIN
112     IF l_debug_level  > 0 THEN
113        oe_debug_pub.add(  'ENTERING OE_Blanket_WF.Check_Negotiation_Exists:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
114     END IF;
115     OE_STANDARD_WF.Set_Msg_Context(actid);
116     IF (funcmode = 'RUN') THEN
117        select count(1)
118        into l_count
119        from wf_items
120        where item_type = OE_GLOBALS.G_WFI_NGO
121        and item_key = itemkey;
122 
123        IF l_count > 0 THEN
124           resultout := 'COMPLETE:Y';
125        ELSE
126           resultout := 'COMPLETE:N';
127        END IF;
128 
129     END IF;
130 
131     IF l_debug_level  > 0 THEN
132        oe_debug_pub.add(  'EXITING OE_BLanket_WF.Check_Negotiation_Exists:' || resultout);
133     END IF;
134 
135 EXCEPTION
136     when others then
137        wf_core.context('OE_Blanket_WF', 'Check_Negotiation_Exists', itemtype, itemkey, to_char(actid), funcmode);
138        -- start data fix project
139        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
140                                           p_itemtype => itemtype,
141                                           p_itemkey => itemkey);
142        -- end data fix project
143        OE_STANDARD_WF.Save_Messages;
144        OE_STANDARD_WF.Clear_Msg_Context;
145        raise;
146 
147 END Check_Negotiation_Exists;
148 
149 
150 PROCEDURE Calculate_Effective_Dates(
151     itemtype  in varchar2,
152     itemkey   in varchar2,
153     actid     in number,
154     funcmode  in varchar2,
155     resultout in out nocopy varchar2)
156 IS
157 --
158 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
159 l_start_date DATE;
160 l_end_date   DATE;
161 l_pre_notification_percent NUMBER;
162 l_aname         wf_engine.nametabtyp;
163 l_avalue        wf_engine.numtabtyp;
164 l_final_timer   NUMBER;
165 l_start_timer   NUMBER;
166 l_return_status VARCHAR2(30);
167 --
168 
169 BEGIN
170 
171     IF l_debug_level  > 0 THEN
172        oe_debug_pub.add(  'ENTERING OE_Blanket_WF.Calculate_Effective_Dates:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
173     END IF;
174     OE_STANDARD_WF.Set_Msg_Context(actid);
175     IF (funcmode = 'RUN') then
176       SELECT obhe.Start_Date_Active, obhe.End_Date_Active
177       INTO   l_start_date, l_end_date
178       FROM   oe_blanket_headers_all obha, oe_blanket_headers_ext obhe
179       WHERE  obha.header_id = to_number(itemkey)
180       AND    obha.order_number = obhe.order_number;
181 
182       -- start date has not been reached
183       IF l_start_date > sysdate THEN
184          l_start_timer := (l_start_date - sysdate) * 1440;
185          wf_engine.setitemattrnumber(itemtype=>itemtype,
186 				     itemkey=>itemkey,
187 				     aname=>'BLANKET_START_TIMER',
188 				     avalue=>l_start_timer);
189          oe_order_wf_util.update_flow_status_code(p_header_id => to_number(itemkey),
190                                                   p_flow_status_code => 'AWAITING_START_DATE',
191                                                   p_item_type => OE_GLOBALS.G_WFI_BKT,
192                                                   x_return_status => l_return_status);
193 
194          resultout := 'COMPLETE:AWAITING_START_DATE';
195          IF l_debug_level  > 0 THEN
196            oe_debug_pub.add('Leaving OE_Blanket_WF.Calculate_Effective_Dates: Start date not reached', 1);
197          END IF;
198          return;
199       ELSIF l_end_date is null THEN --start date reached, but no end date
200            oe_order_wf_util.update_flow_status_code(p_header_id => to_number(itemkey),
201                                                   p_flow_status_code => 'ACTIVE',
202                                                   p_item_type => OE_GLOBALS.G_WFI_BKT,
203                                                   x_return_status => l_return_status);
204            resultout := 'COMPLETE:NO_END_DATE';
205            IF l_debug_level  > 0 THEN
206               oe_debug_pub.add('Leaving OE_Blanket_WF.Calculate_Effective_Date: No end date', 1);
207            END IF;
208            return;
209       ELSIF l_end_date < sysdate THEN --start date reached, end date also reached
210             resultout := 'COMPLETE:EXPIRED';
211             IF l_debug_level  > 0 THEN
212                 oe_debug_pub.add('Leaving OE_Blanket_WF.Calculate_Effective_Dates: EXPIRED', 1);
213             END IF;
214             -- status update will be handled in the Expired activity
215             return;
216       END IF;
217 
218       --if you are here, that means expiration date exists and is in the future
219 
220       l_pre_notification_percent := wf_engine.GetItemAttrNumber(itemtype, itemkey, 'PRE_EXPIRE_TIME_PERCENT');
221 
222       oe_debug_pub.add('sysdate:' || to_char(sysdate, 'DD-MON-RRRR') || ' and end date:' || to_char(l_end_date, 'DD-MON-RRRR'),1);
223 
224       IF l_pre_notification_percent = 0 THEN
225          -- set the FINAL timer only is enough
226          -- this assumes expiration_date is already set to 23:59:59
227          l_final_timer := (l_end_date - sysdate) * 1440;
228          wf_engine.setitemattrnumber(itemtype=>itemtype,
229 				     itemkey=>itemkey,
230 				     aname=>'BLANKET_FINAL_EXPIRE_TIMER',
231 				     avalue=>l_final_timer);
232          oe_order_wf_util.update_flow_status_code(p_header_id => to_number(itemkey),
233                                                   p_flow_status_code => 'ACTIVE',
234                                                   p_item_type => OE_GLOBALS.G_WFI_BKT,
235                                                   x_return_status => l_return_status);
236          resultout := 'COMPLETE:NO_REMINDER';
237          IF l_debug_level  > 0 THEN
238              oe_debug_pub.add('Leaving OE_Blanket_WF.Calculate_Effective_Dates: NO REMINDER', 1);
239          END IF;
240          return;
241       ELSIF to_char(sysdate, 'DD-MON-RRRR') = to_char(l_end_date, 'DD-MON-RRRR') THEN
242          -- pre notification percentage is non-zero
243          -- end_date is today midnight, we should send the reminder
244 
245 	 wf_engine.SetItemAttrNumber(itemtype=>itemtype,
246 				     itemkey=>itemkey,
247                                      aname=> 'BLANKET_FINAL_EXPIRE_TIMER',
248                                      avalue=> (l_end_date - sysdate) * 1440);
249               oe_order_wf_util.update_flow_status_code(p_header_id => to_number(itemkey),
250                                                   p_flow_status_code => 'ACTIVE',
251                                                   p_item_type => OE_GLOBALS.G_WFI_BKT,
252                                                   x_return_status => l_return_status);
253               resultout := 'COMPLETE:EXPIRE_TODAY';
254               IF l_debug_level  > 0 THEN
255                  oe_debug_pub.add('OE_Blanket_WF.Calculate_Effective_Dates: EXPIRE TODAY', 1);
256               END IF;
257       ELSE --expiration is not today, i.e. it is in the future
258            --again end_date should already be in 23:59:59
259               l_aname(1) := 'BLANKET_FINAL_EXPIRE_TIMER';
260               l_avalue(1) := Ceil((l_end_date - sysdate) * l_pre_notification_percent/100) * 1440;
261               l_aname(2) := 'BLANKET_PRE_EXPIRE_TIMER';
262               l_avalue(2) := ((l_end_date - sysdate) * 1440) - l_avalue(1);
263 
264               wf_engine.SetItemAttrNumberArray(itemtype=>itemtype
265                               , itemkey=>itemkey
266                               , aname=>l_aname
267                               , avalue=>l_avalue
268                               );
269               oe_order_wf_util.update_flow_status_code(p_header_id => to_number(itemkey),
270                                                   p_flow_status_code => 'ACTIVE',
271                                                   p_item_type => OE_GLOBALS.G_WFI_BKT,
272                                                   x_return_status => l_return_status);
273               resultout := 'COMPLETE:START_DATE_REACHED';
274       END IF; -- end if of expiration date is today or future
275 
276       IF l_debug_level  > 0 THEN
277            oe_debug_pub.add('Leaving OE_Blanket_WF.Calculate_Effective_Dates: TIMER(S) SET', 1);
278       END IF;
279     END IF;  --funcmode = run
280 
281 EXCEPTION
282     when others then
283        wf_core.context('OE_Blanket_WF', 'Calculate_Effective_Dates', itemtype, itemkey, to_char(actid), funcmode);
284        -- start data fix project
285        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
286                                           p_itemtype => itemtype,
287                                           p_itemkey => itemkey);
288        -- end data fix project
289        OE_STANDARD_WF.Save_Messages;
290        OE_STANDARD_WF.Clear_Msg_Context;
291        raise;
292 
293 END Calculate_Effective_Dates;
294 
295 
296 PROCEDURE Set_Blanket_Hdr_Descriptor
297    (document_id   in VARCHAR2,
298     display_type  in VARCHAR2,
299     document      in out nocopy VARCHAR2,
300     document_type in out nocopy VARCHAR2)
301 IS
302 --
303 l_header_id NUMBER;
304 l_blanket_number NUMBER;
305 l_header_txt VARCHAR2(2000);
306 --
307 BEGIN
308 
309   document_type := display_type;
310   BEGIN
311    -- if viewing method is through URL
312    -- fix bug 1332384
313    SELECT item_key
314    INTO l_header_id
315    FROM wf_item_activity_statuses
316    where notification_id = to_number(document_id);
317   EXCEPTION
318    WHEN NO_DATA_FOUND THEN
319      -- if viewing method is email
320      l_header_id := to_number(wf_engine.setctx_itemkey);
321   END;
322 
323   SELECT order_number
324   INTO   l_blanket_number
325   FROM   oe_blanket_headers_all
326   WHERE  header_id = l_header_id;
327 
328   fnd_message.set_name('ONT', 'OE_WF_BLANKET_ORDER');
329   fnd_message.set_token('BLANKET_NUMBER', to_char(l_blanket_number));
330   l_header_txt := fnd_message.get;
331   document := substrb(l_header_txt, 1, 240);
332 
333 EXCEPTION
334      WHEN OTHERS THEN
335      IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
336      THEN
337         OE_MSG_PUB.Add_Exc_Msg
338         (G_PKG_NAME
339         , 'Set_Blanket_Hdr_Descriptor'
340         );
341         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
342      END IF;
343 END Set_Blanket_Hdr_Descriptor;
344 
345 
346 PROCEDURE Get_Expire_Date
347    (document_id   in VARCHAR2,
348     display_type  in VARCHAR2,
349     document      in out nocopy VARCHAR2,
350     document_type in out nocopy VARCHAR2)
351 IS
352 --
353 l_header_id NUMBER;
354 l_end_date  DATE;
355 --
356 BEGIN
357   document_type := display_type;
358   BEGIN
359    -- if viewing method is through URL
360    -- fix bug 1332384
361    SELECT item_key
362    INTO l_header_id
363    FROM wf_item_activity_statuses
364    where notification_id = to_number(document_id);
365   EXCEPTION
366    WHEN NO_DATA_FOUND THEN
367      -- if viewing method is email
368      l_header_id := to_number(wf_engine.setctx_itemkey);
369   END;
370 
371   SELECT obhe.end_date_active
372   INTO   l_end_date
373   FROM   oe_blanket_headers_all obha, oe_blanket_headers_ext obhe
374   WHERE  obha.header_id = l_header_id
375   AND    obha.order_number = obhe.order_number;
376 
377   document := to_char(l_end_date, 'DD-MON-RRRR');
378 
379 EXCEPTION
380      WHEN OTHERS THEN
381      IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
382      THEN
383         OE_MSG_PUB.Add_Exc_Msg
384         (G_PKG_NAME
385         , 'Get_Expire_Date'
386         );
387         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
388      END IF;
389 
390 END Get_Expire_Date;
391 
392 
393 PROCEDURE Expired(
394     itemtype  in varchar2,
395     itemkey   in varchar2,
396     actid     in number,
397     funcmode  in varchar2,
398     resultout in out nocopy varchar2)
399 IS
400 --
401 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
402 l_return_status VARCHAR2(30);
403 l_sold_to_org_id NUMBER;
404 l_salesrep_id    NUMBER;
405 l_salesrep       VARCHAR2(240);
406 l_sold_to        VARCHAR2(240);
407 l_customer_number  VARCHAR2(30);--bug5562980
408 l_end_date   DATE;
409 l_aname      wf_engine.nametabtyp;
410 l_avaluetext wf_engine.texttabtyp;
411 --
412 BEGIN
413     IF l_debug_level  > 0 THEN
414        oe_debug_pub.add(  'ENTERING OE_BLanket_WF.Expired:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
415     END IF;
416     OE_STANDARD_WF.Set_Msg_Context(actid);
417     IF (funcmode = 'RUN') then
418       OE_ORDER_WF_UTIL.Update_Quote_Blanket( p_item_type => OE_GLOBALS.G_WFI_BKT,
419                                         p_item_key => itemkey,
420                                         p_flow_status_code => 'EXPIRED',
421                                         x_return_status => l_return_status);
422 
423       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
424         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
425       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
426         RAISE FND_API.G_EXC_ERROR;
427       END IF;
428 
429       -- set WF header attributes, values may have been changed during the wait period
430       select bh.sold_to_org_id, bhx.end_date_active, bh.salesrep_id
431       into   l_sold_to_org_id, l_end_date, l_salesrep_id
432       from   oe_blanket_headers_all bh, oe_blanket_headers_ext bhx
433       where  bh.header_id = to_number(itemkey)
434       and    bh.order_number = bhx.order_number;
435 
436       l_salesrep := OE_Id_To_Value.Salesrep(p_salesrep_id=>l_salesrep_id);
437       OE_Id_To_Value.Sold_To_Org(p_sold_to_org_id=>l_sold_to_org_id, x_org=> l_sold_to,
438                                  x_customer_number=>l_customer_number);
439        l_aname(1) := 'SALESPERSON';
440        l_avaluetext(1) := l_salesrep;
441        l_aname(2) := 'SOLD_TO';
442        l_avaluetext(2) := l_sold_to;
443        l_aname(3) := 'BLANKET_EXPIRE_DATE';
444        l_avaluetext(3) := l_end_date;
445 
446        wf_engine.SetItemAttrTextArray(itemtype=>itemtype,
447 				      itemkey=>itemkey,
448 				      aname=>l_aname,
449 				      avalue=>l_avaluetext);
450 
451 
452       resultout := 'COMPLETE:COMPLETE';
453 
454     END IF;
455 EXCEPTION
456     when others then
457        wf_core.context('OE_Blanket_WF', 'Expired', itemtype, itemkey, to_char(actid), funcmode);
458        -- start data fix project
459        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
460                                           p_itemtype => itemtype,
461                                           p_itemkey => itemkey);
462        -- end data fix project
463        OE_STANDARD_WF.Save_Messages;
464        OE_STANDARD_WF.Clear_Msg_Context;
465        raise;
466 END Expired;
467 
468 
469 
470 PROCEDURE Terminate_Internal(
471     itemtype  in varchar2,
472     itemkey   in varchar2,
473     actid     in number,
474     funcmode  in varchar2,
475     resultout in out nocopy varchar2)
476 
477 IS
478 --
479 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
480 l_return_status VARCHAR2(30);
481 --
482 BEGIN
483     IF l_debug_level  > 0 THEN
484        oe_debug_pub.add(  'ENTERING OE_BLanket_WF.Terminate_Internal:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
485     END IF;
486     OE_STANDARD_WF.Set_Msg_Context(actid);
487     IF (funcmode = 'RUN') then
488       OE_ORDER_WF_UTIL.Update_Quote_Blanket( p_item_type => OE_GLOBALS.G_WFI_BKT,
489                                         p_item_key => itemkey,
490                                         p_flow_status_code => 'TERMINATED',
491                                         x_return_status => l_return_status);
492 
493       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
494         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
495       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
496         RAISE FND_API.G_EXC_ERROR;
497       END IF;
498 
499       resultout := 'COMPLETE';
500 
501     END IF;
502 EXCEPTION
503     when others then
504        wf_core.context('OE_Blanket_WF', 'Terminate_Internal', itemtype, itemkey, to_char(actid), funcmode);
505        -- start data fix project
506        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
507                                           p_itemtype => itemtype,
508                                           p_itemkey => itemkey);
509        -- end data fix project
510        OE_STANDARD_WF.Save_Messages;
511        OE_STANDARD_WF.Clear_Msg_Context;
512        raise;
513 
514 END Terminate_Internal;
515 
516 PROCEDURE Close_Internal(
517     itemtype  in varchar2,
518     itemkey   in varchar2,
519     actid     in number,
520     funcmode  in varchar2,
521     resultout in out nocopy varchar2)
522 IS
523 --
524 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
525 l_return_status VARCHAR2(30);
526 l_msg_data VARCHAR2(2000);
527 l_msg_count NUMBER;
528 l_blanket_number NUMBER;
529 --
530 BEGIN
531     IF l_debug_level  > 0 THEN
532        oe_debug_pub.add(  'ENTERING OE_BLanket_WF.Close_Internal:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
533     END IF;
534     OE_STANDARD_WF.Set_Msg_Context(actid);
535     IF (funcmode = 'RUN') then
536       -- check for releases of blanket
537       l_blanket_number := wf_engine.GetItemAttrNumber(itemtype, itemkey, 'TRANSACTION_NUMBER');
538       OE_BLANKET_WF_UTIL.Check_Release(p_blanket_number => l_blanket_number, x_return_status => l_return_status);
539       IF l_return_status <> FND_API.G_RET_STS_SUCCESS THEN
540         --Blanket release check failed, return incomplete
541         --UI will display the message
542         resultout := 'COMPLETE:INCOMPLETE';
543         OE_STANDARD_WF.Save_Messages;
544         OE_STANDARD_WF.Clear_Msg_Context;
545         return;
546       END IF;
547       -- update open_flag to N
548       OE_ORDER_WF_UTIL.Update_Quote_Blanket( p_item_type => OE_GLOBALS.G_WFI_BKT,
549                                         p_item_key => itemkey,
550                                         p_flow_status_code => 'CLOSED',--bug#5589336
551                                         p_open_flag => 'N',
552                                         x_return_status => l_return_status);
553       IF l_return_status = FND_API.G_RET_STS_UNEXP_ERROR THEN
554         RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
555       ELSIF l_return_status = FND_API.G_RET_STS_ERROR THEN
556         RAISE FND_API.G_EXC_ERROR;
557       END IF;
558       resultout := 'COMPLETE:COMPLETE';
559 
560     END IF;
561 EXCEPTION
562     when others then
563        wf_core.context('OE_Blanket_WF', 'Close_Internal', itemtype, itemkey, to_char(actid), funcmode);
564        -- start data fix project
565        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
566                                           p_itemtype => itemtype,
567                                           p_itemkey => itemkey);
568        -- end data fix project
569        OE_STANDARD_WF.Save_Messages;
570        OE_STANDARD_WF.Clear_Msg_Context;
571        raise;
572 
573 END Close_Internal;
574 
575 
576 
577 PROCEDURE Blanket_Date_Changed(p_header_id IN NUMBER,
578                                x_return_status OUT NOCOPY VARCHAR2)
579 IS
580 --
581 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
582 l_activity_name VARCHAR2(30);
583 l_transaction_phase_code VARCHAR2(30);
584 --
585 BEGIN
586     OE_MSG_PUB.initialize;
587     x_return_status := FND_API.G_RET_STS_SUCCESS;
588     IF l_debug_level  > 0 THEN
589        oe_debug_pub.add('ENTERING OE_Blanket_WF.Blanket_Date_Changed: '|| TO_CHAR (p_header_id) ,1);
590     END IF;
591 
592     SELECT transaction_phase_code
593     INTO   l_transaction_phase_code
594     FROM   oe_blanket_headers_all
595     WHERE  header_id = p_header_id;
596 
597     IF nvl(l_transaction_phase_code, 'F') = 'N' THEN
598        -- currently during negotiation phase, there is no impact
599        -- on changing the dates on a blanket
600        RETURN;
601     END IF;
602 
603 
604     BEGIN
605       select wpa.activity_name
606       into l_activity_name
607       from wf_item_activity_statuses wias, wf_process_activities wpa
608       where item_type = OE_GLOBALS.G_WFI_BKT
609       and item_key = to_char(p_header_id)
610       and activity_status = 'NOTIFIED'
611       and wpa.activity_name in ('WAIT_FOR_START_DATE', 'BLANKET_NO_END_DATE', 'WAIT_FOR_EXPIRATION', 'WAIT_FOR_FINAL_EXPIRATION', 'BLANKET_SUBMIT_DRAFT_ELIGIBLE')
612       and wias.process_activity = wpa.instance_id;
613 
614     EXCEPTION
615       WHEN OTHERS THEN
616            fnd_message.set_name('ONT', 'OE_BKT_NO_DATE_CHANGE');
617            oe_msg_pub.add;
618            x_return_status := FND_API.G_RET_STS_ERROR;
619            IF l_debug_level  > 0 THEN
620              oe_debug_pub.add('EXITING OE_Blanket_WF.Blanket_Date_Changed WITH STATUS: '||X_RETURN_STATUS ,1);
621            END IF;
622            return;
623 
624     END;
625 
626     -- ok to go date change
627     -- if it is at blanket_submit_draft_eligible, no need to go date change, calculate effective date later will figure out the right timers
628     IF l_activity_name <> 'BLANKET_SUBMIT_DRAFT_ELIGIBLE' THEN
629         WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_BKT, to_char(p_header_id), l_activity_name, 'DATE_CHANGED');
630     END IF;
631 
632     IF l_debug_level  > 0 THEN
633           oe_debug_pub.add('EXITING OE_Blanket_WF.Blanket_Date_Changed normally', 1);
634     END IF;
635 
636 EXCEPTION
637     WHEN OTHERS THEN
638         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
639         IF l_debug_level  > 0 THEN
640           oe_debug_pub.add('EXITING OE_Blanket_WF.Blanket_Date_Changed WITH STATUS: '||X_RETURN_STATUS ,1);
641         END IF;
642         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
643            THEN
644                  OE_MSG_PUB.Add_Exc_Msg
645                        (   G_PKG_NAME,
646                           'Blanket_Date_Changed'
647                        );
648         END IF;
649 
650 
651 END Blanket_Date_Changed;
652 
653 
654 PROCEDURE Submit_Draft(p_header_id IN NUMBER,
655                        p_transaction_phase_code IN VARCHAR2,
656                        x_return_status OUT NOCOPY VARCHAR2)
657 IS
658 --
659 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
660 l_activity_name VARCHAR2(30);
661 l_sales_document_type VARCHAR2(30);
662 --
663 BEGIN
664     -- OE_MSG_PUB.initialize; commented out due to 4671489
665     x_return_status := FND_API.G_RET_STS_SUCCESS;
666     IF l_debug_level  > 0 THEN
667        oe_debug_pub.add('ENTERING OE_Blanket_WF.Submit_Draft: '|| TO_CHAR (p_header_id) ,1);
668     END IF;
669     BEGIN
670       select wpa.activity_name
671       into l_activity_name
672       from wf_item_activity_statuses wias, wf_process_activities wpa
673       where item_type = OE_GLOBALS.G_WFI_BKT
674       and item_key = to_char(p_header_id)
675       and activity_status = 'NOTIFIED'
676       and wpa.activity_name = 'BLANKET_SUBMIT_DRAFT_ELIGIBLE'
677       and wias.process_activity = wpa.instance_id;
678 
679     EXCEPTION
680       WHEN OTHERS THEN
681            fnd_message.set_name('ONT', 'OE_WF_BLANKET');
682            l_sales_document_type := fnd_message.get;
683            fnd_message.set_name('ONT', 'OE_WF_NO_SUBMIT_DRAFT');
684            -- FND message activity name should match WF activity name for Submit Draft in blanket
685            fnd_message.set_token('SALES_DOCUMENT_TYPE', l_sales_document_type);
686            oe_msg_pub.add;
687            x_return_status := FND_API.G_RET_STS_ERROR;
688            IF l_debug_level  > 0 THEN
689              oe_debug_pub.add('EXITING OE_Blanket_WF.Submit_Draft WITH STATUS: '||X_RETURN_STATUS ,1);
690            END IF;
691            return;
692     END;
693 
694     -- ok to go submit draft
695     WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_BKT, to_char(p_header_id), l_activity_name, 'COMPLETE');
696 
697     IF l_debug_level  > 0 THEN
698           oe_debug_pub.add('EXITING OE_Blanket_WF.Submit_Draft', 1);
699     END IF;
700 
701 EXCEPTION
702     WHEN OTHERS THEN
703         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
704         IF l_debug_level  > 0 THEN
705           oe_debug_pub.add('EXITING OE_Blanket_WF.Submit_Draft WITH STATUS: '||X_RETURN_STATUS ,1);
706         END IF;
707         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
708            THEN
709                  OE_MSG_PUB.Add_Exc_Msg
710                        (   G_PKG_NAME,
711                           'Submit_Draft'
712                        );
713         END IF;
714 
715 
716 END Submit_Draft;
717 
718 
719 PROCEDURE Close(p_header_id IN NUMBER,
720                 x_return_status OUT NOCOPY VARCHAR2)
721 IS
722 --
723 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
724 l_activity_name VARCHAR2(30);
725 l_sales_document_type VARCHAR2(30);
726 --
727 BEGIN
728     OE_MSG_PUB.initialize;
729     x_return_status := FND_API.G_RET_STS_SUCCESS;
730     IF l_debug_level  > 0 THEN
731        oe_debug_pub.add('ENTERING OE_Blanket_WF.Close: '|| TO_CHAR (p_header_id) ,1);
732     END IF;
733     BEGIN
734       select wpa.activity_name
735       into l_activity_name
736       from wf_item_activity_statuses wias, wf_process_activities wpa
737       where item_type = OE_GLOBALS.G_WFI_BKT
738       and item_key = to_char(p_header_id)
739       and activity_status = 'NOTIFIED'
740       and wpa.activity_name = 'CLOSE_BLANKET_ELIGIBLE'
741       and wias.process_activity = wpa.instance_id;
742 
743     EXCEPTION
744       WHEN OTHERS THEN
745            fnd_message.set_name('ONT', 'OE_BKT_NO_CLOSE');
746            oe_msg_pub.add;
747            x_return_status := FND_API.G_RET_STS_ERROR;
748            IF l_debug_level  > 0 THEN
749              oe_debug_pub.add('EXITING OE_Blanket_WF.Close WITH STATUS: '||X_RETURN_STATUS ,1);
750            END IF;
751            return;
752 
753     END;
754 
755     -- ok to go submit draft
756     WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_BKT, to_char(p_header_id), l_activity_name, 'COMPLETE');
757 
758     IF l_debug_level  > 0 THEN
759           oe_debug_pub.add('EXITING OE_Blanket_WF.Close', 1);
760     END IF;
761 
762 EXCEPTION
763     WHEN OTHERS THEN
764         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
765         IF l_debug_level  > 0 THEN
766           oe_debug_pub.add('EXITING OE_Blanket_WF.Close WITH STATUS: '||X_RETURN_STATUS ,1);
767         END IF;
768         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
769            THEN
770                  OE_MSG_PUB.Add_Exc_Msg
771                        (   G_PKG_NAME,
772                           'Close'
773                        );
774         END IF;
775 
776 
777 END Close;
778 
779 
780 PROCEDURE Terminate(p_header_id IN NUMBER,
781                     p_terminated_by IN NUMBER,
782                     p_version_number IN NUMBER,
783                     p_reason_type IN VARCHAR2,
784                     p_reason_code IN VARCHAR2,
785                     p_reason_comments IN VARCHAR2,
786                     x_return_status OUT NOCOPY VARCHAR2)
787 IS
788 --
789 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
790 l_activity_name VARCHAR2(30);
791 l_sales_document_type VARCHAR2(30);
792 l_sold_to_org_id NUMBER;
793 l_salesrep_id    NUMBER;
794 l_salesrep       VARCHAR2(240);
795 l_sold_to        VARCHAR2(240);
796 l_customer_number VARCHAR2(30);--bug5562980
797 l_end_date   DATE;
798 l_aname      wf_engine.nametabtyp;
799 l_avaluetext wf_engine.texttabtyp;
800 l_terminator VARCHAR2(100);
801 l_return_status VARCHAR2(240);
802 l_reason_id  NUMBER;
803 --
804 BEGIN
805     OE_MSG_PUB.initialize;
806     x_return_status := FND_API.G_RET_STS_SUCCESS;
807     IF l_debug_level  > 0 THEN
808        oe_debug_pub.add('ENTERING OE_Blanket_WF.Terminate: '|| TO_CHAR (p_header_id) ,1);
809     END IF;
810     BEGIN
811       select wpa.activity_name
812       into l_activity_name
813       from wf_item_activity_statuses wias, wf_process_activities wpa
814       where item_type = OE_GLOBALS.G_WFI_BKT
815       and item_key = to_char(p_header_id)
816       and activity_status = 'NOTIFIED'
817       and wpa.activity_name in ('WAIT_FOR_START_DATE', 'BLANKET_NO_END_DATE', 'WAIT_FOR_EXPIRATION', 'WAIT_FOR_FINAL_EXPIRATION')
818       and wias.process_activity = wpa.instance_id;
819 
820     EXCEPTION
821       WHEN OTHERS THEN
822            fnd_message.set_name('ONT', 'OE_BKT_NO_TERMINATE');
823            oe_msg_pub.add;
824            x_return_status := FND_API.G_RET_STS_ERROR;
825            IF l_debug_level  > 0 THEN
826              oe_debug_pub.add('EXITING OE_Blanket_WF.Terminate WITH STATUS: '||X_RETURN_STATUS ,1);
827            END IF;
828            return;
829     END;
830 
831     -- ok to go terminate
832     -- call reason API to capture the reason
833 
834     OE_REASONS_UTIL.Apply_Reason(p_entity_code => OE_BLANKET_PUB.G_ENTITY_BLANKET_HEADER,
835                                 p_entity_id => p_header_id,
836                                 p_version_number => p_version_number,
837                                 p_reason_type => p_reason_type,
838                                 p_reason_code => p_reason_code,
839                                 p_reason_comments => p_reason_comments,
840                                 x_reason_id => l_reason_id,
841                                 x_return_status => l_return_status);
842 
843     SELECT USER_NAME
844     INTO   l_terminator
845     FROM FND_USER
846     WHERE USER_ID = p_terminated_by;
847 
848     WF_ENGINE.SetItemAttrText(itemtype=>OE_GLOBALS.G_WFI_BKT,
849 			      itemkey=>to_char(p_header_id),
850 			      aname=>'TERMINATOR',
851 			      avalue=>l_terminator);
852 
853     -- set WF header attributes, values may have been changed during the wait period
854     select bh.sold_to_org_id, bhx.end_date_active, bh.salesrep_id
855     into   l_sold_to_org_id, l_end_date, l_salesrep_id
856     from   oe_blanket_headers_all bh, oe_blanket_headers_ext bhx
857     where  bh.header_id = p_header_id
858     and    bh.order_number = bhx.order_number;
859 
860     l_salesrep := OE_Id_To_Value.Salesrep(p_salesrep_id=>l_salesrep_id);
861     OE_Id_To_Value.Sold_To_Org(p_sold_to_org_id=>l_sold_to_org_id, x_org=> l_sold_to,
862                                  x_customer_number=>l_customer_number);
863     l_aname(1) := 'SALESPERSON';
864     l_avaluetext(1) := l_salesrep;
865     l_aname(2) := 'SOLD_TO';
866     l_avaluetext(2) := l_sold_to;
867     l_aname(3) := 'BLANKET_EXPIRE_DATE';
868     l_avaluetext(3) := l_end_date;
869 
870     wf_engine.SetItemAttrTextArray(itemtype=>OE_GLOBALS.G_WFI_BKT,
871 				   itemkey=>to_char(p_header_id),
872 				   aname=>l_aname,
873 				   avalue=>l_avaluetext);
874 
875     -- end header attributes
876 
877     WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_BKT, to_char(p_header_id), l_activity_name, 'TERMINATE');
878 
879     IF l_debug_level  > 0 THEN
880           oe_debug_pub.add('EXITING OE_Blanket_WF.Terminate', 1);
881     END IF;
882 
883 EXCEPTION
884     WHEN OTHERS THEN
885         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
886         IF l_debug_level  > 0 THEN
887           oe_debug_pub.add('EXITING OE_Blanket_WF.Terminate WITH STATUS: '||X_RETURN_STATUS ,1);
888         END IF;
889         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
890            THEN
891                  OE_MSG_PUB.Add_Exc_Msg
892                        (   G_PKG_NAME,
893                           'Terminate'
894                        );
895         END IF;
896 
897 END Terminate;
898 
899 
900 PROCEDURE Extend(p_header_id IN NUMBER,
901                  x_return_status OUT NOCOPY VARCHAR2)
902 IS
903 --
904 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
905 l_activity_name VARCHAR2(30);
906 --
907 BEGIN
908     OE_MSG_PUB.initialize;
909     x_return_status := FND_API.G_RET_STS_SUCCESS;
910     IF l_debug_level  > 0 THEN
911        oe_debug_pub.add('ENTERING OE_Blanket_WF.Extend: '|| TO_CHAR (p_header_id) ,1);
912     END IF;
913     BEGIN
914       select wpa.activity_name
915       into l_activity_name
916       from wf_item_activity_statuses wias, wf_process_activities wpa
917       where item_type = OE_GLOBALS.G_WFI_BKT
918       and item_key = to_char(p_header_id)
919       and activity_status = 'NOTIFIED'
920       and wpa.activity_name = 'CLOSE_BLANKET_ELIGIBLE'
921       and wias.process_activity = wpa.instance_id;
922 
923     EXCEPTION
924       WHEN OTHERS THEN
925            fnd_message.set_name('ONT', 'OE_BKT_NO_EXTEND');
926            oe_msg_pub.add;
927            x_return_status := FND_API.G_RET_STS_ERROR;
928            IF l_debug_level  > 0 THEN
929              oe_debug_pub.add('EXITING OE_Blanket_WF.Extend WITH STATUS: '||X_RETURN_STATUS ,1);
930            END IF;
931            return;
932     END;
933 
934     -- ok to go extend
935     WF_ENGINE.CompleteActivityInternalName(OE_GLOBALS.G_WFI_BKT, to_char(p_header_id), l_activity_name, 'EXTEND');
936 
937     IF l_debug_level  > 0 THEN
938           oe_debug_pub.add('EXITING OE_Blanket_WF.Extend', 1);
939     END IF;
940 
941 EXCEPTION
942     WHEN OTHERS THEN
943         x_return_status := FND_API.G_RET_STS_UNEXP_ERROR ;
944         IF l_debug_level  > 0 THEN
945           oe_debug_pub.add('EXITING OE_Blanket_WF.Extend WITH STATUS: '||X_RETURN_STATUS ,1);
946         END IF;
947         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
948            THEN
949                  OE_MSG_PUB.Add_Exc_Msg
950                        (   G_PKG_NAME,
951                           'Extend'
952                        );
953         END IF;
954 
955 END Extend;
956 
957 PROCEDURE Set_Header_Attributes_Internal(p_header_id IN NUMBER)
958 IS
959 --
960 l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
961 l_sold_to_org_id NUMBER;
962 l_salesrep_id    NUMBER;
963 l_salesrep       VARCHAR2(240);
964 l_sold_to        VARCHAR2(240);
965 l_customer_number VARCHAR2(30);--bug5562980
966 l_end_date   DATE;
967 l_aname      wf_engine.nametabtyp;
968 l_avaluetext wf_engine.texttabtyp;
969 --
970 BEGIN
971     IF l_debug_level  > 0 THEN
972        oe_debug_pub.add(  'ENTERING OE_Blanket_WF.Set_Header_Attributes_Internal:'||To_char(p_header_id),1);
973     END IF;
974 
975       select bh.sold_to_org_id, bhx.end_date_active, bh.salesrep_id
976       into   l_sold_to_org_id, l_end_date, l_salesrep_id
977       from   oe_blanket_headers_all bh, oe_blanket_headers_ext bhx
978       where  bh.header_id = p_header_id
979       and    bh.order_number = bhx.order_number;
980 
981        l_salesrep := OE_Id_To_Value.Salesrep(p_salesrep_id=>l_salesrep_id);
982        OE_Id_To_Value.Sold_To_Org(p_sold_to_org_id=>l_sold_to_org_id, x_org=> l_sold_to, x_customer_number=>l_customer_number);
983        l_aname(1) := 'SALESPERSON';
984        l_avaluetext(1) := l_salesrep;
985        l_aname(2) := 'SOLD_TO';
986        l_avaluetext(2) := l_sold_to;
987        l_aname(3) := 'BLANKET_EXPIRE_DATE';
988        l_avaluetext(3) := l_end_date;
989 
990        wf_engine.SetItemAttrTextArray(itemtype=>OE_GLOBALS.G_WFI_BKT,
991 				      itemkey=>To_char(p_header_id),
992 				      aname=>l_aname,
993 				      avalue=>l_avaluetext);
994 
995        -- end setting item attribute for WF header attributes
996 EXCEPTION
997     WHEN OTHERS THEN
998         IF OE_MSG_PUB.Check_Msg_Level(OE_MSG_PUB.G_MSG_LVL_UNEXP_ERROR)
999            THEN
1000                  OE_MSG_PUB.Add_Exc_Msg
1001                        (   G_PKG_NAME,
1002                           'Set_Header_Attributes_Internal'
1003                        );
1004            RAISE FND_API.G_EXC_UNEXPECTED_ERROR;
1005         END IF;
1006 
1007 END Set_Header_Attributes_Internal;
1008 
1009 PROCEDURE Set_Header_Attributes(
1010     itemtype  in varchar2,
1011     itemkey   in varchar2,
1012     actid     in number,
1013     funcmode  in varchar2,
1014     resultout in out nocopy varchar2)
1015 IS
1016 --
1017    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1018 --
1019 BEGIN
1020    IF l_debug_level  > 0 THEN
1021        oe_debug_pub.add(  'ENTERING OE_Blanket_WF.Set_Header_Attributes:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
1022    END IF;
1023    OE_STANDARD_WF.Set_Msg_Context(actid);
1024    IF (funcmode = 'RUN') THEN
1025        set_header_attributes_internal(To_number(itemkey));
1026        resultout := 'COMPLETE';
1027    END IF;
1028 EXCEPTION
1029     when others then
1030        wf_core.context('OE_Blanket_WF', 'Set_Header_Attributes', itemtype, itemkey, to_char(actid), funcmode);
1031        -- start data fix project
1032        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
1033                                           p_itemtype => itemtype,
1034                                           p_itemkey => itemkey);
1035        -- end data fix project
1036        OE_STANDARD_WF.Save_Messages;
1037        OE_STANDARD_WF.Clear_Msg_Context;
1038        raise;
1039 END Set_Header_Attributes;
1040 
1041 
1042 PROCEDURE set_final_expiration_date(
1043     itemtype  in varchar2,
1044     itemkey   in varchar2,
1045     actid     in number,
1046     funcmode  in varchar2,
1047     resultout in out nocopy varchar2)
1048 IS
1049 --
1050    l_debug_level CONSTANT NUMBER := oe_debug_pub.g_debug_level;
1051    l_final_timer NUMBER;
1052    l_end_date DATE;
1053    l_from_role VARCHAR2(200);  --for bug 9897971
1054 
1055 --
1056 
1057 BEGIN
1058     IF l_debug_level  > 0 THEN
1059        oe_debug_pub.add(  'ENTERING OE_Blanket_WF.Set_Final_Expiration_Date:'||ITEMTYPE||'/'||ITEMKEY ,1 ) ;
1060     END IF;
1061     OE_STANDARD_WF.Set_Msg_Context(actid);
1062     IF (funcmode = 'RUN') THEN
1063        set_header_attributes_internal(To_number(itemkey));
1064        IF l_debug_level  > 0 THEN
1065          oe_debug_pub.add(  'Done setting header attributes',1);
1066        END IF;
1067 
1068       SELECT obhe.End_Date_Active
1069       INTO   l_end_date
1070       FROM   oe_blanket_headers_all obha, oe_blanket_headers_ext obhe
1071       WHERE  obha.header_id = to_number(itemkey)
1072       AND    obha.order_number = obhe.order_number;
1073 
1074 
1075        l_final_timer := (l_end_date - Sysdate) * 1440;
1076        IF l_final_timer > 0 THEN
1077 	  wf_engine.setitemattrnumber(itemtype=>itemtype,
1078 				      itemkey=>itemkey,
1079 				      aname=>'BLANKET_FINAL_EXPIRE_TIMER',
1080 				      avalue=>l_final_timer);
1081 
1082        /*starting the fix for bug 9897971 */
1083        l_from_role:=wf_engine.GetItemAttrText(itemtype,itemkey,'NOTIFICATION_FROM_ROLE');
1084          IF NOT WF_DIRECTORY.UserActive(l_from_role) THEN
1085             l_from_role := fnd_profile.Value('OE_NOTIFICATION_APPROVER');
1086             IF l_from_role IS null or NOT WF_DIRECTORY.UserActive(l_from_role) then
1087             l_from_role := 'SYSADMIN';
1088             END IF;
1089          END IF;
1090      wf_engine.setItemAttrText(itemtype,itemkey,'NOTIFICATION_FROM_ROLE',l_from_role);
1091      /*ending the fix for bug 9897971 */
1092 
1093 	  resultout := 'COMPLETE';
1094        ELSE
1095           resultout := 'COMPLETE:EXPIRED';
1096        END IF;
1097 
1098        IF l_debug_level  > 0 THEN
1099              oe_debug_pub.add('Leaving OE_Blanket_WF.Set_Final_Expiration_Date', 1);
1100        END IF;
1101     END IF;
1102 EXCEPTION
1103     when others then
1104        wf_core.context('OE_Blanket_WF', 'Set_Final_Expiration_Date', itemtype, itemkey, to_char(actid), funcmode);
1105        -- start data fix project
1106        OE_STANDARD_WF.Add_Error_Activity_Msg(p_actid => actid,
1107                                           p_itemtype => itemtype,
1108                                           p_itemkey => itemkey);
1109        -- end data fix project
1110        OE_STANDARD_WF.Save_Messages;
1111        OE_STANDARD_WF.Clear_Msg_Context;
1112        raise;
1113 END set_final_expiration_date;
1114 
1115 END OE_Blanket_WF;